CodeEff/ECCO huggingface dataset:
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}

for i in a:
    if i in list(ball.keys()):
        ball[i] += 1
    else:
        ball[i] = 1

ball = sorted(list(ball.items()), key=lambda x: -x[1])

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i][1]
    ans = n - ans
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ball = {}

for i in a:
    if i in ball:
        ball[i] += 1
    else:
        ball[i] = 1

ball = sorted(list(ball.items()), key=lambda x: -x[1])

ans = 0
if len(ball) > k:
    for i in range(k):
        ans += ball[i][1]
    ans = n - ans
print(ans)
# Original solution
import sys

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
A_set = set(A)
if len(A_set) <= k:
    print((0))
    sys.exit()
A_count = [0]*len(A_set)
for i, a in enumerate(A_set):
    A_count[i] = A.count(a)
A_count.sort()

num = len(A_set) - k
s = 0
for i in range(num):
    s += A_count[i]
print(s)

# Optimized solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
num = [0]*n
for a in A:
    num[a-1] += 1
num.sort(reverse=True)
cnt = 0
for i in range(k):
    cnt += num[i]
ans = n - cnt
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
import collections
count_dict = collections.Counter(a)
# print(count_dict.most_common())
ans = 0
for i in range(len(count_dict) - k):
    ans += count_dict.most_common()[len(count_dict)-i-1][1]
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
import collections
count_dict = collections.Counter(a)
# print(count_dict.most_common())
ans = 0
unique = count_dict.most_common()
for i in range(len(count_dict) - k):
    ans += unique[len(count_dict)-i-1][1]
print(ans)
# Original solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
array = []
ans = 0

for i in set(A):
    array.append(A.count(i))

array.sort()

if len(set(A)) > k:
    num = len(array) - k
    for i in range(num):
        ans += array[i]

print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
array = {}
ans = 0

for a in A:
    if a in list(array.keys()):
        array[a] += 1
    else:
        array[a] = 1

array = sorted(array.values())

if len(set(A)) > k:
    num = len(array) - k
    for i in range(num):
        ans += array[i]

print(ans)
# Original solution
from collections import Counter
n,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
count = 0
while len(counts) > k:
        mins = min(counts.values())
        count += mins
        del counts[min(counts,key=counts.get)]
        
print(count)

# Optimized solution
from collections import Counter
n,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)
# Original solution
import collections
import sys
input = sys.stdin.readline

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1

List_sorted = sorted(list(List.items()), key=lambda x:x[1])
tmp=0
Num=len(List_sorted)-K

for i in range(Num):
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


# Optimized solution
import heapq

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)
# Original solution
import collections
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
c = collections.Counter(A).most_common()[::-1]
k = len(c)
if k<=K:print((0))
else: print((sum([e[1] for e in c[:k-K]])))

# Optimized solution
from collections import Counter
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
C = Counter(A).most_common()
if len(C)<=K:
    print((0))
else:
    ans = 0
    for c in C[:K]:
        ans+=c[1]
    print((N-ans))
# Original solution
from collections import defaultdict
N, K = list(map(int, input().split()))
A = list(map(int ,input().split()))

d = defaultdict(int)
for i in A:
    d[i] += 1

d_ = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
n =len(d_)
ans = 0
if n <= K:
    print((0))
    exit()
else:
    for i in range(K,n):
        ans += d_[i][1]
print(ans)

# Optimized solution
from collections import Counter
N, K = list(map(int, input().split()))
A = list(map(int ,input().split()))

d = Counter(A)

d_ = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
n =len(d_)
ans = 0
if n <= K:
    print((0))
    exit()
else:
    for i in range(K,n):
        ans += d_[i][1]
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = set(a)
if len(s) < k:
    print(0)
    exit()
d = sorted([(i, a.count(i)) for i in s], key = lambda x: x[1])
cnt = 0
for i in d[:len(s) - k]:
    cnt += i[1]
print(cnt)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = set(a)
if len(s) < k:
    print(0)
    exit()
d = dict()
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in sorted(d.values())[:len(s) - k]:
    cnt += i
