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:
n=int(input())
dic=set()
for i in range(n):
    a,b=input().split()
    if a=="insert":
        dic.add(b)
    else:
        if b in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
# coding: utf-8
import bisect
n = int(input().rstrip())
dic = {}
for i in range(n):
    line = input().rstrip().split()
    if line[0] == "insert":
        dic[line[1]] = True
    else:
        if line[1] in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(n):
    buff = input().split()
    if buff[0][0] == "i":
        s.add(buff[1])
    else:
        if buff[1] in s:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys
d=set();input()
for c in sys.stdin:
 if"i"==c[0]:d.add(c.split()[1])
 else:print(["no","yes"][c.split()[1]in d])

Submission status: Accepted

Solution code:
num = int(input())
dict = {}

for i in range(num):
        strList = input().split()
        if strList[0] == "insert":
                dict[strList[1]] = 1
        elif strList[0] == "find":
                if strList[1] in dict:
                        print("yes")
                else:
                        print("no")

Submission status: Accepted

Solution code:
n = int(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")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

class Dict:
    def __init__(self):
        self.table = [None] * 1046527
        self.table_size = 1046527
    
    def insert(self, key):
        colisions = 0
        while True:
            hash_num = self._calc_hash(self._to_num(key), colisions)
            cand = self.table[hash_num]
            if cand is None:
                self.table[hash_num] = key
                return 0
            elif cand == key:
                return 1
            colisions += 1
    
    def has(self, key):
        colisions = 0
        while True:
            hash_num = self._calc_hash(self._to_num(key), colisions)
            cand = self.table[hash_num]
            if cand == key:
                return True
            elif cand is None or colisions >= self.table_size:
                return False
            else:
                colisions += 1
        return 
    
    def _calc_hash(self, key, colisions):
        hash_1 = key % self.table_size
        hash_2 = 1 + (key % (self.table_size - 1))
        return (hash_1 + colisions * hash_2) % self.table_size
    
    def _to_num(self, str_key):
        sum = 0
        p = 1
        for char in str_key:
            if char == 'A':
                sum += 1 * p
            elif char == 'C':
                sum += 2 * p
            elif char == 'G':
                sum += 3 * p
            elif char == 'T':
                sum += 4 * p
            p *= 5
        return sum

def main_():
    N = int(input())
    commands = [(cmd[0], cmd[1]) for cmd in [input().split() for _ in range(N)]]
    hash_map = Dict()
    for cmd in commands:
        if cmd[0] == 'insert':
            hash_map.insert(cmd[1])
        else:
            ans = 'yes' if hash_map.has(cmd[1]) else 'no'
            print(ans)
            

if __name__ == "__main__":
    main_()

Submission status: Accepted

Solution code:
import sys
def m():
 d=set();input()
 for i in sys.stdin:
  if"i"==i[0]:d.add(i[7:])
  else:print('yes'if i[5:]in d else'no')
if'__main__'==__name__:m()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
dic = {}
for _ in range(n):
    ope = stdin.readline().rstrip().split()
    if ope[0] == "insert":
        dic[ope[1]] = True
    elif ope[0] == "find":
        if dic.get(ope[1], False):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N = int(input())
# S = str(input())
# T = str(input())
# a,b,c = [int(n) for n in input().split()]
S = [0]*N
s = set()
for i in range(N):
    S[i] = str(input())
for i in range(N):
    if(S[i][0] == "i"):
        s.add(S[i][7:])
    elif(S[i][0] == "f"):
        if(S[i][5:] in s):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
def v2i(v):
        v = list(v)
        n = 0
        for i,c in enumerate(v):
            if c == 'A':
                n += 0 + 4 * i
            elif c == 'C':
                n += 1 + 4 * i
            elif c == 'G':
                n += 2 + 4 * i
            elif c == 'T':
                n += 3 + 4 * i
            n *= 4
        n /= 4
        return int(n)



class Dict():

    def __init__(self):
        self.tree = [False] * 4**12

    def find(self,key):
        if self.tree[key] == True:
            print("yes")
        else:
            print("no")
    
    def insert(self,key):
        self.tree[key] = True

    
N = int(input())
D = Dict()
for i in range(N):
    Q,V = input().split()
    if Q == "insert":
        D.insert(v2i(V))
    else:
        D.find(v2i(V))
    #print(D.tree[:60])

Submission status: Accepted

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

class HashTable(list):
    def __init__(self, length):
        list.__init__(self)
        self.length = length
        self[:] = [None] * length

    def h(self, key, i):
        h1 = key % self.length
        h2 = 1 + (key % (self.length - 1))
        return (h1 + i*h2) % self.length

    def insert(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i) # slow...
            if self[j] is None:
                self[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i) # slow...
            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), 5)

if __name__ == '__main__':

    n = int(input())
    T = HashTable(1046527)
    C = [input().split(" ") for i in range(n)]
    
    for command, char in C:
        num = getNum(char)
        if command[0] == "i":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")

Submission status: Accepted

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

Submission status: Accepted

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

"""
辞書
"""

d = {}
N = int(input())
for i in range(N):
    com, s = input().split()
    if com == 'insert':
        d[s] = True
    elif com == 'find':
        if d.get(s):
            print('yes')
        else:
            print('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:
        if val in d:
            print('yes')
        else:
            print('no')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

TABLE_SIZE = 1000000
table = [None] * TABLE_SIZE


def insert(value):
    index = hash(value) % TABLE_SIZE
    values = table[index]
    if not values:
        values = table[index] = []
    values.append(value)


def find(value):
    index = hash(value) % TABLE_SIZE
    values = table[index]
    if not values:
        return False
    return value in values


n = int(sys.stdin.readline())
for _ in range(n):
    command, value = sys.stdin.readline().split()
    if command == 'insert':
        insert(value)
    else:
        print('yes' if find(value) else 'no')

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp
#  Binary Search : python3
#  2018.12.08 yonezawa


#from collections import deque
#import sys
#input = sys.stdin.readline
#import cProfile

def main():
    dic = {}
    for i in range(int(input())):
        l = list(map(str,input().split()))
        if l[0] == 'insert':
            dic[l[1]] = 'yes'
        else:
            try:
                print (dic[l[1]] )
            except:
                print ('no')
if __name__ == '__main__':
   main()
#    pr = cProfile.Profile()
#    pr.runcall(main)
#    pr.print_stats()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n = int(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")

Submission status: Accepted

Solution code:
# coding: utf-8


class Dictionary(object):

    def __init__(self, m):
        self.T = [None] * m
        self.m = m

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

    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if not self.T[j]:
                self.T[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.T[j] == key:
                return j
            elif not self.T[j] or i >= self.m:
                return 'Not Found'
            else:
                i += 1


if __name__ == "__main__":
    # n = 6
    # orders = [
    #     ('insert', 'AAA'),
    #     ('insert', 'AAC'),
    #     ('find', 'AAA'),
    #     ('find', 'CCC'),
    #     ('insert', 'CCC'),
    #     ('find', 'CCC')
    # ]
    n = int(input())
    orders = []
    for _ in range(n):
        order, chars = input().strip().split()
        orders.append((order, chars))

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

    # def get_char_key(chars):
    #     p = 1
    #     key = 0
    #     for c in chars:
    #         key += p * get_char(c)
    #         p *= 5
    #     return key

    # dictionary = Dictionary(m=10000000)
    # for o in orders:
    #     order, chars = o
    #     key = get_char_key(chars)
    #     if order == 'insert':
    #         dictionary.insert(key)
    #     elif order == 'find':
    #         result = dictionary.search(key)
    #         if result == 'Not Found':
    #             print('no')
    #         else:
    #             print('yes')

    dictionary = {}
    for o in orders:
        order, chars = o
        if order == 'insert':
            dictionary[chars] = 0
        elif order == 'find':
            if chars in dictionary:
                print('yes')
            else:
                print('no')

Submission status: Accepted

Solution code:
#Dictionary
import collections
N = int(input().strip())
q = collections.deque()
for i in range(N):
    order = input().strip().split(" ")
    q.append(order)
dct = set()
while len(q):
    order = q.popleft()
    if order[0] == 'insert':
        newword = order.pop()
        dct.add(newword)
    else:
        word = order.pop()
        if word in dct:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_C


"""
s in [list]:
-> linear search O(n)
-> TLE
"""


def solve():
    mydict = {}
    n = int(input())
    for _ in range(n):
        ope, s = map(str, input().split())
        if ope == 'insert':
            mydict[s] = True
        elif ope == 'find':
            if s in mydict:
                print('yes')
            else:
                print('no')


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(n):
    order, value = input().split()
    if order == "insert":
        dic[value] = 1
    elif order == "find":
        if value in dic:
            print("yes")
        else:
            print("no")
    else:
        print("invalid order")

Submission status: Accepted

Solution code:
# input
n=int(input())
dict=set()
for i in range(n):
    ope, key=input().split()
    if ope == "insert":
        dict.add(key)
    elif ope == "find":
        print("yes" if key in dict else "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:
n = int(input())
dic = {}
ans_list = []

for i in range(n):
    cmd,num = input().split()
    if   cmd == 'insert':
        dic[num] = i
    elif cmd == 'find':
        if dic.__contains__(num):
            ans_list.append('yes')
        else:
            ans_list.append('no')

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
dic={}
for x in range(n):
    s=list(map(str,input().split()))
    if(s[0]=="insert"):
        dic[s[1]]=True
    elif(s[0]=="find"):
       if(dic.get(s[1])==True):
           print("yes")
       else:
        print("no")

Submission status: Accepted

Solution code:
m = 1046527
H = [""] * m


def str_to_nume(word):
    ans = ""
    for _ in word:
        if _ == "A":
            ans += ("1")
        elif _ == "C":
            ans += ("2")
        elif _ == "G":
            ans += ("3")
        elif _ == "T":
            ans += ("4")
    return ans


def convert_type(word):
    # print("word", word)
    # print("value", int(str_to_nume(word)))
    return int(str_to_nume(word))


def hash1(key):
    return key % m


def hash2(key):
    '''hash1で衝突したとき用
    '''
    return 1 + key % (m-1)


def find(str_key):
    key = convert_type(str_key)
    for i in range(m):
        h = (hash1(key) + i * hash2(key)) % m
        if H[h] == str_key:
            return 1
        elif len(H[h]) == 0:
            return 0
    return 0


def insert(str_key):
    key = convert_type(str_key)
    for i in range(m):
        h = (hash1(key) + i * hash2(key)) % m
        if H[h] == str_key:
            return 1
        elif len(H[h]) == 0:
            H[h] = str_key
            return 0
    return 0


sols = []
n = int(input())
# print("hoge")
for i in range(n):
    col = input().split()
    if col[0] == "insert":
        insert(col[1])
    else:
        if find(col[1]) == 1:
            sols.append("yes")
        else:
            sols.append("no")
for _ in sols:
    print(_)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
int_num=int(input())
ans_list = {}
for i in range(int_num):
    input_list=list(map(str,input().split()))
    if input_list[0] == 'insert':
        ans_list[(input_list[1])] = True
    else:
        if (input_list[1]) in ans_list.keys():
            print('yes')
        else:
            print('no')

Submission status: Accepted

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

    dic = {}

    for _ in range(n):
        cmd, key = input().split(' ')

        if 'insert' == cmd:
            dic[key] = key

        if 'find' == cmd:
            if key in dic:
                print('yes')
            else:
                print('no')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dic = {}
n = int(input())
for _ in range(n):
    line = input()
    if line[0] == 'i':
        dic[line[7:]] = 1
    else:
        print('yes') if line[5:] in dic else print('no')

Submission status: Accepted

Solution code:
n = int(input())
list_prob = []
dict_prob = {}
for i in range(0,n):
    list_prob.append(list((map(str, input().split()))))
for i in range(0,n):
    if list_prob[i][0] == "insert":
        dict_prob[list_prob[i][1]] = 1
    else:
        try:
            dict_prob[list_prob[i][1]]
            print("yes")
        except KeyError:
            print("no")

Submission status: Accepted

Solution code:
#130
#ALDS1_4_C
n=int(input())
a=set()

for i in range(n):
    c,s=input().split()
    if c == 'insert':
        a.add(s)
    else:
        if s in a:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    h = set()
    _ = int(input())
    for l in stdin:
        cmd, param = l.split()
        if cmd == "insert":
            h.add(param)
        elif param in h:
            print("yes")
        else:
            print("no")


main()

Submission status: Accepted

Solution code:
from sys import stdin

a = {}

n = int(input())

for _ in range(n):
    com, n = stdin.readline().strip().split()
    if com == 'insert':
        a[n] = 1
    else:
        print('yes') if n in a else print('no')

Submission status: Accepted

Solution code:
import sys
import collections

# Set max recursion limit
sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]


def main():
    N = int(input())
    C = [input().split() for _ in range(N)]

    D = collections.defaultdict(lambda: 0)

    for c in C:
        command, value = c

        if command == "insert":
            D[value] = 1
        else:
            if D[value] == 1:
                print("yes")
            else:
                print("no")


main()

Submission status: Accepted

Solution code:
import hashlib
from sys import stdin

def insert(v, B):
    key = hashlib.md5(v.encode("utf-8")).hexdigest()
    B[key] = v

def search(v, B):
    key = hashlib.md5(v.encode("utf-8")).hexdigest()
    if key in B:
        return key
    else:
        return 0

def read_and_print_word_dict(n):
    B = {}
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            insert(cmd[1], B)
        elif cmd[0] == 'find':
            res = search(cmd[1], B)
            if res == 0:
                print("no")
            else:
                print("yes")

n = int(input())
read_and_print_word_dict(n)

Submission status: Accepted

Solution code:
def hashSearch(n):
    l = {}
    res = []
    for x in range(n):
        order = input().split()
        if order[0] == 'insert':
            l[order[1]] = x
        elif order[0] == 'find':
            if order[1] in l:
                res.append('yes')
            else:
                res.append('no')
    print('\n'.join(res))


if __name__ == '__main__':
    N = int(input())
    hashSearch(N)

Submission status: Accepted

Solution code:
import sys

#f = open("input.txt", 'r')
f = sys.stdin
n = ''
d = set()
f.readline()

for line in f:
    cmdarr = line.split()
    if cmdarr[0] == "insert":
        d.add(cmdarr[1])
    else:
        if cmdarr[1] in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

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

Submission status: Accepted

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

data = {}
for v in cmd:
    if v[0][0] == 'i':
        data[v[1]] = True
    else:
        if v[1] in data:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n = int(input())
dic = set()
 
for _ in range(n):
    cmd, value = input().split()
    if cmd == "insert":
        dic.add(value)
    elif cmd == "find":
        if value in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n=int(input())

l=[]
s={}
for i in range(n):
    c,m=input().split()
    if c=='insert':
        s[m]=0
    elif c=='find':
        if m in s:
            l.append('yes')
        else:
            l.append('no')
print(*l,sep='\n')

Submission status: Accepted

Solution code:
import sys
d={}
input()
for i in sys.stdin:
    if i[0] == "i":
        d[i[7:]]=0
    else:
        if i[5:] in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(raw_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 = raw_input().split()
    key = 0
    if command == 'insert':
         dict[word] = 1
    elif command == 'find':
        if word in dict: 
            print 'yes'
        else:
            print 'no'

Submission status: Accepted

Solution code:
def insert(string, hash_list):
    hali = hash_list
    if string not in hali:
        hali[string] = 1
    return hali
 
 
def find(string, hash_list):
    hali = hash_list
    return string in hali
 
 
 
n = int(input())
words = {}
operate = [list(input().split()) for i in range(n)]
 
for i in operate:
    if i[0] == "insert":
        insert(i[1], words)
    elif i[0] == "find":
        if find(i[1], words):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(bool)
for i in range(n):
  q, s = input().split()
  if q=="insert":
    d[s] = True
  elif q=="find":
    if d[s]:
      print("yes")
    else:
      print("no")

Submission status: Accepted

Solution code:
n = int(input())
h = {}
for _ in range(n):
    cmd,val=input().split(' ')
    if cmd == "insert":
      h[val] = 1
    else:
        if  val in h:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
# coding: utf-8
dic=set({})
for i in range(int(input())):
    a,b=input().split()
    if a=='insert':
        dic.add(b)
    else:
        print('yes' if b in dic else 'no')

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for _ in range(n):
	op,gn = input().split()
	if op == 'insert':
		dic[gn] = 1
	elif op == 'find':
		if gn in dic:
			print('yes')
		else:
			print('no')

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for i in range(N)]

D = {}
for row in A:
    order, key = row.split()
    if order[0] == "i":
        D[value] = 1
    else:
        if key in D.keys():
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = []

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

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


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


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = []
N = int(input())
A = [input() for i in range(N)]
M = N * 10
T = [0 for i in range(M)]

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

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


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


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")
def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


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


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))

