let read () = Scanf.scanf "%d " (fun n -> n)
let print int = Printf.printf "%d\n" int

let binary_search arr n value =
    let result =
        (let rec search low high =
            if high = low || high - low = 1
            then
                low
            else
                let mid = (low + high) / 2 in
                if arr.(mid - 1) > value
                then
                    search low mid
                else
                    search mid high
        in search 0 (n + 1))
    in
    print result

let input () =
    let n = read () in
    let price = Array.init n (fun n -> read ()) in
    let m = read () in
    let cash = Array.init m (fun n -> read ()) in
    (n, price, cash)

let solve (n, price, cash) =
    (Array.fast_sort Pervasives.compare price;
    Array.iter (binary_search price n) cash)

let () = solve (input ())

let read () = Scanf.scanf "%d " (fun n -> n)
let print int = Printf.printf "%d\n" int

let make_array n =
    let arr = Array.make n 0 in
    let rec loop i =
        if i < n
        then
            (let int = read () in
            Array.set arr i int;
            loop (i + 1))
        else
            arr
    in loop 0

let binary_search arr n value =
    let result =
        (let rec search low high =
            if high = low || high - low = 1
            then
                low
            else
                let mid = (low + high) / 2 in
                if arr.(mid - 1) > value
                then
                    search low mid
                else
                    search mid high
        in search 0 (n + 1))
    in
    print result

let input () =
    let n = read () in
    let price = make_array n in
    let m = read () in
    let cash = make_array m in
    (n, price, cash)

let solve (n, price, cash) =
    (Array.fast_sort Pervasives.compare price;
    Array.iter (binary_search price n) cash)

let () = solve (input ())

open Printf
open Scanf

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

  Array.sort compare x;

  let find_index m =
  (* return the index of the biggest shop whose cost is <= m *)
  (* -1 if there is no such one *)
    let rec bsearch lo hi =
      (* x.(lo) <= m   x.(hi) > m *)
      if lo + 1 = hi then lo else
	let mid = (lo+hi)/2 in
	if x.(mid) <= m then bsearch mid hi else bsearch lo mid
    in
    if x.(n-1) <= m then n-1
    else if x.(0) > m then -1
    else bsearch 0 (n-1)
  in

  for j=0 to q-1 do
    let i = find_index m.(j) in
    printf "%d\n" (i+1)
  done

let read () = Scanf.scanf "%d " (fun n -> n)
let print int = Printf.printf "%d\n" int

let make_array n =
    let arr = Array.make n 0 in
    let rec loop i =
        if i < n
        then
            (let int = read () in
            Array.set arr i int;
            loop (i + 1))
        else
            arr
    in loop 0

let binary_search arr n value =
    let result =
        (let rec search low high contender =
            assert (high >= low);
            if high = low
            then
                if arr.(low) <= value
                then
                    low
                else
                    contender
            else
                let mid = (low + high) / 2 in
                if arr.(mid) > value
                then
                    if mid = low
                    then
                        contender
                    else
                        search low (mid - 1) contender
                else
                    search (mid + 1) high mid

        in search 0 (n - 1) (-1))
    in
    print (result + 1)

let input () =
    let n = read () in
    let price = make_array n in
    let m = read () in
    let cash = make_array m in
    (n, price, cash)

let solve (n, price, cash) =
    (Array.fast_sort Pervasives.compare price;
    Array.iter (binary_search price n) cash)

let () = solve (input ())

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

let count_smaller ele shop_arr n =
  let print n = Printf.printf "%d\n" n in
  if ele < shop_arr.(0) then print 0
  else if ele >= shop_arr.(n-1) then print n
  else
    let rec bsearch low high =
      if low + 1 = high then print high
      else
        let mid = (low + high) / 2 in
        if ele < shop_arr.(mid) then bsearch low mid
        else if ele >= shop_arr.(mid) then bsearch mid high
    in bsearch 0 (n - 1)

let () =
  let n = read_int () in
  let shop_arr = Array.init n (fun _ ->
      read_int ();
    )
  in
  let q = read_int () in
  let coin_arr = Array.init q (fun _ ->
      read_int ();
    )
  in
  Array.sort compare shop_arr;
  Array.iter (fun x -> count_smaller x shop_arr n) coin_arr

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

let count_smaller ele shop_arr n =
  let print n = Printf.printf "%d\n" n in
  if ele < shop_arr.(0) then print 0
  else if ele >= shop_arr.(n-1) then print n
  else
    let rec bsearch low high =
      if low + 1 = high then print high
      else
        let mid = (low + high) / 2 in
        if ele < shop_arr.(mid) then bsearch low mid
        else if ele > shop_arr.(mid) then bsearch mid high
        else print (mid + 1)
    in bsearch 0 (n - 1)

let () =
  let n = read_int () in
  let shop_arr = Array.init n (fun _ ->
      read_int ();
    )
  in
  let q = read_int () in
  let coin_arr = Array.init q (fun _ ->
      read_int ();
    )
  in
  Array.sort compare shop_arr;
  Array.iter (fun x -> count_smaller x shop_arr n) coin_arr


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

open Printf

let init (x : int) (f : int -> 'a) : 'a list =
  let rec build k =
    if k = x then []
    else (f k) :: build (k + 1) in
  build 0
;;

let run () =
  let open Int64 in
  let n = scan_int () |> of_int in
  let k = scan_int () |> of_int in
  let check x =
    sub x (div x n) >= k in
  let rec f lo hi ans =
    if lo > hi then ans
    else begin
      let md = div (add lo hi) 2L in
      ifprintf stdout "%Ld %Ld %Ld %B\n" lo hi md (check md);
      if check md then f lo (sub md 1L) md
      else f (add md 1L) hi ans
    end in
  printf "%Ld\n" (f 1L 3000000000L max_int)
;;

let () =
  let t = scan_int () in
  for i = 1 to t do
    run ()
  done
;;

(* Codeforces 1352 C K-th Not Divisible by n comp   *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

(* reading reversed list *)
let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;

let rec kth_not_div n k =
	let n1 = Int64.pred n in
	let o = Int64.rem k n1 in
	let d = Int64.div k n1 in
	let oo = if (Int64.compare o Int64.zero) == 0 then Int64.minus_one else o in
	let ret = Int64.add (Int64.mul n d) oo in
	ret;;

let do_one () =
    let n = grl () in
    let k = grl () in
		let kth = kth_not_div n k in
  	Printf.printf "%Ld\n" kth;;

let do_all t =
    for i = 1 to t do
        do_one ()
    done;;

let main() =
	let t = gr () in
	do_all t;;

main();;

(* Codeforces 1352 C K-th Not Divisible by n comp   *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

(* reading reversed list *)
let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;

let rec kth_not_div n k =
	let o = k mod (n - 1) in
	let d = k / (n - 1) in
	let ret = (n * d) + (if o==0 then (-1) else o) in
	(* let _ = Printf.printf "n,k,o,d,ret = %d %d %d %d %d\n" n k o d ret in *)
	ret;;

let do_one () =
    let n = gr () in
    let k = gr () in
		let kth = kth_not_div n k in
  	Printf.printf "%d\n" kth;;

let do_all t =
    for i = 1 to t do
        do_one ()
    done;;

let main() =
	let t = gr () in
	do_all t;;

main();;


let dist a b =
	min (10+b-a) (min (abs (10+a-b)) (abs (a-b)))

let _ =

	let (n,ini,fin) = Scanf.scanf "%d %s %s" (fun i j k -> (i,j,k))
	and res = ref 0 and f mot i = int_of_char (mot.[i]) in
		for i=0 to n-1 do
			res := !res + dist (f ini i) (f fin i);
		done;
	Printf.printf "%d\n" (!res)

let input () =
    let n = Scanf.scanf "%d " (fun n -> n) in
    let start = Array.init n (fun i -> Scanf.scanf "%c " (fun i -> i)) in
    let goal = Array.init n (fun i -> Scanf.scanf "%c " (fun i -> i)) in
    (n, start, goal)

let solve (n, start, goal) =
    let rec loop i count =
        if i < n
        then
            let s = Pervasives.int_of_char (start.(i)) in
            let g = Pervasives.int_of_char (goal.(i)) in
            let min = Pervasives.min s g in
            let max = Pervasives.max s g in
            let try_one = max - min in
            let try_two = min + 10 - max in
            let r = Pervasives.min try_one try_two in
            loop (i + 1) (count + r)
        else
            count
    in loop 0 0

let print result = Printf.printf "%d\n" result
let () = print (solve (input ()))

let split x = x |> Str.split (Str.regexp "") |> List.map int_of_string and
    minimum = List.fold_left min 10 and
    sum = List.fold_left (+) 0 in
let  _ = read_line () and
    fromComb = read_line () |> split and
    toComb = read_line () |> split
in
List.map2 (fun x y -> List.map abs [x-y; y-x; 10+x-y; 10+y-x] |> minimum) fromComb toComb |> sum |> print_int

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

let n = read_int();;
let a = read_line();;
let b = read_line();;
let rec solve index =
    if index >= String.length a || index >= String.length b then
        0
    else (
        let d = int_of_char a.[index] - (int_of_char b.[index]) |> abs in
        let dis = min d (10 - d) in
        dis + (solve (index + 1))
    );;
solve 0 |> print_int;;


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

type road_graph = (int * bool) list array
type dep_graph = int list array
type tout_comp = int -> int

let (%) f g x = f @@ g x

let () =
  let make_dfs g =
    let marked, mark =
      let marked = Array.(make (length g) false) in
      (fun v -> marked.(v)),
      (fun v -> marked.(v) <- true)
    in
    fun fout v ->
    let rec dfs v =
      if not (marked v) then begin
        mark v;
        List.iter dfs g.(v);
        fout v
      end
    in
    dfs v
  in
  let add_edge g a b = g.(a) <- b :: g.(a) in
  let transpose g =
    let g' = Array.(make (length g) []) in
    ArrayLabels.iteri g ~f:(fun a -> List.iter @@ fun b -> add_edge g' b a);
    g'
  in
  let condensation (g : dep_graph) : tout_comp =
    let n = Array.length g in
    let add, iter, get_tout =
      let order = Array.make n ~-1 in
      let index = Array.copy order in
      let size = ref 0 in
      (fun v -> incr size; order.(!size - 1) <- v; index.(v) <- !size -1),
      (fun f -> Array.iter f order),
      (fun v -> index.(v))
    in
    let dfs = make_dfs g in
    for i = 0 to n - 1 do dfs add i done;
    let set_parent, get_parent =
      let parent = Array.(make (length g) ~-1) in
      (fun p v -> parent.(v) <- p),
      (fun v -> parent.(v))
    in
    let dfs = make_dfs @@ transpose g in
    iter (fun i -> dfs (set_parent i) i);
    get_tout % get_parent
  in
  let opposite n i = n / 2 - (i - n / 2) - 1 in
  let _2sat (g : dep_graph) =
    let n = Array.length g in
    let toc = condensation g in
    try
      Some (Array.init (n / 2) (fun v ->
          let tocv = toc v and toc'v = toc @@ opposite n v in
          if tocv <> toc'v then tocv > toc'v
                           else raise Not_found))
    with Not_found -> None
  in
  let dep_graph_of_road_graph (g : road_graph) : dep_graph =
    let n = Array.length g * 2 in
    let (!!) = opposite n in
    let add_disj, get =
      let g = Array.make n [] in
      (fun (a, b) -> add_edge g (!! a) b; add_edge g (!! b) a),
      (fun () -> g)
    in
    let add_disjs = List.iter add_disj in
    ArrayLabels.iteri g ~f:(fun i ->
      List.iter @@ fun (j, asphalted) ->
        add_disjs @@ (* literals correspond to enevenness of switches *)
          if asphalted then [(i, !! j); (j, !!i)] else [(i, j); (!!i, !!j)]);
    get ()
  in
  let solution = function
    | None -> "Impossible"
    | Some a ->
      let to_switch, _ =
        ArrayLabels.fold_left a
          ~init:([], 1)
          ~f:(fun (acc, i) even -> (if not even then i :: acc else acc), i + 1)
      in
      List.(Printf.sprintf "%d\n%s"
              (length to_switch)
              (String.concat " " @@ map string_of_int @@ rev to_switch))
  in
  let input () =
    Scanf.scanf "%d %d" @@ fun n m ->
    let add_road, get =
      let g = Array.make n [] in
      (fun a b asphalted -> add_edge g a (b, asphalted); add_edge g b (a, asphalted)),
      (fun () -> g)
    in
    for i = 1 to m do
      ignore i; (* to get rid of unused variable warning *)
      Scanf.scanf " %d %d %d" @@ fun a b asphalted ->
        add_road (a - 1) (b - 1) (asphalted = 1)
    done;
    get ()
  in
  input ()
  |> dep_graph_of_road_graph
  |> _2sat
  |> solution
  |> Printf.printf "%s\n"

let () =
  Scanf.scanf "%d %d" (fun n m ->
  let g = Array.make n [] in
  for i = 1 to m do
    Scanf.scanf " %d %d %d" (fun a b c ->
      let a = a - 1 and b = b - 1 in
      g.(a) <- (b, c) :: g.(a); g.(b) <- (a, c) :: g.(b))
  done;
  let cc = Array.make n 2 in
  let rec dfs c v = match cc.(v) with
    | 2 -> cc.(v) <- c; List.iter (fun (v, c') -> dfs (1 land (lnot (c lxor c'))) v) g.(v)
    | c' when c = c' -> ()
    | _ -> raise Not_found
  in
  try
    Array.iteri (fun v _ -> try dfs 1 v with Not_found -> dfs 0 v) g;
    let l, _ = Array.fold_left (fun (acc, i) c -> (if c = 1 then string_of_int i :: acc else acc), i + 1) ([], 1) cc in
    Printf.printf "%d\n%s\n" (List.length l) (String.concat " " l)
  with Not_found -> Printf.printf "Impossible\n")

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

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.make (n + n * n) [] in
  let add_edges = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a); g.(b) <- a :: g.(b) in
  let idx a b = n + n * (min a b) + (max a b) in
  for i = 1 to m do
    ignore i;
    Scanf.scanf " %d %d %d" @@ fun a b even ->
      let a = a - 1 and b = b - 1 in
      add_edges @@ if even = 1 then [(a, idx a b); (idx a b, b)] else [(a, b)]
  done;
  let colors = Array.make (n + n * n) None in
  let rec dfs c v = match colors.(v) with
    | Some c' when c <> c' -> raise Not_found
    | Some _ -> ()
    | None -> colors.(v) <- Some c; List.iter (dfs @@ not c) g.(v)
  in
  let get o = match o with Some c -> c | None -> assert false in
  try
    ArrayLabels.iteri colors ~f:(fun v c -> if c = None then dfs false v);
    List.(
      Array.sub colors 0 n |> Array.to_list
      |> mapi (fun i b -> i, b) |> filter (get % snd) |> map (string_of_int % succ % fst) |> fun l ->
        Printf.printf "%d\n%s\n" (length l) @@ String.concat " " l)
  with Not_found -> Printf.printf "Impossible\n"

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

let (%) f g x = f @@ g x

module Option = struct
  let get = function
    | Some x -> x
    | None -> assert false
end

let () =
  let dsf n = object(self)
    val parent = Array.init n (fun x -> x)
    val rank = Array.make n 1
    method get v =
      if v = parent.(v) then v
      else begin
        parent.(v) <- self#get parent.(v);
        parent.(v)
      end
    method merge a b =
      let a, b = (fun a b -> max a b, min a b) (self#get a) (self#get b) in
      if a <> b then begin
        parent.(b) <- a;
        if rank.(a) = rank.(b) then rank.(a) <- rank.(a) + 1
      end
  end in
  let bicolor g =
    let n = Array.length g in
    let colors = Array.make n None in
    let rec dfs color v =
      match colors.(v) with
        | Some c when c <> color -> raise Not_found
        | Some _ -> ()
        | None ->
          colors.(v) <- Some color;
          List.iter (dfs @@ not color) g.(v)
    in
    try
      for v = 0 to n - 1 do
        if colors.(v) = None then dfs false v
      done;
      Some (Array.map Option.get colors)
    with Not_found -> None
  in
  let add_edges g = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a) in
  let condense g : int list array * (int -> int) =
    let n = Array.length g in
    let dsf = dsf n in
    let iter_g f = ArrayLabels.iteri g ~f:(fun a -> List.iter @@ f a) in
    iter_g (fun a (b, asphalted) -> if asphalted then dsf#merge a b);
    let index = Array.make n None in
    let size = ref 0 in
    for i = 0 to n - 1 do
      let root = dsf#get i in
      begin match index.(root) with
        | Some _ -> ()
        | None -> incr size; index.(root) <- Some (!size - 1)
      end;
      index.(i) <- index.(root)
    done;
    let g' = Array.make n [] in
    let get v = Option.get index.(v) in
    iter_g (fun a (b, asphalted) ->
      let a, b = get a, get b in
      if not asphalted then add_edges g' [a, b; b, a]);
    g', get
  in
  let solve g : (int -> bool) option =
    let g', get = condense g in
    match bicolor g' with
      | Some colors -> Some (Array.get colors % get)
      | None -> None
  in
  let output n switched =
    let answer = ref [] in
    for i = 0 to n - 1 do
      if switched i then answer := (i + 1) :: !answer
    done;
    List.(Printf.sprintf "%d\n%s"
      (length !answer)
      (String.concat " " @@ map string_of_int @@ rev !answer))
  in
  let input () =
    Scanf.scanf "%d %d" @@ fun n m ->
    let g = Array.make n [] in
    let add_road a b asphalted = add_edges g [a, (b, asphalted); b, (a, asphalted)] in
    for i = 1 to m do
      ignore i; (* to get rid of unused variable warning *)
      Scanf.scanf " %d %d %d" @@ fun a b asphalted ->
        add_road (a - 1) (b - 1) (asphalted = 1)
    done;
    g
  in
  input ()
  |> fun g ->
    Printf.printf "%s\n" @@
      match solve g with
        | None -> "Impossible"
        | Some f -> output (Array.length g) f

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

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.make n [] in
  let add_edge a b c = g.(a) <- (b, c) :: g.(a); g.(b) <- (a, c) :: g.(b) in
  for i = 1 to m do
    ignore i;
    Scanf.scanf " %d %d %d" @@ fun a b c ->
      add_edge (a - 1) (b - 1) c
  done;
  let colors = Array.make n ~-1 in
  let rec dfs c v = match colors.(v) with
    | -1 -> colors.(v) <- c; List.iter (fun (v, c') -> dfs (1 land (lnot @@ c lxor c')) v) g.(v)
    | c' when c = c' -> ()
    | _ -> raise Not_found
  in
  try
    Array.iteri (fun v _ -> try dfs 1 v with Not_found -> dfs 0 v) colors;
    Array.fold_left (fun (acc, i) c -> (if c = 1 then (string_of_int i) :: acc else acc), i + 1) ([], 1) colors
    |> fun (l, _) ->
    Printf.printf "%d\n%s\n" (List.length l) @@ String.concat " " l
  with Not_found -> Printf.printf "Impossible\n"

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

type road_graph = (int * bool) list array
type dep_graph = int list array
type tout_comp = int -> int

let (%) f g x = f @@ g x

let () =
  let make_dfs g =
    let marked, mark =
      let marked = Array.(make (length g) false) in
      Array.get marked,
      (fun v -> marked.(v) <- true)
    in
    fun fout v ->
    let rec dfs v =
      if not (marked v) then begin
        mark v;
        List.iter dfs g.(v);
        fout v
      end
    in
    dfs v
  in
  let add_edge g a b = g.(a) <- b :: g.(a) in
  let transpose g =
    let g' = Array.(make (length g) []) in
    ArrayLabels.iteri g ~f:(fun a -> List.iter @@ fun b -> add_edge g' b a);
    g'
  in
  let condensation g : tout_comp =
    let n = Array.length g in
    let add, iter, get_tout =
      let order = Array.make n ~-1 in
      let index = Array.copy order in
      let size = ref 0 in
      (fun v -> incr size; order.(!size - 1) <- v; index.(v) <- !size -1),
      (fun f -> Array.iter f order),
      Array.get index
    in
    let set_parent, get_parent =
      let parent = Array.(make (length g) ~-1) in
      (fun p v -> parent.(v) <- p),
      Array.get parent
    in
    let dfs = make_dfs g in
    for i = 0 to n - 1 do dfs add i done;
    let dfs = make_dfs @@ transpose g in
    iter (fun i -> dfs (set_parent i) i);
    get_tout % get_parent
  in
  let opposite n i = n / 2 - (i - n / 2) - 1 in
  let _2sat (g : dep_graph) =
    let n = Array.length g in
    let toc = condensation g in
    try
      Some (Array.init (n / 2) (fun v ->
          let tocv = toc v and tocv' = toc @@ opposite n v in
          if tocv <> tocv' then tocv > tocv'
                           else raise Not_found))
    with Not_found -> None
  in
  let dep_graph_of_road_graph (g : road_graph) : dep_graph =
    let n = Array.length g * 2 in
    let (!!) = opposite n in
    let add_disj, get =
      let g = Array.make n [] in
      (fun (a, b) -> add_edge g (!! a) b; add_edge g (!! b) a),
      (fun () -> g)
    in
    let add_disjs = List.iter add_disj in
    ArrayLabels.iteri g ~f:(fun i ->
      List.iter @@ fun (j, asphalted) ->
        add_disjs @@ (* literals correspond to enevenness of switches *)
          if asphalted then [(i, !!j); (j, !!i)] else [(i, j); (!!i, !!j)]);
    get ()
  in
  let solution = function
    | None -> "Impossible"
    | Some a ->
      let to_switch, _ =
        ArrayLabels.fold_left a
          ~init:([], 1)
          ~f:(fun (acc, i) even -> (if not even then i :: acc else acc), i + 1)
      in
      List.(Printf.sprintf "%d\n%s"
              (length to_switch)
              (String.concat " " @@ map string_of_int @@ rev to_switch))
  in
  let input () =
    Scanf.scanf "%d %d" @@ fun n m ->
    let add_road, get =
      let g = Array.make n [] in
      (fun a b asphalted -> add_edge g a (b, asphalted); add_edge g b (a, asphalted)),
      (fun () -> g)
    in
    for i = 1 to m do
      ignore i; (* to get rid of unused variable warning *)
      Scanf.scanf " %d %d %d" @@ fun a b asphalted ->
        add_road (a - 1) (b - 1) (asphalted = 1)
    done;
    get ()
  in
  input ()
  |> dep_graph_of_road_graph
  |> _2sat
  |> solution
  |> Printf.printf "%s\n"

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

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.make (n + n * n) [] in
  let add_edges = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a); g.(b) <- a :: g.(b) in
  let idx a b = n + n * (min a b) + (max a b) in
  for i = 1 to m do
    ignore i;
    Scanf.scanf " %d %d %d" @@ fun a b even ->
      let a = a - 1 and b = b - 1 in
      add_edges @@ if even = 1 then [(a, idx a b); (idx a b, b)] else [(a, b)]
  done;
  let colors = Array.make (n + n * n) None in
  let rec dfs c v = match colors.(v) with
    | Some c' when c <> c' -> raise Not_found
    | Some _ -> ()
    | None -> colors.(v) <- Some c; List.iter (dfs @@ not c) g.(v)
  in
  let get o = match o with Some c -> c | None -> assert false in
  try
    ArrayLabels.iteri colors ~f:(fun v c -> if c = None then dfs false v);
    List.(
      Array.sub colors 0 n |> Array.to_list
      |> mapi (fun i b -> i, b) |> filter (get % snd) |> map (string_of_int % fst) |> fun l ->
        Printf.printf "%d\n%s\n" (length l) @@ String.concat " " l)
  with Not_found -> Printf.printf "Impossible\n"


let rec pass k = function
  | 0 -> 1
  | x -> (x + pass k (x - 1)) mod k;;
let k = read_int ();;
for i = 1 to k - 1 do
  print_int ((fun x -> if x == 0 then k else x) (pass k i));
  print_string " "
done;;
print_newline ();;

let n = Scanf.scanf "%d" abs;;

let m = ref 0;;

for i = 1 to n-1 do (
	m := ((!m + i) mod n);
	print_int (!m + 1);
	if i <> n-1 then print_string " ";
) done


open Int64 open Str;;
let aset = Array.set;;
let [n; m]= List.map (int_of_string) (split (regexp " ") (read_line ()));;
let mx= Array.make (n + 1) "" and x= ref 0L and y = ref 0L;;
let ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;
let pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;
for i= 0 to n-1 do Array.set mx i (read_line ()) done;;
for i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin
  if j <> m-1 then if String.get mx.(i) (j+1) = '.' then aset ma.(i) j 1L;
  if i <> n-1 then if String.get mx.(i+1) j = '.' then aset mb.(i) j 1L;
end done done;;
for i= 1 to n do for j= 1 to m do
  aset pma.(i) j (sub (add (add pma.(i-1).(j) pma.(i).(j-1)) ma.(i-1).(j-1)) pma.(i-1).(j-1));
  aset pmb.(i) j (sub (add (add pmb.(i-1).(j) pmb.(i).(j-1)) mb.(i-1).(j-1)) pmb.(i-1).(j-1));
done done;;
let q= read_int ();;
for i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (split (regexp " ") (read_line ())) in begin
  x := sub (add pma.(y2).(x2-1) pma.(y1-1).(x1-1)) (add pma.(y2).(x1-1) pma.(y1-1).(x2-1));
  if !x < 0L then x:= 0L;
  y := sub (add pmb.(y2-1).(x2) pmb.(y1-1).(x1-1)) (add pmb.(y2-1).(x1-1) pmb.(y1-1).(x2));
  if !y < 0L then y:= 0L;
  print_endline (to_string (add !x !y))
end done;;

(*#load "str.cma";;*)
open Printf;;
let [n; m]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()));;
let mx= Array.make (n + 1) "";;
let ma= Array.make_matrix (n * 2) (m * 2) 0 and mb= Array.make_matrix (n * 2) (m * 2) 0;;
let pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0 and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0;;
for i= 0 to n - 1 do Array.set mx i (read_line ()) done;;
for i= 0 to n - 1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then
begin
	if j <> m - 1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1;
	if i <> n - 1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1;
end done done;;
for i= 1 to n do for j= 1 to m do
	Array.set pma.(i) j (ma.(i - 1).(j - 1) + pma.(i).(j - 1) + pma.(i - 1).(j) - pma.(i-1).(j-1));
	Array.set pmb.(i) j (mb.(i - 1).(j - 1) + pmb.(i).(j - 1) + pmb.(i - 1).(j) - pmb.(i-1).(j-1));
done done;;
let q= read_int ();;
for i= 1 to q do
  let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ())) in
  begin
		print_int
				((max 0 (pma.(y2).(x2 - 1) - pma.(y2).(x1 - 1) - pma.(y1 - 1).(x2 - 1) + pma.(y1 - 1).(x1 - 1))) +
				(max 0 (pmb.(y2 - 1).(x2) - pmb.(y2 - 1).(x1 - 1) - pmb.(y1 - 1).(x2) + pmb.(y1 - 1).(x1 - 1))));
		print_endline ""
	end
done;;

open Int64;;
let [n; m]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()));;
let mx= Array.make (n + 1) "" and x= ref 0L and y = ref 0L;;
let ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;
let pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;
for i= 0 to n-1 do Array.set mx i (read_line ()) done;;
for i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin
	if j <> m-1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1L;
	if i <> n-1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1L;
end done done;;
for i= 1 to n do for j= 1 to m do
  Array.set pma.(i) j	(sub (add (add ma.(i - 1).(j - 1) pma.(i).(j - 1)) pma.(i - 1).(j)) pma.(i-1).(j-1));
	Array.set pmb.(i) j (sub (add (add mb.(i - 1).(j - 1) pmb.(i).(j - 1)) pmb.(i - 1).(j)) pmb.(i-1).(j-1));
done done;;
let q= read_int ();;
for i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ())) in begin
	x := sub (add pma.(y2).(x2 - 1) pma.(y1 - 1).(x1 - 1)) (add pma.(y2).(x1 - 1) pma.(y1 - 1).(x2 - 1));
	if !x < 0L then x := 0L;
	y := sub (add pmb.(y2 - 1).(x2) pmb.(y1 - 1).(x1 - 1)) (add pmb.(y2 - 1).(x1 - 1) pmb.(y1 - 1).(x2));
	if !y < 0L then y := 0L;
	print_endline (to_string (add !x !y))
end done;;

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 read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
  let h = read_int () in
  let w = read_int () in
  let grid = Array.init h (fun _ -> read_string()) in
  let q = read_int () in
  let query = Array.init q (fun _ ->
    let a = read_pair() in
    let b = read_pair() in
    (a,b)
  ) in

  let geth i j =
    if i<0 || j<0 then '#' else grid.(i).[j]
  in

  let getv i j =
    if i<0 || j<0 then '#' else grid.(j).[i]
  in

  let getcount count i j = if i<0 || j<0 then 0 else count.(i).(j) in

  let make_count h w get =
    let c = Array.make_matrix h w 0 in
    for i=0 to h-1 do
      for j=0 to w-1 do
	let here = if (get i j) = '.' && (get i (j-1)) = '.' then 1 else 0 in
	c.(i).(j) <- here + (getcount c (i-1) j) + (getcount c i (j-2)) - (getcount c (i-1) (j-2));
      done
    done;
    c
  in

  let counth = make_count h w geth in
  let countv = make_count w h getv in

  for k = 0 to q-1 do
    let ((r1,c1),(r2,c2)) = query.(k) in
    let ((r1,c1),(r2,c2)) = ((r1-2,c1-2),(r2-1,c2-1)) in

    let heven =
      let c2 = c2 - (c2 land 1) in
      let c1 = c1 + (c1 land 1) in
      (getcount counth r2 c2)
      - (getcount counth r1 c2) - (getcount counth r2 c1)
      + (getcount counth r1 c1)
    in

    let hodd =
      let c2 = c2 - (1 - (c2 land 1)) in
      let c1 = c1 + (1 - (c1 land 1)) in
      (getcount counth r2 c2)
      - (getcount counth r1 c2) - (getcount counth r2 c1)
      + (getcount counth r1 c1)
    in

    let veven =
      let r2 = r2 - (r2 land 1) in
      let r1 = r1 + (r1 land 1) in
      (getcount countv c2 r2)
      - (getcount countv c1 r2) - (getcount countv c2 r1)
      + (getcount countv c1 r1)
    in

    let vodd =
      let r2 = r2 - (1 - (r2 land 1)) in
      let r1 = r1 + (1 - (r1 land 1)) in
      (getcount countv c2 r2)
      - (getcount countv c1 r2) - (getcount countv c2 r1)
      + (getcount countv c1 r1)
    in

    printf "%d\n" (heven + hodd + veven + vodd)
  done

open Printf;;
let [n; m]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()));;
let mx= Array.make (n + 1) "";;
let ma= Array.make_matrix (n * 2) (m * 2) 0 and mb= Array.make_matrix (n * 2) (m * 2) 0;;
let pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0 and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0;;
for i= 0 to n - 1 do Array.set mx i (read_line ()) done;;
for i= 0 to n - 1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then
begin
	if j <> m - 1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1;
	if i <> n - 1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1;
end done done;;
for i= 1 to n do for j= 1 to m do
	Array.set pma.(i) j (ma.(i - 1).(j - 1) + pma.(i).(j - 1) + pma.(i - 1).(j) - pma.(i-1).(j-1));
	Array.set pmb.(i) j (mb.(i - 1).(j - 1) + pmb.(i).(j - 1) + pmb.(i - 1).(j) - pmb.(i-1).(j-1));
done done;;
let q= read_int ();;
for i= 1 to q do
  let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ())) in
  begin
		if y2 <> 1 && x2 <> 1 then
			print_int
					((max 0 (pma.(y2).(x2 - 1) - pma.(y2).(x1 - 1) - pma.(y1 - 1).(x2 - 1) + pma.(y1 - 1).(x1 - 1))) +
					(max 0 (pmb.(y2 - 1).(x2) - pmb.(y2 - 1).(x1 - 1) - pmb.(y1 - 1).(x2) + pmb.(y1 - 1).(x1 - 1))))
		else if y2 = 1 && x2 <> 1 then
			print_int
					(max 0 (pma.(y2 - 1).(x2) - pma.(y2 - 1).(x1 - 1) - pma.(y1 - 1).(x2) + pma.(y1 - 1).(x1 - 1)))
		else if x2 = 1 && y2 <> 1 then
			print_int
					(max 0 (pmb.(y2).(x2 - 1) - pmb.(y2).(x1 - 1) - pmb.(y1 - 1).(x2 - 1) + pmb.(y1 - 1).(x1 - 1)))
		else print_int 0;
		print_endline ""
	end
done;;

open Int64 open Str;;
let aset = Array.set;;
let [n; m]= List.map (int_of_string) (split (regexp " ") (read_line ()));;
let mx= Array.make (n + 1) "" and x= ref 0L and y = ref 0L;;
let ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;
let pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;
for i= 0 to n-1 do Array.set mx i (read_line ()) done;;
for i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin
  if j <> m-1 then if String.get mx.(i) (j+1) = '.' then aset ma.(i) j 1L;
  if i <> n-1 then if String.get mx.(i+1) j = '.' then aset mb.(i) j 1L;
end done done;;
for i= 1 to n do for j= 1 to m do
  aset pma.(i) j (sub (add (add ma.(i-1).(j) pma.(i).(j-1)) pma.(i-1).(j-1)) pma.(i-1).(j-1));
  aset pmb.(i) j (sub (add (add mb.(i-1).(j-1) pmb.(i).(j-1)) pmb.(i-1).(j)) pmb.(i-1).(j-1));
done done;;
let q= read_int ();;
for i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (split (regexp " ") (read_line ())) in begin
  x := sub (add pma.(y2).(x2-1) pma.(y1-1).(x1-1)) (add pma.(y2).(x1-1) pma.(y1-1).(x2-1));
  if !x < 0L then x:= 0L;
  y := sub (add pmb.(y2-1).(x2) pmb.(y1-1).(x1-1)) (add pmb.(y2-1).(x1-1) pmb.(y1-1).(x2));
  if !y < 0L then y:= 0L;
  print_endline (to_string (add !x !y))
end done;;


#load "str.cma";;

let rec get_input () =
  let n = int_of_string (read_line ()) and
	  ls = Str.split (Str.regexp "[ \t]+") (read_line ()) in
  (n, Array.mapi (fun idx x -> (idx, x))
	(Array.of_list (List.map int_of_string ls)));;

let print_int' n =
  begin
	print_int (n + 1);
	print_string "\n";
  end;;

let solve n sls =
  if n == 1 then print_int' (fst sls.(0))
  else
	begin
	  Array.fast_sort (fun (idxx, x) (idxy, y) -> x - y) sls;
	  (* Array.iter (fun (x, y) -> print_int y) sls;*)
	  if snd (sls.(0)) == snd (sls.(1)) then
		print_string "Still Rozdil\n"
	  else
		print_int' (fst (sls.(0)))
	end;;

let (n, ls) = get_input () in
solve n ls;;

let _ =
  let n = Scanf.scanf " %d" (fun x -> x) in
  let a = Array.make n 0 in
  for i = 0 to n - 1 do
    Scanf.scanf " %d" (fun x -> a.(i) <- x)
  done;
  let k = ref 0 in
  let m = ref a.(0) in
  for i = 1 to n - 1 do
    if a.(i) < !m then (m := a.(i); k := i)
    else if a.(i) = !m then k := -1
  done;
  if !k = -1
  then print_string "Still Rozdil"
  else print_int (!k + 1)
;;

#load "str.cma";;

let rec get_input () =
  let n = read_line () and
	  ls = Str.split (Str.regexp "[ \t]") (read_line ()) in
  (n, List.map int_of_string ls);;

let solve n ls =
  let rec iter l cur flag =
	match l with
		[] -> if flag then -1 else cur
	  | (x::xs) ->
		if x == cur then
		  iter xs x true
		else if x < cur then
		  iter xs x false
		else
		  iter xs cur flag
  in iter ls 1000000001 false;;

let (n, ls) = get_input () in
begin
  (*
  List.iter (fun x -> print_int x; print_string" ") ls;
  print_string "\n";
  *)
  if solve n ls == -1 then
	print_string "Still Rozdil"
  else print_int (solve n ls); print_string "\n";
end


open Printf
open Scanf

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = let u = read_int() in (u,read_int())
let () =
  let n = read_int () in
  let v = read_int () in
  let s = Array.make n [||] in
  for i=0 to n-1 do
    let k = read_int () in
    s.(i) <- Array.init k (fun i-> read_int())
  done;

  let rec loop i ac = if i=n then ac else
      let m = minf 0 ((Array.length s.(i)) -1) (fun j -> s.(i).(j)) in
      if m < v then loop (i+1) (i::ac) else loop (i+1) ac
  in

  let ans = loop 0 [] in
  let ans = List.sort compare ans in

  printf "%d\n" (List.length ans);

  List.iter (fun i -> printf "%d " (i+1)) ans;

  print_newline();

let read_int()=Scanf.scanf "%d " (fun x->x);;
let n=read_int();;
let v=read_int();;
let tab=Array.make (n+1) 0;;
let vec=Array.make (n+1) false;;
let nb=ref 0;;
for i=1 to n do
   let x=read_int() in
   for j=1 to x do
      let a=read_int() in
      if a<v then (vec.(i)<-true;tab.(i)<-a)
   done;
   if vec.(i) then incr nb
done;;
Printf.printf "%d\n" !nb;;
for i=1 to n do
   if vec.(i) then Printf.printf "%d " i
done;;


let main () =
  let gr () = Scanf.scanf " %d" (fun i -> i) in
  let n = gr () in
  let ph flag =
      match flag with
      | 0 -> "I hate"
      | 1 -> "I love"
  in
  let rec f cnt flag =
      match cnt with
      | 1 -> ph flag
      | cnt -> String.concat " that " [ph flag; f (cnt - 1) (1 - flag)]
  in
  Printf.printf "%s it\n"  (f n 0)
  ;;
let _ = main();;

let input () = Scanf.scanf "%d" (fun n -> n)

let solve input =
    let rec loop i =
        if i <= input
        then
            ((if i mod 2 <> 0
            then
                Printf.printf "I hate "
            else
                Printf.printf "I love ");
            (if i <> input
            then
                Printf.printf "that "
            else
                Printf.printf "it\n");
            loop (i + 1))
        else
            ()
    in loop 1

let () = solve (input ())

let rec get_result n p =
    if n > 1 then
        if p = 1 then
            "I hate that " ^ get_result (n-1) (1-p)
        else
            "I love that " ^ get_result (n-1) (1-p)
    else
        if p = 1 then
            "I hate it\n"
        else
            "I love it\n"

;;

let () =
let n = read_int () in
let () = print_string (get_result n 1) in ();;

let rec f t b x =
  if t = x then
    if (b = 1) then Printf.printf "I hate it\n"
    else Printf.printf "I love it\n"
  else
    (if (b = 1) then Printf.printf "I hate that "
    else Printf.printf "I love that ";
    f (t + 1) (1 - b) x)
;;
let _ =
  let x = read_int() in
  f 1 1 x
;;

let text_gen n =
    let rec helper k acc =
        if k == n
        then acc ^ " it"
        else
            if k mod 2 == 0
            then helper (k+1) (acc ^ " that I hate")
            else helper (k+1) (acc ^ " that I love")
    in helper 1 "I hate"
in

let n = read_int() in
Printf.printf "%s\n" (text_gen n)

open Printf
open Scanf

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

  for i = 1 to n do
    if i=1 then printf "I hate "
    else if i land 1 = 1 then printf "that I hate "
    else printf "that I love "
  done;

  printf "it\n"

let input () = Scanf.scanf "%d" (fun n -> n)

let solve input =
    let rec loop i =
        if i <= input
        then
            ((if i mod 2 <> 0
            then
                Printf.printf "I hate "
            else
                Printf.printf "I love ");
            (if i <> input
            then
                Printf.printf "that "
            else
                Printf.printf "it.\n");
            loop (i + 1))
        else
            ()
    in loop 1

let () = solve (input ())


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

let () =
  let n = read_int () in
  let rec loop cnt_ev cnt_od lst_ev lst_od = function
    | 0 -> if cnt_ev = 1 then lst_ev else lst_od
    | c -> (
      let num = read_int () in
      if num mod 2 = 0 then
        loop (cnt_ev+1) cnt_od c lst_od (c - 1)
      else
        loop cnt_ev (cnt_od+1) lst_ev c (c - 1)
    ) in
  Printf.printf "%d\n" (n - (loop 0 0 0 0 n) + 1)

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let o_l = List.mapi (fun i x -> if x mod 2 <> 0 then i+1 else -1) a_lst
            |> List.filter (fun x -> x <> -1)
  in
  let e_l = List.mapi (fun i x -> if x mod 2 = 0 then i+1 else -1) a_lst
            |> List.filter (fun x -> x <> -1)
  in

  if List.length o_l = 1 then
    Printf.printf "%d\n" @@ List.hd o_l
  else
    Printf.printf "%d\n" @@ List.hd e_l

let rec split s i acc =
begin
  if i > String.length s
  then List.rev acc
  else
      let first =
      if String.contains_from s i ' '
         then  String.index_from s i ' '
         else String.length s
    in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc)
end in
let rec find n xs =
   match xs with
  |  (1::0::0::_) | (0::1::1::_) -> n+0
  |  (0::1::0::_) | (1::0::1::_) -> n+1
  |  (0::0::1::_) | (1::1::0::_) -> n+2
  | bs -> find (n+1) (List.tl bs)
in
let _ = int_of_string (read_line ()) in
let xs = split (read_line ()) 0 [] in
print_int (xs |> List.map (fun x -> x mod 2 ) |> find 1 )

let index_of_list elm lst =
  let rec loop lst index =
    match lst with
      | [] -> -1
      | h :: t ->
	if h = elm then index
	else loop t (index+1)
  in
  loop lst 0

let solve lst =
  let evens = List.filter (fun x -> x mod 2 = 0) lst in
  if List.length evens = 1 then (index_of_list (List.hd evens) lst)+1
  else
    let odds = List.filter (fun x -> x mod 2 = 1) lst in
    (index_of_list (List.hd odds) lst)+1

let rec some_int n =
  if 0 >= n then [] else (Scanf.scanf " %d" (fun x -> x)) :: some_int (n - 1)

let _ =
  let lst = Scanf.scanf " %d" some_int in
  Printf.printf "%d\n" (solve (List.rev lst))

let id x = x in
let (@.) f g = fun x -> f @@ g x in
let scan_int () = Scanf.scanf " %d" id in
let rec read_n_ints n = let i = scan_int () in
        if n = 1 then [i]
        else [i] @ (read_n_ints @@ n-1) in

let rec find_first_index p l = match l with
        | [] -> 0
        | hd :: tl when p hd -> 0
        | _ :: tl -> 1 + (find_first_index p tl) in

let n = scan_int () in
let l = read_n_ints n in
let is_even x = x mod 2 = 0 in
let n_even = l |> List.filter is_even |> List.length in
let index = if n_even = 1 then find_first_index is_even l
            else find_first_index (not @. is_even) l in
Printf.printf "%d\n" @@ 1 + index

let read () = Scanf.scanf "%d " (fun n -> n)

let find_rare_parity array =
    let rec loop i odds evens =
        if i < 3
        then
            if array.(i) mod 2 > 0
            then
                loop (i + 1) (odds + 1) evens
            else
                loop (i + 1) odds (evens + 1)
        else
            if odds > evens
            then
                0
            else
                1
    in loop 0 0 0

let get_index parity array l =
    let rec loop i =
        if i < l
        then
            if array.(i) mod 2 = parity
            then
                i + 1
            else
                loop (i + 1)
        else
            failwith "Corrupted input"
    in loop 0

let solve () =
    let l = read () in
    let numbers = Array.init l (fun x -> read ()) in
    get_index (find_rare_parity numbers) numbers l

let print result = Printf.printf "%d\n" result

let () = print (solve ())

let read () = Scanf.scanf "%d " (fun n -> n)

let find_rare_parity array =
    let rec loop i odds evens =
        if i < 3
        then
            if array.(i) mod 2 > 0
            then
                loop (i + 1) (odds + 1) evens
            else
                loop (i + 1) odds (evens + 1)
        else
            if odds > evens
            then
                `even
            else
                `odd
    in loop 0 0 0

let get_index parity array l =
    let rec loop i =
        if i < l
        then
            if parity = `odd
            then
                if array.(i) mod 2 > 0
                then
                    i + 1
                else
                    loop (i + 1)
            else
                if array.(i) mod 2 = 0
                then
                    i + 1
                else
                    loop (i + 1)
        else
            failwith "Corrupted input"
    in loop 0

let solve () =
    let l = read () in
    let numbers = Array.init l (fun x -> read ()) in
    get_index (find_rare_parity numbers) numbers l

let print result = Printf.printf "%d\n" result

let () = print (solve ())

let read () = Scanf.scanf "%d " (fun n -> n)

let find_rare_parity array =
    let rec loop i odds evens =
        if i < 3
        then
            if array.(i) mod 2 > 0
            then
                loop (i + 1) (odds + 1) evens
            else
                loop (i + 1) odds (evens + 1)
        else
            if odds > evens
            then
                `even
            else
                `odd
    in loop 0 0 0

let get_odd_index array l =
    let rec loop i =
        if i < l
        then
            if array.(i) mod 2 > 0
            then
                i + 1
            else
                loop (i + 1)
        else
            failwith "No odd numbers"
    in loop 0

let get_even_index array l =
    let rec loop i =
        if i < l
        then
            if array.(i) mod 2 = 0
            then
                i + 1
            else
                loop (i + 1)
        else
            failwith "No even numbers"
    in loop 0

let solve () =
    let l = read () in
    let numbers = Array.init l (fun x -> read ()) in
    if find_rare_parity numbers = `odd
    then
        get_odd_index numbers l
    else
        get_even_index numbers l

let print result = Printf.printf "%d\n" result

let () = print (solve ())

let index_of_list elm lst =
  let rec loop lst index =
    match lst with
      | [] -> -1
      | h :: t ->
	if h = elm then index
	else loop t (index+1)
  in
  loop lst 0

let solve lst =
  let evens = List.filter (fun x -> x mod 2 = 0) lst in
  if List.length evens = 1 then (index_of_list (List.hd evens) lst)+1
  else
    let odds = List.filter (fun x -> x mod 2 = 1) lst in
    (index_of_list (List.hd odds) lst)+1

let rec some_int n =
  if 0 >= n then [] else (Scanf.scanf " %d" (fun x -> x)) :: some_int (n - 1)

let _ =
  let lst = Scanf.scanf " %d" some_int in
  Printf.printf "%d\n" (solve lst)


let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> Int64.of_int x);;
let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x);;
let read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;
let comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;;
let min x y = if Int64.compare x y < 0 then x else y
let max x y = if Int64.compare x y > 0 then x else y
let empty_read x = read_int64 ();;

let n = read_int ();;
let a = Array.init n empty_read;;
let b = Array.init n empty_read;;
let c = (Array.init n (fun i ->
    if Int64.compare a.(i) b.(i) <= 0
    then (a.(i), b.(i), 0)
    else (b.(i), a.(i), 1)));;
let _ = Array.sort (fun (x, y, z) (u, v, w) ->
    if Int64.compare x u != 0
    then Int64.compare x u
    else
        if Int64.compare y v != 0
        then Int64.compare y v
        else compare z w) c;;
let mx = Array.make 2 Int64.zero;;
let ans = Array.fold_left Int64.add Int64.zero (
    Array.map (fun (a, b, c) -> Int64.sub b a) c);;

let diff = ref Int64.zero;;
for i = 0 to n - 1 do
    match c.(i) with (a, b, x) ->
        diff := max !diff (Int64.sub (min b mx.(1 - x)) a);
        mx.(x) <- max mx.(x) b
done;;

Printf.printf "%s\n" (Int64.to_string (Int64.sub ans (Int64.mul 2L !diff)));;

let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> Int64.of_int x);;
let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x);;
let read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;
let comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;;

let min x y = if Int64.compare x y < 0 then x else y

let max x y = if Int64.compare x y > 0 then x else y

let empty_read x = read_int64 ();;

let n = read_int ();;
let a = Array.init n empty_read;;
let b = Array.init n empty_read;;
let c = (Array.init n (fun i ->
    if Int64.compare a.(i) b.(i) <= 0
    then (a.(i), b.(i), 0)
    else (b.(i), a.(i), 1)));;

let _ = Array.stable_sort (fun (x, y, z) (u, v, w) ->
    if Int64.compare x u != 0
    then Int64.compare x u
    else
        if Int64.compare y v != 0
        then Int64.compare y v
        else compare z w) c;;

let mx = Array.make 2 Int64.zero;;

let ans = Array.fold_left Int64.add Int64.zero (
    Array.map (fun (a, b, c) -> Int64.sub b a) c);;

let diff = ref Int64.zero;;

for i = 0 to n - 1 do
    match c.(i) with (a, b, x) ->
        diff := max !diff (Int64.sub (min b mx.(1 - x)) a);
        mx.(x) <- max mx.(x) b
done;;

Printf.printf "%s\n" (Int64.to_string (Int64.sub ans (Int64.mul 2L !diff)))


let input () = Scanf.scanf "%d " (fun n -> n)

let if_max max ppl_inside =
    if ppl_inside > max
    then
        ppl_inside
    else
        max

