We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).
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 \leq H, W \leq 3 \times 10^5
 - 1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)
 - 1 \leq h_i \leq H
 - 1 \leq w_i \leq W
 - \left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

-----Input-----
Input is given from Standard Input in the following format:
H W M
h_1 w_1
\vdots
h_M w_M

-----Output-----
Print the answer.

-----Sample Input-----
2 3 3
2 2
1 1
1 3

-----Sample Output-----
3

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

Difficulty: interview

Starter code:

Solutions:
import numpy as np
h, w, m = map(int, input().split())
xy = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
row = np.zeros(h, np.int)
col = np.zeros(w, np.int)
for y, x in xy:
	row[y] += 1
	col[x] += 1

max_cnt_y = max(row)
max_cnt_x = max(col)
max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x)
for y, x in xy:
	if row[y] == max_cnt_y and col[x] == max_cnt_x:
		max_pair -= 1

print(max_cnt_y + max_cnt_x - (max_pair == 0))

#!/usr/bin/env python3
import sys
import numpy as np

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return list(map(int, input().split()))


H, W, M = MI()

R = np.zeros(H + 1)
C = np.zeros(W + 1)
bombs = []
for _ in range(M):
    h, w = MI()
    bombs.append((h, w))
    R[h] += 1
    C[w] += 1

R_max = [R == max(R)]
ans = max(R) + max(C)
C_max = [C == max(C)]

cnt = 0
for h, w in bombs:
    if R_max[0][h] and C_max[0][w]:
        cnt += 1

if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max):
    print((int(ans - 1)))
else:
    print((int(ans)))


h,w,m=map(int,input().split())
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
    x,y=item[i]
    row[x-1]+=1
    col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
    r,c=item[i]
    if r-1 in xr and c-1 in xc:
        check-=1
print(mr+mc if check>0 else mr+mc-1)

H,W,M = map(int ,input().split())
width = [0]*W
height = [0]*H

st = set()
for i in range(M):
  y,x = map(int, input().split())
  st.add((x-1,y-1))
  width[x-1] += 1
  height[y-1] += 1

maxW = max(width)
maxH = max(height)

indexW = [i for i, v in enumerate(width) if v == maxW]
indexH = [i for i, v in enumerate(height) if v == maxH]

ans = maxW + maxH

tempX = indexW[0]
tempY = indexH[0]

flag = False

for x in indexW:
  y = tempY
  if not (x,y) in st:
    flag = True
    break

for y in indexH:
  x = tempX
  if not(x,y) in st:
    flag = True
    break

if flag:
  print(ans)
else:
  print(ans-1)



H,W,M = map(int,input().split())

Hmax_temp = [0]*(H+1)
Wmax_temp = [0]*(W+1)
Hmax = 0
Wmax = 0
Bomb = dict()
for i in range(M):
	H_M,W_M = map(int,input().split())
	Hmax_temp[H_M] += 1
	Wmax_temp[W_M] += 1
	Bomb[(H_M,W_M)] = 1

Hmax = max(Hmax_temp)
Wmax = max(Wmax_temp)

#H方向の走査
y_max = []
for i in range(H+1):
	if Hmax == Hmax_temp[i]:
		y_max.append(i)
		
#W方向の走査
x_max = []
for j in range(W+1):
	if Wmax == Wmax_temp[j]:
		x_max.append(j)

#爆弾設置位置に対象が存在するか？
flag = False
for i in y_max:
	for  j in x_max:
		if (i,j) not in Bomb:
			flag = True
			break
	if flag:
		break

#答えのセット
if flag:
	ans = Wmax + Hmax
else:
	ans = Wmax + Hmax - 1
print(ans)

H,W,M = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

hlist = [0]*(H+1)
wlist = [0]*(W+1)
for l in L:
    hlist[l[0]] += 1
    wlist[l[1]] += 1

hmax = max(hlist)
wmax = max(wlist)
h = hlist.count(hmax)
w = wlist.count(wmax)
ans = hmax+wmax-1
cnt = 0
for l in L:
    if hlist[l[0]] == hmax and wlist[l[1]] == wmax:
        cnt += 1

if cnt < h*w:
    ans += 1
print(ans)

from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_locations = set()
    for _ in range(target_count):
        h, w = [int(x) - 1 for x in input().split()]
        count_by_height[h] += 1
        count_by_width[w] += 1
        bomb_locations.add((h, w))
    max_h = max(v for v in list(count_by_height.values()))
    max_w = max(v for v in list(count_by_width.values()))
    max_h_rows = [i for i, x in list(count_by_height.items()) if x == max_h]
    max_w_columns = [i for i, x in list(count_by_width.items()) if x == max_w]
    all_crossing_bomb = all((h, w) in bomb_locations
                            for h in max_h_rows for w in max_w_columns)
    return max_h + max_w - all_crossing_bomb


def __starting_point():
    print((main()))

__starting_point()

H,W,M = map(int,input().split())

hs = [0] * H
ws = [0] * W
s = set()
for i in range(M):
  h,w = map(int, input().split())
  hs[h-1] += 1
  ws[w-1] += 1
  s.add((h-1,w-1))
  
mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)

ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    return
ans -= 1
print(ans)

from collections import defaultdict

H, W, M = list(map(int, input().split()))

row_bom_cnt = defaultdict(int)
col_bom_cnt = defaultdict(int)
row_max = 0
col_max = 0

boms = [list(map(int, input().split())) for _ in range(M)]

for rm, cm in boms:
    row_bom_cnt[rm] += 1
    col_bom_cnt[cm] += 1

    row_max = max(row_max, row_bom_cnt[rm])
    col_max = max(col_max, col_bom_cnt[cm])


target_row = set()
for r, val in list(row_bom_cnt.items()):
    if val == row_max:
        target_row.add(r)

target_col = set()
for c, val in list(col_bom_cnt.items()):
    if val == col_max:
        target_col.add(c)


cnt = 0
for rm, cm in boms:
    if rm in target_row and cm in target_col:
        cnt += 1

if len(target_row) * len(target_col) == cnt:
    print((row_max + col_max - 1))
else:
    print((row_max + col_max))


h, w, m = list(map(int, input().split()))
yx = [tuple([int(x) - 1 for x in input().split()]) for _ in range(m)]
ch = [0] * h
cw = [0] * w

for y, x in yx:
    ch[y] += 1
    cw[x] += 1

ax = max(cw)
ay = max(ch)

nx = 0
ny = 0
for i in range(h):
    ny += ch[i] == ay
for i in range(w):
    nx += cw[i] == ax
can = ny * nx  # 最大値をとる選び方の数
for y, x in yx:
    if ch[y] == ay and cw[x] == ax:
        can -= 1
print((ay + ax - (can == 0)))


H, W, M = map(int,input().split())
row = [0]*H
col = [0]*W
target = set()
for i in range(M):
    h,w = map(int,input().split())
    row[h-1] += 1
    col[w-1] += 1
    target.add((h-1,w-1))
ans = -1
for h,w in target:
    ans = max(ans, row[h]+col[w]-1)
