## TLE '16 Contest 4 P2 - Shepherding

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

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.