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:
def main():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1'or t == 1:
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    if flag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S) + head)


print(S)

Submission status: Wrong Answer

Solution code:
s = input()
nq = int(input())
flg = 0
front = []
back = []
for i in range(nq):
    q = input()
    if len(q) == 1:
        #flg += 1
        flg = (flg+1)%2
    else:
        if flg == 0:
            if q[2] == '1':
                front = [q[-1]] + front
            else:
                back = back + [q[-1]]
        else:
            if q[2] == '1':
                back = back + [q[-1]]
            else:
                front = [q[-1]] + front
                
s = ''.join(front) + s + ''.join(back)
# if flg % 2 == 1:
#     s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = deque((str(input())).split())
loop = int(input())

rev = 0
for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        rev = (rev+1) % 2
    else:
        type = int(queries[1])
        c = str(queries[2])
        if (type + rev) % 2 == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev == 1:
    s.reverse()
print("".join(list(s)))

Submission status: Wrong Answer

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


q = []
for n in range(Q):
  q.append(list(input().rstrip().split()))

#print(q)
def rev(olist):
  nlist  = olist[::-1]
  return nlist

def addhead(olist,ele):
  nlist = olist.insert(0,ele)
  return nlist
  
def addtail(olist,ele):
  nlist = olist.append(ele)
  return nlist

def rev2(flg):
  if flg == 0:
    flg = 1
  else:
    flg = 0
  return flg

def add(olist,ele,j,flg,head,tail):
  if j == '1' and flg == 0:
    head.insert(0,ele)
  elif j == '1' and flg == 1:
    tail.append(ele)
  elif j == '2' and flg == 0:
    tail.append(ele)
  elif j == '2' and flg == 1:
    head.insert(0,ele)

flg = 0
head = []
tail = []

for n in range(Q):
  
  if q[n][0] == '1':
    flg = rev2(flg)
  
  else:
    print(q[n][2])
    add(S,q[n][2],q[n][1],flg,head,tail)

ans = head + S + tail

if flg == 1:
  ans = rev(ans)
  
print(''.join(ans))

Submission status: Wrong Answer

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

r = 0
for i in range(q):
  query=input().split()
  if query[0] == '1':  
    r = r ^ True
  else  :
    if query[1] == '1' and r == 0 :
      s = query[2] + s 
    elif query[1] == '1' and r == 1 :
      s = s + query[2] 
    elif query[1] == '2' and r == 0 :
      s = s + query[2] 
    elif query[1] == '2' and r == 1 :
      s = query[2] + s 

ans = ''
if r ==1:
  s = s[::-1]
else:
  ans = s

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

S = input().split()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = []
q2 = []
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1.append(C)
        else:
            q2.append(C)


if state == 0:
    print(''.join(reversed(q1)), end='')
    print(''.join(S), end='')
    print(''.join(q2))