A = max(row)
B = max(col)
a = [x for x in range(H) if row[x] == A]
b = [x for x in range(W) if col[x] == B]
cnt = 0
for i in a:
    for j in b:
        cnt += 1
        if (i,j) not in target:
            print(A+B)
            return
        if cnt > M:
            print(A+B-1)
            return
print(A+B-1)

from collections import defaultdict
def solve():
  H, W, M = list(map(int, input().split()))
  bomb = defaultdict(lambda: 0)
  lis_h = [0]*H
  lis_w = [0]*W
  for _ in range(M):
    h,w = list(map(int, input().split()))
    h -= 1
    w -= 1
    bomb[(h,w)] = 1
    lis_h[h] += 1
    lis_w[w] += 1
  m_h = max(lis_h)
  m_w = max(lis_w)
  m_h_lis = []
  m_w_lis = []
  for i in range(H):
    if lis_h[i]==m_h:
      m_h_lis.append(i)
  for i in range(W):
    if lis_w[i]==m_w:
      m_w_lis.append(i)
  ans = 0
  for h in m_h_lis:
    for w in m_w_lis:
      if bomb[(h,w)]==0:
        return m_h+m_w
  return m_h+m_w-1
print((solve()))


h,w,m = map(int,input().split())
t = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(m)] 
ht = [0]*h
wt = [0]*w
for y,x in t:
  ht[y] += 1
  wt[x] += 1
htm = max(ht)
wtm = max(wt)
htt = [i for i in range(h) if ht[i]==htm]
wtt = [i for i in range(w) if wt[i]==wtm]
ans = htm+wtm-1
t = set(t)
for i in htt:
  for j in wtt:
    if (i,j) not in t:
      print(htm+wtm)
      return
print(htm+wtm-1)

import sys
input = sys.stdin.readline
h,w,m = map(int,input().rstrip().split())
hw = [list(map(int,input().rstrip().split()))for _ in range(m)]

tate = [0]*(h+1)
yoko = [0]*(w+1)
bombpoint = set()

for x,y in hw:
    tate[x] += 1
    yoko[y] += 1
    bombpoint.add((x,y))

ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
    if tate[i] == x_max:
        ans_x.append(i)
for i in range(len(yoko)):
    if yoko[i] == y_max:
        ans_y.append(i)

ans = x_max + y_max
for x in ans_x:
    for y in ans_y:
        if (x,y) not in bombpoint:
            print(ans)
            return
print(ans - 1)

import sys
import numpy as np
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    h, w, m = MII()
    bombs = [MIIZ() for _ in range(m)]
    a = [0]*h
    b = [0]*w
    for y,x in bombs:
        a[y] += 1
        b[x] += 1
    maxa = max(a)
    maxb = max(b)
    sumv = maxa + maxb
    c = a.count(maxa)*b.count(maxb) - sum(a[y]+b[x] == sumv for y,x in bombs)
    print(sumv - (c<=0))

def __starting_point():
    main()
__starting_point()

h, w, m = list(map(int, input().split()))
a_list = []
b_list = []
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = list(map(int, input().split()))
    a_list.append([a,b])
    h_list[a - 1] += 1
    w_list[b - 1] += 1
h_max = max(h_list)
w_max = max(w_list)
w_flag = [0 for _ in range(w)]
for i in range(w):
    if w_list[i] == w_max:
        w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
    if h_list[i] == h_max:
        h_flag[i] = 1
flag = 0   
for i in range(m):
    if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1:
        flag += 1
s = sum(h_flag) * sum(w_flag)
print((h_max + w_max - 1 if flag == s else h_max + w_max))        


h,w,m = map(int,input().split())
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = map(int,input().split())
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
rcnt,ccnt = 0,0
for v in row:
  if v==r:
    rcnt += 1
for v in col:
  if v==c:
    ccnt += 1
doubled = 0
for i,j in bombs:
  if row[i]==r and col[j]==c:
    doubled += 1
if doubled==rcnt*ccnt:
  print(r+c-1)
else:
  print(r+c)

import collections

h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]

otherwisey = []
otherwisex = []
for i in range(m):
    if X[i] != most_common_x_index:
        otherwisey.append(Y[i])
    if Y[i] != most_common_y_index:
        otherwisex.append(X[i])

most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
    ansx = most_common_y[0][1] + most_common_x_count
else:
    ansx = most_common_x_count

most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0 :
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count

print(max(ansx,ansy))

import sys
sys.setrecursionlimit(10**6)

h, w, m = list(map(int, input().split()))

# 各行各列に何個ずつあるか
hs = [0] * h
ws = [0] * w
# 座標を記録
s = set()

readline = sys.stdin.readline
for _ in range(m):
    r, c = [int(i) for i in readline().split()]
    r -= 1
    c -= 1
    hs[r] += 1
    ws[c] += 1
    s.add((r, c))

# 最大値
mh = 0
mw = 0
for i in range(h):
    mh = max(mh, hs[i])
for j in range(w):
    mw = max(mw, ws[j])

# 最大値をとっている行・列
si = []
sj = []
for i in range(h):
    if mh == hs[i]:
        si.append(i)
for j in range(w):
    if mw == ws[j]:
        sj.append(j)

# 爆破対象がないマスに爆弾を設置できれば尚良し。そこでmh+mwをansに仮に記録して、１個でも見つかればその座標を出力。見つからなければ、爆破対象があるマスに爆弾を設置するのが最大となるので、ans=mh+mw-1となる
ans = mh + mw
for i in si:
    for j in sj:
        if (i, j) in s:
            continue
        print(ans)
        return
print((ans-1))


from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.readline

h, w, m = list(map(int, input().split()))
bombs = [tuple(map(int, input().split())) for _ in range(m)]

x_cnt = defaultdict(int)
y_cnt = defaultdict(int)
for x, y in bombs:
    x_cnt[x] += 1
    y_cnt[y] += 1

x_cnt_max = max(x_cnt.values())
y_cnt_max = max(y_cnt.values())
cnt = cnt_x = cnt_y = 0
for x, y in bombs:
    if x_cnt[x] == x_cnt_max and y_cnt[y] == y_cnt_max:
        cnt += 1

cnt_x = sum(v == x_cnt_max for v in list(x_cnt.values()))
cnt_y = sum(v == y_cnt_max for v in list(y_cnt.values()))
if cnt_x * cnt_y == cnt:
    ans = x_cnt_max + y_cnt_max - 1
else:
    ans = x_cnt_max + y_cnt_max

# print(cnt_x, cnt_y, cnt)
print(ans)


h,w,m=map(int,input().split())

st=set()
h_b=[0 for i in range(h)]
w_b=[0 for i in range(w)]
for i in range(m):
  th,tw=map(int,input().split())
  th-=1
  tw-=1
  st.add((th,tw))
  h_b[th]+=1
  w_b[tw]+=1

h_max=max(h_b)
w_max=max(w_b)

h_cand=[i for i in range(h) if h_b[i]==h_max]
w_cand=[i for i in range(w) if w_b[i]==w_max]

for i in h_cand:
  for j in w_cand:
    if (i,j) not in st:
      print(h_max+w_max)
      return

print(h_max+w_max-1)

