Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

s = input()
q = int(input())

reverse = False
count = 0
for i in range(q):
    qu = input()
    if qu[0] == "1":
        count += 1
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        _, f, c = qu.split()
        if reverse:
            if f == "1":
                s = s + c
            else:
                s = c + s
        else:
            if f == "1":
                s = c + s
            else:
                s = s + c

if count % 2:
    print(s[::-1])
else:
    print(s)

### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

reverse = False
count = 0
mae = deque()
ushiro = deque()
for i in range(q):
    qu = input()
    if qu[0] == "1":
        count += 1
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        _, f, c = qu.split()
        if reverse:
            if f == "1":
                ushiro.append(c)
            else:
                mae.appendleft(c)
        else:
            if f == "1":
                mae.appendleft(c)
            else:
                ushiro.append(c)

s = "".join(mae) + s + "".join(ushiro)

if count % 2:
    print(s[::-1])
else:
    print(s)
### BUGGY CODE ###

def solve():
    N = int(input())
    X = list(map(int, input().split()))
    
    for i in range(N):
        l = X[:i] + X[i+1:]
        l.sort()
        print(l[N//2-1])

if __name__ == '__main__':
    solve()

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()

l = Y[N//2-1]
r= Y[N//2]

for i in X:
    if i <= l:
        print(r)
    else:
        print(l)
### BUGGY CODE ###

import itertools
N = int(input())
L = map(int,input().split())
tmp = list(itertools.combinations(L,3))
ans = 0
for i in range(len(tmp)):
    if tmp[i][0] < (tmp[i][1] + tmp[i][2]):
        if tmp[i][1] < (tmp[i][0] + tmp[i][2]):
            if tmp[i][2] < (tmp[i][0] + tmp[i][1]):
                ans += 1
print(ans)

### FIXED CODE ###

import itertools
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        ind_cmin = j+1
        ind_cmax = bisect.bisect_left(L,a+b)-1
        ans += ind_cmax - ind_cmin + 1
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

for i in range(1, N+1):
    s = A.count(i)
    print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
tm = [0] * n

for i in range(n-1):
    tm[a[i] - 1] += 1

for i in tm:
    print(i)
### BUGGY CODE ###

data = input().split()
a = int(data[0])
b = int(data[1])
n = int(data[2])

max = 0
cnt = 1
for i in range(n+1):
    x = cnt * b - 1
    if x > n:
        x = n
        i = n
    test = int(a*x/b) - a*int(x/b)
    if max < test:
        max = test
    i = i + b
    cnt = cnt + 1
print(max)

### FIXED CODE ###

a,b,n = map(int, input().split())
def func(x):
    return int(a*x/b) - a*int(x/b)

if n < b-1:
    print(func(n))
else :
    print(func(b-1))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

A.sort()

ans = 0
while True:
    count = A.count(A[0])
    if count > A[0]:
        ans += count - A[0]
    elif count < A[0]:
        ans += count
    A = A[count:]
    if len(A) == 0:
        break

print(ans)

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)

ans = 0
for i, m in c.items():
    if m < i:
        ans += m
    else:
        ans += m - i
print(ans)
### BUGGY CODE ###

S=input()
Q=int(input())

for i in range(Q):
  Query=input()
  if len(Query)==1:
    S=S[::-1]
  else:
    if Query[2]=='1':
      S=Query[4]+S
    else:
      S+=Query[4]

print(S)

### FIXED CODE ###

from collections import deque

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

t=True

for i in range(Q):
  query=input().split()
  if query[0]=='1':
    t = not t
  else:
    if (t and query[1]=='1') or (not t and query[1]=='2'):
      S.appendleft(query[2])
    else:
      S.append(query[2])

S=''.join(S)

if not t:
  S=S[::-1]

print(S)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

count = 0
for i in range(n):
    for j in range(i + 1, n):
        dic1 = {}
        dic2 = {}
        for k in range(10):
            
            if s[i][k] in dic1:
                dic1[s[i][k]] += 1
            else:
                dic1[s[i][k]] = 1
            if s[j][k] in dic2:
                dic2[s[j][k]] += 1
            else:
                dic2[s[j][k]] = 1
        
        if dic1 == dic2:
            #print(dic1, dic2)
            count += 1
print(count)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

count = 0
dic1 = {}
#print(s)
for i in range(n):
    #print(s[i])
    so = sorted(s[i])
    so = ''.join(so)
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    #print(count, dic1)
print(count)