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 Scala (judge verdict: Runtime Error)

import scala.io.StdIn

object Main extends App {
  
  val max = 84*12 // T * 12 char: 1008
  val min = 65*12 // A * 12 char:  780
  // 
  // 16,777,216

  val m = max
  val arrayMax = 1000000
  
  def ctoi(data: String) = data.foldLeft(0)((acc, e) => acc+e)
  
  // A: 65, C:67, G:71, T:84
  def makeHash1(key: Int) = {
    key % m
  }

  def makeHash2(key: Int) = {
    1 + key % (m - 1)
  }
  
  def makeHash(key: Int, i: Int) = {
    (makeHash1(key) + i * makeHash2(key)) % m
  }

  val n = StdIn.readLine().trim.toInt

  val dict = Array.fill(arrayMax)("")
  
  def insert(data: String): Unit = {
    var i = 0
    val key = ctoi(data)
    var colision = true
    while(colision){
      val j = makeHash(key, i)
      if(dict(j) == "") {
        dict(j) = data
        colision = false
      }
      else i = i + 1
    }
  }

  def search(data: String): Int = {
    val key = ctoi(data)
    var i = key
    var ret = -1
    while(ret < 0 && i < arrayMax){
      if(dict(i) == data) {
        ret = i
      }
      i += 1
    }
    ret
  }
  
  val result = (0 until n).map{ _ =>
    val cmd = StdIn.readLine().split(' ')
    if(cmd(0) == "insert"){
      insert(cmd(1))
      ""
    } else {
      if(search(cmd(1)) >= 0) f"yes%n" else f"no%n"
    }
  }.filterNot( p => p == "")
  
  print(result.mkString(""))
  
}