Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
otsuri = 1000 - (n % 1000)
if otsuri == 1000:
  print(0)
else:
  print(osturi)

Fixed submission:
n = int(input())
otsuri = 1000 - (n % 1000)
if otsuri == 1000:
  print(0)
else:
  print(otsuri)
Buggy python submission (verdict: Runtime Error):
a,b,c,k = map(int,input().split())

xa = min(a,k)
k1 = k-xa
xb = min(b,k1)
k2 = k1-xb
xc = k2

print(xa-xc)

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

if (len(s) == len(t)-1) and (s == t[:len(t)-1]):
    print("Yes")
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int,input().split())
count = 0
for i in range(k):
    if a > 0:
        count += 1
        a -= 1
        continue
    elif a == 0 and b > 0:
        b -= 1
        continue
    else:
        count -= 1
        c -= 1
print(count)


Fixed submission:
a,b,c,k = map(int,input().split())

xa = min(a,k)
k1 = k-xa
xb = min(b,k1)
k2 = k1-xb
xc = k2

print(xa-xc)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int,input().split())
count = 0
for i in range(k):
    if a > 0:
        count += 1
        a -= 1
        continue
    elif a == 0 and b > 0:
        b -= 1
        continue
    else:
        count -= 1
        c -= 1
print(count)


Fixed submission:
a,b,c,k = map(int,input().split())

xa = min(a,k)
k1 = k-xa
xb = min(b,k1)
k2 = k1-xb
xc = k2

print(xa-xc)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort(reverse=True)
count = 0
for a in range(n-2):
    x=0
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]):
                count += 1
            else:
                if c==b+1 or c==b+2 or c==b+3:
                    x=1
                    break
        if x == 1:
            break
print(count)


Fixed submission:
from bisect import bisect_left
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect_left(l_list,l_list[i]+l_list[j]) - j - 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort(reverse=True)
count = 0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]):
                count += 1
print(count)


Fixed submission:
from bisect import bisect_left
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect_left(l_list,l_list[i]+l_list[j]) - j - 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_list = list(map(int,input().split()))
count = 0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]) and (l_list[b]<l_list[c]+l_list[a]) and (l_list[c]<l_list[a]+l_list[b]):
                count += 1
print(count)


Fixed submission:
from bisect import bisect_left
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        count += bisect_left(l_list,l_list[i]+l_list[j]) - j - 1

print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(input().split())
b = [0]*n
for i,val in enumerate(a):
    b[val-1] = i + 1
print(*b)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i,val in enumerate(a):
    b[val-1] = i + 1
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())
b = []
for i in range(n):
    b.append(str(a.index(str(i+1))+1))
print(' '.join(b))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i,val in enumerate(a):
    b[val-1] = i + 1
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())
b = [0]*n
for i in range(n):
    b[i] = str(a.index(str(i+1))+1)
print(' '.join(b))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i,val in enumerate(a):
    b[val-1] = i + 1
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
def judge(x):
    if x < 1:
        print('No')
    else:
        print('Yes')

n,k,q = map(int,input().split())
human_list = [k]*n
#print(human_list)
for i in range(q):
    a = int(input())
    human_list = list(map(lambda x: x-1,human_list))
    human_list[a-1] += 1
    #print(human_list)
for i in range(n):
    judge(human_list[i])


Fixed submission:
def judge(x):
    if x < 1:
        print('No')
    else:
        print('Yes')

n,k,q = map(int,input().split())
#human_list = [k]*n
ok_list = [0]*n
for i in range(q):
    a = int(input())
    #human_list = list(map(lambda x: x-1,human_list))
    ok_list[a-1] += 1
    #print(human_list)
ok_list = list(map(lambda x: x+k-q,ok_list))
for i in range(n):
    judge(ok_list[i])
Buggy python submission (verdict: Runtime Error):
nums = int(input())

S = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}

for i in nums:
  input_str = input()
  if input_str in S:
    S[input_str] += 1
    
print('AC x %d' % S['AC'])
print('WA x %d' % S['WA'])
print('TLE x %d' % S['TLE'])
print('RE x %d' % S['RE'])


Fixed submission:
nums = int(input())

S = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

for i in range(0, nums):
    input_str = input()
    if input_str in S:
        S[input_str] += 1

