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:
dic = {}
n = int(input())
for i in range(n):
	s = input()
	if s[0] == 'i': dic[s[7:]] = 1
	else: print("yes" if s[5:] in dic else "no")

Submission status: Accepted

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

n = int(input())

st = set()

for _ in range(n):
    command = input()
    if command[0] == "i":
        st.add(command[7:])
    else:
        if command[5:] in st:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
#hashing method
n=int(input())
dic=set()
for i in range(n):
    meirei,string=input().split()
    suuzi=string.replace("A","1").replace("C","2").replace("G","3").replace("T","4")
    num=int(suuzi)

    if meirei=="insert":
        dic.add(num)
    elif meirei=="find":
        if num in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
S = []
for _ in range(n):
    cmd, s = input().split()
    S.append((cmd, s))
    

D = {}
for cmd, s in S:
    if cmd == 'insert':
        D[s] = True
    if cmd == 'find':
        if s in D:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
# ALDS1_4_C
import sys
M = 1046527


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 getChar(gene):
    if gene == 'A':
        return 1
    elif gene == 'C':
        return 2
    elif gene == 'G':
        return 3
    else:
        return 4


def getkey(gene):
    sum = 0
    p = 1
    for i in gene:
        sum += p * getChar(i)
        p *= 5
    return sum


class HashDict:
    def __init__(self):
        self.key = [None] * (2 * 10 ** 6)

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

    def find(self, key):
        i = 0
        while True:
            j = h(key, i)
            # print('find j : {}'.format(j))
            if self.key[j] == key:
                return True
            elif self.key[j] is None or i > M:
                return None
            else:
                i += 1


n = int(input())
T = HashDict()

for i in range(n):
    command, key = sys.stdin.readline().strip().split()
    key = getkey(key)
    # print('i : {}  key : {}'.format(i, key))
    if command == 'insert':
        T.insert(key)
    elif command == 'find':
        if T.find(key):
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
dic={}
for i in range(int(input())):
    command,key=input().split()
    if command=="insert":
        dic[key]=True
    else:
        print("yes" if key in dic else "no")

Submission status: Accepted

Solution code:
def str2int(s):
    i=0
    for c in s:
        i*=5
        if c=='A':
            i+=1
        elif c=='C':
            i+=2
        elif c=='G':
            i+=3
        elif c=='T':
            i+=4
    return i

n=int(input())
l=set()
for i in range(n):
    S=list(input().split())
    k=str2int(S[1])
    if S[0]=='insert':
        l.add(k)
    else:
        print ('yes' if k in l else 'no')

Submission status: Accepted

Solution code:
dic = set()
for i in range(int(input())):
    command = input().split()
    if command[0] == 'insert': dic.add(command[1])
    else:
        if command[1] in dic: print('yes')
        else: print('no')

Submission status: Accepted

Solution code:
import sys
j={}
s=int(input())

for i in range(s):
  x,y=input().split()
  if x=='insert':
    j[y]=1
  elif x=='find':
    if y in j:
      print('yes')
    else:
      print('no')

Submission status: Accepted

Solution code:

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]==-1:
            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]==-1 or i>=m:
            return -1
        else:
            i+=1

def change(c):
    ans=""
    for i in range(len(c)):
        if c[i]=="A":
            ans+="1"
        if c[i]=="C":
            ans+="2"
        if c[i]=="G":
            ans+="3"
        if c[i]=="T":
            ans+="4"
    return int(ans)

m=1046527
n=int(input())
dict=[-1]*m
import sys
input=sys.stdin.readline
for _ in range(n):
    l=list(input().split())
    k=change(l[1])
    if l[0]=="insert":
        insert(dict,k)
    else:
        if search(dict,k)!=-1:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys

dic = {}

n = int(input())
for _ in range(n):
    c, k = input().split()
    if c[0] == "i":
        dic[k] = True
    else:
        if k in dic.keys():
            sys.stdout.write("yes\n")
        else:
            sys.stdout.write("no\n")

Submission status: Accepted

Solution code:
import sys
from collections import deque

def convert_a_to_i(char):

	if char == 'A':
		return 1

	elif char == 'C':
		return 2

	elif char == 'G':
		return 3

	else:
		return 4

def hash_calc(word):

	hash = 0
	p = 1
	for i in range(len(word)):

		hash += convert_a_to_i(word[i]) * p
		p *= 5

	return hash

def find(dictionary,word):

	if dictionary[hash_calc(word)-1] == 1:
		return True
	else:
		return False

def insert(dictionary,word):

	dictionary[hash_calc(word)-1] = 1

def test():

	n = int(sys.stdin.readline())

	dictionary = [0] * (4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4)


	for i in range(n):

		operation = list(sys.stdin.readline().split())

		if operation[0] == 'insert':

			insert(dictionary,operation[1])
		else:

			result = find(dictionary,operation[1])
			if result == True:
				print("yes")
#				with open("out.txt",mode='a') as f:
#					f.write("yes " + operation[1] + "\n")
			else:
				print("no")
#				with open("out.txt",mode='a') as f:
#					f.write("no " + operation[1] + "\n")


if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
import sys

n = int(input())
dict = {}

for i in sys.stdin:
    if i[0] == 'i':
        dict[i[7:]] = 0
    else:
        print('yes' if i[5:] in dict else 'no')

Submission status: Accepted

Solution code:
n = int(input())

dictionary = dict()

for _ in range(n):
    command, value = input().split()
    if command == "insert":
        dictionary[value] = 1
    else:
        if value in dictionary:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())

d = {}
for i in range(n):
    q, t = input().split()
    if q == "insert":
        d[t] = 1
    if q == "find":
        if t in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys

def conv(s):
    patterns = [["A", "1"], ["C", "2"], ["G", "3"], ["T", "4"]]
    for i, j in patterns:
        s = s.replace(i, j)
    return int(s)

MAX_PAT = pow(4,12)

def h1(val):
    return val % MAX_PAT
    
def h2(val):
    return 1 + val % (MAX_PAT-1)

def h(val, i):
    return (h1(val) + i*h2(val)) % MAX_PAT

def insert(val, arr):
    i = 0
    while True:
        idx = h(val, i)
        if arr[idx] == "NIL":
            arr[idx] = val
            return idx
        else:
            i += 1

def find(val, arr):
    i = 0
    while True:
        idx = h(val, i)
        if arr[idx] == val:
            return True
        elif (arr[idx]=="NIL")|(i>=MAX_PAT):
            return False
        else:
            i += 1
    return

dictionary = ["NIL" for i in range(MAX_PAT)]
n = int(input())
for i in range(n):
    cmd, val = sys.stdin.readline().split()
#    cmd, val = input().split()
    val = conv(val)
    if cmd == "insert":
        if not find(val, dictionary):
            insert(val, dictionary)
    if cmd == "find":
        if find(val, dictionary):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys
from sys import stdin
input = stdin.readline
 
dic = {}
n = int(input())
for i in range(n):
    s = input()
    if s[0] == 'i': dic[s[7:]] = 1
    else: print("yes" if s[5:] in dic else "no")

Submission status: Accepted

Solution code:
d={}
for _ in range(int(input())):
    a,b=input().split()
    if a=='find':
        if b in d:print('yes')
        else:print('no')
    else:d[b]=0

Submission status: Accepted

Solution code:
n = int(input())

d = dict()

for i in range(n):
  p, s = input().split()
  if p == "insert":
    d[s] = d.get(s, 0) + 1
  elif p == "find":
    if s in d:
      print("yes")
    else:
      print("no")

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    dic = {}
    for _ in range(n):
        command = input().split(" ")
        value = command[1]
        if command[0] == 'insert':
            if value not in dic:
                dic[value] = 0
        elif command[0] == 'find':
            if value in dic:
                print('yes')
            else:
                print('no')
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  dic = {}
  for _ in range(N):
    command, s = input().split()
    if command == 'insert':
      dic[s] = 1
    elif command == 'find':
      print('yes' if s in dic else 'no')
      
solve()

Submission status: Accepted

Solution code:
n = int(input())
C = []
for i in range(n):
    cmd, str = input().split()
    C.append([cmd, str])

def Dictionary(C):
    D = {}
    for i in range(n):
        if C[i][0] == 'insert':
            D[C[i][1]] = i
        else:
            if C[i][1] in D: #辞書型だと検索が高速
                print("yes")
            else:
                print("no")
Dictionary(C)

Submission status: Accepted

Solution code:
#! python3
# dictionary.py - 簡易辞書をつくる

n = int(input())

strings = set()
for i in range(n):
    order, string = input().split()
    # print(order, string)
    if order == 'insert':
        strings.add(string)
    else:
        if string in strings:
          print('yes')
        else :
          print('no')

Submission status: Accepted

Solution code:
import sys

class HashTable:
    def __init__(self, size):
        self.size = size
        self.table = [None for _ in range(size)]

    def get_char(self, ch):
        if ch == 'A':
            return 1
        elif ch == 'C':
            return 2
        elif ch == 'G':
            return 3
        elif ch == 'T':
            return 4

    def get_key(self, string):
        sum = 0
        p = 1
        for s in string:
            sum += self.get_char(s) * p
            p *= 5
        return sum

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

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

    def insert(self, string):
        key = self.get_key(string)
        i = 0
        while True:
            h = (self.hash1(key) + i * self.hash2(key)) % self.size
            if self.table[h] is None:
                self.table[h] = string
                return
            elif self.table[h] == string:
                return
            i += 1

    def find(self, string):
        key = self.get_key(string)
        i = 0
        while True:
            h = (self.hash1(key) + i * self.hash2(key)) % self.size
            if self.table[h] == string:
                return True
            elif self.table[h] is None:
                return False
            i += 1

h = HashTable(1046527)
n = int(input())
for _ in range(n):
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'insert':
        h.insert(cmd[1])
    elif cmd[0] == 'find':
        if h.find(cmd[1]):
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
from collections import deque
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
DICTIONARY = {}
num_query = int(input())
 
for loop in range(num_query):
    input_str = input().split()
    if input_str[0] == 'insert':
        DICTIONARY[input_str[1]] = True
    else:
        if DICTIONARY.__contains__(input_str[1]):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:

PRIME = 1000231


def main():
    n = int(input())
    d = MyDict()
    for _ in range(n):
        command, v = input().split(' ')
        if command == 'insert':
            d.add(v)
        else:
            if d.find(v):
                print('yes')
            else:
                print('no')




class MyDict:

    def __init__(self, n=PRIME):
        self.n = n
        self.store = [None]*n

    def add(self, v):
        key = self._hash(v)
        while self.store[key] is not None:
            key += 1
        self.store[key] = v

    def find(self, v):
        key = self._hash(v)
        while self.store[key] is not None and self.store[key] != v:
            key += 1
        return self.store[key]

    def _hash(self, v):
        return hash(v) % self.n


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    inst_num = int(input())
    dictionary = {}

    for _ in range(inst_num):
        operation, value = input().split()
        if "insert" == operation:
            dictionary[value] = 1
        elif "find" == operation:
            if dictionary.get(value):
                print("yes")
            else:
                print("no")
        else:
            pass

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n = int(input())
	d = {}
	for i in range(n):
		a,s = map(str,input().split())
		if a == "insert":
			d[s] = 1
		elif a == "find":
			if s in d:
				print("yes")
			else:
				print("no")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())

    result = []
    dict_ = {}
    for i in range(n):
        temp = input().split()

        if temp[0][0] == 'i':
            dict_[temp[1]] = True
        else:
            if temp[1] in dict_:
                result.append('yes')
            else:
                result.append('no')
    print('\n'.join(result))

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from collections import deque


mod = 1000000007

if __name__ == "__main__":
    d={}
    n = int(sys.stdin.readline())
    for i in range(n):
        l= list(sys.stdin.readline().split())
        cmd = l[0]
        if len(l)==2:
            text = l[1]
        if cmd == "insert":
            d[text]=1
        elif cmd == "find":
            if text in d:
                print("yes")
            else:
                print("no")

# import sys
# n = int(sys.stdin.readline())
# d = {}
# for i in range(n):
#     line = sys.stdin.readline().split()
#     cmd = line[0]
#     if len(line) == 2:
#         value = line[1]
#     if cmd == "insert":
#         d[value] = 1
#     elif cmd == "find":
#         if value in d:
#             print("yes")
#         else:
#             print("no")

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
dic = set()
for i in range(N):
    op, string = stdin.readline().rstrip().split()
    if op == 'insert':
        dic.add(string)
    elif op == 'find':
        if string in dic:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
M = 1046527  # prime number
A = [-1 for i in range(M)]


def str2int(s):
    cnt = 0
    for i in range(len(s)):
        if s[i] == 'A':
            cnt += 1
        elif s[i] == 'T':
            cnt += 2
        elif s[i] == 'C':
            cnt += 3
        elif s[i] == 'G':
            cnt += 4
        cnt *= 4
    return cnt


def h1(k):
    return k % M


def h2(k):
    return 1 + k % (M - 1)


def h(k, i):
    return (h1(k) + h2(k) * i) % M


def insert(w):
    k = str2int(w)
    i = 0
    while i < M:
        j = h(k, i)
        if A[j] == -1:
            A[j] = w
            break
        i += 1


def find(w):
    k = str2int(w)
    i = 0
    while i < M:
        j = h(k, i)
        if A[j] == -1:
            break
        if A[j] == w:
            return True
        i += 1
    return False


