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: Time Limit Exceeded

Solution code:
#16D8103010K Ko Okasaki
#ALDS_4_C

from collections import deque

n=int(input())
S=deque()
A=deque()

for i in range(n):
	cnt=0
	str=input().split()
	if str[0][0]=="i":
		S.append(str[1])
	else:
		for i in range(len(S)):
			if S[i]==str[1]:
				cnt+=1
				break
		
		if cnt==1:
			A.append("yes")
		else:
			A.append("no")

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n=int(input())
S=deque()
A=deque()

for i in range(n):
	cnt=0
	str=input().split()
	if str[0][0]=="i":
		S.append(str[1])
	else:
		for i in range(len(S)):
			if S[i]==str[1]:
				cnt+=1
				break
		
		if cnt==1:
			print("yes")
		else:
			print("no")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n=int(input())
S=deque()
A=deque()

for i in range(n):
	cnt=-1
	str=input().split()
	if str[0][0]=="i":
		S.append(str[1])
	else:
		'''for i in range(len(S)):
			if S[i]==str[1]:
				cnt+=1
				break
		'''
		try:
			cnt=S.index(str[1])
		except:
			pass
		if cnt!=-1:
			print("yes")
		else:
			print("no")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n=int(input())
S=deque()

for i in range(n):
	cnt=-1
	str=input().split()
	if str[0][0]=="i":
		S.append(str[1])
	else:
		'''for i in range(len(S)):
			if S[i]==str[1]:
				cnt+=1
				break
		'''
		try:
			cnt=S.index(str[1])
		except:
			pass
		if cnt!=-1:
			print("yes")
		else:
			print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = [0]*n
st = []

for i in range(n):
    c[i] = list(input().split())
    if c[i][0]=='insert':
        st.append(c[i][1])
    if c[i][0]=='find':
        flag = 0
        for j in range(len(st)):
            if c[i][1]==st[j]:
                flag = 1
        if flag == 0:
            print("no")
        else:
            print("yes")

Submission status: Time Limit Exceeded

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

for i in range(n):
  if a[i][0]=='insert':
    b.append(a[i][1])
  if a[i][0]=="find":
    if a[i][1] in b:
      print("yes")
    else:
      print("no")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]

for i in range(n):
  a.append(input().split())
  if a[i][0]=='insert':
    b.append(a[i][1])
  if a[i][0]=="find":
    if a[i][1] in b:
      print("yes")
    else:
      print("no")

Submission status: Time Limit Exceeded

Solution code:
# coding: Shift-JIS
n=int(input())
D=[]
A=[]
for i in range(n):
	command,x=input().split()
	if command=="insert":
		D.append(x)
	elif command=="find":
		if D.__contains__(x):
			A.append("yes")
		else:
			A.append("no")

for a in A:
	print(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=[]
list1=[]
for i in range(n):
    a,b=map(str,input().split())
    if a=="insert":
        list.append(b)
    if a=="find":
        if b in list:
            list1.append(1)
        else:
            list1.append(0)

for i in range(len(list1)):
    if list1[i]==1:
        print("yes")
    else:
        print("no")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
list=[]
list1=[]
for i in range(n):
    a,b=map(str,input().split())
    if a=="insert":
        list.append(b)
    if a=="find":
        if b in list:
            list1.append("yes")
        else:
            list1.append("no")

for i in list1:
    print(i)

Submission status: Time Limit Exceeded

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

n=int(input())

dictionary=[]
ans=""
for i in range(n):
    s=input()
    d=s.split(" ")

    if d[0]=="insert":
        dictionary.append(d[1])
    else:
        if d[1] in dictionary:
            ans+="yes\n"

        else:
            ans+="no\n"
ans=ans.rstrip()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

dictionary=[]
ans=""
for i in range(n):
    s=input()
    d=s.split(" ")

    if d[0]=="insert":
        dictionary.append(d[1])
    else:
        if d[1] in dictionary:
            ans+="yes\n"

        else:
            ans+="no\n"
ans=ans.rstrip()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = [0]*n
st = []

for i in range(n):
    c[i] = list(input().split())
    if c[i][0]=='insert':
        st.append(c[i][1])
        
    if c[i][0]=='find':
        if c[i][1] in st:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:

def Dictionary(b):
    a=list(input().split())
    if(a[0] == "insert"):
        b.append(a[1])
    elif(a[0] == "find"):
        if(a[1] in b):
            print("yes")
        else:
            print("no")

if __name__ == "__main__":
    n=int(input())
    b=[]
    for i in range(n):
        Dictionary(b)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())

