AtCoder Beginner Contest 176 - Bomber

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).

Source: atcoder | Difficulty: MEDIUM


Solutions:
(H, W, M) = list(map(int, input().split()))
hw = set()
w = [0] * 3 * 10 ** 5
h = [0] * 3 * 10 ** 5
for i in range(M):
	(h_i, w_j) = map(int, input().split())
	hw.add(h_i - 1 + (w_j - 1) * 3 * 10 ** 6)
	h[h_i - 1] += 1
	w[w_j - 1] += 1
a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)
x = [i for (i, j) in enumerate(h) if j == mxh_v]
y = [i for (i, j) in enumerate(w) if j == mxw_v]
for i in x:
	for j in y:
		if not i + j * 3 * 10 ** 6 in hw:
			print(mxh_v + mxw_v)
			exit()
print(mxh_v + mxw_v - d)


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, 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)


(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)


(h, w, m) = map(int, input().split())
H = [0] * (h + 1)
W = [0] * (w + 1)
bombs = set()
for _ in range(m):
	(hh, ww) = map(lambda x: int(x) - 1, input().split())
	H[hh] += 1
	W[ww] += 1
	bombs.add((hh, ww))
mh = max(H)
mw = max(W)
mhis = [i for (i, x) in enumerate(H) if x == mh]
mwis = [i for (i, x) in enumerate(W) if x == mw]
duplicated = True
for mhi in mhis:
	for mwi in mwis:
		if not (mhi, mwi) in bombs:
			duplicated = False
			break
ans = mh + mw - duplicated
print(ans)


(h, w, m) = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
(hl, wl) = ([0] * (h + 1), [0] * (w + 1))
for i in hw:
	hl[i[0]] += 1
	wl[i[1]] += 1
(hm, wm) = (max(hl), max(wl))
cnt = hl.count(hm) * wl.count(wm)
for (i, j) in hw:
	if hl[i] + wl[j] == hm + wm:
		cnt -= 1
print(hm + wm if cnt > 0 else hm + wm - 1)


(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)


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())
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)


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()


(H, W, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
takasa = [0] * H
haba = [0] * W
for i in range(M):
	takasa[A[i][0] - 1] += 1
	haba[A[i][1] - 1] += 1
mt = max(takasa)
mh = max(haba)
ct = takasa.count(mt)
ch = haba.count(mh)
a = 0
for i in range(M):
	if takasa[A[i][0] - 1] == mt and haba[A[i][1] - 1] == mh:
		a += 1
if a == ct * ch:
	print(mt + mh - 1)
else:
	print(mt + mh)


(H, W, M) = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)
bom = []
for i in range(M):
	(h, w) = map(int, input().split())
	bom.append([h, w])
	row[h] += 1
	col[w] += 1
rmax = max(row)
cmax = max(col)
cnt = row.count(rmax) * col.count(cmax)
for (h, w) in bom:
	if rmax == row[h] and cmax == col[w]:
		cnt -= 1
print(rmax + cmax - (cnt == 0))


(h, w, m) = map(int, input().split())
hl = [0] * h
wl = [0] * w
bom = []
for i in range(m):
	(h1, w1) = map(int, input().split())
	bom.append([h1 - 1, w1 - 1])
	hl[h1 - 1] += 1
	wl[w1 - 1] += 1
mh = max(hl)
mw = max(wl)
ans = mh + mw
mhl = set()
mwl = set()
for i in range(h):
	if mh == hl[i]:
		mhl.add(i)
for i in range(w):
	if mw == wl[i]:
		mwl.add(i)
count = len(mhl) * len(mwl)
for i in range(len(bom)):
	if bom[i][0] in mhl and bom[i][1] in mwl:
		count -= 1
if count > 0:
	print(ans)
else:
	print(ans - 1)


(H, W, M) = map(int, input().split())
row = [0] * H
col = [0] * W
mat = []
for i in range(M):
	(h, w) = map(int, input().split())
	row[h - 1] += 1
	col[w - 1] += 1
	mat.append((h - 1, w - 1))
r = max(row)
c = max(col)
rr = [1 if row[i] == r else 0 for i in range(H)]
cc = [1 if col[i] == c else 0 for i in range(W)]
x = 0
for k in mat:
	if rr[k[0]] == 1 and cc[k[1]] == 1:
		x += 1
if sum(rr) * sum(cc) == x:
	print(r + c - 1)
else:
	print(r + c)


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) = map(int, input().split())
r = [0] * max(h, w)
c = [0] * max(h, w)
l = []
for i in range(m):
	(x, y) = map(int, input().split())
	r[x - 1] += 1
	c[y - 1] += 1
	l.append([x, y])
cm = max(c)
rm = max(r)
ci = [i for (i, x) in enumerate(c) if x == cm]
ri = [i for (i, x) in enumerate(r) if x == rm]
ans = cm + rm
cnt = 0
for i in range(m):
	if r[l[i][0] - 1] == rm and c[l[i][1] - 1] == cm:
		cnt += 1
if cnt == len(ci) * len(ri):
	print(int(ans) - 1)
else:
	print(int(ans))


(H, W, M) = (int(i) for i in input().split())
hw = set()
hh = [0] * H
ww = [0] * W
for i in range(M):
	(ht, wt) = (int(i) for i in input().split())
	hw.add((ht - 1) * W + wt - 1)
	hh[ht - 1] += 1
	ww[wt - 1] += 1
hhh = max(hh)
ih = [i for (i, x) in enumerate(hh) if x == hhh]
www = max(ww)
iw = [i for (i, x) in enumerate(ww) if x == www]
minus = 1
for iih in ih:
	for iiw in iw:
		if iih * W + iiw not in hw:
			minus = 0
			break
print(hhh + www - minus)


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()


(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)


import sys
(H, W, M) = map(int, input().split())
Hb = [0] * H
Wb = [0] * W
B = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	Hb[h - 1] += 1
	Wb[w - 1] += 1
	B.add((h - 1, w - 1))
HB = max(Hb)
WB = max(Wb)
x = set()
y = set()
for i in range(H):
	if Hb[i] == HB:
		y.add(i)
for i in range(W):
	if Wb[i] == WB:
		x.add(i)
for i in y:
	for j in x:
		if (i, j) not in B:
			print(HB + WB)
			sys.exit()
print(HB + WB - 1)


((h, w, m), *s) = [[*map(int, i.split())] for i in open(0)]
r = [0] * (h + 1)
c = [0] * (w + 1)
for (x, y) in s:
	r[x] += 1
	c[y] += 1
R = max(r)
nr = {i for (i, x) in enumerate(r) if x == R}
C = max(c)
nc = {i for (i, x) in enumerate(c) if x == C}
count = sum((x in nr and y in nc for (x, y) in s))
print(R + C - (len(nr) * len(nc) == count))


(h, w, m) = map(int, input().split())
row = [0] * (h + 1)
rn = [[] for _ in range(h + 1)]
col = [0] * (w + 1)
cn = [[] for _ in range(w + 1)]
data = []
for _ in range(m):
	(hd, wd) = map(int, input().split())
	row[hd] += 1
	rn[hd].append(wd)
	col[wd] += 1
	cn[wd].append(hd)
cm = max(col)
rm = max(row)
ri = [x for (x, y) in enumerate(row) if y == rm]
ci = [x for (x, y) in enumerate(col) if y == cm]
for r in ri:
	rs = set(rn[r])
	for c in ci:
		if c not in rs:
			ans = cm + rm
			print(ans)
			exit()
ans = cm + rm - 1
print(ans)


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)


(h, w, m) = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
r = [0] * (h + 1)
c = [0] * (w + 1)
for (x, y) in s:
	r[x] += 1
	c[y] += 1
R = max(r)
nr = {i for (i, x) in enumerate(r) if x == R}
C = max(c)
nc = {i for (i, x) in enumerate(c) if x == C}
count = sum((x in nr and y in nc for (x, y) in s))
print(R + C - (len(nr) * len(nc) == count))


(h, w, m) = map(int, input().split())
H = [0 for i in range(h)]
W = [0 for i in range(w)]
s = set()
for i in range(m):
	(a, b) = map(int, input().split())
	H[a - 1] += 1
	W[b - 1] += 1
	s.add((a, b))
hma = max(H)
wma = max(W)
h_index = [x for (x, v) in enumerate(H) if v == hma]
w_index = [y for (y, v) in enumerate(W) if v == wma]
val = -1
for p in h_index:
	for q in w_index:
		if not (p + 1, q + 1) in s:
			val = 0
			break
print(hma + wma + val)


(h, w, m) = map(int, input().split())
a = [0] * m
hc = [0] * w
wc = [0] * h
for i in range(m):
	(x, y) = map(int, input().split())
	a[i] = [x - 1, y - 1]
	hc[y - 1] += 1
	wc[x - 1] += 1
hcm = max(hc)
wcm = max(wc)
hk = [0] * w
wk = [0] * h
for i in range(len(hc)):
	if hc[i] == hcm:
		hk[i] = 1
for i in range(len(wc)):
	if wc[i] == wcm:
		wk[i] = 1
c = 0
for i in range(len(a)):
	if wk[a[i][0]] == 1 and hk[a[i][1]] == 1:
		c += 1
if c == sum(hk) * sum(wk):
	print(hcm + wcm - 1)
else:
	print(hcm + wcm)


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) = map(int, input().split())
Y = [0 for i in range(H + 1)]
X = [0 for i in range(W + 1)]
HW = []
for i in range(M):
	(h, w) = map(int, input().split())
	Y[h] += 1
	X[w] += 1
	HW.append([h, w])
LY = []
LX = []
MY = max(Y)
MX = max(X)
for i in range(H + 1):
	if Y[i] == MY:
		LY.append(i)
for i in range(W + 1):
	if X[i] == MX:
		LX.append(i)
count = 0
for i in range(M):
	if Y[HW[i][0]] == MY and X[HW[i][1]] == MX:
		count += 1
if count == len(LY) * len(LX):
	print(MY + MX - 1)
else:
	print(MY + MX)


(H, W, M) = map(int, input().split())
L = [0 for _ in range(H)]
C = [0 for _ in range(W)]
B = {}
for _ in range(M):
	(a, b) = map(int, input().split())
	B[str(a) + ',' + str(b)] = 0
	L[a - 1] += 1
	C[b - 1] += 1
LM = max(L)
CM = max(C)
l = []
c = []
for j in range(H):
	if L[j] == LM:
		l.append(j)
for k in range(W):
	if C[k] == CM:
		c.append(k)
ans = LM + CM - 1
for a in l:
	for b in c:
		if str(a + 1) + ',' + str(b + 1) not in B:
			ans = LM + CM
			break
	if ans == LM + CM:
		break
print(ans)


(H, W, M) = map(int, input().split())
R = [0] * H
C = [0] * W
B = []
for i in range(M):
	(hi, wi) = map(lambda s: int(s) - 1, input().split())
	R[hi] += 1
	C[wi] += 1
	B.append((hi, wi))
Rmax = max(R)
Cmax = max(C)
ans = Rmax + Cmax
if R.count(Rmax) * C.count(Cmax) == sum([R[hi] == Rmax and C[wi] == Cmax for (hi, wi) in B]):
	ans -= 1
print(ans)


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
Y = [0] * W
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]
C = [w for (w, y) in enumerate(Y) if y == maxY]
ans = maxX + maxY
if len(R) * len(C) <= M:
	blank = set(((r, c) for r in R for c in C))
	blank -= set(bomb)
	if len(blank) == 0:
		ans -= 1
print(ans)


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(ans)


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=' ')))


(H, W, M) = map(int, input().split())
r = [0] * (W + 1)
c = [0] * (H + 1)
rc = {}
for i in range(M):
	(h, w) = map(int, input().split())
	rc[h, w] = True
	r[w] += 1
	c[h] += 1
rm = max(r)
cm = max(c)
ri = {i for (i, v) in enumerate(r) if v == rm}
ci = {i for (i, v) in enumerate(c) if v == cm}
cnt = sum([w in ri and h in ci for (h, w) in rc])
print(rm + cm - (len(ri) * len(ci) == cnt))