print('AC x %d' % S['AC'])
print('WA x %d' % S['WA'])
print('TLE x %d' % S['TLE'])
print('RE x %d' % S['RE'])
Buggy python submission (verdict: Runtime Error):
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
k=26
l=1
while N-k>0:
  N-=k
  k*=26
  l+=1
ans=["a"]*l
N-=1
i=-1
while N>26:
  a=N%26
  N=N//26
  ans[i]=alpha[a]
  i-=1
ans[i]=alpha[N]
print("".join(ans))


Fixed submission:
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
ans=""
while True:
  N-=1
  a=N%26
  N=N//26
  ans=alpha[a]+ans
  
  if N==0:
    break
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
k=26
l=1
while N-k>0:
  N-=k
  k*=26
  l+=1
ans=["a"]*l
N-=1
i=-1
while N>26:
  a=N%26
  N=N//26
  ans[i]=alpha[a]
  i-=1
ans[i]=alpha[N]
print("".join(ans))


Fixed submission:
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
ans=""
while True:
  N-=1
  a=N%26
  N=N//26
  ans=alpha[a]+ans
  
  if N==0:
    break
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
k=26
l=1
while N-k>0:
  N-=k
  k*=26
  l+=1
ans=""
N-=1
while N>26:
  a=N%26
  N=N//26
  ans=alpha[a]+ans
ans=alpha[N]+ans
k=len(ans)
for i in range(k,l):
  ans="a"+ans
print(ans)


Fixed submission:
N=int(input())
alpha=list("abcdefghijklmnopqrstuvwxyz")
ans=""
while True:
  N-=1
  a=N%26
  N=N//26
  ans=alpha[a]+ans
  
  if N==0:
    break
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort()
max_a=A[-1]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A[i]
  #print(a)
  if dp[a]==True: 
    if i==N-1:
      ans+=1
    elif a!=A[i+1]:
      ans+=1   
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)

Fixed submission:
X=list(map(int,input().split()))
for i in range(5):
  if X[i]!=i+1:
    print(i+1);exit()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
max_a=A[0]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A.pop()
  #print(a)
  if dp[a]==True: 
    if a not in A:
      ans+=1
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
max_a=A[-1]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A[i]
  #print(a)
  if dp[a]==True: 
    if i==N-1:
      ans+=1
    elif a!=A[i+1]:
      ans+=1
    
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
max_a=A[0]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A.pop()
  #print(a)
  if dp[a]==True: 
    if a not in A:
      ans+=1
    i=1
    k=a
    while k<=max_a:
      dp[k]=False
      i+=1
      k=a*i
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
max_a=A[-1]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A[i]
  #print(a)
  if dp[a]==True: 
    if i==N-1:
      ans+=1
    elif a!=A[i+1]:
      ans+=1
    
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
max_a=A[0]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A.pop()
  #print(a)
  if dp[a]==False:
    continue
  if a not in A:
    ans+=1
  i=1
  k=a
  while k<=max_a:
    dp[k]=False
    i+=1
    k=a*i
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
max_a=A[-1]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A[i]
  #print(a)
  if dp[a]==True: 
    if i==N-1:
      ans+=1
    elif a!=A[i+1]:
      ans+=1
    
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
max_a=max(A)
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A.pop()
  #print(a)
  if dp[a]==False:
    continue
  if a not in A:
    ans+=1
  i=1
  k=a
  while k<=max_a:
    dp[k]=False
    i+=1
    k=a*i
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
max_a=A[-1]
dp=[True]*(max_a+1)
ans=0
for i in range(N):
  a=A[i]
  #print(a)
  if dp[a]==True: 
    if i==N-1:
      ans+=1
    elif a!=A[i+1]:
      ans+=1
    
    k=a
    while k<=max_a:
      dp[k]=False    
      k+=a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[0]*N
d = deque()
ans=[-1]*N
d.append(0)
while d:
  c=d.popleft()
  visited[c]=1
  for e in B[c]:
    if visited[e]:
      continue
    if e in d:
      continue
    
    d.append(e)
    ans[e]=c
    
print("Yes")
for i in range(1,N):
  print(ans[i]+1)
  
  

