AtCoder プログラミングコンテスト2024(AtCoder Beginner Contest 382)
G
Tile Distance 3
AtCoder
⌀ 3278
原题
翻译中…

Problem Statement

翻译中…

Tiles are laid out covering the two-dimensional coordinate plane.

翻译中…

Each tile is a rectangle, and for each integer triple $(i, j, k)$ satisfying $0 \leq k < K$, a corresponding tile is placed according to the following rules:

翻译中…
  • When $i$ and $j$ have the same parity (both even or both odd), the tile corresponding to $(i, j, k)$ covers the area where $iK \leq x \leq (i + 1)K$ and $jK + k \leq y \leq jK + k + 1$.
  • When $i$ and $j$ have different parity, the tile corresponding to $(i, j, k)$ covers the area where $iK + k \leq x \leq iK + k + 1$ and $jK \leq y \leq (j + 1)K$.
翻译中…

Two tiles are adjacent when their edges have a common segment of positive length.

翻译中…

Starting from the tile containing the point $(S_x + 0.5, S_y + 0.5)$, find the minimum number of times you need to move to an adjacent tile to reach the tile containing the point $(T_x + 0.5, T_y + 0.5)$.

翻译中…

There are $T$ test cases; solve each of them.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 10^4$
  • $2 \leq K \leq 10^{16}$
  • $-10^{16} \leq S_x, S_y, T_x, T_y \leq 10^{16}$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\vdots
\text{case}_T

翻译中…

Each case is given in the following format:

翻译中…

K S_x S_y T_x T_y

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.

翻译中…

样例

Input #1
3
3 -2 1 4 -1
4 8 8 0 2
5 -1000000000000 -1000000000000 1000000000000 1000000000000
Output #1
4
4
800000000000
Let us explain the first test case. Let $(i, j, k)$ denote the tile corresponding to integer triple $(i, j, k)$. $(-1.5, 1.5)$ is contained in tile $(-1, 0, 1)$, and $(4.5, -0.5)$ is contained in tile $(1, -1, 2)$. For example, by moving from tile $(-1, 0, 1)$ to $(-1, 0, 2)$ to $(0, 0, 2)$ to $(1, 0, 0)$ to $(1, -1, 2)$, you can reach tile $(1, -1, 2)$ in four moves to an adjacent tile. ![image](https://img.atcoder.jp/abc382/89f3686844bfbe1ca95741ff33cd3468.png)
题目信息
题号
abc382_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。