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:
# -*- coding: utf-8 -*-

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

op1_cnt = 0
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1
    else:
        if op1_cnt % 2 != 0 and len(S) != 1:
            S = S[-1] + S[1:-1] + S[0]
        op1_cnt = 0
        t, F, C = query.split()
        if F == "1":
            S = C + S
        else:
            S = S + C

if op1_cnt % 2 != 0 and len(S) != 1:
    S = S[-1] + S[1:-1] + S[0]

print(S)

Submission status: Wrong Answer

Solution code:
S = list(map(str, input()))
q = int(input())
Q =[list(map(str, input().split())) for k in range(q)]
rev = False
f1 = []
f2 = []
def pls(n):
    global rev
    if n[0] == "1":
        rev = not rev
    else:
        if n[1] == "1":
            if rev:
                f2.append(n[2])
            else:
                f1.append(n[2])
        else:
            if rev:
                f1.append(n[2])
            else:
                f2.append(n[2])

for k in range(q):
    pls(Q[k])

if rev:
    Q.reverse()
    f2.reverse()
    ans = f2 + S + f1
else:
    Q.reverse()
    f1.reverse()
    ans = f1 + S + f2

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

Submission status: Wrong Answer

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

for i in range(Q):
    query = input().split()
    if len(query)==1:
        letter.reverse()
    else:
        if int(query[1])==1: #まえに追加
            letter.insert(0,query[2])
        else:
            letter.append(query[2])
print(''.join(letter))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
#query = [input().split() for _ in range(Q)]
rev = False
forw = ""
back = ""
for i in range(Q):
  query = input().split()
  if query[0] == "1":
    rev = not rev
  else:
    if (not rev and query[1] == "1") or (rev and query[1] == "2"):
      forw = query[2] + forw
    else:
      back += query[2]
S = forw + S + back
#print(S)
if rev:
  #print(S[::-1])
  for i in range(0,len(S), -1) :
    print(S[i], end="")
  #S = back[::-1] + S[::-1] + forw[::-1]
else:
  #S = forw + S + back
  print(S)

Submission status: Wrong Answer

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

for _ in range(q):
	t=input()
	if t[0]=="1":
		s.reverse()
	else:
		t,f,c=t.split()
		if f=="1":
			s.appendleft(c)
		else:
			s.append(c)
print(*s,sep="")

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
mae = ""
ushiro = ""
hanten = 0
check = 0
for i in range(q):
    l = list(map(str, input().split()))
    if l[0] == "1":
        hanten += 1
        check = 1
    else:
        if l[1] == "1":
            if check == 0:
                mae = l[2] + mae
            else:
                ushiro = ushiro + l[2]
        else:
            if check == 0:
                ushiro = ushiro + l[2]
            else:
                mae = l[2] + mae
        check = 0

ans = mae + s + ushiro
if hanten%2 == 1:
    ans = ans[::-1]

print(ans)

Submission status: Wrong Answer

Solution code:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = True
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s
        
#print(mode)
if mode:
    print(front[::-1] + s + back)
else:
    print(back + s[::-1] + front)

#s = front + s + back[::-1]

#for i in range(n):
#    print(qt[i],qf[i],qc[i])

#print(s)

Submission status: Wrong Answer

Solution code:
S = input() 
Q = int(input())
for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        pass
    else:
        if lists[1] == "2":
            S = S + lists[2]
        else:
            S = lists[2] + S
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    t.reverse()
print(ans)

Submission status: Wrong Answer

Solution code:
# 先頭と末尾を保ちつつ
from collections import deque

s = input()
q = int(input())
x, y = deque(), deque()
r = 0
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        r += 1
        x, y = y, x
    elif query[0] == "2":
        f, c = query[1], query[2]
        if f == "1":
            # if len(x) > 1:
            #     if r % 2 == 0:
            #         # x.appendleft(c)
            #         x.append(c)
            #     else:
            #         # x.append(c)
            #         x.appendleft(c)
            # else:
            #     if r % 2 == 0:
            #         # x.append(c)
            #         x.appendleft(c)
            #     else:
            #         # x.appendleft(c)
            #         x.append(c)
            x.appendleft(c)
        elif f == "2":
            # if len(y) > 1:
            #     if r % 2 == 0:
            #         # y.append(c)
            #         y.appendleft(c)
            #     else:
            #         # y.appendleft(c)
            #         y.append(c)
            # else:
            #     if r % 2 == 0:
            #         y.append(c)
            #         # y.appendleft(c)
            #     else:
            #         y.appendleft(c)
            #         # y.append(c)
            y.appendleft(c)
    # t = s
    # xx = x
    # yy = y
    # if r % 2 == 1:
    #     t = t[::-1]
    #     xx = reversed(x)
    #     yy = reversed(y)
    # print("".join(xx) + "+" + t + "+" + "".join(yy))


