let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 150000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  (*let rec phi m k =
    (*incr cnt;*)
    if k = 0
    then (
      (*incr cnt1;*)
      n /| m
    ) else if k = c then (
      (*incr cnt4;*)
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      (*incr cnt2;*)
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      (*incr cnt3;*)
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in*)
  let rec phi32 n k =
    (*incr cnt;*)
    if k = 0
    then n
    else if k = c
    then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)
    else if n <= n2
    then phi'.(n).(k)
    else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)
  in
  let rec phi n k =
    if k = 0
    then n
    else if k = c
    then
      (n /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)
    else if n <= 1000000000L
    then Int64.of_int (phi32 (Int64.to_int n) k)
    else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)
  in
  let res = phi n k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res

let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 250000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  (*let rec phi m k =
    (*incr cnt;*)
    if k = 0
    then (
      (*incr cnt1;*)
      n /| m
    ) else if k = c then (
      (*incr cnt4;*)
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      (*incr cnt2;*)
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      (*incr cnt3;*)
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in*)
  let rec phi32 n k =
    (*incr cnt;*)
    if k = 0
    then n
    else if k = c
    then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)
    else if n <= n2
    then phi'.(n).(k)
    else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)
  in
  let rec phi n k =
    if k = 0
    then n
    else if k = c
    then
      (n /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)
    else if n <= 1000000000L
    then Int64.of_int (phi32 (Int64.to_int n) k)
    else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)
  in
  let res = phi n k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res

let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 250000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  let rec phi m k =
    incr cnt;
    if k = 0
    then (
      incr cnt1;
      n /| m
    ) else if k = c then (
      incr cnt4;
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      incr cnt2;
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      incr cnt3;
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res

let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 200000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  (*let rec phi m k =
    (*incr cnt;*)
    if k = 0
    then (
      (*incr cnt1;*)
      n /| m
    ) else if k = c then (
      (*incr cnt4;*)
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      (*incr cnt2;*)
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      (*incr cnt3;*)
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in*)
  let rec phi32 n k =
    (*incr cnt;*)
    if k = 0
    then n
    else if k = c
    then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)
    else if n <= n2
    then phi'.(n).(k)
    else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)
  in
  let rec phi n k =
    if k = 0
    then n
    else if k = c
    then
      (n /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)
    else if n <= 1000000000L
    then Int64.of_int (phi32 (Int64.to_int n) k)
    else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)
  in
  let res = phi n k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res

let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 250000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  let rec phi m k =
    (*incr cnt;*)
    if k = 0
    then (
      (*incr cnt1;*)
      n /| m
    ) else if k = c then (
      (*incr cnt4;*)
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      (*incr cnt2;*)
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      (*incr cnt3;*)
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res

let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make k 0 in
  let _ =
    for i = 0 to k - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    (*Array.sort (fun x y -> compare y x) a;*)
    Array.sort compare a;
  in
  let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in
  let sn = isqrt n in
  let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in
  let n2 = min 170000L n in
  let n2 = Int64.to_int n2 in
  let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in
  let _ =
    for i = 1 to n2 do
      phi'.(i).(0) <- i;
      for j = 1 to k do
	phi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)
      done;
    done;
  in
  let n3 = n /| Int64.of_int n2 in
  let (c, q) =
    let c = ref 0 in
    let q = ref 1 in
      while !c < k && !q * a.(!c) <= n2 do
	q := !q * a.(!c);
	incr c;
      done;
      (!c, !q)
  in
  let cnt = ref 0 in
  let cnt1 = ref 0 in
  let cnt2 = ref 0 in
  let cnt3 = ref 0 in
  let cnt4 = ref 0 in
  (*let rec phi m k =
    (*incr cnt;*)
    if k = 0
    then (
      (*incr cnt1;*)
      n /| m
    ) else if k = c then (
      (*incr cnt4;*)
      (n /| m /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)
    ) else if m > n3
    then (
      (*incr cnt2;*)
      Int64.of_int phi'.(Int64.to_int (n /| m)).(k)
    ) else (
      (*incr cnt3;*)
      phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)
    )
  in
  let res = phi 1L k in*)
  let rec phi32 n k =
    (*incr cnt;*)
    if k = 0
    then n
    else if k = c
    then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)
    else if n <= n2
    then phi'.(n).(k)
    else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)
  in
  let rec phi n k =
    if k = 0
    then n
    else if k = c
    then
      (n /| Int64.of_int q) *|
	  Int64.of_int phi'.(q).(k) +|
	      Int64.of_int
		phi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)
    else if n <= 1000000000L
    then Int64.of_int (phi32 (Int64.to_int n) k)
    else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)
  in
  let res = phi n k in
    Printf.eprintf "asd %d %d %d %d %d %d\n" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;
    Printf.printf "%Ld\n" res


type tree = Empty | Node of tree * tree * tree

let rec insert t str i len =
  if i=len then Node (Empty,Empty,Empty) else (
    let (ta,tb,tc) = match t with Empty -> (Empty,Empty,Empty) | Node (a,b,c) -> (a,b,c) in
    match str.[i] with
      | 'a' -> Node (insert ta str (i+1) len, tb, tc)
      | 'b' -> Node (ta, insert tb str (i+1) len, tc)
      | 'c' -> Node (ta, tb, insert tc str (i+1) len)
      | _ -> failwith "bad input"
  )

let rec search t str i len ecount =
  if ecount > 1 || t=Empty then false
  else if i=len then ecount=1 else (
    match t with Empty -> false
      | Node (ta,tb,tc) ->
	let ec x = if str.[i]=x then 0 else 1 in
	search ta str (i+1) len (ecount + (ec 'a')) ||
	  search tb str (i+1) len (ecount + (ec 'b')) ||
	  search tc str (i+1) len (ecount + (ec 'c'))
  )

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let n = read_int () in
  let m = read_int () in
  let string = Array.init n (fun _ -> read_string()) in
  let query = Array.init m (fun _ -> read_string()) in

  let tree = Array.make (6*100_000+1) Empty in

  for i=0 to n-1 do
    let len = String.length string.(i) in
    tree.(len) <- insert tree.(len) string.(i) 0 len;
  done;

  for i=0 to m-1 do
    let len = String.length query.(i) in
    let ans = search tree.(len) query.(i) 0 len 0 in
    if ans then printf "YES\n" else printf "NO\n"
  done

type 'a trie = {
  value : 'a option;
  children :  'a trie option array;
}

let list_of_string s = Array.to_list (Array.init (String.length s) (String.get s))

(* empty trie *)
let empty () =
  { value = None;
    children = Array.make 3 None;
  }

let insert t s =
  let rec insert' t p = function
    | [] -> { t with value = Some p }
    | c :: cs ->
        (* index into child array *)
        let i = Char.code c - Char.code 'a' in
        (* replacement node *)
        let n = match t.children.(i) with
        | None -> empty ()
        | Some t -> t
        in
        t.children.(i) <- Some (insert' n c cs);
        t
  in
  insert' t 'z' (list_of_string s)

let find t s =
  let rec find' t p c = function
  | [] -> c && t.value = Some p
  | x :: xs ->
      if c
      then begin
        match t.children.(Char.code x - Char.code 'a') with
        | None -> false
        | Some c -> find' c x true xs
      end
      else begin
        let rec aux a i =
          if i = 3 then a
          else
            match t.children.(i) with
            | None -> aux a (succ i)
            | Some t -> aux (a || find' t (Char.chr (i + Char.code 'a')) (Char.code x - Char.code 'a' <> i) xs) (succ i)
        in
        aux false 0
      end
  in
  find' t 'y' false (list_of_string s)

let () = Scanf.scanf "%d %d\n" (fun n m ->
  (* read memory and construct trie *)
  let rec aux t i =
    if i = n then t else begin
      let t = Scanf.scanf "%s\n" (insert t) in
      aux t (succ i)
    end
  in
  let t = aux (empty ()) 0 in

  (* read and response to queries *)
  for i = 1 to m do
    let q = Scanf.scanf "%s\n" (fun s -> s) in
    print_endline (if find t q then "YES" else "NO")
  done
)


(** a node is a string value and list
 * of outgoing edges *)
type node = {
  v : string;
  e : int list;
  i : int;
  o : int;
}
let empty_node v = { v; e = []; i = 0; o = 0 }

(** doubly-linked list element *)
type 'a el = {
  v : 'a;
  mutable next : 'a el option;
  mutable prev : 'a el option;
}

exception No_trail

let get_password edges nodes n =
  (* dlist of tour *)
  let dl = { v = n; next = None; prev = None } in
  (* end of list *)
  let tl = ref dl in

  (* get the initial trail *)
  let rec trail n tl =
    let node = Hashtbl.find nodes n in
    match node.e with
    | e :: es ->
        let e = String.sub edges.(e) 1 2 in
        let el = { v = e; next = None; prev = Some !tl } in
        !tl.next <- Some el;
        tl := el;
        Hashtbl.replace nodes n { node with e = es };
        trail e tl
    | [] -> ()
  in
  trail n tl;

  (* build the final password *)
  let rec build n =
    (* follow any further edges from this node
     * if necessary *)
    let next = n.next in
    let tl = ref n in
    trail n.v tl;
    (* check that we generated a cycle *)
    if !tl.v = n.v then
      !tl.next <- next
    else
      raise No_trail;

    match n.next with
    | None -> ()
    | Some n -> build n
  in
  build dl;
  dl

let rec print_password p =
  match p.next with
  | None -> ()
  | Some n ->
      print_char n.v.[1];
      print_password n

let () = Scanf.scanf "%d\n" (fun n ->
  (* read all 3-letter substrings (edges of the graph) *)
  let edges = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun e -> e)) in
  (* adjacency list
   * - maps node to a list of
   *   indices into the edges array
   *)
  let nodes = Hashtbl.create n in
  Array.iteri (fun i e ->
    (* start and end nodes of the edge *)
    let hd = String.sub e 0 2
    and tl = String.sub e 1 2 in
    let hd_node =
      if Hashtbl.mem nodes hd
      then Hashtbl.find nodes hd
      else (empty_node hd)
    in
    let hd_node = { hd_node with
      e = (i :: hd_node.e);
      o = (hd_node.o + 1);
    } in
    Hashtbl.replace nodes hd hd_node;
    let tl_node =
      if Hashtbl.mem nodes tl
      then Hashtbl.find nodes tl
      else (empty_node tl)
    in
    Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }
  ) edges;
  (* find nodes with odd degree *)
  let (i, o) = Hashtbl.fold (fun n v (i, o) ->
    match v.o - v.i with
    |  1 -> i, n :: o
    | -1 -> n :: i, o
    |  _ -> i, o
    ) nodes ([], [])
  in
  let start = match o with
  | [n] -> Some n
  | []  -> Some (String.sub edges.(0) 0 2)
  | _   -> None
  in
  match start with
  | None   -> print_endline "NO"
  | Some n ->
      try
        let p = get_password edges nodes n in
        let disjoint = Hashtbl.fold (fun _ v b ->
          b || List.length v.e > 0
        ) nodes false
        in
        if disjoint
        then print_endline "NO"
        else begin
          print_endline "YES";
          print_string (String.sub n 0 2);
          print_password p;
          print_char '\n'
        end
      with
      | No_trail -> print_endline "NO"
)

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
        match (x = c, pending) with
        | false, _ -> (ls, x :: pending)
        | true, [] -> (ls, pending)
        | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
