qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import itertools
def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

H,W,M=map(int,input().split())
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for m  in range(M):
    P.append(list(map(int,input().split())))
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
#max_X=my_index(P_X,Max_X)
#max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in P:
    if  P_X[k[0]] == Max_X and P_Y[k [1]] == Max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)

Fixed code:

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

H,W,M=map(int,input().split())
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for m  in range(M):
    P.append(list(map(int,input().split())))
    P_X[P[m][0]]+=1
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
max_X=my_index(P_X,Max_X)
max_Y=my_index(P_Y,Max_Y)
m_count=0
for k in P:
    if  P_X[k[0]] == Max_X and P_Y[k [1]] == Max_Y:
        m_count += 1
if m_count==len(max_X)*len(max_Y):
    answer=Max_X+Max_Y-1
else:
     answer=Max_X+Max_Y
    
print(answer)
Buggy code:
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)
for y in [i for i,v in enumerate(H) if v==mh]:
  for x in [i for i,v in enumerate(W) if v==mw]:
    print(y,x)
    if y*h+x not in P:
      print(mh+mw)
      exit()

print(mh+mw-1)


Fixed code:
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)
Buggy code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = max(hc)
    maw = max(wc)
    ans = mah+maw
    hmaps = []
    wmaps = []
    for i, h in enumerate(hc):
        if mah == h:
            hmaps.append(i)
    for i, w in enumerate(wc):
        if maw == w:
            wmaps.append(i)

    for h in hmaps:
        for w in wmaps:
            if (h, w) not in maps:
                print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = max(hc)
    maw = max(wc)
    ans = mah+maw
    hmaps = []
    wmaps = []
    for i, h in enumerate(hc):
        if mah == h:
            hmaps.append(i)
    for i, w in enumerate(wc):
        if maw == w:
            wmaps.append(i)

    for h in hmaps:
        for w in wmaps:
            if (h, w) not in maps:
                print(ans)
                return
    else:
        print(ans-1)


if __name__ == '__main__':
    main()
Buggy code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = -1
    maw = -1
    hmaps = set()
    wmaps = set()
    for i, h in enumerate(hc):
        if mah < h:
            mah = h
            hmaps = {i}
        elif mah == h:
            hmaps.add(i)
    for i, w in enumerate(wc):
        if maw < w:
            maw = w
            wmaps = {i}
        elif maw == w:
            wmaps.add(i)
    ans = mah*maw
    aru = True

    for h in list(hmaps):
        for w in list(wmaps):
            if (h, w) not in maps:
                aru = False
                break
    if aru:
        print(ans - 2)
    else:
        print(ans + 1)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = -1
    maw = -1
    hmaps = set()
    wmaps = set()
    for i, h in enumerate(hc):
        if mah < h:
            mah = h
            hmaps = {i}
        elif mah == h:
            hmaps.add(i)
    for i, w in enumerate(wc):
        if maw < w:
            maw = w
            wmaps = {i}
        elif maw == w:
            wmaps.add(i)
    ans = mah+maw
    aru = True
    if len(hmaps) * len(wmaps) <= 5*10**6:
        for h in list(hmaps):
            for w in list(wmaps):
                if (h, w) not in maps:
                    aru = False
                    break
    else:
        aru = False
    if aru:
        print(ans - 1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
Buggy code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


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


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


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

h_max = max(D1.values())
w_max = max(D2.values())
A=[i for i,v in D1.items() if v==h_max]
B=[i for i,v in D2.items() if v==w_max]

minus = -1
for i in A:
    for j in B:
        if (i, j) not in s:
            minus = 0
            break

print(w_max+h_max-minus)






Fixed code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


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


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


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

h_max = max(D1.values())
w_max = max(D2.values())
A=[i for i,v in D1.items() if v==h_max]
B=[i for i,v in D2.items() if v==w_max]

flg = 1
for i in A:
    for j in B:
        if (i, j) not in s:
            flg = 0
            break

print(w_max+h_max-flg)
Buggy code:
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 = maxh + maxw - 1
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) in d:
            result = maxh + maxw
            break
