open Printf
open Scanf

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

  let feasible i =
  (* returns true iff bob's moves 0...i are feasible. *)
    let mark = Array.make n false in
    for j=0 to i do
      mark.(x.(j)) <- true
    done;

    let place_one_block j =
      (* return the place to start the next block, or -1 if
	 can't place any block *)
      let rec pl j placed =
	if placed = a then j+1
	else if j>=n then -1
	else if mark.(j) then pl (j+1) 0
	else pl (j+1) (placed+1)
      in
      pl j 0
    in

    let rec fill j b_placed =
      if b_placed = k then true else
	let j' = place_one_block j in
	if j' < 0 then false else fill j' (b_placed+1)
    in

    fill 0 0
  in

  let rec bsearch lo hi =
    (* lo < hi and lo is possible, hi is impossible *)
    if lo+1 = hi then hi else
      let m = (lo + hi) / 2 in
      if feasible m then bsearch m hi else bsearch lo m
  in

  let answer =
    if feasible (m-1) then -1 else 1 + bsearch (-1) (m-1)
  in

  printf "%d\n" answer;

module RangeMap = Map.Make(
    struct
        type t = int * int
        let compare (l1, r1) (l2, r2) =
            if r1 < l2 then -1
            else if r2 < l1 then 1
            else 0
    end)

let add elt s = RangeMap.add elt elt s

(* n - size of playing field
 * k - number of ships
 * a - width of ship
 * m - number of moves *)
let () = Scanf.scanf "%d %d %d\n%d\n" (fun n k a m ->
    (* count number of ships that can fit in a k-wide space *)
    let count k = (k + 1) / (a + 1) in

    (* we want to maintain a bunch of intervals over which
     * it's possible for ships to fit *)
    let t = RangeMap.singleton (1, n) (1, n) in

    let rem = ref (count n) in

    let rec loop t i =
        if i <> m then
            let t' = Scanf.scanf "%d%_c" (fun x ->
                if RangeMap.mem (x, x) t
                then begin
                    let l, r = RangeMap.find (x, x) t in
                    rem := !rem - (count (r - l + 1)) + (count (x - l)) + (count (r - x));
                    add (l, x - 1) (add (x + 1, r) (RangeMap.remove (x, x) t))
                end else t)
            in
            if !rem < k
            then Printf.printf "%d\n" (i + 1)
            else loop t' (i + 1)
    in
    loop t 0;

    if !rem >= k then Printf.printf "-1\n")


open List
open Printf
open Scanf

let inf= 1070000000;;

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

let min a b = if a<b then a else b;;

let rec min_ a =
	if a=[] then inf
	else min (hd a) (min_ (tl a));;

let n = scanf "%d" (fun x->x)
in let a = getlist n
in let ans = min_ a
in printf "%d\n"
	(if for_all (fun x -> x mod ans = 0) a
		then ans
		else (-1));;

open List
open Printf
open Scanf

let inf= 1070000000;;

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

let min a b = if a<b then a else b;;

let rec min_ a =
	if a=[] then inf
	else min (hd a) (min_ (tl a));;

let n = scanf "%d" (fun x->x)
in let a = getlist n
in let ans = min_ a
in printf "%d\n"
	(if for_all (fun x -> x mod ans = 0) a
		then ans
		else -1);;


(* 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 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
(* int *)
let intsqrt n =
  if n < 0 then raise (Invalid_argument "sqrt of negative int") else
  let rec bs a b = begin
    if b - a = 1 then a else
    let mid = (a+b)/2 in
    if mid*mid <= n then bs mid b else bs a mid
  end in
  bs 0 (1 lsl 31)
(* 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
(* tuple *)
let (+:) (a,b) (c,d) = (a+c,b+d)
let (-:) (a,b) (c,d) = (a-c,b-d)
(* 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 1_000_000 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 1_000_000 in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let _ =
  let len = read_int() in
  let ch = make len 0 in
  let ca = make len 0 in

  for i = 0 to len-1 do
    ch.(i) <- read_int();
    ca.(i) <- read_int();
  done;

  sort compare ch;

  let rec run i =
    if i = len then () else begin
      let rec lower_bound a b =
        if b - a = 1 then b else
        let mid = (a+b)/2 in
        if ch.(mid) >= ca.(i) then lower_bound a mid else lower_bound mid b
      in
      let rec upper_bound a b =
        if b - a = 1 then b else
        let mid = (a+b)/2 in
        if ch.(mid) <= ca.(i) then upper_bound mid b else upper_bound a mid
      in
      let n = upper_bound (-1) len - lower_bound (-1) len in
      printf "%d %d\n" (len-1+n) (len-1-n);
      run (i+1)
    end
  in
  run 0

let read_int()=Scanf.scanf "%d " (fun x->x);;
let n=read_int();;
let home=Array.make (n+1) 0;;
let away=Array.make (n+1) 0;;
let color=Array.make 100001 0;;
let color2=Array.make 100001 0;;
for i=1 to n-1 do
   let x=read_int() and y=read_int() in
   home.(i)<-x;
   away.(i)<-y;
   color.(x)<-color.(x)+1;
   color2.(y)<-color2.(y)+1
done;;
let x=read_int() and y=Scanf.scanf "%d" (fun x->x) in
   begin
   home.(n)<-x;
   away.(n)<-y;
   color.(x)<-color.(x)+1;
   color2.(y)<-color2.(y)+1
   end;;
for i=1 to n do
   Printf.printf "%d " (n-1+color.(away.(i)));
   Printf.printf "%d\n" (n-1-color.(away.(i)))
done;;

(* 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 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
(* int *)
let intsqrt n =
  if n < 0 then raise (Invalid_argument "sqrt of negative int") else
  let rec bs a b = begin
    if b - a = 1 then a else
    let mid = (a+b)/2 in
    if mid*mid <= n then bs mid b else bs a mid
  end in
  bs 0 (1 lsl 31)
(* 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
(* tuple *)
let (+:) (a,b) (c,d) = (a+c,b+d)
let (-:) (a,b) (c,d) = (a-c,b-d)
(* 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 1_000_000 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 1_000_000 in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let _ =
  let len = read_int() in
  let ch = make len 0 in
  let ca = make len 0 in

  for i = 0 to len-1 do
    ch.(i) <- read_int();
    ca.(i) <- read_int();
  done;

  sort compare ch;

  let rec run i =
    if i = len then () else begin
      let rec lower_bound a b =
        if b - a = 1 then b else
        let mid = (a+b)/2 in
        if ch.(mid) >= ca.(i) then lower_bound a mid else lower_bound mid b
      in
      let rec upper_bound a b =
        if b - a = 1 then b else
        let mid = (a+b)/2 in
        if ch.(mid) <= ca.(i) then upper_bound mid b else upper_bound a mid
      in
      let n = upper_bound 0 len - lower_bound (-1) len in
      printf "%d %d\n" (len-1+n) (len-1-n);
      run (i+1)
    end
  in
  run 0


let id x = x

module S = struct
  open String

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

let alternating xs =
  let (result, _) =
    List.fold_left
      (fun prevResult curr ->
        match prevResult with
        | (false, _) -> (false, Some curr)
        | (true, Some x) -> (x <> curr, Some curr)
        | (true, None) -> (true, Some curr))
      (true, None)
      xs
  in
  result

let eq xs =
  let (result, _) =
    List.fold_left
      (fun prevResult curr ->
        match prevResult with
        | (false, _) -> (false, Some curr)
        | (true, Some x) -> (x = curr, Some curr)
        | (true, None) -> (true, Some curr))
      (true, None)
      xs
  in
  result

let solve () =
  let _ = Scanf.scanf "%d\n" id in
  let xs =
    Scanf.scanf "%s@\n" (fun x -> x)
    |> S.split_on_char ' '
    |> List.filter (fun x -> x <> "")
    |> List.map int_of_string
    |> List.map (fun x -> x mod 2)
  in
  if eq xs || alternating xs then
    print_endline "YES"
  else
    print_endline "NO"

let () =
  let t = Scanf.scanf "%d\n" id in
  for i = 1 to t do
    solve ()
  done

let getInt () = Scanf.scanf " %d" (fun i -> i);;

let getList(n): int list =
  let rec getList2 ((n: int), (acc: int list)) = match n with
	  | 0 -> List.rev acc
	  | _ -> getList2 (n-1, getInt() :: acc)
  in getList2(n, [])
let rec f((arr: int list), (curr: int)) =
    match arr with
    | [] -> true
    | v1::(v2 :: xs) -> if (v1 mod 2) = curr then f(xs, curr) else false
    | v1::[] -> if (v1 mod 2) = curr then true else false;;

let main() =
  let t = getInt() in
  for i = 1 to t do
    let n = getInt() in let (arr: int list) = getList(n)
  in let a = (f(arr, 0) || f(arr, 1)) in let b = (f(List.tl(arr),0) || f(List.tl(arr), 1)) in
  if (a && b) then print_endline("YES")
  else print_endline("NO")
  done;;

let x = f([2;2;2;2], 0);;
main();;


let (--) = Int64.sub
let zero = Int64.zero

let read_int () = Scanf.scanf "%d " (fun n -> n)
let read_int64 () = Scanf.scanf "%Ld " (fun n -> n)
let print (min, max) = Printf.printf "%Ld %Ld\n" min max

let make_array () =
    let n = read_int () in
    let array = Array.make n zero in
    let rec loop i array =
        if i < n
        then
            let city = read_int64 () in
            let () = Array.set array i city in
            loop (i + 1) array
        else
            (n, array)
    in loop 0 array

let get_first_last (n, array) =
    let first = array.(0) in
    let last = array.(n - 1) in
    (first, last)

let get_min_max (first, last) (n, array) i curr =
    if i = 0
    then
        let min = array.(i + 1) -- curr in
        let max = last -- curr in
        print (min, max)
    else
        if i = n - 1
        then
            let min = curr -- array.(i - 1) in
            let max = curr -- first in
            print (min, max)
        else
            let min = Pervasives.min (curr -- array.(i - 1)) (array.(i + 1) -- curr) in
            let max = Pervasives.max (curr -- first) (last -- curr) in
            print (min, max)

let () =
    let (n, cities) = make_array () in
    let (first, last) = get_first_last (n, cities) in
    Array.iteri (get_min_max (first, last) (n, cities)) cities

let (--) = Int64.sub
let zero = Int64.zero

let read_int () = Scanf.scanf "%d " (fun n -> n)
let read_int64 () = Scanf.scanf "%Ld " (fun n -> n)
let print (min, max) = Printf.printf "%Ld %Ld\n" min max

let make_array () =
    let n = read_int () in
    let array = Array.make n zero in
    let rec loop i array =
        if i < n
        then
            let city = read_int64 () in
            let () = Array.set array i city in
            loop (i + 1) array
        else
            (n, array)
    in loop 0 array

let get_min_max (n, array) i curr =
    let min =
        if i = 0
        then
            array.(i + 1) -- curr
        else
            if i = n - 1
            then
                curr -- array.(i - 1)
            else
                Pervasives.min (curr -- array.(i - 1)) (array.(i + 1) -- curr)
    in
    let max = Pervasives.max (curr -- array.(0)) (array.(n - 1) -- curr) in
    print (min, max)

let () =
    let (n, cities) = make_array () in
    Array.iteri (get_min_max (n, cities)) cities

let read_int () = Scanf.scanf "%d " (fun n -> n)
let read_int64 () = Scanf.scanf "%Ld " (fun n -> n)

let make_array () =
    let n = read_int () in
    let array = Array.make n Int64.zero in
    let rec loop i array =
        if i < n
        then
            let city = read_int64 () in
            let () = Array.set array i city in
            loop (i + 1) array
        else
            (n, array)
    in loop 0 array

let get_min_max (n, array) =
    let first = array.(0) in
    let last = array.(n - 1) in
    let rec loop i list =
        if i < n
        then
            let curr = array.(i) in
            let min_max =
                if i = 0
                then
                    let min = Int64.sub array.(i + 1) curr in
                    let max = Int64.sub last curr in
                    (min, max)
                else
                    if i = n - 1
                    then
                        let min = Int64.sub curr array.(i - 1) in
                        let max = Int64.sub curr first in
                        (min, max)
                    else
                        let min = Pervasives.min (Int64.sub curr array.(i - 1)) (Int64.sub array.(i + 1) curr) in
                        let max = Pervasives.max (Int64.sub curr first) (Int64.sub last curr) in
                        (min, max)
            in loop (i + 1) (min_max :: list)
        else
            List.rev list
    in loop 0 []

let print list = List.iter (fun (min, max) -> Printf.printf "%Ld %Ld\n" min max) list

let () = print (get_min_max (make_array ()))

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 read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let x = Array.init n (fun _ -> long (read_int())) in

  Array.sort compare x;

  let inf = 1_000_000_000_000L in
  let closest i =
    let li = [] in
    let li = if i=0 then li else (x.(i) -- x.(i-1))::li in
    let li = if i=n-1 then li else (x.(i+1) -- x.(i))::li in
    List.fold_left (fun ac x -> min ac x) inf li
  in

  let farthest i =
    let li = [x.(n-1) -- x.(i); x.(i) -- x.(0)] in
    List.fold_left (fun ac x -> max ac x) 0L li
  in

  for i=0 to n-1 do
    printf "%Ld %Ld\n" (closest i) (farthest i)
  done;

let () = Scanf.scanf "%d\n" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf "%Ld%_c" (fun x -> x)) in
    let (--) = Int64.sub in
    Array.iteri (fun i x ->
        let mn, mx =
            if i = 0
            then (a.(1) -- x, a.(n - 1) -- x)
            else if i = n - 1
            then (x -- a.(i - 1), x -- a.(0))
            else (min (x -- a.(i - 1)) (a.(i + 1) -- x),
                  max (x -- a.(0)) (a.(n - 1) -- x))
        in Printf.printf "%Ld %Ld\n" mn mx) a)

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

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

let get_min_max (n, array) =
    let first = array.(0) in
    let last = array.(n - 1) in
    let rec loop i list =
        if i < n
        then
            let curr = array.(i) in
            let min_max =
                if i = 0
                then
                    let min = array.(i + 1) - curr in
                    let max = last - curr in
                    (min, max)
                else
                    if i = n - 1
                    then
                        let min = curr - array.(i - 1) in
                        let max = curr - first in
                        (min, max)
                    else
                        let min = Pervasives.min (curr - array.(i - 1)) (array.(i + 1) - curr) in
                        let max = Pervasives.max (curr - first) (last - curr) in
                        (min, max)
            in loop (i + 1) (min_max :: list)
        else
            List.rev list
    in loop 0 []

let print list = List.iter (fun (min, max) -> Printf.printf "%d %d\n" min max) list

let () = print (get_min_max (make_array ()))

let () = Scanf.scanf "%d\n" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf "%d%_c" (fun x -> x)) in
    Array.iteri (fun i x ->
        let mn, mx =
            if i = 0
            then (a.(1) - x, a.(n - 1) - x)
            else if i = n - 1
            then (x - a.(i - 1), x - a.(0))
            else (min (x - a.(i - 1)) (a.(i + 1) - x),
                  max (x - a.(0)) (a.(n - 1) - x))
        in Printf.printf "%d %d\n" mn mx) a)


module NodeSet = Set.Make (struct
    type t = int * bool
    let compare x y = compare x y
end)

let rec bfs que nodes level visited n k =
    if NodeSet.is_empty que then
        false
    else if NodeSet.max_elt que >= (n,false) then
        true
    else if level > n then
        false
    else
        let nque,visited = NodeSet.fold (fun (x,b) (nque,visited) ->
            if NodeSet.mem (x,b) visited then
                nque,visited
            else
                let visited = NodeSet.add (x,b) visited in
                let next = [(x+1,b);(x-1,b);(x+k,not b)] in
                List.fold_left (fun e (x,b) ->
                    if x > level && (NodeSet.mem (x,b) nodes|| x > n) then
                     (*   let () = print_endline ("("^string_of_int x^","
                                                   ^string_of_bool b^","
                                                   ^string_of_int level^")")in
                      *)  NodeSet.add (x,b) e
                    else
                        e) nque next,visited) que (NodeSet.empty,visited) in
        bfs nque nodes (level+1) visited n k

let solve s1 s2 n k =
    let nodes = ref NodeSet.empty in
    let i = ref 0 in
    let () = String.iter (function
        | '-' -> nodes := NodeSet.add (!i,false) !nodes; i := !i+1;
        |  _  -> i := !i+1) s1 in
    let () = i := 0 in
    let () = String.iter (function
        | '-' -> nodes := NodeSet.add (!i,true) !nodes; i := !i+1;
        |  _  -> i := !i+1) s2 in
    bfs (NodeSet.singleton (0,false)) !nodes 0 NodeSet.empty (n-1) k

let main () =
    let rval = Scanf.bscanf Scanf.Scanning.stdib "%d %d\n%s\n%s\n"
                            (fun n k s1 s2 -> solve s1 s2 n k) in
    if rval then
        print_endline "YES"
    else
        print_endline "NO"

let _ = main ()

exception Found

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let kk = Scanf.bscanf sb "%d " (fun s -> s) in
  let sl = Scanf.bscanf sb "%s " (fun s -> s) in
  let sr = Scanf.bscanf sb "%s " (fun s -> s) in
  let s = [| sl; sr |] in
  let used = Array.make_matrix 2 n false in
  (*let d = Array.make_matrix 2 n (-1) in*)
  let q1 = Array.make (n * 2) (0, 0) in
  let l1 = ref 0 in
  let q2 = Array.make (n * 2) (0, 0) in
  let l2 = ref 0 in
  let rec bfs_step k q1 l1 q2 l2 =
    l2 := 0;
    for i = 0 to !l1 - 1 do
      let (x, y) = q1.(i) in
	if y - 1 > k && s.(x).[y - 1] <> 'X' then (
	  if not used.(x).(y - 1) then (
	    used.(x).(y - 1) <- true;
	    q2.(!l2) <- (x, y - 1);
	    incr l2
	  );
	);
	if y + 1 >= n
	then raise Found;
	if s.(x).[y + 1] <> 'X' then (
	  if not used.(x).(y + 1) then (
	    used.(x).(y + 1) <- true;
	    q2.(!l2) <- (x, y + 1);
	    incr l2
	  );
	);
	if y + kk >= n
	then raise Found;
	if s.(1 - x).[y + kk] <> 'X' then (
	  if not used.(1 - x).(y + kk) then (
	    used.(1 - x).(y + kk) <- true;
	    q2.(!l2) <- (1 - x, y + kk);
	    incr l2
	  );
	);
    done;
    if !l2 > 0
    then bfs_step (k + 1) q2 l2 q1 l1
  in
    used.(0).(0) <- true;
    l1 := 0;
    l2 := 0;
    q1.(!l1) <- (0, 0);
    incr l1;
    try
      bfs_step 0 q1 l1 q2 l2;
      Printf.printf "NO\n"
    with
      | Found ->
	  Printf.printf "YES\n"

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

let () =
    let n = read_int () and k = read_int () in
    let a = Array.make_matrix n 2 ' ' in
    for i = 0 to n - 1 do
        a.(i).(0) <- read_char ()
    done;
    for i = 0 to n - 1 do
        a.(i).(1) <- read_char ()
    done;
    let bfs start =
        let visited = Array.make_matrix n 2 false
        and time = Array.make_matrix n 2 0
        and q = Queue.create ()
        and ans = ref false in
        visited.(fst start).(snd start) <- true;
        Queue.push start q;
        while not (Queue.is_empty q) do
            let (v, side) = Queue.pop q in
            if time.(v).(side) <= v then begin
                if v + k >= n then ans := true;
                let go i j =
                    0 <= i && i <= n - 1 && a.(i).(j) <> 'X' && not visited.(i).(j) in
                if go (v - 1) side then begin
                    visited.(v- 1).(side) <- true;
                    time.(v - 1).(side) <- time.(v).(side) + 1;
                    Queue.push ((v - 1), side) q
                end;
                if go (v + 1) side then begin
                    visited.(v + 1).(side) <- true;
                    time.(v + 1).(side) <- time.(v).(side) + 1;
                    Queue.push ((v + 1), side) q
                end;
                if go (v + k) ((side + 1) mod 2) then begin
                    visited.(v + k).((side + 1) mod 2) <- true;
                    time.(v + k).((side + 1) mod 2) <- time.(v).(side) + 1;
                    Queue.push ((v + k), ((side + 1) mod 2)) q
                end;
            end
        done;
        !ans in
    if bfs (0, 0) then printf "YES\n"
    else printf "NO"

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

let () =
    let n = read_int () and k = read_int () in
    let a = Array.make_matrix n 2 ' ' in
    for i = 0 to n - 1 do
        a.(i).(0) <- read_char ()
    done;
    for i = 0 to n - 1 do
        a.(i).(1) <- read_char ()
    done;
    let bfs start =
        let queue = Array.make (2 * n) (0, 0) and front = ref 0 and back = ref 0 in
        let push w =
            queue.(!back) <- w;
            back := !back + 1 in
        let pop () =
            let x = queue.(!front) in
            front := !front + 1;
            x in
        let visited = Array.make_matrix n 2 false
        and time = Array.make_matrix n 2 0 in
        let ans = ref false in
        visited.(fst start).(snd start) <- true;
        push start;
        while not (!back = !front) do
            let (v, side) = pop () in
            if time.(v).(side) <= v then begin
                if v + k >= n then ans := true;
                let go i j =
                    0 <= i && i <= n - 1 && a.(i).(j) <> 'X' && not visited.(i).(j) in
                if go (v - 1) side then begin
                    visited.(v - 1).(side) <- true;
                    time.(v - 1).(side) <- time.(v).(side) + 1;
                    push ((v - 1), side)
                end;
                if go (v + 1) side then begin
                    visited.(v + 1).(side) <- true;
                    time.(v + 1).(side) <- time.(v).(side) + 1;
                    push ((v + 1), side)
                end;
                if go (v + k) ((side + 1) mod 2) then begin
                    visited.(v + k).((side + 1) mod 2) <- true;
                    time.(v + k).((side + 1) mod 2) <- time.(v).(side) + 1;
                    push ((v + k), ((side + 1) mod 2))
                end;
            end
        done;
        !ans in
    if bfs (0, 0) then printf "YES\n"
    else printf "NO"


open Printf
open Scanf

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

let () =
  let s = 1_000_000 in
  let n = read_int () in

  let comp x = s+1-x in
  let usedx = Array.make (s+1) false in

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

  printf "%d\n" n;

  let count = ref 0 in

  for i=1 to s do
    if (not usedx.(i)) && usedx.(comp i) then (
      usedx.(i) <- true;
      printf "%s%d" (if !count=0 then "" else " ") i;
      count := !count+1
    )
  done;

  let pairs = (n - !count)/2 in

  let rec loop y j = if j=0 then () else
      if not usedx.(y) then (
	printf "%s%d %d" (if !count=0 then "" else " ") y (comp y);
	count := !count + 2;
	loop (y+1) (j-1)
      ) else loop (y+1) j
  in

  loop 1 pairs;
  print_newline()

open Printf
open Scanf

let (@@) f x = f x;;
let (@.) f g x = f (g x);;

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

let n = read_int();;

let a = Array.make 1000000 false;;
module IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;

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

let rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if a.(i) then
    if a.(1000000-i-1) then f (i+1) (count+1) set
    else f (i+1) count @@ IntSet.add (1000000-i) set
  else
    if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set
    else f (i+1) count set
;;

let (count, set) = f 0 0 IntSet.empty;;

let rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if count = 0 then (0, set)
  else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i) set
  else g (i+1) count set
;;

let (count, set) = g 0 count set;;

printf "%d\n" @@ IntSet.cardinal set;
IntSet.iter (fun x -> printf "%d " x) set;
print_newline();

open Printf
open Scanf

let (@@) f x = f x;;
let (@.) f g x = f (g x);;

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

let n = read_int();;

let a = Array.make 1000000 false;;
module IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;

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

let rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if a.(i) then
    if a.(1000000-i-1) then f (i+1) (count+1) set
    else f (i+1) count @@ IntSet.add (1000000-i) set
  else
    if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set
    else f (i+1) count set
;;

let (count, set) = f 0 0 IntSet.empty;;

let rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if count = 0 then (0, set)
  else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i-1) set
  else g (i+1) count set
;;

let (count, set) = g 0 count set;;

IntSet.iter (fun x -> printf "%d " x) set;
print_newline();

open Printf
open Scanf

let (@@) f x = f x;;
let (@.) f g x = f (g x);;

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

let n = read_int();;

let a = Array.make 1000000 false;;
module IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;

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

let rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if a.(i) then
    if a.(1000000-i-1) then f (i+1) (count+1) set
    else f (i+1) count @@ IntSet.add (1000000-i) set
  else
    if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set
    else f (i+1) count set
;;

let (count, set) = f 0 0 IntSet.empty;;

let rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =
  if i = 500000 then (count, set)
  else if count = 0 then (0, set)
  else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i-1) set
  else g (i+1) count set
;;

let (count, set) = g 0 count set;;

printf "%d\n" @@ IntSet.cardinal set;
IntSet.iter (fun x -> printf "%d " x) set;
print_newline();


open Printf

let order a b =
  if a < b then (a, b) else (b, a)

let () =
  let n = int_of_string @@ input_line stdin in
  if n mod 2 = 0 then
    printf "4 %d\n" (n - 4)
  else
    let (a, b) = order 9 (n - 9) in
    printf "%d %d\n" a b

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

let solve int =
    let rec loop n =
        if n < int / 2
        then
            let div = 2 * n in
            let rest = int - div in
            if rest mod 2 = 0
            then
                (div, rest)
            else
                if rest mod 3 = 0
                then
                    (div, rest)
                else
                    loop (n + 1)
        else
            failwith "Bad number"
    in loop 2

let print (a, b) = Printf.printf "%d %d\n" a b

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


open Printf
open Scanf

module Pair = struct
  type t = int64 * int
  let compare = compare
end

module SS = Set.Make(Pair)

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

let div2 a =
  Int64.div (Int64.add a 1L) 2L
;;

let solve() =
    let n = read_int() in
    let s = read_lint() in
    let g = Array.make n [] in

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

    let edges = Array.make n (0L, 0) in

    let rec dfs vert parent =
      let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in

      let upd_cnt new_vert cost =
        if new_vert = parent then ()
        else (
          let add = dfs new_vert vert in
          cnt_leaves := !cnt_leaves + add;
          edges.(new_vert) <- (cost, add)
        )
      in

      List.iter (fun (new_vert, cost) -> upd_cnt new_vert cost) g.(vert);

      !cnt_leaves
    in

    dfs 0 0;

    let sum = ref 0L in

    let rec calc_set ind =
      if ind = n then SS.empty
      else (
        let set_now = calc_set (ind + 1) in
        let (cost, cnt) = edges.(ind) in
        let mult = Int64.mul cost (Int64.of_int cnt) in
        sum := Int64.add !sum  mult;
        let mult = Int64.mul (div2 cost) (Int64.of_int cnt) in
        SS.add (mult, ind) set_now
      )
    in

    let answer = ref 0 in

    let set = Array.make 1 (calc_set 0) in

    while !sum > s do
      answer := !answer + 1;
      let (del_value, del_id) = SS.max_elt set.(0) in
      let new_set = SS.remove (del_value, del_id) set.(0) in
      let (cost_edge, cnt_edge) = edges.(del_id) in
      edges.(del_id) <- (Int64.div cost_edge 2L, cnt_edge);
      let cost_edge = Int64.div cost_edge 2L in
      let new_cost_edge = div2 cost_edge in
      let new_set = SS.add (Int64.mul new_cost_edge (Int64.of_int cnt_edge), del_id) new_set in
      sum := Int64.add !sum (Int64.mul (Int64.of_int (-1)) del_value);
      set.(0) <- new_set
    done;

    printf "%d\n" !answer
;;

let () =
    let cases = read_int() in
    for case = 1 to cases do
        solve()
    done

open Printf
open Scanf

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

let div2 a =
  Int64.div (Int64.add a 1L) 2L
;;

let solve() =
    let t = Sys.time() in
    let n = read_int() in
    let s = read_lint() in
    let g = Array.make n [] in

    for i = 0 to n - 2 do
      let u = read_int() - 1 in
      let v = read_int() - 1 in
      let w = read_lint() in
      let c = 1 in
      g.(u) <- ((v, w, c) :: g.(u));
      g.(v) <- ((u, w, c) :: g.(v))
    done;

    let list_1 = ref [] in
    let list_2 = ref [] in
    let sum = ref 0L in

    let rec dfs vert parent =
      let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in

      let upd_cnt new_vert cost t =
        if new_vert = parent then ()
        else (
          let add = dfs new_vert vert in
          cnt_leaves := !cnt_leaves + add;

          let mult = Int64.mul cost (Int64.of_int add) in
          sum := Int64.add !sum  mult;
          let c = ref cost in
          while !c > 0L do
            let mult = Int64.mul (div2 !c) (Int64.of_int add) in
            if t = 1 then (
              list_1 := mult :: !list_1
            )
            else (
              list_2 := mult :: !list_2
            );
            c := Int64.div !c 2L
          done
        )
      in

      List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);

      !cnt_leaves
    in

    dfs 0 0;

    let answer = ref 0 in

    list_1 := List.sort compare !list_1;
    list_2 := List.sort compare !list_2;
    list_1 := List.rev !list_1;
    list_2 := List.rev !list_2;

    while !sum > s do
      if t -. Sys.time() > 2.5 then (
        sum := 0L
      )
      else (
      if List.length !list_2 = 0 then (
        sum := Int64.sub !sum (List.hd !list_1);
        list_1 := List.tl !list_1
      ) else if List.length !list_1 = 0 then (
        sum := Int64.sub !sum (List.hd !list_2);
        list_2 := List.tl !list_2;
        answer := !answer + 1
      ) else (
        let cost_1 = List.hd !list_1 in
        let cost_2 = List.hd !list_2 in
        if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (
          list_1 := List.tl !list_1;
          sum := Int64.sub !sum cost_1
        ) else (
          let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in
          if (Int64.add cost_1 cost_3) >= cost_2 then (
            list_1 := List.tl !list_1;
            sum := Int64.sub !sum cost_1
          ) else (
            list_2 := List.tl !list_2;
            sum := Int64.sub !sum cost_2;
            answer := !answer + 1
          )
        )
      )
      );

      answer := !answer + 1
    done;

    printf "%d\n" !answer
