Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
わからん

Fixed submission:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    N,M = map(int,input().split())
    count_list = [0]*(N+1)
    for _ in range(M):
        a,b = map(int,input().split())
        count_list[a] += 1
        count_list[b] += 1
    for c in count_list:
        if c% 2 == 1:
            print('NO')
            return
    print('YES')
    return

    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):


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


counter = 0
for i in range(N-2):
    while a[i] + a[i+1] > x :
        if a[i+1] > 0:
            a[i+1] -=  1
        else :
            a[i] -=  1
        
        counter += 1
       
while a[N-2] + a[N-1] > x:
    if a[N-2] > 0:
        a[N-2] -= 1
    else :
        a[N-1] -= 1
    
    counter += 1

print(counter)

Fixed submission:


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


counter = 0


dif1 = a[N-2] + a[N-1] - x
if dif1 > 0:
        a1 = a[N-2] - dif1
        if a1 > 0:
            a[N-2] -= dif1
            counter  += dif1
        else:
            a[N-1]-= -a1
            a[N-2] = 0
            counter += dif1

for i in range(N-2):
    dif1 = a[i] + a[i+1] - x
    if dif1 > 0:
        a1 = a[i+1] - dif1
        if a1 > 0:
            a[i+1] -= dif1
            counter  += dif1
        else:
            a[i]-= -a1
            a[i+1] = 0
            counter += dif1

       
while a[N-2] + a[N-1] > x:
    if a[N-2] > 0:
        a[N-2] -= 1
    else :
        a[N-1] -= 1
    
    counter += 1

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

Fixed submission:
S=list(input())
if S[len(S)-1]=="s":
  S.append("es")
else:
  S.append("s")
s="".join(S)
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
point=0

for a in range(1, n):
  b=1
  while a*b<n:
    b+=1
    point+=1

print(point)     


Fixed submission:
n = int(input())
ans = 0
for a in range(1, n):
  ans += (n - 1) // a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

point=0
for c in range(1,n):
  a=1
  while n-c>=a:
    if (n-c)%a==0:
      point+=1
    a+=1
    
print(point)

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):
d,t,s=map(int,input().split())
if s*t >= d:
  print("Yes")
else:
  print("No")

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

Buggy python submission (verdict: Runtime Error):
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")
for i in range(3,s+1):
  dp[i]=dp[i-1]+dp[i-3]
  dp.append(dp[i])
  score=dp[s]%(10**9+7)
print(score)
  

Fixed submission:
x=int(input())
if x==0:
  print("1")
else:
  print("0")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
score=[]
for x in range(a,b+1):
  for y in range(c,d+1):
    score.append(x*y)
print(max(score))

Fixed submission:
a,b,c,d = map(int,input().split())
score=[]
score+=a*c,b*c,a*d,b*d
print(max(score))
Buggy python submission (verdict: Runtime Error):
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")
elif 3<=s<6 :
  print("1")
  
for i in range(3,s+1):
  dp[i]=dp[i-1]+dp[i-3]
  dp.append(dp[i])
  score=dp[s]%(10**9+7)
print(score)

Fixed submission:
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")  
else:
  for i in range(3,s+1):
    dp[i]=dp[i-1]+dp[i-3]
    dp.append(dp[i])
    score=dp[s]%(10**9+7)
  print(score)

Buggy python submission (verdict: Runtime Error):
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")
for i in range(3,s+1):
  dp[i]=dp[i-1]+dp[i-3]
  dp.append(dp[i])
  score=dp[s]%(10**9+7)
print(score)
  

Fixed submission:
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")  
else:
  for i in range(3,s+1):
    dp[i]=dp[i-1]+dp[i-3]
    dp.append(dp[i])
    score=dp[s]%(10**9+7)
  print(score)

Buggy python submission (verdict: Runtime Error):
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
for i in range(3,s+1):
  dp[i]=dp[i-1]+dp[i-3]
  dp.append(dp[i])
  score=dp[s]%(10**9+7)
print(score)

Fixed submission:
s = int(input())
#最後に切った場所がiであるようなパターンの数をdp[i]とする
dp=[0]*(s+1)
dp[0]=1
if s<3:
  print("0")  
else:
  for i in range(3,s+1):
    dp[i]=dp[i-1]+dp[i-3]
    dp.append(dp[i])
    score=dp[s]%(10**9+7)
  print(score)
Buggy python submission (verdict: Runtime Error):
d,t,s=int(input())
if S*t >= d:
  print("Yes")
else:
  print("No")


Fixed submission:
D,T,S = map(int,input().split())

if D/S > T:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
tlen = len(T)


