Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input().split()
n = int(s[3])
l1=[1]*int(s[0])
l2=[0]*int(s[1])
l3=[-1]*int(s[2])
l=l1+l2+l3
sum_=0
i=0
while i < n:
    sum_+=l[i]

    i += 1
print(sum_)

Fixed submission:
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)

Buggy python submission (verdict: Runtime Error):
s = input().split()
n = int(s[3])

l1=[1]*int(s[0])
l2=[0]*int(s[1])
l3=[-1]*int(s[2])
l=l1+l2+l3
sum_=0
i=0
while i < n:
    sum_+=l[i]

    i += 1
print(sum_)

Fixed submission:
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)
Buggy python submission (verdict: Runtime Error):
s = input()

l=2s*3.14

print(l)

Fixed submission:
import math

s=float(input())

l=float(2*s)*math.pi
print(l)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Ans = "YES"
List = []

for e in A:
    if e in List:
        Ans = "NO"
        break
    else:
        List.append(e)

print(Ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
Ans = "YES"
List = []
before_n = 0
for e in A:
    if e == before_n:
        Ans = "NO"
        break
    else:
        before_n=e
print(Ans)
Buggy python submission (verdict: Runtime Error):
4 2000

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

t = N*500
if t >= K:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros(w+1)

for w, v in wv:
    dp[w:] = np.maximum(dp[:-w]+v,dp[w:])
print(int(dp[-1]))

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

opt = [0] * len(h)
opt[1] = abs(h[0]-h[1])

for i in range(2,len(h)):
    A = opt[i-1] + abs(h[i-1] - h[i])
    B = opt[i-2] + abs(h[i-2] - h[i])
    opt[i] = min(A, B)
print(opt[-1])
Buggy python submission (verdict: Runtime Error):
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[0]*(n)
  
for i in range(1,k+1):
  dp[i]=abs(h[0]-h[i])
 
for i in range(k,n):
  li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
  dp[i]=min(li)
  
print(dp[-1])

Fixed submission:
n,k=map(int, input().split())
h=list(map(int,input().split()))
dp=[0]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
  
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])
 
for i in range(k,n):
  li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
  dp[i]=min(li)
  
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
import pandas as pd

N = input() # 入力回数をNとして受け取る
n = N.split(" ")
col = int(n[1])
rows = int(n[0])
s = [input() for i in range(rows)] # 複数行の数値の入力を取得
arr_1d = np.array(s)
arr_2 = []
for el in arr_1d:
    chars = [char for char in el ]
    arr_2.append(chars)

arr_2 = np.array(arr_2)
df = pd.DataFrame(arr_2.reshape(rows,col))
df2 = df.replace(["."], np.nan)
df2=df2.dropna(how='all').dropna(how='all', axis=1)
df2=df2.fillna(".")
# print(df2.values)
for a in df2.values:
    print(''.join(a))

Fixed submission:
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
 
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
 
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()
Buggy python submission (verdict: Runtime Error):
a = input()
a = 'ACL' * a
print(a)

Fixed submission:
word = 'ACL'
a = int(input())
word = word *a
print(word)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += a[i] * a[j]
print(ans % (10**9 + 7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = sum(a)
ans = 0
for i in range(n-1):
    ans += a[i] *(b-a[i])
    b = b - a[i]
print(ans % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input()))
count =0
for i in range(0, n, 2):
    if a[i] % 2 ==1:
        count+=1
print(count)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
count =0
for i in range(0, n, 2):
    if a[i] % 2 ==1:
        count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1 * j
    
    return table

a = sum(num_divisors_table(n))
print(a)

Fixed submission:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

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

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

a = num_divisors_table(n)
b = 0
for i in range(1, n+1):
    b += i * a[i]
print(b)

Fixed submission:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

Buggy python submission (verdict: Time Limit Exceeded):


n = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

count = 0
for i in range(1, n + 1):
    count += i * len(make_divisors(i))
print(count)

Fixed submission:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

Buggy python submission (verdict: Runtime Error):
import sympy

n = int(input())


count = 0
for i in range(1, n + 1):
    count += i * len(sympy.divisors(i))
print(count)

Fixed submission:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))

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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    divisors.sort()
    return divisors

