Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
table=[]
H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    table.append((h1-1,w1-1))
    H[h1-1]+=1
    W[w1-1]+=1

h_flag=0
w_flag=0

Hm=max(H)
Wm=max(W)

Hh=[i for i, x in enumerate(H) if x == HM]
Ww=[i for i, x in enumerate(W) if x == Wm]

cnt=0

for (h, w) in table:
    if H[h] == HM and W[w] ==  Wm:
        cnt += 1

if cnt<len(Hh)*len(Ww):
    print(HM+Wm)
else:
    print(HM+Wm-1)



Fixed submission:
h,w,m=map(int,input().split())
table=[]
H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    table.append((h1-1,w1-1))
    H[h1-1]+=1
    W[w1-1]+=1

h_flag=0
w_flag=0

Hm=max(H)
Wm=max(W)

Hh=[i for i, x in enumerate(H) if x == Hm]
Ww=[i for i, x in enumerate(W) if x == Wm]

cnt=0

for (h, w) in table:
    if H[h] == Hm and W[w] ==  Wm:
        cnt += 1

if cnt<len(Hh)*len(Ww):
    print(Hm+Wm)
else:
    print(Hm+Wm-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
table=[]
H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    table.append((h1-1,w1-1))
    H[h1-1]+=1
    W[w1-1]+=1

h_flag=0
w_flag=0



Hh=[i for i, x in enumerate(H) if x == max(H)]
Ww=[i for i, x in enumerate(W) if x == max(W)]

cnt=0

for (h, w) in table:
    if H[h] == max(H) and W[w] == max(W):
        cnt += 1

if cnt<len(Hh)*len(Ww):
    print(max(H)+max(W))
else:
    print(max(H)+max(W)-1)



Fixed submission:
h,w,m=map(int,input().split())
table=[]
H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    table.append((h1-1,w1-1))
    H[h1-1]+=1
    W[w1-1]+=1

h_flag=0
w_flag=0

Hm=max(H)
Wm=max(W)

Hh=[i for i, x in enumerate(H) if x == Hm]
Ww=[i for i, x in enumerate(W) if x == Wm]

cnt=0

for (h, w) in table:
    if H[h] == Hm and W[w] ==  Wm:
        cnt += 1

if cnt<len(Hh)*len(Ww):
    print(Hm+Wm)
else:
    print(Hm+Wm-1)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())

H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    li_h.append(h1)
    li_w.append(w1)
    H[h1-1]+=1
    W[w1-1]+=1


h_flag=0
w_flag=0

if H.count(max(H))==1:
    ans_h=max(H)
    h_flag+=1

if W.count(max(W))==1:
    ans_w=max(W)
    w_flag+=1

if h_flag==1 and w_flag==1:
    print(max(H)+max(W))



else:
    if h_flag==1:
        for i in range(m):
            if li_w[i]==max(H):
                if li_h[i]==0:
                    print(max(H)+max(W))
                    h_flag+=1:
        else:
             h_flag==1:
             print(max(H)+max(W)-1)                   
                
            


    elif w_flag==1:
        for i in range(m):
            if li_h[i]==max(W):
                if li_w[i]==0:
                    print(max(H)+max(W))
                    w_flag+=1:
        else:
             w_flag==1:
             print(max(H)+max(W)-1)       



Fixed submission:
h,w,m=map(int,input().split())
table=[]
H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    table.append((h1-1,w1-1))
    H[h1-1]+=1
    W[w1-1]+=1

h_flag=0
w_flag=0

Hm=max(H)
Wm=max(W)

Hh=[i for i, x in enumerate(H) if x == Hm]
Ww=[i for i, x in enumerate(W) if x == Wm]

cnt=0

for (h, w) in table:
    if H[h] == Hm and W[w] ==  Wm:
        cnt += 1

if cnt<len(Hh)*len(Ww):
    print(Hm+Wm)
else:
    print(Hm+Wm-1)