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

H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    grid[h][w] = 1
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if grid[h][w] == 0:
            print(hmax + wmax)
            sys.exit(0)

print(hmax + wmax - 1)

Fixed submission:
H,W,M = map(int, input().split())
# grid = [[0 for _ in range(W)] for _ in range(H)]
bombs = set()

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    bombs.add((h, w))
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if (h,w) not in bombs:
            print(hmax + wmax)
            exit(0)

print(hmax + wmax - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [(0, h) for h in range(H)]
wc = [(0, w) for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    grid[h][w] = 1
    hc[h] = (hc[h][0] + 1, hc[h][1])
    wc[w] = (wc[w][0] + 1, wc[w][1])

hc = sorted(hc, key=lambda p: p[0], reverse=True)
wc = sorted(wc, key=lambda p: p[0], reverse=True)

hmax = hc[0][0]
wmax = wc[0][0]

uh = 0
while uh < H and hc[uh][0] == hmax:
    uh += 1

uw = 0
while uw < W and wc[uw][0] == wmax:
    uw += 1

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in range(uh):
    for w in range(uw):
        if grid[hc[h][1]][wc[w][1]] == 0:
            found = True
            break
    if found:
        break

print(hmax + wmax if found else hmax + wmax - 1)

Fixed submission:
H,W,M = map(int, input().split())
# grid = [[0 for _ in range(W)] for _ in range(H)]
bombs = set()

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    bombs.add((h, w))
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if (h,w) not in bombs:
            print(hmax + wmax)
            exit(0)

print(hmax + wmax - 1)

Buggy python submission (verdict: Runtime Error):
H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [(0, h) for h in range(H)]
wc = [(0, w) for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    grid[h-1][w-1] = 1
    hc[h-1] = (hc[h-1][0] + 1, hc[h-1][1])
    wc[w-1] = (wc[w-1][0] + 1, wc[w-1][1])

hc = sorted(hc, key=lambda p: p[0], reverse=True)
wc = sorted(wc, key=lambda p: p[0], reverse=True)

hmax = hc[0][0]
wmax = wc[0][0]

uh = 0
while hc[uh][0] == hmax:
    uh += 1

uw = 0
while wc[uw][0] == wmax:
    uw += 1

uh -= 1
uw -= 1
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in range(uh):
    for w in range(uw):

        if grid[hc[h][1]][wc[w][1]] == 0:
            found = True
            break
    if found:
        break

print(hmax + wmax if found else hmax + wmax - 1)

Fixed submission:
H,W,M = map(int, input().split())
# grid = [[0 for _ in range(W)] for _ in range(H)]
bombs = set()

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    bombs.add((h, w))
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if (h,w) not in bombs:
            print(hmax + wmax)
            exit(0)

print(hmax + wmax - 1)

Buggy python submission (verdict: Runtime Error):
H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [(0, h) for h in range(H)]
wc = [(0, w) for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    grid[h-1][w-1] = 1
    hc[h-1] = (hc[h-1][0] + 1, hc[h-1][1])
    wc[w-1] = (wc[w-1][0] + 1, wc[w-1][1])

hc = sorted(hc, key=lambda p: p[0], reverse=True)
wc = sorted(wc, key=lambda p: p[0], reverse=True)

hmax = hc[0][0]
wmax = wc[0][0]

uh = 0
while hc[uh][0] == hmax:
    uh += 1

uw = 0
while hc[uw][0] == wmax:
    uw += 1

uh -= 1
uw -= 1
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in range(uh):
    for w in range(uw):

        if grid[hc[h][1]][wc[w][1]] == 0:
            found = True
            break
    if found:
        break

print(hmax + wmax if found else hmax + wmax - 1)

Fixed submission:
H,W,M = map(int, input().split())
# grid = [[0 for _ in range(W)] for _ in range(H)]
bombs = set()

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    bombs.add((h, w))
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if (h,w) not in bombs:
            print(hmax + wmax)
            exit(0)

print(hmax + wmax - 1)