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: Time Limit Exceeded

Solution code:
import numpy as np

# =============================================================================
# s = np.array(input().split()).astype(int)
# =============================================================================
# =============================================================================
# if s.find("A") >= 0 and s.find("B") >= 0:
#     print("Yes")
# else:
#     print("No")
# =============================================================================

# =============================================================================
# N,A,B = s
# 
# print(N//(A+B)*A + np.array([N%(A+B),A]).min())
# =============================================================================

# =============================================================================
# A,B = s
# 
# eight =  100/8
# ten = 100/10
# x1 = A*eight
# x2 = A*ten
# ans = []
# 
# for i in np.arange(0,np.array([x1,x2]).max().astype(int) + 100):
#     if int(i * 1/eight) == A and int(i * 1/ten) == B:
#         ans.append(i)
# if len(ans) == 0:
#     print(-1)
# else:
#     print(np.array(ans).min().astype(int))
# 
# =============================================================================

query = []
front = ""
back = ""
s = input()
q = int(input())
for ss in range(q):
    query.append(input())
for qi in query:
    if len(qi) <= 2:
# =============================================================================
#         tmp = front
#         front = back[::-1]
#         back = front[::-1]
# =============================================================================
        s = s[::-1]
    else:
        _,F,C = qi.split()
        if int(F) == 1:
            s = C + s
          
        elif int(F) == 2:
            s = s + C
            
print(s)

Submission status: Time Limit Exceeded

Solution code:
def reverse(s):
  ret = ''
  len_ = len(s) - 1
  for i in range(len(s)):
    ret += s[len_ - i]
  return ret

S = input()
N = int(input())
one_flag = False
for i in range(N):
  str_ = input()
  if ' ' in str_:
    c = str_.split()
    if c[1] == '2':
      if one_flag == False:
      	S = S + c[2]
      else:
        S = c[2] + S
    else:
      if one_flag == False:
      	S = c[2] + S
      else:
        S = S + c[2]
  else:
    one_flag = not one_flag
if one_flag == True:
  S = reverse(S)
print(S)

Submission status: Time Limit Exceeded

Solution code:
dic = {0: input()}
left = 0
right = 0
rev = False
q = int(input())
for i in range(q):
  query = input()
  if query[0] == "1":
    #反転
    for i in range(len(dic) // 2):
      dic[left + i], dic[right - i] = dic[right - i], dic[left + i]
    if rev == True:
      rev = False
    else:
      rev = True
  elif query[0] == "2":
    #追加
    num, front, c = query.split()
    if front == "1":
      dic[left - 1] = c
      left -= 1
    elif front == "2":
      dic[right + 1] = c
      right += 1

#出力
for i in range(left, right+1):
  string = dic[i]
  if len(string) > 1 and rev == True:
    string = string[::-1]
  print(string, end="")
print()

Submission status: Time Limit Exceeded

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

for q in range(Q):
  id_list = input().split(' ')
  if len(id_list) == 1:
  	S = ''.join(list(reversed(S)))
  else:
    idx, f, c = id_list
    if f == '1':
      S = c + S
    else:
      S = S + c

print(S)

Submission status: Time Limit Exceeded

Solution code:
def reverse(s):
  ret = ''
  len_ = len(s) - 1
  for i in range(len(s)):
    ret += s[len_ - i]
  return ret

S = input()
N = int(input())
for i in range(N):
  str_ = input()
  if ' ' in str_:
    c = str_.split()
    if c[1] == '2':
      S = S + c[2]
    else:
      S = c[2] + S
  else:
    S = reverse(S)
print(S)

Submission status: Time Limit Exceeded

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

for _ in range(q):
    l = input().split()
    if l[0] == "1":
        s = s[::-1]
    else:
        if l[1] == "1":
            s.insert(0, l[2])
        else:
            s.append(l[2])

print("".join(s))

Submission status: Time Limit Exceeded

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

for i in range(q):
    query = list(input().split())
    if int(query[0]) == 1:
        flg *= -1
    else:
        f, c = int(query[1]), query[2]
        flg *= -1
        if f == 1:
            if flg == 1:
                s += c
            else:
                s = c + s

        else:
            if flg == 1:
                s = c + s
            else:
                s += c
        flg *= -1
    continue

print(s if flg == 1 else s[::-1])

Submission status: Time Limit Exceeded

Solution code:
a = input()
q = input()
q = int(q)
reverse_count = 0
for i in range(q):
    que = input().split(" ")
    if que[0] == "1":
        reverse_count += 1
    else:
        if que[1] == "1":
            if reverse_count % 2 == 0:
                a = que[2]+a
            else:
                a += que[2]
        else:
            if reverse_count % 2 == 0:
                a += que[2]
            else:
                a = que[2]+a
if reverse_count % 2 == 1:
    a = a[::-1]
print(a)

Submission status: Time Limit Exceeded

Solution code:
a = input()
q = input()
q = int(q)
for i in range(q):
    que = input().split(" ")
    if que[0] == "1":
        a = a[::-1]
    else:
        if que[1] == "1":
            a = que[2]+a
        else:
            a += que[2]

print(a)

Submission status: Time Limit Exceeded

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

for i in range(q):
    query = list(input().split())
    if int(query[0]) == 1:
        s = s[::-1]
    else:
        f, c = int(query[1]), query[2]
        if f == 1:
            s = c + s
        else:
            s += c
    continue

print(s)

Submission status: Time Limit Exceeded

Solution code:
s= input();
q = int(input());
while(q>0):
    q-=1;
    ls = list(map(str,input().split(" ")));
    if(ls[0]=='1'):
        s=s[::-1];
    else:
        if(ls[1]=='1'):
            s=ls[2]+s;
        else:
            s=s+ls[2];
print(s)

Submission status: Time Limit Exceeded

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

front = True

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

    if len(query) == 1:
        front = not front
    
    else:
        if front:
            if query[1] == "1":
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if query[1] == "1":
                s = s + query[2]
            else:
                s = query[2] + s      

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

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
a, b = '', ''
cnt = 0
for _ in range(q):
    que = input().split()
    if que[0] == '1':
        cnt += 1
    else:
        if (cnt+int(que[1])) %2 == 0:
            a += que[2]
        else:
            b += que[2]
if cnt%2 == 1:
    s = s[-1::-1]
    s = a[-1::-1]+s+b
else:
    s = b[-1::-1]+s+a
print(s)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdout

s = input()
q = int(input())
order = 1
for i in range (q):
  e = input().split()
  if e[0] == '1':
    order *= (-1)
  else:
    if order == 1:
      if e[1] == '1':
        s = e[2] + s
      else:
        s += e[2]
    else:
      if e[1] == '2':
        s = e[2] + s
      else:
        s += e[2]
stdout.write(s if order == 1 else s[::-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
reversed = False
for _ in range(Q):
    q = input().replace(" ","")
    if len(q) == 3:
        t, f, c = q[0],q[1],q[2]
    else:
        t = q[0]
    if t == "1":
        reversed = not reversed
    elif t == "2":
        if f == "1":
            #元の順のとき
            if not reversed:
                S = c + S
            #元とは逆順になっているとき
            else:
                S = S + c
        else:
            #元の順のとき
            if not reversed:
                S = S + c
            #元とは逆順になっているとき
            else:
                S = c + S
if reversed:
    print(S[::-1])
else:
    print(S)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
for q in qs:
    if len(q) == 1:
        s.reverse()
    else:
        if int(q[1]) == 1:
            s.appendleft(q[2])
        else:
            s.append(q[2])
print("".join(s))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
reverseCount = 0
for _ in range(Q):
    query = input()
    if len(query) == 1:
        reverseCount += 1
    else:
        _, F, C = query.split(" ")
        if (int(F) + reverseCount) % 2 == 1:
            S = C + S
        else:
            S = S + C
if reverseCount % 2 == 0:
    print(S)
else:
    print(S[::-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
S = deque(input())
rev = False
apdlft = S.appendleft
apd = S.append

for _ in range(int(input())):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            apdlft(q[2])
        else:
            apd(q[2])

for i in reversed(range(len(S))) if rev else range(len(S)):
    print(S[i], end="")
else:
    print("")

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
reverseCount = 0
for _ in range(Q):
    query = input()
    if len(query) == 1:
        reverseCount += 1
    else:
        _, F, C = query.split(" ")
        if (F == "1" and reverseCount % 2 == 0) or (F == "2" and reverseCount % 2 == 1):
            S = C + S
        else:
            S = S + C
if reverseCount % 2 == 0:
    print(S)
else:
    print(S[::-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

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

re=False
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re==True:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
S = deque(input())
Q = int(input())
rev = False
apdlft = S.appendleft
apd = S.append

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            apdlft(q[2])
        else:
            apd(q[2])

for i in list(range(len(S)) if rev is False else reversed(range(len(S)))):
    print(S[i], end="")
else:
    print("")

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
S = deque(input())
Q = int(input())
rev = False

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            S.appendleft(q[2])
        else:
            S.append(q[2])

for i in (range(len(S)) if rev is False else reversed(range(len(S)))):
    print(S[i], end="")
else:
    print("")

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S = q[4]+S
        else:
            S = S+q[4]
    else:
        s *= -1
if s==1:
    print(S)
else:
    print(S[::-1])

Submission status: Time Limit Exceeded

Solution code:
import sys

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

re=0
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re+=1
    else:
        if q_i[1]=="1" and re%2==0:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re%2==1:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
state = 0
for i in range(q):
    query = list(input().split())
    if query[0] == "2":
        if state%2 == 0:
            if query[1] == "1":
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if query[1] == "1":
                s = s +  query[2]
            else:
                s = query[2] + s
    else:
        state += 1
ans = ""
if len(s)>1:
    if state%2==1 and state != 1:
        for i in range(len(s)):
            ans += s[-1-i]
        print(ans)
    else:
        print(s)
else:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

re=0
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re+=1
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
for i in range(q):
    query = list(input().split())
    if query[0] == "2":
        if query[1] == "1":
            s = query[2] + s
        else:
            s = s + query[2]
    else:
        temp = s[:]
        s = ""
        for j in range(len(temp)):
            s += temp[-1-j]
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = [input()]
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      s.insert(0,temp[2])
    else:
      s.append(temp[2])
      
s = "".join(s)
if reverse_flag == -1:
  s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

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

for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      s = "".join([temp[2],s])
    else:
      s = "".join([s,temp[2]])
      
if reverse_flag == -1:
  s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

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

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      s = temp[2] + s
    else:
      s = s + temp[2]      
      
if reverse_flag == -1:
  s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

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

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s.append(q_i[2])

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    if int(temp[1])*reverse_flag == 1 or int(temp[1])*reverse_flag == -2:
      s = temp[2] + s
    else:
      s = s + temp[2]      
      
if reverse_flag == -1:
  s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

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


condition = [list(map(str, input().split())) for i in range(Q)]

front = True

for i in condition:

    if i[0] == '1':
        front = not front

    elif i[0] == '2':
        if i[1] == '1':
            if front:
                S = i[2] + S
            else:
                S = S + i[2]
        elif i[1] == '2':
            if front:
                S = S + i[2]
            else:
                S = i[2] + S

if not front:
    S = ''.join(list(reversed(S)))

print(S)

Submission status: Time Limit Exceeded

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


condition = [list(map(str, input().split())) for i in range(Q)]

for i in condition:
    
    if i[0] == '1':
        S = ''.join(list(reversed(S)))
    elif i[0] == '2':
        if i[1] == '1':
            S = i[2] + S
        elif i[1] == '2':
            S = S + i[2]
print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

re=0
for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        re+=1    
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

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


condition = [list(map(str, input().split())) for i in range(Q)]

for i in range(Q):
    if condition[i][0] == '1':
        S = ''.join(list(reversed(S)))
    elif condition[i][0] == '2':
        if condition[i][1] == '1':
            S = condition[i][2] + S
        elif condition[i][1] == '2':
            S = S + condition[i][2]

print(S)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input().split()
    if(Que[0]=='1'):
        rev=not rev
    else:
        if(Que[1]=='1'):
            if(not rev):
                d.appendleft(Que[2])
            else:
                d.append(Que[2])
        else:
            if(not rev):
                d.append(Que[2])
            else:
                d.appendleft(Que[2])
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Submission status: Time Limit Exceeded

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

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

for i in range(1,q+1):
    q_i=stdin.readline().rstrip().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = deque(input())
num = int(input())
for i in range(num):
  a = deque(input().split())
  start = int(a[0])
  if start == 2:
    ns = int(a[1])
    if ns == 1:
      s.appendleft(a[2])
      #s = a[2] + s
    else:
      #s = s + a[2]
      s.append(a[2])
  else:
    s.reverse()
for i in range(len(s)):
  print(s[i], end='')

Submission status: Time Limit Exceeded

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
Q = int(input())
rev = False
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            S = q[2] + S
        else:
            S = S + q[2]
print(S if rev == 0 else S[::-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    S = input()
    Q = int(input())
    qs = list(input() for _ in range(Q))
    rev = False
    for q in qs:
        q = q.split()
        if q[0] == '1':
            rev = not(rev)
        else:
            if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
                S = q[2] + S
            else:
                S = S + q[2]
    print(S if rev == 0 else S[::-1])
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
Q = int(input())
# queries = list(list(input().split()) for _ in range(Q))  # 後でroop回し直すのは2度手間

reverse = 0
# for query in queries:
for query in sys.stdin:
    if query[0] == '1':  # len(query)は改行記号の有無で変わるのでダメ
        reverse = 1 - reverse

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

if reverse:  # reverse処理は重い．実際，最後の一回で良い．
    S = S[::-1]

print(S)

Submission status: Time Limit Exceeded

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

S = input()
Q = int(input())
rev_flg = False

for i in range(Q):
  q = input().split(" ")
  if len(q)==1:
    # T=1のときは文字列を反転する
    rev_flg = not(rev_flg)
  if len(q)==3:
    # print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      if rev_flg==False:
      	S = q[2] + S
      else:
        S = S + q[2]
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      if rev_flg==False:
        S = S + q[2]
      else:
        S = q[2] + S
  
if rev_flg==True:
  print(S[::-1])
else:
  print(S)

Submission status: Time Limit Exceeded

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

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

input_val = []
for i in range(Q):
  q = input().split(" ")
  input_val.append(q)
  
#print(input_val)
output = ""
for q in input_val:
  if len(q)==1:
    #print("T=1, S=",S)
    # T=1のときは文字列を反転する
    S = S[::-1]
    #print(S)
  if len(q)==3:
    #print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      #print("F=1, S:",S,"q[2]:",q[2])
      S = q[2] + S 
      #print(S)
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      #print("F=2, S:",S,"q[2]:",q[2])
      S = S + q[2]
      #print(S)
  #print(q)
  
print(S)

Submission status: Time Limit Exceeded

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

rev_stetus = False
for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        rev_stetus = not rev_stetus
    else:
        f = int(ipt[1])
        c = ipt[2]
        if rev_stetus:
            S = S + c if f == 1 else c + S
        else:
            S = c + S if f == 1 else S + c

if rev_stetus:
    print("".join(reversed(S)))
else:
    print(S)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        S.reverse()
    else:
        if q[1] == "1":
            S.appendleft(q[2])
        else:
            S.append(q[2])
print("".join(S))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
Q = int(input())
qs = list(input() for _ in range(Q))
rev = False
for q in qs:
    q = q.split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            S = q[2] + S
        else:
            S = S + q[2]
print(S if rev == 0 else S[::-1])

Submission status: Time Limit Exceeded

Solution code:
def rev_f(string , i):
    if i[2] == '2':
        string = string + i[4]

    if i[2] == '1':
        string = i[4] + string
    return string



def rev_s(string , i):
    if i[2] == '1':
        string = string + i[4]

    if i[2] == '2':
        string = i[4] + string
    return string




string = input()
num = int(input())
q_list = []
reverse_num = 0
reverse = True
reverese_s = False
for a in range(num):
    i = input()
    if i == '1':
        reverse_num  +=1 
        if reverese_s:
            reverese_s = False
        else:
            reverese_s = True
    else:
        if reverese_s == False:
            string = rev_f(string,i)

        if reverese_s ==True:
            string = rev_s(string,i)
        
if reverse_num %2 == 0:
    reverse = False
    
if reverse == True:
    string = string[::-1]
print(string)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
S = input()
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":\
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S = q[2] + S
        else:
            S += q[2]
print(S if cnt % 2 == 0 else S[::-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
	s = str(input())
	q = int(input())
	shiji = 1
	rcount = 0
	for i in range(q):
		qu = list(map(str,input().split()))
		if qu[0] != '1':
			if shiji == 1:
				if qu[1] == '1':
					s = qu[2] + s
				else:
					s = s + qu[2]
			else:
				if qu[1] == '2':
					s = qu[2] + s
				else:
					s = s + qu[2]
		else:
			shiji *= -1
			rcount += 1
	if rcount % 2 == 0:
		print(s)
	else:
		print(s[::-1])

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
Q = int(input())
qs = list(input() for _ in range(Q))
rev = 0
for q in qs:
    q = q.split()
    if q[0] == '1':
        rev += 1
        rev %= 2
    else:
        if (q[1]=='1' and rev==0) or (q[1]=='2' and rev==1):
            S = q[2] + S
        else:
            S = S + q[2]
print(S if rev == 0 else S[::-1])