dct = []

for line in sys.stdin:

    cmd, val = line.strip().split()

    if cmd == 'insert':
        dct.append(val)

    else:
        if val in dct:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n = int(input())

def converter(string):
    ch_list = ["A", "C", "G", "T"]
    new_string = ""
    for ch in string:
        for i in range(4):
            if ch == ch_list[i]:
                new_string += str(i+1)
    return int(new_string)

    
def sosu(num):
    while True:
        i = 2
        while i <= num ** (1/2) :
            if num % i != 0:
                i += 1

            else:
                num += 1
                i = 2
        break

    return num


def h1(key):
    return key % m

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

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

def insert(T, key):
    i = 0
    while True:
        j = hf(key, i)
        if T[j] == None:
            T[j] = key
            break
        else:
            i += 1

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


m = int(n*1.2)
m = sosu(m)
T = [None for num in range(m)]

cnt = 0
for i in range(n):
    order, string = input().split()
    if order == "insert":
        key = converter(string)
        insert(T,key)
    if order == "find":
        key = converter(string)
        print(search(T, key))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n = int(input())

def converter(string):
    ch_list = ["A", "C", "G", "T"]
    new_string = ""
    for ch in string:
        for i in range(4):
            if ch == ch_list[i]:
                new_string += str(i+1)
    return int(new_string)

    
def sosu(num):
    while True:
        i = 2
        while i <= num ** (1/2) :
            if num % i != 0:
                i += 1
            else:
                num += 1
                i = 2
        break
    return num


def h1(key):
    return key % m

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

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

def insert(T, key):
    i = 0
    while True:
        j = hf(key, i)
        if T[j] == None:
            T[j] = key
            break
        else:
            i += 1

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


m = int(n*1.2)
m = sosu(m)
T = [None for num in range(m)]

cnt = 0
for i in range(n):
    order, string = input().split()
    if order == "insert":
        key = converter(string)
        insert(T,key)
    if order == "find":
        key = converter(string)
        print(search(T, key))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n = int(input())

def converter(string):
    ch_list = ["A", "C", "G", "T"]
    new_string = ""
    for ch in string:
        for i in range(4):
            if ch == ch_list[i]:
                new_string += str(i+1)
    return int(new_string)

    
def sosu(num):
    while True:
        i = 2
        while i <= num ** (1/2) :
            if num % i != 0:
                i += 1
            else:
                num += 1
                i = 2
        break
    return num


def h1(key):
    return key % m

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

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

def insert(T, key):
    i = 0
    while True:
        j = hf(key, i)
        if T[j] == None:
            T[j] = key
            break
        else:
            i += 1

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


m = int(n*1.5)
m = sosu(m)
T = [None for num in range(m)]

cnt = 0
for i in range(n):
    order, string = input().split()
    if order == "insert":
        key = converter(string)
        insert(T,key)
    if order == "find":
        key = converter(string)
        print(search(T, key))

Submission status: Time Limit Exceeded

Solution code:
class BTree:
    def __init__(self):
        self.value = "ZZZ"
        self.left = None
        self.right = None

    def insert(self, s):
        if self.value is "ZZZ":
            self.value = s
        else:
            if self.value < s:
                if self.right is None:
                    self.right = BTree().insert(s)
                else:
                    self.right = self.right.insert(s)
            elif s < self.value:
                if self.left is None:
                    self.left = BTree().insert(s)
                else:
                    self.left = self.left.insert(s)
        return self

    def find(self, s):
        if self.value == s:
            return True
        elif self.value < s:
            if self.right is None:
                return False
            else:
                return self.right.find(s)
        else:
            if self.left is None:
                return False
            else:
                return self.left.find(s)


n = int(input())
tree = BTree()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        tree = tree.insert(command[1])
    elif command[0] == "find":
        if tree.find(command[1]):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
def find(data, s):
    l = 0
    r = len(data)
    while l < r:
        ind = (l + r) // 2
        if data[ind] == s:
            return True
        elif data[ind] < s:
            l = ind + 1
        else:
            r = ind
    return False

n = int(input())
data = []
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data.append(command[1])
        data.sort()
    elif command[0] == "find":
        if find(data, command[1]):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
def find(data, s):
    l = 0
    r = len(data)
    while l < r:
        ind = (l + r) // 2
        if data[ind] == s:
            return True
        elif data[ind] < s:
            l = ind + 1
        else:
            r = ind
    return False


