Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
S=[-int(1e10)]+[int(input()) for _ in range(A)]+[int(2e10)]
T=[-int(1e10)]+[int(input()) for _ in range(B)]+[int(2e10)]
for _ in range(Q):
    x=int(input())
    seq=False
    teq=False
    su=A+1
    sl=0
    while su-sl>1:
        t=(su+sl)//2
        if S[t]==x:
            seq=True
            break
        if S[t]>x: su=t
        else: sl=t
    tu=B+1
    tl=0
    while tu-tl>1:
        t=(tu+tl)//2
        if T[t]==x:
            teq=True
            break
        if T[t]>x: tu=t
        else: tl=t
    
    if seq and teq:
        print(0)
    elif seq:
        print(min(x-T[tl],T[tu]-x))
    elif teq:
        print(min(x-S[sl],S[su]-x))
    else:
        SU=S[su]-x
        TU=T[tu]-x
        SL=x-S[sl]
        TL=x-T[tl]
        print(min([max(SU,TU), max(SL,TL), SU*2+TL, TL*2+SU, TU*2+SL, SL*2+TU]))

Fixed submission:
A,B,Q=map(int,input().split())
S=[-int(1e10)]+[int(input()) for _ in range(A)]+[int(2e10)]
T=[-int(1e10)]+[int(input()) for _ in range(B)]+[int(2e10)]
for _ in range(Q):
    x=int(input())
    seq=False
    teq=False
    su=A+1
    sl=0
    while su-sl>1:
        t=(su+sl)//2
        if S[t]==x:
            seq=True
            break
        if S[t]>x: su=t
        else: sl=t
    tu=B+1
    tl=0
    while tu-tl>1:
        t=(tu+tl)//2
        if T[t]==x:
            teq=True
            break
        if T[t]>x: tu=t
        else: tl=t
    
    if seq and teq:
        print(0)
    elif seq:
        print(min(x-T[tl],T[tu]-x))
    elif teq:
        print(min(x-S[sl],S[su]-x))
    else:
        SU=S[su]-x
        TU=T[tu]-x
        SL=x-S[sl]
        TL=x-T[tl]
        print(min([max(SU,TU), max(SL,TL), SU*2+TL, TL*2+SU, TU*2+SL, SL*2+TU]))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    l=max(0,i-K)
    #m=min([d+abs(H[i]-h) for d,h in zip(dp[l:i],H[l:i])])
    m=min(map(lambda d,h:d+abs(H[i]-h),dp[l:i],H[l:i]))
    dp.append(m)
print(dp[-1])

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    l=max(0,i-K)
    m=min([d+abs(H[i]-h) for d,h in zip(dp[l:i],H[l:i])])
    #m=min(map(lambda d,h:d+abs(H[i]-h),dp[l:i],H[l:i]))
    dp.append(m)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    l=max(0,i-K)
    m=min([d+abs(H[i]-h) for d,h in zip(dp[l:i],H[l:i])])
    dp.append(m)
print(dp[-1])

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    l=max(0,i-K)
    m=min([d+abs(H[i]-h) for d,h in zip(dp[l:i],H[l:i])])
    #m=min(map(lambda d,h:d+abs(H[i]-h),dp[l:i],H[l:i]))
    dp.append(m)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    m=dp[i-1]+abs(H[i]-H[i-1])
    for j in range(2,K+1):
        if i-j<0: break
        m=min(m,dp[i-j]+abs(H[i]-H[i-j]))
    dp.append(m)
print(dp[-1])

Fixed submission:
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]#足場iまでの最小コスト
for i in range(1,N):
    l=max(0,i-K)
    m=min([d+abs(H[i]-h) for d,h in zip(dp[l:i],H[l:i])])
    #m=min(map(lambda d,h:d+abs(H[i]-h),dp[l:i],H[l:i]))
    dp.append(m)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
WV=[]
for _ in range(N):
    WV.append(tuple(map(int,input().split())))
#i番目までの品物をコストw以下になるように選ぶ
dp=[[0]*(N+1) for _ in range(W+1)]
for i in range(1,N+1):
    for w in range(1,W+1):
        if w<WV[i-1][0]:
            dp[w][i]=dp[w][i-1]
        else:
            dp[w][i]=max(dp[w][i-1],dp[w-WV[i-1][0]][i-1]+WV[i-1][1])