import sys
input = sys.stdin.readline
(h, w, m) = map(int, input().split())
b = []
for i in range(m):
	(hi, wi) = map(int, input().split())
	b.append((hi - 1, wi - 1))
H = [0] * h
W = [0] * w
for i in b:
	H[i[0]] += 1
	W[i[1]] += 1
hm = set()
wm = set()
hM = max(H)
for i in range(h):
	if H[i] == hM:
		hm.add(i)
wM = max(W)
for i in range(w):
	if W[i] == wM:
		wm.add(i)
count = 0
for i in b:
	if i[0] in hm and i[1] in wm:
		count += 1
if len(hm) * len(wm) <= count:
	print(hM + wM - 1)
else:
	print(hM + wM)


(h, w, m) = map(int, input().split())
a = [0] * h
b = [0] * w
g = [[] for _ in range(h)]
for _ in range(m):
	(y, x) = map(int, input().split())
	a[y - 1] += 1
	b[x - 1] += 1
	g[y - 1].append(x - 1)
ma = max(a)
mb = max(b)
c = b.count(mb)
for i in range(h):
	if a[i] == ma:
		res = 0
		for p in g[i]:
			if b[p] == mb:
				res += 1
		if res < c:
			print(ma + mb)
			exit(0)
print(ma + mb - 1)


(H, W, M) = map(int, input().split())
listh = [0] * H
listw = [0] * W
s = set()
for i in range(M):
	(hm, wm) = map(int, input().split())
	listh[hm - 1] += 1
	listw[wm - 1] += 1
	s.add((hm - 1, wm - 1))
mh = max(listh)
mw = max(listw)
maxh = [i for (i, v) in enumerate(listh) if v == mh]
maxw = [i for (i, v) in enumerate(listw) if v == mw]
import sys
for i in maxh:
	for j in maxw:
		if (i, j) not in s:
			print(mh + mw)
			sys.exit()
print(mh + mw - 1)


def main():
	(h, w, m) = map(int, input().split())
	hl = [0] * h
	wl = [0] * w
	dic = set()
	for i in range(m):
		(x, y) = map(int, input().split())
		dic.add((x, y))
		hl[x - 1] += 1
		wl[y - 1] += 1
	h_max = max(hl)
	r = [i for i in range(h) if hl[i] == h_max]
	w_max = max(wl)
	c = [i for i in range(w) if wl[i] == w_max]
	flg = 0
	for rc in r:
		for cc in c:
			if (rc + 1, cc + 1) not in dic:
				print(h_max + w_max)
				return
	print(h_max + w_max - 1)
main()


(h, w, m) = map(int, input().split())
r = [0] * h
c = [0] * w
s = set()
for _ in range(m):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	r[i] += 1
	c[j] += 1
	s.add(i * w + j)
rmx = max(r)
cmx = max(c)
rc = [i for i in range(h) if r[i] == rmx]
cc = [j for j in range(w) if c[j] == cmx]
ans = rmx + cmx - 1
for i in rc:
	for j in cc:
		if i * w + j not in s:
			print(ans + 1)
			exit()
print(ans)


(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)


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)
		exit()
else:
	print(hmax + wmax - 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)


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
BIG = 10 ** 18
R = 10 ** 9 + 7

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)


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)


(h, w, m) = map(int, input().split())
xsct = [0] * w
ysct = [0] * h
ips = set()
xsmx = ysmx = 0
for _ in range(m):
	(y, x) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	xsct[x] += 1
	ysct[y] += 1
	ips.add((x, y))
	xsmx = max(xsmx, xsct[x])
	ysmx = max(ysmx, ysct[y])
xs = [x for x in range(w) if xsct[x] == xsmx]
ys = [y for y in range(h) if ysct[y] == ysmx]
ans = xsmx + ysmx - 1
ok = False
for y in ys:
	for x in xs:
		if (x, y) not in ips:
			ans += 1
			ok = True
			break
	if ok:
		break
print(ans)


import collections as cc
import sys
import bisect as bi
I = lambda : list(map(int, input().split()))
(a, b, m) = I()
ar = [I() for i in range(m)]
row = cc.defaultdict(int)
col = cc.defaultdict(int)
rr = cc.defaultdict(int)
ccc = cc.defaultdict(int)
for i in ar:
	rr[i[0]] += 1
	ccc[i[1]] += 1
	row[tuple(i)] = 1
rc = max(rr.values())
cr = max(ccc.values())
p = [i for i in rr if rr[i] == rc]
q = [i for i in ccc if ccc[i] == cr]
ans = rc + cr
tf = 0
for i in p:
	for j in q:
		if row[i, j] == 0:
			tf = 1
			break
	if tf:
		break
if tf == 0:
	ans -= 1
print(ans)


(h, w, m) = map(int, input().split())
row = [0] * h
col = [0] * w
s = []
for _ in range(m):
	(x, y) = map(int, input().split())
	row[x - 1] += 1
	col[y - 1] += 1
	s.append([x - 1, y - 1])
(a, b) = (max(row), max(col))
aa = row.count(a)
bb = col.count(b)
c = 0
for (x, y) in s:
	if row[x] == a and col[y] == b:
		c += 1
if c < aa * bb:
	print(a + b)
else:
	print(a + b - 1)


(h, w, m) = map(int, input().split())
hlist = [0] * (h + 1)
wlist = [0] * (w + 1)
cnt = set()
for i in range(m):
	(a, b) = map(int, input().split())
	hlist[a] += 1
	wlist[b] += 1
	cnt.add((a, b))
(hcnt, wcnt) = (max(hlist), max(wlist))
hhh = [i for (i, v) in enumerate(hlist) if v == hcnt]
www = [i for (i, v) in enumerate(wlist) if v == wcnt]
for i in hhh:
	for j in www:
		if (i, j) not in cnt:
			print(hcnt + wcnt)
			exit()
print(hcnt + wcnt - 1)


(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)
			exit()
print(htm + wtm - 1)


(H, W, M) = map(int, input().split())
hw = []
sh = [0] * H
sw = [0] * W
for i in range(M):
	(h, w) = map(int, input().split())
	hw.append((h - 1, w - 1))
	sh[h - 1] += 1
	sw[w - 1] += 1
mh = max(sh)
mw = max(sw)
count = 0
for i in range(M):
	if sh[hw[i][0]] == mh and sw[hw[i][1]] == mw:
		count += 1
if sh.count(mh) * sw.count(mw) > count:
	print(mh + mw)
else:
	print(mh + mw - 1)


from collections import Counter
(h, w, m) = map(int, input().split())
beds = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
bom_v = Counter((b[0] for b in beds))
bom_h = Counter((b[1] for b in beds))
v_max = max(bom_v.values())
h_max = max(bom_h.values())
cand = list(bom_v.values()).count(v_max) * list(bom_h.values()).count(h_max)
bombs = len([... for (i, j) in beds if bom_v[i] == v_max and bom_h[j] == h_max])
if cand - bombs > 0:
	print(v_max + h_max)
else:
	print(v_max + h_max - 1)


import itertools
(h, w, m) = map(int, input().split(' '))
x = [0] * 300001
y = [0] * 300001
z = []
(mx, my) = (0, 0)
for i in range(m):
	(a, b) = map(int, input().split(' '))
	x[a] += 1
	y[b] += 1
	mx = max(mx, x[a])
	my = max(my, y[b])
	z.append((a, b))
x1 = x.count(mx)
y1 = y.count(my)
z1 = x1 * y1
for (i, j) in z:
	if x[i] == mx and y[j] == my:
		z1 -= 1
if z1:
	print(mx + my)
else:
	print(mx + my - 1)


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
Y = [0] * W
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]
C = [w for (w, y) in enumerate(Y) if y == maxY]
bomb = set(bomb)
for r in R:
	for c in C:
		if (r, c) not in bomb:
			print(maxX + maxY)
			return
print(maxX + maxY - 1)


(h, w, m) = map(int, input().split())
tate = [0] * (h + 1)
yoko = [0] * (w + 1)
basyo = []
for i in range(m):
	(hh, ww) = map(int, input().split())
	basyo.append((hh - 1, ww - 1))
	tate[hh - 1] += 1
	yoko[ww - 1] += 1
(tt, yy) = (0, 0)
x = max(tate)
for i in tate:
	if i == x:
		tt += 1
y = max(yoko)
for i in yoko:
	if i == y:
		yy += 1
ans = x + y
pl = tt * yy
cur = 0
for (i, j) in basyo:
	if tate[i] + yoko[j] == ans:
		cur += 1
if pl > cur:
	print(ans)
else:
	print(ans - 1)


(H, W, M) = map(int, input().split())
bombh = []
bombw = []
bomb = []
w = [0] * W
h = [0] * H
for i in range(M):
	(hs, ws) = map(int, input().split())
	w[ws - 1] += 1
	h[hs - 1] += 1
	bomb.append([hs - 1, ws - 1])
maxh = max(h)
maxw = max(w)
ans = maxh + maxw
count = 0
for i in range(M):
	if ans == h[bomb[i][0]] + w[bomb[i][1]]:
		count += 1
a = h.count(maxh) * w.count(maxw)
if a == count:
	ans -= 1
print(ans)


(H, W, M) = map(int, input().split())
(HL, WL) = ([0] * H, [0] * W)
B = []
for _ in range(M):
	(h, w) = map(lambda x: int(x) - 1, input().split())
	B.append((h, w))
	HL[h] += 1
	WL[w] += 1
(HM, WM) = (max(HL), max(WL))
K = HL.count(HM) * WL.count(WM)
cnt = 0
for (h, w) in B:
	if HL[h] == HM and WL[w] == WM:
		cnt += 1
if K > cnt:
	print(HM + WM)
else:
	print(HM + WM - 1)


import sys
input = sys.stdin.readline
(H, W, M) = map(int, input().split())
s = set()
ys = [0] * (H + 1)
xs = [0] * (W + 1)
for _ in range(M):
	(y, x) = map(int, input().split())
	s.add((y, x))
	ys[y] += 1
	xs[x] += 1
res = 0
mxy = []
mx = max(ys)
for i in range(H + 1):
	if ys[i] == mx:
		mxy.append(i)
res += mx
mxx = []
mx = max(xs)
for i in range(W + 1):
	if xs[i] == mx:
		mxx.append(i)
res += mx - 1
for x in mxx:
	for y in mxy:
		if (y, x) in s:
			continue
		res += 1
		break
	else:
		continue
	break
print(res)


(h, w, m) = map(int, input().split())
h_ = [0] * (h + 1)
w_ = [0] * (w + 1)
plot = set()
for _ in range(m):
	(x, y) = map(int, input().split())
	h_[x] += 1
	w_[y] += 1
	plot.add((x, y))
x = max(h_)
y = max(w_)
a = [i for (i, v) in enumerate(h_) if v == x]
b = [j for (j, q) in enumerate(w_) if q == y]
ans = x + y - 1
c = False
for i in a:
	for j in b:
		if (i, j) not in plot:
			c = True
			break
	if c:
		break
if c:
	print(ans + 1)
else:
	print(ans)


(n, m, k) = map(int, input().split())
m += 1
n += 1
r = [0] * n
c = [0] * m
d = {}
for _ in range(k):
	(a, b) = map(int, input().split())
	d[a, b] = 1
	r[a] += 1
	c[b] += 1
m1 = max(r)
x = []
for i in range(n):
	if r[i] == m1:
		x.append(i)
m2 = max(c)
y = []
for i in range(m):
	if c[i] == m2:
		y.append(i)
ans = m1 + m2
z = 0
for i in x:
	for j in y:
		if (i, j) not in d:
			z = -1
			break
if z == 0:
	print(ans - 1)
else:
	print(ans)


(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)


(h, w, m) = map(int, input().split())
a = [0] * h
b = [0] * w
s = set()
for _ in range(m):
	(x, y) = map(lambda x: int(x) - 1, input().split())
	a[x] += 1
	b[y] += 1
	s.add(x * 10 ** 6 + y)
