Let's call the following process a transformation of a sequence of length $$$n$$$.If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of $$$n$$$ integers: the greatest common divisors of all the elements in the sequence before each deletion.You are given an integer sequence $$$1, 2, \dots, n$$$. Find the lexicographically maximum result of its transformation.A sequence $$$a_1, a_2, \ldots, a_n$$$ is lexicographically larger than a sequence $$$b_1, b_2, \ldots, b_n$$$, if there is an index $$$i$$$ such that $$$a_j = b_j$$$ for all $$$j < i$$$, and $$$a_i > b_i$$$.

The first and only line of input contains one integer $$$n$$$ ($$$1\le n\le 10^6$$$).

Output $$$n$$$ integers  — the lexicographically maximum result of the transformation.

NoteIn the first sample the answer may be achieved this way:  Append GCD$$$(1, 2, 3) = 1$$$, remove $$$2$$$.  Append GCD$$$(1, 3) = 1$$$, remove $$$1$$$.  Append GCD$$$(3) = 3$$$, remove $$$3$$$. We get the sequence $$$[1, 1, 3]$$$ as the result.

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
;;

exception Found;;

let last_big l a =
  let tmp = ref 0 in
  try
    for i = l-1 downto 0 do
      if a.(i) then (tmp := i + 1; raise Found)
    done;
    !tmp
  with Found -> !tmp
;;

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
let last = ref n in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      if j  = !last && !continue = n - 2  then begin
        Printf.printf "%i " !div;
        incr continue;
        Printf.printf "%i " !last;
      end else Printf.printf "%i " !div;
      incr continue;
      b.(j-1) <- false;
      if j = !last then last := last_big !last b
    end
  done;
  div := 2 * !div;
done;
print_newline ()

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let nn =
	let r = ref 1L in
	while !r*2L <= n do
		r *= 2L
	done; !r
let f v =
	let r = ref 1L in
	while !r*v <= n do r *= v
	done; !r
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n / !v) * !v);
			(* print_endline "";
			printf "%Ld\n" nn;
			printf "%Ld %Ld %Ld\n" ((n/2L)*2L) (f !v) ((n / !v) * !v); *)
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

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 b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      incr continue;
      Printf.printf "%i " (if n = 3 && !continue = n then n else !div);
    end
  done;
  div := 2 * !div;
done;
print_newline ()

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 b = Array.make n true in
let div = ref 1 in
let continue = ref true in
while !continue do
  continue := false;
  for j = 1 to n do
    if b.(j-1) then continue := true;
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      print_int !div;
    end
  done;
  div := 2 * !div;
done;
print_newline ()

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 b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      if j = n && !continue = n - 2  then begin
        Printf.printf "%i " !div;
        incr continue;
        Printf.printf "%i " n;
      end else Printf.printf "%i " !div;
      incr continue;
    end
  done;
  div := 2 * !div;
done;
print_newline ()

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" n;
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

