Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, w = (int(x) for x in input().split())
dp = [[0 for i in range(w+1)] for j in range(n+1)] 
for i in range(n):
    a, b = (int(x) for x in input().split())
    for j in range(w+1):
        if j < a:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max([dp[i][j], dp[i][j-a]+b])
print(max(list(itertools.chain.from_iterable(dp))))

Fixed submission:
N,W = map(int,input().split())
wv = []
base_w = float('inf')
for _ in range(N):
    w, v = (int(x) for x in input().split())
    wv.append([w, v])
    base_w = min(base_w, w)

dp = [[-10000000000 for i in range(100*3+1)] for j in range(N+1)]

dp[0][0] = 0

#横軸はお重さの合計、縦軸は何個選ぶか
for ws ,vs in wv:
    ws -= base_w
    for h in range(N+1, 0, -1):
        for w in range(100*3, -1, -1):
            if 0 <= w-ws:
                if dp[h-1][w-ws] != -10000000000:
                    dp[h][w] = max(dp[h][w], dp[h-1][w-ws]+vs)

ans = 0
for i in range(0,N+1):
    tmp_W = W-i*base_w
    #print(tmp_W, i)
    if 0 <= tmp_W:
        #print(dp[i][:tmp_W+1])
        tmp_max_V = max(dp[i][:tmp_W+1])
        ans = max(ans, tmp_max_V)
print(ans)
Buggy python submission (verdict: Runtime Error):
a = list(input())
b = list(input())

ans = []

for i in range(len(a)):
    ans.append(a[i])
    if b[i]:
        ans.append(b[i])
print(''.join(ans))

Fixed submission:
s1=input()

s2=input()

ans = []

for i in range(len(s1)+len(s2)):
    if i%2==0:
        ans.append(s1[i//2])
    else:
        ans.append(s2[i//2])

print(''.join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
a = list(input())
b = list(input())

ans = []

for i in range(len(a)):
    ans.append(a[i])
    ans.append(b[i])
print(''.join(ans))

Fixed submission:
s1=input()

s2=input()

ans = []

for i in range(len(s1)+len(s2)):
    if i%2==0:
        ans.append(s1[i//2])
    else:
        ans.append(s2[i//2])

print(''.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
n,c,k = map(int,input().split())
ab = []
for _ in range(n):
    t=int(input())
    ab.append(t)
ab.sort()

bus = 1
bustime = ab[0] + k
customer = 1

for i in range(1,n):
    if ab[i] <= bustime:
        customer += 1
        if customer == c:
            bustime = ab[i+i]+k
            customer = 0
            bus += 1
    elif bustime < ab[i]:
        bustime = ab[i]+k
        customer = 1
        bus += 1
print(bus)

Fixed submission:
n,c,k = map(int,input().split())
ab = []
for _ in range(n):
    t=int(input())
    ab.append(t)
ab.sort()

bus = 1
bustime = ab[0] + k
customer = 1

for i in range(1,n):
    if customer < c and ab[i] <= bustime:
        customer += 1
    else:
        bustime = ab[i]+k
        customer = 1
        bus += 1
print(bus)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()

s = list(s)

ans = 0

for i in range(len(s)-1):
    if s[i] != 'A': continue
    for j in range(i+1,len(s)):
        if s[j] == 'Z':
            ans = max(ans, j-i+1)
print(ans)

Fixed submission:
s=input()

s = list(s)

memo1=10000000000000000000000

ans = 0

for i in range(len(s)):
    if s[i] == 'A':
        memo1=min(memo1, i)
    if s[i] == 'Z':
        memo2=i
print(memo2-memo1+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
memo = {}
for a in A:
    if a in memo:
        memo[a] += 1
    else:
        memo[a] = 1
memo_sorted = sorted(memo.items(), key=lambda x:-x[1])
memo = []
for a,b in memo_sorted:
    memo.append([a,b])

for key,val in enumerate(memo):
    val_1, val_2 = val
    if val_2 <= 1:
        continue
    else:
        if val_2%2 == 1:
            memo[key][1] = 1
        elif val_2%2 == 0:
            if key < N-1:
                memo[key+1][1] -= 1
            memo[key][1] = 1
ans = 0
for a,b in memo:
    ans += b
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
memo = {}
for a in A:
    if a in memo:
        memo[a] += 1
    else:
        memo[a] = 1
memo_sorted = sorted(memo.items(), key=lambda x:-x[1])
memo = []
for a,b in memo_sorted:
    memo.append([a,b])

for key,val in enumerate(memo):
    val_1, val_2 = val
    if val_2 <= 1:
        continue
    else:
        if val_2%2 == 1:
            memo[key][1] = 1
        elif val_2%2 == 0:
            if key < len(memo)-1:
                memo[key+1][1] -= 1
                memo[key][1] = 1
            else:
                memo[key][1] = 0
ans = 0
for a,b in memo:
    ans += b
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans = ans + ['a']
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans = ans + ['a']
        else:
            ans = ans + [alf]
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))

Fixed submission:
s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans.append('a')
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans.append('a')
        else:
            ans.append(alf)
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
X=a*c
for i in range(a,b+1) :
  for j in range(c,d+1) :
    X=max(X,i*j)
print(X)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N-1) :
  for j in range(i+1,N) :
    sum+=A[i]*A[j]
print(sum%(10**9+7))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
res=0
for i in range(N) :
  SUM-=A[i]
  res+=A[i]*SUM
print(res%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
count=0
B=[A[0]]
for i in range(1,N) :
  if max(B)<A[i] :
    B.append(A[i])
  else :
    B.append(B[i-1])
ans=0
for i in range(N) :
  ans+=B[i]-A[i]
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count=0
B=[A[0]]
for i in range(1,N) :
  if B[i-1]<A[i] :
    B.append(A[i])
  else :
    B.append(B[i-1])
ans=0
for i in range(N) :
  ans+=B[i]-A[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
point=[1]*N
for i in range(K-1,N):
  for j in range(K):
    point[i]*=A[i-j]
for i in range(K-1,N-1):
  if(point[i]>=point[i+1]):
    print("No")
  else:
    print("Yes")

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
point=[1]*N
for i in range(N-K):
  if(A[K+i]>A[i]):
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def main():
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
  print(0)
  return
prod = 1
for a in A:
  prod *= a
  if prod > 1000000000000000000:
    print(-1)
    return
print(prod)

main()


Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()

Buggy python submission (verdict: Runtime Error):
N=int(input())
result=1
A=input().split()
for j in range(N):
  result=result*int(A[j])
  if(result>10**18):
    print(-1)
    return
print(result)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
result=1
A=input().split()
for j in range(N):
  result=result*int(A[j])
if(result>10**18):
  print(-1)
else:
  print(result)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
result=1
for i in range(N):
  A.append(int(input().split()))
for j in range(N):
  result=result*A[j]
if(result>10**18):
  print(-1)
else:
  print(result)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
result=1
for i in range(N):
  A.append(int(input()))
for j in range(N):
  result=result*A[j]
if(result>10**18):
  print(-1)
else:
  print(result)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
T.pop(len(str))
if(T==S):
  print("Yes")
else:
  print("No")

Fixed submission:
S=input()
T=input()
if(T[:-1]==S):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
T.pop()
if(T==S):
  print("Yes")
else:
  print("No")

Fixed submission:
S=input()
T=input()
if(T[:-1]==S):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A,B,C,K=input().split(" ")
if(A>=K):
  print(A)
else:
  if(K<=A+B):
    print(A)
  else:
    print(A-(K-A-B))

Fixed submission:
A,B,C,K=map(int,input().split())
if(A>=K):
  print(K)
elif(A<K and A+B>=K):
  print(A)
else:
  print(A-(K-(A+B)))

Buggy python submission (verdict: Runtime Error):
A,B,C,K=int(input().split(" "))
if(A>=K):
  print(A)
else:
  if(K<=A+B):
    print(A)
  else:
    print(A-(K-A-B))


Fixed submission:
A,B,C,K=map(int,input().split())
if(A>=K):
  print(K)
elif(A<K and A+B>=K):
  print(A)
else:
  print(A-(K-(A+B)))
Buggy python submission (verdict: Runtime Error):
import sys

N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N):
  if(A[i]==A[i+1]):
    print("NO")
    sys.exit()
print("YES")

Fixed submission:
import sys

N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
  if(A[i]==A[i+1]):
    print("NO")
    sys.exit()
print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N=int(input())
A=list(map(int,input().split()))
for i in range(N):
  for j in range(N):
    if(i!=j and A[i]==A[j]):
      print("NO")
      sys.exit()
print("YES")

Fixed submission:
import sys

N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
  if(A[i]==A[i+1]):
    print("NO")
    sys.exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
count=0
N=input()
S=input()
N=int(N)
for i in range(N-2):
  if(S[i]=="A" and S[i+1]=="B" and S[i+2]=="C"):
    count++
print(count)

Fixed submission:
count=0
N=input()
S=input()
N=int(N)
for i in range(N-2):
  if(S[i]=="A" and S[i+1]=="B" and S[i+2]=="C"):
    count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
for i in range(B):
  if(i*A>=B):
    ans=i
    break
print(ans)

Fixed submission:
A,B=map(int,input().split())
for i in range(B):
  if(i*A-i+1>=B):
    ans=i
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
H=list(map(int,input().split()))
count=[0]*N
for i in range(N):
  for j in range(i+1,N):
    if(H[i]>=H[j]):
      count[i]+=1
      i=j
    else:
      break
print(max(count))

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
count=0
maxcount=[0]*N
for i in range(N-1):
  if(H[i]>=H[i+1]):
    count+=1
  else:
    count=0
  maxcount[i]=count

print(max(maxcount))
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,sinput().split())
if(C>=A-B):
  print(C-(A-B))
else:
  print(0)

Fixed submission:
A,B,C=map(int,input().split())
if(C>=A-B):
  print(C-(A-B))
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
a[0]=int(input())
a[1]=int(input())
a[2]=int(input())
a[3]=int(input())
a[4]=int(input())
k=int(input())
for i in range(5):
  for j in range(i+1,5):
    if a[j]-a[i]>k :
      print(":(")
      sys.exit()
print("Yay!")

Fixed submission:
import sys
a=[0]*5
a[0]=int(input())
a[1]=int(input())
a[2]=int(input())
a[3]=int(input())
a[4]=int(input())
k=int(input())
for i in range(5):
  for j in range(i+1,5):
    if a[j]-a[i]>k :
      print(":(")
      sys.exit()
print("Yay!")
Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)+1):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[len(list)-K+1])

Fixed submission:
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)+1):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[len(list)-K])

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[len(list)-K+1])

Fixed submission:
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)+1):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[len(list)-K])

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[K-1])