ma = max(a)
mb = max(b)
c = [i for (i, v) in enumerate(a) if v == ma]
d = [i for (i, v) in enumerate(b) if v == mb]
for x in c:
	for y in d:
		if not x * 10 ** 6 + y in s:
			print(ma + mb)
			exit()
print(ma + mb - 1)


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()


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))


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)
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())
g = []
e1 = [0] * h
e2 = [0] * w
for c in range(m):
	(a, b) = map(int, input().split())
	g.append([a - 1, b - 1])
	e1[a - 1] += 1
	e2[b - 1] += 1
p1 = max(e1)
p2 = max(e2)
x = [1 if e1[c] == p1 else 0 for c in range(h)]
y = [1 if e2[c] == p2 else 0 for c in range(w)]
r = sum(x) * sum(y)
for i in g:
	if x[i[0]] == 1 and y[i[1]] == 1:
		r -= 1
if r == 0:
	print(p1 + p2 - 1)
else:
	print(p1 + p2)


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())
H = [0] * (3 * 10 ** 5 + 1)
W = [0] * (3 * 10 ** 5 + 1)
M = []
for i in range(m):
	(h, w) = map(int, input().split())
	M.append([h, w])
	H[h] += 1
	W[w] += 1
p = max(H)
q = max(W)
X = set([i for i in range(3 * 10 ** 5 + 1) if H[i] == p])
Y = set([i for i in range(3 * 10 ** 5 + 1) if W[i] == q])
cnt = 0
for i in range(m):
	if M[i][0] in X and M[i][1] in Y:
		cnt += 1
if cnt == len(X) * len(Y):
	print(p + q - 1)
else:
	print(p + q)


(h, w, m) = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(m)]
(H, W) = ([0] * h, [0] * w)
for (i, j) in HW:
	H[i - 1] += 1
	W[j - 1] += 1
(max_h, max_w) = (max(H), max(W))
ans = max_h + max_w
cnt = H.count(max_h) * W.count(max_w)
for (i, j) in HW:
	if H[i - 1] == max_h and W[j - 1] == max_w:
		cnt -= 1
print(ans if cnt != 0 else ans - 1)


(H, W, M) = list(map(int, input().split()))
HW = set((tuple((int(x) - 1 for x in input().split())) for _ in range(M)))
h = [0] * H
w = [0] * W
for (hi, wi) in HW:
	h[hi] += 1
	w[wi] += 1
hm = max(h)
wm = max(w)
hh = [i for (i, v) in enumerate(h) if v == hm]
ww = [i for (i, v) in enumerate(w) if v == wm]
ans = hm + wm - 1
for h in hh:
	for w in ww:
		if (h, w) not in HW:
			ans += 1
			break
	else:
		continue
	break
print(ans)


(h, w, m) = map(int, input().split())
d = dict()
s = set()
a = [0] * h
b = [0] * w
for _ in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	a[x] += 1
	b[y] += 1
	d[x * 10 ** 6 + y] = 1
	s.add(x * 10 ** 6 + y)
ma = max(a)
mb = max(b)
ind_x = [i for (i, j) in enumerate(a) if j == ma]
ind_y = [i for (i, j) in enumerate(b) if j == mb]
for x in ind_x:
	for y in ind_y:
		if not x * 10 ** 6 + y in s:
			print(ma + mb)
			exit()
print(ma + mb - 1)


(h, w, m) = map(int, input().split())
l = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
(A, B, ans) = ([0] * h, [0] * w, 0)
for (i, j) in l:
	A[i] += 1
	B[j] += 1
(ma, mb) = (max(A), max(B))
count = A.count(ma) * B.count(mb)
for (i, j) in l:
	if A[i] == ma and B[j] == mb:
		count -= 1
print(ma + mb - 1 if count == 0 else ma + mb)


(h, w, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
(b, c) = ([0] * h, [0] * w)
for (t1, t2) in a:
	b[t1 - 1] += 1
	c[t2 - 1] += 1
(bm, cm) = (max(b), max(c))
(b1, c1) = ([], [])
d = []
for (x, y) in a:
	d.append((x - 1, y - 1))
d = set(d)
for i in range(h):
	if b[i] == bm:
		b1.append(i)
for i in range(w):
	if c[i] == cm:
		c1.append(i)
for i in b1:
	for j in c1:
		if (i, j) not in d:
			print(bm + cm)
			exit()
print(bm + cm - 1)


ans = 0
(h, w, m) = map(int, input().split())
d = list()
from collections import defaultdict
r = defaultdict(int)
c = defaultdict(int)
r = [0] * (h + 1)
c = [0] * (w + 1)
for i in range(m):
	(a, b) = map(int, input().split())
	d += ((a, b),)
	r[a] += 1
	c[b] += 1
R = max(r)
C = max(c)
x = 0
nr = r.count(R)
nc = c.count(C)
for i in range(m):
	(a, b) = d[i]
	if r[a] == R and c[b] == C:
		x += 1
ans = R + C
if x == nr * nc:
	ans -= 1
print(ans)


import sys
input = sys.stdin.readline
(h, w, m) = map(int, input().split())
p = [0] * h
q = [0] * w
lis = set()
for i in range(m):
	(a, b) = map(int, input().split())
	p[a - 1] += 1
	q[b - 1] += 1
	lis.add(10 ** 6 * (a - 1) + b - 1)
P = max(p)
Q = max(q)
r = []
l = []
for i in range(h):
	if p[i] == P:
		r.append(i)
for i in range(w):
	if q[i] == Q:
		l.append(i)
if len(r) * len(l) > m:
	print(P + Q)
	exit()
f = 0
for x in r:
	for y in l:
		if x * 10 ** 6 + y in lis:
			continue
		else:
			f = 1
			break
print(P + Q - 1 + f)


from collections import *
(h, w, m) = map(int, input().split())
mh = [0 for _ in range(h)]
mw = [0 for _ in range(w)]
z = []
for _ in range(m):
	(x, y) = map(int, input().split())
	z.append((x - 1, y - 1))
	mh[x - 1] += 1
	mw[y - 1] += 1
hc = Counter(mh)
wc = Counter(mw)
hm = max(mh)
wm = max(mw)
ans = hm + wm
tmp = 0
for (x, y) in z:
	if mh[x] + mw[y] == ans:
		tmp += 1
if tmp == hc[hm] * wc[wm]:
	print(ans - 1)
else:
	print(ans)


(H, W, M) = list(map(int, input().split()))
h_sum = [0] * H
w_sum = [0] * W
point_list = set()
for _ in range(M):
	(h, w) = list(map(int, input().split()))
	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:
			print(ans)
			return
print(ans - 1)


import sys
input = sys.stdin.readline
(H, W, M) = map(int, input().split())
vert = [0] * (2 * W)

def update(i, d):
	i += W
	vert[i] += d
	while i > 1:
		i >>= 1
		vert[i] = max(vert[i * 2], vert[i * 2 + 1])
lines = [[] for _ in range(H)]
for _ in range(M):
	(y, x) = map(lambda s: int(s) - 1, input().split())
	lines[y].append(x)
	update(x, 1)
best = 0
for l in lines:
	for x in l:
		update(x, -1)
	best = max(best, len(l) + vert[1])
	for x in l:
		update(x, 1)
print(best)


import sys
import numpy as np

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) = map(int, input().split())
bom_list = []
h_list = [0] * h
w_list = [0] * w
for i in range(m):
	(a, b) = map(int, input().split())
	bom_list.append([a - 1, b - 1])
	h_list[a - 1] += 1
	w_list[b - 1] += 1
max_h = max(h_list)
max_w = max(w_list)
ans = max_h + max_w
count = 0
for bom in bom_list:
	if h_list[bom[0]] == max_h and w_list[bom[1]] == max_w:
		count += 1
if h_list.count(max_h) * w_list.count(max_w) == count:
	ans -= 1
print(ans)


from collections import defaultdict
(H, W, M) = map(int, input().split())
hs = [0] * H
ws = [0] * W
D = defaultdict(int)
for i in range(M):
	(h, w) = map(int, input().split())
	hs[h - 1] += 1
	ws[w - 1] += 1
	D[h - 1, w - 1] += 1
hmax = max(hs)
wmax = max(ws)
Hs = []
Ws = []
for h in range(H):
	if hmax == hs[h]:
		Hs.append(h)
for w in range(W):
	if wmax == ws[w]:
		Ws.append(w)
for h in Hs:
	for w in Ws:
		if D[h, w] == 0:
			print(hmax + wmax)
			exit()
print(hmax + wmax - 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()


import sys
(h, w, m) = map(int, input().split())
row = [0] * h
col = [0] * w
bomb = set()
for x in range(m):
	(H, W) = map(int, input().split())
	bomb.add((H - 1, W - 1))
	row[H - 1] += 1
	col[W - 1] += 1
maxrow = max(row)
maxcol = max(col)
ans = maxcol + maxrow - 1
(p, q) = ([], [])
for i in range(h):
	if row[i] == maxrow:
		p.append(i)
for i in range(w):
	if col[i] == maxcol:
		q.append(i)
for i in p:
	for j in q:
		if (i, j) not in bomb:
			print(ans + 1)
			exit()
print(ans)


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]
for h in HL:
	for w in WL:
		if not (h, w) in S:
			print(r + c)
			return
print(r + c - 1)


from collections import defaultdict
(H, W, M) = list(map(int, input().split()))
h = [0] * H
w = [0] * W
hw = defaultdict(set)
for _ in range(M):
	(a, b) = list(map(int, input().split()))
	h[a - 1] += 1
	w[b - 1] += 1
	hw[a - 1].add(b - 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:
		if y not in hw[x]:
			print(hm + wm)
			exit()
else:
	print(hm + wm - 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())
table = []
sum_rows = [0 for i in range(h)]
sum_cols = [0 for i in range(w)]
for i in range(m):
	(h_, w_) = map(int, input().split())
	table.append((h_, w_))
	sum_rows[h_ - 1] += 1
	sum_cols[w_ - 1] += 1
r = max(sum_rows)
c = max(sum_cols)
ans_ = r + c
count = 0
for i in range(m):
	if ans_ == sum_rows[table[i][0] - 1] + sum_cols[table[i][1] - 1]:
		count += 1
if count == sum_rows.count(r) * sum_cols.count(c):
	print(ans_ - 1)
else:
	print(ans_)


(h, w, m) = map(int, input().split())
x = [0] * h
y = [0] * w
c = []
for _ in range(m):
	(a, b) = map(int, input().split())
	x[a - 1] += 1
	y[b - 1] += 1
	c += [(a - 1, b - 1)]
mx = max(x)
my = max(y)
cnt = 0
for (i, j) in c:
	if x[i] == mx and y[j] == my:
		cnt += 1
print(mx + my - (cnt == x.count(mx) * y.count(my)))


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
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))
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
	for (k2, v2) in dic2:
		if v2 < max2:
			break
		if (k1, k2) in s:
			continue
		ans = max(ans, v1 + v2)
		break
print(ans)


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
Y = [0] * w
for (a, b) in bomb:
	X[a] += 1
	Y[b] += 1
(maxX, maxY) = (max(X), max(Y))
R = [h for (h, x) in enumerate(X) if x == maxX]
C = [w for (w, y) in enumerate(Y) if y == maxY]
bomb = set(bomb)
for r in R:
	for c in C:
		if (r, c) not in bomb:
			print(maxX + maxY)
			exit()
print(maxX + maxY - 1)


(H, W, M) = map(int, input().split())
HW = []
for _ in range(M):
	HW.append(list(map(int, input().split())))
A = [0] * (H + 1)
B = [0] * (W + 1)
for (h, w) in HW:
	A[h] += 1
	B[w] += 1
a = max(A)
b = max(B)
cnt = A.count(a) * B.count(b) - len([0 for (h, w) in HW if A[h] == a and B[w] == b])
print(a + b - (cnt == 0))


