Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
if len(aa)*len(bb)>m:
    print(am+bm)
    exit()
for i in aa:
    for j in bb:
        if [i,j] in bomb:
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=set([i for i, x in enumerate(a) if x==am])
bb=set([i for i, x in enumerate(b) if x==bm])
c=[0 for i in range(m)]
d=[0 for i in range(m)]
for x in bomb:
        c[x[0]-1]+=1
        d[x[1]-1]+=1
cm=max(c)
dm=max(d)
aaa=len(aa)
bbb=len(bb)
if cm<bbb or dm<aaa:
    print(am+bm)
else:
    print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if not [i,j] in bomb:
            print(am+bm)
            exit()
print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if not [i,j] in set(bomb):
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if [i,j] in bomb:
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if [i,j] in bomb:
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)