#https://atcoder.jp/contests/abc176/submissions/16118386
import collections
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
H,W,M=map(int,input().split())
A=list()
B=list()
for i in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
c = collections.Counter(A)
s=c.most_common()
k=s[0][0]
t=s[0][1]
L=list()
for i in range(M):
  if A[i]!=k:
    L.append(B[i])
c = collections.Counter(L)
s=c.most_common()
if len(s)!=0:
  ans=s[0][1]+t
else:
  ans=t
c = collections.Counter(B)
s=c.most_common()
k=s[0][0]
t=s[0][1]
L=list()
for i in range(M):
  if B[i]!=k:
    L.append(A[i])
c = collections.Counter(L)
s=c.most_common()
if len(s)!=0:
  q=s[0][1]+t
else:
  q=t
ans=max(ans,q)
print(ans)

h, w, m = list(map(int, input().split()))
r = [0] * (h+1)
c = [0] * (w+1)
bomb = []
for _ in range(m):
    hi, wi = list(map(int, input().split()))
    r[hi] += 1
    c[wi] += 1
    bomb.append([hi, wi])

hmax = max(r)
wmax = max(c)

cnt = 0
ret = 1
for i in range(1, h+1):
    if r[i] == hmax:
        cnt += 1
ret *= cnt

cnt = 0
for i in range(1, w+1):
    if c[i] == wmax:
        cnt += 1

ret *= cnt

for i in range(m):
    hi, wi = bomb[i]
    if r[hi] == hmax and c[wi] == wmax:
        ret -= 1

if ret == 0:
    print((hmax + wmax - 1))
else:
    print((hmax + wmax))


h, w, m = list(map(int, input().split()))
ms = []
hs = [0 for i in range(h)]
ws = [0 for i in range(w)]

for i in range(m):
    hi, wi = list(map(int, input().split()))
    ms.append((hi - 1, wi - 1))
    hs[hi - 1] += 1
    ws[wi - 1] += 1

maxh = max(hs)
maxw = max(ws)
cnt_h = sum([hs[i] == maxh for i in range(h)])
cnt_w = sum([ws[i] == maxw for i in range(w)])
cnt = cnt_h * cnt_w

for x, y in ms:
    if hs[x] == maxh and ws[y] == maxw:
        cnt -= 1

if cnt <= 0:
    print(maxh + maxw - 1)
else:
    print(maxh + maxw)

H,W,M=list(map(int,input().split()))
row=[0]*H
col=[0]*W
target=set()
for i in range(M):
    h,w=list(map(int,input().split()))
    row[h-1]+=1
    col[w-1]+=1
    target.add((h-1,w-1))
A=max(row)
B=max(col)
a=[x for x in range(H) if row[x]==A]
b=[x for x in range(W) if col[x]==B]
for i in a:
    for j in b:
        if (i,j) not in target:
            print((A+B))
            return
print((A+B-1))


def main():
    h,w,m=map(int,input().split())
    row=[0]*(h+1)
    col=[0]*(w+1)
    d=set({})
    for _ in range(m):
        a,b=map(int,input().split())
        row[a]+=1
        col[b]+=1
        d.add((a,b))

    max_row=max(row)
    max_col=max(col)
    max_row_d=set({})
    max_col_d=set({})
    for i in range(1,h+1):
        if row[i]==max_row:
            max_row_d.add(i)
    for i in range(1,w+1):
        if col[i]==max_col:
            max_col_d.add(i)

    sm=max_row+max_col
    for i in max_row_d:
        for j in max_col_d:
            if (i,j) in d : continue
            break
        else : continue
        break
    else : sm-=1

    print(sm)    

main()

from collections import Counter


H, W, M, *hw = map(int, open(0).read().split())
h_cnt = Counter(hw[::2])
w_cnt = Counter(hw[1::2])
h_max = h_cnt.most_common(1)[0][1]
w_max = w_cnt.most_common(1)[0][1]

not_on_bomb = sum(1 for k, v in h_cnt.items() if v == h_max)
not_on_bomb *= sum(1 for k, v in w_cnt.items() if v == w_max)
for h, w in zip(*[iter(hw)] * 2):
    if h_cnt[h] == h_max and w_cnt[w] == w_max:
        not_on_bomb -= 1

ans = h_max + w_max
print(ans) if not_on_bomb else print(ans - 1)


from collections import defaultdict

H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]

d1 = defaultdict(int)
d2 = defaultdict(int)

b = defaultdict(int)

for h, w in hw:
    d1[h] += 1
    d2[w] += 1
    b[(h, w)] = 1

m1 = max(d1.values())
m2 = max(d2.values())

e1 = [k for k in d1.keys() if d1[k] == m1]
e2 = [k for k in d2.keys() if d2[k] == m2]

flag = True

for x in e1:
    for y in e2:
        if b[(x, y)] == 1:
            pass
        else:
            flag = False
            break
    if not flag:
        break

if flag:
    print(m1+m2-1)
else:
    print(m1+m2)

H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
    h[l[i][0]-1]+=1
    w[l[i][1]-1]+=1
maxh=max(h)
maxw=max(w)
hlist=[]
wlist=[]
for i in range(H):
    if h[i]==maxh:
        hlist.append(i)
for i in range(W):
    if w[i]==maxw:
        wlist.append(i)
c=0
for i in range(M):
  if h[l[i][0]-1]==maxh and w[l[i][1]-1]==maxw:
    c+=1
if len(hlist)*len(wlist)==c:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

H, W, M = map(int, input().split())
 
hs = [0] * H
ws = [0] * W
boms = set()
 
for i in range(M):
    r,c = map(int, input().split())
    r -= 1
    c -= 1
 
    hs[r] += 1
    ws[c] += 1
    boms.add((r, c))
mh, mw = 0, 0
for i in range(H):
    mh = max(mh, hs[i])
for j in range(W):
    mw = max(mw, ws[j])
max_h_list = []
max_w_list = []
    
for i in range(H):
    if hs[i] == mh: max_h_list.append(i)    
for j in range(W):
    if ws[j] == mw: max_w_list.append(j)
ans = mh + mw
 
for i in max_h_list:
    for j in max_w_list:
        if (i,j) not in boms:
            print(ans)
            return
print(ans-1) 

import numpy as np

def solve(H, W, M, h, w):
    f = [0] * (H+1)
    g = [0] * (W+1)
    for r, c in zip(h, w):
        f[r] += 1
        g[c] += 1
    p = np.max(f)
    q = np.max(g)
    num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g)))
    for r, c in zip(h, w):
        if (f[r] == p) and (g[c] == q):
            num -= 1
    return p + q - (num <= 0)

H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w))

import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
    h, w, m = map(int,input().split()) 
    h_lis = [0] * (h+1)
    w_lis = [0] * (w+1)
    bombs = set([tuple(map(int,input().split())) for i in range(m)])
    for hh, ww in bombs:
        h_lis[hh] += 1
        w_lis[ww] += 1
    max_h = max(h_lis)
    max_w = max(w_lis)
    h_max_index = [i for i, h in enumerate(h_lis) if h == max_h]
    w_max_index = [i for i, w in enumerate(w_lis) if w == max_w]
    for h_i in h_max_index:
        for w_i in w_max_index:
            if not (h_i, w_i) in bombs:
                print(h_lis[h_i] + w_lis[w_i])
                return
    else:
        print(h_lis[h_i] + w_lis[w_i] - 1)

