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:
s = str(input())
q = int(input())
for _ in range(q):
    query = list(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: Time Limit Exceeded

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

    cnt = 0
    for i in range(Q):
        query = input().split()
        if(query[0] == "1"):
            cnt += 1
        else:
            if(query[1] == "1"):
                if(cnt%2 == 0):
                    S = query[2]+S
                else:
                    S = S+query[2]
            else:
                if(cnt%2 == 0):
                    S = S+query[2]
                else:
                    S = query[2]+S
        
    if(cnt%2 == 0):
        print(S)
    else:
        print(S[::-1])
main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def ep(*params):
    print(*params,file=sys.stderr)

l = ''
r = ''

S = input().rstrip()

Q = int(input())
mode = 0
for _ in range(Q):
    ope = list(input().split())
    if ope[0] == '1':
        mode = (mode + 1)%2
    else:
        op = (int(ope[1]) + mode)%2
        if op == 1:
            l += ope[2]
        else:
            r += ope[2]
    print(mode,l[::-1],S,r,sep=":",file=sys.stderr)    

if mode == 0:
    print(l[::-1],S,r,sep="")    
else:
    print(r[::-1],S[::-1],l,sep="")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

s = deque(list(map(str, input().rstrip())))
q = int(input())

for _ in range(q):
    li = list(map(str, input().split()))
    if li[0] == "1":
        s.reverse()
    elif li[1] == "1":
        s.appendleft(li[2])
    else:
        s.append(li[2])

print("".join(s))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    q = int(input())
    for _ 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)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input()) #行数の入力
Qu = [list( input().split() ) for i in range(Q)] #2行目以降標準入力

for i in range(Q):
  if Qu[i][0] == "1":
    S = S[::-1]
  else:
    if Qu[i][1] == "1":
      S = Qu[i][2] + S
    else:
      S = S + Qu[i][2]

print(S)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    que = input()
    if que == "1":
        s.reverse()
    else:
        f,c = que[2:].split()
        if f == "1":
            s.appendleft(c)
        else:
            s.append(c)

