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

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
query=[]
reverseflg=False

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

for q in range(Q):
  if query[q][0]=="1":
    reverseflg= not reverseflg
  
  if query[q][0]=="2":
    if query[q][1]=="1":
      if reverseflg== True:
        S=query[q][2]+S
      else:
        S=S+query[q][2]
    
    else:
      if reverseflg== True:
        S=S+query[q][2]
      else:
        S=query[q][2]+S
        
if reverseflg==True:
  print(S)
else:
  print(S[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
S = input()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)
if not Front_flag:
    que.reverse()

ans = ''.join(que)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = input()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)
if not Front_flag:
    que.reverse()

for i in que:
    print(i, end='')

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        a = S.pop()
        b = S.popleft()
        S.append(b)
        S.appendleft(a)
    elif int(query[0]) == 2:
        if int(query[1]) == 1:
            S.appendleft(query[2])
        elif int(query[1]) == 2:
            S.append(query[2])

print(''.join(list(S)))

Submission status: Wrong Answer

Solution code:
s = list(input())
q = int(input())
query = [list(input().split()) for i in range(q)]

addPlace = 1
frontlist=[]
endlist=[]
for i in range(len(query)):
    if query[i][0] == "1":
        addPlace = -1 * addPlace
    else:
        if query[i][1] == "1" or (query[i][1] == "2" and addPlace == -1):
            frontlist.append(query[i][2])
        else:
            endlist.append(query[i][2])
s = frontlist[::-1] + s + endlist
if addPlace == 1:
    print("".join(s))
else:
    print("".join(s[::-1]))

Submission status: Wrong Answer

Solution code:
s = list(input())
q = int(input())
query = [list(input().split()) for i in range(q)]

addPlace = 1
for i in range(len(query)):
    if query[i][0] == "1":
        addPlace = -1 * addPlace
    else:
        if query[i][1] == "1" or (query[i][1] == "2" and addPlace == -1):
            s.insert(0, query[i][2])
        else:
            s.append(query[i][2])
if addPlace == 1:
    print("".join(s))
else:
    print("".join(s[::-1]))

Submission status: Wrong Answer

Solution code:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = b + s[i][2]
            else:
                a = s[i][2] + a
if c == 0:
    print(a + x + b)
else:
    print(''.join(list(reversed(b))) + x + ''.join(list(reversed(a))))

Submission status: Wrong Answer

Solution code:
x = input()
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
    
a = ""
b = ""
c = 0
for i in range(n):
    if s[i][0] == "1":
        c += 1
        c = c%2
    else:
        if c == 0:
            if s[i][1] == "1":
                a = s[i][2] + a
            else:
                b = b + s[i][2]
        else:
            if s[i][1] == "1":
                b = s[i][2] + b
            else:
                a = a + s[i][2]
if c == 0:
    print(a + x + b)
else:
    print(b + x + a)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    Q = int(input())
    queries = [input() for _ in range(Q)]

    reverse = False

    for e in queries:
        if e[0] == '1':
            reverse = not reverse
        else:
            T, F, C = e.split()
            if F == '2': F = True
            else: F = False

            if reverse ^ F:
                # 末尾に追加
                S += C
            else:
                continue
                # 先頭に追加
                # S = C + S
        # print(S)

    if reverse:
        S = S[::-1]

    print(S)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    Q = int(input())
    queries = [input() for _ in range(Q)]

    reverse = False

    for e in queries:
        if e[0] == '1':
            reverse = not reverse
        else:
            T, F, C = e.split()
            if F == '2': F = True
            else: F = False

            if reverse ^ F:
                continue
                # 末尾に追加
                # S += C
            else:
                continue
                # 先頭に追加
                # S = C + S
        # print(S)

    if reverse:
        S = S[::-1]

    print(S)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
parity = 0
ans = ["", ""]

for i in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        parity += 1
    else:
        f, c = tmp[1], tmp[2]
        ans[(parity + int(f)) % 2] += c

plt = ""

if parity % 2 == 1:
    p = -1
else:
    p = 1

plt += S[::p]

if p == 1:
    plt = ans[1] + plt + ans[0][::-1]
else:
    plt = ans[0] + plt + ans[1][::-1]

print(plt)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
parity = 0
ans = ["", ""]

for i in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        parity += 1
    else:
        f, c = tmp[1], tmp[2]
        ans[(parity + int(f)) % 2] += c

plt = ""

if parity % 2 == 1:
    p = -1
else:
    p = 1

plt += S[::p]

if p == 1:
    plt = ans[0][::-1] + plt + ans[1]
else:
    plt = ans[1][::-1] + plt + ans[0]

print(plt[::-1])

Submission status: Wrong Answer

Solution code:

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

is_reverse = False
before = ""
after = ""

for _ in range(q):
  lst = input().split()
  if lst[0] == "1":
    is_reverse = not is_reverse
  else:
    _, f, c = lst
    if f == "1":
      if not is_reverse:
        before = c + before
      else:
        after = after + c
    else:
      if not is_reverse:
        after = after + c
      else:
        before = c + before

if is_reverse:
  before, after = after[::-1], before[::-1]

print(before + s + after)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag) % 2].append(c)
    if flag:
        print(''.join(chain(reversed(H), S, T)))
    else:
        print(''.join(chain(reversed(T), reversed(S), H)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag) % 2].append(c)
    if flag:
        print(''.join(chain(reversed(H), S, T)))
    else:
        print(''.join(chain(reversed(T), S, H)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = [input()]
Q = int(input())
flag = 1

for i in range(Q):
    q = list(map(str, input().split()))
    if q==["1"]:
        flag *= -1
    else:
        if flag==1 and q[1]=="1":
            S = [q[2]]+S
        elif flag==1 and q[1]=="2":
            S.append(q[2])
        elif flag==-1 and q[1]=="1":
            S.append(q[2])
        else:
            S = [q[2]]+S
# print(S)

if flag!=1:
    S.reverse()

print("".join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque
# from math import factorial
# import collections
# import sys
# sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
# k = int(input())
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
#s = deque(input())
s = deque([input()])  
q = int(input())
count = 0
for i in range(q):
    query = list(input().split())
    if query[0] == "1":
        count += 1
    else:
        if count % 2 == 0:
            if query[1] == "1":
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if query[1] == "2":
                s.appendleft(query[2])
            else:
                s.append(query[2])
    # print(s)

if count % 2 == 1:
    for i in reversed(s):
        print(i, end="")
else:
    for i in s:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
# from math import factorial
# import collections
# import sys
# sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
# k = int(input())
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
#s = deque(input())
s = deque([input()])  
q = int(input())
count = 0
for i in range(q):
    query = list(input().split())
    if query[0] == "1":
        count += 1
    else:
        if count % 2 == 0:
            if query[1] == "1":
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if query[1] == "2":
                s.appendleft(query[2])
            else:
                s.append(query[2])
    # print(s)

if count % 2 == 0:
    for i in reversed(s):
        print(i, end="")
else:
    for i in s:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
# from math import factorial
# import collections
# import sys
# sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
# k = int(input())
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
s = deque([input()])
q = int(input())
count = 0
for i in range(q):
    query = list(input().split())
    if query[0] == "1":
        count += 1
    else:
        if count % 2 == 0:
            if query[1] == "1":
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if query[1] == "2":
                s.appendleft(query[2])
            else:
                s.append(query[2])

if count % 2 == 1:
    s.reverse()

for i in s:
    print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque([input()])
q = int(input())
count = 0
for i in range(q):
    query = list(input().split())
    if query[0] == "1":
        count += 1
    else:
        if count % 2 == 0:
            if query[1] == "1":
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if query[1] == "2":
                s.appendleft(query[2])
            else:
                s.append(query[2])

if count % 2 == 1:
    for i in reversed(s):
        print(i, end="")
else:
    for i in s:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()
    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])


count = 0
for i in range(n):
    if query[i][0] == 1:
        count += 1
    else:
        if query[i][1] == 1:
            if count % 2 == 0:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])
        else:
            if count % 2 == 0:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])


