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:
n=int(input())
list=[]
ans=[]
for i in range(n):
    A=input().split()
    if A[0]=="insert":
        list.insert(0,A[1])
    elif A[0]=="find":
        a=A[1]
        if list.count(a)>0:
            ans.append("yes")
        else:
            ans.append("no")
for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

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

from collections import deque

n = int(input())
word = deque()

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

Submission status: Time Limit Exceeded

Solution code:

class HashSet:
	
	def __init__(self):
		self.M=1046527
		self.H=['']*self.M

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

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

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

	def h2(self,key):
		return 1+(key%(self.M-1))
	
	def find(self,strng):
		key=self.get_key(strng)
		i=0
		while True:
			h=(self.h1(key)+i*self.h2(key))%self.M
			if self.H[h]==strng:
				return True
			elif self.H[h]=='':
				return False
			i+=1
		return False

	def insert(self,strng):
		key=self.get_key(strng)
		i=0
		while True:
			h=(self.h1(key)+i*self.h2(key))%self.M
			if self.H[h]==strng:
				return
			elif self.H[h]=='':
				self.H[h]=strng
				return
		return
		
hset = HashSet()

n=int(input())
for i in range(n):
	cmd,strng=map(str,input().split())
	if cmd=='insert':
		hset.insert(strng)
	elif cmd=='find':
		if hset.find(strng)==True:
			print('yes')
		else:
			print('no')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    repo = []
    for i in range(n):
        command, acgt = input().split()
        if command[0] == 'i':
            if acgt not in repo:
                repo.append(acgt)
        elif command[0] == 'f':
            if acgt in repo:
                print('yes')
            else:
                print('no')
    return


main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    lines = sys.stdin.readlines()
    n = int(lines[0])

    repo = []
    for i in range(1, n + 1):
        command, acgt = lines[i].split()
        if command[0] == 'i':
            if acgt not in repo:
                repo.append(acgt)
        elif command[0] == 'f':
            if acgt in repo:
                print('yes')
            else:
                print('no')
    return


main()

Submission status: Time Limit Exceeded

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

for _ in range(n):
    cmd,input_str = input().split()
    if   cmd == 'insert':
        str_list.append(input_str)
    elif cmd == 'find':
        if input_str in str_list:
            print('yes')
        else:
            print('no')

Submission status: Time Limit Exceeded

Solution code:
dc = []
result = []
n = int(input())
for i in range(n):
    op, item = input().split()
    if(op=='insert'):
        dc.append(item)
    elif(op=='find'):
        for i in range(len(dc)):
            if(item==dc[i]):
                result.append('yes')
                break
        else:
            result.append('no')
    else:
        break
print(*result, sep='\n')

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic = []
for i in range(n):
    Input = str(input())
    Input = Input.split(" ")
    if Input[0] == "insert":
        dic.append(Input[1])
    elif Input[0] == "find":
        find = Input[1] in dic
        if find == True:
            print("yes")
        else:
            print("no")
    else:
        print("Error:予期しないコマンド")
        break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dic = []
for i in range(n):
    Input = str(input())
    Input = Input.split(" ")
    if Input[0] == "insert":
        dic.append(Input[1])
    elif Input[0] == "find":
        find = Input[1] in dic
        if find == True:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def getChar(letter):
    if letter == 'A':
        return 1
    elif letter == 'G':
        return 2
    elif letter == 'C':
        return 3
    elif letter == 'T':
        return 4

def getKey(string):
    omega = list(string)
    sum = 0
    for letter in omega:
        sum += getChar(letter)
    return sum%100

def insert(dic,letter):
    key = getKey(letter)
    dic[key].append(letter)

def find(dic,letter):
    key = getKey(letter)
    if letter in dic[key]:
        print("yes")
    else:
        print("no")

num = int(input())
dic = [[] for i in range(100)]

for i in range(num):
    command,obj = map(str,input().split(" "))
    if command == "insert":
        insert(dic,obj)
    elif command == "find":
        find(dic,obj)

Submission status: Time Limit Exceeded

Solution code:
def getChar(letter):
    if letter == 'A':
        return 1
    elif letter == 'G':
        return 2
    elif letter == 'C':
        return 3
    elif letter == 'T':
        return 4

