qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import deque

s = deque(list(input()))

q = int(input())

reverse = 0

for i in range(q):
  query = list(input().split())
  if query[0] == '1':
    reverse ^= 1
    continue
  else:
    if query[1] == '1':
      if reverse:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse:
        s.appendleft(query[2])
      else:
        s.append(query[2])
if reverse:
  s = s[::-1]
print(''.join(s))

Fixed code:
from collections import deque

s = deque(list(input()))

q = int(input())

reverse = 0

for i in range(q):
  query = list(input().split())
  if query[0] == '1':
    reverse ^= 1
    continue
  else:
    if query[1] == '1':
      if reverse:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse:
        s.appendleft(query[2])
      else:
        s.append(query[2])
if reverse:
  print(''.join(s)[::-1])
else:
  print(''.join(s))
Buggy code:
from collections import deque


reverse = False

string = deque(input().rstrip())
operate_times = int(input().rstrip())

for i in range(operate_times):
    row = input().rstrip()
    if row[0]=='1':
        if reverse:
            reverse = False
        else:
            reverse = True
    
    if row[0]=='2':
        row = row.split()
        head_or_tail = row[1]
        add_string = row[2]

        if reverse:
            if head_or_tail==1:
                string.append(add_string)
            else:
                string.appendleft(add_string)
        
        else:
            if head_or_tail==2:
                string.append(add_string)
            else:
                string.appendleft(add_string)


answer_string = ''
if reverse:
    for _ in range(len(string)):
        right = string.pop()
        answer_string+=right


print(answer_string)

Fixed code:
from collections import deque


reverse = False

string = deque(input().rstrip())
operate_times = int(input().rstrip())

for i in range(operate_times):
    row = input().rstrip()
    if row[0]=='1':
        if reverse:
            reverse = False
        else:
            reverse = True
    
    if row[0]=='2':
        row = row.split()
        head_or_tail = int(row[1])
        add_string = row[2]

        if reverse:
            if head_or_tail==1:
                string.append(add_string)
            else:
                string.appendleft(add_string)
        
        else:
            if head_or_tail==2:
                string.append(add_string)
            else:
                string.appendleft(add_string)


answer_string = ''
if reverse:
    for _ in range(len(string)):
        right = string.pop()
        answer_string+=right
    print(answer_string)
else:
    print(''.join(string))
Buggy code:
from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
for i in range(Q):
    if querry[i][0] == '1':
        S.reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            S.append(querry[i][2])

ans=list(S)

print("".join(ans))

Fixed code:
from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))
Buggy code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
Q = int(readline())
cnt = 0
start = ''
end = ''
for i in range(Q):
    A = list(map(str,readline().decode().split()))
    if A[0] == '1':
        cnt +=1
    else:
        if (cnt + int(A[1])) % 2:
            start += A[2]
        else:
            end += A[2]
ans = start + S + end
if cnt % 2:
    print(ans[::-1])
else:
    print(ans)

Fixed code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
Q = int(readline())
cnt = 0
start = ''
end = ''
for i in range(Q):
    A = list(map(str,readline().decode().split()))
    if A[0] == '1':
        cnt +=1
    else:
        if (cnt + int(A[1])) % 2:
            start += A[2]
        else:
            end += A[2]
ans = start + S + end
if cnt % 2 == 1:
    print(end[::-1] + S[::-1] + start)
else:
    print(start[::-1] + S + end)
Buggy code:
from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)


Fixed code:
from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)
Buggy code:
S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print('',join(dq))
else:
    print(''.join(dq)[::-1])

Fixed code:
S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print(''.join(dq))
else:
    print(''.join(dq)[::-1])
Buggy code:
from collections import deque

s = deque(input().split())
n = int(input())
query_li = (input().split() for i in range(n))

flag = 1

for query in query_li:
    if int(query[0]) == 1:
        flag = flag * -1
    else:
        if int(query[1]) == 1:
            if flag == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if flag == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])

