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 = str(input())		;#1st input	
num = int(input())		;#2nd input

inv_flag = 1 
left_txt = ""
right_txt =""

##type of valiable##
for i in range(num):
  in_val =input().split()
  if in_val[0] == str(1):
    inv_flag = -1 * inv_flag
  elif in_val[0] == str(2):
    ## add right ##
    if in_val[1] == str(1) and inv_flag == 1:
      left_txt = in_val[2] + left_txt
    if in_val[1] == str(1) and inv_flag == -1:
      rigth_txt = right_txt + in_val[2]
    if in_val[1] == str(2) and inv_flag == 1:
      rigth_txt = right_txt + in_val[2]
    if in_val[1] == str(2) and inv_flag == -1:
      left_txt = in_val[2] + left_txt

out = str(left_txt + S + right_txt)
if inv_flag == 1:
  print(out)
else:
  print(out[::-1])

Submission status: Wrong Answer

Solution code:
import collections

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

Query = [input() for i in range(Q)]

deq = collections.deque([S])

flg = False
for q in Query:
    query = q.split(' ')
    if query[0]=='1':
        flg = not flg

    elif query[0] == '2':
        if query[1] == '1':
            if flg == True:
                deq.append(query[2])
            else:
                deq.appendleft(query[2])
        else:
            if flg==True:
               deq.appendleft(query[2])
            else:
               deq.append(query[2]) 
if flg == True:
    deq.reverse()        
print(''.join(deq))

Submission status: Wrong Answer

Solution code:
import collections

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

Query = [input() for i in range(Q)]

deq = collections.deque([S])

for q in Query:
    query = q.split(' ')
    if query[0]=='1':
        deq.reverse()

    elif query[0]=='2':
        if query[1]=='1':
            deq.appendleft(query[2])
        elif query[1]=='2':
            deq.append(query[2])

print(''.join(deq))

Submission status: Wrong Answer

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

for _ in range(Q):
	qu = input()
	if qu == '1':
		s = s[::-1]
	else:
		_, fi, ci = qu.split()
		if fi == '1':
			s = ci + s
		if fi == '2':
			s += ci
print(s)

Submission status: Wrong Answer

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

S = input().rstrip()
Q = int(input())
FTC = [tuple(input().split()) for _ in range(Q)]

que = deque([S])
cnt = 0
for query in FTC:
    if query[0] == '1':
        cnt ^= 1
        continue

    sign = 0 if query[1] == '1' else 1

    if sign ^ cnt == 0:
        que.appendleft(query[2])
    else:
        que.append(query[2])

ans = ''
while que:
    ans += que.popleft() if cnt == 0 else que.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]
 
for q in Qs:
  if len(q.strip()) == 1:
    S = S[::-1]
  else:
    F, C = q.strip().split()[1:3]
    if F == "1":
      S = C + S
    else:
      S += C
print(S)

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]
 
for q in Qs:
  if len(q.strip()) == 1:
    S = S[::-1]
  else:
    F, C = q.split()[1:3]
    if F == "1":
      S = C + S
    else:
      S += C
print(S)

Submission status: Wrong Answer

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

S = input().rstrip()
Q = int(input())
FTC = [tuple(input().split()) for _ in range(Q)]

que = deque([S])
cnt = 0
for query in FTC:
    if query[0] == '1':
        cnt ^= 1
        continue

    sign = 0 if query[1] == '1' else 1

    if sign ^ cnt == 0:
        que.appendleft(query[2])
    else:
        que.append(query[2])

que = list(que)
ans = ''.join(que[:: (-1)**cnt])
print(ans)

Submission status: Wrong Answer

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

S = input().rstrip()
Q = int(input())
FTC = [tuple(input().split()) for _ in range(Q)]

que = deque([S])
cnt = 0
for query in FTC:
    if query[0] == '1':
        cnt ^= 1
        continue

    sign = 0 if query[1] == '1' else 1

    if sign == cnt:
        que.appendleft(query[2])
    else:
        que.append(query[2])

que = list(que)
ans = ''.join(que[:: (-1)**cnt])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]

for q in Qs:
  T = q.split()[0]
  if T == "1":
    S = S[::-1]
  else:
    F, C = q.split()[1:3]
    if F == "1":
      S = C + S
    else:
      S = S + C
print(S)

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]

for q in Qs:
  T = q.split()[0]
  if T == "1":
    S = S[::-1]
  else:
    F, C = q.split()[1:3]

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]

for q in Qs:
  T = q.split()[0]
  if T == "1":
    S = S[::-1]

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]

for q in Qs:
  T = q.split()[0]

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()
S = s[0]
Q = s[1]
Qs = s[2:]

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readlines()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

# sys.stdin = open('test_cases/abc158d/in/01.txt', 'r')
# sys.stdin = open('input.txt', 'r')

s = deque([s for s in input()])
print(s)
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

# sys.stdin = open('test_cases/abc158d/in/01.txt', 'r')
# sys.stdin = open('input.txt', 'r')

s = deque([s for s in input()])
print(s)
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s.reverse()
print(s)
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top+ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top=ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
aa=[0,1]

for i in range(n-1):
    ss=input()
    if len(ss)==1:
        aa=aa[::-1]
    else:
        a=list(ss.split())
        if a[1]=="1":
            if aa[0]==0:
                s=a[2]+s
            else:
                s=s+a[2]
        else:
            if aa[0]==0:
                s=s+a[2]
            else:
                s=a[2]+s
ss=input()
if len(ss)==1:
        aa=aa[::-1]
else:
    a=list(ss.split())
    if a[1]=="1":
        s=a[2]+s
    else:
            s=s+a[2]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = str(input())
Q = int(input())
x = deque()
x.append(s)
for i in range(Q):
	qu = input()
	if qu == '1':
		x.reverse()
	else:
		q, fi, ci = qu.split()
		if q == '2':
			if fi == '1':
				x.appendleft(ci)
			if fi == '2':
				x.append(ci)
print(''.join(x))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = str(input())
Q = int(input())
x = deque()
ss = ''
x.append(s)
for i in range(Q):
    q = input()
    if q == '1':
        x.reverse()
    else:
        _, fi, ci = q.split()
        if fi == '1':
            x.appendleft(ci)
        if fi == '2':
            x.append(ci)
for i in x:
    ss += i
print(ss)

Submission status: Wrong Answer

Solution code:
## 158-D
from collections import deque

s = deque()
s.append(input())
q = int(input())
is_not_reverse = True
for _ in range(q):
    command = [e for e in input().split()]
    if command[0] == '1':
        is_not_reverse = not is_not_reverse      
    elif command[1] == '1':
        if is_not_reverse:
            s.appendleft(command[2])
        else:
            s.append(command[2])
    elif command[1] == '2':
        if is_not_reverse:
            s.append(command[2])
        else:
            s.appendleft(command[2])
print(''.join(s if is_not_reverse else reversed(s)))

Submission status: Wrong Answer

Solution code:
from collections import deque
ans=deque()
ans.append(input())
c=False
qu=[input().split() for i in range(int(input()))]
c=0
for i in qu:
    if i[0]=='1':
        c=not (c)
    else:
        if (i[1]=='1' and c )or (i[1]=='2'  and not c):
            ans.append(i[2])
        else:
            ans.appendleft(i[2])
            
        
ans=list(ans)
if c:
    print(''.join(ans[::-1]))
else:
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
ans=deque()
ans.append(input())
c=0
qu=[input().split() for i in range(int(input()))]
c=0
for i in qu:
    if i[0]=='1':
        c+=1
    else:
        
        if c%2==0:
            if i[1]=='1':
                ans.appendleft(i[2])
            else:
                ans.append(i[2])
            
        
        else:
            a=list(ans)
            a=a[::-1]
            ans=deque(a)
            if i[1]=='1':
                ans.appendleft(i[2])
            else:
                ans.append(i[2])
        c=0
            
