qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import deque
import sys
input = sys.stdin.readline

s = deque(list(input()))
q = int(input())
rev = -1

for i in range(q):
    a = list(input().split())
    if a[0] == '1': #T1
        rev *= -1 
    
    else: #T2
        if a[1] == '1': #Fi = 1
            if rev == -1:
                s.appendleft(a[2])
            else:
                s.append(a[2])
                
        else: #Fi = 2
            if rev == -1:
                s.append(a[2])
            else:
                s.appendleft(a[2])
                
if rev == -1:
    print(''.join(s))
else:
    s = list(s)
    print(''.join(s[::-1]))

Fixed code:
from collections import deque
#import sys
#input = sys.stdin.readline

s = deque(list(input()))
q = int(input())
rev = -1

for i in range(q):
    a = list(input().split())
    if a[0] == '1': #T1
        rev *= -1 
    
    else: #T2
        if a[1] == '1': #Fi = 1
            if rev == -1:
                s.appendleft(a[2])
            else:
                s.append(a[2])
                
        else: #Fi = 2
            if rev == -1:
                s.append(a[2])
            else:
                s.appendleft(a[2])
                
if rev == -1:
    print(''.join(s))
else:
    s = list(s)
    print(''.join(s[::-1]))
Buggy code:
from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(0, b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s[i]
else:
    for i in range(len(s)):
        c += s[-i-1]
print(c)

Fixed code:
from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s.popleft()
else:
    for i in range(len(s)):
        c += s.pop()
print(c)
Buggy code:
def main():
    from collections import deque
    s = list(input())
    dq = deque()
    for i in s:
        dq.append(i)

    q = int(input())
    flag = True
    for _ in range(q):
        line = input().split(" ")
        if line[0] == "1":
            flag = not flag
        else:
            if line[1] == "1":
                if flag:
                    dq.appendleft(line[2])
                else:
                    dq.append(line[2])
            elif line[1] == "2":
                if flag:
                    dq.append(line[2])
                else:
                    dq.appendleft(line[2])
    if flag == False:
        dq.rotate(-1)
    for i in list(dq):
        print(i,end="")

main()

Fixed code:
def main():
    from collections import deque
    s = list(input())
    dq = deque()
    for i in s:
        dq.append(i)

    q = int(input())
    flag = True
    for _ in range(q):
        line = input().split(" ")
        if line[0] == "1":
            flag = not flag
        else:
            if line[1] == "1":
                if flag:
                    dq.appendleft(line[2])
                else:
                    dq.append(line[2])
            elif line[1] == "2":
                if flag:
                    dq.append(line[2])
                else:
                    dq.appendleft(line[2])
    if flag == False:
        dq.reverse()
    for i in list(dq):
        print(i,end="")
main()
Buggy code:
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

#s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])


Fixed code:
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])
Buggy code:
from collections import deque

d = deque()
S = input()
d.append(S)
Q = int(input())
Flag = True
 
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        Flag = not Flag
    else:
        QueryList = Query.split()
        if Flag:
            if QueryList[1] =="1":
                d.appendleft(QueryList[2])
            else:
                d.append(QueryList[2])
        else:
            if QueryList[1] =="2":
                d.append(QueryList[2])
            else:
                d.appendleft(QueryList[2])

d_string = "".join(list(d))

if not Flag:
    d_string = d_string[::-1]    
print(d_string)
    

Fixed code:
from collections import deque

d = deque()
S = input()
d.append(S)
Q = int(input())
Flag = True
 
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        Flag = not Flag
    else:
        QueryList = Query.split()
        if Flag:
            if QueryList[1] =="1":
                d.appendleft(QueryList[2])
            else:
                d.append(QueryList[2])
        else:
            if QueryList[1] =="2":
                d.appendleft(QueryList[2])
            else:
                d.append(QueryList[2])

d_string = "".join(list(d))

if not Flag:
    d_string = d_string[::-1]    
print(d_string)
Buggy code:
S = input()
nQ = int(input())

