#K63557. Minimum Moves in a Hexagonal Grid

    ID: 31779 Type: Default 1000ms 256MiB

Minimum Moves in a Hexagonal Grid

Minimum Moves in a Hexagonal Grid

You are given a hexagonal grid where each cell has 6 adjacent neighbors. Starting from the origin \((0,0)\), you must determine the minimum number of moves required to reach the cell \((a, b)\). In one move, you can travel to any one of the six neighboring cells.

It can be proven that the minimum number of moves \(d\) is given by the following: \[ d = \begin{cases} |b|, & \text{if } |a| \le |b|, \\ \left\lfloor \frac{|a| + |b| + 1}{2} \right\rfloor, & \text{if } |a| > |b|. \end{cases} \]

For example:

  • For \(a=2,\; b=3\): Since \(|2| \le |3|\), the answer is 3.
  • For \(a=-1,\; b=1\): Since \(|-1| = 1 \le 1=|1|\), the answer is 1.
  • For \(a=1,\; b=-2\): Since \(|1| \le |2|\), the answer is 2.

Your task is to implement this logic.

inputFormat

The input consists of a single line containing two space-separated integers \(a\) and \(b\) which represent the coordinates of the target cell.

\( -10^6 \leq a, b \leq 10^6 \)

outputFormat

Output a single integer representing the minimum number of moves required to reach cell \((a, b)\) from the origin.

## sample
2 3
3

</p>