Problem:


Search III

Your task is to write a program of a simple dictionary which implements the following instructions:

insert str: insert a string str in to the dictionary

find str: if the distionary contains str, then print 'yes', otherwise print 'no'

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Constraints

A string consists of 'A', 'C', 'G', or 'T'

1 ≤ length of a string ≤ 12

 n ≤ 1000000 

Sample Input 1

5
insert A
insert T
insert C
find G
find A

Sample Output 1

no
yes

Sample Input 2

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Sample Output 2

yes
no
no
yes
yes
yes

Notes

Template in C



Sample input:
5
insert A
insert T
insert C
find G
find A


Sample output:
no
yes

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s_dict = {}
    for i in range(n):
        commandLine = input().split()
        if commandLine[0] == "insert":
            s_dict[commandLine[1]] = commandLine[1]
        elif commandLine[0] == "find":
            if s_dict.get(commandLine[1]) != None:
                print("yes")
            else:
                print("no")

Submission status: Accepted

Solution code:
# import sys

# def isHigh(str, compare):
#   if len(str) <= len(compare):
#     for i in range(len(str)):
#       if str[i] > compare[i]:
#         return True
#       elif str[i] < compare[i]:
#         return False
#     return False
#   else:
#     for i in range(len(compare)):
#       if str[i] > compare[i]:
#         return True
#       elif str[i] < compare[i]:
#         return False
#     return True

# def isLow(str, compare):
#   if len(str) <= len(compare):
#     for i in range(len(str)):
#       if str[i] < compare[i]:
#         return True
#       elif str[i] > compare[i]:
#         return False
#     return True
#   else:
#     for i in range(len(compare)):
#       if str[i] < compare[i]:
#         return True
#       elif str[i] > compare[i]:
#         return False
#     return False

# def main():
#     dictionary = []
#     n = int(input())
#     for _ in range(n):
#         order, str = input().split()

#         if order == 'insert':
#             len_dic = len(dictionary)
#             if len_dic > 1:
#                 L = 0
#                 R = len(dictionary) - 1
#                 M = (R + 1) // 2
#                 while M >= L:
#                     is_high = isHigh(str, dictionary[M-1])
#                     is_low = isLow(str, dictionary[M])
#                     if is_high and is_low:
#                         dictionary.insert(M, str)
#                         break
#                     elif is_high and not is_low:
#                         L = M
#                         if L == len(dictionary) - 1:
#                             dictionary.append(str)
#                             break
#                     elif not is_high and is_low:
#                         R = M - 1
#                         if R == 0:
#                             dictionary.insert(0, str)
#                             break
#                     else:
#                         print('予期せぬエラー')
#                         sys.exit(1)
#                     M = (L + R + 1) // 2
#             elif len_dic == 1:
#                 if isHigh(str, dictionary[0]):
#                     dictionary.append(str)
#                 else:
#                     dictionary.insert(0, str)
#             elif len_dic == 0:
#                 dictionary.append(str)
#             else:
#                 print('予期せぬエラー')
#                 sys.exit(1)

#         elif order == 'find':
#             len_dic = len(dictionary)
#             if len_dic > 1:
#                 L = 0
#                 R = len(dictionary) - 1
#                 M = (R + 1) // 2
#                 while M >= L:
#                     # print(L,R,M)
#                     if dictionary[M] == str:
#                         print('yes')
#                         break
#                     is_high = isHigh(str, dictionary[M])
#                     if is_high:
#                         L = M + 1
#                         if L > R:
#                             print('no')
#                             break
#                     else:
#                         R = M - 1
#                         if R < L:
#                             print('no')
#                             break
#                     M = (L + R + 1) // 2
#             elif len_dic == 1:
#                 if dictionary[0] == str:
#                     print('yes')
#                 else:
#                     print('no')
#             elif len_dic == 0:
#                 print('no')
#             else:
#                 print('予期せぬエラー')
#                 sys.exit(1)
#         else:
#             print('入力に誤りがあります。')
#             sys.exit(1)

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