Ques = []
nReverse = 0
nAddFront= 0
nAddBack = 0
for i in range(nQ):
  line = input().split()
  if int(line[0]) == 1:
    nReverse += 1
    Ques.append([int(line[0])])
  else:
    if int(line[1]) == 1:
      if nReverse % 2 == 0:
        nAddFront += 1
      else:
        nAddBack  += 1
    else:
      if nReverse % 2 == 0:
        nAddBack += 1
      else:
        nAddFront  += 1      
    Ques.append([int(line[0]),int(line[1]),line[2]])

#print(nAddFront,nAddBack)
SS = [-1] * (nAddFront + len(S) + nAddBack)
for i in range(len(S)):
   SS[nAddFront + i] = S[i]

left = nAddFront -1
right= nAddFront + len(S)

nReverseLoc = 0
for iQ in Ques:
   print(SS)
   if iQ[0] == 1:
      nReverseLoc += 1
   if iQ[0] == 2:
    if int(iQ[1]) == 1:
      if nReverseLoc % 2 == 0:
        #nAddFront += 1
        SS[left] = iQ[2]
        left -= 1
      else:
        SS[right] = iQ[2]
        right += 1
    else:
      if nReverseLoc % 2 == 0:
        SS[right] = iQ[2]
        right += 1
      else:
        SS[left] = iQ[2]
        left  += 1 

S = "".join(SS)
if nReverse % 2 == 1:
  S = S[::-1]
  
print(S)

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

Ques = []
nReverse = 0
nAddFront= 0
nAddBack = 0
for i in range(nQ):
  line = input().split()
  if int(line[0]) == 1:
    nReverse += 1
    Ques.append([int(line[0])])
  else:
    if int(line[1]) == 1:
      if nReverse % 2 == 0:
        nAddFront += 1
      else:
        nAddBack  += 1
    else:
      if nReverse % 2 == 0:
        nAddBack += 1
      else:
        nAddFront  += 1      
    Ques.append([int(line[0]),int(line[1]),line[2]])

#print(nAddFront,nAddBack)
SS = [-1] * (nAddFront + len(S) + nAddBack)
for i in range(len(S)):
   SS[nAddFront + i] = S[i]

left = nAddFront -1
right= nAddFront + len(S)

nReverseLoc = 0
for iQ in Ques:
   if iQ[0] == 1:
      nReverseLoc += 1
   if iQ[0] == 2:
    if int(iQ[1]) == 1:
      if nReverseLoc % 2 == 0:
        #nAddFront += 1
        SS[left] = iQ[2]
        left -= 1
      else:
        SS[right] = iQ[2]
        right += 1
    else:
      if nReverseLoc % 2 == 0:
        SS[right] = iQ[2]
        right += 1
      else:
        SS[left] = iQ[2]
        left  -= 1 

S = "".join(SS)
if nReverse % 2 == 1:
  S = S[::-1]
  
print(S)
Buggy code:
import copy

S=input()
Q=int(input())
Query=[]
temp=[]

revflag=0
sbef=[]
saft=[]

for i in range(Q):
    temp=input().split()
    if len(temp) ==1:
        revflag += 1
    else:
        if (revflag + int(temp[1])-1 )%2 == 0:
            sbef.append(temp[2])
        else:
            saft.append(temp[2])

ans=""

for i in range(len(sbef)):
    ans+=sbef[len(sbef)-i-1]

ans += S
for i in range(len(saft)):
    ans+=saft[i]
print(ans)

tmp=""
tmp2 = copy.copy(ans)


if revflag%2 ==1:
    for i in range(len(ans)):
        tmp+=tmp2[len(ans)-i-1]
    ans=tmp


print(ans)


Fixed code:
import copy

S=input()
Q=int(input())
Query=[]
temp=[]

revflag=0
sbef=[]
saft=[]

for i in range(Q):
    temp=input().split()
    if len(temp) ==1:
        revflag += 1
    else:
        if (revflag + int(temp[1])-1 )%2 == 0:
            sbef.append(temp[2])
        else:
            saft.append(temp[2])

ans=""

for i in range(len(sbef)):
    ans+=sbef[len(sbef)-i-1]