def getKey(string):
    omega = list(string)
    sum = 0
    for letter in omega:
        sum += getChar(letter)
    return sum%1000

def insert(dic,letter):
    key = getKey(letter)
    dic[key].append(letter)

def find(dic,letter):
    key = getKey(letter)
    if letter in dic[key]:
        print("yes")
    else:
        print("no")

num = int(input())
dic = [[] for i in range(1000)]

for i in range(num):
    command,obj = map(str,input().split(" "))
    if command == "insert":
        insert(dic,obj)
    elif command == "find":
        find(dic,obj)

Submission status: Time Limit Exceeded

Solution code:
def getChar(letter):
    if letter == 'A':
        return 1
    elif letter == 'G':
        return 2
    elif letter == 'C':
        return 3
    elif letter == 'T':
        return 4

def getKey(string):
    omega = list(string)
    sum = 0
    for letter in omega:
        sum += getChar(letter)
    return sum%100000

def insert(dic,letter):
    key = getKey(letter)
    dic[key].append(letter)

def find(dic,letter):
    key = getKey(letter)
    if letter in dic[key]:
        print("yes")
    else:
        print("no")

num = int(input())
dic = [[] for i in range(100000)]

for i in range(num):
    command,obj = map(str,input().split(" "))
    if command == "insert":
        insert(dic,obj)
    elif command == "find":
        find(dic,obj)

Submission status: Time Limit Exceeded

Solution code:
def getChar(letter):
    if letter == 'A':
        return 1
    elif letter == 'G':
        return 2
    elif letter == 'C':
        return 3
    elif letter == 'T':
        return 4

def getKey(string):
    omega = list(string)
    sum = 0
    for letter in omega:
        sum += getChar(letter)
    return sum%97

def insert(dic,letter):
    key = getKey(letter)
    dic[key].append(letter)

def find(dic,letter):
    key = getKey(letter)
    if letter in dic[key]:
        print("yes")
    else:
        print("no")

num = int(input())
dic = [[] for i in range(97)]

for i in range(num):
    command,obj = map(str,input().split(" "))
    if command == "insert":
        insert(dic,obj)
    elif command == "find":
        find(dic,obj)

Submission status: Time Limit Exceeded

Solution code:
def getChar(letter):
    if letter == 'A':
        return 1
    elif letter == 'G':
        return 2
    elif letter == 'C':
        return 3
    elif letter == 'T':
        return 4

def getKey(string):
    omega = list(string)
    sum = 0
    for letter in omega:
        sum += getChar(letter)
    return sum%1046527

def insert(dic,letter):
    key = getKey(letter)
    dic[key].append(letter)

def find(dic,letter):
    key = getKey(letter)
    if letter in dic[key]:
        print("yes")
    else:
        print("no")

num = int(input())
dic = [[] for i in range(1046527)]

for i in range(num):
    command,obj = map(str,input().split(" "))
    if command == "insert":
        insert(dic,obj)
    elif command == "find":
        find(dic,obj)

Submission status: Time Limit Exceeded

Solution code:
d = []

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:
from bisect import bisect_left, insort_left

def index(A, x):
	i = bisect_left(A, x)
	if i != len(A) and A[i] == x:
		return i
	else:
		return -1


d = []
n = int(input())
for i in range(n):
	c, s = input().split()
	if c=='insert':
		insort_left(d, s)
	elif c=='find':
		if index(d, s)>=0:
		 	print('yes')
		else:
			print('no')

Submission status: Time Limit Exceeded

Solution code:
from copy import copy

def find(A, x, i=1):
	B = copy(A)
	for i in range(len(x)):
		B = [b for b in B if x[i:i+1]==b[i:i+1]]
		if B==[]:
			return False
	if x in B:
		return True
	else:
		return False


d = []
n = int(input())
for i in range(n):
	c, s = input().split()
	if c=='insert':
		d.append(s)
	elif c=='find':
		if find(d, s):
		 	print('yes')
		else:
			print('no')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
dic=[]
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic.append(s)
    else:
        print("yes" if s in dic else "no")

Submission status: Time Limit Exceeded

Solution code:
m = int(input())
T = [None]*m