if count % 2 == 0:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()
    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])


count = 0
for i in range(n):
    if query[i][0] == 1:
        count += 1
    else:
        if query[i][1] == 1:
            if count % 2 == 0:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])
        else:
            if count % 2 == 0:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])


if count % 2 == 1:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
quest = [0]*q
state = 0
former, latter = '', ''
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            former = que[2] + former
        elif(state == 0 and que[1] == '2'):
            latter = latter + que[2]
        elif (state == 1 and que[1] == '1'):
            latter = latter + que[2]
        else:
            former = que[2] + former

if (state == 1):
    print(latter + s[::-1] + former)
else:
    print(former + s + latter)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()
    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])


count = 0
l = True
for i in range(n):
    if query[i][0] == 1:
        count += 1
    else:
        if (query[i][1] == 1 and count % 2 == 0) or (query[i][1] == 2 and count % 2 == 1):
            q.appendleft(query[i][2])
        else:
            q.append(query[i][2])

    


if count % 2 == 1:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()
    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])


count = 0
for i in range(n):
    if query[i][0] == 1:
        count += 1
    else:
        if count % 2 == 0:
            if query[i][1] == 1:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])
        else:
            if query[i][1] == 2:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])


if count % 2 == 1:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque()
S = input()
d.append(S)
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
 
for i in range(n):
    if s[i][0] == "1":
        d.reverse()
    else:
        if s[i][1] == "1":
            d.extendleft(s[i][2])
        else:
            d.extend(s[i][2])
 
print("".join(list(d)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution 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)
s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()
    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])


check = False
count = 0
for i in range(n):
    if query[i][0] == 1:
        check = True
        count += 1
    else:
        if check == False:
            if query[i][1] == 1:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])
        else:
            if query[i][1] == 2:
                q.appendleft(query[i][2])
            else:
                q.append(query[i][2])
            check = False


if count % 2 == 1:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
s= input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()

    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])

check = False
count = 0
for i in range(n):
    if query[i][0] == 1:
        check = True
        count += 1
    else:
        if check == False:
            if query[i][1] == 1:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])
        else:
            if query[i][1] == 2:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])
            check = False


if count % 2 == 1:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
s= input()
n = int(input())
q = deque([s])
query = []
for i in range(n):
    m = input()

    if m[0] == "1":
        query.append([int(m[0])])
    else:
        query.append([int(m[0]), int(m[2]), m[4]])

check = False
count = 0
for i in range(n):
    if query[i][0] == 1:
        check = True
        count += 1
    else:
        if check == False:
            if query[i][1] == 1:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])
        else:
            if query[i][1] == 2:
                q.append(query[i][2])
            else:
                q.appendleft(query[i][2])
            check = False


if count % 2 == 0:
    for i in reversed(q):
        print(i, end="")
else:
    for i in q:
        print(i, end="")

Submission status: Wrong Answer

Solution code:
s = str(input())
q = int(input())
querylist = []
for i in range(q):
  query = list(input().split( ))
  querylist.append(query)
qstrlist = [s]
for j in querylist:
  if j[0] == '1':
    qstrlist.reverse()
  elif j[0] == '2':
    if j[1] == '1':
      qstrlist.insert(0, j[2])
    elif j[1] == '2':
      qstrlist.append(j[2]) 
outstr = "".join(qstrlist)
print(outstr)

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
for q in range(Q):
    # 入力
    Q_list = list(input().split())
    
    # 操作
    if len(Q_list)==1:
        S[0], S[-1] = S[-1], S[0]
    elif (len(Q_list)==3) & (Q_list[1]=='1'):
        S.insert(0, Q_list[2])
    else:
        S.append(Q_list[2])