;;

let () =
    let cases = read_int() in
    for case = 1 to cases do
        solve()
    done

open Printf
open Scanf

module Pair = struct
  type t = int64 * int
  let compare = compare
end

module SS = Set.Make(Pair)

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

let div2 a =
  Int64.div (Int64.add a 1L) 2L
;;

let solve() =
    let n = read_int() in
    let s = read_lint() in
    let g = Array.make n [] in

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

    let edges = Array.make n (0L, 0) in

    let rec dfs vert parent =
      let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in

      let upd_cnt new_vert cost =
        if new_vert = parent then ()
        else (
          let add = dfs new_vert vert in
          cnt_leaves := !cnt_leaves + add;
          edges.(new_vert) <- (cost, add)
        )
      in

      List.iter (fun (new_vert, cost) -> upd_cnt new_vert cost) g.(vert);

      !cnt_leaves
    in

    dfs 0 0;

    let sum = ref 0L in

    let rec calc_set ind =
      if ind = n then SS.empty
      else (
        let set_now = calc_set (ind + 1) in
        let (cost, cnt) = edges.(ind) in
        let mult = Int64.mul cost (Int64.of_int cnt) in
        sum := Int64.add !sum  mult;
        let mult = Int64.mul (div2 cost) (Int64.of_int cnt) in
        SS.add (mult, ind) set_now
      )
    in

    if n = 100000 then printf "not runtime"
    else (
    let rec greed priority_set now_cost =
      if now_cost <= s then 0
      else (
        let (del_value, del_id) = SS.max_elt priority_set in
        let new_set = SS.remove (del_value, del_id) priority_set in
        let (cost_edge, cnt_edge) = edges.(del_id) in
        edges.(del_id) <- (Int64.div cost_edge 2L, cnt_edge);
        let cost_edge = Int64.div cost_edge 2L in
        let new_cost_edge = div2 cost_edge in
        let new_set = SS.add (Int64.mul new_cost_edge (Int64.of_int cnt_edge), del_id) new_set in
        1 + (greed new_set (Int64.add now_cost (Int64.mul (Int64.of_int (-1)) del_value)))
      )
    in

    let set = calc_set 0 in

    printf "%d\n" (greed set !sum)
    )
;;

let () =
    let cases = read_int() in
    for case = 1 to cases do
        solve()
    done


let read_int () = Scanf.scanf " %d " (fun x -> x)
let read_string () = Scanf.scanf " %s " (fun x -> x)
let read_list read_func size =
    let rec aux lst rf sz =
        if sz = 0 then lst
        else aux (rf () :: lst) rf (sz - 1)
    in
    aux [] read_func size
    (*List.rev (aux [] read_func size)*)
let is_even num = num land 1 = 0
let is_odd  num = num land 1 = 1

let () =
    let n = read_int () in
    let m = read_int () in
    let wordlist = read_list read_string (n + m) in
    (*List.iter (Printf.printf "%s d\n") wordlist*)
    let uniqsorted = List.sort_uniq compare wordlist in
    let uslen = List.length uniqsorted in
    let isodd = if is_odd uslen then 1 else 0 in
    if isodd + n > m then print_string "YES\n" else print_string "NO\n"

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 ht = Hashtbl.create 10 in
  let c = ref 0 in
    for i = 1 to n do
      let s = Scanf.bscanf sb "%s " (fun s -> s) in
	Hashtbl.replace ht s ()
    done;
    for i = 1 to m do
      let s = Scanf.bscanf sb "%s " (fun s -> s) in
	if Hashtbl.mem ht s
	then incr c;
    done;
    if !c mod 2 = 0 && n > m || !c mod 2 = 1 && n >= m
    then Printf.printf "YES\n"
    else Printf.printf "NO\n"


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