(h, w, m) = map(int, input().split())
lh = [0] * h
lw = [0] * w
l = set()
for i in range(m):
	(h1, w1) = input().split()
	l.add(h1 + '_' + w1)
	lh[int(h1) - 1] += 1
	lw[int(w1) - 1] += 1
hmax = max(lh)
wmax = max(lw)
lh2 = []
lw2 = []
for i in range(h):
	if lh[i] == hmax:
		lh2.append(i)
for i in range(w):
	if lw[i] == wmax:
		for m in lh2:
			if str(m + 1) + '_' + str(i + 1) not in l:
				print(hmax + wmax)
				exit()
print(hmax + wmax - 1)


(H, W, m) = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
(row, col) = ([0] * H, [0] * W)
for (h, w) in hw:
	row[h - 1] += 1
	col[w - 1] += 1
(rowmax, colmax) = (max(row), max(col))
cnt = row.count(rowmax) * col.count(colmax)
for (h, w) in hw:
	if row[h - 1] == rowmax and col[w - 1] == colmax:
		cnt -= 1
print(rowmax + colmax - (cnt == 0))


(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)


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))
	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()


(h, w, m) = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
hlist = [0] * (h + 1)
wlist = [0] * (w + 1)
for (x, y) in hw:
	hlist[x] += 1
	wlist[y] += 1
hmax = max(hlist)
h_index = {n for (n, v) in enumerate(hlist) if v == hmax}
wmax = max(wlist)
w_index = {n for (n, v) in enumerate(wlist) if v == wmax}
count = sum((x in h_index and y in w_index for (x, y) in hw))
print(hmax + wmax - (len(h_index) * len(w_index) == count))


(R, C, T) = map(int, input().split())
RC = []
for _ in range(T):
	RC.append(list(map(int, input().split())))
TR = [0] * (R + 1)
TC = [0] * (C + 1)
mxr = 0
mxc = 0
for (r, c) in RC:
	TR[r] += 1
	TC[c] += 1
	if TR[r] > mxr:
		mxr = TR[r]
	if TC[c] > mxc:
		mxc = TC[c]
ct = TR.count(mxr) * TC.count(mxc) - len([0 for (r, c) in RC if TR[r] == mxr and TC[c] == mxc])
print(mxc + mxr - (ct == 0))


import sys
(h, w, m) = map(int, input().split(' '))
H = [0 for _ in range(h + 1)]
W = [0 for _ in range(w + 1)]
bomb = set()
for m in range(m):
	(i, j) = map(int, input().split(' '))
	bomb.add((i, j))
	H[i] += 1
	W[j] += 1
max_h = max(H)
max_w = max(W)
target_h = [i for (i, v) in enumerate(H) if v == max_h]
target_w = [i for (i, v) in enumerate(W) if v == max_w]
for m in target_h:
	for n in target_w:
		if (m, n) not in bomb:
			print(max_h + max_w)
			sys.exit()
print(max_h + max_w - 1)


(H, W, M) = map(int, input().split())
hw = set()
(cnt_h, cnt_w) = ([0] * H, [0] * W)
for i in range(M):
	(x, y) = map(int, input().split())
	hw.add((x - 1, y - 1))
	cnt_h[x - 1] += 1
	cnt_w[y - 1] += 1
(max_h, max_w) = (max(cnt_h), max(cnt_w))
h_list = [h for h in range(H) if cnt_h[h] == max_h]
w_list = [w for w in range(W) if cnt_w[w] == max_w]
res = max_h + max_w - 1
for h in h_list:
	for w in w_list:
		if (h, w) not in hw:
			print(res + 1)
			exit()
print(res)


(H, W, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
(hl, wl) = ([0] * H, [0] * W)
for (i, j) in A:
	hl[i - 1] += 1
	wl[j - 1] += 1
(mt, mh) = (max(hl), max(wl))
a = 0
for (i, j) in A:
	if hl[i - 1] == mt and wl[j - 1] == mh:
		a += 1
print(mt + mh - 1 if a == hl.count(mt) * wl.count(mh) else mt + mh)


(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())
xs = [0] * H
ys = [0] * W
s = set()
for _ in range(m):
	(h, w) = map(int, input().split())
	h -= 1
	w -= 1
	xs[h] += 1
	ys[w] += 1
	s.add((h, w))
mx = max(xs)
my = max(ys)
mxs = set()
for i in range(H):
	if xs[i] == mx:
		mxs.add(i)
mys = set()
for i in range(W):
	if ys[i] == my:
		mys.add(i)
for x in mxs:
	for y in mys:
		if not (x, y) in s:
			print(mx + my)
			exit()
print(mx + my - 1)


from collections import Counter
(H, W, M) = list(map(int, input().split()))
h = [0] * M
w = [0] * M
for i in range(M):
	(h[i], w[i]) = list(map(int, input().split()))
hc = Counter(h)
wc = Counter(w)
hmax = max(hc.values())
wmax = max(wc.values())
lh = {k[0] for k in hc.items() if k[1] == hmax}
lw = {k[0] for k in wc.items() if k[1] == wmax}
ct = 0
for i in range(M):
	if h[i] in lh and w[i] in lw:
		ct += 1
if ct >= len(lh) * len(lw):
	print(hmax + wmax - 1)
else:
	print(hmax + wmax)


(H, W, M) = map(int, input().split())
R = [0] * H
C = [0] * W
L = []
for _ in range(M):
	(h, w) = map(int, input().split())
	R[h - 1] += 1
	C[w - 1] += 1
	L.append([h - 1, w - 1])
r = max(R)
c = max(C)
print(r + c - (R.count(r) * C.count(c) == sum((R[h] + C[w] == r + c for (h, w) in L))))


from collections import Counter
(H, W, M) = map(int, input().split())
hl = []
wl = []
hwl = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	hl.append(h)
	wl.append(w)
	hwl.add((h, w))
hl = Counter(hl).most_common()
wl = Counter(wl).most_common()
hm = hl[0][1]
wm = wl[0][1]
for (h, hc) in hl:
	if hc < hm:
		break
	for (w, wc) in wl:
		if wc < wm:
			break
		if (h, w) not in hwl:
			print(hm + wm)
			exit()
print(hm + wm - 1)


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())
bomb = [list(map(int, input().split())) for i in range(m)]
num_h = [0] * (h + 1)
num_w = [0] * (w + 1)
bomb_set = set()
for (hi, wi) in bomb:
	num_h[hi] += 1
	num_w[wi] += 1
	bomb_set.add((hi, wi))
max_h = max(num_h)
max_w = max(num_w)
max_hs = [k for (k, v) in enumerate(num_h) if v == max_h]
max_ws = [k for (k, v) in enumerate(num_w) if v == max_w]
result = max_h + max_w
for i in max_hs:
	for j in max_ws:
		if (i, j) not in bomb_set:
			print(result)
			exit(0)
print(result - 1)


from collections import defaultdict
(a, b, m) = map(int, input().split())
r = defaultdict(int)
c = defaultdict(int)
d = defaultdict(int)
for i in range(m):
	(x, y) = map(int, input().split())
	d[x, y] = 1
	r[x] += 1
	c[y] += 1
z = list()
zz = list()
x = max(r, key=r.get)
y = max(c, key=c.get)
for i in r.keys():
	if r[i] == r[x]:
		z.append(i)
for i in c.keys():
	if c[i] == c[y]:
		zz.append(i)
flag = False
for i in z:
	for j in zz:
		if d[i, j] == 0:
			flag = True
			break
if flag == False:
	print(r[x] + c[y] - 1)
else:
	print(r[x] + c[y])


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))


(h, w, m) = map(int, input().split())
r = [0] * h
c = [0] * w
s = set()
for i in range(m):
	(hi, wi) = map(int, input().split())
	hi -= 1
	wi -= 1
	r[hi] += 1
	c[wi] += 1
	s.add((hi, wi))
a = max(r)
b = max(c)
p = []
q = []
for i in range(h):
	if r[i] == a:
		p.append(i)
for j in range(w):
	if c[j] == b:
		q.append(j)
k = 1
for i in p:
	for j in q:
		if (i, j) not in s:
			k = 0
			break
	if k == 0:
		break
print(a + b - k)


(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)


(W, H, M) = [int(_) for _ in input().split()]
HW = [[int(_) for _ in input().split()] for i in range(M)]
yoko = [0] * W
tate = [0] * H
for hw in HW:
	yoko[hw[0] - 1] += 1
	tate[hw[1] - 1] += 1
my = max(yoko)
mt = max(tate)
ans = mt + my
cu = yoko.count(my) * tate.count(mt)
c = 0
for hw in HW:
	if yoko[hw[0] - 1] == my and tate[hw[1] - 1] == mt:
		c += 1
if c == cu:
	ans -= 1
print(ans)


import heapq
(H, W, M) = map(int, input().split())
hw = set([tuple(map(int, input().split())) for i in range(M)])
D1 = [0] * H
D2 = [0] * W
for (x, y) in hw:
	x -= 1
	y -= 1
	D1[x] += 1
	D2[y] += 1
X = max(D1)
Y = max(D2)
h = [x for x in range(H) if D1[x] == X]
w = [x for x in range(W) if D2[x] == Y]
ans = X + Y - 1
for x in h:
	for y in w:
		if (x + 1, y + 1) not in hw:
			ans += 1
			print(ans)
			exit(0)
print(ans)


(h, w, m) = map(int, input().split())
table = []
H = [0] * h
W = [0] * w
li_h = []
li_w = []
for i in range(m):
	(h1, w1) = list(map(int, input().split()))
	table.append((h1 - 1, w1 - 1))
	H[h1 - 1] += 1
	W[w1 - 1] += 1
h_flag = 0
w_flag = 0
Hm = max(H)
Wm = max(W)
Hh = [i for (i, x) in enumerate(H) if x == Hm]
Ww = [i for (i, x) in enumerate(W) if x == Wm]
cnt = 0
for (h, w) in table:
	if H[h] == Hm and W[w] == Wm:
		cnt += 1
if cnt < len(Hh) * len(Ww):
	print(Hm + Wm)
else:
	print(Hm + Wm - 1)


import sys
(H, W, M) = map(int, input().split())
(h_list, w_list) = ([0] * H, [0] * W)
check = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	check.add((h - 1, w - 1))
	h_list[h - 1] += 1
	w_list[w - 1] += 1
(h_max, w_max) = (max(h_list), max(w_list))
h_bom = [i for i in range(H) if h_list[i] == h_max]
w_bom = [i for i in range(W) if w_list[i] == w_max]
for h in h_bom:
	for w in w_bom:
		if not (h, w) in check:
			print(h_max + w_max)
			sys.exit()
print(h_max + w_max - 1)


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)


(H, W, M) = map(int, input().split())
bomb = []
h = [0] * H
w = [0] * W
for i in range(M):
	(hi, wi) = map(int, input().split())
	h[hi - 1] += 1
	w[wi - 1] += 1
	bomb.append([hi, wi])
maxh = max(h)
maxw = max(w)
ans = maxh + maxw
lh = []
lw = []
for i in range(len(h)):
	if h[i] == maxh:
		lh.append(i + 1)
for i in range(len(w)):
	if w[i] == maxw:
		lw.append(i + 1)
a = 0
for i in range(M):
	if ans == h[bomb[i][0] - 1] + w[bomb[i][1] - 1]:
		a += 1
if a == len(lh) * len(lw):
	print(ans - 1)
else:
	print(ans)