(*
let n = get_i64 0
let mx = i32 n +$ 24

let prime = Array.make (mx) true
let preprocess _ =
	prime.(0) <- false;
	prime.(1) <- false;
	repi 2 mx (fun u ->
		if prime.(u) then (
			repi (u*$2) mx (fun v ->
				prime.(v) <- false;
				`Ok
			)
		);
		`Ok
	)

let () =
 *)

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n/2L)*2L);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let nn =
	let r = ref 1L in
	while !r*2L <= n do
		r *= 2L
	done; !r
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" nn;
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n/2L)*2L);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) 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 abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) 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 (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p 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 (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" 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 (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline 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) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L !p (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;


Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem.

The first line contains two integers n, k (1 ≤ n, k ≤ 100). The second line contains n integers ai (1 ≤ ai ≤ 109) — the numbers that Roma has.  The numbers in the lines are separated by single spaces.

In a single line print a single integer — the answer to the problem.

NoteIn the first sample all numbers contain at most four lucky digits, so the answer is 3.In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.

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 rec lucky_enough x k n =
  if n > k then false
  else if x = 0 then true
  else lucky_enough (x / 10) k (if x mod 10 = 4 || x mod 10 = 7 then n+1 else n)

let main =
  let t = Scanf.scanf "%d" (fun t -> t) in
  let k = read_one () in
  let all = read_many t in
  let ans = List.fold_left (fun acc x ->
    if lucky_enough x k 0 then acc + 1 else acc
  ) 0 all in
  Printf.printf "%d\n" ans


While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.  He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.

The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000). The second line contains integer k (1 ≤ k ≤ 1000).

Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.

NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".

let _ =
  let s = Scanf.scanf " %s" (fun s -> s) in
  let k = Scanf.scanf " %d" (fun x -> x) in
  try
    let n = String.length s in
    if n mod k <> 0 then raise Not_found;
    let l = n/k in
    for i=0 to k-1 do
      for j = 0 to l-1 do
        if s.[i*l+j] <> s.[i*l+(l-1-j)] then raise Not_found;
      done
    done;
    Printf.printf "YES\n";
  with
      Not_found -> Printf.printf "NO\n";


Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,  - 2, 1, 3,  - 4. Suppose the mother suggested subarrays (1,  - 2), (3,  - 4), (1, 3), (1,  - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:   the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,  the second flower adds ( - 2)·1 =  - 2, because he is in one of chosen subarrays,  the third flower adds 1·2 = 2, because he is in two of chosen subarrays,  the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,  the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays. Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100). The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers li and ri (1 ≤ li ≤ ri ≤ n) denoting the subarray a[li], a[li + 1], ..., a[ri]. Each subarray can encounter more than once.

Print single integer — the maximum possible value added to the Alyona's happiness.

NoteThe first example is the situation described in the statements.In the second example Alyona should choose all subarrays.The third example has answer 0 because Alyona can choose none of the subarrays.

let () =
  Scanf.scanf "%d %d " @@ fun n m ->
  let moods = Array.make n 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " (Array.set moods i)
  done;
  let value = ref 0 in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d " @@ fun l r ->
    let m = ref 0 in
    for j = l - 1 to r - 1 do
      m := !m + moods.(j)
    done;
    if !m > 0 then value := !value + !m
  done;
  Printf.printf "%d\n" !value


Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.  English alphabet You are given a string s. Check if the string is "s-palindrome".

The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.

Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.

let () = Scanf.scanf "%s\n" (fun s ->
    (* characters that can be the middle of a string *)
    let mid = ['A'; 'H'; 'I'; 'M'; 'O'; 'o'; 'T'; 'U'; 'V'; 'v'; 'W'; 'w'; 'X'; 'x'; 'Y']
    (* mirrored pairs *)
    and pairs = ['b', 'd'; 'd', 'b'; 'p', 'q'; 'q', 'p'] in

    let n = String.length s in

    print_endline (
        if (n mod 2 = 0 || List.mem s.[n / 2] mid) &&
           Array.fold_left (&&) true (Array.init (n / 2) (fun i ->
               (s.[i] = s.[n - i - 1] && List.mem s.[i] mid) ||
               (List.mem_assoc s.[i] pairs && List.assoc s.[i] pairs = s.[n - i - 1])))
        then "TAK" else "NIE"))

let _ =
  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 true in
  let sym =
    function
      | 'A' -> 'A'
      | 'b' -> 'd'
      | 'd' -> 'b'
      | 'H' -> 'H'
      | 'I' -> 'I'
      | 'M' -> 'M'
      | 'O' -> 'O'
      | 'o' -> 'o'
      | 'T' -> 'T'
      | 'U' -> 'U'
      | 'V' -> 'V'
      | 'v' -> 'v'
      | 'W' -> 'W'
      | 'w' -> 'w'
      | 'X' -> 'X'
      | 'x' -> 'x'
      | 'Y' -> 'Y'
      | 'p' -> 'q'
      | 'q' -> 'p'
      | _ -> '\000'
  in
    for i = 0 to (n - 1) / 2 do
      if s.[i] <> sym s.[n - i - 1]
      then res := false
    done;
    if !res
    then Printf.printf "TAK\n"
    else Printf.printf "NIE\n"

let _ =
  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 true in
  let sym =
    function
      | 'A' -> 'A'
      | 'b' -> 'd'
      | 'd' -> 'b'
      | 'H' -> 'H'
      | 'I' -> 'I'
      | 'M' -> 'M'
      | 'O' -> 'O'
      | 'o' -> 'o'
      | 'T' -> 'T'
      | 'U' -> 'U'
      | 'V' -> 'V'
      | 'v' -> 'v'
      | 'W' -> 'W'
      | 'w' -> 'w'
      | 'X' -> 'X'
      | 'x' -> 'x'
      | 'Y' -> 'Y'
      | _ -> '\000'
  in
    for i = 0 to (n - 1) / 2 do
      if s.[i] <> sym s.[n - i - 1]
      then res := false
    done;
    if !res
    then Printf.printf "TAK\n"
    else Printf.printf "NIE\n"


Alyona has recently bought a miniature fridge that can be represented as a matrix with $$$h$$$ rows and $$$2$$$ columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part.  An example of a fridge with $$$h = 7$$$ and two shelves. The shelves are shown in black. The picture corresponds to the first example. Alyona has $$$n$$$ bottles of milk that she wants to put in the fridge. The $$$i$$$-th bottle is $$$a_i$$$ cells tall and $$$1$$$ cell wide. She can put a bottle on some shelf if the corresponding space above the shelf is at least as tall as the bottle. She can not put a bottle on top of another bottle (if there is no shelf between them). Two bottles can not share a cell.Alyona is interested in the largest integer $$$k$$$ such that she can put bottles $$$1$$$, $$$2$$$, ..., $$$k$$$ in the fridge at the same time. Find this largest $$$k$$$.

The first line contains two integers $$$n$$$ and $$$h$$$ ($$$1 \le n \le 10^3$$$, $$$1 \le h \le 10^9$$$) — the number of bottles and the height of the fridge. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le h$$$) — the heights of the bottles.

Print the single integer $$$k$$$ — the maximum integer such that Alyona can put the bottles $$$1$$$, $$$2$$$, ..., $$$k$$$ in the fridge at the same time. If Alyona can put all bottles in the fridge, print $$$n$$$. It is easy to see that Alyona can always put at least one bottle in the fridge.

NoteOne of optimal locations in the first example is shown on the picture in the statement.One of optimal locations in the second example is shown on the picture below.  One of optimal locations in the third example is shown on the picture below.

open Printf
open Scanf

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

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

let check h a =
  let rec check' i s =
    if i >= Array.length a
    then s <= h
    else check' (i+2) (s++a.(i)) in
  check' 0 0L

let rec binary_search l r h a =
  if r - l <= 1
  then l
  else
    let m = (l+r)/2 in
    let b = Array.init m (fun i -> a.(i)) in
    Array.sort (fun x y -> Int64.compare y x) b;
    if check h b
    then binary_search m r h a
    else binary_search l m h a

let () =
  let n,h = bscanf stdin " %d %Ld" (fun x y -> (x,y)) in
  let a = Array.init n read_long in
  printf "%d\n" @@ binary_search (-1) (n+1) h a


When Masha came to math classes today, she saw two integer sequences of length $$$n - 1$$$ on the blackboard. Let's denote the elements of the first sequence as $$$a_i$$$ ($$$0 \le a_i \le 3$$$), and the elements of the second sequence as $$$b_i$$$ ($$$0 \le b_i \le 3$$$).Masha became interested if or not there is an integer sequence of length $$$n$$$, which elements we will denote as $$$t_i$$$ ($$$0 \le t_i \le 3$$$), so that for every $$$i$$$ ($$$1 \le i \le n - 1$$$) the following is true:   $$$a_i = t_i | t_{i + 1}$$$ (where $$$|$$$ denotes the bitwise OR operation) and  $$$b_i = t_i \& t_{i + 1}$$$ (where $$$\&$$$ denotes the bitwise AND operation). The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence $$$t_i$$$ of length $$$n$$$ exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the sequence $$$t_i$$$.  The second line contains $$$n - 1$$$ integers $$$a_1, a_2, \ldots, a_{n-1}$$$ ($$$0 \le a_i \le 3$$$) — the first sequence on the blackboard. The third line contains $$$n - 1$$$ integers $$$b_1, b_2, \ldots, b_{n-1}$$$ ($$$0 \le b_i \le 3$$$) — the second sequence on the blackboard.

In the first line print "YES" (without quotes), if there is a sequence $$$t_i$$$ that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence. If there is such a sequence, on the second line print $$$n$$$ integers $$$t_1, t_2, \ldots, t_n$$$ ($$$0 \le t_i \le 3$$$) — the sequence that satisfies the statements conditions. If there are multiple answers, print any of them.

let rec read_int_seq n stream =
	if n = 1 then Scanf.bscanf stream "%i" (fun x -> [x])
	else Scanf.bscanf stream "%i " (fun x -> x::(read_int_seq (n - 1) stream))
;;

let rec into_bits nums =
	match nums with
	| h::t -> (h / 2, h mod 2)::(into_bits t)
	| [] -> []
;;

let append_to_option head tail =
	match tail with
	| Some t -> Some (head::t)
	| None -> None
;;

let either f g =
	match f () with
	| Some a -> Some a
	| None -> match g () with
		| Some a -> Some a
		| None -> None
;;

let unwrap op =
	match op with
	| Some a -> a
	| None -> failwith "no value in option"
;;

let contradict_barrier want_to_place hint x =
	match hint with
	| Some a when a = want_to_place -> x
	| None -> x
	| _ -> None
;;

