The pretty little nenuphar
Statement
Goal
Once upon a time, in a quiet and beautiful lake was a pretty little nenuphar.But this pretty little nenuphar is expected to become HHUUUGGEEE !!!
The lake is a grid of dimensions WIDTH and HEIGHT.
The PLN (pretty little nenuphar) is at position X Y in the grid.
At day 0, the PLN occupy 1x1 cell.
Each day, the PLN occupies all surrounding cells.
So, at day 1, the PLN will occupy 9 (3x3) cells. At day 2, the PLN will occupy
25 (5x5) cells and so on.
But the PLN can only grow INTO THE LAKE obviously.
Which number of cells will the PLN occupy after N days ?
Input
3 lines containing 1 or 2 integers separated by spaces.
First line : WIDTH HEIGHT
Second line : X Y
Third line : N
First line : WIDTH HEIGHT
Second line : X Y
Third line : N
Output
One line containing the number of cells occupied by the PLN after N days.
Constraints
1 <= WIDTH <= 1000000000
1 <= HEIGHT <= 1000000000
0 <= X < WIDTH
0 <= Y < HEIGHT
1 <= N <= 1000000000
1 <= HEIGHT <= 1000000000
0 <= X < WIDTH
0 <= Y < HEIGHT
1 <= N <= 1000000000
Example
Input
10 10 4 4 1
Output
9
Game modes
Fastest
Test cases
After one day Test
Input
10 10
4 4
1
Output
9
After one day Validator
Input
10 10
4 4
1
Output
9
After two days Test
Input
10 10
4 4
2
Output
25
After two days Validator
Input
10 10
4 4
2
Output
25
After five days Test
Input
10 10
4 4
5
Output
100
After twelve days Validator
Input
50 50
28 5
12
Output
450
In a corner Test
Input
10 10
7 8
2
Output
20
1K Validator
Input
50 50
12 37
19
Output
1024
Another corner Test
Input
10 10
7 8
3
Output
30
A vertical lake Validator
Input
10 100
7 8
5
Output
88
Same corner but the day after Test
Input
10 10
7 8
4
Output
42
An horizontal lake Validator
Input
100 10
7 8
5
Output
77
What a f... huge lake !!! Test
Input
1000000000 1000000000
894150 24315138
580000000
Output
351043129605851989
What a f... huge lake !!! Validator
Input
1000000000 1000000000
795602854 699837200
500000000
Output
563632392655368800
Solution language
Solution
Stub generator input