Under construction

Still being built. Things may change

Stealing Chocolate

Time limit1sMemory limit512 MB

Summary
Starting from an N by M rectangle, repeatedly remove one cell and rearrange the rest into a rectangle whose width-height difference stays within K of the original difference; count the maximum removals, keeping at least one cell.
Level

Medium7 of 10

Topics
Number theory, Math, Brute force, Greedy
Solved
No attempts yet

Problem

Ingyu loves chocolate, and he plans to steal Yeonjin's chocolate one piece at a time. Yeonjin has a chocolate of size N×MN \times M. Ingyu will steal one piece from it, leaving N×M−1N \times M - 1 pieces of chocolate. Stealing a piece changes the shape, so it would reveal that he stole it. Therefore Ingyu will rearrange the remaining chocolate into a rectangle.

The thing to watch is that the difference between the width and height of the new chocolate, D_new\texttt{D}\_{\texttt{new}}, must not differ much from the difference between the width and height of the original chocolate, D_old\texttt{D}\_{\texttt{old}}, or it will be obvious that he stole a piece. So Ingyu will keep ∣D_new−D_old∣|\texttt{D}\_{\texttt{new}} - \texttt{D}\_{\texttt{old}}| at most KK and eat as many pieces as possible.

Consider the figure below as an example.

When K=5K=5, there are 4×4=164 \times 4=16 pieces of chocolate. The original chocolate has equal width and height, so D_old\texttt{D}\_{\texttt{old}} is 00.

If Ingyu eats one piece and rearranges the rest into a 3×53 \times 5 shape, then D_new=∣3−5∣=2≤D_old+K=5\texttt{D}\_{\texttt{new}} = |3 - 5| = 2 \le \texttt{D}\_{\texttt{old}} + K = 5, so he can eat one piece.

If he eats one more piece here, he can rearrange the rest into a 2×72 \times 7 shape. Then D_new=∣2−7∣=5≤D_old+K=5\texttt{D}\_{\texttt{new}} = |2-7| = 5 \le \texttt{D}\_{\texttt{old}} + K = 5, so he can eat one more piece.

If he eats one more piece here, the only possible rearrangement is a 1×131 \times 13 shape. Then D_new=∣1−13∣=12>D_old+K=5\texttt{D}\_{\texttt{new}} = |1-13| = 12 > \texttt{D}\_{\texttt{old}} + K = 5, which does not satisfy the rule, so he cannot eat a third piece.

Here is another example.

When K=4K=4, there are 4×5=204 \times 5 = 20 pieces of chocolate. From the original chocolate, D_old\texttt{D}\_{\texttt{old}} is 11.

If Ingyu eats one piece, he must arrange 1919 pieces into a rectangle, and the smallest ∣D_new−D_old∣|\texttt{D}\_{\texttt{new}} - \texttt{D}\_{\texttt{old}}| is 1818, which is greater than KK, so Ingyu cannot eat any piece. If Ingyu eats 22 pieces and then arranges the rest into a 3×63 \times 6 shape, ∣D_new−D_old∣|\texttt{D}\_{\texttt{new}} - \texttt{D}\_{\texttt{old}}| is 22, which is less than KK, but since he can eat only one piece at a time, he cannot reach that state.

Given N, M, KN,\ M,\ K, find the number of Yeonjin's chocolates that Ingyu can secretly eat.

However, if Ingyu eats all the chocolate, Yeonjin will notice, so at least 11 piece of chocolate must remain.

Input

The first line contains three integers N, M, KN,\ M,\ K separated by spaces. (1≤N, M≤10 0001 \le N,\ M \le 10\,000, 0≤K≤N×M0 \le K \le N \times M)

Output

Print the number of chocolates that Ingyu can secretly eat.

Examples2

  1. Example 1

    Input
    4 4 5
    
    Expected output
    2
    
  2. Example 2

    Input
    4 5 4
    
    Expected output
    0