Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

Alice = Sum(a[::2])
Bob = Sum(a[1::2])

print(Alice - Bob)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

Alice = sum(a[::2])
Bob = sum(a[1::2])

print(Alice - Bob)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

Alice = a[0::2]
Bob = a[1::2]

print(Alice - Bob)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

Alice = sum(a[::2])
Bob = sum(a[1::2])

print(Alice - Bob)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a*b%2 == 0{
  print("Even")
}else{
  print("Odd")
}


Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if a*b%2 == 0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
numbers = input()
number = list(number)
sum = 0
if number[0] == 1:
  sum = sum + 1
if number[1] == 1:
  sum = sum + 1
if number[2] == 1:
  sum = sum + 1
print(sum)

Fixed submission:
number = input()
sum = 0

for i in range(3):
  if number[i] == '1':
    sum += 1
print(sum)
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())

r = len(s) - len(t)
l = []
for start in range(r):
    count = 0
    for i in range(len(t)):
        if t[i] == s[start+i]:
            count +=1
    l.append(count)
ans = len(t)- max(l)
print(ans)
        

Fixed submission:
s = list(input())
t = list(input())

r = len(s) - len(t)
l = []
if r != 0:
    for start in range(r):
        count = 0
        for i in range(len(t)):
            if t[i] == s[start+i]:
                count +=1
        l.append(count)
    ans = len(t)- max(l)
else:
    count = 0
    for i in range(len(t)):
        if t[i] == s[i]:
            count +=1
    ans = len(t)- count   

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
a = list(map(int,input().split()))

l = list(itertools.combinations(a,2))
ans = 0
for i in l:
    ans += i[0]*i[1]
print(ans%(10**9 + 7))

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
ans = 0
total = 0
for i in range(N):
    if i != 0:
        total += a[i-1]
        ans += a[i]*total
print(ans%(10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(1,n):
    while True:
        if a[i] >= a[i-1]:
            break
        else:
            a[i] += 1
            ans += 1
print(ans)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(1,n):
    if a[i] >= a[i-1]:
        continue
    else:
        step = a[i-1] - a[i]
        a[i] += step
        ans += step
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
l = [0]*n

for i in range(1,n):
    while True:
        if a[i] >= a[i-1]:
            break
        else:
            a[i] += 1
            l[i] += 1
print(sum(l))



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(1,n):
    if a[i] >= a[i-1]:
        continue
    else:
        step = a[i-1] - a[i]
        a[i] += step
        ans += step
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy
K = int(input())

def seven(n):
    a = 0
    for i in range(1,n+1):
        a += 10**(i-1) * 7
    return a        

def main():
    ans = 0
    i = 1
    if K %2 == 0:
        ans = -1
    else:
        while True:
        #for _ in range(10):
            num = seven(i)
            a = K * num
            b = [int(x) for x in list(str(a))]
            if numpy.all(numpy.array(b) == 7):
                ans = len(b)
                break
            else:
                i += 1
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
K = int(input())

ai =0
ans = 0
# i = 1
l = set()

if K %2 == 0:
    ans = -1
else:
    for i in range(K):
        ai = (ai * 10 + 7) % K
        if ai == 0:
            ans = i+1
            break
        else:
            if ai in l:
                ans = -1
                break
            else:
                l.add(ai)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
l = []
num = int(N**0.5)+1

# for x in range(1,num+1):
#     for y in range(1,num+1):
#         for z in range(1,num+1):

for x,y,z in itertools.product(range(1, num+1), repeat=3):
    fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
    l.append(fn)

for i in range(1,N+1):
    print(l.count(i)) 


Fixed submission:
import itertools
N = int(input())
num = int(N**0.5)+1

ans = [0]*(N+1)

# for x in range(1,num+1):
#     for y in range(1,num+1):
#         for z in range(1,num+1):

for x,y,z in itertools.product(range(1, num+1), repeat=3):
    fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if fn > N:
        continue
    else:
        ans[fn] += 1

for i in range(1,len(ans)):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
l = []
num = int(N**0.5)+1

for x in range(1,num+1):
    for y in range(1,num+1):
        for z in range(1,num+1):
            fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
            l.append(fn)

for i in range(1,N+1):
    print(l.count(i)) 



Fixed submission:
import itertools
N = int(input())
num = int(N**0.5)+1

ans = [0]*(N+1)

# for x in range(1,num+1):
#     for y in range(1,num+1):
#         for z in range(1,num+1):

for x,y,z in itertools.product(range(1, num+1), repeat=3):
    fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if fn > N:
        continue
    else:
        ans[fn] += 1

for i in range(1,len(ans)):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):
#     total += b_l[j]
#     if total > K:
#         best0 = j-1
#         break
#     elif total == K:
#         best0 = j
#     else:
#         continue

for k in range(N+1):
    if i_l[i] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
    

Fixed submission:
N, M, K = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):
#     total += b_l[j]
#     if total > K:
#         best0 = j-1
#         break
#     elif total == K:
#         best0 = j
#     else:
#         continue