if r % 2 == 1:
    s = s[::-1]
    x = reversed(x)
    y = reversed(y)
print("".join(x) + s + "".join(y))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
query = []
is_normal = False
group1 = ""
group2 = ""
for i in range(Q):
    query = [x for x in input().split()]
    if query[0] == "1":
        is_normal = not is_normal
    else:
        if query[1] == "1" and is_normal:
            group1 = group1 + query[2]
        elif query[1] == "2" and is_normal:
            group2 = group2 + query[2]
        elif query[1] == "1" and not is_normal:
            group2 =  group2 + query[2]
        elif query[1] == "2" and not is_normal:
            group1 =  group1 + query[2]

if is_normal:
    out = "".join(list(reversed(group1))) + S + group2
else:
    out = "".join(list(reversed(group2))) + "".join(list(reversed(S))) + group1
print(out)

Submission status: Wrong Answer

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


def main():
    from collections import deque

    s = input()
    q = int(input())
    d = deque()
    d.append(s)

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

        if qi[0] == '1':
            d = deque(reversed(d))
        else:
            if qi[1] == '1':
                d.appendleft(qi[2])
            else:
                d.append(qi[2])

    print(''.join(map(str, d)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
q = int(input())
toggle = "ok"
top = ""
last = ""

for i in range(q):
    si = input().split()
    if si[0] == "1":
        if toggle == "ok":
            toggle = "re"
        else:
            toggle = "ok"
    else:
        if si[1] == "1" and toggle == "ok":
            top += si[2] 
        elif si[1] == "2" and toggle == "re":
            top += si[2] 
        elif si[1] == "1" and toggle == "re":
            last += si[2]
        elif si[1] == "2" and toggle == "ok":
            last += si[2]
if toggle == "ok":
    retop = ''.join(list(reversed(top)))
    print(retop, end="")
    print(s,end="")
    print(last,end="")
else:
    relast = ''.join(list(reversed(last)))
    print(relast,end="")
    print(s,end="")
    print(top,end="")

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
count = 0
lr = ['', '']
for i in range(Q):
    TFC = input()
    if TFC[0] == '1':
        count += 1
    elif TFC[2] == '1':
        lr[count % 2] += TFC[4]
    else:
        lr[(count+1) % 2] += TFC[4]
if count % 2 == 0:
    # print(lr[0][::-1] + S + lr[1])
    print(str(reversed(lr[0])) + S + lr[1])
else:
    print(str(reversed(lr[1])) + str(reversed(S)) + lr[0])

Submission status: Wrong Answer

Solution code:
import array
def main():
  n=10**5
  s=input()
  q=int(input())
  rev=0
  l=n-1
  r=n+len(s)
  s=array.array('b',[0]*n+[ord(c) for c in s]+[0]*n)
  for _ in range(q):
    query=input().split()
    if(query[0]=='1'):
      rev=1-rev
    elif((int(query[1])+rev)%2==1):
      s[l]=ord(query[2])
      l-=1
    else:
      s[r]=ord(query[2])
      r+=1
  s=[chr(c) for c in s if c!=0]
  if rev==1:
    return ''.join(s[::-1])
  return ''.join(s)
print(main())

Submission status: Wrong Answer

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

for i in range(Q):
    q =  [ i for i in input().split(' ')]
    if len(q) == '1':
        if len(S) != 1:
            head = S[0]
            tail = S[-1]
            S = tail + S[1:-1] + head
    if len(q) > 1:
        if q[1] == '1':
            S = q[2] + S
        else:
            S = S + q[2]
print(S)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

s = raw_input()
qn = int(raw_input())
qs = [raw_input().split() for _ in xrange(qn)]

direction = 1
deq = collections.deque(s)
for q in qs:
    if q[0] == '1':
        direction *= -1
    else:
        _, side, ch = q
        side = -1 if side == '1' else +1
        if direction * side == 1:
            deq.appendleft(ch)
        else:
            deq.append(ch)

#print deq
ans = None
ln = len(deq)
if direction == 1:
    ans = ''.join(deq.pop() for _ in xrange(ln))
else:
    ans = ''.join(deq.popleft() for _ in xrange(ln))
print ans

Submission status: Wrong Answer

Solution code:
S = input()
Q=int(input())
Query=[S]
flag = True
for i in range(Q):
  x=input().split()
  if len(x)==1:
    flag = not flag
  else:
    if flag:
      if x[1]=="1":
        Query=[x[2]]+Query
      else:
        Query.append(x[2])
    else:
      if x[1]=="1":
        Query.append(x[2])
      else:
        Query=[x[2]]+Query
if flag==False:
  Query.reverse()

print("".join(Query))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
ARR = []
TOTAL1 = 0
for i in range(Q):
    arr = input().split(" ")

    if int(arr[0]) == 1:
        TOTAL1 = TOTAL1 + 1
    ARR.append(arr)

def calculate(s,q,arr,total1):

    current1Sums = 0

    s = list(s)
    for ar in arr:
        if int(ar[0]) == 1:
            current1Sums = current1Sums + 1

        if int(ar[0]) == 2:
            nokoru1Sums = total1 - current1Sums

            if int(ar[1]) == 1:
                if nokoru1Sums % 2 == 0:
                    s.insert(0,ar[2])
                else:
                    s.append(ar[2])
            else:
                if nokoru1Sums % 2 == 0:
                    s.append(ar[2])
                else:
                    s.insert(0, ar[2])

    print("".join(s))



calculate(S,Q,ARR,TOTAL1)

Submission status: Wrong Answer

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

reverseCount = 0
for count in range(Q):
    T = list(map(str,input().split()))
    if int(T[0]) == 1:
        reverseCount +=1
    else:
        if reverseCount > 0:
            if reverseCount % 1  == 0:
                reverseCount = 0
                S = S[::-1]
        if int(T[1]) == 1:
            S = T[2] + S
        else:
            S = S + T[2]
print(S)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
inv = 1
for i in range(q):
  t = input()
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if f =='1' and inv == 1:
      s = c+s
    else:
      s = s+c

print(s[::inv])

Submission status: Wrong Answer

Solution code:
from sys import stdin
def toku():
  input = stdin.readline
  S = input()
  Q = int(input())
  s = [S[0]]
  A = []
  count = 0
  for i in range(Q):
    A += [input().split()]
  for i in range(Q):
    if int(A[i][0]) == 2:
      if count % 2 == 1:
        s = s[::-1]
      count = 0
      if int(A[i][1]) == 1:
        s = [A[i][2]] + s
      else:
        s = s + [A[i][2]]
    else:
      count += 1
      if i == Q-1:
        if count % 2 == 1:
          s = s[::-1]


  result = ''.join(s)
  print(result)
toku()

Submission status: Wrong Answer

Solution code:
def switch(S):
    tmp = S[0]
    S[0] = S[-1]
    S[-1] = tmp
    return S


def d():
    S = list(str(input()))
    Q = int(input())

    for i in range(Q):
        # print(S)
        q = list(input().split())

        if q[0] == '1':
            S = switch(S)
        elif q[0] == '2':
            if q[1] == '1':
                S.insert(0, q[2])
            elif q[1] == '2':
                S.append(q[2])
            else:
                raise ValueError(
                    'F({}) is {}, which is invalid!'.format(i, q[1]))
        else:
            raise ValueError('T({}) is {}, which is invalid!'.format(i, q[0]))

    print(''.join(S))


##########
d()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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


print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])
if hanten % 2 == 1:
    t.reverse()
ans = ''.join(t)

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def main():
    S = list(input())

    Q = int(input())

    for _ in range(Q):
        a = tuple(input().split())
        if a[0] == "2":
            if a[1] == "1":
                S.insert(0, a[2])
            else:
                S.append(a[2])
        else:
            S[0], S[-1] = S[-1], S[0]

    print("".join(S))

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
sss=input()
q=int(input())
idx=-1
query=[]
for i in range(q):
    s=input()
    if s!="1" and idx==-1:
        idx=i 
    if idx!=-1:
        query.append([i,s])
one=[]
c=0
for i in range(idx,len(query)):
    if query[i][1]=="1":
        c+=1
        one.append(c)
        #c+=1 
    else:
        one.append(c)
#print(query)
#print(one)
ss=one[-1]
one=[ss-x for x in one]
#print(one)
c=0

for x in query:
    if x[1]!="1":
        y=one[c]
        if y%2==0:
            if x[1][2]=='1':
                sss=x[1][4]+sss 
            else:
                sss=sss+x[1][4]
        else:
            if x[1][2]=='1':
                sss=sss+x[1][4] 
            else:
                sss=x[1][4]+sss
        c+=1 
print(sss)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
turn = 0
for i in range(Q):
  s = input().split()
  if s[0] == "1": # 反転
    turn += 1
  elif s[0] == "2": # 足す
    if (s[1] == "1" and turn % 2 == 0) or (s[1] == "2" and turn % 2 == 1):
      S = s[2] + S
    elif (s[1] == "2" and turn % 2 == 0) or (S[1] == "1" and turn % 2 == 1):
      S = S + s[2]
if turn % 2 == 0:
  print(S)
else:
  print(S[::-1])

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())
trans=0
aft=""
bef=""
for i in range(q):
  que=input()
  if que[0]=="1":
    trans=1-trans
  else:
    que=que.split()
    if (que[1]=="1" and trans==0) or (que[1]=="2" and trans==1):
      bef=bef+que[2]
    else:
      aft=aft+que[2]
if trans==0:
  l=len(bef)
  for i in range(l):
    print(bef[l-1-i],end="")
  print(s,end="")
  for i in range(len(aft)):
    print(aft[i],end="")
else:
  l=len(aft)
  for i in range(l):
    print(aft[l-1-i],end="")
  print(s,end="")
  for i in range(len(bef)):
    print(bef[i],end="")

Submission status: Wrong Answer

Solution code:
import sys
S = input()
Q = int(input())
bool = True
for i in range(0, Q-1):
	s = input()
	if s[0] == "1":
		bool = not bool
	else:
		if s[2] == "1":
			if bool:
				S = s[-1] + S
			else:
				S += s[-1]
		else:
			if bool:
				S += s[-1]
			else:
				S = s[-1] + S

def input():
    return sys.stdin.readline()
s = input()
if s[0] == "1":
	bool = not bool
else:
	if s[2] == "1":
		if bool:
			S = s[-1] + S
		else:
			S += s[-1]
	else:
		if bool:
			S += s[-1]
		else:
			S = s[-1] + S
                
if bool:
	print(S)
else:
	print(S[::-1])

Submission status: Wrong Answer

Solution code:
S = [input()]
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag % 2 == 0:         
            if q[1] == "1":
                S.insert(0,q[2])
            else:
                S.insert(-1,q[2])
        else:
            if q[1] == "1":
                S.insert(-1,q[2])
            else:
                S.insert(0,q[2])
if flag%2 == 0:
    S = "".join(S)
    print(S)
else:
    S = S[::-1]
    S = "".join(S)
    print(S)

Submission status: Wrong Answer

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

r = 0
sort = 0
for i in range(q):
  List=list(input().split())
  if len(List) > 1 :
    if List[1] == '1' and r == 0 :
      s = s + List[2] 
    elif List[1] == '1' and r == 1 :
      s = List[2] + s 
    elif List[1] == '2' and r == 0 :
      s = List[2] + s 
    elif List[1] == '2' and r == 1 :
      s = s + List[2] 
    r = 0
  else:
    sort += 1
    if r == 1 :
      r=0
    else:
      r=1



ans = ''
if sort % 2  == 0:
  print(s)
else:
  for j in range(len(s)):
    ans += s[len(s)-j-1:len(s)-j]

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
Y = [0, 0]
Z = ""

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

print(*S, sep="")

Submission status: Wrong Answer

Solution code:
s = input()
a = "*"
n = int(input())
kaitenn = 1

for i in range(n):
    q = input()
    if len(a) == 10:
        s = a[:a.index("*")]+s[::kaitenn]+a[a.index("*")+1:]
        a = "*"
    elif q[0] == "1":
        kaitenn *= -1
        a = a[::-1]
    else:
        if q[2] == "1":
            a = q[4] + a
        else:
            a = a + q[4]
            
print(a[:a.index("*")]+s[::kaitenn]+a[a.index("*")+1:])

Submission status: Wrong Answer

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

top = ""
tail = ""

rev = 1
#プラスで順列

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

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

Submission status: Wrong Answer

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