let rec at_trainstop ppl_inside max n =
    if n > 0
    then
        let new_ppl = Scanf.scanf "%d %d " (fun a b -> (-a + b)) in
        at_trainstop (ppl_inside + new_ppl) (if_max max (ppl_inside + new_ppl)) (n - 1)
    else
        max

let solve input = at_trainstop 0 0 input

let print result = Printf.printf "%d\n" result

let () = print (solve (input ()))

open Scanf
open Printf

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

let nn = n + 10

let a = Array.make nn (-1);;
let b = Array.make nn (-1);;
let c = Array.make nn (-1);; (*The number of people on tram after each stop*)

for i = 1 to n do
  let (ai,bi) = Scanf.bscanf Scanf.Scanning.stdin "%d %d " ( fun x y -> (x,y) ) in
  a.(i) <- ai; b.(i) <- bi
done
;;

let () = c.(0) <- 0;;

for i = 1 to n do
  c.(i) <- (c.(i-1) + b.(i-1) - a.(i-1))
done
;;

let z = Array.fold_left (fun x y -> if x > y then x else y ) (-1) c
in print_int z; print_endline ""

let solve n stops =
  let rec loop stops passenger max_capacity = match stops with
      [] -> max_capacity
    | first :: rest ->
      loop rest (passenger+(snd first)-(fst first)) (max passenger max_capacity)
  in
  loop stops 0 0;;

let rec get_stops n stops=
  if n <= 0
  then stops
  else get_stops (n-1) (Scanf.scanf "%d %d\n" (fun x y -> (x, y)) :: stops)

let get_stops n = List.rev (get_stops n [])

let _ =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let stops = get_stops n in
  Printf.printf "%d\n" (solve n stops)

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

let solve n =
  let rec find_max n max sum = match n with
    | 0 -> max
    | n -> let a = read_int ()
           and b = read_int () in
           let new_sum = sum - a + b in
             if max > new_sum
             then find_max (n - 1) max new_sum
             else find_max (n - 1) new_sum new_sum
  in find_max n 0 0

let () =
  let n = read_int ()
  in Printf.printf "%d\n" (solve n)

let pf = Printf.printf;;
let sf = Scanf.scanf;;

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

exception Error of string

let inf = 1000000000;;
let eps = 1e-11;;

let _ =
  let n = sf "%d\n" (fun x -> x) in
  let a = ref 0 in
  let b = ref 0 in
  let res = ref 0 in
  for i = 1 to n do
    let (x, y) = sf "%d %d\n" (fun x y -> x, y) in
    a := !a + x;
    b := !b + y;
    res := max !res (!b - !a)
  done;
  pf "%d\n" !res
;;

let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x)

let max a b =
  if a < b then b
  else a

let () =
  let n = ref (read_int ()) in
  let ans = ref 0 in
  let count_now = ref 0 in
  for i = 1 to !n do
    count_now := !count_now + read_int () - read_int ();
    ans := max !ans !count_now;
  done;
  Printf.printf "%d" !ans;

let read_list () =
  let n = read_int()
  and l = ref [] in
    for i = 1 to n do
      let pair = Scanf.scanf " %d %d" (fun a b -> (a, b)) in
      l := pair :: !l;
    done;
    !l

let solve l =
  fst (List.fold_left
    (fun (mx, ac) (hm, hp) ->  let na = (ac + hp - hm) in (max mx na, na))
    (0, 0)
    (List.rev l))

let print_res =
  print_int

let main =
  let l = read_list () in
    print_res (solve l)

let _ =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun n -> n) in
        let rec loop i cur m =
            if i = 0 then Printf.printf "%d\n" m else
                let (a, b) = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> a, b) in
                let cur = cur - a + b in
                let m = max cur m in
                loop (i - 1) cur m
        in
        loop n 0 0
    in
    main ()

let input () = Scanf.scanf "%d " (fun n -> n)

let rec at_trainstop ppl_inside current_max n =
    if n > 0
    then
        let new_ppl = Scanf.scanf "%d %d " (fun a b -> (-a + b)) in
        at_trainstop (ppl_inside + new_ppl) (Pervasives.max current_max (ppl_inside + new_ppl)) (n - 1)
    else
        current_max

let solve input = at_trainstop 0 0 input

let print result = Printf.printf "%d\n" result

let () = print (solve (input ()))

let rec tram n l m o i =
	if n = 0 then m
	else Scanf.scanf "%d %d\n" (fun oo ii ->
		tram (n-1) (l-o+i) (max (l-o+i) m) oo ii
	)
;;

let () =
	let n = read_int () in
	print_int (tram n 0 0 0 0)
;;

let read_int() = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x)
let printf = Printf.printf

let max a b = if (a > b) then a else b

let () =
	let n = read_int() in
	let a = Array.make (n + 1) 0 in
	let b = Array.make (n + 1) 0 in
	let sum = ref 0 in
	let mx = ref 0 in
		for i = 1 to n do
			a.(i) <- read_int();
			b.(i) <- read_int();
			sum := !sum - a.(i) + b.(i);
			mx := max !mx !sum;
		done;
		printf "%d\n" (!mx)

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and r=ref 0 and s=ref 0;;
for i=1 to n do
   let x=read_int() and y=read_int() in
   r:= !r+y-x;
   s:=max !s !r
done;;
Printf.printf "%d" !s;;

let rec tram n m o i =
	if n = 0 then m
	else let oo, ii = Scanf.scanf "%d %d\n" (fun o i -> (o, i))
		in tram (n-1) (max (m-o+i) m) oo ii
;;

let () =
	let n = read_int () in
	print_int (tram n 0 0 0)
;;

let read_int() = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x)
let printf = Printf.printf

let max a b = if (a > b) then a else b

let () =
	let n = read_int() in
	let a = Array.make (n + 1) 0 in
	let b = Array.make (n + 1) 0 in
	let sum = ref 0 in
	let mx = ref 0 in
		for i = 1 to n do
			a.(i) <- read_int();
			b.(i) <- read_int();
			sum := !sum + a.(i) - b.(i);
			mx := max !mx !sum;
		done;
		printf "%d\n" (!mx)

open Scanf
open Printf

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

let nn = n + 10

let a = Array.make nn (-1);;
let b = Array.make nn (-1);;
let c = Array.make nn (-1);; (*The number of people on tram after each stop*)

for i = 1 to n do
  let (ai,bi) = Scanf.bscanf Scanf.Scanning.stdin "%d %d " ( fun x y -> (x,y) ) in
  a.(i) <- ai; b.(i) <- bi
done
;;

let () = c.(0) <- 0;;

for i = 1 to n-1 do
  c.(i) <- (c.(i-1) + b.(i-1) - a.(i-1))
done
;;

let z = Array.fold_left (fun x y -> if x > y then x else y ) (-1) c
in print_int z; print_endline ""

let read_list () =
  let n = read_int()
  and l = ref [] in
    for i = 1 to n do
      let pair = Scanf.scanf " %d %d" (fun a b -> (a, b)) in
      l := pair :: !l;
    done;
    !l

let solve l =
  List.fold_left
    (fun ac (hp, hm) ->  max ac (ac - hp + hm))
    0
    l

let print_res =
  print_int

let main =
  let l = read_list () in
    print_res (solve l)


Scanf.(Array.(
  let n = scanf " %d" @@ fun v -> v in
  let l,r,zero = make 500010 0, make 500010 0, ref 0 in
  init n (fun _ ->
    let s = scanf " %s" @@ fun v -> v in
    let s = init (String.length s) (fun i -> s.[i]) in
    let post,pre = fold_left (fun (sum,pre) -> function
    | '(' -> (sum+1,pre)
    | ')' -> if sum=0 then (0,pre+1) else (sum-1,pre)
    | _ -> failwith ""
    ) (0,0) s in
    if post>0 && pre>0 then ()
    else if post>0 then (
      r.(post) <- r.(post) + 1
    ) else if pre>0 then (
      l.(pre) <- l.(pre) + 1
    ) else (
      zero := !zero + 1
    )
  ) |> ignore;
  fold_left (fun (sum,i) v ->
    let u = r.(i) in (sum + min u v,i+1)
  ) (!zero/2,0) l
  |> fst |> print_int
))

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64_lim,min_i64_lim = Int64.(max_int,min_int)
  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let calc s =
  let cnt,pre,post = ref 0L,ref 0L,ref 0L in
  String.iteri (fun i c ->
    if c = '(' then cnt += 1L
    else (
      cnt -= 1L;
      if !cnt < 0L then (
        pre := max (!pre) (-1L*(!cnt));
      )
    )
  ) s;
  cnt := !pre;
  String.iteri (fun i c ->
    if c = '(' then cnt += 1L
    else (
      cnt -= 1L;
    )
  ) s;
  post := !cnt;
  if !cnt>0L && !pre>0L then (
    `None
  ) else if !pre>0L then (
    `Pre !pre
  ) else if !post>0L then (
    `Post !cnt
  ) else (
    `Zero
  )
let () =
  let n = gi 0 in
  let pos,neg,zero = make 600010 0L,make 600010 0L,ref 0L in
  repi 1 (i32 n) (fun i ->
    let s = scanf " %s" @@ id in
    let v = calc s in
    match v with
    | `None -> ()
    | `Pre v ->
      neg.(i32 v) <- neg.(i32 v) + 1L
    | `Post v ->
      pos.(i32 v) <- pos.(i32 v) + 1L
    | `Zero -> zero += 1L
  );
  let r = ref 0L in
  iteri (fun i v ->
    let w = neg.(i) in
    r += min v w
  ) pos;
  r += !zero/2L;
  printf "%Ld\n" !r

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64_lim,min_i64_lim = Int64.(max_int,min_int)
  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let slen s = String.length s
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let calc s =
  let r = ref [] in
  let lv = ref 0L in
  String.iteri (fun i c ->
    if c = '(' then (
      r := i :: !r;
      lv += 1L;
    ) else (
      match !r with
      | i::tl -> (
        r := tl;
        lv -= 1L
      );
      | [] -> lv -= 1L;
    )
  ) s; !lv
