let read_one () = Scanf.scanf " %d" (fun x -> x)
let read_two () = Scanf.scanf " %d %d" (fun x y -> (x,y))
let read_three () = Scanf.scanf "%d %d %d" (fun x y z -> (x,y,z))

let read_many n =
  let rec helper i acc =
    if i >= n then List.rev acc
    else Scanf.scanf " %d" (fun n -> helper (i+1) (n::acc)) in
  helper 0 []

let list_iteri f lst = List.fold_left (fun j b -> f j b; j+1) 0 lst

let even n = n mod 2 = 0

let rec solve cur tar left l =
  if left <= 0 then []
  else if cur = tar then
    if even left then
      1 :: 1 :: ( solve cur tar (left - 2) l)
    else
      1 :: 2 :: 1 :: (solve cur tar (left - 3) l)
  else if cur > tar then
    let sub = min (cur + 1 - tar) l in
    let new_cur = cur + 1 - sub in
    if new_cur = tar && left = 3 then
	let sub = sub + 1 in
	1 :: sub :: 1 :: []
    else
      1 :: sub :: (solve new_cur tar (left - 2) l)
  else (* cur > tar *)
    let add = min l (tar + 1 - cur) in
    let new_cur = cur + add - 1 in
    if new_cur = tar && left = 3 then
      let add = add - 1 in
      add :: 1 :: 1 :: []
    else if left = 1 then
      let add = tar - cur in
      add :: []
    else
      add :: 1 :: (solve new_cur tar (left - 2) l)

let main =
  let (n,d,l) = read_three() in
  let min_d = (n - n / 2) - (n / 2) * l in
  let max_d = (n - n / 2) * l - (n / 2) in
  if min_d > d || max_d < d then
    Printf.printf "-1\n"
  else
    let print j b =
      if j = n - 1 then Printf.printf "%d\n" b
      else Printf.printf "%d " b in
    ignore (list_iteri print (solve 0 d n l));

let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;

let rec loop n d l x a =
  if n <= 0 then Printf.printf("\n")
  else
    if d > x then
      if a = -1 then begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end
      else let z = min (d-x) (l-1) in
      begin Printf.printf "%d " (z+1); loop (n-1) d l (x+z) (a*(-1)) end
    else if d < x then
      if a = 1 then begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end
      else let z = min (x-d) (l-1) in
      begin Printf.printf "%d " (z+1); loop (n-1) d l (x-z) (a*(-1)) end
    else begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end

let _ =
  let (n,d,l) = read3() in
  if (  (n+1)/2 - (n/2) - (l-1)*(n/2) > d || (n+1)/2 - (n/2) + (l-1)*((n+1)/2) < d )
  then Printf.printf "-1\n"
  else
  loop n d l ( (n+1)/2 - n/2 ) 1;;

let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;

let rec loop n d l x a =
  if n <= 0 then Printf.printf("\n")
  else
    if d > x then
      if a = -1 then begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end
      else let z = min (d-x) (l-1) in
      begin Printf.printf "%d " (z+1); loop (n-1) d l (x+z) (a*(-1)) end
    else if d < x then
      if a = 1 then begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end
      else let z = min (x-d) (l-1) in
      begin Printf.printf "%d " (z+1); loop (n-1) d l (x-z) (a*(-1)) end
    else begin Printf.printf "1 "; loop (n-1) d l x (a*(-1)) end

let _ =
  let (n,d,l) = read3() in
  Printf.printf "%d %d %d\n" n d l;
  if (  (n+1)/2 - (n/2) - (l-1)*(n/2) > d || (n+1)/2 - (n/2) + (l-1)*((n+1)/2) < d )
  then Printf.printf "-1\n"
  else
  loop n d l ( (n+1)/2 - n/2 ) 1;;


let main () =
    let n = read_int () in
    let arr = Array.init n (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun a b -> b, a)) in
    Array.sort (fun a b -> compare b a) arr;
    let list = Array.to_list arr in
    let rec loop r acc = function
        | [] -> acc
        | (a, b) :: tl -> if r = 0 then acc else loop (r - 1 + a) (b + acc) tl
    in
    let ans = loop 1 0 list in
    Printf.printf "%d\n" ans
;;
main ()

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

let sort_cards cards =
  let compare_cards a b =
    if a = b then 0
    else if (snd a) > (snd b) then -1
    else if (snd a) = (snd b) && (fst a) > (fst b) then -1
    else 1
  in
  List.sort compare_cards cards

let rec solve cards opportunity points =
  match cards with
    | [] -> points
    | h :: t ->
      if opportunity = 0 then points
      else solve t (opportunity + (snd h) - 1) (points + (fst h))

let _ =
  let n = Scanf.scanf " %d" (fun x -> x) in
  let cards = input_cards n [] in
  Printf.printf "%d\n" (solve (sort_cards cards) 1 0)


let () =
  let (@@) f x = f x in
  let (|>) x f = f x in
  let open List in
  let open Int64 in
  let split_by_spaces = Str.split @@ Str.regexp_string " " in
  read_line () |> split_by_spaces |> map int_of_string |> tl |> hd |> fun m ->
  read_line () |> split_by_spaces |> map of_string |> Array.of_list |> fun arr ->
  let inc = ref 0L in
  for k = 1 to m do
    read_line () |> split_by_spaces |> List.map int_of_string |> function
      | [1; v; x] -> arr.(v - 1) <- sub (of_int x) !inc
      | [2; y]    -> inc := add !inc @@ of_int y
      | [3; q]    -> print_endline @@ to_string @@ add arr.(q - 1) !inc
      | _ -> failwith @@ "Error on line " ^ string_of_int @@ k + 2
  done

let () =
  let (@@) f x = f x in
  let (|>) x f = f x in
  let split_by_spaces = Str.split @@ Str.regexp_string " " in
  let n, m = match read_line () |> split_by_spaces |> List.map int_of_string with
    | [n; m] -> n, m
    | _ -> failwith "Error on line 1"
  in
  let arr = read_line () |> split_by_spaces |> List.map Int64.of_string |> Array.of_list in
  let inc = ref 0L in
  assert (Array.length arr = n);
  for k = 1 to m do
    match read_line () |> split_by_spaces |> List.map int_of_string with
      | [1; v; x] -> arr.(v - 1) <- Int64.(sub (of_int x) !inc)
      | [2; y]    -> inc := Int64.(add !inc @@ of_int y)
      | [3; q]    -> print_endline @@ Int64.(to_string @@ add arr.(q - 1) !inc)
      | _ -> failwith @@ "Error on line " ^ string_of_int @@ k + 2;
  done

let (+) = Int64.add
let (-) = Int64.sub

type state = {
    arr : int64 array;
    mutable inc : int64
}

let assign state v x =
  state.arr.(v) <- (x - state.inc)

let increment state y =
  state.inc <- state.inc + y

let print state q =
  print_endline (Int64.to_string (state.arr.(q) + state.inc))

let () =
  let open Pervasives in
  let split_by_spaces = Str.split (Str.regexp_string " ") in
  let n, m = match split_by_spaces (read_line ()) with
    | [n; m] -> int_of_string n, int_of_string m
    | _ -> failwith "Error on line 1"
  in
  let int_list_of_string_list = List.map int_of_string in
  let int64_list_of_string_list = List.map Int64.of_string in
  let state =
    { arr = Array.of_list (int64_list_of_string_list (split_by_spaces (read_line ())));
      inc = 0L }
  in
  assert (Array.length state.arr = n);
  let k = ref 0 in
  try while true do
    (match int_list_of_string_list (split_by_spaces (read_line ())) with
      | [1; v; x] -> assign state (v - 1) (Int64.of_int x)
      | [2; y]    -> increment state (Int64.of_int y)
      | [3; q]    -> print state (q - 1)
      | _ -> failwith ("Error on line " ^ (string_of_int (!k + 2))));
    k := !k + 1
  done with End_of_file -> assert (!k = m)

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

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

 let implode l =
  let result = String.create (List.length l) in
  let rec imp i = function
  | [] -> result
  | c :: l -> result.[i] <- c; imp (i + 1) l in
  imp 0 l;;

