Buggy python submission (verdict: Runtime Error):
from collections import deque
S=list(input())
Q=int(input())
Qlst=[list(input().split()) for _ in range(Q)]

len_S=len(S)
s0=deque(sorted(S[:len_S//2]))
s1=deque(S[len_S//2:])

if len_S%2!=0:
    mid=s1.popleft()
else:
    mid=''

fflag=0
for i in range(Q):
    q=Qlst[i]
    if q[0]=='1':
        fflag=abs(fflag-1)
        continue
    if q[1]=='1':
        if fflag==0:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.insert(0,mid)
                mid=''
        else:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.insert(0,mid)
                mid=''
    elif q[1]=='2':
        if fflag==0:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.append(mid)
                mid=''
        else:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.append(mid)
                mid=''

if fflag==0:
    s0.reverse()
    print(''.join(s0)+mid+''.join(s1))
else:
    s1.reverse()
    print(''.join(s1)+mid+''.join(s0))

Fixed submission:
from collections import deque

S=list(input())
Q=int(input())
Sq=deque(S)

flag=1
for _ in range(Q):
    q=input().split()
    if q[0]=='1':
        flag*=-1
        continue
    if (q[1]=='1' and flag==-1) or (q[1]=='2' and flag==1):
        Sq.append(q[2])
    else:
        Sq.appendleft(q[2])
if flag==1:
    print(''.join(Sq))
else:
    Sq.reverse()
    print(''.join(Sq))

Buggy python submission (verdict: Runtime Error):
from collections import deque
S=list(input())
Q=int(input())
Qlst=[list(input().split()) for _ in range(Q)]

len_S=len(S)
s0=deque(sorted(S[:len_S//2]))
s1=deque(S[len_S//2:])

if len_S%2!=0:
    mid=s1.popleft()
else:
    mid=''

fflag=0
for i in range(Q):
    q=Qlst[i]
    if q[0]=='1':
        fflag=abs(fflag-1)
        continue
    if q[1]=='1':
        if fflag==0:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.insert(0,mid)
                mid=''
        else:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.insert(0,mid)
                mid=''
    elif q[1]=='2':
        if fflag==0:
            s1.append(q[2])
            if mid=='':
                mid=s1.popleft()
            else:
                s0.append(mid)
                mid=''
        else:
            s0.append(q[2])
            if mid=='':
                mid=s0.popleft()
            else:
                s1.append(mid)
                mid=''

if fflag==0:
    s0.reverse()
    print(''.join(s0)+mid+''.join(s1))
else:
    s1.reverse()
    print(''.join(s1)+mid+''.join(s0))

Fixed submission:
from collections import deque

S=list(input())
Q=int(input())
Sq=deque(S)

flag=1
for _ in range(Q):
    q=input().split()
    if q[0]=='1':
        flag*=-1
        continue
    if (q[1]=='1' and flag==-1) or (q[1]=='2' and flag==1):
        Sq.append(q[2])
    else:
        Sq.appendleft(q[2])
if flag==1:
    print(''.join(Sq))
else:
    Sq.reverse()
    print(''.join(Sq))