def __starting_point():
    main()
__starting_point()

H,W,M = map(int, input().split())

hs = [0] * H
ws = [0] * W
s = set()

for i in range(M):
  h,w = map(int, input().split())
  h -= 1
  w -= 1
  hs[h] += 1
  ws[w] += 1
  s.add((h,w))

mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])
  
l_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    l_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
    
ans = mh+mw
for i in l_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    return
ans -= 1
print(ans)

h,w,n=map(int,input().split())
H=[0]*h
W=[0]*w
L=[(0,0)]*n
for i in range(n):
    a,b=map(int,input().split())
    L[i]=(a,b)
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
ans=h_max+w_max
cnt=0
for l in L:
    if H[l[0]-1]==h_max and W[l[1]-1]==w_max:
        cnt+=1
if H.count(h_max)*W.count(w_max)==cnt:
    ans-=1
print(ans)

import numpy as np
from collections import defaultdict

h, w, m = map(int, input().split())

rowsum = np.zeros(h, dtype=int)
colsum = np.zeros(w, dtype=int)
targets = defaultdict(int)
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    rowsum[hi] += 1
    colsum[wi] += 1
    targets[(hi, wi)] = 1

rowmax = np.max(rowsum)
colmax = np.max(colsum)
rowindices = np.where(rowsum == rowmax)[0]
colindices = np.where(colsum == colmax)[0]

for ri in rowindices:
    for ci in colindices:
        if targets[(ri, ci)]:
            continue
        print(rowmax + colmax)
        return

print(rowmax + colmax - 1)


import sys
from collections import Counter

H, W, M = map(int, sys.stdin.readline().rstrip().split())#行数H、列数W、爆弾数M
hcnt = [0] * H#何行目に何個あるか
wcnt = [0] * W#何列目に何個あるか
bomb = []

for i in range(M):
    bh,bw=map(int,sys.stdin.readline().rstrip().split())
    hcnt[bh - 1] += 1#行方向
    wcnt[bw - 1] += 1#列方向
    bomb.append((bh - 1,bw - 1))
#hcnt [2,1]
#wcnt[1,1,1]
#bomb[[1,1],[0,0],[0,2]]
hmax = max(hcnt)#2
wmax = max(wcnt)#1

crs = 0#hmax and wmax crosspoint
for (i, j) in bomb:
    if hcnt[i] == hmax and wcnt[j] == wmax:
        crs += 1
#all crosspoint has bomb
if crs == Counter(hcnt)[hmax] * Counter(wcnt)[wmax]:
    print(hmax + wmax - 1)
#more than one crosspoint has no bomb
else:
    print(hmax + wmax)

import itertools
H,W,N=[int(s) for s in input().split()]
hls=[0 for _ in range(H+1)]
wls=[0 for _ in range(W+1)]
bombs=[set() for _ in range(H+1)]
for _ in range(N):
  h,w=[int(s) for s in input().split()]
  hls[h]+=1
  wls[w]+=1
  bombs[h].add(w)
hmax=max(hls)
wmax=max(wls)
hmaxls=[i for i in range(H+1) if hls[i]==hmax]
wmaxls=[i for i in range(W+1) if wls[i]==wmax]
for h,w in itertools.product(hmaxls,wmaxls):
  if not(w in bombs[h]):
    print(hmax+wmax)
    return
else:
  print(hmax+wmax-1)

from collections import Counter

H, W, M = list(map(int, input().split()))
dh, dw = Counter(), Counter()
used = set()

for _ in range(M):
    h, w = list(map(int, input().split()))
    dh[h] += 1
    dw[w] += 1
    used.add((h, w))

ih = dh.most_common()
iw = dw.most_common()
s = ih[0][1] + iw[0][1]
ans = 0

for h, sh in ih:
    for w, sw in iw:
        if sh+sw < s or ans == s:
            break
        b = sh + sw - ((h, w) in used)
        ans = max(ans, b)
print(ans)


import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, M = list(map(int, input().split()))
    bomb = [list([int(x) - 1 for x in input().split()]) for _ in range(M)]
    R = [0] * H
    C = [0] * W

    for h, w in bomb:
        R[h] += 1
        C[w] += 1

    cnt_r = 0
    ma_r = max(R)
    for r in R:
        if r == ma_r:
            cnt_r += 1

    cnt_c = 0
    ma_c = max(C)
    for c in C:
        if c == ma_c:
            cnt_c += 1

    ma = ma_r + ma_c
    cnt_rc = cnt_r * cnt_c
    for h, w in bomb:
        score = R[h] + C[w]
        if score == ma:
            cnt_rc -= 1

    res = ma if cnt_rc else ma - 1
    print(res)


def __starting_point():
    resolve()

__starting_point()

import sys


H, W, M = map(int, input().split())
bomb =[]
for I in range(M):
    bom = tuple(map(lambda x: int(x) - 1, input().split()))
    bomb.append(bom)
X = [0] * H  # X:各行の爆破対象の個数
Y = [0] * W  # Y:各列の爆破対象の個数
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, 
            # 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
            print(maxX + maxY)
            return
print(maxX + maxY - 1)

H,W,M=map(int,input().split())
h=[0]*(H+1)
w=[0]*(W+1)
hw=[0]*M
for i in range(M):
  y,x=map(int,input().split())
  hw[i]=(y,x)
  h[y]+=1
  w[x]+=1
cnt=0
mxh=max(h)
mxw=max(w)
for hi,wi in hw:
  if h[hi]==mxh and w[wi]==mxw:
    cnt+=1
if h.count(mxh)*w.count(mxw)==cnt:
  print(mxh+mxw-1)
else:
  print(mxh+mxw)

from collections import Counter
h, w, m = list(map(int, input().split()))
blist = [list(map(int, input().split())) for _ in range(m)]

blist_set = set(map(tuple, blist))

rowdict = Counter([blist[i][0] for i in range(m)])
coldict = Counter([blist[i][1] for i in range(m)])

maxr = rowdict.most_common()[0][1]
maxr_keys = []
for i in rowdict.most_common():
    if i[1] == maxr:
        maxr_keys.append(i[0])
    else:
        break
maxc = coldict.most_common()[0][1]
maxc_keys = []
for i in coldict.most_common():
    if i[1] == maxc:
        maxc_keys.append(i[0])
    else:
        break

for i in maxr_keys:
    for j in maxc_keys:
        if (i, j) not in blist_set:
            print((maxr + maxc))
            break
    else:
        continue
    break
else:
    print((maxr + maxc - 1))


import sys
input = sys.stdin.readline
from collections import Counter, defaultdict


def read():
    H, W, M = list(map(int, input().strip().split()))
    HW = []
    for i in range(M):
        h, w = list(map(int, input().strip().split()))
        HW.append((h, w))
    return H, W, M, HW


