Problem: 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.

Submission attempts (in order):
from collections import deque

s = input()
d1 = deque()
d2 = deque()
d3 = deque()
num = 0
for i in s:
    d2.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d2) != 1:
                num += 1
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d1.append(c)
            else:
                d3.append(c)
if num % 2 == 1:
    d1.reverse()
    d2.reverse()
    d3.reverse()
s1 = list(d1)
s1 = "".join(s1)
s2 = list(d2)
s2 = "".join(s2)
s3 = list(d3)
s3 = "".join(s3)


print(s3+s2+s1)

from collections import deque

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            num += 1
        else:
            if num %2 == 1:
                d.reverse()
            num = 0   
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

s = list(d)
s = "".join(s)



print(s)

from collections import deque

s = input()
d = deque()
d.append(s)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(s) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp2)
                d.append(tmp1)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
            
s = list(d)
s = "".join(s)
print(s)

from collections import deque

s = input()
d = deque()
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d) != 1:
                tmp1 = d.pop()
                tmp2 = d.popleft()
                d.appendleft(tmp1)
                d.append(tmp2)
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
d.reverse()
s = list(d)
s = "".join(s)
print(s)

from collections import deque

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            tmp = d.pop()
            d[len(d)-1] = d[0]
            d[0] = tmp
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

s = list(d)
s = "".join(s)



print(s)

from collections import deque

s = input()
d = deque()
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
    data = input().split()
    if len(data) == 1:
      if len(d) != 1:
        tmp1 = d.pop()
        tmp2 = d.popleft()
        d.appendleft(tmp1)
        d.append(tmp2)
      else:
        f = int(data[1])
        c = data[2]
        if f == 1:
          d.appendleft(c)
        else:
          d.append(c)
            
s = list(d)
s = "".join(s)
print(s)

from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted