So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter "P" is missing from the pile and there's an extra letter "L".In the third sample there's an extra letter "L".

let charlist_of_string str =
    let n = String.length str in
    let rec iter i cl =
        if i < 0 then
            cl
        else
            let sc = str.[i] in
            iter (i-1) (sc :: cl)
    in iter (n-1) []

let s1 = charlist_of_string (read_line ());;
let s2 = charlist_of_string (read_line ());;
let s3 = charlist_of_string (read_line ());;

let _ =
    let s4 = List.append s1 s2 in
    let s5 = List.sort Char.compare s4 in
    let s6 = List.sort Char.compare s3 in
    let rec compare x =
        match x with
          | ([], []) -> true
          | (r1 :: res1, r2 :: res2) ->
                if r1 = r2 then compare (res1, res2)
                else false
          | _ -> false
    in
    if compare (s5, s6) then
        print_endline "YES"
    else
        print_endline "NO";;

let a = Scanf.scanf "%s\n" (fun x->x);;
let b = Scanf.scanf "%s\n" (fun x->x);;
let l = Scanf.scanf "%s\n" (fun x->x);;

let letters = Hashtbl.create 0;;

String.iter (fun c ->
	if Hashtbl.mem letters c then
		Hashtbl.replace letters c (Hashtbl.find letters c + 1)
	else
		Hashtbl.add letters c 1
) l;;

let it c =
	try
		Hashtbl.replace letters c (Hashtbl.find letters c - 1)
	with _ -> (print_string "NO";exit 0)
;;

String.iter it a;;
String.iter it b;;

Hashtbl.iter (fun _ x ->
	if x <> 0 then begin print_string "NO"; exit 0 end
) letters;;

print_string "YES";;

let list_of_string str =
  let rec loop i lst =
    match i with
    | -1 -> lst
    | i -> loop (i-1) ((String.get str i) :: lst)
  in
  loop ((String.length str)-1) []

let sort lst = List.sort compare lst

let equal lst1 lst2 =
  let rec loop lst1 lst2 =
      match lst1 with
	| [] -> lst2 = []
	| h :: t ->
	  if h = List.hd lst2 then loop t (List.tl lst2)
	  else false
  in
  if List.length lst1 < List.length lst2
  then loop lst1 lst2
  else loop lst2 lst1

let solve guest_name host_name shuffled_name =
  let guest_name = list_of_string guest_name in
  let host_name = list_of_string host_name in
  let shuffled_name = list_of_string shuffled_name in
  if equal (sort (guest_name @ host_name)) (sort shuffled_name)
  then "YES"
  else "NO"

let _ =
  let guest_name = Scanf.scanf "%s\n" (fun s -> s) in
  let host_name = Scanf.scanf "%s\n" (fun s -> s) in
  let shuffled_name = Scanf.scanf "%s\n" (fun s -> s) in
  begin
    Printf.printf "%s\n" (solve guest_name host_name shuffled_name)
  end

(* Codeforces 141A *)

let string_to_char_list s =
  let len = String.length s in
  let rec inner l = function
    | 0 -> s.[0] :: l
    | i -> inner (s.[i] :: l) (i-1)
  in
  inner [] (len-1)

let _ =
  let guest = read_line() in
  let host = read_line() in
  let shuffled_letters = read_line() in
  let buf1 =
    List.sort compare ((string_to_char_list guest) @
	               (string_to_char_list host)) in
  let buf2 = List.sort compare (string_to_char_list (shuffled_letters)) in
  let answer =
    if (buf1 = buf2)
    then "YES"
    else "NO"
  in
  print_endline answer

(* Codeforces 141A *)

let string_to_char_list s =
  let len = String.length s in
  let rec inner l = function
    | 0 -> s.[0] :: l
    | i -> inner (s.[i] :: l) (i-1)
  in
  inner [] (len-1)

let _ =
  let guest = read_line() in
  let host = read_line() in
  let shuffled_letters = read_line() in
  let buf1 = List.sort Char.compare (string_to_char_list (guest^host)) in
  let buf2 = List.sort Char.compare (string_to_char_list (shuffled_letters)) in
  let answer =
    if (buf1 = buf2)
    then "YES"
    else "NO"
  in
  Printf.printf "%s\n" answer

let read () = Pervasives.read_line ()

let get_strings () =
    let host = read () in
    let guest = read () in
    let letters = read () in
    let names = host ^ guest in
    (letters, names)

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

let solve (letters, names) =
    let letters_sorted = List.sort Pervasives.compare (str_to_list letters) in
    let names_sorted = List.sort Pervasives.compare (str_to_list names) in
    if (Pervasives.compare letters_sorted names_sorted) = 0
    then
        "YES"
    else
        "NO"

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

let a = Scanf.scanf "%s\n" (fun x->x);;
let b = Scanf.scanf "%s\n" (fun x->x);;
let l = Scanf.scanf "%s\n" (fun x->x);;

let letters = Hashtbl.create 0;;

String.iter (fun c ->
	if Hashtbl.mem letters c then
		Hashtbl.replace letters c (Hashtbl.find letters c + 1)
	else
		Hashtbl.add letters c 1
) l;;

let it c =
	try
		Hashtbl.replace letters c (Hashtbl.find letters c - 1)
	with _ -> (print_string "NO";exit 0)
;;

String.iter it a;;
String.iter it b;;

Hashtbl.iter (fun _ x ->
	if x < 0 then begin print_string "NO"; exit 0 end
) letters;;

print_string "YES";;

let x, y = Scanf.scanf "%f %f %f\n" (fun a x y -> ( x /. a , y /. a -. 1.));;

if (x < 0.5) && (x > -0.5) && (y < 0.0) && (y > -1.0) then begin
	print_string "1";
	exit 0;
end;;

if (y -. (floor y)) = 0. then begin
	print_string "-1";
	exit 0;
end;;

if (int_of_float (floor y)) mod 2 = 0 then begin
	if (x < 0.5) && (x > -0.5) then begin
		print_int ((int_of_float (floor y)) / 2 * 3 + 2);
	end else begin
		print_string "-1";
		exit 0;
	end
