Stanko is working as an architect in a construction company. His current task is to make a ground plan for a residential building located in Zagreb. He must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be parallel to the building’s sides.

More precisely, the floor is represented in the ground plan as a large rectangle with dimensions $N \times M$, where each apartment is a smaller rectangle with dimensions $a \times b$ located inside of a larger one. The numbers $a$ and $b$ must be integers.

Additionally, the floor must be completely covered with apartments — each point in the floor must be located in an apartment. The apartments must not intersect, but they can touch.

To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its side with the edge of the rectangle representing the floor so it is possible to place a window.

Moreover, all apartments must have the approximately equal area $K$. The deviation of an area of an apartment with dimensions $a \times b$ is defined as $(a \cdot b - K)^2$. The deviation of a ground plan is the sum of all the apartment’s deviations.

Stanko wants to build the best building he can, a building with minimal deviation. Help him and write a program to determine the minimal possible deviation of a ground plan which satisfies the conditions from the task.

Figure 1: A valid arrangement of apartments corresponding to the first example
Figure 2: An invalid arrangement of apartments. The length of apartments’ sides are not integers and there is an apartment without windows.


The first and only line of input contains the integers $N$, $M$, $K$ ($1 \leq N, M \leq 300$, $1 \leq K \leq 10\, 000$).


The first and only line of output must contain the minimal possible deviation of the arrangement of apartments.

Sample Input 1 Sample Output 1
3 3 2
Sample Input 2 Sample Output 2
2 2 2
Sample Input 3 Sample Output 3
2 3 4
CPU Time limit 1 second
Memory limit 1024 MB
Difficulty 6.7hard
Statistics Show
License For educational use only

Please log in to submit a solution to this problem

Log in