Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

# 移動量が最大2から最大Kになっただけ
# でもちょっとめんどい
# K回比較, を適当に関数にしとくことでforで回せるようになるらしい

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
    for j in range(K):
        if i>j:
            dp[i] = min(dp[i], dp[i-j-1] + abs(H[i] - H[i-j-1]))
        # print(dp[i])
    print(dp)
print(dp[N-1])

Fixed submission:
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

# 移動量が最大2から最大Kになっただけ
# でもちょっとめんどい
# K回比較, を適当に関数にしとくことでforで回せるようになるらしい

dp=[float("inf")]*N
dp[0]=0
for i in range(1,N):
    for j in range(K):
        if i>j:
            dp[i] = min(dp[i], dp[i-j-1] + abs(H[i] - H[i-j-1]))
        # print(dp[i])
    # print(dp)
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N,M=list(map(int, input().split()))
P=[set() for _ in range(N)]
for i in range(M):
    x,y=list(map(int, input().split()))
    x-=1
    y-=1
    P[x].add(y)

dp=[-1]*N

def lpth(n):
    if dp[n]>-1:
        return dp[n]
    l=P[n]
    # print(l)
    if l:
        s=[lpth(k) for k in l]
        # print(s)
        a=max(s)+1
    else:
        a=0
    dp[n]=a
    return a

for i in range(N):
    dp[i]=lpth(i)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
P = [set() for _ in range(N)]
for i in range(M):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    P[x].add(y)

dp = [-1]*N


def lpth(n):
    if dp[n] > -1:
        return dp[n]
    l = P[n]
    # print(l)
    if l:
        s = [lpth(k) for k in l]
        # print(s)
        a = max(s)+1
    else:
        a = 0
    dp[n] = a
    return a


for i in range(N):
    dp[i] = lpth(i)
print(max(dp))
# print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
N,M=list(map(int, input().split()))
S=input()
T=input()
g=gcd(N,M)
l=N*M//g
n=l//N
m=l//M
for i in range(l):
  if i%n==0 and i%m==0:
    if S[i//n]!=T[i//m]:
      print(-1)
      exit()
else:
  print(l)

Fixed submission:
from math import gcd
N,M=list(map(int, input().split()))
S=input()
T=input()
g=gcd(N,M)
l=N*M//g
n=l//N
m=l//M
for i in range(0,l,n):
  if i%m==0:
    if S[i//n]!=T[i//m]:
      print(-1)
      exit()
else:
  print(l)
Buggy python submission (verdict: Runtime Error):
N,T=list(map(int, input().split()))
a=10**5
for _ in range(N):
  c,t=list(map(int, input().split()))
  if t<=T:
    a=min(c.a)
if a==10**5:
  print('TLE')
else:
  print(c)

Fixed submission:
N,T=list(map(int, input().split()))
a=10**5
for _ in range(N):
  c,t=list(map(int, input().split()))
  if t<=T:
    a=min(c,a)
if a==10**5:
  print('TLE')
else:
  print(a)
Buggy python submission (verdict: Runtime Error):
S=input()
i=0
while S[i]!='1':
  i+=1
else:
  i=0
print(S[i])

Fixed submission:
S=input()
K=int(input())
i=0
while S[i]=='1' and K>i+1 and i<len(S):
  i+=1
if i==len(S):
  i=0
print(S[i])
Buggy python submission (verdict: Runtime Error):
A,B=list(map(int, input().split()))
if A<=8 and B<=8:
  print('Yay!')
else:
  peint(':(')

Fixed submission:
A,B=list(map(int, input().split()))
if A<=8 and B<=8:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))


def comb(n, k):
    if k > n//2:
        k = n-k
    c, d = 1, 1
    for i in range(k):
        c *= n-i
        d *= i+1
    return c//d


A.sort()
a = A[-1]
k = bisect_left(A, a//2+1)
x = comb(a, A[k-1])
y = comb(a, A[k])
if x >= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)


Fixed submission:
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 2:
    print(A[1], A[0])
    exit()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)
Buggy python submission (verdict: Runtime Error):
S=input()
S.sort()
if S=='abc':
  print('Yes')
else:
  print('No')


Fixed submission:
S=input()
L=''.join(sorted(S))
if L=='abc':
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
S-input()
S.sort()
if S=='abc':
  print('Yes')
else:
  print('No')

Fixed submission:
S=input()
L=''.join(sorted(S))
if L=='abc':
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
date=str(input())
data.replace("2017","2018")
print(data)

Fixed submission:
date=str(input())
print(date.replace("2017","2018",1))

Buggy python submission (verdict: Runtime Error):
date=str(input())
data.replace("2017","2018")