def solve(H, W, M, HW):
    hcount = Counter()
    wcount = Counter()
    for h, w in HW:
        hcount[h] += 1
        wcount[w] += 1
    hm = hcount.most_common()
    wm = wcount.most_common()
    hmax = hm[0][1]
    wmax = wm[0][1]
    hn = len([1 for k, v in list(hcount.items()) if v == hmax])
    wn = len([1 for k, v in list(wcount.items()) if v == wmax])
    m = hn * wn
    for h, w in HW:
        if hcount[h] == hmax and wcount[w] == wmax:
            m -= 1
    if m == 0:
        return hmax + wmax - 1
    return hmax + wmax


def __starting_point():
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print(("%s" % str(outputs)))

__starting_point()

H,W,M = map(int, input().split())

hs = [0] * H
ws = [0] * W
s = set()

for i in range(M):
  h,w = map(int, input().split())
  h -= 1
  w -= 1
  hs[h] += 1
  ws[w] += 1
  s.add((h,w))

mh = 0
mw = 0
for i in range(H):
  mh = max(mh,hs[i])
for j in range(W):
  mw = max(mw,ws[j])
i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    return
ans -= 1
print(ans)


H, W, M = list(map(int, input().split()))

h = [0] * H
w = [0] * W

hw = {}

for _ in range(M):
    a, b = list(map(int, input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    temp = "x" + str(a - 1) + "y" + str(b - 1)
    hw[temp] = 1

hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        temp = "x" + str(x) + "y" + str(y)
        if temp not in hw:
            print((hm + wm))
            return
else:
    print((hm + wm - 1))



import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H  # X:各行の爆破対象の個数
Y = [0] * W  # Y:各列の爆破対象の個数
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, 
            # 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
            print(maxX + maxY)
            return
print(maxX + maxY - 1)

H, W, M = list(map(int, input().split()))
bombs = set([tuple(map(int, input().split())) for _ in range(M)])

cntH = [0] * (H + 1)
cntW = [0] * (W + 1)
for h, w in bombs:
    cntH[h] += 1
    cntW[w] += 1

mxH = max(cntH)
mxW = max(cntW)

ans = mxH + mxW - 1

mxH = [h for h in range(1, H + 1) if cntH[h] == mxH]
mxW = [w for w in range(1, W + 1) if cntW[w] == mxW]

for h in mxH:
    for w in mxW:
        if not (h, w) in bombs:
            ans += 1
            print(ans)
            return
print(ans)


from collections import defaultdict,Counter

h,w,m = map(int,input().split())

w_list = []
h_list = []

se = set()

for _ in range(m):
    nh,nw = map(int,input().split())

    se.add((nh,nw))
    w_list.append(nw)
    h_list.append(nh)

w_count = Counter(w_list)
h_count = Counter(h_list)

max_w = 0
max_h = 0

ch = []
cw = []

for i in w_count.values():
    max_w = max(max_w,i)
    cw.append(i)

for i in h_count.values():
    max_h = max(max_h,i)
    ch.append(i)

ma = ch.count(max_h)*cw.count(max_w)

result = max_h+max_w
point = 0

for i,j in se:
    if w_count[j] == max_w and h_count[i] == max_h:
        point += 1

if point == ma:
    print(result-1)
else:
    print(result)

import sys
from collections import Counter
 
 
def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))
 
    nh = max(Mh)
    nw = max(Mw)
 
    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]
 
    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1
 
    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)
 
 
main()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W, M = list(map(int, input().split()))

    row = [0] * H
    col = [0] * W
    bomb = set()

    for i in range(M):
        h, w = list(map(int, input().split()))
        h -= 1
        w -= 1
        row[h] += 1
        col[w] += 1
        bomb.add((h, w))

    # print(row, col, bomb)

    rowmax = max(row)
    colmax = max(col)

    rows = []
    cols = []
    for i in range(H):
        if row[i] == rowmax:
            rows.append(i)
    for i in range(W):
        if col[i] == colmax:
            cols.append(i)

    for r in rows:
        for c in cols:
            if (r, c) in bomb:
                continue
            else:
                print((rowmax + colmax))
                return

    print((rowmax + colmax - 1))


def __starting_point():
    main()

__starting_point()

# import numpy as np

H, W, M = list(map(int, input().split()))
#map_ = np.zeros((H, W), dtype=np.bool)

h_sum = [0] * H
w_sum = [0] * W
point_list = set()

for _ in range(M):
    h, w = list(map(int, input().split()))
    # map_[h-1, w-1] = 1
    point_list.add((h-1, w-1))
    h_sum[h-1] += 1
    w_sum[w-1] += 1

h_max = max(h_sum)
w_max = max(w_sum)

h_argmax = set()
w_argmax = set()

for i, h in enumerate(h_sum):
    if h == h_max:
        h_argmax.add(i) 

for i, w in enumerate(w_sum):
    if w == w_max:
        w_argmax.add(i)

ans = h_max + w_max

for h in h_argmax:
    for w in w_argmax:
        if (h, w) not in point_list:
        # if map_[h, w] == 0:
            print(ans)
            return
print((ans - 1))


import sys

def solve():
    readline = sys.stdin.readline
    H, W, M = map(int, readline().split())
    h = [0] * H
    w = [0] * W
    b = set()
    for _ in range(M):
        y, x = map(int, readline().split())
        x -= 1
        y -= 1
        h[y] += 1
        w[x] += 1
        b.add(y*W+x)
    h = sorted(zip(h, range(H)), reverse=True)
    ans = 0
    for i in range(W):
        x = w[i]
        for y, j in h:
            if x+y > ans:
                if j*W+i in b:
                    ans = x+y-1
                else:
                    ans = x+y
                    break
            else:
                break
    print(ans)

def __starting_point():
    solve()
__starting_point()

H, W, M = list(map(int, input().split()))

sumh = [0] * W
sumw = [0] * H
checkset = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    checkset.add((h-1, w-1))
    sumh[w-1] += 1
    sumw[h-1] += 1
shmax = max(sumh)
swmax = max(sumw)
sh = []
sw = []
for i, s in enumerate(sumh):
    if s == shmax: sh.append(i)
for i, s in enumerate(sumw):
    if s == swmax: sw.append(i)
ans = shmax + swmax - 1
jdg = False
for i in sh:
    for j in sw:
        if (j, i) not in checkset: 
            ans += 1
            jdg = True
            break

    if jdg: break
print(ans)


H,W,M = list(map(int, input().split()))
width = [0]*W
height = [0]*H

st = set()
for i in range(M):
  y, x = list(map(int, input().split()))
  st.add((x - 1,y - 1))
  width[x-1] += 1
  height[y-1] += 1

maxW = max(width)
maxH = max(height)

indexW = [i for i, v in enumerate(width) if v == maxW]
indexH = [i for i, v in enumerate(height) if v == maxH]

ans = maxW + maxH 

#それぞれ列と行の最大値の中から適当に１つずつ列と行を選ぶ
tmpX = indexW[0]
tmpY = indexH[0]

#HeightとWidthのそれぞれの最大値の点(x, y)に爆弾がない場合があるかどうか
flag = 0

#print(f"indexH {indexH}")
#print(f"indexW {indexW}")

#Heightの最大値と、widthのそれぞれを全探索
for x in indexW:
  y = tmpY
  if not (x, y) in st:
    flag = 1
    break


for y in indexH:
  x = tmpX
  if not (x, y) in st:
    flag = 1
    break

