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

s = input()
n = len(s)

square = [0 for _ in range(n)]
for i in range(n):
    if s[i] == "L":
        add_num = -1
    else:
        add_num = 1
    j = i + add_num
    char = s[i]
    while j > -1 and j < n and char == s[j]:
        j += add_num
    if (i - j) % 2 == 0:
        square[j] += 1
    else:
        square[j - add_num] += 1

print(square[0], end="")
for i in range(1, n):
    print(" ", end="")
    print(square[i], end="")


### FIXED CODE ###

s = input()
n = len(s)

square = [0 for _ in range(n)]
i = 0
while i < n:
    start = i
    char = s[i]
    i += 1
    while i < n and char == s[i]:
        i += 1

    if char == "L":
        num = i - start
        if num % 2 == 0:
            square[start - 1] += num // 2
            square[start] += num // 2
        else:
            square[start] += num // 2 + 1
            square[start - 1] += num // 2
    else:  # R
        num = i - start
        if num % 2 == 0:
            square[i] += num // 2
            square[i - 1] += num // 2
        else:
            square[i] += num // 2
            square[i - 1] += num // 2 + 1
    # if i == n - 1:
    #     i += 1


print(square[0], end="")
for i in range(1, n):
    print(" ", end="")
    print(square[i], end="")
### BUGGY CODE ###

from collections import deque

s = deque(list(str(input())))
q = int(input())
que = [list(map(str, input().split())) for _ in range(q)]

for query in que:
    if len(query) == 1:
        s.reverse()
    else:
        if int(query[1]) == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])

print(*s,sep='')


### FIXED CODE ###

from collections import deque

s = deque(list(str(input())))
q = int(input())
que = [list(map(str, input().split())) for _ in range(q)]

r_cnt=0
for query in que:
    if len(query) == 1:
        r_cnt+=1
    else:
        if int(query[1]) == 1:
            if r_cnt % 2 == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])
        else:
            if r_cnt % 2 == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])

for _ in range(r_cnt % 2):
    s.reverse()

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

n, k = map(int, input().split())
p_i = input().split()
answer = 0
sumlist =[] 
for x in range(n - k + 1):
    sumlist = p_i[x : x + k]
    answer = max(answer, sum(int(i) for i in sumlist))
print((answer + k) / 2)

### FIXED CODE ###

n, k = map(int, input().split())
p_i = list(map(int,input().split()))
answer = 0
sum = 0
for x in range(n):
    if x <= k - 1: 
        sum += p_i[x]
        if x == k - 1: answer = sum
    else:
        sum += p_i[x] - p_i[x - k]
        answer = max(answer, sum)
print((answer + k) / 2)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
G = dict()

for h in range(H):
    for w in range(W):
        G[h * W + w] = dict()

for h in range(H):
    for w in range(W):
        if w != 0:
            G[h * W + w][h * W + w - 1] = 1
        if w != W - 1:
            G[h * W + w][h * W + w + 1] = 1
        if h != 0:
            G[h * W + w][h * W + w - W] = 1
        if h != H - 1:
            G[h * W + w][h * W + w + W] = 1


queue = deque(black_cells)
d = [10000]*(H*W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in G[p].keys():
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p-W)
    if h != H-1:
        q_list.append(p+W)
    if w != 0:
        q_list.append(p-1)
    if w != W-1:
        q_list.append(p+1)
    return q_list


queue = deque(black_cells)
d = [10000]*(H*W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))
### BUGGY CODE ###

import numpy as np
import copy

def main():
    data0 = np.array(list(input()))
    data1 = np.array(list(input()))

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while(count <= len_data):
        if not list(data0):
            break
        count += 1
        c0 = data0[0]
        c1 = data1[0]
        if list(data0 == c0) == list(data1 == c1):
            data0 = data0[data0 != c0]
            data1 = data1[data1 != c1]
        else:
            flag = False

    if flag:
        print('Yes')
    else:
        print('No')



def swap(data, c0, c1):
    data_tmp = copy.copy(data)
    data_tmp[data == c0] = c1
    data_tmp[data == c1] = c0
    return data_tmp

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    data0 = input()
    data1 = input()

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while True:
        if data0 == "":
            break

        data0 = data0.replace(data0[0], "")
        data1 = data1.replace(data1[0], "")

        if len(data0) != len(data1):
            print('No')
            exit()

    print('Yes')

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

from sys import stdin 
from collections import defaultdict, Counter


N, P = map(int, stdin.readline().split())
S, = stdin.readline().split()

ans = 0 


# 2 cases
if P == 2 or P == 5:
	digitdiv = []
	for i in range(N):
		if int(S[i]) % P == 0:
			ans += i + 1

