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

sl = ['']*(q*4)

sl[q*2] = s
m = q*2-1
u = q*2+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:

s=input()
q=int(input())
turn_f = 0
while(q > 0):
    try:
        t, f, c=map(str, input().split())
        if turn_f == -1:
            s = s[::-1]
            turn_f =0
        if int(f) == 1:
            s = c + s
        elif int(f) == 2:
            s = s + c
    except:
        ~turn_f
    q-=1
print(s)

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:
            if len(S) > 1:
                S[0], S[-1] = S[-1], S[0]

    print("".join(S))

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
ss=deque()
s=list(input())
l=len(s)
for i in range(l):
    ss.append(s[i])
q=int(input())
info=[]
rev=[] #i回までに何回反転があるか
num=0
for i in range(q):
    info.append(list(input().split()))
moji=0 #文字の追加数
for i in range(q):
    if info[i][0]=="1":
        num+=1
    else:
        if info[i][1]=="2":
            rev.append([info[i][2],2,num]) #末尾
        else:
            rev.append([info[i][2],1,num])
        moji+=1
if num%2==1:
    ss.rotate(l-1)
#print(rev)
#print(num)
for i in range(moji):
    now=rev[i][1]
    if (num-rev[i][2])%2==1: #これが奇数だと２なら先頭になる
        #print("change")
        if rev[i][1]==2:
            rev[i][1]=1
        else:
            rev[i][1]=2
    if rev[i][1]==2:
        ss.append(rev[i][0])
    else:
        ss.appendleft(rev[i][0])
print("".join(ss))
#print(rev)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
ans = ""
l = ""
r = ""
c = 0
for _ in range(q):
  t = input().split()
  if t[0] == '1':
    c += 1
    a = l
    l = r
    r = a
  else:
    if t[1] == '1':
      l += t[2]
    else:
      r += t[2]
if c%2 ==0:
  print(l[::-1] + s[::-1] + r)
else:
  print(l[::-1] + s + r)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


class Solution:
    def main(self):
        s = input().rstrip()
        q = int(input())

        for i in range(q):
            tfc = list(input().split())
            if int(tfc[0]) == 1:
                if len(s) == 1:
                    continue
                k = len(s) // 2
                if len(s) % 2 == 0:
                    s = s[k:] + s[0:k]
                else:
                    s = s[k + 1:] + s[k] + s[0:k]
                continue
            if int(tfc[1]) == 1:
                s = tfc[2] + s
            else:
                s = s + tfc[2]

        print("".join(s))


# Run main
if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

Solution code:
#A,B = map(int,input().split())

a = input()
n = int(input())
mode = 1

for i in range(n):
    hoge = input().split()
    print(hoge)
    if hoge[0] == '1':
        mode = mode * -1
    else:
        if mode == 1:
            if hoge[1] == '1':
                a = hoge[2] + a
            else:
                a = a + hoge[2]
        else:
            if hoge[1] == '2':
                a = hoge[2] + a
            else:
                a = a + hoge[2]

if mode == -1:
    a = a[::-1]

print(a)

Submission status: Wrong Answer

Solution code:
S = input()
Q = list(map(int,input().split()))[0]

S1=S
S2=S
flg=1
count=0
for i in range(Q):
    Query = input().split()
    if Query[0]=='1':
        flg*=-1
        count+=1
        continue
    if flg==1:
        if Query[1]=='1':
            S2+=Query[2]
        else:
            S1+=Query[2]
    else:
        if Query[1]=='1':
            S1+=Query[2]
        else:
            S2+=Query[2]
print(S1, S2)
if count%2==1:
    print(S1[:-1]+S2)
else:
    print(S2[::-1]+S1.rstrip(S1[-1]))

Submission status: Wrong Answer

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------


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

r=0

a=""
z=""

for i in range(q):
	t = input()
	
	if t=='1':
		if r==0:
			r=1
		else:
			r=0
#		p("t,r,s",t,r,s)
		continue
	
	_,f,c = t.split()

	if r==0:
		if f=='2': z = z + c
		if f=='1': a = a + c
	else:
		if f=='2': a = a + c
		if f=='1': z = z + c

#	p("t,r,_,f,c,x,s","[",t,"]",r,_,f,c,x,s)

ans=""
if (r==0):
	ans = a[::-1] + s + z
else:
	ans = z[::-1] + s + a

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = deque([s])
for i in range(q):
    a = input()
    if len(a) == 1:
        ans.reverse()
    else:
        t, p, w = a.split()
        if p == "1":
            ans.appendleft(w)
        else:
            ans.append(w)
print("".join(ans))

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 r == 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=input()
Q=int(input())
for i in range(Q):
    r=input()
    if len(r.split()) == 3:
        T,F,C=r.split()
    else:
        T='1'
    if T == '1':
        l=list(S)
        tmp=l[0]
        l[0]=l[len(l)-1]
        l[len(l)-1]=tmp
        S="".join(l)
        continue
    if T == '2':
        if F == '1':
            S=C+S
        if F == '2':
            S=S+C

print(S)

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)

d_lis = list(d)

print("".join(d_lis))

Submission status: Wrong Answer

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

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

    for t in tmp:
        if len(t) == 1:
            s = s[::-1]
        else:
            f = int(t[1])
            c = t[2]
            if f == 1:
                s = c + s
            else:
                s = s + c

    print(s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

DQ = deque()
DQ.appendleft(S)


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

    if (len(q) == 1):
        # S = S[::-1]
        DQ.reverse()
    else:
        judge = q[1]
        cha = q[2]
        
        if (int(judge) == 1):
            DQ.appendleft(cha)
            
            # S = cha + S
        else:
            DQ.append(cha)
            
            # S = S + cha

ans = list(DQ)
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
arr = [list(input().split()) for i in range(q)]
mae1 = 0
count1 = 0
for i in arr:
    if i[0] == '1':
        mae1 += 1
        count1 += 1
    else:
        if mae1%2==0:
            if i[1] == '1':
                s = i[2] + s
            else:
                s = s + i[2]
        else:
            if i[1] == '1':
                s = s + i[2]
            else:
                s = i[2] + s
        mae1 = 0
if count1%2 != 0:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

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

for _ in range(n):
  q = input().split()
  if q[0] == "1":
    s = s[-1] + s[1:-1] + s[0]
  else:
    if q[1] == "1":
      s = q[2] + s
    else:
      s += q[2]
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
is_reversed = False
 
for i in range(Q):
    input_val = input().split()
    if input_val[0] == "1":
        is_reversed = not is_reversed
        continue
 
    if input_val[1] == "1":
        if is_reversed:
            S = input_val[2] + S
        else:
            S = S + input_val[2]
    else:
        if is_reversed:
            S = S + input_val[2]
        else:
            S = input_val[2] + S

if not is_reversed:
    print("".join(reversed(S)))
else:
    print(S)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
s = list(readline().strip())
n = int(readline())
q = sys.stdin.readlines()
length = len(s)
for qi in q:
    if qi[0] == '1':
        m1 = length // 2
        m2 = (length+1) //2
        s[:m1], s[m2:] = s[m2:], s[:m1]
    else:
        c = qi[4]
        length += 1
        if qi[2] == '2':
            s.append(c)
        else:
            s = [c] + s
print(''.join(s))

Submission status: Wrong Answer

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

for i in range(Q):
    command = list(input().split())
    if command[0] == "1":
        S[0], S[-1] = S[-1], S[0]
    if command[0] == "2":
        if command[1] == "1":
            S.insert(0, command[2])
        if command[1] == "2":
            S.append(command[2])
    #print(i+1, S)
print("".join(S))

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":
            x.appendleft(c)
        elif f == "2":
            if r % 2 == 1:
                y.appendleft(c)
            else:
                y.append(c)

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

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

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

print("".join(list(S)))

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]
if idx!=0:
    nn=idx+1 
    if nn%2!=0:
        sss=sss[::-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:
from collections import deque
s = list(input())
q = int(input())

for i in range(q):
    buf = input().split()
    if(len(buf) == 1):
        #s.reverse()
        continue
    else:
        if buf[1] == '1':
            s = deque(s)
            s.appendleft(buf[2])
            s = list(s)
        else:
            s.append(buf[2])

print("".join(s))

Submission status: Wrong Answer

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

ans = [s]

for t in ls:
    if t[0] == '1':
        ans = ans[::-1]
    elif t[0] == '2':
        if t[1] == '1':
            ans[0:0] = [t[2]]
        elif t[1] == '2':
            ans.append(t[2])

print("".join(ans))

Submission status: Wrong Answer

Solution code:
import math

s=input()
S=[]
S.append(s)
q=input()
Q=int(q)

#print(S,Q)

for i in range(Q):
  qu = input()
  #print(qu)
  T = int(qu[0])
  
  if T == 1:
    S.reverse()
  else:
    F = int(qu[2])
    if F == 1:
      S.reverse()
      S.append(qu[4])
      S.reverse()
      #print(S)
    else:
      S.append(qu[4])
  #print(S)
      
L="".join(S)
print(L)
#print(S)

Submission status: Wrong Answer

Solution code:
import sys
import math
#import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
li2= [str(x) for x in input().split()]

n=int(input())
x = [list(map(str, input().split())) for _ in range(n)] 

for i in range(n):
  if x[i][0]=='1':
    li2.reverse()   
  else:
    if x[i][1]=='1':
      li2.insert(0,x[i][2])
      
    else:
      li2.append(x[i][2])
      

mojiretu=''
for k in li2:
    mojiretu += k
print(mojiretu)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
from collections import deque

def solve():
    d = deque(list(input().split()))
    Q = int(input())

    is_reverse = False # 反転中か？

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    d.append(c)
                else:
                    # 先頭にcを追加
                    d.appendleft(c)
            else:
                if is_reverse:
                    # 先頭に追加
                    d.appendleft(c)
                else:
                    # 末尾に追加
                    d.append(c)

    if is_reverse:
        d.reverse()
        for moji in d:
            print(moji, end="")
    else:
        for moji in d:
            print(moji, end="")
    print()


def solve2():
    S = list(input().split())
    Q = int(input())
    M = 2*10**5+10
    data = [None]*M
    data.extend(S)
    data.extend([None]*M)
    left, right = M-1, M+len(S)

    is_reverse = False

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    data[right] = c
                    right += 1
                else:
                    # 先頭にcを追加
                    data[left] = c
                    left -= 1
            else:
                if is_reverse:
                    # 先頭に追加
                    data[left] = c
                    left -= 1
                else:
                    # 末尾に追加
                    data[right] = c
                    right += 1

    # 出力
    if is_reverse:
        for i in range(right-1, left, -1):
            print(data[i], end="")
    else:
        for i in range(left+1, right):
            print(data[i], end="")
    print()


if __name__ == "__main__":
    solve2()

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
re = False
front = []
back = []

for i in range(Q):
    t = input()
    
    if len(t) == 1:
        re = not re
        
    else:
        q, f, c = t.split()
        if (re == True and int(f) == 2) or (re == False and int(f) == 1):
            front.append(c)
        elif (re == True and int(f) == 1) or (re == False and int(f) == 2):
            back.append(c)

if not re:
    front.reverse()
    F = "".join(front)
    B = "".join(back)
    print(F + S + B)
else:
    back.reverse()
    F = "".join(front)
    B = "".join(back)
    print(B + S + F)

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    alist =[]
    anslist = []

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]
        anslist.append(ans)

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    anslist.append(i[2])
                else:
                    anslist.insert(0,i[2])

            else:
                if rev_count % 2 == 1:
                    anslist.insert(0,i[2])
                else:
                    anslist.append(i[2])

    print("".join(anslist))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