let update h k f =
  Hashtbl.replace h k
  @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None

(* --- *)
exception InputError of string

let read_into_pair () =
  let e = read_line () |> String.trim in
  match explode e with
  | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)
  | _ -> raise @@ InputError "unexpected input"

(* --- *)
let seqs_count = read_line () |> int_of_string

let degs = Hashtbl.create (62 * 62)

let adj = Hashtbl.create (62 * 62)

;;
for i = 1 to seqs_count do
  let f', t', char_of_path = read_into_pair () in
  update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;
  update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;
  Hashtbl.add adj f' (t', char_of_path)
done

let find_eu start_v =
  let cir = ref [] in
  let rec h vertex =
    while Hashtbl.mem adj vertex do
      let next_vertex, char_of_path = Hashtbl.find adj vertex in
      Hashtbl.remove adj vertex ; h next_vertex
    done ;
    cir := vertex :: !cir
  in
  h start_v ;
  (* ensure it's connected *)
  if List.length !cir = seqs_count + 1 then (
    Printf.printf "YES\n" ;
    Printf.printf "%s" start_v ;
    List.iter (fun s -> Printf.printf "%c" s.[1]) @@ List.tl !cir ;
    Printf.printf "\n" )
  else Printf.printf "NO\n"

let more_outgoings, more_ingoings, last_balanced =
  Hashtbl.fold
    (fun k d (more_outgoings, more_ingoings, last_balanced) ->
      if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)
      else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)
      else (more_outgoings, more_ingoings, Some k) )
    degs ([], [], None)

;;
match (more_outgoings, more_ingoings, last_balanced) with
| [x], [y], _ when Hashtbl.find degs x = 1 && Hashtbl.find degs y = -1 ->
    find_eu x
| [], [], Some x -> find_eu x
| _ -> Printf.printf "NO\n"

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
        match (x = c, pending) with
        | false, _ -> (ls, x :: pending)
        | true, [] -> (ls, pending)
        | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
let update h k f =
  Hashtbl.replace h k
  @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None

(* --- *)
exception InputError of string

let read_into_pair () =
  let e = read_line () |> String.trim in
  match explode e with
  | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)
  | _ -> raise @@ InputError "unexpected input"

(* --- *)
let seqs_count = read_line () |> int_of_string

let degs = Hashtbl.create (62 * 62)

let adj = Hashtbl.create (62 * 62)

;;
for i = 1 to seqs_count do
  let f', t', char_of_path = read_into_pair () in
  update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;
  update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;
  Hashtbl.add adj f' (t', char_of_path)
done

let find_eu start_v =
  let cir = ref [] in
  let rec h vertex =
    while Hashtbl.mem adj vertex do
      let next_vertex, char_of_path = Hashtbl.find adj vertex in
      Hashtbl.remove adj vertex ; h next_vertex
    done ;
    cir := vertex :: !cir
  in
  h start_v ;
  if List.length !cir = seqs_count + 1 then (
    Printf.printf "YES\n" ;
    Printf.printf "%s" start_v ;
    List.iter (fun s -> Printf.printf "%c" s.[1]) @@ List.tl !cir ;
    Printf.printf "\n" )
  else Printf.printf "NO\n"

let more_outgoings, more_ingoings, last_balanced =
  Hashtbl.fold
    (fun k d (more_outgoings, more_ingoings, last_balanced) ->
      if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)
      else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)
      else (more_outgoings, more_ingoings, Some k) )
    degs ([], [], None)

;;
match (more_outgoings, more_ingoings, last_balanced) with
| [x], [_], _ -> find_eu x
| [], [], Some x -> find_eu x
| _ -> Printf.printf "NO\n"

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
        match (x = c, pending) with
        | false, _ -> (ls, x :: pending)
        | true, [] -> (ls, pending)
        | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
let update h k f =
  Hashtbl.replace h k
  @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None

(* --- *)
exception InputError of string

let read_into_pair () =
  let e = read_line () |> String.trim in
  match explode e with
  | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)
  | _ -> raise @@ InputError "unexpected input"

(* --- *)
let seqs_count = read_line () |> int_of_string

let degs = Hashtbl.create (62 * 62)

let adj = Hashtbl.create (62 * 62)

;;
for i = 1 to seqs_count do
  let f', t', char_of_path = read_into_pair () in
  update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;
  update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;
  Hashtbl.add adj f' (t', char_of_path)
done

let find_eu start_v =
  Printf.printf "YES\n" ;
  Printf.printf "%s" start_v ;
  let rec h vertex =
    while Hashtbl.mem adj vertex do
      let next_vertex, char_of_path = Hashtbl.find adj vertex in
      Hashtbl.remove adj vertex ;
      Printf.printf "%c" char_of_path ;
      h next_vertex
    done
  in
  h start_v ; Printf.printf "\n"

let more_outgoings, more_ingoings, last_balanced =
  Hashtbl.fold
    (fun k d (more_outgoings, more_ingoings, last_balanced) ->
      if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)
      else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)
      else (more_outgoings, more_ingoings, Some k) )
    degs ([], [], None)

;;
match (more_outgoings, more_ingoings, last_balanced) with
| [x], [_], _ -> find_eu x
| [], [], Some x -> find_eu x
| _ -> Printf.printf "NO\n"

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
         match (x = c, pending) with
         | false, _ -> (ls, x :: pending)
         | true, [] -> (ls, pending)
         | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
let update h k f =
  Hashtbl.replace h k
  @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None

(* --- *)
exception InputError of string

let read_into_pair () =
  let e = read_line () |> String.trim in
  match explode e with
  | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)
  | _ -> raise @@ InputError "unexpected input"

(* --- *)
let seqs_count = read_line () |> int_of_string

let degs = Hashtbl.create (62 * 62)

let adj = Hashtbl.create (62 * 62)

;;
for i = 1 to seqs_count do
  let f', t', char_of_path = read_into_pair () in
  update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;
  update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;
  Hashtbl.add adj f' (t', char_of_path)
done

let find_eu start_v =
  Printf.printf "YES\n" ;
  Printf.printf "%s" start_v;
  let cir = ref [] in
  let rec h vertex =
    while Hashtbl.mem adj vertex do
      let next_vertex, char_of_path = Hashtbl.find adj vertex in
      Hashtbl.remove adj vertex ; h next_vertex
    done ;
    cir := vertex :: !cir
  in
  h start_v ;
  List.iter (fun s -> Printf.printf "%c" s.[1]) @@ List.tl !cir ;
  Printf.printf "\n"

let more_outgoings, more_ingoings, last_balanced =
  Hashtbl.fold
    (fun k d (more_outgoings, more_ingoings, last_balanced) ->
       if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)
       else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)
       else (more_outgoings, more_ingoings, Some k) )
    degs ([], [], None)

;;
match (more_outgoings, more_ingoings, last_balanced) with
| [x], [_], _ -> find_eu x
| [], [], Some x -> find_eu x
| _ -> Printf.printf "NO\n"

(* --- *)
let concat_chars cs = String.concat "" (List.map (String.make 1) cs)

let explode str =
  let exploded = ref [] in
  for i = String.length str - 1 downto 0 do
    exploded := str.[i] :: !exploded
  done ;
  !exploded

let split_on_char c str =
  let exploded = explode str in
  let cs', pending' =
    List.fold_right
      (fun x (ls, pending) ->
        match (x = c, pending) with
        | false, _ -> (ls, x :: pending)
        | true, [] -> (ls, pending)
        | true, _ -> (pending :: ls, []) )
      exploded ([], [])
  in
  List.map concat_chars (if pending' = [] then cs' else pending' :: cs')

(* --- *)
let update h k f =
  Hashtbl.replace h k
  @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None

(* --- *)
exception InputError of string

let read_into_pair () =
  let e = read_line () |> String.trim in
  match explode e with
  | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)
  | _ -> raise @@ InputError "unexpected input"

(* --- *)
let seqs_count = read_line () |> int_of_string

let degs = Hashtbl.create (62 * 62)

let adj = Hashtbl.create (62 * 62)

;;
for i = 1 to seqs_count do
  let f', t', char_of_path = read_into_pair () in
  update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;
  update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;
  Hashtbl.add adj f' (t', char_of_path)
done

let find_eu start_v =
  Printf.printf "YES\n" ;
  Printf.printf "%s" start_v ;
  let acc = ref [] in
  let rec h vertex =
    while Hashtbl.mem adj vertex do
      let next_vertex, char_of_path = Hashtbl.find adj vertex in
      Hashtbl.remove adj vertex ;
      acc := char_of_path :: !acc ;
      h next_vertex
    done
  in
  h start_v ;
  List.iter (fun c -> Printf.printf "%c" c) !acc ;
  Printf.printf "\n"

let more_outgoings, more_ingoings, last_balanced =
  Hashtbl.fold
    (fun k d (more_outgoings, more_ingoings, last_balanced) ->
      if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)
      else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)
      else (more_outgoings, more_ingoings, Some k) )
    degs ([], [], None)

;;
match (more_outgoings, more_ingoings, last_balanced) with
| [x], [_], _ -> find_eu x
| [], [], Some x -> find_eu x
| _ -> Printf.printf "NO\n"

(** a node is a string value and list
 * of outgoing edges *)
type node = {
  v : string;
  e : int list;
  i : int;
  o : int;
}
let empty_node v = { v; e = []; i = 0; o = 0 }

(** doubly-linked list element *)
type 'a el = {
  v : 'a;
  mutable next : 'a el option;
  mutable prev : 'a el option;
}

let get_password edges nodes n =
  (* dlist of tour *)
  let dl = { v = n; next = None; prev = None } in
  (* end of list *)
  let tl = ref dl in

  (* get the initial trail *)
  let rec trail n tl =
    let node = Hashtbl.find nodes n in
    match node.e with
    | e :: es ->
        let e = String.sub edges.(e) 1 2 in
        let el = { v = e; next = None; prev = Some !tl } in
        !tl.next <- Some el;
        tl := el;
        Hashtbl.replace nodes n { node with e = es };
        trail e tl
    | [] -> ()
  in
  trail n tl;

  (* print the final password *)
  let rec print n =
    print_char n.v.[1];

    (* follow any further edges from this node
     * if necessary *)
    let next = n.next in
    let tl = ref n in
    trail n.v tl;
    !tl.next <- next;

    match n.next with
    | None -> ()
    | Some n -> print n
  in
  print dl;
  print_char '\n'

let () = Scanf.scanf "%d\n" (fun n ->
  (* read all 3-letter substrings (edges of the graph) *)
  let edges = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun e -> e)) in
  (* adjacency list
   * - maps node to a list of
   *   indices into the edges array
   *)
  let nodes = Hashtbl.create n in
  Array.iteri (fun i e ->
    (* start and end nodes of the edge *)
    let hd = String.sub e 0 2
    and tl = String.sub e 1 2 in
    let hd_node =
      if Hashtbl.mem nodes hd
      then Hashtbl.find nodes hd
      else (empty_node hd)
    in
    let hd_node = { hd_node with
      e = (i :: hd_node.e);
      o = (hd_node.o + 1);
    } in
    Hashtbl.replace nodes hd hd_node;
    let tl_node =
      if Hashtbl.mem nodes tl
      then Hashtbl.find nodes tl
      else (empty_node tl)
    in
    Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }
  ) edges;
  (* find nodes with odd degree *)
  let (i, o) = Hashtbl.fold (fun n v (i, o) ->
    match v.o - v.i with
    |  1 -> i, n :: o
    | -1 -> n :: i, o
    |  _ -> i, o
    ) nodes ([], [])
  in
  let start = match o with
  | [n] -> Some n
  | []  -> Some (String.sub edges.(0) 0 2)
  | _   -> None
  in
  match start with
  | None   -> print_endline "NO"
  | Some n ->
      print_endline "YES";
      print_char n.[0];
      get_password edges nodes n
)

let get_password edges nodes s =
  print_string s;
  let rec printer s =
    match Hashtbl.find nodes s with
    | hd :: tl ->
        let e = edges.(hd) in
        print_char e.[2];
        Hashtbl.replace nodes s tl;
        printer (String.sub e 1 2)
    | [] -> () (* done *)
  in
  printer s;
  print_endline ""

let () =
  Scanf.scanf "%d\n" (fun n ->
    (* array of edges *)
    let edges = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun l -> l)) in
    (* adjacency list *)
    let nodes = Hashtbl.create n in
    (* degree of each node *)
    let degree = Hashtbl.create n in
    (* add edges to adjacency list and
     * calculate the degree of nodes *)
    Array.iteri (fun i s ->
      (* start of edge *)
      let hd = String.sub s 0 2
      (* end of edge *)
      and tl = String.sub s 1 2 in
      (* add edge to adjacency list *)
      let edges =
        if Hashtbl.mem nodes hd
        then Hashtbl.find nodes hd
        else []
      in
      Hashtbl.replace nodes hd (i :: edges);
      if not (Hashtbl.mem nodes tl)
      then Hashtbl.add nodes tl [];
      (* increase out degree of start node *)
      let (i, o) =
        if Hashtbl.mem degree hd
        then Hashtbl.find degree hd
        else (0, 0)
      in
      Hashtbl.replace degree hd (i, o + 1);
      (* increase in degree of end node *)
      let (i, o) =
        if Hashtbl.mem degree tl
        then Hashtbl.find degree tl
        else (0, 0)
      in
      Hashtbl.replace degree tl (i + 1, o)
    ) edges;
    (* a directed graph has an Eulerian trail iff at
     * most one node each has o-i = 1 and i-o = 1.
     * fold over the hashtbl to find these nodes *)
    let (inl, outl) =
      Hashtbl.fold (fun s (i, o) (inl, outl) ->
        match o - i with
        |  1 -> (inl, s :: outl)
        | -1 -> (s :: inl, outl)
        |  _ -> (inl, outl)
      ) degree ([], [])
    in
    let start = match outl with
    | [s] -> Some s
    | []  -> Some (String.sub edges.(0) 0 2)
    | _   -> None
    in
    match start with
    | Some s -> print_endline "YES"; get_password edges nodes s
    | None   -> print_endline "NO"
  )

(** a node is a string value and list
 * of outgoing edges *)
type node = {
  v : string;
  e : int list;
  i : int;
  o : int;
}
let empty_node v = { v; e = []; i = 0; o = 0 }

(** doubly-linked list element *)
type 'a el = {
  v : 'a;
  mutable next : 'a el option;
  mutable prev : 'a el option;
}

let get_password edges nodes n =
  (* dlist of tour *)
  let dl = { v = n; next = None; prev = None } in
  (* end of list *)
  let tl = ref dl in

  (* get the initial trail *)
  let rec trail n tl =
    let node = Hashtbl.find nodes n in
    match node.e with
    | e :: es ->
        let e = String.sub edges.(e) 1 2 in
        let el = { v = e; next = None; prev = Some !tl } in
        !tl.next <- Some el;
        tl := el;
        Hashtbl.replace nodes n { node with e = es };
        trail e tl
    | [] -> ()
  in
  trail n tl;

  (* build the final password *)
  let rec build n =
    (* follow any further edges from this node
     * if necessary *)
    let next = n.next in
    let tl = ref n in
    trail n.v tl;
    !tl.next <- next;

    match n.next with
    | None -> ()
    | Some n -> build n
  in
  build dl;
  dl

let rec print_password p =
  match p.next with
  | None -> ()
  | Some n ->
      print_char n.v.[1];
      print_password n

let () = Scanf.scanf "%d\n" (fun n ->
  (* read all 3-letter substrings (edges of the graph) *)
  let edges = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun e -> e)) in
  (* adjacency list
   * - maps node to a list of
   *   indices into the edges array
   *)
  let nodes = Hashtbl.create n in
  Array.iteri (fun i e ->
    (* start and end nodes of the edge *)
    let hd = String.sub e 0 2
    and tl = String.sub e 1 2 in
    let hd_node =
      if Hashtbl.mem nodes hd
      then Hashtbl.find nodes hd
      else (empty_node hd)
    in
    let hd_node = { hd_node with
      e = (i :: hd_node.e);
      o = (hd_node.o + 1);
    } in
    Hashtbl.replace nodes hd hd_node;
    let tl_node =
      if Hashtbl.mem nodes tl
      then Hashtbl.find nodes tl
      else (empty_node tl)
    in
    Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }
  ) edges;
  (* find nodes with odd degree *)
  let (i, o) = Hashtbl.fold (fun n v (i, o) ->
    match v.o - v.i with
    |  1 -> i, n :: o
    | -1 -> n :: i, o
    |  _ -> i, o
    ) nodes ([], [])
  in
  let start = match o with
  | [n] -> Some n
  | []  -> Some (String.sub edges.(0) 0 2)
  | _   -> None
  in
  match start with
  | None   -> print_endline "NO"
  | Some n ->
      let p = get_password edges nodes n in
      let disjoint = Hashtbl.fold (fun _ v b ->
        b || List.length v.e > 0
      ) nodes false
      in
      if disjoint
      then print_endline "NO"
      else begin
        print_endline "YES";
        print_string (String.sub n 0 2);
        print_password p;
        print_char '\n'
      end
)


let read_int () = Scanf.scanf " %d" (fun x -> x)

let fmax = 500_001

let factors n =
  let rec aux i p =
(*    Printf.printf "%d, %d\n" i p; *)
    if p = 1 then []
    else if i*i > p then [p]
    else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)
    else aux (i+1) p
  in
  aux 2 n

(* Mike and Foam *)

let _ =
  let n = read_int () in
  let q = read_int () in
  let beers = Array.init n (fun _ -> read_int ()) in
  let queries = Array.init q (fun _ -> read_int ()) in
  let slots = Array.make fmax 0 in
  let pres = Array.make n false in
  let register sc n =
    let rec it prod = function
      | [] -> ()
      | l::ls -> count (prod*l) ls; it prod ls
    and count prod l =
      slots.(prod) <- slots.(prod)+sc;
      it prod l
    in
    count 1 (factors n)
  in
  let count n =
    let rec count prod l =
      slots.(prod) - it prod l
    and it prod = function
      | [] -> 0
      | l::ls -> count (prod * l) ls + it prod ls
    in
    count 1 (factors n)
  in
  let cur = ref (Int64.zero) in
  for i = 0 to q - 1 do
    (* How many things does it intersect with ? *)
    (* Oops, check presence + the '1' problem *)
    let beer = queries.(i) - 1 in
    let foam = beers.(beer) in
    let score =
      if pres.(beer) then (register (-1) foam; - count foam)
      else (let r = count foam in register 1 foam; r)
    in
    pres.(beer) <- not pres.(beer);
    cur := Int64.add !cur (Int64.of_int score);
    Printf.printf "%Ld\n" !cur
  done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n2 = 500000 in
  let prime = Array.make (n2 + 1) true in
  let p = Array.make (n2 + 1) 0 in
  let pd = Array.make (n2 + 1) [] in
  let pk = ref 0 in
  let () =
    for i = 2 to n2 do
      if prime.(i) then (
	p.(!pk) <- i;
	incr pk;
	pd.(i) <- [i];
	let j = ref (2 * i) in
          while !j <= n2 do
	    let jj = !j in
              prime.(jj) <- false;
	      pd.(jj) <- i :: pd.(jj);
              j := jj + i
          done
      )
    done;
  in
  let pk = !pk - 1 in
  let pd = Array.map Array.of_list pd in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let q = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let b = Array.make (n2 + 1) false in
  let d = Array.make (n2 + 1) 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let res = ref 0L in
    for i = 1 to q do
      let x = Scanf.bscanf sb "%d " (fun s -> s) in
      let (s, ofs) =
	if b.(x) then (
	  b.(x) <- false;
	  (-1, 1)
	) else (
	  b.(x) <- true;
	  (1, 0)
	)
      in
      let x = a.(x - 1) in
      let ds = pd.(x) in
      let k = Array.length ds in
	for i = 0 to 1 lsl k - 1 do
	  let y = ref 1 in
	  let c = ref 0 in
	    for j = 0 to k - 1 do
	      if i land (1 lsl j) <> 0 then (
		y := !y * ds.(j);
		incr c
	      )
	    done;
	    if !c land 1 = 0
	    then res := Int64.add !res (Int64.of_int (s * (d.(!y) - ofs)))
	    else res := Int64.sub !res (Int64.of_int (s * (d.(!y) - ofs)));
	    d.(!y) <- d.(!y) + s;
	done;
	Printf.printf "%Ld\n" !res;
    done;

let read_int () = Scanf.scanf " %d" (fun x -> x)

let fmax = 500_001

let factors n =
  let rec aux i p =
(*    Printf.printf "%d, %d\n" i p; *)
    if p = 1 then []
    else if i*i > p then [p]
    else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)
    else aux (i+1) p
  in
  aux 2 n

(* Mike and Foam *)

let _ =
  let n = read_int () in
  let q = read_int () in
  let beers = Array.init n (fun _ -> read_int ()) in
  let queries = Array.init q (fun _ -> read_int ()) in
  let slots = Array.make fmax 0 in
  let pres = Array.make n false in
  let register sc n =
    let rec it prod = function
      | [] -> ()
      | l::ls -> count (prod*l) ls; it prod ls
    and count prod l =
      slots.(prod) <- slots.(prod)+sc;
      it prod l
    in
    count 1 (factors n)
  in
  let count n =
    let rec count prod l =
      slots.(prod) - it prod l
    and it prod = function
      | [] -> 0
      | l::ls -> count (prod * l) ls + it prod ls
    in
    count 1 (factors n)
  in
  let cur = ref 0 in
  for i = 0 to q - 1 do
    (* How many things does it intersect with ? *)
    (* Oops, check presence + the '1' problem *)
    let beer = queries.(i) - 1 in
    let foam = beers.(beer) in
    let score =
      if pres.(beer) then (register (-1) foam; - count foam)
      else (let r = count foam in register 1 foam; r)
    in
    pres.(beer) <- not pres.(beer);
    cur := !cur + score;
    Printf.printf "%d\n" !cur
  done

let read_int () = Scanf.scanf " %d" (fun x -> x)

let fmax = 500_001

let factors n =
  let rec aux i p =
(*    Printf.printf "%d, %d\n" i p; *)
    if p = 1 then []
    else if i*i > p then [p]
    else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)
    else aux (i+1) p
  in
  aux 2 n

(* Mike and Foam *)

let _ =
  let n = read_int () in
  let q = read_int () in
  let beers = Array.init n (fun _ -> read_int ()) in
  let queries = Array.init q (fun _ -> read_int ()) in
  let slots = Array.make fmax 0 in
  let pres = Array.make n false in
  let register sc n =
    let rec it par prod = function
      | [] -> 0
      | l::ls -> count par (prod*l) ls + it par prod ls
    and count par prod l =
      let t = slots.(prod) in
      slots.(prod) <- t+sc;
      par*(if sc > 0 then t else t + sc) + it (-par) prod l
    in
    sc * count 1 1 (factors n)
  in
  let cur = ref 0 in
  for i = 0 to q - 1 do
    (* How many things does it intersect with ? *)
    (* Oops, check presence + the '1' problem *)
    let beer = queries.(i) - 1 in
    let score = register (if pres.(beer) then -1 else 1) beers.(beer) in
    pres.(beer) <- true;
    cur := !cur + score;
    Printf.printf "%d\n" !cur
  done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n2 = 500000 in
  let prime = Array.make (n2 + 1) true in
  let p = Array.make (n2 + 1) 0 in
  let pd = Array.make (n2 + 1) [] in
  let pk = ref 0 in
  let () =
    for i = 2 to n2 do
      if prime.(i) then (
	p.(!pk) <- i;
	incr pk;
	pd.(i) <- [i];
	let j = ref (2 * i) in
          while !j <= n2 do
	    let jj = !j in
              prime.(jj) <- false;
	      pd.(jj) <- i :: pd.(jj);
              j := jj + i
          done
      )
    done;
  in
  let pk = !pk - 1 in
  let pd = Array.map Array.of_list pd in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let q = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let b = Array.make (n2 + 1) false in
  let d = Array.make (n2 + 1) 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let res = ref 0L in
    for i = 1 to q do
      let x = Scanf.bscanf sb "%d " (fun s -> s) in
      let x = a.(x - 1) in
      let (s, ofs) =
	if b.(x) then (
	  b.(x) <- false;
	  (-1, 1)
	) else (
	  b.(x) <- true;
	  (1, 0)
	)
      in
      let ds = pd.(x) in
      let k = Array.length ds in
	for i = 0 to 1 lsl k - 1 do
	  let y = ref 1 in
	  let c = ref 0 in
	    for j = 0 to k - 1 do
	      if i land (1 lsl j) <> 0 then (
		y := !y * ds.(j);
		incr c
	      )
	    done;
	    if !c land 1 = 0
	    then res := Int64.add !res (Int64.of_int (s * (d.(!y) - ofs)))
	    else res := Int64.sub !res (Int64.of_int (s * (d.(!y) - ofs)));
	    d.(!y) <- d.(!y) + s;
	done;
	Printf.printf "%Ld\n" !res;
    done;


let read_int _ = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x);;
let print_int x = Printf.printf "%d " x;;

let () =
  let n = read_int() in
  let a = Array.init n read_int in
  let res = Array.make n 0 in
  for i = 0 to (n-1) do
    let seen = Array.make n 0 in
    let index = ref (a.(i)-1) in
    seen.(!index) <- 1;
    res.(!index) <- res.(!index) + 1;
    for j = i+1 to (n-1) do
      let k = a.(j)-1 in
      seen.(k) <- seen.(k) + 1;
      if seen.(k) > seen.(!index) ||
         (seen.(k) == seen.(!index) && k < !index) then
        (index := k);
      res.(!index) <- res.(!index) + 1
    done
  done;
  Array.iter print_int res;;

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let t = Array.init n (fun _ -> -1 + read_int()) in
  let wins = Array.make n 0 in

  for i=0 to n-1 do
    let counts = Array.make n 0 in
    let rec loop j maxcount maxcolor = if j < n then (
      let c = t.(j) in
      let nv = counts.(c) + 1 in
      counts.(c) <- nv;
      if nv > maxcount then (
	wins.(c) <- wins.(c) + 1;
	loop (j+1) nv c
      ) else if nv = maxcount then (
	if c < maxcolor then (
	  wins.(c) <- wins.(c) + 1;
	  loop (j+1) nv c
	) else (
	  wins.(maxcolor) <- wins.(maxcolor) + 1;
	  loop (j+1) nv maxcolor
	)
      ) else (
	wins.(maxcolor) <- wins.(maxcolor) + 1;
	loop (j+1) maxcount maxcolor
      )
    )
    in
    loop i 0 0
  done;

  for i=0 to n-1 do
    printf "%d " wins.(i)
  done;

  print_newline()

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let t = Array.init n (fun _ -> -1 + read_int()) in
  let wins = Array.make n 0 in

  for i=0 to n-1 do
    let counts = Array.make n 0 in
    let rec loop j maxcount maxcolor = if j = n then () else (
      let c = t.(j) in
      let nv = counts.(c) + 1 in
      counts.(c) <- nv;
      if nv > maxcount then (
	wins.(c) <- wins.(c) + 1;
	loop (j+1) nv c
      ) else if nv = maxcount then (
	if c < maxcolor then (
	  wins.(c) <- wins.(c) + 1;
	  loop (j+1) nv c
	) else (
	  wins.(maxcolor) <- wins.(maxcolor) + 1;
	  loop (j+1) nv maxcolor
	)
      ) else loop (j+1) maxcount maxcolor
    )
    in
    loop i 0 0
  done;

  for i=0 to n-1 do
    printf "%d " wins.(i)
  done;

  print_newline()


exception Winner of string

let maximal_score l =
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s)
    with
      |Not_found -> Hashtbl.add t p s
  ) l;
  let maxs = Hashtbl.fold (fun _ s v -> max v s) t 0 in
  let pls = Hashtbl.fold (fun p s l -> if s = maxs then p :: l else l) t [] in
  (maxs, pls)

let winner l =
  let (maxs, pls) = maximal_score l in
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s);
      if s' + s >= maxs && List.mem p pls then (raise (Winner p))
    with
      |Not_found ->
        Hashtbl.add t p s;
        if s >= maxs && List.mem p pls then (raise (Winner p))
  ) l