#print(c)
if c!=0:
    if c%2:
        a=list(ans)
        a=a[::-1]
        ans=deque(a)
            
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
T = 0
for i in range(Q):
    flag, *inp = input().split()
    if flag == "1":
        T += 1
    elif int(inp[0]) == T % 2:
        S = inp[1] + S
    else:
        S = S + inp[1]

if T % 2:
    print(S)
else:
    print(S[::-1])

Submission status: Wrong Answer

Solution code:
s = str(input())
Q = int(input())
S = {}

c = 0
x = [c]
S[c] = s
ss = ''

for i in range(Q):
    c+=1
    q = input()
    if q == '1':
        x[0], x[-1] = x[-1], x[0]
    else:
        _, fi, ci = q.split()
        S[c] = ci
        if fi == '1':
            x.insert(0, c)
        if fi == '2':
            x.append(c)

for i in x:
    ss += S[i]
print(ss)

Submission status: Wrong Answer

Solution code:
s = str(input())
Q = int(input())
S = {}

c = 0
x = [c]
S[c] = s

for i in range(Q):
    c+=1
    q = input()
    if q == '1':
        x[0], x[-1] = x[-1], x[0]
    else:
        _, fi, ci = q.split()
        S[c] = ci
        if fi == '1':
            x.insert(0, c)
        if fi == '2':
            x.append(c)

si = [S[i] for i in x]
print(''.join(si))

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=False
for _ in range(q):
	flg=False
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=True
	else:
		if flg:
			s.reverse()
		if query[1]=='1':
			s.appendleft(query[2])
		else:
			s.append(query[2])
if flg:
	s.reverse()

print(''.join(s))

Submission status: Wrong Answer

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

for i in range(Q):
    # while n < Q:
    Query = input()
    if Query == '1':
        s = S[:S.find('_')]
        e = S[S.rfind('_')+1:]
        c = S[S.find('_')+1:S.rfind('_')]
        ecs = e + '_' +c + '_' +s
        S = ecs
    else:
        _, Fi, Ci = Query.split()
        if Fi == '1':
            S = Ci + '_' + S
        if Fi == '2':
            S+='_'+Ci
    #n+=1

print(S.replace('_',''))

Submission status: Wrong Answer

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

while n < Q:
    Query = input()
    if Query == '1':
        s = S[:S.find('_')]
        e = S[S.rfind('_')+1:]
        c = S[S.find('_')+1:S.rfind('_')]
        ecs = e + '_' +c + '_' +s
        S = ecs
    else:
        _, Fi, Ci = Query.split()
        if Fi == '1':
            S = Ci + '_' + S
        if Fi == '2':
            S+='_'+Ci
    n+=1

print(S.replace('_',''))

Submission status: Wrong Answer

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

while n < Q:
    Query = input().split()
    if len(Query) == 1:
        s = S[:S.find('_')]
        e = S[S.rfind('_')+1:]
        c = S[S.find('_')+1:S.rfind('_')]
        ecs = e + '_' +c + '_' +s
        S = ecs
    if len(Query) == 3:
        Ti, Fi, Ci = Query
        if Ti == '2':
            if Fi == '1':
                S = Ci + '_' + S
            if Fi == '2':
                S+='_'+Ci
    n+=1

Submission status: Wrong Answer

Solution code:
words=[]
words.append(input())
order_amount=int(input())
for i in range(order_amount):
    order=input().split()
    if order[0]=='2':
        if order[1]=='1':
            words.insert(0,order[2])
        elif order[1]=='2':
            words.append(order[2])
    else:
        a=words[0]
        words[0]=words[len(words)-1]
        words[len(words)-1]=a
word=''
for i in words:
    word+=i
print(word)

Submission status: Wrong Answer

