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):
if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = []
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.append(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.append(i[2])
                else:
                    rightList.append(i[2])

    ans = ''.join(leftList)+ ans+''.join(rightList)

    print(ans)



if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    alist =[]
    anslist = []

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]
        anslist.append(ans)

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    anslist.append(i[2])
                else:
                    anslist.insert(0,i[2])

            else:
                if rev_count % 2 == 1:
                    anslist.insert(0,i[2])
                else:
                    anslist.append(i[2])

    print("".join(anslist))


if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = []
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 3:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.append(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.append(i[2])
                else:
                    rightList.append(i[2])

    ans = leftList.join + ans+rightList.join

    print(ans)



from collections import deque

if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = deque()
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.appendleft(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.appendleft(i[2])
                else:
                    rightList.append(i[2])

    ans = ''.join(leftList)+ ans+''.join(rightList)

    print(ans)



Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted