Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
if (hhh[0][0], www[0][0]) not in S:
    print(ans)
    sys.exit()
h = hhh[0][0]
for j in range(1, len(www)):
        if www[j][1] == www[j-1][1]:
            if (h, www[j][0]) not in S:
                print(ans)
                sys.exit()
        else:
            break
for i in range(1, len(hhh)):
    if hhh[i][1] == hhh[i-1][1]:
        h = hhh[i][0]
        if (h, www[0][0]) not in S:
            print(ans)
            sys.exit()
        for j in range(1, len(www)):
            if www[j][1] == www[j-1][1]:
                if (h, www[j][0]) not in S:
                    print(ans)
                    sys.exit()
            else:
                break
    else:
        break
print(ans-1)
        


Fixed submission:
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
h = hhh[0][1]
w = www[0][1]
ans = h+w
Nh = 0
Nw = 0
for i in range(len(hhh)):
    if h == hhh[i][1]:
        Nh += 1
    else:
        break
for i in range(len(www)):
    if w == www[i][1]:
        Nw += 1
    else:
        break
tt = Nh*Nw
if tt > M:
    print(ans)
    sys.exit()

for tmp in S:
    if hh[tmp[0]] == h and ww[tmp[1]] == w:
        tt -= 1
if tt > 0:
    print(ans)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
hhhh = deque([hhh[0][0]])
wwww = deque([www[0][0]])
for i in range(1, len(hhh)):
    if hhh[i][1] == hhh[i-1][1]:
        deque.append(hhhh, hhh[i][0])
    else:
        break
for i in range(1, len(www)):
    if www[i][1] == www[i-1][1]:
        deque.append(wwww, www[i][0])
    else:
        break
for h in hhhh:
    for w in wwww:
        if (h, w) not in S:
            print(ans)
            sys.exit()
print(ans-1)


Fixed submission:
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
h = hhh[0][1]
w = www[0][1]
ans = h+w
Nh = 0
Nw = 0
for i in range(len(hhh)):
    if h == hhh[i][1]:
        Nh += 1
    else:
        break
for i in range(len(www)):
    if w == www[i][1]:
        Nw += 1
    else:
        break
tt = Nh*Nw
if tt > M:
    print(ans)
    sys.exit()

for tmp in S:
    if hh[tmp[0]] == h and ww[tmp[1]] == w:
        tt -= 1
if tt > 0:
    print(ans)
else:
    print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
hhhh = [hhh[0][0]]
wwww = [www[0][0]]
for i in range(1, len(hhh)):
    if hhh[i][1] == hhh[i-1][1]:
        hhhh.append(hhh[i][0])
    else:
        break
for i in range(1, len(www)):
    if www[i][1] == www[i-1][1]:
        wwww.append(www[i][0])
    else:
        break
for h in hhhh:
    for w in wwww:
        if (h, w) not in S:
            print(ans)
            sys.exit()
print(ans-1)


Fixed submission:
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
h = hhh[0][1]
w = www[0][1]
ans = h+w
Nh = 0
Nw = 0
for i in range(len(hhh)):
    if h == hhh[i][1]:
        Nh += 1
    else:
        break
for i in range(len(www)):
    if w == www[i][1]:
        Nw += 1
    else:
        break
tt = Nh*Nw
if tt > M:
    print(ans)
    sys.exit()

for tmp in S:
    if hh[tmp[0]] == h and ww[tmp[1]] == w:
        tt -= 1
if tt > 0:
    print(ans)
else:
    print(ans-1)