Solution code:
words=[]
words.append(input())
order_amount=int(input())
for i in range(order_amount):
    order=list(input().split())
    if order[0]=='2':
        if order[1]=='1':
            words.insert(0,order[2])
        elif order[1]=='2':
            words.append(order[2])
    else:
        a=words[0]
        words[0]=words[len(words)-1]
        words[len(words)-1]=a
word=''
for i in words:
    word+=i
print(word)

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():

    st=deque([input()])
    N = int(input())
    sw=True
    for i in range(N):
        t= input().split()
        if t[0]=='1':
            sw=not sw

        elif (sw and t[1]=='2') or (not sw and t[1] == '1'):

            st.append(t[2])
        else:
            st.appendleft(t[2])

    if not sw:
        print(''.join(reversed(st)))
    else:
        print(''.join(st))
main()

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
flag = True
for _ in range(Q):
    T = input().split()
    if len(T) == 1:
        flag = not flag

                        
    if flag: #1
        print("regular")
        if int(T[0]) == 2:
            if int(T[1]) == 1:
                S = T[2]+ S
            elif int(T[1]) == 2: 
                S = S + T[2]
    else: #2
        print("rev")
        if int(T[0]) == 2:
            if int(T[1]) == 1:
                S = S + T[2]
            elif int(T[1]) == 2: 
                S = T[2] + S
if not flag:
    S = S[::-1]
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Q_query = []
for _ in range(Q):
    T = input().split()
    print(T)
    if len(T) == 1:
        Q_query.append(int(T[0]))
    else: 
        Q_query.append([int(T[0]), int(T[1]), T[2]])
        
for query in Q_query:
    if type(query) == int:
        if query == 1:
            S = S[::-1]            
    else: 
        if int(query[0]) == 2:
            if int(query[1]) == 1:
                S = query[2]+ S
            elif int(query[1]) == 2: 
                S = S + query[2]
print(S)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Q_query = []
for _ in range(Q):
    T = input().split()
    print(T)
    if len(T) == 1:
        T = int(T[0])
        if T == 1:
            S = S[::-1]            
    else: 
        if int(T[0]) == 2:
            if int(T[1]) == 1:
                S = T[2]+ S
            elif int(T[1]) == 2: 
                S = S + T[2]
print(S)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
front = ''
back = ''
count = 1
for i in range(n):
    q = input().split()
    if q[0] == '1':
        count *= -1
    else:
        if q[1] == '1':
            if count == 1:
                front += q[2]
            else:
                back += q[2]
        else:
            if count == 1:
                back += q[2]
            else:
                front += q[2]
if count == 1:
    print(front[::-1] + s + back[::-1])
else:
    print(back + s[::-1] + front)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        if len(s) != 1:
            mid = len(s)//2
            s_new = s[mid:len(s)] + s[0:mid] if len(s)==0 else s[mid+1:len(s)] +s[mid]+ s[0:mid]
            s = s_new
        else:
            pass
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        if len(s) != 1:
            s_new = s[-1] + s[1:-1] + s[0]
            s = s_new
        else:
            pass
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        s_new = s[-1] + s[1:-1] + s[0]
        s = s_new
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)

Submission status: Wrong Answer

Solution code:
st=input()
N = int(input())
t = [0] * N
x = [0] * N
y = [0] * N
sw=0
for i in range(N):
    try:
        t[i], x[i], y[i] = map(str,input().split())
    except ValueError :
        t[i]='1'
        x[i]=''
        y[i]=''
    if t[i]=='2':
        if sw==0:
            if x[i]=='1':
                st=y[i]+st
            elif x[i]=='2':
                st=st+y[i]
        elif sw==1:
            if x[i]=='1':
                st=st+y[i]
            elif x[i]=='2':
                st=y[i]+st
    elif t[i]=='1':
        sw=1

if sw==1:
    print(st[::-1])
else:
    print(st)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(input())
n = int(input())
initial = "left"
for i in range(n):
    order = list(input().split())
    if len(order) == 3:
        if initial == "left":
            if int(order[1]) == 1:
                s.appendleft(order[2])
            else:
                s.append(order[2])
        else:
            if int(order[1]) == 1:
                s.append(order[2])
            else:
                s.appendleft(order[2])
    else:
        initial = "right"
    