s = ''.join(s)

print(s)

Fixed code:
from collections import deque

s = deque(input().split())
n = int(input())
query_li = (input().split() for i in range(n))

flag = 1

for query in query_li:
    if int(query[0]) == 1:
        flag = flag * -1
    else:
        if int(query[1]) == 1:
            if flag == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if flag == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])

s = ''.join(s)
if flag == -1:
    s = s[::-1]

print(s)
Buggy code:
S=input()
Q=int(input())

flip=0
fr=''
ba=''
for i in range(Q):
    Qq=input()
    
    if(Qq.count(' ')>0):
        ti,fi,ci=Qq.split()
        if( flip%2==0   ):
            if(fi=='1'):
                fr=str(ci)+fr
            else:
                ba=ba+str(ci)
        else:
            if(fi=='1'):
                #fr=fr+str(ci)
                ba=ba+str(ci)
            else:
                #ba=str(ci)+ba
                fr=str(ci)+fr
    else:
        flip+=1
        #S=S[::-1]
if(flip&2==0):
    print(fr+S+ba)
else:
    print(ba[::-1]+S[::-1]+fr[::-1])


Fixed code:
S=input()
Q=int(input())

flip=0
fr=''
ba=''
for i in range(Q):
    Qq=input()
    
    if(Qq.count(' ')>0):
        ti,fi,ci=Qq.split()
        if( flip%2==0   ):
            if(fi=='1'):
                fr=str(ci)+fr
            else:
                ba=ba+str(ci)
        else:
            if(fi=='1'):
                ba=ba+str(ci)
            else:
                fr=str(ci)+fr
    else:
        flip+=1
if(flip%2==0):
    print(fr+S+ba)
else:
    print(ba[::-1]+S[::-1]+fr[::-1])
Buggy code:
S=input()
Q=int(input())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev != rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)


Fixed code:
S=input()
Q=int(input())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev = not rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)
Buggy code:
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations)

MAX_INT = 2**62-1
sys.setrecursionlimit(10**7)

input = sys.stdin.readline


def read_n_int():
    return map(int, input().split())


def main():
    s = input()
    q = int(input())
    queue = deque(s)
    is_reversed = 0

    for _ in range(q):
        t, *x = input().split()
        if t == '1':
            is_reversed ^= 1
        else:
            where, c = x
            where = int(where) & 1
            if where ^ is_reversed:
                queue.appendleft(c)
            else:
                queue.append(c)
    if is_reversed:
        queue.reverse()
    print(''.join(queue))


if __name__ == "__main__":
    main()


Fixed code:
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations)

MAX_INT = 2**62-1
sys.setrecursionlimit(10**7)

input = sys.stdin.readline


def read_n_int():
    return map(int, input().split())


def main():
    s = input().strip()
    q = int(input())
    queue = deque(s)
    is_reversed = 0

    for _ in range(q):
        t, *x = input().strip().split()
        # print(t, x, queue)
        if t == '1':
            is_reversed ^= 1
        else:
            where, c = x
            where = int(where) & 1
            if where ^ is_reversed:
                queue.appendleft(c)
            else:
                queue.append(c)
    if is_reversed:
        queue.reverse()

    print(''.join(queue))


if __name__ == "__main__":
    main()
Buggy code:
S=input()
Q=int(input())

guuki=0
ANS=S
ANS_front=""
ANS_back=""
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        guuki+=1
    elif int(A[1])*guuki%2==1 or (A[1]=="2" and guuki%2==0):
        ANS_back+=A[2]
    else:
        ANS_front=A[2]+ANS_front
if guuki%2==1:
    ANS=ANS[::-1]
    ANS_back,ANS_front=ANS_front,ANS_back
print(ANS_front[::-1]+ANS+ANS_back)

Fixed code:
S=input()
Q=int(input())

