Problem:


Score : 400 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

Starting with this string, he will produce a new one in the procedure given as follows.

The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:

If T_i = 1: reverse the string S.

If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.

If F_i = 1 : Add C_i to the beginning of the string S.

If F_i = 2 : Add C_i to the end of the string S.

Help Takahashi by finding the final string that results from the procedure.

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

1 \leq Q \leq 2 \times 10^5

T_i = 1 or 2.

F_i = 1 or 2, if provided.

C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Sample Input 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

cpa

There will be Q = 4 operations. Initially, S is a.

Operation 1: Add p at the beginning of S. S becomes pa.

Operation 2: Reverse S. S becomes ap.

Operation 3: Add c at the end of S. S becomes apc.

Operation 4: Reverse S. S becomes cpa.

Thus, the resulting string is cpa.

Sample Input 2

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Sample Output 2

aabc

There will be Q = 6 operations. Initially, S is a.

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy



Sample input:
a
4
2 1 p
1
2 2 c
1


Sample output:
cpa

Submission status: Wrong Answer

Solution code:
import sys

def ep(*params):
    print(*params,file=sys.stderr)

l = ''
r = ''

lc = ''
rc = ''

S = input().rstrip()

if len(S) > 1:
    l = S[0]
    r = S[-1]
    S = S[1:len(S)-1]
else:
    l = S[0]
    S = ''

Q = int(input())
for _ in range(Q):
    ope = list(input().split())
    if ope[0] == '1':
        (l,r) = (r,l)
    else:
        if ope[1] == '1':
            lc += l
            l = ope[2]
        else:
            rc += r
            r = ope[2]
    if r == '':
        tmp = l+lc+S+rc+r
        if len(tmp) == 2:
            l=tmp[0]
            r=tmp[1]
            lc=''
            s=''
            rc=''
    #print(l,lc[::-1],S,rc,r,sep=":",file=sys.stderr)    

print(l,lc[::-1],S,rc,r,sep="")

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    s = deque([list(input())])
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    s = deque([input()])
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s = list(s)[::-1]
    print(*s, sep="")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input().split())
Q = int(input())

judge = 1
for _ in range(Q):
    a, *b = map(str, input().split())

    if a == '1':
        judge ^= 1
    else:
        F = b[0]
        C = b[1]
        if ((judge==1) and (F=='1')) or ((judge==0) and (F=='2')):
            s.appendleft(C)
        else:
            s.append(C)
if judge:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input().split())
Q = int(input())

judge = 1
for _ in range(Q):
    a, *b = map(str, input().split())

    if a == '1':
        judge ^= 1
    else:
        F = b[0]
        C = b[1]
        if (judge==1 and F=='1') or (judge==0 and F=='2'):
            s.appendleft(C)
        else:
            s.append(C)
if judge:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input().split())
Q = int(input())

judge = 1
for _ in range(Q):
    a, *b = map(str, input().split())

    if a == '1':
        judge ^= 1
    else:
        F = b[0]
        C = b[1]
        if (judge==1 and F=='1') or (judge==0 and F=='2'):
            s.appendleft(C)
        else:
            s.append(C)
s = list(s)
if judge:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

Submission status: Wrong Answer

Solution code:
s = input()
Q = int(input()) #手順の数
n = len(s)

if n >= 3:
    tmp_s = s[1:-1]
    d_lead = s[0]
    d_end = s[-1]
elif n == 2:
    d_lead = s[0]
    d_end = s[-1]
else:
    d_lead = s[0]

flg = 0
flg_end = 0 #d_endが存在するかどうか
for _ in range(Q):
    a, *b = map(str, input().split())
    if int(a) == 1 and len(d_lead)!=0 and flg_end!=0:
        tmp_lead = d_lead[::-1]
        tmp_end = d_end[::-1]
        d_lead = tmp_end
        d_end = tmp_lead
        if n >= 3:
            tmp_s = tmp_s[::-1]
    elif int(a)==2:
        F = int(b[0])
        C = b[1]
        if F == 1:
            d_lead = C+d_lead
            if flg == 0 and flg_end == 0:
                d_end = d_lead[-1]
                d_lead = d_lead[0]
                flg = 1
                flg_end = 1
        else:
            if not flg_end:
                d_end = C
                flg_end = 1
            else:
                d_end += C
if n>= 3:
    print(d_lead + tmp_s + d_end)
else:
    if flg_end:
        print(d_lead + d_end)
    else:
        print(d_lead)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
