Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lenlen = len(lsmaxx)*len(lsmaxy)
factor = 1
for i in lsmaxx:
    for j in lsmaxy:
        if not [i,j] in lsxy:
            factor = 0
            break
    if factor == 0:
        break
print(maxx+maxy-factor)


Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lenlen = len(lsmaxx)*len(lsmaxy)
for i in range(M):
    if lsxy[i][0] in lsmaxx and lsxy[i][1] in lsmaxy:
        lenlen -= 1
if lenlen == 0:
    factor = 1
else:
    factor = 0
print(maxx+maxy-factor)

Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lenlen = len(lsmaxx)*len(lsmaxy)
for i in range(M):
    if lsxy[i][0] in lsmaxx and lsxy[i][1] in lsmaxy:
        lenlen -= 1
if lenlen == 0:
    factor = 1
else:
    factor = 0
print(maxx+maxy-factor)

Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append((x,y))
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lsp = list(itertools.product(lsmaxx,lsmaxy))
factor = 1
for i in lsp:
    if not i in lsxy:
        factor = 0
        break
print(maxx+maxy-factor)

Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append((x,y))
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lsp = list(itertools.product(lsmaxx,lsmaxy))
ii = 0
for i in range(M):
    if lsxy[i] in lsp:
        ii += 1
if len(lsp)-ii == 0:
    factor = 1
else:
    factor = 0
print(maxx+maxy-factor)


Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append((x,y))
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lsp = list(itertools.product(lsmaxx,lsmaxy))
ii = 0
for i in range(M):
    if lsxy[i] in lsp:
        ii += 1
if len(lsp)-ii == 0:
    factor = 1
else:
    factor = 0
print(maxx+maxy-factor)


Fixed submission:
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)