Fixed submission:
date=str(input())
print(date.replace("2017","2018",1))
Buggy python submission (verdict: Runtime Error):
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B.sort(reversed=True)
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))

Fixed submission:
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B = reversed(sorted(B))
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))
Buggy python submission (verdict: Time Limit Exceeded):
def prime(n):
    if n==1:
        return False
    flag=True
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            flag=False
    return flag

Q=int(input())
L=[0]*Q
for _ in range(Q):
    l,r=list(map(int, input().split()))
    ct=0
    for i in range(l,r+1,2):
        n,m=i,(i+1)//2
        flag=prime(n)&prime(m)
        ct+=flag
    L[_]=ct
for _ in range(Q):
    print(L[_])

Fixed submission:
S = set()
L = [True]*(10**5+1)
L[0] = False
L[1] = False
for i in range(2, 10**5+1):
    if L[i]:
        S.add(i)
        for j in range(i*2, 10**5+1, i):
            L[j] = False


def prime(n):
    return n in S


M = [0]*(5*10**4+1)
for i in range(1, 5*10**4+1):
    m = 2*i-1
    n = i
    M[i] = M[i-1]+(prime(m) & prime(n))

Q = int(input())
ans = [0]*Q
for _ in range(Q):
    l, r = list(map(int, input().split()))
    i = (l+1)//2
    j = (r+1)//2
    ans[_] = M[j]-M[i-1]
for _ in range(Q):
    print(ans[_])
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right

N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
A.sort()
S=set(A)
S=list(S)
B=[]

def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)

for i in S:
  a=A[0]
  j = bisect_right(A,a)
  B+=[j]
  del A[:j]
B.sort()
# print(B)
C=B[:len(S)-K]
print(sum(C))


Fixed submission:
#ABC_081_A_Placing_Marbles
a=input(str())
count=0
for i in range(0,3):
	if a[i]=='1':
		count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b,c=list(map(int,input().split()))
if a==b:
  print(c)
elif b==c:
  print(a)
eles:
  print(b)

Fixed submission:
a,b,c=list(map(int,input().split()))
if a==b:
  print(c)
elif b==c:
  print(a)
else:
  print(b)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
B=set(A)
# print(A)
# print(B)

# シミュレーションする方法で解いてみる
C=set()
for i in range(N):
  if A[i] in C:
    C.remove(A[i])
  else:
    C=C|{A[i]}
  # print(C)
print(len(C))

Fixed submission:
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
A.sort()
# print(A)

# 想定解で解くしかない
res=0
i=0
while i<N:
  c=A[i]
  f=0
  while i<N and A[i]==c:
    f+=1
    i+=1
  res+=f%2
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
B=set(A)
# print(A)
# print(B)

ct=0
for i in B:
  if A.count(i)%2==1:
    ct+=1
print(ct)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
A.sort()
# print(A)

# 想定解で解くしかない
res=0
i=0
while i<N:
  c=A[i]
  f=0
  while i<N and A[i]==c:
    f+=1
    i+=1
  res+=f%2
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = list(map(int, input().split()))
C = Counter()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C += {a: b}
# print(C)
L = list(C.keys())
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])


Fixed submission:
N, K = list(map(int, input().split()))
C = [0]*(10**5+1)
S=set()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C[a] += b
    S.add(a)

L = list(S)
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = list(map(int, input().split()))
C = Counter()
S = set()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C += {a: b}
    S.add(a)
# print(C)
L = list(S)
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])


Fixed submission:
N, K = list(map(int, input().split()))
C = [0]*(10**5+1)
S=set()
for _ in range(N):
    a, b = list(map(int, input().split()))
    C[a] += b
    S.add(a)

L = list(S)
L.sort()
i = 0
ct = C[L[0]]
while ct < K:
    i += 1
    ct += C[L[i]]
print(L[i])
Buggy python submission (verdict: Runtime Error):
a,b=list(input())
if a==b:
  print('H')
else:
  print('D')

Fixed submission:
a,b=list(input().split())
if a==b:
  print('H')
else:
  print('D')
Buggy python submission (verdict: Runtime Error):
X=abs(int(input()))
ct=1
sum=1
while X<=sum:
  ct+=1
  sub+=ct
print(ct)X=int(input())
ct=1
sum=1
while X>sum:
  ct+=1
  sum+=ct
print(ct)

Fixed submission:
X=int(input())
ct=1
sum=1
while X>sum:
  ct+=1
  sum+=ct
print(ct)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
p=1
for i in range(N):
  p*=(i+1)
#  p=p%(10**9+7)

p=p%(10**9+7)
print(p)

Fixed submission:
N=int(input())
p=1
for i in range(N):
  p*=(i+1)
  p=p%(10**9+7)