SIZE = 13
POW = [1] * SIZE
for i in range(1, SIZE):
    POW[i] = POW[i-1] * 4
index = {'A': 1, 'G': 2, 'C': 3, 'T': 4}
DICT = [False]*POW[12] # 4^12個の要素

def getNum(s):
    global POW, index
    n = -1
    for i in range(len(s)):
        n += index[s[i]]*POW[i]

    return n

def main():
    global DICT
    n = int(input())

    for _ in range(n):
        c, s = input().split()

        if c == 'insert':
            DICT[getNum(s)] = True
        else:
            if DICT[getNum(s)]:
                print('yes')
            else:
                print('no')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    Q = [LSS() for _ in range(n)]

    d = set()

    for i, j in Q:
        if i=='insert':
            d.add(j)
        else:
            if j in d:
                print('yes')
            else:
                print('no')

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(n):
    a,b = input().split()
    if a == "insert":
        s.add(b)
    elif b in s:
        print("yes")
    else:
        print("no")

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


n = int(input())
d = set()
for i in range(n):
    command,s = input().split()
    if command == "insert":
        d.add(s)
    else:
        if s in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
data = {}
for i in range(n):
    a,b = map(str,input().split())
    if a == "insert":
        data[b] = 1
    else:
        if b in data:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
d = {}
ans = []

for i in range(n):
    order = list(map(str, input().split()))
    if order[0] == 'insert':
        d[order[1]] = i
    else:
        if d.__contains__(order[1]):
            ans.append('yes')
        else:
            ans.append('no')

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
cmd = []
d = set()

n = int(input())
for i in range(n):
    cmd.clear()
    cmd = input().split()
    if cmd[0] =='insert':
        d.add(cmd[1])
    else:
        if cmd[1] in d:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n=int(input())
answer=[]
d={}
for i in range(n):
    cmd,word=input().split()
    if cmd=="insert":
        d[word]=True
    
    else:
        if word in d:
            print("yes")

        else:
            print("no")

Submission status: Accepted

Solution code:
from collections import deque, defaultdict
import sys
import math

if __name__ == '__main__':
    n = int(input())
    s = defaultdict(int)
    for _ in range(n):
        a, b = input().split()
        if a == 'insert':
            s[b] += 1
        else:
            if s[b]:
                print('yes')
            else:
                print('no')

Submission status: Accepted

Solution code:
import time

n = int(input())
#t1 = time.time()

S = set()
for i in range(0,n):
	lst = list(input().split())
	if lst[0] == 'insert':
		S.add(lst[1])
	elif lst[0] == 'find':
		if lst[1] in S:
			print('yes')
		else:
			print('no')

#S = []
#for i in range(0,n):
#	lst = list(input().split())
#	if lst[0] == 'insert':
#		S.append(lst[1])
#	elif lst[0] == 'find':
#		if S.count(lst[1]) != 0:
#			print('yes')
#		else:
#			print('no')

#t2 = time.time()
#elapsed = t2-t1
#print('経過時間:{0}'.format(elapsed))

Submission status: Accepted

Solution code:
def insert(dic,text):
  dic[text] = 1

def find(dic,text):
  if text in dic:
    print('yes')
  else:
    print('no')
    
num = int(input())
d = {}
while num > 0:
  ope , s = input().split()
  if ope == 'insert':
    insert(d,s)
  elif ope == 'find':
    find(d,s)  
  num -= 1

Submission status: Accepted

Solution code:
import sys

D = {}
input()
for line in sys.stdin:
    if line[0] == "f":
        print('yes' if line[5:] in D else 'no')
    else:
        D[line[7:]] = 0

Submission status: Accepted

Solution code:
# coding: utf-8
# ハッシュ（Dictパターン）

hash_list = {}