print(dp[W][N])

Fixed submission:
N,W=map(int,input().split())
WV=[]
for _ in range(N):
    WV.append(tuple(map(int,input().split())))
#i番目までの品物をコストw以下になるように選ぶ
dp=[[0]*(N+1) for _ in range(W+1)]
for i in range(1,N+1):
    for w in range(1,W+1):
        if w<WV[i-1][0]:
            dp[w][i]=dp[w][i-1]
        else:
            dp[w][i]=max(dp[w][i-1],dp[w-WV[i-1][0]][i-1]+WV[i-1][1])
print(dp[W][N])
Buggy python submission (verdict: Runtime Error):
N,H,W=map(int,input())
ans=0
for _ in range(N):
    a,b=map(int,input().split())
    if a>=H and b>=W:
        ans+=1
print(ans)

Fixed submission:
N,H,W=map(int,input().split())
ans=0
for _ in range(N):
    a,b=map(int,input().split())
    if a>=H and b>=W:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
n=len(S)
ans=0

i=0
while i<n-1:
    if S[i]=='B' and S[i+1]=='W':
        S[i],S[i+1]='W','B'
        ans+=1
        if i: i-=1
        else: i=1
    else:
        i+=1
print(ans)


Fixed submission:
S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)

Buggy python submission (verdict: Runtime Error):
S=list(input())
n=len(S)

def search(t,ans):
    if t==n-1:
        print(ans)
    elif S[t]=='B' and S[t+1]=='W':
        S[t],S[t+1]='W','B'
        if t: search(t-1,ans+1)
        else: search(1,ans+1)
    else:
        search(t+1,ans)
    
search(0,0)


Fixed submission:
S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)

Buggy python submission (verdict: Runtime Error):
S=list(input())
n=len(S)

def search(t):
    for i in range(t,n-1):
        if S[i]=='B' and S[i+1]=='W':
            S[i],S[i+1]='W','B'
            if i>0:
                return 1+search(i-1)
            else:
                return 1+search(1)
    return 0

print(search(0))


Fixed submission:
S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)

Buggy python submission (verdict: Runtime Error):
S=list(input())
n=len(S)

def search(t):
    for i in range(t,n-1):
        if S[i]=='B' and S[i+1]=='W':
            S[i],S[i+1]='W','B'
            if t>0:
                return 1+search(t-1)
            else:
                return 1+search(1)
    return 0

print(search(0))


Fixed submission:
S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
n=len(S)
ans=0
flag=True
while flag:
    flag=False
    for i in range(n-1):
        if S[i]=='B' and S[i+1]=='W':
            S[i],S[i+1]='W','B'
            ans+=1
            flag=True
print(ans)

Fixed submission:
S=list(input())
n=len(S)
ans=0
b=0

for s in S:
    if s=='B':b+=1
    else:ans+=b
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
inp=[]
for _ in range(N):
    inp.append(int(input()))
inp.sort(reverse=True)
    
data=[inp[0]]