Fixed submission:
A,B,K=map(int,input().split())
list=[]
for i in range(1,min(A,B)+1):
  if A%i==0 and B%i==0 :
    list.append(i)
print(list[len(list)-K])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[]*N
for i in ragne(N):
  A[i]=list(map(int,input().split()))

Fixed submission:
N,M=map(int,input().split())
KA=[0]*N
count=[0]*(M+1)
for i in range(N):
  KA[i]=list(map(int,input().split()))
for i in range(N):
  for j in range(1,len(KA[i])):
    count[KA[i][j]]+=1
ans=0
for i in range(1,M+1):
  if count[i]==N :
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,H,W=map(int,input().split())
print((N-H+1)*(N-W+1))

Fixed submission:
N=int(input())
H=int(input())
W=int(input())
print((N-H+1)*(N-W+1))
Buggy python submission (verdict: Runtime Error):
D=int(input())
if D=25 :
  print("Christmas")
elif D=24 :
  print("Christmas Eve")
elif D=23 :
  print("Christmas Eve Eve")
else :
  print("Christmas Eve Eve Eve")

Fixed submission:
D=int(input())
if D==25 :
  print("Christmas")
elif D==24 :
  print("Christmas Eve")
elif D==23 :
  print("Christmas Eve Eve")
else :
  print("Christmas Eve Eve Eve")