ans += S
for i in range(len(saft)):
    ans+=saft[i]

tmp=""
tmp2 = copy.copy(ans)


if revflag%2 ==1:
    for i in range(len(ans)):
        tmp+=tmp2[len(ans)-i-1]
    ans=tmp


print(ans)
Buggy code:
s=input()
q=int(input())
h=0
m=''
u=''
for _  in range(q):
  d=input()
  if '2' in d:
    a,b,c=map(str,d.split())
    if b=='1':
      if h%2==0:
        u+=c
      else:
        m+=c
        
    else:
      if h%2==0:
        m+=c
      else:
        u+=c
        
  else:
    h+=1
    
M=list(m)
G=list(reversed(M))
s=G+s+u
if h%2==0:
  print(s)
else:
  f=list(s)
  g=list(reversed(f))
  print(''.join(g))

Fixed code:
s=input()
q=int(input())
h=0
m=''
u=''
for _  in range(q):
  d=input()
  if '2' in d:
    a,b,c=map(str,d.split())
    if b=='1':
      if h%2==0:
        m+=c
      else:
        u+=c
        
    else:
      if h%2==0:
        u+=c
      else:
        m+=c
        
  else:
    h+=1
    
M=list(m)
G=list(reversed(M))
GG=''.join(G)
s=GG+s+u
if h%2==0:
  print(s)
else:
  f=list(s)
  g=list(reversed(f))
  print(''.join(g))
Buggy code:
S = input()
Q = int(input())
flag = True
from collections import deque
que=deque(S)

for i in range(Q):
    a = input().split()
    if a[0]=="1":
        flag = not flag

    else:
        f = a[1]
        c = a[2]
        if f=="1":
            if flag:
                que.appendleft(c)
            else:
                que.append(c)
        else:
            if flag:
                que.append(c)
            else:
                que.appendleft(c)


    
print("".join(que))

Fixed code:
S = input()
Q = int(input())
flag = True
from collections import deque
que=deque(S)

for i in range(Q):
    a = input().split()
    if a[0]=="1":
        flag = not flag

    else:
        f = a[1]
        c = a[2]
        if f=="1":
            if flag:
                que.appendleft(c)
            else:
                que.append(c)
        else:
            if flag:
                que.append(c)
            else:
                que.appendleft(c)

if not flag:
    que.reverse()

print("".join(que))
Buggy code:
s = input()
q = int(input())

head = []
tail = []
flip = 0

for i in range(q):
	query = input().split()
	if query[0] == '1':
		flip ^= 1
	else:
		f = query[1]
		c = query[2]
		if (f ^ flip) == 0:
			head.append(c)
		else:
			tail.append(c)

if flip:
	head, tail = tail, head
	s = s[::-1]

head = ''.join(head)
tail = ''.join(tail)

print(head[::-1] + s + tail)

Fixed code:
s = input()
q = int(input())

head = []
tail = []
flip = 0

for i in range(q):
	query = input().split()
	if query[0] == '1':
		flip ^= 1
	else:
		f = int(query[1]) - 1
		c = query[2]
		if (f ^ flip) == 0:
			head.append(c)
		else:
			tail.append(c)

if flip:
	head, tail = tail, head
	s = s[::-1]

head = ''.join(head)
tail = ''.join(tail)

print(head[::-1] + s + tail)
Buggy code:
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
reverse_flg = False

Q = int(input())
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        reverse_flg = not reverse_flg
    else:
        if f == '1':
            S_list.appendleft(c)
        else:
            S_list.append(c)
if reverse_flg:
    S_list.reverse()
print(''.join(S_list))

Fixed code:
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
is_reverse = False

Q = int(input())
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        is_reverse = not is_reverse
    else:
        if f == '1':
            if is_reverse:
                S_list.append(c)
            else:
                S_list.appendleft(c)
        else:
            if is_reverse:
                S_list.appendleft(c)
            else:
                S_list.append(c)
if is_reverse:
    S_list.reverse()
print(''.join(S_list))
Buggy code:
import sys
input=sys.stdin.readline
from collections import deque