let (--) i j =
  let rec aux n acc =
    if n < i then acc else aux (n-1) (n :: acc)
  in aux j []

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

  let bit = Array.init (n + 1) (fun _ -> 0L) in

  let update x v =
    let x = ref x in
    while !x <= n do
      bit.(!x) <- Int64.add bit.(!x) v;
      x := !x + (!x land (~- !x));
    done
  in

  let sum x =
    let x = ref x in
    let ret = ref 0L in
    while !x > 0 do
      ret := Int64.add !ret bit.(!x);
      x := !x - (!x land (~- !x));
    done;
    !ret
  in

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

  for i = 0 to n-1 do
    update (i+1) arr.(i);
    update (i+2) (Int64.neg arr.(i));
  done;

  for i = 1 to m do
    let t = read_int () in
    match t with
      | 1 ->
          let x = read_int () in
          let v = (Int64.of_int (read_int ())) in
          let curr = sum x in
          update x (Int64.neg curr);
          update (x+1) curr;
          update x v;
          update (x+1) (Int64.neg v);
      | 2 ->
          let y = Int64.of_int (read_int ()) in
          update 1 y;
      | 3 ->
          let q = read_int () in
          let curr = sum q in
          Printf.printf "%Ld\n" curr;
      | _ -> assert false
   done;

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

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

 let implode l =
  let result = String.create (List.length l) in
  let rec imp i = function
  | [] -> result
  | c :: l -> result.[i] <- c; imp (i + 1) l in
  imp 0 l;;

let (--) i j =
  let rec aux n acc =
    if n < i then acc else aux (n-1) (n :: acc)
  in aux j []

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

  let bit = Array.init (n + 1) (fun _ -> 0) in

  let update x v =
    let x = ref x in
    while !x <= n do
      bit.(!x) <- bit.(!x) + v;
      x := !x + (!x land (~- !x));
    done
  in

  let sum x =
    let x = ref x in
    let ret = ref 0 in
    while !x > 0 do
      ret := !ret + bit.(!x);
      x := !x - (!x land (~- !x));
    done;
    !ret
  in

  let arr = Array.init n read_int in

  for i = 0 to n-1 do
    update (i+1) arr.(i);
    update (i+2) (-arr.(i));
  done;

  for i = 1 to m do
    let t = read_int () in
    match t with
      | 1 ->
          let x = read_int () in
          let v = read_int () in
          let curr = sum x in
          update x (-curr);
          update (x+1) curr;
          update x v;
          update (x+1) (-v);
      | 2 ->
          let y = read_int () in
          update 1 y;
      | 3 ->
          let q = read_int () in
          let curr = sum q in
          Printf.printf "%d\n" curr;
      | _ -> assert false
   done;

type state = {
    arr : int array;
    mutable inc : int
}

let assign state v x =
  state.arr.(v) <- (x - state.inc)

let increment state y =
  state.inc <- state.inc + y

let print state q =
  print_endline (string_of_int (state.arr.(q) + state.inc))

let () =
  let split_by_spaces = Str.split (Str.regexp_string " ") in
  let n, m = match split_by_spaces (read_line ()) with
    | [n; m] -> int_of_string n, int_of_string m
    | _ -> failwith "Error on line 1"
  in
  let int_list_of_string_list = List.map int_of_string in
  let state =
    { arr = Array.of_list (int_list_of_string_list (split_by_spaces (read_line ())));
      inc = 0 }
  in
  assert (Array.length state.arr = n);
  let k = ref 0 in
  try while true do
    (match int_list_of_string_list (split_by_spaces (read_line ())) with
      | [1; v; x] -> assign state (v - 1) x
      | [2; y]    -> increment state y
      | [3; q]    -> print state (q - 1)
      | _ -> failwith ("Error on line " ^ (string_of_int (!k + 2))));
    incr k
  done with End_of_file -> assert (!k = m)


let () =
  let t = read_line () |> int_of_string in
  for i = 1 to t do
    let [a; b] =
      read_line ()
      |> Str.split (Str.regexp " ")
      |> List.map String.trim
      |> List.map int_of_string
    in
    let n = abs (b - a) in
    (n + 9) / 10
    |> string_of_int
    |> print_endline
  done

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

let solve (a : int) (b : int) : int =
  ((abs (a - b)) + 9) / 10

let () =
  let t = read_int () in
  for i = 1 to t do
    let a = read_int () in
    let b = read_int () in
    print_endline ( string_of_int (solve a b))
  done;


(* https://codeforces.com/contest/1493/problem/A *)

let solution m k =
    let nums = Array.make m true in
    nums.(k-1) <- false;
    let rec helper i =
        if i < 0
        then ()
        else if (i+1) > k
        then helper (i-1)
        else if (i+1) = k
        then helper (i-1)
        else if (i+1) < k && nums.(i)
        then begin
            let index = k - (i+1) - 1 in
            if index <> i
            then nums.(k-(i+1)-1) <- false;
            helper (i-1)
        end in
    helper (m-1);
    Array.mapi (fun i e -> if e then Some (i+1) else None) nums
    |> Array.to_list
    |> List.filter (fun e -> e <> None)
    |> List.map (fun (Some e) -> e)

let input_case () =
    read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let print_sol arr =
    List.iter (fun e -> Printf.printf "%d " e) arr

let () =
    let cases = read_int () in
    for i = 1 to cases do
        let m::k::_ = input_case () in
        let sol = solution m k in
        Printf.printf "%d\n" (List.length sol);
        print_sol sol;
        print_newline ()
    done

let l = ref []

let () =
  for i=1 to (read_int ()) do
    l := (Scanf.scanf " %d %d" (fun x y -> x,y))::!l
  done

let rec getListfromArray a n k i =
  if i > n
  then []
  else if i > k
  then
  (i)::(getListfromArray a n k (i+1))
  else if i < k-1
    then if a.(i) = 1 then (i+1)::(getListfromArray a n k (i+1)) else getListfromArray a n k (i+1)
    else getListfromArray a n k (i+1)

let rec printList l =
  match l with
  | h::t -> (Printf.printf "%d " h; printList t)
  | _ -> print_newline ()

let findList (n,k) =
  let a = Array.make (k-1) 0 in
  let () = for i=1 to (k-1) do if a.(i-1) <> 1 then a.(k-i-1) <- 1 done in
  let l = getListfromArray a n k 0 in
  let () = print_endline (string_of_int (List.length l)) in
  printList l

let rec testCases l =
  match l with
  | h::t -> (testCases t; findList h)
  | _ -> ()

let rec testAll l =
  match l with
  | h::t -> (testAll t; findList h)
  | _ -> ()

let () = testAll !l


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

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

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let 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 toint c = (int_of_char c) - (int_of_char 'A')
let tochar i = char_of_int ((int_of_char 'A') + i)

let () =
  let s = read_str() in
  let t = read_str() in
  let n = String.length s in
  let hs = Array.make 26 0 in
  let h = Array.make 26 0 in

  let () =
    for i=0 to n-1 do
      let (c,d) = (toint s.[i], toint t.[i]) in
	hs.(c) <- hs.(c) + 1;
	h.(c) <- h.(c) + 1;
	h.(d) <- h.(d) - 1
    done
  in

  let tot = sum 0 25 (fun i-> abs h.(i)) in
  let () = print_string (Printf.sprintf "%d\n" (tot/2)) in

  let () =
    for i=0 to n-1 do
      let c = toint s.[i] in
	if h.(c) <= 0 then (
	  print_string (Printf.sprintf "%c" (tochar c));
	) else (
	  let rec loop j = if h.(j) < 0 then j else loop (j+1) in
	  let d = loop 0 in
	    if d > c && hs.(c) > h.(c) then (
	      print_string (Printf.sprintf "%c" (tochar c));
	    ) else (
	      h.(d) <- h.(d) + 1;
	      h.(c) <- h.(c) - 1;
	      print_string (Printf.sprintf "%c" (tochar d))
	    )
	);
	hs.(c) <- hs.(c) - 1
    done
  in
    print_string "\n"

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

let read_string () = Scanf.fscanf input " %s " (fun x -> x) ;;

let s = read_string () and t = read_string () ;;

let index c = int_of_char c - int_of_char 'A' ;;
let letter i = char_of_int (i + int_of_char 'A') ;;

let freqs = Array.make 26 0 and freqt = Array.make 26 0 ;;
for i = 0 to String.length s - 1 do
    freqs.(index s.[i]) <- freqs.(index s.[i]) + 1 ;
    freqt.(index t.[i]) <- freqt.(index t.[i]) + 1
done ;;

let (z, result) =
    let rec next_available i =
        if i > 25 then -1
        else if freqt.(i) > freqs.(i) then i
        else next_available (i + 1)
    and r = String.create (String.length s)
    in let rec loop i a cur =
        if i = String.length s then (a, r)
        else let c = index s.[i] in
            (* Need to replace this character *)
            if freqt.(c) = 0 || freqs.(c) > freqt.(c) && cur < c then
            (
                r.[i] <- letter cur ;
                freqt.(cur) <- freqt.(cur) - 1 ;
                freqs.(c) <- freqs.(c) - 1;
                loop (i + 1) (a + 1) (next_available cur)
            )
            (* Need to save this character *)
            else
            (
                r.[i] <- letter c ;
                freqt.(c) <- freqt.(c) - 1 ;
                freqs.(c) <- freqs.(c) - 1;
                loop (i + 1) a cur
            )
    in loop 0 0 (next_available 0) ;;

Printf.fprintf output "%d\n%s\n" z result ;;

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

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

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let 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 toint c = (int_of_char c) - (int_of_char 'A')
let tochar i = char_of_int ((int_of_char 'A') + i)

let () =
  let s = read_str() in
  let t = read_str() in
  let n = String.length s in
  let hs = Array.make n 0 in
  let h = Array.make n 0 in

  let () =
    for i=0 to n-1 do
      let (c,d) = (toint s.[i], toint t.[i]) in
	hs.(c) <- hs.(c) + 1;
	h.(c) <- h.(c) + 1;
	h.(d) <- h.(d) - 1
    done
  in

  let () =
    for i=0 to n-1 do
      let c = toint s.[i] in
	if h.(c) <= 0 then (
	  print_string (Printf.sprintf "%c" (tochar c));
	) else (
	  let rec loop j = if h.(j) < 0 then j else loop (j+1) in
	  let d = loop 0 in
	    if d > c && hs.(c) > h.(c) then (
	      print_string (Printf.sprintf "%c" (tochar c));
	    ) else (
	      h.(d) <- h.(d) + 1;
	      h.(c) <- h.(c) - 1;
	      print_string (Printf.sprintf "%c" (tochar d))
	    )
	);
	hs.(c) <- hs.(c) - 1
    done
  in
    print_string "\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 read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int()in
  let m = read_int() in
  let rowempty = Array.make n 1 in
  let colempty = Array.make n 1 in
  for i=1 to m do
    let r = read_int() in
    let c = read_int() in
    rowempty.(r-1) <- 0;
    colempty.(c-1) <- 0;
  done;

  let r = sum 0 (n-1) (fun i -> rowempty.(i)) in
  let c = sum 0 (n-1) (fun i -> colempty.(i)) in

  let dp = Array.make_matrix (r+1) (c+1) None in

  let rec calc r c =
    if r<0 || c<0 then 0.0 else
      match dp.(r).(c) with Some x -> x | None ->
	let answer =
	  if r=0 && c=0 then 0.0 else (
	    let cells = float (n * (r+c) - r*c) in
	    let area = float (n*n) in
	    let p = cells /. area in
	  (* prob that we hit a useful one.  1/p is E(time till we hit) *)

	  (* now, given that we hit a useful one what is the probability of the
	     three different types .... *)
	    let pboth = (float (r*c)) /. cells in
	    let pcol = ((float (c*(n-r))) /. cells) in
	    let prow = ((float (r*(n-c))) /. cells) in

	    (1.0 /. p) +.
	      pboth *. (calc (r-1) (c-1)) +.
	      pcol *. (calc r (c-1)) +.
	      prow *. (calc (r-1) c)
	  )
	in
	dp.(r).(c) <- Some answer;
	answer
  in

  printf "%15.10f\n" (calc r c)


let solve (a:int array) =
	let n = Array.length a in
	let rec find l l_sum r r_sum =
		if l>r then l,(n-l)
		else if l_sum<=r_sum then find (l+1) (l_sum + a.(l)) r r_sum
		else find l l_sum (r-1) (r_sum+a.(r))
	in
	let l, r = find 0 0 (n-1) 0 in
	Printf.printf "%d %d\n" (l) (n-l);;

let trim (line: string) =
	(* trim leading white space *)
	let line = Str.replace_first (Str.regexp "^[ \t\n\r]+") "" line in
	(* trim trailing white space *)
	let line = Str.replace_first (Str.regexp "[ \t\n\r]+$") "" line in
	line
;;

let ints_of_string (line: string) =
	Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (trim line)))
;;

let _ =
	let _ = int_of_string (read_line()) in
	let a = ints_of_string (read_line()) in
	solve a

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

let ubound a n =
  let rec go l h =
    if l = h then
      l
    else
      let m = (l+h)/2 in
      if (if m > 0 then a.(m-1) else 0) <= a.(n-1)-a.(m) then
        go (m+1) h
      else
        go l m
  in go 0 n

let () =
  let n = read_int 0 in
  let a = Array.init n read_int in
  for i = 1 to n-1 do
    a.(i) <- a.(i)+a.(i-1)
  done;
  let x = ubound a n in
  Printf.printf "%d %d\n" x (n-x)

let solve (a:int array) =
    let n = Array.length a in
    let s = Array.fold_left (fun s x -> s + x) 0 a in
    let half = s / 2 in
    let rec find idx s =
        if s+a.(idx)>half then idx
        else find (idx+1) (s + a.(idx))
    in
    let l = find 0 0 in
    print_int l;
    print_string " ";
    print_int (n-l);
    print_newline ()
    ;;

let trim (line: string) =
    (* trim leading white space *)
    let line = Str.replace_first (Str.regexp "^[ \t\n\r]+") "" line in
    (* trim trailing white space *)
    let line = Str.replace_first (Str.regexp "[ \t\n\r]+$") "" line in
    line
;;

let ints_of_string (line: string) =
    Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (trim line)))
;;

let _ =
    let n = int_of_string (read_line()) in
    let a = ints_of_string (read_line()) in
    solve a

let solve (a:int array) =
	let n = Array.length a in
	let s = Array.fold_left (fun s x -> s + x) 0 a in
	let half = (1+ s) / 2 in
	let rec find idx s =
		if (idx >= n || s+a.(idx)>half) then idx
		else find (idx+1) (s + a.(idx))
	in
	let l = find 1 (a.(0)) in
	Printf.printf "%d %d\n" l (n-l);;
	(*
	print_int l;
	print_string " ";
	print_int (n-l);
	print_newline ()
	;;
*)

let trim (line: string) =
	(* trim leading white space *)
	let line = Str.replace_first (Str.regexp "^[ \t\n\r]+") "" line in
	(* trim trailing white space *)
	let line = Str.replace_first (Str.regexp "[ \t\n\r]+$") "" line in
	line
;;

let ints_of_string (line: string) =
	Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (trim line)))
;;

let _ =
	let n = int_of_string (read_line()) in
	let a = ints_of_string (read_line()) in
	solve a

let solve (a:int array) =
    let n = Array.length a in
    let s = Array.fold_left (fun s x -> s + x) 0 a in
    let half = (1+ s) / 2 in
    let rec find idx s =
        if (idx >= n || s+a.(idx)>half) then idx
        else find (idx+1) (s + a.(idx))
    in
    let l = find 0 0 in
    Printf.printf "%d %d\n" l (n-l);;
    (*
    print_int l;
    print_string " ";
    print_int (n-l);
    print_newline ()
    ;;
*)

let trim (line: string) =
    (* trim leading white space *)
    let line = Str.replace_first (Str.regexp "^[ \t\n\r]+") "" line in
    (* trim trailing white space *)
    let line = Str.replace_first (Str.regexp "[ \t\n\r]+$") "" line in
    line
