CodeEff/ECCO huggingface dataset:
# Original solution
from bisect import bisect
N = int(eval(input()))
D = list(map(int,input().split()))
D.sort()

ans = 0
for i in range(10**5+5):
    j = bisect(D, i)
    if j==N//2:
        ans += 1
    elif j>N//2:
        break
print(ans)

# Optimized solution
N = int(eval(input()))
D = list(map(int,input().split()))
D.sort()
print((D[N//2] - D[N//2-1]))
# Original solution
N = int(eval(input()))
d = sorted(list(map(int, input().split())))
ans = 0
for i in range(1,d[-1] + 1):
    if sum(x <i for x in d) == N//2:
        ans += 1
    else:
        pass
print(ans)

# Optimized solution
N = int(eval(input()))
d = sorted(list(map(int, input().split())))

print((d[N//2] - d[N//2 - 1]))
# Original solution
a=[]
i=1
k=1
l=0
rk=[]
bk=[]
a.append(int(eval(input())))
for x in input().split(" "):
    a.append(int(x))

while k<=100000:
    while i<=a[0]:
        if a[i]>=k:
            rk.append(a[i])
        else:
            bk.append(a[i])
        i+=1
    if len(rk)==len(bk):
        l+=1
    rk=[]
    bk=[]
    i=1
    k+=1
        
print(l)

# Optimized solution
n=0
a=[]
i=1
ii=1
l=0
tasu=0
rk=[]
bk=[]
n=int(eval(input()))
for x in input().split(" "):
    a.append(int(x))

a.sort()

print((a[int(len(a)/2)]-a[int(len(a)/2)-1]))
# Original solution
n = int(eval(input()))
d = list(map(int,input().split()))

d.sort()
ans = 0
start_num = d[int(n / 2 - 1)]
end_num = d[int(n / 2)]

ans = end_num - start_num

print(ans)


# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))

d.sort()

print((d[n // 2] - d[n // 2 - 1]))
# Original solution
num_input = int(eval(input()))
input_arr = [int(x) for x in input().split()]

max_input = max(input_arr)
count = 0

for input_ in range(max_input):
    first_arr = [s for s in input_arr if input_ < s]
    second_arr = [s for s in input_arr if input_ >= s]
    if len(first_arr) == len(second_arr):
        count = count + 1
print(count)

# Optimized solution
num_input = int(eval(input()))
input_arr = [int(x) for x in input().split()]

max_input = max(input_arr)
count = 0
second_arr =[]
first_arr = []
sorted_arr = sorted(input_arr)
ans = sorted_arr[int(num_input/2)] - sorted_arr[int(num_input/2)-1]
print(ans)
# Original solution
def calculate(arr):
    length = len(arr)
    s1 = (length // 2) - 1
    s2 = (length // 2)

    if arr[s2] == arr[s1]:
        return 0
    else:
        return arr[s2] - arr[s1]


def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:

        for i in range(lastIndex):
            if arr[i + 1] < arr[i]:
                tmp = arr[i + 1]
                arr[i + 1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1

    return arr

N = int(eval(input()))

if N == 0:
    result = 0
else:
    arr = rank([int(s) for s in  input().split(" ")])
    result = calculate(arr)

print(result)


# Optimized solution
def calculate(arr):
    length = len(arr)
    s1 = (length // 2) - 1
    s2 = (length // 2)

    if arr[s2] == arr[s1]:
        return 0
    else:
        return arr[s2] - arr[s1]

N = int(eval(input()))

if N == 0:
    result = 0
else:
    list = list([int(s) for s in  input().split(" ")])
    list.sort()
    result = calculate(list)

print(result)
# Original solution
n = int(eval(input()))
d = list(map(int, input().split()))

d = sorted(d)
min_ans = d[n//2-1]
max_ans = d[n//2]

print((max_ans - min_ans))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

a = sorted(a)
print((a[n // 2] - a[n // 2 - 1]))
# Original solution
n = eval(input())
l = list(map(int,input().split()))


num =0
for i in range(max(l)+1):
    s =0
    u =0
    for j in l:
        if j <i:
            s +=1
        else:
            u +=1
    if s ==u:
        num +=1
print(num)

# Optimized solution
n = eval(input())
l = list(map(int,input().split()))


m = sorted(l)
if len(m)%2!=0:
    print((0))
else:
    i = len(m)//2 -1
    ans = m[i+1]-m[i]
    print(ans)
# Original solution
N=int(eval(input()))
d=list(map(int, input().split()))
C=N//2
for x in reversed(list(range(1,N+1))):
    for y in range(0,x-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
if d[C]==d[C-1]:
    print((0))
else:
    print((d[C-1]-d[C]))


# Optimized solution
N=int(eval(input()))
d=list(map(int, input().split()))
C=N//2
d.sort()
if d[C]==d[C-1]:
    print((0))
else:
    print((d[C]-d[C-1]))
# Original solution
n = int(eval(input()))
d = sorted(list(map(int, input().split())))
ans = 0
for i in range(d[n//2-1]+1,d[n//2]+1):
    ans +=1
print(ans)

# Optimized solution
n = int(eval(input()))
d = sorted(list(map(int, input().split())))
if d[n//2]==d[n//2 - 1]:
    print((0))
else:
    print((d[n//2]-d[n//2 - 1]))
# Original solution
x = int(eval(input()))
y = input().split()
for u in range(len(y)):
    y[u] = int(y[u])
y = sorted(y)
count = 0

for i in range(max(y)):
    a = [u for u in y if u > i]
    if len(a) == int(len(y) / 2):
        count += 1
print(count)

# Optimized solution
x = int(eval(input()))
y = input().split()
for u in range(len(y)):
    y[u] = int(y[u])
y = sorted(y)
count = y[int(len(y) / 2)] - y[int((len(y) / 2)) - 1]
print(count)
# Original solution
#ABC132_C
N=int(eval(input()))
d=list(map(int,input().split()))

L=2
R=2*10**5


while 1:
    #print('Lis',L)
    #print('Ris',R)
    k=int((L+R)/2)
    #print('kis',k)
    ABC_num=0
    for i in range(len(d)):
        if d[i]<k:
            ABC_num+=1
    #print('ABC_num_is',ABC_num)
    if ABC_num==N/2:
        k_start=k
        break
    elif (L+1)==R:
        k_start=0
        break
    elif ABC_num<N/2:
        L=k
    else:
        R=k       
if k_start!=0:
    k=k_start+1
    while 1:
        ABC_num=0
        for i in range(len(d)):
            if d[i]<k:
                ABC_num+=1
        if ABC_num==N/2:
            k+=1
        else:
            k_r=k-1
            break
    k=k_start-1
    while 1:
        ABC_num=0
        for i in range(len(d)):
            if d[i]<k:
                ABC_num+=1
        if ABC_num==N/2:
            k-=1
        else:
            k_l=k+1
            break
    #print('k_ris',k_r)
    #print('k_lis',k_l)
    print((k_r-k_l+1))
else:
    print((0))

# Optimized solution
#ABC132_C
N=int(eval(input()))
d=list(map(int,input().split()))

d.sort()

ans=d[int(N/2)]-d[int(N/2-1)]
print(ans)
# Original solution
N=int(eval(input()))
D=[int(s) for s in input().split()]

D=sorted(D)
sum=[]
count=0
for i in reversed(list(range(len(D)))):
    sum.append(D.pop(i))
    if len(sum) == len(D):
        Ans=len(sum)
        break
for i in range(D[Ans-1],sum[Ans-1],1):
    count+=1
print(count)

# Optimized solution
N=int(eval(input()))
d=[int(s) for s in input().split(" ")]

d.sort()
K=d[(N//2)]-d[(N//2)-1]
print(K)
# Original solution
N = int(eval(input()))
d_list = list(map(int, input().split()))

count = 0
for k in range(min(d_list), max(d_list) + 1):
    ABC = 0
    ARC = 0
    for i in range(N):
        if k > d_list[i]:
            ABC += 1
        else:
            ARC += 1
    if ABC > ARC:
        break
    elif ABC == ARC:
        count += 1
    else:
        pass

print(count)
        

# Optimized solution
N = int(eval(input()))
d_list = list(map(int, input().split()))
d_list.sort()

k = d_list[int(N/2)]
count = 0
for i in range(N):
    if count == int(N/2):
        print((d_list[int(N/2)] - d_list[int(N/2)-1]))
        break
    elif k > d_list[i]:
        count += 1
    else:
        pass
else: # kの候補の右端は必ずd_listの中
    print((0))
# Original solution
n = int(eval(input()))
d = list(map(int, input().split()))
d = sorted(d)
l = []
now = 0
ans = 0
for i in range(n-1):
    if d[i] != d[i+1]:
        a = d.index(d[i])
        b = d.count(d[i])
        index = a+b-1
        #print(index)
        if index+1 == n/2:
            #print(d[i+1], d[i])
            ans = d[i+1]-d[i]
print(ans)

# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))
d = sorted(d)
print((d[int(n/2)]-d[int(n/2)-1]))
# Original solution
n = int(eval(input()))
d = list(map(int,input().split()))
d.sort()
ans=0
for k in range(1,d[-1]+1):
    abc=[k>i for i in d]
    arc=[k<=i for i in d]
    if sum(arc)==sum(abc):
        ans+=1
print(ans)

# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))
d.sort()
print((d[n//2]-d[(n//2)-1]))
# Original solution
N = int(eval(input()))
d = list(map(int, input().split(' ')))
c = 0
mid = (max(d) + min(d))//2
for i in range(mid//2, mid*2):
    a = sum([1 for val in d if val < i])
    b = sum([1 for val in d if val >= i])
    if a == b:
        c += 1
print(c)

# Optimized solution
N = int(eval(input()))
d = list(map(int, input().split(' ')))
d.sort()

print(( d[N//2] - d[N//2 - 1] ))
# Original solution
N = int(eval(input()))
d = list(map(int, input().split()))
cnt = 0
maxd = max(d)
mind = min(d)
for K in range(mind, maxd+1):
  if len([i for i in d if i >= K]) == len([i for i in d if i < K]): cnt += 1
print(cnt)
  

# Optimized solution
N = int(eval(input()))
d = list(map(int, input().split()))
sor_d = sorted(d)
print((sor_d[int(N*0.5)]-sor_d[int(N*0.5)-1]))
# Original solution
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N = int(eval(input()))
d = sorted(inpl())
if N % 2:
    print((0))
else:
    print((d[N//2]-d[N//2-1]))

# Optimized solution
print(((lambda N,d:((N+1)%2)*(d[N//2]-d[N//2-1]))(int(eval(input())),sorted(list(map(int,input().split()))))))
# Original solution
N = int(eval(input()))
d = list(map(int, input().split()))
""" 
d = [9, 1, 4, 4, 6, 7]
#N = 8
N = 6
#d = [9, 1, 14, 5, 5, 4, 4, 14]
d = [9, 1, 4, 4, 6, 7]
 """
# prob
# [number,value]
prob = []
cnt = 0
for i in d:
    prob.append([cnt, i])
    cnt += 1

""" print(prob)
print(sorted(prob, key=lambda x: x[1]))
 """
sorted_d = sorted(prob, key=lambda x: x[1])

d_max = sorted_d[N-1][1]
d_min = sorted_d[0][1]
#print(d_min, d_max)

cnt = 0
for i in range(N):
    """ print(sorted_d[0:i])
    print(sorted_d[i:])
 """
    if len(sorted_d[0:i]) == len(sorted_d[i:]):
        """ print("True")
        print(sorted_d[i][1])
        print(sorted_d[i-1][1])
        print(sorted_d[i][1] - sorted_d[i-1][1])
         """
        cnt += sorted_d[i][1] - sorted_d[i-1][1]
    # print("------")

print(cnt)


# Optimized solution
N = int(eval(input()))
d = list(map(int, input().split()))
""" 
d = [9, 1, 4, 4, 6, 7]
#N = 8
N = 6
#d = [9, 1, 14, 5, 5, 4, 4, 14]
d = [9, 1, 4, 4, 6, 7]
 """
# prob
# [number,value]
prob = []
cnt = 0
for i in d:
    prob.append([cnt, i])
    cnt += 1

""" print(prob)
print(sorted(prob, key=lambda x: x[1]))
 """
sorted_d = sorted(prob, key=lambda x: x[1])

#print(d_min, d_max)
cnt = 0
# if len(sorted_d[0:i]) == len(sorted_d[i:]):
cnt += sorted_d[int(N/2)][1] - sorted_d[int(N/2-1)][1]

print(cnt)
# Original solution
import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(eval(input()))
    d = list(map(int,input().split()))
    cnt=0

    d.sort()
    a=d[0]
    b=d[n-1]
    c=b-a+1

    for i in range(c):
        index=bisect.bisect_right(d,i+a)
        D=d[index:]
        lend=len(D)
        if(int(n//2)==lend):
            cnt+=1
    
    print(cnt)
    
main()


# Optimized solution
import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(eval(input()))
    d = list(map(int,input().split()))
    cnt=0

    d.sort()
    a=d[(n//2)-1]
    b=d[(n//2)]
    ans=b-a
    print(ans)
    
main()
# Original solution
k=int(eval(input()))
d=sorted(list(map(int,input().split())))
ans=0
for i in range(d[int(len(d)/2)-1]+1,d[int(len(d)/2)]+1):
    ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
a=sorted(list(map(int,input().split())))
p=a[n//2-1]
q=a[n//2]
print((q-p))
# Original solution
n=int(eval(input()))
l=[int(s) for s in input().split()]
cnt=0
mx=max(l)
for i in range(1,mx+1):
  k=i
  arc=0
  abc=0
  for j in range(len(l)):
    if l[j]>=k:
      arc+=1
    else:
      abc+=1
  if arc==abc:
    cnt+=1
print(cnt)

# Optimized solution
n=int(eval(input()))
l=[int(s) for s in input().split()]
cnt=0
l.sort()
print((l[n//2]-l[n//2-1]))
# Original solution
N = int(eval(input()))
d = list(map(int,input().split()))
d.sort()

if d[N//2-1] == d[N//2]:
    print((0))
else:
    print((d[N//2]-d[N//2-1]))

# Optimized solution
N = int(eval(input()))
d = list(map(int,input().split()))
d.sort()

print((d[N//2]-d[N//2-1]))
# Original solution
N = int(eval(input()))
D = [int(i) for i in input().split(" ")]
count = 0
maxd = max(D)
for i in range(maxd+1):
    ARC = []
    ABC = []
    for j in D:
        if i < j:
            ARC.append(j)
        else:
            ABC.append(j)
    if len(ARC) == len(ABC):
        count+=1
print(count)

# Optimized solution
N = int(eval(input()))
D = [int(i) for i in input().split(" ")]
D.sort()
print((D[int(N/2)]-D[int(N/2)-1]))
# Original solution
n = int(eval(input()))
d = list(map(int,input().split()))
c = 0
k = 1
d.sort()

for i in range(1,max(d)+1):
  ab = [j for j in d if i <= j]
  ar = [j for j in d if i > j]
  #print(ab,ar)
  if(len(ab)==len(ar)):
    c = c + 1
  ab = 0
  ar = 0
print(c)

# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))

d.sort()

print((d[int(n/2)] - d[int(n/2)-1]))
# Original solution
#ABC132 C

N = int(eval(input()))
D = list(map(int,input().split()))
count = 0
for K in range(max(D) + 1):
    A = []
    B = []
    for i in range(N):
        if D[i] >= K:
            A.append(D[i])
        else:
            B.append(D[i])
        
    if len(A) == len(B):
        count += 1
        
    
    
print(count)

# Optimized solution
#ABC132 C

N = int(eval(input()))
D = list(map(int,input().split()))
D.sort()
A = list(range(D[int(N/2)-1]+1,D[int(N/2)]+1))

print((len(A)))
# Original solution
N = int(eval(input()))
D = sorted([int(i) for i in input().split()])

maxK = D[N // 2]
minK = D[N // 2 - 1]

print((maxK - minK))

# Optimized solution
n = int(eval(input()))
D = sorted([int(i) for i in input().split()])

if n % 2 == 1:
    print((0))
else:
    m = n // 2
    print((D[m] - D[m - 1]))
# Original solution
# -*- coding: utf-8 -*-
n = int(eval(input()))
d = [int(i) for i in input().split()] 

d.sort()
ans = d[n // 2] - d[n // 2 - 1]
print((max(ans, 0)))


# Optimized solution
# -*- coding: utf-8 -*-
n = int(eval(input()))
d = [int(i) for i in input().split()]

d.sort()
k = d[n // 2] - d[n // 2 - 1]
print(k)
# Original solution
# -*- coding: utf-8 -*-
def main():
    N = int(eval(input()))
    D =[int(i) for i in input().split()]
    count = 0
    D.sort()
    D.reverse()
    #print(D)
    for j in range(100000):
        if j > D[0]:
            break
        for i in range(N):
            if D[i] < j:
                if i == (N/2):
                    count+=1
                else:
                    break
    print(count)
if __name__ == '__main__':
    main()

# Optimized solution
# -*- coding: utf-8 -*-
def main():
    N = int(eval(input()))
    D =[int(i) for i in input().split()]
    #count = 0
    D.sort()
    D.reverse()
    center = D[int(N/2)]
    print((D[int((N/2))-1]-center))
if __name__ == '__main__':
    main()
# Original solution
from sys import stdin
import itertools

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
key = n//2
print((li[key:][0]-li[:key][-1]))

# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))

d.sort()

print((d[n//2]-d[n//2-1]))
# Original solution
N = int(eval(input()))
d = list(map(int, input().split()))
c = 0

c_R = 0
c_B = 0

d_min = min(d)
d_max = max(d)

for K in range(d_min,d_max+1):
    c_R = 0
    c_B = 0
    for i in range(N):
        if K <= d[i] :
            c_R = c_R + 1
        else:
            c_B = c_B + 1
    if c_R == c_B:
        c = c + 1

print(c)
        
    


# Optimized solution
N = int(eval(input()))
d = list(map(int, input().split()))
d.sort()
K = d[N//2]
J = d[N//2 - 1]
if K == J :
    print((0))
else:
    print((K - J))
# Original solution
n = int(eval(input()))

d = list(map(int,input().split()))
ans = 0
k_m = max(d)

for i in range(1, k_m+1):
    abc = []
    arc = []
    arc = [j for j in d if j >= i]  
    abc = [k for k in d if k < i]
    if len(arc) == len(abc):
        ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))

d = sorted(list(map(int,input().split())))

print((d[n//2] - d[n//2-1]))
# Original solution
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)


Q = int(eval(input()))
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        S_list.reverse()
    else:
        if f == '1':
            S_list.appendleft(c)
        else:
            S_list.append(c)
print((''.join(S_list)))

# Optimized solution
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
is_reverse = False

Q = int(eval(input()))
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        is_reverse = not is_reverse
    else:
        if f == '1':
            if is_reverse:
                S_list.append(c)
            else:
                S_list.appendleft(c)
        else:
            if is_reverse:
                S_list.appendleft(c)
            else:
                S_list.append(c)
if is_reverse:
    S_list.reverse()
print((''.join(S_list)))
# Original solution
from collections import deque

S = input().rstrip('\r\n')
S_list = deque(S)
is_reverse = False

Q = int(eval(input()))
for _ in range(Q):
    query = input().rstrip('\r\n')
    t, f, c = '', '', ''
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(' ')
    if t == '1':
        is_reverse = not is_reverse
    else:
        if f == '1':
            if is_reverse:
                S_list.append(c)
            else:
                S_list.appendleft(c)
        else:
            if is_reverse:
                S_list.appendleft(c)
            else:
                S_list.append(c)
if is_reverse:
    S_list.reverse()
print((''.join(S_list)))

# Optimized solution
import sys
input = sys.stdin.readline
from collections import deque
def main():
    S = input().rstrip("\r\n")
    Q = int(eval(input()))
    d = deque(S)
    reverse = False
    for _ in range(Q):
        q = input().rstrip("\r\n")
        if q == "1":
            reverse = not reverse
        else:
            _, f, c = q.split()
            if (f == "1" and not reverse) or (f == "2" and reverse):
                d.appendleft(c)
            else:
                d.append(c)
    l = list(d)
    if reverse:l.reverse()
    print(("".join(l)))
if __name__ == "__main__":
    main()
# Original solution
from collections import deque

d = deque(list(input()))
for _ in range(int(input())):
    a = input()
    if a[0] == '1':
        d.reverse()
    elif a[2] == '1':
        d.appendleft(a[4])
    else:
        d.append(a[4])
print(*d, sep='')


# Optimized solution
from collections import deque

d = deque(list(input()))
flag = 1
for _ in range(int(input())):
    a = input()
    if a[0] == '1':
        flag *= -1
    elif a[2] == '1' and flag == 1:
        d.appendleft(a[4])
    elif a[2] == '1' and flag == -1:
        d.append(a[4])
    elif a[2] == '2' and flag == 1:
        d.append(a[4])
    else:
        d.appendleft(a[4])
if flag == -1:
    d.reverse()
print(*d, sep='')
# Original solution
from collections import deque
s,q=deque([*input()]),int(input())
for i in range(q):
  t=input().split()
  if len(t)==1:
    s.reverse()
  else:
    t,f,c=t
    if f=='1': s.appendleft(c)
    else: s.append(c)
print(*s,sep='')


# Optimized solution
from collections import deque
s,q=deque([*input()]),int(input())
judge=False
for i in range(q):
  t=input().split()
  if len(t)==1:
    judge = not judge
  else:
    t,f,c=t
    if not judge and f=='1': s.appendleft(c)
    elif not judge and f=='2': s.append(c)
    elif judge and f=='1': s.append(c)
    else: s.appendleft(c)
if judge: s.reverse()
print(*s,sep='')
# Original solution
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = readline().decode().strip()
q = int(readline())
is_reversed = False
qs = read().decode().split("\n")
left = ""
right = ""
for i in range(q):
    query = qs[i].split()
    t = int(query[0])
    if t == 1:
        is_reversed = not is_reversed
    elif t == 2:
        f = int(query[1])
        c = query[2]
        if f == 1:
            if is_reversed:
                right += c
            else:
                left += c
        elif f == 2:
            if is_reversed:
                left += c
            else:
                right += c
s = left[::-1] + s + right
if is_reversed:
    print((s[::-1]))
else:
    print(s)

# Optimized solution
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = readline().decode().strip()
q = int(readline())
is_reversed = False
qs = read().decode().split("\n")
left = []
right = [] 
for i in range(q):
    query = qs[i].split()
    t = int(query[0])
    if t == 1:
        is_reversed = not is_reversed
    elif t == 2:
        f = int(query[1])
        c = query[2]
        if f == 1:
            if is_reversed:
                right.append(c)
            else:
                left.append(c)
        elif f == 2:
            if is_reversed:
                left.append(c)
            else:
                right.append(c)

s = "".join(reversed(left)) + s + "".join(right)
if is_reversed:
    print((s[::-1]))
else:
    print(s)
# Original solution
from sys import stdin

def main():

    S = stdin.readline().rstrip() 
    Q = int(eval(input()))
    rev = 0
    for _ in range(Q):
        q = stdin.readline()

        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    S = "{}{}".format(q[4], S)
                else:
                    S = "{}{}".format(S, q[4])
            else:
                if rev ==0:
                    S = "{}{}".format(S, q[4])
                else:
                    S = "{}{}".format(q[4], S)
    if rev == 1:
        S = S[::-1]

    print(S)

main()

# Optimized solution
from sys import stdin

def main():
    S = list(stdin.readline().rstrip())
    Q = int(eval(input()))
    rev = 0
    head = []
    tail = []

    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    head.append(q[4])
                else:
                    tail.append(q[4])
            else:
                if rev ==0:
                    tail.append(q[4])
                else:
                    head.append(q[4])

    if rev == 0:
        ans = "".join(head[::-1] + S + tail)
    else:
        ans = "".join(tail[::-1] + S[::-1] + head)
    
    print(ans)
    """
    S = stdin.readline().rstrip() 
    Q = int(input())
    rev = 0
    for _ in range(Q):
        q = stdin.readline()

        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    S = "{}{}".format(q[4], S)
                else:
                    S = "{}{}".format(S, q[4])
            else:
                if rev ==0:
                    S = "{}{}".format(S, q[4])
                else:
                    S = "{}{}".format(q[4], S)
    if rev == 1:
        print(S[::-1])
    else:
        print(S)
    """
main()