for t in range(1,N):
    
    if t%2:
        a=inp[-(t//2+1)]
    else:
        a=inp[t//2]
    
    max_num=abs(data[0]-a)
    max_ind=0
     
    if max_num<abs(data[-1]-a):
        max_num=abs(data[-1]-a)
        max_ind=len(data)
         
    for i in range(1,len(data)):
        temp=abs(data[i]-a)+abs(data[i-1]-a)-abs(data[i]-data[i-1])
        if temp > max_num:
            max_num=temp
            max_ind=i
            
    data.insert(max_ind,a)
    
ans=0

for i in range(N-1):
    ans += abs(data[i+1]-data[i])
    
print(ans)

Fixed submission:
N=int(input())
inp=[]
for _ in range(N):
    inp.append(int(input()))
inp.sort()

if N%2:
    
    m1=inp[:(N//2+1)]
    M1=inp[(N//2+1):]
    
    m2=inp[:N//2]
    M2=inp[N//2:]
    
    a1=sum(M1)*2-sum(m1)*2+m1[-1]+m1[-2]
    a2=sum(M2)*2-sum(m2)*2-M2[0]-M2[1]
    
    print(max(a1,a2))
    
else:
    
    m=inp[:N//2]
    M=inp[N//2:]
    
    a=sum(M)*2-sum(m)*2+m[-1]-M[0]
    
    print(a)
Buggy python submission (verdict: Runtime Error):
import math
import sys

N,M=map(int,input().split())
length=N*M//math.gcd(N,M)

S=input()
T=input()

a=length//N
b=length//M
l=a*b//math.gcd(a,b)
s=l//a
t=l//b

for i in range(math.gcd(N,M)):
    if S[i*s]!=T[i*t]:
        print(-1)
        sys.exit()
print(length)



Fixed submission:
import sys

def gcd(a,b):
    if a<b:
        a,b = b,a
    if a%b==0:
        return b
    else:
        return gcd(a%b,b)
        
N,M=map(int,input().split())
length=N*M//gcd(N,M)

S=input()
T=input()

a=length//N
b=length//M
l=a*b//gcd(a,b)
s=l//a
t=l//b

for i in range(gcd(N,M)):
    if S[i*s]!=T[i*t]:
        print(-1)
        sys.exit()
print(length)
Buggy python submission (verdict: Runtime Error):
print(1100-int(input())

Fixed submission:
print(1110-int(input()))
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N,X=map(int,input().split())
x=list(map(int,input().split()))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
x.append(X)
x.sort()
y=[]

for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
    
print(gcd_list(y))

Fixed submission:
N,X=map(int,input().split())
x=list(map(int,input().split()))

def devidable(numbers,i):
    for number in numbers:
        if number%i: return False
    return True

def gcd(numbers):
    i=min(numbers)
    while True:
        if devidable(numbers,i): return i
        else: i-=1

x.append(X)
x.sort()
y=[]

for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
    
print(gcd(y))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=[]
memory.append(request[0][1])
head = request[0][0]
index = 0
ans = 0

def equalmin():
    if memory == []: return False
    else: return head == min(memory)

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if equalmin():
        ans +=1
        memory = []
    elif equal():
        index+=1
        memory.append(request[index][1])
    else: head +=1
        
print(ans)

Fixed submission:
N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=request[0][1]
head = request[0][0]
index = 0
ans = 0

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if head == memory:
        ans +=1
        memory = N+1
    elif equal():
        index +=1
        memory=min(request[index][1],memory)
    else: head +=1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=[]
memory.append(request[0])
head = request[0][0]
index = 0
ans = 0

def find(n,li):
    for row in li:
        if row[1]==n:return True
    return False

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if find(head,memory):
        ans +=1
        memory = []
    elif equal():
        index+=1
        memory.append(request[index])
    else: head +=1
        
print(ans)

Fixed submission:
N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=request[0][1]
head = request[0][0]
index = 0
ans = 0

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if head == memory:
        ans +=1
        memory = N+1
    elif equal():
        index +=1
        memory=min(request[index][1],memory)
    else: head +=1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))

a0=A[1:N-1]
a1n=A[0]
a2n=A[-1]
a1=A[0]
a2=A[-1]
while True:
    if a0==[]:break
    if a1n<a2n:
        a1n+=a0[0]
        a1.append(a0[0])
        a0.pop(0)
    else:
        a2n+=a0[-1]
        a2.insert(0,a0[0])
        a0.pop(-1)
        
a3n=a1[0]
a4n=a1[-1]
while True:
    if a1==[]:break
    elif a3n<a4n:
        a3n+=a1[0]
        a1.pop(0)
    else:
        a4n+=a1[-1]
        a1.pop(-1)
        
a5n=a2[0]
a6n=a2[-1]
while True:
    if a2==[]:break
    elif a5n<a6n:
        a5n+=a2[0]
        a2.pop(0)
    else:
        a6n+=a2[-1]
        a2.pop(-1)
        
num=[sum(a3),sum(a4),sum(a5),sum(a6)]
print(max(num)-min(num))

Fixed submission:
N=int(input())
if N%2: print(N*2)
else: print(N)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))

a0=A[1:N-1]
a1n=A[0]
a2n=A[-1]
a1=A[0]
a2=A[-1]
while True:
    if a0==[]:break
    if a1n<a2n:
        a1n+=a0[0]
        a1.append(a0[0])
        a0.pop(0)
    else:
        a2n+=a0[-1]
        a2.insert(0,a0[0])
        a0.pop(-1)
        
a3n=a1[0]
a4n=a1[-1]
while True:
    if a1==[]:break
    elif a3n<a4n:
        a3n+=a1[0]
        a1.pop(0)
    else:
        a4n+=a1[-1]
        a1.pop(-1)
        
a5n=a2[0]
a6n=a2[-1]
while True:
    if a2==[]:break
    elif a5n<a6n:
        a5n+=a2[0]
        a2.pop(0)
    else:
        a6n+=a2[-1]
        a2.pop(-1)
        
num=[sum(a3),sum(a4),sum(a5),sum(a6)]
print(max(num)-min(num))

Fixed submission:
N=int(input())
if N%2: print(N*2)
else: print(N)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

ans=9999999999

n1=min(min(A),max(A)-N)
n2=max(A)

for b in range(n1,n2):
    num=0
    for i,a in enumerate(A):
        num += abs(a-(b+i+1))
    if num<ans: 
        ans=num
print(ans)

Fixed submission:
import numpy as np

N=int(input())
A=list(map(int, input().split()))

AA=[]
for i,a in enumerate(A):
    AA.append(a-i+1)

b=np.median(AA)
ans=0

for a in AA:
    ans+=abs(a-b)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

ans=9999999999
for b in range(min(min(A),max(A)-N),max(A)):
    num=0
    for i,a in enumerate(A):
        num += abs(a-(b+i+1))
    if num<ans:ans=num
print(ans)

Fixed submission:
import numpy as np

N=int(input())
A=list(map(int, input().split()))

AA=[]
for i,a in enumerate(A):
    AA.append(a-i+1)

b=np.median(AA)
ans=0

for a in AA:
    ans+=abs(a-b)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

ans=99999999
for b in range(min(A)-N,max(A)+N+1):
    num=0
    for i,a in enumerate(A):
        num += abs(a-(b+i+1))
    if num<ans:ans=num
print(ans)

Fixed submission:
import numpy as np

N=int(input())
A=list(map(int, input().split()))

AA=[]
for i,a in enumerate(A):
    AA.append(a-i+1)

b=np.median(AA)
ans=0

for a in AA:
    ans+=abs(a-b)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
S=input()
ans=0
for i in S:
    if i='+':ans+=1
    else: i-=1

Fixed submission:
S=input()
ans=0
for i in S:
    if i=='+':ans+=1
    else: ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,len(s)+1):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])

Fixed submission:
s=input()
K=int(input())
substring=set()
for start in range(len(s)):
    for end in range(start+1,min(len(s)+1,start+K+1)):
        substring.add(s[start:end])
print(sorted(list(substring))[K-1])
Buggy python submission (verdict: Runtime Error):
a,b,c,d = int(input().split())
ans_list= []
ans_list.append(a*c)
ans_list.append(a*d)
ans_list.append(b*c)
ans_list.append(b*d)
print max(ans_list)


Fixed submission:
a,b,c,d = input().split()
ans_list= []
ans_list.append(int(a)*int(c))
ans_list.append(int(a)*int(d))
ans_list.append(int(b)*int(c))
ans_list.append(int(b)*int(d))
print(max(ans_list))
Buggy python submission (verdict: Runtime Error):
d, t, s = input().split()
if t*s >= d:
	print "Yes"
else:
	print "No"

Fixed submission:
d, t, s = map(int, input().split())
if t*s >= d:
	print ("Yes")
else:
	print ("No")

Buggy python submission (verdict: Runtime Error):
d, t, s = input().split()
if t*s >= d:
	return "Yes"
else:
	return "No"

Fixed submission:
d, t, s = map(int, input().split())
if t*s >= d:
	print ("Yes")
else:
	print ("No")
Buggy python submission (verdict: Runtime Error):
n = input()
if n % 9 == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in a:
  m = m*i
if m<= 10**18:
  print(m)
else:
  print(-1)

Fixed submission:
A, B = list(map(int, input().split()))
print(A * B)

Buggy python submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))
print(A * B

Fixed submission:
A, B = list(map(int, input().split()))
print(A * B)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in range(n):
  m = m*a[i]
if m<= 10**18:
  print(m)
else:
  print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        m = m * a[i]
        if m > 10 ** 18:
            print(-1)
            break
        elif i == n - 1:
            print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in a:
  m = m*i
print(m if m <= 10**18 else -1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        m = m * a[i]
        if m > 10 ** 18:
            print(-1)
            break
        elif i == n - 1:
            print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = []
for i in range(N):
    S = input()
    List.append(S)
New_List = []
for j in List:
    if j not in New_List:
        New_List.append(j)
print(len(New_List))

Fixed submission:
N = int(input())
List = []
for i in range(N):
    S = input()
    List.append(S)
print(len(set(List)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = ""
List = []
for i in range(N):
    S = input()
    List.append(S)
New_List = []
for j in List:
    if j not in New_List:
        New_List.append(j)
print(len(New_List))

Fixed submission:
N = int(input())
List = []
for i in range(N):
    S = input()
    List.append(S)
print(len(set(List)))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

s = []
for i in range(h):
   s.append(input().rstrip('\n'))

INF = 10 ** 10
d = [INF] * (h*w)

A = 10**18
B = 10**9

nex = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i, j) in [(-1,0),(1,0),(0,-1),(0,1),(0,0)]:
            continue
        else:
            nex.append((i,j))

d[(ch-1) * w + (cw-1)] = 0

T = ((-1,0), (1,0), (0,1), (0,-1))

q = [(ch-1)*A + (cw-1)*B + 0]
use = [0] * (h * w)

for x in q:
    curh = (x // A)
    x -= curh * A
    curw = (x // B)
    cnt = x - curw * B
    tmp = curh * w + curw
    if d[tmp] < cnt or use[tmp]: continue
    d[tmp] = cnt
    use[tmp] = 1

    for dh, dw in T:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and d[nh * w + nw] > cnt:
            d[nh * w + nw] = cnt
            use[nh * w + nw] = 0
            q.append(nh*A + nw*B + cnt)
    for dh, dw in nex:
        nh = curh + dh
        nw = curw + dw
        if nh >= 0 and nh < h and nw >= 0 and nw < w and s[nh][nw] == '.' and d[nh * w + nw] > cnt:
            d[nh * w + nw] = cnt + 1
            use[nh * w + nw]
            q.append(nh*A + nw*B + cnt+1)

# for item in d:
#     print(item)
gh -= 1
gw -= 1

if d[gh*w + gw] == INF:
    print(-1)
else:
    print(d[gh*w + gw])


Fixed submission:
def A():
    n, x, t = map(int, input().split())
    print(t * ((n+x-1)//x))

def B():
    n = list(input())
    s = 0
    for e in n:
        s += int(e)
    print("Yes" if s % 9 == 0 else "No")

def C():
    int(input())
    a = list(map(int, input().split()))
    l = 0
    ans = 0
    for e in a:
        if e < l: ans += l - e
        l = max(l, e)
    print(ans)

def E():
    h, w, m = map(int, input().split())
    row = [0] * h
    col = [0] * w
    exist = set([])
    th = 1000000000
    for i in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        row[x] += 1
        col[y] += 1
        exist.add(x*th + y)

    max_row = max(row)
    max_col = max(col)
    candi_row = []
    candi_col = []
    for i in range(h):
        if row[i] == max_row: candi_row.append(i)
    for i in range(w):
        if col[i] == max_col: candi_col.append(i)

    ans = max_row + max_col
    for x in candi_row:
        for y in candi_col:
            if x*th + y in exist: continue
            print(ans)
            return
    print(ans - 1)

E()
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
def my_gcd(a, b):
    if a < b: a, b = b, a
    c = a % b
    if c == 0: return b
    for _ in range(100):
        c = a % b
        a = b
        b = c
        if c == 0: return a

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = my_gcd(a, b)
        for c in range(1, k+1): ans += my_gcd(t, c)
print(ans)


Fixed submission:
from math import gcd
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans+=gcd(gcd(a,b),c)
print(ans)
Buggy python submission (verdict: Runtime Error):
from decimal import *
a, b, c = map(int, input().split())
if decimal(a) + decimal(b) < decimal(c):
  print("Yes")
else:
  print("No")

Fixed submission:
from decimal import *
a, b, c = map(int, input().split())
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
#----------------------------------------------------------
P = 10**9 + 7
N = 10000
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)


Fixed submission:
#----------------------------------------------------------
P = 10**9 + 7
N = 500000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)