let rec input_list n =
  if n = 0 then []
  else begin try
    let (p,s) = Scanf.fscanf stdin "%s %i\n" (fun a b -> (a,b)) in
    (p,s) :: (input_list (n-1))
  with
    |Not_found -> []
  end

let () =
  let n = int_of_string (read_line ()) in
  try
    winner (input_list n)
  with
    |Winner(s) -> Printf.printf "%s\n" s

open Hashtbl;;
open Scanf;;
open List;;

let players = Hashtbl.create 0;;
let scores = ref [];;

let ib = Scanf.Scanning.stdib;;
let add_player name x =
	if not (Hashtbl.mem players name) then begin
		Hashtbl.add players name 0
	end;

	let player = Hashtbl.find players name in
	let score = player + x in
	let _ = scores := ((name, score) :: !scores) in
	Hashtbl.replace players name score
;;

let ln = read_int ();;
for i = 0 to ln-1 do
	Scanf.bscanf ib "%s %d\n" add_player
done;;

let m = Hashtbl.fold (fun _ p m -> max p m) players 0;;

for i = ln-1 downto 0 do
	let name, score = List.nth (!scores) i in
	if (score >= m) && ((Hashtbl.find players name) = m) then begin
		print_string name;
		exit 0
	end
done;

let (|>) x f = f x

module Player = struct
  type t = String.t
  let equal = (=)
  let hash = Hashtbl.hash
end

type game = {
  nr     : int;
  player : Player.t;
  score  : int;
}

let make_game nr player score = { nr; player; score }

module Scoretbl = Hashtbl.Make (Player)

let parse_games () : game array =
  let parse n =
    Array.init n
      (fun i -> Scanf.scanf "%s %d\n"
                  (fun p s -> make_game i p s)) in
  Scanf.scanf "%d\n" parse

let score_players games : game list Scoretbl.t =
  let scores = Scoretbl.create 10 in
  let add_score g =
    match Scoretbl.mem scores g.player with
      | true -> Scoretbl.replace scores g.player (g :: (Scoretbl.find scores g.player))
      | false -> Scoretbl.add scores g.player [g] in
  Array.iter add_score games;
  scores

let total_score games : int =
  List.fold_left (fun a g -> a + g.score) 0 games

let leaders scores =
  let highscore = ref min_int
  and leaders = ref [] in
  let check p games =
    let s = total_score games in
    if s = !highscore
    then leaders := p :: !leaders
    else if s > !highscore
    then begin
      highscore := s;
      leaders := [p]
    end in
  Scoretbl.iter check scores;
  !highscore, !leaders

let threshold high games =
  let rec count i s = function
    | [] -> i
    | h::t -> if s >= high then i else count h.nr (s + h.score) t
  in count 0 0 (List.rev games)

let winner scores (high, players) =
  let (p,_) =
    List.fold_left (fun ((w,r) as m) pl ->
                     let round = threshold high (Scoretbl.find scores pl) in
                     if round < r then (pl,round) else m)
      ("",max_int)
      players in
  p

let _ =
  let scores = parse_games () |> score_players in
  Printf.printf "%s\n" (winner scores (leaders scores))

let (|>) x f = f x

let read_rounds n a =
  let rec go n acc =
    if n = 0 then
      List.rev acc
    else (
      let line = read_line () in
      let name, v = Scanf.sscanf line "%s %d" (fun x y -> x,y) in
      let vv = (try Hashtbl.find a name with _ -> 0) + v in
      Hashtbl.replace a name vv;
      go (n-1) ((name,vv)::acc)
    )
  in go n []

let rec f maxv a = function
  | [] -> None
  | (name,v)::tl -> if v >= maxv && Hashtbl.find a name = maxv then
      Some name
    else
      f maxv a tl

let () =
  let n = read_int () in
  let a = Hashtbl.create n in
  let rounds = read_rounds n a in
  let maxv = Hashtbl.fold (fun name v maxv -> max maxv v) a 0 in
  match f maxv a rounds with
  | Some name -> print_endline name

let rec read_rounds n score_tbl =
  if n > 0 then
	let line = read_line () in
	let (name, score) = Scanf.sscanf line "%s %d" (fun x y -> (x, y)) in
	(* Printf.printf "line: %s\n" line; *)
	let so_far = (try Hashtbl.find score_tbl name with _ -> 0) + score in
	Hashtbl.replace score_tbl name so_far;
	(* Printf.printf "%s %d\n" name score; *)
	(name, so_far) :: read_rounds (n - 1) score_tbl
  else
	[]

let rec winner rounds max_final_score score_tbl =
  match rounds with
  | [] -> None
  | (name, score) :: tl -> if (score >= max_final_score) && ((Hashtbl.find score_tbl name) = max_final_score) then
							 Some name
						   else
							 winner tl max_final_score score_tbl

let () =
  let n = read_int () in
  let score_tbl = Hashtbl.create n in
  let rounds = read_rounds n score_tbl in
  let max_final_score = ref 0 in
  Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;
  match winner rounds !max_final_score score_tbl with
  | Some name -> Printf.printf "%s\n" name

let rec read_rounds n score_tbl =
  if n > 0 then
	let line = read_line () in
	let (name, score) = Scanf.sscanf line "%s %d" (fun x y -> (x, y)) in
	(* Printf.printf "line: %s\n" line; *)
	Hashtbl.replace score_tbl name ((try Hashtbl.find score_tbl name with _ -> 0) + score);
	(* Printf.printf "%s %d\n" name score; *)
	(name, score) :: read_rounds (n - 1) score_tbl
  else
	[]

let rec winner rounds max_final_score score_tbl =
  match rounds with
  | [] -> None
  | (name, score) :: tl -> let x = (try Hashtbl.find score_tbl name with _ -> 0) + score in
						   if x >= max_final_score then
							 Some name
						   else (
							 Hashtbl.replace score_tbl name x;
							 winner tl max_final_score score_tbl
						   )

let () =
  let n = read_int () in
  let score_tbl = Hashtbl.create n in
  let rounds = read_rounds n score_tbl in
  let max_final_score = ref 0 in
  Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;
  let score_tbl2 = Hashtbl.create n in
  match winner rounds !max_final_score score_tbl2 with
  | Some name -> Printf.printf "%s\n" name

let rec read_rounds n score_tbl =
  if n > 0 then
	let line = read_line () in
	let (name, score) = Scanf.sscanf line "%s %d" (fun x y -> (x, y)) in
	(* Printf.printf "line: %s\n" line; *)
	let so_far = (try Hashtbl.find score_tbl name with _ -> 0) + score in
	Hashtbl.replace score_tbl name so_far;
	(* Printf.printf "%s %d\n" name score; *)
	(name, so_far) :: read_rounds (n - 1) score_tbl
  else
	[]

let rec winner rounds max_final_score =
  match rounds with
  | [] -> None
  | (name, score) :: tl -> if score >= max_final_score then Some name else winner tl max_final_score

let () =
  let n = read_int () in
  let score_tbl = Hashtbl.create n in
  let rounds = read_rounds n score_tbl in
  let max_final_score = ref 0 in
  Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;
  match winner rounds !max_final_score with
  | Some name -> Printf.printf "%s\n" name

let rec read_rounds n score_tbl =
  if n > 0 then
	let line = read_line () in
	let (name, score) = Scanf.sscanf line "%s %d" (fun x y -> (x, y)) in
	(* Printf.printf "line: %s\n" line; *)
	Hashtbl.replace score_tbl name ((try Hashtbl.find score_tbl name with _ -> 0) + score);
	(* Printf.printf "%s %d\n" name score; *)
	(name, score) :: read_rounds (n - 1) score_tbl
  else
	[]

let rec winner rounds max_final_score score_tbl =
  match rounds with
  | [] -> None
  | (name, score) :: tl -> let x = (try Hashtbl.find score_tbl name with _ -> 0) + score in
						   if x >= max_final_score then
							 Some name
						   else (
							 Hashtbl.replace score_tbl name x;
								 winner tl max_final_score score_tbl
						   )

let () =
  let n = read_int () in
  let score_tbl = Hashtbl.create n in
  let rounds = read_rounds n score_tbl in
  let max_final_score = ref 0 in
  Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;
  Hashtbl.reset score_tbl;
  match winner rounds !max_final_score score_tbl with
  | Some name -> Printf.printf "%s\n" name

open Hashtbl;;
open Scanf;;
open List;;

let players = Hashtbl.create 0;;
let scores = ref [];;

let ib = Scanf.Scanning.stdib;;
let add_player name x =
	if not (Hashtbl.mem players name) then begin
		Hashtbl.add players name 0
	end;

	let player = Hashtbl.find players name in
	let score = player + x in
	let _ = scores := ((name, score) :: !scores) in
	Hashtbl.replace players name score
;;

let ln = read_int ();;
for i = 0 to ln-1 do
	Scanf.bscanf ib "%s %d\n" add_player
done;;

let m = Hashtbl.fold (fun _ p m -> max p m) players 0;;

if ln = 15 then print_int m;

for i = ln-1 downto 0 do
	let name, score = List.nth (!scores) i in
	if (score = m) && ((Hashtbl.find players name) = m) then begin
		print_string name;
		exit 0
	end
done;

open Hashtbl;;
open Scanf;;
open List;;

let players = Hashtbl.create 0;;
let scores = ref [];;

let ib = Scanf.Scanning.stdib;;
let add_player name x =
	if not (Hashtbl.mem players name) then begin
		Hashtbl.add players name 0
	end;

	let player = Hashtbl.find players name in
	let score = player + x in
	let _ = scores := ((name, score) :: !scores) in
	Hashtbl.replace players name score
;;

let ln = read_int ();;
for i = 0 to ln-1 do
	Scanf.bscanf ib "%s %d\n" add_player
done;;

let m = Hashtbl.fold (fun _ p m -> max p m) players 0;;

for i = List.length (!scores) - 1 downto 0 do
	let name, score = List.nth (!scores) i in
	if (score = m) && ((Hashtbl.find players name) = m) then begin
		print_string name;
		exit 0
	end
done;

open Hashtbl;;
open Scanf;;
open List;;

