Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
if k % 2 == 0:
    print(-1)
    exit()

ten = 1
now = 0
for i in range(10**7):
    x = (ten*7)%k
    now = (now+x)%k
    if now == 0:
        print(i+1)
        exit()
    ten = ten*10%k

Fixed submission:
k = int(input())
if k % 2 == 0:
    print(-1)
    exit()

ten = 1
now = 0
for i in range(10**8):
    x = (ten*7)%k
    now = (now+x)%k
    if now == 0:
        print(i+1)
        exit()
    ten = ten*10%k
print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

dp = [[-1]*100000 for i in range(n+1)]

dp[0][0] = 1000

for i in range(n):
    for j in range(100000):
        if dp[i][j] >= 0:
            x = dp[i][j]
            c = x//a[i]
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
            dp[i+1][j+c] = max(dp[i+1][j+c],x-a[i]*c)
            dp[i+1][0] = max(dp[i+1][0],x+a[i]*j)
print(max(dp[-1]))

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

count = [1000,0]
x = a[0]
for i in range(1,n):
    if a[i] > x:
        d = count[0]//x
        count = [count[0]-d*x, d+count[1]]
    else:
        count = [count[0]+count[1]*x,0]
    x = a[i]
if count[1]:
    count[0] += count[1]*x
print(count[0])

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

dp = [[-1]*100000 for i in range(n+1)]
dp[0][0] = 1000


for i in range(n):
    for j in range(99999):
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if dp[i+1][j] >= a[i]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]-a[i])
        
    for j in range(99999,0,-1):
        if dp[i+1][j] >= 0:
             dp[i+1][j-1] = max(dp[i+1][j-1],dp[i+1][j]+a[i])
print(max(dp[-1]))


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

count = [1000,0]
x = a[0]
for i in range(1,n):
    if a[i] > x:
        d = count[0]//x
        count = [count[0]-d*x, d+count[1]]
    else:
        count = [count[0]+count[1]*x,0]
    x = a[i]
if count[1]:
    count[0] += count[1]*x
print(count[0])

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

dp = [[-1]*1000 for i in range(n+1)]
dp[0][0] = 1000


for i in range(n):
    for j in range(1000):
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if dp[i+1][j] >= a[i]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]-a[i])
        
    for j in range(999,0,-1):
        if dp[i+1][j] >= 0:
             dp[i+1][j-1] = max(dp[i+1][j-1],dp[i+1][j]+a[i])
print(max(dp[-1]))


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

count = [1000,0]
x = a[0]
for i in range(1,n):
    if a[i] > x:
        d = count[0]//x
        count = [count[0]-d*x, d+count[1]]
    else:
        count = [count[0]+count[1]*x,0]
    x = a[i]
if count[1]:
    count[0] += count[1]*x