let () =
  let n = gi 0 in
  let pos,neg,zero = make 100010 0L,make 100010 0L,ref 0L in
  repi 1 (i32 n) (fun i ->
    let s = scanf " %s" @@ id in
    let v = calc s in
    (* printf "%Ld\n" v; *)
    if v > 0L then (
      pos.(i32 v) <- pos.(i32 v) + 1L
    ) else if v < 0L then (
      neg.(-i32 v) <- neg.(-i32 v) + 1L
    ) else zero += 1L
  );
  let r = ref 0L in
  iteri (fun i v ->
    let w = neg.(i) in
    r += min v w
  ) pos;
  r += !zero/2L;
  printf "%Ld\n" !r


let read () = Scanf.scanf "%d " (fun n -> n)

let make_array () =
    let n = read () in
    let array = Array.make n (0, 0) in
    let rec loop i array prev =
        if i < n
        then
            let quantity = read () in
            let min = prev + 1 in
            let max = prev + quantity in
            let () = Array.set array i (min, max) in
            loop (i + 1) array max
        else
            (n, array)
    in loop 0 array 0

let make_list () =
    let n = read () in
    let rec loop i list =
        if i < n
        then
            let value = read () in
            loop (i + 1) (value :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let piles = make_array () in
    let worms = make_list () in
    (piles, worms)

let classify (min, max) value =
    if value >= min && value <= max
    then
        `Inside
    else
        if value < min
        then
            `To_the_left
        else
            `To_the_right

let rec binary_search array value low high =
    let mid = (low + high) / 2 in
    match classify array.(mid) value with
    | `To_the_right -> binary_search array value (mid + 1) high
    | `To_the_left -> binary_search array value low (mid - 1)
    | `Inside -> mid + 1

let wrapper (n, array) value =
    let result = binary_search array value 0 n in
    Printf.printf "%d\n" result

let solve (piles, worms) =
    List.iter (wrapper piles) worms

let () =
    solve (input ())

open Printf
open Scanf

let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let long x = Int64.of_int x

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

let () =
  let n = read_int() in
  let a = Array.init n (fun _ -> read_long()) in
  let m = read_int() in
  let q = Array.init m (fun _ -> read_long()) in

  let ends = Array.make n 0L in
  ends.(0) <- a.(0);

  for i=1 to n-1 do
    ends.(i) <- ends.(i-1) ++ a.(i)
  done;

  let find i =
    let rec bsearch lo hi =
    (* must be in lo, lo+1....hi-1 *)
      if lo+1 = hi then lo else
	let m = (lo+hi)/2 in
	if i > ends.(m-1) then bsearch m hi else bsearch lo m
    in

    bsearch 0 n
  in

  for i=0 to m-1 do
    printf "%d\n" (1 + find q.(i))
  done;


let _ =
  let sb = Scanf.Scanning.stdib in
  let h = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make h (-1) in
  let ht = Hashtbl.create h in
  let res = ref 0 in
    for i = 0 to n - 1 do
      let op = Scanf.bscanf sb "%s " (fun s -> s) in
	match op with
	  | "+" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Scanf.bscanf sb "%d " (fun s -> s) in
	      let j = ref hash in
		while a.(!j) >= 0 do
		  j := (!j + m) mod h;
		  incr res;
		done;
		Hashtbl.replace ht id !j;
		a.(!j) <- id;
	  | "-" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Hashtbl.find ht id in
		Hashtbl.remove ht id;
		a.(hash) <- -1;
	  | _ -> assert false
    done;
    Printf.printf "%d\n" !res;

let rec gcd a b =
  if b = 0
  then a
  else gcd b (a mod b)

let g2d n = n land (-n)

let fenwick_new n =
  Array.make n 0

let fenwick_modify ft n x =
  let i = ref (n + 1) in
    while !i <= Array.length ft do
      ft.(!i - 1) <- ft.(!i - 1) + x;
      i := !i + g2d !i;
    done

let fenwick_count ft n =
  let i = ref (n + 1) in
  let res = ref 0 in
    while !i > 0 do
      res := !res + ft.(!i - 1);
      i := !i - g2d !i;
    done;
    !res

let fenwick_count2 ft m n =
  fenwick_count ft n - fenwick_count ft (m - 1)

let _ =
  let sb = Scanf.Scanning.stdib in
  let h = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make h (-1) in
  let b = Array.make (2 * h) (-1) in
  let c = Array.make h (-1) in
  let g = gcd m h in
  let () =
    let pos = ref 0 in
      for i = 0 to h - 1 do
	if c.(i) < 0 then (
	  let k = ref i in
	    for j = 0 to h / g - 1 do
	      c.(!k) <- !pos;
	      b.(!pos) <- !k;
	      b.(!pos + h / g) <- !k;
	      incr pos;
	      k := (!k + m) mod h;
	    done;
	  pos := !pos + h / g;
	)
      done
  in
  let ft = fenwick_new (2 * h) in
  let ht = Hashtbl.create h in
  let res = ref 0L in
    for i = 0 to n - 1 do
      let op = Scanf.bscanf sb "%s " (fun s -> s) in
	match op with
	  | "+" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Scanf.bscanf sb "%d " (fun s -> s) in
	      let l = ref (c.(hash) - 1) in
	      let r = ref (c.(hash) + h / g) in
		while !l < !r - 1 do
		  let m = (!l + !r) / 2 in
(*Printf.printf "step %d %d %d   %d\n" !l !r m (fenwick_count2 ft c.(hash) m);*)
		    if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)
		    then r := m
		    else l := m
		done;
		res := Int64.add !res (Int64.of_int (!r - c.(hash)));
		let hash = b.(!r) in
(*Printf.printf "add %d %d   %d %d\n" id hash !l !r;*)
		(*while a.(!j) >= 0 do
		  j := (!j + m) mod h;
		  incr res;
		done;*)
		  Hashtbl.replace ht id hash;
		  a.(hash) <- id;
		  fenwick_modify ft c.(hash) 1;
		  fenwick_modify ft (c.(hash) + h / g) 1;
	  | "-" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Hashtbl.find ht id in
		Hashtbl.remove ht id;
		a.(hash) <- -1;
		fenwick_modify ft c.(hash) (-1);
		fenwick_modify ft (c.(hash) + h / g) (-1);
	  | _ -> assert false
    done;
    Printf.printf "%Ld\n" !res;

let rec gcd a b =
  if b = 0
  then a
  else gcd b (a mod b)

let g2d n = n land (-n)

let fenwick_new n =
  Array.make n 0

let fenwick_modify ft n x =
  let i = ref (n + 1) in
    while !i <= Array.length ft do
      ft.(!i - 1) <- ft.(!i - 1) + x;
      i := !i + g2d !i;
    done

let fenwick_count ft n =
  let i = ref (n + 1) in
  let res = ref 0 in
    while !i > 0 do
      res := !res + ft.(!i - 1);
      i := !i - g2d !i;
    done;
    !res

let fenwick_count2 ft m n =
  fenwick_count ft n - fenwick_count ft (m - 1)

let _ =
  let sb = Scanf.Scanning.stdib in
  let h = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make h (-1) in
  let b = Array.make (2 * h) (-1) in
  let c = Array.make h (-1) in
  let g = gcd m h in
  let () =
    let pos = ref 0 in
      for i = 0 to h - 1 do
	if c.(i) < 0 then (
	  for j = 0 to h / g - 1 do
	    c.((i + j * m) mod h) <- !pos;
	    b.(!pos) <- (i + j * m) mod h;
	    b.(!pos + h / g) <- (i + j * m) mod h;
	    incr pos
	  done;
	  pos := !pos + h / g;
	)
      done
  in
  let ft = fenwick_new (2 * h) in
  let ht = Hashtbl.create h in
  let res = ref 0 in
    for i = 0 to n - 1 do
      let op = Scanf.bscanf sb "%s " (fun s -> s) in
	match op with
	  | "+" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Scanf.bscanf sb "%d " (fun s -> s) in
	      let l = ref (c.(hash) - 1) in
	      let r = ref (c.(hash) + h / g) in
		while !l < !r - 1 do
		  let m = (!l + !r) / 2 in
(*Printf.printf "step %d %d %d   %d\n" !l !r m (fenwick_count2 ft c.(hash) m);*)
		    if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)
		    then r := m
		    else l := m
		done;
		res := !res + !r - c.(hash);
		let hash = b.(!r) in
(*Printf.printf "add %d %d   %d %d\n" id hash !l !r;*)
		(*while a.(!j) >= 0 do
		  j := (!j + m) mod h;
		  incr res;
		done;*)
		  Hashtbl.replace ht id hash;
		  a.(hash) <- id;
		  fenwick_modify ft c.(hash) 1;
		  fenwick_modify ft (c.(hash) + h / g) 1;
	  | "-" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Hashtbl.find ht id in
		Hashtbl.remove ht id;
		a.(hash) <- -1;
		fenwick_modify ft c.(hash) (-1);
		fenwick_modify ft (c.(hash) + h / g) (-1);
	  | _ -> assert false
    done;
    Printf.printf "%d\n" !res;

let rec gcd a b =
  if b = 0
  then a
  else gcd b (a mod b)

let g2d n = n land (-n)

let fenwick_new n =
  Array.make n 0

let fenwick_modify ft n x =
  let i = ref (n + 1) in
    while !i <= Array.length ft do
      ft.(!i - 1) <- ft.(!i - 1) + x;
      i := !i + g2d !i;
    done

let fenwick_count ft n =
  let i = ref (n + 1) in
  let res = ref 0 in
    while !i > 0 do
      res := !res + ft.(!i - 1);
      i := !i - g2d !i;
    done;
    !res

let fenwick_count2 ft m n =
  fenwick_count ft n - fenwick_count ft (m - 1)

