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

import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
import bisect #二部探索
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
INF = 10**9 + 7
mod = 10**9 + 7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    n = int(input())
    # 1～n-1 までcを回す
    c = 1
    ans = 0
    while(c <= n-1):
        ab = n - c
        if ab == 1:
            ans += 1
            break
        arr_ab = factorization(ab)
        ans_temp = 1
        for i in range(len(arr_ab)):
            ans_temp *= arr_ab[i][1] + 1
        #print(ans_temp, arr_ab)
        ans += ans_temp
        c += 1
    print(ans)
    return 0

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
import bisect #二部探索
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
INF = 10**9 + 7
mod = 10**9 + 7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int-type.')
    if n < 2:
        raise ValueError('n is more than 2')
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

def main():
    n = int(input())
    # 1～n-1 までcを回す
    x = math.floor(math.sqrt(n-1))
    ans = 0
    a = 1
    while(a <= x):
        ans += (n-1) // a
        a += 1
    ans -= (x - 1) * x / 2
    ans *= 2
    ans -= x
    print(int(ans))
    return 0

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

n, k, c = map(int, input().split())
s = list(map(lambda x: 1 if x == 'o' else 0, input()))
b_a = []
c_k = 0
for i in range(n-1, -1, -1):
    if c_k == 0 and s[i] == 1:
        b_a.append(i)
        c_k = c
    else:
        c_k = max(c_k-1, 0)
c_k = 0
ans = []
for i in range(n):
    if c_k == 0 and s[i] == 1:
        if i in b_a:
            ans.append(i+1)
        c_k = c
    else:
        c_k = max(c_k-1, 0)
if len(ans) <= k:
    for i in ans:
        print(i)

### FIXED CODE ###

from collections import deque
n, k, c = map(int, input().split())
s = list(map(lambda x: 1 if x == 'o' else 0, input()))
b_a = deque()
b_b = deque()
c_k = 0
for i in range(n-1, -1, -1):
    if c_k == 0 and s[i] == 1:
        b_a.append(i)
        c_k = c
    else:
        c_k = max(c_k-1, 0)
c_k = 0
for i in range(n):
    if c_k == 0 and s[i] == 1:
        b_b.append(i)
        c_k = c
    else:
        c_k = max(c_k-1, 0)

