Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1,w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

max_H_list = [kv[0] for kv in cntH.items() if kv[1] == max(cntH.values())]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == max(cntW.values())]
ans = max(cntH.values()) + max(cntW.values())

flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if not flag:
    ans -= 1
print(ans)

Fixed submission:
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1, w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

maxH, maxW = max(cntH.values()), max(cntW.values())
max_H_list = [kv[0] for kv in cntH.items() if kv[1] == maxH]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == maxW]

ans = maxH + maxW - 1
flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if flag:
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
tot = set()
for i in range(M):
    h, w = map(int, input().split())
    tot.add((h-1,w-1))
    if h-1 in cntH:
        cntH[h-1] += 1
    else:
        cntH[h-1] = 1
    if w-1 in cntW:
        cntW[w-1] += 1
    else:
        cntW[w-1] = 1
#print(cntH, cntW)
ma = 0
for u in cntH.keys():
    for v in cntW.keys():
        res = cntH[u] + cntW[v]
        if (u, v) in tot:
            res -= 1
        ma = max(ma, res)
print(ma)

Fixed submission:
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1, w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

maxH, maxW = max(cntH.values()), max(cntW.values())
max_H_list = [kv[0] for kv in cntH.items() if kv[1] == maxH]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == maxW]

ans = maxH + maxW - 1
flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if flag:
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
tot = set()
for i in range(M):
    h, w = map(int, input().split())
    tot.add((h-1,w-1))
    if h-1 in cntH:
        cntH[h-1] += 1
    else:
        cntH[h-1] = 1
    if w-1 in cntW:
        cntW[w-1] += 1
    else:
        cntW[w-1] = 1
#print(cntH, cntW)
ma = 0
for u in cntH.keys():
    for v in cntW.keys():
        res = cntH[u] + cntW[v]
        if (u, v) in tot:
            res -= 1
        ma = max(ma, res)
print(ma)

Fixed submission:
H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1, w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

maxH, maxW = max(cntH.values()), max(cntW.values())
max_H_list = [kv[0] for kv in cntH.items() if kv[1] == maxH]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == maxW]

ans = maxH + maxW - 1
flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if flag:
    ans += 1

print(ans)