CodeEff/ECCO huggingface dataset:
# Original 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)


# Optimized solution
import sys


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


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

bombw = [0]*w
bombh = [0]*h
bomb = [[0 for j in range(w)] for i in range(h)]
# print(bomb)
for i in range(m):
    hi,wi = list(map(int,input().split()))
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    bomb[hi-1][wi-1] = 1
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if bomb[i][j] == 0:
            print(ans)
            exit()
print((ans-1))

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

bombw = [0]*w
bombh = [0]*h
bomb = []
# print(bomb)
for i in range(m):
    hi,wi = list(map(int,input().split()))
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    bomb.append([str(hi-1)+"-"+str(wi-1)])
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if [str(i)+"-"+str(j)] not in bomb:
            print(ans)
            exit()
print((ans-1))
# Original solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def MAP1()  : return [int(x)-1 for x in input().split()]
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    regy = [0]*h
    regx = [0]*w
    c = [[0]*w for i in range(h)]
    for x in s:
        regy[x[0]] += 1
        regx[x[1]] += 1
        c[x[0]][x[1]] = 1
    maxy = 0
    indy = []
    for i in range(h):
        if maxy < regy[i]:
            indy = [i]
            maxy = regy[i]
        elif maxy == regy[i]:
            indy.append(i)
    maxx = 0
    indx = []
    for i in range(w):
        if maxx < regx[i]:
            indx = [i]
            maxx = regx[i]
        elif maxx == regx[i]:
            indx.append(i)

    ans = maxy + maxx
    tmp = 1
    if len(indy)*len(indx) > m:
        tmp = 0
    else:
        for y in indy:
            for x in indx:
                if c[y][x] == 0:
                    tmp = 0
    print((ans - tmp))

if __name__ == '__main__':
    solve()


# Optimized solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def MAP1()  : return [int(x)-1 for x in input().split()]
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += 1
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()
# Original solution
H, W, M, *HW = list(map(int, open(0).read().split()))

R = HW[::2]
C = HW[1::2]

A = [0] * (H + 1)
B = [0] * (W + 1)
for h, w in zip(*[iter(HW)] * 2):
    A[h] += 1
    B[w] += 1

S = set(zip(*[iter(HW)] * 2))

ans = 0
for r in R:
    for c in C:
        ans = max(ans, A[r] + B[c] - ((r, c) in S))

print(ans)

# Optimized solution
H, W, M, *HW = list(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)))
# Original solution
import sys
H, W, M = list(map(int, sys.stdin.readline().split()))
hlst = {}
wlst = {}
hwlst = []

for i in range(M):
    h, w = sys.stdin.readline().split()
    if h in hlst:
        hlst[h] += 1
    else:
        hlst[h] = 1

    if w in wlst:
        wlst[w] += 1
    else:
        wlst[w] = 1

    hwlst.append([h, w])

h = max(hlst.values())
w = max(wlst.values())
hmax = [i for i in hlst if hlst[i] == h]
wmax = [i for i in wlst if wlst[i] == w]
num = len(hmax)*len(wmax)
ans = h + w -1


for i in hwlst:
    if hlst[i[0]] == h and wlst[i[1]] == w:
        num -= 1

if num == 0:
    print(ans)
else:
    print((ans+1))


# Optimized solution
import sys
H, W, M = list(map(int, sys.stdin.readline().split()))
hlst = {}
wlst = {}
hwlst = []

for i in range(M):
    h, w = list(map(int, sys.stdin.readline().split()))
    if h in hlst:
        hlst[h] += 1
    else:
        hlst[h] = 1

    if w in wlst:
        wlst[w] += 1
    else:
        wlst[w] = 1

    hwlst.append([h, w])

h = max(hlst.values())
w = max(wlst.values())
hmax = [i for i in hlst if hlst[i] == h]
wmax = [i for i in wlst if wlst[i] == w]
num = len(hmax)*len(wmax)


for i in hwlst:
    if hlst[i[0]] == h and wlst[i[1]] == w:
        num -= 1

if num:
    print((h+w))
else:
    print((h+w-1))
# Original solution
H,W,M=list(map(int,input().strip().split()))
h=[0 for _ in range(H)]
w=[0 for _ in range(W)]

