#C11524. Minimum Moves to Origin

    ID: 40850 Type: Default 1000ms 256MiB

Minimum Moves to Origin

Minimum Moves to Origin

Given an integer (p) representing the initial position of a character on a one-dimensional number line and an integer (m) representing the fixed distance the character can jump in one move, your task is to determine the minimum number of moves required for the character to reach the origin (position 0).

In one move, the character can either:

  1. Jump exactly (m) units to the left or right, if the position allows a sequence of such moves to exactly land on 0; or
  2. Use a teleport move which instantly transports the character to the origin.

    The optimal strategy is to use jump moves if the absolute value of (p) is exactly divisible by (m) (i.e. (\left|p\right| \mod m = 0)). Otherwise, a single teleport move is sufficient. Note that if the starting position is already 0, no moves are required.

inputFormat

The input is provided via standard input (stdin) and consists of a single line containing two space-separated integers (p) and (m), where (-10^9 \leq p \leq 10^9) and (1 \leq m \leq 10^9).

outputFormat

Output to standard output (stdout) a single integer representing the minimum number of moves required for the character to reach the origin.## sample

0 5
0