ans = list(set(b_a) & set(b_b))
ans.sort()
if len(ans) <= k:
    for i in ans:
        print(i+1)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def get_yakusu(n):
    ans = set()
    for i in range(1, int(math.sqrt(n)) + 2):
        if n % i == 0:
            if i != 1:
                ans.add(i)
            if n // i != i:
                ans.add(n // i)
    return list(ans)

def main():
    N = I()
    cnt = 0
    yakusu = get_yakusu(N)
    n1yakusu = get_yakusu(N-1)
    for n in yakusu:
        cpN = N
        while cpN % n == 0:
            cpN //= n
        if cpN % n == 1:
            cnt += 1
    cnt += len(n1yakusu)
    print(cnt)
main()



### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def get_yakusu(n):
    ans = set()
    for i in range(1, int(math.sqrt(n)) + 2):
        if n % i == 0:
            if i != 1:
                ans.add(i)
            if n // i != i:
                ans.add(n // i)
    return ans

def main():
    N = I()
    cnt = 0
    yakusu = get_yakusu(N)
    n1yakusu = get_yakusu(N-1)
    for n in yakusu:
        cpN = N
        loop = 0
        while True:
            loop += 1
            if loop > 100:
                break
            if cpN % n == 0:
                cpN = cpN // n
            else:
                break
        if cpN % n == 1:
            cnt += 1
    cnt += len(n1yakusu)
    print(cnt)
main()
### BUGGY CODE ###

N, M = list(map(int, input().split()))
P = []
S = []

def f(s):
  lst = s.split()
  return int(lst[0]),lst[1]



for i in range(M):
  p, s = f(input())
  P.append(p)
  S.append(s)

correct = 0
penalty = 0
q = []
relate = []

for i, j in enumerate(S):
  if 'AC' in j:
    if P[i] not in q:
      q.append(P[i])
      relate.append(P[i])
      correct += 1
    else:
      relate.append(P[i])
      continue
  if 'WA' in j:
    if P[i] not in q:
        penalty += 1
    else:
      continue

for i, j in enumerate(S):
  if 'WA' in j:
    if P[i] not in relate:
      penalty -= 1

print(correct, penalty)


### FIXED CODE ###


N,M = map(int, input().split())

isAC = [0] * (N+1)
isWA = [0] * (N+1)

ACnum = 0
WAnum = 0

for _ in range(M):
    p, s = input().split()
    p = int(p)

    if isAC[p] == 1: continue
    if s == 'AC':
        isAC[p] = 1
        ACnum += 1
        WAnum += isWA[p]
    elif s == 'WA':
        isWA[p] += 1

print("%d %d"%(ACnum, WAnum))
### BUGGY CODE ###

def main():
    h, w = list(map(int, input().split()))
    matrix = []
    for _ in range(h):
        matrix.append([c for c in input()])

    adj = [(0, 1), (0, -1), (1, 0), (-1, 0)]

    def step(mat):
        filled = mat
        target = []
        for i in range(h):
            for j in range(w):
                if mat[i][j] == '#':
                    target.append((i, j))
        for ti, tj in target:
            for dy, dx in adj:
                if -1 < ti + dy < h and -1 < tj + dx < w:
                    filled[ti+dy][tj+dx] = '#'

        return filled

    def finished(mat):
        for i in range(h):
            for j in range(w):
                if mat[i][j] != '#':
                    return False
        return True

    count = 0
    mat = matrix
    for _ in range(h * w):
        # for line in mat:
        #    print(line)

        if finished(mat):
            break

        # print('-' * 20)
        mat = step(mat)
        count += 1

    print(count)

main()


### FIXED CODE ###

import numpy

def main():
    h, w = map(int, input().split())
    max_value = h + w
    gridmap = []

    for y in range(h):
        gridmap.append([0 if v == '#' else max_value for v in input().strip()])

    values = numpy.array(gridmap)

    for x in range(w - 1):
        values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

    for x in range(w - 1, 0, -1):
        values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

    for y in range(h - 1):
        values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

    for y in range(h - 1, 0, -1):
        values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

    print(numpy.max(values))


main()
### BUGGY CODE ###

N = int (input ())
A = [int (x) for x in input().split()]
X = 0
for i in range (N-1):
  for j in range (N-i-1):
    X += A[i]*A[j+i+1]
    if X > 10**9+7:
      X = X%(10**9+7)
print (X)

### FIXED CODE ###

N = int (input ())
A = [int (x) for x in input().split()]
S = sum (A)
X = 0
for i in range (N-1):
  X += A[i]*(S-A[i])
  S -= A[i]
  if X > 10**9+7:
    X = X%(10**9+7)
print (X)
### BUGGY CODE ###

N = int(input())
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = 1
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

### FIXED CODE ###

N = int(input())
P = [1,1]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]//t,P[1]//a,1)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))
### BUGGY CODE ###

N = int(input())
S = []
S.append(input())
r = 1
for i in range(N-1):
    p = input()
    q = 0
    for k in range(r):
        if p == S[k]:
            q = 1
            break
    if q == 0:
        S.append(p)
        r += 1
print(r)

### FIXED CODE ###

N = int(input())
S = set()
for i in range(N):
    S.add(input())
print(len(S))
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    tot = 0
    while A:
        A.pop()
        tot += A.pop()
        A.pop(0)
    return tot

if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    tot = 0
    for i in range(N):
        tot += A[3*N-2-2*i]
    return tot
if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

def main():
    import numpy as np

    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    A = np.append(A, 0)
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=int)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
    print(*A[:-1])


if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
from numba import jit


@jit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


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

def main():
    H, W = map(int, input().split())
    N = 80 * (H+W) // 2 + 1
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    dp = [[[False] * N for _ in range(W+1)] for _ in range(2)]
    dp[0][1][0] = True
    for i in range(H):
        dp[(i+1) & 1] = [[False] * N for _ in range(W+1)]
        for j in range(W):
            diff = abs(A[i][j] - B[i][j])
            for k in range(N):
                dp[(i+1) & 1][j+1][abs(k - diff)] |= dp[i & 1][j+1][k]
                dp[(i+1) & 1][j+1][abs(k - diff)] |= dp[(i+1) & 1][j][k]
                if k + diff < N:
                    dp[(i+1) & 1][j+1][k + diff] |= dp[i & 1][j+1][k]
                    dp[(i+1) & 1][j+1][k + diff] |= dp[(i+1) & 1][j][k]
    print(dp[H & 1][W].index(True))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    N = 80 * (H+W) // 2
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    dp = [[set() for _ in range(W+1)] for _ in range(2)]
    dp[0][1].add(0)
    def ltN(x): return x <= N
    for i in range(H):
        dp[(i+1) & 1] = [set() for _ in range(W+1)]
        for j in range(W):
            diff = abs(A[i][j] - B[i][j])
            tmp = set()
            for x in dp[i & 1][j + 1]:
                tmp.add(abs(x + diff))
                tmp.add(abs(x - diff))
            for x in dp[(i+1) & 1][j]:
                tmp.add(abs(x + diff))
                tmp.add(abs(x - diff))
            dp[(i+1) & 1][j+1] = tmp
    print(min(dp[H & 1][W]))


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

