Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split()) #Nマス Q呪文回数
s = input()
g_num = [1 for i in range(N)]

def sposi(t):
    s_list = []
    s_size = len(s)
    for ss in range(s_size):
        if s[ss]==t:
            s_list.append(ss)
    return s_list
  
for q in range(Q):
    t,d = map(str,input().split())
    s_posi = sposi(t)
    for k in s_posi:
      	if g_num[k]!=0:
            if k==0 and d=='L':
                g_num[k]-=1
            elif (k==N-1 or k==-1) and d=='R':
                g_num[k]-=1
            elif d=='L':
                g_num[k]-=1
                g_num[k-1]+=1
            elif d=='R':
                g_num[k]-=1
                g_num[k+1]+=1
golem = 0
for i in range(len(g_num)):
    golem+= g_num[i]
print(golem)

Fixed submission:
list = list(map(int,input().split()))
if len(set(list)) == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
total = 0.0
rate = 380000

for i in range(N):
  a,t = input().split()
  if(t=="BTC"):
    total += float(a) * rate
  else:
    total += float(a)
print(total)

Fixed submission:
list = input().split("/")
y = int(list[0])
m = int(list[1])

if (y>=2019 and m>=5):
    print("TBD")
else:
    print("Heisei")

Buggy python submission (verdict: Runtime Error):
N = input()
total = 0

for i in range(len(N)):
    if (N[i][1]=="BTC"):
        total += float(N[i][0])*380000
    else:
        total += float(N[i][0])
print(total)

Fixed submission:
list = input().split("/")
y = int(list[0])
m = int(list[1])

if (y>=2019 and m>=5):
    print("TBD")
else:
    print("Heisei")

Buggy python submission (verdict: Runtime Error):
list = S.split("/")
y = int(list[0])
m = int(list[1])
d = int(list[2])

if (y > 2019):
    print("TBD")
elif (y < 2019):
    print("Heisei")
elif (m > 4):
    print("TBD")
elif (m < 4):
    print("Heisei")
elif (d > 30):
    print("TBD")
else:
    print("Heisei")

Fixed submission:
list = input().split("/")
y = int(list[0])
m = int(list[1])

if (y>=2019 and m>=5):
    print("TBD")
else:
    print("Heisei")

Buggy python submission (verdict: Runtime Error):
def(S):

  list = S.split("/")
  y = int(list[0])
  m = int(list[1])
  d = int(list[2])

  if (y > 2019):
      print("TBD")
  elif (y < 2019):
      print("Heisei")
  elif (m > 4):
      print("TBD")
  elif (m <= 4):
      print("Heisei")

Fixed submission:
list = input().split("/")
y = int(list[0])
m = int(list[1])

if (y>=2019 and m>=5):
    print("TBD")
else:
    print("Heisei")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr = list(map(int, input().split()))
z=1
for i in range(n):
    z=z*arr[i]
if(z>1000000000000000000):
    print("-1")
else:
    print(z)
    



Fixed submission:
n=int(input())
arr = list(map(int, input().split()))
z=1
flag=0
zero=1
for i in range(n):
    z=z*arr[i]
    if(z>1000000000000000000):
        flag=1
        break
for i in range(n):
    if(arr[i]==0):
        zero=0
if(flag==0 or zero==0):
    print(z*zero)
else:
    print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
    for j in range(i+1, N+1):
        amari = (A_list[i-1] * A_list[j-1]) % (10**9 + 7) 
        cnt += amari
        if cnt >= (10**9 + 7):
            cnt %= (10**9 + 7)
print(cnt)

Fixed submission:
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
    for j in range(i+1, N+1):
        if A_list[i-1] * A_list[j-1] >= 10**9 + 7:
            cnt += (A_list[i-1] * A_list[j-1]) % (10**9 + 7) 
        else:
            cnt += A_list[i-1] * A_list[j-1]
        if cnt >= (10**9 + 7):
            cnt %= (10**9 + 7)
print(cnt)

Fixed submission:
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
    for j in range(i+1, N+1):
        cnt += A_list[i-1] * A_list[j-1]
        if cnt >= (10**9 + 7):
            cnt %= (10**9 + 7)
print(cnt)