for k in range(N+1):
    if i_l[k] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

for i in range(1,N+1):
    count = a.count(i)
    print(count)

Fixed submission:
import collections
N = int(input())
a = list(map(int, input().split()))
l = [0]* N

for i in range(N-1):
    #print(i, a[i]-1)
    l[a[i]-1] += 1
#print(l)
for j in range(N):
    print(l[j])
Buggy python submission (verdict: Time Limit Exceeded):
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
k = int(input())
ans = 0

if k == 1:
    ans = 1
else:
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                a = math.gcd(i,j)
                b = math.gcd(a,k)
                ans += b
print(ans)

Fixed submission:
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
import numpy as np
import itertools
k = int(input())
ans = 0

if k == 1:
    ans = 1
else:
    for i in range(1,k+1):
        for j in range(1,k+1):
            a = math.gcd(i,j)
            for k in range(1,k+1):
                b = math.gcd(a,k)
                ans += b    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int,input().split(' '))
A_i = list()
for k in range(Q):
    k = int(input())
    A_i.append(k)

First = [K-Q] * N

for i in A_i:
    First[i] += 1
for j in First:
    if j <= 0:
        print('No')
    else:
        print('Yes') 

Fixed submission:
N,K,Q = map(int,input().split(' '))
A_i = list()
for k in range(Q):
    k = int(input())
    A_i.append(k)

First = [K-Q] * N

for i in A_i:
    First[i-1] += 1
for j in First:
    if j <= 0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
N,k = map(int,input().split())
l = list(map(int,input().split()))
cost = [0] * N

for i in range(N):
    temp = []
    for j in range(max(0,i-k),i):
        delta = cost[j]+abs(l[i]-l[j])
        temp.append(delta)
        cost[i] = min(temp)
print(cost[N-1])

Fixed submission:
N,k = map(int,input().split())
l = list(map(int,input().split()))
cost = [0] * N

for i in range(1,N):
    temp = []
    cost[i] = min([cost[j]+abs(l[i]-l[j]) for j in range(max(0,i-k),i)])
print(cost[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
# ABC100 C "*3 or /2"

import numpy
N = int(input())
a = numpy.array(list(map(int, input().split())))
# a.sort(reversed = False)
a.sort()
a = a[::-1]

count = 1

if all(elem % 2 !=0 for elem in a) == True:
    ans = 0
else:
    while True:
        if all(elem % 2 !=0 for elem in a) == True:
            ans = count -1
            break
        else:
            for ind in range(N):
                if a[ind] % 2 ==0:
                    i = ind
                    break
            a[i] = a[i]/2
            a[:i] = a[:i]*3
            a[i+1:] = a[i+1:]*3
            a.sort()
            a = a[::-1]
            count += 1
        
print(ans)

Fixed submission:
import numpy
N = int(input())
a = numpy.array(list(map(int, input().split())))
count = 0

for i in range(N):
    if a[i] % 2 == 0:
        x = a[i]
        while True:
            if x %2 != 0:
                break
            else:
                x = x/2
                count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
N = input()
l = list(map(int,N))
i = 0
#ans = l[0] - 1 + (len(l)-1)*9 #暫定の答え

if int(N) < 9:
    ans  = 0
elif l.count(9) >= len(l)-1:
    if l[len(l)-1] != 9:
        spot = 8
    else:
        spot = min(l)

else:
    while True:
        if l[i] < 9 and i < len(l)-1:
            spot = l[i] - 1
            break
        else:
            i += 1 
ans = spot + (len(l)-1)*9
print(ans)


Fixed submission:
N = input()
l = list(map(int,N))
i = 0
#ans = l[0] - 1 + (len(l)-1)*9 #暫定の答え

if int(N) < 9:
    ans  = int(N)

elif l.count(9) >= len(l)-1:
    if l[len(l)-1] != 9:
        spot = 8
    else:
        spot = min(l)
    ans = spot + (len(l)-1)*9

else:
    while True:
        if l[i] < 9 and i < len(l)-1:
            spot = l[i] - 1
            break
        else:
            i += 1 
    ans = spot + (len(l)-1)*9

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x,y = map(int,input().split())
ans = -1
i = 1

if x == y:
    ans = -1
else:
    while True:
        a = (x*i) % y
        if a != 0:
            ans = x*i
            break
        else:
            i += 1

print(ans)

Fixed submission:
x,y = map(int,input().split())
ans = -1
i = 1

while True:
    a = (x*i) % y
    if a != 0:
        ans = x*i
        break
    else:
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(N):
        if i+1 == a[j] and a[i] == j+1:
            ans += 1
            continue
print(int(ans/2))


Fixed submission:
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    if i+1 == a[a[i]-1]:
        ans += 1
        continue
print(ans // 2)
Buggy python submission (verdict: Runtime Error):
class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int,input().split())
uf = Unionfind(n)


for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)

print(uf.group_count()-1)

Fixed submission:
class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())