N,X = map(int,input().split())
x = list(map(int,input().split()))

for i in range(N):
    x[i] = abs(x[i] - X)
    if x[i] == 0:
        x[i] = 10000000000
m = min(x)

flg = True
for i in range(m,0,-1):
    for j in range(N):
        if x[j] % i != 0:
            flg = False
            break

    if flg == True:
        print(i)
        exit()
    else:
        flg = True


### FIXED CODE ###

import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
 
ans = 0
for i in range(N):
    ans = fractions.gcd(ans,abs(x[i]-X))
print(ans)
### BUGGY CODE ###

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

for i in range(n):
    ary.append(a[i]-1)
    ary.append(a[i])
    ary.append(a[i]+1)

maxcount = 1
for i in ary:
    if ary.count(i) > maxcount:
        maxcount = ary.count(i)

print(maxcount)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1

print(max(ary))
### BUGGY CODE ###

x = list(map(int,input().split()))
a = 0
b = x[1]+1
for i in range(x[0],x[1]+1):
    if i % x[2] ==0:
        a = 1
        b=i        
        break
c = (x[1]-b)//x[2] + 1
print(c)

### FIXED CODE ###

x = list(map(int,input().split()))
a = 0
if x[0]%x[2]==0:
    b = x[0]
else:
     b = ((x[0] // x[2])+1)*x[2]
c = (x[1]-b)//x[2] + 1

print(c)
### BUGGY CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
B=T.copy()    
d=0
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        c=deque()    
        s=0
        c+=[i,j]
        
        t=len(c)//2
        while t>0:
                s+=1
                t=len(c)//2
                for k in range(t):
                        m = c.popleft()
                        n = c.popleft()
                        T[m][n]=s
                        if m != H-1:
                                if T[m+1][n]==0:c+=[m+1,n]
                        if m != 0:
                                if T[m-1][n]==0:c+=[m-1,n] 
                        if n != W-1:
                                if T[m][n+1]==0:c+=[m,n+1]
                        if n != 0:
                                if T[m][n-1]==0:c+=[m,n-1]
                        #c += (chk_route([c.popleft(),c.popleft()]))
                
        #print(T)
        d = max(d,s)
        T=B.copy()
        
print(d-2)

### FIXED CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
#T=[]
S=np.zeros_like(T,dtype=int) 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
c=deque()  
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
          
        c.append((i,j))
        S[i][j] = 1
        #c.append(j)
        
        #t=len(c)
        while True:

                try:
                  m,n = c.popleft()
                except IndexError: break
                
                
                for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                  if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                  if T[kk]==1:continue
                  if S[kk] == 0:
                    c.append(kk)
                    S[kk] = S[m][n]+1        
                        
 
        #print(T)
        d = max(d,np.max(S))
        S=np.zeros_like(T,dtype=int)
        
print(d-1)
### BUGGY CODE ###

import numpy as np
n,m = map(int, input().split())

routes = []
for i in range(m):
    route = list(map(int, input().split()))
    routes.append(route)
    routes[i] = routes[i] - np.ones(2) #道の番号をずらす

rooms = np.zeros(n) # 行ってない部屋は0、行った部屋は1
marks = np.zeros(n) # 部屋におく道標
roomsrate = [[0]] # １回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in roomsrate:
    newrate = []
    for j in roomsrate[turn]: #turn回目に行ける部屋を調べる
        for k in range(m):
            a = int(routes[k][0])
            b = int(routes[k][1]) 
            if (j == a and int(rooms[b]) == 0):
                rooms[b] = 1
                marks[b] = a
                newrate.append(b)
            elif (j == b and int(rooms[a]) == 0):
                rooms[a] = 1
                marks[a] = b
                newrate.append(a)
    roomsrate.append(newrate)
    if (len(newrate) == 0):
        break
    turn = turn + 1

if(np.all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')

### FIXED CODE ###

n,m = map(int, input().split())

routes = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    routes[x-1].append(y-1)
    routes[y-1].append(x-1)


rooms = [0 for i in range(n)] # 行ったら1,まだなら0
marks = [0 for i in range(n)] # 部屋におく道標
rooms_rate = [[0]] # ０回目、１回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in rooms_rate:
    newrate = []
    for j in rooms_rate[turn]: #(turn)回目に行けた部屋から行ける部屋を調べる
        for k in routes[j]: 
            if (rooms[k] == 0): #行ったことのない部屋なら
                rooms[k] = 1
                marks[k] = j # 道標をセット
                newrate.append(k)
    rooms_rate.append(newrate)
    if (len(newrate) == 0): #新しく行けなくなったら終わり
        break
    turn = turn + 1


if(all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')
### BUGGY CODE ###

import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()
def gcd_core(a, b):
    if b == 0: return a
    else: return gcd_core(b, a % b)
def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)): g = gcd_core(g, arr[i])
    return g
def main():
    K = I()
    for a in range(1, K+1):
        for b in range(a, K+1):
            for c in range(b, K+1):
                x = len({a, b, c})
                yield gcd([a, b, c])*sum([i for i in range(1, x+1)])
if __name__ == '__main__':
    print(sum(main()))

### FIXED CODE ###

import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()
def gcd_core(a, b):
    if b == 0: return a
    else: return gcd_core(b, a % b)
def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)): g = gcd_core(g, arr[i])
    return g