print(p)
Buggy python submission (verdict: Runtime Error):
N,M=list(map(int, input().split()))
K=N-2*M
  print(max(N+K//3,N))

Fixed submission:
N,M=list(map(int, input().split()))
K=M-2*N
if K>=0:
  print(N+K//4)
else:
  print(min(N, M//2))
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]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)


Fixed submission:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))

C=[1 for i in range(220000)]
for i in range(N):
    if C[A[i]]==0:
        continue
    for j in range(2,220000//A[i]-1):
        C[A[i]*j]=0

ans=0
for i in range(N):
    if i!=N-1 and A[i]==A[i+1]:
        C[A[i]]=0
        continue
    if C[A[i]]==1:
        ans+=1
        C[A[i]]=0

print(ans)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))

C=[1 for i in range(10**6+1)]
for i in range(N):
    if C[A[i]]==0:  #すでに割り切るものがあるとわかった場合
        continue
    if C[A[i]]==-1:  #同じ数字を2回目に通った時
        C[A[i]]=0
        continue
    C[A[i]]*=-1  #通ったの印
    j=2
    while A[i]*j<=10**6:  #それの倍数はすべてダメ
        C[A[i]*j]=0
        j+=1

print(C.count(-1))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
goto=[[] for i in range(N+1)]
for i in range(M):
    goto[AB[i][0]].append(AB[i][1])
    goto[AB[i][1]].append(AB[i][0])
#print(goto)

from collections import deque
from sys import exit
AB=deque(AB)
rank=[[1]]
flag=1

while len(AB)>0:
    l=len(AB)
    rank.append([])
    for i in range(l):
        ab=AB.popleft()
        if ab[0] in rank[-2] and ab[1] not in rank[-2]:
            rank[-1].append(ab[1])
        elif ab[1] in rank[-2] and ab[0] not in rank[-2]:
            rank[-1].append(ab[0])
        elif ab[0] not in rank[-2] and ab[1] not in rank[-2]:
            AB.append(ab)
    if l==len(AB):
        print('No')
        exit()

#print(rank)
print('Yes')
rank2=[-1 for i in range(N+1)]
rank2[1]=0
for i in range(1,len(rank)):
    for j in range(len(rank[i])):
        rank2[rank[i][j]]=i

#print(rank2)

for i in range(2,N+1):
    s=set(goto[i])&set(rank[rank2[i]-1])
    print(list(s)[0])

Fixed submission:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
goto=[[] for i in range(N+1)]
for i in range(M):
    goto[AB[i][0]].append(AB[i][1])
    goto[AB[i][1]].append(AB[i][0])
#print(goto)

parent=[0 for i in range(N+1)]
done=[0 for i in range(N+1)]
done[1]=1

from collections import deque
q=deque([1])

while q:
    r=q.popleft()
    for t in goto[r]:
        if done[t]:
            continue
        parent[t]=r
        done[t]=1
        q.append(t)

#print(parent)

print('Yes')
for i in range(2,N+1):
    print(parent[i])
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

for i in range(1,min(K+1,100)):
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=0
saigo=tour[-1]
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<=before:
    print(tour[K-1])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

while True:
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=1
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<len(tour):
    print(tour[K])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

for i in range(1,100):
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=0
saigo=tour[-1]
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<=before:
    print(tour[K-1])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

while True:
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=1
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<len(tour):
    print(tour[K])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(100010)]
R=[0 for i in range(100010)]
for i in range(N):
    if A[i]+i<100010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(100010):
    ans+=L[i]*R[i]
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(200010)]
R=[0 for i in range(200010)]
for i in range(N):
    if A[i]+i<200010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(200010):
    ans+=L[i]*R[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)
dp=[0 for i in range(N)]
check=[0 for i in range(N)]

List=[]
moji = ''
kireme=False
for i in range(N):
    moji+=S[i]
    dp[i]=dp[i-1]
    l=len(moji)
    for j in range(l):
        if int(moji[l-j-1:])%2019==0:
            List.append((i-j,i,int(moji[l-j-1:])))
            check[i]+=1+check[i-j-1]
            dp[i]+=1
            """
            if check[max(i-j-1,0)]:
                #check[i-j-1]+=1
                dp[i]+=check[i-j-1]
            """
            