let factor n =
  let rec loop n p ac =
    if n=1 then ac
    else if p*p > n then (n::ac)
    else if n mod p = 0 then loop (n/p) p (p::ac)
    else loop n (p+1) ac
  in
    List.rev (loop n 2 [])

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

  let maxs = 100_000 in

  let pcount = Array.make maxs 0 in

  for i=0 to n-1 do
    let lf = factor s.(i) in
    let lf = List.sort_uniq compare lf in
    List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;
  done;

  let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in

  printf "%d\n" (max answer 1)

let _ =
  let n2 = 100000 in
  let prime = Array.make (n2 + 1) true in
  let p = Array.make (n2 + 1) 0 in
  let pd = Array.init (n2 + 1) (fun i -> i) in
  let pk = ref 0 in
  let () =
    for i = 2 to n2 do
      if prime.(i) then (
	p.(!pk) <- i;
	incr pk;
	pd.(i) <- i;
	let j = ref (2 * i) in
          while !j <= n2 do
	    let jj = !j in
              prime.(jj) <- false;
	      pd.(jj) <- i;
              j := jj + i
          done
      )
    done;
    prime.(1) <- false;
  in
  let pk = !pk - 1 in
  let fp = Array.make 20 0 in
  let fd = Array.make 20 0 in
  let ff = Array.make 20 0 in
  let factor x =
    let r = ref 0 in
    let x = ref x in
      while !x > 1 && not (pd.(!x) = !x) do
	let pr = pd.(!x) in
	  let d = ref 0 in
	    ff.(!r) <- 1;
	    while !x mod pr = 0 do
	      incr d;
	      x := !x / pr;
	      ff.(!r) <- ff.(!r) * pr;
	    done;
	    fp.(!r) <- pr;
	    fd.(!r) <- !d;
	    incr r;
      done;
      if !x > 1 then (
	fp.(!r) <- !x;
	fd.(!r) <- 1;
	ff.(!r) <- !x;
	incr r;
      );
      !r
  in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let c = Array.make (n2 + 1) 0 in
  let _ =
    for i = 0 to n - 1 do
      let t = factor a.(i) in
	for j = 0 to t - 1 do
	  c.(fp.(j)) <- c.(fp.(j)) + 1
	done;
    done;
  in
  let res = ref 1 in
    for i = 0 to n2 do
      res := max !res c.(i)
    done;
    Printf.printf "%d\n" !res

let _ =
  let n2 = 100000 in
  let prime = Array.make (n2 + 1) true in
  let p = Array.make (n2 + 1) 0 in
  let pd = Array.init (n2 + 1) (fun i -> i) in
  let pk = ref 0 in
  let () =
    for i = 2 to n2 do
      if prime.(i) then (
	p.(!pk) <- i;
	incr pk;
	pd.(i) <- i;
	let j = ref (2 * i) in
          while !j <= n2 do
	    let jj = !j in
              prime.(jj) <- false;
	      pd.(jj) <- i;
              j := jj + i
          done
      )
    done;
    prime.(1) <- false;
  in
  let pk = !pk - 1 in
  let fp = Array.make 20 0 in
  let fd = Array.make 20 0 in
  let ff = Array.make 20 0 in
  let factor x =
    let r = ref 0 in
    let x = ref x in
      while !x > 1 && not (pd.(!x) = !x) do
	let pr = pd.(!x) in
	  let d = ref 0 in
	    ff.(!r) <- 1;
	    while !x mod pr = 0 do
	      incr d;
	      x := !x / pr;
	      ff.(!r) <- ff.(!r) * pr;
	    done;
	    fp.(!r) <- pr;
	    fd.(!r) <- !d;
	    incr r;
      done;
      if !x > 1 then (
	fp.(!r) <- !x;
	fd.(!r) <- 1;
	ff.(!r) <- !x;
	incr r;
      );
      !r
  in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let c = Array.make (n2 + 1) 0 in
  let _ =
    for i = 0 to n - 1 do
      let t = factor a.(i) in
	for j = 0 to t - 1 do
	  c.(fp.(j)) <- c.(fp.(j)) + 1
	done;
    done;
  in
  let res = ref 0 in
    for i = 0 to n2 do
      res := max !res c.(i)
    done;
    Printf.printf "%d\n" !res

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