for i in range(tlen, 1):
    for k in range(0, tlen+1-i):
        Tinclude = T[k:i]
        print(tlen-i)
        break

Fixed submission:
D,T,S = map(int,input().split())

if D/S > T:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()

for i in range(0,len(S)-len(T)+1):
  score=0
  for j in range(0,len(T)):
    if(S[i] != T[i+j]):
      score += 1
  score = min(score, len(T))
print(score)

Fixed submission:
S = input()
T = input()
 
Nmax = len(T)
for i in range(len(S)-len(T)+1):
    diff = 0
    for j in range(len(T)):
        if(S[i+j] != T[j]):
            diff += 1
 
    Nmax = min(diff, Nmax)
 
print(Nmax)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
score=0
mod=10**9+7
for i in range(0,n-1):
  b=a[0]
  del a[0]
  score+=b*sum(a)
print(score%mod)
    

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
score=0
mod=10**9+7

for i in range(0,n-1):
  j=n-1
  while i < j:    
    score+=a[i]*a[j]
    j-=1
print(score%mod)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))

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

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

score=0
for j in range(n):
  i=0
  while i < j:
    score += a[i]*a[j]
    i += 1
print(score%mod)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))

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

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N, X, T = map(int,input().split())
takoyakitime=math.ceil(N/T/X)
print(takoyakitime)

Fixed submission:
import math
N, X, T = map(int,input().split())
takoyakitime=math.ceil(N/X)
t_takoyakitime = takoyakitime*T
print(t_takoyakitime)

Buggy python submission (verdict: Runtime Error):
N, X, T = map(int,inout().split())
takoyakitime=math.ceil(N/T/X)
print(takoyakitime)

Fixed submission:
import math
N, X, T = map(int,input().split())
takoyakitime=math.ceil(N/X)
t_takoyakitime = takoyakitime*T
print(t_takoyakitime)
Buggy python submission (verdict: Runtime Error):
N=int(input())
Ls = list(map(int,input().split()))
score=0
for i in range(0,N-2):
  a = Ls[i]
  for j in range(i+1, N-1):
      b = Ls[j]
      for k in range(j+1, N):
        c = Ls[k]
        if ((a+b>c)&(a+c>b)&(b+c>a)&(a!=b)&(a!=c)&(b!=c)):
          score+=1
          L_list=[i,j,k]
          print(L_list)
print(score)

Fixed submission:
N=int(input())
n= str(N)
total=0
for i in range(len(n)):
  k = n[i]
  k = int(k)
  total += k
  
if total%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N,M,K = map(int,input().split())	
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a=[0]
b=[0]
for i in range(N):
  a.append(a[-1]+A[i])
for j in range(M):
  b.append(b[-1]+B[j])  
for i in range(len(A)+1):
  for j in range(len(B)+1):
    score=a[i]+b[j]
    if score <= K:
      point=[]
      point.append(i+j)
print(max(point))


Fixed submission:
a=int(input())
score=a+a**2+a**3
print(score)
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
a = list(map(int,input().split()))
score=1
for i in a:
  score*=i
if score>10**18:
  print(-1)
  exit()
print(score)


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

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


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

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
score=1
a=input().split()
for i in a:
  score*=int(i)
if score>1e18:
  score=-1
print(score)

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

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

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
score=1
if 0 in a:
  print(0)
  exit()
for i in a:
  score*=i
  if score>10**18:
    print(-1)
    exit()
print(score)
Buggy python submission (verdict: Runtime Error):
a,b,h,m=map(float,input().split())
#時針の角度をA
c=(30*h-11/2*m)
ct=math.radians(c)
cos=math.cos(ct)
ans=a**2+b**2-2*a*b*abs(cos)
print(math.sqrt(ans))

Fixed submission:
import math
 
A, B, H, M = map(int, input().split())
 
angle_A = 6*M
angle_B = 30*(H+M/60)
angle_C = abs(angle_A-angle_B)
 
rad_C = math.radians(angle_C)
 
C = math.sqrt(A**2+B**2-2*A*B*math.cos(rad_C))
 
print(C)

Buggy python submission (verdict: Runtime Error):
a,b,h,m=map(float,input().split())
#時針の角度をA
c=(30*h-11/2*m)
ct=math.radians(c)
cos=math.cos(ct)
ans=a**2+b**2-2*a*b*abs(cos)
print(math.sqrt(ans))

Fixed submission:
import math
 
A, B, H, M = map(int, input().split())
 
angle_A = 6*M
angle_B = 30*(H+M/60)
angle_C = abs(angle_A-angle_B)
 