#print(List)
#print(check)
#print(dp) 
print(dp[N-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)


S = input()
N, P = len(S),2019

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    sys.exit()

num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
Rs,Gs,Bs=[],[],[]

for i in range(n):
    if s[i]=='R':
        Rs.append(i)
    elif s[i]=='G':
        Gs.append(i)
    else:
        Bs.append(i)

ans=len(Rs)*len(Gs)*len(Bs)
for i in Rs:
    for j in Gs:
        for k in Bs:
            l=[i,j,k]
            l.sort()
            a,b,c=l[0],l[1],l[2]
            if b-a==c-b:
                ans-=1

print(ans)


Fixed submission:
n=int(input())
s=input()
Rs,Gs,Bs=[],[],[]

for i in range(n):
    if s[i]=='R':
        Rs.append(i)
    elif s[i]=='G':
        Gs.append(i)
    else:
        Bs.append(i)

ans=len(Rs)*len(Gs)*len(Bs)
for i in Rs:
    for j in Gs:
        dis=abs(i-j)
        a=min(i,j)-dis
        b=max(i,j)+dis
        c=min(i,j)+dis//2
        if a>=0:
            if s[a]=='B':
                ans-=1
        if b<n:
            if s[b]=='B':
                ans-=1
        if dis%2==0:
            if s[c]=='B':
                ans-=1

print(ans)
Buggy python submission (verdict: Runtime Error):
S=list(input())

for i in range(len(S)//2):
    F=1
#    print(S[i],S[-(i+1)])
    if S[i]!=S[-(i+1)]:
        F=0
        break

N=len(S)
s=S[:N//2]
#print(s)
for i in range(N//2//2):
    FF=1
#    print(s[i],s[-(i+1)])
    if s[i]!=s[-(i+1)]:
        FF=0
        break

if F and FF:
    print('Yes')
else:
    print('No')

Fixed submission:
S=list(input())
SV=S[::-1]
N=len(S)

for i in range(N):
    F=1
    if S[i]!=SV[i]:
        F=0
        break

s=S[:N//2]
sv=s[::-1]
n=len(s)
#print(s)
for i in range(n):
    FF=1
#    print(s[i],s[-(i+1)])
    if s[i]!=sv[i]:
        FF=0
        break

if F and FF:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S+front)
else:
    print(front[::-1]+S+rear)

Fixed submission:
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=op[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+rear)

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

for i in range(QN):
    op=input()
    if op[0]=='1':
        S=S[::-1]
    else:
        if op[2]=='1':
            S=op[4]+S
        else:
            S=S+op[4]

print(S)

Fixed submission:
S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=op[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+rear)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
mod=10**9+7

def nCmMOD(A,B,Mod):
    #a conb b を　Mod で割った余り
    num,den=1,1
    for i in range(B):
        num*=(A-i)
        den*=(i+1)
        num%=Mod
        den%=Mod
    return (num*pow(den,Mod-2,Mod))%Mod

A=nCmMOD(n,a,mod)
B=nCmMOD(n,b,mod)
#print(A,B)

def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2, (n - 1) // 2)%mod

An=pow_r(2,n)
print((An-1+mod*2-A-B)%mod)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7

def nCmMOD(A,B,Mod):
    num,den=1,1
    for i in range(B):
        num*=(A-i)
        den*=(i+1)
        num%=Mod
        den%=Mod
    return (num*pow(den,Mod-2,Mod))%Mod

A=nCmMOD(n,a,mod)
B=nCmMOD(n,b,mod)

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
An=power_func(2,n,mod)

print((An-1+mod*2-A-B)%mod)
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))

Fixed submission:
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def lcm(a,b):
    return(int((a*b / gcd(a,b))))
    
A,B=map(int,input().split())
print(lcm(A,B))
Buggy python submission (verdict: Runtime Error):
print(int(input()**2))


Fixed submission:
print(int(input())**2)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N=int(input())
L=list(map(int,input().split()))
L.sort()

ans=0

def find_gt(a,x):
    i = bisect.bisect_right(a,x)
    if i != len(a):
        return i
    return(-1)

for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        l=L[:j]
        if len(l)>=1:
            num=find_gt(l,L[i]-L[j])
            if num!=-1:
                ans+=len(l)-num
        else:
            continue


print(ans)

Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))
L.sort()
count=0

for i in range(N):
    for j in range(i+1,N):
        T=bisect.bisect_left(L,L[i]+L[j])
        count+=T-j-1
print(count)

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

ans=0
for i in range(N):
    for j in range(i+1,N):
#        print([L[i],L[j],abs(L[i]-L[j])+1,L[i]+L[j]-1])
        for k in range(j+1,N):
            if abs(L[i]-L[j])+1<=L[k] and L[k]<=L[i]+L[j]-1:
#                print(L[i],L[j],L[k])
                ans+=1

print(ans)


Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))
L.sort()
count=0

for i in range(N):
    for j in range(i+1,N):
        T=bisect.bisect_left(L,L[i]+L[j])
        count+=T-j-1
print(count)