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: Runtime Error

Solution code:
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: Runtime Error

Solution code:
n = int( raw_input( ) )
dic = ()
for i in range( n ):
	cmd, word = raw_input( ).split( " " )
	if "insert" == cmd:
		dic[ word ] = True
	elif "find" == cmd:
		if word in dic:
			print( "yes" )
		else:
			print( "no" )

Submission status: Runtime Error

Solution code:
n = int(raw_input())
d = ""
for i in range(n):
    p,q = map(str,raw_input().split())
    if p == "insert":
        d = Insert(d,q)
    elif p == "find":
        rst = Find(d,q)
        print rst

def Insert(d,v):
    d += v
    return d

def Find(d,v):
    r = d.find(v)
    if(r >= 0):
        return "yes"
    else:
        return "no"

Submission status: Runtime Error

Solution code:
n = int(raw_input())
d = ""
for i in range(n):
    p,q = map(str,raw_input().split())
    if p == "insert":
        d += q
    elif p == "find":
        r = d.find(q)
        if(r >= 0):
            return "yes"
        else:
            return "no"

Submission status: Runtime Error

Solution code:
import sys


def search_combination(elements, target):
    if len(elements) == 0:
        if target == 0:
            return True
        else:
            return False

    return search_combination(elements[1:], target - elements[0]) or search_combination(elements[1:], target)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    elements = [int(x) for x in lines[1].strip().split(" ")]
    targets = [int(x) for x in lines[3].strip().split(" ")]

    for target in targets:
        result = "yes" if search_combination(elements, target) else "no"
        print(result)

Submission status: Runtime Error

Solution code:
n = int(raw_input().strip())
commands = []
for i in range(n):
    commands.append(raw_input().strip())


d = [False]*16777220

def hash(s):
    ret = 0
    i = 0
    for dg in s:
        if dg == 'A':
            ret += 1 * 10**i
        elif dg == 'C':
            ret += 2 * 10**i
        elif dg == 'G':
            ret += 3 * 10**i
        elif dg == 'T':
            ret += 4 * 10**i
        i += 1
    return ret

def insert(d,s):
    h = hash(s)
    d[h] = True

def find(d,s):
    h = hash(s)
    if d[h]: print 'yes'
    else: print 'no'

for c in commands:
    if c[0] == 'i':
        insert(d,c[7:])
    else:
        find(d,c[5:])

Submission status: Runtime Error

Solution code:
class HashTable:
    def __init__(self, size = 1000003):
        self.size = size
        self.hash_table = [None] * size

    def _gen_key(self, val):
        h1 = hash(val) % self.size
        h2 = 1 + (hash(val) % (self.size - 1))
        for i in range(h1, self.size, h2):
            if (self.hash_table[i] == None) or (self.hash_table[i] == val):
                return i

    def insert(self, val):
        key = self._gen_key(val)
        self.hash_table[key] = val

    def search(self, val):
        key = self._gen_key(val)
        if self.hash_table[key]:
            return True
        else:
            return False


import sys

n = int(sys.stdin.readline())

simple_dict = HashTable()

ans = ''

for i in range(n):
    operation = sys.stdin.readline()
    if operation[0] == 'i':
        simple_dict.insert(operation[7:])
    else:
        if simple_dict.search(operation[5:]):
            ans += 'yes'
        else:
            ans += 'no'
        ans += '\n'

print(ans, end = '')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

  count = 0
  n = input()

  for i in range(n):
    com,str = [str, raw_input().split()]
    if com == 'insert':
      dic[count] = str
      count += 1
    elif com == 'find':
      for j in range(count-1):
        if dic[j] == str:
          print 'yes'
        else:
          print 'no'

Submission status: Runtime Error

Solution code:
  count = 0
  n = input()

  for i in range(n-1):
    com, str = map(str, raw_input().split())
    if com == 'insert':
      dic[count] = str
      count += 1
    elif com == 'find':
      for j in range(count-1):
        if dic[j] == str:
          print 'yes'
          break
        elif j == count-1:
          print 'no'
          break

Submission status: Runtime Error

Solution code:
count = 0
n = input()
dic = []

for i in range(n):
  com, str = map(str, raw_input().split())
  if com == 'insert':
    dic[count] = str
    count += 1
  elif com == 'find':
    for j in range(count-1):
      if dic[j] == str:
        print 'yes'
        break
      elif j == count-1:
        print 'no'
        break

Submission status: Runtime Error

Solution code:
n = input()
dic = set()
 