count = 0
for i in range(1, n + 1):
    count += i * len(make_divisors(i))
    
print(count)

Fixed submission:
n = int(input())
def div(n):
    a = 0
    for i in range(1, n+1):
        y = int(n/i)
        a += y* (y+1)*i/2
    return int(a)
print(div(n))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

count = 1
for i in range(n):
    count *= a[i]
if count > 10 ** 18:
    print(-1)
else:
    print(count)

Fixed submission:
n = int(input())

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

count = 1
if 0 in a:
    print(0)
else:

    for i in a:
        count *= i
        if count > 10 ** 18:
            print(-1)
            break
    if count <= 10 ** 18:
        print(count)

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

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

count = 1
for i in a:
    count *= i
if count > 10 ** 18:
    print(-1)
else:
    print(count)

Fixed submission:
n = int(input())

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

count = 1
if 0 in a:
    print(0)
else:

    for i in a:
        count *= i
        if count > 10 ** 18:
            print(-1)
            break
    if count <= 10 ** 18:
        print(count)

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

a = list(map(int, input().split()))
count = 1
for i in a:
    count *= i
if count > 10 ** 18:
    print(-1)
else:
    print(count)

Fixed submission:
n = int(input())

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

count = 1
if 0 in a:
    print(0)
else:

    for i in a:
        count *= i
        if count > 10 ** 18:
            print(-1)
            break
    if count <= 10 ** 18:
        print(count)
Buggy python submission (verdict: Runtime Error):

a = list(map(int, input().split()))
count = 1
for i in a:
    count *= i
if count > 10 ** 18:
    print(-1)
else:
    print(count)

Fixed submission:
import math
ab = input()
ab = list(ab.split())
a, b = int(ab[0]), ab[1]
b = b[0] + b[2] + b[3]
b = int(b)

print(a * b // 100)
Buggy python submission (verdict: Runtime Error):
T = input()
T = list(T)
que = T.count('?')

for i in range(que):
    a = T.index('?')
    if T[a - 1] == 'P':
        T[a] = 'D'
    elif T[a + 1] == 'D':
        T[a] = 'P'
    else:
        T[a] = 'D'
T = ''.join(T)
print(T)

Fixed submission:
T = list(input())
for i in range(len(T)):
    if T[i] == '?':
        T[i] = 'D'
T = ''.join(T)
print(T)
Buggy python submission (verdict: Runtime Error):
 = input()
 
A, B, C, K = map(int, a.split())
 
if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(- B - C +K)

Fixed submission:
a = input()
 
A, B, C, K = map(int, a.split())
 
if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(2 * A + B - K)

Buggy python submission (verdict: Runtime Error):
 = input()
 
A, B, C, K = map(int, a.split())
 
if A >= K:
  print(A)
elif A + B >= K > A:
  print(A)
else:
  print(- B - C +K)

Fixed submission:
a = input()
 
A, B, C, K = map(int, a.split())
 
if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(2 * A + B - K)
Buggy python submission (verdict: Runtime Error):
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(300000)
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}"
    def __setitem__(self,i,v):
        self.l[i]=v
N,Q=map(int,input().split())
g=uf(N)
for i in range(Q):
    t,u,v=map(int,input().split())
    if t:
        if g.sa(u,v):
            print(1)
        else:
            print(0)
    else:
        g.me(u,v)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(300000)
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}"
    def __setitem__(self,i,v):
        self.l[i]=v
N,Q=map(int,input().split())
g=uf(N)
for i in range(Q):
    t,u,v=map(int,input().split())
    if t:
        if g.sa(u,v):
            print(1)
        else:
            print(0)
    else:
        g.me(u,v)
Buggy python submission (verdict: Runtime Error):
D,T,S=map(int,input().spltit())
if D>T*S:
    print("No")