guuki=0
ANS=S
ANS_back=""
ANS_front=""
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        guuki+=1
    elif int(A[1])*guuki%2==1 or (A[1]=="2" and guuki%2==0):
        ANS_back+=A[2]
    else:
        ANS_front+=A[2]
if guuki%2==1:
    ANS=ANS[::-1]
    ANS_back,ANS_front=ANS_front,ANS_back
print(ANS_front[::-1]+ANS+ANS_back)
Buggy code:
s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))

Fixed code:
import collections

s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))
Buggy code:
import sys
input = sys.stdin.readline


from collections import deque
reverse = -1
S = deque(input())
Q = int(input())
for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        reverse *= -1
    else:
        if Query[1] == "1":
            if reverse == 1:
                S.append(Query[2])
            else:
                S.appendleft(Query[2])
        else:
            if reverse == 1:
                S.appendleft(Query[2])
            else:
                S.append(Query[2])

ans = "".join(S)
if reverse == 1:
    ans = ans[::-1]
print(ans)

Fixed code:
from collections import deque
reverse = -1
S = deque(input())
Q = int(input())
for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        reverse *= -1
    else:
        if Query[1] == "1":
            if reverse == 1:
                S.append(Query[2])
            else:
                S.appendleft(Query[2])
        else:
            if reverse == 1:
                S.appendleft(Query[2])
            else:
                S.append(Query[2])

ans = "".join(S)
if reverse == 1:
    ans = ans[::-1]
print(ans)
Buggy code:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(S)


Fixed code:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)
Buggy code:
S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
        print("query=1")
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
        print("query=2")
print((forward+S+back)[::1 if(fb) else -1])

Fixed code:
S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
print((forward+S+back)[::1 if(fb) else -1])
Buggy code:
def main():
    s = input()
    q = int(input())
    r = 1
    front = ""
    back = ""
    for _ in range(q):
        n, *fc = input().split()
        if n == "1":
            r *= -1
        else:
            f, c = fc
            f = 1 if f == "1" else -1
            if f*r == 1:
                front += c
            else:
                back += c
    print(front[::-1]+s[::r]+back)

if __name__ == "__main__":
    main()

Fixed code:
def main():
    s = input()
    q = int(input())
    r = 1
    front = ""
    back = ""
    for _ in range(q):
        n, *fc = input().split()
        if n == "1":
            r *= -1
        else:
            f, c = fc
            f = 1 if f == "1" else -1
            if f*r == 1:
                front += c
            else:
                back += c
    if r == 1:
        print(front[::-1]+s+back)
    else:
        print(back[::-1]+s[::-1]+front)

if __name__ == "__main__":
    main()
Buggy code:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 0
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
print("".join(d))

Fixed code:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))
Buggy code:
S = input()
Q = int(input())
reverse = 0
left = ""
right = ""
for _ in range(Q):
  q = input().split()
  if q[0]=="1":
    reverse += 1
    left, right = right, left
  if q[0]=="2":
    if q[1]=="1":
      left = q[2]+left
    if q[1]=="2":
      right = right+q[2]
if reverse%2==1:
  left = left[::-1]
  right = right[::-1]
  S = S[::-1]
print(left+S+right)

Fixed code:
S = input()
Q = int(input())
reverse = 0
left = ""
right = ""
for _ in range(Q):
    q = input().split()
    if q[0]=="1":
        reverse += 1
        left, right = right, left
    if q[0]=="2" and q[1]=="1":
        if reverse%2==0: left = q[2]+left
        else: left = left+q[2]
    if q[0]=="2" and q[1]=="2":
        if reverse%2==0: right = right+q[2]
        else: right = q[2]+right
if reverse%2==1:
    left = left[::-1]
    right = right[::-1]
    S = S[::-1]