print(count[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(input())
c1 = x.count("1")+1
c2 = c1-2

now1 = 0
now2 = 0

for i in range(n):
    if x[-1-i] == "1":
        now1 += pow(2,i,c1)
        now2 += pow(2,i,c2)
        
    now1 %= c1
    now2 %= c2

for i in range(n):
    if x[i] == "1":
        #print(n-1-i)
        now = (now2-pow(2,n-1-i,c2))%c2
        #print(i,now,c2)
        count = 1
        while now > 0:
            q = bin(now)
            y = q.count("1")
            now %= y
            count += 1
        print(count)
    else:
        #print(n-1-i)
        now = (now1+pow(2,n-1-i,c1))%c1
        #print(i,now,c1)
        count = 1
        while now > 0:
            q = bin(now)
            y = q.count("1")
            now %= y
            count += 1
        print(count)


Fixed submission:
n = int(input())
x = list(input())
c1 = x.count("1")+1
c2 = c1-2

now1 = 0
now2 = 0

for i in range(n):
    if x[-1-i] == "1":
        now1 += pow(2,i,c1)
        if c2 != 0:
            now2 += pow(2,i,c2)
        
    now1 %= c1
    if c2 != 0:
        now2 %= c2

for i in range(n):
    if x[i] == "1":
        #print(n-1-i)
        if c2 == 0:
            print(0)
            continue
        now = (now2-pow(2,n-1-i,c2))%c2
        #print(i,now,c2)
        count = 1
        while now > 0:
            q = bin(now)
            y = q.count("1")
            now %= y
            count += 1
        print(count)
    else:
        #print(n-1-i)
        now = (now1+pow(2,n-1-i,c1))%c1
        #print(i,now,c1)
        count = 1
        while now > 0:
            q = bin(now)
            y = q.count("1")
            now %= y
            count += 1
        print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    if input() == "AC":
        ac += 1
    elif input() == "WA":
        wa += 1
    elif input() == "TLE":
        tle += 1
    elif input() == "RE":
        re += 1

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

Fixed submission:
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s== "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
a.sort()
mi = []
pl = []
zero = 0
for i in a:
    if i < 0:
        mi.append(i)
    elif i == 0:
        zero += 1
    else:
        pl.append(i)

if n-zero < k:
    print(0)
    exit()
if mi == []:
    ans = 1
    count = 0
    while count < k:
        ans *= a[-1-count]
        ans %= mod
        count += 1
    print(ans)
    
    exit()
if pl == []:
    if k%2:
        if zero:
            print(0)
        else:
            ans = 1
            count = 0
            while count < k:
                ans *= a[-1-count]
                ans %= mod
                count += 1
            print(ans)
            
    else:
        ans = 1
        count = 0
        while count < k:
            ans *= a[count]
            ans %= mod
            count += 1
        print(ans)
        
    exit()

ans = 0
ip = 0
im = 0
if k%2:
    count = pl[-1]
    k -= 1
    ip += 1
else:
    count = 1
while k > 0:
    check1 = True
    check2 = True
    if ip+2 <= len(pl):
        x = pl[-1-ip]*pl[-2-ip]
        
    else:
        x = 1
        check1 = False
    if im+2 <= len(pl):
        y = mi[im]*mi[im+1]
    else:
        y = 1
        check2 = False
    if x >= y:
        if check1:
            ip += 2
        count = (x*count)%mod
    else:
        if check2:
            im += 2
        count = (y*count)%mod
    if check1 == False and check2 == False:
        break
    k -= 2
if k:
    print(0)
else:
    print(count%mod)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
a.sort()
mi = []
pl = []
if n == k:
    ans = 1
    for i in a:
        ans *= i
        ans %= mod
    print(ans)
    exit()
for i in a:
    if i < 0:
        mi.append(i)
    else:
        pl.append(i)
if pl == []:
    ans = 1
    count = 0
    if k%2:
        while count < k:
            ans *= a[-1-count]
            ans %= mod
            count += 1
    else:
        while count < k:
            ans *= a[count]
            ans %= mod
            count += 1
    print(ans)    
    exit()
pl = sorted(pl,reverse=True)
ip = 0
im = 0
if k%2:
    count = pl[0]
    k -= 1
    ip += 1
else:
    count = 1
while k > 0:
    check1 = True
    check2 = True
    if ip+2 <= len(pl):
        x = pl[ip]*pl[ip+1]    
    else:
        x = 1
        check1 = False
    if im+2 <= len(mi):
        y = mi[im]*mi[im+1]
    else:
        y = 1
        check2 = False
    if x > y or (check1 and not check2):
        ip += 2
        count = (x*count)%mod
    else:
        if check2:
            im += 2
            count = (y*count)%mod
    if check1 == False and check2 == False:
        break
    k -= 2

print(count%mod)
Buggy python submission (verdict: Time Limit Exceeded):
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
t = [int(input()) for i in range(d)]
now = [0]*26

score = [[0] for i in range(26)]
for i in range(d):
    
    now[t[i]-1] = i+1
    ind = t[i]-1
    for j in range(26):
        if j == ind:
            score[j].append(s[i][ind]+score[j][-1])
        else:
            x = (i+1-now[j])*c[j]
            score[j].append(-x+score[j][-1])
m = int(input())
l = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    x,y = l[i]
    be = t[x-1]
    be -= 1
    now = 0
    t[x-1] = y
    y -= 1
    count = [0]
    for j in range(d):
        if be == t[j]-1:
            now = j+1
            count.append(s[j][be]+count[-1])
        else:
            count.append(-(j+1-now)*c[be]+count[-1])
    score[be] = count
    count = [0]
    now = 0
    for j in range(d):
        if y == t[j]-1:
            now = j+1
            count.append(s[j][y]+count[-1])
        else:
            count.append(-(j+1-now)*c[y]+count[-1])
    score[y] = count

    ans = 0
    for i in range(26):
        ans += score[i][-1]
    print(ans)
        


    


Fixed submission:
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
t = [int(input()) for i in range(d)]
now = [0]*26

score = [0]*26
for i in range(d):
    
    now[t[i]-1] = i+1
    ind = t[i]-1
    for j in range(26):
        if j == ind:
            score[j] += s[i][ind]
        else:
            x = (i+1-now[j])*c[j]
            score[j]-= x
m = int(input())
l = [list(map(int,input().split())) for i in range(m)]
ans = sum(score)
for i in range(m):
    x,y = l[i]
    be = t[x-1]
    be -= 1
    now1 =  0
    now2 = 0
    t[x-1] = y
    y -= 1
    count1 = 0
    count2 = 0
    for j in range(d):
        if be == t[j]-1:
            now1 = j+1
            count1 +=s[j][be]
        else:
            count1 -= (j+1-now1)*c[be]
        if y == t[j]-1:
            now2 = j+1
            count2 +=s[j][y]
        else:
            count2 -= (j+1-now2)*c[y]

    ans += count1+count2-score[be]-score[y]
    print(ans)
    score[be] = count1
    score[y] = count2
Buggy python submission (verdict: Runtime Error):
import decimal
a,b = input().split()

b = decimal(b)

ans = a*b
print(int(ans))



Fixed submission:
from decimal  import *
a,b = input().split()

b = Decimal(b)
a = Decimal(a)
ans = a*b
print(int(ans))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = set()
for i in range(k):
    d = int(input())
    l = list(map(int,input().split()))
    for i in l:
        s.add(i)
print(n-len(s))

Fixed submission:
s = input()
print("ARC" if s == "ABC" else "ABC")
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import heapq
    
    def dijkstra(graph,start,cd,MAX,s):
        dist = [[float("inf")]*MAX for _ in range(n)]
        q = []
        
        c,d = cd[start]
        for i in range(MAX):
            if c*i+s < MAX:
                dist[start][c*i+s] = d*i
                heapq.heappush(q, (d*i,start,s+c*i))
            else:
                break
        while q:
            cost, cur_node,coin = heapq.heappop(q)
            
            if dist[cur_node][coin] < cost:
                continue
            
            for nex_node,nex_cost,nex_time  in graph[cur_node]:
                if coin >= nex_cost and dist[nex_node][coin-nex_cost] > cost+nex_time:
                    now_coin = coin - nex_cost
                    now_cost = cost+nex_time
                    c,d = cd[nex_node]
                    for i in range(MAX):
                        if c*i+now_coin < MAX:
                            if dist[nex_node][c*i+now_coin] > d*i+now_cost:
                                dist[nex_node][c*i+now_coin] = d*i+now_cost
                                heapq.heappush(q, (d*i+now_cost,nex_node,now_coin+c*i))
                        else:
                            break
                    
        for i in dist[1:]:
            print(min(i))
    n,m,s = map(int,input().split())
    E = [[] for i in range(n)]
    la = []
    for i in range(m):
        u,v,a,b = map(int,input().split())
        u -= 1
        v-= 1
        la.append(a)
        E[u].append((v,a,b))
        E[v].append((u,a,b))

    cd = [list(map(int,input().split())) for i in range(n)]

    dijkstra(E,0,cd,2501,min(s,2500))
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    import heapq
    
    def dijkstra(graph,start,cd,s):
        dist = [[float("inf")]*2505 for _ in range(n)]
        q = []
        dist[start][s] = 0
        heapq.heappush(q, (0,start,s))
        
        while q:
            cost, cur_node,coin = heapq.heappop(q)
            
            if dist[cur_node][coin] < cost:
                continue
            
            for nex_node,nex_cost,nex_time  in graph[cur_node]:
                if coin >= nex_cost and dist[nex_node][coin-nex_cost] > cost+nex_time:
                    dist[nex_node][coin-nex_cost] = cost+nex_time
                    heapq.heappush(q, (cost+nex_time,nex_node,coin-nex_cost))
            if dist[cur_node][min(2500,coin+cd[cur_node][0])] > cost+cd[cur_node][1]:
                 dist[cur_node][min(2500,coin+cd[cur_node][0])] = cost+cd[cur_node][1]
                 heapq.heappush(q,(cost+cd[cur_node][1],cur_node,min(2500,coin+cd[cur_node][0])))
                    
        for i in dist[1:]:
            print(min(i))
    n,m,s = map(int,input().split())
    E = [[] for i in range(n)]
    la = []
    for i in range(m):
        u,v,a,b = map(int,input().split())
        u -= 1
        v-= 1
        la.append(a)
        E[u].append((v,a,b))
        E[v].append((u,a,b))

    cd = [list(map(int,input().split())) for i in range(n)]

    dijkstra(E,0,cd,min(s,2500))
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
           
            ans +=math.gcd(math.gcd(i,j),m)

print(ans)

Fixed submission:
import math
k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
           
            ans +=math.gcd(math.gcd(i,j),m)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    dp = [[-float("INF")]*(n//2+1) for i in range(n+1)]
    dp[0][0] = 0
    dp[1][0] = 0
    dp[1][1] = l[0]
    for i in range(1,n):
        for j in range(max(0,i//2-1),min(i//2+2,n//2+1)):
            dp[i+1][j] = max(dp[i][j],dp[i-1][j-1]+l[i])
    print(dp[-1][-1])

if __name__ == "__main__":
    main()

Fixed submission:
n = int(input())
def main():
    import sys
    input = sys.stdin.readline
    l = list(map(int,input().split()))
    dp = [[-float("INF")]*(3) for i in range(n+1)]
    dp[0][0] = 0
    dp[1][-1] = 0
    dp[1][1] = l[0]
    for i in range(1,n):
        
        dp[i+1][-1] = max(dp[i][0],dp[i-1][-1]+l[i])
        dp[i+1][0] = max(dp[i][1],dp[i-1][0]+l[i])
        dp[i+1][1] = dp[i-1][1]+l[i]
    print(max(dp[-1][0],dp[-1][-1]))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
dp = [[-float("INF")]*(n//2+1) for i in range(n+1)]
dp[0][0] = 0
dp[1][0] = 0
dp[1][1] = l[0]
for i in range(1,n):
    for j in range(max(0,i//2-2),min(i//2+2,n//2+1)):
        dp[i+1][j] = max(dp[i][j],dp[i-1][j-1]+l[i])
print(dp[-1][-1])



Fixed submission:
n = int(input())
def main():
    import sys
    input = sys.stdin.readline
    l = list(map(int,input().split()))
    dp = [[-float("INF")]*(3) for i in range(n+1)]
    dp[0][0] = 0
    dp[1][-1] = 0
    dp[1][1] = l[0]
    for i in range(1,n):
        
        dp[i+1][-1] = max(dp[i][0],dp[i-1][-1]+l[i])
        dp[i+1][0] = max(dp[i][1],dp[i-1][0]+l[i])
        dp[i+1][1] = dp[i-1][1]+l[i]
    print(max(dp[-1][0],dp[-1][-1]))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import numpy as np
    h,w,k = map(int,input().split())
    l = [list(input()) for i in range(h)]

    def check(lis):
        lis.append(h)
        num = [0]*(len(lis))
        ans = 0
        for i in range(w):
            ch = 0
            num2 = [0]*(len(lis))
            for j in range(h):
                
                if l[j][i] == "1":
                    if j <= lis[ch]:
                        num2[ch] += 1
                    else:
                        ch += 1
                        num2[ch] += 1
            if max(num2) > k:
                return float("INF")
            else:
                for i in range(len(num)):
                    num[i] += num2[i]
                    if num[i] > k:
                        ans += 1
                        num = num2
                        break 
            
            
        return ans

    ans = 10**9

    for i in range(2**(h-1)):
        count = 0
        lis1 = []
        for j in range(h-1):
            if (i >> j) & 1:
                lis1.append(j)
                count += 1
        
        ans = min(ans,count+check(lis1))
        
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
n,m = map(int,input().split())
print(n*(n-1)//2+m*(m-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,s = map(int,input().split())
    A = list(map(int,input().split()))
    dp = [[[] for j in range(s+1)] for i in range(n+1)]

    mod = 998244353

    ans = 0

    dp[0][0] = [1]

    for i in range(n):
        for j in range(s):
            if j == 0:
                if A[i] <= s:
                    dp[i+1][A[i]].append(i)
            elif dp[i][j]:
                dp[i+1][j] += dp[i][j]
                if A[i]+j <= s:
                    dp[i+1][j+A[i]] = dp[i][j]
        if dp[i+1][s]:
            for num in dp[i+1][s]:
                ans += ((num+1)*(n-i))%mod
                ans %= mod
            dp[i+1][s] = []

    print(ans%mod)
if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
n,s = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
ans = 0
dp = np.zeros(s+1,np.int64)
for i in A:
    dp[0] += 1
    dp[i:] += dp[:-i].copy()
    dp %= mod
    ans += dp[-1]
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w = map(int,input().split())
l = [list(input()) for i in range(h)]

dp = [[[-1]*(h*w) for i in range(w)] for i in range(h)]
q = deque([])
if l[0][0] == ".":
    q.append((0,0,0,"."))
else:
    q.append((0,0,1,"#"))
dx = [0,1]
dy = [1,0]
while q:
    
    bx,by,num,bef = q.popleft()
    for j in range(2):
        nx = bx+dx[j]
        ny = by+dy[j]
        if nx < h and ny < w:
            if bef == "." and l[nx][ny] == "#":
                if dp[nx][ny][num+1] == -1:
                
                    dp[nx][ny][num+1] = 1
                    q.append((nx,ny,num+1,l[nx][ny]))
            elif dp[nx][ny][num] == -1:
                dp[nx][ny][num] = 1
                q.append((nx,ny,num,l[nx][ny]))

print(dp[-1][-1].index(1))
              



Fixed submission:
def main():
    from collections import deque
    h,w = map(int,input().split())
    l = [list(input()) for i in range(h)]

    dp = [[[-1]*(h*w) for i in range(w)] for i in range(h)]
    q = deque([])
    if l[0][0] == ".":
        q.append((0,0,0,"."))
    else:
        q.append((0,0,1,"#"))
    dx = [0,1]
    dy = [1,0]
    while q:
        
        bx,by,num,bef = q.popleft()
        for j in range(2):
            nx = bx+dx[j]
            ny = by+dy[j]
            if nx < h and ny < w:
                if bef == "." and l[nx][ny] == "#":
                    if dp[nx][ny][num+1] == -1:
                    
                        dp[nx][ny][num+1] = 1
                        q.append((nx,ny,num+1,l[nx][ny]))
                elif dp[nx][ny][num] == -1:
                    dp[nx][ny][num] = 1
                    q.append((nx,ny,num,l[nx][ny]))

    print(dp[-1][-1].index(1))
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
l = ["a","b","c","d","e","f","g","i","j","k"]
n = int(input())
ans = [[] for i in range(n)]
ans[0].append("a")

for i in range(1,n):
    for j in ans[i-1]:
        for k in range(ord(j[-1])-ord("a")+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()
for i in count:
    print(i)

Fixed submission:
l = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"]
n = int(input())
ans = [[] for i in range(n)]
ans[0].append("a")

for i in range(1,n):
    
    for j in ans[i-1]:
        a = 0
        for k in j:
            a = max(a,ord(k)-ord("a"))
        for k in range(a+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()
for i in count:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        s = s[::-1]
    else:
        if a[1] == "1":
            s.insert(0,a[2])
        else:
            s.append(a[2])
print(*s,sep="")


Fixed submission:
from collections import deque
s = list(input())
ans = deque(s)
q = int(input())
check = 1
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        check *= -1
    else:
        if a[1] == "1":
            if check == 1:
                ans.appendleft(a[2])
            else:
                ans.append(a[2])
        else:
            if check == 1:
                ans.append(a[2])
            else:
                ans.appendleft(a[2])
    
ans = list(ans)
if check==1:
    print(*ans,sep="")
else:
    ans = ans[::-1]
    print(*ans,sep="")

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        s = s[::-1]
    else:
        if a[1] == "1":
            s.insert(0,a[2])
        else:
            s.append(a[2])
print(*s,sep="")


Fixed submission:
from collections import deque
s = list(input())
ans = deque(s)
q = int(input())
check = 1
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        check *= -1
    else:
        if a[1] == "1":
            if check == 1:
                ans.appendleft(a[2])
            else:
                ans.append(a[2])
        else:
            if check == 1:
                ans.append(a[2])
            else:
                ans.appendleft(a[2])
    
ans = list(ans)
if check==1:
    print(*ans,sep="")
else:
    ans = ans[::-1]
    print(*ans,sep="")