((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 sys
input = lambda : sys.stdin.readline().rstrip()
(H, W, M) = map(int, input().split())
X = [0] * H
Y = [0] * W
Z = []
for _ in range(M):
	(h, w) = map(int, input().split())
	(h, w) = (h - 1, w - 1)
	X[h] += 1
	Y[w] += 1
	Z.append((h, w))
mX = max(X)
mY = max(Y)
cX = X.count(mX)
cY = Y.count(mY)
c = 0
for (h, w) in Z:
	if X[h] == mX and Y[w] == mY:
		c += 1
print(mX + mY - (0 if c < cX * cY else 1))


(H, W, M) = map(int, input().split())
hk = [[0, i] for i in range(H + 1)]
wk = [[0, j] for j in range(W + 1)]
s = set()
for i in range(M):
	(h, w) = map(int, input().split())
	hk[h][0] += 1
	wk[w][0] += 1
	s.add((h, w))
hk.sort(reverse=True)
wk.sort(reverse=True)
colmax = wk[0][0]
ans = 0
for (lowacc, i) in hk:
	if lowacc + colmax <= ans:
		break
	for (colacc, j) in wk:
		if lowacc + colacc <= ans:
			break
		else:
			ans = max(ans, lowacc + colacc - ((i, j) in s))
print(ans)


(h, w, m) = map(int, input().split())
a = [0] * h
b = [0] * w
hw = []
for _ in range(m):
	(hh, ww) = map(int, input().split())
	hw += ((hh - 1, ww - 1),)
	a[hh - 1] += 1
	b[ww - 1] += 1
ma = max(a)
mb = max(b)
cnt = 0
for (i, j) in hw:
	if a[i] == ma and b[j] == mb:
		cnt += 1
if cnt == a.count(ma) * b.count(mb):
	print(ma + mb - 1)
else:
	print(ma + mb)


(H, W, M) = map(int, input().split())
nh = [0] * H
nw = [0] * W
boms = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	nh[h - 1] += 1
	nw[w - 1] += 1
	boms.add((h - 1, w - 1))
maxh = max(nh)
maxw = max(nw)
i_indexes = []
for i in range(H):
	if nh[i] == maxh:
		i_indexes.append(i)
j_indexes = []
for j in range(W):
	if nw[j] == maxw:
		j_indexes.append(j)
for i in i_indexes:
	for j in j_indexes:
		if (i, j) in boms:
			continue
		print(maxh + maxw)
		exit()
print(maxh + maxw - 1)


(H, W, M) = map(int, input().split())
A = [0] * H
B = [0] * W
D = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	A[h - 1] += 1
	B[w - 1] += 1
	D.add((h - 1, w - 1))
(a, b) = (max(A), max(B))
res = a + b - 1
(E, F) = ([], [])
for i in range(H):
	if A[i] == a:
		E.append(i)
for j in range(W):
	if B[j] == b:
		F.append(j)
for i in E:
	for j in F:
		if (i, j) not in D:
			print(res + 1)
			exit()
print(res)


(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)
			exit()
print(h_max + w_max - 1)


(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)


(h, w, m) = map(int, input().split())
row = [0 for i in range(h)]
col = [0 for i in range(w)]
a = []
for i in range(m):
	(r, c) = map(lambda x: int(x) - 1, input().split())
	a.append([r, c])
	row[r] += 1
	col[c] += 1
rmax = max(row)
cmax = max(col)
ans = rmax + cmax
flag = row.count(rmax) * col.count(cmax)
for (i, j) in a:
	if row[i] == rmax and col[j] == cmax:
		flag -= 1
if flag == 0:
	ans -= 1
print(ans)


from collections import *
((h, w, m), *z) = [tuple(map(int, o.split())) for o in open(0)]
s = set(z)
(y, x) = [Counter(t).most_common() for t in zip(*z)]
(a, b) = (y[0][1], x[0][1])
p = [i for (i, v) in y if v == a]
q = [i for (i, v) in x if v == b]
for i in p:
	for j in q:
		if (i, j) not in s:
			exit(print(a + b))
print(a + b - 1)


import itertools
(H, W, M) = map(int, input().split())
d = {}
nh = [0] * H
nw = [0] * W
for _ in range(M):
	(h, w) = map(int, input().split())
	h -= 1
	w -= 1
	d[h, w] = 1
	nh[h] += 1
	nw[w] += 1
hmax = max(nh)
wmax = max(nw)
is_h = [i for i in range(H) if nh[i] == hmax]
is_w = [i for i in range(W) if nw[i] == wmax]
for (i_h, i_w) in itertools.product(is_h, is_w):
	if (i_h, i_w) not in d:
		print(hmax + wmax)
		break
else:
	print(hmax + wmax - 1)


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())
X = [0 for i in range(H)]
Y = [0 for j in range(W)]
s = set([])
for i in range(M):
	(h, w) = map(int, input().split())
	X[h - 1] += 1
	Y[w - 1] += 1
	s.add((h - 1, w - 1))
mX = max(X)
mY = max(Y)
I = [i for i in range(H) if X[i] == mX]
J = [j for j in range(W) if Y[j] == mY]
flag = 0
for i in I:
	for j in J:
		if {(i, j)} <= s:
			continue
		flag = 1
		print(mX + mY)
		break
	if flag == 1:
		break
if flag == 0:
	print(mX + mY - 1)


(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)


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()


(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)


(w, h, m) = [int(_) for _ in input().split()]
hw = [[int(_) for _ in input().split()] for i in range(m)]
yoko = [0 for i in range(w)]
tate = [0 for j in range(h)]
for i in range(m):
	yoko[hw[i][0] - 1] += 1
	tate[hw[i][1] - 1] += 1
mt = max(tate)
my = max(yoko)
cu = yoko.count(my) * tate.count(mt)
c = 0
for i in range(m):
	if yoko[hw[i][0] - 1] == my and tate[hw[i][1] - 1] == mt:
		c += 1
ans = mt + my
if c == cu:
	ans -= 1
print(ans)


f = lambda : map(int, input().split())
(H, W, M) = f()
g = [set() for _ in range(H)]
ch = [0] * H
cw = [0] * W
for _ in range(M):
	(h, w) = f()
	g[h - 1].add(w - 1)
	ch[h - 1] += 1
	cw[w - 1] += 1
mh = max(ch)
mw = max(cw)
lh = [i for i in range(H) if ch[i] == mh]
lw = [i for i in range(W) if cw[i] == mw]
c = mh + mw
for i in lh:
	if len(g[i]) < 1:
		exit(print(c))
	for j in lw:
		if j not in g[i]:
			exit(print(c))
print(c - 1)


(H, W, M) = map(int, input().split())
bomb = []
h_sum = [0] * W
w_sum = [0] * H
for _ in range(M):
	(h, w) = map(int, input().split())
	bomb.append((h, w))
	h_sum[w - 1] += 1
	w_sum[h - 1] += 1
max_h = max(h_sum)
max_w = max(w_sum)
target_cnt = h_sum.count(max_h) * w_sum.count(max_w)
for (h, w) in bomb:
	if h_sum[w - 1] == max_h and w_sum[h - 1] == max_w:
		target_cnt -= 1
if target_cnt == 0:
	print(max_h + max_w - 1)
else:
	print(max_h + max_w)


import sys
input = sys.stdin.readline
(h, w, m) = map(int, input().split())
G = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
A = [0] * h
B = [0] * w
for (i, j) in G:
	A[i] += 1
	B[j] += 1
ans = 0
max_A = max(A)
max_B = max(B)
cnt = A.count(max_A) * B.count(max_B)
for (i, j) in G:
	if A[i] == max_A and B[j] == max_B:
		cnt -= 1
if cnt == 0:
	print(max_A + max_B - 1)
else:
	print(max_A + max_B)


(h, w, m) = map(int, input().split())
bomb = [list(map(int, input().split())) for i in range(m)]
cnt_h = [0] * h
cnt_w = [0] * w
for (h, w) in bomb:
	cnt_h[h - 1] += 1
	cnt_w[w - 1] += 1
mx_h = max(cnt_h)
mx_w = max(cnt_w)
mxh_ind = cnt_h.count(mx_h)
mxw_ind = cnt_w.count(mx_w)
hit = 0
for (h, w) in bomb:
	if cnt_h[h - 1] == mx_h and cnt_w[w - 1] == mx_w:
		hit += 1
if hit == mxh_ind * mxw_ind:
	print(mx_h + mx_w - 1)
else:
	print(mx_h + mx_w)


(H, W, M) = map(int, input().split())
P = [0] * (H + 1)
Q = [0] * (W + 1)
A = set()
for k in range(M):
	(a, b) = map(int, input().split())
	P[a] += 1
	Q[b] += 1
	A.add((a, b))
Pmax = max(P)
Qmax = max(Q)
Pindex = []
Qindex = []
for i in range(H + 1):
	if P[i] == Pmax:
		Pindex.append(i)
for i in range(W + 1):
	if Q[i] == Qmax:
		Qindex.append(i)
ans = Pmax + Qmax - 1
key = 0
for x in Pindex:
	for y in Qindex:
		if (x, y) not in A:
			ans += 1
			key = 1
			break
	if key == 1:
		break
print(ans)


(H, W, M) = map(int, input().split())
sumh = [0] * H
sumw = [0] * W
bomb = []
for i in range(M):
	(h, w) = map(int, input().split())
	sumh[h - 1] += 1
	sumw[w - 1] += 1
	bomb.append((h, w))
maxh = max(sumh)
maxw = max(sumw)
ch = sumh.count(maxh)
cw = sumw.count(maxw)
cnt = 0
for (h, w) in bomb:
	if sumh[h - 1] == maxh and sumw[w - 1] == maxw:
		cnt += 1
if cnt == ch * cw:
	print(maxh + maxw - 1)
else:
	print(maxh + maxw)


from collections import *
(h, w, m) = map(int, input().split())
d = defaultdict(int)
a = [0] * h
b = [0] * w
for _ in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	a[x] += 1
	b[y] += 1
	d[x, y] += 1
ma = max(a)
mb = max(b)
ind_x = [i for (i, j) in enumerate(a) if j == ma]
ind_y = [i for (i, j) in enumerate(b) if j == mb]
for x in ind_x:
	for y in ind_y:
		if d[x, y] == 0:
			print(ma + mb)
			exit()
print(ma + mb - 1)


(h, w, m) = map(int, input().split())
retu = [0 for i in range(w)]
gyo = [0 for i in range(h)]
basyo = set()
for i in range(m):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	retu[b] += 1
	gyo[a] += 1
	basyo.add((a, b))
t = max(retu)
mare = [i for (i, v) in enumerate(retu) if v == t]
s = max(gyo)
magy = [i for (i, v) in enumerate(gyo) if v == s]
for i in magy:
	for j in mare:
		if not (i, j) in basyo:
			print(s + t)
			exit()
print(s + t - 1)


(H, W, M) = map(int, input().split())
HB = [0] * H
WB = [0] * W
place = []
for i in range(M):
	(h, w) = map(int, input().split())
	place.append((h, w))
	HB[h - 1] += 1
	WB[w - 1] += 1
m_hb = max(HB)
m_wb = max(WB)
result = m_hb + m_wb
count = 0
for (x, y) in place:
	if HB[x - 1] == m_hb and WB[y - 1] == m_wb:
		count += 1
if HB.count(m_hb) * WB.count(m_wb) <= count:
	result -= 1
print(result)


(h, w, m) = map(int, input().split())
b = []
x = [0 for _ in range(w)]
y = [0 for _ in range(h)]
for i in range(m):
	(bh, bw) = map(int, input().split())
	bh -= 1
	bw -= 1
	b.append((bh, bw))
	x[bw] += 1
	y[bh] += 1
mxx = max(x)
mxy = max(y)
cmxb = 0
for (by, bx) in b:
	if y[by] + x[bx] == mxx + mxy:
		cmxb += 1
cmxx = 0
for xi in x:
	if xi == mxx:
		cmxx += 1
cmxy = 0
for yi in y:
	if yi == mxy:
		cmxy += 1
if cmxb == cmxx * cmxy:
	print(mxx + mxy - 1)
else:
	print(mxx + mxy)


(h, w, m) = map(int, input().split())
a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
mh = [0 for i in range(h)]
mw = [0 for j in range(w)]
for (i, j) in a:
	mh[i] += 1
	mw[j] += 1
hmax = max(mh)
wmax = max(mw)
ans = hmax + wmax
flag = mh.count(hmax) * mw.count(wmax)
for (i, j) in a:
	if mh[i] == hmax and mw[j] == wmax:
		flag -= 1
if flag == 0:
	print(ans - 1)
else:
	print(ans)


(h, w, m) = map(int, input().split())
sumw = [set() for _ in range(w)]
sumh = [0] * h
for _ in range(m):
	(hi, wi) = map(int, input().split())
	hi -= 1
	wi -= 1
	sumh[hi] += 1
	sumw[wi].add(hi)
maxi = 0
for i in range(w):
	maxi = max(maxi, len(sumw[i]))
s = set([i for i in range(h)])
for i in range(w):
	if len(sumw[i]) == maxi:
		s = s & sumw[i]
ans = 0
for i in range(h):
	if i not in s:
		ans = max(ans, sumh[i] + maxi)
	else:
		ans = max(ans, sumh[i] + maxi - 1)
print(ans)


I = lambda : list(map(int, input().split()))
(h, w, m) = I()
x = {}
y = {}
l = []
dic = {}
for i in range(m):
	(a, b) = I()
	l.append([a, b])
	dic[a, b] = 1
	x[a] = x.get(a, 0) + 1
	y[b] = y.get(b, 0) + 1
(p, q) = (max(x.values()), max(y.values()))
(a, b) = ([i for i in x if x[i] == p], [i for i in y if y[i] == q])
an = p + q
fl = 0
for i in a:
	for j in b:
		if dic.get((i, j), -1) == -1:
			fl = 1
			break
	if fl:
		break
an -= fl == 0
print(an)


(H, W, M) = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = set()
for i in range(M):
	(hh, ww) = map(int, input().split())
	h[hh - 1] += 1
	w[ww - 1] += 1
	DP.add((hh - 1, ww - 1))
hhh = max(h)
www = max(w)
hhhh = [i for (i, x) in enumerate(h) if x == hhh]
wwww = [i for (i, x) in enumerate(w) if x == www]
check = 0
for i in hhhh:
	for j in wwww:
		if (i, j) not in DP:
			print(hhh + www)
			exit()
print(hhh + www - 1)


(h, w, m) = map(int, input().split())
H = [0] * (h + 1)
W = [0] * (w + 1)
d = {}
for i in range(m):
	(x, y) = map(int, input().split())
	d[x, y] = 1
	H[x] += 1
	W[y] += 1
mh = max(H)
mw = max(W)
la = []
lb = []
for i in range(h + 1):
	if H[i] == mh:
		la.append(i)
for i in range(w + 1):
	if W[i] == mw:
		lb.append(i)
ans = mh + mw - 1
for i in la:
	for j in lb:
		if (i, j) not in d:
			print(ans + 1)
			exit()
print(ans)


(h, w, m) = map(int, input().split())
hh = [[0, i] for i in range(h)]
ww = [[0, i] for i in range(w)]
hw = set()
for _ in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	hh[a][0] += 1
	ww[b][0] += 1
	hw.add((a, b))
ww.sort(reverse=1)
s = ww[0][0]
w = []
for (x, j) in ww:
	if x == s:
		w.append(j)
hh.sort(reverse=1)
ans = 0
t = max(hh)[0]
for j in w:
	for (x, i) in hh:
		if x != t:
			break
		if (i, j) in hw:
			ans = s + x - 1
		else:
			exit(print(s + x))
print(ans)


(h, w, m) = map(int, input().split())
bomb = []
x = [0] * (h + 1)
y = [0] * (w + 1)
for i in range(m):
	(h1, w1) = map(int, input().split())
	x[h1] += 1
	y[w1] += 1
	bomb.append((h1, w1))
maxx = max(x)
maxy = max(y)
r = []
c = []
bomb = set(bomb)
for i in range(1, h + 1):
	if x[i] == maxx:
		r.append(i)
for j in range(1, w + 1):
	if y[j] == maxy:
		c.append(j)
for j in r:
	for k in c:
		if (j, k) not in bomb:
			print(maxx + maxy)
			exit()
print(maxx + maxy - 1)


(H, W, M) = map(int, input().split())
(h, w, bomb) = ([0] * H, [0] * W, [])
for i in range(M):
	(a, b) = map(int, input().split())
	bomb.append((a - 1, b - 1))
	h[a - 1] += 1
	w[b - 1] += 1
max_h = max(h)
max_w = max(w)
bomb_and_max = 0
for (i, j) in bomb:
	if h[i] == max_h and w[j] == max_w:
		bomb_and_max += 1
if bomb_and_max == h.count(max_h) * w.count(max_w):
	print(max_h + max_w - 1)
else:
	print(max_h + max_w)


(H, W, M) = map(int, input().split())
hc = [0] * H
wc = [0] * W
d = {}
for _ in range(M):
	(h, w) = map(lambda x: int(x) - 1, input().split())
	hc[h] += 1
	wc[w] += 1
	d[h, w] = 1
maxh = max(hc)
maxw = max(wc)
result = max(maxh + maxw - 1, 0)
wi = [i for i in range(W) if wc[i] == maxw]
for h in [i for i in range(H) if hc[i] == maxh]:
	for w in wi:
		if (h, w) not in d:
			result = maxh + maxw
			break
print(result)


import sys
input = sys.stdin.readline
(h, w, m) = map(int, input().split())
a = [0] * h
b = [0] * w
(H, W) = ([0] * m, [0] * m)
for i in range(m):
	(H[i], W[i]) = map(int, input().split())
	H[i] -= 1
	W[i] -= 1
	a[H[i]] += 1
	b[W[i]] += 1
a1 = max(a)
a2 = max(b)
s = sum((i == a1 for i in a))
t = sum((i == a2 for i in b))
ans = 0
for i in range(m):
	if a[H[i]] == a1 and b[W[i]] == a2:
		ans += 1
print(a1 + a2 - 1 if ans == s * t else a1 + a2)


(H, W, M) = map(int, input().split())
h = [0] * H
w = [0] * W
boms = set()
for _ in range(M):
	(x, y) = map(int, input().split())
	h[x - 1] += 1
	w[y - 1] += 1
	boms.add((x, y))
h_max = max(h)
w_max = max(w)
h_idx = [x + 1 for (x, y) in enumerate(h) if y == h_max]
w_idx = [x + 1 for (x, y) in enumerate(w) if y == w_max]
minus = -1
for x in h_idx:
	for y in w_idx:
		if not (x, y) in boms:
			minus = 0
			break
print(h_max + w_max + minus)


(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)


(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]
flag = 0
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) = map(int, input().split())
cx = [0] * w
cy = [0] * h
xy = set()
for _ in range(m):
	(y, x) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	cx[x] += 1
	cy[y] += 1
	xy.add((x, y))