print("".join(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
d = True
q = int(input())
for _ in range(q):
    a = input().split()
    if a[0] == '1':
        d = not d
    else:
        if a[1] == '1':
            if d:
                s = a[2] + s
            else:
                s = s + a[2]
        else:
            if d:
                s = s + a[2]
            else:
                s = a[2] + s

if not d:
    print(s[::-1])
else:
    print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False

for i in range(Q):
    if query[i][0] == str(1):
        if tag == False:
            tag = True
        else:
            tag = False
    elif query[i][0] == str(2):
        if query[i][1] == str(1):
            if tag == False:
                S = query[i][2] + S
            else:
                S = S + query[i][2]
        else:
            if tag == False:
                S = S + query[i][2]
            else:
                S = query[i][2] + S
if tag == True:
    S = S[::-1]
print(S)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
Q=int(input())
for i in range(Q):
    tmp=list(input().split())
    a=tmp[0]
    #print(tmp)
    if a=='1':
        S.reverse()
    elif a=='2' and tmp[1]=='1':
        S.insert(0,tmp[2])
    else:
        S.append(tmp[2])
print(*S,sep='')

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

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

Submission status: Time Limit Exceeded

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

reverse=0
for i in range(q):
    if Q[i][0]=="1":
        reverse+=1
    elif Q[i][0]=="2" and reverse%2==0:
        if Q[i][1]=="1":
            S.insert(0,Q[i][2])
        elif Q[i][1]=="2":
            S.append(Q[i][2])
    elif Q[i][0]=="2" and reverse%2==1:
        if Q[i][1]=="2":
            S.insert(0,Q[i][2])
        elif Q[i][1]=="1":
            S.append(Q[i][2])
if reverse%2==1:
    S.reverse()
for i in S:
    print(i,end="")

Submission status: Time Limit Exceeded

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

for i in range(q):
    if Q[i][0]=="1":
        S.reverse()
    elif Q[i][0]=="2":
        if Q[i][1]=="1":
            S.insert(0,Q[i][2])
        elif Q[i][1]=="2":
            S.append(Q[i][2])
for i in S:
    print(i,end="")

Submission status: Time Limit Exceeded

Solution code:
# D - String Formation
# 2020-05-21 08:17


def main():
    s = input()
    n = int(input())
    for _ in range(n):
        query = input().split()
        if query[0] == '1':
            s = s[::-1]
        else:
            if query[1] == '1':
                s = query[2] + s
            else:
                s += query[2]
    return s


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
s = input().replace('\n', '')
q = int(input())
flag = True
for i in range(q):
    query = list(map(str, input().split()))
    if query[0]=='1':
        if flag: flag = False
        else: flag = True
    else:
        
        if (not flag and query[1]=='1') or flag and query[1]=='2':
            s += query[2]
        else:
            s = query[2] + s
print(s if flag else s[::-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().replace('\n', '')
q = int(input())
flag = True
for i in range(q):
    query = list(map(str, input().split()))
    if query[0]=='1':
        if flag: flag = False
        else: flag = True
    else:
        if (not flag and query[1]=='1') or flag and query[1]=='2':
            s += query[2]
        else:
            s = query[2] + s
print(s if flag else s[::-1])

Submission status: Time Limit Exceeded

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

for i in range(Q):
    query = input().split()
    if len(query) == 1:
        parity += 1
    else:
        if int(query[1]) == 1 + (parity % 2):
            S = query[2] + S
        else:
            S = S + query[2]

if parity % 2 == 1:
    S = S[::-1]
print(S)

Submission status: Time Limit Exceeded

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

tmp = 1
for i in range(q):
    x = input()
    if x[0]==str(1):
        tmp*=-1
    else:
        t,f,c = x.split()
        t,f = int(t),int(f)
        if tmp==-1:
            if f==1:
                s = s+c
            if f==2:
                s = c+s
        if tmp==1:
            if f==1:
                s = c+s
            if f==2:
                s = s+c

print(s[::tmp])

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
T = [0]*q
F = [0]*q
C = ['' for i in range(q)]

for i in range(q):
    x = input()
    if x[0]==str(1):
        T[i]=1
    else:
        t,f,c = x.split()
        T[i],F[i],C[i] = int(t),int(f),c

tmp = 1
for i in range(q):
    if T[i]==1:
        tmp*=-1
    if T[i]==2:
        if tmp==-1:
            if F[i]==1:
                s = s+C[i]
            if F[i]==2:
                s = C[i]+s
        if tmp==1:
            if F[i]==1:
                s = C[i]+s
            if F[i]==2:
                s = s+C[i]

print(s[::tmp])

Submission status: Time Limit Exceeded

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

reverse = 0

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        S.insert(0, Query[i][2])
      else:
        S.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        S.append(Query[i][2])
      else:
        S.insert(0, Query[i][2])
        
ans = ''
s = ''.join(S)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)

Submission status: Time Limit Exceeded

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

reverse = 0

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        S = Query[i][2] + S
      else:
        S = S + Query[i][2]
    else:
      if reverse % 2 == 0:
        S = S + Query[i][2]
      else:
        S = Query[i][2] + S
        
ans = ''
if reverse % 2 == 0:
  ans = S
else:
  ans = S[::-1]
  
print(ans)

Submission status: Time Limit Exceeded

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

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

count = 0
c = 0
for q in Q:
    if q[0] == "1":
        count += 1
        c = count % 2
    else:
        if (c == 0 and q[1] == "1") or (c == 1 and q[1] == "2"):
            S.insert(0, q[2])
        elif (c == 0 and q[1] == "2") or (c == 1 and q[1] == "1"):
            S.append(q[2])

if count % 2  == 1:
    print("".join(S[::-1]))
else:
    print("".join(S))

Submission status: Time Limit Exceeded

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

Q = [list(input().split()) for _ in range(N)]
direction = 0
count = 0
for q in Q:
    if q[0] == "1":
        direction = abs(direction*1 - 1)
        count += 1
    else:
        if (direction == 0 and q[1] == "1") or (direction == 1 and q[1] == "2"):
            S.insert(0, q[2])
        elif (direction == 0 and q[1] == "2") or (direction == 1 and q[1] == "1"):
            S.append(q[2])

if count % 2  == 1:
    print("".join(S[::-1]))
else:
    print("".join(S))

Submission status: Time Limit Exceeded

Solution code:
txt = input()
n = (int)(input())
count = 0
sentou = ""
saigo = ""
for i in range(n):
  temp = input()
  if temp[0] == '1':
    count += 1
  else:
    sec, moji = (int)(temp.split(" ")[1]), temp.split(" ")[2]
    if (sec + count) % 2 == 1:
      sentou = moji + sentou
    else:
      saigo += moji
if count % 2 == 1:
  txt = saigo[::-1] + txt[::-1] + sentou[::-1]
else:
  txt = sentou + txt + saigo
print(txt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    Q = int(input())
    ans = S
    rev = False # rev=1で反転した状態
    for i in range(Q):
        query = input()
        if len(query)==1:
            rev = not rev
        else:
            tmp = list(query.split())
            f = int(tmp[1])
            c = tmp[2]
            if rev:
                ans = ans+c if f==1 else c+ans
            else:
                ans = c+ans if f==1 else ans+c

    ans = ans[::-1] if rev else ans
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    Q = int(input())
    t = [-1] * Q
    ans = S
    for i in range(Q):
        query = input()
        if len(query)==1:
            ans = ans[::-1]
        else:
            tmp = list(query.split())
            f = int(tmp[1])
            c = tmp[2]
            ans = c+ans if f==1 else ans+c
            
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    Q = int(input())
    t = [-1] * Q
    f = [-1] * Q
    c = [""] * Q
    for i in range(Q):
        query = input()
        if len(query)==1:
            t[i] = 1
        else:
            tmp = list(query.split())
            t[i] = int(tmp[0])
            f[i] = int(tmp[1])
            c[i] = tmp[2]

    ans = S
    for i in range(Q):
        if t[i]==1:
            ans = ans[::-1]
        else:
            if f[i]==1:
                ans = c[i]+ans
            else:
                ans = ans+c[i]
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
txt = input()
n = (int)(input())
count = 0
for i in range(n):
  temp = input()
  if temp[0] == '1':
    count += 1
  else:
    sec, moji = (int)(temp.split(" ")[1]), temp.split(" ")[2]
    if (sec + count) % 2 == 1:
      txt = moji + txt
    else:
      txt += moji
if count % 2 == 1:
  txt = txt[::-1]
print(txt)

Submission status: Time Limit Exceeded

Solution code:
txt = input()
n = (int)(input())
for i in range(n):
  temp = input()
  if temp[0] == '1':
    txt = txt[::-1]
  else:
    sec, moji = (int)(temp.split(" ")[1]), temp.split(" ")[2]
    if sec == 1:
      txt = moji + txt
    else:
      txt += moji
print(txt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[2] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[2]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
flag = True
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            S = i[2]+S
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            S = S+i[2]
if flag:
    print(S)
else:
    print(S[::-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
for i in Query:
    if i[0]=="1":
        S = S[::-1]
    else:
        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:
def main():
    s = input()
    Q = int(input())
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            s = s[::-1]
        else: # q[0]=="2"
            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 = int(input())
ba = 1
for _ in range(Q):
  q = input().split()
  if len(q) == 1:
    ba *= -1
  else:
    T, F, C = q
    if (F == '1' and ba == 1) or (F=='2' and ba==-1):
      S = C + S
    elif (F == '2' and ba == 1) or (F=='1' and ba ==-1):
      S = S + C
if ba == 1:
  print(S)
else:
  print(S[::-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
S = input()
Q = int(input())

state = 1 # 反転していたら-1
for i in range(Q):
    q = input()
    if q == '1':
        state *= -1
    else:
        Y, f, c = q.split()
        if (state == 1 and f == '1') or (state == -1 and f == '2'):
            S = c + S
        elif (state == 1 and f == '2') or (state == -1 and f == '1'):
            S = S + c

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
Q = int(input())
Y = [0] * Q
Task = [0] * Q

state = 1 # 反転していたら-1
for i in range(Q):
    q = input()
    if q == '1':
        state *= -1
    else:
        Y, f, c = q.split()
        if (state == 1 and f == '1') or (state == -1 and f == '2'):
            S = c + S
        elif (state == 1 and f == '2') or (state == -1 and f == '1'):
            S = S + c

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = int(input())
l = []

base = 1

for i in range(n):
  l=list(input().split())
  if l[0] == '1':
    base = base *-1
  else:
    if l[1] =='1' and base == 1 :
      s = l[2]+s
    elif l[1] =='2' and base == 1 :
      s = s+l[2]
    elif l[1] =='1' and base == -1 :
      s = s+l[2]
    elif l[1] =='2' and base == -1 :
      s = l[2]+s

if base ==-1:
  s=''.join(list(reversed(s)))
      
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = int(input())
l = []
for i in range(n):
  l=list(input().split())
  if l[0] == '1':
    s = ''.join(list(reversed(s)))
  else:
    if l[1] =='1':
      s = l[2]+s
    else:
      s = s+l[2]
      
print(s)

Submission status: Time Limit Exceeded

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

r = False
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        r = not r
    else:
        if (q[1] == '1' and not r) or (q[1] == '2' and r):
            S = q[2] + S
        else:
            S = S + q[2]
            
if r:
    S = ''.join(reversed(S))
print(S)

Submission status: Time Limit Exceeded

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

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

a = s

flag = True

for i in range(len(query)):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a = query[i][2] + a
        else:
            a = a + query[i][2]

if not(flag):
    a = a[::-1]

print(a)

Submission status: Time Limit Exceeded

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

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

a = s
for i in range(len(query)):
    if query[i][0] == "1":
        a = a[::-1]
    else:
        if query[i][1] == "1":
            a = query[i][2] + a
        else:
            a = a + query[i][2]

print(a)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
m = int(input())
q_list = [list(input().split()) 
          for nesya in range(m)]
n = 0
for q in q_list:
  if q[0] == '1':
    n += 1
  else:
    f = n + int(q[1])
    if f%2 == 1:
      s = q[2] + s
    else:
      s = s + q[2]
if n%2 == 1:
  s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

Solution code:
s=input()
q=int(input())
flag=0
for _ in range(q):
  query=input().split()
  if len(query)==1:
    flag=(flag+1)%2
  else:
    if (int(query[1])+flag)%2:
      s=query[2]+s
    else:
      s=s+query[2]
print(s if flag==0 else s[::-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            sque.appendleft(que[i][2])
        else:
            sque.append(que[i][2])
    else:
        sque.reverse()
print("".join(list(sque)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = []
for i in range(q):
    que.append(list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            sque.appendleft(que[i][2])
        else:
            sque.append(que[i][2])
    else:
        sque.reverse()
print("".join(list(sque)))

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
que = []
for i in range(q):
    que.append(list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            s = que[i][2] + s
        else:
            s += que[i][2]
    else:
        s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        if que[i][1] == '1':
            s = que[i][2] + s
        else:
            s += que[i][2]
    else:
        s = s[::-1]
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        t.append(que[i][0])
        f.append(que[i][1])
        c.append(que[i][2])
    else:
        t.append(que[i][0])
count = 0
for i in range(q):
    if t[i] == '1':
        s = s[::-1]
    else:
        if f[count] == '1':
            s = c[count] + s
            count += 1
        else:
            s += c[count]
            count += 1
print(s)

Submission status: Time Limit Exceeded

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

from collections import deque

q = deque(S)

r = 0  #反転の有無

for i in range(Q):
    if Query[i][0] == '1':
        r = 1-r
    else:
        if (r + int(Query[i][1])) % 2 == 1:
            q.appendleft(Query[i][2])
        else:
            q.append(Query[i][2])

A = list(q)

if r % 2 == 1:
    A.reverse()

ans = ''
for i in range(len(A)):
    ans += A[i]

print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(Q):
  a = list(input().split())
  if a[0] == "1":
    rev += 1
  else:
    if rev%2 == 0:
      if a[1] == "1":
        S = a[2] + S
      else:
        S = S + a[2]
    else:
      if a[1] == "2":
        S = a[2] + S
      else:
        S = S + a[2]
      
if rev%2 == 1:
  S = S[::-1]
print(S)

Submission status: Time Limit Exceeded

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

for _ in range(Q):
  a = list(input().split())
  if a[0] == "1":
    S = S[::-1]
  else:
    if a[1] == "1":
      S = a[2] + S
    else:
      S = S + a[2]
      
print(S)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                s.insert(0, q[2])
            else:
                s.append(q[2])
    if reverse:
        s.reverse()
    print(*s, sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    s=str(query[2])+s
                else:
                    s+=str(query[2])
                    
            else:
                if check==-1:
                    s+=str(query[2])
                else:
                    s=str(query[2])+s
    if check==1:
        print(s[::-1]) 
    else:
        print(s)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    s=str(query[2])+s
                else:
                    s+=str(query[2])
                    
            else:
                if check==-1:
                    s+=str(query[2])
                else:
                    s=str(query[2])+s
    if check==1:
        print(s[::-1]) 
    else:
        print(s)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    s=str(query[2])+s
                else:
                    s+=str(query[2])
                    
            else:
                if check==-1:
                    s+=str(query[2])
                else:
                    s=str(query[2])+s
    if check==1:
        print(s[::-1]) 
    else:
        print(s)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(list(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    s=str(query[2])+s
                else:
                    s+=str(query[2])
                    
            else:
                if check==-1:
                    s+=str(query[2])
                else:
                    s=str(query[2])+s
    if check==1:
        print(s[::-1]) 
    else:
        print(s)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(list(input().split()))
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            s=s[::-1]
        else:
            if query[1]=="1":
                s=str(query[2])+s
            else:
                s+=str(query[2])
    print(s)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
q=int(input())
queryy=[]

for i in range(q):
    queryy.append(list(input().split()))
for query in queryy:
 #   print(query)
    if query[0]=="1":
        s=s[::-1]
    else:
        if query[1]=="1":
            s=str(query[2])+s
        else:
            s+=str(query[2])
print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
queries = []
for _ in range(q):
    query = input().split()
    queries.append(query)
flag = True
for i in queries:
    if i[0] == "1":
        flag = (flag+1) % 2
    else:
        if flag:
            if i[1] == "1":
                s = i[2] + s
            if i[1] == "2":
                s = s + i[2]
        if not flag:
            if i[1] == "1":
                s = s + i[2]
            if i[1] == "2":
                s = i[2] + s
if flag:
    print(s)
if not flag:
    s = s[::-1]
    print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input()
q = int(input())
queries = []
for _ in range(q):
    query = input().split()
    queries.append(query)
flag = True
for i in queries:
    if i[0] == "1":
        flag = (flag+1) % 2
    else:
        if flag:
            if i[1] == "1":
                s = i[2] + s
            if i[1] == "2":
                s = s + i[2]
        if not flag:
            if i[1] == "1":
                s = s + i[2]
            if i[1] == "2":
                s = i[2] + s
if flag:
    print(s)
if not flag:
    s = s[::-1]
    print(s)

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
q=int(input())
cnt=1

for _ in range(q):
	a=list(input().split())
	if len(a)==1:
		cnt*=(-1)
	else:
		if cnt==1:
			if a[1]=="1":
				s=a[2]+s
			else:
				s=s+a[2]
		else:
			if a[1]=="1":
				s=s+a[2]
			else:
				s=a[2]+s
				
if cnt==-1:
	s=s[::-1]
	
print(s)