if __name__ == '__main__':
    n = int(raw_input())
    for i in range(n):
        cmd, s = raw_input().split()
        if cmd == "insert":
            insert(s)
        elif cmd == "find":
            if find(s):
                print "yes"
            else:
                print "no"
        else:
            pass

Submission status: Accepted

Solution code:
d={}
n=int(input())
for i in range(n):
    com,gen=input().split(" ")
    if com=="insert":
        d[gen]=d.get(gen,0)+1
    if com=="find":
        if gen in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
def insert(st):
    if st[0]=="A":
        return 0
    elif st[0]=="C":
        return 1
    elif st[0]=="G":
        return 2
    else:
        return 3
 
def finder(li,st):
    serach=insert(st)
    return "yes" if st in li[serach] else "no"
 
n=int(input())
dic=[set() for _ in range(4)]
for i in range(n):
    s,c=input().split()
    if s[0]=="i":
        dic[insert(c)].add(c)
    else:
        print(finder(dic,c))

Submission status: Accepted

Solution code:
class c:
    def __init__(self):
        self.d = {}

    def insert(self,s):
        self.d[s] = 1

    def find(self,s):
        try:
            if self.d[s]:
                print('yes')
        except KeyError:
            print('no')


n = int(input())
d = c()
for i in range(n):
    s,k = input().split()
    if s == 'insert':
        d.insert(k)
    else:
        d.find(k)

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

d=set()
for _ in range(int(input())):
    a,b=input().split()
    if a == 'find':
        if b in d:
            print('yes')
        else:
            print('no')
    else:
        d.add(b)

Submission status: Accepted

Solution code:
"""
辞書
"""
n = int(input())
s = set()
for _ in range(n):
    com,string = input().split()
    if com == "insert":
        s.add(string)
    elif com == "find":
        flg = string in s
        if flg:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
data=set()
ans=deque()
for i in range(n):
    command=input().split()
    if command[0]=="insert":
        data.add(command[1])
    else:
        ans.append("yneos"[1-(command[1] in data)::2])


for i in range(len(ans)):
    print(ans.popleft())

Submission status: Accepted

Solution code:
#他の人の見てみた結果
#これでfindごとに全探索回避できるのだろうか？
n=int(input())
D=set()
for i in range(n):
    order,str=input().split( )
    if order == "insert":
        D.add(str)
    else:
        if str in D:
            print("yes")
        else:
            print("no")

Submission status: Accepted

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

for i in range(n):
    command=list(map(str,input().split()))
    if command[0]=='insert':
        dictionary[command[1]]=True
    else:
        if command[1] in dictionary:
            print('yes')
        else:
            print('no')

Submission status: Accepted

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

for i in range(n):
    order, str = input().split()
    if order == 'insert':
        str_set.add(str)
    elif order == 'find':
        if str in str_set:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    d = set()
    for i in range(n):
        c, w = input().split()
        if c == "insert":
            d.add(w)
        else:
            if w in d:
                print("yes")
            else:
                print("no")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

dict_ACGT = {}

for _ in range(n):

    command, string = input().split()
    
    if   command == "insert":
        # insert str
        dict_ACGT[string] = ""
    elif command == "find":
        # find str
        if string in dict_ACGT:
            print("yes")
        else:
            print("no")
    else:
        raise

Submission status: Accepted

Solution code:
def solve():
     n = int(input())
     dic = set()
     for i in range(n):
          a = input().split()
          if a[0] == "insert":
               dic.add(a[1])
          if a[0] == "find":
               if a[1] in dic:
                    print("yes")
               else:
                    print("no")
solve()

Submission status: Accepted

Solution code:
n = int(input())

s = set()

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

Submission status: Accepted

Solution code:
n = int(input())
a = [list(input().split()) for _ in range(n)]

strs = set()

for c, s in a:
    if c == "insert":
        strs.add(s)
    elif c == "find":
        if s in strs:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
dic = set()
n = int(input())
for _ in range(n):
    order = input().split()
    if order[0] == "insert":
        dic.add(order[1])
    elif order[0] == "find":
        if order[1] in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

table = {}

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

Submission status: Accepted

Solution code:
n = int(input())
dict = set()
tmp = set()
for _ in range(n):
  data = list(map(str,input().split()))
  if(data[0][0] == "i"):
    dict.add(data[1])
  elif(data[0][0] == "f"):
    tmp.add(data[1])
    print("yes" if len(dict&tmp) != 0 else "no")
    tmp.clear()

Submission status: Accepted

