#K82917. Largest Tree-Free Square in a Park

    ID: 36082 Type: Default 1000ms 256MiB

Largest Tree-Free Square in a Park

Largest Tree-Free Square in a Park

You are given a rectangular park of n rows and m columns. In the park, there are k trees located at specific coordinates. Your task is to find the largest square area (with sides parallel to the grid) that does not contain any trees.

Let the park be represented as a grid where each cell can either be empty or contain a tree. Formally, if a cell (i, j) contains a tree, we mark it as 1, otherwise 0. The problem is to find the square subgrid with the maximum side length s such that all cells in this square are 0 (i.e., tree-free), and output the area of this square, which is given by:

[ Area = s^2 ]

If no tree-free cell exists for a square of size at least 1, the answer will be 0.

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains three space-separated integers: n, m, and k, representing the number of rows, the number of columns, and the number of trees in the park respectively.

Each of the following k lines contains two space-separated integers r and c, representing the 0-indexed row and column positions of a tree.

It is guaranteed that 1 ≤ n, m ≤ 1000, 0 ≤ k ≤ n*m, and 0 ≤ r < n, 0 ≤ c < m.

outputFormat

Output a single integer to standard output (stdout) representing the area of the largest square in the park that does not contain any trees. If no such square exists, output 0.## sample

4 5 5
0 0
0 2
1 2
2 2
3 4
4

</p>