let players = Hashtbl.create 0;;
let scores = ref [];;

let ib = Scanf.Scanning.stdib;;
let add_player name x =
	if not (Hashtbl.mem players name) then begin
		Hashtbl.add players name 0
	end;

	let player = Hashtbl.find players name in
	let score = player + x in
	let _ = scores := ((name, score) :: !scores) in
	Hashtbl.replace players name score
;;

let ln = read_int ();;
for i = 0 to ln-1 do
	Scanf.bscanf ib "%s %d\n" add_player
done;;

let m = Hashtbl.fold (fun _ p m -> max p m) players 0;;

for i = ln-1 downto 0 do
	let name, score = List.nth (!scores) i in
	if (score = m) && ((Hashtbl.find players name) = m) then begin
		print_string name;
		exit 0
	end
done;

exception Winner of string

let maximal_score l =
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s)
    with
      |Not_found -> Hashtbl.add t p s
  ) l;
  Hashtbl.fold (fun _ s v -> max v s) t 0

let winner l =
  let maxs = maximal_score l in
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s);
      if s' + s = maxs then (raise (Winner p))
    with
      |Not_found ->
          Hashtbl.add t p s;
          if s = maxs then (raise (Winner p))
  ) l

let rec input_list n =
  if n = 0 then []
  else begin try
    let (p,s) = Scanf.fscanf stdin "%s %i\n" (fun a b -> (a,b)) in
    (p,s) :: (input_list (n-1))
  with
    |Not_found -> []
  end

let () =
  let n = int_of_string (read_line ()) in
  try
    winner (input_list n)
  with
    |Winner(s) -> Printf.printf "%s\n" s

exception Winner of string

let maximal_score l =
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s)
    with
      |Not_found -> Hashtbl.add t p s
  ) l;
  Hashtbl.fold (fun _ s v -> max v s) t 0

let winner l =
  let maxs = maximal_score l in
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s);
      if s' + s >= maxs then (raise (Winner p))
    with
      |Not_found ->
          Hashtbl.add t p s;
          if s >= maxs then (raise (Winner p))
  ) l

let rec input_list n =
  if n = 0 then []
  else begin try
    let (p,s) = Scanf.fscanf stdin "%s %i\n" (fun a b -> (a,b)) in
    (p,s) :: (input_list (n-1))
  with
    |Not_found -> []
  end

let () =
  let n = int_of_string (read_line ()) in
  try
    winner (input_list n)
  with
    |Winner(s) -> Printf.printf "%s\n" s

exception Winner of string

let maximal_score l =
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s)
    with
      |Not_found -> Hashtbl.add t p s
  ) l;
  Hashtbl.fold (fun _ s v -> max v s) t 0

