We’re preparing your current view and syncing the latest data.
Number Spiral
gfgGiven coordinates (x, y) on an infinite two-dimensional grid, the point values are assigned according to a number spiral pattern. The spiral starts at (1, 1) with the value 1 and extends outward in layers, incrementing numbers along the edges. The task is to find the value at position (x, y).
A single line containing two integers x and y (1 ≤ x, y ≤ 10^9).
Output a single integer: the value at coordinates (x, y) in the number spiral.
1 ≤ x, y ≤ 10^9