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

Solution in Go (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	T := make([]int, n)
	e := []string{}
	for range T {
		sc.Scan()
		cmd := sc.Text()
		sc.Scan()
		str := sc.Text()
		switch cmd {
		case "insert":
			insert(getInt(str), T)
		case "find":
			if find(getInt(str), T) {
				e = append(e, "yes")
				continue
			}
			e = append(e, "no")
		}
	}
	t := trimBracket(fmt.Sprint(e))
	fmt.Println(strings.Replace(t, " ", "\n", -1))
}

func trimBracket(s string) string {
	return strings.Trim(s, "[]")
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	n, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func getInt(str string) int {
	cnt, p := 0, 1
	for _, v := range str {
		cnt += p * int(v)
		p *= 5
	}
	return cnt
}

func h1(key, n int) int {
	return key % n
}

func h2(key, n int) int {
	return 1 + h1(key, n-1)
}

func h(key, n, i int) int {
	return (h1(key, n) + i*h2(key, n)) % n
}

func insert(key int, T []int) {
	n := len(T)
	for i := 0; i < n; i++ {
		j := h(key, n, i)
		if T[j] == 0 {
			T[j] = key
			break
		}
	}
}

func find(key int, T []int) bool {
	sort.Ints(T)
	left, mid, right := 0, 0, len(T)
	for left < right {
		mid = (left + right) / 2
		if T[mid] == key {
			return true
		} else if key > T[mid] {
			left = mid + 1
			continue
		}
		right = mid
	}
	return false
}