if __name__ == "__main__":
    n = int(input())

    for _ in range(n):
        command, arg = input().split()

        if command == 'insert':
            hash_list[arg] = 1
        else:
            print('yes' if arg in hash_list else 'no')

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
    req = input().split()
    if(req[0] == "insert"):
        dic[req[1]] = i
    elif(req[0] == "find"):
        if(req[1] in dic):
               print("yes")
        else:
               print("no")

Submission status: Accepted

Solution code:
a = int(input())

d = {}
for i in range(a):
    o,v = input().split()
    if o == 'insert':
        d[v] = v
    elif o == 'find':
        if v in d:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    commands = []
    for i in range(n):
        command=input().split()
        commands.append(command)
    return n, commands

def main(n,commands):
    d = dict()
    for cmd in commands:
        if(cmd[0]=='insert'):
            d[cmd[1]]=cmd[1]
        elif(cmd[0]=='find'):
            if(cmd[1] in d):
                print('yes')
            else:
                print('no')

if __name__=='__main__':
    n,commands=readinput()
    main(n,commands)

Submission status: Accepted

Solution code:
n = int(input())

values = {}
for _ in range(n):
  command, value = input().split()

  if command[0] == 'i':
    values[value] = value
  if command[0] == 'f':
    if value in values:
      print ('yes')
    else:
      print ('no')

Submission status: Accepted

Solution code:
n = int(input())
index = set()

for _ in range(n):
    command, string = input().split()
    if command == "insert":
        index.add(string)
    else:
        if string in index:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:

import sys
from sys import stdin
input = stdin.readline

n = int(input())
D = {}
for i in range(n):
    s = input()
    if s[0] == "i":
        D[s[7:]] = 11111111111111111111111111111111111
    else:
        print("yes" if s[5:] in D else "no")

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    a = set()
    _ = int(stdin.readline())
    for command,value in (line.split() for line in stdin.readlines()):
        if command == "insert":
            a.add(value)
        else:
            print("yes" if value in a else "no")

main()

Submission status: Accepted

Solution code:
n = int(input())
dict = set()
for i in range(n):
  a,b = input().split()
  if a=="insert":
    dict.add(b)
  else:
    if b in dict:
      print("yes")
    else:
      print("no")

Submission status: Accepted

Solution code:
n = int(input())
order = [''] * n
st = [''] * n
for i in range(n):
    order[i], st[i] = map(str, input().split())

dic = {}
for i in range(n):
    if order[i] == 'insert':
        dic.setdefault(st[i], 0)
    else:
        if st[i] in dic:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
d = {}

for i in range(n):
	op, NA = sys.stdin.readline().split()
	if op == "insert":
		d[NA] = 0
	else:
		if NA in d:
			print("yes")
		else:
			print("no")

Submission status: Accepted

Solution code:
n=int(input())
D=set()
for i in range(n):
    command,str_=input().split()
    if command=='insert':
        D.add(str_)
    elif command=='find':
        if str_ in D:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
a = {}

n = int(input())

for i in range(n):
  cmd, val = input().split()
  if cmd == 'insert':
    a[val] = val
  elif cmd == 'find':
    print('yes' if val in a else 'no')

Submission status: Accepted

Solution code:
n = int(input())
d = set()
for i in range(n):
    cmd, val = input().split()
    if cmd == 'insert':
        d.add(val)
    else:
        print('yes'*(val in d)or'no')

Submission status: Accepted

Solution code:
n = int(input())
lst = []

for i in range(n):
	tmp = input().split()
	lst.append(tmp)
	
d = {}

for i in range(n):
	if lst[i][0] == 'insert':
		d[lst[i][1]] = d.get(lst[i][1], 0) + 1
	elif lst[i][0] == 'find':
		print('yes') if lst[i][1] in d else print('no')

Submission status: Accepted

Solution code:
n = int(input())
myDict = {}

