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:
from collections import deque

def string_formation(s, q_list):
    ans = deque()
    for x in s:
        ans.append(x)
    for query in q_list:
        # print(ans)
        count = 0
        if query[0] == '1':
            count += 1
            ans[0], ans[-1] = ans[-1], ans[0]
        else:
            if count % 2 == 1:
                ans[0], ans[-1] = ans[-1], ans[0]
            count = 0
            if query[1] == '1':
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
    print(''.join(ans))

    # ans = []
    # for x in s:
    #     ans.append(x)
    # for query in q_list:
    #     print(ans)
    #     count = 0
    #     if query[0] == '1':
    #         count += 1
    #         ans[0], ans[-1] = ans[-1], ans[0]
    #     else:
    #         if count % 2 == 1:
    #             ans[0], ans[-1] = ans[-1], ans[0]
    #         count = 0
    #         if query[1] == '1':
    #             ans = [query[2]] + ans
    #         else:
    #             ans = ans + [query[2]]
    # print(ans)

s = input()
q = int(input())
q_list = []
for _ in range(q):
    tmp = input().split()
    q_list.append(tmp)

string_formation(s, q_list)

Submission status: Wrong Answer

Solution 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':
            S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(ans))
else:
    print("".join(reversed(ans)))

Submission status: Wrong Answer

Solution code:
import time

from collections import deque

def string_formation(s, q_list):
    ans = deque()
    for x in s:
        ans.append(x)
    for query in q_list:
        print(ans)
        count = 0
        if query[0] == '1':
            count += 1
            ans[0], ans[-1] = ans[-1], ans[0]
        else:
            if count % 2 == 1:
                ans[0], ans[-1] = ans[-1], ans[0]
            count = 0
            if query[1] == '1':
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
    print(''.join(ans))

    # ans = []
    # for x in s:
    #     ans.append(x)
    # for query in q_list:
    #     print(ans)
    #     count = 0
    #     if query[0] == '1':
    #         count += 1
    #         ans[0], ans[-1] = ans[-1], ans[0]
    #     else:
    #         if count % 2 == 1:
    #             ans[0], ans[-1] = ans[-1], ans[0]
    #         count = 0
    #         if query[1] == '1':
    #             ans = [query[2]] + ans
    #         else:
    #             ans = ans + [query[2]]
    # print(ans)

t1 = time.time()

s = input()
q = int(input())
q_list = []
for _ in range(q):
    tmp = input().split()
    q_list.append(tmp)

string_formation(s, q_list)

t2 = time.time()
print(t2-t1)

Submission status: Wrong Answer

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

for _ in range(Q):
  T = list(input().split())

  if T[0] == '1':
    reverse_flag = not reverse_flag

  else:
    if (T[1] == '1' and reverse_flag) or (T[1] != '1' and (not reverse_flag)):
      S = T[2]+S

    else:
      S = S+T[2]
    reverse_flag = True 