Buggy python submission (verdict: Runtime Error):
N,T=map(int,input().split())
ct=[0]*N
cost=[]
for i in range(N):
  ct[i]=list(map(int,input().split()))
  if ct[i][1]<T :
    cost.append(ct[i][0])
print(min(cost))

Fixed submission:
N,T=map(int,input().split())
ct=[0]*N
cost=[]
for i in range(N):
  ct[i]=list(map(int,input().split()))
  if ct[i][1]<=T :
    cost.append(ct[i][0])
if cost==[] :
  print("TLE")
else :
  print(min(cost))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input())
if A*B%2==0 :
  print("No")
else :
  print("Yes")

Fixed submission:
A,B=map(int,input().split())
if A*B%2==0 :
  print("No")
else :
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
res=[]
for b in range(1,1000):
  for p in range(2,1000):
    if b**p<=X :
      res.append(b**p)
print(res[-1])

Fixed submission:
X=int(input())
res=0
for b in range(1,1000):
  for p in range(2,1000):
    if b**p<=X :
      res=max(res,b**p)
    else:
      break
print(res)
Buggy python submission (verdict: Runtime Error):
S=input()
S[3]="8"
print(S)

Fixed submission:
S=input()
print(S.replace("2017","2018"))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
if A>B :
  print("GREATER")
elif A==B :
  print("EQUAL")
else :
  print("LESS")

Fixed submission:
A=int(input())
B=int(input())
if A>B :
  print("GREATER")
elif A==B :
  print("EQUAL")
else :
  print("LESS")
Buggy python submission (verdict: Time Limit Exceeded):
class Unionfind():  # 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)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xysort = sorted(xy)

uf = Unionfind(n)
for i, (p, q) in enumerate(xysort):
    for j, (x, y) in enumerate(xysort[:i]):
        if q > y:
            uf.union(i, j)

for x, y in xy:
    print(uf.size(x - 1))


Fixed submission:
class Unionfind():  # 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)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xysort = [None] * n
for x, y in xy:
    xysort[x - 1] = y - 1

# 解説AC
uf = Unionfind(n)
tmp, yfrag = 0, [0] * n
for x, y in enumerate(xysort[:n - 1], 1):
    yfrag[y] = 1
    tmp += yfrag[n - x] + (y > n - x)
    if tmp < x:
        uf.union(x, x - 1)

for x, y in xy:
    print(uf.size(x - 1))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
mod = 998244353

s = []
for l, r in lr:
    s += [i for i in range(l, r + 1)]

dp = [0] * (n + 1)
dp[1] = 1
for i in range(2, n + 1):
    for j in s:
        dp[i] += dp[max(i - j, 0)]
    dp[i] %= mod
print(dp[n])


Fixed submission:
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
mod = 998244353

dp = [0] * (n + 1)
acc = [0] * (n + 1)
dp[1], acc[1] = 1, 1
for i in range(2, n + 1):
    for l, r in lr:
        dp[i] += acc[max(i - l, 0)]
        dp[i] -= acc[max(i - (r + 1), 0)]
    dp[i] %= mod
    acc[i] = (dp[i] + acc[i - 1]) % mod
print(dp[n])
Buggy python submission (verdict: Runtime Error):
n = int(input())

print(1 if x == 0 else 0)



Fixed submission:
n = int(input())
print(1 if n == 0 else 0)