if initial == "left":
    print(''.join(s))
else:
    print(''.join(s)[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
initial = "right"
for i in range(n):
    order = list(input().split())
    if len(order) == 3:
        if initial == "right":
            if int(order[1]) == 1:
                s = order[2] + s
            else:
                s += order[2]
        else:
            if int(order[1]) == 1:
                s += order[2]
            else:
                s = order[2] + s
    else:
        initial = "left"
    
if initial == "right":
    print(s)
else:
    print(s[::-1])

Submission status: Wrong Answer

Solution code:
#import time
S = input()
Q = int(input())
f = True
head = []
tail = []
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '0' and not f):
            head.append(query[2])
        else:
            tail.append(query[2])

S = ''.join(head)+S+''.join(tail)
if not f:
    S = S[::-1]
print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#import time
S = input()
Q = int(input())
f = True
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '0' and not f):
            S = query[2]+S
        else:
            S = S+query[2]

print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Wrong Answer

Solution code:

S=input()
Q=int(input())
lis=[]
for _ in range(Q):
    lis.append(input().split())
ans=S
cnt=0
li=[['2','1',"a"] for i in range(2*100000)]
for i in li:
    if(int(i[0]) == 1):
        cnt= (cnt+1) % 2
    elif((cnt== 0 and i[1]=='1') or (cnt == 1 and i[1]=='2')):
        ans= i[2] + ans
    else:
        ans+=i[2]

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

Submission status: Wrong Answer

Solution code:

S=input()
Q=int(input())
lis=[]
for _ in range(Q):
    lis.append(input().split())
ans=S
cnt=0
for i in lis:
    if(i[0] == '1'):
        cnt+=1
    elif(cnt % 2 == 0):
        if(i[1] == '1'):
            ans= i[2] + ans
        else:
            ans+=i[2]
    else:
        if(i[1]==0):
            ans+=i[2]
        else:
            ans= i[2] + ans
print(ans[::-1]) if(cnt % 2 == 1) else print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

def D():
    S = raw_input()
    q = deque()
    q.append(S)
    Q = int(raw_input())
    for qdx in range(Q):
        parts = raw_input().split()
        if len(parts) == 1:
            q.reverse()
        else:
            _, F, C = parts
            if F == '1':
                q.appendleft(C)
            else:
                q.append(C)
    return ''.join(q)

print(D())

Submission status: Wrong Answer

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

flag = 0

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        flag ^= -1
    elif q[1] == '1':
        S.insert(flag, q[2])
    else:
        S.insert(flag ^ -1, q[2])

if flag:
    S.reverse()

print(''.join(S))

Submission status: Wrong Answer

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

for i in range(q):
    buf = input().split()
    if len(buf) == 1:
        s_first = s[0]
        s_last = s[-1]
        s[0] = s_last
        s[-1] = s_first

    elif len(buf) == 3:
        if buf[1] == '1':
            s.insert(0, buf[2])
        elif buf[1] == '2':
            s.append(buf[2])

for i in range(len(s)):
    print(s[i], end="")

Submission status: Wrong Answer

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


for i in range(q):
    buf = input().split()
    if len(buf) == 1:
        s_first = s[0]
        s_last = s[-1]
        s[0] = s_last
        s[-1] = s_first

    if len(buf) == 3:
        if buf[1] == '1':
            s.insert(0, buf[2])
        if buf[1] == '2':
            s.append(buf[2])

for i in range(len(s)):
    print(s[i], end="")

Submission status: Wrong Answer

Solution code:
Ti = n = 0
S = []
S = list(map(str, input()))
Q = int(input())
while n < Q:
    Query = input().split()
    if len(Query) == 1:
        S[0], S[-1] = S[-1], S[0]

    if len(Query) == 3:
        Ti, Fi, Ci = Query
        if Ti == '2':
            if Fi == '1':
                S.insert(0, Ci)
            if Fi == '2':
                S.append(Ci)
    n+=1