s = input()
q = int(input())
hanten = 0
ans = deque(s)
for _ in range(q):
    a = list(input().split())
    if a[0] == "1":
        hanten += 1
    else:
        if hanten % 2 == 0:
            if a[1] == "1":
                ans.appendleft(a[2])
            if a[1] == "2":
                ans.append(a[2])
        else:
            if a[1] == "1":
                ans.append(a[2])
            if a[1] == "2":
                ans.appendleft(a[2])
if hanten % 2 == 0:
    print(*ans, sep="")
else:
    ans.reverse()
    print(*ans, sep="")


Fixed code:
from collections import deque
s = input()
q = int(input())
hanten = 0
ans = deque(s)
for _ in range(q):
    a = list(input().split())
    if a[0] == "1":
        hanten += 1
    else:
        if hanten % 2 == 0:
            if a[1] == "1":
                ans.appendleft(a[2])
            if a[1] == "2":
                ans.append(a[2])
        else:
            if a[1] == "1":
                ans.append(a[2])
            if a[1] == "2":
                ans.appendleft(a[2])
if hanten % 2 == 0:
    print(*ans, sep="")
else:
    ans.reverse()
    print(*ans, sep="")
Buggy code:
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
cnt = 0
r = []
l = []
for i in range(q-1,-1,-1):
    if tbl[i][0] == '1':
        cnt += 1
    else:
        if (cnt + int(tbl[i][1]))%2 == 1:
            l.append(tbl[i][2])
        else:
            r.append(tbl[i][2])
l = ''.join(l[::-1])
s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)


Fixed code:
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
cnt = 0
r = []
l = []
for i in range(q-1,-1,-1):
    if tbl[i][0] == '1':
        cnt += 1
    else:
        if (cnt + int(tbl[i][1]))%2 == 1:
            l.append(tbl[i][2])
        else:
            r.append(tbl[i][2])
l = ''.join(l)
if cnt%2 == 1:
    s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)
Buggy code:
# coding: utf-8

S = input()
Q = int(input())

query = []

for i in range(Q):
    query.append(input().split())


left = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        left = not left

    else:
        if i[1]=="1":
            if left:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if left:
                suf += i[2]
            else:
                pre = i[2]+pre

print(pre+S+suf) if left else print(suf+S[::-1]+pre)


Fixed code:
# coding: utf-8

S = input()
Q = int(input())

query = []

for i in range(Q):
    query.append(input().split())


bool = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        bool = not(bool)

    else:
        if i[1]=="1":
            if bool:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if bool:
                suf += i[2]
            else:
                pre = i[2]+pre

S = pre+ S +suf
print(S) if bool else print(S[::-1])
Buggy code:
from collections import deque

deq=deque()
deq.append(input())
q=int(input())
x=True
for i in range(q):
	a=input()
	if a[0]=="1":
		x = not x
		print(x)
	elif a[2]=="1":
		if x%2!=0:
			deq.appendleft(a[4])
		else:
			deq.append(a[4])
	else:
		if x%2!=0:
			deq.append(a[4])
		else:
			deq.appendleft(a[4])
if x==True:
	c="".join(deq)
else:
	deq.reverse()
	c="".join(deq)
print(c)


Fixed code:
from collections import deque

deq=deque()
k = input()
for i in range(len(k)):
	deq.append(k[i])
q=int(input())
x=True
for i in range(q):
	a=input()
	if a[0]=="1":
		x = not x
	elif a[2]=="1":
		if x==True:
			deq.appendleft(a[4])
		else:
			deq.append(a[4])
	else:
		if x==True:
			deq.append(a[4])
		else:
			deq.appendleft(a[4])
if x==True:
	c="".join(deq)
else:
	deq.reverse()
	c="".join(deq)
print(c)
Buggy code:
def rev_f(string , i):
    if i[2] == '2':
        string = string + i[4]

    if i[2] == '1':
        string = i[4] + string
    return string



def rev_s(string , i):
    if i[2] == '1':
        string = string + i[4]

    if i[2] == '2':
        string = i[4] + string
    return string