for i in range(n):
    cmd,key = input().split()
    if cmd == "insert":
        myDict.setdefault(key,key)
    else:
        if key in myDict.keys():
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
mp = {}
for _ in range(int(input())):
    op, x = input().split()
    if op == "insert":
        mp[x] = True
    else:
        print(['no', 'yes'][x in mp])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
dic = set()
def insert(s):
    dic.add(s)
def find(s):
    if s in dic:
        print("yes")
    else:
        print("no")
i = int(input())
for c in range(i):
    op,s = map(str,input().split())
    if op == "insert":
        insert(s)
    elif op == "find":
        find(s)

Submission status: Accepted

Solution code:
n = int(input())
s = set([])
for i in range(n):
    cmd, str1 = input().split()
    if cmd == "insert":
        s.add(str1)
    else:
        if str1 in s:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
N = int(input())

dic = {}
for i in range(N):
    com, s = input().split()
    if com == 'insert':
        dic[s] = True
    elif com == 'find':
        print('yes' if s in dic else 'no')

Submission status: Accepted

Solution code:
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
    if i in s:
        c+=1
print(c)
"""
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
    L=0
    R=n-1#探索する方の配列(s)はソート済みでないといけない
    while L<=R:
        M=(L+R)//2
        if s[M]<t[i]:
            L=M+1
        elif s[M]>t[i]:
            R=M-1
        else:
            a+=1
            break
print(a)
"""
#Dictionary
#dict型オブジェクトに対しinを使うとキーの存在確認になる
n=int(input())
d={}
for i in range(n):
    command,words=input().split()
    if command=='find':
        if words in d:
            print('yes')
        else:
            print('no')
    else:
        d[words]=0

Submission status: Accepted

Solution code:
class Dict(object):
    def __init__(self, size):
        self.dict = [None for _ in range(size)]
        self.size = size

    def h1(self, key):
        return key % self.size

    def h2(self, key):
        return 1 + (key % (self.size-1))

    def h(self, key, i):
        return (self.h1(key) + i * self.h2(key)) % self.size

    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.dict[j] == None:
                self.dict[j] = key
                break
            else:
                i += 1

    def find(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.dict[j] == key:
                return 1
            elif self.dict[j] == None or i >= self.size:
                return 0
            else:
                i += 1


def get_key(table, word):
    return int(word.translate(table))


if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

    table = str.maketrans({
        "A": "1",
        "C": "2",
        "G": "3",
        "T": "4"
    })

    m = 1046527
    d = Dict(m)

    n = int(input())

    for _ in range(n):
        command = input()
        if command[0] == 'i':
            d.insert(get_key(table, command[7:]))
        else:
            if d.find(get_key(table, command[5:])):
                print('yes')
            else:
                print('no')

Submission status: Accepted

Solution code:
n = int(input())

d = {}
for i in range(n):
    order,string = input().split()
    if order == "insert":
        d[string] = 1
    else:
        try:
            if d[string] :
                print("yes")
        except:
            print("no")

Submission status: Accepted

Solution code:
N = int(input())

a = set([])
for i in range(N):
    S = input()
    if S[0] == "i":
        a.add(S[7:])
        #print("a",a)
    else:
        print("yes" if S[5:] in a else "no")

Submission status: Accepted

Solution code:

def main():
    s = set()
    n = int(input())
    for _ in range(n):
        com = input().split()
        if com[0] == 'insert':s.add(com[1])
        else :
            if com[1] in s:print('yes')
            else          :print('no')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def insert(cnt, data):
    T[str(data)] = cnt


cnt = 0
T = {}
n = int(input())
for i in range(n):
    Order, data_S = input().split()
    if Order[0] =="i":
        insert(cnt, data_S)
        cnt +=1

    else:
        if str(data_S) in T:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
S = {}

ans = []
for i in range(n):
	order = input().split()
	if order[0] == "insert":
		S[order[1]] = 0
	elif order[0] == "find":
		if order[1] in S:
			ans.append("yes")
		else:
			ans.append("no")

for i in range(len(ans)):
	print(ans[i])

Submission status: Accepted

Solution code:
from sys import stdin
import math
# from sympy import nextprime
class hash():
    def __init__(self,n):#ｎは素数
        self.n=1000003
        self.memo=[None]*self.n
    def madekey(self,key):
        if key=='A':return '1'
        elif key=='C':return '2'
        elif key=='G':return '3'
        elif key=='T':return '4'
    def getkey(self,KEY):
        key=""
        for S in KEY:
            key=key+self.madekey(S)
        return int(key)
    def h1(self,key):
        return key%self.n
    def h2(self,key):
        return (key%(self.n-1))+1
    def insert(self,S):
        key=self.getkey(S)
        h1 = self.h1(key)
        h2 = self.h2(key)
        for i in range(0,self.n+1):
            j=(h1+(i*h2)) % self.n
            if self.memo[j] is None:
                self.memo[j]=S
                break

    def search(self,S):
        key = self.getkey(S)
        h1 = self.h1(key)
        h2 = self.h2(key)
        for i in range(0,self.n+1):
            j = (h1+(i*h2)) % self.n
            if self.memo[j] ==S:
                return 'yes'
            elif self.memo[j] is None or i ==self.n:
                return 'no'
n=list(map(int,(stdin.readline().strip().split())))
dic=hash(n)
for _ in range(n[0]):
    S =list(stdin.readline().strip().split())
    if S[0]=='insert':
        dic.insert(S[1])
    elif S[0]=='find':
        print(dic.search(S[1]))

Submission status: Accepted

Solution code:
n = int(input())
mydic = {}
for _ in range(n):
    s,t = input().split()
    if s == "insert":
        mydic[t] = 1
    else:
        if t in mydic.keys():
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())

l = set()

for _ in range(n):
    command, s = input().split()
    if command == "insert":
        l.add(s)
    else:
        if s in l:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
my_dict = {}

for i in range(n):
  order, key = input().split(' ')
  if order == 'insert':
    my_dict[key] = True
  elif order== 'find':
    if key in my_dict.keys():
      print('yes')
    else:
      print('no')

Submission status: Accepted

Solution code:
# Dictionary
from collections import defaultdict

N = int(input())
S = [(input().split()) for _ in range(N)]

d = defaultdict(bool)

for c, v in S:
    if c == 'insert':
        d[v] = True
    else:
        print('yes' if v in d else 'no')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ALDS1_4_C_Dictionary

def main():
    d = set()
    for l in open(0).readlines()[1:]:
        o, k = l.split()
        if o == "insert":
            d.add(k)
            continue
        if k in d:
            print("yes")
        else:
            print("no")

main()

Submission status: Accepted

Solution code:
DICT = {}
N = int(input())
for loop in range(N):
    com,str = input().split()
    if com == "insert":
        DICT[str] = True

    elif com == "find":
        if DICT.__contains__(str):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
b = 20000000
a = [None]*b
def getC(c):
    if c == "A": t = 1
    elif c == "C": t = 2
    elif c == "G": t = 3
    elif c == "T": t = 4
    return t
def getK(s):
  ret = 0
  for c in s:
    ret = ret*5 + getC(c)
  return ret
def hash1(key):
  return key % b
def hash2(key):
  return 1 + key % (b-1)
def find(key):
  #print(key,a)
  i = 0
  j = (hash1(key)+i*hash2(key))%b
  while a[j]:
    if a[j] == key:
      return True
    i += 1
    j = (hash1(key)+i*hash2(key))%b
  return False
def insert(key):
  i = 0
  j = (hash1(key)+i*hash2(key))%b
  while a[j]:
    i += 1
    j = (hash1(key)+i*hash2(key))%b
  if a[j] == None:
    a[j] = key
for i in range(n):
  q,s = sys.stdin.readline().split()
  if q[0]=="i":
    insert(getK(s))
  else:
    if find(getK(s)):
      print("yes")
    else:
      print("no")

