CodeEff/ECCO huggingface dataset:
# Original solution
def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return 1
    elif v==w:
        return 0
    else:
        return -1


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])==1):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


def bis_exist(lis,dev):
    a=0
    b=len(lis)-1
    if lis[b]==dev:
        return 1
    while a<b:
        c=(a+b)//2
        if lis[c]==dev:
            return 1
        if comp(lis[c],dev)==1:
            a=c+1
        if comp(lis[c],dev)==-1:
            b=c
    return 0


h,w,m=list(map(int,input().split()))
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=list(map(int,input().split()))
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
k=mergesort(g)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
if len(x)*len(y)>m:
    r=0
else:
    for i in x:
        for j in y:
            if bis_exist(k,[i,j])==0:
                r=0
                break
        else:
            continue
        break
print((p+q-r))

# Optimized solution
h,w,m=list(map(int,input().split()))
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=list(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))
# Original solution
H, W, M = list(map(int, input().split()))
hrz = [0]*H
vrt = [0]*W
targets = set()
for _ in range(M):
    h, w = list([int(x) - 1 for x in input().split()])
    targets.add((h, w))
    hrz[h] += 1
    vrt[w] += 1

hrz_max = max(hrz)
vrt_max = max(vrt)
for h in [i for i in range(H) if hrz[i] == hrz_max]:
    for w in [i for i in range(W) if vrt[i] == vrt_max]:
        if not (h, w) in targets:
            print((hrz_max+vrt_max))
            exit()
print((hrz_max+vrt_max-1))


# Optimized solution
H, W, M = list(map(int, input().split()))
hrz = [0]*H
vrt = [0]*W
targets = set()
for _ in range(M):
    h, w = list([int(x) - 1 for x in input().split()])
    targets.add((h, w))
    hrz[h] += 1
    vrt[w] += 1

hrz_max = max(hrz)
vrt_max = max(vrt)
hrz_max_lines = [i for i in range(H) if hrz[i] == hrz_max]
vrt_max_lines = [i for i in range(W) if vrt[i] == vrt_max]
for h in hrz_max_lines:
    for w in vrt_max_lines:
        if not (h, w) in targets:
            print((hrz_max+vrt_max))
            exit()
print((hrz_max+vrt_max-1))
# Original solution
import sys
input = sys.stdin.readline
l = []