dp=[[0 for _ in range(W)] for _ in range(H)]
for m in range(M):
    i,j=list(map(int,input().strip().split()))
    dp[i-1][j-1]=1
    h[i-1]+=1
    w[j-1]+=1

h_max=0
hmax_l=[]
for i in range(H):
    if h_max==h[i]:
        hmax_l.append(i+1)
    elif h_max<h[i]:
        h_max=h[i]
        hmax_l=[]
        hmax_l.append(i+1)
w_max=0
wmax_l=[]
for i in range(W):
    if w_max==w[i]:
        wmax_l.append(i+1)
    elif w_max<w[i]:
        w_max=w[i]
        wmax_l=[]
        wmax_l.append(i+1)

d=True
for i in range(len(hmax_l)):
    for j in range(len(wmax_l)):
        if dp[hmax_l[i]-1][wmax_l[j]-1]==0:
            d=False
            break

ans=max(h)+max(w) if d==False else max(h)+max(w)-1
print(ans)

# Optimized solution
H,W,M=list(map(int,input().strip().split()))
h=[0 for _ in range(H)]
w=[0 for _ in range(W)]

dp=[]
for m in range(M):
    i,j=list(map(int,input().strip().split()))
    dp.append((i,j))
    h[i-1]+=1
    w[j-1]+=1

h_max=0
hmax_l=[]
for i in range(H):
    if h_max==h[i]:
        hmax_l.append(i+1)
    elif h_max<h[i]:
        h_max=h[i]
        hmax_l=[]
        hmax_l.append(i+1)
w_max=0
wmax_l=[]
for i in range(W):
    if w_max==w[i]:
        wmax_l.append(i+1)
    elif w_max<w[i]:
        w_max=w[i]
        wmax_l=[]
        wmax_l.append(i+1)

cnt=0
for m in range(M):
    if h[dp[m][0]-1]+w[dp[m][1]-1]==h_max+w_max:
        cnt+=1

ans=h_max+w_max if cnt<len(hmax_l)*len(wmax_l) else h_max+w_max-1
print(ans)
# Original solution
h,w,m = list(map(int,input().split()))
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = list(map(int,input().split()))
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0
while 1:
    if j > w:
        break
    if  x[i][1] == ma:
        if (x[i][0],y[j][0]) in s:
            pass
        else:
            if x[i][1]+y[j][1] == ma+mb:
                sw = 1
                break
        i += 1
    else:
        i = 0
        j += 1

    
print((ma+mb+sw-1))


# Optimized solution
import time

t0 = time.time()

h,w,m = list(map(int,input().split()))
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = list(map(int,input().split()))
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0
while 1:
    if j > w:
        break
    if  x[i][1] == ma:
        if (x[i][0],y[j][0]) in s:
            pass
        else:
            if x[i][1]+y[j][1] == ma+mb:
                sw = 1
                break
        i += 1
    else:
        i = 0
        j += 1
    if time.time() - t0 > 2.5:
        break

    
print((ma+mb+sw-1))
# Original solution
import  collections

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

H_count = collections.defaultdict(int)
W_count = collections.defaultdict(int)
points = set()
for m in range(M):
    h, w = list(map(int, input().split()))
    H_count[h] += 1
    W_count[w] += 1
    points.add((h, w))

H_count_sort = sorted(list(H_count.items()), key=lambda x: x[1])
W_count_sort = sorted(list(W_count.items()), key=lambda x: x[1])

max_count = 0
for h_count in reversed(H_count_sort):
    for w_count in reversed(W_count_sort):
        count = h_count[1] + w_count[1]
        if (h_count[0], w_count[0]) in points:
            count -= 1

        if max_count > count:
            break
        max_count = max(max_count, count)

print(max_count)

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

cnt_h = [0] * (H + 1)
cnt_w = [0] * (W + 1)
points = set()
for m in range(M):
    h, w = list(map(int, input().split()))
    cnt_h[h] += 1
    cnt_w[w] += 1
    points.add((h, w))

H_max = max(cnt_h)
W_max = max(cnt_w)

H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max]
W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max]

flag = 0
for h_num in H_max_num:
    for w_num in W_max_num:
        if (h_num, w_num) not in points:
            print((H_max + W_max))
            exit()