print(result)


Fixed code:
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)
Buggy code:
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 == x:
        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)

Fixed code:
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)
Buggy code:
from collections import defaultdict
H,W,M = list(map(int,input().split()))

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

hw = defaultdict(set)

for _ in range(H):
    hw.append([0] * W)

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 in hw[x]:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)



Fixed code:
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)
Buggy code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[(tmp_h-1, tmp_w-1)] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)

Fixed code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[(tmp_h-1, tmp_w-1)] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(int(h_max + w_max))
else:
    print(int(h_max + w_max - 1))
Buggy code:
H, W, M = map(int,input().split())
ARR = []

for i in range(M):
    ARR.append(list(map(int,input().split())))

def calculate(h, w, m, arr):
    points = set()



    rowSum = [0 for i in range(h)]
    columnSum = [0 for i in range(w)]

    for ar in arr:
        points.add((ar[0]-1, ar[1]-1))
        rowSum[ar[0]-1] += 1
        columnSum[ar[1]-1] += 1

    maxRowSum = max(rowSum)
    maxColumnSum = max(columnSum)


    a0 = []

    for i in range(len(rowSum)):
        if rowSum[i] == maxRowSum:
            a0.append(i)

    a1 = []
    for i in range(len(columnSum)):
        if columnSum[i] == maxColumnSum:
            a1.append(i)

    result = 0
    for hIndex in a0:
        for wIndex in a1:

            if (hIndex,wIndex) in points:
                result = max(result, maxRowSum + maxColumnSum - 1)
            else:
                result = max(result, maxRowSum + maxColumnSum)
                print(result)
                break

    print(result)


calculate(H, W, M, ARR)


Fixed code:
H, W, M = map(int,input().split())
ARR = []

for i in range(M):
    ARR.append(list(map(int,input().split())))

def calculate(h, w, m, arr):
    points = set()



    rowSum = [0 for i in range(h)]
    columnSum = [0 for i in range(w)]

    for ar in arr:
        points.add((ar[0]-1, ar[1]-1))
        rowSum[ar[0]-1] += 1
        columnSum[ar[1]-1] += 1

    maxRowSum = max(rowSum)
    maxColumnSum = max(columnSum)


    a0 = []

    for i in range(len(rowSum)):
        if rowSum[i] == maxRowSum:
            a0.append(i)

    a1 = []
    for i in range(len(columnSum)):
        if columnSum[i] == maxColumnSum:
            a1.append(i)

    result = 0
    for hIndex in a0:
        for wIndex in a1:

            if (hIndex,wIndex) in points:
                result = max(result, maxRowSum + maxColumnSum - 1)
            else:
                result = max(result, maxRowSum + maxColumnSum)
                print(result)
                exit()

    print(result)


calculate(H, W, M, ARR)
Buggy code:
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])
    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] in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)

Fixed code:
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)
Buggy code:
H, W, M = map(int, input().split())

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

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)


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

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

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

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

for i in range(len(bom)):
  if bom[i][0] in mwl and bom[i][1] in mhl:
    count-=1
if count<=0:
  print(ans-1)
else:
  print(ans)


Fixed code:
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)
Buggy code:
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) * WM.count(WL)

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)

Fixed code:
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)
Buggy code:
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    B.append((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

Fixed code:
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
Hcountmax=max(Hcount)
Wcountmax=max(Wcount)
h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax]
w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)
Buggy code:
h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
bomb = set()
h_list = [0] * (h+1)
w_list = [0] * (w+1)
for H,W in hw:
  h_list[H] += 1
  w_list[W] += 1
  bomb.add((H,W))
max_h = max(h_list)
max_w = max(w_list)
maxh_list = []
maxw_list = []
for k,v in enumerate(h_list):
  if v == max_h:
    maxh_list.append(k)
for k,v in enumerate(w_list):
  if v == max_w:
    maxw_list.append(k)
