Unfair Poll
Contest: Codeforces Round 392 (Div. 2)
Difficulty rating: 1700
Tags: binary search, constructive algorithms, implementation, math

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

1. the maximum number of questions a particular pupil is asked,
2. the minimum number of questions a particular pupil is asked,
3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input format:
The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output format:
Print three integers:

1. the maximum number of questions a particular pupil is asked,
2. the minimum number of questions a particular pupil is asked,
3. how many times the teacher asked Sergei.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
The order of asking pupils in the first test:

1. the pupil from the first row who seats at the first table, it means it is Sergei;
2. the pupil from the first row who seats at the second table;
3. the pupil from the first row who seats at the third table;
4. the pupil from the first row who seats at the first table, it means it is Sergei;
5. the pupil from the first row who seats at the second table;
6. the pupil from the first row who seats at the third table;
7. the pupil from the first row who seats at the first table, it means it is Sergei;
8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

1. the pupil from the first row who seats at the first table;
2. the pupil from the first row who seats at the second table;
3. the pupil from the second row who seats at the first table;
4. the pupil from the second row who seats at the second table;
5. the pupil from the third row who seats at the first table;
6. the pupil from the third row who seats at the second table;
7. the pupil from the fourth row who seats at the first table;
8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
9. the pupil from the third row who seats at the first table;

Example input:
1 3 8 1 1

Example output:
3 2 3

Example input:
4 2 9 4 2

Example output:
2 1 1

Editorial:
Let's learn to count f(x, y) — the number of questions which were asked to the pupil in the x-th row, at the y-th place in the order.
Note that the process of asking is periodic. During one period children were asked in the following order:
• the pupil from the first row who seats at the first table;
• the pupil from the first row who seats at the second table;
• the pupil from the first row who seats at the ... table;
• the pupil from the first row who seats at the m table;
• the pupil from the second row who seats at the first table;
• the pupil from the second row who seats at the second table;
• the pupil from the second row who seats at the ... table;
• the pupil from the second row who seats at the m table;
• the pupil from the ... row who seats at the ... table;
• the pupil from the n - 1 row who seats at the first table;
• the pupil from n - 1 row who seats at the second table;
• the pupil from the n - 1 row who seats at the ... table;
• the pupil from the n - 1 row who seats at the m table;
• the pupil from the n row who seats at the first table;
• the pupil from the n row who seats at the second table;
• the pupil from the n row who seats at the ... table;
• the pupil from the n row who seats at the m table;
• the pupil from the n - 1 row who seats at the first table;
• the pupil from the n - 1 row who seats at the second table;
• the pupil from the n - 1 row who seats at the ... table;
• the pupil from the n - 1 row who seats at the m table;
• the pupil from the ... row who seats at the ... table;
• the pupil from the second row who seats at the first table;
• the pupil from the second row who seats at the second table;
• the pupil from the second row who seats at the ... table;
• the pupil from the second row who seats at the m table.
Thus, during one period T = n·m + (n - 2)·m pupils who seats at the outer rows will be asked once, others will be asked twice. If n = 1, then T = m.
The number of full periods equals $$\left\lfloor \frac{k}{T} \right\rfloor$$. The remaining questions are k mod T  ≤ T, so we can only make poll on the remaining questions for the O(n·m) or for individual x and y print the formula.
Thus, f(x, y) can be seen as O(n·m) or as O(1).
On what places are people who may be asked more times than the other? Firstly, this is the first row and the first table, because the poll begins from it. Secondly, this is the second row and the first table, because the poll of the central, not outer part of a class at the right side, begins from it. Thirdly, the n - 1 row and the first place because the poll of the central, not outer part of a class at the left side, begins from it.
The maximum number of asked questions to one pupil equals max(f(1, 1), f(2, 1), f(n - 1, 1)).
The minimum number of asked questions to one pupil equals f(n, m), because the pupil who seats on the last row and at the last table will be asked less than others.
Thus, we have decisions with the asymptotic O(n·m) or O(1).