print((H_max + W_max -1))
# Original solution
def main():
    def solve(strings_max, rows_max, mapa):
        summa = maxs + maxr - 1
        if summa == h + w - 1 or summa == m:
            return summa
        for h_item in strings_max:
            for w_item in rows_max:
                if w_item not in mapa.get(h_item, []):
                    return summa + 1
        return summa


    h, w, m = list(map(int, input().split()))
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = list(map(int, input().split()))
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    maxs = max(strings)
    maxr = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == maxs:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == maxr:
            rows_max.append(i)
    
    ans = solve(strings_max, rows_max, mapa)
    print(ans)

main()


# Optimized solution
def main():
    h, w, m = list(map(int, input().split()))
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = list(map(int, input().split()))
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print((max_s + max_r))
    else:
        print((max_s + max_r - 1))

main()
# Original solution
from collections import deque
H, W, M = list(map(int, input().split()))
grid = [[0 for _ in range(W)] for _ in range(H)]
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = list(map(int, input().split()))
  h -= 1
  w -= 1
  grid[h][w] = 1
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = deque([])
k = 0
while k < H:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while k < W:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:  
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      if grid[h][w] == 0:
        ans += 1
        break
    else:
      continue
    break
print(ans)


# Optimized solution
from collections import deque
H, W, M = list(map(int, input().split()))
bomb = []
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = list(map(int, input().split()))
  h -= 1
  w -= 1
  bomb.append([h, w])
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
k = 0
while k < H:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while k < W:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:  
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      if [h, w] not in bomb:
        ans += 1
        break
    else:
      continue
    break
print(ans)
# Original solution
from collections import deque
H, W, M = list(map(int, input().split()))
bomb = []
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = list(map(int, input().split()))
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
k = 0
while k < H:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while k < W:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)


# Optimized solution
from collections import deque
H, W, M = list(map(int, input().split()))
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = list(map(int, input().split()))
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
hw = []
cnt_h, cnt_w = [0] * H, [0] * W
for i in range(M):
    x, y = list(map(int, input().split()))
    hw.append((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]

from itertools import product

for h, w in product(h_list, w_list):
    if (h, w) not in set(hw):
        print((max_h + max_w))
        break
else:
    print((max_h + max_w - 1))
    

# Optimized solution
H, W, M = list(map(int, input().split()))
hw = set()
cnt_h, cnt_w = [0] * H, [0] * W
for i in range(M):
    x, y = list(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)
# Original solution
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = list(map(int,input().split()))
l_h = [0]*(h+1)
l_w = [0]*(w+1)
a = min(h*w,3*10**5)
l_hw = [[0 for _ in range(a)] for __ in range(h+1)]

for x in range(m):
    h,w = list(map(int,input().split()))
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h][x] += w

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

for i in l_h_2:
    flag = False
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)

# Optimized solution
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = list(map(int,input().split()))
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = list(map(int,input().split()))
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

flag = False

for i in l_h_2:
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)
# Original solution
import itertools
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = list(map(int,input().split()))
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = list(map(int,input().split()))
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)


for i,j in itertools.product(l_h_2,l_w_2):
    if j not in l_hw[i]:
        break
else:
    ans -= 1

print(ans)

# Optimized solution
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = list(map(int,input().split()))
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = list(map(int,input().split()))
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)
# Original solution
h,w,m=list(map(int,input().split()))
s=[0]*m
t=[0]*m
temp=[0]*m
for i in range(m):
  sm,tm=list(map(int,input().split()))
  s[i]=sm
  t[i]=tm
  temp[i]=[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)
        exit()
  else:
    print((ans-1))

# Optimized solution
h,w,m=list(map(int,input().split()))
s=[0]*m
t=[0]*m
temp=set()
for i in range(m):
  sm,tm=list(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)
        exit()
  else:
    print((ans-1))
# Original solution
h,w,m=list(map(int, input().split()))
r = [0]*max(h,w)
c = [0]*max(h,w)
l=[]

for i in range(m):
    x,y=list(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
#print(l,ci,ri)
for i in range(m):
    if l[i][0]-1 in ri and l[i][1]-1 in ci:
        cnt += 1

if cnt == len(ci)*len(ri):
    print((int(ans)-1))
else:
    print((int(ans)))

# Optimized solution
h,w,m=list(map(int, input().split()))
r = [0]*max(h,w)
c = [0]*max(h,w)
l=[]

for i in range(m):
    x,y=list(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
#print(l,ci,ri)
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)))