Submission status: Accepted

Solution code:
N=int(input())
h_num=10000
L=[[] for x in range(h_num)]
def string_to_hash(S):
    S_num=0
    i=0
    for s in S:
        i+=1
        if s=='A':
            S_num+=1*i
        elif s=='C':
            S_num+=10*i
        elif s=='G':
            S_num+=100*i
        elif s=='T':
            S_num+=1000*i
    return(S_num%h_num)

for n in range(N):
    cmd , str_ = input().split()
    h=string_to_hash(str_)
    if cmd=='insert':
        L[h].append(str_)
    elif cmd== 'find':
        L_temp=L[h]
        if str_ in L_temp:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

m = 1046527

H = [None]*m

table = str.maketrans({
'A':'1',
'C':'2',
'G':'3',
'T':'4',
})

# 文字から数値に変換
# https://qiita.com/tag1216/items/df6c93bdb823dd48af6c参照
def getChar(string):
    return int(string.translate(table))

# pythonでは12桁でもメモリを考えず動くのでgetKeyを実装していません。

def h1(key):
    return key % m

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

def find(string):
    i = 0
    key = getChar(string)
    while True:
        h = (h1(key) + i*h2(key))%m
        if H[h] == string:
            return 1
        elif H[h] is None:
            return 0
        else:
            i += 1

def insert(string):
    i = 0
    key = getChar(string)
    while True:
        h = (h1(key) + i*h2(key))%m
        if H[h] is None:
            H[h] = string
            break
        else:
            i += 1

for _ in range(n):
    com, string = input().split()
    if com[0] == 'i':
        insert(string)
    else:
        if find(string):
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
class Dictonary:

    def __init__(self):
        self.d = set()

    def insert(self, s: str):
        if s not in self.d:
            self.d.add(s)

    def find(self, s: str):
        if s in self.d:
            print('yes')
        else:
            print('no')

d = Dictonary()
n = int(input())