print(S) if reverse_flag else print(S[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

S = str(input())
Q = int(input())
Query = [list(map(str, input().split())) for _ in range(Q)]

sArry = deque(S.split())
rFlag = False
for i in range(Q):
    if Query[i][0] == '1':
        sArry.reverse()
    else:
        if Query[i][1] == '1':
            sArry.appendleft(Query[i][2])
        else:
            sArry.append(Query[i][2])
#    print("  ", i, Query[i], "".join(sArry))


print("".join(sArry))

Submission status: Wrong Answer

Solution code:
s = input()
q_number = int(input())
 
queries = [input().split() for dummy in range(q_number)]
flag = 1
count = 0
for i in range(q_number):
  if queries[i][0] == "1": 
    flag = flag * -1
    count += 1
  else:
    if int(queries[i][1])*flag == 1 or -2:
      s = queries[i][2] + s
    else:
      s = s + queries[i][2]      

      
s = s[::-1]

print(s)

Submission status: Wrong Answer

Solution code:
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def S(): return input().rstrip()
def LIR(n): return [S().split() for i in range(n)]

def main():
    s = S()
    Q = I()
    Qu = LIR(Q)
    mode = 0; left = ''; right =  ''
    for que in Qu:
        if que[0] == '1': mode = (mode+1)%2
        else:
            if mode:
                if que[1] == '1': right = ''.join([right, que[2]])
                else: left = ''.join([que[2], left])
            else:
                if que[1] == '1': left = ''.join([que[2], left])
                else: right = ''.join([right, que[2]])
    if mode: print(right+s+left)
    else: print(left+s+right)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for _ in range(Q):
  T = list(input().split())

  if T[0] == '1':
    reverse_flag = not reverse_flag

  else:
    reverse_flag = True 
    if (T[1] == '1' and reverse_flag) or (T[1] != '1' and (not reverse_flag)):
      S = T[2]+S

    else:
      S = S+T[2]

print(S) if reverse_flag else print(S[::-1])

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
flag = False
head = ""
tail = ""
for i in range(q):
    query = input()
    if query[0] == "1":
        flag = not flag
    else:
        [t, f, c] = query.split()
        f = True if f == "1" else False
        if flag == f:
            head = c + head
        else:
            tail += c
s = head + s + tail
if not flag:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
s=deque(list(input().split()))
ans=""
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    #print("1",s)
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
        #print("2",s)
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
      #print("22",s)
if flag==False:
    s = list(reversed(s))

print("".join(map(str, s)))

Submission status: Wrong Answer

Solution code:
init = input()
num = int(input())

_strings = [''] * (num * 2 + 1)
_strings[num] = init

isReverse = False

fi = num - 1
li = num + 1

i = 0
while i < num:
    query = input().split()
    type = int(query[0])

    if type == 1:
        # _strings.reverse()
        isReverse = not isReverse
    else:
        mode = int(query[1])

        if (mode == 1 and not isReverse) or (mode == 2 and isReverse):
            _strings[fi] = str(query[2])
            fi -= 1
            # _strings.insert(0, str(query[2]))
        else:
            _strings[li] = str(query[2])
            li += 1
            # _strings.append(str(query[2]))
    i += 1

if isReverse:
    _strings.reverse()

print(''.join(_strings))

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            S.reverse()
        else:
            if f == '1':
                S.appendleft(c)
            else:
                S.append(c)
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
  from collections import deque
  import sys
  input = sys.stdin.readline
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()

Submission status: Wrong Answer

Solution code:

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

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
# slist = list(slist)
if isReversed:
    slist.reverse()

print("".join(slist))
# print(S)

Submission status: Wrong Answer

Solution code:
a=input()
q=int(input())
val=0
mae=""
usiro=""
for i in range(q):
    b=input().split()
    if b[0]=="1":
        val+=1
    else:
        if b[1]=="1":
            if val%2==0:
                usiro=b[2]+usiro
            else:
                mae+=b[2]
        else:
            if val%2==0:
                mae+=b[2]
            else:
                usiro=b[2]+usiro
if val%2==0:
    print(mae+a+usiro)
else:
    print((mae+a+usiro)[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
s=deque(list(input().split()))
ans=""
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    #print("1",s)
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
        #print("2",s)
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
      #print("22",s)
if not flag:
    s = list(reversed(s))

print("".join(map(str, s)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def main():
    s = input().strip()
    q = int(input())
    queries = [input().split() for _ in range(q)]
    pre = []
    post = []
    flg = True
    for query in queries:
        if query[0] == "1":
            flg = not flg
            continue
        if query[1] == "1":
            if flg:
                pre.append(query[2])
            else:
                post.append(query[2])
        else:
            if flg:
                post.append(query[2])
            else:
                pre.append(query[2])
    if not flg:
        s = s[::-1]
    pre.reverse()
    pre.append(s)
    pre.extend(post)
    s = "".join(pre)
    if not flg:
        s = s[::-1]
    print(s)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

F = []
L = []
rev = False
for i in range(Q):
  q = input()
  if q[0] == '1':
    rev = not rev
  else:
    if q[2] == '1' and rev or q[2] == '2' and not rev:
      L.append(q[4])
    else:
      F.append(q[4])
      
print(L[::-1]+S[::-1]+F[::-1] if rev else F+S+L)

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    S = deque(input().split())
    Q = int(input())

    hantei = 0
    
    for i in range(Q):
        QList = list(input().split())
    
        if QList[0] == '1':
            if hantei == 0:
                hantei = 1
            else:
                hantei = 0
        else:
            if QList[1] == '1':
                if hantei == 0:
                    S.appendleft(QList[2])
                else:
                    S.append(QList[2])
            else:
                if hantei == 0:
                    S.append(QList[2])
                else:
                    S.appendleft(QList[2])
    
    if hantei == 0:
        print("".join(list(S)))
    else:
        S.reverse()
        print("".join(list(S)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

s = deque([sys.stdin.readline().rstrip()])
q = int(input())
cnt = 0
for i in range(q):
    query = sys.stdin.readline().split()
    if query[0] == '1':
        cnt = (cnt + 1)%2
    else:
        if (int(query[1]) + cnt)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])

if cnt:
    s = "".join(s)[::-1]
print(s)

Submission status: Wrong Answer

Solution code:

def main2(s,x,q):
    res = s
    rev = 1 #-1なら反転中
    lstA = []
    lstB = []
    for op in q:
        if int(op[0]) == 1:
            rev = rev * -1
        elif int(op[1])*rev == 1 or int(op[1])*rev == -2:
            lstA.append(op[2])
        elif int(op[1])*rev == -1 or int(op[1])*rev == 2:
            lstB.append(op[2])
    if rev == 1:
        res = "".join(lstA[::-1])+res+"".join(lstB)
    else :
        res = "".join(lstB[::-1])+res+"".join(lstA)
    return res

s = input()
x = int(input())
q = [input().split() for _ in range(x)]
print(main2(s,x,q))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

S = input().split()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q = deque()
for s in S:
    q.append(s)

for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        F = int(F) - 1
        if state ^ F:
            q.append(C)
        else:
            q.appendleft(C)

ans = []
if state == 0:
    while q:
        ans.append(q.popleft())
else:
    while q:
        ans.append(q.pop())

print(*ans, sep='')

Submission status: Wrong Answer

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

count = 0
left = ""
right = ""
for query in P:
    if query[0]=="1":
        count+=1
    else:
        if query[1]=="1":
            if count%2==0:
                left+=query[2]
            else:
                right+=query[2]
        else:
            if count%2==0:
                right+=query[2]
            else:
                left+=query[2]
if count%2==1:
    S=left[::-1]+S[::-1]+right
    
print(S)

Submission status: Wrong Answer

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


inv = False
mae = []
usiro = []

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae.append(tmp[2])
    elif tmp[1] == '2' and not inv:
        usiro.append(tmp[2])
    elif tmp[1] == '1' and inv:
        usiro.insert(0,tmp[2])
    elif tmp[1] == '2' and inv:
        mae.insert(0,tmp[2])

    # print(mae,s,usiro)

ans = ''.join(mae) + s + ''.join(usiro)

if inv:
    ans = ans[::-1]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input().strip()
Q = int(input())
is_reverse = False
A = ""
B = ""
for i in range(Q):
  query = [j for j in input().strip().split()]
  T = int(query[0])
  if T == 1:
    is_reverse = not is_reverse
  else:
    F, C = int(query[1]), query[2]
    if F == 1:
      if not is_reverse:
        A = A + C
      else:
        B = B + C
    else:
      if not is_reverse:
        B = C + B
      else:
        A = C + A

res = A + S + B
if not is_reverse:
  print(res)
else:
  print(res[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])
    else:
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])

if revcnt % 2 == 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))

Submission status: Wrong Answer

Solution code:

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

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f=="1":
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
if isReversed:
    slist.reverse()

print("".join(slist))

Submission status: Wrong Answer

Solution code:
s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
c=""
d=""
if q<=10**5:
    for i in range(q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    if b==0:
        print(s)
    else:
        s= ''.join(list(reversed(s)))
        print(s)

else:
    for i in range(10**5):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    for i in range(10**5+1,q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    c=a[i][4]+c
                else:
                    d=d+a[i][4]
            else:
                if a[i][2]=="1":
                    d=d+a[i][4]
                else:
                    c=a[i][4]+c
    if b==0:
        print(c+s+d)
    else:
        c=''.join(list(reversed(c)))
        d=''.join(list(reversed(d)))
        s= ''.join(list(reversed(s)))
        print(d+s+c)

Submission status: Wrong Answer

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

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

right = ""
left = ""
for qu in query:
    if len(qu.split()) == 1:
        right, left = left, right
        continue
    num, f, c = qu.split()
    f = int(f)

    if f == 1:
        left += c
        
    else:
        right += c

print(left[::-1] + s + right)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

S = input()
Q = int(input())
# print("S:{}".format(S))
# print("Q:{}".format(Q))
query = []

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

# for i in query:
#     if len(i) == 1:
#         S = S[::-1]
#     else:
#         if i[1]=="1":
#             S = i[2]+S
#         else:
#             S += i[2]
# print(S)
left = True
for i in query:
    if len(i) == 1:
        left = not left
        print(left)
    else:
        if i[1]=="1":
            if left:
                S = i[2]+S
            else:
                S += i[2]
        else:
            if left:
                S += i[2]
            else:
                S = i[2]+S
if left:
    print(S)
else:
    print(S[::-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

querys = []
op1_cnt = 0
op2_cnt = 0
op2_C = {"1": [], "2": []}
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            args = op2_C["1"][::-1]
            args.extend(S)
            args.extend(op2_C["2"])
            S = ''.join(args)
            op2_C = {"1": [], "2": []}
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0 and len(S) != 1:
            args = [S[-1]]
            args.extend(S[1:-1])
            args.extend(S[0])
            S = ''.join(args)

        op1_cnt = 0

        t, F, C = query.split()
        op2_C[F].append(C)

if op1_cnt % 2 != 0 and len(S) != 1:
    args = [S[-1]]
    args.extend(S[1:-1])
    args.extend(S[0])
    S = ''.join(args)

if op2_cnt != 0:
    args = op2_C["1"][::-1]
    args.extend(S)
    args.extend(op2_C["2"])
    S = ''.join(args)


print(S)

Submission status: Wrong Answer

Solution code:
s=input()
a=[]
b=[]
now=0
q=int(input())
for i in range(q):
    x=list(input().split())
    if x[0]=="1":
        now=~now
    else:
        if now and x[1]=="2" or ~now and x[1]=="1":
            b.append(x[2])
        else:
            a.append(x[2])
if now:
    ans=a[::-1]+list(s)+b
    print(*ans,sep="")
else:
    ans=b[::-1]+list(s[::-1])+a
    print(*ans,sep="")

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.insert(0, d)
        else:
            S.append(d)
    print(S)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Submission status: Wrong Answer

Solution code:
from collections import deque

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

d = deque(S)
head = "l"

for _ in range(Q):
    q = input()
    if len(q) == 1:
        if head == "l":
            head = "r"
        else:
            head = "l"
    else:
        T, F, C = q.split()
        if F == 1:
            if head == "l":
                d.appendleft(C)
            else:
                d.append(C)
        else:
            if head == "l":
                d.append(C)
            else:
                d.appendleft(C)

print("".join(list(d)))

Submission status: Wrong Answer

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

for i in range(Q):
    X = list(input().split(" "))
    if int(X[0]) == 1:
        A = S[0]
        #S[0] = S[-1]
        #S[-1] = A
        S.insert(0, S[-1])
        S.append(A)
    elif int(X[0]) == 2 and int(X[1]) == 1:
        S.insert(0, X[2])
    elif int(X[0]) == 2 and int(X[1]) == 2:
        S.append(X[2])

print(*S, sep="")

Submission status: Wrong Answer

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

top = ""
tail = ""

rev = 1
#プラスで順列

for i in range(q):
    query = input()
    if query == "1":
        rev *= -1
    elif query[2] == "1":
        if rev == 1:
            top += query[4]
        else:
            tail += query[4]
    else:
        if rev != 1:
            top += query[4]
        else:
            tail += query[4]

if rev == 1:
    reversed(top)
    print(top + s + tail)
else:
    reversed(tail)
    reversed(s)
    print(tail + s + top)

Submission status: Wrong Answer

Solution code:
from collections import deque

d = deque(input())
q = int(input())

reverse = True

for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))

print("".join(d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

a = input().split()
q = int(input())
mode = 0
L = []
R = []

for _ in range(q):
    q_list = input().split()

    if q_list[0] == '1':
        if mode == 0:
            mode = 1
        else:
            mode = 0
    else:
        if q_list[1] == '1':
            if mode == 0:
                L.append(q_list[2])
            else:
                R.append(q_list[2])
        else:
            if mode == 1:
                L.append(q_list[2])
            else:
                R.append(q_list[2])

L = L[::-1]
r = L + a + R
if mode == 1:
    r = r[::-1]

result = ''.join(r)
print(result)

Submission status: Wrong Answer

Solution code:
a = input()
qn = int(input())

dir = 1

for q in range(qn):
  q = input()
  if q[0]=="1":
    dir = 1-dir
  else:
    d, f, c = q.split()
    if f=="1":
      if dir==1:
        a+=c
      else:
        a=c+a
    else:
      if dir==1:
        a=c+a
      else:
        a+=c

if dir==1:
  a = reversed(a)

print(''.join(list(a)))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input().split()
Q = int(input())

rev = True
out = deque(S)
for _ in range(Q):
    s = input().split()
    if s[0] == "1":
        rev = not(rev)
    else:
        t = s[0]
        f = s[1]
        c = s[2]
        if rev:
            if f == "1":
                out.appendleft(c)
            else:
                out.append(c)
        else:
            if f == "1":
                out.append(c)
            else:
                out.appendleft(c)

if not rev:
    out = reversed(out)
print("".join(out))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

T = 0
F = 2
C = 4

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

cnt = 0

front = ""
back = ""

for i in range(q):
    query = input()

    if query[T] == "1":
        cnt += 1
        continue

    # モード通常
    if cnt % 2 == 0:
        if query[F] == "1":
            front =  query[C] + front
        else:
            back = query[C] + back

    # モード反転
    else:
        if query[F] == "1":
            back = query[C] + back
        else:
            front =  query[C] + front


# print(cnt)
# print(front)
# print(s)
# print(back)

moji = front+s+back

if cnt % 2 == 0:
    # print(s)
    pass
else:
    moji = moji[::-1]
    # print(s[::-1])

# front = front[::-1]

# print(front,s,back)

print(moji)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
reverse = False

for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse = not reverse
    else:
        F, C = query[1:]
        if (F == "1" and not reverse) or (F == "2" and reverse):
            ans.appendleft(C)
        else:
            ans.append(C)

if reverse:
    ans.reverse()

print("".join(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

S=input()
Q=int(input())
Qs=np.zeros((Q,2))
qs=['']*Q
a=[]
for i in range(Q):
    a=input().split()
    #print(a)
    if int(a[0])==2:
        Qs[i][0]=int(a[0])
        Qs[i][1]=int(a[1])
        qs[i]=a[2] 
        #print("here")   
    else:
        Qs[i][0]=int(a[0])

que=[S]
for i in range(Q):
    if Qs[i][0]==1:
        tmp=que[0]
        que[0]=que[len(que)-1]
        que[len(que)-1]=tmp
    else:
        if Qs[i][1]==1:
            #que=qs[i]+que
            que.insert(0,qs[i])
        else:
            #que=que+qs[i]
            que.append(qs[i])
        
c=''
#print(que)
for i in range(len(que)):
    c=c+que[i]
print(c)

Submission status: Wrong Answer

Solution code:
S = list(input().rstrip())
Q = int(input().rstrip())


q = []
for n in range(Q):
  q.append(list(input().rstrip().split()))

#print(q)
def rev(olist):
  nlist  = olist[::-1]
  return nlist

def addhead(olist,ele):
  nlist = olist.insert(0,ele)
  return nlist
  
def addtail(olist,ele):
  nlist = olist.append(ele)
  return nlist
v = []
for n in range(Q):
  if q[n][0] == '1':
    S = rev(S)
  else:
    if q[n][1] == '1':
      S.append(q[n][2])
    else:
      S.insert(0,q[n][2])

print(''.join(S))

Submission status: Wrong Answer

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