if flag == 1:
  print(ans)
else:
  print((ans - 1))


(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a,b=[0]*h,[0]*w
for y,x in e:
    a[y-1]+=1
    b[x-1]+=1
ans=max(a)+max(b)
c=a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==ans for y,x in e)
print(ans-(c<=0))

import collections
import sys
def input() : return sys.stdin.readline().strip()
h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]

otherwisey = []
otherwisex = []
for i in range(m):
    if X[i] != most_common_x_index:
        otherwisey.append(Y[i])
    if Y[i] != most_common_y_index:
        otherwisex.append(X[i])

most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
    ansx = most_common_y[0][1] + most_common_x_count
else:
    ansx = most_common_x_count

most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0:
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count

print(max(ansx,ansy))

h, w, m = map(int, input().split())
bord_x, bord_y = [0]*h, [0]*w
 
hw = []
for _i in range(m):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    bord_x[s] += 1
    bord_y[t] += 1
    hw.append([s, t])
 
x_max, y_max = max(bord_x), max(bord_y)
 
cnt = 0
for i, j in hw:
    if bord_x[i] == x_max and bord_y[j] == y_max:
        cnt += 1
 
if cnt == bord_x.count(x_max)*bord_y.count(y_max):
    x_max -= 1
 
print(x_max+y_max)

from collections import defaultdict

h, w, m = map(int, input().split())

rowsum = [0] * h
rowmax = 0
colsum = [0] * w
colmax = 0
targets = defaultdict(int)
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    rowsum[hi] += 1
    rowmax = max(rowmax, rowsum[hi])
    colsum[wi] += 1
    colmax = max(colmax, colsum[wi])
    targets[(hi, wi)] = 1

rowindices = []
for i, v in enumerate(rowsum):
    if v == rowmax:
        rowindices.append(i)

colindices = []
for i, v in enumerate(colsum):
    if v == colmax:
        colindices.append(i)

ans = rowmax + colmax - 1
for ri in rowindices:
    for ci in colindices:
        if targets[(ri, ci)]:
            continue
        print(rowmax + colmax)
        return

print(ans)

H, W, M = map(int, input().split())
bombs = {}
rows = []
cols = []
for i in range(H):
    rows.append([i, 0])
for i in range(W):
    cols.append([i, 0])
for i in range(M):
    y, x = map(lambda x: x - 1, map(int, input().split()))
    bombs[(y,x)] = True
    rows[y][1] += 1
    cols[x][1] += 1


rows = sorted(rows, key=lambda x: x[1], reverse=True)
cols = sorted(cols, key=lambda x: x[1], reverse=True)
answer = 0
for row in rows:
    a = cols[0][1] + row[1] - (1 if (row[0], cols[0][0]) in bombs else 0)
    if a > answer:
        answer = a
for col in cols:
    a = rows[0][1] + col[1] - (1 if (rows[0][0], col[0]) in bombs else 0)
    if a > answer:
        answer = a
print(answer)

H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
cntx = 0
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        cntx += 1
if cntx == cnth.count(mxh) * cntw.count(mxw):
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

def solve(H, W, M, h, w):
    f = [0] * (H+1)
    g = [0] * (W+1)
    for r, c in zip(h, w):
        f[r] += 1
        g[c] += 1
    p = max(f)
    q = max(g)
    num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g)))
    num -= len(list(filter(lambda _: f[_[0]] + g[_[1]] == p + q, zip(h, w))))
    return p + q - (num <= 0)

H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w))

H, W, M = map(int, input().split())
 
h = [0] * H
w = [0] * W
Mem = [tuple(map(int, input().split())) for _ in range(M) ]
for i, j in Mem:
  h[i-1] += 1
  w[j-1] += 1

maxh = max(h)
maxw = max(w)
 
listh = {i for i, v in enumerate(h, 1) if v == maxh}
listw = {j for j, v in enumerate(w, 1) if v == maxw}

cnt = len(listh) * len(listw)

for i, j in Mem:
  if i in listh and j in listw:
    cnt -= 1
 
if cnt:
  ans = maxh + maxw
else:
  ans = maxh + maxw - 1

print(ans)


H,W,M=list(map(int,input().split()))

HSum=[0 for _ in range(H)]
WSum=[0 for _ in range(W)]


bombs = set()
for _ in range(M):
	hi,wi = [int(x)-1 for x in input().split()]
	HSum[hi] += 1
	WSum[wi] += 1
	bombs.add( (hi,wi) )
# print(HSum)
# print(WSum)



curMax = 0

## 計算量多すぎ。。
# for h in range(H):
# 	for w in range(W):
# 		tmp = HSum[h] + WSum[w]
# 		if curMax <= tmp:
# 			if (h,w) in bombs:
# 				tmp -= 1
# 			curMax = max( curMax, tmp )

hMax = max(HSum)
wMax = max(WSum)
tmpMax = hMax + wMax

ans = 0

hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax]
wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax]

for h in hSumMaxOnly:
	if ans == tmpMax:
		break
	for w in wSumMaxOnly:
		if (h,w) in bombs:
			ans = tmpMax - 1
		else:
			ans = tmpMax
			break



print(ans)


h,w,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
ch,cw=[0]*(h+1),[0]*(w+1)
for x in l:
    ch[x[0]]+=1
    cw[x[1]]+=1
Mh,Mw=max(ch),max(cw)
n0=ch.count(Mh)*cw.count(Mw)
cnt=0
for x in l:
    if ch[x[0]]==Mh and cw[x[1]]==Mw:cnt+=1
ans=Mh+Mw-1
if cnt<n0:ans+=1
print(ans)

import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                return

    print(ans-1)

def __starting_point():
    main()
__starting_point()

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
H,W,M = readInts()

dic1 = Counter()
dic2 = Counter()
s = set()
for i in range(M):
    h,w = [int(x)-1 for x in input().split()]
    dic1[h] += 1
    dic2[w] += 1
    s.add((h,w))
# print(dic)
ans = 0

# 重なっているもので最大値がある時もあれば
# 行、列の交差点でボムなしが一番大きいものがある
for h,w in s:
    ans = max(ans, dic1[h] + dic2[w] - 1)

dic1 = dic1.most_common()
dic2 = dic2.most_common()
max1 = dic1[0][1]
max2 = dic2[0][1]

for k1,v1 in dic1:
    if v1 < max1:
        break # continueする必要がない most_commonで大きい方から集めてるので
    for k2,v2 in dic2:
        if v2 < max2:
            break # 同じく
        if (k1,k2) in s: # 一度計算したもの
            continue
        # 両方とも最大であればok
        ans = max(ans, v1 + v2)
        break
print(ans)


H,W,M=map(int,input().split())
row=[0]*H
col=[0]*W
target=set()
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
    target.add((h-1,w-1))
A=max(row)
B=max(col)
a=[x for x in range(H) if row[x]==A]
b=[x for x in range(W) if col[x]==B]
cnt=0
for i in a:
    for j in b:
        cnt+=1
        if (i,j) not in target:
            print(A+B)
            return
        if cnt>M:
            print(A+B-1)
            return
print(A+B-1)

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

h,w,m=nii()