flag = False
add_after = ""
add_before = ""
for q_num in q_list:
    if int(q_num[0]) == 1:
        if flag == False:
            flag = True
        else:
            flag = False
    
    else:
        if int(q_num[1]) == 1 and flag == False or int(q_num[1]) == 2 and flag == True:
            add_before = q_num[2] + add_before
        else:
            add_after = add_after + q_num[2]

if flag:
    print(add_after[::-1] + s + add_before[::-1])
else:
    print(add_before + s + add_after)

Submission status: Wrong Answer

Solution code:
import sys
S = sys.stdin.readline()
Q = int(sys.stdin.readline())

mode = True

for _ in range(Q):
  TFC = list(map(str, sys.stdin.readline().split()))
  if "1" in TFC[0]:
    mode = not mode
    continue
  if mode:
    if "1" in TFC[1]:
      S = ''.join([TFC[2],S])
    else:
      S = ''.join([S,TFC[2]])
  else:
    if "1" in TFC[1]:
      S = ''.join([S,TFC[2]])
    else:
      S = ''.join([TFC[2],S])
        
if mode:
  print(S)
  exit()
print(S[::-1])

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    s = ns()
    Q = ni()

    T1 = 0
    FrontS = ""
    BackS = ""
    for _ in range(Q):
        T = stdin.readline().split()
        if T[0] == "1":
            T1 += 1
        else:
            if T1 % 2 == 0:
                # これは元通り
                if T[1] == "1":
                    FrontS = T[2] + FrontS
                else:
                    BackS += T[2]
            else:
                # これは逆向き
                if T[1] == "1":
                    BackS = T[2] + BackS
                else:
                    FrontS += T[2]
    
    if T1 % 2 == 0:
        print(FrontS + s + BackS)
    else:
        print(BackS + s[::-1] + FrontS)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
S = list(input())
n = int(input())
s = []
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
for i in range(n):
    if s[i][0] == "1":
        S.reverse()
    else:
        if s[i][1] == "1":
            S.insert(0,s[i][2])
        else:
            S.append(s[i][2])
 