rad_C = math.radians(angle_C)
 
C = math.sqrt(A**2+B**2-2*A*B*math.cos(rad_C))
 
print(C)
Buggy python submission (verdict: Runtime Error):
s = input()

if s[len(s)] == 's':
    print(s+'es')
else:
    print(s+'s')  

Fixed submission:
s = input()

if s[len(s)-1] == 's':
    print(s+'es')
else:
    print(s+'s')
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
ruijimax = 0

for first in range(len(S)-len(T)):
    ruiji = 0
    for i in range(len(T)):
        if S[first+i] == T[i]:
            ruiji += 1
    if ruijimax <= ruiji:
        ruijimax = ruiji

print(len(T)-ruijimax)

Fixed submission:
d,t,s = map(int, input().split())

if d/t<=s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = ""
ac=0
wa=0
tle=0
re=0

for i in range(n):
    s = input()

    if s == 'AC':
        ac = ac+1
    elif s == 'TLE':
        tle = tle+1
    elif s == 'WA':
        wa = wa+1
    elif s == 'RE':
        re = re+1

print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Fixed submission:
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000-n%1000)

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

if n%1000 = 0:
    print(n / 1000)
else 
    print(n/1000+1)



Fixed submission:
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000-n%1000)

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

satsu = n / 1000

printf(satsu+1)

Fixed submission:
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000-n%1000)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ac, tle, wa, re = 0

for i in range(n):
    s[i-1] = input()
    
    
    if s[i-1] =="AC":
        ac = ac+1
    elif s[i-1] =="TLE"
        tle = tle+1
    elif s[i-1] =="WA"
        wa = wa+1
    elif s[i-1] =="RE"
        re = re+1

print("AC x "+ac)
print("WA x "+wa)
print("TLE x "+tle)
print("RE x "+re)

Fixed submission:
n = int(input())
s = ""
ac=0
wa=0
tle=0
re=0

for i in range(n):
    s = input()

    if s == 'AC':
        ac = ac+1
    elif s == 'TLE':
        tle = tle+1
    elif s == 'WA':
        wa = wa+1
    elif s == 'RE':
        re = re+1

print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))
Buggy python submission (verdict: Runtime Error):
    x.append(int(input()))N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

print(int(hpsum))

Fixed submission:
N = int(input())
x = []
hp = []
xa = 0
hpsum = 0

x = [int(e) for e in input().split()]
for i in range(N):
    xa += x[i]



xa = xa / N

if xa % 1 < 0.5:
    xa = int(xa / 1)
elif xa % 1 >= 0.5:
    xa = int(xa / 1 + 1)

for j in range(N):
    hp.append((x[j]-xa)*(x[j]-xa))
    hpsum += hp[j]

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

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))
v = 1
if 0 in a:
    print(0)
    sys.exit(0)
for i in a: 
    v *= i
    if v > 10 ** 18:
        v = -1
        break
print(v)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

x = int(input())

for i in range(-2000, 2000):
    for j in range(-2000, 2000):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            sys.exit()


Fixed submission:
import sys

x = int(input())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools 
n, m, q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(q)]

ls = [0] * n + [1] * (m - 1)
mx = 0
for l in itertools.permutations(ls):
    a = [0]
    idx = 1
    for i in l: 
        if i == 0: a.append(idx)
        else: idx += 1
    #print(l, a)
    v = 0
    for i in query:
        if a[i[1]] - a[i[0]] == i[2]: v += i[3]
    mx = max(v, mx)
print(mx)


Fixed submission:
import itertools 
n, m, q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(q)]

ls = list(range(n + m - 1))
mx = 0
for l in itertools.combinations(ls, m - 1):
    a = [0]
    idx = 0
    val = 1
    for i in range(n + m - 1): 
        if idx < m - 1 and i == l[idx]:
            val += 1
            idx += 1
        else: 
            a.append(val)
    #print(l, a)
    v = 0
    for i in query:
        if a[i[1]] - a[i[0]] == i[2]: v += i[3]
    mx = max(v, mx)
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
v = 0
for a in range(1, k + 1):
  for b in range(1, k + 1):
    for c in range(1, k + 1):
      v += math.gcd(math.gcd(a, b), c)
print(v)


Fixed submission:
import math
k = int(input())
v = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        g = math.gcd(a, b)
        for c in range(1, k + 1):
            v += math.gcd(g, c)
print(v)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
v = 0
for a in range(1, k + 1):
  for b in range(1, k + 1):
    for c in range(1, k + 1):
      v += math.gcd(a, math.gcd(b, c))
print(v)