Fixed submission:
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
    for j in range(i+1, N+1):
        cnt += A_list[i-1] * A_list[j-1]
#        if cnt >= (10**9 + 7):
print(cnt % (10**9 + 7))

Fixed submission:
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
H,W,M = map(int,input().split())
h_list = [0] * M
w_list = [0] * M
for m in range(M):
    h_list[m],w_list[m] = map(int,input().split())
hh_list = [0] * H
ww_list = [0] * W
for m in range(M):
    hh_list[h_list[m]-1] += 1
for m in range(M):
    ww_list[w_list[m]-1] += 1
h_max = max(hh_list)
w_max = max(ww_list)

h_ans = []
w_ans = []

for hh in range(H):
    if hh_list[hh] == h_max:
        h_ans.append(hh)
for ww in range(W):
    if ww_list[ww] == w_max:
        w_ans.append(ww)
cnt = 0
for i,j in zip(h_list,w_list):
    if i-1 in set(h_ans) and j-1 in set(w_ans):
        cnt += 1
if cnt == len(h_ans) * len(w_ans):
    print(h_max + w_max - 1)
else:
    print(h_max + w_max)

Fixed submission:
from itertools import product
H,W,M = map(int,input().split())
h_list = [0] * M
w_list = [0] * M
for m in range(M):
    h_list[m],w_list[m] = map(int,input().split())
hh_list = [0] * H
ww_list = [0] * W
for m in range(M):
    hh_list[h_list[m]-1] += 1
for m in range(M):
    ww_list[w_list[m]-1] += 1
h_max = max(hh_list)
w_max = max(ww_list)

h_ans = []
w_ans = []

for hh in range(H):
    if hh_list[hh] == h_max:
        h_ans.append(hh)
for ww in range(W):
    if ww_list[ww] == w_max:
        w_ans.append(ww)
cnt = 0
h_set = set(h_ans)
w_set = set(w_ans)
for i,j in zip(h_list,w_list):
    if i-1 in h_set and j-1 in w_set:
        cnt += 1
if cnt == len(h_ans) * len(w_ans):
    print(h_max + w_max - 1)
else:
    print(h_max + w_max)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
At_list = [A_list[0]]
D_list = list()
Dt_list = list()
mone = 1000
stoc = 0
for i in range(1,len(A_list)):
    D_list.append(A_list[i]-A_list[i-1])
for h in range(len(D_list)):
    if D_list[h] != 0:
        Dt_list.append(D_list[h])
        At_list.append(A_list[h + 1])
for j in range(len(Dt_list)):
    if Dt_list[j] > 0:#買う
        stoc = mone // At_list[j]
        mone = mone % At_list[j]
    elif Dt_list[j] < 0:
        mone = mone + stoc * At_list[j]
        stoc = 0
        last_sell = j
if At_list[-1] >= At_list[-2]:
    mone = mone + stoc * At_list[-1]
else:
    mone = mone + stoc * At_list[last_sell]
print(mone)

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
At_list = [A_list[0]]
D_list = list()
Dt_list = list()
mone = 1000
stoc = 0
for i in range(1,len(A_list)):
    D_list.append(A_list[i]-A_list[i-1])
for h in range(len(D_list)):
    if D_list[h] != 0:
        Dt_list.append(D_list[h])
        At_list.append(A_list[h + 1])
for j in range(len(Dt_list)):
    if Dt_list[j] > 0:#買う
        stoc = stoc + mone // At_list[j]
        mone = mone % At_list[j]
    elif Dt_list[j] < 0:
        mone = mone + stoc * At_list[j]
        stoc = 0
        last_sell = j
if len(Dt_list) != 0:
    if At_list[-1] >= At_list[-2]:
        mone = mone + stoc * At_list[-1]
    else:
        mone = mone + stoc * At_list[last_sell]
else:
    mone = 1000
print(mone)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,20):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
print(mx_cmfrt)

Fixed submission:
N = int(input())
M = 10000 - N
M = str(M)
M = M[-3:]
M = int(M)
print(M)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,18):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
print(mx_cmfrt)

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
score = A[0]
for i in range(1, math.ceil(N*0.5)):
    if N - i * 2 != 1:
        score += 2 * A[i]
    else:
        score += A[i]