Q = int(input()) #手順の数
n = len(s)
d_lead = deque()
d_end = deque()
if n >= 3:
    tmp_s = s[1:-1]
    d_lead.append(s[0])
    d_end.append(s[-1])
elif n == 2:
    d_lead.append(s[0])
    d_end.append(s[-1])
else:
    d_lead.append(s[0])


flg = 0
for _ in range(Q):
    a, *b = map(str, input().split())
    if int(a) == 1 and len(d_lead)!=0 and len(d_end)!=0:
        tmp_lead = d_lead.popleft()
        tmp_end = d_end.pop()
        d_lead.appendleft(tmp_end)
        d_end.append(tmp_lead)
    elif int(a)==2:
        F = int(b[0])
        C = b[1]
        if F == 1:
            d_lead.appendleft(C)
            if flg == 0 and len(d_end) == 0:
                tmp_lead = d_lead.pop()
                d_end.append(tmp_lead)
                flg = 1
        else:
            d_end.append(C)
d_lead = list(d_lead)
d_end = list(d_end)
if n >= 3:
    print(''.join(d_lead)+tmp_s+''.join(d_end))
else:
    print(''.join(d_lead)+''.join(d_end))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    s = deque(readline().rstrip().decode())
    q = int(readline())

    #dir=1のとき順方向 
    dir = 1
    for _ in range(q):
        txt = readline().rstrip().decode()
        if txt[0] == '1':
            dir ^= 1
        elif txt[0] == '2':
            f = txt[2]
            c = txt[4]
            if ((dir==1) and (f==1)) or ((dir==0) and (f==2)):
                s.appendleft(c)
            else:
                s.append(c)
    if dir!=1:
        print(''.join(reversed(s)))
    else:
        print(''.join(s))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    s = deque(readline().rstrip().decode())
    q = int(readline())

    #dir=1のとき順方向 
    dir = 1
    for _ in range(q):
        txt = readline().rstrip().decode()
        if txt[0] == '1':
            dir ^= 1
        elif txt[0] == '2':
            f = txt[2]
            c = txt[4]
            if ((dir==1) and (f==1)) or ((dir==0) and (f==2)):
                s.appendleft(c)
            else:
                s.append(c)
    if dir==1:
        print(''.join(reversed(s)))
    else:
        print(''.join(s))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
 
a = []
b = []
rev = 0
 
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        a, b = b, a
        rev += 1
    else:
        if q[1] == '1':
            a.append(q[2])
        else:
            b.append(q[2])
 
print(a)
print(b)
if rev % 2 == 1:
    S = S[::-1]
ans = ''.join(a[::-1]) + S + ''.join(b)
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
q = int(input())

k = 0 #0ならそのまま１なら反転
for i in range(q):
  t = list(input().split())
  if t[0] == '1':
    if k == 0:
      k = 1
    else:
      k = 0
  else:
    if (t[1] == 1 and k == 0) or (t[1] == 0 and k == 1):
      S.insert(0,t[2])
    else:
      S.append(t[2])
if k ==1:
  l = S[0]
  for i in range(1,len(S)):
    l += S[i]
  print(l)
else:
  l = S[len(S)-1]
  for i in range(1,len(S)):
    l += S[len(S)-1-i]
  print(l)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = int(input())

Q = [list(input().split()) for _ in range(N)]

count = 0
c = 0

ans_append = []
ans_insert = []