def trans(S):
  tmp = ""
  for i in range(len(S)):
    tmp += str(ord(S[i]))
  return int(tmp)

def h1(key):
  return trans(key) % m

def h2(key):
  return 1 + (trans(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] == 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:
      print("yes")
      return j
    elif T[j] == None or i >= m:
      print("no")
      return None
    else:
      i += 1

for i in range(m):
  cmd, obj = input().split()
  if cmd == "insert":
    insert(T, obj)
  if cmd == "find":
    search(T, obj)

Submission status: Time Limit Exceeded

Solution code:
m = int(input())
T = [None]*m

def trans(S):
  tmp = ""
  for i in range(len(S)):
    if S[i] == "A":
      char = 1
    elif S[i] == "G":
      char = 2
    elif S[i] == "C":
      char = 3
    else:
      char = 4
    tmp += str(char)
  return int(tmp)

def h1(key):
  return trans(key) % m

def h2(key):
  return 1 + (trans(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] == 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:
      print("yes")
      return j
    elif T[j] == None or i >= m:
      print("no")
      return None
    else:
      i += 1

for i in range(m):
  cmd, obj = input().split()
  if cmd == "insert":
    insert(T, obj)
  if cmd == "find":
    search(T, obj)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    n = int(raw_input())
    dic = []
    for i in range(n):
        t = raw_input().split()
        if t[0] == "insert":
            dic.append(t[1])
        if t[0] == "find":
            if(t[1] in dic):
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
def BinarySearch(A, n, key):
    left = 0
    right = n
    mid = 0
    while left < right:
        mid = (left+right)/2
        if A[mid] == key:
            return "FOUND"
        elif A[mid] > key:
            right = mid
        else:
            left = mid + 1
    return left

if __name__ == "__main__":
    n = int(raw_input())
    dic = []
    num = 0
    for i in range(n):
        t = raw_input().split()
        if t[0] == "insert":
            point = BinarySearch(dic, num, t[1])
            if point != "FOUND":
                dic.insert(point, t[1])
                num += 1
        if t[0] == "find":
            if(BinarySearch(dic, num, t[1]) == "FOUND"):
                print("yes")
            else:
                print("no")

Submission status: Time Limit Exceeded

Solution code:
class TrieTree:
    def __init__(self):
        self.flag = 0
        self.next = [None, None, None, None]

def judge(c):
    if c == "A":
        return 0
    elif c == "C":
        return 1
    elif c == "G":
        return 2
    else:
        return 3

def find(key, trie):

    if(len(key)>=1):
        index = judge(key[0])
	if(trie.next[index]!=None):
            find(key[1:], trie.next[index])
        else:
            print("no")
    else:
        if(trie.flag):
            print("yes")
        else:
            print("no")

def insert(key, trie):
    if(len(key)>=1):
        index = judge(key[0])
        if(trie.next[index]!=None):
            insert(key[1:], trie.next[index])
        else:
            trie.next[index] = TrieTree()
            insert(key[1:], trie.next[index])
    else:
	trie.flag = 1

if __name__ == "__main__":

    root = TrieTree()
    n = int(raw_input())
    for i in range(n):
        com = raw_input().split()
        if(com[0][0] == "i"):
            insert(com[1], root)
        else:
            find(com[1], root)

Submission status: Time Limit Exceeded

Solution code:
class TrieTree:
    def __init__(self):
        self.flag = 0
        self.next = [None, None, None, None]

def judge(c):
    if c == "A":
        return 0
    elif c == "C":
        return 1
    elif c == "G":
        return 2
    else:
        return 3

def find(key, trie):

    if(len(key)>=1):
        index = judge(key[0])
        if(trie.next[index]==None):
            print("no")
        else:
            find(key[1:], trie.next[index])
    else:
        if(trie.flag):
            print("yes")
	else:
            print("no")

def insert(key, trie):
    if(len(key)>=1):
	index = judge(key[0])
	if(trie.next[index]==None):
            trie.next[index] = TrieTree()
            insert(key[1:], trie.next[index])
        else:
            insert(key[1:], trie.next[index])
    else:
        trie.flag = 1

if __name__ == "__main__":

    root = TrieTree()
    n = int(raw_input())
    for i in range(n):
        com = raw_input().split()
        if(com[0][0] == "i"):
            insert(com[1], root)
        else:
            find(com[1], root)

Submission status: Time Limit Exceeded

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C
# Dictionary
# Result:
import sys

class Dictionary(object):
    def __init__(self, length):
        self.lst_len = length
        self.lst = [''] * self.lst_len

    def __str__(self):
        return str(self.lst)

    def insert(self, val):
        code = self.__code(val)
        i = 0
        while True:
            j = self.__hash(code, i)
            if self.lst[j] == '':
                self.lst[j] = val
                return j
            else:
                i += 1

    def find(self, val):
        code = self.__code(val)
        i = 0
        while True:
            j = self.__hash(code, i)
            if self.lst[j] == val:
                return j
            elif self.lst[j] == '' and i >= self.lst_len:
                return -1
            else:
                i += 1

    def __hash(self, code, i):
        h1 = self.__hash1(code)
        h2 = self.__hash2(code)
        return (h1 + i * h2) % self.lst_len

    def __hash1(self, code):
        return code % self.lst_len

    def __hash2(self, code):
        return 1 + (code % (self.lst_len - 1))

    def __code(self, val):
        code = 0
        for s in val:
            code = code << 2
            if s == 'A':
                code += 0
            elif s == 'C':
                code += 1
            elif s == 'G':
                code += 2
            elif s == 'T':
                code += 3
        return code


### main
op_len = int(sys.stdin.readline().rstrip())
mydict = Dictionary(op_len)
for opi in range(0, op_len):
    opr, string = sys.stdin.readline().rstrip().split(' ')
    if opr == 'insert':
        mydict.insert(string)
    elif opr == 'find':
        if mydict.find(string) >= 0:
            print 'yes'
        else:
            print 'no'
    #print mydict

Submission status: Time Limit Exceeded

Solution code:
dict=[]
n=int(raw_input())
for i in range(n):
	list=raw_input().split()
	if list[0]=='insert':
		dict.append(list[1])
	elif list[0]=='find':
		try:
			dict.index(list[1])
			print 'yes'
		except:
			print 'no'

Submission status: Time Limit Exceeded

Solution code:
count=int(raw_input())
l=[]
n=[]
for i in xrange(count):
	a,b=raw_input().split()
	if a=='insert':
		l.append(b)
	elif a=='find':
		if b in l:
			n.append('yes')
		else:
			n.append('no')

for i in n:
	print i

Submission status: Time Limit Exceeded

Solution code:
def hash1(m,key):
    return key % m

def hash2(m,key):
    return 1 +  key % ( m -1 )

def hash(m,key,i):
    return (hash1(m,key) + i * hash2(m,key) ) % m

def insert(T,key):
    i = 0
    l = len(T)
    while True:
        h = hash(l,key,i)
        if (T[h] is None ):
            T[h] = key
            return h
        else:
            i += 1

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

def find(T,key):
    a = search(T,key)
    if(a == -1):
        print('no')
    else:
        print('yes')

dict = {'A' : '1', 'C' : '2', 'G' : '3', 'T' : '4'}
data = []
T = [None]*4444
n = int(input())


while n > 0:
    st = input()
    d = list(st.split())

### convert key to num(1~4)
    tmp_key = ''
    for x in list(d[1]):
        tmp_key += dict[x]

    data.append([d[0],int(tmp_key)])
    n -= 1
for com in data:
    if(com[0] == 'insert'):
        insert(T,com[1]) 
    else:
        find(T,com[1])

Submission status: Time Limit Exceeded

Solution code:
def hash1(m,key):
    return key % m

def hash2(m,key):
    return 1 +  key % ( m -1 )

def hash(m,key,i):
    return (hash1(m,key) + i * hash2(m,key) ) % m

def insert(T,key):
    i = 0
    l = len(T)
    while True:
        h = hash(1046527,key,i)
        if (T[h] == None ):
            T[h] = key
            return h
        else:
            i += 1

def search(T,key):
    l = len(T)
    i = 0
    while True:
        h = hash(1046527,key,i)
        if(T[h] == key):
            return h
        elif(T[h] is None or h >= l):
            return -1
        else:
            i += 1

def find(T,key):
    a = search(T,key)
    if(a == -1):
        print('no')
    else:
        print('yes')

dict = {'A' : '1', 'C' : '2', 'G' : '3', 'T' : '4'}
data = []
T = [None]*1046527
n = int(input())


while n > 0:
    st = input()
    d = list(st.split())

### convert key to num(1~4)
    tmp_key = ''
    for x in list(d[1]):
        tmp_key += dict[x]

    data.append([d[0],int(tmp_key)])
    n -= 1
for com in data:
    if(com[0] == 'insert'):
        insert(T,com[1]) 
    else:
        find(T,com[1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
#1_4_C
n = int(input())
dic = []
for i in range(n):
    cmd, word = input().split()
    if cmd == "find":
        if word in dic:
            print("yes")
        else:
            print("no")
    else:
        dic.append(word)

Submission status: Time Limit Exceeded

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


def process(commands):
    d = []
    for c in commands:
        cpair = c.split()
        if cpair[0] == "insert":
            d.append(cpair[1])
        elif cpair[0] == "find":
            r = "yes" if cpair[1] in d else "no"
            print(r)


def main():
    n = int(input())
    commands = [input() for i in range(n)]
    process(commands)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

import bisect


def isincluded(array, value):
    i = bisect.bisect_left(array, value)
    if i != len(array) and array[i] == value:
        return True
    else:
        return False


def process(commands):
    d = []
    for c in commands:
        cpair = c.split()
        if cpair[0] == "insert":
            bisect.insort_left(d, cpair[1])
        elif cpair[0] == "find":
            r = "yes" if isincluded(d, cpair[1]) else "no"
            print(r)


def main():
    n = int(input())
    commands = [input() for i in range(n)]
    process(commands)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


from collections import deque

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

Submission status: Time Limit Exceeded

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


from collections import deque

q_list = deque()
n = int(input())
tmp = [input().split() for i in range(n)]

for i in tmp:
    cmd, v = i
    if cmd == "find":
        if v in q_list:
            print("yes")
        else:
            print ("no")
    else:
        q_list.append(v)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ind = {"A":0,"C":1,"G":2,"T":3}
dic = [[],[],[],[]]
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[ind[t[1][0]]].append(t[1])
    else:
        if t[1] in dic[ind[t[1][0]]]:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
dic = {"A":[],"C":[],"G":[],"T":[]}
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1][0]].append(t[1])
    else:
        if t[1] in dic[t[1][0]]:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
dic = []
ind = {"A":0,"C":1,"G":2,"T":3}
dic = [[[],[],[],[]] for i in range(12)]
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[len(t[1])-1][ind[t[1][0]]].append(t[1])
    else:
        if t[1] in dic[len(t[1])-1][ind[t[1][0]]]:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

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

for _ in range(n):
    opr, word = input().strip().split()
    word = int(word.translate(str.maketrans('ACGT', '1234')), base=5)
    if opr.startswith('i'):
        l.append(word)
    else:
        print('yes' if word in l else 'no')

Submission status: Time Limit Exceeded

Solution code:
def insert(S, string):
    S.append(string)

def find(S, string):
    cnt = 0
    for i in range(len(S)):
        cnt = cnt + 1
        if S[i] == string:
            print 'yes'
            break
        elif cnt == len(S):
            print 'no'

    if cnt == 0:
        print 'no'

n = input()

S = []

for i in range(n):
    tmp1, tmp2  = map(str,raw_input().split())
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print 'error!'

Submission status: Time Limit Exceeded

Solution code:
def insert(S, string):
    S.add(string)

def find(S, string):
    cnt = 0
    for i in range(len(S)):
        cnt = cnt + 1
        if string in S:
            print 'yes'
            break
        elif cnt == len(S):
            print 'no'
    if cnt == 0:
        print 'no'

n = input()

S = set([])

for i in range(n):
    tmp1, tmp2  = map(str,raw_input().split())
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print 'error!'

Submission status: Time Limit Exceeded

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

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.append(arg)
    elif cmd == "find":
        if arg in dictionary:
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
def binary_search(dic, word, imin, imax):
    if imax < imin:
        return "no"
    imid = imin + (imax - imin) // 2
    if dic[imid] > word:
        return binary_search(dic, word, imin, imid - 1)
    elif dic[imid] < word:
        return binary_search(dic, word, imid + 1, imax)
    else:
        return "yes"


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

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.append(arg)
        dictionary.sort()
    elif cmd == "find":
        print(binary_search(dictionary, arg, 0, len(dictionary) - 1))

Submission status: Time Limit Exceeded

Solution code:
n=input()
wlist=[]
for i in range(n):
    a=raw_input().split()
    if a[0][0]=="i":
        wlist.append(a[1])
    else :
        if a[1] in wlist :
            print("yes")
        else:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
n=input()
wdic={}
for i in range(n):
    flag=False
    a=raw_input().split()
    if a[0][0]=="i":
        wdic[a[1]]=1
    else:
        for i in wdic.keys():
            if a[1]==i and wdic[i]==1:
                print("yes")
                flag=True
                break
        if flag==False:
            print("no")

Submission status: Time Limit Exceeded

Solution code:
A = []
n = input()

for i in range(n):
    command = raw_input().split()

    if command[0] == 'insert':
        A.insert(0, command[1])
    elif command[0] == 'find':
        if A.count(command[1]) != 0:
            print "yes"
        else:
            print "no"

Submission status: Time Limit Exceeded

Solution code:
A = []
n = input()

for i in xrange(n):
    command = raw_input().split()

    if command[0] == 'insert':
        A.insert(0, command[1])
    elif command[0] == 'find':
        if A.count(command[1]) != 0:
            print "yes"
        else:
            print "no"

Submission status: Time Limit Exceeded

Solution code:
A = []
n = input()

for i in xrange(n):
    command = raw_input().split()

    if command[0] == 'insert':
        A.insert(0, command[1])
    elif command[0] == 'find':
        if command[1] in A:
            print "yes"
        else:
            print "no"

Submission status: Time Limit Exceeded

Solution code:
A = []
n = input()

for i in xrange(n):
    command = raw_input().split()

    if command[0] == 'insert':
        A.append(command[1])
    elif command[0] == 'find':
        if command[1] in A:
            print "yes"
        else:
            print "no"

Submission status: Time Limit Exceeded

Solution code:
import sys

class HashTable:
    def __init__(self):
        self.table = [None] * 4
        self.flag = False

class Dictionary:
    def __init__(self):
        self.hashTable = HashTable()

    def insert(self, key):
        table = self.hashTable
        for c in key:
            hash = self.toHash(c)
            if table.table[hash] is None:
                table.table[hash] = HashTable()
            table = table.table[hash]
        table.flag = True

    def find(self, key):
        table = self.hashTable
        for c in key:
            hash = self.toHash(c)
            if table.table[hash] is None:
                return False
            table = table.table[hash]
        if table.flag:
            return True
        else:
            return False

    def toHash(self, key):
        key = key.replace("A", "0")
        key = key.replace("C", "1")
        key = key.replace("G", "2")
        key = key.replace("T", "3")
        return int(key)

if __name__ == "__main__":
    dic = Dictionary()
    lines = sys.stdin.readlines()
    del lines[0]
    for command in lines:
        key = command.split()[1]
        if command[0] == "i":
            dic.insert(key)
        else:
            if dic.find(key):
                print "yes"
            else:
                print "no"

Submission status: Time Limit Exceeded

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

n = int(raw_input())
dic = []
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.append(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"

Submission status: Time Limit Exceeded

Solution code:
dic = set()
n = int(input())
for i in range(n):
    ins, op = input().split()
    if ins == 'insert':
        dic = dic | {op}
    if ins == 'find':
        print({True: 'yes', False: 'no'}[op in dic])

Submission status: Time Limit Exceeded

Solution code:
dic = tuple()
n = int(input())
for i in range(n):
    ins, op = input().split()
    if ins == 'insert':
        dic += (op,)
    if ins == 'find':
        print({True: 'yes', False: 'no'}[op in dic])

Submission status: Time Limit Exceeded

Solution code:
import sys
dic = set()
L = sys.stdin.readlines()

for Ins in L[1:]:
    ins, op = Ins.split()
    if ins == 'insert':
        dic = dic | {op}
    if ins == 'find':
        print({True: 'yes', False: 'no'}[op in dic])