print(''.join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(list(input()))
cnt = 0
for _ in range(int(input())):
    q = list(input().split())
    flag = 1
    if q[0] == '1':
        cnt += 1
        if flag == 1:
            flag = -1
        else:
            flag = 1
    else:
        if q[1] == '1':
            if flag ==1:
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if flag ==1:
                s.append(q[2])
            else:
                s.appendleft(q[2])
s = ''.join(s)
print(s if cnt %2 == 0 else s[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(list(input()))
cnt = 0
for _ in range(int(input())):
    q = list(input().split())
    flag = 1
    if q[0] == '1':
        cnt += 1
        if flag == 1:
            flag = -1
        else:
            flag = 1
    else:
        if q[1] == '1':
            if flag ==1:
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if flag ==1:
                s.appendleft(q[2])
            else:
                s.append(q[2])
s = ''.join(s)
print(s if cnt %2 == 0 else s[::-1])

Submission status: Wrong Answer

Solution code:
import sys



prase = input()
q = int(input())
query = [None]*q

for i in range(q):
    query[i] = [n for n in input().split()]
counter =0
pr =""
pl =""

for i in range(1,q+1):
    if query[i-1][0] == "1":
        counter +=1

    else :
        if query[i-1][1] =="1" and counter%2 ==0:
            pl = query[i-1][2] + pl

        elif query[i-1][1] =="1" and counter%2 ==1:
            pr =  pr + query[i-1][2]

        elif query[i-1][1] =="2" and counter%2 ==0:
            pr = pr  + query[i-1][2]
        elif query[i-1][1] =="2" and counter%2 ==1 :
            pl  = query[i-1][2] + pl


if counter%2 ==0:
    print(pl+prase+pr)

else:
    pr = pr[::-1]
    pl = pl[::-1]
    print(pr + prase + pl)

Submission status: Wrong Answer

Solution code:
import sys



s = input()
q = int(input())
query = [None]*q

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

prase = s
pr = ""
pl = ""
counter =0

for i in range(1,q+1):
    if query[i-1][0] == "1":
        counter +=1

    else :
        if query[i-1][1] =="1" and counter%2 ==0:
            pl = pl + query[i-1][2]

        elif query[i-1][1] =="1" and counter%2 ==1:
            pr = pr + query[i-1][2]

        elif query[i-1][1] =="2" and counter%2 ==0:
            pr = pr + query[i-1][2]
        elif query[i-1][1] =="2" and counter%2 ==1 :
            pl = pl + query[i-1][2]



if counter%2 ==0:
    pl = pl[::-1]
    prase = pl + prase + pr
    print(prase)
    sys.exit()

else :
    pr = pr[::-1]
    prase = pr + prase + pl
    print(prase)

Submission status: Wrong Answer

Solution code:
import sys



s = input()
q = int(input())
query = [None]*q

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

prase = s
pr = ""
pl = ""
counter =0

for i in range(1,q+1):
    if query[i-1][0] == "1":
        counter +=1

    else :
        if query[i-1][1] =="1" and counter%2 ==0:
            pl = pl + query[i-1][2]

        elif query[i-1][1] =="1" and counter%2 ==1:
            pr = pr + query[i-1][2]

        elif query[i-1][1] =="2" and counter%2 ==0:
            pr = pr + query[i-1][2]
        else :
            pl = pl + query[i-1][2]



if counter%2 ==0:
    pl = pl[::-1]
    prase = pl + prase + pr
    print(prase)
    sys.exit()

else :
    pr = pr[::-1]
    prase = pr + prase + pl
    print(prase)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
#inp = [input().split() for _ in range(Q)]

# 無駄なところ除く

cnt = 0
for i in range(Q):
    inp = input().split()
    if len(inp) == 1:
        cnt += 1
        #S = S[::-1]
    else:
        if cnt % 2 != 0:
            S = S[::-1]
            cnt = 0
        f, c = inp[1:]
        if int(f) == 1:
            S = c + S
        else:
            S = S + c
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque(input())
flag = 0
for T_F_C in (input().split() for _ in range(int(input()))):
    if T_F_C[0] == '1':
        flag ^= 1
        continue
    _, f, c = T_F_C
    if (flag+int(f)) % 2:
        d.append(c)
    else:
        d.appendleft(c)
if flag:
    print("".join(d))
else:
    print("".join(reversed(d)))

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque(input())
flag = 0
for T_F_C in (input().split() for _ in range(int(input()))):
    if T_F_C[0] == '1':
        flag ^= 1
        continue
    _, f, c = T_F_C
    if flag ^ int(f):
        d.append(c)
    else:
        d.appendleft(c)
if flag:
    print("".join(d))
else:
    print("".join(reversed(d)))

Submission status: Wrong Answer

Solution code:
S=input()
st=S
Q=int(input())
q=[]
for _ in range(Q):
  q.append(input())
ls=[0]
t=0
for i in range(Q):
  if q[i]=="1":
    ls[-1]+=1
    t+=1
  else:
    T,F,C=q[i].split()
    if F=="1" and ls[-1]%2==0:
      st=C+st
    elif F=="2" and ls[-1]%2==0:
      st=st+C
    elif F=="1" and ls[-1]%2==1:
      st=st+C
    else:
      st=C+st
    ls.append(0)
if t%2==0:
  print(st)
else:
  print(st[::-1])

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    S=input()
    Q=int(input())
    A=[input().split() for _ in range(Q)]
    d=deque(S)
    for x in A:
        if x[0]=="1":
            d.reverse()
        else:
            if x[1]=="1":
                d.appendleft(x[2])
            else:
                d.append(x[2])

    print("".join(d))    

    print(-1)    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
S = input()
s = list(S)
d = deque()
for i in range(len(s)):
    d.append(s[i])
Q = int(input())
p = [[0 for i in range(3)]for j in range(Q)]
x = 1
for i in range(Q):
    p[i] = list(map(str,input().split()))
def add(s,x,f,c):
    if x ==1:
        if f == 1:
            s.appendleft(str(c))
        else:
            s.append(str(c))
    else:
        if f == 1:
            s.append(str(c))
        else:
            s.appendleft(str(c))
for i in range(Q):
    if int(p[i][0]) == 1:
        x = -x
    else:
        add(d,x,int(p[i][1]),p[i][2])
if x == 1:
    print(''.join(d))
else:
    s.reverse()
    print(''.join(d))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
q = [input() for i in range(Q)]
reverse = False
for i in range(0,Q,1):
    if q[i][0]=="1":
        reverse=not reverse

    elif q[i][0]=="2":
        num,F,C = q[i].split(sep=" ")
        print(F,C)
        if F=="1":
            if reverse == False:
                S=C+S
            else:
                S=S+C
        elif F=="2":
            if reverse == False:
                S=S+C
            else:
                S=C+S
if reverse:
    print(S[::-1])
else:
    print(S)

Submission status: Wrong Answer

Solution code:
import numpy as np
s = input()
q = int(input())
rbef = []
aft = []
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            rbef.append(qi[2])
        else:
            aft.append(qi[2])

'''
bef = ''.join(list(reversed(rbef)))
ans = bef+s+aft

if sgn == 1:
    print(ans)
else:
    rans = ''.join(list(reversed(ans)))
    print(rans)
'''

Submission status: Wrong Answer

Solution code:
import numpy as np
s = input()
q = int(input())
rbef = str()
aft = str()
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            rbef += qi[2]
        else:
            aft += qi[2]

'''
bef = ''.join(list(reversed(rbef)))
ans = bef+s+aft

if sgn == 1:
    print(ans)
else:
    rans = ''.join(list(reversed(ans)))
    print(rans)
'''

Submission status: Wrong Answer

Solution code:
import numpy as np
s = input()
q = int(input())
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            s = qi[2] + s
        else:
            s = s + qi[2]

'''
if sgn == 1:
    print(s)
else:
    news = ''.join(list(reversed(s)))
    print(news)
'''