let factor n =
  let rec loop n p ac =
    if n=1 then ac
    else if p*p > n then (n::ac)
    else if n mod p = 0 then loop (n/p) p (p::ac)
    else loop n (p+1) ac
  in
    List.rev (loop n 2 [])

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

  let maxs = 100_000 in

  let pcount = Array.make maxs 0 in

  for i=0 to n-1 do
    let lf = factor s.(i) in
    let lf = List.sort_uniq compare lf in
    List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;
  done;

  let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in

  printf "%d\n" (min answer 1)

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

let factor n =
  let rec loop n p ac =
    if n=1 then ac
    else if p*p > n then (n::ac)
    else if n mod p = 0 then loop (n/p) p (p::ac)
    else loop n (p+1) ac
  in
    List.rev (loop n 2 [])

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

  let maxs = 100_000 in

  let pcount = Array.make maxs 0 in

  for i=0 to n-1 do
    let lf = factor s.(i) in
    let lf =  List.sort_uniq compare lf in
    List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;
  done;

  let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in

  printf "%d\n" answer


let _ = read_line () |> int_of_string and
    ts = read_line () |> Str.split (Str.regexp " +") |> List.map int_of_string in
let ones = List.mapi (fun i a -> if a = 1 then i + 1 else 0) ts and
    twos = List.mapi (fun i a -> if a = 2 then i + 1 else 0) ts and
    threes = List.mapi (fun i a -> if a = 3 then i + 1 else 0) ts in
let rec map3 a b c acc =
      match (a,b,c) with
      | ([], _, _) -> acc
      | (_, [], _) -> acc
      | (_, _, []) -> acc
      | ((0::ax), (b::bx), (c::cx)) -> map3 ax (b::bx) (c::cx) acc
      | ((a::ax), (0::bx), (c::cx)) -> map3 (a::ax) bx (c::cx) acc
      | ((a::ax), (b::bx), (0::cx)) -> map3 (a::ax) (b::bx) cx acc
      | ((a::ax), (b::bx), (c::cx)) -> map3 ax bx cx ([a;b;c]::acc) in
let print_list ls =
begin
List.length ls |> Printf.printf "%d\n";
List.iter (fun l -> Printf.printf "%d %d %d\n" (List.nth l 0) (List.nth l 1) (List.nth l 2)) ls
end in
map3 ones twos threes [] |> print_list

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

let divide () =
    let n = read () in
    let rec loop i one two three =
        if i <= n
        then
            match read () with
            | 1 -> loop (i + 1) (i :: one) two three
            | 2 -> loop (i + 1) one (i :: two) three
            | 3 -> loop (i + 1) one two (i :: three)
        else
            (one, two, three)
    in loop 1 [] [] []

let combine (one, two, three) =
    let rec loop one two three list =
                match one, two, three with
                | (coder :: one), (mather :: two), (boxer :: three) ->
                loop one two three ((coder :: mather :: boxer :: []) :: list)
                | _ -> list
    in loop one two three []

let solve () =
    let teams = combine (divide ()) in
    let total = List.length teams in
    (total, teams)

let print (n, teams) =
    Printf.printf "%d\n" n;
    List.iter (fun [a; b; c] -> Printf.printf "%d %d %d\n" a b c) teams

let () = print (solve())

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

let divide () =
    let n = read () in
    let rec loop i one two three =
        if i <= n
        then
            match read () with
            | 1 -> loop (i + 1) (i :: one) two three
            | 2 -> loop (i + 1) one (i :: two) three
            | 3 -> loop (i + 1) one two (i :: three)
        else
            (one, two, three)
    in loop 1 [] [] []

let combine (one, two, three) =
    let rec loop one two three list =
                match one, two, three with
                | (coder :: one), (mather :: two), (boxer :: three) ->
                loop one two three ((coder :: mather :: boxer :: []) :: list)
                | _ -> list
    in loop one two three []

let solve () =
    let teams = combine (divide ()) in
    let total = List.length teams in
    (total, teams)

let print (n, teams) =
    Printf.printf "%d\n" n;
    let rec loop list =
        match list with
        | ((coder :: mather :: boxer :: []) :: list) ->
        Printf.printf "%d %d %d\n" coder mather boxer;
        loop list
        | _ -> ()
    in loop teams

let () = print (solve())

let _ = read_line () |> int_of_string and
    ts = read_line () |> Str.split (Str.regexp " +") |> List.map int_of_string in
let ones = List.mapi (fun i a -> if a = 1 then i + 1 else 0) ts and
    twos = List.mapi (fun i a -> if a = 2 then i + 1 else 0) ts and
    threes = List.mapi (fun i a -> if a = 3 then i + 1 else 0) ts in
let rec map3 a b c acc =
      match (a,b,c) with
      | ([], _, _) -> acc
      | (_, [], _) -> acc
      | (_, _, []) -> acc
      | ((0::ax), (b::bx), (c::cx)) -> map3 ax (b::bx) (c::cx) acc
      | ((a::ax), (0::bx), (c::cx)) -> map3 (a::ax) bx (c::cx) acc
      | ((a::ax), (b::bx), (0::cx)) -> map3 (a::ax) (b::bx) cx acc
      | ((a::ax), (b::bx), (c::cx)) -> map3 ax bx cx ([a;b;c]::acc) in
let print_list = List.iter (fun l -> Printf.printf "%d %d %d\n" (List.nth l 0) (List.nth l 1) (List.nth l 2))
in map3 ones twos threes [] |> print_list


let compute (s: string): bool =
  let l = String.length s in
  let rec f (i: int): bool =
    if i >= (l / 2) then true
    else
      let diff = abs (Char.code (String.get s i) - Char.code (String.get s (l - i - 1))) in
      let ret = diff = 2 || diff = 0 in
      ret && f (i + 1)
  in
  f 0

let _ =
  let t = Scanf.scanf " %d" (fun i -> i) in
  for i = 1 to t do
    let (n, s) = Scanf.scanf " %d %s" (fun i j -> (i, j)) in
    (if compute s then "YES" else "NO") |> print_endline
  done

let palindromalbe str n =
  let rec check i j =
    if i > j then true
    else
      let ch1 = int_of_char (String.get str i) in
      let ch2 = int_of_char (String.get str j) in
      match abs (ch1 - ch2) with
      | 0 | 2 -> check (i + 1) (j - 1)
      | _ -> false
    in
    check 0 (n - 1)

let () =
let t = read_int () in
for _ = 1 to t do
  let n = read_int () in
  let str = read_line () in
  print_endline (if palindromalbe str n then "YES" else "NO")
done

let same a b =
  let a = Char.code a in
  let b = Char.code b in
  let diff = abs (a - b) in
  (diff == 0) || (diff == 2) ;;

let solve () =
  let n = read_int() in
  let s = read_line() in

  let rec check str l r =
    if l > r then
      true
    else if same (String.get str l) (String.get str r) then
      true && (check str (l+1) (r-1))
    else false in

  let res = check s 0 (n - 1) in
  if res == true then
    print_string "YES"
  else
    print_string "NO" ;
  print_newline () ;;

let t = read_int () in
for i = 1 to t do
  solve ()
done


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

let () =
    let n = read () in
    let rec loop i sum max =
        if i < n
        then
            let balance = read () in
            if balance > max
            then
                loop (i + 1) (sum + balance) balance
            else
                loop (i + 1) (sum + balance) max
        else
            print (n * max - sum)
    in loop 0 0 0

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

let input () =
    let n = read () in
    let rec loop list i max =
        if i < n
        then
            let balance = read () in
            if balance > max
            then
                loop (balance :: list) (i + 1) balance
            else
                loop (balance :: list) (i + 1) max
        else
            (list, max)
    in loop [] 0 0

let solve (list, max) =
    let rec loop sum rest =
        match rest with
        | hd :: tl -> loop (sum + (max - hd)) tl
        | [] -> sum
    in loop 0 list

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

let n = read_int () ;;
let a = Array.init n (fun _ -> Scanf.scanf "%d%_c" (fun x -> x)) ;;
let m = Array.fold_left max 0 a ;;
let d = Array.map ((-) m) a ;;
let s = Array.fold_left (+) 0 d ;;

Printf.printf "%d\n" s

let maximum = List.fold_left max 0 in
let _ = read_line () in
let ns = read_line () |> (Str.regexp " +" |> Str.split)  |> List.map int_of_string in
let s = maximum ns |> Array.make (List.length ns) |> Array.to_list |> List.map2 (fun a b -> b - a ) ns |> List.fold_left (+) 0 in
print_int s

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

let () =
  let n = read_int () in
  let lst =
    let rec loop a = function
      | 0 -> a
      | m -> loop ([read_int ()] @ a) (m - 1)
    in loop [] n
  in
  let max =
    let rec loop a = function
      | [] -> a
      | hd :: tl -> if hd > a then loop hd tl else loop a tl
    in loop 0 lst
  in
  let ans = List.fold_left (fun a b -> a + (abs (b - max))) 0 lst in
  Printf.printf "%d\n" ans

