Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
l = []

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    l.append((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

maxi = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            maxi += 1
            print(maxi)
            exit()
print(maxi)

Fixed submission:
import sys
input = sys.stdin.readline
l = set()

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    l.add((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

if len(hlist)*len(wlist) > m:
    print(maxh+maxw)
    exit()

ans = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            print(ans+1)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
d = defaultdict(list)

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    d[h-1].append(w-1)
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

maxi = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if j not in d[i]:
            maxi += 1
            print(maxi)
            exit()
print(maxi)

Fixed submission:
import sys
input = sys.stdin.readline
l = set()

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    l.add((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

if len(hlist)*len(wlist) > m:
    print(maxh+maxw)
    exit()

ans = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            print(ans+1)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
d = defaultdict(list)

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    d[h-1].append(w-1)
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

maxi = 0
for i in hlist:
    for j in wlist:
        ans = maxh + maxw
        if j in d[i]:
            ans -= 1
        maxi = max(maxi,ans)
        # print(maxi)
print(maxi)


Fixed submission:
import sys
input = sys.stdin.readline
l = set()

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    l.add((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

if len(hlist)*len(wlist) > m:
    print(maxh+maxw)
    exit()

ans = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            print(ans+1)
            exit()
print(ans)