Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
m = [[False] * W for _ in range(H)]
dh = dict()
dw = dict()
for _ in range(M):
    h_, w_ = map(int, input().split())
    m[h_ - 1][w_ - 1] = True
    
    if h_ in dh:
        dh[h_] += 1
    else:
        dh[h_] = 1
        
    if w_ in dw:
        dw[w_] += 1
    else:
        dw[w_] = 1

dhl = list(dh.items())
dhl.sort(key=lambda x: x[1], reverse=True)
dwl = list(dw.items())
dwl.sort(key=lambda x: x[1], reverse=True)

h, w = [], []
maxh = dhl[0][1]
maxw = dwl[0][1]

for i, n in dhl:
    if n == maxh:
        h.append(i)
for i, n in dwl:
    if n == maxw:
        w.append(i)

res = maxh + maxw - 1
for hh in h:
    for ww in w:
        if m[hh - 1][ww - 1] is False:
            res = maxh + maxw
            break

print(res)


Fixed submission:
H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)

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

for h, w in bom:
    if rmax == row[h] and cmax == col[w]:
        cnt -= 1

print(rmax + cmax - (cnt == 0))

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
m = [[False] * W for _ in range(H)]
dh = dict()
dw = dict()
for _ in range(M):
    h_, w_ = map(int, input().split())
    m[h_ - 1][w_ - 1] = True
    
    if h_ in dh:
        dh[h_] += 1
    else:
        dh[h_] = 1
        
    if w_ in dw:
        dw[w_] += 1
    else:
        dw[w_] = 1

dhl = list(dh.items())
dhl.sort(key=lambda x: x[1], reverse=True)
dwl = list(dw.items())
dwl.sort(key=lambda x: x[1], reverse=True)

h, w = [], []
maxh = dhl[0][1]
maxw = dwl[0][1]

for i, n in dhl:
    if n == maxh:
        h.append(i)
for i, n in dwl:
    if n == maxw:
        w.append(i)

res = maxh + maxw - 1
for hh in h:
    for ww in w:
        if m[hh - 1][ww - 1] is False:
            res = maxh + maxw
            break

print(res)


Fixed submission:
H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)

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

for h, w in bom:
    if rmax == row[h] and cmax == col[w]:
        cnt -= 1

print(rmax + cmax - (cnt == 0))

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
d1 = dict()
d2 = dict()
G = [[False] * (W + 1) for _ in range(H + 1)]
for i in range(M):
    h, w = map(int, input().split())
    if h not in d1:
        d1[h] = 0
    if w not in d2:
        d2[w] = 0
    d1[h] += 1
    d2[w] += 1
    G[h][w] = True

d1 = list(d1.items())
d2 = list(d2.items())

d1.sort(reverse=True, key=lambda x: x[1])
d2.sort(reverse=True, key=lambda x: x[1])

print(d1[0][1] + d2[0][1] - int(G[d1[0][0]][d2[0][0]]))


Fixed submission:
H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)

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

for h, w in bom:
    if rmax == row[h] and cmax == col[w]:
        cnt -= 1

print(rmax + cmax - (cnt == 0))