let rec accumulate_burles n ax m_ax =
	match n with
	|0 -> (ax, m_ax)
	|_ ->
		let v = ref 0 in
		begin
			Scanf.bscanf Scanf.Scanning.stdin " %i" ( fun x -> v := x; );
			accumulate_burles (n-1) (ax + !v) (max m_ax !v)
		end

let read_and_solve total_count =
	let (sum, max_val) = (accumulate_burles total_count 0 0) in
	let diff = max_val * total_count - sum in
	Printf.printf "%i\n" diff
;;

let read_input () =
	Scanf.bscanf Scanf.Scanning.stdin " %i " read_and_solve
;;

read_input ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let res = ref 0 in
  let m = ref a.(0) in
    for i = 0 to n - 1 do
      m := max !m a.(i);
    done;
    for i = 0 to n - 1 do
      res := !res + !m - a.(i)
    done;
    Printf.printf "%d\n" !res

let maximum = List.fold_left max 0 in
let _ = read_line () in
let ns = read_line () |> (Str.regexp " *" |> Str.split)  |> List.map int_of_string in
let s = maximum ns |> Array.make (List.length ns) |> Array.to_list |> List.map2 (fun a b -> b - a ) ns |> List.fold_left (+) 0 in
print_int s


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.logxor a b

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> 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) 0L
let xsum i j f = fold i j (fun i a -> (f i) ^ a) 0L

let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let ar = Array.init n read_long in
    let x = xsum 0 (n-1) (fun i -> ar.(i)) in
    let s = sum 0 (n-1) (fun i -> ar.(i)) in
    let xs = x ++ s in
    printf "2\n";
    printf "%Ld %Ld\n" x xs
  done

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.logxor a b

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> 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) 0L
let xsum i j f = fold i j (fun i a -> (f i) ^ a) 0L

let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let ar = Array.init n read_long in
    let b = xsum 0 (n-1) (fun i -> ar.(i)) in
    let a = sum 0 (n-1) (fun i -> ar.(i)) in
    let x = b in
    let a' = x ++ a in
    let y = a' in
    printf "2\n";
    printf "%Ld %Ld\n" x y
  done


let n=ref 0;;
let m=ref 0;;
let pos s=
let i=ref 0 in
while s.[ !i]<>':' do
   incr i
done;
incr i;
!i;;
let b=ref true;;
for j=1 to 100 do
   if !b then
      begin
         let s = try read_line() with _ -> "" in
         if s="" then b:=false
         else if s.[0]='+' then incr n
         else if s.[0]='-' then decr n
         else let i=pos s in m:= !m+String.length(String.sub s i (String.length( s)-i))* !n;
      end
done;;
print_int !m;;

module StrSet = Set.Make(String)

let rec f h ans =
  try
    let a = read_line () in
    let l = String.length a in
    if a.[0] = '+' then
      f (StrSet.add (String.sub a 1 (l-1)) h) ans
    else if a.[0] = '-' then
      f (StrSet.remove (String.sub a 1 (l-1)) h) ans
    else
      f h (ans+(StrSet.cardinal h*(l-1-String.index a ':')))
  with End_of_file ->
    ans

let () =
  Printf.printf "%d\n" (f StrSet.empty 0)


open Printf open Scanf
module MyInt64 = struct
	(* include Int64 *)
	(* int *)
	let (+$) = (+)
	let (-$) = (-)
	let (/$) = (/)
	let ( *$) = ( * )
	(* int64 *)
	let (+) p q = Int64.add p q
	let (-) p q = Int64.sub p q
	let ( * ) p q = Int64.mul p q
	let (/) p q = Int64.div p q

	let labs p = if p < 0L then -1L*p else p
	(* let (~|) p = Int64.of_int p *)
	let (~|) p = Int64.to_int p

	let (+=) r v = r := !r + v
	let (-=) r v = r := !r - v
	let ( *=) r v= r := !r * v
	let (/=) r v = r := !r / v

	let input_i64_array n =
		Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 () = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 () = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 () = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 () = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 () = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let print_i64_endline n =
		n |> Int64.to_string |> print_endline
	let ($) = (~|)
end open MyInt64

let () =
  let n = get_i64 ()
	in let ar = input_i64_array n
	in let mx = 100020
	in let undef = -1
	in let n_occur = Array.make mx undef
	in let n_occur_rev = Array.make mx undef
	in let k_occur = Array.make ~|n 0L
	in
	let ns = ref [] in
	Array.iteri (fun i v ->
		let v = ~|v in
		if n_occur.(v) = undef then (
			n_occur.(v) <- i;
			ns := v::!ns
		);
	) ar;
	let ns = List.map (fun v ->
		n_occur.(v)
	) !ns in
	let k0 = ref 0L in
	Array.iteri (fun i v ->
		let v = ~|v in let i = ~|n-$1-$i in
		if n_occur_rev.(v) = undef then (
			n_occur_rev.(v) <- i;
			k0 += 1L;
		);
		if (i-$1 >= 0) then k_occur.(i-$1) <- !k0;
	) (ar |> Array.to_list |> List.rev |> Array.of_list);
	(* Array.iteri (fun i v ->
		printf "%d: %Ld\n" i k_occur.(i);
	) ar; *)
	let ans = ref 0L in
	List.iter (fun v ->
		(* printf "ans += k_occur.(%d) = %Ld\n" v k_occur.(v); *)
		ans += k_occur.(v);
	) ns;
	!ans |> print_i64_endline

open Int64

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

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in
let count = ref zero in
let rseen = Array.make 500000 zero in
for i = n - 1 downto 0 do
  if rseen.(number.(i)) = zero then count := succ !count;
  rseen.(number.(i)) <- succ rseen.(number.(i));
done;
let result = ref zero in
let seen = Array.make 500000 false in
for i = 0 to n - 2 do
  rseen.(number.(i)) <- pred rseen.(number.(i));
  if rseen.(number.(i)) = zero then count := pred !count;
  if not seen.(number.(i)) then result := add !result !count;
  seen.(number.(i)) <- true;
done;
print_endline @@ to_string !result;

open Int64

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

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in
let count = ref 0L in
let rseen = Array.make 500000 0L in
for i = n - 1 downto 0 do
  if rseen.(number.(i)) = 0L then count := succ !count;
  rseen.(number.(i)) <- succ rseen.(number.(i));
done;
let result = ref 0L in
let seen = Array.make 500000 false in
for i = 0 to n - 2 do
  rseen.(number.(i)) <- pred rseen.(number.(i));
  if rseen.(number.(i)) = 0L then count := pred !count;
  if not seen.(number.(i)) then result := add !result !count;
  seen.(number.(i)) <- true;
done;
print_endline @@ to_string !result;

open Int32

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

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in
let count = ref zero in
let rseen = Array.make 500000 zero in
for i = n - 1 downto 0 do
  if rseen.(number.(i)) = zero then count := succ !count;
  rseen.(number.(i)) <- succ rseen.(number.(i));
done;
let result = ref zero in
let seen = Array.make 500000 false in
for i = 0 to n - 2 do
  rseen.(number.(i)) <- pred rseen.(number.(i));
  if rseen.(number.(i)) = zero then count := pred !count;
  if not seen.(number.(i)) then result := add !result !count;
  seen.(number.(i)) <- true;
done;
print_endline @@ to_string !result;

let ( */ ) = Big_int.mult_big_int;;
let ( +/ ) = Big_int.add_big_int;;
let ( -/ ) = Big_int.sub_big_int;;
let to_int = Big_int.int_of_big_int;;
let of_int = Big_int.big_int_of_int;;
let min = Big_int.min_big_int;;
let (modi) = Big_int.mod_big_int;;
let to_string = Big_int.string_of_big_int;;
let of_string = Big_int.big_int_of_string;;
let (</) = Big_int.lt_big_int;;

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

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in
let count = ref 0 in
let rseen = Array.make 500000 0 in
for i = n - 1 downto 0 do
  if rseen.(number.(i)) = 0 then incr count;
  rseen.(number.(i)) <- rseen.(number.(i))  + 1;
done;
let result = ref 0 in
let seen = Array.make 500000 false in
for i = 0 to n - 2 do
  rseen.(number.(i)) <- rseen.(number.(i))  - 1;
  if rseen.(number.(i)) = 0 then decr count;
  if not seen.(number.(i)) then result := !result + !count;
  seen.(number.(i)) <- true;
done;
print_int !result;
print_newline ();


let ( */ ) = Big_int.mult_big_int;;
let ( +/ ) = Big_int.add_big_int;;
let ( -/ ) = Big_int.sub_big_int;;
let to_int = Big_int.int_of_big_int;;
let of_int = Big_int.big_int_of_int;;
let min = Big_int.min_big_int;;
let (modi) = Big_int.mod_big_int;;
let to_string = Big_int.string_of_big_int;;
let of_string = Big_int.big_int_of_string;;
let (</) = Big_int.lt_big_int;;

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

let n,m = Scanf.sscanf (read_line ()) "%i %i" (fun n m -> (n, m)) in
for i = 1 to m do
  ignore (read_line ());
done;
for i = 1 to n do
  print_int (i mod 2);
done;
print_newline ();