;;

let ints_of_string (line: string) =
    Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (trim line)))
;;

let _ =
    let n = int_of_string (read_line()) in
    let a = ints_of_string (read_line()) in
    solve a

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

let ubound a n =
  let rec go l h =
    if l = h then
      l
    else
      let m = (l+h)/2 in
      if a.(m) <= a.(n-1)-a.(m) then
        go (m+1) h
      else
        go l m
  in go 0 n

let () =
  let n = read_int 0 in
  let a = Array.init n read_int in
  for i = 1 to n-1 do
    a.(i) <- a.(i)+a.(i-1)
  done;
  let x = ubound a n in
  Printf.printf "%d %d\n" x (n-x)


exception No;;
let check_one_line l=
  List.fold_left (fun a b ->
                   if a !=b
                   then raise No
                   else a)
                 (List.hd l)
                 l;;

let check_two_line l =
  List.fold_left (fun a b ->
                   check_one_line b;
                   if (List.hd a)==(List.hd b)
                   then raise No else b)
                 [10;10]
                 l;;

let rec get_line m =
  if m==0 then []
  else (Scanf.scanf "%c" (fun c -> Char.code c - Char.code '0')):: (get_line (m-1));;

let rec get_line_wrap m =
  let
    a = get_line m;
  in
  Scanf.scanf "%c" (fun c -> c);
  a;;

let rec get_lines n m =
  if n<=0 then []
  else get_line_wrap m :: get_lines (n-1) m;;

let () =
  let l = Scanf.scanf "%d %d\n" get_lines in
  try
    check_two_line l;Printf.printf "Yes\n"
  with No -> Printf.printf "No\n";;

exception No;;
let check_one_line l=
  List.fold_left (fun a b ->
                   if a !=b
                   then raise No
                   else a)
                 (List.hd l)
                 l;;

let check_two_line l =
  List.fold_left (fun a b ->
                   check_one_line b;
                   if (List.hd a)==(List.hd b)
                   then raise No else b)
                 [10;10]
                 l;;

let rec get_line_wrap m =
  let rec get_line m r =
  if m==0 then r
  else get_line (m-1) ((Scanf.scanf "%c" (fun c -> Char.code c - Char.code '0'))::r)
  in
  let
    a = get_line m [];
  in
  Scanf.scanf "%c" (fun c -> c);
  a;;

let get_lines_wrap n m =
  let rec get_lines n m r=
    if n<=0 then r
    else get_lines (n-1) m ((get_line_wrap m) :: r)
  in
  get_lines n m [];;

let () =
  let l = Scanf.scanf "%d %d\n" get_lines_wrap in
  try
    check_two_line l;Printf.printf "Yes\n"
  with No -> Printf.printf "No\n";;

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

let () =
  let n = read_int 0 in
  let m = read_int 0 in
  let a = Array.init n read_str in
  let rec go i j =
    if i = n then
      true
    else if j = m then
      go (i+1) 0
    else if j > 0 && a.(i).[j-1] <> a.(i).[j] then
      false
    else if i > 0 && j = 0 && a.(i-1).[0] = a.(i).[0] then
      false
    else
      go i (j+1)
  in
  print_endline (if go 0 0 then "YES" else "NO")


module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;; (* primes, ancestors, primlimit *)

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )

let calc_primes_count ((primes, _, _) as sieve) value =
  let rec fact_folder ancs value acc =
    if value = 1 then acc
    else fact_folder ancs (value / ancs.(value)) (acc + 1)
  in
  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc
  in
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (_primes, _ancs, _primlimit) = sieve in
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES" else "NO" in
  let () = Printf.fprintf outp "%s\n" answer in
(*   let () = Printf.fprintf outp "Val A: %d; Val B: %d\n" a b in
  let () = Printf.fprintf outp "Count A: %d; Count B: %d\n" count_a count_b in
 *)  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  (* let primlimit = 20 in *)
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

(* 6:26 *)

open Printf
open Scanf

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

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 rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)
let sum i j f = fold i j (fun i a -> (f i) + a) 0

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let () =
  let cases = read_int() in
  for case = 1 to cases do
    let (a,b) = read_pair () in
    let k = read_int () in

    let g = gcd a b in

    let answer =
      if k = 1 then if a=b then false else g=a || g=b else
	let nfa = List.length (factor a) in
	let nfb = List.length (factor b) in
	let maxmoves = nfa + nfb in
	let minmoves = if a=b then 0 else if g = a || g = b then 1 else 2 in
	if k < minmoves then false
	else if k > maxmoves then false
	else if k = maxmoves then true
	else if k = maxmoves-1 then nfa >= 2 || nfb >=2
	else true
    in
    if answer then printf "YES\n" else printf "NO\n"
  done

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)

let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n -> let () = f state in repeat f state (n - 1);;

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in incr j
        done
      end
    done
  in
  (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)

let rec fact_folder ancs value acc =
  if value = 1 then acc else fact_folder ancs (value / ancs.(value)) (acc + 1);;

let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
  match primes with
  | [] -> if value = 1 then acc else acc + 1
  | prime::primes_tail as primes ->
    if value <= primlimit then fact_folder ancs value acc
    else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
    else helper sieve primes_tail value acc;;

let calc_primes_count ((primes, _, _) as sieve) value = helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then a != b && (a mod b = 0 || b mod a = 0)
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES\n" else "NO\n" in
  let () = Printf.fprintf outp "%s" answer in
  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)

let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n -> let () = f state in repeat f state (n - 1);;

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in incr j
        done
      end
    done
  in
  (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)

let rec fact_folder ancs value acc =
  if value = 1 then acc else fact_folder ancs (value / ancs.(value)) (acc + 1);;

let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
  match primes with
  | [] -> if value = 1 then acc else acc + 1
  | prime::primes_tail as primes ->
    if value <= primlimit then fact_folder ancs value acc
    else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
    else helper sieve primes_tail value acc;;

let calc_primes_count ((primes, _, _) as sieve) value = helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES\n" else "NO\n" in
  let () = Printf.fprintf outp "%s" answer in
  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)

let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;;

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)

let rec fact_folder ancs value acc =
  if value = 1 then acc
  else fact_folder ancs (value / ancs.(value)) (acc + 1);;

  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc;;

let calc_primes_count ((primes, _, _) as sieve) value =
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES\n" else "NO\n" in
  let () = Printf.fprintf outp "%s" answer in
  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;;

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)

let rec fact_folder ancs value acc =
  if value = 1 then acc
  else fact_folder ancs (value / ancs.(value)) (acc + 1);;

  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc;;

let calc_primes_count ((primes, _, _) as sieve) value =
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES" else "NO" in
  let () = Printf.fprintf outp "%s\n" answer in
  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let gc_defaults = Gc.get ();;

let () =
  Gc.set
  { gc_defaults with
    minor_heap_size = 1024 * 1024
  ; major_heap_increment = 1024 * 1024
  };;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;; (* primes, ancestors, primlimit *)

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )

let calc_primes_count ((primes, _, _) as sieve) value =
  let rec fact_folder ancs value acc =
    if value = 1 then acc
    else fact_folder ancs (value / ancs.(value)) (acc + 1)
  in
  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc
  in
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (_primes, _ancs, _primlimit) = sieve in
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES" else "NO" in
  let () = Printf.fprintf outp "%s\n" answer in
(*   let () = Printf.fprintf outp "Val A: %d; Val B: %d\n" a b in
  let () = Printf.fprintf outp "Count A: %d; Count B: %d\n" count_a count_b in
 *)  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  (* let primlimit = 20 in *)
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let gc_defaults = Gc.get ();;

let () =
  Gc.set
  { gc_defaults with
    minor_heap_size = 1024 * 1024 * 16
  ; major_heap_increment = 1024 * 1024 * 32
  };;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;; (* primes, ancestors, primlimit *)

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )

let calc_primes_count ((primes, _, _) as sieve) value =
  let rec fact_folder ancs value acc =
    if value = 1 then acc
    else fact_folder ancs (value / ancs.(value)) (acc + 1)
  in
  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc
  in
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (_primes, _ancs, _primlimit) = sieve in
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let result =
    if c = 1 then
      if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else
      let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
      count_a + count_b >= c
  in
  let answer = if result then "YES" else "NO" in
  let () = Printf.fprintf outp "%s\n" answer in
(*   let () = Printf.fprintf outp "Val A: %d; Val B: %d\n" a b in
  let () = Printf.fprintf outp "Count A: %d; Count B: %d\n" count_a count_b in
 *)  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  (* let primlimit = 20 in *)
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;; (* primes, ancestors, primlimit *)

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )

let calc_primes_count ((primes, _, _) as sieve) value =
  let rec fact_folder ancs value acc =
    if value = 1 then acc
    else fact_folder ancs (value / ancs.(value)) (acc + 1)
  in
  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc
  in
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (_primes, _ancs, _primlimit) = sieve in
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
  let result =
    if c = 1 then if a != b && (a mod b = 0 || b mod a = 0) then true else false
    else count_a + count_b >= c
  in
  let () =
    if result then Printf.fprintf outp "YES\n"
    else Printf.fprintf outp "NO\n"
  in
(*   let () = Printf.fprintf outp "Val A: %d; Val B: %d\n" a b in
  let () = Printf.fprintf outp "Count A: %d; Count B: %d\n" count_a count_b in
 *)  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  (* let primlimit = 20 in *)
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

module Stdlib = Pervasives
let std_in = Stdlib.stdin and std_out = Stdlib.stdout;;
(* let std_in = Stdlib.open_in "input.txt" and std_out = Stdlib.stdout;; *)
let identity x = x;;
let tup3 x1 x2 x3 = (x1, x2, x3);;

let rec repeat f state = function
  | 0 -> ()
  | n ->
    let () = f state in
    repeat f state (n - 1);;

type sieve = int list * int array * int;; (* primes, ancestors, primlimit *)

let create_sieve n =
  let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in
  let () =
    for i = 2 to n do
      begin
        if ancs.(i) = 0 then
          let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in
          incr primes_count
        else ();
        let j = ref 0 in
        while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do
          let () = ancs.(i * primes.(!j)) <- primes.(!j) in
          incr j
        done
      end
    done
  in
  ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )

let calc_primes_count ((primes, _, _) as sieve) value =
  let rec fact_folder ancs value acc =
    if value = 1 then acc
    else fact_folder ancs (value / ancs.(value)) (acc + 1)
  in
  let rec helper ((_, ancs, primlimit) as sieve) primes value acc =
    match primes with
    | [] -> if value = 1 then acc else acc + 1
    | prime::primes_tail as primes ->
      if value <= primlimit then fact_folder ancs value acc
      else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)
      else helper sieve primes_tail value acc
  in
  helper sieve primes value 0

let solution (inp, outp, sieve) =
  let (_primes, _ancs, _primlimit) = sieve in
  let (a, b, c) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in
  let result =
    if c mod 2 = 1 && a = b then false
    else
      let add_a = if a > 1 then 1 else 0 in
      let add_b = if b > 1 then 1 else 0 in
      count_a + count_b >= c - add_a - add_b
  in
  let () =
    if result then Printf.fprintf outp "YES\n"
    else Printf.fprintf outp "NO\n"
  in
(*   let () = Printf.fprintf outp "Val A: %d; Val B: %d\n" a b in
  let () = Printf.fprintf outp "Count A: %d; Count B: %d\n" count_a count_b in
 *)  ();;

let () =
  let inp = std_in and outp = std_out in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  (* let primlimit = 20 in *)
  let primlimit = 31623 in
  let sieve = create_sieve primlimit in
  let state = (inp, outp, sieve) in
  repeat solution state tests_count;;

(* 6:26 *)

open Printf
open Scanf

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

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 rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)
let minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)
let sum i j f = fold i j (fun i a -> (f i) + a) 0

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let () =
  let cases = read_int() in
  for case = 1 to cases do
    let (a,b) = read_pair () in
    let k = read_int () in

    let g = gcd a b in

    let answer =
      let nfa = List.length (factor a) in
      let nfb = List.length (factor b) in
      let maxmoves = nfa + nfb in
      let minmoves = if a=b then 0 else if g = a || g = b then 1 else 2 in
      if k < minmoves then false
      else if k > maxmoves then false
      else if k = maxmoves then true
      else if k = maxmoves-1 then nfa >= 2 || nfb >=2
      else true
    in
    if answer then printf "YES\n" else printf "NO\n"
  done


let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 27 27 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref 26 in
    let prevc = ref 0 in
    let cur = ref (c2i s.[0]) in
    let curc = ref 1 in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
(*Printf.printf "asd %d: %d %d %d %d  %d\n" c !prev !prevc !cur !curc !res;*)
	  if c = !prev && not a.(!prev).(!cur) then (
	    let t = !cur
	    and tc = !curc in
	      cur := !prev;
	      curc := !prevc;
	      prev := t;
	      prevc := tc;
	      incr curc;
	  ) else if !curc = 0 then (
	    cur := c;
	    curc := 1;
	  ) else if c = !cur then (
	    incr curc;
	  ) else (
	    if not a.(!prev).(!cur) then (
	      if !prevc < !curc
	      then res := !res + !prevc
	      else res := !res + !curc
	    );
	    prev := !cur;
	    prevc := !curc;
	    cur := c;
	    curc := 1;
	  )
      done;
      if not a.(!prev).(!cur) then (
	if !prevc < !curc
	then res := !res + !prevc
	else res := !res + !curc
      );
      Printf.printf "%d\n" !res;

let main () =
    let s = read_line () in
    let k = read_int () in
    let forbid = Array.create_matrix 26 26 true in
    for i = 1 to k do
        let c = read_line () in
        let a1 = int_of_char c.[0] - int_of_char 'a' in
        let a2 = int_of_char c.[1] - int_of_char 'a' in
        forbid.(a1).(a2) <- false;
        forbid.(a2).(a1) <- false
    done;
    let rec loop arr i =
        if i < 0 then arr else (
            let arr2 = Array.copy arr in
            let c = int_of_char s.[i] - int_of_char 'a' in
            arr2.(c) <- 1;
            for j = 0 to 25 do
                if arr.(j) >= 0 && forbid.(j).(c) then (
                    arr2.(c) <- max arr2.(c) (arr.(j) + 1)
                )
            done;
            loop arr2 (i - 1)
        )
    in
    let arr = loop (Array.create 26 (-1)) (String.length s - 1) in
    let ans = String.length s - Array.fold_left max 0 arr in
    Printf.printf "%d\n" ans
;;
main ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 26 26 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref (c2i s.[0]) in
    let prevc = ref 1 in
    let cur = ref 0 in
    let curc = ref 0 in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
(*Printf.printf "asd %d: %d %d %d %d\n" c !prev !prevc !cur !curc;*)
	  if c = !prev then (
	    let t = !cur
	    and tc = !curc in
	      cur := !prev;
	      curc := !prevc;
	      prev := t;
	      prevc := tc;
	      incr curc;
	  ) else if !curc = 0 then (
	    cur := c;
	    curc := 1;
	  ) else if c = !cur then (
	    incr curc;
	  ) else (
	    if not a.(!prev).(!cur) then (
	      if !prevc < !curc
	      then res := !res + !prevc
	      else res := !res + !curc
	    );
	    prev := !cur;
	    prevc := !curc;
	    cur := c;
	    curc := 1;
	  )
      done;
      if not a.(!prev).(!cur) then (
	if !prevc < !curc
	then res := !res + !prevc
	else res := !res + !curc
      );
      Printf.printf "%d\n" !res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 26 26 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref (c2i s.[0]) in
    let prevc = ref 1 in
    let cur = ref 0 in
    let curc = ref 0 in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
(*Printf.printf "asd %d: %d %d %d %d\n" c !prev !prevc !cur !curc;*)
	  if c = !prev then (
	    incr prevc;
	  ) else if !curc = 0 then (
	    cur := c;
	    curc := 1;
	  ) else if c = !cur then (
	    incr curc;
	  ) else (
	    if not a.(!prev).(!cur) then (
	      if !prevc < !curc
	      then res := !res + !prevc
	      else res := !res + !curc
	    );
	    prev := !cur;
	    prevc := !curc;
	    cur := c;
	    curc := 0;
	  )
      done;
      if not a.(!prev).(!cur) then (
	if !prevc < !curc
	then res := !res + !prevc
	else res := !res + !curc
      );
      Printf.printf "%d\n" !res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 26 26 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref (c2i s.[0]) in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
	  if a.(!prev).(c) then (
	    prev := c
	  ) else (
	    incr res
	  )
      done;
      Printf.printf "%d\n" !res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 26 26 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref (c2i s.[0]) in
    let prevc = ref 1 in
    let cur = ref 0 in
    let curc = ref 0 in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
(*Printf.printf "asd %d: %d %d %d %d\n" c !prev !prevc !cur !curc;*)
	  if c = !prev then (
	    incr prevc;
	  ) else if !curc = 0 then (
	    cur := c;
	    curc := 1;
	  ) else if c = !cur then (
	    incr curc;
	  ) else (
	    if not a.(!prev).(!cur) then (
	      if !prevc < !curc
	      then res := !res + !prevc
	      else res := !res + !curc
	    );
	    prev := !cur;
	    prevc := !curc;
	    cur := c;
	    curc := 1;
	  )
      done;
      if not a.(!prev).(!cur) then (
	if !prevc < !curc
	then res := !res + !prevc
	else res := !res + !curc
      );
      Printf.printf "%d\n" !res;

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix 26 26 true in
  let res = ref 0 in
  let c2i c = Char.code c - Char.code 'a' in
    for i = 1 to k do
      let t = Scanf.bscanf sb "%s " (fun s -> s) in
	a.(c2i t.[0]).(c2i t.[1]) <- false;
	a.(c2i t.[1]).(c2i t.[0]) <- false;
    done;
    let prev = ref (c2i s.[0]) in
    let prevc = ref 1 in
    let cur = ref 0 in
    let curc = ref 0 in
      for i = 1 to String.length s - 1 do
	let c = c2i s.[i] in
(*Printf.printf "asd %d: %d %d %d %d  %d\n" c !prev !prevc !cur !curc !res;*)
	  if c = !prev && not a.(!prev).(!cur) then (
	    let t = !cur
	    and tc = !curc in
	      cur := !prev;
	      curc := !prevc;
	      prev := t;
	      prevc := tc;
	      incr curc;
	  ) else if !curc = 0 then (
	    cur := c;
	    curc := 1;
	  ) else if c = !cur then (
	    incr curc;
	  ) else (
	    if not a.(!prev).(!cur) then (
	      if !prevc < !curc
	      then res := !res + !prevc
	      else res := !res + !curc
	    );
	    prev := !cur;
	    prevc := !curc;
	    cur := c;
	    curc := 1;
	  )
      done;
      if not a.(!prev).(!cur) then (
	if !prevc < !curc
	then res := !res + !prevc
	else res := !res + !curc
      );
      Printf.printf "%d\n" !res;


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

let n = read_int ();;
let p1 = read_int ();;
let p2 = read_int ();;
let p3 = read_int ();;
let t1 = read_int ();;
let t2 = read_int ();;

let power_of_period x =
	if x > t1 + t2 then p1 * t1 + p2 * t2 + p3 * (x - t1 - t2)
	else if x > t1 then p1 * t1 + p2 * (x - t1)
	else x * p1

let ans = ref 0;;
let last = ref (-1);;

for i = 1 to n do
	let (l, r) = Scanf.scanf "%d %d " (fun x y -> (x, y)) in begin
		ans := !ans + power_of_period (l - (if !last = -1 then l else !last)) + (r - l) * p1;
		last := r;
	end
done;;

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

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

let () =
  let n = read_int 0 in
  let p1 = read_int 0 in
  let p2 = read_int 0 in
  let p3 = read_int 0 in
  let t1 = read_int 0 in
  let t2 = read_int 0 in
  let rec go i t s =
    if i >= n then
      s
    else
      let l = read_int 0 in
      let r = read_int 0 in
      let _,s' = if i > 0 then List.fold_left (fun (t,s) (pi,ti) ->
          let d = min ti (l-t) in t+d, s+d*pi
        ) (t,s) [p1,t1; p2,t2; p3,max_int] else t,s in
      go (i+1) r (s'+(r-l)*p1)
  in
  Printf.printf "%d\n" (go 0 0 0)


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

let _ =
  let mm = 1000000007 in
  let mmm = Int64.of_int mm in
  let mmod n =
    let r = Int64.rem n mmm in
      if r < 0L
      then r +| mmm
      else r
  in
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let res = ref 1L in
    for i = 0 to n - 1 do
      let c = s.[i] in
      let d =
	match c with
	  | '0'..'9' -> Char.code c - Char.code '0'
	  | 'A'..'Z' -> Char.code c - Char.code 'A' + 10
	  | 'a'..'z' -> Char.code c - Char.code 'a' + 36
	  | '-' -> 62
	  | '_' -> 63
	  | _ -> assert false
      in
	for i = 0 to 5 do
	  if d land (1 lsl i) = 0 then (
	    res := mmod (!res *| 3L)
	  )
	done;
    done;
    Printf.printf "%Ld\n" !res

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 rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac + (f i))
let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
  let s = read_string () in
  let n = String.length s in

  let rec bitcount x = if x=0 then 0 else (x land 1) + bitcount (x/2) in

  let zeros = sum 0 (n-1) (fun i ->
    let c = s.[i] in
    let numb =
      if '0' <= c && c <= '9' then (int_of_char c) - (int_of_char '0')
      else if 'A' <= c && c <= 'Z' then 10 + (int_of_char c) - (int_of_char 'A')
      else if 'a' <= c && c <= 'z' then 36 + (int_of_char c) - (int_of_char 'a')
      else if c = '-' then 62
      else if c = '_' then 63
      else failwith "bad input"
    in
    6 - (bitcount numb)
  ) 0 in

  let m = 1_000_000_007L in

  let rec ( ^ ) e p =
    if p=0 then 1L else
      let a = e^(p/2) in
      let a2 = (a**a) %% m in
      if (p land 1)=0 then a2 else (e**a2) %% m
  in

  printf "%Ld\n" (3L ^ zeros)


let score m' w' x' =
    let m = float m' and w = float w' and x = float x' in
 max (0.3 *. x) ((1. -. m /. 250.) *. x -. 50. *. w)

let main () =
    let (m1,m2,m3,m4,m5,w1,w2,w3,w4,w5,hs,hu) = Scanf.scanf
    "%d %d %d %d %d %d %d %d %d %d %d %d"
    (fun a b c d e f g h i j k l -> (a,b,c,d,e,f,g,h,i,j,k,l)) in
         let sc = score m1 w1 500 +. score m2 w2 1000 +. score m3 w3 1500 +. score m4 w4 2000 +. score m5 w5 2500 +. 100. *. (float hs) -. 50. *. (float hu) in
             Printf.printf "%d" (int_of_float sc);;

main ();;

let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;
let read5 () = Scanf.scanf "%d %d %d %d %d\n" ( fun x y z a b-> x, y, z, a, b);;
let read x = (if x = 0 then Scanf.scanf "%d\n" else Scanf.scanf "%d ") ( fun x -> x );;

let (+$) x y =
  if x > max_int - y then max_int
  else x + y;;

let rec ( *$ ) x y =
  if y = 0 then 0 else
  if y mod 2 = 1 then x *$ (y-1) +$ x
  else let a = x *$ (y/2) in a +$ a;;

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

let licz m w x =
  max (75*x) ( (250 - m)*x - 250*50*w );;

let _ =
  let (a,b,c,d,e) = read5 ()
  and (f,g,h,i,j) = read5 ()
  and (hs, hu) = read2 ()
  in
  let suma = (licz a f 500) + (licz b g 1000) + (licz c h 1500) + (licz d i 2000) + (licz e j 2500) in
  Printf.printf "%d\n" ( suma/250 + (2*hs-hu)*50 ) ;;

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (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) 0