Fixed submission:
from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[0]*N
d = deque()
ans=[-1]*N
d.append(0)
visited[0]=1
while d:
  c=d.popleft()
  for e in B[c]:
    if visited[e]:
      continue
      
    d.append(e)
    visited[e]=1
    ans[e]=c
    
print("Yes")
for i in range(1,N):
  print(ans[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[]
d = deque()
ans=[-1]*N
now=0
d.append(0)
while d:
  c=d.popleft()
  visited.append(c)
  for e in B[c]:
    if e in visited:
      continue
    if e in d:
      continue
    
    d.append(e)
    ans[e]=c
    
if ans.count(-1)!=1:
  print("No")
else:
  print("Yes")
  for i in range(1,N):
    print(ans[i]+1)
  
  

Fixed submission:
from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[0]*N
d = deque()
ans=[-1]*N
d.append(0)
visited[0]=1
while d:
  c=d.popleft()
  for e in B[c]:
    if visited[e]:
      continue
      
    d.append(e)
    visited[e]=1
    ans[e]=c
    
print("Yes")
for i in range(1,N):
  print(ans[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

B=[]
C=[]
for i,a in enumerate(A):
  B.append(a-i)
  C.append(-a-i)
ans=0
for b in B:    
  ans+=C.count(b)
print(ans)

Fixed submission:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i,a in enumerate(A):
  B.append(i+a)
  C.append(i-a)
  
b = Counter(B)
c = Counter(C)
ans=0
for d in b.items():
  ans+=d[1]*c[d[0]]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
k=[0]*2019
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*(10**i)
  l=t%2019
  k[l]+=1
  
ans=0
for l in k:
  ans+=l*(l-1)//2
print(ans)

Fixed submission:
S=input()
k=[0]*2019
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*pow(10,i,2019)
  t%=2019
  k[t]+=1
  
ans=0
for l in k:
  ans+=l*(l-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
k={}
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*(10**i)
  l=t%2019
  if l in k:
    k[l]+=1
  else:
    k[l]=1
  
ans=0
for i in k.values():
  ans+=i*(i-1)//2
print(ans)

Fixed submission:
S=input()
k=[0]*2019
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*pow(10,i,2019)
  t%=2019
  k[t]+=1
  
ans=0
for l in k:
  ans+=l*(l-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
  print(A.count(i+1))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
T=[0 for i in range(N)]
for a in A:
  T[a-1]+=1
for t in T:
  print(t)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)

for r in R:
  for g in G:
    for b in B:
      i=min(min(r,g),b)
      k=max(max(r,g),b)
      if r!=i and r!=k:
        j=r
      elif g!=i and g!=k:
        j=g
      else:
        j=b
      
      if j-i!=k-j:
        ans+=1
print(ans)
      
      

Fixed submission:
import math
N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)
ans=len(R)*len(G)*len(B)

for r in R:
  for g in G:
    if (r+g)%2==0:
      if S[(r+g)//2]=="B":
        ans-=1
    
for r in R:
  for b in B:
    if(r+b)%2==0:
      if S[(r+b)//2]=="G":
        ans-=1
    
for g in G:
  for b in B:
    if (g+b)%2==0:
      if S[(g+b)//2]=="R":
        ans-=1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if j-i!=k-j:
        if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
          ans+=1
print(ans)

Fixed submission:
import math
N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)
ans=len(R)*len(G)*len(B)

for r in R:
  for g in G:
    if (r+g)%2==0:
      if S[(r+g)//2]=="B":
        ans-=1
    
for r in R:
  for b in B:
    if(r+b)%2==0:
      if S[(r+b)//2]=="G":
        ans-=1
    
for g in G:
  for b in B:
    if (g+b)%2==0:
      if S[(g+b)//2]=="R":
        ans-=1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,K,C= map(int,input().split())
S = input()
T = [n for n, v in enumerate(S) if v == "o"]

a,b=[T[0]],[T[-1]]

for i in range(len(T)):
  if len(a)==K and len(b)==K:
    break
  if len(a)!=K:
    if T[i]-a[-1]>C:
      a.append(T[i])
  if len(b)!=K:
    if b[0]-T[-i-1]>C:
      b.insert(0,T[-i-1])
      
for i in range(K):
  if a[i]==b[i]:
    print(a[i]+1)
  

Fixed submission:
N,K,C= map(int,input().split())
S = input()
T = [n for n, v in enumerate(S) if v == "o"]

a,b=[T[0]],[T[-1]]

for i in range(len(T)):
  if len(a)!=K:
    if T[i]-a[-1]>C:
      a.append(T[i])
  if len(b)!=K:
    if b[-1]-T[-i-1]>C:
      b.append(T[-i-1])
      
for i in range(K):
  if a[i]==b[-i-1]:
    print(a[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,K,C= map(int,input().split())
S = input()
T = [n for n, v in enumerate(S) if v == "o"]

a,b=[T[0]],[T[-1]]

for i in range(len(T)):
  if len(a)!=K:
    if T[i]-a[-1]>C:
      a.append(T[i])
  if len(b)!=K:
    if b[0]-T[-i-1]>C:
      b.insert(0,T[-i-1])
      
for i in range(K):
  if a[i]==b[i]:
    print(a[i]+1)
  

Fixed submission:
N,K,C= map(int,input().split())
S = input()
T = [n for n, v in enumerate(S) if v == "o"]

a,b=[T[0]],[T[-1]]

for i in range(len(T)):
  if len(a)!=K:
    if T[i]-a[-1]>C:
      a.append(T[i])
  if len(b)!=K:
    if b[-1]-T[-i-1]>C:
      b.append(T[-i-1])
      
for i in range(K):
  if a[i]==b[-i-1]:
    print(a[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y=map(int,input().split())
D=[]
X-=1;Y-=1
for i in range(N-1):
  for j in range(i+1,N):
    if i<=X:
      if j<=X:
        d=j-i
      elif X<j<Y:
        d=min(j-i,X-i+1+Y-j)
      else:
        d=X-i+1+j-Y
    elif X<i<Y:
      if X<j<Y:
        d=min(j-i,i-X+1+Y-j)
      else:
        d=min(j-i,i-X+1+j-Y)
    else:
      d=j-i
    #print(i,j,d)
    D.append(d)
for i in range(1,N):
  print(D.count(i))

Fixed submission:
N,X,Y=map(int,input().split())
Ans=[0 for i in range(1,N)]
X-=1;Y-=1
for i in range(N-1):
  for j in range(i+1,N):
    if i<=X:
      if j<=X:
        d=j-i
      elif X<j<Y:
        d=min(j-i,X-i+1+Y-j)
      else:
        d=X-i+1+j-Y
    elif X<i<Y:
      if X<j<Y:
        d=min(j-i,i-X+1+Y-j)
      else:
        d=min(j-i,i-X+1+j-Y)
    else:
      d=j-i
    #print(i,j,d)
    Ans[d-1]+=1
for a in Ans:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]

def p(x,y,res):
  if S[y][x]=="#":
    res+=1
  m,n=10001,10001
  if x==W-1 and y==H-1:
    return res
  else:
    if x!=W-1:
      m=p(x+1,y,res)
    if y!=H-1:
      n=p(x,y+1,res)
  return min(m,n)   
  
print(p(0,0,0))

Fixed submission:
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
INF=10001
dp = [[INF]*W for _ in range(H)]
dp[0][0] = 0 if S[0][0] == "." else 1
 
for i in range(H):
  for j in range(W):
    m,n=INF,INF
    if i != 0:
      m = dp[i-1][j] + (S[i-1][j] == "." and S[i][j] == "#")
    if j != 0:
      n = dp[i][j-1] + (S[i][j-1] == "." and S[i][j] == "#")
 
    dp[i][j] = min(m, n, dp[i][j])
  
print(dp[H-1][W-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
F=0
l=""
r=""
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
  else:
    if q[1]=="1":
      if F%2==0:
        l += q[2]
      else:
        r += q[2]
    else:
      if F%2==0:
        r += q[2]
      else:
        l += q[2]  
if F%2==0:
  print(l[::-1]+S+r)
else:
  print(r[::-1]+S[::-1]+l)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
F=0
d=deque(S)
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
    F%=2
  else:
    if q[1]=="1":
      if F==0:
        d.appendleft(q[2])
      else:
        d.append(q[2])
    else:
      if F==0:
        d.append(q[2])
      else:
        d.appendleft(q[2])  
d=list(d)
if F%2==0:
  print("".join(d))
else:
  print("".join(d[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
F=0
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
  else:
    if q[1]=="1":
      if F%2==0:
        S = q[2]+S
      else:
        S = S+q[2]
    else:
      if F%2==0:
        S = S+q[2]
      else:
        S = q[2]+S  
if F%2==0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
from collections import deque
S = input()
Q = int(input())
F=0
d=deque(S)
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
    F%=2
  else:
    if q[1]=="1":
      if F==0:
        d.appendleft(q[2])
      else:
        d.append(q[2])
    else:
      if F==0:
        d.append(q[2])
      else:
        d.appendleft(q[2])  
d=list(d)
if F%2==0:
  print("".join(d))
else:
  print("".join(d[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import  fractions
N = int(input())
A = list(map(int,input().split()))
mod =10**9+7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
inv_t = [0]+[1]
for i in range(2,10**7):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
  
k=1
for a in A:
  k=lcm(k,a)
  
ans=0
for a in A:
  ans+=k*inv_t[a]%mod
print(ans%mod)

Fixed submission:
import  fractions
N = int(input())
A = list(map(int,input().split()))
mod =10**9+7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
inv_t = [0]+[1]
for i in range(2,10**6+5):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
  
k=1
ans=0
for a in A:
  k=lcm(k,a)
  ans+=inv_t[a]%mod
k%=mod

print(ans*k%mod)

Buggy python submission (verdict: Runtime Error):
import  fractions
N = int(input())
A = list(map(int,input().split()))
mod =10**9+7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
inv_t = [0]+[1]
for i in range(2,10**6):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
  
k=1
for a in A:
  k=lcm(k,a)
  
ans=0
for a in A:
  ans+=k*inv_t[a]%mod
print(ans)

Fixed submission:
import  fractions
N = int(input())
A = list(map(int,input().split()))
mod =10**9+7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
inv_t = [0]+[1]
for i in range(2,10**6+5):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
  
k=1
ans=0
for a in A:
  k=lcm(k,a)
  ans+=inv_t[a]%mod
k%=mod

print(ans*k%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
B=[]
for i in range(n):
  x,l=map(int,input().split())
  B.append([x+l,x-l])
B.sort()
Left=[]
for b in B:
  l=b[1];r=b[0]
  flag=1
  for c in Left:
    if (c[0]<l and c[1]>l) or (c[0]<r and c[1]>r):
      flag=0;break   
    elif c[0]>=l and c[1]<=r:
      flag=0;break    
  if flag:
    Left.append([l,r])
print(len(Left))

Fixed submission:
n=int(input())
B=[]
for i in range(n):
  x,l=map(int,input().split())
  B.append([x-l,x+l])
B.sort(key=lambda x:x[1])
max_l=-10**18-5
ans=0
for b in B:
  if max_l <= b[0]:
    max_l = b[1]
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0

for i in range(N-1):
  for j in range(i+1,N):
    ans += A[i]^A[j]
    ans %= mod
print(ans)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0
count=[0]*60
for a in A:
  for i in range(60):
    count[i] += a & 1
    a >>= 1
    
for i in range(60):
  ans += count[i] * (N - count[i]) * (2 ** i)
  ans %= mod
print(ans)

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

ans=0
for i in range(N-1):
  for j in range(i+1,N):
    ans+=A[i]^A[j]
    ans%=MOD
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 0
count=[0]*60
for a in A:
  for i in range(60):
    count[i] += a & 1
    a >>= 1
    
for i in range(60):
  ans += count[i] * (N - count[i]) * (2 ** i)
  ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map( int,input().split() )
A = list( map(int,input().split()) )
remain = M

while remain > 0:
  i = A.index(max(A))
  A[i] = A[i]//2
  remain -= 1
print(sum(A))


Fixed submission:
import heapq
N,M=map(int,input().split())
A=list(map(int,input().split()))
A=[-i for i in A]

heapq.heapify(A)
for i in range(M):
    a=-heapq.heappop(A)
    heapq.heappush(A,-(a//2))
print(-sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
if n == 1:print(0);exit()
sum = 0
for i in range(0,n-1):
  sum += i+1
print(sum)

Fixed submission:
n = int(input())
print((1+n-1)*(n-1)//2)