Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
hl=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
    t=[]
    for j in range(1,min(i+1,k+1)):
        t.append(dp[i-j]+abs(hl[i-j]-hl[i]))
    dp.append(min(t))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
hl=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
    t=[]
    for j in range(1,min(i+1,k+1)):
        t.append(dp[i-j]+abs(hl[i-j]-hl[i]))
    dp.append(min(t))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(W+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
l1=len(s)
l2=len(t)
dp=[[0 for _ in range(l1)] for _ in range(l2)]
flg=False
for i in range(l1):
    if flg or t[0]==s[i]:
        flg=True
        dp[0][i]=1
flg=False
for i in range(l2):
    if flg or s[0]==t[i]:
        flg=True
        dp[i][0]=1
for i in range(1,l2):
    for j in range(1,l1):
        if t[i]==s[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=''
i=l2-1
j=l1-1
while i>=0 and j>=0:
    if s[j]==t[i]:
        ans+=s[j]
        i-=1
        j-=1
    else:
        if i==0:
            j-=1
        elif j==0:
            i-=1
        elif dp[i-1][j]>dp[i][j-1]:
            i-=1
        else:
            j-=1
print(ans[::-1])

Fixed submission:
s=input()
t=input()
l1=len(s)
l2=len(t)
dp=[[0 for _ in range(l1)] for _ in range(l2)]
flg=False
for i in range(l1):
    if flg or t[0]==s[i]:
        flg=True
        dp[0][i]=1
flg=False
for i in range(l2):
    if flg or s[0]==t[i]:
        flg=True
        dp[i][0]=1
for i in range(1,l2):
    for j in range(1,l1):
        if t[i]==s[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=''
i=l2-1
j=l1-1
while i>=0 and j>=0:
    if s[j]==t[i]:
        ans+=s[j]
        i-=1
        j-=1
    else:
        if i==0:
            j-=1
        elif j==0:
            i-=1
        elif dp[i-1][j]>dp[i][j-1]:
            i-=1
        else:
            j-=1
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
p=list(map(float,input().split()))
dp=[[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(N):
        dp[i+1][j]+=dp[i][j]*(1-p[i])
        dp[i+1][j+1]+=dp[i][j]*p[i]
print(sum(dp[-1][N//2+1:]))

Fixed submission:
N=int(input())
p=list(map(float,input().split()))
dp=[[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(N):
        dp[i+1][j]+=dp[i][j]*(1-p[i])
        dp[i+1][j+1]+=dp[i][j]*p[i]
print(sum(dp[-1][N//2+1:]))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
pl=[[] for i in range(n)]
cl=[]
for i in range(m):
    p,y=list(map(int,input().split()))
    cl+=[[p,y]]
    bisect.insort(pl[p-1],y)
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Fixed submission:
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
pl=[[] for i in range(n)]
cl=[]
for i in range(m):
    p,y=list(map(int,input().split()))
    cl+=[[p,y]]
    pl[p-1].append(y)
for i in range(n):
    pl[i].sort()
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Fixed submission:
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
cl=[list(map(int,input().split())) for i in range(m)]
pl=[[] for i in range(n)]
for p,y in cl:
    pl[p-1].append(y)
for i in range(n):
    pl[i].sort()
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Fixed submission:
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
cl=[list(map(int,input().split())) for i in range(m)]
pl=[[] for i in range(n)]
for p,y in cl:
    bisect.insort(pl[p-1],y)
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Fixed submission:
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
s=input()
k=input()
if s[0]=='1' or len(s)==1:
    print(s[1])
else:
    for i in s:
        if int(i)>1:
            print(i)

Fixed submission:
s=input()
k=int(input())
for i in range(min(len(s),k)):
    if int(s[i])>1:
            print(s[i])
            exit()
print(1)

Buggy python submission (verdict: Runtime Error):
s=input()
k=input()
if s[0]=='1':
    print(s[1])
else:
    print(s[0])

Fixed submission:
s=input()
k=int(input())
for i in range(min(len(s),k)):
    if int(s[i])>1:
            print(s[i])
            exit()
print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    ans+=sum(x<b[i] for x in a)*sum(y>b[i] for y in c)
print(ans)

Fixed submission:
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        t1=n*i*j
        t2=4*i*j-n*i-n*j
        if t2>0:
            k,m=divmod(t1,t2)
            if k>0 and m==0:
                print(i,j,k)
                exit()

Fixed submission:
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        t1=n*i*j
        t2=4*i*j-n*i-n*j
        if t2>0:
            k,m=divmod(t1,t2)
            if k>0 and m==0:
                print(i,j,k)
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ansl=[]
for i in range(n):
    a=int(input())
    if a in ansl:
        ansl.remove(a)
    else:
        ansl.append(a)
print(len(ansl))

Fixed submission:
n=int(input())
ansl=set([])
for i in range(n):
    a=int(input())
    if a in ansl:
        ansl.remove(a)
    else:
        ansl.add(a)
print(len(ansl))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
al=list(map(int,input().split()))
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,al.count(a)+al.count(a+1)+al.count(a-1))
print(ans)

Fixed submission:
import bisect
n=int(input())
al=list(map(int,input().split()))
al.sort()
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,bisect.bisect_right(al,a+1)-bisect.bisect_left(al,a-1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
al=list(map(int,input().split()))
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,al.count(a)+al.count(a+1)+al.count(a-1))
print(ans)

Fixed submission:
import bisect
n=int(input())
al=list(map(int,input().split()))
al.sort()
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,bisect.bisect_right(al,a+1)-bisect.bisect_left(al,a-1))
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
pl=list(map(int,input().split()))
ans=0
for i in range(n):
    if pl[i]==i+1:
        ans+=1
        pl[i+1]=pl[i]
print(ans)

Fixed submission:
n=int(input())
pl=list(map(int,input().split()))
ans=0
for i in range(n):
    if pl[i]==i+1:
        ans+=1
        if i<n-1:
            pl[i+1]=pl[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
n=int(input())
al=list(map(int,input().split()))
tl=al[:]
for i in range(1,n):
    tl[i]=(tl[i-1]+tl[i])
ta=bisect.bisect_left(tl,tl[-1]/2)
print(abs(al[ta+1]-al[ta]))

Fixed submission:
n=int(input())
al=list(map(int,input().split()))
sm=sum(al)
t=0
ans=10**15
for i in range(n-1):
    t+=al[i]
    ans=min(ans,abs(sm-t*2))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in a:
    ans.append(i)
    ans=ans[::-1]
print(*ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a1=[]
for i in range(n-1,-1,-2):
    a1.append(a[i])
a2=[]
for i in range(n-2,-1,-2):
    a2.append(a[i])
a2.reverse()
a1+=a2
print(*a1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
mod=10**9+7
ans=1
for i in range(1,n+1):
    ans*=i
print(ans%mod)

Fixed submission:
n=int(input())
mod=10**9+7
ans=1
for i in range(1,n+1):
    ans=ans*i%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
print(s.replace(',',' ')

Fixed submission:
s=input()
print(s.replace(',',' '))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a=map(int,input().split())
x=list(map(int,input().split()))
pd=list(itertools.product(range(2),repeat=n))
pd=pd[1:]
ans=0
for l in pd:
    c=0
    s=0
    for i in range(n):
        if l[i]==1:
            c+=1
            s+=x[i]
    if s/c==a:
        ans+=1
print(ans)

Fixed submission:
n,a=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0]*(n*50+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(j*50+1):
            if k<x[i-1]:
                dp[i][j][k]=dp[i-1][j][k]
            else:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
ans=0
for i in range(1,n+1):
    ans+=dp[-1][i][i*a]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def main():
    n = int(input())
    a = list(map(int, input().split()))
    sum = 0
    mod = 1000000007
    for i in range(n-1):
        for j in range(i+1, n):
            sum += a[i]*a[j]
    print(sum%mod)

if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
from itertools import accumulate
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = (accumulate(reversed(a)))
    a_sum = list(reversed(list(a_sum)))
    sum = 0
    mod = 1000000007
    for i in range(n-1):
        sum += a[i]*a_sum[i+1]
    print(sum%mod)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

# 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

def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    # if is_prime(k):
    #     print(k-1)
    sevens = 0
    for i in range(k):
        sevens = sevens*10+7
        if sevens%k == 0:
            print(i+1)
            return
    print(k-1)

def main2():
    print(777777777%9)
        
if __name__ == '__main__':
    main()

Fixed submission:
k=int(input())
rm=7%k
an=-1
for i in range(10**6):
	if rm==0:
		an=i+1;break
	rm=(rm*10+7)%k
print(an)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    ans = A.pop(0)
    for i in range(N - 2):
        if i%2 == 0:
            x = A.pop(0)
        ans += x
    print(ans)
            
if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque
def main():
    N = int(input())
    A = deque(sorted(list(map(int, input().split()))))
    ans = A.pop()
    for i in range(N - 2):
        if i%2 == 0:
            x = A.pop()
        ans += x
    print(ans)
            
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a = A[0]
    A2 = [a]
    b = B[0]
    B2 = [b]
    for i in range(1, n):
        a += A[i]
        A2.append(a)

    for i in range(1, m):
        b += B[i]
        B2.append(b)
    max = -2
    for ia, aa in enumerate(A2):
        for ib, bb in enumerate(B2):
            if aa + bb > k:
                break
            if ia + ib > max:

                max = ia + ib
    print(max + 2)


def answer():
    N, M, K = map(int, input().split())


    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
        for i in range(M):
            b.append(b[i] + B[i])

        ans, j = 0, M
        for i in range(N + 1):
        if a[i] > K:
        break
        while b[j] > K - a[i]:
        j -= 1
        ans = max(ans, i + j)
        print(ans)
if __name__ == '__main__':
    answer()

Fixed submission:
# -*- coding: utf-8 -*-


# def main():
#     n, m, k = map(int, input().split())
#     A = list(map(int, input().split()))
#     B = list(map(int, input().split()))
#     a = A[0]
#     A2 = [a]
#     b = B[0]
#     B2 = [b]
#     for i in range(1, n):
#         a += A[i]
#         A2.append(a)
# 
#     for i in range(1, m):
#         b += B[i]
#         B2.append(b)
#     max = -2
#     for ia, aa in enumerate(A2):
#         for ib, bb in enumerate(B2):
#             if aa + bb > k:
#                 break
#             if ia + ib > max:
# 
#                 max = ia + ib
#     print(max + 2)
# 

def answer():
    N, M, K = map(int, input().split())


    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)
if __name__ == '__main__':
    answer()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    prod = 1
    for i in a:
        prod *= i
        if prod > 1000000000000000000:
            print(-1)
            return
main()

Fixed submission:
a, b = map(int, input().split(' '))
print(a*b)

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

Fixed submission:
a, b = map(int, input().split(' '))
print(a*b)

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

Fixed submission:
a, b = map(int, input().split(' '))
print(a*b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1
nums = map(int, input().split(' '))
for i in nums:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
a, b = map(int, input().split(' '))
print(a*b)
Buggy python submission (verdict: Runtime Error):
def main ():
N = int(input())
A = list(map(int,input(). split ()))
if 0 in A:
    print(0)
    return
prod = 1
for a in A:
    prod *= a
    if prod > 1000000000000000000:
        print(-1)
        åçreturn
print(prod)
main ()

Fixed submission:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    prod = 1
    for i in a:
        prod *= i
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    keihin_list = []
    for i in range(n):
        s = input()
        if not s in keihin_list:
            keihin_list.append(s)
    print(len(keihin_list))

if __name__ == "__main__":
    main()

Fixed submission:
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    keihin_list = []
    for i in range(n):
        s = input()
        keihin_list.append(s)
    print(len(set(keihin_list)))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
top = 0
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                s = x.split()[2] + s
            else:
                s = s + x.split()[2]
        else:
            if top == 1:
                s = x.split()[2] + s
            else:
                s = s + x.split()[2]
if top == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
s = input()
n = int(input())
top = 0
llist = ""
rlist = ""
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
        else:
            if top == 1:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
if top == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
for i in range(n):
    x = input()
    if x == "1":
        s = s[::-1]
    else:
        if x.split()[1] == '1':
            s = x.split()[2] + s
        else:
            s = s + x.split()[2]
print(s)


Fixed submission:
s = input()
n = int(input())
top = 0
llist = ""
rlist = ""
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
        else:
            if top == 1:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
if top == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sum = 0
for i in range(1, n):
    sum += i
print(sum)

Fixed submission:
n = int(input())
ans = int((n*(n-1))//2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split(' ')))
for i in range(n-1):
    for j in range(i+1, n):
        if x[i] - x[j] >= 2:
            print('No')
            exit()

print('Yes')

Fixed submission:
n = int(input())
x = list(map(int, input().split(' ')))
now = 0
for i in range(n):
    if now < x[i]:
        now = x[i] - 1
    if now > x[i]:
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Runtime Error):
l = input()
n = int(l)
l = input()
a = list(map(int, input().split(' ')))

if max(a) < sum(a)-max(a):
  print('Yes')
else:
  print('No')


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

if max(a) < sum(a)-max(a):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def main():
    n, w = map(int, input().split())
    weight_list = []
    value_list = []
    wv_list = []
    for i in range(n):
        weight, value = map(int, input().split())
        weight_list.append(weight)
        value_list.append(value)
    
    dp = [[0] * (w+1) for i in range(n)]
    for i in range(w+1):
        if weight_list[0] <= i:
            dp[0][i] = value_list[0]
    for i in range(1, n):
        for j in range(0, w+1):
            if weight_list[i] <= j:
                # print(dp[i-1][j-weight_list[i]]+value_list[i])
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight_list[i]] + value_list[i])
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[-1][-1])
if __name__ == "__main__":
    main()

Fixed submission:
# -*- coding: utf-8 -*-
def main():
    n, w = map(int, input().split())
    weight_list = []
    value_list = []
    wv_list = []
    for i in range(n):
        weight, value = map(int, input().split())
        weight_list.append(weight)
        value_list.append(value)
    
    dp = [[0] * (w+1) for i in range(n)]
    for i in range(w+1):
        if weight_list[0] <= i:
            dp[0][i] = value_list[0]
    for i in range(1, n):
        for j in range(0, w+1):
            if weight_list[i] <= j:
                # print(dp[i-1][j-weight_list[i]]+value_list[i])
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight_list[i]] + value_list[i])
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[-1][-1])
if __name__ == "__main__":
    main()