let () =
  let m = Array.init 5 (fun _ -> read_int()) in
  let w = Array.init 5 (fun _ -> read_int()) in
  let hs = read_int() in
  let hu = read_int() in

  let x = [|500; 1000; 1500; 2000; 2500|] in

  let score i =
    max ((3*x.(i)) / 10) ((x.(i) / 250) * (250-m.(i)) - 50*w.(i))
  in

  let total_score = (sum 0 4 score) + 100*hs - 50*hu in

  printf "%d\n" total_score


let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and m=read_int() and k=read_int();;
let tab=Array.make (k+1) false;;
let temp=Array.make (k+1) 0;;
let block=Array.make (n+1) 0;;
let mat=Array.make_matrix (n+1) (m+1) 0;;

for i=1 to n do
   for j=1 to m do
      mat.(i).(j)<-read_int()
   done
done;;

let init vec i j=
for p=i to j do
   vec.(p)<-0
done;;

for j=1 to m do
   init temp 1 k;
   for i=1 to n do
      if (block.(i)=0)&&(mat.(i).(j)<>0) then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1
   done;
   for i=1 to n do
      if (block.(i)=0)&&((temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)))&&(mat.(i).(j)<>0) then (block.(i)<-j;tab.(mat.(i).(j))<-true)
   done
done;;

for i=1 to n do
   print_int block.(i);
   if i<>n then print_newline()
done;;

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make_matrix n m 0 in
  let res = Array.make n 0 in
    for i = 0 to n - 1 do
      for j = 0 to m - 1 do
	let k = Scanf.bscanf sb "%d " (fun s -> s) in
	  a.(i).(j) <- k
      done
    done;
    let b = Array.make k false in
      for j = 0 to m - 1 do
	let c = Array.make k 0 in
	  for i = 0 to n - 1 do
	    if res.(i) = 0 && a.(i).(j) <> 0 then (
	      c.(a.(i).(j) - 1) <- c.(a.(i).(j) - 1) + 1
	    )
	  done;
	  for i = 0 to n - 1 do
	    if res.(i) = 0 && a.(i).(j) <> 0 &&
	      (c.(a.(i).(j) - 1) > 1 || b.(a.(i).(j) - 1))
	    then (
	      res.(i) <- j + 1;
	      b.(a.(i).(j) - 1) <- true;
	    )
	  done;
      done;
      for i = 0 to n - 1 do
	Printf.printf "%d\n" res.(i);
      done

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and m=read_int() and k=read_int();;
let tab=Array.make (k+1) false;;
let temp=Array.make (k+1) 0;;
let block=Array.make (n+1) 0;;
let mat=Array.make_matrix (n+1) (m+1) 0;;

for i=1 to n do
   for j=1 to m do
      mat.(i).(j)<-read_int()
   done
done;;

let init vec i j=
for p=i to j do
   vec.(p)<-0
done;;

for j=1 to m do
   init temp 1 k;
   for i=1 to n do
      if (block.(i)=0)&&(mat.(i).(j)<>0) then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1
   done;
   for i=1 to n do
      if ((block.(i)=0)&&(temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)))&&(mat.(i).(j)<>0) then (block.(i)<-j;tab.(mat.(i).(j))<-true)
   done
done;;

for i=1 to n do
   print_int block.(i);
   if i<>n then print_newline()
done;;

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and m=read_int() and k=read_int();;
let tab=Array.make (k+1) false;;
let temp=Array.make (k+1) 0;;
let block=Array.make (n+1) 0;;
let mat=Array.make_matrix (n+1) (m+1) 0;;

for i=1 to n do
   for j=1 to m do
      mat.(i).(j)<-read_int()
   done
done;;

let init vec i j=
for p=i to j do
   vec.(p)<-0
done;;

for j=1 to m do
   init temp 1 k;
   for i=1 to n do
      if block.(i)=0 then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1
   done;
   for i=1 to n do
      if (block.(i)=0)&&(temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)) then (block.(i)<-j;tab.(mat.(i).(j))<-true)
   done
done;;

for i=1 to n do
   print_int block.(i);
   if i<>n then print_newline()
done;;