xmx = max(cx)
ymx = max(cy)
xs = [x for x in range(w) if cx[x] == xmx]
ys = [y for y in range(h) if cy[y] == ymx]
ans = xmx + ymx - 1
ok = False
for y in ys:
	for x in xs:
		if (x, y) not in xy:
			ans += 1
			ok = True
			break
	if ok:
		break
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))
curMax = 0
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) = 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) = map(int, input().split())
bombs_h = [0] * H
bombs_w = [0] * W
B = []
for _ in range(M):
	(h, w) = map(lambda x: int(x) - 1, input().split())
	B.append((h, w))
	bombs_h[h] += 1
	bombs_w[w] += 1
max_h = max(bombs_h)
max_w = max(bombs_w)
hs = [i for (i, x) in enumerate(bombs_h) if x == max_h]
ws = [i for (i, x) in enumerate(bombs_w) if x == max_w]
k = len(hs) * len(ws)
cnt = 0
for (h, w) in B:
	if bombs_h[h] == max_h and bombs_w[w] == max_w:
		cnt += 1
ans = max_w + max_h - (cnt == k)
print(ans)


(h, w, m) = map(int, input().split())
mp = set()
hp = [0] * h
wp = [0] * w
for i in range(m):
	(a, b) = map(int, input().split())
	mp.add((a, b))
	l = [a, b]
	hp[l[0] - 1] += 1
	wp[l[1] - 1] += 1
maxhp = max(hp)
maxwp = max(wp)
hpdex = [i for (i, x) in enumerate(hp) if x == maxhp]
wpdex = [i for (i, x) in enumerate(wp) if x == maxwp]
for i in hpdex:
	for j in wpdex:
		if (i + 1, j + 1) not in mp:
			print(max(hp) + max(wp))
			exit()
print(max(hp) + max(wp) - 1)


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)


(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))


import sys
from collections import Counter
(H, W, M) = map(int, sys.stdin.readline().rstrip().split())
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))
hmax = max(hcnt)
wmax = max(wcnt)
crs = 0
for (i, j) in bomb:
	if hcnt[i] == hmax and wcnt[j] == wmax:
		crs += 1
if crs == Counter(hcnt)[hmax] * Counter(wcnt)[wmax]:
	print(hmax + wmax - 1)
else:
	print(hmax + wmax)


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)


(h, w, m) = map(int, input().split())
R = [0] * h
C = [0] * w
XY = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(m)]
for (x, y) in XY:
	R[x] += 1
	C[y] += 1
(maxR, maxC) = (max(R), max(C))
cnt0 = R.count(maxR) * C.count(maxC)
cnt1 = sum((R[x] == maxR and C[y] == maxC for (x, y) in XY))
print(maxR + maxC - int(cnt0 == cnt1))


(H, W, M) = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for (h, w) in hw:
	h_cnt[h] += 1
	w_cnt[w] += 1
h_mx = max(h_cnt)
w_mx = max(w_cnt)
cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for (h, w) in hw:
	val = h_cnt[h] + w_cnt[w]
	if val == h_mx + w_mx:
		cnt -= 1
if cnt:
	ans = h_mx + w_mx
else:
	ans = h_mx + w_mx - 1
print(ans)


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
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)
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
g = defaultdict(int)
(h, w, m) = map(int, input().split())
d = [0] * (3 * 10 ** 5 + 1)
e = [0] * (3 * 10 ** 5 + 1)
for i in range(m):
	(h, w) = map(int, input().split())
	g[h * (3 * 10 ** 5 + 1) + w] += 1
	d[h] += 1
	e[w] += 1
h1 = max(d)
w1 = max(e)
ans = h1 + w1
h = []
l = []
for i in range(3 * 10 ** 5 + 1):
	if d[i] == h1:
		h.append(i)
	if e[i] == w1:
		l.append(i)
for i in h:
	for j in l:
		if g[i * (3 * 10 ** 5 + 1) + j] == 0:
			print(ans)
			exit()
print(ans - 1)


(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)


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))


(H, W, M) = map(int, input().split())
bomb = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)]
cntRow = [0] * H
cntCol = [0] * W
for (h, w) in bomb:
	cntRow[h] += 1
	cntCol[w] += 1
mxR = max(cntRow)
mxC = max(cntCol)
R = set([h for h in range(H) if cntRow[h] == mxR])
C = set([w for w in range(W) if cntCol[w] == mxC])
ans = mxR + mxC
if len([0 for (h, w) in bomb if h in R and w in C]) == len(R) * len(C):
	ans -= 1
print(ans)


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()


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)


(h, w, m) = map(int, input().split())
R = [0] * h
C = [0] * w
XY = [tuple(map(int, input().split())) for i in range(m)]
X = [x - 1 for (x, y) in XY]
Y = [y - 1 for (x, y) in XY]
for (x, y) in zip(X, Y):
	R[x] += 1
	C[y] += 1
(maxR, maxC) = (max(R), max(C))
cnt0 = R.count(maxR) * C.count(maxC)
cnt1 = 0
for (x, y) in zip(X, Y):
	if R[x] == maxR and C[y] == maxC:
		cnt1 += 1
print(maxR + maxC - int(cnt0 == cnt1))


(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)
y_max = []
for i in range(H + 1):
	if Hmax == Hmax_temp[i]:
		y_max.append(i)
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)


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)


(H, W, M) = map(int, input().split())
h_cnt = [0] * H
w_cnt = [0] * W
hw = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]
for (h, w) in hw:
	h_cnt[h] += 1
	w_cnt[w] += 1