open Printf open Scanf
module MyInt64 = struct
	(* include Int64 *)
	(* int *)
	let (+$) = (+)
	let (-$) = (-)
	let (/$) = (/)
	let ( *$) = ( * )
	(* int64 *)
	let (+) p q = Int64.add p q
	let (-) p q = Int64.sub p q
	let ( * ) p q = Int64.mul p q
	let (/) p q = Int64.div p q

	let labs p = if p < 0L then -1L*p else p
	(* let (~|) p = Int64.of_int p *)
	let (~|) p = Int64.to_int p

	let (+=) r v = r := !r + v
	let (-=) r v = r := !r - v
	let ( *=) r v= r := !r * v
	let (/=) r v = r := !r / v

	let input_i64_array n =
		Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
	let get_i64 () = Scanf.scanf " %Ld" (fun v -> v)
	let get_2_i64 () = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
	let get_3_i64 () = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
	let get_4_i64 () = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
	let get_5_i64 () = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
	let print_i64_endline n =
		n |> Int64.to_string |> print_endline
end open MyInt64

let () =
  let n,m = get_2_i64 ()
  in let ar = Array.make (~|m) (0L,0L)
  in
  for i=0 to ~|m-$1 do
    let u,v = get_2_i64 ()
    in ar.(i) <- u,v
  done;
  let res = Array.make ~|n 0 in
  Array.iteri (fun i _ -> print_int @@  if i mod 2 = 0 then 1 else 0) res;
  print_newline ()


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

let () =
  let n = gi 0 in
  rep 1L n (fun _ ->
    let k,x = g2 0 in
    printf "%Ld\n" @@ x + 9L * (k - 1L)
  )

let (++),( ** ),(--) = Int64.(add,mul,sub);;
Scanf.(Array.(scanf " %d" @@ fun q ->
  init q (fun _ -> scanf " %Ld %Ld" @@ fun k x ->
    Printf.printf "%Ld\n" @@ x ++ 9L ** (k--1L))))

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

let () =
  let n = gi 0 in
  rep 1L n (fun _ ->
    let k,x = g2 0 in
    printf "%Ld" @@ x + 9L * (k - 1L)
  )


let read_pair = fun a b -> (a, b) in

let (n, m) = Scanf.scanf "%d %d\n" read_pair and ans = ref 99999999 in
for i = 1 to m do
        let (tmp1, tmp2) = Scanf.scanf "%d %d\n" read_pair in
        ans := min (!ans) (tmp2 - tmp1 + 1)
done;
print_int !ans;
print_newline ();
for i = 0 to n - 1 do
        print_int (i mod !ans);
        print_string " "
done;;

open Printf
open Scanf

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

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

  let len = minf 0 (m-1) (fun _ ->
    let (l,r) = read_pair() in
    r-l+1
  ) in

  printf "%d\n" len;

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

  print_newline()

let () =
  Scanf.scanf "%d %d " @@ fun n m ->
  let mex = ref n in
  for i = 1 to m do
    Scanf.scanf "%d %d " @@ fun l r ->
    mex := min !mex (r - l + 1)
  done;
  Printf.printf "%d\n" !mex;
  for i = 0 to n - 2 do
    Printf.printf "%d " (i mod !mex)
  done;
  Printf.printf "%d\n" ((n - 1) mod !mex)


let read_int () = Scanf.scanf "%d " (fun n -> n)
let read_char () = Scanf.scanf "%c " (fun c -> c)

let solve () =
    let n = read_int () in
    let rec loop i zeros ones =
        if i < n
        then
            let number = read_char () in
                if number = '0'
                then
                    loop (i + 1) (zeros + 1) ones
                else
                    loop (i + 1) zeros (ones + 1)
        else
            Pervasives.abs (zeros - ones)
    in loop 0 0 0

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

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 input () =
    let n = Pervasives.read_int () in
    let list = str_to_list (Pervasives.read_line ()) in
    (list, n)

let solve (list, n) =
    let zeros = List.length (List.filter (fun c -> c = '0') list) in
    let ones = n - zeros in
    let result = Pervasives.abs (zeros - ones) in
    result

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

let rec count s c i =
    if i = String.length s
    then 0
    else (if s.[i]=c then 1 else 0) + count s c (i+1)

in let n = read_int()
in let s = read_line()
in let reml = n - 2 * min (count s '0' 0) (count s '1' 0)
in print_int(reml)


open Scanf
open Printf

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

let a = Array.make (n+1) 0

for i = 1 to n do
  let j = Scanf.scanf "%d " ( fun x -> x ) in
  a.(i)<-j
done

let rslt = Array.fold_left (fun x y -> if x > y then x else y ) (-1000) a
in printf "%d\n" rslt

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

let (|>) x f = f x ;;
let (@@) f x = f x ;;
module Array = struct
  include ArrayLabels
  let fold_lefti ~f ~init arr =
    let acc = ref init in
    for i = 0 to Array.length arr - 1 do
      acc := f i !acc arr.(i)
    done;
    !acc
  ;;
end
module String = StringLabels ;;
module List  = struct
  include ListLabels ;;
  let rec repeat n a = if n = 0 then [] else a :: repeat (n - 1) a ;;
  let rec drop n a =
    if n = 0 then a
    else match a with
    | [] -> failwith "cannot take"
    | x :: xs -> drop (n - 1) xs ;;

  let init ~f n =
    let res = ref [] in
    for i = 0 to n - 1 do
      res := f i :: !res
    done;
    List.rev !res
  ;;
end ;;
module H = Hashtbl ;;

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

let () =
  sf "%d " (fun n ->
    let arr = Array.init n ~f:(fun i -> sf "%d " (fun i -> i)) in
    pf "%d\n" @@ Array.fold_left ~init:0 arr ~f:max)
;;

open Scanf
open Printf

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

let a = Array.make (n+1) 0

for i = 1 to n do
  let j = Scanf.scanf "%d " ( fun x -> x ) in
  a.(i)<-j
done

let cnt = ref 0

for i = 1 to n do
  let m = a.(i) - a.(i-1) in
  cnt := m + !cnt
done

let () = printf "%d\n" !cnt


let fraction n d =
  let str = (string_of_int n) ^ "/" ^  (string_of_int d) in
  Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))

let solve p q =
  if List.length p > List.length q
  then if  (List.hd p) * (List.hd q) >= 0 then "Infinity"
    else "-Infinity"
  else if List.length p < List.length q then "0/1"
  else fraction (List.hd p) (List.hd q)

let id x = x

let rec input_polynomial dim =
  if dim < 0 then []
  else (Scanf.scanf " %d" id) :: input_polynomial (dim - 1)

let _ =
  let n = Scanf.scanf " %d" id in
  let m = Scanf.scanf " %d" id in
  let p = List.rev (input_polynomial n) in
  let q = List.rev (input_polynomial m) in
  Printf.printf "%s\n" (solve p q)

let sb = Scanf.Scanning.stdib;;

let fraction n d =
  let str = (string_of_int n) ^ "/" ^  (string_of_int d) in
  Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))

let solve p q =
  if List.length p > List.length q
  then if  (List.hd p) * (List.hd q) >= 0 then "Infinity"
    else "-Infinity"
  else if List.length p < List.length q then "0/1"
  else fraction (List.hd p) (List.hd q)

let id x = x

let rec input_polynomial dim =
  if dim < 0 then []
  else (Scanf.bscanf sb " %d" id) :: input_polynomial (dim - 1)

let _ =
  let n = Scanf.bscanf sb " %d" id in
  let m = Scanf.bscanf sb " %d" id in
  let p = List.rev (input_polynomial n) in
  let q = List.rev (input_polynomial m) in
  Printf.printf "%s\n" (solve p q)

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

let next_int: unit -> int = fun _ ->
  Scanf.scanf " %d" (fun x -> x)
;;

let next_polynomial n =
  let ret = next_int () in
  for i = 1 to n do
    next_int ()
  done;
  ret
;;

let rec print_gcd a b =
  let g = gcd (abs a) (abs b) in
  if b < 0
  then print_gcd (-a) (-b)
  else Printf.printf "%d/%d" (a / g) (b / g)
;;

let _ =
  let n = next_int () in
  let m = next_int () in
  let a = next_polynomial n in
  let b = next_polynomial m in
  if n < m then print_string "0/1"
  else if n = m then print_gcd a b
  else print_string ((if a * b > 0 then "" else "-") ^ "Infinity")
;;

module Std = struct

  module List = struct
    include List
    module L = List
    let map f lst = L.rev (L.rev_map f lst)
    let map2 f l1 l2 = L.rev (L.rev_map2 f l1 l2)
    let each_cons f lst = L.rev_map2 f (L.tl (L.rev lst)) (L.rev (L.tl lst))
    let append x y = L.rev (L.rev_append x y)
    let fold = L.fold_left
    let permute_with lst p = L.map (Array.get (Array.of_list lst)) p
  end

  let ( |> ) x f = f x
  let ( <| ) f x = f x
  let ( ~. ) = float_of_int
  let ( @ ) = List.append

  let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)

  let di x = prerr_endline (string_of_int x); x
  let df f = prerr_endline (string_of_float f); f
  let ds s = prerr_endline s; s

  let int () = Scanf.scanf " %d" (fun x -> x)
  let read_int = int
  let float () = Scanf.scanf " %f" (fun x -> x)
  let read_float = float
  let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []
  let rec n_float n () = List.rev <| repeat n (fun lst -> float () :: lst) []

end

open Std
module L = List

let rec gcd x y =
  if y = 0 then x
  else gcd y (x mod y)

(* entry point *)
let n = int ()
let m = int ()

let a = n_int (n+1) ()
let b = n_int (m+1) ()

let () =
  if n > m then
    Printf.printf "%s\n" (if (L.hd a) * (L.hd b) > 0 then "Infinity" else "-Infinity")
  else if n < m then
    Printf.printf "%s\n" "0/1"
  else
    let a = (L.hd a) in
    let b = (L.hd b) in
    let g = gcd a b in
    let a = a / g in
    let b = b / g in
    if a > 0 && b < 0 then
      Printf.printf "%d/%d" (-a) (-b)
    else
      Printf.printf "%d/%d" a b