print(cnt)
# Original solution
s, t  = list(map(int, input().split()))
u = list(map(int,input().split()))
from collections import Counter
v = Counter(u)
w = 0
for i in range(s):
    if len(v) <= t:
        print(w)
        break
    else:
        w += min(v.values())
        del v[min(v, key = v.get)]

# Optimized solution
from collections import Counter
n,k = list(map(int,input().split()))
L = list( map(int,input().split()))
l = len(L)
L = Counter(L)
L = sorted(list(L.most_common(k)))

ans = 0
for i in range(len(L)):
    ans += L[i][1]
print((l - ans))
# Original solution
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
l1=[]
l2=[]
c=0
for i in l:
  if i in l1:
    l2[l1.index(i)]+=1
  else:
    l1.append(i)
    l2.append(1)
if m>=len(l2):
  print((0))
else:
  l2=sorted(l2)
  for i in range(len(l2)-m):
    c+=l2[i]
  print(c)

# Optimized solution
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
d={}

c=0
for i in l:
  if i in d:
    d[i]+=1
  else:
    d[i]=1
l1=list(d.values())
if m>=len(l1):
  print((0))
else:
  l1=sorted(l1)
  for i in range(len(l1)-m):
    c+=l1[i]
  print(c)
# Original solution
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))

a = list(set((A)))
check = len(a)
dff = check - K
if dff <= 0:
  print((0))
  exit(0)
ans_list = []

for i in range(check):
  ans = 0
  checker = a[i]
  for j in range(len(A)):
    if checker == A[j]:
      ans += 1
  ans_list.append(ans) 

ans_list.sort()

result = sum(ans_list[:dff])
print(result)

# Optimized solution
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))

a = list(set((A)))
check = len(a)
dff = check - K
if dff <= 0:
  print((0))
  exit(0)
ans_list = [0]*check
A.sort()
index = 0
for i in range(len(A)):
  
  if i >= 1 and A[i] != A[i-1]:
    index += 1
  ans_list[index] += 1
ans_list.sort()
result = sum(ans_list[:dff])
print(result)
# Original solution
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
A = collections.Counter(LI())
count_A = sorted([v for v in list(A.values())])
surplus = max(0,len(A)-K)
print((sum(count_A[:surplus])))


# Optimized solution
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
A = collections.Counter(LI())
value_A = sorted(A.values())
surplus = max(0,len(A)-K)
print((sum(value_A[:surplus])))
# Original solution
from collections import defaultdict

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

for x in a:
  d[x] += 1

new_d = sorted(list(d.items()), key=lambda x: x[1])
ans = 0
cnt = 0
for x in new_d:
  if(cnt < len(new_d) - k):
    ans += x[1]
    cnt += 1
  else:
    break
print(ans)

# Optimized solution
from collections import Counter
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
c=Counter(a)
v=list(c.values())
n=len(v)
if n>k:
    ans=sum(sorted(v)[:n-k])
    print(ans)
else:
    print((0))
# Original solution
from collections import Counter

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

print((sum(v for _, v in Counter(A).most_common()[K:])))


# Optimized solution
from collections import *
N,K=list(map(int,input().split()))
print((sum(v for _,v in Counter(list(map(int,input().split()))).most_common()[K:])))
# Original solution
from collections import *
N,K=list(map(int,input().split()))
print((sum(v for _,v in Counter(list(map(int,input().split()))).most_common()[K:])))

# Optimized solution
from collections import Counter

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

print((sum(sorted(list(Counter(A).values()), reverse=True)[K:])))
# Original solution
from collections import Counter
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
if len(set(A)) <= K:
    print((0))
    exit()

d = [a for a in list(Counter(A).values())]
tmp = 0
for i in range(K):
    tmp += max(d)
    d.remove(max(d))
print((len(A)-tmp))


# Optimized solution
from collections import Counter
N,K = (int(i) for i in input().split())
d = Counter([int(i) for i in input().split()])
if len(d) <= K:
    print((0))
    exit()

tmp = 0
for _,p in d.most_common(K):
    tmp += p
print((N-tmp))
# Original solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A).most_common()
dif = len(C) - k
if dif <= 0:
	print((0))