front = ''
back = ''
string = input()
num = int(input())
q_list = []
reverse_num = 0
reverse = True
reverese_s = False
for a in range(num):
    i = input()
    if i == '1':
        reverse_num  +=1 
        if reverese_s:
            reverese_s = False
        else:
            reverese_s = True
    else:
        if reverese_s == False:
            if i[2] == '2':
                back += i[4]
            else:
                front += i[4]
            
        else :
            if i[2] == '2':
                front += i[4]
            else:
                back += i[4]
        
if reverse_num %2 == 0:
    reverse = False
    
if reverse == True:
    string = back + string[::-1] + front
    
else:
    string = front + string + back
print(string)


Fixed code:
def rev_f(string , i):
    if i[2] == '2':
        string = string + i[4]

    if i[2] == '1':
        string = i[4] + string
    return string



def rev_s(string , i):
    if i[2] == '1':
        string = string + i[4]

    if i[2] == '2':
        string = i[4] + string
    return string



front = ''
back = ''
string = input()
num = int(input())
q_list = []
reverse_num = 0
reverse = True
reverese_s = False
for a in range(num):
    i = input()
    if i == '1':
        reverse_num  +=1 
        if reverese_s:
            reverese_s = False
        else:
            reverese_s = True
    else:
        if reverese_s == False:
            if i[2] == '2':
                back += i[4]
            else:
                front = i[4] + front
            
        else :
            if i[2] == '2':
                front = i[4] + front
            else:
                back += i[4]
        
if reverse_num %2 == 0:
    reverse = False
    
string = front + string + back
if reverse == True:
    string = string[::-1]
    
print(string)
Buggy code:
s = input()
t = ''
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

for qi in Q:
    if int(qi[0]) == 1:
        s, t = t, s
    else:
        if int(qi[1])  == 1:
            t += qi[2]
        else:
            s += qi[2]
t[::-1]
t += s
print(t)


Fixed code:
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)
Buggy code:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
parity = rev % 2
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if (int(qi[2]) + parity) % 2:
            ans.appendleft(qi[4])
        else:
            ans.append(qi[4])


if parity:
    ans.reverse()
for i in ans:
    print(i, end='')

Fixed code:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if (int(qi[2]) + rev%2) % 2:
            ans.appendleft(qi[4])
        else:
            ans.append(qi[4])

if rev % 2:
    ans.reverse()
for i in ans:
    print(i, end='')
Buggy code:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    for i in ans[::-1]:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')

Fixed code:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')
Buggy code:
def main():
    s=input()
    q=int(input())
    queryy=[]
    sent="1"
    back="1"
    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    sent+=query[2]
                  #  s=str(query[2])+s
                else:
                    back+=query[2]
                   # s+=str(query[2])
                    
            else:
                if check==-1:
                    back+=query[2]
                    #s+=str(query[2])
                else:
                    sent+=query[2]
                    #s=str(query[2])+s
    s=s[::-1]
   # print(type(sent))
    if sent[0]=="1"
        sent=sent[1:]
    sent=sent[::-1]
    if back[0]=="1"
        back=back[1:]

    if check==1:
        
        print((sent+s+back)[::-1]) 
    else:
        print(sent+s+back)

if __name__=="__main__":
    main()          


Fixed code:
def main():
    s=input()
    q=int(input())
    queryy=[]
    sent="a"
    back="a"
    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    sent+=str(query[2])
                   # s=str(query[2])+s
                else:
                    back+=str(query[2])
                   # s+=str(query[2])
                    
            else:
                if check==-1:
                    back+=str(query[2])
                    #s+=str(query[2])
                else:
                    sent+=str(query[2])
                    #s=str(query[2])+s
   # print(type(sent))
    #if sent[0]=="1":
     #   sent=sent[1:]
    sent=sent[1:]
    sent=sent[::-1]   
    back=back[1:]

    if check==1:
        s=sent+s+back        
        print(s[::-1]) 
    else:
        s=sent+s+back
        print(s)

if __name__=="__main__":
    main()