for _ in range(n):
    cmd, s = input().split()
    if cmd == 'insert':
        d.insert(s)
    elif cmd == 'find':
        d.find(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix

DICT_SIZE = 1000003
REHASH = 10007
DICT = [None] * DICT_SIZE


def hash_value(S):
    M = 257
    val = 0
    for c in S:
        val = (val * M + ord(c)) % DICT_SIZE
    return val


def insert(s):
    h = hash_value(s)
    while DICT[h] is not None:
        if DICT[h] == s:
            return
        h = (h + REHASH) % DICT_SIZE
    DICT[h] = s


def find(s):
    h = hash_value(s)
    while True:
        if DICT[h] is None:
            return 'no'
        elif DICT[h] == s:
            return 'yes'
        h = (h + REHASH) % DICT_SIZE


if __name__ == "__main__":

    n = int(input())

    for _ in range(n):
        cmd, s = input().split()
        if cmd == 'insert':
            insert(s)
        else:
            print(find(s))

Submission status: Accepted

Solution code:
n = int(input())
lst = [input().split() for i in range(n)]
dict = {}
for op, s in lst:
    if op == 'insert':
        dict[s] = 1
    if op == 'find':
        try:
            if dict[s] == 1:
                print('yes')
        except:
            print('no')

Submission status: Accepted

Solution code:
M = 1046527

def charToKey(a):
    if a == "A":
        return 1
    elif a == "C":
        return 2
    elif a == "G":
        return 3
    elif a == "T":
        return 4
    else:
        return 0

def strToKey(s):
    sum = 0
    coef = 1
    for c in s:
        key = charToKey(c)
        sum += coef * key
        coef *= 5
    return sum

def hash1(key):
    return key % M

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

def insert(A, value):
    key = strToKey(value)
    for i in range(M):
        hash = (hash1(key) + i * hash2(key)) % M
        if A[hash] == value:
            return
        elif A[hash] is None:
            A[hash] = value
            return
    return

def find(A, value):
    key = strToKey(value)
    for i in range(M):
        hash = (hash1(key) + i * hash2(key)) % M
        if A[hash] == value:
            return True
        elif A[hash] is None:
            return False
    return False

if __name__ == "__main__":
    A = [None for i in range(M)]

    N = int(input())
    for i in range(N):
        command, value = input().split()
        if command == "insert":
            insert(A, value)
        else:
            if (find(A, value)):
                print("yes")
            else:
                print("no")

Submission status: Accepted

Solution code:
keys = set()
n = int(input())
for i in range(n):
    order, string = input().split()
    if order == "insert":
        keys.add(string)
    elif order == "find":
        if string in keys:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
def hash(v):
    return v % 100001

def insert(hashTable, value):
    key = hash(value)
    if hashTable[key] == None:
        hashTable[key] = [value]
    else:
        hashTable[key].append(value)

def find(hashTable, value):
    key = hash(value)
    if hashTable[key] == None:
        return False
    else:
        for val in hashTable[key]:
            if val == value:
                return True
    return False

def convert(string):
    res = ''
    for s in string:
        res += str(ord(s))
    return int(res)

n = int(input())
hashTable = [None] * 10**6
for i in range(n):
    com, val = input().split()
    val = convert(val)
    if com == 'insert':
        insert(hashTable, val)
    else:
        print('yes') if find(hashTable, val) else print('no')

Submission status: Accepted

Solution code:
n = int(input())
S = set()
for _ in range(n):
    op, arg = input().split()
    if op == "insert":
        S.add(arg)
    elif arg in S:
        print("yes")
    else:
        print("no")

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
res = []

for i in range(n):
    com = input().split()
    if com[0] == "insert":
        dic[com[1]] = i
    elif com[0] == "find":
        if com[1] in dic:
            res.append("yes")
        else:
            res.append("no")
            
for i in res:
    print(i)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
t = {}
for i in range(n):
    c, s = input().split()
    if c[0] == "i":
        t[s] = 0
    else:
        print('yes' if s in t else 'no')

Submission status: Accepted

Solution code:
n = int(input())
t = set()
for i in range(n):
    c, s = input().split()
    if c == "insert":
        t.add(s)
    elif s in t:
        print("yes")
    else:
        print("no")

Submission status: Accepted

Solution code:
N = int(input())

comm_list = [input().split() for _ in  range(N)]

dictionary = set()

for comm, v in comm_list:
    if comm == 'insert':
        dictionary.add(v)
    elif comm == 'find':
        if v in dictionary:
            print('yes')
        else:
            print('no')
    else:
        raise

Submission status: Accepted

Solution code:
dic={}
N=int(input())
for i in range(N):
    a,b=input().split()
    if a=="insert":
        dic[b]=1
    else:
        try:
            if dic[b]:
                print('yes')
        except:
            print('no')

Submission status: Accepted

Solution code:
class MyDict:
    def __init__(self, max):
        self.max = max
        self.pow = [1] * (self.max + 1)
        for i in range(1, self.max + 1):
            self.pow[i] = self.pow[i - 1] * 4
        self.d = [False] * (self.pow[-1])
        
    def __hash(self, val):
        l = len(val)
        h = -1
        for i in range(l):
            if val[i] == 'A':
                h += (1*self.pow[i])
            elif val[i] == 'C':
                h += (2*self.pow[i])
            elif val[i] == 'G':
                h += (3*self.pow[i])
            elif val[i] == 'T':
                h += (4*self.pow[i])
        return h
    
    def insert(self, x):
        key = self.__hash(x)
        self.d[key] = True
    
    def find(self, x):
        key = self.__hash(x)
        return self.d[key]
        

n = int(input())
dic = MyDict(12)

for _ in range(n):
    cmd, x = input().split()
    
    if cmd == 'insert':
        dic.insert(x)
    elif cmd == 'find':
        print('yes') if dic.find(x) else print('no')