Problem:


Score : 400 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

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

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

If T_i = 1: reverse the string S.

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

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

T_i = 1 or 2.

F_i = 1 or 2, if provided.

C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

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

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Sample Input 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

cpa

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

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

Operation 2: Reverse S. S becomes ap.

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

Operation 4: Reverse S. S becomes cpa.

Thus, the resulting string is cpa.

Sample Input 2

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

Sample Output 2

aabc

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

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy



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


Sample output:
cpa

Submission status: Wrong Answer

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

s = input()
q = int(input())
par = 0
pre = ""
pos = ""

for i in range(q):
  t = input().split()
  if t[0] == "1":
    par += 1
  elif (par + int(t[1]))%2 == 1:
    pre = t[2] + pre
  else:
    pos = pos + t[2]
    
ans = pre + s + pos

if par%2 == 0:
  print(ans)
else:
  print(ans[::-1])

Submission status: Wrong Answer

Solution code:
def main():
    c = 0
    s = input()
    f = ''
    b = ''
    for _ in range(int(input())):
        q = input().split()
        if q[0] == '1':
            c += 1
        else:
            if (q[1] == '1' and c%2 == 0) or (q[1]=='2' and c%2==1):
                f = q[2] + f
            else:
                b += q[2]
    if c % 2:
        print(f+s+b)
    else:
        print(b[::-1]+s[::-1]+f[::-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    c = 0
    s = input()
    for _ in range(int(input())):
        q = input().split()
        if q[0] == '1':
            c += 1
        else:
            if q[1] == '1':
                s = q[2] + s
            else:
                s += q[2]
    if c%2 == 0:
	    print(s)
    else:
        print(s[::-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

front = True

for i in condition:

    if i[0] == '1':
        front = not front

    elif i[0] == '2':
        if i[1] == '1':
            if front:
                S = i[2] + S
            else:
                S = S + i[2]
        elif i[1] == '2':
            if front:
                S = S + i[2]
            else:
                S = i[2] + S
print(S)

Submission status: Wrong Answer

Solution code:

import collections

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

rev = False
deque = collections.deque()
deque.append(S)
for _ in range(Q):
    read = input()
    if read == '1':
        rev = not rev
    else:
        _, f, c = read.split()
        if not rev:
            if f == '1':
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == '1':
                deque.append(c)
            else:
                deque.appendleft(c)

ret = ''.join(deque if not rev else reversed(deque))
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

from collections import deque

d = deque()
s = input()
d.append(s)
q = int(input())
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        d.reverse()
    else:
        if t[1] == "1":
            d.appendleft(t[2])
        else:
            d.append(t[2])

print("".join(d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

re=0
for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        re+=1    
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

rev_cnt = 0
flag = False
S_list = deque()
S_list.append(S)

for i in range(0, Q):
    op = [x for x in input().split()]
    if op[0] == '1':
        flag = (not flag)
        rev_cnt += 1
    else:
        if flag is False:
            if op[1] == '1':
                S_list.appendleft(op[2])
            else:
                S_list.append(op[2])
        else:
            if op[1] == '2':
                S_list.appendleft(op[2])
            else:
                S_list.append(op[2])
            flag = False

S_list = list(S_list)
if rev_cnt % 2:
    print("".join(S_list[::-1]))
else:
    print("".join(S_list))

Submission status: Wrong Answer

Solution code:

import collections

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

rev = False
deque = collections.deque()
deque.append(S)
for _ in range(Q):
    read = input()
    if read == '1':
        rev = not rev
    else:
        _, f, c = read.split()
        if f == '1':
            if not rev:
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if rev:
                deque.appendleft(c)
            else:
                deque.append(c)
ret = ''.join(deque if not rev else reversed(deque))
print(ret)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
s1 = ""
s2 = ""
cnt = 1
for i in range(q):
  l1 = list(input().split())
  if len(l1) == 1:
    cnt *= -1
  else:
    if (cnt == 1 and l1[1] == "1") or (cnt == -1 and l1[1] == "2"):
      s1 = l1[2] + s1
    else:
      s2 = s2 + l1[2]
if cnt == 1:
  print(s1+s+s2)
else:
  print(s2[::-1]+s+s1[::-1])

Submission status: Wrong Answer

Solution code:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
l = []
l2 = []
cnt = 1
for i in range(q):
  l1 = list(input().split())
  if len(l1) == 1:
    cnt *= -1
  else:
    if (cnt == 1 and l1[1] == "1") or (cnt == -1 and l1[1] == "2"):
      l.insert(0, l1[2])
    else:
      l2.append(l1[2])
if cnt == 1:
  print("".join(l)+s+"".join(l2))
else:
  print("".join(l2[::-1])+s+"".join(l[::-1]))

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]      

      
if flag == -1:
  s = s[::-1]

print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [input().split() for _ in range(q)]


flag = True
ans = deque()
ans.append(s)

for i in op:
    if i[0] == "1":
        flag = not flag
    else:
        if i[1] == "1":
            if flag:
                ans.appendleft(i[2])
            else:
                ans.append(i[2])
        else:
            if flag:
                ans.append(i[2])
            else:
                ans.appendleft(i[2])

if flag:
    while(ans):
        t = ans.popleft()
        print(t, end='')
else:
    while(ans):
        t = ans.pop()
        print(t, end='')

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    s = input()
    ans = deque([s])
    flag = False
    for i in range(int(input())):
        tmp = input()
        if len(tmp)==1:
            flag = not flag
        else:
            t,f,c = map(str, tmp.split())
            if f == '1':
                if not flag:
                    ans.appendleft(c)
                else:
                    ans.append(c)
            else:
                if not flag:
                    ans.append(c)
                else:
                    ans.appendleft(c)

    if not flag:
        while(ans):
            t = ans.popleft()
            print(t, end='')
    else:
        while(ans):
            t = ans.pop()
            print(t, end='')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
a = ""
b = ""
for i in range(q):
  l = list(input().split())
  if len(l) == 1:
    a, b = b, a
  else:
    if l[1] == "1":
      s = a + s
      a = l[2]
      if b == "":
        b = s
        s = ""
    else:
      s = s + b
      b = l[2]
      if a == "":
        a = s
        s = ""
print(a+s+b)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [list(map(str, input().split())) for _ in range(q)]


ans = deque()
ans.append(s)

flag = True

for i in op:
    if len(ans) <= 1 and i[0] == "1":
        continue
    elif i[0] == "1":
        flag = not flag
    else:
        if i[1] == "1":
            if flag:
                ans.appendleft(i[2])
            else:
                ans.append(i[2])
        else:
            if flag:
                ans.append(i[2])
            else:
                ans.appendleft(i[2])

if flag:
    while(ans):
        t = ans.popleft()
        print(t, end='')
else:
    while(ans):
        t = ans.pop()
        print(t, end='')

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [list(map(str, input().split())) for _ in range(q)]


ans = deque()
ans.append(s)

flag = True

for i in op:
    if i[0] == "1":
        flag = not flag
    if i[0] == "2":
        if i[1] == "1" and flag == 1:
            ans.appendleft(i[2])
        elif i[1] == "2" and flag == 1:
            ans.append(i[2])
        elif i[1] == "1" and flag == 0:
            ans.append(i[2])
        elif i[1] == "2" and flag == 0:
            ans.appendleft(i[2])

if flag:
    while(ans):
        t = ans.popleft()
        print(t, end='')
else:
    while(ans):
        t = ans.pop()
        print(t, end='')

Submission status: Wrong Answer

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

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



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

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



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

Submission status: Wrong Answer

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

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



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

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



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

Submission status: Wrong Answer

Solution code:
flag = True
S = input()
Q = int(input())
for i in range(Q):
  T = input().split()
  if T[0] == "1" :
    flag = not flag
  else:
    if flag:
      if T[1] == "1":
        S = T[-1] + S
      else:
        S = S + T[-1]
    else:
      if T[1] == "1":
        S = S + T[-1]
      else:
        S = T[-1] + S
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [input().split() for _ in range(q)]


ans = deque()
ans.append(s)

flag = True

for i in op:
    if i[0] == "1":
        flag = not flag
    if i[0] == "2":
        if i[1] == "1" and flag == 1:
            ans.appendleft(i[2])
        elif i[1] == "2" and flag == 1:
            ans.append(i[2])
        elif i[1] == "1" and flag == 0:
            ans.append(i[2])
        elif i[1] == "2" and flag == 0:
            ans.appendleft(i[2])

if flag == 1:
    print("".join(ans))
elif flag == 0:
    ans.reverse()
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for i in range(q):
    x = list(input().split())
    if len(x) == 3:
        if x[1] == '1':
            s.appendleft(x[2])
        else:
            s.append(x[2])
    else:
        a = s[0]
        b = s[-1]
        s.pop()
        s.popleft()
        s.append(a)
        s.appendleft(b)
print(*s, sep='')

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
op = [input().split() for _ in range(q)]


ans = deque()
ans.append(s)

end_flag = 1

for i in op:
    if i[0] == "1":
        if end_flag == 1:
            end_flag = 0
        elif end_flag == 0:
            end_flag = 1
    if i[0] == "2":
        if i[1] == "1" and end_flag == 1:
            ans.appendleft(i[2])
        elif i[1] == "2" and end_flag == 1:
            ans.append(i[2])
        elif i[1] == "1" and end_flag == 0:
            ans.append(i[2])
        elif i[1] == "2" and end_flag == 0:
            ans.appendleft(i[2])

if end_flag == 1:
    print("".join(ans))
elif end_flag == 0:
    ans.reverse()
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for i in range(q):
    x = list(input().split())
    if len(x) == 3:
        if x[1] == '1':
            s.appendleft(x[2])
        else:
            s.append(x[2])
    else:
        s[0], s[-1] = s[-1], s[0]
print(*s, sep='')

Submission status: Wrong Answer

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

for i in range(q):
    x = list(input().split())
    if len(x) == 3:
        if x[1] == '1':
            s.insert(0, x[2])
        else:
            s.append(x[2])
    else:
        s[0], s[-1] = s[-1], s[0]
print(*s, sep='')

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    s = input()
    ans = deque([s])
    flag = False
    for i in range(int(input())):
        tmp = input()
        if len(tmp)==1:
            flag = not flag
        else:
            t,f,c = map(str, tmp.split())
            if f == '1':
                if not flag:
                    ans.appendleft(c)
                else:
                    ans.append(c)
            else:
                if not flag:
                    ans.append(c)
                else:
                    ans.appendleft(c)
    if flag:
        ans.reverse()
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S=readline().rstrip()
from collections import deque
A=deque([S])
Q=int(readline())

cur=True
for i in range(Q):
  q=list(readline().rstrip().split())
  if q[0]=="1":
    cur^=True
  elif q[0]=="2":
    f,c=q[1],q[2]
    front=(f=="1")
    if (f=="1")^cur:
      A.append(c)
    else:
      A.appendleft(c)

A=list(A)
if not cur:
  A=A[::-1]
  
print("".join(A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-03-07 22:57:40 +0900
# LastModified: 2020-03-08 13:27:21 +0900
#


from collections import deque

def main():
    S=deque()
    tmp=input()
    S.append(tmp)
    Q=int(input())
    for _ in range(Q):
        query = input()
        if query[0]=='1':
            S.reverse()
        else:
            _,index,arg = query.split()
            if index=='1':
                S.appendleft(arg)
            else:
                S.append(arg)

    print(''.join(S))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s, h]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# print(s)
s = input()
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]

for t in query:
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      s = c+s
    else:
      s = s+c

print(s[::inv])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-03-07 22:57:40 +0900
# LastModified: 2020-03-08 13:22:46 +0900
#


from collections import deque

def main():
    S=deque()
    tmp=input()
    S.append(tmp)
    Q=int(input())
    for _ in range(Q):
        query = input()
        if query[0]=='1':
            S.reverse()
        elif query[0]=='2':
            _,index,arg = query.split()
            if index=='1':
                S.appendleft(arg)
            else:
                S.append(arg)

    print(''.join(S))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

S=readline().rstrip()
from collections import deque
A=deque([S])
Q=int(readline())

cur=True
for i in range(Q):
  q=list(readline().rstrip().split())
  if q[0]=="1":
    cur^=True
  elif q[0]=="2":
    f,c=q[1],q[2]
    if f=="1":
      if cur:
        A.appendleft(c)
      else:
        A.append(c)
    elif f=="2":
      if cur:
        A.append(c)
      else:
        A.appendleft(c)

A=list(A)
if not cur:
  A=A[::-1]
  
print("".join(A))

Submission status: Wrong Answer

Solution code:
S=input()
li=[S[i] for i in range(len(S))]
former=0
result=[former]
Q=int(input())
for i in range(Q):
    query=input().split()
    if len(query)==1:
        query_1=query
        result.reverse()
    else:
        query_2 = query
        if query_2[1]=="1":
            result.insert(0,query_2[2])
        else:
            result.append(query_2[2])
indexinfo=result.index(former)
result[indexinfo]="".join(li)
print("".join(result))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        # 反転処理
        if inversion_flg:
            if i[1] == "1":
                i[1] = 2
            else:
                i[1] = 1
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
        inversion_flg = False

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = 2
            else:
                i[1] = 1
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
flag = True
S = input()
Q = int(input())
for i in range(Q):
  T = input().split()
  if T[0] == "1":
    if flag == True:
      flag = False
    else:
      flag = True
  else:
    if flag == True:
      if T[1] == "1":
        S = T[-1] + S
      else:
        S = S + T[-1]
    else:
      if T[1] == "1":
        S = S + T[-1]
      else:
        S = T[-1] + S
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

ans = deque()
center_ans = []
center_ans.append(input())
for i in range(len(center_ans)):
    a = center_ans[i]
    ans.append(a)
q = int(input())

list_data = [ list(map(str,input().split(" "))) for i in range(q)]
#print(list_data)
re = 0
for i in range(q):
    list_a = list_data[i]
    #print(list_a)
    if list_a[0] == "1":
        re += 1
    elif list_a[0] == "2":
        if list_a[1] == "1":
            if re % 2 == 0:
                ans.appendleft(list_a[2])
            elif re % 2 == 1:
                ans.append(list_a[2])
        elif list_a[1] == "2":
            if re % 2 == 0:
                ans.append(list_a[2])
            elif re % 2 == 1:
                ans.appendleft(list_a[2])

if re % 2 == 1:
    ans.reverse()

print("".join(ans))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
query = []
for i in range(q):
    query.append(input().split())
f = False
c = 0
for i in range(q):
    if query[i][0] == '1':
        if f:
            c += 1
        else:
            f = True
            if c % 2 == 1:
                s = s[::-1]
    else:
        f = False
        c = 0
        if query[i][1] == '1':
             s = query[i][2] + s
        else:
            s += query[i][2]
if c % 2 == 1:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
# D - String Formation
s = input()
q = int(input())

fb = ['','']
odd = 0
for i in range(q):
    t,*fc = input().split()
    if t=='1': odd ^= 1 #t1
    else: #t2
        fb[odd & int(fc[0])] += fc[1]
        # if odd: #odd:reverse
        #     if fc[0]=='1': fb[1] += fc[1] #f1
        #     else: fb[0] += fc[1] #f2
        # else: #even
        #     if fc[0]=='1': fb[0] += fc[1] #f1
        #     else: fb[1] += fc[1] #f2

if odd: print(fb[1][::-1] + s[::-1] + fb[0])
else: print(fb[0][::-1] + s + fb[1])

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
q = int(input())
direction = 0
top = 99999
bottom = 99999 + len(s)
li = ["-1"] * 100000 + s  + ["-1"] * 100000
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        direction += 1
    elif (int(query[1]) + direction) % 2 == 0:
        bottom += 1
        li.insert(bottom, query[2])
    else:
        top -= 1
        li.insert(top, query[2])
s = [i for i in li if i!='-1']
if direction % 2 == 1:
    s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def main():
    ans=[]
    S=input()
    Q=int(input())
    query=[]
    for i in range(Q):
        li = input().split(' ')
        query.append(li)
    f=True
    ans.append(S)
    for i in range(Q):
        if(query[i][0]=='1'):
            f=not f
            continue
        else:
            F=query[i][1]
            C=query[i][2]
            
            if(f):
                if(F=='1'):
                    ans.insert(0,C)
                else:
                    ans.append(C)
            else:
                C=C[::-1]
                if(F=='1'):
                    ans.append(C)                    
                else:
                    ans.insert(0,C)                    
                    
    if(not f):
        ans=ans[::-1]
    s="".join(ans)
    print(s)


    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def main():
    ans=[]
    S=input()
    Q=int(input())
    query=[]
    for i in range(Q):
        li = input().split(' ')
        query.append(li)
    f=True
    ans.append(S)
    for i in range(Q):
        if(query[i][0]=='1'):
            f=not f
            continue
        else:
            F=query[i][1]
            C=query[i][2]
            
            if(f):
                if(F=='1'):
                    ans.insert(0,C)
                else:
                    ans.append(C)
            else:
                if(F=='1'):
                    ans.append(C)                    
                else:
                    ans.insert(0,C)                    
                    
    if(not f):
        ans=ans[::-1]
    s="".join(ans)
    print(s)


    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

ans = deque()
ans.append(input())
q = int(input())

list_data = [ list(map(str,input().split(" "))) for i in range(q)]
#print(list_data)
re = 0
for i in range(q):
    list_a = list_data[i]
    #print(list_a)
    if list_a[0] == "1":
        re += 1
    elif list_a[0] == "2":
        if list_a[1] == "1":
            for j in range(2, len(list_a)):
                if re % 2 == 0:
                    ans.appendleft(list_a[j])
                elif re % 2 == 1:
                    ans.append(list_a[j])
        elif list_a[1] == "2":
            for j in range(2, len(list_a)):
                if re % 2 == 0:
                    ans.append(list_a[j])
                elif re % 2 == 1:
                    ans.appendleft(list_a[j])

if re % 2 == 1:
    ans.reverse()

print("".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import *

def main():
    S = deque(list(input().split()))
    d = 0

    for i in range(int(input())):
        q = input().split()

        if len(q) == 1: d = not d
        else:
            if q[1] == '1': x = 0
            else: x = 1
            if d: x = not x
        
            if not x: S.appendleft(q[2])
            else: S.append(q[2])

    S = list(S)

    if d: S = S[::-1]
    print(''.join(S))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

ans = deque()
ans.append(input())
q = int(input())

list_data = [ list(map(str,input().split(" "))) for i in range(q)]

#print(list_data)
re = 0
for i in range(q):
    list_a = list_data[i]
    #print(list_a)
    if list_a[0] == "1":
        re += 1
    elif list_a[0] == "2":
        if list_a[1] == "1":
            if re % 2 == 0:
                ans.appendleft(list_a[2])
            elif re % 2 == 1:
                ans.append(list_a[2])
        elif list_a[1] == "2":
            if re % 2 == 0:
                ans.append(list_a[2])
            elif re % 2 == 1:
                ans.appendleft(list_a[2])

if re % 2 == 1:
    ans.reverse()

print("".join(ans))

Submission status: Wrong Answer

Solution code:
import collections

s = input()
q = int(input())
rev = 0
ans = collections.deque(['S'])

for _ in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    rev += 1
  else:
    if int(query[1]) == 1:      # 先頭
      if rev%2 == 0:
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:                       # 末尾
      if rev%2 == 0:
        ans.appendleft(query[2])
      else:
        ans.appendleft(query[2])

ans = ''.join(ans)
mes = ans.replace("S", s)
if rev%2 == 0:
  print(mes)
else:
  print(mes[::-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
s = str(input().rstrip())
ans = deque(list(s))

f = True
q = int(input())
for i in range(q):
    q = list(map(str, input().split()))
    if int(q[0]) == 1:
        f = not f
    else:
        f_i = int(q[1])
        if f_i == 1 ^ f:
            ans.appendleft(q[2])
        else:
            ans.append(q[2])
ans = "".join(list(ans))
if not f:
    ans = ans[::-1]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split()
ans = s
ans_top=[]
s = input().split()
q = int(s[0])
count = 0
for i in range(q):
    s = input().split()
    if s[0] == '1':
        count += 1
    else:
        if s[1] == '1':
            if count%2==0:
                ans_top = list(s[2])+ans_top
            else:
                ans.append(s[2])
        else:
            if count % 2 == 0:
                ans.append(s[2])
            else:
                ans_top = list(s[2])+ans_top
ans=ans_top+ans
if count % 2 == 1:
    ans=ans[::-1]
print(''.join(ans))