max_h = max(h_cnt)
max_w = max(w_cnt)
hs = [i for i in range(H) if h_cnt[i] == max_h]
ws = [i for i in range(W) if w_cnt[i] == max_w]
ans = max_h + max_w - 1
hw = set(hw)
for h in hs:
	for w in ws:
		if (h, w) not in hw:
			print(max_h + max_w)
			exit()
print(max_h + max_w - 1)


(h, w, m) = map(int, input().split())
objs = [tuple(map(int, input().split())) for i in range(m)]
setobj = set(objs)
(xs, ys) = zip(*objs)
from collections import Counter as co
(xs, ys) = (co(xs), co(ys))
(xim, yim) = (xs.most_common(1)[0][1], ys.most_common(1)[0][1])
A = len([1 for u in xs.values() if u == xim]) * len([1 for u in ys.values() if u == yim])
for (a, b) in setobj:
	if xs[a] == xim and ys[b] == yim:
		A -= 1
print(xim + yim - 1 + int(A > 0))


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]
otherwise = []
for i in range(m):
	if X[i] != most_common_x_index:
		otherwise.append(Y[i])
most_common_y = collections.Counter(otherwise).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_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]
otherwise = []
for i in range(m):
	if Y[i] != most_common_y_index:
		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))


import sys
input = sys.stdin.readline
(h, w, m) = map(int, input().split())
row = [0] * h
col = [0] * w
enemy = []
for i in range(m):
	(hh, ww) = map(lambda x: int(x) - 1, input().split())
	row[hh] += 1
	col[ww] += 1
	enemy.append((hh, ww))
enemy = set(enemy)
rmax = max(row)
cmax = max(col)
on_r = row.count(rmax)
on_c = col.count(cmax)
on = 0
for (hh, ww) in enemy:
	if row[hh] == rmax and col[ww] == cmax:
		on += 1
if on == on_r * on_c:
	print(rmax + cmax - 1)
else:
	print(rmax + cmax)


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())


(x, y, m) = map(int, input().split())
mat = set()
r = [0] * x
c = [0] * y
smx = 0
smy = 0
for _ in range(m):
	(p, q) = map(int, input().split())
	p -= 1
	q -= 1
	mat.add((p, q))
	r[p] += 1
	c[q] += 1
	smx = max(smx, r[p])
	smy = max(smy, c[q])
xs = []
ys = []
for i in range(x):
	if smx == r[i]:
		xs.append(i)
for i in range(y):
	if smy == c[i]:
		ys.append(i)
ans = smx + smy - 1
for h in xs:
	for w in ys:
		if (h, w) in mat:
			continue
		print(ans + 1)
		exit()
print(ans)


(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)


(h, w, m) = map(int, input().split())
g = [0] * h
l = [0] * w
b = []
for i in range(m):
	(x, y) = map(int, input().split())
	g[x - 1] += 1
	l[y - 1] += 1
	b.append((x - 1, y - 1))
mxg = max(g)
mxl = max(l)
mg = set([i for (i, x) in enumerate(g) if x == mxg])
ml = set([i for (i, x) in enumerate(l) if x == mxl])
c = 0
for (x, y) in b:
	if x in mg and y in ml:
		c += 1
print(mxg + mxl - (c == len(mg) * len(ml)))


(h, w, m) = map(int, input().split())
(H, W) = ([0] * h, [0] * w)
P = set()
for i in range(m):
	(y, x) = 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)
			exit()
print(mh + mw - 1)


from collections import Counter
(h, w, m) = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
hlst = [x for (x, _) in hw]
wlst = [x for (_, x) in hw]
hcnt = Counter(hlst)
wcnt = Counter(wlst)
(_, hmax) = hcnt.most_common(1)[0]
(_, wmax) = wcnt.most_common(1)[0]
hcand = set([k for (k, v) in hcnt.items() if v == hmax])
wcand = set([k for (k, v) in wcnt.items() if v == wmax])
ng = [(hh, ww) for (hh, ww) in hw if hh in hcand and ww in wcand]
if len(hcand) * len(wcand) > len(ng):
	print(hmax + wmax)
else:
	print(hmax + wmax - 1)


import sys
(H, W, M) = map(int, input().split())
A = [list(map(lambda x: int(x) - 1, 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)
			exit(0)
print(my + mx - 1)


(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)


(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)


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)
	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()


(H, W, M) = map(int, input().split())
(h, w) = map(list, zip(*[list(map(int, input().split())) for i in range(M)]))
from collections import Counter
(hc, wc) = (Counter(h), Counter(w))
(hx, wx) = (hc.most_common()[0][1], wc.most_common()[0][1])
(hl, wl) = (set([k for (k, v) in hc.items() if v == hx]), set([k for (k, v) in wc.items() if v == wx]))
x = sum([1 for i in range(M) if h[i] in hl and w[i] in wl])
print(hx + wx if len(hl) * len(wl) - x else hx + wx - 1)


(h, w, m) = (int(i) for i in input().split())
l1 = []
l2 = [0] * h
l3 = [0] * w
for i in range(m):
	(x, y) = (int(i) for i in input().split())
	l1.append((x, y))
	l2[x - 1] += 1
	l3[y - 1] += 1
m1 = max(l2)
m2 = max(l3)
m3 = max(m1, m2)
if m1 > m2:
	l4 = [0] * w
	k = l2.index(m1)
	for i in range(m):
		if l1[i][0] != k + 1:
			l4[l1[i][1] - 1] += 1
	k1 = max(l4)
	print(m3 + k1)
else:
	l4 = [0] * h
	k = l3.index(m2)
	for i in range(m):
		if l1[i][1] != k + 1:
			l4[l1[i][0] - 1] += 1
	k1 = max(l4)
	print(m3 + k1)


(H, W, M) = map(int, input().split())
h_lis = [0] * H
w_lis = [0] * W
hw_set = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	h_lis[h - 1] += 1
	w_lis[w - 1] += 1
	hw_set.add((h - 1, w - 1))
h_max = max(h_lis)
w_max = max(w_lis)
h_maxlis = [i for (i, x) in enumerate(h_lis) if x == h_max]
w_maxlis = [i for (i, x) in enumerate(w_lis) if x == w_max]
import sys
for hi in h_maxlis:
	for wi in w_maxlis:
		if (hi, wi) not in hw_set:
			print(h_max + w_max)
			sys.exit()
else:
	print(h_max + w_max - 1)


import collections
(h, w, m) = map(int, input().split())
gyou = [0 for i in range(h)]
retu = [0 for i in range(w)]
l = []
for i in range(m):
	(y, x) = map(int, input().split())
	gyou[y - 1] += 1
	retu[x - 1] += 1
	l.append((y - 1, x - 1))
ymax = max(gyou)
xmax = max(retu)
c_ymax = gyou.count(ymax)
c_xmax = retu.count(xmax)
ans = ymax + xmax
c = 0
for (y, x) in l:
	if gyou[y] == ymax and retu[x] == xmax:
		c += 1
if c == c_ymax * c_xmax:
	print(ans - 1)
else:
	print(ans)


(H, W, M) = map(int, input().split())
hl = [0 for i in range(H + 1)]
wl = [0 for i in range(W + 1)]
ms = []
for i in range(M):
	(h, w) = map(int, input().split())
	hl[h] += 1
	wl[w] += 1
	ms.append([h, w])
a = max(hl)
b = max(wl)
hmax = []
wmax = []
s = 0
for x in ms:
	if hl[x[0]] == a and wl[x[1]] == b:
		s += 1
c = hl.count(a)
d = wl.count(b)
if s < c * d:
	print(a + b)
else:
	print(a + b - 1)


import sys
(h, w, m) = map(int, input().split())
h_t = [0 for _ in range(h)]
w_t = [0 for _ in range(w)]
t = []
for _ in range(m):
	(hi, wi) = map(int, input().split())
	h_t[hi - 1] += 1
	w_t[wi - 1] += 1
	t.append([hi - 1, wi - 1])
hmax = max(h_t)
wmax = max(w_t)
hmaxi = [i1 for i1 in range(h) if h_t[i1] == hmax]
wmaxi = [i2 for i2 in range(w) if w_t[i2] == wmax]
c = len(hmaxi) * len(wmaxi)
d = 0
for (ht, wt) in t:
	if h_t[ht] == hmax:
		if w_t[wt] == wmax:
			d += 1
if c == d:
	print(hmax + wmax - 1)
else:
	print(hmax + wmax)


(h, w, m) = map(int, input().split())
hw = set()
hh = [0] * h
ww = [0] * w
for _ in range(m):
	(h, w) = map(int, input().split())
	h -= 1
	w -= 1
	hw.add(h * 10 ** 6 + w)
	hh[h] += 1
	ww[w] += 1
mxh = max(hh)
mxw = max(ww)
mh = [i for (i, j) in enumerate(hh) if j == mxh]
mw = [i for (i, j) in enumerate(ww) if j == mxw]
for i in mh:
	for j in mw:
		if i * 10 ** 6 + j not in hw:
			print(mxh + mxw)
			exit(0)
print(mxh + mxw - 1)


(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())
L = []
bh = [0] * (H + 1)
bw = [0] * (W + 1)
for _ in range(M):
	(h, w) = map(int, input().split())
	L.append((h, w))
	bh[h] += 1
	bw[w] += 1
(p, q) = (max(bh), max(bw))
num = len(list(filter(p.__eq__, bh))) * len(list(filter(q.__eq__, bw)))
num -= len(list(filter(lambda x: bh[x[0]] == p and bw[x[1]] == q, L)))
ans = p + q - 1
if num > 0:
	ans += 1
print(ans)


(H, W, M) = map(int, input().split())
h = [None] * M
w = [None] * M
for i in range(M):
	(a, b) = map(int, input().split())
	(h[i], w[i]) = (a - 1, b - 1)
from collections import Counter
ch = Counter(h)
cw = Counter(w)
x_max = max(ch.values())
n_x_max = sum((ch[x] == x_max for x in range(H)))
y_max = max(cw.values())
n_y_max = sum((cw[y] == y_max for y in range(W)))
cnt = sum((ch[h[i]] == x_max and cw[w[i]] == y_max for i in range(M)))
if cnt < n_x_max * n_y_max:
	print(x_max + y_max)
else:
	print(x_max + y_max - 1)


import sys
(h, w, m) = map(int, input().split())
hight = [0] * h
width = [0] * w
S = set()
for i in range(m):
	(hi, wi) = map(int, input().split())
	S.add((hi - 1, wi - 1))
	hight[hi - 1] += 1
	width[wi - 1] += 1
max_vh = max(hight)
max_vw = max(width)
max_h = [i for i in range(h) if hight[i] == max_vh]
max_w = [i for i in range(w) if width[i] == max_vw]
for i in max_h:
	for j in max_w:
		if not (i, j) in S:
			print(max_vh + max_vw)
			sys.exit()
print(max_vh + max_vw - 1)


(H, W, M) = map(int, input().split())
HW = [list(map(int, input().split())) for i in range(M)]
g_h = [0] * (H + 1)
g_w = [0] * (W + 1)
for (h, w) in HW:
	g_h[h] += 1
	g_w[w] += 1
mxh = max(g_h)
mxw = max(g_w)
cnt = 0
for (h, w) in HW:
	if g_h[h] == mxh and g_w[w] == mxw:
		cnt += 1
if cnt == g_h.count(mxh) * g_w.count(mxw):
	print(mxh + mxw - 1)
else:
	print(mxh + mxw)


(H, W, M) = map(int, input().split())
lh = [0] * (H + 1)
lw = [0] * (W + 1)
l = []
for _ in range(M):
	(h, w) = map(int, input().split())
	lh[h] += 1
	lw[w] += 1
	l += [[h, w]]
maxh = max(lh)
maxw = max(lw)
cnt = 0
ch = lh.count(maxh)
cw = lw.count(maxw)
for (y, x) in l:
	if lh[y] == maxh and lw[x] == maxw:
		cnt += 1
ans = maxh + maxw
if cnt == ch * cw:
	ans -= 1
print(ans)


(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
hmax = max(H)
wmax = max(W)
cthmax = 0
ctwmax = 0
for i in range(h):
	if H[i] == hmax:
		cthmax += 1
for i in range(w):
	if W[i] == wmax:
		ctwmax += 1
ct = 0
for i in range(m):
	if H[l[i][0] - 1] == hmax and W[l[i][1] - 1] == wmax:
		ct += 1
if cthmax * ctwmax > ct:
	print(hmax + wmax)
else:
	print(hmax + wmax - 1)


from collections import Counter
(H, W, M) = [int(i) for i in input().split()]
g = set()
h = [0] * M
w = [0] * M
for i in range(M):
	(h[i], w[i]) = [int(j) for j in input().split()]
	g.add((h[i], w[i]))
ch = Counter(h)
cw = Counter(w)
chm = max(ch.values())
cwm = max(cw.values())
hi = [i for i in ch.keys() if ch[i] == chm]
wi = [i for i in cw.keys() if cw[i] == cwm]
for i in hi:
	for j in wi:
		if (i, j) not in g:
			print(ch[i] + cw[j])
			exit()
print(ch[hi[0]] + cw[wi[0]] - 1)


(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)


(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)


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), *s) = [[*map(int, i.split())] for i in open(0)]
(r, c) = ([0] * -~h, [0] * -~w)
for (x, y) in s:
	r[x] += 1
	c[y] += 1