print("".join(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

last = 1

for i in range(n):
    if l[i][0] == '1':
        last = last * -1
    else:
        s = l[i][2] + s
        sc += l[i][2]

if last > 0:
    print(s)
else:
    print(sc)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
S = input()
Q = int(input())

count = 0
ans = [S]

for i in range(Q):
    T = input().split()
    if len(T)==1:
        count+=1
        continue

    if count%2==0:
        if T[1] == '1': ans.insert(0, T[2])
        else: ans.append(T[2])
    else:
        if T[1] == '1': ans.append(T[2])
        else: ans.insert(0, T[2])


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

Submission status: Wrong Answer

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

sl = ['']*(q*2+2)
sl[q] = s
m = q-1
u = q+1
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        #s = ''.join([query[2], s])
        sl[m] = query[2]
        m -= 1

    elif query[0] == '2' and query[1] == '1' and rev:
        #s = ''.join([s, query[2]])
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and not(rev):
        #s = ''.join([s, query[2]])
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and rev:
        #s = ''.join([query[2], s])
        sl[m] = query[2]
        m -= 1

if rev:
    sl.reverse()
    print(''.join(sl))
else:
    print(''.join(sl))

Submission status: Wrong Answer

Solution code:
from collections import deque


d = deque()
S = input()
d.append(S)
q = int(input())

for i in range(q):
    query = input()
    if query == '1':
        if len(d) > 1:
            d.reverse()
    else:
        s_lis = query.split()
        n = int(s_lis[0])
        f = int(s_lis[1])
        c = s_lis[2]
        if f == 1:
            d.appendleft(c)
        else:
            d.append(c)

print("".join(d))

Submission status: Wrong Answer

Solution code:
S=[]
a=input()
S.append(a)
Q=int(input())
for i in range(Q):
    q=list(input().split())
    if int(q[0])==1:
        S.reverse()
    else:
        T=int(q[1])
        if T==2:
            S.append(q[2])
        else:
            S.insert(0,q[2])
S="".join(S)
print(S)

Submission status: Wrong Answer

Solution code:
s=input()
q = int(input())
toggle = "ok"
top = ""
last = ""

for i in range(q):
    si = input().split()
    if si[0] == "1":
        if toggle == "ok":
            toggle = "re"
        else:
            toggle = "ok"
    else:
        if si[1] == "1" and toggle == "ok":
            top += si[2] 
        elif si[1] == "2" and toggle == "re":
            top += si[2] 
        elif si[1] == "1" and toggle == "re":
            last += si[2]
        elif si[1] == "2" and toggle == "ok":
            last += si[2]
if toggle == "ok":
    retop = ''.join(list(reversed(top)))
    print(retop+s+last)
else:
    relast = ''.join(list(reversed(last)))
    print(relast+s+top)

Submission status: Wrong Answer

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

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=list(s)
gyaku_fig=False
for ll in l:
    if ll[0]=='1':
        if gyaku_fig==False:
            gyaku_fig=True
        elif gyaku_fig==True:
            gyaku_fig=False
    elif ll[0]=='2':
        if gyaku_fig==True:
            if ll[1]=='1':
                t_str=list(ll[2])+t_str
            elif ll[1]=='2':
                t_str+=list(ll[2])
        elif gyaku_fig==False:
            if ll[1]=='2':
                t_str=list(ll[2])+t_str
            elif ll[1]=='1':
                t_str+=list(ll[2])
if gyaku_fig==True:
    ans=''.join(t_str)
    print(ans)
else:
    t_str=t_str[::-1]
    ans=''.join(t_str)
    print(ans)
# t_str=s
# gyaku_fig=False
# for ll in l:
#     if ll[0]=='1':
#         if gyaku_fig==False:
#             gyaku_fig=True
#         elif gyaku_fig==True:
#             gyaku_fig=False
#     elif ll[0]=='2':
#         if gyaku_fig==True:
#             if ll[1]=='1':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='2':
#                 t_str+=ll[2]
#         elif gyaku_fig==False:
#             if ll[1]=='2':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='1':
#                 t_str+=ll[2]        
# if gyaku_fig==True:
#     print(t_str)
# else:
#     print(t_str[::-1])

Submission status: Wrong Answer

Solution code:
s = list(input())
n = int(input())
q = [list(map(str, input().split())) for _ in range(n)]

#print(q)

l = []
r = []
for i in range(n):
    if q[i][0] == "1":
        l, r = r[::-1], l[::-1]
    if q[i][0] == "2":
        if q[i][1] == "1":
            l = [q[i][2]] + l
        elif q[i][1] == "2":
            r = r + [q[i][2]]

ans = l + s + r

print("".join(ans))

Submission status: Wrong Answer

Solution code:
def switch(S):
    tmp = S[0]
    S[0] = S[-1]
    S[-1] = tmp
    return S


def d():
    S = list(str(input()))
    Q = int(input())

    for i in range(Q):
        # print(S)
        q = list(input().split())

        if q[0] == '1':
            S = switch(S)
        elif q[0] == '2':
            if q[1] == '1':
                S.insert(0, q[2])
            elif q[1] == '2':
                S.append(q[2])
            else:
                raise ValueError(
                    'F({}) is {}, which is invalid!'.format(i, q[1]))
        else:
            raise ValueError('T({}) is {}, which is invalid!'.format(i, q[0]))

    print(''.join(S))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
right = []
left = []
switch = 1
for _ in range(q):
    l = list(input().split())
    if l[0] == '1':
        switch *= -1
        left = left[::-1]
        right = right[::-1]
    else:
        if switch ==1:
            if l[1] == '1':
                left.append(l[2])
            else:
                right.append(l[2])
        else:
            if l[1] == '1':
                right.append(l[2])
            else:
                left.append(l[2])
lef = ''.join(left)
rig = ''.join(right)
if switch == -1:
    print(rig+s+lef)
else:
    print(lef+s+rig)

Submission status: Wrong Answer

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

S = str(input())
Q = int(input())
# print(S, Q)

S_copy = S
is_reverse = False
for i in range(Q):
    query = list(input().split())
    # print(query)
    if int(query[0]) == 1:
        # print("reverse")
        # Sを反転
        # S_copy = S_copy[::-1]
        is_reverse = not is_reverse
    else:
        if int(query[1]) == 1:
            # Sの先頭にC_iを追加
            # print("prepend C_i")
            if is_reverse:
                S_copy = S_copy + query[2]
            else:
                S_copy = query[2] + S_copy
        else:
            # Sの末尾にC_iを追加
            # print("append C_i")
            if is_reverse:
                S_copy = query[2] + S_copy 
            else:
                S_copy = S_copy + query[2]

print(S_copy)

Submission status: Wrong Answer

Solution code:
S = input() 
Q = int(input())
for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        pass
    else:
        S = S + lists[2]
print(S)