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

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = ns()
k = ni()
ans = []

for j in range(len(s)):
    ans.append(s[j])
    if j < len(s)-1:
        t = j+2
        while True:
            ans.append(s[j:t])
            if t == len(s):
                break
            t += 1
l = list(set(ans))
l.sort()
print(l[k-1])


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = ns()
k = ni()
ans = []

for i in range(len(s)):
    ans.append(s[i])
    if i < len(s)-1:
        t = i+2
        while True:
            ans.append(s[i:t])
            if t == len(s):
                break
            t += 1
            if t - i > 5:
                break

ans = list(set(ans))
ans.sort()
print(ans[k-1])
### BUGGY CODE ###

H,W,D = map(int,input().split(" "))
mass = [[0 for _ in range(W)] for _ in range(H)]
num = [[0,0] for _ in range(H * W + 1)]
DP = [0 for _ in range(H * W + 1)]
for i in range(H):
  mass[i] = list(map(int,input().split(" ")))
for i in range(H):
  for i2 in range(W):
    num[mass[i][i2]] = [i,i2]
for i in range(D,W * H + 1):
  DP[i] = abs(num[i][0] - num[i - D][0]) + abs(num[i][1] - num[i - D][1])
L = 0
R = 0
ans = 0
Q = int(input())
for i in range(Q):
  ans = 0
  L,R = map(int,input().split(" "))
  while L != R:
    L += D
    ans += DP[L]
  print(ans)


### FIXED CODE ###

H,W,D = map(int,input().split(" "))
mass = [[0 for _ in range(W)] for _ in range(H)]
num = [[0,0] for _ in range(H * W + 1)]
DP = [0 for _ in range(H * W + 1)]
for i in range(H):
  mass[i] = list(map(int,input().split(" ")))
for i in range(H):
  for i2 in range(W):
    num[mass[i][i2]] = [i,i2]
for i in range(D,W * H + 1):
  DP[i] = DP[i - D] + abs(num[i][0] - num[i - D][0]) + abs(num[i][1] - num[i - D][1])
L = 0
R = 0
ans = 0
Q = int(input())
for i in range(Q):
  ans = 0
  L,R = map(int,input().split(" "))
  print(DP[R] - DP[L])
### BUGGY CODE ###

n = int(input())
L = list(map(int,input().split()))
ans = 0
import itertools
for l in list(itertools.combinations(L,3)):
    a, b, c = l
    if a < b + c and b < c + a and c < a + b:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
L.sort()
L2 = []
ans = 0
import bisect
for i in range(n-2):
    for j in range(i+1, n-1):
        index = bisect.bisect_left(L,  L[i] + L[j])
        ans += index - j - 1
print(ans)
### BUGGY CODE ###

N=int(input())
H=list(map(int,input().split()))
count=[0]*N
for i in range(N):
  for j in range(i+1,N):
    if(H[i]>=H[j]):
      count[i]+=1
      i=j
    else:
      break
print(max(count))

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
count=0
maxcount=[0]*N
for i in range(N-1):
  if(H[i]>=H[i+1]):
    count+=1
  else:
    count=0
  maxcount[i]=count

print(max(maxcount))
### BUGGY CODE ###

import numpy as np

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
 
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
  B = np.cumsum(B)
  #for i in range(1, N):
    #B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
 
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)
### BUGGY CODE ###

def d_lamp(H, W, Grid):
    num_left = [[0] * W for _ in range(H)]
    num_right = [[0] * W for _ in range(H)]
    num_down = [[0] * W for _ in range(H)]
    num_up = [[0] * W for _ in range(H)]

    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '.':
                num_left[row][col] = 1 if col == 0 else (num_left[row][col - 1] + 1)

    for row in range(H):
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                num_right[row][col] = 1 if col == W - 1 else (num_right[row][col + 1] + 1)

    for col in range(W):
        for row in range(H):
            if Grid[row][col] == '.':
                num_up[row][col] = 1 if row == 0 else (num_up[row - 1][col] + 1)

    for col in range(W):
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                num_down[row][col] = 1 if row == H - 1 else (num_down[row + 1][col] + 1)

    ans = max(num_left[row][col] + num_right[row][col] + num_up[row][col]
              + num_down[row][col] - 3 for row in range(H) for col in range(W))
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(d_lamp(H, W, Grid))

### FIXED CODE ###

def d_lamp(H, W, Grid):
    field_horizontal = [[0] * W for _ in range(H)]
    field_vertical = [[0] * W for _ in range(H)]
    field = [[0] * W for _ in range(H)]

    for row in range(H):
        tmp = 0
        for col in range(W):
            if Grid[row][col] == '.':
                tmp += 1
                field_horizontal[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_horizontal[row][col])
                field_horizontal[row][col] = max_val
            else:
                max_val = 0

    for col in range(W):
        tmp = 0
        for row in range(H):
            if Grid[row][col] == '.':
                tmp += 1
                field_vertical[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_vertical[row][col])
                field_vertical[row][col] = max_val
            else:
                max_val = 0

    for row in range(H):
        for col in range(W):
            field[row][col] = field_horizontal[row][col] + field_vertical[row][col]

    ans = 0
    for row in range(H):
        for col in range(W):
            ans = max(ans, field[row][col])

    return max(ans - 1, 0)

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(d_lamp(H, W, Grid))
### BUGGY CODE ###

from bisect import bisect_left, bisect_right, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                ri = bisect_right(abc[i], r)
                if li != ri:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

dic = {0: input()}
left = 0
right = 0
rev = False
q = int(input())
for i in range(q):
  query = input()
  if query[0] == "1":
    #反転
    for i in range(len(dic) // 2):
      dic[left + i], dic[right - i] = dic[right - i], dic[left + i]
    if rev == True:
      rev = False
    else:
      rev = True
  elif query[0] == "2":
    #追加
    num, front, c = query.split()
    if front == "1":
      dic[left - 1] = c
      left -= 1
    elif front == "2":
      dic[right + 1] = c
      right += 1

#出力
for i in range(left, right+1):
  string = dic[i]
  if len(string) > 1 and rev == True:
    string = string[::-1]
  print(string, end="")
print()

### FIXED CODE ###

from collections import deque
s = list(input())
moji = deque(s)

is_forward = True

q = int(input())
for i in range(q):
    query = input()
    if query[0] == "1":
        is_forward = is_forward ^ 1
    elif query[0] == "2":
        _, f, c = query.split()
        f = int(f)
        f %= 2
        is_end = f ^ is_forward
        if is_end:
            moji.append(c)
        else:
            moji.appendleft(c)

if is_forward == False:
    moji = list(moji)[::-1]
print("".join(moji))
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]


def max_GCD(m_list):
  m_list.sort()
  a = m_list.pop()
  result = a
  while m_list:
    b = m_list.pop()
    a = GCD(a, b)
    if a < result:
      result = a
    if result == 1:
      return result
  return result

def GCD(m, n):
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

r_list = [0] * N
for i in range(N):
  A_ = A.copy()
  A_.pop(i)
  r_list[i] = max_GCD(A_)
  
print(max(r_list))

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]

def GCD(m, n):
  if m == 0:
    return n
  elif n == 0:
    return m
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
  L[i + 1] = GCD(L[i], A[i])
  R[N - i - 1] = GCD(R[N - i], A[N - i - 1])
M = [GCD(L[i], R[i+1]) for i in range(N)]
print(max(M))
### BUGGY CODE ###

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def func(v, d, c, color, depth, graph):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return

    for u in graph[v]:
        func(u, d - 1, c, color, depth, graph)

def main():
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for v, d, c in q[::-1]:
        func(v, d, c, color, depth, graph)
    print(*color, sep="\n")

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


color, depth, graph = [], [], {}
def func(v, d, c):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return
    depth[v] = d
    for u in graph[v]:
        func(u, d - 1, c)


def main():
    global color, depth, graph
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for i in range(Q - 1, -1, -1):
        func(q[i][0], q[i][1], q[i][2])
    print(*color, sep="\n")

if __name__ == '__main__':
    main()
### BUGGY CODE ###

k = int(input())

if k%2==0:
    print('-1')
    exit()

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
print(i)


### FIXED CODE ###

k = int(input())

if k%2==0:
    print('-1')
    exit()

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)
### BUGGY CODE ###

