CodeEff/ECCO huggingface dataset:
# Original solution
H, W, m = list(map(int, input().split()))

H_bomb = [0]*H
W_bomb = [0]*W
S = set()

for _ in range(m):
    h, w = list(map(int, input().split()))
    h, w = h-1, w-1
    S.add(tuple([h, w]))
    H_bomb[h] += 1
    W_bomb[w] += 1

H_max = max(H_bomb)
W_max = max(W_bomb)

H_memo = []
W_memo = []

for i in range(H):
    if H_bomb[i] == H_max:
        H_memo.append(i)

for j in range(W):
    if W_bomb[j] == W_max:
        W_memo.append(j)

ans = H_max + W_max

daburi = 1

for i in H_memo:
    for j in W_memo:
        if tuple([i, j]) not in S:
            daburi = 0
print((ans - daburi))

# Optimized solution
import sys

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

H_bomb = [0]*H
W_bomb = [0]*W
S = set()

for _ in range(m):
    h, w = list(map(int, sys.stdin.readline().split()))
    h, w = h-1, w-1
    S.add(tuple([h, w]))
    H_bomb[h] += 1
    W_bomb[w] += 1

H_max = max(H_bomb)
W_max = max(W_bomb)

H_memo = []
W_memo = []

for i in range(H):
    if H_bomb[i] == H_max:
        H_memo.append(i)

for j in range(W):
    if W_bomb[j] == W_max:
        W_memo.append(j)

ans = H_max + W_max

for i in H_memo:
    for j in W_memo:
        if tuple([i, j]) not in S:
            print(ans)
            exit()
print((ans-1))
# Original solution
H, W, M = list(map(int, input().split()))
cnth = [[0, i] for i in range(H)]
cntw = [[0, i] for i in range(W)]
L = [[False for _ in range(W)] for _ in range(H)]
for _ in range(M):
    h, w = [int(x) - 1 for x in input().split()]
    cnth[h][0] += 1
    cntw[w][0] += 1
    L[h][w] = True
cnth.sort(reverse=True)
cntw.sort(reverse=True)
mh = set()
ph = cnth[0]
for h in cnth:
    if ph[0] == h[0]:
        mh.add(h[1])
    else:
        break
    ph = h
mw = set()
pw = cntw[0]
for w in cntw:
    if pw[0] == w[0]:
        mw.add(w[1])
    else:
        break
    pw = w
max = cnth[0][0] + cntw[0][0]
for h in mh:
    for w in mw:
        if not (L[h][w]):
            print(max)
            break
    else:
        continue
    break
else:
    print((max - 1))


# Optimized solution
def main():
    H, W, M = list(map(int, input().split()))
    cnth = [[0, i] for i in range(H)]
    cntw = [[0, i] for i in range(W)]
    L = set()
    for _ in range(M):
        h, w = [int(x) - 1 for x in input().split()]
        cnth[h][0] += 1
        cntw[w][0] += 1
        L.add((h, w))
    cnth.sort(reverse=True)
    cntw.sort(reverse=True)
    mh = set()
    ph = cnth[0]
    for h in cnth:
        if ph[0] == h[0]:
            mh.add(h[1])
        else:
            break
        ph = h
    mw = set()
    pw = cntw[0]
    for w in cntw:
        if pw[0] == w[0]:
            mw.add(w[1])
        else:
            break
        pw = w
    maxans = cnth[0][0] + cntw[0][0]
    for h in mh:
        for w in mw:
            if not ((h, w) in L):
                print(maxans)
                break
        else:
            continue
        break
    else:
        print((maxans - 1))
if __name__ == "__main__":
    main()
# Original solution
h, w, m = list(map(int, input().split()))
h_cnt = [0 for _ in range(h)]
w_cnt = [0 for _ in range(w)]
mat = [[0 for _ in range(w)] for _ in range(h)]
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    h_cnt[y] += 1
    w_cnt[x] += 1
    mat[y][x] += 1
h_dict = {i:v for i, v in enumerate(h_cnt)}
w_dict = {i:v for i, v in enumerate(w_cnt)}
h_max = max(h_dict.values())
w_max = max(w_dict.values())
h_max_induce = [i for i in list(h_dict.keys()) if h_dict[i] == h_max]
w_max_induce = [i for i in list(w_dict.keys()) if w_dict[i] == w_max]

for h_idx in h_max_induce:
    for w_idx in w_max_induce:
        if mat[h_idx][w_idx] == 0:
            print((h_max+w_max))
            exit()

print((h_max+w_max-1))



# Optimized solution
h, w, m = list(map(int, input().split()))
h_cnt = [0 for _ in range(h)]
w_cnt = [0 for _ in range(w)]
xs = []
ys = []
for _ in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    h_cnt[y] += 1
    w_cnt[x] += 1
    xs.append(x)
    ys.append(y)
h_max = max(h_cnt)
w_max = max(w_cnt)
h_max_induce = {i: v for i, v in enumerate(h_cnt) if v == h_max}
w_max_induce = {i: v for i, v in enumerate(w_cnt) if v == w_max}

cnt = 0
for i in range(m):
    x = xs[i]
    y = ys[i]
    if x in w_max_induce and y in h_max_induce:
        cnt += 1
if cnt == len(list(h_max_induce.keys()))*len(list(w_max_induce.keys())):
    print((h_max+w_max-1))
else:
    print((h_max+w_max))
# Original solution
h,w,m=list(map(int,input().split()))
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=list(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=[i for i,x in enumerate(g) if x==mxg]
ml=[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)))))

# Optimized solution
h,w,m=list(map(int,input().split()))
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=list(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)))))
# Original solution
h,w,m = list(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)))

# Optimized solution
#実験 貼り付けコード
h,w,m = list(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)))
# Original solution
from collections import Counter
h, w, m = list(map(int, input().split()))
blist = [list(map(int, input().split())) for _ in range(m)]

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:
            print((maxr + maxc))
            break
    else:
        continue
    break
else:
    print((maxr + maxc - 1))


# Optimized solution
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))
# Original solution
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
H,W,M=list(map(int,input().split()))
matrix=[[1 for i in range(W)] for j in range(H)]
for i in range(M):
    h,w=list(map(int,input().split()))
    row[h]+=1
    col[w]+=1
    matrix[h-1][w-1]=0
#print(row)
#print(col)
#for i in matrix:
#    print(*i)
temp=list(row.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt=0
for i in range(W):
    temp=0
    if matrix[a-1][i]==0:
        temp=(b+col[i+1]-1)
    else:
        temp=(b+col[i+1])
    cnt=max(cnt,temp)
print(cnt)

# Optimized solution
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
H,W,M=list(map(int,input().split()))
#matrix=[[1 for i in range(W)] for j in range(H)]
matrix=defaultdict(bool)
for i in range(M):
    h,w=list(map(int,input().split()))
    row[h-1]+=1
    col[w-1]+=1
    matrix[(h-1,w-1)]=True
#print(row)
#print(col)
#for i in matrix:
#    print(*i)
temp=list(row.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt=0
for i in range(W):
    temp=0
    if matrix[(a,i)]:
        temp=(b+col[i]-1)
    else:
        temp=(b+col[i])
    cnt=max(cnt,temp)
#print(cnt)
temp=list(col.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt2=0
for i in range(H):
    temp=0
    if matrix[(i,a)]:
        temp=(b+row[i]-1)
    else:
        temp=(b+row[i])
    cnt2=max(cnt2,temp)
print((max(cnt,cnt2)))
# Original solution
h,w,m=[int(i) for i in input().split()]
r=[0 for i in range(h)]

c=[0 for i in range(w)]
d={}
for i in range(m):
    h1,w1=[int(i)-1 for i in input().split()]
    r[h1]+=1
    c[w1]+=1
    x=str(h1)+"#"+str(w1)
    d[x]=d.get(x,0)+1
maxx=0
for i in range(h):
    for j in range(w):
        x=str(i)+"#"+str(j)
        maxx=max(maxx,r[i]+c[j]-d.get(x,0))
print(maxx)


# Optimized solution
h,w,m=[int(i) for i in input().split()]
r=[0 for i in range(h)]
c=[0 for i in range(w)]
d={}
for i in range(m):
    h1,w1=[int(j)-1 for j in input().split()]
    r[h1]+=1
    c[w1]+=1
    x=str(h1)+'#'+str(w1)
    d[x]=d.get(x,0)+1
maxx=max(r)
r1=[]
for i in range(len(r)):
    if maxx==r[i]:
        r1.append(i)
maxx=max(c)
c1=[]
for i in range(len(c)):
    if maxx==c[i]:
        c1.append(i)
maxx1=0;flag=0
for i in r1:
    for j in c1:
        x=str(i)+'#'+str(j)
        if(d.get(x,0)==0):
            maxx1=max(maxx1,r[i]+c[j])
            flag=1
        else:
            maxx1=max(maxx1,r[i]+c[j]-d[x])
    if flag:
        break
print(maxx1)
# Original solution
h, w, m = list(map(int, input().split()))
a = [[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
    hi, wi = list(map(int, input().split()))
    a[hi-1][wi-1] = 1

mh = [sum(a[i][:]) for i in range(h)]
mw = [sum([r[i] for r in a]) for i in range(w)]
ans = max(mh) + max(mw)

mh = [i for i, v in enumerate(mh) if v == max(mh)]
mw = [i for i, v in enumerate(mw) if v == max(mw)]

flag = 0
for i in mh:
    for j in mw:
        if a[i][j] == 0:
            print(ans)
            exit()
print((ans - 1))

# Optimized solution
h, w, m = list(map(int, input().split()))
a = [list([int(x) - 1 for x in 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)
# Original solution
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return list(map(int, sys.stdin.readline().split()))


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    h, w, m = MI()
    targets = [[] for i in range(h)]
    tate = [[] for i in range(w)]
    tate_length = [0] * w
    original = []
    lengths = [0] * h
    for i in range(m):
        target = LI()
        original.append(target)
        targets[target[0] - 1].append(target[1] - 1)
        tate[target[1] - 1].append(target[0] - 1)
        lengths[target[0] - 1] += 1
        tate_length[target[1] - 1] += 1

    max_length = max(lengths)
    max_h_indexes = [i for i, x in enumerate(lengths) if x == max_length]
    semi_max_h_indexes = [i for i, x in enumerate(
        lengths) if x == max_length - 1]

    for j in range(len(tate)):
        tate[j] = set(tate[j])
    ans = 0

    for index in max_h_indexes:
        for j in range(w):
            if index in tate[j]:
                ans = max(ans, tate_length[j] + lengths[index] - 1)
            else:
                ans = max(ans, tate_length[j] + lengths[index])
    for index in semi_max_h_indexes:
        for j in range(w):
            if index in tate[j]:
                ans = max(ans, tate_length[j] + lengths[index] - 1)
            else:
                ans = max(ans, tate_length[j] + lengths[index])

    print(ans)


main()


# Optimized solution
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return list(map(int, sys.stdin.readline().split()))


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    h, w, m = MI()
    targets = [[] for i in range(h)]
    tate = [[] for i in range(w)]
    tate_length = [0] * w
    original = []
    lengths = [0] * h
    for i in range(m):
        target = LI()
        original.append(target)
        targets[target[0] - 1].append(target[1] - 1)
        tate[target[1] - 1].append(target[0] - 1)
        lengths[target[0] - 1] += 1
        tate_length[target[1] - 1] += 1

    max_length = max(lengths)
    max_length_tate = max(tate_length)

    max_w_indexes = [i for i, x in enumerate(
        tate_length) if x == max_length_tate]

    max_h_indexes = [i for i, x in enumerate(
        lengths) if x == max_length]

    max_h_indexes = set(max_h_indexes)
    max_w_indexes = set(max_w_indexes)

    ttl = len(max_h_indexes) * len(max_w_indexes)

    for target in original:
        if target[0] - 1 in max_h_indexes and target[1] - 1 in max_w_indexes:
            ttl -= 1

    if ttl > 0:
        print((max_length + max_length_tate))
    else:
        print((max_length+max_length_tate - 1))


main()
# Original solution
def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) in bomb_set:
                res = max(res, max_col + max_row -1)
            else:
                res = max(res, max_col + max_row)
    print(res)

if __name__ == "__main__":
    resolve()


# Optimized solution
def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) not in bomb_set:
                res =max_col + max_row
                break
        else:
            res = max(res, max_col + max_row -1 )
    print(res)

if __name__ == "__main__":
    resolve()
# Original solution
h, w, m = list(map(int, input().split()))

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

ans = 0
for x in xs:
    for y in ys:
        if (y, x) in points:
            ans = max(ans, count_h[y] + count_w[x] - 1)
        else:
            ans = max(ans, count_h[y] + count_w[x])
print(ans)



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

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = list(map(int, input().split()))
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

    
ans = ch_max + cw_max
if len(ys) * len(xs) <= m:
    def _find():
        for x in xs:
            for y in ys:
                if (y, x) not in points:
                    return True
        return False
    if not _find():
        ans -= 1
print(ans)
# Original solution
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = list(map(int, input().split()))
    Hlist = [0] * H
    Wlist = [0] * W
    hwmatrix = [[0 for _ in range(W)] for _ in range(H)]

    for _ in range(M):
        h, w = list(map(int, input().split()))
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hwmatrix[h-1][w-1] = 1

    hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]

    flag = False
    for h in hmax:
        for w in wmax:
            if hwmatrix[h][w] == 0:
                flag = True
                break

    if flag:
        print((Hlist[h] + Wlist[w]))
    else:
        print((Hlist[h] + Wlist[w] - 1))





if __name__ == '__main__':
    solve()

# Optimized solution
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = list(map(int, input().split()))
    Hlist = [0] * H
    Wlist = [0] * W
    hwset = [set() for _ in range(H)]

    for _ in range(M):
        h, w = list(map(int, input().split()))
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hwset[h-1].add(w)


    hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]

    flag = False
    for h in hmax:
        for w in wmax:
            if w+1 not in hwset[h]:
                flag = True
                break

    if flag:
        print((Hlist[h] + Wlist[w]))
    else:
        print((Hlist[h] + Wlist[w] - 1))





if __name__ == '__main__':
    solve()
# Original solution
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = list(map(int, input().split()))
    Hlist = [0] * H
    Wlist = [0] * W
    hw = []

    for _ in range(M):
        h, w = list(map(int, input().split()))
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hw.append([h, w])


    hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]
    hmaxset = set(hmax)
    wmaxset = set(wmax)

    flag = False
    count = 0
    for hh in hw:
        h = hh[0] - 1
        w = hh[1] - 1
        if h in hmaxset and w in wmaxset:
            count += 1
    if count != len(hmax) * len(wmax):
        flag = True

    if flag:
        print((Hlist[hmax[0]] + Wlist[wmax[0]]))
    else:
        print((Hlist[hmax[0]] + Wlist[wmax[0]] - 1))





if __name__ == '__main__':
    solve()


# Optimized solution
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = list(map(int, input().split()))
    Hlist = collections.defaultdict(int)
    Wlist = collections.defaultdict(int)
    hw = []

    for _ in range(M):
        h, w = list(map(int, input().split()))
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hw.append([h, w])

    #hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    #wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]

    Hlist = sorted(list(Hlist.items()), key=lambda x: x[1], reverse=True)
    Wlist = sorted(list(Wlist.items()), key=lambda x: x[1], reverse=True)

    hmaxset = set()
    wmaxset = set()

    maxH = Hlist[0][1]
    for k, v in Hlist:
        if v != maxH:
            break
        else:
            hmaxset.add(k)

    maxW = Wlist[0][1]
    for k, v in Wlist:
        if v != maxW:
            break
        else:
            wmaxset.add(k)


    flag = False
    count = 0
    for hh in hw:
        h = hh[0] - 1
        w = hh[1] - 1
        if h in hmaxset and w in wmaxset:
            count += 1

    lenhmax = len(hmaxset)
    lenwmax = len(wmaxset)

    if count != lenhmax * lenwmax:
        flag = True

    if flag:
        print((maxH + maxW))
    else:
        print((maxH + maxW - 1))





if __name__ == '__main__':
    solve()
# Original solution
import sys

h, w, m = list(map(int, input().split()))
row = [0]*h
col = [0]*w
bomb = []
for x in sys.stdin.readlines():
    H, W = list(map(int, x.split()))
    bomb.append([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)


# Optimized solution
import sys

h, w, m = list(map(int, input().split()))
row = [0]*h
col = [0]*w
bomb = set()
for x in range(m):
    H, W = list(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)
# Original solution
import sys

h, w, m = list(map(int, input().split()))
row = [0]*h
col = [0]*w
bomb = []
for x in range(m):
    H, W = list(map(int, input().split()))
    bomb.append((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)


# Optimized solution
import sys

h, w, m = list(map(int, input().split()))
row = [0]*h
col = [0]*w
bomb = set()
for x in sys.stdin.readlines():
    H, W = list(map(int, x.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)