else:
	s = 0
	for i in range(dif):
		s += C[-(i + 1)][1]
	print(s)

# Optimized solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
dif = len(C) - k
if dif <= 0:
	print((0))
else:
	print((sum(sorted(C.values())[:dif])))
# Original solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
n = len(C)
if n<=K:
    cnt = 0
else:
    cnt = 0
    for i in range(K,n):
        cnt += C[i][1]
print(cnt)

# Optimized solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
if len(C)<=K:
    print((0))
else:
    cnt = 0
    for i in range(K,len(C)):
        cnt += C[i][1]
    print(cnt)
# Original solution
n, k = list(map(int, input().split()))
balls = list(map(int, input().split()))
amo = []

kinds = set(balls)
amo = sorted([balls.count(i) for i in kinds])
print((sum(amo[:max(0, len(kinds)-k)])))

# Optimized solution
n, k = list(map(int, input().split()))
balls = sorted(input().split())
kinds = len(set(balls))
amo = [1] * kinds

balls.append(0)
j = 0
for i in range(n):
    if balls[i] == balls[i+1]:
        amo[j] += 1
    else:
        j += 1
amo.sort()
print((sum(amo[:max(0, kinds-k)])))
# Original solution
import collections

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

cA = collections.Counter(A)

ans = 0
if len(cA) > K:
  for x in range(len(cA)-K):
    ans += list(reversed(cA.most_common()))[x][1]
else:
  ans = 0
print(ans)

# Optimized solution
import collections

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

cA = collections.Counter(A)

ans = 0
if len(cA) > K:
  _, counts = list(zip(*cA.most_common()[::-1]))
  ans =sum(counts[:len(cA)-K])
else:
  ans = 0
print(ans)
# Original solution
from collections import Counter

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
while len(c) > K:
    res = c.pop(0)
    ans += res[1]
print(ans)


# Optimized solution
from collections import Counter

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
if len(c) > K:
    for i in range(len(c) - K):
        ans += c[i][1]

print(ans)
# Original solution
from collections import Counter
n, k = list(map(int, input().split()))
*a, = list(map(int, input().split()))

c = Counter(a)
kv = sorted(list(c.items()), key=lambda x: x[1], reverse=True)

if n <= k:
    print((0))
else:
    ans = n
    for i in range(k):
        try:
            ans -= kv[i][1]
        except:
            pass
    print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))


d = {}
for a in A:
    if a in list(d.keys()):
        d[a] += 1
    else:
        d[a] = 1



ls = sorted(d.values())
ans = 0
for v in ls[:len(ls)-k]:
    ans += v
print(ans)
# Original solution
from collections import Counter
n, k = list(map(int, input().split()))
*a, = list(map(int, input().split()))

c = Counter(a)
kv = sorted(list(c.items()), key=lambda x: x[1], reverse=True)

if n <= k:
    print((0))
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)

# Optimized solution
from collections import Counter
n, k = list(map(int, input().split()))
*a, = list(map(int, input().split()))
c = Counter(a)

if n <= k:
    print((0))
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)
# Original solution
from collections import Counter
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a = Counter(a)
a = a.most_common()
p = len(a)
ans = 0
for i in range(-1,-n-1,-1):
    if p <=k:break
    ans += a[i][1]
    p-=1

print(ans)


# Optimized solution
n,K = list(map(int,input().split()))
a = list(map(int,input().split()))
cnt = {}
for x in a:
    if x not in cnt:cnt[x] = 1
    else:cnt[x] +=1
res = []
for k in cnt:
    v = cnt[k]
    res.append(v)
res.sort()
ans = 0
for i in range(len(res)):
    if len(res) - i <=K:
        
        print(ans)
        break
    ans +=res[i]
# Original solution
import collections as c
N,K,*A= list(map(int,open(0).read().split()))
ans=0
C=c.Counter(A)
C=sorted(C.values())

colors = len(C)

for i in range(colors):
  if len(C)<=K:
    break
  _c = C.pop(0)
  ans+=_c
print(ans)


# Optimized solution
import collections as c
N,K,*A= list(map(int,open(0).read().split()))
ans=0
C=c.Counter(A)
C=sorted(C.values())
#Aprint(C)
for i in range(len(C)-K):
  ans+=C[i]