def main():
    n = int(input())
    x = input()

    A = [0] * n
    nx = int(x, 2)
    c1 = x.count('1')
    for i in range(n):
        c1s = c1
        nxs = nx
        if x[i] == '0':
            c1s += 1
            nxs += 2 ** (n - i - 1)
        else:
            c1s -= 1
            nxs -= 2 ** (n - i - 1)

        while c1s > 0:
            nxs %= c1s
            c1s = format(nxs, 'b').count('1')
            A[i] += 1

    for a in A:
        print(a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    x = input()

    c1 = x.count('1')
    c1p, c1m = c1 + 1, c1 - 1
    sp = sum(pow(2, n - i - 1, c1p) for i, c in enumerate(x) if c == '1')
    sm = None
    if c1m > 0:
        sm = sum(pow(2, n - i - 1, c1m) for i, c in enumerate(x) if c == '1')

    A = [0] * n
    for i in range(n):
        nx = None
        if x[i] == '0':
            nx = (sp + pow(2, n - i - 1, c1p)) % c1p
        else:
            if sm is None:
                continue

            nx = (sm - pow(2, n - i - 1, c1m)) % c1m

        A[i] += 1

        while nx > 0:
            nx %= format(nx, 'b').count('1')
            A[i] += 1

    for a in A:
        print(a)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

input = sys.stdin.readline

N, M, K = [int(s) for s in input().split()]
n = 0
A = [0]
for s in input().split():
    n = n + int(s)
    A.append(n)

n = 0
B = [0]
for s in input().split():
    n = n + int(s)
    B.append(n)

ans = 0
for i, a_time in enumerate(A):
    for j, b_time in enumerate(B):
        read_time = a_time + b_time
        if read_time <= K:
            if ans <= i + j:
                ans = i + j
        else:
            break

print(ans)

### FIXED CODE ###

import sys

N, M, K = [int(s) for s in sys.stdin.readline().split()]
n = 0
A = [0]
for s in sys.stdin.readline().split():
    n = n + int(s)
    A.append(n)

n = 0
B = [0]
for s in sys.stdin.readline().split():
    n = n + int(s)
    B.append(n)

ans = 0
for i in range(N + 1):
    if A[i] > K:
        break
    for j in range(M, -1, -1):
        if A[i] + B[j] <= K:
            ans = max(ans, i + j)
            M = j
            break

print(ans)
### BUGGY CODE ###

import math
N= int(input())
c=list(str(input()))
#N=4
#c=['W', 'W', 'R', 'R']
#c.reverse()
#print(c)
num=0
for i in range(N):
    if c[N-1-i]=='R':
        #print('1',i+1)
        for u in range(N):
            if c[u]=='W' and u<N-1-i:
                #print('2',u+1)
                c[N-1-i]='W'
                c[u]='R'
                num+=1
                break
print(num)

### FIXED CODE ###

N= int(input())
c=list(str(input()))
#N=4
#c=['W', 'W', 'R', 'R']
#c.reverse()
#print(c)

t1=t2=True

n1=0
n2=0
num=0
while t1:
    t2=True
    if not 0<=N-1-n1<=N-1:
        t1=False
    if c[N-1-n1]=='W':
        n1+=1
        continue
    else:
        while t2:
            if c[n2]=='W':
                if n2<N-1-n1:
                    c[N-1-n1]='W'
                    c[n2]='R'
                    num+=1
                    t2=False
                    continue
                else:
                    t1=False 
            n2+=1
            if not 0<=n2<=N-1:
                t1=False
                t2=False
print(num)
### BUGGY CODE ###

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

rev = False

for i in range(q):
    inp = input()
    if inp == '1':
        rev = True if rev == False else False
    else:
        n = inp.split()[1]
        t = inp.split()[2]
        if n == '1':
            s = s + t if rev == True else t + s
        else:
            s = t + s if rev == True else s + t

if rev == True:
    s_rev = s[::-1]
    print(s_rev)
else:
    print(s)


### FIXED CODE ###

from collections import deque

s = input()
d = deque(s)
q = int(input())

rev = False

for i in range(q):
    inp = input()
    if inp == '1':
        rev = True if rev == False else False
    else:
        n = inp.split()[1]
        t = inp.split()[2]
        if n == '1':
            d.append(t) if rev == True else d.appendleft(t)
        else:
            d.appendleft(t) if rev == True else d.append(t)

if rev == True:
    d.reverse()

print(''.join(d))
### BUGGY CODE ###

import math
from functools import reduce 
import itertools
k = int(input())
l = [i for i in range(1,k+1)]
ans = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for x in itertools.product(l,repeat=3):
    ans += gcd(x[0],x[1],x[2])
print(ans)

### FIXED CODE ###

import math
from functools import reduce 
import itertools
k = int(input())
l = [i for i in range(1,k+1)]
ans = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for x in itertools.product(l,repeat=3):
    ans += gcd(x[0],x[1],x[2])
print(ans)
### BUGGY CODE ###

import bisect
def prime(n):
    seq = list(range(2, n))
    while len(seq) > 0:
        prime = seq.pop(0)
        yield prime
        # 素数で割り切れない数字のリストを作成
        seq = [i for i in seq if not i % prime == 0]

q=int(input())
l = []
r = []
for i in range(q):
    x,y = map(int,input().split())
    l.append(x)
    r.append(y)

a = list(prime(max(r)+1))
#print('a',a)
c = []
for i in range(len(a)):
    if (a[i]+1)/2 in a:
        c.append(a[i])

c.sort()
#print('c',c)

for i in range(q):
    h = bisect.bisect_left(c,l[i])
    j = bisect.bisect_right(c,r[i])
    print(j-h)

### FIXED CODE ###

import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])
### BUGGY CODE ###

