Under construction

Still being built. Things may change

Cow Pool

Interview

Time limit1sMemory limit1024 MB

Summary
Find the largest L-shaped pool, counted in gridpoints, that fits in a W by H forest without covering any of the N tree points.
Level

Medium6 of 10

Topics
Prefix sum, Brute force, Matrix
Solved
No attempts yet

Problem

The cows have decided they must have a swimming pool for next summer. They have also chosen a shape: an "L"-shaped pool. The pool will go in a forest near their pastures, and the cows do not want to remove any trees. You are given the size of the forest, W wide by H high, and a set of N tree locations. Find the largest possible pool by area that can be built in the forest.

Here is an example grid and forest with the largest pool:

.  .  *  .  .  .  .      .  .  *  .  .  .  .
*  .  .  .  .  .  .      *  P  P  .  .  .  .
.  .  .  *  *  *  .      .  P  P  *  *  *  .
.  .  .  .  .  .  .      .  P  P  .  .  .  .
*  .  .  *  .  *  .  ->  *  P  P  *  .  *  .
.  .  .  .  .  .  .      .  P  P  P  P  P  .
.  .  .  .  .  .  .      .  P  P  P  P  P  .
*  .  .  .  .  .  *      *  P  P  P  P  P  *
.  .  *  .  *  .  .      .  .  *  .  *  .  .

The largest pool covers 23 gridpoints.

The pool has an "L" shape, formed by combining two rectangles that share the lower left corner. The lower bar of the "L" must be wider than the upper part. The upper part must be taller than the lower bar. The "L" is never rotated or reflected. A simple rectangle is not an "L" shape.

Input

The first line has three integers, W (5 ≤ W ≤ 150), H (5 ≤ H ≤ 150), and N (1 ≤ N ≤ 20000).

Each of the next N lines has two integers, the row and column of a tree. The upper left corner of the tree map is Row 1, Column 1. In the example above, the top row contains a tree at Row 1, Column 3.

Output

Print a single line with the number of gridpoints covered by the largest possible pool.

Examples1

  1. Example 1

    Input
    7 9 12
    1 3
    2 1
    3 4
    3 5
    3 6
    5 1
    5 4
    5 6
    8 1
    8 7
    9 3
    9 5
    
    Expected output
    23