sh,sw,m = list(map(int,input().split()))
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = list(map(int,input().split()))
    l.append((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

maxi = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            maxi += 1
            print(maxi)
            exit()
print(maxi)

# Optimized solution
import sys
input = sys.stdin.readline
l = set()

sh,sw,m = list(map(int,input().split()))
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = list(map(int,input().split()))
    l.add((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

if len(hlist)*len(wlist) > m:
    print((maxh+maxw))
    exit()

ans = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            print((ans+1))
            exit()
print(ans)
# Original solution
from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [[] for _ in range(H)]

    for _ in range(M):
        a, b = list(map(int, input().split()))
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].append(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print((solver()))


# Optimized solution
from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [set() for _ in range(H)]

    for _ in range(M):
        a, b = list(map(int, input().split()))
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].add(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print((solver()))
# Original solution
h, w, m =  list(map(int, input().split()))
bom_list = []
h_list = [0] * h
w_list = [0] * w

for i in range(m):
    a, b =  list(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_h_list = [i for i, x in enumerate(h_list) if x == max_h]
max_w = max(w_list)
max_w_list = [i for i, x in enumerate(w_list) if x == max_w]
ans = max_h + max_w
count = 0

for i in range(len(max_h_list)):
    for j in range(len(max_w_list)):
        if [max_h_list[i], max_w_list[j]] in bom_list:
            count += 1

if len(max_h_list) * len(max_w_list) == count:
    ans -= 1

print(ans)


# Optimized solution
h, w, m =  list(map(int, input().split()))
bom_list = []
h_list = [0] * h
w_list = [0] * w

for i in range(m):
    a, b =  list(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)
# Original solution
import sys
input = sys.stdin.buffer.readline

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

bomb_h = [0] * H
bomb_w = [0] * W
grid = [[False] * W for _ in range(H)]

max_h = 0
max_w = 0
h_indices = []
w_indices = []

for i in range(M):
    h, w = list(map(int, input().split()))
    bomb_h[h-1] += 1
    bomb_w[w-1] += 1
    if bomb_h[h-1] == max_h:
        h_indices.append(h-1)
    elif bomb_h[h-1] > max_h:
        h_indices = [h-1]
        max_h = bomb_h[h-1]

    if bomb_w[w-1] == max_w:
        w_indices.append(w-1)
    elif bomb_w[w-1] > max_w:
        w_indices = [w-1]
        max_w = bomb_w[w-1]

    grid[h-1][w-1] = True

ans = max_w + max_h - 1
for h in h_indices:
    for w in w_indices:
        if not grid[h][w]:
            ans += 1
            print(ans)
            exit()

if ans == -1:
    ans = 0

print(ans)


# Optimized solution
import sys
input = sys.stdin.buffer.readline

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

bomb_h = [0] * H
bomb_w = [0] * W
bomb = set()
for i in range(M):
    h, w = list(map(int, input().split()))
    bomb_h[h-1] += 1
    bomb_w[w-1] += 1
    bomb.add((h-1, w-1))

max_h = max(bomb_h)
max_w = max(bomb_w)

h_indices = []
for i in range(H):
    if bomb_h[i] == max_h:
        h_indices.append(i)

w_indices = []
for i in range(W):
    if bomb_w[i] == max_w:
        w_indices.append(i)

ans = max_w + max_h - 1
for h in h_indices:
    for w in w_indices:
        if (h, w) not in bomb:
            ans += 1
            print(ans)
            exit()

if ans == -1:
    ans = 0

print(ans)
# Original solution

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

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


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



curMax = 0

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

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

ans = 0

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

for h in [h for h, x in enumerate(HSum) if x == hMax]:
	if ans == tmpMax:
		break
	for w in [w for w, y in enumerate(WSum) if y == wMax]:
		if (h,w) in bombs:
			ans = tmpMax - 1
		else:
			ans = tmpMax
			break



print(ans)


# Optimized solution

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

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


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



curMax = 0

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

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

ans = 0

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

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



print(ans)
# Original solution
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def SS(): return eval(input())
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, M = LI()
    hw = [LI() for _ in range(M)]
    hw_set = set([(h, w) for h, w in hw])

    cnt_h = collections.Counter([h for h, w in hw])
    cnt_w = collections.Counter([w for h, w in hw])

    # i行目にはどの列にあります
    # print(cnt_h)
    # print(cnt_w)
    max_h = max(cnt_h.values())
    max_w = max(cnt_w.values())
    max_h_k = [k for k, v in list(cnt_h.items()) if v == max_h]
    max_w_k = [k for k, v in list(cnt_w.items()) if v == max_w]
    is_on_target = True
    for i, j in itertools.product(max_h_k, max_w_k):
        if (i, j) not in hw_set:
            is_on_target = False

    if is_on_target:
        ans = max(cnt_h.values()) + max(cnt_w.values()) - 1
    else:
        ans = max(cnt_h.values()) + max(cnt_w.values())
    print(ans)

if __name__ == '__main__':
    resolve()


# Optimized solution
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def SS(): return eval(input())
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, M = LI()
    hw = [LI() for _ in range(M)]
    hw_set = set([(h, w) for h, w in hw])

    cnt_h = collections.Counter([h for h, w in hw])
    cnt_w = collections.Counter([w for h, w in hw])

    # i行目にはどの列にあります
    # print(cnt_h)
    # print(cnt_w)
    max_h = max(cnt_h.values())
    max_w = max(cnt_w.values())
    max_h_k = [k for k, v in list(cnt_h.items()) if v == max_h]
    max_w_k = [k for k, v in list(cnt_w.items()) if v == max_w]
    is_on_target = True
    for i, j in itertools.product(max_h_k, max_w_k):
        if (i, j) not in hw_set:
            is_on_target = False
            break

    if is_on_target:
        ans = max_h + max_w - 1
    else:
        ans = max_h + max_w
    print(ans)

if __name__ == '__main__':
    resolve()
# Original solution
h, w, m = list(map(int, input().split()))
h_cnt = [0] * h
w_cnt = [0] * w

bomb_list = []

for i in range(m):
    h_, w_ = list(map(int, input().split()))
    h_ -= 1
    w_ -= 1
    h_cnt[h_] += 1
    w_cnt[w_] += 1
    bomb_list.append((h_, w_))

max_h = max(h_cnt)
max_h_idx = []
for i in range(h):
    if h_cnt[i] == max_h:
        max_h_idx.append(i)

max_w = max(w_cnt)
max_w_idx = []
for i in range(w):
    if w_cnt[i] == max_w:
        max_w_idx.append(i)

minus = -1
for i in max_h_idx:
    for j in max_w_idx:
        if (i, j) not in bomb_list:
            print((max_h + max_w))
            exit()
print((max_h + max_w - 1))


# Optimized solution
h, w, m = list(map(int, input().split()))
h_cnt = [0] * h
w_cnt = [0] * w

bomb_set = set()

for i in range(m):
    h_, w_ = list(map(int, input().split()))
    h_ -= 1
    w_ -= 1
    h_cnt[h_] += 1
    w_cnt[w_] += 1
    bomb_set.add((h_, w_))

max_h = max(h_cnt)
max_h_idx = []
for i in range(h):
    if h_cnt[i] == max_h:
        max_h_idx.append(i)

max_w = max(w_cnt)
max_w_idx = []
for i in range(w):
    if w_cnt[i] == max_w:
        max_w_idx.append(i)

minus = -1
for i in max_h_idx:
    for j in max_w_idx:
        if (i, j) not in bomb_set:
            print((max_h + max_w))
            exit()
print((max_h + max_w - 1))
# Original solution
from sys import exit

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

b = [[False] * W for _ in range(H)]
r = [0] * H
c = [0] * W
for _ in range(M):
    h, w = list(map(int, input().split()))
    b[h-1][w-1] = True
    r[h-1] += 1
    c[w-1] += 1

list_r, list_c = [], []
max_r, max_c = max(r), max(c)

for i in range(H):
    if r[i] == max_r:
        list_r.append(i)

for i in range(W):
    if c[i] == max_c:
        list_c.append(i)

for v1 in list_r:
    for v2 in list_c:
        if not b[v1][v2]:
            print((max_r + max_c))
            exit()

print((max_r + max_c - 1))

# Optimized solution
from sys import exit

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

r = [0] * H
c = [0] * W
l = []
for _ in range(M):
    h, w = list(map(int, input().split()))
    l.append([h-1, w-1])
    r[h-1] += 1
    c[w-1] += 1

set_r = set()
set_c = set()
max_r, max_c = max(r), max(c)

for i in range(H):
    if r[i] == max_r:
        set_r.add(i)

for i in range(W):
    if c[i] == max_c:
        set_c.add(i)

cnt = 0
for x, y in l:
    if x in set_r and y in set_c:
        cnt += 1

if cnt == len(set_r) * len(set_c):
    print((max_r + max_c - 1))
else:
    print((max_r + max_c))
# Original solution
import copy
import sys
H, W, M= list(map(int,input().split()))
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = list(map(int, s.split()))
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max
c = 0
p = len(cand_h)*len(cand_w)
if M >= p:
   for i in range(len(object)):
      if object[i][0] in cand_h and object[i][1] in cand_w:
         c += 1
print((ans - (c == p)))

# Optimized solution
import copy
import sys
H, W, M= list(map(int,input().split()))
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = list(map(int, s.split()))
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max
c = 0
p = len(cand_h)*len(cand_w)
cand_h = set(cand_h)
cand_w = set(cand_w)
if M >= p:
   for i in range(len(object)):
      if object[i][0] in cand_h and object[i][1] in cand_w:
         c += 1
print((ans - (c == p)))
# Original solution
H, W, M = [int(n) for n in input().split()]
H_freq = [0] * H
W_freq = [0] * W

coordinates = {}
for m in range(M):
    h, w = [int(n)-1 for n in input().split()]
    H_freq[h] += 1
    W_freq[w] += 1
    if h in list(coordinates.keys()):
        coordinates[h].append(w)
    else:
        coordinates[h] = [w]

max_h = max(H_freq)
max_w = max(W_freq)
most_freqent_h = [i for i, h in enumerate(H_freq) if h == max_h]
most_freqent_w = [i for i, w in enumerate(W_freq) if w == max_w]

ans = 0
for h in most_freqent_h:
    for w in most_freqent_w:
        if w in coordinates[h]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            print(ans)
            exit()
print(ans)


# Optimized solution
H, W, M = [int(n) for n in input().split()]
H_freq = [0] * H
W_freq = [0] * W

table = []
for m in range(M):
    h, w = [int(n)-1 for n in input().split()]
    H_freq[h] += 1
    W_freq[w] += 1
    table.append((h, w))

max_h = max(H_freq)
max_w = max(W_freq)
most_freqent_h = [i for i, h in enumerate(H_freq) if h == max_h]
most_freqent_w = [i for i, w in enumerate(W_freq) if w == max_w]

count = 0
for (h, w) in table:
    if H_freq[h] == max_h and W_freq[w] == max_w:
        count += 1

if count < len(most_freqent_h) * len(most_freqent_w):
    print((max_h + max_w))
else:
    print((max_h + max_w - 1))
# Original solution
h, w, m = list(map(int, input().split()))

target = set()
rows = [0] * h
cols = [0] * w
for i in range(m):
    y, x = [int(x) - 1 for x in input().split()]
    rows[y] += 1
    cols[x] += 1
    target.add((y, x))

rows_sorted = [(a, i) for i, a in enumerate(rows)]
rows_sorted.sort(reverse=True)
cols_sorted = [(a, i) for i, a in enumerate(cols)]
cols_sorted.sort(reverse=True)

max_r = rows_sorted[0][0]
max_c = cols_sorted[0][0]

i = 0
max_val = max(max_r, max_c)
while i < h and rows_sorted[i][0] == max_r:
    j = 0
    while j < w and cols_sorted[j][0] == max_c:
        val = rows_sorted[i][0] + cols_sorted[j][0]
        if (rows_sorted[i][1], cols_sorted[j][1]) in target:
            val -= 1
        else:
            max_val = val
            break
        max_val = max(max_val, val)
        j += 1
    i += 1
print(max_val)


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

target_pos = set()
target_n_row = [0] * h
target_n_col = [0] * w
for i in range(m):
    y, x = [int(x) - 1 for x in input().split()]
    target_n_row[y] += 1
    target_n_col[x] += 1
    target_pos.add((y, x))

sorted_row = [(a, i) for i, a in enumerate(target_n_row)]
sorted_row.sort(reverse=True)
sorted_col = [(a, i) for i, a in enumerate(target_n_col)]
sorted_col.sort(reverse=True)

max_r = sorted_row[0][0]
max_c = sorted_col[0][0]

i = 0
max_val = max_r + max_c - 1
while i < h and sorted_row[i][0] == max_r:
    j = 0
    while j < w and sorted_col[j][0] == max_c:
        if not (sorted_row[i][1], sorted_col[j][1]) in target_pos:
            max_val = sorted_row[i][0] + sorted_col[j][0]
            break
        j += 1
    i += 1
print(max_val)
# Original solution

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

mp = set()
hp = [0] * h
wp = [0] * w

for i in range(m):
    a, b = list(map(int, input().split()))
    mp.add((a,b))
    l = [a, b]
    hp[l[0]-1] += 1
    wp[l[1]-1] += 1

hpdex = [i for i, x in enumerate(hp) if x == max(hp)]
wpdex = [i for i, x in enumerate(wp) if x == max(wp)]

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

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

mp = set()
hp = [0] * h
wp = [0] * w

for i in range(m):
    a, b = list(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))
# Original solution
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
w_flag = [0 for _ in range(w)]
for i in range(w):
    if w_list[i] == max(w_list):
        w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
    if h_list[i] == max(h_list):
        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((max(h_list) + max(w_list) - 1 if flag == s else max(h_list) + max(w_list)))        


# Optimized solution
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))
# Original solution
from collections import Counter


def solve():
    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()

    h, counth = ih[0]
    w, countw = iw[0]
    ans = counth + countw - ((h, w) in used)

    for h, counth in ih:
        for w, countw in iw:
            b = counth + countw - ((h, w) in used)
            if b<ans:
                break
            ans = b
    print(ans)


solve()

# Optimized solution
from collections import Counter


def solve():
    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()

    h, counth = ih[0]
    w, countw = iw[0]

    s = counth + countw
    ans = counth + countw - ((h, w) in used)

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


solve()