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:
S = input()
Q = int(input())

for i in range(Q):
    query = [list(map(str, input().split()))]

for i in query:
    if i[0] == '1':
        S = S[::-1]
    elif i[0] == '2':
        if i[1] == '1':
            S = i[2] + S
        elif i[1] == '2':
            S += i[2]

print(S)

Submission status: Wrong Answer

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

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

def addFirst(base, s):
    return s + base

def addLast(base, s):
    return base + s

def swap(a, b):
    return b,a

x, y = S, ""
for ls in qs:
    if ls[0] == "1":
        x, y = y, x
    else:
        if ls[1] == "1":
            x += ls[2]
        else:
            y += ls[2]

x = ''.join(list(reversed(x)))

print(x+y)

Submission status: Wrong Answer

Solution code:
S=input()
# Python3 program to Split string into characters 
def split(word): 
    return [char for char in word]  
def convert(s): 
  
    # initialization of string to "" 
    new = "" 
  
    # traverse in the string  
    for x in s: 
        new += x  
  
    # return string  
    return new 
      
      
# Driver code 
word = S
splits=split(S)
Q=int(input())
flipcounter=0
for i in range(0,Q):
  inputforround=input()
  if inputforround=='1':
    flipcounter=flipcounter+1
  else:
    T,F,C=map(str,inputforround.split())
    if (int(F)+flipcounter)%2==0:
      splits.insert(0,C)
    else:
      splits.append(C)
if flipcounter%2==0:
  splits.reverse()
ans=convert(splits)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys

def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]

    s = deque(s)
    r = 1
    for q in qs:
        if len(q) == 1:
            r = r * -1
        else:
            if q[1] == '1':
                if r == -1:
                    s.appendleft(q[2])
                else:
                    s.append(q[2])
            else:
                if r == -1:
                    s.append(q[2])
                else:
                    s.appendleft(q[2])

    s if r == -1 else s.reverse()
    print(''.join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
 
def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]
    s = deque(s)
    r = 1
 
    for q in qs:
        if len(q) == 1:
            r = r * -1
        else:
            if q[1] == 1:
                s.appendleft(q[2])
            else:
                s.append(q[2])
 
    s if r == -1 else s.reverse()
    print(''.join(s))
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

deque = deque([S])
for _ in range(Q):
  pack = input().split()

  T = int(pack[0])
  if T == 1:
    deque[0], deque[-1] = deque[-1], deque[0]

  if T == 2:
    F, C = int(pack[1]), pack[2]
    if F == 1:
      # 最初に追加するパターン
      deque.appendleft(C)
    if F == 2:
      # 最後尾に追加するパターン
      deque.append(C)

print("".join(deque))

Submission status: Wrong Answer

Solution code:
import sys

def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]

    r = 1
    for q in qs:
        if len(q) == 1:
            r = r * -1
        else:
            if q[1] == 1:
                s = q[2] + s
            else:
                s += q[2]

    if r == 1:
        print(s[::-1])
    else:
        print(s)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys

def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]
    s = deque(s)
    r = 1

    for q in qs:
        if len(q) == 1:
            r = r * -1
        else:
            if q[1] == 1:
                s.leftappend(q[2])
            else:
                s.append(q[2])

    s if r == -1 else s.reverse()
    print(''.join(s))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

S = deque(reversed(input().split()))
Q = int(input())
reverse = False
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    else:
        if query[1] == '1':
            if not reverse:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        else:
            if reverse:
                S.append(query[2])
            else:
                S.appendleft(query[2])
if reverse:
    print(''.join(list(S)))
else:
    print(''.join(list(reversed(S))))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = deque(reversed(input().split()))
Q = int(input())
reverse = False
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    else:
        right = query[1] == '1'
        if right == reverse:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if reverse:
    print(''.join(list(S)))
else:
    print(''.join(list(reversed(S))))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
    print(s , flag)
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Submission status: Wrong Answer

Solution code:
from collections import deque

S = deque(input().split())
Q = int(input())
reverse = False
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    else:
        right = query[1] == '1'
        if right == reverse:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if reverse:
    print(''.join(list(S)))
else:
    print(''.join(list(reversed(S))))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = deque(input().split())
Q = int(input())
reverse = True
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    else:
        right = query[1] == '1'
        if right == reverse:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if reverse:
    print(''.join(list(S)))
