Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
H, W, M = map(int, input().split())
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(tate.items(), key=lambda x:x[1], reverse=True)
yoko = sorted(yoko.items(), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            else:
                break
    else:
        break
print(ans)

Fixed submission:
from collections import defaultdict
H, W, M = map(int, input().split())
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(tate.items(), key=lambda x:x[1], reverse=True)
yoko = sorted(yoko.items(), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if ans == tate_m + yoko_m:
        break
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            else:
                break
    else:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
H, W, M = map(int, input().split())
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(tate.items(), key=lambda x:x[1], reverse=True)
yoko = sorted(yoko.items(), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            elif yoko[j][1] == yoko_m - 1:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 2)
                else:
                    ans = max(ans, tate_m + yoko_m - 1)
            else:
                break
    elif tate[i][1] == tate_m - 1:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 2)
                else:
                    ans = max(ans, tate_m + yoko_m - 1)
            else:
                break
    else:
        break
print(ans)

Fixed submission:
from collections import defaultdict
H, W, M = map(int, input().split())
tate = defaultdict(int)
yoko = defaultdict(int)
T = {}
for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1]+= 1
    T[(h-1, w-1)] = 1

tate = sorted(tate.items(), key=lambda x:x[1], reverse=True)
yoko = sorted(yoko.items(), key=lambda x:x[1], reverse=True)
tate_m = tate[0][1]
yoko_m = yoko[0][1]
ans = 0
for i in range(len(tate)):
    if ans == tate_m + yoko_m:
        break
    if tate[i][1] == tate_m:
        for j in range(len(yoko)):
            if yoko[j][1] == yoko_m:
                if (tate[i][0], yoko[j][0]) in T:
                    ans = max(ans, tate_m + yoko_m - 1)
                else:
                    ans = max(ans, tate_m + yoko_m)
            else:
                break
    else:
        break
print(ans)