Fixed submission:
import math
k = int(input())
v = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        g = math.gcd(a, b)
        for c in range(1, k + 1):
            v += math.gcd(g, c)
print(v)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
s = s.replace('R', '0')
s = s.replace('G', '1')
s = s.replace('B', '2')

s0 = [0] * (n + 5)
s1 = [0] * (n + 5)
s2 = [0] * (n + 5)

for i in range(n):
    s0[i + 1] = s0[i] + (s[i] == '0')
    s1[i + 1] = s1[i] + (s[i] == '1')
    s2[i + 1] = s2[i] + (s[i] == '2')

#print(s0)
#print(s1)
#print(s2)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]: continue
        h = 99 - (ord(s[i]) + ord(s[j]))
        if h == 0:
            ans += s0[n] - s0[j]
            if 2 * j - i < n and s[2 * j - i] == '0': ans -= 1
        if h == 1:
            ans += s1[n] - s1[j]
            if 2 * j - i < n and s[2 * j - i] == '1': ans -= 1
        if h == 2:
            ans += s2[n] - s2[j]
            if 2 * j - i < n and s[2 * j - i] == '2': ans -= 1
        #print(i, j, h, ans)
print(ans)

Fixed submission:
n = int(input())
s = input()
s = s.replace('R', '0')
s = s.replace('G', '1')
s = s.replace('B', '2')

s0 = [0] * (n + 5)
s1 = [0] * (n + 5)
s2 = [0] * (n + 5)

for i in range(n):
    s0[i + 1] = s0[i] + (s[i] == '0')
    s1[i + 1] = s1[i] + (s[i] == '1')
    s2[i + 1] = s2[i] + (s[i] == '2')

#print(s0)
#print(s1)
#print(s2)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]: continue
        h = 99 - (ord(s[i]) + ord(s[j]))
        if h == 0:
            ans += s0[n] - s0[j]
            if 2 * j - i < n and s[2 * j - i] == '0': ans -= 1
        if h == 1:
            ans += s1[n] - s1[j]
            if 2 * j - i < n and s[2 * j - i] == '1': ans -= 1
        if h == 2:
            ans += s2[n] - s2[j]
            if 2 * j - i < n and s[2 * j - i] == '2': ans -= 1
        #print(i, j, h, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
from decimal import *
a,b,c = map(int,input().split())
getcontext().prec = 100
print("Yes" if sqrt(a) + sqrt(b) < sqrt(c) else "No")

Fixed submission:
a, b, c = map(int, input().split())
if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2: print("Yes")
else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = deque(list(input()))
q = int(input())
rev = False
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        s.reverse()
    else:
        if qr[1] == '1':
            s.appendleft(qr[2])
        else:
            s.append(qr[2])
print(''.join(s))

Fixed submission:
s = input()
q = int(input())
a, b = "", ""
rev = False
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        rev = 1 - rev
    else:
        if qr[1] == '1':
            if rev: b += qr[2]
            else  : a += qr[2]
        else:
            if rev: a += qr[2]
            else  : b += qr[2]
if rev:
    print(b[::-1] + s[::-1] + a)
else:
    print(a[::-1] + s + b)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        s = s[::-1]
    else:
        if qr[1] == '1': s = qr[2] + s
        else: s = s + qr[2]
print(s)

Fixed submission:
s = input()
q = int(input())
a, b = "", ""
rev = False
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        rev = 1 - rev
    else:
        if qr[1] == '1':
            if rev: b += qr[2]
            else  : a += qr[2]
        else:
            if rev: a += qr[2]
            else  : b += qr[2]
if rev:
    print(b[::-1] + s[::-1] + a)
else:
    print(a[::-1] + s + b)
Buggy python submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))
l = a[0]
for i in range(1, n): l = l // fractions.gcd(l, a[i]) * a[i]
print(sum([l // a[i] for i in range(n)]) % 1000000007)


Fixed submission:
n = int(input())
c = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, n + 1):
    l = int(str(i)[0])
    r = i % 10
    c[l][r] += 1
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = [0] * 60
for i in a:
    for j in range(60):
        b[j] += bool(i & (1 << j))
#print(b[j])
ans = 0
inf = int(1e9 + 7)
for i in range(60):
    ans += b[i] * (n - b[i]) * (1 << i) % inf
    ans %= inf
print(ans)

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

b = [0] * 60
for i in a:
    for j in range(60):
        b[j] += bool(i & (1 << j))
#print(b[j])
ans = 0
inf = int(1e9 + 7)
for i in range(60):
    ans += b[i] * (n - b[i]) * (1 << i) % inf
    ans %= inf
print(ans)