else:
    print(''.join(list(reversed(S))))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == 1 and flag :
            s.appendleft(x[4])
        elif x[2] == 2 and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in range(1, len(s)+1) :
        print(s[-i], end='')
else :
    for i in range(len(s)):
        print(s[i], end='')
print('')

Submission status: Wrong Answer

Solution code:
from collections import deque


reverse = False

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

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

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


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

Submission status: Wrong Answer

Solution code:
from collections import deque


reverse = False

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

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

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


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

Submission status: Wrong Answer

Solution code:
from collections import deque


reverse = False

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

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

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


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


print(answer_string)

Submission status: Wrong Answer

Solution code:
from collections import deque


reverse = False

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

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

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

if reverse==True:
    for _ in range(len(string)):
        left = string.popleft()
        string.append(left)

print(''.join(string))

Submission status: Wrong Answer

Solution code:
reverse = False

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

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

        if reverse==True:
            if head_or_tail==1:
                head_or_tail = 'tail'
            else:
                head_or_tail = 'head'
        
        else:
            if head_or_tail==2:
                head_or_tail = 'tail'
            else:
                head_or_tail = 'head'
        operates.append(head_or_tail)
        add_strings.append(add_string)

for i in range(len(operates)):
    operate = operates[i]
    add_string = add_strings[i]

    if operate=='head':
        string = add_string + string
    else:
        string = string + add_string


if reverse==True:
    string = string[::-1]

print(string)

Submission status: Wrong Answer

Solution code:
reverse = False

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

        if reverse==True:
            if head_or_tail==1:
                string = string + add_string
            else:
                string = add_string + string
        
        else:
            if head_or_tail==2:
                string = string + add_string
            else:
                string = add_string + string

if reverse==True:
    string = string[::-1]

print(string)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
head = 1
d = deque([S])

for _ in range(Q):
    q = input().split()
    if q[0]=='1':
        head = head*-1
    else:
        if q[1]=='1':
            h = head*1
        else:
            h = head*-1
        
        if h==1:
            d.appendleft(q[2])
        else:
            d.append(q[2])
if head == -1:
    d.reverse()

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

Submission status: Wrong Answer

Solution code:
A = input()
Q = int(input())
lis = [input() for i in range(Q)]


