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()
T=4*100000
q=[""]*(T)
s=199999
q[s+1]=S
e=200001
Q=int(input())

for i in range(Q):
    QE=input()
    if QE=="1":
        ts=s
        te=e
        if (e-s)%2==0:
            while ts!=te:
                q[ts],q[te]=q[te],q[ts]
                ts+=1
                te-=1
        else:
            while ts<te:
                q[ts],q[te]=q[te],q[ts]
                ts+=1
                te-=1
            
    else:
        _,F,C=QE.split()
        
        if F=="1":
            q[s]=C
            s-=1
        else:
            q[e]=C
            e+=1
print("".join(q[s+1:e]))

Submission status: Wrong Answer

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

mae = ""
usiro =""

r_num=0

for i in range(Q):
    query = (input())
    if query=="1":
        kari = mae
        mae=usiro[::-1]
        usiro=kari[::-1]
    else:
        query = query.split(" ")
        if query[1] == "1":
            mae = query[2]+mae
        else:
            usiro += query[2]
if r_num%2 == 1:
    S=S[::-1]
print(mae+S+usiro)

Submission status: Wrong Answer

Solution code:
"""
// Author : snape_here - Susanta Mukherjee
     
"""
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def si(): return input()
def mi(): return map(str,input().split())
def li(): return list(mi())
 
 
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 
 
 
import math

mod=1000000007 

def main():

    s=si()
    c=0
    n=ii()
    for i in range(n):
        a=li()
        if i==n-1 and len(a)==1:
            s=s[::-1]
        if len(a)==1:
            c+=1
        else:
            if a[1]=='1':
                if c%2:
                    s=a[2]+s 
                else:
                    s+=a[2]
            else:
                if c%2==0:
                    s=a[2]+s 
                else:
                    s+=a[2]
    print(s)

# region fastio#
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
 
if __name__ == "__main__":
    #read()
    main() 
#Comment read()

Submission status: Wrong Answer

Solution code:
from collections import deque
S=input()
Q=int(input())
q=deque([S])
cnt=0
for i in range(Q):
  A=list(input().split())
  if int(A[0])==1:
    cnt+=1
  else:
    if int(A[1])==cnt%2+1:
      q.appendleft(A[-1])
    else:
      q.append(A[-1])
if cnt%2==0:
  for i in range(len(q)):
    print(q.popleft(),end='')
else:
  for i in range(len(q)):
    print(q.pop(),end='')

Submission status: Wrong Answer

Solution code:
a = list(input().split())

q = int(input())

queries = [list(input().split()) for i in range(q)]

revers = False

head = []

tail = []

for query in queries:
    if len(query) == 1:
        revers = not revers
    else:
        command, f, chara = query
        if f == '1':
            if not revers:
                head.append(chara)
            else:
                tail.append(chara)
        else:
            if not revers:
                tail.append(chara)
            else:
                head.append(chara)

# print(revers)
#
# print(head)
#
# print(tail)

if revers:
    tail.reverse()
    print(''.join(tail) + ''.join(a) + ''.join(head))
else:
    head.reverse()
    print(''.join(head) + ''.join(a) + ''.join(tail))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
f = []
for i in range(q):
    ff = [i for i in input().split()]
    f.append(ff)
ans = [s]
cnt = 0
f1 = 0
for i in range(q):
    if i > 0:
        if f[i-1][0] == '2' and f[i][0] == '1':
            cnt = 0
    if f[i][0] == '1':
        cnt += 1
        f1 += 1
    else:
        if f[i][1] == '1':
            if cnt % 2 == 0:
                ans.insert(0,f[i][2])
            else:
                ans.append(f[i][2])
        else:
            if cnt % 2 == 0:
                ans.append(f[i][2])
            else:
                ans.insert(0,f[i][2])
if f1 % 2 == 0:
    print(''.join(map(str,ans)))
else:
    ans2 = []
    for i in (reversed(ans)):
        ans2.append(i)
    print(''.join(map(str,ans2)))

Submission status: Wrong Answer

