Bomb Square

0

0 votes
Problem

We have a two-dimensional grid with H×W squares. There are M targets to destroy in this grid - the position of the i-th target is (hi,wi)

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

1≤H,W≤3×105

1≤M≤min(H×W,3×105)

1≤hi≤H

1≤wi≤W

(hi,wi)≠(hj,wj)(i≠j)

Input

Input is given from Standard Input in the following format:

H W M

h1 w1

hM wM

Output

Print the maximum number of targets that can be destroyed.

 

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

We can destroy all the targets by placing the bomb at (1,2).

Editor Image

?