def exhastive_search(target, head, sum):
    for i in range(head, N):
        sum += A[i]
        print(sum)
        if target == sum:
            return True
        elif target > sum:
            if exhastive_search(target, i+1, sum):
                return True
            sum -= A[i]
        else:
            sum -= A[i]
    return False


for target in M:
    sum = 0
    result = "no"
    for i in range(N):
        if exhastive_search(target, i, sum):
            result = "yes"
            break
    print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
s = {}
for i in range(n):
    order = list(map(str, input().split()))
    if (order[0][0] == 'i'):
        s.add(order[1])
    else:
        if order[1] in s:
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}
for i in range(n):
    x = input()
    if 'insert' in x:
        dic.append(x.strip('insert '))
    else :
        if x.strip('find ') in dic:
            print('yes')
        else :
            print('no')

Submission status: Runtime Error

Solution code:
n = int(input())
dic = ()
for i in range(n):
    x = input()
    if 'insert' in x:
        dic.append(x.strip('insert '))
    else :
        if x.strip('find ') in dic:
            print('yes')
        else :
            print('no')

Submission status: Runtime Error

Solution code:
n = int(input())
dic = ()
for i in range(n):
    x = input()
    if 'insert' in x:
        dic.add(x.strip('insert '))
    else :
        if x.strip('find ') in dic:
            print('yes')
        else :
            print('no')

Submission status: Runtime Error

Solution code:
<?php
$length = (int)trim(fgets(STDIN));
$dictionary=array();


for($i=0; $i<$length; ++$i){
    list($action,$str) = explode(' ',trim(fgets(STDIN)));
    if($action=="insert"){
        $dictionary[] = $str;
    }
    if($action=="find"){
        if(in_array($str, $dictionary)){
            echo 'yes'.PHP_EOL;
        } else {
            echo 'no'.PHP_EOL;
        }
    }
}