print(score)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,18):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[j-1],reached_list[j])
    reached_list.insert(insx_list[j], A_list[j])
    mx_cmfrt += cmfrt
    cmfrt = 0
print(mx_cmfrt)

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
score = A[0]
for i in range(1, math.ceil(N*0.5)):
    if N - i * 2 != 1:
        score += 2 * A[i]
    else:
        score += A[i]
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
cmfrt = 0
mx_cmfrt = 0
counter = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    for i in range(1, len(reached_list)):
        cmfrt = min(reached_list[i-1], reached_list[i])
        if cmfrt > mx_cmfrt:
            mx_cmfrt = cmfrt
            insrt_pst = i
    reached_list.insert(insrt_pst,A_list[j])
    counter += mx_cmfrt
    mx_cmfrt = 0
print(counter)

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
score = A[0]
for i in range(1, math.ceil(N*0.5)):
    if N - i * 2 != 1:
        score += 2 * A[i]
    else:
        score += A[i]
print(score)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
cnt_list = [0] * N
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        cnt_list[j - 1] += 1
ans = 0
for h in range(1, N + 1):
    ans += h * cnt_list[h -1]
print(ans)

Fixed submission:
import math
N = int(input())
cnt_list = [0] * N
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        cnt_list[j - 1] += 1
ans = 0
for h in range(1, N + 1):
    ans += h * cnt_list[h -1]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,12):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)

Fixed submission:
N = input()
if N.islower():
    print("a")
else:
    print("A")

Buggy python submission (verdict: Runtime Error):
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
output = ""
while N >= 26:
    mod = N % 26
    N = N / 26
    output = alpha[mod-1] + output
output = alpha[N-1] + output
print(output)

Fixed submission:
N = input()
if N.islower():
    print("a")
else:
    print("A")
Buggy python submission (verdict: Runtime Error):
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,10):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)

Fixed submission:
N = int(input())
n = N
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in range(1,12):
    
    if n <= 26 ** i:
        digits = i
        break
    else:
        n -= 26 ** i
#print("桁数は{0}桁".format(digits))
n -= 1
output = ""
for j in range(digits-1):
    amari = n % 26
    n //= 26
    output = alpha[amari] + output
output = alpha[n] + output
print(output)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
S =sum(A_list)
for i in range(Q):
    B,C = map(int,input().split())
    count = 0
    for j in A_list:
        if j == B:
            A_list[A_list.index(j)] = C
            count += 1
    S = S + count * (C - B)
    print(S)

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
S = sum(A_list)
count_list = [0] * (10 ** 5 + 1)
for A in A_list:
    count_list[A] += 1 
for i in range(Q):
    B,C = map(int,input().split())
    S = S + count_list[B] * (C - B)
    count_list[C] += count_list[B]
    count_list[B] = 0
    print(S)
#    print(sum(A_list))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    for j in A_list:
        if j == B:
            A_list[A_list.index(j)] = C
    print(sum(A_list))

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
S = sum(A_list)
count_list = [0] * (10 ** 5 + 1)
for A in A_list:
    count_list[A] += 1 
for i in range(Q):
    B,C = map(int,input().split())
    S = S + count_list[B] * (C - B)
    count_list[C] += count_list[B]
    count_list[B] = 0
    print(S)
#    print(sum(A_list))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = input()
A = A.split()
A = [int(c) for c in A]
A.sort()
count = 0
for i in range(N):
    for j in range(i,N):
        if A[i] % A[j] == 0 and i != j:
            count += 1
            break
print(N-count)

Fixed submission:
a,b,c,d,e = map(int, input().split())
count = 1
for i in [a,b,c,d,e]:
    if i == 0:
        print(count)
    count += 1

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = input()
A = A.split()
A = [int(c) for c in A]
count = 0
for i in range(N):
    for j in range(N):
        if A[i] % A[j] == 0 and i != j:
            count += 1
            break
print(len(A)-count)

Fixed submission:
a,b,c,d,e = map(int, input().split())
count = 1
for i in [a,b,c,d,e]:
    if i == 0:
        print(count)
    count += 1
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1

for i in range(N):
    output *= A_list[i]

    if (output > 10 ** 18 and flug != 1):
        print(-1)
        flug = 1
        break
