Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = 0
for i in C.values():
    ans += int(0.5* i * (i-1))
for j in A:
    print(ans-C[j]+1)


Fixed submission:
from collections import deque
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False
que = deque([S])

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:
                que.appendleft(query[i][2])
            else:
                que.append(query[i][2])
        else:
            if tag == False:
                que.append(query[i][2])
            else:
                que.appendleft(query[i][2])
ans = "".join(que)
if tag == True:
    ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)


Fixed submission:
from collections import deque
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False
que = deque([S])

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:
                que.appendleft(query[i][2])
            else:
                que.append(query[i][2])
        else:
            if tag == False:
                que.append(query[i][2])
            else:
                que.appendleft(query[i][2])
ans = "".join(que)
if tag == True:
    ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)


Fixed submission:
from collections import deque
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False
que = deque([S])

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:
                que.appendleft(query[i][2])
            else:
                que.append(query[i][2])
        else:
            if tag == False:
                que.append(query[i][2])
            else:
                que.appendleft(query[i][2])
ans = "".join(que)
if tag == True:
    ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)


Fixed submission:
from collections import deque
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False
que = deque([S])

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:
                que.appendleft(query[i][2])
            else:
                que.append(query[i][2])
        else:
            if tag == False:
                que.append(query[i][2])
            else:
                que.appendleft(query[i][2])
ans = "".join(que)
if tag == True:
    ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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)


Fixed submission:
from collections import deque
S = str(input())
Q = int(input())
query = [ input().split() for _ in range(Q) ]

tag = False
que = deque([S])

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:
                que.appendleft(query[i][2])
            else:
                que.append(query[i][2])
        else:
            if tag == False:
                que.append(query[i][2])
            else:
                que.appendleft(query[i][2])
ans = "".join(que)
if tag == True:
    ans = ans[::-1]
print(ans)