let _ =
  let sb = Scanf.Scanning.stdib in
  let h = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make h (-1) in
  let b = Array.make (2 * h) (-1) in
  let c = Array.make h (-1) in
  let g = gcd m h in
  let () =
    let pos = ref 0 in
      for i = 0 to h - 1 do
	if c.(i) < 0 then (
	  for j = 0 to h / g - 1 do
	    c.((i + j * m) mod h) <- !pos;
	    b.(!pos) <- (i + j * m) mod h;
	    b.(!pos + h / g) <- (i + j * m) mod h;
	    incr pos
	  done;
	  pos := !pos + h / g;
	)
      done
  in
  let ft = fenwick_new (2 * h) in
  let ht = Hashtbl.create h in
  let res = ref 0 in
    for i = 0 to n - 1 do
      let op = Scanf.bscanf sb "%s " (fun s -> s) in
	match op with
	  | "+" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Scanf.bscanf sb "%d " (fun s -> s) in
	      let l = ref (c.(hash) - 1) in
	      let r = ref (c.(hash) + h / g) in
		while !l < !r - 1 do
		  let m = (!l + !r) / 2 in
(*Printf.printf "step %d %d %d   %d\n" !l !r m (fenwick_count2 ft c.(hash) m);*)
		    if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)
		    then r := m
		    else l := m
		done;
		res := !res + !r - c.(hash);
		let hash = b.(!r) in
(*Printf.printf "add %d %d   %d %d\n" id hash !l !r;*)
		(*while a.(!j) >= 0 do
		  j := (!j + m) mod h;
		  incr res;
		done;*)
		  Hashtbl.replace ht id hash;
		  a.(hash) <- id;
		  fenwick_modify ft !r 1;
		  fenwick_modify ft (!r + h / g) 1;
	  | "-" ->
	      let id = Scanf.bscanf sb "%d " (fun s -> s) in
	      let hash = Hashtbl.find ht id in
		Hashtbl.remove ht id;
		a.(hash) <- -1;
		fenwick_modify ft c.(hash) (-1);
		fenwick_modify ft (c.(hash) + h / g) (-1);
	  | _ -> assert false
    done;
    Printf.printf "%d\n" !res;


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

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

	let tab = Array.make n 0
	and uzyte = Array.make 100007 false
	and dp = Array.make (n + 1) 0 in

	for i = 0 to n - 1 do
		tab.(i) <- read_int ()
	done;

	for i = n - 1 downto 0 do
		if uzyte.(tab.(i)) = false then
			dp.(i) <- dp.(i + 1) + 1
		else
			dp.(i) <-  dp.(i + 1);

		uzyte.(tab.(i)) <- true;
	done;

	for i = 1 to m do
		let a = read_int () in
		printf "%d\n" dp.(a - 1);
	done;

let read () = Scanf.scanf "%d " (fun n -> n)

let list_init n f =
    let rec loop i list =
        if i < n
        then
            let element = f(i) in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = read () in
    let m = read () in
    let arr = Array.init n (fun n -> read ()) in
    let list = list_init m (fun n -> read ()) in
    (n, arr, list)

let count_duplicates n arr =
    let seen = Array.make 100001 0 in
    let dup_count = Array.make n 0 in
    let rec loop i count =
        if i >= 0
        then
            let a = arr.(i) in
            if seen.(a) = 0
            then
                (seen.(a) <- 1;
                dup_count.(i) <- count;
                loop (i - 1) count)
            else
                (dup_count.(i) <- count + 1;
                loop (i - 1) (count + 1))
        else
            dup_count
    in loop (n - 1) 0

let count_uniques arr i n list =
    let a = n - i - arr.(i) in
    (a :: list)

let solve (n, arr, list) =
    let dups = count_duplicates n arr in
    let rec loop rest uniqs =
        match rest with
        | (i :: tl) -> loop tl (count_uniques dups (i - 1) n uniqs)
        | [] -> List.rev uniqs
    in loop list []

let print list = List.iter (Printf.printf "%d\n") list

let () = print (solve (input ()))

let read () = Scanf.scanf "%d " (fun n -> n)

let list_init n f =
    let rec loop i list =
        if i < n
        then
            let element = f(i) in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = read () in
    let m = read () in
    let arr = Array.init n (fun n -> read ()) in
    let list = list_init m (fun n -> read ()) in
    (n, arr, list)

let count_uniqs n arr =
    let seen = Array.make 100001 0 in
    let uniq_count = Array.make n 0 in
    let rec loop i count =
        if i >= 0
        then
            let a = arr.(i) in
            if seen.(a) = 0
            then
                (seen.(a) <- 1;
                uniq_count.(i) <- count + 1;
                loop (i - 1) (count + 1))
            else
                (uniq_count.(i) <- count;
                loop (i - 1) count)
        else
            uniq_count
    in loop (n - 1) 0

let solve (n, arr, list) =
    let uniqs = count_uniqs n arr in
    List.map (fun i -> uniqs.(i - 1)) list

let print list = List.iter (Printf.printf "%d\n") list

let () = print (solve (input ()))

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

let () =
	let n = read_int ()
	and m = read_int () in
	let a = Array.init n read_int in

	let vis = Array.make 100001 false
	and suf = Array.make (n + 1) 0 in

	for i = n - 1 downto 0 do
		let x = a.(i) in
		suf.(i) <- suf.(i + 1);
		if not vis.(x) then suf.(i) <- suf.(i) + 1;
		vis.(x) <- true
	done;
	for i = 1 to m do
		let l = read_int () in
		printf "%d\n" suf.(l - 1)
	done

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

let n = read_int() and m = read_int() in
let a = Array.init n (fun _ -> read_int()) in
let e = Array.init 100001 (fun _ -> false) in
let b = Array.make n 0 in

b.(n-1) <- 1;
e.(a.(n-1)) <- true;

for i = n-2 downto 0 do
  b.(i) <- b.(i+1);
  if not e.(a.(i)) then
  begin
    e.(a.(i)) <- true;
    b.(i) <- b.(i) + 1;
  end
done;

for i = 1 to m do
  let l = read_int() in
    Printf.printf "%d\n" b.(l-1);
done;

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

let () =
  let n = read_int() in
  let m = read_int() in
  let a = Array.init n read_int in
  let dp = Array.make n 0 in
  let check = Array.make 100000 0 in
  check.(a.(n-1) - 1) <- 1;
  dp.(n-1) <- 1;
  let rec loop = function
    | k -> (if check.(a.(k)-1) = 0
            then
              (check.(a.(k)-1) <- 1;
              dp.(k) <- dp.(k+1) + 1)
            else
              dp.(k) <- dp.(k+1));
           if k > 0 then loop (k-1);
           in
  let rec loop2 = function
    | k when k = m -> ()
    | k -> let t = read_int 0 in
    print_int dp.(t-1); loop2 (k+1) in
  if n > 1 then loop (n-2);
  loop2 0;;


open Array;;

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

let flip f y x = f x y

let readInStr _ = Scanf.scanf "%d " identity
let readIntLn _ = Scanf.scanf "%d\n" identity
let main () =
        let n = readInStr () in
        let a = readInStr () in
        let b = readIntLn () in
                let h = init n (fun i -> readInStr())  in
                  fast_sort(-)h;
                  h.(b) - h.(b-1) |> print_int
        ;;
main()

open Array;;

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

let flip f y x = f x y

let readInStr _ = Scanf.scanf "%d " identity
let readIntLn _ = Scanf.scanf "%d\n" identity
let main () =
        let n = readInStr () in
        let a = readInStr () in
        let b = readIntLn () in
                let h = init n (fun i -> readInStr())  in
                  fast_sort(-)h;
                 if b <= n-1
                 then h.(b) - h.(b-1) |> print_int
                 else print_int 1
        ;;
main()


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

let () =
  let n = xint () in
  let sum = ref 0 in
  for i = 1 to n do
    let x1 = xint () in
    let y1 = xint () in
    let x2 = xint () in
    let y2 = xint () in
    sum := !sum + (x2 - x1 + 1) * (y2 - y1 + 1);
  done;
  print_int !sum

let () =
	let n = Scanf.scanf "%d" (fun i -> i) and res = ref 0  in
		for i=1 to n do
			Scanf.scanf " %d %d %d %d" (fun i j k l -> res := !res + (k-i+1)*(l-j+1));
		done;
	Printf.printf "%d" !res


open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = let u = read_int() in (u,read_int())
let () =
  let n = read_int () in
  let tree = Array.make n [] in

  for i=0 to n-2 do
    let u = (read_int()) -1 in
    let v = (read_int()) -1 in
    tree.(u) <- v::tree.(u);
    tree.(v) <- u::tree.(v);
  done;

  let init = Array.init n (fun _ -> read_int()) in

  for i=0 to n-1 do
    let b = read_int () in
    init.(i) <- init.(i) lxor b
  done;

  let parent = Array.make n (-1) in

  let rec dfs u p =
    List.iter (fun v ->
      if v <> p then (
	parent.(v) <- u;
	dfs v u
      )
    ) tree.(u)
  in

  dfs 0 (-1);

  let rec loop i ac = if i=n then ac else
      let condadd bit = if bit=0 then ac else i::ac in
      if parent.(i) < 0 || parent.(parent.(i)) < 0 then loop (i+1) (condadd init.(i))
      else loop (i+1) (condadd (init.(i) lxor init.(parent.(parent.(i)))))
  in

  let li = loop 0 [] in
  printf "%d\n" (List.length li);
  List.iter (fun i -> printf "%d\n" (i+1)) (loop 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 len = read_int() in
  let graph = make len [] in
  for i = 0 to len-2 do
    let a = read_int() - 1 in
    let b = read_int() - 1 in
    graph.(a) <- b :: graph.(a);
    graph.(b) <- a :: graph.(b)
  done;
  let ini = init len (fun i -> read_int() ) in
  let goal = init len (fun i -> read_int() ) in

  let cnt = ref [] in
  let rec dfs lv odd even p i =
    let curr = if is_odd lv then (ini.(i) lxor odd) else (ini.(i) lxor even) in
    if curr <> goal.(i) then begin
      cnt := i :: !cnt;
      let odd  = if is_odd lv then odd lxor 1 else odd in
      let even = if is_even lv then even lxor 1 else even in
      L.iter (fun j -> if j <> p then dfs (lv+1) odd even i j) graph.(i)
    end else
      L.iter (fun j -> if j <> p then dfs (lv+1) odd even i j) graph.(i)
  in
  dfs 0 0 0 (-1) 0;
  printf "%d\n" (L.length !cnt);
  L.iter (fun i -> printf "%d\n" (i+1)) !cnt