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:
# -*- 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)
        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

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

Solution code:
n = int(input())
dic = []
for i in range(n):
    f, st = input().split()
    if f == "insert":
        dic.append(st)
    else:
        if st in dic:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

D = deque()
N = int(input())

for i in range(N):
	c, s = input().split()
	if c == "insert":
		D.append(s)
	elif c == "find":
		if (s in D):
			print("yes")
		else:
			print("no")

Submission status: Time Limit Exceeded

Solution code:
command_num = int(input())
dict = []

for i in range(command_num):
    in_command, in_str = input().rstrip().split(" ")
    
    if in_command == "insert":
        dict.append(in_str)
    elif in_command == "find":
        if dict.count(in_str) > 0:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    try:
        n = int(raw_input())
    except:
        print 'the first input must be integer value!'
        exit()

    genoms = []
    answers = []
    for _ in range(n):
        values = raw_input().split()
        order = values[0]
        genom = values[1]
        if order == "insert":
            genoms.append(genom)
        else:
            answers.append('yes' if genom in genoms else 'no' )

    # print(genoms)
    # print(answers)

    for answer in answers:
        print answer

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
dict=[]
for i in range(N):
    a=input().split()
    if a[0]=="insert":
        dict.append(a[1])
    elif a[0]=="find":
        if a[1] in dict:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n = int(input())
dict = deque()
for i in range(n):
    order = input().split()
    if order[0] == "insert":
        dict.append(order[1])
    else:
        if order[1] in dict:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
class Hash:
    def __init__(self):
        self.size = 1000000
        self.l = [0] * 1000000

    def insert_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == 0:
                self.l[j] = st
                #print("inserted")
                return
            else:
                i = i+1

    def find_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == st:
                return "yes"
            elif self.l[j] == 0 or (i >= self.size):
                return "no"
            else:
                i += 1

    def h1(self, key):
        return sum([ord(c) for c in key]) % self.size

    def h2(self, key):
        return 1 + sum([ord(c) for c in key]) % ( self.size - 1 )

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

#main
n = int(input())
hash = Hash()

for _ in range(n):
    ope, st = input().split()
    if ope == "insert":
        hash.insert_key(st)
    elif ope == "find":
        print(hash.find_key(st))

Submission status: Time Limit Exceeded

Solution code:
class Hash:
    def __init__(self):
        self.size = 1046527
        self.l = [0] * self.size

    def insert_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == 0:
                self.l[j] = st
                #print("inserted")
                return
            else:
                i = i+1

    def find_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == st:
                return "yes"
            elif self.l[j] == 0 or (i >= self.size):
                return "no"
            else:
                i += 1

    def h1(self, key):
        return sum([ord(c) for c in key]) % self.size

    def h2(self, key):
        return 1 + sum([ord(c) for c in key]) % ( self.size - 1 )

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

#main
n = int(input())
hash = Hash()

for _ in range(n):
    ope, st = input().split()
    if ope == "insert":
        hash.insert_key(st)
    elif ope == "find":
        print(hash.find_key(st))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for _ in range(n):
    ss = input().split()
    order, string = ss[0], ss[1]
    if order == "insert":
        l.append(string)
    else:
        print('yes' if string in l else 'no')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
l = deque()
for _ in range(n):
    ss = input().split()
    order, string = ss[0], ss[1]
    if order == "insert":
        l.append(string)
    else:
        print('yes' if string in l else 'no')

Submission status: Time Limit Exceeded