Solution code:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque()
S.append(Str)
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            S.extendleft(B)
            B = []
            S.extend(C)
            C = []
        else:
            S.extendleft(C)
            C = []
            S.extend(B)
            B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        S.extendleft(B)
        B = []
        S.extend(C)
        C = []
    else:
        S.extendleft(C)
        C = []
        S.extend(B)
        B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

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

for i in range(Q):
    Query = input().split()
    if Query[0]=='1':
        S=S[::-1]
    else:
        if Query[1]=='1':
            S=Query[2]+S
        else:
            S=S+Query[2]
print(S)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    st = S()
    Q = I()
    queries = []
    # print(st[0])
    # s = [st[i] for i in range(len(st))]
    # s = [None for i in range(3 * 10**5 + 2)]
    # st = 'a' * (10 ** 5)
    LEN = 6 * 10 ** 5
    START = 3 * 10 ** 5 - len(st) // 2
    s = [None] * (LEN + 2)
    for i in range(START, START + len(st)):
        # print(st[START - i], START - i)
        s[i] = st[START - i]

    for i in range(Q):
        queries.append(list(MS()))

    op = True
    first = START - 1
    last = START + len(st) + 1
    # print(s)

    for i in range(Q):
        query = queries[i]
        if len(query) == 1:
            op = not op
        else:
            if (query[1] == '1' and op is True) or (query[1] == '2' and op is False):
                s[first] = query[2]
                first -= 1
                # s.insert(0, query[2])
            elif (query[1] == '1' and op is False) or (query[1] == '2' and op is True):
                s[last] = query[2]
                last += 1
                # s.append(query[2])
            else:
                exit(-1)
                return

    # print(''.join([t for t in s if t is not None]))
    # print(s)
    if op is True:
        s = [t for t in s if t is not None]
        print(''.join(s))
    else:
        s = [t for t in s if t is not None]
        print(''.join(s[::-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=input()
Q=int(input())
Query=[[j for j in input().split()] for i in range(Q)]

c=0

for i in range(Q):
    if Query[i][0]=='1':
        c=c+1
    else:
        if ((Query[i][1]=='1')and(c%2==1)) or ((Query[i][2]=='1')and(c%2==0)):
            S=Query[i][2]+S
        else:
            S = S+Query[i][2]

if c%2==1:
    print(S)
else:
    print(''.join(list(reversed(S))))

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
result = S
for i in range(Q):
    A = list(map(str,input().split()))
    if int(A[0]) == 1:
        result = result[-1] + result[1:-1] + result[0]
    else:
        if int(A[1]) == 1:
            result = A[2] + result
        else:
            result = result + A[2]
    #print(result)
print(result)

Submission status: Wrong Answer

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

def add_car(S,s,is_left,is_rev):
    if is_rev:
        is_left = not(is_left)
    if is_left:
        S = ''.join([s,S])
    else:
        S = ''.join([S,s])
    return S

is_rev = False
for q in range(Q):
    x = input().split(' ')
    if len(x) == 1:
        is_rev = not is_rev
    else:
        S = add_car(S,x[2],x[1]=='1',is_rev)

if is_rev:
    S = list(reversed(S))
print(S)

Submission status: Wrong Answer

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

res = S

is_rev = False

def add_char(s, f, c, is_rev):
  if(f == "1"):
    return c + s if not is_rev else s + c
  else:
    return s + c if not is_rev else c + s

for _ in range(Q):
  q = input().split()
  
  if(q[0] == '1'): # Ti = 1
    is_rev = not is_rev
  
  else: #Ti = 2
    res = add_char(res, q[1], q[2], is_rev)


print(res)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
flag = False
head = ""
tail = ""
for i in range(q):
    query = input()
    if query[0] == "1":
        flag = not flag
    else:
        [t, f, c] = query.split()
        f = True if f == "1" else False
        if flag == f:
            head += c
        else:
            tail += c
s = head + s + tail
if not flag:
    s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
flg=False
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not flg:
			flg = True
		else:
			Flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
		if Q[1] == "2":
			if flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
if flg:
	S =S[::-1]
print(S)

Submission status: Wrong Answer

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

ans = [S]
X = []
Y = []
state = 1

for k in range(Q):
    if Query[k][0]=="1":
        state *= -1
    elif Query[k][0]=="2":
        if Query[k][1]=="1":
            if state == 1:
                X.append(Query[k][2])
            else:
                Y.append(Query[k][2])
        else:
            if state == 1:
                Y.append(Query[k][2])
            else:
                X.append(Query[k][2])

if state == 1:
    X = list(reversed(X))
    ans = X + ans + Y
else:
    Y = list(reversed(Y))
    ans = Y + ans + X

print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
S=input()
Q=int(input())
d = deque([S])
flag=0
for i in range(Q):
    x=input().split()
    if len(x)==1:
        d=deque(reversed(d))
    else:
        if int(x[1])==1:
            d.appendleft(x[2])
        else:
            d.append(x[2])
print(*d, sep="")

Submission status: Wrong Answer

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

import sys
from collections import deque

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def read_str():
    return sys.stdin.readline().rstrip()
    
def read_str_list(sep = " "):
    return [s for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    d = deque(list(read_str()))
    q = read_int()

    reversed_ = False
    for _ in range(0, q):
        query = read_str_list()
        if query[0] == "1":
            reversed_ = not reversed_
            continue
        # query[0] == "2"
        f, c = query[1:]
        if f == "1" or (f == "2" and reversed_):  # insert to the left
            d.appendleft(c)
        else:
            d.append(c)
    if reversed_:
        print("".join(reversed(list(d))))
    else:
        print("".join(list(d)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
  s = list( input() )
  q = int(input())
  r = [list(input().split()) for _ in range(q)]
  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()

Submission status: Wrong Answer

Solution code:
#D - String Formation
S = list(str(input()))
Q = int(input())
q = [input().split() for i in range(Q)]

#print(S)
#print(q)

for i in range(Q):
    tmp1 = ""
    if q[i][0] == '1':
       tmp1 = S[0]
       S[0] = S[-1]
       S[-1] = tmp1
    else:
        if q[i][1] == "1":
            S.insert(0,q[i][2])
        else:
            S.append(q[i][2])
ans = ''.join(S)
print(ans)

Submission status: Wrong Answer

Solution code:


#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque()
S.append(Str)
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            S.extendleft(B)
            B = []
            S.extend(C)
            C = []
        else:
            S.extendleft(C)
            C = []
            S.extend(B)
            B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
        if A%2==0:
            S.extendleft(B)
            B = []
            S.extend(C)
            C = []
        else:
            S.extendleft(C)
            C = []
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

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

is_reverse = False
b = ''
a = ''

for i in range(Q):
    q = input().split()
    if len(q) == 1:
        is_reverse = not is_reverse

    else:
        if (q[1] == '1' and is_reverse) or (q[1] == '2' and not is_reverse):
            a += q[2]
        else:
            b += q[2]

if is_reverse:
    print(a[::-1] + S + b)

else:
    print(b[::-1] + S + a)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math as m

def main(**kwargs):
    front = ""
    back = ""
    now = "f"

    for q in qs:
        if q[0] == "1":
            if now == "b":
                now = "f"
            else:
                now = "b"
        else:
            if (q[1] == "1" and now == "f") or (q[1] == "2" and now == "b"):
                front += q[2]
            else:
                back += q[2]

    res = back + s + front

    if now == "f":
        res = res[::-1]

    return res

if __name__ == "__main__":
    cin = np.array(input().split(" "))
    s, *_ = cin
    cin = np.array(input().split(" ")).astype("int")
    n, *_ = cin

    qs = []

    for i in range(n):
        cin = np.array(input().split(" "))
        qs.append(list(cin))
    
    cout = main(s=s, n=n, qs=qs)
    print(cout)

Submission status: Wrong Answer

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

s = s[::-1]
s = list(s)
for _ in range(q):
    q = input()
    if q[0] == '1':
        s = s[::-1]
    else:
        q = q.split(' ')
        if q[1] == '1':
            s.insert(0,q[-1])
        else:
            s.extend(q[-1])
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = input()
qq = int(input())
qs = []
flag = True
for i in range(qq):
    l = input().split()
    qs.append(l)
    if l[0] == "1":
        #print("pre")
        flag = not(flag)


preflag = flag
#print(qs)
res = ""
pre = ""
suf = ""
for i in range(qq-1, -1, -1):
    q = qs[i]
    #print(">>", q, "fla", flag)
    if q[0] == "1":
        #print("rev")
        flag = not(flag)

    elif q[0] == "2":
        if q[1] == "1":
            #print("ins 1")
            if flag:
                pre = pre + q[2]
            else:
                suf = suf + q[2]

        elif q[1] == "2":
            #print("ins 2")
            if flag:
                suf = q[2] + suf
            else:
                pre = q[2] + pre

"""
print("res")
print(res)
print("pre")
print(pre)
print("suf")
print(suf)
print(preflag)
"""
if not preflag:
    print(suf[::-1] + s[::-1] + pre[::-1])
else:
    print(pre + s + suf)

Submission status: Wrong Answer

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

Query = []
for i in range(Q):
  Query.append(list(map(str, input())))

for i in range(len(Query)):
  if len(Query[i]) == 5:
    Query[i].pop(1)
    Query[i].pop(2)
    Query[i][0], Query[i][1] = int(Query[i][0]), int(Query[i][1])
  else:
    Query[i][0] = int(Query[i][0])


print(Query)    
    
for i in range(Q):
  if Query[i][0] == 1:
    S = S[::-1]
  else: #Query[i][0] == 2
    if Query[i][1] == 1:
      S = Query[i][2] + S
    else: #Query[i][1] == 2
      S = S + Query[i][2]
      
print(S)

Submission status: Wrong Answer

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

is_reversed = False
first = ""
second = ""

for _ in range(Q):
    q = input().split(" ")
    if q[0] == "1":
        if is_reversed:
            S = second + S + first
        else:
            S = first + S + second
        first = ""
        second = ""
        is_reversed = not is_reversed
    else:
        if q[1] == "1":
            first = q[2] + first
        else:
            second += q[2]
if is_reversed:
    S = second + S + first
    S = ''.join(list(reversed(S)))
else:
    S = first + S + second

print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())
muki=True
a=[[_ for _ in input().split()] for i in range(q)]
front=""
back=""
for i in a:
    if i[0]=="1":
        muki=not muki
        continue
    if (i[1]=="1" and muki) or (i[1]=="2" and not muki):
        front+=i[2]
    else:
        back+=i[2]
if muki:
    print(front+s+back)
else:
    print((front+s+back)[::-1])

Submission status: Wrong Answer

Solution code:
s = input()
qn = int(input())
q = []
rev = False

for i in range(qn):
    qi = input().split()
    if i == 0:
        ordqi = (-1, (-1, -1))
    else:
        ordqi = q[-1]
    if len(qi) == 1:
        rev = not rev
    else:
        if rev:
            qi[1] = str((not (int(qi[1])-1)) + 1)
        if ordqi[0] == 2:
            if int(ordqi[1][0]) == 1 and int(qi[1]) == 1:
                q.pop()
                qi[2] += ordqi[1][1]
            if int(ordqi[1][0]) == 2 and int(qi[1]) == 2:
                q.pop()
                qi[2] += ordqi[1][1]
        q.append((int(qi[0]), (int(qi[1]), qi[2])))
if rev:
    q.append((1, ()))
for i in range(len(q)):
    if q[i][0] == 1:
        s = s[::-1]
    else:
        if q[i][1][0] == 1:
            s = q[i][1][1] + s
        else:
            s = s + q[i][1][1]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

# List of ints
def LI(): return list(map(int, sys.stdin.readline().split()))

# Single int
def I(): return int(sys.stdin.readline())

# List, which contains Lists of chars (not strings)
def LS():return list(map(list, sys.stdin.readline().split()))

# Single List of chars (not strings)
def S(): return list(sys.stdin.readline())[:-1]

# List of "n" integers from "n" lines.
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
# List of "n" Lists of integers
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l


# Runtime Complexity: O(?)
# Space Complexity: O(?)
# Solution
s = sys.stdin.readline().split()
lines_count = I()

chars = deque(s)

def prepend(chars, ch):
    chars.appendleft(ch)

def append(chars, ch):
    chars.append(ch)

actions = {
    1: prepend,
    2: append
}

for i in range(lines_count):
    line = LS()

    if len(line) == 1:
        actions[1], actions[2] = actions[2], actions[1]
    else:
        if line[1][0] == '1':
            actions[1](chars, line[2][0])
        else:
            actions[2](chars, line[2][0])

if actions[1] == append:
    chars.reverse()

print(''.join(list(chars)))

Submission status: Wrong Answer

Solution code:
import math

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

for _ in range(0, q):
    c = input().split()

    if len(c) == 3:
        d = int(c[1])
        e = c[2]
        s = e + s if d == 1 else s + e
    else:
        if len(s) == 1:
            s = s
        elif len(s) == 2:
            s = s[1] + s[0]
        else:
            s = s[-1] + s[1:-1] + s[0]

print(s)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
reverse_flag = False
temp = [0, 0, -1]

def add_s(s, f, c):
  if f == '1':
    # 先頭
    s = c + s
  else:
    # 末尾
    s = s + c
  return s

for i in range(Q):
  q = input()
  if q == '1':
    reverse_flag = not reverse_flag
    continue
  _, f, c = q.split()
  # print(reverse_flag, f, c)
  if reverse_flag:
    S = add_s(S, '1' if f == '2' else '1', c)
  else:
    S = add_s(S, f, c)

if reverse_flag:
  S = S[::-1]
print(S)

Submission status: Wrong Answer

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

mae = ""
usiro =""

r_num=0

for i in range(Q):
    query = (input())
    if query=="1":
        kari = mae
        mae=usiro[::-1]
        usiro=kari[::-1]
    else:
        query = query.split(" ")
        if query[1] == "1":
            mae += query[2]
        else:
            usiro += query[2]
if r_num%2 == 1:
    S=S[::-1]
print(mae+S+usiro)

Submission status: Wrong Answer

Solution code:
from collections import deque

S = deque(input().strip())
q = int(input())

rev = True
for _ in enumerate(range(q)):
    query = input().split()
    if query[0] == '1':
        rev = not rev
    else:
        if (query[1] == '1') ^ rev:
            S.appendleft(query[2])
        else:
            S.append(query[2])
S = S if not rev else reversed(S)
print(*S, sep='')

Submission status: Wrong Answer

Solution code:
import math

S = input().strip()
Q = int(input().strip())
order = 1

for i in range(Q):
  q = input().strip().split()
  #print(q)
  if q[0] == '1':
    # 反転
    # S = S[::-1]
    order *= -1
  else:
    F = q[1]
    if F == '1':
      if order == 1:
        # 先頭にCを追加
        S = q[2] + S
      else:
        # 末尾にCを追加
        S = S + q[2]
    else:
      if order == 2:
        # 末尾にCを追加
        S = S + q[2]        
      else:
        # 先頭にCを追加
        S = q[2] + S
        
print(S[::order])

Submission status: Wrong Answer

Solution code:
#ABC158 D - String Formation

S = str(input())
Q = int(input())
print(S)
for i in range(Q):
    q = input().split(' ')
    if(q[0] == '1'):
        S = S[::-1]

    else:
        if(q[1] == '1'):
            temp = [q[2]]
            S = q[2] + S
        else:
            S = S + q[2]

print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = deque([input()])

dic = 1
Q = int(input())
for i in range(0,Q):
    Query = input()
    if Query == '1':
        dic = 1*(-1)
    else:
        T, F, C = Query.split()
        if (F*dic == 2) or (F*dic == -1):
            S.append(C)
        else:
            S.appendleft(C)
print(''.join(list(S)))

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque()
s = input()
d.append(s)


Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        d.reverse()
    else:
        if (ls[1]== '1'):
            d.appendleft(ls[2])
        else:
            d.append(ls[2])

ans = ''.join(list(d))

print (ans)

Submission status: Wrong Answer

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

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

print(out)