let rec gcd x y =
  if y == 0 then x else gcd y (x mod y)

let solve n m p q =
  let a = List.hd p in
  let b = List.hd q in
  if n > m  then if  a * b >= 0 then "Infinity" else "-Infinity"
  else if n < m then "0/1"
  else
    let gcd = gcd a b in
    let a = a / gcd in
    let b = b / gcd in
    if a > 0 && b < 0
    then (string_of_int  (- a)) ^ "/" ^ (string_of_int (- b))
    else (string_of_int a) ^ "/" ^ (string_of_int b)

let id x = x

let rec input_polynomial dim =
  if dim < 0 then []
  else (Scanf.scanf " %d" id) :: input_polynomial (dim - 1)

let _ =
  let n = Scanf.scanf " %d" id in
  let m = Scanf.scanf " %d" id in
  let p = List.rev (input_polynomial n) in
  let q = List.rev (input_polynomial m) in
  Printf.printf "%s\n" (solve n m p q)

let rec gcd x y =
  if y == 0 then x else gcd y (x mod y)

let solve n m p q =
  let a = List.hd p in
  let b = List.hd q in
  if n > m  then if  a * b >= 0 then "Infinity" else "-Infinity"
  else if n < m then "0/1"
  else
    let gcd = gcd a b in
    let a = a / gcd in
    let b = b / gcd in
    (string_of_int a) ^ "/" ^ (string_of_int b)

let id x = x

let rec input_polynomial dim =
  if dim < 0 then []
  else (Scanf.scanf " %d" id) :: input_polynomial (dim - 1)

let _ =
  let n = Scanf.scanf " %d" id in
  let m = Scanf.scanf " %d" id in
  let p = List.rev (input_polynomial n) in
  let q = List.rev (input_polynomial m) in
  Printf.printf "%s\n" (solve n m p q)

let sb = Scanf.Scanning.stdib;;

let fraction n d =
  let str = (string_of_int n) ^ "/" ^  (string_of_int d) in
  Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))

let solve p q =
  if List.length p > List.length q
  then if  (List.hd p) > 0 then "Infinity"
    else "-Infinity"
  else if List.length p < List.length q then "0/1"
  else fraction (List.hd p) (List.hd q)

let id x = x

let rec input_polynomial dim =
  if dim < 0 then []
  else (Scanf.bscanf sb " %d" id) :: input_polynomial (dim - 1)

let _ =
  let n = Scanf.bscanf sb " %d" id in
  let m = Scanf.bscanf sb " %d" id in
  let p = List.rev (input_polynomial n) in
  let q = List.rev (input_polynomial m) in
  Printf.printf "%s\n" (solve p q)

module Std = struct

  module List = struct
    include List
    module L = List
    let map f lst = L.rev (L.rev_map f lst)
    let map2 f l1 l2 = L.rev (L.rev_map2 f l1 l2)
    let each_cons f lst = L.rev_map2 f (L.tl (L.rev lst)) (L.rev (L.tl lst))
    let append x y = L.rev (L.rev_append x y)
    let fold = L.fold_left
    let permute_with lst p = L.map (Array.get (Array.of_list lst)) p
  end

  let ( |> ) x f = f x
  let ( <| ) f x = f x
  let ( ~. ) = float_of_int
  let ( @ ) = List.append

  let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)

  let di x = prerr_endline (string_of_int x); x
  let df f = prerr_endline (string_of_float f); f
  let ds s = prerr_endline s; s

  let int () = Scanf.scanf " %d" (fun x -> x)
  let read_int = int
  let float () = Scanf.scanf " %f" (fun x -> x)
  let read_float = float
  let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []
  let rec n_float n () = List.rev <| repeat n (fun lst -> float () :: lst) []

end

open Std
module L = List

let rec gcd x y =
  if y = 0 then x
  else gcd y (x mod y)

(* entry point *)
let n = int ()
let m = int ()

let a = n_int (n+1) ()
let b = n_int (m+1) ()

let () =
  if n > m then
    Printf.printf "%s\n" (if (L.hd a > 0) then "Infinity" else "-Infinity")
  else if n < m then
    Printf.printf "%s\n" "0/1"
  else
    let a = (L.hd a) in
    let b = (L.hd b) in
    let g = gcd a b in
    let a = a / g in
    let b = b / g in
    if a > 0 && b < 0 then
      Printf.printf "%d/%d" (-a) (-b)
    else
      Printf.printf "%d/%d" a b

module Std = struct

  module List = struct
    include List
    module L = List
    let map f lst = L.rev (L.rev_map f lst)
    let map2 f l1 l2 = L.rev (L.rev_map2 f l1 l2)
    let each_cons f lst = L.rev_map2 f (L.tl (L.rev lst)) (L.rev (L.tl lst))
    let append x y = L.rev (L.rev_append x y)
    let fold = L.fold_left
    let permute_with lst p = L.map (Array.get (Array.of_list lst)) p
  end

  let ( |> ) x f = f x
  let ( <| ) f x = f x
  let ( ~. ) = float_of_int
  let ( @ ) = List.append

  let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)

  let di x = prerr_endline (string_of_int x); x
  let df f = prerr_endline (string_of_float f); f
  let ds s = prerr_endline s; s

  let int () = Scanf.scanf " %d" (fun x -> x)
  let read_int = int
  let float () = Scanf.scanf " %f" (fun x -> x)
  let read_float = float
  let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []
  let rec n_float n () = List.rev <| repeat n (fun lst -> float () :: lst) []

end

open Std
module L = List

let rec gcd x y =
  if y = 0 then x
  else gcd y (x mod y)

(* entry point *)
let n = int ()
let m = int ()

let a = n_int (n+1) ()
let b = n_int (m+1) ()

let () =
  if n > m then
    Printf.printf "%s\n" (if (L.hd a > 0) then "Infinity" else "-Infinity")
  else if n < m then
    Printf.printf "%s\n" "0/1"
  else
    let a = (L.hd a) in
    let b = (L.hd b) in
    let g = gcd a b in
    Printf.printf "%d/%d" (a / g) (b / g)


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

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) 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 sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))
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 k = read_long () in
  let a = Array.init n (fun _ -> read_long()) in
  let b = Array.init n (fun _ -> read_long()) in

  let can_bake m =
    let mp = sum 0 (n-1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in
    mp <= k
  in

  let rec bsearch lo hi =
    (* lo can be made, hi cannot *)
    if lo++1L = hi then lo else
      let m = (lo ++ hi) // 2L in
      if can_bake m then bsearch m hi else bsearch lo m
  in

  let rec findhi hi = if can_bake hi then findhi (2L ** hi) else hi in

  printf "%Ld\n" (bsearch 0L (findhi 1L))

open Printf
open Scanf

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

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b
let ( ^^ ) a b = Int64.shift_left a b
let rec sum (i : int) (j : int) f (ac : int64) =
  if i > j then
    ac
  else
    sum (i + 1) j f (ac ++ (f i));;

let () =
  try
    while true do
      let n = read_int () in
      let k = read_long () in
      let a = Array.init n (fun _ -> read_long()) in
      let b = Array.init n (fun _ -> read_long()) in

      let possible m =
        let x = sum 0 (n - 1) (fun i -> min 4000000000L (max 0L ((m ** a.(i)) -- b.(i)))) 0L in
        x <= k
      in

      let rec binary_search small large =
        if (small ++ 1L) < large then
          let (mid : int64) = (small ++ large) // 2L in
          if possible mid then binary_search mid large else binary_search small mid
        else
          small
      in

      printf "%Ld\n" (binary_search 0L 2000000001L)
    done
  with End_of_file -> ()

open Printf
open Scanf

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

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b
let ( ^^ ) a b = Int64.shift_left a b
let rec sum (i : int) (j : int) f (ac : int64) =
  if i > j then
    ac
  else
    sum (i + 1) j f (ac ++ (f i));;

let () =
  try
    while true do
      let n = read_int () in
      let k = read_long () in
      let a = Array.init n (fun _ -> read_long()) in
      let b = Array.init n (fun _ -> read_long()) in

      let possible m =
        let x = sum 0 (n - 1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in
        x <= k
      in

      let rec binary_search small large =
        if (small ++ 1L) < large then
          let mid = (small ++ large) // 2L in
          if possible mid then binary_search mid large else binary_search small mid
        else
          small
      in

      printf "%Ld\n" (binary_search 0L 1000000001L)
    done
  with End_of_file -> ()

open Printf
open Scanf

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

let ( ** ) a b = Int64.mul a b
let ( ++ ) a b = Int64.add a b
let ( -- ) a b = Int64.sub a b
let ( // ) a b = Int64.div a b
let ( %% ) a b = Int64.rem a b
let ( ^^ ) a b = Int64.shift_left a b
let rec sum (i : int) (j : int) f (ac : int64) =
  if i > j then
    ac
  else
    sum (i + 1) j f (ac ++ (f i));;

let () =
  try
    while true do
      let n = read_int () in
      let k = read_long () in
      let a = Array.init n (fun _ -> read_long()) in
      let b = Array.init n (fun _ -> read_long()) in

      let possible m =
        let x = sum 0 (n - 1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in
        x <= k
      in

      let rec binary_search small large =
        if (small ++ 1L) < large then
          let mid = (small ++ large) // 2L in
          if possible mid then binary_search mid large else binary_search small mid
        else
          small
      in

      printf "%Ld\n" (binary_search 0L 2000000001L)
    done
  with End_of_file -> ()