else:
	#
	count = Counter()
	prefix = []
	ten = 1
	mod = 0
	for i in range(N):
		x = (int(S[N - i - 1])*ten + mod) % P 
		prefix.append(x)
		count[x] += 1
		ten *= 10
		mod = x
	prefix.append(0)
	count[0] += 1
	for val in count.values():
		ans += val*(val - 1)//2


print (ans)





### FIXED CODE ###

from sys import stdin 
from collections import defaultdict, Counter


N, P = map(int, stdin.readline().split())
S, = stdin.readline().split()

ans = 0 


# 2 cases
if P == 2 or P == 5:
	digitdiv = []
	for i in range(N):
		if int(S[i]) % P == 0:
			ans += i + 1

else:
	#
	count = Counter()
	prefix = []
	ten = 1
	mod = 0
	for i in range(N):
		x = (int(S[N - i - 1])*ten + mod) % P 
		prefix.append(x)
		count[x] += 1
		ten = (ten * 10) % P 
		mod = x
	prefix.append(0)
	count[0] += 1
	for val in count.values():
		ans += val*(val - 1)//2


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

import sys

import numpy as np

MOD = 998244353

def main():
    N, S = map(int, input().split())
    X = [int(x) for x in sys.stdin.readline().split()]

    dp = np.zeros((N+1)*(S+1), dtype=np.int).reshape((N+1),(S+1))

    dp[0][0] = 1

    for i in range(N):
        xi = X[i]
        # xi を U に加えない場合
        for j in range(S+1):
            dp[i+1][j] += dp[i][j]*2  # T に加える／加えない
            dp[i+1][j] %= MOD
            # xi を U に加える場合
            if j+xi > S: continue
            dp[i+1][j+xi] += dp[i][j]
            dp[i+1][j+xi] %= MOD

    print(dp[N][S] % MOD)

main()

### FIXED CODE ###

import sys

MOD = 998244353

def main():
    N, S = map(int, input().split())
    X = [int(x) for x in sys.stdin.readline().split()]

    # dp = np.zeros((N+1)*(S+1), dtype=np.int).reshape((N+1),(S+1))
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]

    dp[0][0] = 1

    for i in range(N):
        xi = X[i]
        # xi を U に加えない場合
        for j in range(S+1):
            dp[i+1][j] += dp[i][j]*2  # T に加える／加えない
            dp[i+1][j] %= MOD
            # xi を U に加える場合
            if j+xi > S: continue
            dp[i+1][j+xi] += dp[i][j]
            dp[i+1][j+xi] %= MOD

    print(dp[N][S] % MOD)

main()
### BUGGY CODE ###

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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)

    if temp!=1:
        arr.append(temp)

    return arr

N=int(input())
A=list(map(int, input().split()))
S=set(factorization(A[0]))
T=set(factorization(A[0]))
flg=0
for i in range(1,N):
    k=A[i]
    prime=set(factorization(k))
    if T&prime!=set():
        flg=1
    S=S&prime
    T=T|prime
    #print(S,T)
if S!=set():
    print('not coprime')
elif flg==1:
    print('setwise coprime')
else:
    print('pairwise coprime')


### FIXED CODE ###

from math import gcd
from functools import reduce

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):#1を除く(素因数,指数)のリスト
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e)) 
    return result


def f():
    s = set()
    for i in range(N):
        t = prime_factorize(A[i])
        for p, _ in t:
            if p in s:
                return False
            s.add(p)
    return True


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

prime_table = make_prime_table(10 ** 6)
if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a :
    print(0)

else:
    for i in range(n):
        ans *= a[i]
    print([ans,-1][ans>10**18])


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a :
    ans = 0

else:
    for i in range(n):
        ans *= a[i]
        if ans >10**18:
            ans = -1
            break
            
print(ans)
### BUGGY CODE ###

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

N,W = map(int, readline().split())
w=[];v=[]
for _ in range(N):
  a,b = map(int, readline().split())
  w.append(a)
  v.append(b)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j >= w[i]:
      dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])
    else:
      dp[i+1][j] = dp[i][j]
print(dp[N][W])

### FIXED CODE ###

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

N,W = map(int, readline().split())
w=[];v=[]
for _ in range(N):
  a,b = map(int, readline().split())
  w.append(a)
  v.append(b)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j >= w[i]:
      dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])
    else:
      dp[i+1][j] = dp[i][j]
print(dp[N][W])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# Range Minimum Query

n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1]*1001
for i in range(q):
    comi,xi,yi = map(int,raw_input().split())
    if comi and abs(yi-xi)<=199:
        print min(A[xi:yi+1])
    elif comi and 200<= abs(yi-xi):
        print min(min(A[xi:(xi/100+1)*100]),min(B[xi/100+1:yi/100]),min(A[yi/100:]))
    else:#comi == 0
        A[xi]=yi
        B[xi/100] = min(B[xi/100],yi)

### FIXED CODE ###