def insert(data, s):
    if len(data) == 0:
        data.append(s)
    else:
        for i in range(len(data)):
            if s <= data[i]:
                data.insert(i, s)
                return data
        data.append(s)
    return data


n = int(input())
data = []
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data = insert(data, command[1])
    elif command[0] == "find":
        if find(data, command[1]):
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

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

    d = MyDict()

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            d.insert(value)
        elif cmd == 'find':
            if d.find(value):
                print('yes')
            else:
                print('no')

class MyDict():
    def __init__(self):
        self.E = []
    
    def insert(self, value):
        self.E.append(value)
    
    def find(self, value):
        return value in self.E

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Time Limit Exceeded

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

    d = MyDict()

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            d.insert(value)
        elif cmd == 'find':
            if d.find(value):
                print('yes')
            else:
                print('no')

class MyDict():
    def __init__(self):
        self.stacks = {
            'A': [],
            'C': [],
            'G': [],
            'T': []
        }
    
    def insert(self, value):
        self.stacks[value[0]].append(value)
    
    def find(self, value):
        return value in self.stacks[value[0]]

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Time Limit Exceeded

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

    d = MyDict()

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            d.insert(value)
        elif cmd == 'find':
            if d.find(value):
                print('yes')
            else:
                print('no')


class MyDict():
    def __init__(self):
        self.stacks = {
            'A': [],
            'C': [],
            'G': [],
            'T': []
        }
    
    def insert(self, value):
        st = self.stacks[value[0]]
        st.append(value[1:])
        self.stacks[value[0]] = sorted(st)
    
    def find(self, value):
        st = self.stacks[value[0]]
        return binary_search(st, len(st), value[1:])

def binary_search(S, n, t):
    left = 0
    right = n - 1
    while left <= right:
        mid = (left + right) // 2
        if S[mid] == t:
            return True
        elif S[mid] > t:
            right = mid - 1
        else:
            left = mid + 1
    
    return False

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Time Limit Exceeded

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

    d = MyDict()

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            d.insert(value)
        elif cmd == 'find':
            if d.find(value):
                print('yes')
            else:
                print('no')


class MyDict():
    def __init__(self):
        self.stacks = {
            1: [], 2: [], 3: [], 4: [], 5: [],
            6: [], 7: [], 8: [], 9: [], 10: [],
            11: [], 12: []
        }
    
    def insert(self, value):
        st = self.stacks[len(value)].append(value)
    
    def find(self, value):
        st = self.stacks[len(value)]
        return value in st

def binary_search(S, n, t):
    left = 0
    right = n - 1
    while left <= right:
        mid = (left + right) // 2
        if S[mid] == t:
            return True
        elif S[mid] > t:
            right = mid - 1
        else:
            left = mid + 1
    
    return False

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
class Node():
    def __init__(self, data):
        # string
        self.data = data
        self.children = dict()
        
class Tries():
    def __init__(self):
        self.head = Node("*")

    def add(self, string):
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        for node in nodelist:
            char = node.data
            if char not in cur_node.children:
                cur_node.children[char] = node
                cur_node = cur_node.children[char]
            else:
                cur_node = cur_node.children[char]
        cur_node.children["*"] = 0

    def _add(self, string):
        '''
        deprecated
        '''
        
        nodelist = [Node(char) for char in string]
        cur_node = self.head
        i = 0
        
        while(i < len(nodelist)):
            node = nodelist[i]
            char = node.data
            
            if char not in cur_node.children:
                cur_node.children[char] = nodelist[i]
                cur_node = cur_node.children[char]

            else:
                # cur_node.children[char]
                cur_node = cur_node.children[char]

            i += 1
            
    def find(self, string):
        i = 0
        cur_node = self.head
        while(i <= len(string)-1):
            
            char = string[i]
            if char in cur_node.children:
                cur_node = cur_node.children[char]
                i += 1
            else:
                return False
        if cur_node.children.get("*") == None:
            return False
        return True
                
if __name__ == "__main__":
    
    n = int(input())
    ops = []
    words = []
    for _ in range(n):
        op, word = input().split()
        ops.append(op)
        words.append(word)
    
    tries = Tries()
    for op, word in zip(ops, words):
        if op=='insert':
            tries.add(word)
        else:
            if tries.find(word)==True:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    D = []

    for _ in range(N):
        command, value = [i for i in input().split()]

        if command == "insert":
            D.append(value)
        else:
            if value in D:
                print("yes")
            else:
                print("no")

main()

Submission status: Time Limit Exceeded