else:
    print(''.join(reversed(q2)), end='')
    print(''.join(reversed(S)), end='')
    print(''.join(q1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
 
def main():
    S = list(stdin.readline().rstrip())
    Q = int(input())
    rev = 0
    head = []
    tail = []
 
    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    head.append(q[4])
                else:
                    tail.append(q[4])
            else:
                if rev ==0:
                    tail.append(q[4])
                else:
                    head.append(q[4])
 
    if rev == 0:
        ans = "".join(head[::-1] + S + tail)
    else:
        ans = "".join(tail[::-1] + S[::-1] + head)
    
    print(ans)

Submission status: Wrong Answer

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

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if not len(L) == 1:
            L.reverse()
    else:	
        if a[1] == '1':
            L.append(a[2])
        else:
            L.insert(0, a[2])
L.reverse()
A = "".join(L)
print(A)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
queries = list(list(input().split()) for _ in range(Q))

for query in queries:
    if len(query) == 1:
        S_temp = S[len(S) - 1]
        S_temp += S[1:len(S) - 1] + S[0]
        S = S_temp
    else:
        if int(query[1]) == 1:
            S = query[2] + S
        else:
            S += query[2]

print(S)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    if flag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

reverse = 0
S = deque(list(input()))
q = int(input())

for _ in range(q):
    query = input()
    if query[0] == '1':
        reverse = 1 - reverse
        continue

    _, f, c = query.split()
    f = int(f)
    action = (reverse + f) % 2
    if action:
        S.appendleft(c)
    else:
        S.append(c)

if reverse:
    S.reverse()
    
print(''.join(S))

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = True
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
        # print(q)
        # print("".join(S))
    if flag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

Submission status: Wrong Answer

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

for i in range(0,q):
    query.append(input().split())
for i in query:
    if int(i[0]) == 1:
        inversion_flg = False if inversion_flg else True
    else:
        if int(i[1]) == 1:
            if inversion_flg:
                lead = lead + i[2] 
            else:
                end = end + i[2]
        else:
            if not inversion_flg:
                lead = lead + i[2] 
            else:
                end = end + i[2]
lead = ''.join(list(reversed(lead)))
s = lead+end

# 最後が反転なら反転
if not int(query[-1][0]) == 1:
    s = ''.join(list(reversed(s)))
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

sArry = deque(S.split())
rFlag = False
for i in range(Q):
    if Query[i][0] == '1':
        rFlag = (rFlag == False)
        
    else:
        if rFlag:
            sArry.reverse()
            rFlag = False
        
        if Query[i][1] == '1':
            sArry.appendleft(Query[i][2])
        else:
            sArry.append(Query[i][2])
#    print("  ", i, Query[i], "".join(sArry))


if rFlag:
    sArry.reverse()
print("".join(sArry))

Submission status: Wrong Answer

Solution code:
import sys

S = input().split()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = []
q2 = []
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1.append(C)
        else:
            q2.append(C)

ans = ''
if state == 0:
    print(*q1[::-1], end='', sep='')
    print(*S, end='', sep='')
    print(*q2, sep='')
else:
    print(*q2[::-1], end='', sep='')
    print(*S[::-1], end='', sep='')
    print(*q1, sep='')

Submission status: Wrong Answer

Solution code:
from collections import deque
t=list(input().split())
s=deque(t)
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    continue
  if ques[1]=="1":
    if flag:
      s.appendleft(ques[2])
    else:
      s.append(ques[2])
  else:
    if flag:
      s.append(ques[2])
    else:
      s.appendleft(ques[2])
if flag==False:
    print(''.join(reversed(list(s))))
else:
    print(''.join(list(s)))

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque
    S = deque(input().split())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = True
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
        # print(q)
        # print("".join(S))
    print("".join(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

front = []
back = []
back.append(s)

for query in query_list:
    if query[0] == '1':
        front, back = back, front
    elif query[0] == '2':
        key = int(query[1])
        value = query[2]
        if key == 1:
            front.append(value)
        else:
            back.append(value)
print(''.join(front[::-1]+back))

Submission status: Wrong Answer

Solution code:
def main2(s,x,q):
    res = s
    rev = 1 #-1なら反転中
    lstA = []
    lstB = []
    for op in q:
        if int(op[0]) == 1:
            rev = rev * -1
        elif int(op[1])*rev == 1 or int(op[1])*rev == -2:
            lstA.append(op[2])
        elif int(op[1])*rev == -1 or int(op[1])*rev == 2:
            lstB.append(op[2])
    if rev == 1:
        res = "".join(lstB)+res+"".join(lstA)
        res = res[::-1]
    else :
        res = "".join(lstB)+res+"".join(lstA)
    return res

s = input()
x = int(input())
q = [input().split() for _ in range(x)]
print(main2(s,x,q))

Submission status: Wrong Answer

Solution code:
from collections import deque

def string_formation(s, q_list):
    ans = deque()
    for x in s:
        ans.append(x)
    count = 0
    for query in q_list:
        # print(ans)
        if query[0] == '1':
            count += 1
        else:
            if count % 2 == 1:
                ans[0], ans[-1] = ans[-1], ans[0]
            count = 0
            if query[1] == '1':
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
    if count % 2 == 1:
        ans[0], ans[-1] = ans[-1], ans[0]
    print(''.join(ans))

    # ans = []
    # for x in s:
    #     ans.append(x)
    # for query in q_list:
    #     print(ans)
    #     count = 0
    #     if query[0] == '1':
    #         count += 1
    #         ans[0], ans[-1] = ans[-1], ans[0]
    #     else:
    #         if count % 2 == 1:
    #             ans[0], ans[-1] = ans[-1], ans[0]
    #         count = 0
    #         if query[1] == '1':
    #             ans = [query[2]] + ans
    #         else:
    #             ans = ans + [query[2]]
    # print(ans)

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque
def resolve():
    s = deque(input().split())
    q = int(input())
    for i in range(q):
        list = input().split()
        t = list[0]
        if t == "1" :
            if len(s) > 1:
                l, r = s.popleft(), s. pop()
                s.appendleft(r)
                s.append(l)
        else:
            f, c = list[1], list[2]
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
    print("".join(s))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

def abc158d(s_init, n, query):
    head = ""
    tail = ""
    reverse = 0
    for i in range(n):
        tgt = query[i]
        if tgt[0] == "1":
            reverse = (reverse + 1) % 2
        elif tgt[0] == "2":
            if tgt[1] == "1":
                if reverse == 0:
                    head += tgt[2]
                else:
                    tail += tgt[2]
            elif tgt[1] == "2":
                if reverse == 0:
                    tail += tgt[2]
                else:
                    head += tgt[2]
            else:
                print("invalid query!!:" + str(tgt[0]) + str(tgt[1]))
        else:
            print("invalid query!!:" + str(tgt[0]))
    if reverse == 0:
        return head[::-1] + s_init + tail
    else:
        return tail[::-1] + s_init + head

###
# main
if(__name__ == '__main__'):
    # input
    s_init = input()
    n = int(input())
    query = []
    for i in range(n):
        query.append(input().split(" "))
    
    accomplishment = abc158d(s_init, n, query)
    
    # output
    print(accomplishment)
# else:
    # do nothing

Submission status: Wrong Answer

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

query_list = []
for _ in range(q):
    query_list += [input()]


def query1(s):
    s = s[::-1]
    return s

def query2_1(letters,s):
    s = letters[4] + s
    return s

def query2_2(letters,s):
    s = s +  letters[4]
    return s

true_position = True
left = ""
right = ""

for i in range(q):
    if len(query_list[i])==1:
        true_position = not true_position
        # print(s)
    else:
        if query_list[i][2]=="1":
            if true_position:
                left = query_list[i][4] + left
            else:
                right = right + query_list[i][4]
        elif query_list[i][2]=="2":
            if true_position:
                right = right + query_list[i][4]
            else:
                left = query_list[i][4] + left

if true_position:
    ans = left + s + right
else:
    ans = right[::-1]+s+left[::-1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

sArry = deque(S.split())
rFlag = False
for i in range(Q):
    if Query[i][0] == '1':
        rFlag = (rFlag == False)
        
    else:
        if rFlag:
            sArry.reverse()
        
        if Query[i][1] == '1':
            sArry.appendleft(Query[i][2])
        else:
            sArry.append(Query[i][2])
#    print("  ", i, Query[i], "".join(sArry))


if rFlag:
    sArry.reverse()
print("".join(sArry))

Submission status: Wrong Answer

Solution code:
from collections import deque
t=list(input().split())
s=deque(t)
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    continue
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
if flag==False:
    print(''.join(reversed(list(s))))
else:
    print(''.join(list(s)))

Submission status: Wrong Answer

Solution code:
from collections import deque
def resolve():
    s = deque(input().split())
    q = int(input())
    for i in range(q):
        list = input().split()
        t = list[0]
        if t == "1" :
            if len(s) > 1:
                l, r = s.popleft(), s. pop()
                s.appendleft(r)
                s.append(l)
        else:
            f, c = list[1], list[2]
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
    print("".join(s))

Submission status: Wrong Answer

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


a = deque(input().split())
q = int(input())
mode = 0
L = deque()
R = deque()
r = deque()

for _ in range(q):
    q_list = input().split()

    if q_list[0] == '1':
        if mode == 0:
            mode = 1
        else:
            mode = 0
    else:
        if q_list[1] == '1':
            if mode == 0:
                L.extend(q_list[2])
            else:
                R.extend(q_list[2])
        else:
            if mode == 1:
                L.extend(q_list[2])
            else:
                R.extend(q_list[2])
a.extendleft(L)
a.extend(R)
if mode == 1:
    a.reverse()
r = list(a)
result = ''.join(r)
print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque
s=deque(list(input().split()))

q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    continue
  else:
    if ques[1]=="1":
      if flag:
        s.appendleft(ques[2])
      else:
        s.append(ques[2])
    else:
      if flag:
        s.append(ques[2])
      else:
        s.appendleft(ques[2])
if flag==False:
    print(''.join(reversed(list(s))))
else:
    print(''.join(list(s)))

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)


print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

def string_formation(s, q_list):
    ans = deque()
    for x in s:
        ans.append(x)
    count = 0
    for query in q_list:
        print(ans)
        if query[0] == '1':
            count += 1
        else:
            if count % 2 == 1:
                ans[0], ans[-1] = ans[-1], ans[0]
            count = 0
            if query[1] == '1':
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
    if count % 2 == 1:
        ans[0], ans[-1] = ans[-1], ans[0]
    print(''.join(ans))

    # ans = []
    # for x in s:
    #     ans.append(x)
    # for query in q_list:
    #     print(ans)
    #     count = 0
    #     if query[0] == '1':
    #         count += 1
    #         ans[0], ans[-1] = ans[-1], ans[0]
    #     else:
    #         if count % 2 == 1:
    #             ans[0], ans[-1] = ans[-1], ans[0]
    #         count = 0
    #         if query[1] == '1':
    #             ans = [query[2]] + ans
    #         else:
    #             ans = ans + [query[2]]
    # print(ans)

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

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

sArry = deque(S.split())
rFlag = False
for i in range(Q):
    if Query[i][0] == '1':
        rFlag = (rFlag == False)
        
    else:
        if rFlag:
            sArry.reverse()
        
        if Query[i][1] == '1':
            sArry.appendleft(Query[i][2])
        else:
            sArry.append(Query[i][2])
#    print("  ", i, Query[i], "".join(sArry))


print("".join(sArry))

Submission status: Wrong Answer

Solution code:
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) == 1:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

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

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
rev = False
for i in range(q):
  inp = input()
  if int(inp[0]) == 1:
    rev = not rev
  else:
    t, f, c = inp.split()
    if (int(f) == 1 and rev) or (int(f) == 2 and not rev):
      s += c
    else:
      s = c + s
print(reversed(s) if rev else s)

Submission status: Wrong Answer

Solution code:
from sys import stdin

s = stdin.readline().rstrip().split()
q = int(stdin.readline().rstrip())

left = []
right = s

direction = 1

for i in range(q):
    query = stdin.readline().rstrip().split()
    if len(query) == 1:
        direction *= -1
    else:
        if ((direction == 1) and (query[1] == '1')) or ((direction == -1) and (query[1] == '2')):
            left.append(query[2])
        else:
            right.append(query[2])

if direction == 1:
    print(''.join(left[::-1] + right))
else:
    print(''.join(right[::-1] + left))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
now = 1
q = int(input())
strs = deque([])
strs.append("endl")
for i in range(q):
    query = input()
    if len(query) == 5:
        #t = int(Query[i][0])
        f = int(query[2])
        c = query[4]
        if f == 1:
            strs.appendleft(c)
        else:
            strs.append(c)
    else:
        now *= -1
        strs.reverse()
strs = list(strs)
if now:
    for i in range(len(strs)):
        if strs[i] == "endl":
            ans = "".join(strs[:i])
            break
    ans += s + "".join(strs[i+1:])
else:
    ans += s[::-1] + "".join(strs[i+1:])
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

query = []

for i in range(Q):
    query.append(input().split())


left = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        left = not left

    else:
        if i[1]=="1":
            if left:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if left:
                suf += i[2]
            else:
                pre = i[2]+pre

print(pre+S+suf) if left else print(suf+S[::-1]+pre)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
    
# print(S, Q)
    
queries = []
for i in range(Q):
    query = input()
    queries.append(query)
    
from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
    
if isReversed:
    slist.reverse()
print("".join(slist))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
now = 1
q = int(input())
strs = deque([])
strs.append("endl")
for i in range(q):
    query = input()
    if len(query) == 5:
        #t = int(Query[i][0])
        f = int(query[2])
        c = query[4]
        if f == 1:
            strs.appendleft(c)
        else:
            strs.append(c)
    else:
        now *= -1
        strs.reverse()
strs = list(strs)
if now:
    for i in range(len(strs)):
        if strs[i] == "endl":
            ans = "".join(strs[:i])
            break
    ans += s + "".join(strs[i+1:])
else:
    ans += s[::-1] + "".join(strs[i+1:])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) == 1:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))
  exit()
  a = pre_s + s + after_s
  if reverse_count % 2 != 0:
    a = a[::-1]
  print(a)
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

d = deque(S)
head = "l"

for _ in range(Q):
    q = input()
    if len(q) == 1:
        if head == "l":
            head = "r"
        else:
            head = "l"
    else:
        T, F, C = q.split()
        if int(F) == 1:
            if head == "l":
                d.appendleft(C)
            else:
                d.append(C)
        else:
            if head == "l":
                d.append(C)
            else:
                d.appendleft(C)

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

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
        else:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
s = sol + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Submission status: Wrong Answer

Solution code:
S1 = ""
S2 = ""
S = str(input())
Q = int(input())
flag = 1
for i in range(Q):
    T = list(map(str, input().split()))
    if T[0] == "1":
        flag *= -1
    else:
        if T[1] == "1":
            if flag == 1:
                S1 = T[2] + S1
            else:
                S2 += T[2]
        else:
            if flag == 1:
                S2 += T[2]
            else:
                S1 = T[2] + S1
if flag == 1:
    S = S1 + S + S2
else:
    S = S2[::-1] + S + S1[::-1]
print(S)