hl=[0 for i in range(h+1)]
wl=[0 for i in range(w+1)]
hwl=set()

for i in range(m):
  th,tw=nii()
  hl[th]+=1
  wl[tw]+=1
  hwl.add((th,tw))

h_max=max(hl)
w_max=max(wl)

h_cand=[i for i in range(h+1) if hl[i]==h_max]
w_cand=[i for i in range(w+1) if wl[i]==w_max]

for i in h_cand:
  for j in w_cand:
    if (i,j) not in hwl:
      print(h_max+w_max)
      return

print(h_max+w_max-1)

#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

h,w,m = inm()
ha = [0]*h
wa = [0]*w
q = {}
for i in range(m):
    hh,ww = inm()
    hh -= 1
    ww -= 1
    q[(hh,ww)] = 1
    ha[hh] += 1
    wa[ww] += 1
mh = max(ha)
mw = max(wa)
a = [i for i in range(h) if ha[i]==mh]
b = [i for i in range(w) if wa[i]==mw]
for i in a:
    for j in b:
        if (i,j) not in q:
            print(mh+mw)
            return
print(mh+mw-1)


########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
    bomb = tuple(map(lambda x:int(x)-1, input().split()))
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
for h,w in bombs:
    H_list[h] += 1
    W_list[w] += 1
    
maxX = max(H_list)
maxY = max(W_list)

max_H = [i for i,k in enumerate(H_list) if k == maxX]
max_W = [i for i,k in enumerate(W_list) if k == maxY]

bombs = set(bombs)
for i in max_H:
    for k in max_W:
        if (i,k) not in bombs:
            print(maxX + maxY)
            return

print(maxX + maxY -1)

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print(("Yes" if b==1 else "No"))
    return

def resolve():
    readline=sys.stdin.readline

    h,w,m=list(map(int, readline().rstrip().split()))
    cntH=[0]*h
    cntW=[0]*w

    ys=[0]*m
    xs=[0]*m

    for i in range(m):
        y,x = list(map(int, readline().rstrip().split()))
        y-=1
        x-=1
        cntH[y]+=1
        cntW[x]+=1
        ys[i]=y
        xs[i]=x
    maxX = max(cntW)
    maxY = max(cntH)
    cntMaxX=cntW.count(maxX)
    cntMaxY=cntH.count(maxY)
    cntMax=cntMaxX*cntMaxY

    for i in range(m):
        y=ys[i]
        x=xs[i]
        maxPtn=False
        if cntH[y]==maxY and cntW[x]==maxX:
            cntMax-=1
    if cntMax > 0:
        print((maxX+maxY))
    else:
        print((maxX+maxY-1))
    return


if 'doTest' not in globals():
    resolve()
    return

### ----------------
### ここまで 
### ----------------


h,w,m = map(int,input().split())
x = {}
y = {}
dic = {}
for _ in range(m):
    a,b = map(int,input().split())
    dic[(a,b)] = 1
    x[a] = x.get(a,0) + 1
    y[b] = y.get(b,0) + 1
p = max(x.values())
q = max(y.values())
cnt = 1
a = [i for i in x if x[i] == p]
b = [j for j in y if y[j] == q]
for i in a:
    for j in b:
        if dic.get((i,j),-1) == -1:
            cnt = 0
            break
    if not cnt:
        break
print(p+q-cnt)

import collections

h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]

otherwisey = []
otherwisex = []
for i in range(m):
    if X[i] != most_common_x_index:
        otherwisey.append(Y[i])
    if Y[i] != most_common_y_index:
        otherwisex.append(X[i])

most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
    ansx = most_common_y[0][1] + most_common_x_count
else:
    ansx = most_common_x_count

most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0:
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count

print(max(ansx,ansy))

H,W,M = list(map(int,input().split()))
hs = [0] * H
ws = [0] * W
s = set()

for i in range(M):
  r,c = list(map(int,input().split()))
  r -= 1
  c -= 1
  hs[r] += 1
  ws[c] += 1
  s.add((r,c))
mh = 0
mw = 0
for i in range(H):
  mh = max(mh, hs[i])
for j in range(W):
  mw = max(mw, ws[j])

i_s = list()
j_s = list()
for i in range(H):
  if mh == hs[i]:
    i_s.append(i)
for j in range(W):
  if mw == ws[j]:
    j_s.append(j)
ans = mh + mw
for i in i_s:
  for j in j_s:
    if (i,j) in s:
      continue
    print(ans)
    return
ans -= 1
print(ans)


H, W, M = map(int, input().split())

Hc = [0 for i in range(H)]
Wc = [0 for i in range(W)]
B = []

for m in range(M):
  h, w = map(int, input().split())
  Hc[h - 1] += 1
  Wc[w - 1] += 1
  B.append((h - 1, w - 1))
Hcmax = max(Hc)
Hcmax_idx = [i for i, x in enumerate(Hc) if x == Hcmax] 
Wcmax = max(Wc)
Wcmax_idx = [i for i, x in enumerate(Wc) if x == Wcmax] 

ans = Hcmax + Wcmax - 1
B = set(B)
f = False
for i in Hcmax_idx:
  if f:
    break
  for j in Wcmax_idx:
    if (i, j) not in B:
      ans = Hcmax + Wcmax
      f = True
      break
print(ans)

import numpy as np
H, W, M = map(int, input().split())
col = np.zeros(H)
row = np.zeros(W)
memo = []
for i in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    col[h] += 1
    row[w] += 1
    memo.append((h,w))

col_max = col.max()
row_max = row.max()

col_max_indexes = np.where(col == col_max)[0]
row_max_indexes = np.where(row == row_max)[0]

ans = col_max + row_max - 1
memo = set(memo)
for c in col_max_indexes:
    for r in row_max_indexes:
        if (c,r) not in memo:
            ans = col_max + row_max
            print(int(ans))
            return

print(int(ans))

def main():
    h, w, m, *BOM = list(map(int, open(0).read().split()))
    row = [0] * h
    col = [0] * w
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        row[i] += 1
        col[j] += 1

    p, q = max(row), max(col)
    rr = sum(1 for i in range(h) if row[i] == p)
    rl = sum(1 for i in range(w) if col[i] == q)

    cnd = rr * rl

    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        if (row[i], col[j]) == (p, q):
            cnd -= 1

    if cnd > 0:
        ans = p + q
    else:
        ans = p + q - 1

    print(ans)


def __starting_point():
    main()

__starting_point()

from collections import Counter


def main():
    H, W, M = list(map(int, input().split()))
    bombs = [list(map(int, input().split())) for _ in range(M)]
    counter_row = Counter([h for h, _ in bombs])
    val_max_row, max_rows = 0, []
    for h, v in counter_row.items():
        if val_max_row < v:
            val_max_row = v
            max_rows = [h]
        elif val_max_row == v:
            max_rows.append(h)
    counter_col = Counter([w for _, w in bombs])
    val_max_col, max_cols = 0, []
    for w, v in counter_col.items():
        if val_max_col < v:
            val_max_col = v
            max_cols = [w]
        elif val_max_col == v:
            max_cols.append(w)
    # 基本的には val_max_row + val_max_col が答え。
    # 行・列で重複カウントになるケースだった場合はここから1引かないといけない。
    max_rows = Counter(max_rows)
    max_cols = Counter(max_cols)
    n_max_cells = len(max_rows.keys()) * len(max_cols.keys())
    n_cells = 0
    for h, w in bombs:
        if max_rows[h] > 0 and max_cols[w] > 0:
            n_cells += 1
    ans = val_max_row + val_max_col
    if n_cells >= n_max_cells:
        ans -= 1
    print(ans)