def gcd(a):
    b = sorted(a)
    c = [0 for i in range(len(b))]
    for i in range(len(b)):
        if b[i]%b[0]==0:
            c[i]=b[0]
        else:
            c[i]=b[i]%b[0]
    d=sorted(c)
    if d[0]==d[-1]:
        return d[0]
    else:
        return gcd(c)
n = int(input())
a = list(map(int,input().split()))
e = [0 for i in range(n)]
for i in range(n):
    e[i] = gcd(a[:i]+a[i+1:])
print(max(e))


### FIXED CODE ###

def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n)]
r=[0 for i in range(n)]
e=[0 for i in range(n)]
for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))
### BUGGY CODE ###

N = int(input())
edges = []
for i in range(N-1):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, c])
    edges.append([b-1, a-1, c])
Q, K = map(int, input().split())
K -= 1
def bellman_ford(edges, num_v, start):
    dist = [float('inf') for _ in range(num_v)]
    dist[start] = 0

    changed = True
    while changed:
        changed = False
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                changed = True
    return dist

ans_list = []
base = bellman_ford(edges, N, K)
for i in range(Q):
    x, y = map(lambda n: int(n) - 1, input().split())
    x_K = base[x]
    K_y = base[y]
    ans_list.append(x_K + K_y)

for i in ans_list:
    print(i)

### FIXED CODE ###

import heapq
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    edges[a-1].append([b-1, c])
    edges[b-1].append([a-1, c])
Q, K = map(int, input().split())
K -= 1


ans_list = []
def dijkstra(edges, num_v, start):
    dist = [float('inf')] * num_v
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])

    while len(q) > 0:
        _, u = heapq.heappop(q)
        for edge in edges[u]:
            if dist[edge[0]] > dist[u] + edge[1]:
                dist[edge[0]] = dist[u] + edge[1]
                heapq.heappush(q, [dist[u] + edge[1], edge[0]])
    return dist
base = dijkstra(edges,  N, K)
for i in range(Q):
    x, y = map(lambda n: int(n) - 1, input().split())
    x_K = base[x]
    K_y = base[y]
    ans_list.append(x_K + K_y)

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

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

for i in range(q):
    t = input()
    if t == "1":
        s = s[::-1]
    else:
        t2, f, c = t.split()
        if f == "1":
            s = c + s
        elif f == "2":
            s += c

print(s)


### FIXED CODE ###

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

is_reverse = False
front_queue = []
back_queue = []
for i in range(q):
    t = input()
    if t == "1":
        is_reverse = not is_reverse
    else:
        t2, f, c = t.split()
        if (f == "1" and not is_reverse) or (f == "2" and is_reverse):
            front_queue.append(c)
        else:
            back_queue.append(c)

result = ""
if is_reverse:
    result = "".join(reversed(back_queue)) + s[::-1] + "".join(front_queue)
else:
    result = "".join(reversed(front_queue)) + s + "".join(back_queue)
print(result)
### BUGGY CODE ###

n=int(input())
s=0
for i in range(1,n):
    for j in range(1,n):
        if i*j<n:
            s+=1
print(s)    

### FIXED CODE ###

n=int(input())
s=[n-1]
for i in range(2,n):
    s.append((n-1)//i)
t=0    
for j in s:
    t+=j
print(t)