rev_flag = False
x_lis = []
y_lis = []
for _ in range(q):
    i = input()
    if i == '1':
        rev_flag = not rev_flag
    else:
        a,b,c = i.split()
        if rev_flag:
            if b == '1':
                #s = s + c
                y_lis.append(c)
            else:
                #s = c + s
                x_lis.append(c)
        else:
            if b == '1':
                #s = c + s
                x_lis.append(c)
            else:
                #s = s + c
                y_lis.append(c)
x = ''.join(reversed(x_lis))
y = ''.join(reversed(y_lis))
if rev_flag:
    print(''.join(list(reversed(x+s+y))))
else:
    print(x+s+y)

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:
            pass
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
query_list = []
for i in range(Q):
    query_list.append(input())
# print(S, Q, query_list)

M = 10 ** 6
start_position = int(M / 2)
left_position = start_position
right_position = start_position + len(S)
result = ["-"] * M
for i in range(len(S)):
    #print(i + left_position)
    result[i + left_position] = S[i]

#result = "".join(result[left_position:right_position])
#print(result)
#exit(0)
reverse_flag = False

for i in range(Q):
    # print(i + 1)
    q = query_list[i]
    # print(q)
    t = int(q[0])
    if t == 1:
        reverse_flag = not reverse_flag
    else:
        t, f, c = q.split()
        f = int(f)
        c = c
        if f == 1:
            if reverse_flag:
                result[right_position + 1] = c
                right_position += 1
            else:
                result[left_position - 1] = c
                left_position -= 1
        else:
            if reverse_flag:
                result[left_position - 1] = c
                left_position -= 1
            else:
                result[right_position + 1] = c
                right_position += 1
    # print(t, f, c, result)
    # print("--------")