# coding: utf-8

n, q = map(int,raw_input().split())
A = [(1<<31) - 1 for i in xrange(100000)]
B = [(1<<31) - 1 for i in xrange(101)]
 
def update(i,x):
    if A[i] == (1<<31) - 1:
        A[i] = x
        B[i/1000] = min(x, B[i/1000])
    else:
        A[i] = x
        MIN = (1<<31) - 1
        for j in xrange(i/1000 * 1000, (i/1000 + 1) * 1000):
            if A[j] < MIN:
                MIN = A[j]
        B[i/1000] = MIN
 
def find(s,t):
    MIN = (1<<31) - 1
    if s/1000 == t/1000 or s/1000 + 1 == t/1000:
        for i in xrange(s, t+1):
            if A[i] < MIN:
                MIN = A[i]
    else:
        #left range
        for i in xrange(s, (s/1000 + 1) * 1000):
            if A[i] < MIN:
                MIN = A[i]
        #middle range
        for j in xrange(s/1000 + 1, t/1000):
            if B[j] < MIN:
                MIN = B[j]
         
        #right range
        for i in xrange(t/1000 * 1000, t+1):
            if A[i] < MIN:
                MIN = A[i]
    print MIN   
     
for i in xrange(q):
    com, s, t = map(int,raw_input().split())
    if com: #find
        find(s,t)
    else: #update
        update(s,t)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
tizu = [list(input()) for _ in range(h)]
check = [[False for _ in range(w)] for _ in range(h)]
queue = deque()
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(h):
    for j in range(w):
        if tizu[i][j] == "#":
            queue.append([i, j])
            queue.append(0)
            check[i][j] = True
            
while queue:
    pos = queue.popleft()
    ans = queue.popleft() + 1
    for dy, dx in directions:
        next_y = pos[0] + dy
        next_x = pos[1] + dx
        if next_x == -1 or next_y == -1 or next_x == w or next_y == h:
            continue
        if check[next_y][next_x]:
            continue
        check[next_y][next_x] = True
        queue.append([next_y, next_x])
        queue.append(ans)
        
print(ans - 1)
                
                

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
tizu = [list(input()) for _ in range(h)]
check = [[False for _ in range(w)] for _ in range(h)]
queue = deque()
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(h):
    for j in range(w):
        if tizu[i][j] == "#":
            queue.append([i, j])
            queue.append(0)
            check[i][j] = True
            
while queue:
    pos = queue.popleft()
    ans = queue.popleft() + 1
    for dy, dx in directions:
        next_y = pos[0] + dy
        next_x = pos[1] + dx
        if next_x == -1 or next_y == -1 or next_x == w or next_y == h:
            continue
        if check[next_y][next_x]:
            continue
        check[next_y][next_x] = True
        queue.append([next_y, next_x])
        queue.append(ans)
        
print(ans - 1)
### BUGGY CODE ###

from bisect import bisect_right