Solution code:
dictionary = []
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.append(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
dictionary = deque()
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.append(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')

Submission status: Time Limit Exceeded

Solution code:
#5.4
n = int(input())
strs = [];

for i in range(0, n):
    tmp = list(input().split())
    if tmp[0] == 'insert':
        strs.append(tmp[1])
    elif tmp[0] == 'find':
        try:
            strs.index(tmp[1])
            print('yes')
        except:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
#5.4
n = int(input())
strs = [];

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

Submission status: Time Limit Exceeded

Solution code:
M = 1046527

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

def get_key(s):
    p = 1
    sum = 0
    for c in s:
        sum += p * get_char(c)
        p *= 5
    return sum

def h1(key):
    return key % M

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

def find(s, H):
    key = get_key(s)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == s:
            return 1
        elif len(H[h]) == 0:
            return 0
    return 0

def insert(s, H):
    key = get_key(s)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == s: 
            return 1
        elif len(H[h]) == 0:
            H[h] = s
            return 0
    return 0

n = int(input())
H = [""] * M
result_list = list()

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

    if com == "insert":
        insert(s, H)
    else:
        if find(s, H):
            result_list.append("yes")
        else:
            result_list.append("no")

for result in result_list:
    print(result)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = input()
    D = []
    O = []
    for i in range(n):
        c, k = raw_input().split()
        if c == 'insert':
            D.append(k)
        else:
            O.append(search(D,k))

    for item in O:
        print item

    return 0


def search(D,k):
    Dc = D[:]
    o = 'no'
    while Dc != []:
        d = Dc.pop()
        if d == k:
            o = 'yes'
            break

    return o
            

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
m = 10**6

def MyHash(k,i):
    return (k%m+i*(1+(k%m)))%m

def main():
    n = input()
    T = ['']*10**6
    O = []
    for i in range(n):
        c, k = raw_input().split()
        i = 0
        if c == 'insert':
            k_hashed = hash(k)
            while True:
                j = MyHash(k_hashed,i)
                if T[j] == '':
                    T[j] = k
                    break
                else:
                    i += 1
        else:
            O.append(search(T,k))

    for item in O:
        print item

    return 0


def search(T,k):
    k_hashed = hash(k)
    i = 0
    while True:
        j = MyHash(k_hashed,i)
        if T[j] == k:
            o = 'yes'
            break
        elif T[j] == '':
            o = 'no'
            break
        else:
            i += 1

    return o


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8

n = int(input())
dic_list = []

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

Submission status: Time Limit Exceeded

Solution code:
d_list = []

times = int(input())
for i in range(times):
    elm = input().split()
    if elm[0] == "insert":
        d_list.append(elm[1])
    elif elm[0] == "find":
        if elm[1] in d_list:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
d_list_a = []
d_list_c = []
d_list_g = []
d_list_t = []

times = int(input())
for i in range(times):
    elm = input().split()
    if elm[0] == "insert":
        if elm[1][0] == "A":
            d_list_a.append(elm[1])
        if elm[1][0] == "C":
            d_list_c.append(elm[1])
        if elm[1][0] == "G":
            d_list_g.append(elm[1])
        else:
            d_list_t.append(elm[1])
    elif elm[0] == "find":
        if elm[1][0] =="A":
            if elm[1] in d_list_a:
                print("yes")
            else:
                print("no")
        elif elm[1][0] =="C":
            if elm[1] in d_list_c:
                print("yes")
            else:
                print("no")
        elif elm[1][0] =="G":
            if elm[1] in d_list_g:
                print("yes")
            else:
                print("no")
        elif elm[1][0] =="T":
            if elm[1] in d_list_t:
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
d_list = []

times = int(input())
for i in range(times):
    elm = input().split()
    code = elm[1].replace("A","1")
    code = code.replace("C","2")
    code = code.replace("G","3")
    code = code.replace("T","4")
    if elm[0] == "insert":
        d_list.append(code)
        d_list = sorted(d_list)

    elif elm[0] == "find":
        lower_bound = 0
        upper_bound = len(d_list)-1
        found = False

        while lower_bound <= upper_bound and not found:
            mid = (lower_bound + upper_bound)//2
            if d_list[mid] < code:
                lower_bound = mid + 1
            elif d_list[mid] > code:
                upper_bound = mid - 1
            else:
                found = True
        if found:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    inp = sys.stdin.readlines()
    lis = []
    for i in range(n):
        com = inp[i].split()
        if com[0] == "insert":
            lis.append(com[1])
        elif com[1] in lis:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0 for i in range(22369621)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 4
    if s[0] == "insert":
        a[num] = 1
    else:
        if a[num] == 1:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
M = 1046527
a = [0 for i in range(M)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 5
    h1 = num % M
    h2 = h1 + num % (M - 1)
    k = 0
    h = (h1 + k * h2) % M
    if s[0][0] == "i":
        while True:
            if a[h] == 0:
                a[h] = s[1]
                break
            elif a[h] == s[1]:
                break
            else:
                k += 1
    else:
        while True:
            if a[h] == s[1]:    
                print("yes")
                break
            elif a[h] == 0:
                print("no")
                break
            else:
                k += 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0 for i in range(22369621)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 4
    if s[0][0] == "i":
        a[num] = 1
    else:
        if a[num] == 1:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
M = 1046527
a = [0 for i in range(M)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 5
    h1 = num % M
    h2 = h1 + num % (M - 1)
    k = 0
    if s[0][0] == "i":
        while True:
            h = (h1 + k * h2) % M
            if a[h] == 0:
                a[h] = s[1]
                break
            elif a[h] == s[1]:
                break
            else:
                k += 1
    else:
        while True:
            h = (h1 + k * h2) % M
            if a[h] == s[1]:    
                print("yes")
                break
            elif a[h] == 0:
                print("no")
                break
            else:
                k += 1

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())
	dictionary = []

	for _ in range(n):
		order, code = input().split()
		if order == 'insert':
			dictionary.append(code)
		elif order == 'find':
			if code in dictionary:
				print('yes')
			else:
				print('no')
		else:
			raise Exception('InputError')

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
dic=[]
n=int(input())
cmd=[list(input().split()) for i in range(n)]
for c, l in cmd:
    if c=="insert":
        dic.append(l)
    if c=="find":
        if l in dic:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??\????????????????????????????°?????????????????????????????£??????????????????????

insert str: ????????? str ??????????????????
find str: ????????? str ?????????????????´??? 'yes'??¨????????????????????´??? 'no'??¨???????????????

??????????????????????????????'A', 'C', 'G', 'T' ???????¨????????????????????§????????????????
1 ??? ?????????????????? ??? 12  n ??? 1,000,000

"""
import sys

# ????´??????¢?????¬????????????
NoVal = -1

# ????????¨????????????
Black = 0
Red = 1

class Node:
    """ ???????????? """

    def __init__(self, pnode, color, value):
        """ ????????????????????? """
        self.P = pnode # ????????????
        self.V = value # ???
        self.C = color # ???
        self.L = NoVal # ??????
        self.R = NoVal # ??????

def Find(r,value):
    """ ????????¨??¢?´¢ """
    
    if isinstance(r, Node) == False:
        return False
    if value == r.V:
#        print("Finded p:'{}' v:'{}'".format(r.V, value))
        return True
    if value < r.V: # ?°????????????§??????
        if isinstance(r.L, Node) == True:
#            print("Left Search p:'{}' v:'{}'".format(r.V, value))
            return Find(r.L, value)
    elif value > r.V: # ??§???????????§??????
        if isinstance(r.R, Node) == True:
#            print("Right Search p:'{}' v:'{}'".format(r.V, value))
            return Find(r.R, value)
#    print("Not Exists r:{} v:'{}'".format(r.V, value))
    return False

def Insert(r, value):
    """ ????????¨???????????? """
    if isinstance(r, Node) == False: # ???????????????
#        print("Root Insert '{}'".format(value))
        return Node(NoVal, Black, value) # ????´??????\

    if value == r.V: # ???????????????????????????????????§??????
#        print("Exists p:'{}' v:'{}'".format(r.V, value))
        return NoVal

    if value < r.V: # ?°???????
        if isinstance(r.L, Node) == False: # ??????????????????
            r.L = Node(r, Red, value) # ??????????´??????\
#            print("Left Insert '{}'".format(value))
            return r.L
        else:
#            print("Next Left p'{}' v'{}'".format(r.V, value))
            Insert(r.L, value) # ?????????
    elif value > r.V: # ??§??????
        if isinstance(r.R, Node) == False: # ??????????????????
#            print("Right Insert '{}'".format(value))
            r.R = Node(r, Red, value) # ??????????´??????\
            return r.R
        else:
#            print("Next Right p:'{}' v:'{}'".format(r.V, value))
            Insert(r.R, value) # ?????????

def RotateR(a):
    """ ????????¨???????????¢ a:????????? ?????????:??°????????? """
    b = a.L     # a ???????????? b ??¨??????
    b.P = a.P   # b ????????? a ???????????????
    a.P = b     # a ????????? b ?????????
    a.L = b.R   # a ???????????? b ??????????????????
    a.L.P = a   # a ?????????????????? a ?????????
    b.R = a     # b ???????????? a ?????????
    if b.P != NoVal: # b ??????????´????????????????
       if b.P.L == a: # b ?????????????????? a ??????
            b.P.L = b    # b ?????????????????? b ?????????
       elif b.P.R == a: # b ?????????????????? a ??????
            b.P.R = b    # b ?????????????????? b ?????????
    return b

def RotateL(a):
    """ ????????¨???????????¢ r:????????? """
    b = a.R     # a ???????????? b ??¨??????
    b.P = a.P   # b ????????? a ???????????????
    a.P = b     # a ????????? b ?????????
    a.R = b.L   # a ???????????? b ??????????????????
    a.R.P = a   # a ?????????????????? a ?????????
    b.L = a     # b ???????????? a ?????????
    if b.P != NoVal: # b ??????????´????????????????
       if b.P.L == a: # b ?????????????????? a ??????
            b.P.L = b    # b ?????????????????? b ?????????
       elif b.P.R == a: # b ?????????????????? a ??????
            b.P.R = b    # b ?????????????????? b ?????????
    return b

def Restruct(r):
    """ ????§???? """
    
    if isinstance(r, Node) == False: # ?????§??????
        return
    
    if r.C == Black: # ???????????????????????????????????????
        return

    p = r.P
    if p == NoVal: # ???????????????
        r.C = Black # ???????????????????????????
        return

    if p.C == Red: # ????????????
        if p.P.L == p: # ????????????
            if p.L == r: # ???????????????
                p = RotateR(p) # LL:????????¢
            else: # ???????????????
                RotateL(r) # LR: 1.????????¢
                p = RotateR(p) # LR: 2.????????¢
        else: # ????????????
            if r.P.L == r: # ???????????????
                RotateR(r) # RL: 1.????????¢
                p = RotateL(p) # RL: 2.????????¢
            else: # ???????????????
                p = RotateL(p) ## LR: ????????¢
        if p.C == Red: # ??°???????????????????????°???????????????????§????
            Restruct(p)

def main():
    """ ????????? """
    num = int(input().strip())
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    root = NoVal
    
    for i in cmds:
        if i[0] == "i":
            r = Insert(root, i[7:])
            if isinstance(root, Node) == False:
                root = r
        elif i[0] == "f":
            ret = Find(root, i[5:])
            if ret == True:
                print("yes")
            else:
                print("no")

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??\????????????????????????????°?????????????????????????????£??????????????????????

insert str: ????????? str ??????????????????
find str: ????????? str ?????????????????´??? 'yes'??¨????????????????????´??? 'no'??¨???????????????

??????????????????????????????'A', 'C', 'G', 'T' ???????¨????????????????????§????????????????
1 ??? ?????????????????? ??? 12  n ??? 1,000,000

"""
import sys
import random

class Node:
    """ Treap???????´?????????? """

    def __init__(self, value, usen):
        """ ????????????????????? """
        self.V = value # ???
        self.U = usen # ?????????
        self.L = None # ??????
        self.R = None # ??????

def Find(t, value):
    """ ????????¨??¢?´¢ """
    
    if t is not None:
        if value == t.V: # ?????????
#            print("Finded p:'{}' v:'{}'".format(t.V, value))
            return True

        elif value < t.V: # ?°????????????§??????
#            print("Left Search p:'{}' v:'{}'".format(t.V, value))
            return Find(t.L, value)

        elif value > t.V: # ??§???????????§??????
#            print("Right Search p:'{}' v:'{}'".format(t.V, value))
            return Find(t.R, value)

#    print("Not Exists v:'{}'".format(value))
    return False

def Insert(t, value):
    """ ????????¨???????????? """

    if t is None: # ???????????????
        t = Node(value, random.random())
#        print("\tInsert '{}'".format(value))
        return t # ????´??????\

    if value < t.V: # ?°???????
#        print("\tto Left p:'{}' v:'{}'".format(t.V, value))
        t.L = Insert(t.L, value) # ??????????´??????\
        if t.U > t.L.U:
            return RotateR(t)

    elif value > t.V: # ??§??????
#        print("\tto Right p:'{}' v:'{}'".format(t.V, value))
        t.R = Insert(t.R, value) # ?????????
        if t.U > t.R.U:
            return RotateL(t)

#    elif value == t.V: # ???????????????????????????????????§??????
#        print("\tExists p:'{}' v:'{}'".format(t.V, value))

    return t

def RotateR(a):
    """ ????????¨???????????¢ a:??? b:??°????????? """
    if a.L is None: # ??????????????????
        return a
    b = a.L     # b ??? a ?????????
    a.L = b.R   # a ???????????? b ??????????????????
    b.R = a     # b ???????????? a ?????????
#    print("\t\tRotateR a:{} b:{} b.R.V:{}".format(a.V, b.V, b.R.V))
    return b

def RotateL(a):
    """ ????????¨???????????¢ a:??? b:??°????????? """

    if a.R is None: # ??????????????????
        return a
    b = a.R     # b ??? a ?????????
    a.R = b.L   # a ???????????? b ??????????????????
    b.L = a     # b ???????????? a ?????????
#    print("\t\tRotateL a:{} b:{} b.L.V:{}".format(a.V, b.V, b.L.V))
    return b

def GetList(t, a):
    if t is not None:
        a.append(t.V)
        GetList(t.L, a)
        GetList(t.R, a)

def main():
    """ ????????? """
    random.seed() # ??±??°?????????
    num = int(input().strip())
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    root = None
    
    for i in cmds:
#        print("cmd:{} tree:{}".format(i,root))
        if i[0] == "i":
            root = Insert(root, i[7:])
        elif i[0] == "f":
            ret = Find(root, i[5:])
            if ret == True:
                print("yes")
            else:
                print("no")
#        a = []
#        GetList(root,a)
#        print(a)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for data in statements:
    if data[0] == 'insert':
        inserts.append(data[1])
        continue
    print('yes' if data[1] in inserts else 'no')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

class Hash:
    def __init__(self):
        self.m = 1000003
        self.T = [None] * self.m
    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.T[j] == None:
                self.T[j] = key
                break
            else:
                i = i + 1
    def search(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.T[j] == key:
                return j
            elif self.T[j] == None:
                return None
            else:
                i += 1
        return self.T[self.h(key)]
    def h(self, key, i):
        ki = self.key2int(key)
        h1 = ki % self.m
        h2 = i * (1 + (ki % (self.m - 1)))
        return (h1 + h2) % self.m
    def key2int(self, key):
        return sum([['A', 'C', 'G', 'T'].index(s) + 1 for s in key])

h = Hash()
for i in range(n):
    op, st = input().split()
    if op == 'insert':
        h.insert(st)
    else:
        if h.search(st):
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

class Hash:
    def __init__(self):
        self.m = 1000003
        self.T = [None] * self.m
    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.T[j] == None:
                self.T[j] = key
                break
            else:
                i = i + 1
    def search(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.T[j] == key:
                return j
            elif self.T[j] == None:
                return None
            else:
                i += 1
        return self.T[self.h(key)]
    def h(self, key, i):
        ki = self.key2int(key)
        h1 = ki % self.m
        h2 = i * (1 + (ki % (self.m - 1)))
        return (h1 + h2) % self.m
    def key2int(self, key):
        p = 1
        ret = 0
        for s in key:
            a = ['A', 'C', 'G', 'T'].index(s) + 1
            ret += p * a
            p *= 5
        return ret

h = Hash()
for i in range(n):
    op, st = input().split()
    if op == 'insert':
        h.insert(st)
    else:
        if h.search(st):
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())

dict = []
for i in range(n):
    command, word = raw_input().split()
    if command == 'insert':
        dict.append(word)
    else:
        try:
            dict.index(word)
            print 'yes'
        except:
            print 'no'
            pass

Submission status: Time Limit Exceeded

Solution code:
ls = []
for i in range(int(input())):
    command, text = input().split()
    if command == "insert":
        ls.append(text)

    else:
        if ls.count(text) >= 1:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input()
ls = []
line = map(lambda x:x.split(), sys.stdin.readlines())
for i in line:
    if i[0] == "insert":
        ls.append(i[1])
    else:
        print("yes" if i[1] in ls else "no")