print(left+S+right)
Buggy code:
S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.insert(0,q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.insert(0,q[i][2])
if rev==1:
    S_list.append(left)
    S_list.insert(0,right)
else:
    S_list.reverse()
    S_list.append(left)
    S_list.insert(0,right)
    
S=''.join(S_list)
print(S)

Fixed code:
S=str(input())
S_list=list(S)

Q=int(input())

q=[]
right=[]
left=[]

rev=1

for i in range(Q):
    q.append(input().split())
    if q[i][0]=="1":
        rev=rev*(-1)
    elif q[i][0]=="2":
        if q[i][1]=="1":
            if rev==1:
                right.append(q[i][2])
            else:
                left.append(q[i][2])
        elif q[i][1]=="2":
            if rev==1:
                left.append(q[i][2])
            else:
                right.append(q[i][2])
right.reverse()
if rev==1:
    S_list=right+S_list+left
else:
    S_list=right+S_list+left
    S_list.reverse()

S=''.join(S_list)
print(S)
Buggy code:
s = input()
T = ""
n = int(input())
for i in range(n):
    # print(s,T)
    t = list(map(str,input().split()))
    if t[0] == "1":
        s,T = T,s
    else:
        if t[1] == "1":
            s += t[2]
        else:
            T += t[2]

print(T+s[::-1])

Fixed code:
s = input()
T = ""
n = int(input())
for i in range(n):
    # print(s,T)
    t = list(map(str,input().split()))
    if t[0] == "1":
        s,T = T,s
    else:
        if t[1] == "1":
            T += t[2]
        else:
            s += t[2]

print(T[::-1]+s)
Buggy code:
S = input()
Q = int(input())

r_flg = False
for i in range(Q):
    q = input()
    if q == '1':
        r_flg = True
        continue
    t,f,c = q.split()
    if f == '1':
        S = c + S if not r_flg else S + c
    else:
        S = S + c if not r_flg else c + S
if r_flg:
    print(S[::-1])
else:
    print(S)

Fixed code:
S = input()
Q = int(input())



front = ''
back = ''

r_flg = False
for i in range(Q):
    q = input()
    if q == '1':
        r_flg = False if r_flg else True
        continue
        
    t,f,c = q.split()
    if not r_flg:
        if f == '1':
            front += c
        else:
            back += c
    else:
        if f == '1':
            back += c
        else:
            front += c
    
if not r_flg:
    print(front[::-1]+S+back)
else:
    print(back[::-1] + S[::-1] + front)
Buggy code:
import sys
input = sys.stdin.readline

S = input()
L = []
R = []
rev = 0
for _ in range(int(input())):
    A = input().split()
    if A[0] == "1":
        rev ^= 1
    else:
        if (int(A[1]) ^ rev) & 1:
            L.append(A[2])
        else:
            R.append(A[2])

if rev:
    print("".join(R[::-1]) + S[::-1] + "".join(L))
else:
    print("".join(L[::-1]) + S + "".join(R))


Fixed code:
import sys
input = lambda: sys.stdin.readline().rstrip()

S = input()
L = []
R = []
rev = 0
for _ in range(int(input())):
    A = input().split()
    if A[0] == "1":
        rev ^= 1
    else:
        if (int(A[1]) ^ rev) & 1:
            L.append(A[2])
        else:
            R.append(A[2])

if rev:
    print("".join(R[::-1]) + S[::-1] + "".join(L))
else:
    print("".join(L[::-1]) + S + "".join(R))
Buggy code:
import sys
from collections import deque
	S=[input()]
	S=deque(S)
	Q=int(sys.stdin.readline())
	flag=0
	for i in range(Q):
		qu=tuple(input().split())
		if qu[0]=='1':
			if flag==0:
				flag+=1
			else:
				flag=0
		else:
			if qu[1]=='1' and flag==0:
				S.appendleft(qu[2])
			elif qu[1]=='1' and flag==1:
				S.append(qu[2])
			elif qu[1]=='2' and flag==0:
				S.append(qu[2])
			elif qu[1]=='2' and flag==1:
				S.appendleft(qu[2])
	if flag==1:
		S.reverse()
	print(''.join(S))

Fixed code:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))