n, m = map(int,input().split())
uf = Unionfind(n)


for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

print(uf.group_count()-1)
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
if N >= 1000000:
    ans = 13969985
    N -= 1000000
else:
    ans = 0 

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for i in range(N):
    AB = make_divisors(i)
    ans += len(AB)

print(ans)

Fixed submission:
n = int(input())
ans = 0
for a in range(1, n):
    ans += (n - 1) // a
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
hoge = 10**9+7
if N == 1:
    print(0)
else:
    a = math.factorial(N) / math.factorial(N-2)
    b = 10**(N-2)
    print(a*b%hoge)

Fixed submission:
n = int(input())
mod = (10**9)+7
ans = (10**n) - 2*(9**n) + 8**n
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
s=input()
num=0
a=[]
for i in s:
    if i=="R":
        num+=1
    elif i!="R":
        a.append(num)
        num=0
print(max(a))

Fixed submission:
s=input()
num=0
a=[0]
for i in s:
    if i=="R":
        num+=1
        a.append(num)
    else:
        num=0
print(max(a))
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
n=int(input())
a=list(map(int,input().split()))
ans=functools.partial(functools.reduce,operator.mul)
print(-1 if ans(a)>10**18 else ans(a))

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

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

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=1
if 0 in a:
    ans=0
else:
    for i in a:
        ans*=i
        if ans>10**18:
            ans=-1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a,b=map(int,input().split())

for i in range(a,b+1):
    if i%n==0:
        flag=1
if flag==1:
    print("OK")
else:
    print("NG")


Fixed submission:
n=int(input())
a,b=map(int,input().split())
flag=0
for i in range(a,b+1):
    if i%n==0:
        flag=1
if flag==1:
    print("OK")
else:
    print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n+1):
  buka=a.count(i)
  print(buka)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in a:
  ans[i-1]+=1
for j in ans:
  print(j)
Buggy python submission (verdict: Runtime Error):
s=str(input())
n=int(len(s))
a=int(((n-1)/2)+1)
b=int(((n+3)/2)+1)
if s[0]==s[a] and s[b]==s[n-1]:
    print("Yes")
else:
    print("No")

Fixed submission:
s=str(input())
n=len(s)//2
f=s[:n]
if f==f[::-1] and f==s[n+1:]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
full=[]
while len(full)<n:
    for _ in range(a):
        full.append("b")
    for _ in range(b):
        full.append("r")
if len(full)>n:
    del full[n:-1]
print(full.count("b"))


Fixed submission:
N, A, B = map(int, input().split())
 
m = N%(A+B)
 