if len(maxh_list) * len(maxv_list) > m:
  ans = max_h * max_w
else:
  ans = max_h * max_w - 1
  for i in maxh_list:
    for j in maxw_list:
      if (i,j) not in bomb:
        ans = max_h * max_w
        break
print(ans)
      

Fixed code:
h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
bomb = set()
h_list = [0] * (h+1)
w_list = [0] * (w+1)
for H,W in hw:
  h_list[H] += 1
  w_list[W] += 1
  bomb.add((H,W))
max_h = max(h_list)
max_w = max(w_list)
maxh_list = []
maxw_list = []
for k,v in enumerate(h_list):
  if v == max_h:
    maxh_list.append(k)
for k,v in enumerate(w_list):
  if v == max_w:
    maxw_list.append(k)
if len(maxh_list) * len(maxw_list) > m:
  ans = max_h + max_w
else:
  ans = max_h + max_w - 1
  for i in maxh_list:
    for j in maxw_list:
      if (i,j) not in bomb:
        ans = max_h + max_w
        break
print(ans)
Buggy code:
from collections import defaultdict as dd
h, w, m = map(int, input().split())

#dic[row, col] -> set(ids)
h_dic = dd(int)
w_dic = dd(int)
spot = set()

for i in range(m):
    h_c, w_c = map(int, input().split())
    h_dic[h_c] += 1
    w_dic[w_c] += 1
    spot.add((h_c, w_c))
#print(h_dic, w_dic)

#H_lis -> [i, num_spot(int)]
max_h_num = 0
for key, val in h_dic.items():
    max_h_num = max(max_h_num, val)
max_w_num = 0
W_lis = []
for key, val in w_dic.items():
    max_w_num = max(max_w_num, val)


#print(H_lis, W_lis)
#print(max_h)

ans = 0
max_h_lis = [key for key in h_dic if h_dic[key] == max_h_num]
max_w_lis = [key for key in w_dic if w_dic[key] == max_w_num]
for i in max_h_lis:
    for j in max_w_lis:
        if (i, j) not in spot:
            print(max_h_num * max_w_num)
            break
else:
    print(max_h_num * max_w_num - 1)

"""    
max_counter = 0
for i in h_dic.keys():
    for j in w_dic.keys():
        counter = len(h_dic[i] | w_dic[j])
        #print(i, j, h_dic[i] | w_dic[j],counter)
        max_counter = max(max_counter, counter)
print(max_counter)

"""

Fixed code:
from sys import exit
from collections import defaultdict as dd
h, w, m = map(int, input().split())

#dic[row, col] -> set(ids)
h_dic = dd(int)
w_dic = dd(int)
spot = set()

for i in range(m):
    h_c, w_c = map(int, input().split())
    h_dic[h_c] += 1
    w_dic[w_c] += 1
    spot.add((h_c, w_c))
#print(h_dic, w_dic)

#H_lis -> [i, num_spot(int)]
max_h_num = 0
for key, val in h_dic.items():
    max_h_num = max(max_h_num, val)
max_w_num = 0
W_lis = []
for key, val in w_dic.items():
    max_w_num = max(max_w_num, val)


#print(H_lis, W_lis)
#print(max_h)

ans = 0
max_h_lis = [key for key in h_dic if h_dic[key] == max_h_num]
max_w_lis = [key for key in w_dic if w_dic[key] == max_w_num]
for i in max_h_lis:
    for j in max_w_lis:
        if (i, j) not in spot:
            print(max_h_num + max_w_num)
            exit()
else:
    print(max_h_num + max_w_num - 1)

"""    
max_counter = 0
for i in h_dic.keys():
    for j in w_dic.keys():
        counter = len(h_dic[i] | w_dic[j])
        #print(i, j, h_dic[i] | w_dic[j],counter)
        max_counter = max(max_counter, counter)
print(max_counter)

"""
Buggy code:
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()

Fixed code:
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 not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)