(R, C) = (max(r), max(c))
print(R + C - (r.count(R) * c.count(C) == sum((r[x] + c[y] == R + C for (x, y) in s))))


import itertools
(H, W, M) = map(int, input().split())
Bh = [0] * (H + 1)
Bw = [0] * (W + 1)
OD = set()
for _ in range(M):
	(h, w) = map(int, input().split())
	Bh[h] += 1
	Bw[w] += 1
	OD.add((h, w))
M1 = max(Bh)
M2 = max(Bw)
l1 = [i for (i, x) in enumerate(Bh) if x == M1]
l2 = [j for (j, x) in enumerate(Bw) if x == M2]
for (i, j) in itertools.product(l1, l2):
	if (i, j) not in OD:
		break
else:
	print(M1 + M2 - 1)
	exit()
print(M1 + M2)


f = lambda : map(int, input().split())
(h, w, m) = f()
(l, H, W) = ([], [0] * -~h, [0] * -~w)
for _ in range(m):
	(x, y) = f()
	l += [(x, y)]
	H[x] += 1
	W[y] += 1
(s, t) = (max(H), max(W))
print(s + t - (H.count(s) * W.count(t) == sum((H[x] + W[y] == s + t for (x, y) in l))))


(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())
boms = []
(h, w) = ([0] * (H + 1), [0] * (W + 1))
for _ in range(M):
	(h_, w_) = map(int, input().split())
	boms.append([h_, w_])
	h[h_] += 1
	w[w_] += 1
hmax = max(h)
wmax = max(w)
cnt = h.count(hmax) * w.count(wmax)
for (hh, ww) in boms:
	if hmax == h[hh] and wmax == w[ww]:
		cnt -= 1
print(hmax + wmax - (cnt == 0))


(H, W, M) = map(int, input().split())
h = [0] * (H + 1)
w = [0] * (W + 1)
l = set()
for i in range(M):
	(x, y) = map(int, input().split())
	h[x] += 1
	w[y] += 1
	l.add((x, y))
c = max(h)
d = max(w)
a = [i for (i, x) in enumerate(h) if x == c]
b = [i for (i, x) in enumerate(w) if x == d]
flag = False
for s in a:
	for t in b:
		if (s, t) not in l:
			flag = True
			break
	if flag:
		break
ans = c + d
if not flag:
	ans -= 1
print(ans)


(H, W, M) = map(int, input().split())
(tate, yoko) = ([0] * W, [0] * H)
ans = 0
memo = set([])
for _ in range(M):
	(h, w) = map(int, input().split())
	h -= 1
	w -= 1
	tate[w] += 1
	yoko[h] += 1
	memo.add((h, w))
(tateArr, yokoArr) = ([], [])
ans = 0
(t, y) = (max(tate), max(yoko))
for i in range(W):
	if tate[i] == t:
		tateArr.append(i)
for i in range(H):
	if yoko[i] == y:
		yokoArr.append(i)
for i in yokoArr:
	for j in tateArr:
		if (i, j) not in memo:
			print(t + y)
			exit()
print(t + y - 1)


(H, W, M, *hw) = map(int, open(0).read().split())
H_cnt = [0] * (H + 1)
W_cnt = [0] * (W + 1)
bombs = [(h, w) for (h, w) in zip(*[iter(hw)] * 2)]
for (h, w) in bombs:
	H_cnt[h] += 1
	W_cnt[w] += 1
H_max_cnt = max(H_cnt)
W_max_cnt = max(W_cnt)
comb_cnt = H_cnt.count(H_max_cnt) * W_cnt.count(W_max_cnt)
for (h, w) in bombs:
	if H_cnt[h] == H_max_cnt and W_cnt[w] == W_max_cnt:
		comb_cnt -= 1
ans = H_max_cnt + W_max_cnt
print(ans if comb_cnt else ans - 1)


(h, w, m) = map(int, input().split())
A = [0] * h
B = [0] * w
G = []
for i in range(m):
	(x, y) = map(int, input().split())
	A[x - 1] += 1
	B[y - 1] += 1
	G.append([x - 1, y - 1])
q = max(A)
e = max(B)
Q = [i for i in range(h) if A[i] == q]
W = [j for j in range(w) if B[j] == e]
cnt = len(Q) * len(W)
for i in range(m):
	(x, y) = G[i]
	if A[x] == q and B[y] == e:
		cnt -= 1
if cnt == 0:
	print(q + e - 1)
else:
	print(q + e)


(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)


(h, w, m) = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
hc = [0] * h
wc = [0] * w
d = {}
for (_h, _w) in hw:
	hc[_h - 1] += 1
	wc[_w - 1] += 1
	d[_h - 1, _w - 1] = 1
maxh = max(hc)
maxw = max(wc)
hoge = True
wi = [i for i in range(w) if wc[i] == maxw]
for h in [i for i in range(h) if hc[i] == maxh]:
	for w in wi:
		if (h, w) not in d:
			hoge = False
			break
if hoge:
	print(maxh + maxw - 1)
else:
	print(maxh + maxw)


(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)


(H, W, M, *HW) = map(int, open(0).read().split())
HW = list(zip(*[iter(HW)] * 2))
A = [0] * (H + 1)
B = [0] * (W + 1)
for (h, w) in HW:
	A[h] += 1
	B[w] += 1
a = max(A)
b = max(B)
cnt = A.count(a) * B.count(b) - len([0 for (h, w) in HW if A[h] == a and B[w] == b])
print(a + b - (cnt == 0))


(n, m, t) = map(int, input().split())
grid = []
row = [0] * n
col = [0] * m
for _ in range(t):
	(x, y) = map(int, input().split())
	grid.append((x - 1, y - 1))
	row[x - 1] += 1
	col[y - 1] += 1
prow = []
pcol = []
qr = max(row)
for i in range(n):
	if row[i] == qr:
		prow.append(i)
qc = max(col)
for i in range(m):
	if col[i] == qc:
		pcol.append(i)
num = len(prow) * len(pcol)
ans = qr + qc
for i in grid:
	if row[i[0]] == qr and col[i[1]] == qc:
		num -= 1
if num > 0:
	print(ans)
else:
	print(ans - 1)


(h, w, m) = map(int, input().split())
hli = [0] * h
wli = [0] * w
li = []
liset = set()
for i in range(m):
	(a, b) = map(int, input().split())
	li.append([a, b])
	liset.add((a, b))
	hli[a - 1] += 1
	wli[b - 1] += 1
a = max(hli)
b = max(wli)
hli2 = []
wli2 = []
for i in range(h):
	if hli[i] == a:
		hli2.append(i + 1)
for i in range(w):
	if wli[i] == b:
		wli2.append(i + 1)
for i in hli2:
	for j in wli2:
		if (i, j) not in liset:
			print(a + b)
			exit()
print(a + b - 1)


(h, w, m) = list(map(int, input().split()))
b = []
r = [0] * (3 * 10 ** 5 + 2)
c = [0] * (3 * 10 ** 5 + 2)
for i in range(m):
	(h, w) = list(map(int, input().split()))
	r[h] = r[h] + 1
	c[w] = c[w] + 1
	b.append([h, w])
if max(r) > max(c):
	j = r.index(max(r))
	for i in range(len(b)):
		if b[i][0] == j:
			c[b[i][1]] = c[b[i][1]] - 1
else:
	i = c.index(max(c))
	for j in range(len(b)):
		if b[j][1] == i:
			r[b[j][0]] = r[b[j][0]] - 1
print(max(r) + max(c))


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)
	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()


(h, w, m) = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
hb = [0] * h
wb = [0] * w
for i in range(m):
	hb[hw[i][0] - 1] += 1
	wb[hw[i][1] - 1] += 1
max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w
count = hb.count(max_h) * wb.count(max_w)
for i in range(m):
	if hb[hw[i][0] - 1] == max_h and wb[hw[i][1] - 1] == max_w:
		count -= 1
if count <= 0:
	ans -= 1
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
(h, w, m) = map(int, input().split())
hw = []
hcount = [0] * h
wcount = [0] * w
for _ in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	hcount[a] += 1
	wcount[b] += 1
	hw.append([a, b])
hmax = max(hcount)
wmax = max(wcount)
x = hcount.count(hmax) * wcount.count(wmax)
for (a, b) in hw:
	if hcount[a] == hmax and wcount[b] == wmax:
		x -= 1
if x == 0:
	print(hmax + wmax - 1)
else:
	print(hmax + wmax)


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())
countW = [0] * (W + 1)
countH = [0] * (H + 1)
bomb = []
for i in range(M):
	(h, w) = map(int, input().split())
	bomb.append((h, w))
	countH[h] += 1
	countW[w] += 1
maxW = max(countW)
maxH = max(countH)
ans = maxW + maxH - 1
countMaxW = countW.count(maxW)
countMaxH = countH.count(maxH)
sumz = 0
for i in range(M):
	(h, w) = bomb[i]
	if countH[h] == maxH and countW[w] == maxW:
		sumz += 1
if countMaxW * countMaxH > sumz:
	ans += 1
print(ans)


(H, W, M) = map(int, input().split())
lsx = [0] + [0] * H
lsy = [0] + [0] * W
lsxy = []
for i in range(M):
	(x, y) = map(int, input().split())
	lsx[x] += 1
	lsy[y] += 1
	lsxy.append([x, y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx * cy
for i in range(M):
	if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
		al -= 1
if al == 0:
	factor = 1
else:
	factor = 0
print(maxx + maxy - factor)


(H, W, M) = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(M)]
ss = set(S)
Y = [0] * H
X = [0] * W
for i in range(M):
	(y, x) = S[i]
	(y, x) = (y - 1, x - 1)
	Y[y] += 1
	X[x] += 1
YM = max(Y)
XM = max(X)
YI = []
for i in range(H):
	if Y[i] == YM:
		YI.append(i)
XI = []
for i in range(W):
	if X[i] == XM:
		XI.append(i)
for y in YI:
	for x in XI:
		if (y + 1, x + 1) not in ss:
			print(YM + XM)
			exit()
else:
	print(YM + XM - 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())
mine_h = [0] * H
mine_w = [0] * W
val = -1
mine = set()
for i in range(M):
	(a, b) = map(int, input().split())
	mine_h[a - 1] += 1
	mine_w[b - 1] += 1
	mine.add((a, b))
max_h = max(mine_h)
max_w = max(mine_w)
h_index = [i + 1 for (i, x) in enumerate(mine_h) if x == max_h]
w_index = [i + 1 for (i, x) in enumerate(mine_w) if x == max_w]
for i in h_index:
	for j in w_index:
		if (i, j) in mine:
			continue
		else:
			val = 0
			break
print(max_h + max_w + val)