for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            ans_insert.append(q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            ans_append.append(q[2])


if count % 2  == 1:
    ans = ans_append[::-1] + S + ans_insert
    print("".join(ans))
else:
    ans = ans_insert[::-1] + S + ans_append
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0
for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2:
        S = Query[i][2] + S
      else:
        S = S + Query[i][2]
    else:
      if reverse % 2:
        S = S + Query[i][2]
      else:
        S = Query[i][2] + S
        
ans = ''
if reverse % 2:
  ans = S
else:
  for i in range(len(S)):
    ans = ans + S[len(S)-1-i]
  
print(ans)

Submission status: Wrong Answer

Solution code:
txt = input()
n = (int)(input())
count = 0
sentou = ""
saigo = ""
for i in range(n):
  temp = input()
  if temp[0] == '1':
    count += 1
  else:
    sec, moji = (int)(temp.split(" ")[1]), temp.split(" ")[2]
    if (sec + count) % 2 == 1:
      sentou = moji + sentou
    else:
      saigo += moji
if count % 2 == 1:
  txt = saigo[::-1] + txt + sentou[::-1]
else:
  txt = sentou + txt + saigo
print(txt)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[1] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[1]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[2] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[2]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
print(Query)
for i in Query:
    if i[0]=="1":
        S = S[::-1]
    else:
        if i[1]=="1":
            S = i[2]+S
        elif i[1]=="2":
            S = S+i[2]
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
ba = 1
for _ in range(Q):
  q = input().split()
  if len(q) == 1:
    ba *= -1
  else:
    T, F, C = q
    if (F == '1' and ba == 1) or (F=='2' and ba==-1):
      S = C + S
    elif (F == '2' and ba == 1) or (F=='1' and ba ==-1):
      S = S + C
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([input()])
Q = int(input())
is_reverse = False

for _ in range(Q):
  inp = input().split()
  if len(inp) == 1:
    if is_reverse:
      is_reverse = False
    else:
      is_reverse = True
  else:
    _, f, c = inp
    if f == '1':
      if is_reverse:
        S.append(c)
      else:
        S.appendleft(c)
    else:
      if is_reverse:
        S.appendleft(c)
      else:
        S.append(c)

if is_reverse:
  S.reverse()
  print("".join(S))
else:
  print("".join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([input()])
Q = int(input())

for _ in range(Q):
  inp = input().split()
  if len(inp) == 1:
    S.reverse()
  else:
    _, f, c = inp
    if f == '1':
      S.appendleft(c)
    else:
      S.append(c)

print("".join(S))

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
left = []
right = [s]
for i in range(qn):
    q = input()
    if q[0] == '1':
        left, right = right, left
    else:
        _, f, c = q.split()
        if f == '1':
            left.append(c)
        else:
            right.append(c)
print(''.join(left[::-1]) + ''.join(right))

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
right = []
left = [s]
for i in range(qn):
    q = input()
    if q[0] == '1':
        right, left = left, right
    else:
        _, f, c = q.split()
        if f == '1':
            left.append(c)
        else:
            right.append(c)
print(''.join(left[::-1]) + ''.join(right))

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
right = [s]
left = []
for i in range(qn):
    q = input()
    if q[0] == '1':
        right, left = left, right
    else:
        _, f, c = q.split()
        if f == '1':
            left.append(c)
        else:
            right.append(c)
print(''.join(left[::-1]) + ''.join(right))

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
right = [s]
left = []
for i in range(qn):
    qfc = input().split()
    if qfc[0] == '1':
        right, left = left, right
    else:
        if qfc[1] == '1':
            left.append(qfc[2])
        else:
            right.append(qfc[2])
print(''.join(left[::-1]) + ''.join(right))

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
right = [s]
left = []
for i in range(qn):
    qfc = input().split()
    if qfc[0] == '1':
        right, left = left, right
    else:
        if qfc[1] == '1':
            left.append(qfc[2])
        else:
            right.append(qfc[2])
print(''.join(left) + ''.join(right))

Submission status: Wrong Answer

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

a = []
b = []

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        a, b = b, a
    else:
        if q[1] == '1':
            a.append(q[2])
        else:
            b.append(q[2])

#print(a)
#print(b)
ans = ''.join(a[::-1]) + S + ''.join(b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = deque([s])

flag = True

for i in range(q):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a.appendleft(query[i][2])
        else:
            a.append(query[i][2])

b = list(a)
if not(flag):
    b.reverse()

print("".join(b))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = deque([s])

flag = True

for i in range(q):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a.appendleft(query[i][2])
        else:
            a.append(query[i][2])


if not(flag):
    deque.reverse(a)

print("".join(a))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = deque([s])

flag = True

for i in range(len(query)):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a.appendleft(query[i][2])
        else:
            a.append(query[i][2])


if not(flag):
    deque.reverse(a)

print("".join(a))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
q = [[i for i in input().split()] for j in range(Q)]

f = ""
l = ""
count = 0
for i in range(Q):
    if q[i][0] == "1":
        count += 1
    elif q[i][0] == "2":
        if q[i][1] == "1":
            if count % 2 == 0:
                f = f + q[i][2]
            else:
                l = l + q[i][2]
        else:
            if count % 2 == 1:
                f = q[i][2] + f
            else:
                l = l + q[i][2]
        
if count % 2 == 0:
    print(f+S+l)
else:
    print((f+S+l)[::-1])

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
results_forward = str("")
results_back = str("")
qlist = []
for i in range(q):
  qlist.extend(input().split(" "))

amount = 0
for i in range(len(qlist)):
  if qlist[i] == "1" or qlist[i] == "2":
    amount += int(qlist[i])
  elif amount%2 == 1:
    results_forward = qlist[i] + results_forward
    amount = 0
  elif amount%2 == 0:
    results_back = results_back + qlist[i]
    amount = 0

if q%2 == (len(results_forward)+len(results_back))%2:
  print(results_forward+s+results_back)
else:
  print((results_forward+s+results_back)[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
print("".join(list(sque)))

Submission status: Wrong Answer

Solution code:
# 2020/05/15
# AtCoder Beginner Contest 158 - D

# Input
s = input()
q = int(input())

rvflg = False
rstr = list()
lstr = list()

for i in range(q):
    l = list(input().split())
    t = int(l[0])

    if t == 1:
        rvflg = not rvflg
    else:
        f = int(l[1])
        c = l[2]
        if rvflg == False and f == 1:
            lstr.insert(0, c)
        elif rvflg == False and f == 2:
            rstr.append(c)
        elif rvflg == True and f == 1:
            rstr.append(c)
        elif rvflg == True and f == 2:
            lstr.insert(0, c)


if rvflg == False:
    ans = ''.join(lstr) + s + ''.join(rstr)
else:
    rstr.reverse()
    lstr.reverse()
    ans = ''.join(rstr) + s + ''.join(lstr)

print(ans)

'''
test = 'abcde'
atest = test[::-1]
print(atest)  # edcba
'''

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        t.append(que[i][0])
        f.append(que[i][1])
        c.append(que[i][2])
    else:
        t.append(que[i][0])
count = 0
for i in range(q):
    if t[i] == '1':
        s = s[::-1]
        print(t[i-1])
    else:
        if f[count] == '1':
            s = c[count] + s
            count += 1
        else:
            s += c[count]
            count += 1
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
swt = 0
for i in range(Q):
    letter = input()
    if letter == "1" and swt == 0:
        swt = 1
    elif letter == "1" and swt == 1:
        swt = 0
    else:
        m, F, C = letter.split()
        if F == 1 and swt == 0:
            S = C + S
        elif F == 1 and swt == 1:
            S = S + C
        elif F == 2 and swt == 0:
            S = S + C
        else:
            S = C + S
if swt == 1:
    S = ''.join(list(reversed(S)))
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
swt = 0
for i in range(Q):
    letter = input()
    if letter == "1" and swt == 0:
        swt = 1
    elif letter == "1" and swt == 1:
        swt = 0
    else:
        m, F, C = letter.split()
        if F == 0 and swt == 0:
            S = C + S
        elif F == 0 and swt == 1:
            S = S + C
        elif F == 1 and swt == 0:
            S = S + C
        else:
            S = C + S
if swt == 1:
    S = ''.join(list(reversed(S)))
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
queue = deque(S)

rev_cnt = 0
for i in range(Q):
  query = input().split()
  if query[0]=="1":
    rev_cnt += 1
  elif query[0]=="2":
    #print(query)
    rev = rev_cnt % 2
    s=query[2]
    if query[1] == "1" and rev == 0:
      queue.appendleft(s)
    elif query[1] == "1" and rev == 1:
      queue.append(s)
    elif query[1] == "2" and rev == 0:
      queue.append(s)
    elif query[1] == "2" and rev == 1:
      queue.appendleft(s)
if rev == 0:
  print(''.join(list(queue)))
else:
  print(''.join(reversed(list(queue))))

Submission status: Wrong Answer

Solution 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
    s=s[::-1]
   # print(type(sent))
    #if sent[0]=="1":
     #   sent=sent[1:]
    sent=sent[::-1]
    sent=sent[:len(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()

Submission status: Wrong Answer

Solution 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
    s=s[::-1]
   # print(type(sent))
    #if sent[0]=="1":
     #   sent=sent[1:]
    sent=sent[::-1]
    sent=sent[:len(sent)-1]
    if back[0]=="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()

Submission status: Wrong Answer

Solution 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+=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
    s=s[::-1]
   # print(type(sent))
    #if sent[0]=="1":
     #   sent=sent[1:]
    sent=sent[::-1]
    sent=sent[:len(sent)-1]
    if back[0]=="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()

Submission status: Wrong Answer

Solution 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+=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
    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:
        s=sent+s+back        
        print(s[::-1]) 
    else:
        s=sent+s+back
        print(s)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution 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:
        s=sent+s+back        
        print((s)[::-1]) 
    else:
        s=sent+s+back
        print(s)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution 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()

Submission status: Wrong Answer

Solution 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()

Submission status: Wrong Answer

Solution 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))
    sent=sent[1:]
    sent=sent[::-1]
    back=back[1:]

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

if __name__=="__main__":
    main()