print(ans)
# Original solution
def main():
  from collections import Counter
  n,k,*a = list(map(int,open(0).read().split()))
  a = Counter(a)
  ans = 0
  for i in range(max(0,len(a)-k)):
    ans += a.most_common()[-1-i][1]
  print(ans)
main()

# Optimized solution
n,k,*a = list(map(int,open(0).read().split()))
b = {}
for i in a:
  if i in b:
    b[i] += 1
  else:
    b[i] = 1
ans = 0
a = sorted(list(b.values()))
for i in range(max(0,len(a)-k)):
  ans += a[i]
print(ans)
# Original solution
from collections import Counter


N, K = list(map(int, input().split()))
A = sorted((v, k) for k, v in list(Counter(list(map(int, input().split()))).items()))
print((sum(v for v, k in A[: max(0, len(A) - K)])))


# Optimized solution
from collections import Counter


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A_cntr = Counter(A)
print((sum(sorted(v for v in list(A_cntr.values()))[:-K])))
# Original solution
from collections import Counter

N, K = list(map(int, input().split()))
counter = Counter(list(map(int, input().split())))
ans = 0
if len(list(counter.keys())) > K:
    for i in range(len(list(counter.keys())) - K):
        ans += counter.most_common()[0 - i - 1][1]

print(ans)


# Optimized solution
import collections

N, K = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = 0
cnt = collections.defaultdict(int)
for num in arr:
    cnt[num] += 1

vals = sorted(cnt.values())

if len(cnt) > K:
    for i in range(len(cnt) - K):
        ans += vals[i]

print(ans)
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
import collections
counter=collections.Counter(a)
v=sorted(counter.values())
print((sum(v[:len(v)-k])))


# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
import collections
v=sorted(collections.Counter(a).values())
print((sum(v[:len(v)-k])))
# Original solution
import collections
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
c=collections.Counter(A)
tot=0
for i in range(min(k,len(set(A)))):
  tot+=c.most_common()[i][1]
print((n-tot))


# Optimized solution
import collections
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
c=collections.Counter(A)
tot=0
for i in c.most_common(min(k,len(set(A)))):
  tot+=i[1]
print((n-tot))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cnt = {}

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

cnt = sorted(list(cnt.items()), key=lambda x: x[1])
ans = 0

while len(cnt) > K:
    ans += cnt[0][1]
    cnt = cnt[1:]

print(ans)


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cnt = {}

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

cnt = sorted(list(cnt.items()), key=lambda x: x[1])
ans = 0

for i in range(len(cnt)):
    if len(cnt) - i <= K:
        break
    ans += cnt[i][1]

print(ans)
# Original solution
n, k = list(map(int, input().split()))
*a, = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
a.sort(key=lambda x: d[x])
b = sorted(set(a), key=a.index)
cnt = len(b)
ans = 0
for i in b:
    if cnt <= k:
        break
    ans += d[i]
    cnt -= 1
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
*a, = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
cnt = len(d)
ans = 0
for _, i in sorted(list(d.items()), key=lambda x: x[1]):
    if cnt <= k:
        break
    ans += i
    cnt -= 1
print(ans)
# Original solution
def insert(S, string):
    S.add(string)

def find(S, string):
    cnt = 0
    for i in range(len(S)):
        cnt = cnt + 1
        if string in S:
            print('yes')
            break
        elif cnt == len(S):
            print('no')
    if cnt == 0:
        print('no')

n = eval(input())

S = set([])

for i in range(n):
    tmp1, tmp2  = list(map(str,input().split()))
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print('error!')

# Optimized solution
def insert(S, string):
    S.add(string)

def find(S, string):
    if string in S:
        print('yes')
    else:
        print('no')

n = eval(input())

S = set()

for i in range(n):
    tmp1, tmp2  = list(map(str, input().split()))
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print('error!')
# Original solution
n = eval(input())
dic = []
for i in range(n):
    order = input().split()
    if order[0][0] == 'i':
        dic.append(order[1])
    else:
        print("yes" if order[1] in dic else "no")

