Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[c for c in range(h) if e1[c]==p1]
y=[c for c in range(w) if e2[c]==p2]
if len(x)*len(y)>m:
    print(p1+p2)
    exit()
for i in x:
    for j in y:
        if [i,j] not in g:
            print(p1+p2)
            exit()
print(p1+p2-1)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p+q-1)
else:
    print(p+q)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[c for c in range(h) if e1[c]==p1]
y=[c for c in range(w) if e2[c]==p2]
if len(x)*len(y)>m:
    print(p1+p2)
    exit()
for i in x:
    for j in y:
        if [i,j] not in g:
            print(p1+p2)
            exit()
print(p+q-1)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Time Limit Exceeded):
def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return 1
    elif v==w:
        return 0
    else:
        return -1


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])==1):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


def bis_exist(lis,dev):
    a=0
    b=len(lis)-1
    if lis[b]==dev:
        return 1
    while a<b:
        c=(a+b)//2
        if lis[c]==dev:
            return 1
        if comp(lis[c],dev)==1:
            a=c+1
        if comp(lis[c],dev)==-1:
            b=c
    return 0


h,w,m=map(int,input().split())
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
k=mergesort(g)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
if len(x)*len(y)>m:
    r=0
else:
    for i in x:
        for j in y:
            if bis_exist(k,[i,j])==0:
                r=0
                break
        else:
            continue
        break
print(p+q-r)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Time Limit Exceeded):
def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return 1
    elif v==w:
        return 0
    else:
        return -1


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])==1):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


def bis_exist(lis,dev):
    a=0
    b=len(lis)-1
    if lis[b]==dev:
        return 1
    while a<b:
        c=(a+b)//2
        if lis[c]==dev:
            return 1
        if comp(lis[c],dev)==1:
            a=c+1
        if comp(lis[c],dev)==-1:
            b=c
    return 0


h,w,m=map(int,input().split())
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
k=mergesort(g)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
if len(x)*len(y)>m:
    r=0
else:
    for i in x:
        for j in y:
            if bis_exist(k,[i,j])==0:
                r=0
                break
        else:
            continue
        break
print(p+q-r)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Time Limit Exceeded):
def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return True
    else:
        return False


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


h,w,m=map(int,input().split())
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
if len(x)*len(y)>m:
    r=0
else:
    for i in x:
        for j in y:
            if not ([i,j] in g):
                r=0
                break
        else:
            continue
        break
print(p+q-r)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)

Buggy python submission (verdict: Time Limit Exceeded):
def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return True
    else:
        return False


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


h,w,m=map(int,input().split())
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
for i in x:
    for j in y:
        if not ([i,j] in g):
            r=0
            break
    else:
        continue
    break
print(p+q-r)

Fixed submission:
h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)