def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    A_map = {}
    for a in A:
        i = bisect_right(B, a)
        B_ = B[i:]
        A_map[a] = B_
    
    B_map = {}
    for b in B:
        i = bisect_right(C, b)
        c_num = len(C) - i
        B_map[b] = c_num

    count = 0
    for a in A:
        for b in A_map[a]:
            count += B_map[b]
    print(count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_right
from itertools import accumulate

def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    B_counts = []
    for b in B:
        i = bisect_right(C, b)
        B_counts.append(len(C) - i)
    B_counts_cumsum = list(accumulate(B_counts))
    B_counts_cumsum.insert(0, 0)

    count = 0
    for a in A:
        i = bisect_right(B, a)
        if i == len(B):
            continue
        count += B_counts_cumsum[-1] - B_counts_cumsum[i]

    print(count)


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

N=int(input())
numlist=list(map(int,input().split()))
result=1
for x in numlist:
    result=result*x
if result<=1000000000000000000:
    print(result)
else:
    print(-1)


### FIXED CODE ###

N=int(input())
numlist=list(map(int,input().split()))
result=1
if 0 in numlist:
    print(0)
else:
    for x in numlist:
        result=result*x
        if result>10**18:
            break
    if result<=10**18:
        print(result)
    else:
        print(-1)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    g = gcd(a, b)

    ans = 1
    for i in range(1, g + 1):
        if g % i == 0 and is_prime(i):
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    g = gcd(a, b)

    ans = 1
    for i in range(1, int(g ** 0.5) + 1):
        if g % i == 0:
            if is_prime(i):
                ans += 1
            if is_prime(g // i):
                ans += 1

    print(ans)


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

N=int(input())

li=[]
l=0
m=0

for i in range(-(-N//2)):
  if N%(i+1)==0:
    l=i
    m=N/(i+1)-1
    li.append(l+m)
  else:
    pass

print(int(min(li)))



### FIXED CODE ###

import math 

N=int(input())

li=[]
l=0
m=0

for i in range(math.floor(math.sqrt(N))):
  if N%(i+1)==0:
    l=i
    m=N/(i+1)-1
    li.append(l+m)
  else:
    pass

print(int(min(li)))
### BUGGY CODE ###

n = int(input())
*x, = map(int, input().split())
for i in range(n):
    y = sorted(x[:i]+x[i+1:])
    print(y[(n-1)//2])

### FIXED CODE ###

n = int(input())
*x, = map(int, input().split())
y = sorted(x)
for i in x:
    if i < y[n//2]:
        print(y[n//2])
    else:
        print(y[n//2-1])
### BUGGY CODE ###

N,M = map(int,input().split())
a=[]
pass_1= []
for i in range(M):
    a.append(list(map(int,input().split())))
for i in range(M):
    if(a[i][0]==1):
        pass_1.append(a[i][1])
for j in pass_1:
    if([j,N] in a):
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

### FIXED CODE ###

N,M = map(int,input().split())
a_list=[]
pass_1= []
for i in range(M):
    a = list(map(int,input().split()))
    if(a[0]==1):
        pass_1.append(a[1])
    elif(a[1]==N):
        a_list.append(a[0])
    
if list(set(pass_1) & set(a_list)):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

n,k=map(int,input().split())
h=[]

for i in range(n):
    a,b=map(int,input().split())
    for j in range(b):
        h.append(a)

h=sorted(h)
print(h[k-1])


### FIXED CODE ###

n,k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
now = 0
for i in a:
  now += i[1]
  if now >= k:
    print(i[0])
    break
### BUGGY CODE ###

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

x = A[0]
y = sum(A[1:])

ans = abs(x-y)

for i in range(1,N-1):
  x=sum(A[:i])
  y=sum(A[i:])
  if abs(x-y) < ans:
    ans = abs(x-y)

print(ans)

### FIXED CODE ###

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

x = A[0]
y = sum(A[1:])

c=x-y
ans=abs(c)

for i in range(1,N-1):
  c+=2*A[i]
  if abs(c)< abs(ans):
    ans = abs(c)

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

S = input()
count = 0

for i in range(len(S)-3):
  for j in range(i+3, len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      count += 1

print(count)

### FIXED CODE ###

from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

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

import sys
P = int(input())
As = list(map(int, input().split()))
rs = [0]*P
mod = P
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 3000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(P):
    if As[i]:
        rs[0] += 1
        for k in range(P):
            rs[k] += (-1 + 2*(k%2)) * power(i, (P-1-k)) * cmb(P-1, k)
            rs[k] %= P
print(*rs)



### FIXED CODE ###

import sys
P = int(input())
As = list(map(int, input().split()))
rs = [0]*P
mod = P
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 3000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
C = []
for i in range(P):
    C.append(cmb(P-1, i))


for i in range(P):
    if As[i]:
        rs[0] += 1
        tmp = 1
        for k in range(P):
            k = P-1-k
            rs[k] += (-1 + 2*(k%2)) * tmp * C[k]
            rs[k] %= mod
            tmp = tmp * i % mod
print(*rs)
### BUGGY CODE ###

L,R = map(int,input().split())

ans = []

for i in range(L,R+1):
	for j in range(i+1,R+1):
		ans.append((i*j)%2019)
ans.sort()
print(ans[0])

### FIXED CODE ###

L,R = map(int,input().split())
 
ans = 2019
m = []
l = R-L+1
if l < 2019:
	for i in range(L,R+1):
		m.append(i%2019)
else:
	for i in range(L,L+2019):
		m.append(i%2019)

for i in range(len(m)):
	for j in range(i+1,len(m)):
		tmp = (m[i]*m[j])%2019
		if ans> tmp:
			ans = tmp
		if tmp == 0:
			break				
print(ans)
### BUGGY CODE ###

import math

k = int(input())
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += math.gcd(math.gcd(i, j), m)

print(res)

### FIXED CODE ###

from math import gcd

k = int(input())
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += gcd(gcd(i, j), m)

print(res)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
for i in set(a):
        cnt_list.append(a.count(i))
ans = 0
cnt_list.sort()
if len(cnt_list) <= k:
    ans = 0
else:
    tmp = len(cnt_list) - k
    ans = sum(cnt_list[:tmp])
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_dict = {}
for i in a:
    if i in cnt_dict:
        cnt_dict[i] += 1
    else:
        cnt_dict[i] = 1
cnt_dict_sorted = sorted(cnt_dict.items(), key=lambda x: x[1])
ans = 0
if len(cnt_dict_sorted) <= k:
    ans = 0
else:
    tmp = len(cnt_dict_sorted) - k
    for j in range(tmp):
        ans += cnt_dict_sorted[j][1]
print(ans)