import sys x = int(sys.stdin.readline()) y = int(sys.stdin.readline()) L = int(sys.stdin.readline()) if x == 0 and y == 0: print(0) sys.exit() def compute_rotation_cost(current, target): clockwise = (target - current) % 4 counter = (current - target) % 4 return min(clockwise, counter) if x == 0: if y >= 0: moves = (y + L - 1) // L print(moves) else: rotates = 2 moves = (-y + L - 1) // L print(rotates + moves) sys.exit() if y == 0: rotates = 1 moves = (abs(x) + L - 1) // L print(rotates + moves) sys.exit() # Both x and y are non-zero # Case 1: Process Y first y_dir = 0 if y >= 0 else 2 x_dir = 1 if x >= 0 else 3 rotate_y = 0 if y >= 0 else 2 current_after_y = y_dir target_x = x_dir rotate_x = compute_rotation_cost(current_after_y, target_x) moves_y = (abs(y) + L - 1) // L moves_x = (abs(x) + L - 1) // L case1 = rotate_y + moves_y + rotate_x + moves_x # Case 2: Process X first x_dir_case = 1 if x >= 0 else 3 y_dir_case = 0 if y >= 0 else 2 rotate_x_case = 1 # Rotate from North to East/West (1 step) current_after_x = x_dir_case target_y_case = y_dir_case rotate_y_case = compute_rotation_cost(current_after_x, target_y_case) moves_x_case = (abs(x) + L - 1) // L moves_y_case = (abs(y) + L - 1) // L case2 = rotate_x_case + moves_x_case + rotate_y_case + moves_y_case print(min(case1, case2))