Buggy python submission (verdict: Time Limit Exceeded):
import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for w, y in enumerate(Y):
    cntY.append((len(y), w))

cntX.sort(reverse=True)
cntY.sort(reverse=True)
maxX = cntX[0][0]
maxY = cntY[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for tmp, w in cntY:
        if tmp < maxY:
            break
        tmp += cnt - (w in x)
        if ans < tmp:
            ans = tmp
    if cnt == maxX + maxY:
        break
print(ans)


Fixed submission:
import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
cntX = [0] * H
cntY = [0] * W
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
    cntX[h] += 1
    cntY[w] += 1

maxX = max(cntX)
maxY = max(cntY)
ans = 0
if maxX > maxY:
    for i, cnt in enumerate(cntX):
        if cnt < maxX:
            continue
        for w in range(W):
            tmp = cnt + len(Y[w]) - (w in X[i])
            if ans < tmp:
                ans = tmp
else:
    for i, cnt in enumerate(cntY):
        if cnt < maxY:
            continue
        for h in range(H):
            tmp = cnt + len(X[h]) - (h in Y[i])
            if ans < tmp:
                ans = tmp
print(ans)


Fixed submission:
import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for y in Y:
    cntY.append((len(y), y))

cntX.sort(reverse=True)
maxX = cntX[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for w in range(W):
        tmp = cnt + len(Y[w]) - (w in x)
        if ans < tmp:
            ans = tmp
print(ans)


Fixed submission:
import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)