for i in range(n):
  com, st = map(str, raw_input().split())
  if com == 'insert':
    dic.add(st)
  elif com == 'find':
    for j in dic:
      if j == st:
        print 'yes'
        break
      elif j == count-1:
        print 'no'
        break

Submission status: Runtime Error

Solution code:
import sys

class dictionary:
    def __init__(self):
        self.lst = [None] * 444444444445

    def insert(self, key):
        hash = self.toHash(key)
        self.lst[hash] = 1

    def find(self, key):
        hash = self.toHash(key)
        if self.lst[hash] is not None:
            return True
        else:
            return False

    def toHash(self, key):
        key = key.replace("A", "1")
        key = key.replace("C", "2")
        key = key.replace("G", "3")
        key = key.replace("T", "4")
        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: Runtime Error

Solution code:
class Dict(object):

    m1 = 2 ** 9 - 1
    m2 = 3

    def __init__(self):
        self._dict = ["" for _ in range(self.m1)]

    def insert(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == "":
                self._dict[ix] = k
                return
            else:
                i += 1

    def find(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == k:
                return ix
            elif self._dict[ix] == "":
                return -1
            else:
                i += 1

    def _h(self, k, i):
        return self._h1(k) + i * self._h2(k)

    def _h1(self, k):
        return k % self.m1

    def _h2(self, k):
        return k % self.m2 + 1


def to_int(s):
    _s = s[::]

    ret = 0
    i = 1
    for e in _s:
        if e == 'A':
            ret += 1 * i
        elif e == 'C':
            ret += 2 * i
        elif e == 'G':
            ret += 3 * i
        elif e == 'T':
            ret += 4 * i
        i *= 4

    return ret


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

    d = Dict()

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

        if cmd == "insert":
            d.insert(to_int(val))
        else:
            ans = "yes" if d.find(to_int(val)) != -1 else "no"
            print(ans)

Submission status: Runtime Error

Solution code:
m1 = 1046527
_dict = [""] * m1


def insert(k):
    i = 0

    while True:
        ix = _h(k, i)
        if _dict[ix] == "":
            _dict[ix] = k
            return
        else:
            i += 1


def find(k):
    i = 0

    while True:
        ix = _h(k, i)
        if _dict[ix] == k:
            return True
        elif _dict[ix] == "":
            return False
        else:
            i += 1

    return False


def _h(k, i):
    return ((k % m1) + i * (1 + k % (m1 - 1))) % m1




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(strings):
    Sum = 0
    p = 1
    for i in xrange(len(strings)):
        Sum += p * getChar(strings[i])
        p *= 5

    return Sum


def to_int(s):
    ret = 0
    i = 1
    for j in range(len(s)):
        e = s[len(s) - j - 1]

        if e == 'A':
            ret += 1 * i
        elif e == 'C':
            ret += 2 * i
        elif e == 'G':
            ret += 3 * i
        elif e == 'T':
            ret += 4 * i
        i *= 5

    return ret


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

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

        if cmd[0] == "i":
            insert(getKey(val))
        else:
            ans = "yes" if find(getKey(val)) else "no"
            print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
sample_input = list(range(3))
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] = ''''''
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
def convert_ACGT_to_int(acgt_str):
        result = 0
        for char in acgt_str:
            result *= 5
            if char == 'A':
                result += 1
            elif char == 'C':
                result += 2
            elif char == 'G':
                result += 3
            elif char == 'T':
                result += 4
            else:
                assert False
        
        return result


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return True
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if increasing_list[index_min] == elem:
        return True
    elif increasing_list[index_max] == elem:
        return True
    else:
        return False


class Dict (object):
    
    def __init__(self):
        self.data = []
        pass
        
    def insert(self, item):
        self.data.append(item)
        for index in range(len(self.data)-1, 0, -1):
            if self.data[index] < self.data[index-1]:
                tmp = self.data[index]
                self.data[index] = self.data[index-1]
                self.data[index-1] = tmp
            else:
                break
    
    def find(self, item):
        return binary_search(self.data, item)


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
sample_input = list(range(3))
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'''
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
from collections import deque


def convert_ACGT_to_int(acgt_str):
        result = 0
        for char in acgt_str:
            result *= 5
            if char == 'A':
                result += 1
            elif char == 'C':
                result += 2
            elif char == 'G':
                result += 3
            elif char == 'T':
                result += 4
            else:
                assert False
        
        return result


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return (True, index_middle + 1)
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if index_max >= index_min:
        if increasing_list[index_max] == elem:
            return (True, index_max + 1)
        elif increasing_list[index_min] == elem:
            return (True, index_min + 1)
        elif increasing_list[index_max] < elem:
            return (False, index_max + 1)
        elif increasing_list[index_min] > elem:
            return (False, index_min)
        elif increasing_list[index_min] < increasing_list[index_max]:
            return (False, index_max)
        elif increasing_list[index_min] == increasing_list[index_max]:
            val = increasing_list[index_min]
            if elem < val:
                return (False, index_min)
            else:
                return (False, index_max + 1)
        else:
            assert False
                
                
    
    if index_max < index_min:
        return (False, None)


class Dict (object):
    
    def __init__(self):
        self.data = deque()
        pass
        
    def insert(self, item):
        index = binary_search(list(self.data), item)[1]
        if index is None:
            self.data.append(item)
        else:
            self.data.insert(index, item)
    
    def find(self, item):
        return binary_search(list(self.data), item)[0]


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

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
from collections import deque


def convert_ACGT_to_int(acgt_str):
        result = 0
        for char in acgt_str:
            result *= 5
            if char == 'A':
                result += 1
            elif char == 'C':
                result += 2
            elif char == 'G':
                result += 3
            elif char == 'T':
                result += 4
            else:
                assert False
        
        return result


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return (True, index_middle + 1)
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if index_max >= index_min:
        if increasing_list[index_max] == elem:
            return (True, index_max + 1)
        elif increasing_list[index_min] == elem:
            return (True, index_min + 1)
        elif increasing_list[index_max] < elem:
            return (False, index_max + 1)
        elif increasing_list[index_min] > elem:
            return (False, index_min)
        elif increasing_list[index_min] < increasing_list[index_max]:
            return (False, index_max)
        elif increasing_list[index_min] == increasing_list[index_max]:
            val = increasing_list[index_min]
            if elem < val:
                return (False, index_min)
            else:
                return (False, index_max + 1)
        else:
            assert False
                
                
    
    if index_max < index_min:
        return (False, None)


class Dict (object):
    
    def __init__(self):
        self.data = deque()
        pass
        
    def insert(self, item):
        index = binary_search(list(self.data), item)[1]
        if index is None:
            self.data.append(item)
        else:
            self.data.insert(index, item)
    
    def find(self, item):
        return binary_search(list(self.data), item)[0]


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

Solution code:
from collections import deque

def convert_ACGT_to_int(acgt_str):
        result = 0
        for char in acgt_str:
            result *= 5
            if char == 'A':
                result += 1
            elif char == 'C':
                result += 2
            elif char == 'G':
                result += 3
            elif char == 'T':
                result += 4
            else:
                assert False
        
        return result


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return (True, index_middle + 1)
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if index_max >= index_min:
        if increasing_list[index_max] == elem:
            return (True, index_max + 1)
        elif increasing_list[index_min] == elem:
            return (True, index_min + 1)
        elif increasing_list[index_max] < elem:
            return (False, index_max + 1)
        elif increasing_list[index_min] > elem:
            return (False, index_min)
        elif increasing_list[index_min] < increasing_list[index_max]:
            return (False, index_max)
        elif increasing_list[index_min] == increasing_list[index_max]:
            val = increasing_list[index_min]
            if elem < val:
                return (False, index_min)
            else:
                return (False, index_max + 1)
        else:
            assert False
                
                
    
    if index_max < index_min:
        return (False, None)


class Dict (object):
    
    def __init__(self):
        self.data = deque()
        pass
        
    def insert(self, item):
        index = binary_search(list(self.data), item)[1]
        if index is None:
            self.data.append(item)
        else:
            self.data.insert(index, item)
    
    def find(self, item):
        return binary_search(list(self.data), item)[0]


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

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
from collections import deque

def convert_ACGT_to_int(acgt_str):
        result = 0
        for char in acgt_str:
            result *= 5
            if char == 'A':
                result += 1
            elif char == 'C':
                result += 2
            elif char == 'G':
                result += 3
            elif char == 'T':
                result += 4
            else:
                assert False
        
        return result


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return (True, index_middle + 1)
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if index_max >= index_min:
        if increasing_list[index_max] == elem:
            return (True, index_max + 1)
        elif increasing_list[index_min] == elem:
            return (True, index_min + 1)
        elif increasing_list[index_max] < elem:
            return (False, index_max + 1)
        elif increasing_list[index_min] > elem:
            return (False, index_min)
        elif increasing_list[index_min] < increasing_list[index_max]:
            return (False, index_max)
        elif increasing_list[index_min] == increasing_list[index_max]:
            val = increasing_list[index_min]
            if elem < val:
                return (False, index_min)
            else:
                return (False, index_max + 1)
    
    if index_max < index_min:
        return (False, None)


class Dict (object):
    
    def __init__(self):
        self.data = deque()
        pass
        
    def insert(self, item):
        index = binary_search(list(self.data), item)[1]
        if index is None:
            self.data.append(item)
        else:
            self.data.insert(index, item)
    
    def find(self, item):
        return binary_search(list(self.data), item)[0]


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

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
from collections import deque

def convert_ACGT_to_int(acgt_str):
    result = 0
    for char in acgt_str:
        result *= 5
        if char == 'A':
            result += 1
        elif char == 'C':
            result += 2
        elif char == 'G':
            result += 3
        elif char == 'T':
            result += 4
        else:
            assert False
        
    return result        


def binary_search(increasing_list, elem):
    index_min = 0
    index_max = len(increasing_list) - 1
    
    while index_max - index_min >= 2:
        index_middle = int((index_min + index_max) / 2)
        if increasing_list[index_middle] == elem:
            return (True, index_middle + 1)
        elif increasing_list[index_middle] > elem:
            index_max = index_middle
        else:
            index_min = index_middle
            
    if index_max >= index_min:
        if increasing_list[index_max] == elem:
            return (True, index_max + 1)
        elif increasing_list[index_min] == elem:
            return (True, index_min + 1)
        elif increasing_list[index_max] < elem:
            return (False, index_max + 1)
        elif increasing_list[index_min] > elem:
            return (False, index_min)
        elif increasing_list[index_min] < increasing_list[index_max]:
            return (False, index_max)
        elif increasing_list[index_min] == increasing_list[index_max]:
            val = increasing_list[index_min]
            if elem < val:
                return (False, index_min)
            else:
                return (False, index_max + 1)
    
    if index_max < index_min:
        return (False, None)


class Dict (object):
    
    def __init__(self):
        self.data = deque()
        pass
        
    def insert(self, item):
        index = binary_search(list(self.data), item)[1]
        if index is None:
            self.data.append(item)
        else:
            self.data.insert(index, item)
    
    def find(self, item):
        return binary_search(list(self.data), item)[0]


dict = Dict()
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(convert_ACGT_to_int(data))
    else:
        if dict.find(convert_ACGT_to_int(data)):
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

Solution code:
mport sys

n = int(input())
dic = {}
input_ = sys.stdin.readlines()

for i in input_:
    c, s = i.split()
    if c == 'insert':
        dic[s] = 0
    else:
        if s in dic:
            print('yes')
        else:
            print('no')

Submission status: Runtime Error

Solution code:
import sys

dict = {}
l = []
line = map(lambda x: x.split(), sys.stdin.readlines())
s = ""
for (c, arg) in line:
    if c == "insert":
        dict[arg] = 0
    elif c == "find":
        if arg in dict:
            s += "yes\n"
        else:
            s += "no\n"
print(s, end="")

Submission status: Runtime Error

Solution code:
import sys
??
n = int(input())
dic = {}
input_ = sys.stdin.readlines()
??
for i in input_:
????????c, s = i.split()
????????if c == 'insert':
????????????????dic[s] = 0
????????else:
????????????????if s in dic:
????????????????????????print('yes')
????????????????else:
????????????????????????print('no')

Submission status: Runtime Error

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 c:
                print("yes")
            else:
                print("no")

Submission status: Runtime Error

Solution code:
import sys

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 my_insert(dic, key):
    i = 0

    while 1:
        j = H(key, i)
        if dic[j] is None:
            dic[j] = key
            return j
        else:
            i += 1

def my_search(dic, key):
    i = 0

    while 1:
        j = H(key, i)
        if dic[j] == key:
            return True
        elif dic[j] is None or i >= M:
            return False
        else:
            i += 1

def str2int(s):
    res = s

    res = res.replace("A", "1")
    res = res.replace("C", "2")
    res = res.replace("G", "3")
    res = res.replace("T", "4")

    return int(res)

M = 1_000_003
dic = [None] * M

n = int(sys.stdin.readline())

for k in range(n):
    cmd, s = sys.stdin.readline().split()

    if cmd == "insert":
        my_insert(dic, str2int(s))
    else:
        print("yes" if my_search(dic, str2int(s)) else "no")