You are shepherding near ancient Bethlehem when you hear that Jesus is born! Unfortunately, you are the last of your fellow shepherds to go and the sheep that the shepherds are supposed to watch are still scattered around the field.
The field can be represented as an meters by meters grid where each square in the grid represents m2 of grass. You have to herd the sheep into an area as small as possible, but each sheep needs to remain in the field and needs an entire square for itself. Afterward, you will erect a temporary fence around the sheep along the grid lines. What is the minimum length of fence, in meters, required?
Input Specification
The first line of input will contain two space separated integers, and .
The second line of input will contain a single integer, .
For 20% of the points, .
For another 20% of the points, .
For another 30% of the points, .
Note: It is recommended to use 64-bit integers to compute the solution (long long
in C++, long
in Java, int64
in Pascal).
Output Specification
Output a single integer, the minimum length of fence, in meters, required to surround the sheep.
Sample Input
5 5
14
Sample Output
16
Explanation for Sample Output
You can herd the sheep like this, where .
represents an empty square and *
represents a square with one sheep:
****.
****.
***..
***..
.....
This requires meters of fencing.
Comments
nvm
This is the amount of fencing needed to surround the sheep. The fence starts at the top edge and goes counter-clockwise.