let rec solve nums_a nums_b current_hint_l current_hint_r =
	let infer_l a_bit b_bit a_tail b_tail =
		let infer_r l_res next_hint_l =
			match (snd a_bit, snd b_bit, current_hint_r) with
			| (0, 0, _) -> contradict_barrier 0 current_hint_r (append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0)))
			| (1, 1, _) -> contradict_barrier 1 current_hint_r (append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1)))
			| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))
			| (0, 1, _) -> None
			| _ -> failwith "corrupt data"
		in
		match (fst a_bit, fst b_bit, current_hint_l) with
		| (0, 0, _) -> contradict_barrier 0 current_hint_l (infer_r 0 (Some 0))
		| (1, 1, _) -> contradict_barrier 1 current_hint_l (infer_r 1 (Some 1))
		| (1, 0, Some 0) -> infer_r 0 (Some 1)
		| (1, 0, Some 1) -> infer_r 1 (Some 0)
		| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))
		| (0, 1, _) -> None
		| _ -> failwith "corrupt data"
	in
	match (nums_a, nums_b) with
	| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2
	| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]
;;

let n = read_int();;
let input_len = n - 1;;
let nums_a = read_line();;
let nums_b = read_line();;
let nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;
let nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;
let nums_a = into_bits nums_a;;
let nums_b = into_bits nums_b;;

let solution = solve nums_a nums_b None None;;
match solution with
	| Some solution -> (Printf.printf "YES\n"; List.iter (fun (x, y) -> Printf.printf "%i " (2*x + y)) solution)
	| None -> Printf.printf "NO\n"
;;

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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 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 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
end open Lib

open I64_infix
let () =
	let tbl = Hashtbl.create ~random:true 10014 in
	rep 0L 3L (fun t ->
		rep 0L 3L (fun a ->
			rep 0L 3L (fun b ->
				let ls = ref (-1L) in
				rep 0L 3L (fun tt ->
					if a = t lor tt && b = t land tt then ls := tt
				);
				if !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls

			)
		)
	);
	let n = get_i64 0 in
	let a = input_i64_array (n-1L) in
	let b = input_i64_array (n-1L) in
	let t = Array.make (i32 n) 0L in
	rep 0L 3L (fun t0 ->
		t.(0) <- t0;
		let f = ref true in
		repf 1L (n-1L) (fun i ->
			let i = i32 i in
			try
				t.(i) <- Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1));
				`Ok
			with | Not_found -> (
				f := false; `Break
			)
		);
		if !f then (
			printf "YES\n";
			dump_array Int64.to_string t; exit 0
		)
	);
	printf "NO\n";

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
	(* 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 I64_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
	(* io *)
	let input_i64_array n = Array.init (i32 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 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 *)
	let alen a = i64 @@ Array.length a
	let llen l = i64 @@ List.length l
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
end open Lib

open I64_infix
let undef = -77L
let () =
	let tbl = Hashtbl.create ~random:true 10014 in
	rep 0L 3L (fun t ->
		rep 0L 3L (fun a ->
			rep 0L 3L (fun b ->
				let ls = ref (-1L) in
				rep 0L 3L (fun tt ->
					if a = t lor tt && b = t land tt then ls := tt
				);
				if !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls
				else Hashtbl.add tbl (t,a,b) undef
			)
		)
	);
	let n = get_i64 0 in
	let a = input_i64_array (n-1L) in
	let b = input_i64_array (n-1L) in
	let t = Array.make (i32 n) 0L in
	rep 0L 3L (fun t0 ->
		t.(0) <- t0;
		let f = ref true in
		repf 1L (n-1L) (fun i ->
			let i = i32 i in
			let v = Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1))
			in if v = undef then (f := false; `Break)
			else (t.(i) <- v; `Ok)
		);
		if !f then (
			printf "YES\n";
			dump_array Int64.to_string t; exit 0
		)
	);
	printf "NO\n";

let rec read_int_seq n stream =
	if n = 1 then Scanf.bscanf stream "%i" (fun x -> [x])
	else Scanf.bscanf stream "%i " (fun x -> x::(read_int_seq (n - 1) stream))
;;

let rec into_bits nums =
	match nums with
	| h::t -> (h / 2, h mod 2)::(into_bits t)
	| [] -> []
;;

let append_to_option head tail =
	match tail with
	| Some t -> Some (head::t)
	| None -> None
;;

let either f g =
	match f () with
	| Some a -> Some a
	| None -> match g () with
		| Some a -> Some a
		| None -> None
;;

let unwrap op =
	match op with
	| Some a -> a
	| None -> failwith "no value in option"
;;

let rec solve nums_a nums_b current_hint_l current_hint_r =
	let infer_l a_bit b_bit a_tail b_tail =
		let infer_r l_res next_hint_l =
			match (snd a_bit, snd b_bit, current_hint_r) with
			| (0, 0, _) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 1, _) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))
			| (0, 1, _) -> None
			| _ -> failwith "corrupt data"
		in
		match (fst a_bit, fst b_bit, current_hint_l) with
		| (0, 0, _) -> infer_r 0 (Some 0)
		| (1, 1, _) -> infer_r 1 (Some 1)
		| (1, 0, Some 0) -> infer_r 0 (Some 1)
		| (1, 0, Some 1) -> infer_r 1 (Some 0)
		| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))
		| (0, 1, _) -> None
		| _ -> failwith "corrupt data"
	in
	match (nums_a, nums_b) with
	| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2
	| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]
;;

let n = read_int();;
let input_len = n - 1;;
let nums_a = read_line();;
let nums_b = read_line();;
let nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;
let nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;
let nums_a = into_bits nums_a;;
let nums_b = into_bits nums_b;;

let solution = solve nums_a nums_b None None;;
match solution with
	| Some solution -> (Printf.printf "YES\n"; List.iter (fun (x, y) -> Printf.printf "%i " (2*x + y)) solution)
	| None -> Printf.printf "NO\n"
;;


Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.  Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

On the single line of the output print the number of groups of magnets.

NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.

let solve () =
    let n = Pervasives.read_int () in
    let rec loop i last count =
        if i <= n
        then
            let current = Pervasives.read_line () in
            if String.compare current last = 0
            then
                loop (i + 1) last count
            else
                loop (i + 1) current (count + 1)
        else
            count
    in loop 2 (Pervasives.read_line ()) 1

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

let () = print (solve ())

let n = int_of_string (read_line ()) in
let g = Array.init n (fun i -> int_of_string (read_line ())) |> Array.to_list in
print_int (List.fold_left (fun (b,c) a -> (a, c + if a != b then 1 else 0)) (List.hd g, 1) (List.tl g)  |> snd)

let n = read_int () in
let g = ref 1 in
let l = ref '2' in
for i = 1 to n do
    match read_line () with
        "01" -> if !l = '0' then g := !g + 1; l := '1'
      | "10" -> if !l = '1' then g := !g + 1; l := '0'
done ;
print_int !g ; print_newline () ;;


The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately every 24 months. The implication of Moore's law is that computer performance as function of time increases exponentially as well.You are to prepare information that will change every second to display on the indicator board. Let's assume that every second the number of transistors increases exactly 1.000000011 times.

The only line of the input contains a pair of integers n (1000 ≤ n ≤ 10 000) and t (0 ≤ t ≤ 2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time.

Output one number — the estimate of the number of transistors in a dence integrated circuit in t seconds since the initial time. The relative error of your answer should not be greater than 10 - 6.

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let t = Scanf.bscanf sb "%f " (fun s -> s) in
  let res = float_of_int n *. 1.000000011 ** t in
    Printf.printf "%.6f\n" res


You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.Your task is to add spaces to the text by the following rules:  if there is no punctuation mark between two words, then they should be separated by exactly one space  there should be no spaces before each punctuation mark  there should be exactly one space after each punctuation mark It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.

The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.

Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.

galileo galilei was an   italian physicist  ,mathematician,astronomer

galileo galilei was an italian physicist, mathematician, astronomer

type state =
  | Start
  | Word of Buffer.t
  | Mark

let _ =
  let s = input_line stdin in
  let s = s ^ " " in
  let n = String.length s in
  let state = ref Start in
    for i = 0 to n - 1 do
      let c = s.[i] in
	match c with
	  | 'a'..'z' -> (
	      match !state with
		| Start ->
		    let b = Buffer.create 10 in
		      Buffer.add_char b c;
		      state := Word b
		| Word b ->
		    Buffer.add_char b c
		| Mark ->
		    output_char stdout ' ';
		    let b = Buffer.create 10 in
		      Buffer.add_char b c;
		      state := Word b
	    )
	  | '.' | ',' | '!' | '?' -> (
	      match !state with
		| Start ->
		    output_char stdout c;
		    state := Mark
		| Word b ->
		    output_string stdout (Buffer.contents b);
		    output_char stdout c;
		    state := Mark;
		| Mark ->
		    output_char stdout c;
	    )
	  | ' ' -> (
	      match !state with
		| Start -> ()
		| Word b ->
		    output_string stdout (Buffer.contents b);
		    state := Mark
		| Mark -> ()
	    )
	  | _ -> assert false
    done


New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) — the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros.

For each test case, print the answer on it — the number of minutes before the New Year.

let f h m =
  (60 * (23 - h)) + (60 - m)

let () =
  let n = read_int () in
  for i = 1 to n do
    let t = Scanf.scanf "%d %d\n" f in
    Printf.printf "%d\n" t
  done


On the number line there are $$$m$$$ points, $$$i$$$-th of which has integer coordinate $$$x_i$$$ and integer weight $$$w_i$$$. The coordinates of all points are different, and the points are numbered from $$$1$$$ to $$$m$$$.A sequence of $$$n$$$ segments $$$[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$$$ is called system of nested segments if for each pair $$$i, j$$$ ($$$1 \le i < j \le n$$$) the condition $$$l_i < l_j < r_j < r_i$$$ is satisfied. In other words, the second segment is strictly inside the first one, the third segment is strictly inside the second one, and so on.For a given number $$$n$$$, find a system of nested segments such that:  both ends of each segment are one of $$$m$$$ given points;  the sum of the weights $$$2\cdot n$$$ of the points used as ends of the segments is minimal. For example, let $$$m = 8$$$. The given points are marked in the picture, their weights are marked in red, their coordinates are marked in blue. Make a system of three nested segments:  weight of the first segment: $$$1 + 1 = 2$$$  weight of the second segment: $$$10 + (-1) = 9$$$  weight of the third segment: $$$3 + (-2) = 1$$$  sum of the weights of all the segments in the system: $$$2 + 9 + 1 = 12$$$     System of three nested segments

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of input test cases. An empty line is written before each test case. The first line of each test case contains two positive integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$m$$$ ($$$2 \cdot n \le m \le 2 \cdot 10^5$$$).  The next $$$m$$$ lines contain pairs of integers $$$x_i$$$ ($$$-10^9 \le x_i \le 10^9$$$) and $$$w_i$$$ ($$$-10^4 \le w_i \le 10^4$$$) — coordinate and weight of point number $$$i$$$ ($$$1 \le i \le m$$$) respectively. All $$$x_i$$$ are different. It is guaranteed that the sum of $$$m$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output $$$n + 1$$$ lines: in the first of them, output the weight of the composed system, and in the next $$$n$$$ lines output exactly two numbers  — the indices of the points which are the endpoints of the $$$i$$$-th segment ($$$1 \le i \le n$$$). The order in which you output the endpoints of a segment is not important — you can output the index of the left endpoint first and then the number of the right endpoint, or the other way around. If there are several ways to make a system of nested segments with minimal weight, output any of them.

NoteThe first test case coincides with the example from the condition. It can be shown that the weight of the composed system is minimal.The second test case has only $$$6$$$ points, so you need to use each of them to compose $$$3$$$ segments.

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let rec fusion2 p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt y x -> x::(fusion2 q1 p2)
  | _,x::q2 -> x::(fusion2 p1 q2)
;;

let rec tri_fusion2 p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion2 (tri_fusion2 a) (tri_fusion2 b)
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let rec prend_pet len l = match l with
  |[]->[],Int64.zero
  |p::q when len = 0 -> [] , Int64.zero
  |p::q -> let m,l,k = p in let a,b = (prend_pet (len-1) q) in p::a,(Int64.add (Int64.of_int l) b)

;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((a,b,j))::(!liste)
  done;
  let banned, total = prend_pet (nsegs*2) (tri_fusion2 !liste)in
  print_endline (Int64.to_string (total)) ;
  let casentbon = tri_fusion (banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let rec fusion2 p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt y x -> x::(fusion2 q1 p2)
  | _,x::q2 -> x::(fusion2 p1 q2)
;;

let rec tri_fusion2 p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion2 (tri_fusion2 a) (tri_fusion2 b)
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let rec prend_pet len l = match l with
  |[]->[],Int64.zero
  |p::q when len = 0 -> [] , Int64.zero
  |p::q -> let m,l,k = p in let a,b = (prend_pet (len-1) q) in p::a,(Int64.add (Int64.of_int l) b)

;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((a,b,j))::(!liste)
  done;
  let banned, total = prend_pet (nsegs*2) (tri_fusion2 !liste)in
  print_endline (string_of_int (Int64.to_int total)) ;
  let casentbon = tri_fusion (banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*absisse,poids,id*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let rec fusion2 p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt y x -> x::(fusion2 q1 p2)
  | _,x::q2 -> x::(fusion2 p1 q2)
;;

let rec tri_fusion2 p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion2 (tri_fusion2 a) (tri_fusion2 b)
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let rec prend_pet len l = match l with
  |[]->[],0
  |p::q when len = 0 -> [] , 0
  |p::q -> let m,l,k = p in let a,b = (prend_pet (len-1) q) in p::a,l+b

;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((a,b,j))::(!liste)
  done;
  let banned, total = prend_pet (nsegs*2) (tri_fusion2 !liste)in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*absisse,poids,id*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let rec fusion2 p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt y x -> x::(fusion2 q1 p2)
  | _,x::q2 -> x::(fusion2 p1 q2)
;;

let rec tri_fusion2 p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion2 (tri_fusion2 a) (tri_fusion2 b)
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let rec prend_pet len l = match l with
  |[]->[],0
  |p::q when len = 0 -> [] , 0
  |p::q -> let a,b = (prend_pet (len-1) q) in p::a,1+b

;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((a,b,j))::(!liste)
  done;
  let banned, total = prend_pet (nsegs*2) (tri_fusion2 !liste)in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*absisse,poids,id*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,j))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*absisse,poids,id*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in q>w ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in s>x ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,j))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*absisse,poids,id*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q<w ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,j))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*poids,absisse*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,j))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    let mm,ll,kk = temp in
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*poids,absisse*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,i))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    let mm,ll,kk = temp in
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*poids,absisse*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,i))::(!liste)
  done;
  let banned= ref [] in
  for j = 1 to nsegs *2 do
    let temp = min (!liste) (!banned) in
    let mm,ll,kk = temp in
    prerr_endline (string_of_int(mm)) ;
    prerr_endline (string_of_int(ll)) ;
    prerr_endline (string_of_int(kk)) ;
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;