Solution code:
D = []

def append(value):
    global D

    hashvalue = ""
    for letter in value:
        hashvalue += str(ord(letter))

    D.append(int(hashvalue))

def find(value):
    hashvalue = ""
    for letter in value:
        hashvalue += str(ord(letter))

    hashvalue = int(hashvalue)

    left = 0
    right = len(D) - 1

    while True:
        mid = (left + right) // 2

        if not 0 <= mid < len(D):
            print("no")
            return

        if D[mid] == hashvalue:
            print("yes")
            return
        elif D[mid] < hashvalue:
            left = mid + 1
        else:
            right = mid - 1

        if left > right:
            print("no")
            return


def main():
    global D

    N = int(input())
    finds = []

    for _ in range(N):
        command, value = [i for i in input().split()]

        if command == "insert":
            append(value)
            D.sort()
        else:
            find(value)

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
input_list = []  # using for input
for i in range(n):
    input_list.append(input())

dictionary_list = []  # dictionary
count = 0

for i in range(n):
    # print('i: ' + str(i))
    if 'find' in input_list[i] and len(dictionary_list) == 0:
        print('no')
    elif 'insert' in input_list[i]:
        dictionary_list.append(input_list[i][7:])
        count += 1
    elif 'find' in input_list[i]:
        for j in range(count):
            # print('j: ' + str(j))
            if dictionary_list[j] == input_list[i][5:]:
                print('yes')
                break
                # print(input_list)
                # print(dictionary_list)
                # print(dictionary_list[j])
                # print('count: ' + str(count))
                # continue

            elif j == count-1:
                # print(dictionary_list)
                print('no')
                break

            # else:
            #     print('no')
                # print(input_list)
                # print(dictionary_list)
                # print(dictionary_list[j])
                # print('count: ' + str(count))
                # continue

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
input_list = []  # using for input
for i in range(n):
    input_list.append(input())

dictionary_list = []  # dictionary
count = 0

for i in range(n):
    # print('i: ' + str(i))
    if 'insert' in input_list[i]:
        dictionary_list.append(input_list[i][7:])
        count += 1
    elif 'find' in input_list[i]:
        if len(dictionary_list) == 0:
            print('no')
        else:
            for j in range(count):
                if dictionary_list[j] == input_list[i][5:]:
                    print('yes')
                    break
                elif j == count-1:
                    print('no')
                    break

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#i = 0
a,b=[],[]
check = re.compile('insert')
n=input()
#while True:
for x in xrange(n):
    (i,f)=map(str, raw_input().split())
    if check.search(i):
        a.append(f)
    else:
        b.append(f)
#print a
#print b
#for y in b:
        if f in a:
            print 'yes'
        else:
            print 'no'

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#i = 0
a,b=[],[]
check = re.compile('insert')
n=input()
#while True:
for x in xrange(n):
    (i,f)=map(str, raw_input().split())
    if check.search(i):
        a.append(f)
    else:
#        b.append(f)
#print a
#print b
#for y in b:
        if f in a:
            print 'yes'
        else:
            print 'no'

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
ls = []
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls.append(inp[7:])
    else:
        print "yes" if inp[5:] in ls else "no"

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
ls = [[] for i in range(12)]
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[len(inp[7:])].append(inp[7:])
    else:
        print "yes" if inp[5:] in ls[len(inp[5:])] else "no"

Submission status: Memory Limit Exceeded

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

def input_converter(key_string):
    key_string = key_string.replace('A', '1')
    key_string = key_string.replace('T', '2')
    key_string = key_string.replace('C', '3')
    key_string = key_string.replace('G', '4')
    return int(key_string)


class HashTable(object):
    def __init__(self, hash_size = 2 ** 27):
        self.hash_size = hash_size
        self.hash_array = [None] * self.hash_size

    def insert_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        while self.hash_array[next_index] is not None:
            collision_number += 1
            next_index = self.hash_function(key, collision_number)
        # print self.hash_array[next_index]
        self.hash_array[next_index] = data

    def search_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        next_data = self.hash_array[next_index]
        while True:
            if (next_data is None) or (collision_number > self.hash_size):
                return False
            elif next_data == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)
                next_data = self.hash_array[next_index]

    def hash_function(self, key, collision_number):
        def h1(key):
            return key % self.hash_size
    
        def h2(key):
            return key % (self.hash_size - 1)

        return (h1(key) + collision_number * h2(key)) % self.hash_size