Buggy python submission (verdict: Runtime Error):
n = int(input())

print(1 in x == 0 else 0)



Fixed submission:
n = int(input())
print(1 if n == 0 else 0)
Buggy python submission (verdict: Runtime Error):
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = []
for col in range(W):
    colcnt.append(sum(row[col] for row in mat))

rowmax, colmax = max(rowcnt), max(colcnt)
print(rowmax + colmax - 1)


Fixed submission:
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

row, col = [0] * H, [0] * W
for h, w in hw:
    row[h - 1] += 1
    col[w - 1] += 1

rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
    if row[h - 1] == rowmax and col[w - 1] == colmax:
        cnt -= 1
print(rowmax + colmax - (cnt == 0))

Buggy python submission (verdict: Runtime Error):
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = [sum(row[col] for row in mat) for col in range(W)]

rowmax, colmax = max(rowcnt), max(colcnt)
print(rowmax + colmax - 1)


Fixed submission:
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

row, col = [0] * H, [0] * W
for h, w in hw:
    row[h - 1] += 1
    col[w - 1] += 1

rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
    if row[h - 1] == rowmax and col[w - 1] == colmax:
        cnt -= 1
print(rowmax + colmax - (cnt == 0))

Buggy python submission (verdict: Runtime Error):
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = [sum(row[col] for row in mat) for col in range(W)]

rowmax, colmax = max(rowcnt), max(colcnt)
for r, mat_h in zip(rowcnt, mat):
    for c, mat_hw in zip(colcnt, mat_h):
        if r == rowmax and c == colmax and mat_hw == 0:
            print(rowmax + colmax)
            exit()
print(rowmax + colmax - 1)


Fixed submission:
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

row, col = [0] * H, [0] * W
for h, w in hw:
    row[h - 1] += 1
    col[w - 1] += 1

rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
    if row[h - 1] == rowmax and col[w - 1] == colmax:
        cnt -= 1
print(rowmax + colmax - (cnt == 0))
Buggy python submission (verdict: Runtime Error):
x, k, d = map(int, input().split())

x, cnt = abs(x), abs(x) // d
if k % 2 == cnt % 2:
    ans = abs(x - d * min(k, cnt))
elif k % 2 != cnt % 2:
    ans = abs(x - d * min(k, cnt + 1)
print(ans)


Fixed submission:
x, k, d = map(int, input().split())

cnt = abs(x) // d
x = abs(x)
if k % 2 == cnt % 2:
    ans = min(abs(x - d * min(k,cnt)), abs(x + d * min(k,cnt)))
elif k % 2 != cnt % 2:
    ans = min(abs(x - d * min(k,(cnt + 1))), abs(x - d * min(k,(cnt + 1))))
print(ans)
Buggy python submission (verdict: Runtime Error):
k = int(input())

# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 1, 7
for i in range(k):
    if num % k == 0:
        print(i+1)
        break
    num = (num % k) * 10 + 7


Fixed submission:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 7
for i in range(1,10**6):
    if num % k == 0:
        print(i)
        break
    num = (num % k) * 10 + 7

Buggy python submission (verdict: Runtime Error):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

ans, num = 1, 7
while 1:
    if num % k == 0:
        print(i)
        break
    ans += 1
    num = num * 10 + 7
print(ans)


Fixed submission:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 7
for i in range(1,10**6):
    if num % k == 0:
        print(i)
        break
    num = (num % k) * 10 + 7

Buggy python submission (verdict: Runtime Error):
from math import gcd


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]

k = int(input())
ans = {2: -1, 3: 1, 5: -1, 7: 1}
if k in ans:
    print(ans[k])
if k % 7 == 0:
    k //= 7

p = make_divisors(k-1)
for i in p:
    if int('7' * i) % p == 0:
        print(i)
         

Fixed submission:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 7
for i in range(1,10**6):
    if num % k == 0:
        print(i)
        break
    num = (num % k) * 10 + 7