let () = Scanf.scanf "%d\n" (fun n ->
    (* read volume in office, volume in hall and confidence *)
    let read i = Scanf.scanf "%Ld %Ld %Ld\n" (fun v d p -> (i + 1, v, d, p)) in
    (* build array of children *)
    let c = Array.to_list (Array.init n read) in

    let (+) = Int64.add
    and (-) = Int64.sub in

    let rec dentist l acc = match l with
        | [] -> acc
        | (i, v, _, _) :: rest ->
                (* calculate the new line by removing the office volume from elements
                 * and summing the line volume as well *)
                let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->
                    (* prevent underflow of the volume from the office *)
                    let ov = max ov 0L in
                    (* calculate new confidence level *)
                    let p' = p - ov - lv in

                    if p' < 0L
                    (* this child leaves the queue, so add their line volume to lv
                     * NB: prevent overflow here, since the max confidence is only 10^6 *)
                    then (ov - 1L, lv + d, acc)
                    (* otherwise, this child remains in the queue with a new confidence *)
                    else (ov - 1L, lv, ((i, v, d, p') :: acc))) (v, 0L, []) rest in
                dentist (List.rev line) (i :: acc)
    in
    let res = List.rev (dentist c []) in
    Printf.printf "%d\n%s\n" (List.length res) (String.concat " " (List.map string_of_int res)))

let () = Scanf.scanf "%d\n" (fun n ->
    (* read volume in office, volume in hall and confidence *)
    let read i = Scanf.scanf "%d %d %d\n" (fun v d p -> (i + 1, v, d, p)) in
    (* build array of children *)
    let c = Array.to_list (Array.init n read) in

    let rec dentist l acc = match l with
        | [] -> acc
        | (i, v, d, p) :: rest ->
                (* calculate the new line by removing the office volume from elements
                 * and summing the line volume as well *)
                let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->
                    let ov = max ov 0 in
                    let p' = p - ov - lv in
                    if p' < 0
                    then (ov - 1, min (lv + d) 1000000, acc)
                    else (ov - 1, lv, ((i, v, d, p') :: acc))) (v, 0, []) rest in
                dentist (List.rev line) (i :: acc)
    in
    let res = List.rev (dentist c []) in
    Printf.printf "%d\n%s\n" (List.length res) (String.concat " " (List.map string_of_int res)))

let () = Scanf.scanf "%d\n" (fun n ->
    (* read volume in office, volume in hall and confidence *)
    let read i = Scanf.scanf "%d %d %d\n" (fun v d p -> (i + 1, v, d, p)) in
    (* build array of children *)
    let c = Array.to_list (Array.init n read) in

    let rec dentist l acc = match l with
        | [] -> acc
        | (i, v, d, p) :: rest ->
                (* calculate the new line by removing the office volume from elements
                 * and summing the line volume as well *)
                let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->
                    let ov = max ov 0 in
                    let p' = p - ov - lv in
                    if p' < 0
                    then (ov - 1, lv + d, acc)
                    else (ov - 1, lv, ((i, v, d, p') :: acc))) (v, 0, []) rest in
                dentist (List.rev line) (i :: acc)
    in
    let res = List.rev (dentist c []) in
    Printf.printf "%d\n%s\n" (List.length res) (String.concat " " (List.map string_of_int res)))


open Printf
open String

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

let rec msplit t i ll=
  if t="" || i>=String.length t then
    List.rev ll
  else
    begin
      try
        let j = String.index_from t i '/' in
        let s1= String.sub t i (j-i) in
        match s1 with
        |"" -> msplit t (j+1) ll
        |_ -> msplit t (j+1) (s1::ll)
      with
        Not_found ->
        let s1 = String.sub t i ((String.length t) - i) in
        List.rev (s1::ll)
    end

let msplit2 s = msplit s 0 []

              (*
let a = msplit2 "home/xyzt" in
    let () =List.iter (printf "%s ") a in
    print_endline "\n====\n"
               *)

let rec process_cd t cwd =
  if t="" then
    cwd
  else
    begin
      match (String.get t 0) with
      | '/' -> (process_cd (String.sub t 1 ((String.length t)-1)) [])
      | _ ->
         begin
           let ll = msplit t 0 [] in
           process_dirs ll cwd
         end
    end
and process_dirs l c =
  match l with
  | [] -> c
  | hd::lr ->
     begin
       match hd with
       |"." -> process_dirs lr c
       |".."-> process_dirs lr (List.tl c)
       | _ -> process_dirs lr (hd::c)
     end

let rec process_command ls cwd =
  match ls with
  |[] -> ()
  |s::lr ->
    begin
      match s with
      | "pwd" ->
         List.iter (fun x -> printf "/%s" x) (List.rev cwd); print_endline "/";
         process_command lr cwd
      | "cd" ->
         let cwd1 = process_cd (List.hd lr) cwd in
         process_command (List.tl lr) cwd1
    end

let rec readl l =
    let s = Scanf.scanf "%s " (fun x -> x) in
    match s with
    | "" -> List.rev l
    | _ -> readl (s::l)

let commands = readl [];;

  (*
let _ = List.iter (fun x -> printf "%s " x) commands
in print_endline "\n---"
   *)

let _ = process_command commands []

open Printf;;
open Scanf;;

let output_directory dir =
  let rec process_dir dir =
  match dir with
    | []   -> printf "\n"
    | h::t -> printf "%s/" h;
	      process_dir t
  in
  printf "/";
  process_dir (List.rev dir)
;;

let rec change_directory act_dir s idx act_str =
  if idx < (String.length s) then
    match s.[idx] with
    | '/' -> if(act_str = "..") then
		change_directory (List.tl act_dir) s (idx+1) ""
	     else
		change_directory (act_str::act_dir) s (idx+1) ""
    | c   -> change_directory act_dir s (idx+1) (act_str ^ (Char.escaped c))
  else
    act_dir
;;

let process_line dir =
  let s = scanf "%s" (fun x->x) in
(*   printf "mam komende %s\n" s; *)
  if s = "pwd" then begin
(*     printf "%s\n" s; *)
    let _ = scanf "%s\n" (fun x->x) in
    output_directory dir;
    dir
  end else begin
(*     printf "%s\n" s; *)
    let s2 = scanf " %s\n" (fun x->x) in
(*     printf "robie cd do %s\n" s2; *)
    if s2.[0] = '/' then
      change_directory [] (s2^"/") 1 ""
    else
      change_directory dir (s2^"/") 0 ""
  end

;;

let rec solve n directory =
  if n <> 0 then
    solve (n-1) (process_line directory)
;;

let n = scanf "%d\n" (fun x->x) in
solve n []


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

let solve n =
	let t = Array.make (n + 1) 0 and
	color = Array.make (n + 1) 0 and
	cnt = Array.make (n + 1) 0 in
	for i = 1 to n do
		let a = read_int () in
		t.(i) <- a;
	done;
	for i = 1 to n do
		if color.(i) = 0 then
			let cur = ref i in
			while color.(!cur) = 0 do
				cnt.(i) <- (cnt.(i) + 1);
				color.(!cur) <- i;
				cur := t.(!cur);
			done;
		printf "%d " cnt.(color.(i));
		else printf "%d " cnt.(color.(i));
	done;
	printf "\n";
	()

let () =
	let q = read_int () in
	for tests = 1 to q do
		let n = read_int () in
		solve n;
	done;


let n = int_of_string (input_line stdin) in
for i = 0 to n-1 do
  let l , r = Scanf.sscanf (input_line stdin) "%d  %d" (fun l r -> (l,r)) in
  if l = 0 then print_endline "1"
  else begin
    let b = Int64.add (Int64.of_int r) (Int64.of_int r) in
    let a = Int64.add b (Int64.of_int (l+1)) in
    print_endline (Int64.to_string a)
  end
done;;

open Printf
open Scanf
module LL = Int64
let rd_ll () = bscanf Scanning.stdin " %Ld " (fun x -> x)

let (&) x = LL.of_int x
let ( + ) x y = LL.add x y
let ( - ) x y = LL.sub x y
let ( * ) x y = LL.mul x y
let ( / ) x y = LL.div x y
let ( % ) x y = x - ( y * (x / y) )

let solve x y =
  if x = 0L then 1L
  else x+2L*y+1L

let () =
  let t = read_int () in
  for i=1 to t do
    let n = rd_ll () in
    let x = rd_ll () in
    printf "%Ld\n" (solve n x)
  done;


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;
    Array.sort compare a
  in
  let res = ref 1 in
    for i = 0 to n - 1 do
      if a.(i) >= !res
      then incr res
    done;
    Printf.printf "%d\n" !res

open Printf
open Scanf

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

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

  Array.sort compare a;

  let rec scan i mval = if i=n then mval else
      if a.(i) >= mval
      then scan (i+1) (mval+1)
      else scan (i+1) mval
  in

  printf "%d\n" (scan 0 1)


module A = Array
module L = List
module I = Int64
module B = Big_int

module Opt = struct
  let get = function
    | None -> assert false
    | Some v -> v
end

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let i_bit x i = (x lsr i) land 1

let () =
  let n = read_int () in
  let q = read_int () in
  let ans = Array.make n 0 in
  let gr = Array.make n [] in
  let qrs = Array.init q (fun _ ->
    let x = read_int () - 1 in
    let y = read_int () - 1 in
    let v = read_int () in
    (x, y, v)
  ) in

  Array.iter (fun (x, y, v) ->
    if (x <> y) then begin
      gr.(x) <- (y, v) :: gr.(x);
      gr.(y) <- (x, v) :: gr.(y);
    end
  ) qrs;

  let bit_val = Array.make n (-1) in
  for b = 29 downto 0 do
    Array.fill bit_val 0 n (-1);
    for i = 0 to q - 1 do
      let (x, y, v) = qrs.(i) in
      (* pf "q = %d %d %d %d\n" i x y v;
      pf "q = %d %d %d %b\n" i  (i_bit v x ) (i_bit v y ) (i_bit v x = 0 && i_bit v y = 0); *)
      if (x = y) then bit_val.(x) <- i_bit v x
      else if (i_bit v b = 0 && i_bit v b = 0) then begin
        bit_val.(x) <- 0;
        bit_val.(y) <- 0;
      end
    done;

    for i = 0 to n - 1 do
      if (bit_val.(i) = -1) then begin
        let is_one = List.exists (fun (y, v) -> bit_val.(y) = 0 && i_bit v b = 1) gr.(i) in
        (* pf "%d %d %b\n" b i is_one; *)
        if (is_one) then bit_val.(i) <- 1
        else bit_val.(i) <- 0;
      end;
      ans.(i) <- ans.(i) lor (bit_val.(i) lsl b);
    done;
  done;

  Array.iter (fun x -> pf "%d " x) ans;

open Printf
open Scanf

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let () =
  let (n,q) = read_pair () in
  let constr = Array.init q (fun _ ->
    let i = -1 + read_int() in
    let j = -1 + read_int() in
    let x = read_int() in
    (i,j,x)
  ) in

  let req0 = Array.make n 0 in
  let req1 = Array.make n 0 in

  let adj = Array.make n [] in

  let add_edge i j x =
    adj.(i) <- (j,x)::adj.(i);
    adj.(j) <- (i,x)::adj.(j)
  in

  for k = 0 to q-1 do
    let (i,j,x) = constr.(k) in
    if i=j then (
      req0.(i) <- req0.(i) lor (lnot x);
      req1.(i) <- req1.(i) lor x
    ) else (
      req0.(i) <- req0.(i) lor (lnot x);
      req0.(j) <- req0.(j) lor (lnot x);
      add_edge i j x
    )
  done;

  for i = 0 to n-1 do
    req1.(i) <- List.fold_left (fun ac (j,x) ->
      (req0.(j) land x) lor ac
    ) req1.(i) adj.(i);
    req0.(i) <- lnot req1.(i)
  done;

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