else:
    print("Yes")

Fixed submission:
d,t,s=map(int,input().split())
if s*t<d:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
N=int(input())
A=list(map(int,input().split()))
l=[0]*1000001
pr=[]
for i in range(2,1000001):
    if l[i]:
        continue
    pr.append(i)
    for j in range(i**2,1000001,i):
        l[j]=1
lp=len(pr)
l=[0]*lp
g=gcd(A[0],A[1])
for i in A:
    g=gcd(g,i)
if g>1:
    print("not coprime")
    exit()
for i in A:
    t=i
    for j in range(lp):
        pj=pr[j]
        if pj>t:
            break
        if t%pj==0:
            if l[j]:
                print("setwise coprime")
                exit()
            l[j]=1
            while 1:
                t//=pj
                if t%pj:
                    break
print("pairwise coprime")

Fixed submission:
from math import gcd
N=int(input())
A=list(map(int,input().split()))
g=gcd(A[0],A[1])
for i in A:
    g=gcd(g,i)
if g>1:
    print("not coprime")
    exit()
l=[0]*1000001
for i in A:
    l[i]+=1
for i in range(2,1000000):
    c=0
    for j in range(i,1000001,i):
        c+=l[j]
    if c>1:
        print("setwise coprime")
        break
else:
    print("pairwise coprime")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
cx,cy=map(lambda x: int(x)+1,input().split())
dx,dy=map(lambda x: int(x)+1,input().split())
S=["#"*(W+4)]*2+["##"+input()+"##" for i in range(H)]+["#"*(W+4)]*2
l=[[-2]*(W+4) for i in range(H+4)]
for i in range(2,H+2):
    for j in range(2,W+2):
        if S[i][j]==".":
            l[i][j]=-1
l[cx][cy]=0
b=[(cx,cy)]
bb=[(cx,cy)]
t=0
while bb:
    while b:
        a=[]
        for i in b:
            if l[i[0]+1][i[1]]==-1:
                l[i[0]+1][i[1]]=t
                a.append((i[0]+1,i[1]))
            if l[i[0]-1][i[1]]==-1:
                l[i[0]-1][i[1]]=t
                a.append((i[0]-1,i[1]))
            if l[i[0]][i[1]+1]==-1:
                l[i[0]][i[1]+1]=t
                a.append((i[0],i[1]+1))
            if l[i[0]][i[1]-1]==-1:
                l[i[0]][i[1]-1]=t
                a.append((i[0],i[1]-1))
        bb+=a
        b=a
    aa=[]
    t+=1
    b=[]
    for i in bb:
        for j in range(-2,3):
            for k in range(-2,3):
                if l[i[0]+j][i[1]+k]==-1:
                    l[i[0]+j][i[1]+k]=t
                    aa.append((i[0]+j,i[1]+k))
                    b.append((i[0]+j,i[1]+k))
    if l[dx][dy]>=0:
        break
    bb=aa
print(l[dx][dy])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
cx,cy=map(lambda x: int(x)+1,input().split())
dx,dy=map(lambda x: int(x)+1,input().split())
S=["#"*(W+4)]*2+["##"+input()+"##" for i in range(H)]+["#"*(W+4)]*2
l=[[-2]*(W+4) for i in range(H+4)]
for i in range(2,H+2):
    for j in range(2,W+2):
        if S[i][j]==".":
            l[i][j]=-1