# Optimized solution
n = eval(input())
dic = set([])
for i in range(n):
    order = input().split()
    if order[0][0] == 'i':
        dic.add(order[1])
    else:
        print("yes" if order[1] in dic else "no")
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    x,m = list(map(str,input().split()))
    if x[0] =='i':a.append(m)
    elif x[0] =='f':
        if m in a:
            print('yes')
        else:
            print('no')
    
    


# Optimized solution
n = int(eval(input()))
a = {}
for i in range(n):
    x,m = input().split()
    if x[0] =='i':a[m] = 0
    else:
        if m in a:
            print('yes')
        else:
            print('no')
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def h1(key):
    return key % m


def h2(key):
    return 1 + (key % (m - 1))


def h(key, i):
    return (h1(key) + i * h2(key)) % m


def insert(key):
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 'NULL':
            T[j] = key
            return j
        else:
            i += 1


def search(key):
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            print('yes')
            return j
        elif T[j] == 'NULL' or i >= m:
            print('no')
            return 'NULL'
        else:
            i += 1


def str_to_key(_str):
    _length = len(_str)
    _sum, p = 0, 1
    for i in range(_length):
        _sum += p * (ord(_str[i]) - 64)
        # why choose p=5 ?
        p *= 5

    # key = sum([ord(each) - 64
    #            for each in _str])
    # print(key, _str)
    return _sum


def action(command, content):
    key = str_to_key(content)
    if command[0] == 'i':
        insert(key=key)
    elif command[0] == 'f':
        search(key=key)
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    m = 1046527
    length = int(_input[0])
    command_list = list([x.split() for x in _input[1:]])
    T = ['NULL' for _ in range(m)]
    for command, content in command_list:
        action(command=command, content=content)

# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def h1(key):
    return key % m


def h2(key):
    return 1 + (key % (m - 1))


def h(key, i):
    return (h1(key) + i * h2(key)) % m


def insert(key):
    i = 0
    while True:
        j = h(key, i)
        if not T[j]:
            T[j] = key
            return j
        else:
            i += 1


def search(key):
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            print('yes')
            return j
        elif not T[j] or i >= m:
            print('no')
            return None
        else:
            i += 1


def str_to_key(_str):
    _length = len(_str)
    _sum, p = 0, 1
    for i in range(_length):
        _sum += p * (ord(_str[i]) - 64)
        # why choose p=5 ?
        p *= 5

    # key = sum([ord(each) - 64
    #            for each in _str])
    # print(key, _str)
    return _sum


def action(command, content):
    key = str_to_key(content)
    if command[0] == 'i':
        insert(key=key)
    elif command[0] == 'f':
        search(key=key)
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    m = 1046527
    length = int(_input[0])
    command_list = list([x.split() for x in _input[1:]])
    T = [None] * m
    for command, content in command_list:
        action(command=command, content=content)
# Original solution
M = 10 ** 6 + 3
HASH_MAP = [None for i in range(M)]


def hash1(key):
    return key % M


def hash2(key):
    return 1 + (key % M-1)


def my_hash(key, i):
    return (hash1(key)+i*hash2(key)) % M


def make_num(s):
    return len(s) + ord(s[0]) + ord(s[-1])


def insert(key):
    i = 0
    key_n = make_num(key)
    while True:
        j = my_hash(key_n, i)
        if HASH_MAP[j] is None:
            HASH_MAP[j] = key
            return j

        i += 1


def search(key):
    i = 0
    key_n = make_num(key)
    while True:
        j = my_hash(key_n, i)
        if HASH_MAP[j] == key:
            return j
        elif HASH_MAP[j] is None or i >= M:
            return None

        i += 1


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

    for i in range(n):
        order = input().split()
        if order[0] == "insert":
            insert(order[1])
        else:
            if search(order[1]) is None:
                print("no")
            else:
                print("yes")


if __name__ == '__main__':
    main()



# Optimized solution
def main():
    n = int(eval(input()))

    s_set = set()
    for i in range(n):
        order = input().split()
        if order[0] == "insert":
            s_set.add(order[1])
        else:
            if order[1] in s_set:
                print("yes")
            else:
                print("no")


if __name__ == '__main__':
    main()