Line Sweep

No attempts yetTime limit10sMemory limit256 MB

Problem

You have been coding so much that your room turned dusty. Sweep it before your parents find out.

The room is a grid with NN rows and MM columns. Each cell either holds a piece of furniture or is empty and has to be swept. At least one cell is empty.

You clean with a linear broom. A broom of length XX covers XX consecutive cells of one column. A single sweep means putting the broom down and then pushing it horizontally by any distance, and that distance may be 0. During the whole sweep the broom stays completely inside the room, and all XX cells it covers are empty at every moment. Every cell the broom passes over during the sweep loses its dust.

A longer broom is better, so you buy the longest broom that can still sweep the whole room. The room is completely swept once every empty cell belongs to at least one sweep. After the broom length is fixed, you also want the number of sweeps to be as small as possible.

Input

The first line contains the number of rows NN, the number of columns MM, and the number of pieces of furniture FF (1N20001 \le N \le 2000, 1M20001 \le M \le 2000, 1F<NM1 \le F < NM).

Each of the next FF lines contains the row rr and the column cc of one piece of furniture (1rN1 \le r \le N, 1cM1 \le c \le M). No two pieces of furniture share the same coordinates.

Output

Print the length of the longest broom you can buy on the first line.

Print the minimum number of sweeps needed to sweep every empty cell with that broom on the second line.