Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=defaultdict()
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb[(hi,wi)]=True

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not bomb[(i,j)]:
            ofst=0
            break
                
print(hmax+wmax+ofst)


Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=defaultdict(False)
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb[(hi,wi)]=True

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not bomb[(hi,wi)]:
            ofst=0
            break
                
print(hmax+wmax+ofst)


Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
#存在チェックのアクセスがリストで持たせるより高速
#リストは突っ込めないので注意(hashabeのみOK)
bomb=defaultdict(False)
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb[(hi,wi)]=True

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if !bomb[(hi,wi)]:
            ofst=0
            break
                
print(hmax+wmax+ofst)


Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
#O(H)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add([hi,wi])

#O(H)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(H)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(H**2)
ofst=-1
for i in hidx:
    for j in widx:
        if not [i,j] in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=[]
#O(M)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.append([hi,wi])

#O(M)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(M)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(M**2*)
ofst=-1
for i in hidx:
    for j in widx:
        if not [i,j] in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush


h,w,m=[int(x) for x in input().split()]

#defaultdictにすることにより後に使うmax関数のコストを削減
hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=[]
#O(M)
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add([hi,wi])

#O(M)
hmax=max(hcnt.values())
wmax=max(wcnt.values())

#O(M)
hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

#O(M**2*)
ofst=-1
for i in hidx:
    for j in widx:
        if not [i,j] in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
bomb=[]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    bomb.append((hi,wi))

hmax=max(hnm)
wmax=max(wnm)
    
hidx=[]
for idx,val in enumerate(hnm):
    if hmax==val:
        hidx.append(idx)
    
widx=[]
for idx,val in enumerate(wnm):
    if wmax==val:
        widx.append(idx)
    
ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
bomb=[]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    bomb.append((hi,wi))

sth=[[j,i] for i,j in enumerate(hnm)]
sth.sort(reverse=True)
stw=[[j,i] for i,j in enumerate(wnm)]
stw.sort(reverse=True)
    
hmax=-1
hidx=[]
for val,idx in sth:
    if hmax==-1:
        hmax=val
    elif hmax!=val:
        break
    hidx.append(idx)
    
wmax=-1
widx=[]
for val,idx in stw:
    if wmax==-1:
        wmax=val
    elif wmax!=val:
        break
    widx.append(idx)
    
ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in range(h):
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in range(w):
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in range(h):
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in range(w):
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1<<20)
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in hnm:
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in wnm:
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1<<20)
h,w,m=[int(x) for x in input().split()]

hnm=[0]*h
wnm=[0]*w
hw=[[0]*w for _ in range(h)]
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hnm[hi]+=1
    wnm[wi]+=1
    hw[hi][wi]+=1

hm_idx=[]
hm_val=-1
for i in hnm:
    if hnm[i]>hm_val:
        hm_idx=[i]
        hm_val=hnm[i]
    elif hnm[i]==hm_val:
        hm_idx.append(i)

mn1=True
wm_val=-1
for i in wnm:
    if wnm[i]>wm_val:
        wm_val=wnm[i]
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
    elif wnm[i]==wm_val:
        mn1=True
        for j in hm_idx:
            if hw[j][i]==0:
                mn1=False
                break
                
print(hm_val+wm_val+(-1 if mn1 else 0))

Fixed submission:
from collections import Counter
from collections import defaultdict
from heapq import heapify
from heapq import heappop
from heapq import heappush
from _collections import defaultdict

h,w,m=[int(x) for x in input().split()]

hcnt=defaultdict(int)
wcnt=defaultdict(int)
bomb=set()
for _ in range(m):
    hi,wi=[int(x)-1 for x in input().split()]
    hcnt[hi]+=1
    wcnt[wi]+=1
    bomb.add((hi,wi))

hmax=max(hcnt.values())
wmax=max(wcnt.values())

hidx=[x for x,y in hcnt.items() if y==hmax]
widx=[x for x,y in wcnt.items() if y==wmax]

ofst=-1
for i in hidx:
    for j in widx:
        if not (i,j) in bomb:
            ofst=0
            break
                
print(hmax+wmax+ofst)