def main():
    K = I()
    for a in range(1, K+1):
        for b in range(a, K+1):
            for c in range(b, K+1):
                x = len({a, b, c})
                if x == 1: pass
                elif x == 2: x = 3
                else: x = 6
                yield gcd([a, b, c])*x
if __name__ == '__main__':
    print(sum(main()))
### BUGGY CODE ###

import bisect

N,M=map(int,input().split())
A=[int(_) for _ in input().split()]
A.sort()
for m in range(M):
    a=A.pop(-1)//2
    insert_index = bisect.bisect_right(A,a)
    A[insert_index:insert_index]=[a]
print(sum(A))


### FIXED CODE ###

import heapq

N,M=map(int,input().split())
A=[-int(_) for _ in input().split()]
heapq.heapify(A)

for _ in range(M):
    a=heapq.heappop(A)
    heapq.heappush(A,-((-a)//2))

print(-sum(A))
### BUGGY CODE ###

N = int(input())
S = input()
# RGBの時点で一つ目の条件を満たすものは少ないはず
d = {}
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            d[(i, j)] = 1
counter = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if (i, j) in d:
                if (i, k) in d:
                    if (j, k) in d:
                        if j-i != k-j:
                            counter += 1
print(counter)

### FIXED CODE ###

N = int(input())
S = input()
d = {'R': 0, 'G': 0, 'B': 0}
for i in range(N):
    d[S[i]]+=1
tot = d['R']*d['G']*d['B']

counter = 0
for i in range(N):
    width = 1
    tmp = i+2
    while tmp < N:
        if S[i] != S[i+width] and S[i] != S[i+2*width] and S[i+width] != S[i+2*width]:
            counter += 1
        width += 1
        tmp = i + 2 * width
print(tot-counter)
### BUGGY CODE ###

s = list(str(input()))
q = int(input())

for _ in range(q):
    X = input().split()
    if X[0] == '1':
        s.reverse()
    else:
        if X[1] == '1':
            s.insert(0, X[2])
        else:
            s.append(X[2])

print(''.join(map(str, s)))


### FIXED CODE ###

s = list(str(input()))
q = int(input())

from collections import deque
d = deque(s)
REVERSE = False

for _ in range(q):
    X = input().split()
    if X[0] == '1':
        REVERSE = not REVERSE
    else:
        if X[1] == '1' and not REVERSE:
            d.appendleft(X[2])
        elif X[1] == '2' and not REVERSE:
            d.append(X[2])
        elif X[1] == '1' and REVERSE:
            d.append(X[2])
        elif X[1] == '2' and REVERSE:
            d.appendleft(X[2])

if REVERSE:
    d.reverse()

print(*d, sep='')
### BUGGY CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
num = []
for i in range(n-k+1):
  An = 1
  for j in range(k):
    An = An*A[i+j]
  num.append(An)
  

for i in range(n-k):
  if num[i+1] > num[i]:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
for i in range(n-k):
  if A[i] < A[i+k]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

from collections import Counter
n,k = map(int,input().split())
a = [i for i in input().split()]
cnt = Counter(a)
ll = len(cnt)
ans = 0
if ll < k:
    print(0)
    quit()
for i in range(k):
    ans += cnt.most_common()[i][1]
print(n-ans)

### FIXED CODE ###

from collections import Counter
n,k = map(int,input().split())
a = [i for i in input().split()]
cnt = Counter(a)
li = list(cnt.values())
li.sort()
ll = len(li)
if ll > k:
    print(sum(li[:ll-k]))
else:
    print(0)