end else begin
	if ((x > 0.) && (x < 1.)) then begin
		print_int ((int_of_float (floor y)) / 2 * 3 + 4);
	end else if ((x > -1.) && (x < 0.)) then begin
		print_int ((int_of_float (floor y)) / 2 * 3 + 3);
	end else begin
		print_string "-1";
		exit 0;
	end
end;;


Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.

The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.

Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.

open Scanf
open Printf

let loops = [| 1; 0; 0; 0; 1; 0; 1; 0; 2; 1 |]

let compute k =
  if k > 2 * 18 then "-1" else
    let rec inner str = function
      | 0 -> str
      | 1 -> str ^ "6"
      | k -> inner (str ^ "8") (k - 2)
    in
    inner "" k

let () =
  let k = scanf " %u\n" (fun x -> x) in
  compute k |> print_endline

open Scanf
open Printf

let loops = [| 1; 0; 0; 0; 1; 0; 1; 0; 2; 1 |]

let compute k =
  if k > 144 then "-1" else
    let rec inner str = function
      | 0 -> str
      | 1 -> str ^ "6"
      | k -> inner (str ^ "8") (k - 2)
    in
    inner "" k

let () =
  let k = scanf " %u\n" (fun x -> x) in
  compute k |> print_endline


Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.A k-tree is an infinite rooted tree where:  each vertex has exactly k children;  each edge has some weight;  if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k. The picture below shows a part of a 3-tree.      As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).

A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

open Printf
open Scanf

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

let mm = 1000000007L

let ( ++ ) a b =
  let a = Int64.of_int a in
  let b = Int64.of_int b in
  let ans = Int64.rem (Int64.add a b) mm in
  Int64.to_int ans

let () =
  let n = read_int () in
  let k = read_int () in
  let d = read_int () in

  let a = Array.make_matrix (n+1) (n+k+1) 0 in
  let b = Array.make_matrix (n+1) (n+k+1) 0 in

  a.(0).(0) <- 1;

  let count = ref 0 in

  let rec pass i =
    (* job is to fill in the i+1 st position and continue *)
    if i+1 > n then () else (
      for s=0 to n do
	for v = 1 to k do
	  if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) ++ a.(i).(s);
	  b.(i+1).(s+v) <- b.(i+1).(s+v) ++ b.(i).(s);
	  if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) ++ a.(i).(s);
	done
      done;
      count := !count ++ b.(i+1).(n);
      pass (i+1)
    )
  in

  pass 0;

  printf "%d\n" !count

open Printf
open String
open Bigarray
open Num

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

let dp = Array.init (n1+2) (fun _ -> Array.make 3 (num_of_int (-10)) )

let modn = num_of_int 1000000007

let rec ways n flag =
  if n=  0 then
    if flag=1 then num_of_int 1
    else num_of_int 0
  else if n< 0 then
    num_of_int 0
  else
    begin
      let x = dp.(n).(flag) in
      if x >=/ num_of_int 0 then
        x
      else
        begin
          let cnt = ref (num_of_int 0) in
          for i = 1 to d-1 do
            cnt := !cnt +/ (ways (n-i) flag)
          done;
          for i = d to k do
            cnt := !cnt +/ (ways (n-i) 1)
          done; cnt:=mod_num !cnt modn; dp.(n).(flag)<- !cnt; !cnt
        end
    end

let rslt = ways n1 0

let _ = printf "%s\n" (string_of_num rslt)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      let t = 2L * run (n-1L) mod modulo in
      if n <= up then t else
      (t - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else LL.((run n + modulo) mod modulo)

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) + modulo) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

open Printf
open Scanf

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

let mm = 1000000007L

let ( ++ ) a b =
  let a = Int64.of_int a in
  let b = Int64.of_int b in
  let ans = Int64.rem (Int64.add a b) mm in
  Int64.to_int ans

let () =
  let n = read_int () in
  let k = read_int () in
  let d = read_int () in

  let a = Array.make_matrix (n+1) (n+k+1) 0 in
  let b = Array.make_matrix (n+1) (n+k+1) 0 in

  a.(0).(0) <- 1;

  let count = ref 0 in

  let rec pass i =
    (* job is to fill in the i+1 st position and continue *)
    if i+1 > n then () else (
      for s=0 to n do
	for v = 1 to k do
	  if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) + a.(i).(s);
	  b.(i+1).(s+v) <- b.(i+1).(s+v) + b.(i).(s);
	  if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) + a.(i).(s);
	done
      done;
      count := !count ++ b.(i+1).(n);
      pass (i+1)
    )
  in

  pass 0;

  printf "%d\n" !count

open Printf
open String
open Bigarray

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

let dp = Array.init (n1+2) (fun _ -> Array.make 3 (-10) )

let rec ways n flag =
  if n= 0 then
    if flag=1 then 1
    else 0
  else if n<0 then
    0
  else
    begin
      let x = dp.(n).(flag) in
      if x >=0 then
        x
      else
        begin
          let cnt = ref 0 in
          for i = 1 to d-1 do
            cnt := !cnt + (ways (n-i) flag)
          done;
          for i = d to k do
            cnt := !cnt + (ways (n-i) 1)
          done; dp.(n).(flag)<- !cnt; !cnt
        end
    end

let rslt = ways n1 0

let _ = printf "%d\n" rslt

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      let t = 2L * run (n-1L) mod modulo in
      if n <= up then t else
      (t - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      if up < 1L then 0L else
      if n <= up then 2L * run (n-1L) mod modulo else
      (2L * run (n-1L) - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let read_int64 () =
  let digit c = Int64.of_int( int_of_char c - 48 )in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (Int64.add (Int64.mul 10L n) (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then Int64.neg (read (digit c)) else run c
    end else
    if c = '\000' then 0L else
    run (read_char())
  in
  run (read_char())

module LL = struct
  include Int64
  let (+) a b = add a b
  let (-) a b = sub a b
  let ( * ) a b = mul a b
  let (/) a b = div a b
  let (mod) a b = rem a b
  let (land) a b = logand a b
  let (lor) a b = logor a b
  let (lxor) a b = logxor a b
  let (lnot) a = lognot a
end

let modulo = 1_000_000_007L

let isum n up =
  let arr = make (LL.to_int n + 1) (-1L) in
  let read n = arr.(LL.to_int n) in
  let save n v = arr.(LL.to_int n) <- v; v in

  let rec run (n: int64) = LL.(
    if read n <> -1L then read n else
    let ans =
      if n <= 1L then 1L else
      if n <= up then 2L * run (n-1L) mod modulo else
      (2L * run (n-1L) - run (n-1L-up)) mod modulo
    in
    save n ans
  ) in
  if up = 0L then 0L else run n

let _ =
  let n = read_int64() in
  let k = read_int64() in
  let d = read_int64() in
  let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in
  printf "%s\n" (LL.to_string ans)

(* let _ =
  for i = 0 to 10 do
    let i = LL.of_int i in
    printf "%s\n" (LL.to_string (isum i i))
  done *)

(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)

open Printf
open Scanf
open Array

module S = String
module Q = Queue
module T = Stack
module H = Hashtbl
module L = List

(* misc *)
let neg_compare x y = - compare x y
let min3 a b c = min a (min b c)
let mid3 a b c = if a < b then max a (min b c) else max b (min a c)
let max3 a b c = max a (max b c)
let min4 a b c d = min (min a b) (min c d)
let max4 a b c d = max (max a b) (max c d)
let itb a = a <> 0
let bti b = if b then 1 else 0
let rec bsearch_min a b test =
  if b - a = 1 then b else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_min a mid test else
  bsearch_min mid b test
let rec bsearch_max a b test =
  if b - a = 1 then a else
  let mid = (a-b)/2 + b in
  if test mid then bsearch_max mid b test else
  bsearch_max a mid test
(* int *)
let sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)
let sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i)
(* float *)
let round f = truncate (f +. 0.5)
let inv_float f = 1. /. f
(* functional *)
let id x = x
let const x _ = x
let (|>) x f = f x
let (^>) x f = f x
let (@@) a b = a b
let on g f a b = g (f a) (f b)
let rec fix f = f (fun x -> fix f x)
let ift cond a = if cond then a
let ifte cond a b = if cond then a else b
let rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f
(* predicate *)
let is_odd x = x land 1 = 1
let is_even x = x land 1 = 0
(* option *)
let is_none = function | Some _ -> false | None -> true
let is_some = function | Some _ -> true | None -> false
let default x = function Some y -> y | None -> x
(* ref *)
let (+=) a b = a := !a + b
let (-=) a b = a := !a - b
let ( *= ) a b = a := !a * b
let assign_min x y = x := min !x y
let assign_max x y = x := max !x y
(* array *)
let set_min x i v = x.(i) <- min x.(i) v
let set_max x i v = x.(i) <- max x.(i) v
let swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t
(* int, int *)
let (++) (a,b) (c,d) = (a+c,b+d)
let (--) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 128 in
  let rec read c =
    if is_space c || c = '\000' then contents buf else begin
      add_char buf c;
      read (read_char())
    end
  in
  let rec run c =
    if is_space c then run (read_char()) else
    if c = '\000' then "" else
    read c
  in
  run (read_char())
let read_line () =
  let open Buffer in
  let buf = create (4*1024) in
  let rec run c =
    if c = '\n' || c = '\000' then contents buf else begin
      add_char buf c;
      run (read_char())
    end
  in
  run (read_char())
let newline () = print_newline()
let print_int n = printf "%d\n" n
let print_tuple s (x,y) = printf s x y
let print_array s arr = Array.iter (printf s) arr; print_newline()
let print_matrix s mat = Array.iter (print_array s) mat
let print_list s lis = List.iter (printf s) lis; print_newline()
;;

let isum n up =
  let rec run n =
    if n <= 1 then 1 else
    if n <= up then 2 * run (n-1) else
    2 * run (n-1) - run (n-1-up)
  in
  run n

let _ =
  let n = read_int() in
  let k = read_int() in
  let d = read_int() in
  let ans = isum n k - isum n (d-1) in
  printf "%d\n" ans


Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

open Printf
open Scanf

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

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

  let test b =
  (* does the range [2...b] work *)
    let mult6 = b/6 in
    let mult2 = b/2 - mult6 in
    let mult3 = b/3 - mult6 in
    (max 0 (n - mult2)) + (max 0 (m - mult3)) <= mult6
  in

  let rec bsearch lo hi =
  (* lo fails, hi works *)
    if lo+1 = hi then hi else
      let mid = (lo + hi)/2 in
      if test mid then bsearch lo mid else bsearch mid hi
  in

  let answer = bsearch 1 10_000_000 in

  printf "%d\n" answer


Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.So they play with each other according to following rules:  Alex and Bob play the first game, and Carl is spectating;  When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner. Alex, Bob and Carl play in such a way that there are no draws.Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!

The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played. Then n lines follow, describing the game log. i-th line contains one integer ai (1 ≤ ai ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.

Print YES if the situation described in the log was possible. Otherwise print NO.

NoteIn the first example the possible situation is:  Alex wins, Carl starts playing instead of Bob;  Alex wins, Bob replaces Carl;  Bob wins. The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let n = scan_int() and gra = ref 1 and pom = ref 0 and gra2 = ref 2  and siedzi = ref 3 and czy = ref 1 in
begin
for i = 1 to n do
	let x= scan_int() in
      if x = !siedzi then czy := 0
      else if !gra = x then begin pom:= !siedzi; siedzi := !gra2; gra2 := !pom end
           else begin pom := !siedzi; siedzi := !gra; gra := !pom end
done;
if !czy = 1 then print_string("YES")
else print_string("NO")
end

let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";;
let b2i x = if x == true then 1 else 0;;

let n = scan_int();;
let stan = ref 3;;
let wyn = ref 1;;

for i = 0 to (n - 1) do
  let x = scan_int() in
  if((1 lsl (x - 1)) land (!stan) == 0) then wyn := 0;
  stan := (!stan - (1 lsl (x - 1))) lxor 7;
done;

if !wyn = 1 then print_string("YES") else print_string("NO");;

open Printf
open Scanf

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

  let rec loop (x,y) i = if i=n then true else (
    let z = 6 - x - y in
    if w.(i) = x then loop (x,z) (i+1)
    else if w.(i) = y then loop (y,z) (i+1)
    else false
  ) in

  if loop (1,2) 0 then printf "YES\n" else printf "NO\n"


Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:  on this day the gym is closed and the contest is not carried out;  on this day the gym is closed and the contest is carried out;  on this day the gym is open and the contest is not carried out;  on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:    ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;  ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;  ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;  ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:   to do sport on any two consecutive days,  to write the contest on any two consecutive days.

NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

open Printf

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act =
  match (d, act) with
  | (A, Sport) -> false
  | (A,  Test) -> false
  | (B, Sport) -> false
  | (C,  Test) -> false
  | (_,     _) -> true

type rmin = { mutable rest : int; mutable sport : int; mutable test : int};;

  (*Note: should not use Array.make here*)
let r = Array.init (n+1) (fun i ->
                     {rest = max_int; sport = max_int; test = max_int });;

let () = r.(0) <- {rest = 0; sport = 0; test = 0};;

let () =
  for i = 1 to n
  do
    let x = r.(i-1).sport in
    let y = r.(i-1).test in
    let z = r.(i-1).rest in
    begin
      if (act_poss a.(i-1) Rest) then
        let w = min x (min y z) in
        if(w<max_int) then r.(i).rest <- (w+1);
      if (act_poss a.(i-1) Sport) then r.(i).sport<- (min y z);
      if (act_poss a.(i-1) Test) then  r.(i).test <- (min x z)
    end;
    (* printf "-- %d %d %d\n" r.(i).rest r.(i).sport r.(i).test *)
  done;;

let () =  printf "%d\n" ( min r.(n).test (min r.(n).rest r.(n).sport ));;

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

let () =
    let n = read_int () in
    let a = Array.init (n + 1) (fun i -> if i = 0 then 0 else read_int ())
    and dp = Array.make_matrix (n + 1) 4 1000000000 in
    dp.(0).(0) <- 0;
    for i = 1 to n do
        dp.(i).(0) <- 1 + (min dp.(i - 1).(0) (min dp.(i - 1).(1) dp.(i - 1).(2)));
        if a.(i) = 1 || a.(i) = 3 then
            dp.(i).(1) <- min dp.(i - 1).(0) dp.(i - 1).(2);
        if a.(i) = 2 || a.(i) = 3 then
            dp.(i).(2) <- min dp.(i - 1).(0) dp.(i - 1).(1)
    done;
    printf "%d\n" (min dp.(n).(0) (min dp.(n).(1) dp.(n).(2)))

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act =
  match (d, act) with
  | (A, Sport) -> false
  | (A,  Test) -> false
  | (B, Sport) -> false
  | (C,  Test) -> false
  | (_,     _) -> true

type rmin = { mutable rest : int; mutable sport : int; mutable test : int};;

  (*Note: should not use Array.make here*)
let r = Array.init (n+1) (fun i ->
                     {rest = max_int; sport = max_int; test = max_int });;

let () = r.(0) <- {rest = 0; sport = 0; test = 0};;

let () =
  for i = 1 to n
  do
    let x = r.(i-1).sport in
    let y = r.(i-1).test in
    let z = r.(i-1).rest in
    begin
      if (act_poss a.(i-1) Rest) then
        let w = min x (min y z) in
        if(w<max_int) then r.(i).rest <- (w+1);
      if (act_poss a.(i-1) Sport) then r.(i).sport<- (min y z);
      if (act_poss a.(i-1) Test) then  r.(i).test <- (min x z)
    end;
    (* printf "-- %d %d %d\n" r.(i).rest r.(i).sport r.(i).test *)
  done;;

let () =  Printf.printf "%d\n" ( min r.(n).test (min r.(n).rest r.(n).sport ));;

open Printf

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

let n = read_int ()

type action = Rest | Test | Sport | None;;
type day = A | B | C | D;; (* 0, 1, 2, 3*)

let itoa = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | 3 -> D

let a = Array.init n (fun i -> (read_int () |> itoa))

let act_poss d act p_act =
  match (d, act, p_act) with
  | (A, Sport,     _) -> false
  | (A,  Test,     _) -> false
  | (B, Sport,     _) -> false
  | (B,  Test,  Test) -> false
  | (C,  Test,     _) -> false
  | (C, Sport, Sport) -> false
  | (D, Sport, Sport) -> false
  | (D,  Test,  Test) -> false
  | (_,     _,     _) -> true

let r = Array.make (n+1) max_int;;

let () = r.(0) <- 0 in
let act = Array.make (n+1) None in
let () = act.(0) <- Rest in
let () =
  for i = 1 to n
  do
    if (act_poss a.(i-1) Rest act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1)+1 ) then
          begin
            act.(i) <- Rest;
            r.(i) <- r.(i-1) + 1
          end
      end;
    if (act_poss a.(i-1) Test act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1) ) then
          begin
            act.(i) <- Test;
            r.(i) <- r.(i-1)
          end
      end;
    if (act_poss a.(i-1) Sport act.(i-1) ) then
      begin
        if ( r.(i) > r.(i-1) ) then
          begin
            act.(i) <- Sport;
            r.(i) <- r.(i-1)
          end
      end;
  done in ()
;;

let () = printf "%d\n" r.(n);;


The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.

The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.

Print a single integer — the least possible difference the teacher can obtain.

NoteSample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.

let (no_of_ppl, no_of_puzzles) = Scanf.scanf "%d %d " (fun n m -> n, m)

let read m =
    let rec loop list m =
    if m > 0
    then
        let var = Scanf.scanf "%d " (fun v -> v) in
        loop (var :: list) (m - 1)
    else
        list
    in loop [] no_of_puzzles

let sort list = List.sort(Pervasives.compare) (List.rev list)

let find_min list n m =
    let rec traverse i min =
    if i + n - 1< m
    then
        let dif = List.nth list (i + n - 1) - List.nth list i in
        if dif < min
        then
            traverse (i + 1) dif
        else
            traverse (i + 1) min
    else
        min
    in traverse 0 1000

let solve (no_of_ppl, no_of_puzzles) = find_min (sort (read no_of_puzzles)) no_of_ppl no_of_puzzles

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

let () = print (solve (no_of_ppl, no_of_puzzles))

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let ans = ref 1001 in
  let n   = read_int () in
  let m   = read_int () in
  let lst = List.sort compare (parse_list m) in
  for k = 0 to m-n do
    let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in
    ans := min !ans diff
  done;
  print_int !ans

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let b = ref 1001 in
  let n = read_int () in
  let m = read_int () in
  let lst = parse_list m in
  let sorted_lst = List.sort compare lst in
  for k = 0 to m-n do
    let diff = (List.nth sorted_lst (k + n - 1)) - (List.nth sorted_lst k) in
    b := min !b diff
  done;
  print_int !b

let (n, m) = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
let p = Array.make m 0 in
for i = 0 to m - 1 do
    Scanf.scanf "%d%[ ]" (fun x _ -> p.(i) <- x)
done ;
Array.sort compare p ;
let b = ref max_int in
for i = 0 to m - n do
    b := min !b (p.(i + n - 1) - p.(i))
done ;
Printf.printf "%d\n" !b ;;

open Scanf;;
open String;;

let n = bscanf Scanning.stdin "%d " (fun x -> x);;
let m = bscanf Scanning.stdin "%d " (fun x -> x);;

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = bscanf Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + n-1) <= (m-1) do
    let diff =  p.(!i+n-1) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;

open Scanf;;
open String;;

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

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + n-1) <= (m-1) do
    let diff =  p.(!i+n-1) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;

let (n, m) = Scanf.scanf "%d %d\n" (fun n m -> n, m) in

let a = Array.make m 0 in
for i = 0 to m - 1 do
    Scanf.scanf "%d%[ ]" (fun x _ -> a.(i) <- x)
done ;

Array.sort compare a ;

let ans = ref max_int in
for i = 0 to m - n do
    ans := min !ans (a.(i + n - 1) - a.(i))
done ;

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

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

let parse_list (n : int) : (int list) =
  let rec parse_list_helper acc = function
    | 0 -> acc
    | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)
  in
    parse_list_helper [] n

let () =
  let ans = ref 1001 in
  let n   = read_int () in
  let m   = read_int () in
  let lst = List.sort compare (parse_list m) in
  for k = 1 to m-n do
    let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in
    ans := min !ans diff
  done;
  print_int !ans

open Scanf;;
open String;;

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

let p = Array.init m (fun x -> 0);;

for i=0 to m-1 do
  let  f = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x)   in
  p.(i) <- f
done;;

(*Sort the array ascendingly*)
Array.sort (fun x y ->  x-y ) p;;

(*Test the sorting result
Array.iter (fun x -> Printf.printf "%d " x)  p;;
*)

let i = ref 0 in
let maxdiff = ref  max_int in
let () =
  while (!i + 3) <= (m-1) do
    let diff =  p.(!i+3) -p.(!i) in
    if ( diff < !maxdiff) then  maxdiff := diff ;
    i := !i + 1
  done in
print_int !maxdiff; print_endline ""
;;


Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:   deletes all the vowels,  inserts a character "." before each consonant,  replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.

The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.

Print the resulting string. It is guaranteed that this string is not empty.

let _ =
    let main () =
        let conv k =
            let s = String.lowercase k in

            let rec loop i acc =
                if i < 0 then acc else
                    let k = try String.index "aoyeui" s.[i] with _ -> -1 in
                    loop (i - 1) (if k >= 0 then acc else s.[i] :: acc)
            in
            loop (String.length s - 1) []
        in
        let s = read_line () in
        let result = conv s in
        List.iter (Printf.printf ".%c") result;
        print_newline ()
    in
    main ()

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

let word = Scanf.scanf "%s" (fun word -> str_to_list (String.lowercase(word)))

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

let remove_vowels l = List.filter(fun char -> is_consonant char) l

let add_dot = (fun l -> List.concat(List.map(fun char -> ['.'; char]) l))

let () = List.iter(Printf.printf "%c") (add_dot(remove_vowels word))

String.iter (fun c ->
	if not (c = 'a' || c = 'o' || c = 'y' || c = 'e' || c = 'u' || c = 'i') then
		(print_char '.'; print_char c)
) (String.lowercase (read_line()));;

let stringToList str =
  let rec loop idx str =
    let len = String.length(str) in
    if idx >= len then
      []
    else
      str.[idx] :: loop (idx+1) str in
  loop 0 str;;

let isConsonant ch =
  match ch
  with 'a'|'o'|'y'|'e'|'u'|'i' -> false
  | _ -> true;;

let printWithDot ch =
  Printf.printf ".%c" ch;;

let _ =
  let line = read_line() in
  let l = stringToList (String.lowercase line) in
  List.map printWithDot (List.filter isConsonant l) in
  print_newline()

let s=read_line();;
let rec op t=
if t="" then [] else t.[0]::(op (String.sub t 1 (String.length(t)-1)));;
let l=op s;;
let letter char= match char with
| 'a' | 'e' | 'i' | 'o' | 'u' | 'y'
   | 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' ->()
|'a'..'z'->print_string ".";print_char char
|'A'..'Z'->print_string ".";print_char (Char.chr(int_of_char(char)+32))
|_->();;
let rec doo=function
|[]->()
|h::t->letter h;doo t;;
doo l;;

let do_it c =
	match c with
	'a'|'o'|'y'|'e'|'u'|'i'|'A'|'O'|'Y'|'E'|'U'|'I' -> c
	|_ -> print_string ("." ^ String.make 1 c); c
;;

String.map do_it (String.lowercase (read_line()))

let str=String.lowercase(read_line());;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

let atr=read_line();;
let str=String.lowercase(atr);;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

let consonants s =
  let regex_vowel = Str.regexp "[aeiouy]" in
  let vowel_deleted = Str.split regex_vowel (String.lowercase s)
  in
  String.concat "" vowel_deleted
;;

let () =
  Scanf.scanf "%s" (fun s -> String.iter (fun c -> Printf.printf ".%c" c)
                                         (consonants s));
  print_newline ()
;;

open Scanf
open Num
open Printf
open String

let s = Scanf.bscanf Scanf.Scanning.stdin "%s " ( fun x -> x) |> String.lowercase

let explode s =
  let r = ref [] in
  for i = 0 to (length s - 1) do
    let c = String.get s i in
    r := !r@[c]
  done; !r
;;

let is_vowel = function
  | 'a' -> true
  | 'o' -> true
  | 'y' -> true
  | 'e' -> true
  | 'u' -> true
  | 'i' -> true
  | _ -> false

let l = ( explode s
  |> List.filter (fun x -> (not (is_vowel x)) )
  );;

List.iter (fun x -> print_string ("."^(String.make 1 x)) ) l; print_endline "";;

let solve =
  let s = read_line () in
    let terminated_s = s ^ "." in
      let rec parse_string i = match terminated_s.[i] with
        | '.' -> print_string "\n"
        | 'a' | 'o' | 'y' | 'e' | 'u' | 'i'
        | 'A' | 'O' | 'Y' | 'E' | 'U' | 'I' -> parse_string (i+1)
        | c when c >= 'A' && c <= 'Z' ->
          print_char '.'; print_char (Char.lowercase c); parse_string (i+1)
        | c -> print_char '.'; print_char c; parse_string (i+1)
      in parse_string 0; ()

let () = solve

let vowels = 'a'::'i'::'u'::'e'::'o'::'y'::[]

let petya c =
    let lower = Char.lowercase c in
    if List.exists (fun x -> x = lower) vowels then ()
    else Printf.printf ".%c" lower

let main () =
    let gr () = Scanf.scanf "%s\n" (fun i -> i) in
    let str = gr () in
    let () = String.iter petya str in
    Printf.printf("\n")
;;

let _ = main();;

open String;;
open Printf;;
open Scanf;;
open Char;;

let convert ch =
  match ch with
  |'a'|'e'|'u'|'i'|'o'|'y'
  |'A'|'E'|'U'|'I'|'O'|'Y' -> None
  |_ -> Some ("." ^ String.make 1 (Char.lowercase ch))

let rec process inp =
  let res = ref "" in
  for i = 0 to length inp - 1 do
    let ch = convert inp.[i] in
    match ch with
    | Some x -> res := (!res ^ x)
    | None -> ()
  done;
  !res

let () =
  let inp = read_line () in
  printf "%s\n" (process inp)
  ;;

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

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

exception Error of string

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

let f s =
  let t = Char.lowercase s in
  if List.memq t ['a'; 'i'; 'u'; 'e'; 'o'; 'y']
  then ""
  else "." ^ Char.escaped t
;;

let _ =
  let str = read_line() in
  let res = ref "" in
  for i = 0 to String.length str - 1 do
    res := !res ^ f str.[i]
  done;
  print_endline !res
;;

let atr=read_line();;
let str=String.lowercase(atr);;
let ans= ref "" ;;
for i=1 to String.length(str) do
    let va= str.[i-1] in
    if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)
done;;
print_endline(!ans)

let vowels = 'a'::'i'::'u'::'e'::'o'::[]

let petya c =
    let lower = Char.lowercase c in
    if List.exists (fun x -> x = lower) vowels then ()
    else Printf.printf ".%c" lower

let main () =
    let gr () = Scanf.scanf "%s\n" (fun i -> i) in
    let str = gr () in
    let () = String.iter petya str in
    Printf.printf("\n")
;;

let _ = main();;


Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.

A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.

Output the given word after capitalization.

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

let solve input = String.capitalize input

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

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

let () =
  let s = read_line () in
  let len = String.length s in
  let head = String.sub s 0 1 in
  let tail = String.sub s 1 (len - 1)
  in
  print_endline (String.uppercase head ^ tail);;

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

let () = read_int () |> String.capitalize
|> print_endline ;;

(* Codeforces 281A *)

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%s" (fun s -> String.capitalize s))

open Printf

let main =
    let s = read_line() in
    let h = s.[0] in
    let t = String.sub s 1 ((String.length s) - 1) in

    printf "%c%s\n" (Char.uppercase h) t;

let () =
  let s = read_line() in
  let isupper c = int_of_char c <= int_of_char 'Z' && int_of_char c >= int_of_char 'A' in
    if not (isupper s.[0]) then
      s.[0] <- char_of_int ((int_of_char s.[0]) + (int_of_char 'A') - (int_of_char 'a'));

    Printf.printf "%s\n" s


In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East".Limak isn’t sure whether the description is valid. You must help him to check the following conditions:  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.  The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

5
7500 South
10000 East
3500 North
4444 West
4000 North

4
50 South
50 North
15000 South
15000 North

NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.

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

let ( $ ) f x = f x

let main () =
  let n = ref (read_int ()) in
  let cur = ref 0 in
  let fail = ref false in
  let t = ref 0 in
  let str = ref "" in
  for i = 1 to !n do
    fail := !fail || not(0 <= !cur && !cur <= 20000);
    t := read_int ();
    str := read_string ();
    if !str = "North" then
      cur := !cur - !t
    else if !str = "South" then
      cur := !cur + !t
    else if (!str = "East" || !str = "West") && (!cur = 0 || !cur = 20000) then
      fail := true

  done;
  Printf.printf (if not !fail && !cur = 0 then "YES" else "NO")

let () = main ()

open Printf
open Scanf

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

let () =
  let n = read_int () in

  let rec loop i x = if i=n then x=0 else
      let t = read_int() in
      match (read_string()) with
	| "South" ->
	  let x = x + t in
	  if x > 20_000 then false
	  else loop (i+1) x
	| "North" ->
	  let x = x - t in
	  if x < 0 then false
	  else loop (i+1) x
	| _ ->
	  if x = 0 || x = 20_000 then false
	  else loop (i+1) x
  in

  if loop 0 0 then printf "Yes\n" else printf "No\n"


A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output "YES", if the string is a pangram and "NO" otherwise.

let n = int_of_string (input_line stdin);;
let s = input_line stdin;;
let a = Array.make 26 false;;

for i = 0 to n - 1 do
  a.(Char.code (Char.lowercase s.[i]) - Char.code 'a') <- true;
done;;

if List.mem false (Array.to_list a) then print_string "NO"
else print_string "YES";;
print_newline ();;

let input () =
    let total = Scanf.scanf "%d " (fun n -> n) in
    let rec read i list =
        if i < total
        then
            let char = Char.lowercase (Scanf.scanf "%c" (fun c -> c)) in
            read (i + 1) (char :: list)
        else
            list
    in read 0 []

let rec get_uniques = function
    | head :: (middle :: _ as tail) ->
        if head = middle
        then
            get_uniques tail
        else
            (head :: get_uniques tail)
    | smaller -> smaller

let solve list =
    let uniques = List.length (get_uniques (List.sort(Pervasives.compare) list)) in
    if uniques = 26
    then
        "YES"
    else
        "NO"

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

let answer s n =
  let a = Array.make 26 false in
  for i = 0 to n-1 do
    let c = Char.code s.[i] in
    if c >= 97 then a.(c-97) <- true
    else a.(c-65) <- true
  done;
  let b = ref true in
  for i = 0 to 25 do
    b := !b && a.(i)
  done;
  if !b then print_endline "YES" else print_endline "NO"

let () =
  let n = int_of_string (read_line ()) in
  let s = read_line () in
  answer s n


Find the minimum number with the given sum of digits $$$s$$$ such that all digits in it are distinct (i.e. all digits are unique).For example, if $$$s=20$$$, then the answer is $$$389$$$. This is the minimum number in which all digits are different and the sum of the digits is $$$20$$$ ($$$3+8+9=20$$$).For the given $$$s$$$ print the required number.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 45$$$) — the number of test cases. Each test case is specified by a line that contains the only integer $$$s$$$ ($$$1 \le s \le 45$$$).

Print $$$t$$$ integers — the answers to the given test cases.

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

let run_case = function
| n ->
    let rec get_digits = function
    | (x, c) ->
         if (x<10) then begin
             if (x<=c) then [x]
             else c::get_digits((x-c),(c-1))
         end
         else c::get_digits((x-c),(c-1))
     in
     let ds = get_digits (n, 9) in
     List.iter (fun x-> print_int x) (List.rev ds);
     print_newline ()
;;

let rec iter_cases = function
| 0 -> ()
| t ->
     let n = read_int () in
     run_case (n);
     iter_cases (t-1)
;;

let c = read_int () in iter_cases (c);;


Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.

The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.

Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.

open String;;
open Char;;

let check = fun s ->
let fhc = get s 0 and shc = get s 1
and fmc = get s 3 and smc = get s 4 in
let fh = code (get s 0) - 48 and sh = code (get s 1) - 48
and fm = code (get s 3) - 48 and sm = code (get s 4) - 48 in
let minutes = fm * 10 + sm
and potential_minutes = sh *  10 + fh in
if fh < 2 then
        if sh > 5 || (sh = 5 && minutes >= 50 + fh) then
                begin
                        print_int (fh + 1);
                        print_string "0:0";
                        print_int (fh + 1)
                end

        else if minutes < potential_minutes then begin
                print_int fh;
                print_int sh;
                print_string ":";
                print_int sh;
                print_int fh;
        end
        else begin
                print_int fh;
                print_int (sh + 1);
                print_string ":";
                print_int (sh + 1);
                print_int fh;
        end
else (* fh = 2 *)
        if sh = 3 && minutes >= 32 then print_string "00:00"
        else   begin
                print_int fh;
                print_int sh;
                print_string ":";
                print_int sh;
                print_int fh;
        end
;;

Scanf.scanf "%s" (check);;


You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.

The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Print the number of ways to choose a suitable problemset for the contest.

NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

let rec f = function
	| t::q	-> let lis = f q in
			(List.map (fun (sum,min,max) ->
					if sum = 0
						then (t,t,t)
						else (t+sum,t,max))
				lis)@lis
	| []	-> [0,0,0]

let () =
	let (n,l,r,x) = Scanf.scanf "%d %d %d %d" (fun i j k l -> (i,j,k,l)) and lis = ref [] in
	for i = 1 to n do
		Scanf.scanf " %d" (fun i -> lis := i::!lis);
	done;
	Printf.printf "%d" (List.length (List.filter (fun (i,j,k) -> i >= l && i <= r && k-j >= x) (f (List.sort compare !lis))))


Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

Output one integer — the answer to the problem.

NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]

let _ =
  let n = Scanf.scanf " %d" (fun i -> i) in
  Printf.printf "%d\n" (n / 2 + 1)


Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.

First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning. Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.

Print the only integer — maximum number of liters of kefir, that Kolya can drink.

NoteIn the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.

open Printf
open Scanf

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

let long x = Int64.of_int x

let ceil x y = (x++y--1L)//y
let floor x y = x//y

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

let () =
  let n = read_long () in
  let a = read_long () in
  let b = read_long () in
  let c = read_long () in

  let answer =
    if a <= b--c || n < b then (
      floor n a
    ) else (
      let k1 = ceil (n--b++1L) (b--c) in
      let n' = n -- k1 ** (b--c) in
      let k2 = floor n' a in
      k1 ++ k2
    )
  in

  printf "%Ld\n" answer

open Printf
open Scanf

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

let long x = Int64.of_int x

let ceil x y = (x++y--1L)//y
let floor x y = x//y

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

let () =
  let n = read_long () in
  let a = read_long () in
  let b = read_long () in
  let c = read_long () in

  let answer =
    if a <= b--c then (
      floor n a
    ) else (
      let k1 = ceil (n--b++1L) (b--c) in
      let n' = n -- k1 ** (b--c) in
      let k2 = floor n' a in
      k1 ++ k2
    )
  in

  printf "%Ld\n" answer

open Printf
open Scanf

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

let long x = Int64.of_int x

let ceil x y = (x++y--1L)//y
let floor x y = x//y

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

let () =
  let n = read_long () in
  let a = read_long () in
  let b = read_long () in
  let c = read_long () in

  let answer =
    if a <= b--c then (
      floor n a
    ) else (
      let k1 = floor (n--b) (b--c) in
      let n = n -- (k1 ** (b--c)) in

      let rec loop n k = if n < b then (n,k) else loop (n--b++c) (k++1L) in
      let (n,k2) = loop n 0L in
      let k3 = floor n a in
      k1 ++ k2 ++ k3
    )
  in

  printf "%Ld\n" answer

open Printf
open Scanf

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

let long x = Int64.of_int x

let ceil x y = (x++y--1L)//y
let floor x y = x//y

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

let () =
  let n = read_long () in
  let a = read_long () in
  let b = read_long () in
  let c = read_long () in

  let answer =
    if a <= b--c then (
      floor n a
    ) else (
      let k1 = ceil (n--b) (b--c) in
      let n = n -- (k1 ** (b--c)) in
      let (n,k2) = if n >= b then (n--b++c, 1L) else (n,0L) in
      let k3 = floor n a in
      k1 ++ k2 ++ k3
    )
  in

  printf "%Ld\n" answer


There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.   Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.

The single line of input contains one integer n (0  ≤  n  ≤  109).

Print single integer — the last digit of 1378n.

NoteIn the first example, last digit of 13781 = 1378 is 8.In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.

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

let solve n =
    if n = 0
    then
        1
    else
        match (n mod 4) with
        | 1 -> 8
        | 2 -> 4
        | 3 -> 2
        | 4 | 0 -> 6

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

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

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let answer = if n=0 then 1 else [|6;8;4;2|].(n mod 4) in
  printf "%d\n" answer


Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.Help Mister B to calculate how many days he needed to finish the book.

First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.

Print one integer — the number of days Mister B needed to finish the book.

NoteIn the first sample test the book contains 5 pages, so Mister B read it right at the first day.In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.

open Printf
open Scanf

let read_5 _ = bscanf Scanning.stdib " %d %d %d %d %d " (fun a b c d e -> (a,b,c,d,e))
let () =
  let (c,v0,v1,a,l) = read_5() in

  let rec read current_page d =  (* d = days already spent reading *)
    if current_page >= c then d
    else
      let new_page = (max (current_page - l) 0) + (min (v0 + (d*a)) v1) in
      read new_page (d+1)
  in
  printf "%d\n" (read 0 0)

open Printf
open Scanf

let read_5 _ = bscanf Scanning.stdib " %d %d %d %d %d " (fun a b c d e -> (a,b,c,d,e))
let () =
  let (c,v0,v1,a,l) = read_5() in

  let rec read current_page d =  (* d = days already spent reading *)
    if current_page >= c then d
    else
      let new_page = (max (current_page - l) 0) + v0 + (d*a) in
      read new_page (d+1)
  in
  printf "%d\n" (read 0 0)


Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:  1+2*3=7  1*(2+3)=5  1*2*3=6  (1+2)*3=9 Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.It's easy to see that the maximum value that you can obtain is 9.Your task is: given a, b and c print the maximum value that you can get.

The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).

Print the maximum value of the expression that you can obtain.

let input = Scanf.scanf "%d %d %d" (fun a b c -> (a, b, c))

let get_max (a, b, c)=
    List.fold_left (Pervasives.max) 0
        [a * (b + c);
        (a + b) * c;
        a * b * c;
        a * b + c;
        a + b * c;
        a + b + c]

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

let () = print (get_max (input))

let () =
let a,b,c = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in
Printf.printf "%d\n" @@
List.fold_left max 0
[
a+b+c;
a * b * c;
(a+b) * c;
a+(b * c);
(a * b)+c;
a * (b+c);
]


Alice and Bob are playing a game with $$$n$$$ piles of stones. It is guaranteed that $$$n$$$ is an even number. The $$$i$$$-th pile has $$$a_i$$$ stones.Alice and Bob will play a game alternating turns with Alice going first.On a player's turn, they must choose exactly $$$\frac{n}{2}$$$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $$$\frac{n}{2}$$$ nonempty piles).Given the starting configuration, determine who will win the game.

The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the number of piles. It is guaranteed that $$$n$$$ is an even number. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$) — the number of stones in the piles.

Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).

NoteIn the first example, each player can only remove stones from one pile ($$$\frac{2}{2}=1$$$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.In the second example, Alice can remove $$$2$$$ stones from the first pile and $$$3$$$ stones from the third pile on her first move to guarantee a win.

open Printf
open Scanf

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

let () =
  let n = read_int () in
  let a = Array.init n read_int in
  Array.sort compare a;

  if a.(n/2) = a.(0) then printf "Bob\n" else printf "Alice\n"


The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.

The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.

In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).

let (|>) x f = f x

exception Bug

let () =
  let ds = ['U',(-1,0); 'R',(0,1); 'D',(1,0); 'L',(0,-1)] in
  let a = ref (0,0) in
  let h = Hashtbl.create 100 in
  Hashtbl.add h !a ();
  (try
    read_line () |> String.iter (fun c ->
      let xx,yy = List.assq c ds in
      let a' = fst !a + xx, snd !a + yy in
      let z = List.map snd ds |> List.fold_left (fun z (xx,yy) ->
        let a'' = fst a' + xx, snd a' + yy in
        (try Hashtbl.find h a''; z+1 with Not_found -> z)
      ) 0 in
      if z <> 1 || (try Hashtbl.find h a'; true with Not_found -> false) then
        raise Bug;
      a := a';
      Hashtbl.add h a' ();
    );
    "OK"
  with Bug ->
    "BUG")
  |> print_endline

let (|>) x f = f x

let scanl f e s =
  let n = String.length s in
  let rec go i e acc =
    if i >= n then
      acc
    else
      let e' = f e s.[i] in
      go (i+1) e' (e'::acc)
  in go 0 e [e]

let rec uniq = function
  | [] | [_] -> true
  | x::((y::zs) as xs) -> x <> y && uniq xs

let () =
  print_endline (if scanl (fun (x,y) c ->
    let xx,yy = List.assq c ['U',(-1,0); 'R',(0,1); 'D',(1,0); 'L',(0,-1)] in
    x+xx,y+yy) (0,0) (read_line ()) |> List.sort compare |> uniq then "OK" else "BUG")


Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Print a single integer — the answer to the problem.

NoteIn the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

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

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

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

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

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

let () =
  let n, m = sf "%d %d " (fun n m -> n, m) in
  let sock = ref n in
  let i = ref 1 in
  while !sock > 0 do
    epf "i, sock = %d, %d\n" !i !sock;
    decr sock;
    if !i > 1 && !i mod m = 0 then incr sock;
    if !sock > 0 then incr i;
  done;
  pf "%d\n" !i
;;

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

let add socks days m =
    if days mod m = 0
    then
        socks + 1
    else
        socks

let solve (n, m) =
    let rec loop socks days =
        if socks > 0
        then
            loop ((add socks days m) - 1) (days + 1)
        else
            days - 1
    in loop n 1

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