Problem
It has been a long holiday and it’s time to hand in your homework!
Your classroom can be viewed as a $N \times M$ grid, with $N$ rows and $M$ seats per row. There are $N \times M$ students.
Student $1$ sit at seat $(1,1)$, student $2$ sit at seat $(1,2)$, so on, and student $M+1$ sit at seat $(2,1)$. Therefore, student $N \cdot M$ sit at seat $(N,M)$.
Here is an example of a $3 \times 4$ classroom:
| 1 | 2 | 3 | 4 |
|---|---|---|---|
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
Student $K$ is the class monitor. Everyone’s homework must be passed to the monitor’s seat. To do this, a student can pass all homework in his hand to one of his four adjacent neighbours (up/down/left/right). This takes $1$ second. The number of homework passed doesn’t affect the time.
Note that many students can pass homework at the same time, and a student can hold more than 1 homework. After several times of passing, finally the monitor receives all the homework.
As the monitor wants to hand in the homework to the teacher as fast as possible, he asks you: What is the minimum time to collect all the homework?
Input
The only line consists of three integers $N, M$ and $K$, denoting the classroom size and the class number of the monitor.
Output
The minimum time for the monitor to collect all the homework.
Subtasks
For all test cases, $1 \le N, M \le 10^9$, $1 \le K \le N \times M$
Subtask $1$ $(9$ pts$)$: $N = 1, M = 2$
Subtask $2$ $(23$ pts$)$: $N = 1$
Subtask $3$ $(29$ pts$)$: $N, M \le 3000$
Subtask $4$ $(39$ pts$)$: No Additional Constraints
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 4 6 | 3 |
Scoring: Per Subtask
Authored by s22f26
Appeared in 2026 Mini Comp 3