Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
L,R=map(int,input().split())
A=range(L,R+1)
for i in range(1,M):
  L,R=map(int,input().split())
  A=set(A)&set(range(L,R+1))
print(len(A))

Fixed submission:
N,M=map(int,input().split())
L,R=map(int,input().split())
a,b=L,R
for i in range(1,M):
  L,R=map(int,input().split())
  a=max(a,L)
  b=min(b,R)
if a>b:
  print(0)
else:
  print(b-a+1)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=list(input())
L=list()
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    S[i]="a"
t=[0]*(N+2)
for i in range(N):
  t[i+2]=S[:i+1].count("a")
for i in range(Q):
  n,m=map(int,input().split())
  print(t[m]-t[n])

Fixed submission:
N,Q=map(int,input().split())
S=input()
L=[0]*N
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=L[i-1]+1
  else:
    L[i]=L[i-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(L[b-1]-L[a-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
L=list()
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    L.append(i)
for i in range(Q):
  n,m=map(int,input().split())
  k= sum(1 for x in L if n-1<=x<m-1)
  print(k)

Fixed submission:
N,Q=map(int,input().split())
S=input()
L=[0]*N
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=L[i-1]+1
  else:
    L[i]=L[i-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(L[b-1]-L[a-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for i in range(Q):
  n,m=map(int,input().split())
  a=S[n-1:m]
  print(a.count("AC"))

Fixed submission:
N,Q=map(int,input().split())
S=input()
L=[0]*N
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=L[i-1]+1
  else:
    L[i]=L[i-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(L[b-1]-L[a-1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import sys
  i=0
  L=list(input())
  N=len(L)
  if N==1:
    print(0)
    sys.exit()
  for j in range(N):
    i=0
    S=len(L)
    if S==1 or S==0:
      break
    while True:
      if L[i]!=L[i+1]:
        L.pop(i)
        L.pop(i)
        if L==[]:
          print(N)
          sys.exit()
      i+=1
      if i>len(L)-2:
        break
    if S==len(L):
      break
  print(N-len(L))
main()

Fixed submission:
S=input()
a=S.count("1")
b=S.count("0")
print(min(a,b)*2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
i=0
L=list(input())
N=len(L)
if N==1:
  print(0)
  sys.exit()
for j in range(N):
  i=0
  S=len(L)
  if S==1 or S==0:
    break
  while True:
    if L[i]!=L[i+1]:
      L.pop(i)
      L.pop(i)
      if L==[]:
        print(N)
        sys.exit()
    i+=1
    if i>len(L)-2:
      break
  if S==len(L):
    break
print(N-len(L))

Fixed submission:
S=input()
a=S.count("1")
b=S.count("0")
print(min(a,b)*2)

Buggy python submission (verdict: Runtime Error):
import sys
i=0
L=list(input())
N=len(L)
if N==1:
  print(0)
  sys.exit()
for j in range(N):
  i=0
  while True:
    if L[i]!=L[i+1]:
      L.pop(i)
      L.pop(i)
      if L==[]:
        sys.exit()
    i+=1
    if i>len(L)-2:
      break
print(N-len(L))

Fixed submission:
S=input()
a=S.count("1")
b=S.count("0")
print(min(a,b)*2)
Buggy python submission (verdict: Runtime Error):
a=input()
c=len(a)
d=c-7
for i in range(8):
  if a[:i]+a[-(7-i):]=="keyence" or a[:i]=="keyence" or a[-(7-i):]=="keyence":
    print("YES")
    sys.exit()
print("NO")

Fixed submission:
S=input()
if S=="keyence":
  print("YES")
  exit()
for i in range(7):
  T=S[:i]+S[len(S)-7+i:]
  if T=="keyence":
    print("YES")
    exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,K=map(int,input().split())
L=factorization(N)
ans=1
for i in L:
  ans*=L[0]**(L[1]//N)
print(ans)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,K=map(int,input().split())
L=factorization(K)
ans=1
for i in L:
  ans*=i[0]**(i[1]//N)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=input()
for i in range(3):
  if N[i]=="1":
    N[i]=9
  else:
    N[i]=1

Fixed submission:
L=[0]*3
N=input()
for i in range(3):
  if N[i]=="1":
    L[i]=9
  else:
    L[i]=1
print((L[0]*100)+(L[1]*10)+L[2])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
L=list(map(int,input().split()))
R=[0]
sums=0
for i in L:
  sums+=i
  R.append(sums)
ans=0
for i in range(N):
  for j in range(i,N):
    if (R[j]-R[i-1])%M==0:
      ans+=1
print(ans)

Fixed submission:
import collections
N,M=map(int,input().split())
L=list(map(int,input().split()))
R=[0]
sums=0
for i in L:
  sums+=i
  sums=sums%M
  R.append(sums)
c = collections.Counter(R)
A=list(c.values())
A=[i*(i-1)//2 for i in A]
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections

N,M=map(int,input().split())
L=list()
for i in range(M):
  a,b=map(int,input().split())
  A=list(range(a,b))
  L.append(A)
R=tuple(itertools.chain.from_iterable(L))
i=0
while True:
  L=[i for i in L if collections.Counter(R).most_common()[0][0] not in i]
  R=tuple(itertools.chain.from_iterable(L))
  i+=1
  if len(L)==0:
    break
print(i)

Fixed submission:
N,M=map(int,input().split())
L=list()
for i in range(M):
  a,b=map(int,input().split())
  A=list([b,a])
  L.append(A)
L=sorted(L)
R=[L[0][0]-1]
for j in range(M):
  if R[-1] not in range(L[j][1],L[j][0]):
    R.append(L[j][0]-1)
print(len(R))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set([i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)

Fixed submission:
N=int(input())
L=list(input())
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set(L[i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)
Buggy python submission (verdict: Time Limit Exceeded):
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,len(s)+1):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

Fixed submission:
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,len(s)+1):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
  print(L[K-1])

Fixed submission:
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
L=list()
s=input()
K=int(input())
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    L.append(str(s[i:j]))
L=sorted(list(set(L)))
print(L[K-1])

Fixed submission:
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
L=list()
s=input()
K=int(input())
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    L.append(str(s[i:j]))
L=sorted(list(set(L)))
print(L[K-1])

Fixed submission:
L=list()
s=input()
K=int(input())
if len(s)<10:
  for i in range(len(s)):
    for j in range(i+1,len(s)+1):
      L.append(str(s[i:j]))
  L=sorted(list(set(L)))
  print(L[K-1])
else:
  A=sorted(list(s))
  B=[A[0],A[1],A[2],A[3],A[4]]
  for i in range(len(s)):
    if s[i] in B:
      for j in range(i+1,min(i+6,len(s)+1)):
        L.append(str(s[i:j]))
      L=sorted(list(set(L)))
      if len(L)>K:
        L=list(L[:K])
  print(L[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
c=0
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
  for j in range(i+1,N):
    if sum(A[i:j+1])==0:
      c=c+1
for i in range(N):
  if A[i]==0:
    c=c+1
print(c)

Fixed submission:
N=int(input())
L=list(map(int,input().split()))
R={}
sums=0
for i in range(N):
  sums+=L[i]
  if sums in R:
    R[sums]+=1
  else:
    R[sums]=1
k=0
if 0 in R:
  k=R[0]
print(sum([i*(i-1)//2 for i in R.values()])+k)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for o in range((2*N)-1):
  a=0
  if o<N:
    i=0
    j=o
    omomi=N-j
  else:
    j=0
    i=o-N+1
    omomi=N-i
  for t in range(N):
    for q in range(t):
      if L[i+t][j+q]!=L[i+q][j+t]:
        a=1
        break
    if a==1:
      break
  if a==0:
    ans+=omomi
print(ans)

Fixed submission:
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for o in range((2*N)-1):
  a=0
  if o<N:
    i=0
    j=o
    omomi=N-j
  else:
    j=0
    i=o-N+1
    omomi=N-i
  for t in range(N):
    for q in range(t):
      if L[i+t][j+q]!=L[i+q][j+t]:
        a=1
        break
    if a==1:
      break
  if a==0:
    ans+=omomi
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for i in range(N):
  for j in range(N):
    a=0
    for t in range(N):
      for q in range(t):
        if L[i+t][j+q]!=L[i+q][j+t]:
          a=1
          break
      if a==1:
        break
    if a==0:
      ans+=1
print(ans)

Fixed submission:
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for o in range((2*N)-1):
  a=0
  if o<N:
    i=0
    j=o
    omomi=N-j
  else:
    j=0
    i=o-N+1
    omomi=N-i
  for t in range(N):
    for q in range(t):
      if L[i+t][j+q]!=L[i+q][j+t]:
        a=1
        break
    if a==1:
      break
  if a==0:
    ans+=omomi
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
R=[0]*N
K=(N//2)-1
S=K+1
L=list(map(int,input().split()))
for i in range(N):
  R[i]=[L[i],i]
R=sorted(R)
for i in range(N):
  if R.index([L[i],i])<S:
    print(R[S][0])
  else:
    print(R[K][0])

Fixed submission:
N=int(input())
L=list(map(int,input().split()))
n=N//2
R=sorted(L)
for i in L:
  if i>R[n-1]:
    print(R[n-1])
  else:
    print(R[n])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
L={i for i in range(A,A+K)}
R={i for i in range(B-K+1,B+1)}
S=[i for i in range(A,B+1) if i in L or i in R]
for i in range(len(S)):
  print(S[i])

Fixed submission:
A,B,K=map(int,input().split())
S=[i for i in range(A,B+1) if i<A+K or i>=B-K+1]
for i in range(len(S)):
  print(S[i])

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
L=range(A,A+K)
R=range(B-K+1,B+1)
S=[i for i in range(A,B+1) if i in L or i in R]
for i in range(len(S)):
  print(S[i])

Fixed submission:
A,B,K=map(int,input().split())
S=[i for i in range(A,B+1) if i<A+K or i>=B-K+1]
for i in range(len(S)):
  print(S[i])
Buggy python submission (verdict: Runtime Error):
N=int(input())
L=list(map(int,input().split()))
L=set(L)
if len(L)==4:
  print("Four")
else:
  print("Three")

Fixed submission:
N=int(input())
L=list(input().split())
L=set(L)
if len(L)==4:
  print("Four")
else:
  print("Three")
Buggy python submission (verdict: Runtime Error):
S=list(input())
S[3]=8
print("".join(S))

Fixed submission:
S=list(input())
S[3]="8"
print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
mina=10**10
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,H=map(int,input().split())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
sb=sum(B)
for i in range(N):
  S=[k for k in B if k>A[i]]
  n=sum(S)
  if H-n<=0:
    mina=min(mina,len(S))
  else:
    mina=min(mina,waru(H-n,A[i])+len(S))
print(mina)

Fixed submission:
import sys
mina=10**10
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,H=map(int,input().split())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ma=max(A)
ind=A.index(ma)
B=[i for i in B if i>ma]
B=sorted(B,reverse=True)
cou=1
s=0
for i in range(len(B)):
  s+=B[i]
  if H<=s:
    print(i+1)
    sys.exit()
H=H-s
print(len(B)+waru(H,ma))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
L=seachPrimeNum(100000)
R=[i for i in L if (i+1)//2 in L]
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  print(len([i for i in R if i>=a and i<=b]))

Fixed submission:

def primes(n):
    candidate = list(range(2, n+1))
    prime = []
    limit = n**0.5 + 1
    while True:
        p = candidate[0] 
        if limit <= p:
            prime.extend(candidate)
            break
        prime.append(p)

        candidate = [i for i in candidate if i % p != 0]
    return prime
L=primes(100000)
R=set([i for i in L if (i+1)//2 in L])
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  print(len([i for i in R if i>=a and i<=b]))
Buggy python submission (verdict: Runtime Error):
a,b=int(input().split())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print((1+a+b)/2)

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(int((a+b)/2))
else:
  print(int((1+a+b)/2))

Buggy python submission (verdict: Runtime Error):
a,b=int(input())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print((1+a+b)/2)

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(int((a+b)/2))
else:
  print(int((1+a+b)/2))

Buggy python submission (verdict: Runtime Error):
a,b=int(print())
if (a+b)%2==0:
  print((a+b)/2)
if (a+b)%2==1:
  print((a+b+1)/2)

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==0:
  print(int((a+b)/2))
else:
  print(int((1+a+b)/2))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
R=set(L)
ans=0
for i in R:
  c=L.count(i)
  if c<i:
    ans+=c
  else:
    ans+=c-i
print(ans)

Fixed submission:
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
ke=list(Counter(L).values())
val=list(Counter(L).keys())
ans=0
for i in range(len(val)):
  if val[i]>ke[i]:
    ans+=ke[i]
  else:
    ans+=ke[i]-val[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
R=set(L)
ans=0
for i in R:
  c=L.count(i)
  if c<i:
    ans+=c
  else:
    ans+=c-i
print(ans)

Fixed submission:
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
ke=list(Counter(L).values())
val=list(Counter(L).keys())
ans=0
for i in range(len(val)):
  if val[i]>ke[i]:
    ans+=ke[i]
  else:
    ans+=ke[i]-val[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
L=list(map(int,input().split()))
R=list(map(int,input().split()))
if L[0]==R[2] and L[1]==R[1] and L[2]==R[0]:
  print("YES")
else:
  print("NO")

Fixed submission:
L=list(input())
R=list(input())
if L[0]==R[2] and L[1]==R[1] and L[2]==R[0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
  input = sys.stdin.readline
  maxa=0
  N=int(input())
  L=list(map(int,input().split()))
  L=sorted(L)
  R=tuple(set(L))
  for i in range(len(R)):
    s=L.count(R[i])+L.count(R[i]+1)+L.count(R[i]-1)
    maxa=max(maxa,s)
  print(maxa)
if __name__ == '__main__':
    main()

Fixed submission:
maxa=0
N=int(input())
L=list(map(int,input().split()))
c=[0]*100000
for i in L:
  c[i]+=1
for i in range(1,99999):
  s=c[i]+c[i-1]+c[i+1]
  maxa=max(maxa,s)
print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
maxa=0
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
R=list(set(L))
for i in range(len(R)):
  s=L.count(R[i])+L.count(R[i]+1)+L.count(R[i]-1)
  maxa=max(maxa,s)
print(maxa)

Fixed submission:
maxa=0
N=int(input())
L=list(map(int,input().split()))
c=[0]*100000
for i in L:
  c[i]+=1
for i in range(1,99999):
  s=c[i]+c[i-1]+c[i+1]
  maxa=max(maxa,s)
print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
maxa=0
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
R=list(set(L))
for i in range(len(R)):
  s=L.count(R[i])+L.count(R[i]+1)+L.count(R[i]-1)
  maxa=max(maxa,s)
print(maxa)

Fixed submission:
maxa=0
N=int(input())
L=list(map(int,input().split()))
c=[0]*100000
for i in L:
  c[i]+=1
for i in range(1,99999):
  s=c[i]+c[i-1]+c[i+1]
  maxa=max(maxa,s)
print(maxa)
Buggy python submission (verdict: Runtime Error):
L=list(input())
L=list(set(L))
L=sorted(L)
R=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
  if L[i]!=R[i]:
    print(R[i])
    exit()
print("None")

Fixed submission:
L=list(input())
L=list(set(L))
L=sorted(L)
R=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(min(26,len(L))):
  if L[i]!=R[i]:
    print(R[i])
    exit()
if len(L)<26:
  print(R[len(L)])
  exit()
print("None")
Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

Fixed submission:
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  exit()
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])
Buggy python submission (verdict: Runtime Error):
import collections

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
K = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, K + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n=int(input())
print(n)
nCk=n
R=list()
L=list(map(int,input().split()))
c = collections.Counter(L)
nikai=c.most_common()[0][0]#2回出てくる数
for i in range(n+1):
  if L[i]==nikai:
    R.append(i)
#Rに二個のindがある。それぞれR[0]こ、N-R[1]
k=n-R[1]+R[0]
for i in range(1,n):
  nCk=cmb(n+1,i+1,mod)
  a = cmb(k,i,mod)
  print((nCk-a)%mod)
print(1)

Fixed submission:
import collections

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
K = 2*(10**5)
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, K + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n=int(input())
print(n)
nCk=n
R=list()
L=list(map(int,input().split()))
c = collections.Counter(L)
nikai=c.most_common()[0][0]#2回出てくる数
for i in range(n+1):
  if L[i]==nikai:
    R.append(i)
#Rに二個のindがある。それぞれR[0]こ、N-R[1]
k=n-R[1]+R[0]
for i in range(1,n):
  nCk=cmb(n+1,i+1,mod)
  a = cmb(k,i,mod)
  print((nCk-a)%mod)
print(1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
i=0
hidari=str()
migi=str()
a=0
while S[i]==")":
  hidari+="("
  i+=1
while i<N:
  if S[i]=="(":
    a+=1
  else:
    a-=1
  i+=1
if a<0:
  hidari+=abs(a)*"("
elif a>0:
  migi+=a*")"
print(hidari+S+migi)

Fixed submission:
N=int(input())
S=input()
i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    a+=1
  else:
    a-=1
  i+=1
if a<0:
  hidari+=abs(a)*"("
elif a>0:
  migi+=a*")"
s=hidari+S+migi


i=0
hidari=str()
migi=str()
a=0
while i<N:
  if S[i]==")":
    hidari+="("
    i+=1
  else:
    break
while i<N:
  if S[i]=="(":
    if a<0:
      a=0
    a+=1
    mina=0
  else:
    a-=1
    if a<0:
      if mina>a:
        hidari+="("
  i+=1
if a>0:
  migi+=a*")"
t=hidari+S+migi
if len(s)==len(t):
  print(s)
elif len(s)>len(t):
  print(s)
else:
  print(t)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if b-a=c-b:
  print("YES")
else:
  print("NO")

Fixed submission:
a,b,c=map(int,input().split())
if b-a==c-b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
ans=0
K,S=map(int,input().split())
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k==S:
        ans+=1
print(ans)

Fixed submission:
ans=0
K,S=map(int,input().split())
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-i-j<=K:
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
def saiki(T):
  if len(T)<=len(S):
    if T==S:
      print("YES")
      exit()
    return saiki(T+"dream"),saiki(T+"erase"),saiki(T+"dreamer"),saiki(T+"eraser")
S=input()
saiki("")
print("NO")

Fixed submission:
T=input()
while True:
  if T==str():
    print("YES")
    exit()
  if len(T)<5:
    print("NO")
    exit()
  if T[-5:]=="dream":
    T=str(T[:-5])
  elif T[-7:]=="dreamer":
    T=str(T[:-7])
  elif T[-5:]=="erase":
    T=str(T[:-5])
  elif T[-6:]=="eraser" :
    T=str(T[:-6])
  else:
    print("NO")
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
X=input()
A=len(X)
B=X.count("S")
if B>A-B:
  K=A-B
else:
  K=B
for i in range(K):
  X=X.replace("ST","")
print(len(X))

Fixed submission:
L=0
R=0
X=list(input())
A=len(X)
for i in range(A):
  if X[i]=="S":
    R=R+1
  elif X[i]=="T":
    if R!=0:
      L=L+1
      R=R-1
print(A-2*L)

Buggy python submission (verdict: Time Limit Exceeded):
X=input()
A=len(X)
for i in range(A//2):
  X=X.replace("ST","")
print(len(X))

Fixed submission:
L=0
R=0
X=list(input())
A=len(X)
for i in range(A):
  if X[i]=="S":
    R=R+1
  elif X[i]=="T":
    if R!=0:
      L=L+1
      R=R-1
print(A-2*L)