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:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
sample_input = list(range(4))
sample_input[0] = '''6
insert AAA
insert AAC
find AAA
find CCC
insert CCC
find CCC'''
sample_input[1] = '''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_input[2] = '''20
find CTT
find TAG
insert AA
insert CTC
find G
insert TGT
find AAC
find TTG
insert AA
insert TTG
insert G
insert A
insert GG
insert C
insert TT
find T
insert C
find GG
find G
insert CG'''
sample_input[3]='''15
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
find CC
insert T
find TTT
find T
find A'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
class ACGTDictNode (object):
    
    def __init__(self):
        self.A = None    # None | ACGTDictNode
        self.C = None
        self.G = None
        self.T = None
        self.has_end = False
    
    
    def add_and_see(self, acgt):
        if acgt == 'A':
            if self.A is not None:
                return self.A
            else:
                self.A = ACGTDictNode()
                return self.A
        elif acgt == 'C':
            if self.C is not None:
                return self.C
            else:
                self.C = ACGTDictNode()
                return self.C
        elif acgt == 'G':
            if self.G is not None:
                return self.G
            else:
                self.G = ACGTDictNode()
                return self.G
        elif acgt == 'T':
            if self.T is not None:
                return self.T
            else:
                self.T = ACGTDictNode()
                return self.T
        else:
            assert False
            
            
    def has_child(self, acgt):
        if acgt == 'A':
            return self.A is not None
        elif acgt == 'C':
            return self.C is not None
        elif acgt == 'G':
            return self.G is not None
        elif acgt == 'T':
            return self.T is not None
        else:
            assert False
            
    
    def add_end(self):
        self.has_end = True

        

class ACGTDict (object):
    
    def __init__(self):
        self.tree = ACGTDictNode()
        
        
    def insert(self, string):
        node = self.tree
        for c in string:
            node = node.add_and_see(c)
        node.add_end()
            
    
    def find(self, string):
        node = self.tree
        for c in string:
            if not node.has_child(c):
                return False
            else:
                node = node.add_and_see(c)
        return node.has_end
        

dict = ACGTDict()
num_of_commands = int(input())
for n in range(num_of_commands):
    input_str = input()
    command, data = input_str.split(' ')
    if command == 'insert':
        dict.insert(data)
    else:
        if dict.find(data):
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

hash = []
for i in range(n):
    command, value = input().split()
    if command == 'insert':
        hash.append(value)
    elif command == 'find':
        if value in hash:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
li = deque()
n = int(input())

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    cmd = input().split()
    if cmd[0] == 'insert':
        l.append(cmd[1])
    if cmd[0] == 'find':
        sl = set(l)
        if len( sl & {cmd[1]} ) == 1:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
l = deque()

for i in range(n):
    cmd = input().split()
    if cmd[0] == 'insert':
        l.append(cmd[1])
    if cmd[0] == 'find':
        sl = set(l)
        if len( sl & {cmd[1]} ) == 1:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
l = deque()

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
l = deque()

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

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
stl = []
for i in range(n):
    od, st = input().split()
    if od == 'insert':
        stl.append(st)
    else:
        if st in stl:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
n=input()

d=[]
for x in xrange(n):
    cmd, st = map(str, raw_input().split())
    
    if cmd == "insert":
        d.append(st)
    elif cmd == "find":
        print 'yes' if st in d else 'no'

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8
def Dic(n,A):
    dic=[]
    for i in range(n):
        order=A[i][0]
        txt=A[i][1]
        if order=="insert":
            dic.append(txt)
        else:
            if txt in dic:
                print("yes")
            else:
                print("no")
  
if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(input().split(" "))
    Dic(n,A)

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8
def Dic(n,A):
    dic=[]
    for i in range(n):
        order=A[i][0]
        txt=A[i][1]
        if order=="insert":
            if txt in dic:
                continue
            dic.append(txt)
        else:
            if txt in dic:
                print("yes")
            else:
                print("no")
  