def __starting_point():
    main()
__starting_point()

import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                return

    print(ans-1)

def __starting_point():
    main()
__starting_point()

import sys
h,w,m = list(map(int,input().split()))
h_lst = [[0,i] for i in range(h)]
w_lst = [[0,i] for i in range(w)]
memo = []

for i in range(m):
  x,y = list(map(int,input().split()))
  h_lst[x-1][0] += 1
  w_lst[y-1][0] += 1
  memo.append((x-1,y-1))

h_lst.sort(reverse = True)
w_lst.sort(reverse = True)
Max_h = h_lst[0][0]
Max_w = w_lst[0][0]
h_ans = [h_lst[0][1]]
w_ans = [w_lst[0][1]]
if h != 1:
  s = 1
  while s < h and h_lst[s][0] == Max_h:
    h_ans.append(h_lst[s][1])
    s+= 1  
if w!= 1:  
  t=1  
  while t < w and w_lst[t][0] == Max_w:
    w_ans.append(w_lst[t][1])
    t += 1
  

memo = set(memo)

#探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない！             
for j in h_ans:
  for k in w_ans:
    if (j,k) not in memo:
      print((Max_h+Max_w))
      return
print(((Max_h+Max_w)-1))        
  



h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=set()
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp.add((s[i],t[i]))
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if (maxs[i]+1,maxt[j]+1) not in temp:
        print(ans)
        return
  else:
    print(ans-1)

import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                return

    print(ans-1)

def __starting_point():
    main()
__starting_point()

import numpy as np
import sys
read = sys.stdin.read

def solve(stdin):
	h, w, m = stdin[:3]

	row = np.zeros(h, np.int)
	col = np.zeros(w, np.int)
	for i in range(3, m * 2 + 3, 2):
		y, x = stdin[i: i + 2] - 1
		row[y] += 1
		col[x] += 1

	max_cnt_y = max(row)
	max_cnt_x = max(col)
	max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x)
	for i in range(3, m * 2 + 3, 2):
		y, x = stdin[i: i + 2] - 1
		if row[y] == max_cnt_y and col[x] == max_cnt_x:
			max_pair -= 1

	return max_cnt_y + max_cnt_x - (max_pair == 0)

print(solve(np.fromstring(read(), dtype=np.int, sep=' ')))

import collections

h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
#まず一番大いX座標を調べる
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0] #x座標
most_common_x_count = most_common_x[0][1] #その線に存在する爆弾の個数
#爆破されない座標たちの共通するY座標を探す
otherwise = []
for i in range(m):
    if X[i] != most_common_x_index:#not most common
        otherwise.append(Y[i])
most_common_y = collections.Counter(otherwise).most_common()
if len(most_common_y)!= 0: #ある特定のyが存在した時
    ansx = most_common_y[0][1] + most_common_x_count
else: #もともと全部のy座標が揃っていた時
    ansx = most_common_x_count
#次にY座標を基準にして調べる
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0] #x座標
most_common_y_count = most_common_y[0][1] #その線に存在する爆弾の個数
otherwise = []
for i in range(m):
    if Y[i] != most_common_y_index:#not most common
        otherwise.append(X[i])
most_common_x = collections.Counter(otherwise).most_common()
if len(most_common_x)!= 0 :
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count
print(max(ansx,ansy))

h,w,m=list(map(int,input().split()))
h=[]
w=[]
for i in range(m):
  h_,w_=list(map(int,input().split()))
  h.append(h_)
  w.append(w_)
from collections import Counter
dic_h=Counter(h)
dic_w=Counter(w)
max_h=max(dic_h.values())
max_w=max(dic_w.values())

h_set=set()
w_set=set()
for i in dic_h:
  if dic_h[i]==max_h:
    h_set.add(i)
for j in dic_w:
  if dic_w[j]==max_w:
    w_set.add(j)

cnt=0
for i in range(m):
  if h[i] in h_set and w[i] in w_set:
    cnt+=1
if len(h_set)*len(w_set)>cnt:
  print((max_h+max_w))
else:
  print((max_h+max_w-1))
  
  


import sys

H, W, M = map(int, input().split())
R = [0] * H
C = [0] * W
S = set()

for _ in range(M):
  h, w = map(int, input().split())
  S.add((h - 1, w - 1))
  R[h - 1] += 1
  C[w - 1] += 1

r = max(R)
c = max(C)

HL = [i for i in range(H) if R[i] == r]
WL = [j for j in range(W) if C[j] == c]
 
#print(r, HL)
#print(c, WL)
  
for h in HL:
  for w in WL:
    if not (h, w) in S:
      print(r + c)
      return

print(r + c - 1)

import sys

H, W, M = list(map(int, input().split()))
A = [list([int(x) - 1 for x in input().split()]) for i in range(M)]

cnth = [0] * H
cntw = [0] * W
st = set()

for y, x in A:
    cnth[y] += 1
    cntw[x] += 1
    st.add((y, x))

my = max(cnth)
mx = max(cntw)

Y = []
X = []

for i in range(H):
    if cnth[i] == my:
        Y.append(i)

for i in range(W):
    if cntw[i] == mx:
        X.append(i)

for y in Y:
    for x in X:
        if not (y, x) in st:
            print((my + mx))
            return

print((my + mx - 1))


def main():
    H, W, M = list(map(int, input().split()))
    hw = [tuple(list(map(int, input().split()))) for _ in [0]*M]
    hw_set = set(hw)
    h_count = [0 for i in range(H+1)]
    w_count = [0 for i in range(W+1)]
    for h, w in hw:
        h_count[h] += 1
        w_count[w] += 1
    h_m = max(h_count)
    w_m = max(w_count)
    h_list = []
    w_list = []
    for i in range(H+1):
        if h_count[i] == h_m:
            h_list.append(i)
    for i in range(W+1):
        if w_count[i] == w_m:
            w_list.append(i)
    #print(h_list, w_list)
    for i in h_list:
        for j in w_list:
            if (i, j) not in hw_set:
                print((h_m+w_m))
                return
    print((h_m+w_m-1))


main()


import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0] * H
    ws = [0] * W
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                return
    print(ans-1)


def __starting_point():
    main()
__starting_point()

h,w,m=list(map(int,input().split()))

H,W=[0]*h,[0]*w
P=set()

for i in range(m):
  y,x=list(map(int,input().split()))
  H[~-y]+=1
  W[~-x]+=1
  P.add(~-y*w+~-x)

mh,mw=max(H),max(W)
MH=[i for i,h in enumerate(H) if h==mh]
MW=[i for i,v in enumerate(W) if v==mw]
for y in MH:
  for x in MW:
    if y*w+x not in P:
      print((mh+mw))
      return

print((mh+mw-1))