if reverse_flag:
    result = result[::-1]
# result = str(result)
#result = "".join(result)
#print(result)
#print(result[left_position:right_position])

result = "".join(result[left_position:right_position])
print(result)

Submission status: Wrong Answer

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

# 文字列格納リスト
ans = [S]

# クエリ格納リスト
q_s = []

for i in range(Q):
  _q = list(map(str, input().split()))
  if _q[0] == "2":
    q_s.append(_q)
  elif _q[0] == "1":
    if len(q_s) > 0:
      if q_s[-1][0] == "1":
        del q_s[-1]
      else:
        q_s.append(_q)
    elif len(q_s) == 0:
      q_s.append(_q)
for i in q_s:
  if i[0] == "1":
    ans.reverse()
  elif i[0] == "2":
    if i[1] == "1":
      # 前に追加
      ans.insert(0,i[2])
    elif i[1] == "2":
      # 後ろに追加
      ans.append(i[2])
print("".join(ans))

Submission status: Wrong Answer

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

q_list = []

rev_c = 0
count = 0

for _ in range(q):
  v = input()
  q_list.append(v)
  if v == '1':
    rev_c += 1

for v in q_list:
  if v == '1':
    count += 1
  else:
    num = v[2]
    char = v[4]
    if ((rev_c-count)%2==0 and num=='1') or  ((rev_c-count)%2==1 and num == '2'):
      s = char + s
    else:
      s = s + char
print(s)

Submission status: Wrong Answer

Solution code:
S = list(input())
Q = int(input())
t_count = 0
before = []
after = []

for i in range(Q):
  list_ = list(input().split())
  T = int(list_[0])
  if T == 1:
    t_count += 1
  else:
    F, C = int(list_[1]), list_[2]
    if F == 1:
      if t_count%2 == 0:
        before.append(C)
      else:
        after.append(C)
    else:
      if t_count%2 == 0:
        after.append(C)
      else:
        before.append(C)
if t_count%2 == 1:
    S.reverse()
before.reverse()
S.extend(after)
before.extend(S)
if t_count%2 == 1:
  before.reverse() 
ans = ''.join(before)
print(ans)

Submission status: Wrong Answer

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

sl = ['']*(q*4)
print(sl)
sl[q*2] = s
m = q*2-1
u = q*2+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:

# -*- coding: utf-8 -*-

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

rev = False
S1 = ['0'] * Q
S1i = 0
S2 = ['0'] * Q
S2i = 0

for q in range(Q):
    i = input()
    if i[0] == "1":
        rev = not rev
    elif not rev and i[2] == "1" or rev and i[2] == "2":
        # S = i[4] + S
        S1[S1i] = i[4]
        S1i += 1
    else:
        # S = S + i[4]
        S2[S2i] = i[4]
        S2i += 1

S1 = S1[0:S1i]
S2 = S2[0:S2i]
S2 = S2[::-1]

S = ''.join([''.join(S2), S, ''.join(S1)])

if not rev:
    S = S[::-1]

print(S)

Submission status: Wrong Answer

Solution code:
#!python3