let winner l =
  let maxs = maximal_score l in
  print_int maxs;
  print_endline "";
  let t = Hashtbl.create 13 in
  List.iter (fun (p,s) ->
    try
      let s' = Hashtbl.find t p in
      Hashtbl.replace t p (s' + s);
      if s' + s >= maxs then (raise (Winner p))
    with
      |Not_found ->
          Hashtbl.add t p s;
          if s >= maxs then (raise (Winner p))
  ) l

let rec input_list n =
  if n = 0 then []
  else begin try
    let (p,s) = Scanf.fscanf stdin "%s %i\n" (fun a b -> (a,b)) in
    (p,s) :: (input_list (n-1))
  with
    |Not_found -> []
  end

let () =
  let n = int_of_string (read_line ()) in
  try
    winner (input_list n)
  with
    |Winner(s) -> Printf.printf "%s\n" s

let (|>) x f = f x
let identity x = x

module Player = struct
  type t = String.t
  let equal = (=)
  let hash = Hashtbl.hash
end

module Gametbl = Hashtbl.Make (Player)

module Score = struct
  type t = int
  let equal = (=)
  let hash = identity
end

module Scoretbl = Hashtbl.Make (Score)

let parse_games () =
  let games = Gametbl.create 10 in
  let push k v =
    match Gametbl.mem games k with
        true -> Gametbl.replace games k (v::(Gametbl.find games k))
      | false -> Gametbl.add games k [v] in
  let rec loop = function
      0 -> ()
    | n -> Scanf.scanf "%s %d\n" push; loop (n - 1) in
  Scanf.scanf "%d\n" loop;
  games

let best_players gt =
  let scores = Scoretbl.create 10 in
  let max_score = ref 0 in
  let score_player p game_scores =
    let s = List.fold_left (+) 0 game_scores in
    max_score := max !max_score s;
    match Scoretbl.mem scores s with
        true -> Scoretbl.replace scores s (p::(Scoretbl.find scores s))
      | false -> Scoretbl.add scores s [p] in
  Gametbl.iter score_player gt;
  !max_score, Scoretbl.find scores !max_score

let winner gt (m,players) =
  match players with
    [] -> raise (Invalid_argument "No Player")
    | p::ps -> let rec score_reached scores cs i =
      if cs >= m
      then i
      else
        match scores with
            [] -> i
          | h::t -> score_reached t (cs+h) (i+1) in
      let game = ref (score_reached (List.rev (Gametbl.find gt p)) 0 0) in
      let better_player bp pl =
        let g = score_reached (List.rev (Gametbl.find gt pl)) 0 0 in
        if g < !game then (game := g; pl) else bp in
      List.fold_left better_player p ps

let _ =
  let gt = parse_games () in
  Printf.printf "%s\n" (winner gt (best_players gt))

let (|>) x f = f x

module Player = struct
  type t = String.t
  let equal = (=)
  let hash = Hashtbl.hash
end

type game = {
  nr     : int;
  player : Player.t;
  score  : int;
}

let make_game nr player score = { nr; player; score }

module Scoretbl = Hashtbl.Make (Player)

let parse_games () : game array =
  let parse n =
    Array.init n
      (fun i -> Scanf.scanf "%s %d\n"
                  (fun p s -> make_game i p s)) in
  Scanf.scanf "%d\n" parse

let score_players games : game list Scoretbl.t =
  let scores = Scoretbl.create 10 in
  let add_score g =
    match Scoretbl.mem scores g.player with
      | true -> Scoretbl.replace scores g.player (g :: (Scoretbl.find scores g.player))
      | false -> Scoretbl.add scores g.player [g] in
  Array.iter add_score games;
  scores

let total_score games : int =
  List.fold_left (fun a g -> a + g.score) 0 games

let leaders scores =
  let highscore = ref min_int
  and leaders = ref [] in
  let check p games =
    let s = total_score games in
    if s = !highscore
    then leaders := p :: !leaders
    else if s > !highscore
    then begin
      highscore := s;
      leaders := [p]
    end in
  Scoretbl.iter check scores;
  !highscore, !leaders

let threshold high games =
  let rec count i s = function
    | [] -> i
    | h::t -> if s >= high then i else count (i + 1) (s + h.score) t
  in count 0 0 (List.rev games)

let winner scores (high, players) =
  let (p,_) =
    List.fold_left (fun ((w,r) as m) pl ->
                     let round = threshold high (Scoretbl.find scores pl) in
                     if round < r then (pl,round) else m)
      ("",max_int)
      players in
  p

let _ =
  let scores = parse_games () |> score_players in
  Printf.printf "%s\n" (winner scores (leaders scores))


open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_long () = bscanf Scanning.stdib " %Ld " (fun x -> x)

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b

let () =
  let n = read_int () in
  let m = read_int () in

  let a = Array.make_matrix n m 0L in

  for i=0 to n-1 do
    for j=0 to m-1 do
      a.(i).(j) <- read_long ()
    done
  done;

  let ur = Array.make_matrix n m 0L in
  let dr = Array.make_matrix n m 0L in
  let ul = Array.make_matrix n m 0L in
  let dl = Array.make_matrix n m 0L in

  let probe a i j = if i<0 || j<0 || i>n-1 || j>m-1 then 0L else a.(i).(j) in

  for i=0 to n-1 do
    for j=0 to m-1 do
      ul.(i).(j) <- a.(i).(j) ++ (max (probe ul (i-1) j) (probe ul i (j-1)))
    done;
    for j=m-1 downto 0 do
      ur.(i).(j) <- a.(i).(j) ++ (max (probe ur (i-1) j) (probe ur i (j+1)))
    done
  done;

  for i=n-1 downto 0 do
    for j=0 to m-1 do
      dl.(i).(j) <- a.(i).(j) ++ (max (probe dl (i+1) j) (probe dl i (j-1)))
    done;
    for j=m-1 downto 0 do
      dr.(i).(j) <- a.(i).(j) ++ (max (probe dr (i+1) j) (probe dr i (j+1)))
    done
  done;

  let best = ref 0L in

  for i=1 to n-2 do
    for j=1 to m-2 do
      let opt1 = ul.(i-1).(j) ++ ur.(i).(j+1) ++ dl.(i).(j-1) ++ dr.(i+1).(j) in
      let opt2 = ur.(i-1).(j) ++ dr.(i).(j+1) ++ ul.(i).(j-1) ++ dl.(i+1).(j) in
      best := max (max opt1 opt2) !best
    done
  done;

  printf "%Ld\n" !best

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (+:) (a,b) (c,d) = (a+c,b+d)
let (-:) (a,b) (c,d) = (a-c,b-d)
(* number theory *)
let sieve_under len = (* len > 0 *)
  let sieve  = Array.make len true in
  Array.fill sieve 0 (min len 2) false;
  let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in
  for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;
  sieve
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let _ =
  let row = read_int() in
  let col = read_int() in
  let mat = make_matrix row col 0 in
  for i = 0 to row -1 do
    for j = 0 to col -1 do
      mat.(i).(j) <- read_int()
    done
  done;

  let is_valid (y,x) =
    0 <= x && x < col &&
    0 <= y && y < row
  in
  let save mat (y,x) v = mat.(y).(x) <- v; v in
  let read mat (y,x) = mat.(y).(x) in

  let cub = init 4 (fun i -> make_matrix row col (-1)) in
  let config = [|
    [| (row-1,col-1); (-1,0); (0,-1) |];
    [| (0,0)        ; (1,0) ; (0,1)  |];
    [| (row-1,0)    ; (-1,0); (0, 1) |];
    [| (0,col-1)    ; (1,0) ; (0,-1) |];
  |] in

  for i = 0 to 3 do
    let rec dp pos =
      if not (is_valid pos) then 0 else
      let t = read cub.(i) pos in
      if t <> (-1) then t else begin
        let m  = max (dp (pos +: config.(i).(1))) (dp (pos +: config.(i).(2))) in
        save cub.(i) pos (m + read mat pos)
      end
    in
    dp config.(i).(0) |> ignore;
  done;

  let rec run i j m =
    if i = row-1 then m else
    if j = col-1 then run (i+1) 1 m else
    let pos = (i,j) in
    let a = read cub.(0) (pos -: (0,1)) + read cub.(1) (pos +: (0,1))
          + read cub.(2) (pos -: (1,0)) + read cub.(3) (pos +: (1,0)) in
    let b = read cub.(0) (pos -: (1,0)) + read cub.(1) (pos +: (1,0))
          + read cub.(2) (pos +: (0,1)) + read cub.(3) (pos -: (0,1)) in
    let m' = max a b in
    run i (j+1) (max m m')
  in

 (*  for i = 0 to 3 do print_matrix ("%d ") cub.(i) done;
 *)
  printf "%d\n" (run 1 1 0)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (+:) (a,b) (c,d) = (a+c,b+d)
let (-:) (a,b) (c,d) = (a-c,b-d)
(* number theory *)
let sieve_under len = (* len > 0 *)
  let sieve  = Array.make len true in
  Array.fill sieve 0 (min len 2) false;
  let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in
  for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;
  sieve
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let _ =
  let row = read_int() in
  let col = read_int() in
  let mat = make_matrix row col 0 in
  for i = 0 to row -1 do
    for j = 0 to col -1 do
      mat.(i).(j) <- read_int()
    done
  done;

  let is_valid (y,x) =
    0 <= x && x < col &&
    0 <= y && y < row
  in
  let save mat (y,x) v = mat.(y).(x) <- v; v in
  let read mat (y,x) = mat.(y).(x) in

  let cub = init 4 (fun i -> make_matrix row col (-1)) in
  let config = [|
    [| (row-1,col-1); (-1,0); (0,-1) |];
    [| (row-1,0)    ; (-1,0); (0, 1) |];
    [| (0,col-1)    ; (1,0) ; (0,-1) |];
    [| (0,0)        ; (1,0) ; (0,1)  |];
  |] in

  for i = 0 to 3 do
    let rec dp pos =
      if not (is_valid pos) then 0 else
      let t = read cub.(i) pos in
      if t <> (-1) then t else begin
        let m  = max (dp (pos +: config.(i).(1))) (dp (pos +: config.(i).(2))) in
        save cub.(i) pos (m + read mat pos)
      end
    in
    dp config.(i).(0) |> ignore;
  done;

  let rec run i j m =
    if i = row then m else
    if j = col then run (i+1) 0 m else
    let pos = (i,j) in
    let m' = for_ 0 4 0 (fun i c -> c + read cub.(i) pos) - 4 * read mat pos in
    run i (j+1) (max m m')
  in

  (* for i = 0 to 3 do print_matrix ("%d ") cub.(i) done; *)
  printf "%d\n" (run 0 0 0)


let compte mot =
	let tab = Array.make 123 0 in
	for i=0 to String.length mot-1 do
		tab.(int_of_char (mot.[i])) <- 1 + tab.(int_of_char (mot.[i]));
	done;
	tab;;

let f mot1 mot2 =
	let tab1 = compte mot1 and tab2 = compte mot2
	and compteur = ref 0 and compteur2 = ref 0 in
	for i=0 to 122 do
		let a = min (tab1.(i)) (tab2.(i)) in
			compteur := a + !compteur;
			tab1.(i) <- tab1.(i) - a;
			tab2.(i) <- tab2.(i) - a;
	done;
	let tab_r1 = Array.init 26 (fun i -> tab1.(65 +i) + tab1.(97 + i))
	and tab_r2 = Array.init 26 (fun i -> tab2.(65 +i) + tab2.(97 + i))
	in
	for i=0 to 25 do
		let a = min (tab_r1.(i)) (tab_r2.(i)) in
			compteur2 := a + !compteur2;
			tab_r1.(i) <- tab_r1.(i) - a;
			tab_r2.(i) <- tab_r2.(i) - a;
	done;
	!compteur, !compteur2;;

let main () =
	let mot1 = Scanf.scanf "%s " (fun i -> String.trim i) in
	let mot2 = Scanf.scanf "%s " (fun i -> String.trim i) in
	let (a,b) = f mot1 mot2 in
		Printf.printf "%d %d " a b;;

main ();;

open Printf
open Scanf

let isupper c = c <= 'Z' && c >= 'A'
let l2n c = (int_of_char c) - (int_of_char 'a')
let l2N c = (int_of_char c) - (int_of_char 'A')

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let s = read_string () in
  let t = read_string () in

  let compute_hist s =
    let h = Array.make_matrix 26 2 0 in
    let n = String.length s in
    for i=0 to n-1 do
      if isupper s.[i] then (
	let x = l2N s.[i] in
	h.(x).(1) <- h.(x).(1) + 1;
      ) else (
	let x = l2n s.[i] in
	h.(x).(0) <- h.(x).(0) + 1;
      )
    done;
    h
  in

  let hist_s = compute_hist s in
  let hist_t = compute_hist t in

  let ( ++ ) (a,b) (c,d) = (a+c, b+d) in

  let eval_letter ls hs lt ht =
    let yay = (min ls lt) + (min hs ht) in
    let short = min (ls+hs) (lt+ht) in
    (yay, short-yay)
  in

  let (x,y) = fold 0 25 (
    fun i ac ->
      (eval_letter hist_s.(i).(0) hist_s.(i).(1) hist_t.(i).(0) hist_t.(i).(1)) ++ ac
  ) (0,0)
  in

  printf "%d %d\n" x y


let rec print1 n =
  for i = 1 to n do
  	Printf.printf "1";
  done;;

let n = read_int () ;;
if n mod 2 == 0 then print1 (n / 2)
else begin
	print_int 7;
	print1 (n / 2 - 1)
end

let a = read_int();;
let n = ref a;;

if (a mod 2 == 1) then
	print_int 7;
	n := a-3;;

if (a mod 2 == 0) then
	n := a;;

let x = (!n)/2
for i=1 to x do
	Printf.printf "1"
done

let n=read_int();;
let g = n;
if n mod 2 == 1 then print_string("7");
let n = if n mod 2 == 1 then n - 3 else n in
for i = 1 to n / 2 do
print_string("1");
done;;

open Printf;;
let n=read_int();;

if n mod 2 > 0 then begin
    printf "7";
    for i=1 to (n-3)/2 do
        printf "1"
    done
end
else begin
  for i=1 to n/2 do
    printf "1"
    done
end;;

open Printf;;

let n=read_int();;

(if (n mod 2 == 1) then
    printf "%d" (7)
);

for i = 1 to (n / 2 - (n mod 2)) do
    printf "%d" (1)
done;;

let n=read_int();;
if n == 1 then print_endline("0")
else
	for i = 1 to n/2 do
	    if n mod 2 == 1 && i==1 then Printf.printf "%d" 7
    	else Printf.printf "%d" 1
 	done;;

let rec print1 n =
  for i = 1 to n do
  	Printf.printf "1";
  done;;

let n = read_int () ;;
if n mod 2 == 0 then print1 (n / 2)
else begin
	print1 (n / 2 - 1) ;
	print_int 7
end

let rec print1 n =
  match n with
  | -1  -> true;
  | 0  -> true;
  | nn -> print_int 1 ; print1 (n-1)

let n = read_int () ;;
if n mod 2 == 0 then print1 (n / 2)
else begin
	print1 (n / 2 - 1) ;
	print_int 7;
	true
end


let xint _ = Scanf.scanf " %d" (fun x -> x)

let () =
  let min x y =
    if x < y then x
    else y
  in
  let n = xint() and w = xint() in
  let a = Array.make (n * 2) 0 in
  for i = 0 to (n * 2 - 1) do
    a.(i) <- xint();
  done;
  Array.sort compare a;
  let x = a.(0) and y = a.(n) in
  let z = min (float_of_int y) ((float_of_int x) *. 2.) in
  Printf.printf "%.10f\n" (min (float_of_int w) (z *. 1.5 *. (float_of_int n)));

module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue
module S = String

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let (|>) x f = f x
let (@@) f x = f x

let id x = x
let id2 x y = (x, y)
let id3 x y z = (x, y, z)
let id4 a b c d = (a, b, c, d)
let id5 a b c d e = (a, b, c, d, e)

let err s = raise (Failure s)

let inf = 1000000000
let eps = 1e-11

let _ =
  let n, w = sf "%d %f " id2 in
  let a = A.make (2 * n) 0. in
  for i = 0 to 2 * n - 1 do
    let ai = sf "%d " id in
    a.(i) <- float ai
  done;
  A.sort compare a;
  let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in
  r *. 1.5 *. float n |> min w |> pf "%.9f\n"
;;

module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue
module S = String

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let (|>) x f = f x
let (@@) f x = f x

let id x = x
let id2 x y = (x, y)
let id3 x y z = (x, y, z)
let id4 a b c d = (a, b, c, d)
let id5 a b c d e = (a, b, c, d, e)

let err s = raise (Failure s)

let inf = 1000000000
let eps = 1e-11

let _ =
  let n, w = sf "%d %d " id2 in
  let a = A.make (2 * n) 0. in
  for i = 0 to 2 * n - 1 do
    let ai = sf "%d " id in
    a.(i) <- float ai
  done;
  A.sort compare a;
  let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in
  r *. 1.5 *. float n |> max 1. |> pf "%.9f\n"
;;

module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue
module S = String

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let (|>) x f = f x
let (@@) f x = f x

let id x = x
let id2 x y = (x, y)
let id3 x y z = (x, y, z)
let id4 a b c d = (a, b, c, d)
let id5 a b c d e = (a, b, c, d, e)

let err s = raise (Failure s)

let inf = 1000000000
let eps = 1e-11

let _ =
  let n, w = sf "%d %d " id2 in
  let a = A.make (2 * n) 0. in
  for i = 0 to 2 * n - 1 do
    let ai = sf "%d " id in
    a.(i) <- float ai
  done;
  A.sort compare a;
  let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in
  pf "%.9f\n" @@ r *. 1.5 *. float n
;;


let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";;
let b2i x = if x == true then 1 else 0;;

let n = scan_int() and m = scan_int();;
let a = Array.make n 0 and b = Array.make m (0, 0) and wyn = Array.make m 0;;

for i = 0 to n - 1 do
  a.(i) <- scan_int ();
done;

for i = 0 to m - 1 do
  b.(i) <- (scan_int (), i);
done;

Array.sort compare a; Array.sort compare b;

let cnt = ref 0 and l = ref 0 in

for i = 0 to m - 1 do
  while (!l < n) && a.(!l) <= fst (b.(i)) do
    incr cnt; incr l;
  done;
  wyn.(snd b.(i)) <- !cnt;
done;

for i = 0 to m - 1 do
  print_int(wyn.(i)); psp();
done;

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";;
let b2i x = if x == true then 1 else 0;;

let n = scan_int() and m = scan_int();;
let a = Array.make n 0 and b = Array.make m (0, 0) and wyn = Array.make m 0;;

for i = 0 to n - 1 do
  a.(i) <- scan_int ();
done;

for i = 0 to m - 1 do
  b.(i) <- (scan_int (), i);
done;

Array.fast_sort compare a; Array.fast_sort compare b;

let cnt = ref 0 and l = ref 0 in

for i = 0 to m - 1 do
  while (!l < n) && a.(!l) <= fst (b.(i)) do
    incr cnt; incr l;
  done;
  wyn.(snd b.(i)) <- !cnt;
done;

for i = 0 to m - 1 do
  print_int(wyn.(i)); psp();
done;

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let b = Array.make m 0 in
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 0 to m - 1 do
      b.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    Array.sort compare a;
    for i = 0 to m - 1 do
      let l = ref (-1)
      and r = ref n in
	while !l < !r - 1 do
	  let m = (!l + !r) / 2 in
	    if a.(m) <= b.(i)
	    then l := m
	    else r := m
	done;
	Printf.printf "%d " !r;
    done;
    Printf.printf "\n"


type passenger = {
    mutable f : int;
    mutable t : int;
};;

(* Echange deux éléments d'un tableau *)
let echange tab i j =
    let z = tab.(i) in
        tab.(i) <- tab.(j);
        tab.(j) <- z;;

(* Quicksort : Sort on the floor of each passenger *)
let partition tab p r =
    let x = tab.(r) in (* Pivot *)
    let i = ref (p - 1) in
        for j = p to r - 1 do
            if tab.(j).f <= x.f then begin
                i := !i + 1 ;
                echange tab !i j
            end
        done ; echange tab (!i + 1) r ;
        (!i + 1);;
let rec quickSort tab p r =
    if p < r then begin
        let q = partition tab p r in
            quickSort tab p (q-1) ;
            quickSort tab (q + 1) r
    end;;

let n, s = Scanf.scanf "%d %d " (fun n' s' -> n', s') in
    let passengers = Array.init n (fun _i ->
        let pass_f, pass_t = Scanf.scanf "%d %d " (fun f' t' -> f', t') in
            {f = pass_f ; t = pass_t}
    ) in
        quickSort passengers 0 (n-1) ;
        let time = ref 0 in
        let floor = ref s in
            for i = 0 to (n-1) do
                time := !time + (!floor - (passengers.(i).f)); (* Temps de descente *)
                floor := passengers.(i).f;
                if !time < passengers.(i).t then
                    time := !time + (passengers.(i).t - !time) (* Temps d'attente *)
            done ;
            time := !time + !floor ; (* On descend tout en bas *)
            print_int !time;;

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))

let () =
  let n = read_int () in
  let s = read_int () in
  let pass = Array.init n (fun _ -> read_pair()) in
  let arrive = Array.make (s+1) 0 in

  for i=0 to n-1 do
    let (f,t) = pass.(i) in
    arrive.(f) <- max arrive.(f) t
  done;

  let rec loop floor time = if floor = 0 then time else
  (* at floor arrive at time *)
      let time = max time arrive.(floor) in
      loop (floor-1) (time+1)
  in

  printf "%d\n" (loop s 0)

let r2 = Scanf.scanf " %d %d" ;;
let n, s = r2 (fun x y -> (x, y)) ;;

let a = Array.make s 0 ;;
for _ = 1 to n do
    let f, t = r2 (fun x y -> (x-1, y)) in
    a.(f) <- max a.(f) t
done ;;

let rec time f t = match f with
    | 0 -> t
    | f -> time (f-1) (1 + max t a.(f-1) )
;;
print_int @@ time s 0


open Printf
open Scanf

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)

let build_answer n b =
  let v = Array.make_matrix n n 0 in
  for i=0 to n-1 do
    v.(i).(i) <- b.(i)
  done;

  for d=2 to n do
    for l=0 to n-d do
      let r = l+d-1 in
      v.(l).(r) <- v.(l+1).(r) lxor v.(l).(r-1)
    done
  done;

  for r=1 to n-1 do
    for l=r-1 downto 0 do
      v.(l).(r) <- max v.(l).(r) v.(l+1).(r)
    done
  done;

  for r=1 to n-1 do
    for l=r-1 downto 0 do
      v.(l).(r) <- max v.(l).(r) v.(l).(r-1)
    done
  done;

  v

let () =
  let n = read_int () in
  let b = Array.init n read_int in
  let q = read_int () in

  let v = build_answer n b in

  for i=1 to q do
    let l = read_int() -1 in
    let r = read_int() -1 in
    printf "%d\n" v.(l).(r)
  done

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";; let pnl () = print_newline ();;
let b2i x = if x == true then 1 else 0;;
let dbg x = print_int(x); pnl();;

let n = scan_int();;
let a = Array.init n (fun i -> scan_int());;

let f = Array.make_matrix n n 0 and wyn = Array.make_matrix n n 0;;
for i = 0 to (n - 1) do
  f.(i).(i) <- a.(i);
  wyn.(i).(i) <- a.(i);
done;;

for i = 2 to n do
  for j = 0 to (n - i) do
    let r = j + i - 1 in
    f.(j).(r) <- f.(j + 1).(r) lxor f.(j).(r - 1);
    wyn.(j).(r) <- max (f.(j).(r)) (max wyn.(j+1).(r) wyn.(j).(r - 1));
  done;
done;;

let q = scan_int();;
for i = 1 to q do
  let a = scan_int() and b = scan_int() in
  print_int(wyn.(a - 1).(b - 1)); pnl();
done;;

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";; let pnl () = print_newline ();;
let b2i x = if x == true then 1 else 0;;
let dbg x = print_int(x); pnl();;

let n = scan_int();;
let a = Array.init n (fun i -> scan_int());;

let f = Array.make_matrix n n 0 and wyn = Array.make_matrix n n 0;;
for i = 0 to (n - 1) do
  f.(i).(i) <- a.(i);
  wyn.(i).(i) <- a.(i);
done;;

for i = 2 to n do
  for j = 0 to (n - i) do
    let r = j + i - 1 in
    f.(j).(r) <- f.(j + 1).(r) lxor f.(j).(r - 1);
    wyn.(j).(r) <- max f.(j).(r) (max f.(j+1).(r) f.(j).(r - 1));
  done;
done;;

let q = scan_int();;
for i = 1 to q do
  let a = scan_int() and b = scan_int() in
  print_int(wyn.(a - 1).(b - 1)); pnl();
done;;


let (+|) = Int64.add
let (-|) = Int64.sub
let ( *| ) = Int64.mul
let ( /| ) = Int64.div

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0L in
  let s = ref 0L in
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%Ld " (fun s -> s);
      s := !s +| a.(i);
    done;
    Array.sort compare a;
    let ma = !s /| Int64.of_int n in
    let mb =
      ma +| if ma *| Int64.of_int n = !s then 0L else 1L
    in
    let x = ref 0L in
    let y = ref 0L in
      for i = 0 to n - 1 do
	if a.(i) < ma
	then x := !x +| ma -| a.(i)
	else if a.(i) > mb
	then y := !y +| a.(i) -| mb
      done;
      let res = max !x !y in
      Printf.printf "%Ld\n" res

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let ( ++ ) a b = Int64.add a b
let ( ** ) a b = Int64.mul a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let long x = Int64.of_int x
let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))

let () =

  let n = read_int() in
  let nn = long n in
  let m = Array.init n (fun _ -> long (read_int())) in
  let s = sum 0 (n-1) (fun i -> m.(i)) 0L in

  let p = s//nn in
  let q = (s++(nn--1L)) // nn in

  let total_above_q = sum 0 (n-1) (fun i -> max 0L (m.(i) -- q)) 0L in
  let total_below_p = sum 0 (n-1) (fun i -> max 0L (p -- m.(i))) 0L in

  printf "%Ld\n" (max total_above_q total_below_p)

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let ( ++ ) a b = Int64.add a b
let ( ** ) a b = Int64.mul a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let long x = Int64.of_int x
let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))

let () =

  let n = read_int() in
  let nn = long n in
  let m = Array.init n (fun _ -> long (read_int())) in
  let s = sum 0 (n-1) (fun i -> m.(i)) 0L in

  let p = s//nn in
  let q = (s++(nn--1L)) // nn in

  let total_above_q = sum 0 (n-1) (fun i -> max 0L (m.(i) -- q)) 0L in
  let total_below_p = sum 0 (n-1) (fun i -> min 0L (p -- m.(i))) 0L in

  printf "%Ld\n" (max total_above_q total_below_p)