atcoder#AGC062D. [AGC062D] Walk Around Neighborhood
[AGC062D] Walk Around Neighborhood
Score : points
Problem Statement
Takahashi, with a notepad, is standing at the origin of a two-dimensional plane. His notepad has even numbers written.
Takahashi will perform the following actions times on the plane.
- He chooses and erases one even number written on the notepad. Let be the chosen even number. He then moves to a point exactly distance away in terms of Manhattan distance. More precisely, if Takahashi is currently at the coordinates , he moves to a point such that .
After performing actions, Takahashi must return to the origin .
Determine if it is possible to perform actions in such a way. If it is possible, find the minimum value of , where are the coordinates where Takahashi is located after the -th action (we can prove that this value is an integer).
Constraints
- is even.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is impossible to perform actions as described above, print -1
. If it is possible, print the minimum value of as an integer.
3
2 4 6
4
If Takahashi erases from his notepad for the first to third actions, respectively, and moves as $(0,0)\rightarrow (0,2) \rightarrow (-4,0) \rightarrow (0,0)$, then is , which is the minimum.
5
2 2 2 2 6
3
If Takahashi erases from his notepad for the first to fifth actions, respectively, and moves as $(0,0)\rightarrow (\frac{1}{2},\frac{3}{2})\rightarrow (0,3) \rightarrow (0,-3) \rightarrow (-\frac{1}{2},-\frac{3}{2}) \rightarrow (0,0)$, then is , which is the minimum.
Takahashi can also move to non-grid points.
2
2 200000
-1
Takahashi cannot return to the origin after performing actions as described above.