print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys

def main():

    try:
        Ti = n = 0
        S = []
        S = list(map(str, input()))
        Q = int(input())
        while n < Q:
            Query = input().split()
            if len(Query) == 1:
                S[0], S[-1] = S[-1], S[0]

            if len(Query) == 3:
                Ti, Fi, Ci = Query
                if Ti == '2':
                    if Fi == '1':
                        S.insert(0, Ci)
                    if Fi == '2':
                        S.append(Ci)
            n+=1
        print(''.join(S))

    except KeyboardInterrupt:
        sys.exit(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
Q = [input() for i in range(int(input()))]
rev = 0
l,r = -1,1
res ={0:S}
for q in Q:
  if q=="1":
    rev = (rev+1)%2
  else:
    t,f,c = q.split()
    if int(f) + rev == "1" :
      res[l] = c
      l -= 1
    else:
      res[r] = c
      r += 1

if rev == 1:
  for i in range(l+1,r):
    print(res[i],end="")
else:
  for i in range(r-1,l,-1):
    print("".join(list(reversed(res[i]))),end="")

Submission status: Wrong Answer

Solution code:
A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        A,C = C,A
    else:
        if D[1] == "1":
            A += D[2]
        else:
            C += D[2]
A = A[::-1]
print(A+C)

Submission status: Wrong Answer

Solution code:
A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        A,C = C,A
    else:
        if D[1] == "1":
            A += D[2]
        else:
            C += D[2]
A = A[::-1]
print(A+C)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
string_list = list(input())
n = int(input())

for i in range(n):
  line = list(input().split())
  if int(line[0]) == 1:
    string_list.reverse()
  elif int(line[0]) == 2:
    if int(line[1]) == 1:
      string_list = [line[2]]+ string_list
    elif int(line[1]) == 2:
      string_list.append(line[2])
for s in string_list:
  print(s, end ="")

Submission status: Wrong Answer

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

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not False)):
            s.insert(0, q[2])
        else:
            s.append(q[2])

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=False
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=True
	else:
		if flg:
			s.reverse()
		if query[1]=='1':
			s.appendleft(query[2])
		else:
			s.append(query[2])
if flg:
	s.reverse()

print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input())
q = int(input())
flag = 1
for _ in range(q):
    tfc = input().split()
    print(tfc)
    if tfc[0] == "1":
        flag *= -1

    elif tfc[0] == "2":
        if (tfc[1] == "1" and flag == 1) or (tfc[1] == "2" and flag == -1):
            s.appendleft(tfc[2])
        elif (tfc[1] == "1" and flag == -1) or (tfc[1] == "2" and flag == 1):
            s.append(tfc[2])
else:

    if flag == -1:
        s = list(s)[::-1]
        
print("".join(s))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

rev_flag = 0

bef = ''
aft = ''

for i in range(Q):
    if Query[i][0] == '1':
        rev_flag = (rev_flag + 1) % 2
    if Query[i][0] == '2':
        if Query[i][1] == '1':
            if rev_flag == 0:
                bef = Query[i][2] + bef
            elif rev_flag == 1:
                aft = aft + Query[i][2]
        elif Query[i][1] == '2':
            if rev_flag == 1:
                bef = Query[i][2] + bef
            elif rev_flag == 0:
                aft = aft + Query[i][2]

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

S = bef + S + aft
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input().split())
n = int(input())
query_li = (input().split() for i in range(n))

flag = 1

for query in query_li:
    if int(query[0]) == 1:
        flag = flag * -1
    else:
        if int(query[1]) == 1:
            if flag == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if flag == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])

s = ''.join(s)

print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque(input().split())
n = int(input())
query_li = (input().split() for i in range(n))

for query in query_li:
    if int(query[0]) == 1:
        s = deque(reversed(s))
    else:
        if int(query[1]) == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])

s = ''.join(s)

print(s)