print((N//(A+B))*A + (A if m > A else m))
Buggy python submission (verdict: Runtime Error):
n=input()
print(n**3)


Fixed submission:
n=int(input())
print(n**3)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(sum(b)+ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(sum(b)+ans)
Buggy python submission (verdict: Runtime Error):
a=input()
s=input()
if a>=3200:
    print(s)
else:
    print("red")

Fixed submission:
a=int(input())
s=str(input())
if a>=3200:
    print(s)
else:
    print("red")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
a=s[k-1].lower
print(s[:k-1]+a+s[k:])

Fixed submission:
n,k=map(int,input().split())
s=input()
print(s[:k-1]+s[k-1].lower()+s[k:])
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print("Yay!" if A<=8 and B<=8 else ":(")

Fixed submission:
A=list(map(int,input().split()))
A=sorted(A)
print(abs(A[2]-A[0]))
Buggy python submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(m):
    if a[m]<x:
        ans+=1
 
print(min(ans,m-ans))

Fixed submission:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(n+1)
for i in a:
    b[i]=1
print(min(sum(b[:x]),sum(b[x:])))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
mod = 998244353

s = [] 
for i in range(k):
    lk = list(map(int, input().split()))
    for j in range(lk[0], lk[1] + 1):
        s.append(j)

dp = [0 for _ in range(n)]
dp[0] = 1

for i in range(1,n):
    for j in s:
        if i - j >= 0:
            dp[i] += dp[i-j]
            dp[i] %= mod

print(dp[-1]%mod)

Fixed submission:
n, k = map(int, input().split())
s = [] 
mod = 998244353

for i in range(k):
    l, r = map(int, input().split())
    s.append([l, r])

dp = [0 for _ in range(n+1)]
dp[1] = 1
dpsum = [0 for _ in range(n+1)]
dpsum[1] = 1

for i in range(2,n+1):
    for l, r in s:
        li = max(i-r,1)
        ri = max(i-l,0)
        dp[i] += (dpsum[ri] - dpsum[li-1])%mod
    dpsum[i] = (dpsum[i-1] + dp[i])%mod

print(dp[n]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = [] 
mod = 998244353

for i in range(k):
    l, r = map(int, input().split())
    s.append([l, r])

dp = [0 for _ in range(n+1)]
dp[1] = 1
dpsum = [0 for _ in range(n+1)]
dpsum[1] = 1

for i in range(2,n+1):
    for l, r in s:
        li = max(i-r,1)
        ri = max(i-l,0)
        dp[i] += dpsum[ri] - dpsum[li-1]
    dpsum[i] = dpsum[i-1] + dp[i]

print(dp[n]%mod)

Fixed submission:
n, k = map(int, input().split())
s = [] 
mod = 998244353

for i in range(k):
    l, r = map(int, input().split())
    s.append([l, r])

dp = [0 for _ in range(n+1)]
dp[1] = 1
dpsum = [0 for _ in range(n+1)]
dpsum[1] = 1

for i in range(2,n+1):
    for l, r in s:
        li = max(i-r,1)
        ri = max(i-l,0)
        dp[i] += (dpsum[ri] - dpsum[li-1])%mod
    dpsum[i] = (dpsum[i-1] + dp[i])%mod

print(dp[n]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
mod = 998244353

s = [] 
for i in range(k):
    lk = list(map(int, input().split()))
    for j in range(lk[0], lk[1] + 1):
        s.append(j)

dp = [0 for _ in range(n)]
dp[0] = 1

for i in range(1,n):
    for j in s:
        if i - j >= 0:
            dp[i] += dp[i-j]

print(dp[-1]%mod)

Fixed submission:
n, k = map(int, input().split())
s = [] 
mod = 998244353

for i in range(k):
    l, r = map(int, input().split())
    s.append([l, r])

dp = [0 for _ in range(n+1)]
dp[1] = 1
dpsum = [0 for _ in range(n+1)]
dpsum[1] = 1

for i in range(2,n+1):
    for l, r in s:
        li = max(i-r,1)
        ri = max(i-l,0)
        dp[i] += (dpsum[ri] - dpsum[li-1])%mod
    dpsum[i] = (dpsum[i-1] + dp[i])%mod

print(dp[n]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
a = [[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
    hi, wi = map(int, input().split())
    a[hi-1][wi-1] = 1

mh = [sum(a[i][:]) for i in range(h)]
mw = [sum([r[i] for r in a]) for i in range(w)]
ans = max(mh) + max(mw)

mh = [i for i, v in enumerate(mh) if v == max(mh)]
mw = [i for i, v in enumerate(mw) if v == max(mw)]

flag = 0
for i in mh:
    for j in mw:
        if a[i][j] == 0:
            print(ans)
            exit()
print(ans - 1)

Fixed submission:
h, w, m = map(int, input().split())
a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
mh = [0 for i in range(h)]
mw = [0 for j in range(w)]

for i, j in a:
    mh[i] += 1
    mw[j] += 1 

hmax = max(mh)
wmax = max(mw)
ans = hmax + wmax

flag = mh.count(hmax) * mw.count(wmax)
for i,j in a:
    if mh[i] == hmax and mw[j] == wmax:
        flag -= 1

if flag == 0:
    print(ans - 1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
a = [[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
    hi, wi = map(lambda x:int(x) - 1, input().split())
    a[hi][wi] = 1

mh = [sum(a[i][:]) for i in range(h)]
mw = [sum([r[i] for r in a]) for i in range(w)]
s = [["B" for _ in range(w)] for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == 0:
            v = mh[i] + mw[j]
            s[i][j] = v
        else:
            v = mh[i] + mw[j] - 1

        if v >= ans:
            ans = v
print(ans)

Fixed submission:
h, w, m = map(int, input().split())
a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
mh = [0 for i in range(h)]
mw = [0 for j in range(w)]

for i, j in a:
    mh[i] += 1
    mw[j] += 1 

hmax = max(mh)
wmax = max(mw)
ans = hmax + wmax

flag = mh.count(hmax) * mw.count(wmax)
for i,j in a:
    if mh[i] == hmax and mw[j] == wmax:
        flag -= 1

if flag == 0:
    print(ans - 1)
else:
    print(ans)