l[cx][cy]=0
b=[(cx,cy)]
bb=[(cx,cy)]
t=0
while bb:
    while b:
        a=[]
        for i in b:
            if l[i[0]+1][i[1]]==-1:
                l[i[0]+1][i[1]]=t
                a.append((i[0]+1,i[1]))
            if l[i[0]-1][i[1]]==-1:
                l[i[0]-1][i[1]]=t
                a.append((i[0]-1,i[1]))
            if l[i[0]][i[1]+1]==-1:
                l[i[0]][i[1]+1]=t
                a.append((i[0],i[1]+1))
            if l[i[0]][i[1]-1]==-1:
                l[i[0]][i[1]-1]=t
                a.append((i[0],i[1]-1))
        bb+=a
        b=a
    aa=[]
    t+=1
    b=[]
    for i in bb:
        for j in range(-2,3):
            for k in range(-2,3):
                if l[i[0]+j][i[1]+k]==-1:
                    l[i[0]+j][i[1]+k]=t
                    aa.append((i[0]+j,i[1]+k))
                    b.append((i[0]+j,i[1]+k))
    if l[dx][dy]>=0:
        break
    bb=aa
print(l[dx][dy])
Buggy python submission (verdict: Runtime Error):
N=int(input())
X=input()
def fx(n,c):
    if c==0:
        return 0
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
lp=[1]*N
lm=[1]*N
for i in range(N-2,-1,-1):
    lp[i]=2*lp[i+1]%(c+1)
    lm[i]=2*lm[i+1]%(c-1)
np=n%(c+1)
if c>1:
    nm=n%(c-1)
else:
    nm=1
for i in range(N):
    if X[i]=="0":
        print(fx(np+lp[i],c+1))
    else:
        print(fx(nm-lm[i],c-1))

Fixed submission:
N=int(input())
X=input()
def fx(n,c):
    if c==0:
        return 0
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
lp=[1]*N
lm=[1]*N
for i in range(N-2,-1,-1):
    lp[i]=2*lp[i+1]%(c+1)
    if c==1:
        lm[i]=1
    else:
        lm[i]=2*lm[i+1]%(c-1)
np=n%(c+1)
if c>1:
    nm=n%(c-1)
else:
    nm=1
for i in range(N):
    if X[i]=="0":
        print(fx(np+lp[i],c+1))
    else:
        print(fx(nm-lm[i],c-1))

Buggy python submission (verdict: Runtime Error):
N=int(input())
X=input()
def fx(n,c):
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
for i in range(N):
    if X[i]=="0":
        print(fx(n+2**(N-i-1),c+1))
    else:
        print(fx(n-2**(N-i-1),c-1))

Fixed submission:
N=int(input())
X=input()
def fx(n,c):
    if c==0:
        return 0
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
lp=[1]*N
lm=[1]*N
for i in range(N-2,-1,-1):
    lp[i]=2*lp[i+1]%(c+1)
    if c==1:
        lm[i]=1
    else:
        lm[i]=2*lm[i+1]%(c-1)
np=n%(c+1)
if c>1:
    nm=n%(c-1)
else:
    nm=1
for i in range(N):
    if X[i]=="0":
        print(fx(np+lp[i],c+1))
    else:
        print(fx(nm-lm[i],c-1))

Buggy python submission (verdict: Runtime Error):
N=int(input())
X=input()
def fx(n):
    t=bin(n).count("1")
    b=n%t
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    return fx(b)+1
c=X.count("1")
n=int(X,2)
for i in range(N):
    if X[i]=="0":
        print(fx(n+2**(N-i-1)))
    else:
        print(fx(n-2**(N-i-1)))

Fixed submission:
N=int(input())
X=input()
def fx(n,c):
    if c==0:
        return 0
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
lp=[1]*N
lm=[1]*N
for i in range(N-2,-1,-1):
    lp[i]=2*lp[i+1]%(c+1)
    if c==1:
        lm[i]=1
    else:
        lm[i]=2*lm[i+1]%(c-1)
np=n%(c+1)
if c>1:
    nm=n%(c-1)
else:
    nm=1
for i in range(N):
    if X[i]=="0":
        print(fx(np+lp[i],c+1))
    else:
        print(fx(nm-lm[i],c-1))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S=input()
    a=0 
    b=[0]*2019
    l=[0]*2019
    for i in S:
        k=int(i)
        for j in range(2019):
            l[(j*10+k)%2019]=b[j]
        l[k]+=1
        a+=l[0]
        b=l.copy()
    print(a)