Solution code:
n = int(input())
M = 1046527
table = [""]*M
def getKey(str):
    sum = 0
    p = 1
    for i in range(len(str)):
        if str[i] == "A":
            num = 4
        elif str[i] == "T":
            num = 3
        elif str[i] == "G":
            num = 2
        else:
            num = 1
        sum += p*num
        p *= 5
    return sum

for ni in range(n):
    instruction = input().split()
    if instruction[0][0] == "i":
        key = getKey(instruction[1])
        h = key%M
        i = 0
        while table[h] != "" and table[h] != instruction[1]:
             i += 1
             h = (key%M + i *(1 + key%(M-1)) )%M
        table[h] = instruction[1]
    elif instruction[0][0] == "f":
        key = getKey(instruction[1])
        h = key%M
        i = 0
        while table[h] != "" and table[h] != instruction[1]:
             i += 1
             h = (key%M + i *(1 + key%(M-1)) )%M
        if table[h] == instruction[1]:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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:
import sys
input = sys.stdin.readline

class Dict:
  def __init__(self, size):
    self.table = [None] * 1046527
    self.table_size = 1046527

  def insert(self, val):
    key = self.get_key(val)
    collision = 0
    while True:
      h = self.generate_hash(key, collision)
      if self.table[h] is None:
        self.table[h] = val
        break
      elif self.table[h] == val:
        break
      collision += 1
  def find(self, val):
    key = self.get_key(val)
    collision = 0
    while True:
      h = self.generate_hash(key, collision)
      if self.table[h] == val: return 1
      elif self.table[h] is None: return 0
      collision += 1

  def get_key(self, val):
    sum, P = 0, 1
    for i in range(len(val)):
      sum += P * self.get_char(val[i])
      P *= 5
    return sum

  def get_char(self, ch):
    if ch == 'A': return 1
    elif ch =='C': return 2
    elif ch =='G': return 3
    elif ch =='T': return 4
    else: return 0

  def generate_hash(self, key, collision):
    h1 = key % self.table_size
    h2 = 1 + key % (self.table_size - 1)
    return (h1 + collision * h2) % self.table_size

def _main():
  N = int(input())
  d = Dict(N)
  commands = [input().split() for _ in range(N)]

  for i in range(N):
    if commands[i][0] == 'insert':
      d.insert(commands[i][1])
    else:
      ans = 'yes' if d.find(commands[i][1]) else 'no'
      print(ans)



if __name__ == '__main__':
  _main()

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
dic = defaultdict(int)

for _ in range(n):
  c, v = input().split()
  if c == 'insert':
    dic[v] = 1
  else:
    if dic[v] == 1:
      print('yes')
    else:
      print('no')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
from sys import stdin

num = int(input())

dict = {}
for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "insert":
		dict[cmd[1]] = 1
	elif cmd[0] == "find":
		if cmd[1] in dict:
			print("yes")
		else:
			print("no")

Submission status: Accepted

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

for i in range(n):
  ord, char = input().split()
  if ord == 'insert':
    dict.add(char)
  elif ord == 'find':
    if char in dict:
      print('yes')
    else:
      print('no')

Submission status: Accepted

Solution code:
from collections import*
l=defaultdict(int)
for i in range(int(input())):
    a,b=input().split()
    if a=="insert":
        l[b]=1
    else:
        print(["no","yes"][l[b]==1])

Submission status: Accepted

Solution code:
n = int(input())
dic = set()
for i in range(n):
    com, x = map(str, input().split())
    if com == 'insert':
        dic.add(x)
    elif com == 'find':
        if x in dic:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
class Dictionary:
    def __init__(self, data={}):
        self.data = data
    def insert(self, x):
        self.data[x] = 0
    def find(self, x):
        if x in self.data:
            return 'yes'
        else:
            return 'no'
n = int(input())
d = Dictionary()
s = [list(input().split()) for i in range(n)]
for i in s:
    if i[0] == 'insert':
        d.insert(i[1])
    else:
        print(d.find(i[1]))

Submission status: Accepted

Solution code:
n = int(input())

l = set()
o = ''
for _ in range(n):
    c = input().split()
    if c[0] == 'insert':
        l.add(c[1])
    elif c[0] == 'find':
        o += ('yes' if c[1] in l else 'no') + "\n"

print(o, end='')

Submission status: Accepted

Solution code:
num = int(input())
dictionary = {}
for i in range(num):
    com, key = tuple(input().split(' '))
    if com == 'insert':
        dictionary[key] = dictionary.get(key, 0) + 1
    if com == 'find':
        if dictionary.get(key):
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n = int(input())
h = {}
for i in range(n):
    op, s = input().split()
    if op == "insert":
        h[s] = True
    else:
        if s in h:
            print("yes")
        else:
            print("no")