def main():
    input_size = int(raw_input())
    hash_table = HashTable()
    counter = 0
    while counter < input_size:
        command, key = raw_input().split(' ')
        if command == 'insert':
            hash_table.insert_value(key, input_converter(key))
        else:
            if hash_table.search_value(key, input_converter(key)):
                print 'yes'
            else:
                print 'no'
        counter += 1


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

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

def input_converter(key_string):
    key_string = key_string.replace('A', '1')
    key_string = key_string.replace('T', '2')
    key_string = key_string.replace('C', '3')
    key_string = key_string.replace('G', '4')
    return int(key_string)


class HashTable(object):
    def __init__(self, hash_size = 2 ** 27):
        self.hash_size = hash_size
        self.hash_array = [None] * self.hash_size

    def insert_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        while self.hash_array[next_index] is not None:
            collision_number += 1
            next_index = self.hash_function(key, collision_number)
        if collision_number != 0:
            print collision_number
        self.hash_array[next_index] = data

    def search_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        next_data = self.hash_array[next_index]
        while True:
            if (next_data is None) or (collision_number > self.hash_size):
                return False
            elif next_data == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)
                next_data = self.hash_array[next_index]

    def hash_function(self, key, collision_number):
        def h1(key):
            return key % self.hash_size
    
        def h2(key):
            return key % (self.hash_size - 1)

        return (h1(key) + collision_number * h2(key)) % self.hash_size


def main():
    input_size = int(raw_input())
    hash_table = HashTable()
    counter = 0
    while counter < input_size:
        command, key = raw_input().split(' ')
        if command == 'insert':
            hash_table.insert_value(key, input_converter(key))
        else:
            if hash_table.search_value(key, input_converter(key)):
                print 'yes'
            else:
              print 'no'
        counter += 1


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

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

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

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

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

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

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

def getNum(char):
    char2num = str.maketrans("ACGT", "1234")
    return int(char.translate(char2num))

if __name__ == '__main__':

    n = int(input())
    T = HashTable(n*100)
    C = map(lambda x:(x[0], getNum(x[1])), [input().split(" ") for i in range(n)])
    

    for command, num in C:
        if command == "insert":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")

    """
    char2num = str.maketrans("ACGT", "1234")
    for _ in range(n):
        command, char = input().split(" ")
        num = int(char.translate(char2num))
        if command == "insert":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")
    """

Submission status: Memory Limit Exceeded

Solution code:
#coding: Shift_JIS
hmax=0
a=1
for i in range(12):
	hmax+=4*a
	a*=5

def hash(str):
	v=0
	b=1
	for s in str:
		if s=='A': v+=b
		elif s=='C': v+=2*b
		elif s=='G': v+=3*b
		elif s=='T': v+=4*b
		b*=5
	return v

dic=[0]*hmax
n=int(input())
for i in range(n):
	str=input()
	com=str.split()
	if com[0]=="insert":
		dic[hash(com[1])]=1
	elif com[0]=="find":
		if dic[hash(com[1])]==1: print("yes")
		else: print("no")

Submission status: Memory Limit Exceeded

Solution code:
import sys

htable = [0 for _ in range(244140624)]


def to_int(s):
    if s == 'A':
        return 1
    elif s == 'C':
        return 2
    elif s == 'G':
        return 3
    else:
        return 4


def to_hash(string):
    h = 0
    for i, s in enumerate(string):
        ints = to_int(s)
        h += 5**i * ints

    return h


def insert(string):
    h = to_hash(string)
    htable[h] = 1


def find(string):
    h = to_hash(string)
    if htable[h]:
        print('yes')
    else:
        print('no')


if __name__ == '__main__':

    n = int(input())

    for line in sys.stdin:
        cmd, string = line.strip().split()

        if cmd == 'insert':
            insert(string)

        else:
            find(string)

Submission status: Memory Limit Exceeded

Solution code:
import sys

htable = [0] * 244140625


def to_int(s):
    if s == 'A':
        return 1
    elif s == 'C':
        return 2
    elif s == 'G':
        return 3
    else:
        return 4


def to_hash(string):
    h = 0
    for i, s in enumerate(string):
        ints = to_int(s)
        h += 5**i * ints

    return h


def insert(string):
    h = to_hash(string)
    htable[h] = 1


def find(string):
    h = to_hash(string)
    if htable[h]:
        print('yes')
    else:
        print('no')


if __name__ == '__main__':

    n = int(input())

    for line in sys.stdin:
        cmd, string = line.strip().split()

        if cmd == 'insert':
            insert(string)

        else:
            find(string)