main()


Fixed submission:
S=input()
a=0
b=[0]*2019
No=[None]*2019
for i in S:
    l=No.copy()
    k=int(i)
    for j in range(2019):
        l[(j*10+k)%2019]=b[j]
    l[k]+=1
    a+=l[0]
    b=l
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
a=0
b=[0]*2019
for i in S:
    l=[None]*2019
    k=int(i)
    for j in range(2019):
        l[(j*10+k)%2019]=b[j]
    l[k]+=1
    a+=l[0]
    b=l
print(a)

Fixed submission:
S=input()
a=0
b=[0]*2019
No=[None]*2019
for i in S:
    l=No.copy()
    k=int(i)
    for j in range(2019):
        l[(j*10+k)%2019]=b[j]
    l[k]+=1
    a+=l[0]
    b=l
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=deque(input())
Q=int(input())
h=0
for i in range(Q):
    q=input().split()
    if q[0]=="1":
        h=1-h
    else:
        t=int(q[1])
        if t==h+1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
if h==0:
    for i in S:
        print(i,end="")
else:
    for i in range(len(S)):
        print(S[-i-1],end="")

Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
h=0
for i in range(Q):
    q=input().split()
    if q[0]=="1":
        h=1-h
    else:
        t=int(q[1])
        if t==h+1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
if h==0:
    for i in S:
        print(i,end="")
else:
    for i in range(len(S)):
        print(S[-i-1],end="")
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,N=map(int,input().split())
l=[1000000000]*(H+1)
l[0]=0
for i in range(N):
    A,B=map(int,input().split())
    for j in range(1,A+1):
        if l[j]>B:
            l[j]=B
    for j in range(H):
        if j+A<=H:
            if l[j]+B<l[j+A]:
                l[j+A]=l[j]+B
print(l[-1])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
H,N=map(int,input().split())
l=[1000000000]*(H+1)
l[0]=0
for i in range(N):
    A,B=map(int,input().split())
    for j in range(1,min(A+1,H+1)):
        if l[j]>B:
            l[j]=B
    for j in range(H):
        if j+A<=H:
            if l[j]+B<l[j+A]:
                l[j+A]=l[j]+B
print(l[-1])
Buggy python submission (verdict: Runtime Error):
N,K,S=map(int,input().split())
if S==10**9:
    print("1000000000 "*K+"1"*(N-K))
else:
    print(f"{S} "*K +"1000000000 "*(N-K))

Fixed submission:
N,K,S=map(int,input().split())
if S==10**9:
    l=[10**9]*K + [1]*(N-K)
    print(*l)
else:
    l=[S]*K+[10**9]*(N-K)
    print(*l)
Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
l=[2]
for j in range(3,100004):
    for i in l:
        if j%i==0:
            break
    else:
        if j>=X:
            t=j
            break
        l.append(j)
if X==2:
    t=2
print(t)


Fixed submission:
X=int(input())
l=[2]
t=3
while 1:
    for i in l:
        if t%i==0:
            break
    else:
        if t>=X:
            break
        l.append(t)
    t+=1
if X==2:
    t=2
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
l=[2]
t=3
while 1:
    for i in l:
        if t%i==0:
            break
    else:
        if t>=X:
            break
        l.append(t)
    t+=1
if X==2:
    t=2
print(t)


Fixed submission:
X=int(input())
l=[2]
t=3
while 1:
    for i in l:
        if t%i==0:
            break
    else:
        if t>=X:
            break
        l.append(t)
    t+=1
if X==2:
    t=2
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())
l=[2]
t=3
while 1:
    for i in l:
        if t%i==0:
            break
    else:
        if t>=X:
            break
        l.append(t)
    t+=1
if X==2:
    t=2
print(t)

Fixed submission:
X=int(input())
l=[2]
t=3
while 1:
    for i in l:
        if t%i==0:
            break
    else:
        if t>=X:
            break
        l.append(t)
    t+=1
if X==2:
    t=2
print(t)