if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(input().split(" "))
    Dic(n,A)

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
    n_line = int(input())
    l = []
    for i in range(n_line):
        input_line = input().split()
        if input_line[0] == "insert":
            l.append(input_line[1])
        else:
            if input_line[1] in l:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
    n_line = int(input())
    input_list = [tuple(input().split()) for i in range(n_line)]
    l = []
    for c, s in input_list:
        if c == "insert":
            l.append(s)
        else:
            if s in l:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
    n_line = int(input())
    input_list = [tuple(input().split()) for i in range(n_line)]
    dict_list = [s if c == "insert" else "" for c, s in input_list ]
    search_list = [(i,l[1]) for i,l in enumerate(input_list) if l[0] == "find"]
    ans_list = ["yes" if s in dict_list[:i] else "no" for i, s in search_list]
    print("\n".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ?????? '''


class Dictionary(object):
    """ Dictionary """

    def __init__(self):
        self.dict = []

    def insert(self, x):
        self.dict.append(x)

    def find(self, x):
        if x in self.dict:
            print('yes')
        else:
            print('no')

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

    d = Dictionary()

    for _ in range(N):
        command, key = list(input().split())
        if command == 'insert':
            d.insert(key)
        elif command == 'find':
            d.find(key)

Submission status: Time Limit Exceeded

Solution code:
# const
M = 1046527

def h1(key):
    return key % M

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

def hash(key ,i):
    return (h1(key) + i*h2(key)) % M

def conv_str_to_num(str):
    converted = 0
    s_list = list(str)
    for (i,c) in enumerate(s_list):
        if c == 'A':
            n = 1
        elif c == 'C':
            n = 2
        elif c == 'G':
            n = 3
        elif c == 'T':
            n = 4
        else:
            n = 0

        converted += 5**i * n

    return converted



class hashTable(object):
    def __init__(self, arg):
        self.T = ["" for _ in range(arg)]

    def insert(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == "":
                self.T[h] = s
                break
            i += 1

    def find(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == s:
                return 1
            elif self.T[h] == "":
                return 0

            i += 1
        return 0


if __name__ == '__main__':
    h_t = hashTable(M)
    ans = []
    n = int(input())
    for _ in range(n):
        op, s = input().split()
        if op == "insert":
            h_t.insert(s)
        else:
            tmp = h_t.find(s)
            if tmp == 1:
                ans.append("yes")
            else:
                ans.append("no")

    for s in ans:
        print(s)

Submission status: Time Limit Exceeded

Solution code:
# const
M = 1046527

def h1(key):
    return key % M

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

def hash(key ,i):
    return (h1(key) + i*h2(key)) % M

def conv_str_to_num(str):
    converted = 0
    s_list = list(str)
    for (i,c) in enumerate(s_list):
        if c == 'A':
            n = 1
        elif c == 'C':
            n = 2
        elif c == 'G':
            n = 3
        elif c == 'T':
            n = 4
        else:
            n = 0

        converted += 5**i * n

    return converted



class hashTable(object):
    def __init__(self, arg):
        self.T = [""] * arg

    def insert(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == "":
                self.T[h] = s
                break
            i += 1

    def find(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == s:
                return 1
            elif self.T[h] == "":
                return 0

            i += 1
        return 0


if __name__ == '__main__':
    h_t = hashTable(M)
    n = int(input())
    for _ in range(n):
        op, s = input().split()
        if op == "insert":
            h_t.insert(s)
        else:
            tmp = h_t.find(s)
            if tmp == 1:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
# const
M = 6094397

def h1(key):
    return key % M

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

def hash(key ,i):
    return (h1(key) + i*h2(key)) % M

def conv_str_to_num(str):
    converted = 0
    s_list = list(str)
    for (i,c) in enumerate(s_list):
        if c == 'A':
            n = 1
        elif c == 'C':
            n = 2
        elif c == 'G':
            n = 3
        elif c == 'T':
            n = 4
        else:
            n = 0

        converted += 5**i * n

    return converted



class hashTable(object):
    def __init__(self, arg):
        self.T = [""] * arg

    def insert(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == "":
                self.T[h] = s
                break
            i += 1

    def find(self, s):
        key = conv_str_to_num(s)
        i = 0
        while True:
            h = hash(key, i)
            if self.T[h] == s:
                return 1
            elif self.T[h] == "":
                return 0

            i += 1
        return 0


if __name__ == '__main__':
    h_t = hashTable(M)
    n = int(input())
    for _ in range(n):
        op, s = input().split()
        if op == "insert":
            h_t.insert(s)
        else:
            tmp = h_t.find(s)
            if tmp == 1:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

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] is None:
            T[j] = key
            return j
        else:
            i += 1


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


global m
r = {"A": 1, "C": 2, "G": 3, "T": 4, }
t = []
m = int(input())
for i in range(m):
    cmd, key = input().split()
    if cmd == "insert":
        t.append(key)
    else:
        if key in t:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
dic = []

for i in range(int(input())):
  cmd, arg = input().split()
  if cmd == "insert":
    dic.append(arg)
  else:
    if arg in dic:
      print("yes")
    else:
      print("no")

Submission status: Time Limit Exceeded

Solution code:
dic = {"A":[], "C":[], "G":[], "T":[]}

for i in range(int(input())):
  cmd, arg = input().split()
  if cmd == "insert":
    dic[arg[0]].append(arg)
  else:
    if arg in dic[arg[0]]:
      print("yes")
    else:
      print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = set()
for i in range(n):
    c = input()
    if c[0] == 'i':
        d = d|{c[7:]}
    else:
        if c[5:] in d:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
d = set()
for i in range(n):
    c = sys.stdin.readline()
    if c[0] == 'i':
        d = d|{c[7:]}
    else:
        if c[5:] in d:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
d = []
for i in range(n):
    c = sys.stdin.readline()
    if c[0] == 'i':
        d.append(c[7:])
    else:
        if c[5:] in d:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
m = 1046527
n = int(input())
s = []
v = []
for i in range(n):
    tmp = input().split()
    s.append(str(tmp[0]))
    v.append(str(tmp[1]))

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 getChar(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 getKey(string):
    sum = 0
    p = 1
    for i in range(len(string)):
        sum += p*getChar(string[i])
        p *= 5
    return sum

T = [-1]*m

for i in range(n):
    val = list(v[i])
    key = getKey(val)
    if s[i] == 'insert':
        insert(T,key)
    if s[i] == 'find':
        result = search(T,key)
        if result < 0:
            print('no')
        else:
            print('yes')

Submission status: Time Limit Exceeded

Solution code:
m = 1046527
n = int(input())
s = []
v = []
for i in range(n):
    tmp = input().split()
    s.append(str(tmp[0]))
    v.append(str(tmp[1]))

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

def getChar(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 getKey(string):
    sum = 0
    p = 1
    for i in range(len(string)):
        sum += p*getChar(string[i])
        p *= 5
    return sum

T = [-1]*m

for i in range(n):
    val = list(v[i])
    key = getKey(val)
    if s[i] == 'insert':
        insert(T,key)
    if s[i] == 'find':
        result = search(T,key)
        if result < 0:
            print('no')
        else:
            print('yes')

Submission status: Time Limit Exceeded

Solution code:
diction = []
for i in range(int(input())):
    command = input().split()
    if command[0] == "insert":
        diction.append(command[1])
    else:
        if command[1] in diction:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
import sys
diction = []
n = int(input())
command = sys.stdin.readlines()
for i in range(n):
    a,b = command[i].split()
    if a == "insert":
        diction.append(b)
    else:
        if b in diction:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
n = int(input())
command = sys.stdin.readlines()
Q = deque()
for i in range(n):
    a,b = command[i].split()
    if a == "insert":
        Q.append(b)
    else:
        if b in Q:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
command = sys.stdin.readlines()
Q = {}
for i in range(n):
    a,b = command[i].split()
    if a == "insert":
        Q[b] = 0
    else:
        if b in set(Q.keys()):
            print("yes")
        else:
            print("no")

Submission status: Time 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 ** 15):
        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)
        while True:
            if (self.hash_array[next_index] is None) or (collision_number > self.hash_size):
                return False
            elif self.hash_array[next_index] == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)

    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():
    hash_table = HashTable()
    input_size = int(raw_input())
    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: Time 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 ** 20):
        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)
        while True:
            if (self.hash_array[next_index] is None) or (collision_number > self.hash_size):
                return False
            elif self.hash_array[next_index] == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)

    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(2 ** 20)
    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: Time 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 ** 22):
        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)
        while True:
            if (self.hash_array[next_index] is None) or (collision_number > self.hash_size):
                return False
            elif self.hash_array[next_index] == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)

    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(2 ** 20)
    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: Time 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 ** 23):
        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)
        while True:
            if (self.hash_array[next_index] is None) or (collision_number > self.hash_size):
                return False
            elif self.hash_array[next_index] == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)

    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(2 ** 20)
    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: Time 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 ** 26):
        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(2 ** 20)
    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()