(*poids,absisse*)

let rec somme l = match l with
  |[]-> 0
  |p::q -> let a,b,c = p in b + somme q
;;

let gt a b = let q,s,d = a in let w,x,c = b in s>x ;;

let gt2 a b = let q,s,d = a in let w,x,c = b in q>w ;;

let rec fission q=match q with
  | [] | [_] -> q, []
  | x::y::p -> let a,b=fission p in x::a, y::b
;;

let rec fusion p1 p2=match p1, p2 with
  | [],_ -> p2
  | _, [] -> p1
  | x::q1, y::_ when gt2 y x -> x::(fusion q1 p2)
  | _,x::q2 -> x::(fusion p1 q2)
;;

let rec tri_fusion p=match p with
  | [] | [_] -> p
  | _ -> let a,b=fission p in fusion (tri_fusion a) (tri_fusion b)
;;

let rec appartient x liste = match liste with
  |[]->false
  |p::q -> if p = x then true else appartient x q
;;

let min l banned =
  let rec aux m l banned = match l with
    |[]->m
    |p::q -> aux (if gt m p && not(appartient p banned) then p else m) q banned
  in aux (999999,99999999,9999999) l banned
;;

let rec finish l1 l2 nsegs = match l1,l2 with
  |_ when nsegs <= 0 -> ()
  | p::q, r::s -> let a,b,c = p in let d,e,f = r in
      print_endline (string_of_int(c)^" "^string_of_int(f)) ; finish q s (nsegs-1)
;;

let n = int_of_string(input_line stdin) in
let fjdskq = input_line stdin in
for i = 0 to n-1 do
  let nsegs, npairs = Scanf.sscanf(input_line stdin)" %d  %d"(fun nsegs npairs->nsegs, npairs) in
  let liste = ref [] in
  for j = 1 to npairs do
    let a,b = Scanf.sscanf(input_line stdin)" %d %d"(fun a b -> a,b) in
    liste := ((b,a,i))::(!liste)
  done;
  let banned= ref [] in
  for j = 0 to nsegs *2 -1 do
    let temp = min (!liste) (!banned) in
    let mm,ll,kk = temp in
    prerr_endline (string_of_int(mm)) ;
    prerr_endline (string_of_int(ll)) ;
    prerr_endline (string_of_int(kk)) ;
    banned := (temp)::(!banned) ;
  done;
  let total = somme (!banned) in
  print_endline (string_of_int total) ;
  let casentbon = tri_fusion (!banned) in
  let bbb = List.rev casentbon in
  finish casentbon bbb nsegs;
  if (i<> n-1) then (let fjdskljfq = input_line stdin in () );
done;;


Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 × 5 table is 15 + 8 + 3 = 26.

The first line of the input contains a single integer x (1 ≤ x ≤ 1018) — the number of squares inside the tables Spongebob is interested in.

First print a single integer k — the number of tables with exactly x distinct squares inside. Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality — in the order of increasing m.