if(flug != 1):
    print(output)

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1
if flug != 1:
    for i in range(N):
        output *= A_list[i]
        
        if (output > 10 ** 18):
            print(-1)
            flug = 1
            break
if(flug != 1):
    print(output)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

for i in range(N):
    output *= A_list[i]
    if 0 in A_list:
        print(0)
        flug = 1
        break
    if (output > 10 ** 18):
        print(-1)
        flug = 1
        break
if(flug != 1):
    print(output)

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1
if flug != 1:
    for i in range(N):
        output *= A_list[i]
        
        if (output > 10 ** 18):
            print(-1)
            flug = 1
            break
if(flug != 1):
    print(output)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int,input().split()))
output = 1
for i in range(N):
    output *= A_list[i]
    if (output > 10 ** 18):
        print(-1)
        flug = 1
        break
if(flug != 1):
    print(output)

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1
if flug != 1:
    for i in range(N):
        output *= A_list[i]
        
        if (output > 10 ** 18):
            print(-1)
            flug = 1
            break
if(flug != 1):
    print(output)

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

Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
output = 1
flug = 0

if 0 in A_list:
    print(0)
    flug = 1
if flug != 1:
    for i in range(N):
        output *= A_list[i]
        
        if (output > 10 ** 18):
            print(-1)
            flug = 1
            break
if(flug != 1):
    print(output)
Buggy python submission (verdict: Runtime Error):
import math
A,B = map(double,input().split())
print(int(A * B))

Fixed submission:
import math
from decimal import Decimal
a, b = input().split()
a = int(a)
b = Decimal(b)
print(math.floor(a * b))
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
N = int(input())
S = input()
R_lst = []
G_lst = []
B_lst = []
cnt = 0
for i,s in enumerate(S):
    if s == "R":
        R_lst.append(i)
    elif s == "G":
        G_lst.append(i)
    else:
        B_lst.append(i)
for r in R_lst:
    for g in G_lst:
        for b in B_lst:
            mid = median([r,g,b])
            if max(r,g,b) - mid != mid - min(r,g,b):
                cnt += 1
print(cnt)

Fixed submission:
N = int(input())
S = input()
total = S.count("R") * S.count("G") * S.count("B")
sub = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        h = j + j - i
        if h > N - 1 or S[j] == S[h] or S[h] == S[i]:
            continue
        sub += 1
print(total - sub)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
ans = deque(S)
Q = int(input())
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        ans.reverse()
    elif a_list[1] == "1":
        ans.appendleft(a_list[2])
    else:
        ans.append(a_list[2])
ans = "".join(ans)
print(ans)

Fixed submission:
from collections import deque
S = input()
ans = deque(S)
Q = int(input())
rev = False
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        if rev == True:
            rev = False
        else:
            rev = True
    elif (a_list[1] == "1" and rev == False) or (a_list[1] == "2" and rev == True):
        ans.appendleft(a_list[2])
    else:
        ans.append(a_list[2])
if rev:
    ans.reverse()
ans = "".join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
ans = deque(S)
Q = int(input())
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        ans.reverse()
    elif a_list[1] == "1":
        ans.appendleft(a_list[2])
    else:
        ans.append(a_list[2])
print(*ans, sep = "")

Fixed submission:
from collections import deque
S = input()
ans = deque(S)
Q = int(input())
rev = False
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        if rev == True:
            rev = False
        else:
            rev = True
    elif (a_list[1] == "1" and rev == False) or (a_list[1] == "2" and rev == True):
        ans.appendleft(a_list[2])
    else:
        ans.append(a_list[2])
if rev:
    ans.reverse()
ans = "".join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        S = S[::-1]
    elif a_list[1] == "1":
        S = a_list[2] + S
    else:
        S = S + a_list[2]
print(S)

Fixed submission:
from collections import deque
S = input()
ans = deque(S)
Q = int(input())
rev = False
for i in range(Q):
    a_list = input().split()
    if a_list[0] == "1":
        if rev == True:
            rev = False
        else:
            rev = True
    elif (a_list[1] == "1" and rev == False) or (a_list[1] == "2" and rev == True):
        ans.appendleft(a_list[2])
    else:
        ans.append(a_list[2])
if rev:
    ans.reverse()
ans = "".join(ans)
print(ans)