for i in range(Q):

    if len(lis[i].split()) == 1:
        for j in range(len(A)//2):
            A1 = list(A)
            A1[j],A1[len(A)-(j+1)] = A1[len(A)-(j+1)],A1[j]
            
        A = ""
        for j in range(len(A1)):
                A += A1[j]

    if len(lis[i].split()) == 3:

        if (lis[i].split())[1] == str(1):
            A = (lis[i].split())[2] + A

        if (lis[i].split())[1] == str(2):
            A = A + (lis[i].split())[2]

print(A)

Submission status: Wrong Answer

Solution code:

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

for i in range(q):
    l = []
    l = list(input().split())
    if l[0] == "1":
        tmp = ""
        tmp = s[0]
        s[0] = s[-1]
        s[-1] = tmp
    else:
        if l[1] == "1":
            s.insert(0,l[2])
        else:
            s.append(l[2])
print("".join(s))

Submission status: Wrong Answer

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

flag = 1
front = ""
back = ""

for i in range(q):
    t = query[i]
    if t == "1":
        flag *= -1
    else:
        dest = -int(t[2])*2+3
        tmp = t[4]
        if flag*dest == 1:
            front += tmp
        else:
            back += tmp
            
if flag == 1:
    s = front[::-1] + s + back
    print(s)
else:
    s = back[::-1] + s + front
    print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

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

left = []
right = []
rev = False
for i in range(Q):
    l = input().split()
    if l[0] == '1':
        rev = not rev
    else:
        if ( l[1] == '1' and not rev) or (l[1] == '2' and rev):
            left.append(l[2])
        else:
            right.append(l[2])

S = ''.join(left[::-1]) + S + ''.join(right)

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

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = []
for i in range(Q):
    Query.append(list(input().split()))
revodd = 0
full = 0
count = 0
for i in Query:
    if len(i) == 1:
        full += 1
for i in Query:
    if revodd < full:
        if len(i) == 1:
            revodd += 1
            count += 1
        else:
            if revodd % 2 == 1:
                if int(i[1]) == 1:
                    S = S + i[2]
                    count += 1
                else:
                    S = i[2] + S
                    count += 1
            else:
                if int(i[1]) == 1:
                    S = i[2] + S
                    count += 1
                else:
                    S = S + i[2]
                    count += 1
    else:
        S = S[::-1]
        break
for i in range(count, Q):
    if int(Query[i][1]) == 1:
        S = Query[i][2] + S
    else:
        S = S + Query[i][2]
print(S)

Submission status: Wrong Answer

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

def main():
    S = input()[:-1]
    Q = int(input())
    li = ['' for _ in range(2)]
    now = 0
    for _ in range(Q):
        x = input()
        if(x[0] == '2'):
            if(x[2]=='1'):
                li[1-now] += x[4]
            else:
                li[now] += x[4]
        else:
            now = 1-now

    print(li[1-now][::-1]+S+li[now])
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
 
s = deque(input())
q = int(input())
 
for _ in range(q):
  a = list(input().split())
  print(s)
  if a[0] == '1':
    s.reverse()
  else:  
    if a[1]=='1':
      s.appendleft(a[2])
    else:
      s.append(a[2])
      
print(''.join(s))  #リスト内の結合（''内のもので区切る）

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()

n = int(input())

#y = []
#for i in range(n):
#    x = input()
#    y.append(x)
#
#print(y)
#print(y[0].split())
for i in range(n):
    x = input()
    if int(x[0]) == 1:
        s = s[::-1]
    else:
        x = x.split()
        if int(x[1]) == 1:
            s = x[2] + s

        else:
            s = s + x[2]


print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for _ in range(q):
  a = input()

  if a[0] == '1':
    s.reverse()
  else:  
    if a[1]==1:
      s.appendleft(a[2])
    else:
      s.append(a[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=1
t = [input().split() for l in range(q)]
for i in range(q):
  if t[i][0]=='1':
    flag=flag*(-1)
  else:
    if t[i][1]=='1' and flag==1:
      d.appendleft(t[i][2])
    elif t[i][1]=='1' and flag==-1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==1:
      d.append(t[i][2])
    elif t[i][1]=='2' and flag==-1:
      d.appendleft(t[i][2])
if flag==-1:
  d.reverse()
d="".join(list(d))
print(d)

Submission status: Wrong Answer

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

Query=[]
for i in range(Q):
    Query.append(list(input().split()))
#print(Query)

check=1
for j in range(Q):
    if len(Query[j])==1:
        check*=-1      
        #print(S)
    else:
        if Query[j][1]=='1':
            if check==1:
                S=Query[j][2]+S
            else:
                S+=Query[j][2]
            #print(S)
        else:
            if check==1:
                S+=Query[j][2]
            else:
                S=Query[j][2]+S
            #print(S)

print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for i in range(len(ans)):
        print(ans[i],end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for i in range(len(ans)):
        print(i,end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

Submission status: Wrong Answer

Solution code:
from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for si in ans:
        print(si,end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

Submission status: Wrong Answer

Solution code:
s=[input()]
Q=int(input())

rev=-1
for i in range(Q):
    que=input().split()
    if que[0]=="1":
        rev*=-1
    else:
        if que[1]=="1":
            if rev>0:
                s.append(que[2])
            else:
                s=[que[2]]+s
        else:
            if rev<0:
                s.append(que[2])
            else:
                s=[que[2]]+s
if rev<0:
    print(*s)
else:
    print(*s[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]
countA,countB = 0,0
latter = []
former = []
for i in range(Q):
    if(Query[Q-i-1][0] == "1"):
        countA += 1
        countB += 1
    else:
        t = lambda x:1 if x=="1" else 0
        if((t(Query[Q-i-1][1])+countB)%2 == 1):
            former.append(Query[Q-i-1][2])
        else:
            latter.append(Query[Q-i-1][2])

for i in former:
    print(i,end="")
if(countA%2 == 0):
    print(S,end="")
else:
    for j in range(len(S)):
        print(S[len(S)-j-1],end="")
for i in latter:
    print(i,end="")

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]
countA,countB = 0,0
latter = []
former = []
for i in range(Q):
    if(Query[Q-i-1][0] == "1"):
        countA += 1
        countB += 1
    else:
        t = lambda x:1 if x=="1" else 0
        if((t(Query[Q-i-1][1])+countB)%2 == 1):
            former.append(Query[Q-i-1][2])
        else:
            latter.append(Query[Q-i-1][2])
print(former)
print(latter)
print(countA)

for i in former:
    print(i,end="")
if(countA%2 == 0):
    print(S,end="")
else:
    for j in range(len(S)):
        print(S[len(S)-j-1],end="")
for i in latter:
    print(i,end="")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

input = sys.stdin.readline


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


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

input = sys.stdin.readline


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


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

S = str(input())
Q = int(input())
query=[]
a=""
b=""
# for line in range(Q):
# 	query.append(list(input().split()))
t=True

for i in range(Q):
	q=list(input().split())
	if int(q[0])==1:
		t= not t
	else:
		if int(q[1])==1:
			if t:
				a=q[2]+a
			else:
				b=b+q[2]

		else:
			if t:
				b=b+q[2]
			else:
				a=q[2]+a

if t:
	print(a+S+b)
else:
	print(a[::-1]+S[::-1]+b[::-1])

Submission status: Wrong Answer

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

for i in range(q):
    q_i = input()
    if len(q_i) == 1:
        s = s[-1] + s[1:len(s)-1] + s[0]
    else:
        lis = [i for i in q_i.split()]
        if lis[1] == "1":
            s = lis[2] + s
        else:
            s += lis[2]

print(s)

Submission status: Wrong Answer

Solution code:
temp = input()
s = ["tikan"]
flag = "off"
q = int(input())
dummy = ""
for i in range(q):
  q_list = input().split()
  if q_list[0] == "1":
    if flag == "on":
      flag = "off"
    else:
      flag = "on"
  else:
    if q_list[1] == "1":
      if flag == "off":
        s.insert(0,q_list[2])
      else:
        s.append(q_list[2])
    else:
      if flag == "off":
        s.append(q_list[2])
      else:
        s.insert(0,q_list[2])
#  print(s)
ans = ""
for i in s:
  if i == "tikan":
    i = temp
    if flag == "on":
      i = list(i)
      i.reverse()
      i = "".join(i)
  ans += i
if flag == "on":
  ans = list(ans)
  ans.reverse()
  ans = "".join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
N = int(input())
S = []
for _ in range(N):
    S.append(input().split())

order = 1
for res in S:
    print(res)
    print(order)
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            s = res[2]+s
        else:
            s = s+res[2]
    else:
        if order == 1:
            s = s+res[2]
        else:
            s = res[2]+s

if order == -1:
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

Solution code:
s = input()
N = int(input())
S = []
for _ in range(N):
    S.append(input().split())

order = 1
for res in S:
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            s = res[2]+s
        else:
            s = s+res[2]
    else:
        if order == "1":
            s = s + res[2]
        else:
            s = res[2] + s

if order == -1:
    print(s[::-1])
else:
    print(s)

Submission status: Wrong Answer

Solution code:
temp = input()
s = ["tikan"]
flag = "off"
q = int(input())
dummy = ""
for i in range(q):
  q_list = input().split()
  if q_list[0] == "1":
    s.reverse()
    if flag != "on":
      flag = "off"
    else:
      flag = "on"
  else:
    if q_list[1] == "1":
      s.insert(0,q_list[2])
    else:
      s.append(q_list[2])
ans = ""
for i in s:
  if i == "tikan":
    i = temp
  ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
q = int(input())
dummy = ""
for i in range(q):
  q_list = input().split()
  if q_list[0] == "1":
    dummy = s[0]
    s[0] = s[-1]
    s[-1] = dummy
  else:
    if 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:
s = str(input())
q = int(input())

head = ''
back = ''
flg = 1
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == '1':
        head, back = back, head
        flg *= -1
    else:
        if i[1] == '1':
            head = i[2] + head
        else:
            back = back + i[2]

if flg == 1:
    print(head[::-1]+s[::-1]+back[::-1])
else:
    print(head + s+ back)

Submission status: Wrong Answer

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

head = ''
back = ''
flg = 1
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == '1':
        head, back = back, head
        flg *= -1
    else:
        if i[1] == '1':
            head = i[2] + head
        else:
            back = back + i[2]

if flg == 1:
    print(head[::-1]+s+back[::-1])
else:
    print(head + s+ back)

Submission status: Wrong Answer

Solution code:
from collections import deque

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