NoteIn a 1 × 2 table there are 2 1 × 1 squares. So, 2 distinct squares in total.  In a 2 × 3 table there are 6 1 × 1 squares and 2 2 × 2 squares. That is equal to 8 squares in total.

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

open Printf
open Scanf

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

  let pyramid n =
    ((n--1L) ** n ** (n++n--1L)) // 6L
  in

  let rec find_max_n i = if pyramid i >= x then i -- 1L else find_max_n (i++1L) in

  let maxn = find_max_n 1L in

  let test n =
    let denom n = (n ** (n++1L)) // 2L in
    let numerator n x =
      x -- (pyramid n) ++ (n**n**(n -- 1L))//2L
    in
    let num = numerator n x in
    let den = denom n in
    let m = num // den in
    if m < n || m ** den <> num then None else Some m
  in

  let rec list_solutions n ac = if n>maxn then ac else
      match test n with
	| None -> list_solutions (n++1L) ac
	| Some m -> list_solutions (n++1L) ((n,m)::ac)
  in

  let l1 = list_solutions 1L [] in

  let (lastn,lastm) = List.hd l1 in

  let l2 = List.map (fun (n,m) -> (m,n)) l1 in

  let answer = if lastn <> lastm
    then (List.rev l1) @ l2
    else (List.rev (List.tl l1)) @ l2
  in

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

  List.iter (fun (n,m) -> printf "%Ld %Ld\n" n m) answer

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

open Printf
open Scanf

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

  let pyramid n =
    ((n--1L) ** n ** (n++n--1L)) // 6L
  in

  let rec find_max_n i = if pyramid i >= x then i -- 1L else find_max_n (i++1L) in

  let maxn = find_max_n 1L in

  printf "%Ld\n" maxn;

  let test n =
    let denom n = (n ** (n++1L)) // 2L in
    let numerator n x =
      x -- (pyramid n) ++ (n**n**(n -- 1L))//2L
    in
    let num = numerator n x in
    let den = denom n in
    let m = num // den in
    if m < n || m ** den <> num then None else Some m
  in

  let rec list_solutions n ac = if n>maxn then ac else
      match test n with
	| None -> list_solutions (n++1L) ac
	| Some m -> list_solutions (n++1L) ((n,m)::ac)
  in

  let l1 = list_solutions 1L [] in

  let (lastn,lastm) = List.hd l1 in

  let l2 = List.map (fun (n,m) -> (m,n)) l1 in

  let answer = if lastn <> lastm
    then (List.rev l1) @ l2
    else (List.rev (List.tl l1)) @ l2
  in

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

  List.iter (fun (n,m) -> printf "%Ld %Ld\n" n m) answer


Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):   Clerihew (aabb);  Alternating (abab);  Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.

The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.

2 1
day
may
sun
fun
test
hill
fest
thrill

NoteIn the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".

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

let n = read_int()
let k = read_int()

let is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false

let rec vowel_place s kk i =
  if i<0 || kk<=0 then None
  else if (is_vowel s.[i]) then
    if (kk=1) then Some i else vowel_place s (kk-1) (i-1)
  else vowel_place s kk (i-1)

let rec tail_equals s t ls lt i j =
  if i>=ls then true else s.[i] = t.[j] && (tail_equals s t ls lt (i+1) (j+1))

let smatch s t kk =
  let vp ss = vowel_place ss kk ((String.length ss)-1) in
  let ls = String.length s in
  let lt = String.length t in
  let a = vp s in
  let b = vp t in
    match (a,b) with
      | (None, _) | (_, None) -> false
      | (Some i, Some j) ->
	  if (ls-i)<>(lt-j) then false else tail_equals s t ls lt i j

let schemes = ref 15

let () =
  for i=0 to n-1 do
    let l1 = read_string() in
    let l2 = read_string() in
    let l3 = read_string() in
    let l4 = read_string() in
      match (smatch l1 l2 k, smatch l1 l3 k, smatch l1 l4 k, smatch l2 l3 k, smatch l2 l4 k, smatch l3 l4 k) with
	| (true, true, true, true, true, true) -> () (* aaaa *)
	| (true, false, false, false, false, true) -> (* aabb *) schemes := !schemes land 4
	| (false, true, false, false, true, false) -> (* abab *) schemes := !schemes land 2
	| (false, false, true, true, false, false) -> (* abba *) schemes := !schemes land 1
	| _ -> schemes := 0
  done

;;
match !schemes with
  | 15 -> Printf.printf "aaaa\n"
  | 4 -> Printf.printf "aabb\n"
  | 2 -> Printf.printf "abab\n"
  | 1 -> Printf.printf "abba\n"
  | _ -> Printf.printf "NO\n"