Rectangles 2
Time limit2sMemory limit512 MB
Count axis-aligned rectangles with vertices on grid points of an n x m grid whose perimeter is at least p.
- Level
Medium5 of 10
- Topics
- Math, Combinatorics, Prefix sum, Implementation
- Solved
- No attempts yet
Problem

In the grid shown above, the rectangles whose vertices all lie on grid points and whose sides are vertical or horizontal are: six , four , three , two , two , and one , for a total of 18. A grid point is the intersection of a vertical line and a horizontal line.
You are given a grid of size . Count how many rectangles have all four vertices on grid points, have vertical or horizontal sides, and have perimeter at least . A rectangle of size has perimeter .
Input
The first and only line of standard input contains three integers , , and separated by spaces (, ). Here and are the dimensions of the grid, and is the lower bound on the rectangle perimeter.
Output
On the first line of standard output, print a single integer: the number of rectangles in the grid whose vertices lie on grid points, whose sides are vertical or horizontal, and whose perimeter is at least .