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

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

(*let read_pair () = let a = read_int () in (a , read_int ());;*)

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

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

let n , t = read_pair ();;

let data = Array.init (n+1) (fun i -> if i = 0 then Int64.of_int 0 else read_long ());;

let sum = Array.init 100005 (fun i -> Int64.of_int 0);;

for i = 1 to n do
        sum.(i) <- sum.(i-1) ++ data.(i)
done;;

let left , right = ( ref 1 , ref n );;

let binary_search len =
        let isok = ref false in
        for i = 0 to n-len do
                isok := !isok || (sum.(i+len) -- sum.(i) <= Int64.of_int t)
        done;
        !isok;;

while !left <= !right do
        let mid = (!left + !right)/2 in
        if binary_search mid then left := mid + 1
        else right := mid - 1
done;;

Printf.printf "%d\n" !right;;

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

let () =
  let n = read_int 0 in
  let t = read_int 0 in
  let a = Array.init n read_int in

(*
  let () = for i=1 to n-1 do
    a.(i) <- a.(i-1) + a.(i)
  done in
    (* so now a.(i) = the time needed to read books a.(0)...a.(i) *)
    (* so to read books i to j requires time a.(j) - a.(i-1) *)
*)

  let rec loop i j sum ac = if j=n-1 then ac else
    (* sum = total time of the books from i to j inclusive *)
    (* ac is the biggest number of book found so far that I can read *)
    if sum + a.(j+1) > t
      then loop (i+1) j (sum - a.(i)) ac
      else loop i (j+1) (sum + a.(j+1)) (max ac ((j+1)-i+1))
  in

  let answer = loop 0 0 a.(0) (if a.(0) > t then 0 else 1) in
    Printf.printf "%d\n" answer

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

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

let n , t = read_pair ();;

let data = Array.init (n+1) (fun i -> if i = 0 then 0 else read_int ());;

let sum = Array.init 100005 (fun i -> 0);;

for i = 1 to n do
        sum.(i) <- sum.(i-1) + data.(i)
done;;

let left , right = ( ref 1 , ref n );;

let binary_search len =
        let isok = ref false in
        for i = 0 to n-len do
                isok := !isok || (sum.(i+len) - sum.(i) <= t)
        done;
        !isok;;

while !left <= !right do
        let mid = (!left + !right)/2 in
        if binary_search mid then left := mid + 1
        else right := mid - 1
done;;

Printf.printf "%d\n" !right;;

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

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

(*let read_pair () = let a = read_int () in (a , read_int ());;*)

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

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

let n , t = read_pair ();;

let data = Array.init (n+1) (fun i -> if i = 0 then Int64.of_int 0 else read_long ());;

let sum = Array.init 100005 (fun i -> Int64.of_int 0);;

for i = 1 to n-1 do
        sum.(i) <- sum.(i-1) ++ data.(i)
done;;

let left , right = ( ref 1 , ref n );;

let binary_search len =
        let isok = ref true in
        for i = 0 to n-len do
                isok := !isok || (sum.(i+len) -- sum.(i) <= Int64.of_int t)
        done;
        !isok;;

while !left <= !right do
        let mid = (!left + !right)/2 in
        if binary_search mid then left := mid + 1
        else right := mid - 1
done;;

Printf.printf "%d\n" !right;;


let () = Scanf.scanf "%f\n%f\n%f" (fun l p q ->
    Printf.printf "%f\n" (l /. (q /. p +. 1.)))

open Printf
open Scanf

let () =
  let l = float_of_int (read_int ()) in
  let p = float_of_int (read_int ()) in
  let q = float_of_int (read_int ()) in
  let res = p *. (l /. (p +. q)) in
  printf "%f\n%!" res

open Printf
open Scanf

let read_float () = bscanf Scanning.stdib " %f " (fun x -> x)

let () =
  let l = read_float () in
  let p = read_float () in
  let q = read_float () in

  let answer = (p *. l) /. (p +. q) in

  printf "%.5f\n" answer


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

let () =
  let add, get, iter =
    let n = read_int () in
    let mk v = Array.make (n + 1) v in
    let p, mcc, mcf, cc = mk ~-1, mk ~-1, mk false, mk 1 in
    let set i c inc =
      let set a v = Array.set a i v in
      let r = cc.(i) in
      if inc then (set mcc c; set mcf false; set cc c)
             else (set mcf true; set cc (succ c));
      r < cc.(i)
    in
    let rec update i =
      let pi, c = p.(i), cc.(i) in
      let set = set pi c in
      let sgn a = if a = 0 then 0 else a / abs a in
      if (match pi, lazy (sgn (c - mcc.(pi)), mcf.(pi)) with
          | -1, _ -> false
          | _, lazy (1, _) -> set true
          | _, lazy (0, false) -> set false
          | _ -> false)
      then update pi
    in
    let k = ref 0 in
    (fun i -> incr k; p.(!k) <- i - 1; update !k),
    (fun () -> mcc.(0)),
    fun f -> for i = 1 to n do f (i < n) done
  in
  iter @@ fun s ->
   Scanf.scanf " %d" add;
   print_int (get ());
   print_char (if s then ' ' else '\n')

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

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

module Max : sig
  type t
  val mk : int -> t
  val cmp : int -> t -> [`Lt | `Gt | `Eq]
  val int : t -> int
end = struct
  type t = int
  let mk v = v
  let cmp a =
    function
    | b when a < b -> `Lt
    | b when a = b -> `Eq
    | _ -> `Gt
  let int m = m
end

type vertex =
  { mutable s : Max.t * bool * int;
    p : vertex option }

let () =
  let vertex p = { s = Max.mk ~-1, false, 1; p } in
  let vertex p =
    let rec update =
      function
      | { p = None } -> ()
      | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->
        match Max.cmp c mcc, mcf with
        | `Gt, _ ->
          p.s <- Max.mk c, false, c;
          if pc < c then update p
        | `Eq, false ->
          p.s <- mcc, true, c + 1;
          update p
        | `Eq, true | `Lt, _ -> ()
    in
    let v = vertex p in
    update v;
    v
  in
  let n = read_int () in
  let open Array in
  let vs = make (n + 1) (vertex None) in
     init n (fun _ -> Scanf.scanf " %d" @@ fun x -> x - 1)
  |> mapi (fun i pi ->
       vs.(i + 1) <- vertex (Some vs.(pi));
       let mcc, _, _ = vs.(0).s in Max.int mcc)
  |> map string_of_int
  |> to_list
  |> String.concat " "
  |> print_endline

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

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

module List = struct
  include List
  let map f =
    let rec loop acc =
      function
      | [] -> rev acc
      | x :: xs -> loop (f x :: acc) xs
    in
    loop []
  let mapi f =
    map (let c = ref ~-1 in fun e -> incr c; f !c e)
end

module Max : sig
  type t
  val mk : int -> t
  val cmp : int -> t -> [`Lt | `Gt | `Eq]
  val int : t -> int
end = struct
  type t = int
  let mk v = v
  let cmp a =
    function
    | b when a < b -> `Lt
    | b when a = b -> `Eq
    | _ -> `Gt
  let int m = m
end

type vertex =
  { mutable s : Max.t * bool * int;
    p : vertex option }

let () =
  let vertex p = { s = Max.mk ~-1, false, 1; p } in
  let vertex p =
    let rec update =
      function
      | { p = None } -> ()
      | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->
        match Max.cmp c mcc, mcf with
        | `Gt, _ ->
          p.s <- Max.mk c, false, c;
          if pc < c then update p
        | `Eq, false ->
          p.s <- mcc, true, c + 1;
          update p
        | `Eq, true | `Lt, _ -> ()
    in
    let v = vertex p in
    update v;
    v
  in
  let n = read_int () in
  let vs = Array.make (n + 1) (vertex None) in
     Array.init n (fun _ -> Scanf.scanf " %d" @@ fun x -> x - 1)
  |> Array.mapi (fun i pi ->
          vs.(i + 1) <- vertex (Some vs.(pi));
          let { s = mcc, _, _ } = vs.(0) in Max.int mcc)
  |> Array.map string_of_int
  |> Array.to_list
  |> String.concat " "
  |> print_endline

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

type vertex =
  { mutable s : int * bool * int;
    p : vertex option }

let () =
  let vertex p = { s = -1, false, 1; p } in
  let vertex p =
    let rec update =
      function
      | { p = None } -> ()
      | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->
        let sgn a = if a = 0 then 0 else a / abs a in
        match sgn (c - mcc), mcf with
        | 1, _ ->
          p.s <- c, false, c;
          if pc < c then update p
        | 0, false ->
          p.s <- mcc, true, c + 1;
          update p
        | _ -> ()
    in
    let v = vertex p in
    update v;
    v
  in
  let n = read_int () in
  let open Array in
  let vs = make (n + 1) (vertex None) in
     init n (fun _ -> Scanf.scanf " %d" @@ fun x -> x - 1)
  |> iteri
       (fun i pi ->
       vs.(i + 1) <- vertex (Some vs.(pi));
       let mcc, _, _ = vs.(0).s in
       print_int mcc;
       if i < n - 1 then print_char ' ');
  print_newline ()

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

let () =
  let add, get, iter =
    let n = read_int () in
    let mk v = Array.make (n + 1) v in
    let p, mcc, cc = mk ~-1, mk ~-1, mk 1 in
    let rec update i =
      let pi, c = p.(i), cc.(i) in
      if (match lazy (c - mcc.(pi), cc.(pi) > mcc.(pi), cc.(pi)) with
          | _ when pi = -1 -> false
          | lazy (d, _, pc) when d > 0 ->
            mcc.(pi) <- c;
            cc.(pi) <- c;
            pc < c
          | lazy (0, false, _) ->
            cc.(pi) <- c + 1;
            true
          | _ -> false)
      then update pi
    in
    let k = ref 0 in
    (fun i -> incr k; p.(!k) <- i - 1; update !k),
    (fun () -> mcc.(0)),
    fun f -> for i = 1 to n do f (i < n) done
  in
  iter @@ fun s ->
   Scanf.scanf " %d" add;
   print_int (get ());
   print_char (if s then ' ' else '\n')

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

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

type vertex =
  { mutable mcc : int;
    mutable c : int;
    p : vertex option }

let () =
  let n = read_int () in
  let vs = Array.make (n + 1) None in
  let vertex p =
    let rec update =
      let cmp a =
        function
        | b when a < b -> `Lt
        | b when a = b -> `Eq
        | _ -> `Gt
      in
      function
      | { p = None } -> ()
      | { c; p = Some p } ->
        match cmp c p.mcc with
        | `Gt -> p.mcc <- c
        | `Eq -> p.c <- p.c + 1; update p
        | `Lt -> ()
    in
    let v = { mcc = -1; c = 0; p } in
    update v;
    v
  in
  let r = { mcc = -1; c = 0; p = None } in
  vs.(0) <- Some r;
    read_line ()
  |> Str.(split (regexp_string " "))
  |> List.mapi (fun i ->
        pred % int_of_string
     %> fun pi ->
          vs.(i + 1) <- Some (vertex vs.(pi));
          r.mcc + 1)
  |> List.map string_of_int
  |> String.concat " "
  |> print_endline

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

type vertex =
  { mutable s : (int * bool) * int;
    p : vertex option }

let () =
  let vertex p = { s = (-1, false), 1; p } in
  let vertex p =
    let rec update =
      function
      | { p = None } -> ()
      | { s = _, c; p = Some ({ s = (mcc, mcf), pc } as p) } ->
        if c > mcc then (
          p.s <- (c, false), c;
          if pc < c then update p
        ) else if not mcf then (
          p.s <- (mcc, true), c + 1;
          update p
        )
    in
    let v = vertex p in
    update v;
    v
  in
  let n = read_int () in
  let open Array in
  let vs = make (n + 1) (vertex None) in
     init n (fun _ -> Scanf.scanf " %d" @@ fun x -> x - 1)
  |> iteri
       (fun i pi ->
       vs.(i + 1) <- vertex (Some vs.(pi));
       let (mcc, _), _ = vs.(0).s in
       print_int mcc;
       if i < n - 1 then print_char ' ');
  print_newline ()


module Digraph =
struct
  type t =
      {mutable nv : int;
       mutable e : int array array;
       mutable degree : int array;
      }

  let create n =
    {nv = n;
     e = Array.make n [| |];
     degree = Array.make n 0
    }

  let nb_vertex g = g.nv

  let iter_succ f g u =
    let vs = g.e.(u) in
      for i = 0 to g.degree.(u) - 1 do
	f vs.(i)
      done

  let add_edge g u v =
    if u >= g.nv || v >= g.nv then (
      (* TODO *)
      assert false;
    );
    let {e; degree; _} = g in
      if degree.(u) >= Array.length e.(u) then (
	let s = Array.length e.(u) * 2 + 1 in
	let c = e.(u) in
	let c' = Array.make s 0 in
	  for i = 0 to Array.length c - 1 do
	    c'.(i) <- c.(i)
	  done;
	  e.(u) <- c'
      );
      e.(u).(degree.(u)) <- v;
      degree.(u) <- degree.(u) + 1

end

module Dfs =
struct

  module type G =
  sig
    type t

    val nb_vertex : t -> int
    val iter_succ : (int -> unit) -> t -> int -> unit
  end

  module Make (G : G) =
  struct
    let do_nothing _ = ()

    let iter ?(pre = do_nothing) ?(post = do_nothing) g =
      let n = G.nb_vertex g in
      let used = Array.make n false in
      let rec dfs u =
	used.(u) <- true;
	pre u;
	G.iter_succ
	  (fun v ->
	     if not used.(v) then (
	       dfs v
	     )
	  ) g u;
	post u
      in
	for i = 0 to n - 1 do
	  if not used.(i)
	  then dfs i
	done

    type iterator = G.t * bool array

    let start g =
      let n = G.nb_vertex g in
      let used = Array.make n false in
	(g, used)

    let iter_component ?(pre = do_nothing) ?(post = do_nothing) (g, used) u =
      let rec dfs u =
	used.(u) <- true;
	pre u;
	G.iter_succ
	  (fun v ->
	     if not used.(v) then (
	       dfs v
	     )
	  ) g u;
	post u
      in
	if not used.(u)
	then dfs u

    type prefix_iterator = G.t * bool array * int array

    let prefix_start g =
      let n = G.nb_vertex g in
      let used = Array.make n false in
      let stack = Array.make n 0 in
	(g, used, stack)

    let prefix_component pre (g, used, stack) u =
      if not used.(u) then (
	let pos = ref 0 in
	let rec dfs () =
	  if !pos > 0 then (
	    decr pos;
	    let u = stack.(!pos) in
	    pre u;
	    G.iter_succ
	      (fun v ->
		 if not used.(v) then (
		   stack.(!pos) <- v;
		   incr pos;
		   used.(v) <- true;
		 )
	      ) g u;
	    dfs ()
	  )
	in
	  stack.(!pos) <- u;
	  incr pos;
	  used.(u) <- true;
	  dfs ()
      )
  end

end

module DigraphDFS = Dfs.Make(Digraph)

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let g = Digraph.create n in
  let gr = Digraph.create n in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	Digraph.add_edge g u v;
	if f.(v) <> 1
	then Digraph.add_edge gr v u;
    done
  in
  let a = Array.make n false in
  let r = Array.make n false in
  let dfs = DigraphDFS.prefix_start g in
  let dfs2 = DigraphDFS.prefix_start gr in
    for i = 0 to n - 1 do
      if f.(i) = 1
      then DigraphDFS.prefix_component (fun v -> a.(v) <- true) dfs i;
    done;
    for i = 0 to n - 1 do
      if f.(i) = 2
      then DigraphDFS.prefix_component
	(fun v -> if a.(v) then r.(v) <- true)
	dfs2 i;
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let esr = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
	esr.(v) <- u :: esr.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let esr = Array.map Array.of_list esr in
  let used = Array.make n false in
  let a = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    a.(u) <- true;
    for i = 0 to Array.length es.(u) - 1 do
      let v = es.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs v
    done;
  in
  let rec dfs2 u =
    used.(u) <- true;
    if a.(u)
    then r.(u) <- true;
    for i = 0 to Array.length esr.(u) - 1 do
      let v = esr.(u).(i) in
	if f.(v) = 1
	then r.(v) <- true;
	if not used.(v) && f.(v) <> 1
	then dfs2 v;
    done;
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then dfs i
    done;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 2
      then dfs2 i
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
    done
  in
  let es = Array.map Array.of_list es in
  let used = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    let b = ref r.(u) in
      if f.(u) = 2
      then b := true;
      for i = 0 to Array.length es.(u) - 1 do
	let v = es.(u).(i) in
	  if not used.(v) then (
	    if f.(v) <> 1
	    then b := dfs v || !b
	  ) else b := !b || r.(v)
      done;
      if !b then (
	r.(u) <- true;
      );
      !b
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then ignore (dfs i)
    done;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then ignore (dfs i)
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
    done
  in
  let es = Array.map Array.of_list es in
  let used = Array.make n false in
  let r = Array.make n 0 in
  let rec dfs u =
    used.(u) <- true;
    let b = ref false in
      if f.(u) = 2
      then b := true;
      for i = 0 to Array.length es.(u) - 1 do
	let v = es.(u).(i) in
	  if not used.(v) && f.(v) <> 1
	  then b := !b || dfs v
      done;
      if !b
      then r.(u) <- 1;
      !b
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then ignore (dfs i)
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" r.(i)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
    done
  in
  let es = Array.map Array.of_list es in
  let used = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    let b = ref false in
      if f.(u) = 2
      then b := true;
      for i = 0 to Array.length es.(u) - 1 do
	let v = es.(u).(i) in
	  if not used.(v) then (
	    if f.(v) <> 1
	    then b := dfs v || !b
	  ) else b := !b || r.(v)
      done;
      if !b
      then r.(u) <- true;
      !b
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then ignore (dfs i)
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let esr = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
	esr.(v) <- u :: esr.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let esr = Array.map Array.of_list esr in
  let used = Array.make n false in
  let a = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    a.(u) <- true;
    for i = 0 to Array.length es.(u) - 1 do
      let v = es.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs v
    done;
  in
  let rec dfs2 u =
    used.(u) <- true;
    if a.(u)
    then r.(u) <- true;
    for i = 0 to Array.length esr.(u) - 1 do
      let v = esr.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs2 v;
	if f.(v) = 1
	then r.(v) <- true
    done;
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then dfs i
    done;
    if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 2
      then dfs2 i
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let esr = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
	esr.(v) <- u :: esr.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let esr = Array.map Array.of_list esr in
  let used = Array.make n false in
  let a = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    a.(u) <- true;
    for i = 0 to Array.length es.(u) - 1 do
      let v = es.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs v
    done;
  in
  let rec dfs2 u =
    used.(u) <- true;
    if a.(u)
    then r.(u) <- true;
    for i = 0 to Array.length esr.(u) - 1 do
      let v = esr.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs2 v;
	if f.(v) = 1
	then r.(v) <- true
    done;
  in
    if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then dfs i
    done;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 2
      then dfs2 i
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let esr = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
	esr.(v) <- u :: esr.(v);
    done
  in
    if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;
  let es = Array.map Array.of_list es in
  let esr = Array.map Array.of_list esr in
  let used = Array.make n false in
  let a = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    a.(u) <- true;
    for i = 0 to Array.length es.(u) - 1 do
      let v = es.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs v
    done;
  in
  let rec dfs2 u =
    used.(u) <- true;
    if a.(u)
    then r.(u) <- true;
    for i = 0 to Array.length esr.(u) - 1 do
      let v = esr.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs2 v;
	if f.(v) = 1
	then r.(v) <- true
    done;
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then dfs i
    done;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 2
      then dfs2 i
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
    done
  in
  let es = Array.map Array.of_list es in
  let used = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    let b = ref false in
      if f.(u) = 2
      then b := true;
      for i = 0 to Array.length es.(u) - 1 do
	let v = es.(u).(i) in
	  if not used.(v) then (
	    if f.(v) <> 1
	    then b := !b || dfs v
	  ) else b := !b || r.(v)
      done;
      if !b
      then r.(u) <- true;
      !b
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then ignore (dfs i)
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let f = Array.make n (-1) in
  let es = Array.make n [] in
  let esr = Array.make n [] in
  let () =
    for i = 0 to n - 1 do
      f.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
	es.(u) <- v :: es.(u);
	esr.(v) <- u :: esr.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let esr = Array.map Array.of_list esr in
  let used = Array.make n false in
  let a = Array.make n false in
  let r = Array.make n false in
  let rec dfs u =
    used.(u) <- true;
    a.(u) <- true;
    for i = 0 to Array.length es.(u) - 1 do
      let v = es.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs v
    done;
  in
  let rec dfs2 u =
    used.(u) <- true;
    if a.(u)
    then r.(u) <- true;
    for i = 0 to Array.length esr.(u) - 1 do
      let v = esr.(u).(i) in
	if not used.(v) && f.(v) <> 1
	then dfs2 v;
	if f.(v) = 1
	then r.(v) <- true
    done;
  in
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 1
      then dfs i
    done;
    for i = 0 to n - 1 do
      used.(i) <- false
    done;
    if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;
    for i = 0 to n - 1 do
      if not used.(i) && f.(i) = 2
      then dfs2 i
    done;
    for i = 0 to n - 1 do
      Printf.printf "%d\n" (if r.(i) then 1 else 0)
    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 () =
  let n = read_int () in
  let tree = Array.make (n+1) [] in

  for i=2 to n do
    let p = read_int() in
    tree.(i) <- p::tree.(i);
    tree.(p) <- i::tree.(p)
  done;

  let c = Array.make (n+1) 0 in
  for i=1 to n do c.(i) <- read_int() done;

  let rec dfs p u =
    List.fold_left (fun ac v -> if v = p then ac else
	let diff = if c.(u) <> c.(v) then 1 else 0 in
	ac + diff + (dfs u v)
    ) 0 tree.(u)
  in

  printf "%d\n" (1 + dfs 0 1)

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

let () =
    let n = read_int () in
    let g = Array.make (n + 1) []
    and visited = Array.make (n + 1) false
    and colors = Array.make (n + 1) 0
    and ans = ref 0 in
    let rec dfs v color =
        if not visited.(v) then begin
            visited.(v) <- true;
            if colors.(v) <> color then incr ans;
            List.iter (fun w -> dfs w colors.(v)) g.(v)
        end in
    for i = 2 to n do
        let a = read_int () in
        g.(i) <- a::g.(i);
        g.(a) <- i::g.(a)
    done;
    for i = 1 to n do
        colors.(i) <- read_int ()
    done;
    dfs 1 0;
    printf "%d\n" !ans


let n = read_int();;

let graf = Array.make_matrix 26 26 false;;
let slowa = ref [];;

for i = 0 to n - 1 do
    slowa := (read_line())::(!slowa)
done;;

slowa := List.rev !slowa;;

let impossibru = ref false;;

let chti x = (Char.code x) - (Char.code 'a');;

let porownaj a b =
    let m = min (String.length a) (String.length b)
    and i = ref 0
    and st = ref false in
    while !i < m && not !st do
        if a.[!i] <> b.[!i] then
            begin
                graf.(chti a.[!i]).(chti b.[!i]) <- true;
                st := true
            end
        else i := !i + 1
    done;
    if !i = m && (String.length a) > (String.length b) then impossibru := true

let rec gen l =
    let rec genpom a l =
        match l with
        | [] -> ()
        | h::t ->
            porownaj a h;
            genpom a t in
    match l with
    | [] -> ()
    | h::t ->
        genpom h t;
        gen t;;

gen !slowa;;

let btc x =
    match x with
    | false -> '0'
    | true -> '1';;

let odw = Array.make 26 (-1);;
let gnr = ref 1;;

let rec dfs v =
    odw.(v) <- 0;
    for i = 0 to 25 do
        if graf.(v).(i) then
            begin
                if odw.(i) = -1 then dfs i
                else if odw.(i) = 0 then impossibru := true
            end
    done;
    odw.(v) <- !gnr;
    gnr := !gnr + 1;;

for i = 0 to 25 do
    if odw.(i) = -1 then dfs i
done;;

if !impossibru then print_string "Impossible\n"
else
    let res = String.make 26 ' ' in
    for i = 0 to 25 do
        Bytes.set res (26 - odw.(i)) (Char.chr (Char.code 'a' + i))
    done;
    print_string res
;;

type seen = Unseen | Temp | Seen
exception Cycle

(* non-fatal string indexing *)
let nth s n =
  try Some s.[n] with Invalid_argument "index out of bounds" -> None

(* array indexing *)
let get a c = a.(int_of_char c - int_of_char 'a')
let set g d a b t =
  g.(int_of_char a - int_of_char 'a') <- b :: t;
  let (ain, aout) = get d a in
  d.(int_of_char a - int_of_char 'a') <- (ain, aout + 1);
  let (bin, bout) = get d b in
  d.(int_of_char b - int_of_char 'a') <- (bin + 1, bout)

(* group strings by their nth letter *)
let group s n =
  let g = List.fold_left (fun a x -> match nth x n with
  | None -> a
  | Some c -> begin
    match a with
    | [] -> [c, [x]]
    | (d, _) :: _ when c <> d -> (c, [x]) :: a
    | (_, xs) :: t -> (c, x :: xs) :: t
  end
  ) [] s in
  List.rev_map (fun (c, xs) -> (c, List.rev xs)) g

let strcmp order a b =
  let l = min (String.length a) (String.length b) in
  let rec aux i =
    if i >= l then match (nth a i, nth b i) with
    | (None, None) | (Some _, Some _) -> 0
    | (Some _, None) -> 1
    | (None, Some _) -> -1
    else
      let c = compare (get order a.[i]) (get order b.[i]) in
      if c = 0 then aux (i + 1) else c
  in
  aux 0

let () = Scanf.scanf "%d\n" (fun n ->
  (* list of strings *)
  let strs = Array.to_list (Array.init n (fun _ -> Scanf.scanf "%s\n" (fun s -> s))) in

  (* graph of letter ordering *)
  let gr = Array.make 26 []
  and deg = Array.make 26 (0, 0) in
  let get' = get gr
  and set = set gr deg in

  (* recursively process strings *)
  let rec process s n =
    let g = group s n in
    match g with
    | [] -> ()
    | _ ->
      ignore (List.fold_left (fun p (c, xs) ->
        (match p with
         | Some p -> let t = get' p in set p c t
         | None -> ());
        process xs (n + 1);
        Some c) None g)
  in
  process strs 0;

  let s = Stack.create ()
  and alphabet = Stack.create ()
  and seen = Array.make 26 Unseen
  and order = Array.make 26 0
  in
  for i = 0 to 25 do Stack.push i s done;

  let rec visit i =
    match seen.(i) with
    | Temp -> raise Cycle
    | Seen -> ()
    | Unseen -> begin
      seen.(i) <- Temp;
      List.iter (fun c -> visit (int_of_char c - int_of_char 'a')) gr.(i);
      seen.(i) <- Seen;
      Stack.push (char_of_int (i + int_of_char 'a')) alphabet
    end
  in

  (* topologically sort the graph in gr *)
  try
    while not (Stack.is_empty s) do
      visit (Stack.pop s)
    done;
    (* sort strs according to alphabet and
     * check that it doesn't change *)
    let i = ref 0 in
    Stack.iter (fun c -> order.(int_of_char c - int_of_char 'a') <- !i; incr i) (Stack.copy alphabet);
    if List.sort (strcmp order) strs = strs then begin
      Stack.iter print_char alphabet;
      print_char '\n'
    end else raise Cycle
  with Cycle -> print_endline "Impossible"
)

let n = read_int();;

let graf = Array.make_matrix 26 26 false;;
let slowa = ref [];;

for i = 0 to n - 1 do
    slowa := (read_line())::(!slowa)
done;;

slowa := List.rev !slowa;;

let impossibru = ref false;;

let chti x = (Char.code x) - (Char.code 'a');;

let porownaj a b =
    let m = min (String.length a) (String.length b)
    and i = ref 0
    and st = ref false in
    while !i < m && not !st do
        if a.[!i] <> b.[!i] then
            begin
                graf.(chti a.[!i]).(chti b.[!i]) <- true;
                st := true
            end
        else i := !i + 1
    done;
    if !i = m then impossibru := true

let rec gen l =
    let rec genpom a l =
        match l with
        | [] -> ()
        | h::t ->
            porownaj a h;
            genpom a t in
    match l with
    | [] -> ()
    | h::t ->
        genpom h t;
        gen t;;

gen !slowa;;

let btc x =
    match x with
    | false -> '0'
    | true -> '1';;

let odw = Array.make 26 (-1);;
let gnr = ref 1;;

let rec dfs v =
    odw.(v) <- 0;
    for i = 0 to 25 do
        if graf.(v).(i) then
            begin
                if odw.(i) = -1 then dfs i
                else if odw.(i) = 0 then impossibru := true
            end
    done;
    odw.(v) <- !gnr;
    gnr := !gnr + 1;;

for i = 0 to 25 do
    if odw.(i) = -1 then dfs i
done;;

if !impossibru then print_string "Impossible\n"
else
    let res = String.make 26 ' ' in
    for i = 0 to 25 do
        Bytes.set res (26 - odw.(i)) (Char.chr (Char.code 'a' + i))
    done;
    print_string res
;;

type seen = Unseen | Temp | Seen
exception Cycle

(* non-fatal string indexing *)
let nth s n =
  try Some s.[n] with Invalid_argument "index out of bounds" -> None

(* array indexing *)
let get a c = a.(int_of_char c - int_of_char 'a')
let set g d a b t =
  g.(int_of_char a - int_of_char 'a') <- b :: t;
  let (ain, aout) = get d a in
  d.(int_of_char a - int_of_char 'a') <- (ain, aout + 1);
  let (bin, bout) = get d b in
  d.(int_of_char b - int_of_char 'a') <- (bin + 1, bout)

(* group strings by their nth letter *)
let group s n =
  let g = List.fold_left (fun a x -> match nth x n with
  | None -> a
  | Some c -> begin
    match a with
    | [] -> [c, [x]]
    | (d, _) :: _ when c <> d -> (c, [x]) :: a
    | (_, xs) :: t -> (c, x :: xs) :: t
  end
  ) [] s in
  List.rev_map (fun (c, xs) -> (c, List.rev xs)) g

let () = Scanf.scanf "%d\n" (fun n ->
  (* list of strings *)
  let s = Array.to_list (Array.init n (fun _ -> Scanf.scanf "%s\n" (fun s -> s))) in

  (* graph of letter ordering *)
  let gr = Array.make 26 []
  and deg = Array.make 26 (0, 0) in
  let get = get gr
  and set = set gr deg in

  (* recursively process strings *)
  let rec process s n =
    let g = group s n in
    match g with
    | [] -> ()
    | _ ->
      ignore (List.fold_left (fun p (c, xs) ->
        (match p with
         | Some p -> let t = get p in set p c t
         | None -> ());
        process xs (n + 1);
        Some c) None g)
  in
  process s 0;

  let s = Stack.create ()
  and alphabet = Stack.create ()
  and seen = Array.make 26 Unseen in
  for i = 0 to 25 do Stack.push i s done;

  let rec visit i =
    match seen.(i) with
    | Temp -> raise Cycle
    | Seen -> ()
    | Unseen -> begin
      seen.(i) <- Temp;
      List.iter (fun c -> visit (int_of_char c - int_of_char 'a')) gr.(i);
      seen.(i) <- Seen;
      Stack.push (char_of_int (i + int_of_char 'a')) alphabet
    end
  in

  (* topologically sort the graph in gr *)
  try
    while not (Stack.is_empty s) do
      visit (Stack.pop s)
    done;
    Stack.iter print_char alphabet;
    print_char '\n'
  with Cycle -> print_endline "Impossible"
)


let getnum =
  let l = 512000 in
  let buf = String.make l ' ' in
  let s = ref 0 in
  let pos = ref 0 in
  let getc () =
    if !pos >= !s then (
      let new_s = input stdin buf 0 l in
	(*if new_s = 0 then raise End_of_file;*)
	s := new_s;
	if new_s = 0 then (
	  buf.[0] <- '\000';
	  s := 1;
	);
	pos := 0;
    );
    let c = buf.[!pos] in
      incr pos;
      c
  in
  let aux () =
    let n = ref 0 in
    let k = ref 1 in
      if !s - !pos < 50 then (
	let c = ref (getc ()) in
	  while !c <= ' ' do
	    c := getc ()
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := getc ();
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := getc ()
	  done;
	  !n * !k
      ) else (
	let c = ref (buf.[!pos]) in
	  incr pos;
	  while !c <= ' ' do
	    c := buf.[!pos];
	    incr pos;
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := buf.[!pos];
	    incr pos;
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := buf.[!pos];
	    incr pos;
	  done;
	  !n * !k
      )
  in
    aux

let _ =
  let sqr x = x *. x in
  let n = getnum () in
  let a = Array.make_matrix n n 0 in
  let () =
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	a.(i).(j) <- getnum ()
      done
    done
  in
  let resc = ref 0 in
  let ress = ref 0 in
  let d = 5 in
  let used = Array.make_matrix n n false in
  let stack = Array.make (n * n) (0, 0) in
  let pos = ref 0 in
  let f = 5 in
  let a' = Array.make_matrix n n 0 in
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	let b = ref 0 in
	  for i' = -f to f do
	    for j' = -f to f do
	      let x = j + j'
	      and y = i + i' in
		if x >= 0 && y >= 0 && x < n && y < n
		then b := !b + a.(y).(x)
	    done
	  done;
	  if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4
	  then a'.(i).(j) <- 1
      done
    done;
    for i = 0 to n - 1 do
      a.(i) <- a'.(i)
    done;
    for i = 0 to n - 1 - d do
      for j = 0 to n - 1 - d do
	if not used.(i).(j) then (
	  let b = ref true in
	    for i' = 0 to d - 1 do
	      for j' = 0 to d - 1 do
		if a.(i + i').(j + j') = 0
		then b := false
	      done
	    done;
	    if !b then (
	      let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in
	      let border = ref [] in
	      let rec dfs () =
		if !pos > 0 then (
		  decr pos;
		  let (x, y) = stack.(!pos) in
		    for i = 0 to 3 do
		      let (dx, dy) = d.(i) in
		      let x = x + dx
		      and y = y + dy in
			if x >= 0 && y >= 0 && x < n && y < n &&
			  a.(y).(x) > 0
			then (
			  if not used.(y).(x) then (
			    stack.(!pos) <- (x, y);
			    incr pos;
			    used.(y).(x) <- true;
			  )
			) else (
			  border := (x, y) :: !border
			)
		    done;
		    dfs ()
		)
	      in
		pos := 0;
		stack.(!pos) <- (j, i);
		incr pos;
		used.(i).(j) <- true;
		dfs ();
		let border = Array.of_list !border in
		let l = Array.length border in
		let (mx, my) =
		  let mx = ref 0 in
		  let my = ref 0 in
		    for i = 0 to l - 1 do
		      let (x, y) = border.(i) in
			mx := !mx + x;
			my := !my + y;
		    done;
		    (float_of_int !mx /. float_of_int l,
		     float_of_int !my /. float_of_int l)
		in
		let d =
		  Array.map
		    (fun (x, y) ->
		       let x = float_of_int x
		       and y = float_of_int y in
			 sqrt (sqr (x -. mx) +. sqr (y -. my))
		    ) border
		in
		let r =
		  let r = ref 0.0 in
		    for i = 0 to l - 1 do
		      r := !r +. d.(i)
		    done;
		    !r /. float_of_int l
		in
		let sr =
		  let sr = ref 0.0 in
		    for i = 0 to l - 1 do
		      sr := !sr +. sqr (d.(i) -. r)
		    done;
		    !sr /. float_of_int l
		in
		  if sr /. r < 0.03
		  then incr resc
		  else incr ress;
		  (*Printf.printf "asd %f %f %f %f\t%f  %d\n"
		    mx my r sr (sr /. r) l*)
	    )
	)
      done
    done;
    Printf.printf "%d %d\n" !resc !ress;

let getnum =
  let l = 512000 in
  let buf = String.make l ' ' in
  let s = ref 0 in
  let pos = ref 0 in
  let getc () =
    if !pos >= !s then (
      let new_s = input stdin buf 0 l in
	(*if new_s = 0 then raise End_of_file;*)
	s := new_s;
	if new_s = 0 then (
	  buf.[0] <- '\000';
	  s := 1;
	);
	pos := 0;
    );
    let c = buf.[!pos] in
      incr pos;
      c
  in
  let aux () =
    let n = ref 0 in
    let k = ref 1 in
      if !s - !pos < 50 then (
	let c = ref (getc ()) in
	  while !c <= ' ' do
	    c := getc ()
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := getc ();
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := getc ()
	  done;
	  !n * !k
      ) else (
	let c = ref (buf.[!pos]) in
	  incr pos;
	  while !c <= ' ' do
	    c := buf.[!pos];
	    incr pos;
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := buf.[!pos];
	    incr pos;
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := buf.[!pos];
	    incr pos;
	  done;
	  !n * !k
      )
  in
    aux

let _ =
  let sqr x = x *. x in
  let n = getnum () in
  let a = Array.make_matrix n n 0 in
  let () =
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	a.(i).(j) <- getnum ()
      done
    done
  in
  let resc = ref 0 in
  let ress = ref 0 in
  let d = 5 in
  let used = Array.make_matrix n n false in
  let stack = Array.make (n * n) (0, 0) in
  let pos = ref 0 in
    for i = 0 to n - 1 - d do
      for j = 0 to n - 1 - d do
	if not used.(i).(j) then (
	  let b = ref true in
	    for i' = 0 to d - 1 do
	      for j' = 0 to d - 1 do
		if a.(i + i').(j + j') = 0
		then b := false
	      done
	    done;
	    if !b then (
	      let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in
	      let border = ref [] in
	      let rec dfs () =
		if !pos > 0 then (
		  decr pos;
		  let (x, y) = stack.(!pos) in
		    for i = 0 to 3 do
		      let (dx, dy) = d.(i) in
		      let x = x + dx
		      and y = y + dy in
			if x >= 0 && y >= 0 && x < n && y < n &&
			  a.(y).(x) > 0
			then (
			  if not used.(y).(x) then (
			    stack.(!pos) <- (x, y);
			    incr pos;
			    used.(y).(x) <- true;
			  )
			) else (
			  border := (x, y) :: !border
			)
		    done;
		    dfs ()
		)
	      in
		pos := 0;
		stack.(!pos) <- (j, i);
		incr pos;
		used.(i).(j) <- true;
		dfs ();
		let border = Array.of_list !border in
		let l = Array.length border in
		let (mx, my) =
		  let mx = ref 0 in
		  let my = ref 0 in
		    for i = 0 to l - 1 do
		      let (x, y) = border.(i) in
			mx := !mx + x;
			my := !my + y;
		    done;
		    (float_of_int !mx /. float_of_int l,
		     float_of_int !my /. float_of_int l)
		in
		let d =
		  Array.map
		    (fun (x, y) ->
		       let x = float_of_int x
		       and y = float_of_int y in
			 sqrt (sqr (x -. mx) +. sqr (y -. my))
		    ) border
		in
		let r =
		  let r = ref 0.0 in
		    for i = 0 to l - 1 do
		      r := !r +. d.(i)
		    done;
		    !r /. float_of_int l
		in
		let sr =
		  let sr = ref 0.0 in
		    for i = 0 to l - 1 do
		      sr := !sr +. sqr (d.(i) -. r)
		    done;
		    !sr /. float_of_int l
		in
		  if sr < 1.0
		  then incr resc
		  else incr ress;
		  (*Printf.printf "asd %f %f %f %f  %d\n" mx my r sr l*)
	    )
	)
      done
    done;
    Printf.printf "%d %d\n" !resc !ress;

let getnum =
  let l = 512000 in
  let buf = String.make l ' ' in
  let s = ref 0 in
  let pos = ref 0 in
  let getc () =
    if !pos >= !s then (
      let new_s = input stdin buf 0 l in
	(*if new_s = 0 then raise End_of_file;*)
	s := new_s;
	if new_s = 0 then (
	  buf.[0] <- '\000';
	  s := 1;
	);
	pos := 0;
    );
    let c = buf.[!pos] in
      incr pos;
      c
  in
  let aux () =
    let n = ref 0 in
    let k = ref 1 in
      if !s - !pos < 50 then (
	let c = ref (getc ()) in
	  while !c <= ' ' do
	    c := getc ()
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := getc ();
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := getc ()
	  done;
	  !n * !k
      ) else (
	let c = ref (buf.[!pos]) in
	  incr pos;
	  while !c <= ' ' do
	    c := buf.[!pos];
	    incr pos;
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := buf.[!pos];
	    incr pos;
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := buf.[!pos];
	    incr pos;
	  done;
	  !n * !k
      )
  in
    aux

let _ =
  let sqr x = x *. x in
  let n = getnum () in
  let a = Array.make_matrix n n 0 in
  let () =
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	a.(i).(j) <- getnum ()
      done
    done
  in
  let resc = ref 0 in
  let ress = ref 0 in
  let d = 5 in
  let used = Array.make_matrix n n false in
  let stack = Array.make (n * n) (0, 0) in
  let pos = ref 0 in
  let f = 5 in
  let a' = Array.make_matrix n n 0 in
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	let b = ref 0 in
	  for i' = -f to f do
	    for j' = -f to f do
	      let x = j + j'
	      and y = i + i' in
		if x >= 0 && y >= 0 && x < n && y < n
		then b := !b + a.(y).(x)
	    done
	  done;
	  if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4
	  then a'.(i).(j) <- 1
      done
    done;
    for i = 0 to n - 1 do
      a.(i) <- a'.(i)
    done;
    for i = 0 to n - 1 - d do
      for j = 0 to n - 1 - d do
	if not used.(i).(j) then (
	  let b = ref true in
	    for i' = 0 to d - 1 do
	      for j' = 0 to d - 1 do
		if a.(i + i').(j + j') = 0
		then b := false
	      done
	    done;
	    if !b then (
	      let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in
	      let border = ref [] in
	      let rec dfs () =
		if !pos > 0 then (
		  decr pos;
		  let (x, y) = stack.(!pos) in
		    for i = 0 to 3 do
		      let (dx, dy) = d.(i) in
		      let x = x + dx
		      and y = y + dy in
			if x >= 0 && y >= 0 && x < n && y < n &&
			  a.(y).(x) > 0
			then (
			  if not used.(y).(x) then (
			    stack.(!pos) <- (x, y);
			    incr pos;
			    used.(y).(x) <- true;
			  )
			) else (
			  border := (x, y) :: !border
			)
		    done;
		    dfs ()
		)
	      in
		pos := 0;
		stack.(!pos) <- (j, i);
		incr pos;
		used.(i).(j) <- true;
		dfs ();
		let border = Array.of_list !border in
		let l = Array.length border in
		let (mx, my) =
		  let mx = ref 0 in
		  let my = ref 0 in
		    for i = 0 to l - 1 do
		      let (x, y) = border.(i) in
			mx := !mx + x;
			my := !my + y;
		    done;
		    (float_of_int !mx /. float_of_int l,
		     float_of_int !my /. float_of_int l)
		in
		let d =
		  Array.map
		    (fun (x, y) ->
		       let x = float_of_int x
		       and y = float_of_int y in
			 sqrt (sqr (x -. mx) +. sqr (y -. my))
		    ) border
		in
		let r =
		  let r = ref 0.0 in
		    for i = 0 to l - 1 do
		      r := !r +. d.(i)
		    done;
		    !r /. float_of_int l
		in
		let sr =
		  let sr = ref 0.0 in
		    for i = 0 to l - 1 do
		      sr := !sr +. sqr (d.(i) -. r)
		    done;
		    !sr /. float_of_int l
		in
		  if sr < 1.0
		  then incr resc
		  else incr ress;
		  (*Printf.printf "asd %f %f %f %f  %d\n" mx my r sr l*)
	    )
	)
      done
    done;
    Printf.printf "%d %d\n" !resc !ress;

let getnum =
  let l = 512000 in
  let buf = String.make l ' ' in
  let s = ref 0 in
  let pos = ref 0 in
  let getc () =
    if !pos >= !s then (
      let new_s = input stdin buf 0 l in
	(*if new_s = 0 then raise End_of_file;*)
	s := new_s;
	if new_s = 0 then (
	  buf.[0] <- '\000';
	  s := 1;
	);
	pos := 0;
    );
    let c = buf.[!pos] in
      incr pos;
      c
  in
  let aux () =
    let n = ref 0 in
    let k = ref 1 in
      if !s - !pos < 50 then (
	let c = ref (getc ()) in
	  while !c <= ' ' do
	    c := getc ()
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := getc ();
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := getc ()
	  done;
	  !n * !k
      ) else (
	let c = ref (buf.[!pos]) in
	  incr pos;
	  while !c <= ' ' do
	    c := buf.[!pos];
	    incr pos;
	  done;
	  if !c = '-' then (
	    k := -1;
	    c := buf.[!pos];
	    incr pos;
	  );
	  while !c > ' ' do
	    n := !n * 10 + (Char.code !c - Char.code '0');
	    c := buf.[!pos];
	    incr pos;
	  done;
	  !n * !k
      )
  in
    aux

let _ =
  let sqr x = x *. x in
  let n = getnum () in
  let a = Array.make_matrix n n 0 in
  let () =
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	a.(i).(j) <- getnum ()
      done
    done
  in
  let resc = ref 0 in
  let ress = ref 0 in
  let d = 5 in
  let used = Array.make_matrix n n false in
  let stack = Array.make (n * n) (0, 0) in
  let pos = ref 0 in
  let f = 3 in
  let a' = Array.make_matrix n n 0 in
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
	let b = ref 0 in
	  for i' = -f to f do
	    for j' = -f to f do
	      let x = j + j'
	      and y = i + i' in
		if x >= 0 && y >= 0 && x < n && y < n
		then b := !b + a.(y).(x)
	    done
	  done;
	  if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4
	  then a'.(i).(j) <- 1
      done
    done;
    for i = 0 to n - 1 do
      a.(i) <- a'.(i)
    done;
    for i = 0 to n - 1 - d do
      for j = 0 to n - 1 - d do
	if not used.(i).(j) then (
	  let b = ref true in
	    for i' = 0 to d - 1 do
	      for j' = 0 to d - 1 do
		if a.(i + i').(j + j') = 0
		then b := false
	      done
	    done;
	    if !b then (
	      let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in
	      let border = ref [] in
	      let rec dfs () =
		if !pos > 0 then (
		  decr pos;
		  let (x, y) = stack.(!pos) in
		    for i = 0 to 3 do
		      let (dx, dy) = d.(i) in
		      let x = x + dx
		      and y = y + dy in
			if x >= 0 && y >= 0 && x < n && y < n &&
			  a.(y).(x) > 0
			then (
			  if not used.(y).(x) then (
			    stack.(!pos) <- (x, y);
			    incr pos;
			    used.(y).(x) <- true;
			  )
			) else (
			  border := (x, y) :: !border
			)
		    done;
		    dfs ()
		)
	      in
		pos := 0;
		stack.(!pos) <- (j, i);
		incr pos;
		used.(i).(j) <- true;
		dfs ();
		let border = Array.of_list !border in
		let l = Array.length border in
		let (mx, my) =
		  let mx = ref 0 in
		  let my = ref 0 in
		    for i = 0 to l - 1 do
		      let (x, y) = border.(i) in
			mx := !mx + x;
			my := !my + y;
		    done;
		    (float_of_int !mx /. float_of_int l,
		     float_of_int !my /. float_of_int l)
		in
		let d =
		  Array.map
		    (fun (x, y) ->
		       let x = float_of_int x
		       and y = float_of_int y in
			 sqrt (sqr (x -. mx) +. sqr (y -. my))
		    ) border
		in
		let r =
		  let r = ref 0.0 in
		    for i = 0 to l - 1 do
		      r := !r +. d.(i)
		    done;
		    !r /. float_of_int l
		in
		let sr =
		  let sr = ref 0.0 in
		    for i = 0 to l - 1 do
		      sr := !sr +. sqr (d.(i) -. r)
		    done;
		    !sr /. float_of_int l
		in
		  if sr < 1.0
		  then incr resc
		  else incr ress;
		  (*Printf.printf "asd %f %f %f %f  %d\n" mx my r sr l*)
	    )
	)
      done
    done;
    Printf.printf "%d %d\n" !resc !ress;


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

module Dmap = Map.Make (struct type t = int let compare = compare end)

let () =
  let (n,m) = read_pair() in
  let k = read_int() in

  let rtable = Hashtbl.create 100 in (* represent each of the m+1 rows of length n *)
  let ctable = Hashtbl.create 100 in (* represent each of the n+1 columns of length m *)

  let increment map key delta =
    let odelta = try Dmap.find key map with Not_found -> 0 in
      Dmap.add key (odelta+delta) map
  in

  let () =
    for i=0 to k-1 do
      let (a,b) = read_pair() in
      let (c,d) = read_pair() in
      let (table, which, lo, hi) =
	if a=c then (ctable, a, min b d, max b d)
	else        (rtable, b, min a c, max a c)
      in
      let map = try Hashtbl.find table which with Not_found -> Dmap.empty in
      let map = increment map lo 1 in
      let map = increment map hi (-1) in
	Hashtbl.replace table which map
    done
  in

  let maplength map dim =
    (* total length of the zero regions of this map, where b is the upper bound of things in it *)
    let rec loop depth ac x map = if Dmap.is_empty map then ac + (dim-x) else
      let (x',delta) = Dmap.min_binding map in
      let map = Dmap.remove x' map in
      let ac = if depth=0 then ac + (x'-x) else ac in
      let depth = delta + depth in
	loop depth ac x' map
    in
      loop 0 0 0 map
  in

  let find_move nimber map dim =
    (* returns the position in the given map so that a move from 0 to that position cancels out the nimber *)
    (* we know that it is possible to do this *)
    let rec loop depth need x map = if Dmap.is_empty map then x+need else
      let (x',delta) = Dmap.min_binding map in
      let map = Dmap.remove x' map in
      let need' = if depth=0 then need - (x'-x) else need in
      let depth = delta + depth in
	if need' > 0 then loop depth need' x' map
	else x+need
    in
    let pile = maplength map dim in
    let pile' = pile lxor nimber in
      loop 0 (pile - pile') 0 map
  in

  let augment_table table dim =
    (* add an extra row or column if the number of untouched rows/colunns is odd *)
    let size = Hashtbl.length table in
      if ((dim-1) - size) mod 2 = 1 then
	let rec find_unused x = if not (Hashtbl.mem table x) then x else find_unused (x+1) in
	let unused = find_unused 1 in
	  Hashtbl.add table unused Dmap.empty
  in

  let () =
    augment_table rtable m;
    augment_table ctable n;
  in

  let compute_nimber table dim =
    Hashtbl.fold (fun _ map ac -> (maplength map dim) lxor ac) table 0
  in

  let nimber = (compute_nimber rtable n) lxor (compute_nimber ctable m) in

    (* Printf.printf "nimber = %d\n" nimber; *)

    if nimber = 0 then Printf.printf "SECOND\n" else (
      (* nimber is non-zero so we have to figure out what move to make *)
      (* find a move pile in which to move which has a 1 in the position of the
	 top 1 bit of the nimber. *)
      let rec compute_top_bit b = if (b lor (b-1)) land nimber = nimber then b else compute_top_bit (2*b) in
      let top_bit = compute_top_bit 1 in
      let find_good_pile table dim =
	Hashtbl.fold (fun v map ac -> if (top_bit land (maplength map dim)) <> 0 then (v,map) else ac)
	  table (-1, Dmap.empty)
      in

      let (row,rmap) = find_good_pile rtable n in
      let (column,cmap) = find_good_pile ctable m in
	(* Printf.printf "nimber = %d  top_bit = %d row = %d column = %d\n" nimber top_bit row column; *)

      let (sx,sy,ex,ey) = if row >= 0 then (
	let move = find_move nimber rmap n in
	  (0, row, move, row)
      )
      else if column >=0 then (
	let move = find_move nimber cmap m in
	  (column, 0, column, move)
      )
      else (
	Printf.printf "Error: can't find move\n";
	(0,0,0,0)
      )
      in
	Printf.printf "FIRST\n";
	Printf.printf "%d %d %d %d\n" sx sy ex ey
    )

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

module Dmap = Map.Make (struct type t = int let compare = compare end)

let () =
  let (n,m) = read_pair() in
  let k = read_int() in
  let cuts = Array.init k (
    fun _ ->
      let (a,b) = read_pair() in
      let (c,d) = read_pair() in
	(a,b,c,d)
  ) in

  let rtable = Hashtbl.create 100 in (* represent each of the m+1 rows of length n *)
  let ctable = Hashtbl.create 100 in (* represent each of the n+1 columns of length m *)

  let increment map key delta =
    let odelta = try Dmap.find key map with Not_found -> 0 in
      Dmap.add key (odelta+delta) map
  in

  let () =
    for i=0 to k-1 do
      let (a,b,c,d) = cuts.(i) in
      let (table, which, lo, hi) =
	if a=c then (ctable, a, min b d, max b d)
	else        (rtable, b, min a c, max a c)
      in
      let map = try Hashtbl.find table which with Not_found -> Dmap.empty in
      let map = increment map lo 1 in
      let map = increment map hi (-1) in
	Hashtbl.replace table which map
    done
  in

  let maplength map dim =
    (* total length of the zero regions of this map, where b is the upper bound of things in it *)
    let rec loop depth ac x map = if Dmap.is_empty map then ac + (dim-x) else
      let (x',delta) = Dmap.min_binding map in
      let map = Dmap.remove x' map in
      let ac = if depth=0 then ac + (x'-x) else ac in
      let depth = delta + depth in
	loop depth ac x' map
    in
      loop 0 0 0 map
  in

  let find_move nimber map dim =
    (* returns the position in the given map so that a move from 0 to that position cancels out the nimber *)
    (* we know that it is possible to do this *)
    let rec loop depth need x map = if Dmap.is_empty map then x+need else
      let (x',delta) = Dmap.min_binding map in
      let map = Dmap.remove x' map in
      let need' = if depth=0 then need - (x'-x) else need in
      let depth = delta + depth in
	if need' > 0 then loop depth need' x' map
	else x+need
    in
    let pile = maplength map dim in
    let pile' = pile lxor nimber in
      loop 0 (pile - pile') 0 map
  in

  let augment_table table dim =
    (* add an extra row or column if the number of untouched rows/colunns is odd *)
    let size = Hashtbl.length table in
      if ((dim+1) - size) mod 2 = 1 then
	let rec find_unused x = if not (Hashtbl.mem table x) then x else find_unused (x+1) in
	let unused = find_unused 0 in
	  Hashtbl.add table unused Dmap.empty
  in

  let () =
    augment_table rtable m;
    augment_table ctable n;
  in

  let compute_nimber table dim =
    Hashtbl.fold (fun _ map ac -> (maplength map dim) lxor ac) table 0
  in

  let nimber = (compute_nimber rtable n) lxor (compute_nimber ctable m) in

    (* Printf.printf "nimber = %d\n" nimber; *)

    if nimber = 0 then Printf.printf "SECOND\n" else (
      (* nimber is non-zero so we have to figure out what move to make *)
      (* find a move pile in which to move which has a 1 in the position of the
	 top 1 bit of the nimber. *)
      let rec compute_top_bit b = if (b lor (b-1)) land nimber = nimber then b else compute_top_bit (2*b) in
      let top_bit = compute_top_bit 1 in
      let find_good_pile table dim =
	Hashtbl.fold (fun v map ac -> if (top_bit land (maplength map dim)) <> 0 then (v,map) else ac)
	  table (-1, Dmap.empty)
      in

      let (row,rmap) = find_good_pile rtable n in
      let (column,cmap) = find_good_pile ctable m in
	(* Printf.printf "nimber = %d  top_bit = %d row = %d column = %d\n" nimber top_bit row column; *)

      let (sx,sy,ex,ey) = if row >= 0 then (
	let move = find_move nimber rmap n in
	  (0, row, move, row)
      )
      else if column >=0 then (
	let move = find_move nimber cmap m in
	  (column, 0, column, move)
      )
      else (
	Printf.printf "Error: can't find move\n";
	(0,0,0,0)
      )
      in
	Printf.printf "FIRST\n";
	Printf.printf "%d %d %d %d\n" sx sy ex ey
    )


let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let x = Scanf.bscanf sb "%d " (fun s -> s) in
  let x = x - 1 in
  let a = Array.make n 0 in
  let b = Array.make n (-1) in
  let () =
    for i = 0 to n - 1 do
      let k = Scanf.bscanf sb "%d " (fun s -> s) in
	a.(i) <- k - 1;
	if k > 0
	then b.(k - 1) <- i
    done;
  in
  let used = Array.make n false in
  let c = Array.make n 1 in
  let rec dfs k =
    used.(k) <- true;
    if b.(k) >= 0 then (
      dfs b.(k);
      c.(k) <- c.(b.(k)) + 1;
    )
  in
  let used2 = Array.make n false in
  let bob =
    let c = ref 1 in
    let p = ref x in
      used2.(x) <- true;
      while a.(!p) >= 0 do
	incr c;
	p := a.(!p);
	used2.(!p) <- true;
      done;
      !c
  in
  let () =
    for i = 0 to n - 1 do
      if not used.(i)
      then dfs i
    done;
  in
  let s = ref [] in
  let () =
    for i = 0 to n - 1 do
      if not used2.(i) && a.(i) < 0
      then s := c.(i) :: !s
    done;
  in
  let s = Array.of_list !s in
  let a = Array.make (n + 1) false in
    a.(0) <- true;
    for k = 0 to Array.length s - 1 do
      let k = s.(k) in
(*Printf.printf "asd %d\n" k;*)
	for i = n downto k do
	  if a.(i - k)
	  then a.(i) <- true
	done
    done;
    (*for i = 0 to n - 1 do
      Printf.printf "c %d %d %d\n" i c.(i) x;
    done;*)
    for i = 0 to n do
      if a.(i)
      then Printf.printf "%d\n" (i + bob);
    done


let input = open_in "input.txt"
let output = open_out "output.txt"

let read_int () = Scanf.fscanf input " %d " (fun x -> x) ;;

let n = read_int () ;;

let a =
    let len = 2 * n
    in let rec loop i f =
        if i > len then f []
        else let ai = read_int () in loop (i + 1) (fun l -> f ((ai, i) :: l))
    in loop 1 (fun x -> x) ;;

let upper = List.fold_left (fun x (v, i) -> max x v) 0 a ;;
let seen = Array.make (upper + 1) 0 ;;

let pairs =
    let rec loop l a = match l with
        | [] -> a
        | (v, i) :: t ->
            if seen.(v) = 0 then (seen.(v) <- i ; loop t a)
            else let j = seen.(v) in seen.(v) <- 0 ; loop t ((j, i) :: a)
    in loop a [] ;;

let possible =
    let rec loop i =
        if i > upper then true
        else if seen.(i) <> 0 then false else loop (i + 1)
    in loop 1 ;;

if not possible then Printf.fprintf output "-1\n"
else
    let print_pair (a, b) = Printf.fprintf output "%d %d\n" a b
    in let rec loop = function
        | [] -> ()
        | h :: t -> print_pair h ; loop t
    in loop pairs ;;

let input = open_in "input.txt"
let output = open_out "output.txt"

let read_int () = Scanf.fscanf input " %d " (fun x -> x) ;;

let n = read_int () ;;

let a =
    let len = 2 * n
    in let rec loop i f =
        if i > len then f []
        else let ai = read_int () in loop (i + 1) (fun l -> f ((ai, i) :: l))
    in loop 1 (fun x -> x) ;;

let seen = Array.make 5001 0 ;;

let pairs =
    let rec loop l a = match l with
        | [] -> a
        | (v, i) :: t ->
            if seen.(v) = 0 then (seen.(v) <- i ; loop t a)
            else let j = seen.(v) in seen.(v) <- 0 ; loop t ((j, i) :: a)
    in loop a [] ;;

let possible =
    let rec loop i =
        if i > 5000 then true
        else if seen.(i) <> 0 then false else loop (i + 1)
    in loop 1 ;;

let print_pair (a, b) = Printf.fprintf output "%d %d\n" a b ;;

if not possible then Printf.fprintf output "-1\n"
else
    let rec loop = function
        | [] -> ()
        | h :: t -> print_pair h ; loop t
    in loop pairs ;;

let chan = Scanf.Scanning.from_channel (open_in "input.txt")
let read_int () = Scanf.bscanf chan " %d " (fun x -> x)

let ochan = open_out "output.txt"
let print_string s = Printf.fprintf ochan "%s" s

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

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

  let t = Array.make 5001 (-1) in

  let rec loop i p = if i=2*n then () else (
    if t.(a.(i)) >= 0 then (
      if p then print_string (Printf.sprintf "%d %d\n" (1+t.(a.(i))) (i+1));
      t.(a.(i)) <- -1;
      loop (i+1) p
    ) else (
      t.(a.(i)) <- i;
      loop (i+1) p
    )
  )
  in

    loop 0 false;

    if (maxf 0 5000 (fun i-> t.(i))) = -1 then (
      loop 0 true;
    ) else (
      print_string "-1\n"
    )

let chan = Scanf.Scanning.from_channel (open_in "input.txt")
let read_int () = Scanf.bscanf chan " %d " (fun x -> x)

let ochan = open_out "output.txt"
let print_string s = Printf.fprintf ochan "%s" s

module Iset = Set.Make (struct type t = int let compare = compare end)

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

  let rec loop i p s = if i=2*n then s else (
    if Iset.mem a.(i) s
    then (
      if p then print_string (Printf.sprintf "%d %d\n" a.(i) a.(i));
      loop (i+1) p (Iset.remove a.(i) s)
    )
    else loop (i+1) p (Iset.add a.(i) s)
  )
  in
  let s = loop 0 false Iset.empty in

    if Iset.is_empty s then (
      ignore (loop 0 true Iset.empty)
    ) else (
      print_string "-1\n"
    )


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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let ps = Array.make n (0L, 0L) in
  let _ =
    for i = 0 to n - 1 do
      let x = Scanf.bscanf sb "%Ld " (fun s -> s) in
      let y = Scanf.bscanf sb "%Ld " (fun s -> s) in
	ps.(i) <- (x, y)
    done;
  in
  let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in
  let area3 (x, y) (x1, y1) (x2, y2) =
    x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2
  in
  let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =
    if x1 < x2
    then -1
    else if x1 > x2
    then 1
    else compare y1 y2
  in
  let _ = Array.sort cmp ps in
    (* Convex hull *)
  let p1 = ps.(0)
  and p2 = ps.(n - 1) in
  let up = Array.make n (0L, 0L) in
  let down = Array.make n (0L, 0L) in
  let pos_up = ref 0 in
  let pos_down = ref 0 in
  let hull =
    up.(!pos_up) <- p1;
    incr pos_up;
    down.(!pos_down) <- p1;
    incr pos_down;
    for i = 1 to n - 1 do
      if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (
	while !pos_up >= 2 &&
	  area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) >= 0L do
	    decr pos_up
	done;
	up.(!pos_up) <- ps.(i);
	incr pos_up;
      );
      if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (
	while !pos_down >= 2 &&
	  area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) <= 0L do
	    decr pos_down
	done;
	down.(!pos_down) <- ps.(i);
	incr pos_down;
      );
    done;
    let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in
      for i = 0 to !pos_up - 1 do
	hull.(i) <- up.(i)
      done;
      for i = !pos_down - 2 downto 1 do
	hull.(!pos_down - 2 - i + !pos_up) <- down.(i)
      done;
      hull
  in
  let area3 (x, y) (x1, y1) (x2, y2) =
    let x = float_of_int x
    and y = float_of_int y
    and x1 = float_of_int x1
    and y1 = float_of_int y1
    and x2 = float_of_int x2
    and y2 = float_of_int y2 in
      x *. y1 +. x1 *. y2 +. x2 *. y -. x2 *. y1 -. x1 *. y -. x *. y2
  in
  let hull =
    Array.map (fun (x, y) -> (Int64.to_int x, Int64.to_int y)) hull
  in
  let maxs = ref 0.0 in
  let b = ref (0, 0, 0) in
    (*for i = 0 to Array.length hull - 1 do
      let (x, y) = hull.(i) in
	Printf.eprintf "asd %Ld %Ld\n" x y
    done;*)
    for i = 0 to Array.length hull - 1 do
      let k = ref i in
	for j = i + 2 to Array.length hull - 1 do
	  let s = ref 0.0 in
	  let s' = ref 0.0 in
	    s := abs_float (area3 hull.(i) hull.(j) hull.(!k));
	    while !k < j - 1 &&
	      (s' := abs_float (area3 hull.(i) hull.(j) hull.(!k + 1));
	       !s' >= !s)
	    do
	      incr k;
	      s := !s';
	      (*Printf.eprintf "qaz %d %d %d %Ld\n" i j !k !s;*)
	    done;
	    (*Printf.eprintf "zxc %d %d %Ld\n" i j !s;*)
	    if !maxs < !s then (
	      maxs := !s;
	      b := (i, j, !k);
	    )
	done;
    done;
    let (i, j, k) = !b in
    let (x1, y1) = hull.(i)
    and (x2, y2) = hull.(j)
    and (x3, y3) = hull.(k) in
      (*Printf.eprintf "qwe %Ld %Ld\n" x1 y1;
      Printf.eprintf "qwe %Ld %Ld\n" x2 y2;
      Printf.eprintf "qwe %Ld %Ld\n" x3 y3;*)
      Printf.printf "%d %d\n" (x2 + x3 - x1) (y2 + y3 - y1);
      Printf.printf "%d %d\n" (x3 + x1 - x2) (y3 + y1 - y2);
      Printf.printf "%d %d\n" (x1 + x2 - x3) (y1 + y2 - y3);

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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)

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

let long x = Int64.of_int x
let short x = Int64.to_int x

let cross (x1,y1) (x2,y2) = (x1**y2) -- (y1**x2)
let ( --- ) (x1,y1) (x2,y2) = (x1--x2, y1--y2)
let ( +++ ) (x1,y1) (x2,y2) = (x1++x2, y1++y2)

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 _ = read_long () in (* don't need s *)
  let p = Array.init n (fun _ ->
    let x = read_long() in
    (x, read_long())
  ) in

  let area a b c = Int64.abs (cross (b --- a) (c --- a)) in

  let rec expand no_change_count ar (a,b,c) =
    if no_change_count = 2 then (a,b,c) else
      let (ar', c') = maxf 0 (n-1) (fun c -> (area p.(a) p.(b) p.(c), c)) in
      if ar' > ar then expand 0 ar' (c',a,b) else expand (no_change_count+1) ar (c,a,b)
  in

  let (a,b,c) = expand 0 0L (0,1,2) in
  let (a,b,c) = (p.(a), p.(b), p.(c)) in

  let pr (x,y) = printf "%Ld %Ld\n" x y in
  pr (a +++ b --- c);
  pr (b +++ c --- a);
  pr (c +++ a --- b)

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let ps = Array.make n (0L, 0L) in
  let _ =
    for i = 0 to n - 1 do
      let x = Scanf.bscanf sb "%Ld " (fun s -> s) in
      let y = Scanf.bscanf sb "%Ld " (fun s -> s) in
	ps.(i) <- (x, y)
    done;
  in
  let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in
  let area3 (x, y) (x1, y1) (x2, y2) =
    x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2
  in
  let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =
    if x1 < x2
    then -1
    else if x1 > x2
    then 1
    else compare y1 y2
  in
  let _ = Array.sort cmp ps in
    (* Convex hull *)
  let p1 = ps.(0)
  and p2 = ps.(n - 1) in
  let up = Array.make n (0L, 0L) in
  let down = Array.make n (0L, 0L) in
  let pos_up = ref 0 in
  let pos_down = ref 0 in
  let hull =
    up.(!pos_up) <- p1;
    incr pos_up;
    down.(!pos_down) <- p1;
    incr pos_down;
    for i = 1 to n - 1 do
      if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (
	while !pos_up >= 2 &&
	  area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) >= 0L do
	    decr pos_up
	done;
	up.(!pos_up) <- ps.(i);
	incr pos_up;
      );
      if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (
	while !pos_down >= 2 &&
	  area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) <= 0L do
	    decr pos_down
	done;
	down.(!pos_down) <- ps.(i);
	incr pos_down;
      );
    done;
    let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in
      for i = 0 to !pos_up - 1 do
	hull.(i) <- up.(i)
      done;
      for i = !pos_down - 2 downto 1 do
	hull.(!pos_down - 2 - i + !pos_up) <- down.(i)
      done;
      hull
  in
  let maxs = ref 0L in
  let b = ref (0, 0, 0) in
    (*for i = 0 to Array.length hull - 1 do
      let (x, y) = hull.(i) in
	Printf.eprintf "asd %Ld %Ld\n" x y
    done;*)
    for i = 0 to Array.length hull - 1 do
      let k = ref i in
      let s = ref 0L in
	for j = i + 2 to Array.length hull - 1 do
	  while !k < j - 1 &&
	    Int64.abs (area3 hull.(i) hull.(j) hull.(!k + 1)) > !s
	  do
	    incr k;
	    s := Int64.abs (area3 hull.(i) hull.(j) hull.(!k));
	  done;
	  if !maxs < !s then (
	    maxs := !s;
	    b := (i, j, !k);
	  )
	done;
    done;
    let (i, j, k) = !b in
    let (x1, y1) = hull.(i)
    and (x2, y2) = hull.(j)
    and (x3, y3) = hull.(k) in
      Printf.printf "%Ld %Ld\n" (x2 +| x3 -| x1) (y2 +| y3 -| y1);
      Printf.printf "%Ld %Ld\n" (x3 +| x1 -| x2) (y3 +| y1 -| y2);
      Printf.printf "%Ld %Ld\n" (x1 +| x2 -| x3) (y1 +| y2 -| y3);

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let ps = Array.make n (0L, 0L) in
  let _ =
    for i = 0 to n - 1 do
      let x = Scanf.bscanf sb "%Ld " (fun s -> s) in
      let y = Scanf.bscanf sb "%Ld " (fun s -> s) in
	ps.(i) <- (x, y)
    done;
  in
  let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in
  let area3 (x, y) (x1, y1) (x2, y2) =
    x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2
  in
  let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =
    if x1 < x2
    then -1
    else if x1 > x2
    then 1
    else compare y1 y2
  in
  let _ = Array.sort cmp ps in
    (* Convex hull *)
  let p1 = ps.(0)
  and p2 = ps.(n - 1) in
  let up = Array.make n (0L, 0L) in
  let down = Array.make n (0L, 0L) in
  let pos_up = ref 0 in
  let pos_down = ref 0 in
  let hull =
    up.(!pos_up) <- p1;
    incr pos_up;
    down.(!pos_down) <- p1;
    incr pos_down;
    for i = 1 to n - 1 do
      if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (
	while !pos_up >= 2 &&
	  area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) > 0L do
	    decr pos_up
	done;
	up.(!pos_up) <- ps.(i);
	incr pos_up;
      );
      if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (
	while !pos_down >= 2 &&
	  area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) < 0L do
	    decr pos_down
	done;
	down.(!pos_down) <- ps.(i);
	incr pos_down;
      );
    done;
    let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in
      for i = 0 to !pos_up - 1 do
	hull.(i) <- up.(i)
      done;
      for i = !pos_down - 2 downto 1 do
	hull.(!pos_down - 2 - i + !pos_up) <- down.(i)
      done;
      hull
  in
  let maxs = ref 0L in
  let b = ref (0, 0, 0) in
    (*for i = 0 to Array.length hull - 1 do
      let (x, y) = hull.(i) in
	Printf.printf "asd %Ld %Ld\n" x y
    done;*)
    for i = 0 to Array.length hull - 1 do
      let k = ref i in
      let s = ref 0L in
	for j = i + 2 to Array.length hull - 1 do
	  while !k < j - 1 &&
	    Int64.abs (area3 hull.(i) hull.(j) hull.(!k + 1)) > !s
	  do
	    incr k;
	    s := Int64.abs (area3 hull.(i) hull.(j) hull.(!k));
	  done;
	  if !maxs < !s then (
	    maxs := !s;
	    b := (i, j, !k);
	  )
	done;
    done;
    let (i, j, k) = !b in
    let (x1, y1) = hull.(i)
    and (x2, y2) = hull.(j)
    and (x3, y3) = hull.(k) in
      Printf.printf "%Ld %Ld\n" (x2 +| x3 -| x1) (y2 +| y3 -| y1);
      Printf.printf "%Ld %Ld\n" (x3 +| x1 -| x2) (y3 +| y1 -| y2);
      Printf.printf "%Ld %Ld\n" (x1 +| x2 -| x3) (y1 +| y2 -| y3);


(* CF odd game prob 276 B *)
open Filename;;

(* you can use either gr or rdln but not both *)
let use_input_txt = false;;
let fn = (Filename.dirname Filename.current_dir_name);;
let filename = Filename.concat "." "input.txt";;
let cin = if use_input_txt then Scanf.Scanning.open_in filename
	else Scanf.Scanning.stdin;;

let cout = open_out "output.txt";;
let gr () = Scanf.bscanf cin " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line Pervasives.stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlisti64 li = List.iter (fun i -> (print_string (Int64.to_string i); print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let rec has1 i s =
	if i >= (String.length s) then false
	else if s.[i] = '1' then true
	else has1 (i+1) s;;

let can_convert a b =
	if (String.length a) <> (String.length b) then false
	else
		let ha = has1 0 a in
		let hb = has1 0 b in
		ha = hb;;

let main() =
	let sa = rdln() in
	let sb = rdln() in
	begin
		print_string (if can_convert sa sb then "YES" else "NO")
	end;;

main();;

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let sum i j f = fold i j (fun i a -> (f i) + a) 0
let rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)
let rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)

let () =
  let a = read_line() in
  let b = read_line() in
  let na = String.length a in
  let nb = String.length b in
  let all_zeros s n = forall 0 (n-1) (fun i -> s.[i] = '0') in
  let answer =
    if na != nb then false
    else if all_zeros a na then all_zeros b nb
    else not (all_zeros b nb)
  in
    print_string (if answer then "YES\n" else "NO\n")


let rv f p q = f q p
let fi = float_of_int
let (++),( ** ),(--),fi64,i64 = Int64.(add,mul,sub,to_float,of_int)
;;
Scanf.(Array.(scanf " %d %Ld %Ld" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0L in
  init n (fun left ->
    let left = left + 1 in
    total := !total ++ a.(left-1);
    let add = m -- (i64 n -- i64 left) in
    let limit = (i64 left) ** k in
    let add = min limit add in
    let r =
      if add < 0L then 0.
      else (fi64 (!total ++ add)) /. (fi left) in
    r
  )
  |> fold_left max 0.
  |> Printf.printf "%.14f"
));;

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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))
let () =
  let (n,k) = read_pair () in
  let m = read_int() in
  let a = Array.init n read_int in
  let s = Array.make (n+1) 0.0 in

  Array.sort compare a;

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

  let answer = maxf 0 (min m (n-1)) (fun i ->
    (* i are removed *)
    let kept = s.(n) -. s.(i) in
    let j = float (n-i) in (* number left in the set *)
    let ninc = min (float (m-i)) (j *. (float k)) in
    (kept +. ninc) /. j
  ) in

  printf "%f\n" answer

let rv f p q = f q p
let fi = float_of_int
let (++),( ** ),fi64,i64 = Int64.(add,mul,to_float,of_int)
;;
Scanf.(Array.(scanf " %d %d %d" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0L in
  init n (fun left ->
    let left = left + 1 in
    total := !total ++ a.(left-1);
    let add = i64 @@ m - (n - left) in
    let limit = (i64 left) ** (i64 k) in
    let add = min limit add in
    let r =
      if add < 0L then 0.
      else (fi64 (!total ++ add)) /. (fi left) in
    (* Printf.printf "%2d : %2Ld :: %2Ld :: %f\n" left add !total r; *)
    r
  )
  |> fold_left max (((fi64 @@ fold_left (++) 0L a)) /. (fi n))
  |> Printf.printf "%.14f"
))

let rv f p q = f q p
let fi = float_of_int;;
Scanf.(Array.(scanf " %d %d %d" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0 in
  init n (fun left ->
    let left = left + 1 in
    total := !total + a.(left-1);
    let add = m - (n - left) in
    let limit = left * k in
    let add = min limit add in
    let r =
      if add < 0 then 0.
      else (fi (!total + add)) /. (fi left) in
    (* Printf.printf "%2d : %2d :: %2d :: %f\n" left add !total r; *)
    r
  )
  |> fold_left max 0.
  |> print_float
))

let rv f p q = f q p
let fi = float_of_int
let (++),i64f,i64 = Int64.(add,to_float,of_int)
;;
Scanf.(Array.(scanf " %d %d %d" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0L in
  init n (fun left ->
    let left = left + 1 in
    total := !total ++ a.(left-1);
    let add = m - (n - left) in
    let limit = left * k in
    let add = i64 @@ min limit add in
    let r =
      if add < 0L then 0.
      else (i64f (!total ++ add)) /. (fi left) in
    (* Printf.printf "%2d : %2d :: %2d :: %f\n" left add !total r; *)
    r
  )
  |> fold_left max 0.
  |> print_float
));;

let rv f p q = f q p
let fi = float_of_int;;
Scanf.(Array.(scanf " %d %d %d" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0 in
  init n (fun left ->
    let left = left + 1 in
    total := !total + a.(left-1);
    let add = m - (n - left) in
    let limit = left * k in
    let add = min limit add in
    let r = (fi (!total + add)) /. (fi left) in
    (* Printf.printf "%2d : %2d :: %2d :: %f\n" left add !total r; *)
    r
  )
  |> fold_left max 0.
  |> print_float
))

let rv f p q = f q p
let fi = float_of_int
let (++),i64f,i64 = Int64.(add,to_float,of_int)
;;
Scanf.(Array.(scanf " %d %d %d" @@ fun n k m ->
  let a = init n (fun _ -> scanf " %Ld" @@ fun v -> v) in
  sort (rv compare) a;
  let total = ref 0L in
  init n (fun left ->
    let left = left + 1 in
    total := !total ++ a.(left-1);
    let add = m - (n - left) in
    let limit = left * k in
    let add = i64 @@ min limit add in
    let r =
      if add < 0L then 0.
      else (i64f (!total ++ add)) /. (fi left) in
    (* Printf.printf "%2d : %2d :: %2d :: %f\n" left add !total r; *)
    r
  )
  |> fold_left max ((i64f @@ fold_left (++) 0L a) /. (fi n))
  |> print_float
));;

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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))
let () =
  let (n,k) = read_pair () in
  let m = read_int() in
  let a = Array.init n read_int in
  let s = Array.make (n+1) 0.0 in

  Array.sort compare a;

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

  let answer = maxf 0 (min m (n-1)) (fun i ->
    let kept = s.(n) -. s.(i) in
    let j = n-i in (* number left in the set *)
    let ninc = min (m-i) (j * k) in
    (kept +. (float ninc)) /. (float (n-i))
  ) in

  printf "%f" answer


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 n0 = scan_int () in
  let n1 = scan_int () in
  let n2 = scan_int () in
  let lst =
    if (n0 = 0 && n2 = 0) then begin
      let one = 10 :: (init ((n1 - 1) / 2) (fun _x -> 10)) in
      if (n1 mod 2 = 0) then 0 :: one
      else one
    end
    else if n1 = 0 && n2 = 0 then init (n0 + 1) (fun _x -> 0)
    else if (n0 = 0 && n1 = 0) then init (n2 + 1) (fun _x -> 1)
    else begin
      let zer = init (n0+1) (fun _x -> 0) in
      let two = init (n2+1) (fun _x -> 1) in
      if n0 > 0 then
        let one = init ((n1 - 1) / 2) (fun _x -> 10) in
        if n1 mod 2 = 0 then 1 :: (zer @ (one @ two))
        else (zer @ (one @ two))
      else
        let one = init (n1 / 2) (fun _x -> 10) in
        if n1 mod 2 = 1 then 0 :: (one @ two)
        else one @ two
    end in
  List.iter (printf "%d") lst;
  print_endline ""
;;

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

(* Codeforces 1352 D Alice, Bob and Candies 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;;

(* ============= above library below custom ========== *)

let rec bs_rec i bts n0 n1 n2 =
	let ii = (i + 1) in
	if n0 > 0 then
		let _ = (Bytes.set bts i '0') in
		bs_rec ii bts (n0-1) n1 n2
	else if n1 > 0 then
		let ch = if (n1 mod 2) == 1 then '1' else '0' in
		let _ = (Bytes.set bts i ch) in
		bs_rec ii bts 0 (n1-1) n2
	else if n2 > 0 then
		let _ = (Bytes.set bts i '1') in
		bs_rec ii bts 0 0 (n2 - 1)
	else
		();;

let binary_string bts n0 n1 n2 n =
	if n0==0 && n1==0 then Bytes.fill bts 0 n '1'
	else if n1==0 && n2==0 then Bytes.fill bts 0 n '0'
	else
  	let _ = if (n1 mod 2) == 0
		  then
				begin
					Bytes.set bts 0 '1';
					Bytes.set bts 1 '0'
				end
			else
				(Bytes.set bts 0 '0') in
  	let i0,nn1 = if (n1 mod 2) == 0 then 2,(n1 - 1) else 1,n1 in
		bs_rec i0 bts n0 nn1 n2;;

let do_one () =
    let n0 = gr () in
    let n1 = gr () in
    let n2 = gr () in
		let n = n0 + n1 + n2 + 1 in
		let bts = Bytes.create n in
    let _ = binary_string bts n0 n1 n2 n in
		let bs = Bytes.to_string bts in
  	Printf.printf "%s\n" bs;;

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

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

main();;

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 n0 = scan_int () in
  let n1 = scan_int () in
  let n2 = scan_int () in
  let lst =
    if (n0 = 0 && n2 = 0) then begin
      let one = 10 :: (init ((n1 - 1) / 2) (fun _x -> 10)) in
      if (n1 mod 2 = 0) then 0 :: one
      else one
    end
    else if n1 = 0 && n2 = 0 then init (n0 + 1) (fun _x -> 0)
    else if (n0 = 0 && n1 = 0) then init (n2 + 1) (fun _x -> 1)
    else begin
      let zer = init (n0+1) (fun _x -> 0) in
      let two = init (n2+1) (fun _x -> 1) in
      if n0 > 0 then
        let one = init ((n1 - 1) / 2) (fun _x -> 10) in
        if n1 mod 2 = 0 then 1 :: (zer @ (one @ two))
        else (zer @ (one @ two))
      else
        let one = init (n1 / 2) (fun _x -> 10) in
        if n1 mod 2 = 0 then 0 :: (one @ two)
        else one @ two
    end in
  List.iter (printf "%d") lst;
  print_endline ""
;;

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


let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
    for i = 1 to n do
      let l = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let r = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let k = Scanf.bscanf sb "%d " (fun s -> s) in
      let len = r - l + 1 in
      let s2 = String.copy s in
	for j = l to r do
	  let p = ((j - l - k) mod len + len) mod len + l in
	    s.[j] <- s2.[p]
	done;
    done;
    Printf.printf "%s\n" s

open Array;;

let string_to_list s =
  let rec explode i l =
    if ( i < 0 ) then l
    else explode (i-1) (s.[i] :: l)
  in explode ( String.length s - 1) [];;

let licz x a b k =
  let y = init ( Array.length x ) (fun i -> x.(i) )
  in
    for i = a-1 to b-1 do
      set y i x.( ( ( (i-a+1-k) mod (b-a+1) ) + (b-a+1) ) mod (b-a+1) + a-1 )
    done;
    y;;

let case x =
  Scanf.bscanf Scanf.Scanning.stdin "%d %d %d\n" ( licz x );;

let x = Array.of_list ( string_to_list ( read_line() ) );;

let rec repeat x f y =
  if x > 0 then
  begin
    let z = f y in
    repeat (x-1) f z
  end
  else y;;

iter print_char ( repeat ( read_int() ) case x );;


let read_int()=Scanf.scanf "%d " (fun x->x);;
let a=read_int();;
let b=read_int();;
let c=read_int();;
let tab=Array.make 5 0;;
tab.(1)<-a;;
tab.(2)<-b;;
tab.(3)<-c;;
let d=Scanf.scanf "%d\n" (fun x->x);;
tab.(4)<-d;;
let s=Scanf.scanf "%s" (fun x->x);;
let n=String.length(s);;
let nb=ref 0;;
for i=0 to n-1 do
   nb:= !nb+tab.(int_of_char(s.[i])-48)
done;;
print_int !nb;;

(* 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_int n = printf "%d\n" n
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 arr = init 4 (fun i -> read_int()) in
  let str = read_line() in

  let len = S.length str in
  let rec run i acc =
    if i = len then acc else
    run (i+1) (acc + arr.(int_of_char str.[i] - 49))
  in
  printf "%d\n" (run 0 0)

let str_to_list s =
    let rec loop i l =
        if i < 0
        then l
        else loop (i - 1) (s.[i] :: l) in
    loop (String.length s - 1) []

let digit_to_int c =
    Pervasives.int_of_char c - Pervasives.int_of_char '0'

let input () =
    let costs = Scanf.scanf "%d %d %d %d " (fun a b c d -> [a; b; c; d]) in
    let moves = Scanf.scanf "%s" (fun s -> List.map digit_to_int (str_to_list s)) in
    (costs, moves)

let solve (costs, moves) =
    List.fold_left (+) 0 (List.map (fun n -> List.nth costs (n - 1)) moves)

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

let str_to_list s =
    let rec loop i l =
        if i < 0
        then l
        else loop (i - 1) (s.[i] :: l) in
    loop (String.length s - 1) []

let digit_to_int c =
    Pervasives.int_of_char c - Pervasives.int_of_char '0'

let input () =
    let costs = Scanf.scanf "%d %d %d %d " (fun a b c d -> [a; b; c; d]) in
    let moves = Scanf.scanf "%s" (fun s -> List.map digit_to_int (str_to_list s)) in
    (costs, moves)

let solve (costs, moves) =
    let rec loop list i total =
        match list with
        | (head :: tail) ->
            let quantity = List.length (List.filter (fun n -> n = i) moves) in
            let curr_cost = head * quantity in
            loop tail (i + 1) (total + curr_cost)
        | [] -> total
    in loop costs 1 0

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

open Printf
open Scanf

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

let () =
  let a = Array.init 4 (fun _ -> read_int()) in
  let s = read_string () in

  let n = String.length s in

  let t = ref 0 in

  for i=0 to n-1 do
    let d = (int_of_char s.[i]) - (int_of_char '1') in
    t := !t + a.(d)
  done;

  printf "%d\n" !t


open Printf
open Scanf

let ( ** ) a b = Int64.mul a b
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.stdin " %d " (fun x -> x)
let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))

let () =
  let n = read_int() in
  let a = Array.make n 0L in
  let b = Array.make n 0 in
  let c = Array.make n 0 in
  for i=0 to n-1 do
    a.(i) <- read_long ();
    b.(i) <- read_int ();
    c.(i) <- read_int ();
  done;

  let tree = Array.make n [] in

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

  let rec dfs p u mincost =
    (* return (excess_ones, excess_zeros, cost) for this subtree *)
    let rec loop li ac0 ac1 ac_cost =
      match li with
	| [] -> (ac0, ac1, ac_cost)
	| v::tail ->
	  if v = p then loop tail ac0 ac1 ac_cost else
	    let (v0, v1, v_cost) = dfs u v (min mincost a.(v)) in
	    loop tail (ac0+v0) (ac1+v1) (ac_cost ++ v_cost)
    in
    let (ac0, ac1, ac_cost) = loop tree.(u) 0 0 0L in
    let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in
    let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in
    let change = min ac0 ac1 in
    let cost = ac_cost ++ 2L ** (long change) ** mincost in
    (ac0 - change, ac1 - change, cost)
  in

  let (c0, c1, cost) = dfs (-1) 0 a.(0) in
  printf "%Ld\n" (if c0 + c1 <> 0 then -1L else cost)

open Printf
open Scanf

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b

let long x = Int64.of_int x
let short x = Int64.to_int x

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let sum i j f = fold i j (fun i a -> (f i) + a) 0
let rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))

let () =
  let n = read_int() in
  let a = Array.make n 0L in
  let b = Array.make n 0 in
  let c = Array.make n 0 in
  for i=0 to n-1 do
    a.(i) <- read_long ();
    b.(i) <- read_int ();
    c.(i) <- read_int ();
  done;

  let tree = Array.make n [] in

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

  let ones_there = sum 0 (n-1) (fun i -> b.(i)) in
  let ones_wanted = sum 0 (n-1) (fun i -> c.(i)) in
  if ones_there <> ones_wanted then (
    printf "-1\n"
  ) else (

    (*
    let ex = Array.make_matrix 2 n 0 in  (*excess 0s and 1s *)

    let rec dfs0 p u =
      let rec loop li ac0 ac1 =
	match li with
	  | [] -> (ac0, ac1)
	  | v::tail ->
	    if v = p then loop tail ac0 ac1 else
	      let (v0, v1) = dfs0 u v in
	      loop tail (ac0+v0) (ac1+v1)
      in
      let (ac0, ac1) = loop tree.(u) 0 0 in
      let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in
      let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in
(*      let change = min ac0 ac1 in
      let (ac0, ac1) = (ac0 - change, ac1 - change) in *)
      ex.(0).(u) <- ac0;
      ex.(1).(u) <- ac1;
      (ac0, ac1)
    in
    let _ = dfs (-1) 0 in
    *)

    let rec dfs p u mincost =
    (* return (excess_ones, excess_zeros, cost) for this subtree *)
      let rec loop li ac0 ac1 ac_cost =
	match li with
	  | [] -> (ac0, ac1, ac_cost)
	  | v::tail ->
	    if v = p then loop tail ac0 ac1 ac_cost else
	      let (v0, v1, v_cost) = dfs u v (min mincost a.(v)) in
	      loop tail (ac0+v0) (ac1+v1) (ac_cost ++ v_cost)
      in
      let (ac0, ac1, ac_cost) = loop tree.(u) 0 0 0L in
      let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in
      let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in
      let change = min ac0 ac1 in
      let cost = ac_cost ++ 2L ** (long change) ** mincost in
      (ac0 - change, ac1 - change, cost)
    in

    let (_, _, cost) = dfs (-1) 0 a.(0) in
    printf "%Ld\n" cost
  )