eolymp
bolt
Try our new interface for solving problems
Problems

Numerical spiral

Numerical spiral

Except of addition to finding the sum of digits, Tiger also likes to represent numbers in the form of a square matrix with size \textbf{N}x\textbf{N}. In the matrix are recorded serial numbers starting with \textbf{1}. The filling of the matrix is going clockwise from both directions. The first direction begins from the upper-left corner of the matrix, and the second - from bottom right corner. \includegraphics{https://static.e-olymp.com/content/37/378ea924995a0230f959e045706b28469bca2951.jpg} During the filling of the matrix numbers, Tigre was curious to know what the number is at the intersection of \textbf{I}-th row and \textbf{J}-th column. \InputFile It is given three integers, separated by spaces: \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{10^9}) - the dimension of the matrix and \textbf{I}, \textbf{J} (\textbf{1} ≤ \textbf{I}, \textbf{J} ≤ \textbf{N}) - the line number and column. \OutputFile One number, which is located at the intersection of \textbf{I}-th row and \textbf{J}-th column.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6 4 4
Output example #1
17
Author Ruban Nikolaj