input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
n, m = list(map(int, input().split())) work = [tuple(map(int, input().split())) for _ in range(n)] work.sort(key = lambda x: (x[1], -x[0]), reverse = True) do = [0] * (m+1) money = 0 for a, b in work: if a > m: continue while do[a] != 0: a += 1 if a > m: break if a > m: continue do[a] = 1 money += b print(money)
import bisect as bi n, m = list(map(int, input().split())) work = [tuple(map(int, input().split())) for _ in range(n)] work.sort(key = lambda x: (x[1], -x[0]), reverse = True) ava = list(range(0, m+1)) money = 0 for a, b in work: if a > m: continue l = bi.bisect_left(ava, a) if l >= len(ava): continue del ava[l] money += b print(money)
p02948
import sys from heapq import heappush, heappop input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) jobs = {} for _ in range(N): A, B = list(map(int, input().split())) if A > M: continue if A in list(jobs.keys()): jobs[A] = jobs[A] + [-B] else: jobs[A] = [-B] profit = 0 days = list(jobs.keys()) potential_jobs = [] # M-1日後から今日まで遡る for elappsed_day in range(1, M+1): if elappsed_day in days: for job in jobs[elappsed_day]: heappush(potential_jobs, job) if len(potential_jobs) > 0: profit += heappop(potential_jobs) print((-profit)) if __name__ == "__main__": main()
import sys from heapq import heappush, heappop input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) jobs = {} for _ in range(N): A, B = list(map(int, input().split())) if A > M: continue if A in list(jobs.keys()): jobs[A] += [-B] else: jobs[A] = [-B] profit = 0 days = list(jobs.keys()) potential_jobs = [] # M-1日後から今日まで遡る for elappsed_day in range(1, M+1): if elappsed_day in days: for job in jobs[elappsed_day]: heappush(potential_jobs, job) if len(potential_jobs) > 0: profit += heappop(potential_jobs) print((-profit)) if __name__ == "__main__": main()
p02948
# ABC137 D - Summer Vacation import heapq as hp n,m=list(map(int,input().split())) AB=[[] for i in range(m+1)] l=[] for i in range(n): a,b=list(map(int,input().split())) if a<=m: AB[a].append(-b) ans=0 hp.heapify(l) for ab in AB: for x in ab: hp.heappush(l,x) if len(l)>0: ans-=hp.heappop(l) print(ans)
import heapq as hp n,m=list(map(int,input().split())) AB=[[] for i in range(m+1)] for i in range(n): a,b=list(map(int,input().split())) if a<=m: AB[a].append(-b) ans=0 l=[] hp.heapify(l) for ab in AB: for t in ab: hp.heappush(l,t) if len(l)>0: ans-=hp.heappop(l) print(ans)
p02948
import heapq n,m=list(map(int, input().split())) a=[list(map(int, input().split())) for i in range(n)] a.sort(key=lambda x: x[1],reverse=True) x=[1 for i in range(m)] ans=0 count=0 q=[] for i in range(1,m+1): for j in range(n): if a[j][0]==i: heapq.heappush(q,-a[j][1]) if len(q)!=0: ans+=-heapq.heappop(q) print(ans)
import heapq n,m=list(map(int, input().split())) a=[list(map(int, input().split())) for i in range(n)] a.sort() x=[1 for i in range(m)] ans=0 q=[] cnt=0 for i in range(1,m+1): for j in range(cnt,n): if a[j][0]==i: heapq.heappush(q,-a[j][1]) cnt+=1 else: break if len(q)!=0: ans+=-heapq.heappop(q) print(ans)
p02948
from collections import deque import sys def input(): return sys.stdin.readline()[:-1] N, M = list(map(int, input().split())) C = {} for _ in range(N): A,B = list(map(int, input().split())) if not A in C: C[A] = [] C[A].append(B) for i in C: C[i] = deque(sorted(C[i])[::-1]) answer = 0 tmp = deque() for i in range(1, M+1): if i in C: tmp2 = tmp tmp = deque() right = C[i] while len(tmp2) != 0 and len(right) != 0: # line7 if tmp2[0] > right[0]: # line8 tmp.append(tmp2.popleft()) # line9 else: # line10 tmp.append(right.popleft()) # line11 if len(tmp2) != 0: # line12 tmp+=tmp2 # line13 else: # line14 tmp+=right if tmp != deque(): answer += tmp[0] tmp.popleft() print(answer)
import heapq N, M = list(map(int, input().split())) C = {} for _ in range(N): A,B = list(map(int, input().split())) if A in C: C[A].append(B) else: C[A] = [] C[A].append(B) for i in C: C[i] = sorted(C[i])[::-1] answer = 0 tmp = [] heapq.heapify(tmp) for i in range(M+1): if i in C: right = C[i] for j in right: heapq.heappush(tmp,-1*j) if tmp != []: answer += -1*heapq.heappop(tmp) print(answer)
p02948
# ABC-137-D import heapq import bisect N, M = list(map(int, input().split())) AB = []#Aでソートをかけて利用する。 BA = []#Bでソートをかけてheapqで利用する。 heapq.heapify(BA) for _ in range(N): A, B = list(map(int, input().split())) AB.append((A, B)) AB = sorted(AB) ans = 0 check_M = 1 while check_M <= M: r = bisect.bisect_right(AB, (check_M+1, 0)) for A, B in AB[:r]: heapq.heappush(BA, (-1*B, A)) try: max_B = heapq.heappop(BA) except: check_M += 1 AB = AB[r:] continue ans += (-1) * max_B[0] check_M += 1 AB = AB[r:] print(ans)
# ABC-137-D import heapq N, M = list(map(int, input().split())) day_value = [[] for _ in range(M+1)] for _ in range(N): A, B = list(map(int, input().split())) if A <= M: day_value[A].append(B) ans = 0 check_M = 1 BA = [] heapq.heapify(BA) while check_M <= M: for item in day_value[check_M]: heapq.heappush(BA, -1*item) try: max_B = heapq.heappop(BA) except: check_M += 1 continue ans += (-1) * max_B check_M += 1 print(ans)
p02948
import sys import heapq input = sys.stdin.readline n, m = list(map(int, input().split())) sum = 0 # Aiが最小のものから順に選ぶ # 重複するときは最大金額を選び残りはAiを+1する # Ai>Mのものは最初から除外 # 受け取りにA日かかるということはM-A+1日目までに受けなければならない # index = M-A(day) # element = B(reword) schedule = [[] for _ in range(m+1)] for _ in range(n): day, reword = list(map(int, input().split())) if day > m: continue schedule[m-day+1].append(reword) for i in range(m, 0, -1): if not schedule[i]: del schedule[i] continue max_reword = heapq.nlargest(1, schedule[i]) sum += max_reword[0] schedule[i].remove(max_reword[0]) if schedule[i]: schedule[i-1].extend(schedule[i]) del schedule[i] print(sum)
import sys from heapq import heappop, heappush input = sys.stdin.readline n, m = list(map(int, input().split())) # Ai>Mのものは最初から除外 # Aiが最小のものから順に選ぶ # index = A(day-1), element = B(reword) schedule = [[] for _ in range(m)] for _ in range(n): day, reword = list(map(int, input().split())) if day > m: continue schedule[day-1].append(reword) hq = [] sum = 0 for i in range(m): while schedule[i]: heappush(hq, -schedule[i][-1]) del schedule[i][-1] if hq: sum -= heappop(hq) print(sum)
p02948
def dfs(l, r): if (l, r) in cache: return cache[(l, r)] if l == r: return 0 return min(dfs(l, m) + dfs(m + 1, r) + L[l][1] * L[m][0] * L[m + 1][1] * L[m + 1][0] for m in range(l, r)) cache = {} L = [list(map(int, input().split())) for _ in range(eval(input()))] print(dfs(0, len(L) - 1))
def dfs(l, r): if l == r: return 0 if (l, r) in cache: return cache[(l, r)] cache[(l, r)] = min(dfs(l, m) + dfs(m + 1, r) + L[l][0] * L[m][1] * L[m + 1][0] * L[r][1] for m in range(l, r)) return cache[(l, r)] cache = {} L = [list(map(int, input().split())) for _ in range(eval(input()))] print(dfs(0, len(L) - 1))
p00145
from functools import reduce def f(a,b): return [Card[a][0], Card[b][1]] n = int(input()) Card = [[] for _ in [0]*n] Cost = {} for i in range(n): Card[i] = list(map(int, input().split())) Cost[(i, i)] = 0 for i in range(1, n): for j in range(0, n-i): a = j+i Cost[(j, a)] = min([reduce(lambda a,b: a*b, f(j, k) + f(k+1, a)) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)]) print(Cost[0, n-1])
from functools import reduce n = int(input()) Card = [[] for _ in [0]*n] Cost = {} for i in range(n): Card[i] = list(map(int, input().split())) Cost[(i, i)] = 0 for i in range(1, n): for j in range(0, n-i): a = j+i Cost[(j, a)] = min([reduce(lambda a,b: a*b, [Card[j][0],Card[k][1],Card[k+1][0],Card[a][1]]) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)]) print(Cost[0, n-1])
p00145
from functools import reduce n = int(input()) Card = [[] for _ in [0]*n] Cost = {} for i in range(n): Card[i] = list(map(int, input().split())) Cost[(i, i)] = 0 for i in range(1, n): for j in range(0, n-i): a = j+i Cost[(j, a)] = min([reduce(lambda a,b: a*b, [Card[j][0],Card[k][1],Card[k+1][0],Card[a][1]]) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)]) print(Cost[0, n-1])
n = int(input()) Card = [[] for _ in [0]*n] Cost = {} for i in range(n): Card[i] = list(map(int, input().split())) Cost[(i, i)] = 0 for i in range(1, n): for j in range(0, n-i): a = j+i Cost[(j, a)] = min([Card[j][0] * Card[k][1] * Card[k+1][0] * Card[a][1] + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)]) print(Cost[0, n-1])
p00145
from collections import Counter n, k = list(map(int, input().split())) l = list(map(int, input().split())) dic = Counter(l) ans = 0 kv = list(dic.items()) kv = sorted(kv, key=lambda x: x[1]) while len(kv) > k: ans += kv[0][1] del kv[0] print(ans)
from collections import Counter n, k = list(map(int, input().split())) dic = Counter(list(map(int, input().split()))) kv = list(dic.items()) kv = sorted(kv, key=lambda x: x[1]) ans = 0 cnt = 0 while len(kv)-cnt > k: ans += kv[cnt][1] cnt+=1 print(ans)
p03497
# ARC086C - Not so Diverse n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) ans = 0 for i in range(len(cnt)): if k > 0: k -= 1 continue ans += cnt[i] print(ans)
# ARC086C - Not so Diverse (ABC081C) n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().rstrip().split()))) dic = {} for i in lst: if i not in dic: dic[i] = 1 else: dic[i] += 1 cnt = sorted([i for i in list(dic.values())], reverse=True) print((n - sum(cnt[:k])))
p03497
# ARC086C - Not so Diverse (ABC081C) from collections import Counter def main(): _, k, *a = list(map(int, open(0).read().split())) print((sum(sorted(list(Counter(a).values()), reverse=True)[k:]))) if __name__ == "__main__": main()
# ABC081C - Not so Diverse (ARC086C) from collections import Counter def main(): n, k = list(map(int, input().rstrip().split())) A = sorted(list(Counter(input().split()).values()), reverse=True) print((sum(A[k:]))) if __name__ == "__main__": main()
p03497
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = collections.Counter(a) cnt = 0 c = b.most_common()[::-1] while len(c) > k: cnt += c[0][1] c.pop(0) print (cnt)
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = collections.Counter(a) cnt = 0 c = b.most_common() s = 0 for i in range(len(c)): cnt += 1 if cnt > k: for j in range(i,len(c)): s += c[j][1] break print (s)
p03497
n, k = list(map(int, input().split())) L = list(map(int, input().split())) d = {} for a in L: if a not in d: d[a] = 1 else: d[a] += 1 l = [] for v in list(d.values()): l.append(v) if len(l) <= k: print((0)) else: ans = float('inf') for i in range(2 ** len(l)): b = [0] * len(l) for j in range(len(l)): if ((i >> j) & 1): b[j] = 1 if b.count(1) <= k: cnt = 0 for m in range(len(l)): if b[m] == 0: cnt += l[m] ans = min(ans, cnt) print(ans)
n, k = list(map(int, input().split())) L = list(map(int, input().split())) d = {} for a in L: if a not in d: d[a] = 1 else: d[a] += 1 l = [] for v in list(d.values()): l.append(v) l.sort(reverse=True) print((n - sum(l[:k])))
p03497
import os,re,sys,operator,math from collections import Counter,deque from operator import itemgetter from itertools import accumulate,combinations,groupby from sys import stdin,setrecursionlimit from copy import deepcopy import heapq setrecursionlimit(10**6) n,k=list(map(int,stdin.readline().rstrip().split())) a=[int(i) for i in stdin.readline().rstrip().split()] t=deque(Counter(a).most_common()) ans=0 while len(t)>k: now=t.pop() ans+=now[1] print(ans)
from collections import Counter n,k=list(map(int,input().split())) a=[int(i) for i in input().split()] c=Counter(a).most_common() c.sort(key=lambda x: x[1]) #print(c) l=len(c) print((sum(c[i][1] for i in range(l-k))))
p03497
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) c = collections.Counter(a) vs = [] for v in list(c.values()): vs.append(v) vs.sort() i = 0 if len(vs) <= k: print(i) exit() else: while len(vs) > k: i += vs[0] vs = vs[1:] else: print(i) exit()
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) c = collections.Counter(a) vs = [] for v in list(c.values()): vs.append(v) vs.sort(reverse=True) i = 0 if len(vs) <= k: print(i) exit() else: while len(vs) > k: i += vs[-1] vs.pop() else: print(i) exit()
p03497
from collections import Counter n, m = list(map(int, input().split())) dic = Counter(list(map(int, input().split()))) lis = sorted(list(dic.items()), key=lambda x: x[1], reverse=True) res = 0 for i, x in enumerate(lis): if i < m: continue else: res += x[1] print(res)
from collections import Counter n, m = list(map(int, input().split())) dic = Counter(list(map(int, input().split()))) lis = sorted(list(dic.items()), key=lambda x: x[1], reverse=True) res = 0 for i in range(min(m, len(lis))): res += lis[i][1] print((n - res))
p03497
N, K=list(map(int, input().split())) A=list(map(int, input().split())) sa=set(A) if len(sa)<=K: print((0)) else: # 書き換える要素の種類数 sub=len(sa)-K # 少ないやつを書き換えたい a=list(sa) numl=[] for i in a: numl.append(A.count(i)) numl.sort() print((sum(numl[:sub])))
N, K=list(map(int, input().split())) A=list(map(int, input().split())) sa=set(A) if len(sa)<=K: print((0)) else: # 書き換える要素の種類数 sub=len(sa)-K # 少ないやつを書き換えたい A.sort() A.append(A[-1]) a=[0]*len(sa) j=0 for i in range(N): a[j]+=1 if A[i]!=A[i+1]: j+=1 a.sort() print((sum(a[:sub])))
p03497
n, k = list(map(int,input().split())) a = list(map(int,input().split())) aset = set(a) count = [] n = len(aset) for i in aset: count.append([i,a.count(i)]) if n <= k: print((0)) else: c = n - k count.sort(key=lambda x: x[1]) ans = 0 for i in range(c): ans += count[i][1] print(ans)
n, k = list(map(int,input().split())) a = list(map(int,input().split())) a.sort() count = [] c = 1 for i in range(n-1): if a[i] != a[i+1]: count.append(c) c = 1 else: c += 1 if i == n - 2: count.append(c) l = len(count) #print(a) #print(count) c = 0 if l <= k: print((0)) else: count.sort() for i in range(l): l -= 1 c += count[i] if l <= k: print(c) quit()
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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]])))
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))
p03497
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)
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)
p03497
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)
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)
p03497
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)]
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))
p03497
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)
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)
p03497
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)
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)
p03497
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])))
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])))
p03497
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)
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))
p03497
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:])))
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:])))
p03497
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:])))
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:])))
p03497
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))
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))
p03497
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)
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])))
p03497
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)
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)
p03497
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)])))
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)])))
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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)
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)
p03497
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)
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]
p03497
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)
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)
p03497
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()
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)
p03497
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)])))
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])))
p03497
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)
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)
p03497
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])))
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])))
p03497
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))
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))
p03497
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)
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)
p03497
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)
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)
p03497
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!')
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!')
p02269
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")
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")
p02269
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')
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')
p02269
#!/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)
#!/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)
p02269
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()
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()
p02269
dic = {"A":[], "C":[], "G":[], "T":[]} for i in range(int(eval(input()))): cmd, arg = input().split() if cmd == "insert": dic[arg[0]].append(arg) else: if arg in dic[arg[0]]: print("yes") else: print("no")
dic = {} for i in range(int(eval(input()))): cmd, arg = input().split() if cmd == "insert": dic[arg] = 0 else: if arg in dic: print("yes") else: print("no")
p02269
#! python3 # dictionary.py # ハッシュ法, チェイン法, 開番地法, etc # オープンアドレス法で実装する M = 113131 def getkey(text): dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} sum = 0 p = 1 for c in text: sum += p*dic[c] p *= 5 return sum def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
#! python3 # dictionary.py # ハッシュ法, チェイン法, 開番地法, etc # オープンアドレス法で実装する M = 8193173 def getkey(text): dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} sum = 0 p = 1 for c in text: sum += p*dic[c] p *= 5 return sum def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
p02269
#! python3 # dictionary.py # ハッシュ法, チェイン法, 開番地法, etc # オープンアドレス法で実装する M = 8193173 def getkey(text): dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} sum = 0 p = 1 for c in text: sum += p*dic[c] p *= 5 return sum def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
M = 15140366 def getkey(text): dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} sum = 0 p = 1 for c in text: sum += p*dic[c] p *= 5 return sum def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
p02269
import hashlib M = 15140366 def getkey(text): dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} sum = 0 p = 1 for c in text: sum += p*dic[c] p *= 5 return sum dict = {} def find(text): global dict # key = getkey(text) i = 0 while i < M: h = hashlib.md5(text.encode()).hexdigest() if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict # key = getkey(text) i = 0 while i < M: j = hashlib.md5(text.encode()).hexdigest() if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
M = 15140366 def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M word_dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} def getkey(text): sum = 0 p = 1 for c in text: sum += p*word_dic[c] p *= 5 return sum dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
p02269
M = 15140366 def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M word_dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} def getkey(text): sum = 0 p = 1 for c in text: sum += p*word_dic[c] p *= 5 return sum dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
M = 2056197 def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M word_dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} def getkey(text): sum = 0 p = 1 for c in text: sum += p*word_dic[c] p *= 5 return sum dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
p02269
M = 1046527 def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M word_dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} def getkey(text): sum = 0 p = 1 for c in text: sum += p*word_dic[c] p *= 5 return sum dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) for i in range(n): op, text = input().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
import sys M = 1046527 def h1(key): return key % M def h2(key): return 1 + (key %(M-1)) def h3(key, i): return (h1(key) + i*h2(key)) % M word_dic = {'A': 1, 'T': 2, 'G': 3, 'C': 4} def getkey(text): sum = 0 p = 1 for c in text: sum += p*word_dic[c] p *= 5 return sum dict = {} def find(text): global dict key = getkey(text) i = 0 while i < M: h = h3(key, i) if dict.get(h) == None: break elif dict[h] == text: return True i += 1 return False def insert(text): global dict key = getkey(text) i = 0 while i < M: j = h3(key, i) if dict.get(j) == None: dict[j] = text break else: i += 1 n = int(eval(input())) operations = sys.stdin.readlines() for ope in operations: op, text = ope.rstrip().split(' ') if op == 'insert': insert(text) elif op == 'find': rst = find(text) if rst: print('yes') else: print('no')
p02269
from collections import deque n = int(eval(input())) dict = deque() for i in range(n): order = input().split() if order[0] == "insert": dict.append(order[1]) else: if order[1] in dict: print("yes") else: print("no")
from collections import deque n = int(eval(input())) dict = {} for i in range(n): order = input().split() if order[0] == "insert": dict[order[1]] = i else: if order[1] in dict: print("yes") else: print("no")
p02269
#!/usr/bin/env python # -*- coding:utf-8 -*- #from __future__ import print_function import time import sys import io import re import math #start = time.clock() #i = 0 a,b=[],[] check = re.compile('insert') n=eval(input()) #while True: for x in range(n): (i,f)=list(map(str, input().split())) if check.search(i): a.append(f) else: # b.append(f) #print a #print b #for y in b: if f in a: print('yes') else: print('no')
#!/usr/bin/env python # -*- coding:utf-8 -*- #from __future__ import print_function import time import sys import io import re import math #start = time.clock() #i = 0 #check = 'insert' n=eval(input()) a=set() for x in range(n): (i,f)=list(map(str, input().split())) if i=='insert': a.add(f) else: if f in a: print('yes') else: print('no')
p02269
import sys d={} for e in sys.stdin.readlines()[1:]: c,g=e.split() if'i'==c[0]:d[g]=0 else:print((['no','yes'][g in d]))
import sys d={} for e in sys.stdin.readlines()[1:]: if'i'==e[0]:d[e[7:]]=0 else:print((['no','yes'][e[5:]in d]))
p02269
import sys d={} for e in sys.stdin.readlines()[1:]: if'f'==e[0]:print(('yes'if e[5:]in d else'no')) else:d[e[7:]]=0
import sys def m(): d={} for e in sys.stdin.readlines()[1:]: if'f'==e[0]:print(('yes'if e[5:]in d else'no')) else:d[e[7:]]=0 if'__main__'==__name__:m()
p02269
import sys def m(): d={} for e in sys.stdin.readlines()[1:]: if'f'==e[0]:print(('yes'if e[5:]in d else'no')) else:d[e[7:]]=0 if'__main__'==__name__:m()
import sys def m(): d={};eval(input()) for e in sys.stdin: if'f'==e[0]:print(('yes'if e[5:]in d else'no')) else:d[e[7:]]=0 if'__main__'==__name__:m()
p02269
import sys def m(): d={};eval(input()) for e in sys.stdin: if'f'==e[0]:print(('yes'if e[5:]in d else'no')) else:d[e[7:]]=0 if'__main__'==__name__:m()
import sys def m(): d={};eval(input()) for e in sys.stdin: if'f'==e[0]:print((['no','yes'][e[5:]in d])) else:d[e[7:]]=0 if'__main__'==__name__:m()
p02269
import sys def m(): d={0};eval(input()) for e in sys.stdin: if'f'==e[0]:print((['no','yes'][e[5:]in d])) else:d|={e[7:]} if'__main__'==__name__:m()
import sys def m(): d={};eval(input()) for e in sys.stdin: if'f'==e[0]:print((['no','yes'][e[5:]in d])) else:d[e[7:]]=0 if'__main__'==__name__:m()
p02269
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ??\????????????????????????????°?????????????????????????????£?????????????????????? insert str: ????????? str ?????????????????? find str: ????????? str ?????????????????´??? 'yes'??¨????????????????????´??? 'no'??¨??????????????? ??????????????????????????????'A', 'C', 'G', 'T' ???????¨????????????????????§???????????????? 1 ??? ?????????????????? ??? 12 n ??? 1,000,000 """ import sys import random class Node: """ Treap???????´?????????? """ def __init__(self, value, usen): """ ????????????????????? """ self.V = value # ??? self.U = usen # ????????? self.L = None # ?????? self.R = None # ?????? def Find(t, value): """ ????????¨??¢?´¢ """ if t is not None: if value == t.V: # ????????? # print("Finded p:'{}' v:'{}'".format(t.V, value)) return True elif value < t.V: # ?°????????????§?????? # print("Left Search p:'{}' v:'{}'".format(t.V, value)) return Find(t.L, value) elif value > t.V: # ??§???????????§?????? # print("Right Search p:'{}' v:'{}'".format(t.V, value)) return Find(t.R, value) # print("Not Exists v:'{}'".format(value)) return False def Insert(t, value): """ ????????¨???????????? """ if t is None: # ??????????????? t = Node(value, random.random()) # print("\tInsert '{}'".format(value)) return t # ????´??????\ if value < t.V: # ?°??????? # print("\tto Left p:'{}' v:'{}'".format(t.V, value)) t.L = Insert(t.L, value) # ??????????´??????\ if t.U > t.L.U: return RotateR(t) elif value > t.V: # ??§?????? # print("\tto Right p:'{}' v:'{}'".format(t.V, value)) t.R = Insert(t.R, value) # ????????? if t.U > t.R.U: return RotateL(t) # elif value == t.V: # ???????????????????????????????????§?????? # print("\tExists p:'{}' v:'{}'".format(t.V, value)) return t def RotateR(a): """ ????????¨???????????¢ a:??? b:??°????????? """ if a.L is None: # ?????????????????? return a b = a.L # b ??? a ????????? a.L = b.R # a ???????????? b ?????????????????? b.R = a # b ???????????? a ????????? # print("\t\tRotateR a:{} b:{} b.R.V:{}".format(a.V, b.V, b.R.V)) return b def RotateL(a): """ ????????¨???????????¢ a:??? b:??°????????? """ if a.R is None: # ?????????????????? return a b = a.R # b ??? a ????????? a.R = b.L # a ???????????? b ?????????????????? b.L = a # b ???????????? a ????????? # print("\t\tRotateL a:{} b:{} b.L.V:{}".format(a.V, b.V, b.L.V)) return b def GetList(t, a): if t is not None: a.append(t.V) GetList(t.L, a) GetList(t.R, a) def main(): """ ????????? """ random.seed() # ??±??°????????? num = int(input().strip()) istr = sys.stdin.read() cmds = list(istr.splitlines()) root = None for i in cmds: # print("cmd:{} tree:{}".format(i,root)) if i[0] == "i": root = Insert(root, i[7:]) elif i[0] == "f": ret = Find(root, i[5:]) if ret == True: print("yes") else: print("no") # a = [] # GetList(root,a) # print(a) if __name__ == '__main__': main()
import sys def main(): """ MAIN """ num = int(input().strip()) istr = sys.stdin.read() cmds = list(istr.splitlines()) D = {} for i in cmds: if i[0] == "i": D[i[7:]] = 1 elif i[0] == "f": if i[5:] in D: print("yes") else: print("no") if __name__ == '__main__': main()
p02269
N = int(eval(input())) d = {} for i in [None]*N: a, b = input().split() if a == "insert": d[b] = 1 else: print(("yes" if b in d else "no"))
class Dictionary(object): def __init__(self, size): self.size = size self.a = [None]*size def hash(self, x): key = hash(x) % self.size while self.a[key] and self.a[key] != x: key = (key + 10**9+7) % self.size return key def insert(self, x): self.a[self.hash(x)] = x def find(self, x): return self.a[self.hash(x)] is not None if __name__ == "__main__": import sys n = int(input()) dictionary = Dictionary(n) result = [] for command, s in (l.split() for l in sys.stdin): if command == "insert": dictionary.insert(s) else: result.append("yes" if dictionary.find(s) else "no") print(*result, sep="\n")
p02269
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 13:14:10 2018 ALDS1-4c simple implementation @author: maezawa """ n = int(eval(input())) a = [] for s in range(n): cmd, word = input().split() if cmd == 'insert': a.append(word) else: if word in a: print('yes') else: print('no')
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 13:14:10 2018 ALDS1-4c implementation with dictionary @author: maezawa """ n = int(eval(input())) a = dict([]) for s in range(n): cmd, word = input().split() if cmd == 'insert': a[word]='' else: if word in a: print('yes') else: print('no')
p02269
command_num = int(eval(input())) dict = [] for i in range(command_num): in_command, in_str = input().rstrip().split(" ") if in_command == "insert": dict.append(in_str) elif in_command == "find": if dict.count(in_str) > 0: print("yes") else: print("no")
command_num = int(eval(input())) dict = set([]) for i in range(command_num): in_command, in_str = input().rstrip().split(" ") if in_command == "insert": dict.add(in_str) elif in_command == "find": if in_str in dict: print("yes") else: print("no")
p02269
def find(data, s): l = 0 r = len(data) while l < r: ind = (l + r) // 2 if data[ind] == s: return True elif data[ind] < s: l = ind + 1 else: r = ind return False def insert(data, s): if len(data) == 0: data.append(s) else: for i in range(len(data)): if s <= data[i]: data.insert(i, s) return data data.append(s) return data n = int(eval(input())) data = [] for _ in range(n): command = input().split() if command[0] == "insert": data = insert(data, command[1]) elif command[0] == "find": if find(data, command[1]): print("yes") else: print("no")
n = int(eval(input())) data = set() for _ in range(n): command = input().split() if command[0] == "insert": data.add(command[1]) elif command[0] == "find": if command[1] in data: print("yes") else: print("no")
p02269
class my_dict: def __init__(self): self.d = [] def insert(self, x): if (x not in self.d): self.d.append(x) def find(self, x): if (x in self.d): return 'yes' else: return 'no' def main(): n = int(eval(input())) my_d = my_dict() for i in range(n): command, string = input().split() if (command == 'insert'): my_d.insert(string) elif (command == 'find'): print((my_d.find(string))) if __name__ == "__main__": main()
def main(): n = int(eval(input())) d = set([]) for i in range(n): command, string = input().split() if (command == 'insert'): d.add(string) elif (command == 'find'): if string in d: print('yes') else: print('no') if __name__ == "__main__": main()
p02269
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(T, key): i = 0 while True: j = h(key, i) if T[j] is None: T[j] = key return j else: i += 1 def search(T, key): i = 0 while True: j = h(key, i) if T[j] == key: return j elif T[j] is None or i >= m: return None else: i += 1 global m r = {"A": 1, "C": 2, "G": 3, "T": 4, } t = [] m = int(eval(input())) for i in range(m): cmd, key = input().split() if cmd == "insert": t.append(key) else: if key in t: print("yes") else: print("no")
t = set() m = int(eval(input())) for i in range(m): cmd, key = input().split() if cmd == "insert": t.add(key) else: if key in t: print("yes") else: print("no")
p02269
import sys readline = sys.stdin.readline li = [] for _ in range(int(readline())): c, s = readline().split() if c == "insert": li.append(s) elif c == "find": print(("yes" if s in li else "no"))
import sys readline = sys.stdin.readline SET = set() for _ in range(int(readline())): c, s = readline().split() if c == "insert": SET.add(s) elif c == "find": print(("yes" if s in SET else "no"))
p02269
import sys readline = sys.stdin.readline SET = set() for _ in range(int(readline())): c, s = readline().split() if c == "insert": SET.add(s) elif c == "find": print(("yes" if s in SET else "no"))
import sys readline = sys.stdin.readline SET = set() eval(input()) for s in sys.stdin: if s[0] == "i": SET.add(s[7:]) elif s[0] == "f": print(("yes" if s[5:] in SET else "no"))
p02269
n = int(input()) dict = [] for i in range(n): command, word = input().split() if command == 'insert': dict.append(word) else: try: dict.index(word) print('yes') except: print('no') pass
n = int(input()) def makeHash(letter): if letter == 'A': return 1 elif letter == 'C': return 2 elif letter == 'G': return 3 elif letter == 'T': return 4 return 0 dict = {} for i in range(n): command, word = input().split() key = 0 if command == 'insert': dict[word] = 1 elif command == 'find': if word in dict: print('yes') else: print('no')
p02269
if __name__ == '__main__': try: n = int(input()) except: print('the first input must be integer value!') exit() genoms = [] answers = [] for _ in range(n): values = input().split() order = values[0] genom = values[1] if order == "insert": genoms.append(genom) else: answers.append('yes' if genom in genoms else 'no' ) # print(genoms) # print(answers) for answer in answers: print(answer)
if __name__ == '__main__': try: n = int(input()) except: print('the first input must be integer value!') exit() genoms = set([]) answers = [] for _ in range(n): values = input().split() order = values[0] genom = values[1] if order == "insert": genoms.add(genom) else: # TODO: fasten here! answers.append('yes' if genom in genoms else 'no' ) # print(genoms) # print(answers) for answer in answers: print(answer)
p02269
n = int(eval(input())) s = set() for i in range(n): c, m = input().split() if c[0] == 'i': s.add(m) elif c[0] == 'f': if m in s: print('yes') else: print('no')
n = int(input()) l = [] s = {} for i in range(n): c, m = input().split() if c[0] == 'i': s[m] = 0 elif c[0] == 'f': if m in s: l.append('yes') else: l.append('no') print(*l,sep='\n')
p02269
from collections import deque n = int(eval(input())) l = deque() for i in range(n): cmd = input().split() if cmd[0] == 'insert': l.append(cmd[1]) if cmd[0] == 'find': if cmd[1] in set(l): print('yes') else: print('no')
n = int(eval(input())) l = set() for i in range(n): cmd = input().split() if cmd[0] == 'insert': l.add(cmd[1]) if cmd[0] == 'find': if cmd[1] in l: print('yes') else: print('no')
p02269
n = int(eval(input())) class Hash: def __init__(self): self.m = 1000003 self.T = [None] * self.m def insert(self, key): i = 0 while True: j = self.h(key, i) if self.T[j] == None: self.T[j] = key break else: i = i + 1 def search(self, key): i = 0 while True: j = self.h(key, i) if self.T[j] == key: return j elif self.T[j] == None: return None else: i += 1 return self.T[self.h(key)] def h(self, key, i): ki = self.key2int(key) h1 = ki % self.m h2 = i * (1 + (ki % (self.m - 1))) return (h1 + h2) % self.m def key2int(self, key): p = 1 ret = 0 for s in key: a = ['A', 'C', 'G', 'T'].index(s) + 1 ret += p * a p *= 5 return ret h = Hash() for i in range(n): op, st = input().split() if op == 'insert': h.insert(st) else: if h.search(st): print('yes') else: print('no')
n = int(eval(input())) h = {} for i in range(n): op, st = input().split() if op == 'insert': h[st] = 'yes' else: print((h.get(st, 'no')))
p02269
import sys def main(): _ = int(eval(input())) imps = sys.stdin.readlines() db = [] for imp in imps: command = imp.split(' ') if command[0] == 'insert': db.append(command[1]) else: if command[1] in db: print('yes') else: print('no') main()
import sys n = int(eval(input())) dic = {} input_ = sys.stdin.readlines() for i in input_: c, s = i.split() if c == 'insert': dic[s] = 0 else: if s in dic: print('yes') else: print('no')
p02269
from collections import deque n = int(eval(input())) l = deque() for _ in range(n): ss = input().split() order, string = ss[0], ss[1] if order == "insert": l.append(string) else: print(('yes' if string in l else 'no'))
n = int(eval(input())) l = {} for _ in range(n): ss = input().split() order, string = ss[0], ss[1] if order == "insert": l[string] = 1 else: print(('yes' if string in l else 'no'))
p02269
n = int(eval(input())) strs = [] for i in range(n): s = input().split() if(s[0] == 'insert'): if(s[1] not in strs): strs.append(s[1]) else: if(s[1] in strs): print('yes') else: print('no')
n = int(eval(input())) strs = {} for i in range(n): s = input().split() if(s[0] == 'insert'): if(s[1] not in strs): strs[s[1]] = '' else: if(s[1] in strs): print('yes') else: print('no')
p02269
from collections import deque D = deque() N = int(eval(input())) for i in range(N): c, s = input().split() if c == "insert": D.append(s) elif c == "find": if (s in D): print("yes") else: print("no")
from collections import deque D = set() N = int(eval(input())) for i in range(N): c, s = input().split() if c == "insert": D.add(s) elif c == "find": if (s in D): print("yes") else: print("no")
p02269
import sys class HashTable: def __init__(self): self.table = [None] * 4 self.flag = False class Dictionary: def __init__(self): self.hashTable = HashTable() def insert(self, key): table = self.hashTable for c in key: hash = self.toHash(c) if table.table[hash] is None: table.table[hash] = HashTable() table = table.table[hash] table.flag = True def find(self, key): table = self.hashTable for c in key: hash = self.toHash(c) if table.table[hash] is None: return False table = table.table[hash] if table.flag: return True else: return False def toHash(self, key): key = key.replace("A", "0") key = key.replace("C", "1") key = key.replace("G", "2") key = key.replace("T", "3") return int(key) if __name__ == "__main__": dic = Dictionary() lines = sys.stdin.readlines() del lines[0] for command in lines: key = command.split()[1] if command[0] == "i": dic.insert(key) else: if dic.find(key): print("yes") else: print("no")
import sys class HashTable: def __init__(self): self.table = [None] * 4 self.flag = False class Dictionary: def __init__(self): self.hashTable = HashTable() def insert(self, key): table = self.hashTable for c in key: hash = self.toHash(c) if table.table[hash] is None: table.table[hash] = HashTable() table = table.table[hash] table.flag = True def find(self, key): table = self.hashTable for c in key: hash = self.toHash(c) if table.table[hash] is None: return False table = table.table[hash] if table.flag: return True else: return False def toHash(self, key): if key == "A": return 0 elif key == "C": return 1 elif key == "G": return 2 else: return 3 if __name__ == "__main__": dic = Dictionary() lines = sys.stdin.readlines() del lines[0] for command in lines: key = command.split()[1] if command[0] == "i": dic.insert(key) else: if dic.find(key): print("yes") else: print("no")
p02269
n = int(eval(input())) M = 1046527 a = [0 for i in range(M)] for i in range(n): s = input().split(" ") num = 0 p = 1 for j in range(len(s[1])): if s[1][j] == "A": num += p * 1 elif s[1][j] == "C": num += p * 2 elif s[1][j] == "G": num += p * 3 else: num += p * 4 p *= 5 h1 = num % M h2 = h1 + num % (M - 1) k = 0 if s[0][0] == "i": while True: h = (h1 + k * h2) % M if a[h] == 0: a[h] = s[1] break elif a[h] == s[1]: break else: k += 1 else: while True: h = (h1 + k * h2) % M if a[h] == s[1]: print("yes") break elif a[h] == 0: print("no") break else: k += 1
n = int(eval(input())) dic = set() for i in range(n): Cmd, Key = input().split(" ") if Cmd == "insert": dic.add(Key) else: if Key in dic: print("yes") else: print("no")
p02269
n = int( eval(input( )) ) dic = {} output = [] for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if not dic.get( word ): output.append( "no" ) else: output.append( "yes" ) print(( "\n".join( output ) ))
n = int( input( ) ) dic = {} for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if not dic.get( word ): print( "no" ) else: print( "yes" )
p02269
n = int( input( ) ) dic = {} for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if not dic.get( word ): print( "no" ) else: print( "yes" )
n = int( input( ) ) dic = {} for i in range( n ): cmd, word = input( ).split( " " ) if "insert" == cmd: dic[ word ] = True elif "find" == cmd: if word in dic: print( "yes" ) else: print( "no" )
p02269
def binarySearch(array, key): left = 0 right = len(array) while left < right: mid = int((left + right) / 2) if key == array[mid]: return True elif key > array[mid]: left = mid + 1 elif key < array[mid]: right = mid else: print("ERROR") return False def convertor(string): result = "" for s in string: if s == 'A': result += "1" elif s == 'C': result += "2" elif s == 'G': result += "3" elif s == 'T': result += "4" else: print("ERROR") return eval(result) n = int(eval(input())) d = [] for i in range(n): cmd, string = input().split() string = convertor(string) if cmd == "insert": d.append(string) else: if binarySearch(sorted(d), string): print("yes") else: print("no")
n = int(eval(input())) d = {} for i in range(n): cmd, string = input().split() if cmd == "insert": d[string] = True else: try: if d[string]: print("yes") except: print("no")
p02269
#! /usr/bin/env python # -*- coding: utf-8 -*- ''' ?????? ''' class Dictionary(object): """ Dictionary """ def __init__(self): self.dict = [] def insert(self, x): self.dict.append(x) def find(self, x): if x in self.dict: print('yes') else: print('no') if __name__ == '__main__': N = int(eval(input())) d = Dictionary() for _ in range(N): command, key = list(input().split()) if command == 'insert': d.insert(key) elif command == 'find': d.find(key)
#! /usr/bin/env python # -*- coding: utf-8 -*- ''' ?????? ''' class Dictionary(object): """ Dictionary """ def __init__(self): self.dict = {} def insert(self, x): self.dict[x] = 0 def find(self, x): if x in list(self.dict.keys()): print('yes') else: print('no') if __name__ == '__main__': N = int(eval(input())) d = Dictionary() for _ in range(N): command, key = list(input().split()) if command == 'insert': d.insert(key) elif command == 'find': d.find(key)
p02269
class Dictionary: def __init__(self): self.dic = [] def insert(self, key): self.dic.append(key) def find(self, key): return key in self.dic dic = Dictionary() n = int(eval(input())) for i in range(n): cmd = input().split() if cmd[0] == "insert": dic.insert(cmd[1]) elif cmd[0] == "find": if dic.find(cmd[1]): print("yes") else: print("no") else: print("wrong command")
dic = set() n = int(eval(input())) for i in range(n): cmd, val = input().split() if cmd == "insert": dic.add(val) elif cmd == "find": print(("yes" if val in dic else "no")) else: print("wrong command")
p02269
dict = {"A":1,"C":2,"G":3,"T":4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]]*4**i return ans n = int(input()) ls = [0 for i in range(6710886)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
dict = {"A":1,"C":2,"G":3,"T":4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]]*4**i return ans n = int(input()) ls = [0 for i in range(3000000)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
p02269
dict = {"A":1,"C":2,"G":3,"T":4} def a2n(a): ans = 0 for i in range(len(a)): ans += dict[a[i]]*4**i return ans n = int(input()) ls = [0 for i in range(3000000)] for i in range(n): inp = input() if inp[0] == "i": ls[a2n(inp[7:])] = 1 else: print("yes" if ls[a2n(inp[5:])] else "no")
n = int(input()) ls = {} for i in range(n): inp = input() if inp[0] == "i": ls[inp[7:]] = 1 else: try: if ls[inp[5:]] == 1: print("yes") except: print("no")
p02269
# -*- coding: utf-8 -*- class HashTable(list): def __init__(self, length): list.__init__(self) self.length = length self[:] = [None] * length def h1(self, key): return key % self.length def h2(self, key): return 1 + (key % (self.length - 1)) def h(self, key, i): return (self.h1(key) + i*self.h2(key)) % self.length def insert(self, key): i = 0 while True: j = self.h(key, i) if self[j] is None: self[j] = key return j else: i += 1 def search(self, key): i = 0 while True: j = self.h(key, i) if self[j] == key: return j elif self[j] is None or i >= self.length: return None else: i += 1 if __name__ == '__main__': n = int(eval(input())) T = HashTable(n) char2num = str.maketrans("ACGT", "1234") for _ in range(n): command, char = input().split(" ") num = int(char.translate(char2num)) if command == "insert": T.insert(num) else: if T.search(num) is None: print("no") else: print("yes")
# -*- coding: utf-8 -*- class HashTable(list): def __init__(self, length): list.__init__(self) self.length = length self[:] = [None] * length def h1(self, key): return key % self.length def h2(self, key): return 1 + (key % (self.length - 1)) def h(self, key, i): return (self.h1(key) + i*self.h2(key)) % self.length def insert(self, key): i = 0 while True: j = self.h(key, i) if self[j] is None: self[j] = key return j else: i += 1 def search(self, key): i = 0 while True: j = self.h(key, i) if self[j] == key: return j elif self[j] is None or i >= self.length: return None else: i += 1 def getNum(char): char2num = str.maketrans("ACGT", "1234") return int(char.translate(char2num)) if __name__ == '__main__': n = int(eval(input())) T = HashTable(n) C = [input().split(" ") for i in range(n)] C = [(x[0], getNum(x[1])) for x in C] for command, num in C: if command == "insert": T.insert(num) else: if T.search(num) is None: print("no") else: print("yes")
p02269
# -*- coding: utf-8 -*- class HashTable(list): def __init__(self, length): list.__init__(self) self.length = length self[:] = [None] * length def h1(self, key): return key % self.length def h2(self, key): return 1 + (key % (self.length - 1)) def h(self, key, i): return (self.h1(key) + i*self.h2(key)) % self.length def insert(self, key): i = 0 while True: j = self.h(key, i) if self[j] is None: self[j] = key return j else: i += 1 def search(self, key): i = 0 while True: j = self.h(key, i) if self[j] == key: return j elif self[j] is None or i >= self.length: return None else: i += 1 def getNum(char): char2num = str.maketrans("ACGT", "1234") return int(char.translate(char2num)) if __name__ == '__main__': n = int(eval(input())) T = HashTable(n) C = [(x[0], getNum(x[1])) for x in [input().split(" ") for i in range(n)]] for command, num in C: if command == "insert": T.insert(num) else: if T.search(num) is None: print("no") else: print("yes")
# -*- coding: utf-8 -*- class HashTable(list): def __init__(self, length): list.__init__(self) self.length = length self[:] = [None] * length def h1(self, key): return key % self.length def h2(self, key): return 1 + (key % (self.length - 1)) def h(self, key, i): return (self.h1(key) + i*self.h2(key)) % self.length def insert(self, key): i = 0 while True: j = self.h(key, i) if self[j] is None: self[j] = key return j else: i += 1 def search(self, key): i = 0 while True: j = self.h(key, i) if self[j] == key: return j elif self[j] is None or i >= self.length: return None else: i += 1 def getNum(char): char2num = str.maketrans("ACGT", "1234") return int(char.translate(char2num)) if __name__ == '__main__': n = int(eval(input())) T = HashTable(n*10) C = [input().split(" ") for i in range(n)] C = [(x[0], getNum(x[1])) for x in C] for command, num in C: if command == "insert": T.insert(num) else: if T.search(num) is None: print("no") else: print("yes")
p02269