import sys
iim = lambda: map(int, input().rstrip().split())
from collections import deque

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

    rev = False
    for ti, *arg in (line.split() for line in sys.stdin):

        if ti == "1":
            rev = not rev
        else:
            fi, ci = arg
            fi = fi == "1"
            if fi ^ rev:
                S.appendleft(ci)
            else:
                S.append(ci)
    if rev:
        S.reverse()
    print(*S, sep="")


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def main():

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

    for i in range(Q):
        q = input().split()
        if q[0] == '1':
            S.reverse()
        elif q[0] == '2':
            if q[1] == '1':
                tmp = [q[2]]
                tmp.extend(S)
                S = tmp
            elif q[1] == '2':
                S.append(q[2])
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def Exchange(s):
    return s[len(s) - 1:] + s[1:len(s) - 1] + s[:1]

for i in range(q):
    querys = list(map(str, input().split()))
    #前後を反転
    if querys[0] == '1' and len(s) > 1:
        s = Exchange(s)
    else:
        #文字を付加
        if querys[1] == '1':
            s = querys[2] + s
        else:
            s = s + querys[2]
print(s)

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])
            elif a[1] == "2":
                S.append(a[2])
        elif a[0] == "1":
            if len(S) > 1:
                S[0], S[-1] = S[-1], S[0]

    print("".join(S))

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
S=list(input())
N=int(input())
for i in range(N):
    a=input().split()
    if a[0]=="1":
        S=S[::-1]
    else:
        if a[1]=="1":S.insert(0,a[2])
        else:S.append(a[2])
print("".join(S))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque

d=deque()

S = stdin.readline().rstrip().split()
Q = [int(x) for x in stdin.readline().rstrip().split()]

d.append(S[0])
#print(d)
for i in range(Q[0]):
  s=input().split()

  if len(s)==1:

      #S=S[::-1]
      #print(d)
      d.reverse()
      #print(d)

  else:
      if int(s[1])==1:
          d.appendleft(s[2])
          #print(d)
          #S.insert(0,s[2])


      else:
          d.append(s[2])
          #print(d)
          #S.append(s[2])
for i in range(len(d)):
  print(d[i],end="")

Submission status: Wrong Answer

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

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s.insert(0, q[2])
    else:
        s.append(q[2])


if div:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque
S=list(input())
Q=int(input())
Qlst=[list(input().split()) for _ in range(Q)]

len_S=len(S)
s0=deque(sorted(S[:len_S//2]))
s1=deque(S[len_S//2:])

if len_S%2!=0:
    mid=s1.popleft()
else:
    mid=''

fflag=0
for i in range(Q):
    q=Qlst[i]
    if q[0]=='1':
        fflag=abs(fflag-1)
        continue
    if q[1]=='1':
        if fflag==0:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.append(mid)
                mid=''
        else:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.append(mid)
                mid=''
    elif q[1]=='2':
        if fflag==0:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.append(mid)
                mid=''
        else:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.append(mid)
                mid=''

if fflag==0:
    s0.reverse()
    print(''.join(s0)+mid+''.join(s1))
else:
    s1.reverse()
    print(''.join(s1)+mid+''.join(s0))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

result_list = []
result_list.append(S)
for que in Query:
    if len(que) > 1:
        que_list = que.split()
        if que_list[1] == "1":
            result_list.insert(0, que_list[2])
        else:
            result_list.append(que_list[2])
    else:
        result_list.reverse()

print(''.join(result_list))

Submission status: Wrong Answer

Solution code:
def string_formation(s, q_list):
    s = [x for x in s]
    for query in q_list:
        if query[0] == '1':
            s[0], s[-1] = s[-1], s[0]
        else:
            if query[1] == '1':
                s = [query[2]] + s
            else:
                s = s + [query[2]]
    print(''.join(s))
    
s = input()
q = int(input())
q_list = []
for _ in range(q):
    tmp = input().split()
    q_list.append(tmp)

string_formation(s, q_list)

Submission status: Wrong Answer

Solution code:
def main():
  s,q,*r = [list(k.split()) for k in open(0)]
  s=s[0]
  p = False
  for x in r:
    if len(x)==1:
      p = True
      continue
    if (p == False and x[1]=='1') or (p == True and x[1]=='2'):
      s = x[2] + s
    else:
      s = s + x[2]
    
  print("".join(s) if p==False else "".join(s)[::-1])
  
if __name__=='__main__':
  main()