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 OCaml (judge verdict: Accepted)

let m = 1039999

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let to_x = Array.make 128 0

let to_key s =
  let ret = ref 0 in
  let p = ref 1 in
  for i = 0 to String.length s - 1 do
    ret := !ret + !p * (to_x.(Char.code s.[i]));
    p := 5 * !p;
  done;
  !ret

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if find s t then "yes" else "no")
    | [_; s] -> insert s t
    | _ -> assert false
  done