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 ()))


In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.

Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.

Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.

NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.

let data = Array.init 4 (fun i -> read_line () ) ;;

let solve i j = let cnt = ref 0 in
                for ii = 0 to 1 do for jj = 0 to 1 do
                        if (data.(i+ii)).[j+jj] = '#' then cnt := !cnt + 1
                 done
                done;
                !cnt <= 1;;

let solve2 i j = let cnt = ref 0 in
                for ii = 0 to 1 do for jj = 0 to 1 do
                        if (data.(i+ii)).[j+jj] = '.' then cnt := !cnt + 1
                 done
                done;
                !cnt <= 1;;

(*for i = 0 to 3 do print_endline data.(i) done;;*)

let flag = ref false;;

for i = 0 to 2 do
        for j = 0 to 2 do
                flag := !flag || solve i j || solve2 i j
        done
done;;

if !flag = false then print_string "NO\n"
else print_string "YES\n";;

(* Codeforces 103A - UnilShtan *)

open Filename;;

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

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

let rec readlist n acc = match n with
	| 0 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;

let aa = Array.make 4 "";;

let rec readaa i n =
	if i == n then ()
	else (
		aa.(i) <- rdln();
		readaa (i +1) n
	);;

let cntaa ii jj c =
	let cnt = ref 0 in (
		for i = ii to ii +1 do
			for j = jj to jj +1 do
				if aa.(i).[j] == c then
					cnt := !cnt + 1
			done
		done;
		!cnt
	);;

let rec ifiq () =
	let iqok = ref false in
	begin
		for ii = 0 to 2 do
			for jj = 0 to 2 do
				begin
					if (cntaa ii jj '#') >= 3 then iqok := true;
					if (cntaa ii jj '.') >= 3 then iqok := true
				end
			done
		done;
		!iqok
	end;;

let main() =
	begin
		readaa 0 4;
		print_string (if ifiq() then "YES" else "NO")
	end;;

main();;


Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.For example, consider the following string:   This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows:   candy cane 1: remove the letter w,  snowflake 1: repeat the letter p twice,  candy cane 2: leave the letter n,  snowflake 2: remove the letter w,  snowflake 3: leave the letter e.   Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.Andrey knows that messages from Irina usually have a length of $$$k$$$ letters. Help him to find out if a given string can encode a message of $$$k$$$ letters, and if so, give an example of such a message.

The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $$$200$$$. The second line contains an integer number $$$k$$$ ($$$1 \leq k \leq 200$$$), the required message length.

Print any message of length $$$k$$$ that the given string can encode, or «Impossible» if such a message does not exist.

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let a = init (String.length s) (fun i -> s.[i]) in
  let undef = -7 in
  let p,q,r,_ = fold_left (fun (p,q,r,i) -> function
  | '*' -> (List.tl p,   q,i,i+1)
  | '?' -> (List.tl p,i::q,r,i+1)
  |  _  -> (     i::p,   q,r,i+1)
  ) ([],[],undef,0) a in
  let p,q = List.(rev p, rev q) in
  if List.length p = n then
    (List.iter (fun i -> print_char a.(i)) p; exit 0)
  else if List.length p > n then
    (print_string "Impossible"; exit 0);
  let need = n - List.length p in
  let u = ref p in
  if r<>undef then (
    iteri (fun i c ->
      if List.length !u > 0 && List.hd !u = i then (
        print_char a.(i); u := List.tl !u
      ) else if i+1=r then
        for k=1 to need do print_char a.(i) done
    ) a
  ) else (
    if need > List.length q then
      (print_string "Impossible"; exit 0);
    let w = ref q in
    let rest = ref need in
    iteri (fun i c ->
      if List.length !u > 0 && List.hd !u = i then (
        print_char a.(i); u := List.tl !u
      ) else if List.length !w > 0 && List.hd !w = i+1 && !rest > 0 then (
        print_char a.(i); w := List.tl !w;
        rest := !rest - 1
      ) else if i+1=r then
        for k=1 to need do print_char a.(i) done
    ) a
  )
)

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

let () =
  let s = scanf " %s" @@ id in
  let n = gi 0 in
  let hat,rep = ref [],ref [] in
  let a = fix (fun f i x ->
    if i>=String.length s then x
    else
      let c = s.[i] in
      if c='?' || c='*' then (
        if c='?' then hat := i::!hat;
        if c='*' then rep := i::!rep;
        f (i+$1) (List.tl x)
      ) else f (i+$1) (c::x)
  ) 0 [] |> List.rev in
  let l = List.length a in
  (* printf "%d\n" l;
  print_list string_of_int !hat;
  print_list string_of_int !rep; *)
  (* print_list (String.make 1) a; *)
  rep := List.sort compare !rep;
  hat := List.sort compare !hat;
  if llen a > n then (
    print_endline "Impossible"; exit 0
  ) else if llen a = n then (
    print_endline @@ string_of_list ~separator:"" (String.make 1) a; exit 0
  );
  if List.length !rep = 0 then (
    if llen a + llen !hat < n then (
      print_endline "Impossible"; exit 0
    ) else (
      let cnt = ref @@ n - llen a in
      String.iteri (fun i c ->
        (* printf "%d :: %d <> %d :: %Ld\n" (List.length !hat) (i+$1) (List.hd !hat) !cnt; *)
        if List.length !hat > 0 && i+$1=List.hd !hat && !cnt > 0L then (
          hat := List.tl !hat;
          print_char c;
          cnt -= 1L;
        ) else if c='?' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*'))
        then (

        ) else (
          print_char c;
        )
      ) s
    )
  ) else (
    let rest = i32 @@ n - llen a in
    let j = List.hd !rep in
    String.iteri (fun i c ->
      if i+$1=j then (
        repi 1 rest (fun _ -> printf "%c" c)
      )
      else
      if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()
      else (
        print_char c
      )
    ) s
  )

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

let () =
  let s = scanf " %s" @@ id in
  let n = gi 0 in
  let hat,rep = ref [],ref [] in
  let a = fix (fun f i x ->
    if i>=String.length s then x
    else
      let c = s.[i] in
      if c='?' || c='*' then (
        if c='?' then hat := i::!hat;
        if c='*' then rep := i::!rep;
        f (i+$1) (List.tl x)
      ) else f (i+$1) (c::x)
  ) 0 [] |> List.rev in
  let l = List.length a in
  (* printf "%d\n" l;
  print_list string_of_int !hat;
  print_list string_of_int !rep; *)
  (* print_list (String.make 1) a; *)
  if llen a > n then (
    print_endline "Impossible"; exit 0
  ) else if llen a = n then (
    print_endline @@ string_of_list ~separator:"" (String.make 1) a; exit 0
  );
  if List.length !rep = 0 then (
    if llen a + llen !hat > n then (
      print_endline "Impossible"; exit 0
    ) else (
      let cnt = ref @@ List.length !hat in
      String.iteri (fun i c ->
        if c='?' then ()
        else (
          if List.length !rep > 0 && i+$1=List.hd !rep && !cnt > 0 then (
            rep := List.tl !rep;
            cnt := !cnt -$ 1;
          );
          print_char c;
        )
      ) s
    )
  ) else (
    let rest = i32 @@ n - llen a in
    let j = List.hd !rep in
    String.iteri (fun i c ->
      if i+$1=j then (
        repi 1 rest (fun _ -> printf "%c" c)
      )
      else
      if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()
      else (
        print_char c
      )
    ) s
  )

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let p,q,r,_ = init (String.length s) (fun i -> s.[i])
  |> fold_left (fun (p,q,r,i) c ->
    if c = '?' then (List.tl p,i::q,r,i+1)
    else if c='*' then (List.tl p,q,i::r,i+1)
    else ((c,i)::p,q,r,i+1)
  ) ([],[],[],0) in
  let p,q,r = List.(rev p,rev q,rev r) in
  if List.length p = n then
    List.map fst p |> List.iter print_char
  else if List.length p > n then
    print_endline "Impossible"
  else (
    let need = n - List.length p in
    if List.length r <> 0 then (
      let j = List.hd r in
      List.iter (fun (c,i) ->
        print_char c;
        if i=j-2 then for k=0 to need do
          print_char s.[i+1]
        done
      ) p
    ) else (
      if List.length p + List.length q < n then
        print_endline "Impossible"
      else (
        List.fold_left (fun (rest,q) (c,i) ->
          print_char c;
          match q with
          | [] -> (rest,q)
          | h::t as q ->
            if i=h-2 then (
              print_char s.[h-1]; (rest-1,t)
            ) else (rest,q)
        ) (need,q) p |> ignore
      )
    )
  ))

let rec fix f x = f (fix f) x;;
Array.(Scanf.scanf " %s %d" @@ fun s n ->
  let p,q,r,_ = init (String.length s) (fun i -> s.[i])
  |> fold_left (fun (p,q,r,i) c ->
    if c = '?' then (List.tl p,i::q,r,i+1)
    else if c='*' then (List.tl p,q,i::r,i+1)
    else ((c,i)::p,q,r,i+1)
  ) ([],[],[],0) in
  let p,q,r = List.(rev p,rev q,rev r) in
  if List.length p = n then
    List.map fst p |> List.iter print_char
  else if List.length p > n then
    print_endline "Impossible"
  else (
    let need = n - List.length p in
    if List.length r <> 0 then (
      let j = List.hd r in
      List.iter (fun (c,i) ->
        print_char c;
        if i=j-2 then for k=1 to need do
          print_char s.[i+1]
        done
      ) p
    ) else (
      if List.length p + List.length q < n then
        print_endline "Impossible"
      else (
        List.fold_left (fun (rest,q) (c,i) ->
          print_char c;
          match q with
          | [] -> (rest,q)
          | h::t as q ->
            if i=h-2 then (
              print_char s.[h-1]; (rest-1,t)
            ) else (rest,q)
        ) (need,q) p |> ignore
      )
    )
  ))


A and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.For each chess piece we know its weight:   the queen's weight is 9,  the rook's weight is 5,  the bishop's weight is 3,  the knight's weight is 3,  the pawn's weight is 1,  the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board.As A doesn't like counting, he asked you to help him determine which player has the larger position weight.

The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot).  It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.

Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

NoteIn the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.In the second test sample the weights of the positions of the black and the white pieces are equal to 39.In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.

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

let colour char =
    if char != '.' && char != '\n'
    then
        if Char.lowercase char = char
        then
            `Black
        else
            `White
    else
        `Pass

let count char score =
    match Char.lowercase char with
    | 'q' -> score + 9
    | 'r' -> score + 5
    | 'b' | 'n' -> score + 3
    | 'p' -> score + 1
    | 'k' -> score

let get_winner black white =
    if black > white
    then
        "Black"
    else
        if white > black
        then
            "White"
        else
            "Draw"

let solve () =
    let rec loop i score_black score_white =
        if i < 64
        then
            let char = read () in
                match (colour char) with
                | `Black -> loop (i + 1) (count char score_black) score_white
                | `White -> loop (i + 1) score_black (count char score_white)
                | `Pass -> loop (i + 1) score_black score_white
        else
            get_winner score_black score_white
    in loop 0 0 0

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

let evalue = function
	|'Q'	-> (9,0)
	|'R'	-> (5,0)
	|'B'	-> (3,0)
	|'N'	-> (3,0)
	|'P'	-> (1,0)
	|'q'	-> (0,9)
	|'r'	-> (0,5)
	|'b'	-> (0,3)
	|'n'	-> (0,3)
	|'p'	-> (0,1)
	|_	-> (0,0);;

let main () =
	let a = ref 0 and b = ref 0 and l= ref [] in
	for i=0 to 7 do
		l := (Scanf.scanf "%s\n" (fun j -> j))::!l;
	done;
	List.iter (fun x ->
			for i=0 to String.length x - 1 do
				let (c,d) = evalue (x.[i]) in
					a:= !a + c;
					b:= !b + d;
			done) !l;
	if !a < !b
		then Printf.printf "Black"
		else if !a = !b
			then Printf.printf "Draw"
			else Printf.printf "White";;

main ();;

let score x =
    let check_upp = function
        | 'a' .. 'z' -> false
        | 'A' .. 'Z' -> true
        | _ -> false in
    let upper x = (if (check_upp x) then x else Char.uppercase x) in
    ((if (check_upp x) then 0 else 1) , match (upper x) with
        | 'Q' -> 9
        | 'R' -> 5
        | 'B' -> 3
        | 'N' -> 3
        | 'P' -> 1
        | _ -> 0);;

(*Running Code*)
let ans = [|ref 0; ref 0|];;
for i = 1 to 8 do
    let a = ref (read_line ()) in
    for j = 0 to ((String.length !a) - 1) do
        let p = (score !a.[j]) in
        (ans.(fst p)) := !(ans.(fst p)) + (snd p);
    done;
done;;
print_string (if (!(ans.(0)) > !(ans.(1))) then "White" else (if (!(ans.(0)) = !(ans.(1))) then "Draw" else "Black"));;
print_string "\n"

open Printf
open Scanf

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

let isupper c = c <= 'Z' && c >= 'A'
let toupper = Char.uppercase

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let board = Array.init 8 (fun _ -> read_string()) in

  let score p =
    let s = match toupper p with
      | 'K' -> 0
      | 'Q' -> 9
      | 'R' -> 5
      | 'B' -> 3
      | 'N' -> 3
      | 'P' -> 1
      | '.' -> 0
      | _ -> failwith "bad input"
    in

    if isupper p then s else -s
  in

  let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in

  if answer = 0 then printf "Draw\n"
  else if answer > 0 then printf "White\n"
  else printf "Black\n"

let evalue = function
	|'Q'	-> (9,0)
	|'R'	-> (5,0)
	|'B'	-> (3,0)
	|'N'	-> (3,0)
	|'P'	-> (1,0)
	|'q'	-> (0,9)
	|'r'	-> (0,5)
	|'b'	-> (0,3)
	|'n'	-> (0,3)
	|'p'	-> (0,1)
	|_	-> (0,0);;

let main () =
	let a = ref 0 and b = ref 0 and l= ref [] in
	for i=0 to 7 do
		l := (Scanf.scanf "%s" (fun j -> j))::!l;
	done;
	List.iter (fun x ->
			for i=0 to String.length x - 1 do
				let (c,d) = evalue (x.[i]) in
					a:= !a + c;
					b:= !b + d;
			done) !l;
	if !a < !b
		then Printf.printf "White"
		else if !a = !b
			then Printf.printf "Draw"
			else Printf.printf "Black";;

main ();;

open Printf
open Scanf

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

let isupper c = c <= 'Z' && c >= 'A'
let toupper = Char.uppercase

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let board = Array.init 8 (fun _ -> read_string()) in

  let score p =
    let s = match toupper p with
      | 'K' -> 0
      | 'Q' -> 8
      | 'R' -> 5
      | 'B' -> 3
      | 'N' -> 3
      | 'P' -> 1
      | '.' -> 0
      | _ -> failwith "bad input"
    in

    if isupper p then s else -s
  in

  let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in

  if answer = 0 then printf "Draw\n"
  else if answer > 0 then printf "White\n"
  else printf "Black\n"


PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.

The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.

Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.

NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.

let read_int () = Scanf.scanf " %d " (fun x -> x)
let solve n = if n > 2 then n - 2 else n + 2

let main () =
        let n = read_int () in
        let answer = if n > 2 then n - 2 else n + 2 in
        print_int answer;;

main ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m =
    if n + 2 <= 1000
    then n + 2
    else n - 2
  in
    Printf.printf "%d\n" m

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = n + 2 in
    Printf.printf "%d\n" m


InputThe input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.OutputOutput "YES" or "NO".ExamplesInput
HELP
Output
YES
Input
AID
Output
NO
Input
MARY
Output
NO
Input
ANNA
Output
YES
Input
MUG
Output
YES
Input
CUP
Output
NO
Input
SUM
Output
YES
Input
PRODUCT
Output
NO

let rec check (i : int) (s : string) =
  if (i + 2 >= String.length s) then
    true
  else
    let a1 = Char.code s.[i] in
    let a2 = Char.code s.[i+1] in
    let a3 = Char.code s.[i+2] in
    if (((a1 - 65) + (a2 - 65)) mod 26) != (a3 - 65) then
      false
    else
      check (i+1) s
;;

let s = read_line () in
let ret = check 0 s in
if ret = false then
  print_endline "NO"
else
  print_endline "YES"


Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.

Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.

NoteIn the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".

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

let traverse (remix, l) =
    let rec loop i original =
        if i + 3 <= l
        then
            if remix.[i] = 'W'
            then
                if remix.[i + 1] = 'U'
                then
                    if remix.[i + 2] = 'B'
                    then
                        loop (i + 3) (' ' :: original)
                    else
                        loop (i + 2) (remix.[i + 1] :: remix.[i] :: original)
                else
                    loop (i + 1) (remix.[i] :: original)
            else
                loop (i + 1) (remix.[i] :: original)
        else
            if i + 2 <= l
            then
                (' ' :: remix.[i + 1] :: remix.[i] :: original)
            else
                if i + 1 <= l
                then
                    (' ' :: remix.[i] :: original)
                else
                    (' ' :: original)
    in loop 0 [' ']

let solve input = List.rev (traverse input)

let build result =
    let rec loop last list temp =
        (match (temp, last) with
            |(' ' :: tail), ' ' -> loop ' ' list tail
            |(x :: tail), _ ->
               loop x (x :: list) tail
            |[], _ -> List.rev list)
    in loop ' ' [] result

let rec print list =
    (match list with
    |[' '] -> ()
    |(x :: tail) ->
        Printf.printf "%c" x;
        print tail
    |[] -> ())

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

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

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

let traverse input =
    let rec loop remix original =
        match remix with
        |('W' :: 'U' :: 'B' :: tail) -> loop tail (' ' :: original)
        |[] -> List.rev original
        |(x :: tail) -> loop tail (x :: original)
    in loop input [' ']

let build result =
    let rec loop last list temp =
        (match (temp, last) with
            |(' ' :: tail), ' ' -> loop ' ' list tail
            |(x :: tail), _ ->
               loop x (x :: list) tail
            |[], _ -> List.rev list)
    in loop ' ' [] result

let rec print list =
    (match list with
    |[' '] -> ()
    |(x :: tail) ->
        Printf.printf "%c" x;
        print tail
    |[] -> ())

let () = print (build (traverse (input())))

let split_WUB s =
  Str.split (Str.regexp "WUB") s

let add_space words =
  let f word =
    if word = "" then word
    else " " ^ word
  in
  (List.hd words) ::  (List.map f (List.tl words))

let solve s =
  List.iter (Printf.printf "%s") (add_space (split_WUB s))

let _ =
  Scanf.scanf " %s" solve


Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.  Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.

The first line of the input contains three integers d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths.    d1 is the length of the path connecting Patrick's house and the first shop;  d2 is the length of the path connecting Patrick's house and the second shop;  d3 is the length of the path connecting both shops.

Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.

NoteThe first sample is shown on the picture in the problem statement. One of the optimal routes is: house  first shop  second shop  house.In the second sample one of the optimal routes is: house  first shop  house  second shop  house.

let input () = Scanf.scanf "%d %d %d" (fun d1 d2 d3 -> d1, d2, d3)
let solve (d1, d2, d3) =
    let p1 = d1 + d2 + d3 in
    let p2 = 2 * d1 + 2 * d2 in
    let p3 = 2 * d1 + 2 * d3 in
    let p4 = 2 * d2 + 2 * d3 in
    let paths = (p1 :: p2 :: p3 :: p4 :: []) in
    let min = List.hd (List.sort (Pervasives.compare) paths) in
    min
let print result = Printf.printf "%d\n" result
let () = print (solve (input ()))

let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d3+d2 ;d1+d3+d3+d1] max_int |> print_int

open Printf
open Scanf

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

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min (min ((d1++d2)**2L) (d1++d2++d3)) (min ((d1++d3)**2L) ((d2++d3)**2L)) in

  printf "%Ld\n" answer

let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1] max_int |> print_int

let ints = read_line () |> Str.split (Str.regexp " +")  |> List.map int_of_string in
let d1 = List.nth ints 0 and
    d2 = List.nth ints 1 and
    d3 = List.nth ints 2 and
    max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in
List.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1; d2+d3+d3+d2] max_int |> print_int

open Printf
open Scanf

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

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min ((d1++d2)**2L) (d1++d2++d3) in

  printf "%Ld\n" answer

open Printf
open Scanf

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

let () =
  let d1 = read_int () in
  let d2 = read_int () in
  let d3 = read_int () in

  let answer = min ((d1+d2)*2) (d1+d2+d3) in

  printf "%d\n" answer


You are given two integer numbers, $$$n$$$ and $$$x$$$. You may perform several operations with the integer $$$x$$$.Each operation you perform is the following one: choose any digit $$$y$$$ that occurs in the decimal representation of $$$x$$$ at least once, and replace $$$x$$$ by $$$x \cdot y$$$.You want to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$. What is the minimum number of operations required to do that?

The only line of the input contains two integers $$$n$$$ and $$$x$$$ ($$$2 \le n \le 19$$$; $$$1 \le x < 10^{n-1}$$$).

Print one integer — the minimum number of operations required to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$, or $$$-1$$$ if it is impossible.

NoteIn the second example, the following sequence of operations achieves the goal:  multiply $$$x$$$ by $$$2$$$, so $$$x = 2 \cdot 2 = 4$$$;  multiply $$$x$$$ by $$$4$$$, so $$$x = 4 \cdot 4 = 16$$$;  multiply $$$x$$$ by $$$6$$$, so $$$x = 16 \cdot 6 = 96$$$;  multiply $$$x$$$ by $$$9$$$, so $$$x = 96 \cdot 9 = 864$$$.

open Printf
open Scanf

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

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

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

  let rec ndigits x = if x = 0L then 0 else 1 + ndigits (x // 10L) in
  let rec dlistx n = if n=0L then [] else (short(n %% 10L))::(dlistx (n // 10L)) in
  let dlist x =
    let li = List.sort_uniq compare (dlistx x) in
    List.filter (fun d -> d <> 0 && d <> 1) li
  in

  let grow x =
  (* apply the grow operator to x in all possible ways *)
  (* return the list of possible results *)
    List.map (fun d -> x ** (long d)) (dlist x)
  in

  let rec bfs li nops =
    if li = [] then -1
    else if List.exists (fun x -> ndigits x = goal_length) li then nops
    else bfs (List.sort_uniq compare (List.concat (List.map grow li))) (nops+1)
  in

  printf "%d\n" (bfs [x] 0)


Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.

let read ()  = Scanf.scanf " %d" (fun x -> x) and
    foi = float_of_int in
let (k,n) = (read(), read()) in
let s = ref 0 in
for i = 0 to n-1 do s := !s + (read()) done;
let (fn , fs, fk ) = (foi n, foi !s, foi k) in
print_int @@ if fs /. fn  > fk -. 0.5 then 0 else int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5

open Printf
open Scanf

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

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

  let s = sum 0 (n-1) (fun i -> a.(i)) in

  printf "%d\n" (max 0 (2*n*k - n - 2 * s))

let read ()  = Scanf.scanf " %d" (fun x -> x) and
    foi = float_of_int in
let (k,n) = (read(), read()) in
let s = ref 0 in
for i = 0 to n-1 do s := !s + (read()) done;
let (fn , fs, fk ) = (foi n, foi !s, foi k) in
print_int @@ int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5


One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input data contains the only number n (1 ≤ n ≤ 109).

Output the only number — answer to the problem.

NoteFor n = 10 the answer includes numbers 1 and 10.

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

let f n =
  let rec go n ten sum =
    if n = 0 then
      sum
    else
      go (n/2) (ten*10) (sum+ten*(n mod 2))
  in go n 1 0

let () =
  let n = read_int 0 in
  let rec go i =
    if f i > n then
      i-1
    else
      go (i+1)
  in
  go 0 |> Printf.printf "%d\n"


You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.

First line contains an integer n (6 ≤ n ≤ 8) – the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).

Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).

NoteHere's a set of names in a form you can paste into your solution:["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}

let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp ("^" ^ s ^ "$") in
    print_endline (List.find (fun p -> Str.string_match pat p 0) ps))
;;

let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp s in
    print_endline (List.find (fun p -> String.length s = String.length p && Str.string_match pat p 0) ps))
;;

let ps = ["vaporeon"; "jolteon"; "flareon"; "espeon"; "umbreon"; "leafeon"; "glaceon"; "sylveon"]

let () =
  Scanf.scanf "%d %s " (fun n s ->
    let pat = Str.regexp s in
    print_endline (List.find (fun p -> Str.string_match pat p 0) ps))
;;


Recently you have received two positive integer numbers $$$x$$$ and $$$y$$$. You forgot them, but you remembered a shuffled list containing all divisors of $$$x$$$ (including $$$1$$$ and $$$x$$$) and all divisors of $$$y$$$ (including $$$1$$$ and $$$y$$$). If $$$d$$$ is a divisor of both numbers $$$x$$$ and $$$y$$$ at the same time, there are two occurrences of $$$d$$$ in the list.For example, if $$$x=4$$$ and $$$y=6$$$ then the given list can be any permutation of the list $$$[1, 2, 4, 1, 2, 3, 6]$$$. Some of the possible lists are: $$$[1, 1, 2, 4, 6, 3, 2]$$$, $$$[4, 6, 1, 1, 2, 3, 2]$$$ or $$$[1, 6, 3, 2, 4, 1, 2]$$$.Your problem is to restore suitable positive integer numbers $$$x$$$ and $$$y$$$ that would yield the same list of divisors (possibly in different order).It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers $$$x$$$ and $$$y$$$.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 128$$$) — the number of divisors of $$$x$$$ and $$$y$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^4$$$), where $$$d_i$$$ is either divisor of $$$x$$$ or divisor of $$$y$$$. If a number is divisor of both numbers $$$x$$$ and $$$y$$$ then there are two copies of this number in the list.

Print two positive integer numbers $$$x$$$ and $$$y$$$ — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.

(* #require "str" *)

let divisors (n:int) : int list =
  let rec divhelper m lst =
    if m * m > n then lst
    else if m * m = n then m :: lst
    else if n mod m = 0 then divhelper (m+1) ((n/m)::m::lst)
    else divhelper (m+1) lst
  in List.sort compare (divhelper 1 [])

let rec remove lst1 lst2=
  match lst1, lst2 with
  | _, [] -> lst1
  | [], _ -> failwith "Should not occur"
  | (f1::r1), (f2::r2) -> if f1 = f2 then remove r1 r2 else
                           f1 :: remove r1 lst2

let lmax = List.fold_left max 0

let split = Str.split (Str.regexp " +")

let main ()=
  let _ = read_line() in
  let lst1 = List.sort compare
               (List.map int_of_string (split (read_line()))) in
  let a1 = lmax lst1 in
  let fdiv = divisors a1 in
  let a2 = lmax (remove lst1 fdiv) in
  print_string (string_of_int a1 ^ " " ^ string_of_int a2 ^"\n")

let () = main ()


User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >> When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.There are some conditions in the navigation:  If page 1 is in the navigation, the button "<<" must not be printed.  If page n is in the navigation, the button ">>" must not be printed.  If the page number is smaller than 1 or greater than n, it must not be printed.   You can see some examples of the navigations. Make a program that prints the navigation.

The first and the only line contains three integers n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n)

Print the proper navigation. Follow the format of the output from the test samples.

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and m=read_int() and k=read_int();;
if m-k>1 then print_string "<< ";;
for i=m-k to m+k do
   if (i>=1)&&(i<=n) then
   begin
   if i=m then print_string "(";
   print_int i;
   if i=m then print_string ")";
   if i<>m+k then print_string " "
   end
done;;
if m+k<n then print_string " >>";;


Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).  Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

Print the only integer a — the total number of printed segments.

let num_segs = function
  | 0 -> 6
  | 1 -> 2
  | 2 -> 5
  | 3 -> 5
  | 4 -> 4
  | 5 -> 5
  | 6 -> 6
  | 7 -> 3
  | 8 -> 7
  | 9 -> 6

let rec total_segs = function
  | 0 -> 0
  | n -> num_segs (n mod 10) + total_segs (n / 10)

let () =
  let [lo; hi] = read_line ()
    |> Str.split (Str.regexp " ")
    |> List.map int_of_string in
  let sum = ref 0 in
  for i = lo to hi do
    sum := !sum + total_segs i
  done;
  print_int !sum;
  print_newline ()

let _ =
  let sb = Scanf.Scanning.stdib in
  let a = Scanf.bscanf sb "%d " (fun s -> s) in
  let b = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = a - 1 in
  let d = [| 6; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] in
  let t = 49 in
  let rec calc n =
    if n = 0
    then 0
    else (
      let r = ref 0 in
      let c = n mod 10 in
	if c = 0
	then (
	  let m = ref n in
	    while !m > 0 do
	      r := !r + d.(!m mod 10);
	      m := !m / 10;
	    done;
	    (*Printf.printf "qwe1 %d %d\n" n (!r - d.(0) + t * (n / 10));*)
	    !r - d.(0) + t * (n / 10) + 10 * calc ((n - 1) / 10);
	) else (
	  let m = ref n in
	    while !m > 0 do
	      r := !r + d.(!m mod 10);
	      m := !m / 10;
	    done;
	    r := (!r - d.(c)) * c;
	    for i = 1 to c do
	      r := !r + d.(i);
	    done;
	    (*!r + t * (n / 10) + 10 * calc (n / 10)*)
	    (*Printf.printf "qwe2 %d %d\n" n !r;*)
	    !r + calc (n - c)
	)
    )
  in
  let res = calc b - calc a in
    Printf.printf "%d\n" res

open Printf
open Scanf

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

let read_pair () = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))
let () =
  let (a,b) = read_pair () in

  let tab = [|6;2;5;5;4;5;6;3;7;6|] in
          (*  0 1 2 3 4 5 6 7 8 9 *)

  let score x = if x=0 then tab.(0) else
      let rec loop x = if x=0 then 0 else tab.(x mod 10) + loop (x/10) in
      loop x
  in

  printf "%d\n" (sum a b score)

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s)
    done;
  in
  let ks = ref [] in
  let ht = Hashtbl.create 10 in
  let prev = ref (-1) in
    for i = 0 to n - 1 do
      if Hashtbl.mem ht a.(i) then (
	ks := (!prev + 1, i) :: !ks;
	prev := i;
	Hashtbl.clear ht;
      ) else (
	Hashtbl.replace ht a.(i) ()
      )
    done;
    let ks =
      if !prev = n - 1
      then !ks
      else (
	match !ks with
	  | [] ->
	      Printf.printf "-1\n";
	      exit 0
	  | (l, r) :: ks ->
	      (l, n - 1) :: ks
      )
    in
    let ks = List.rev ks in
      Printf.printf "%d\n" (List.length ks);
      List.iter
	(fun (l, r) ->
	   Printf.printf "%d %d\n" (l + 1) (r + 1)
	) ks


Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100$$$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.

Print one integer — the maximum number of problems Mishka can solve.

NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems.

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

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

exception End;;

let n,k = Scanf.sscanf (read_line ()) "%i %i" (fun n k -> n,k)  in
let problem = read_line () |> split_on_char ' ' |> List.map int_of_string  |> Array.of_list in
let count = ref 0 in
while !count < n && problem.(!count) <= k do
  incr count;
done;
let tmp = !count in
begin try
  for i = n - 1 downto tmp + 1 do
    if problem.(i) > k then raise End;
    incr count;
  done
  with End -> ();
end;
Printf.printf "%i" !count;
print_newline ();

(* Codeforces  *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let rec readlist n acc = match n with
| 0 -> acc
| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;

let rec head_cnt k cnt l = match l with
| [] -> (cnt, [])
| h :: tl ->
	if h > k then (cnt, l)
	else head_cnt k (cnt+1) tl;;

let main() =
	let n = gr () in
	let k = gr () in
	let a = readlist n [] in
	let ha, tl = head_cnt k 0 a in
	let rev_tl = List.rev tl in
	let ta, _ = head_cnt k 0 rev_tl in
	begin
		(* print_string "a = "; printlisti a;
		print_string " ha = ";
		print_int ha; print_string "  ta = ";
		print_int ta; print_string " \n"; *)
		print_int (ha + ta);
		print_string "\n"
   end;;

main();;


Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:         Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).The potion can be used infinite amount of times.

The first line contains four integer numbers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively. The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.

Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).

NoteIn the first example there exists such sequence of moves:   — the first type of move   — the third type of move

Scanf.scanf "%d %d %d %d %d %d" (fun x y tx ty cx cy -> print_string(
let mx,my=tx-x,ty-y in
if mx mod cx=0 && my mod cy=0 && mx/cx land 1 = my/cy land 1 then "YES" else "NO"))

Scanf.scanf "%d %d %d %d %d %d" (fun x y tx ty cx cy -> print_string(
let mx=tx-x in let my=ty-y in
if mx mod cx=0 && my mod cy=0 && mx/cx land 1 = my/cy land 1 then "YES" else "NO"))


The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm:   Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger.  Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor).  Moves from the $$$b$$$-th floor back to the $$$x$$$-th.  The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the number of people on each floor.

In a single line, print the answer to the problem — the minimum number of electricity units.

NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \cdot 2 + 8 \cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor.

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

let () =
  let n = gi 0 in let a  = iia n in
  let res = ref max_i64 in
  rep 1L n (fun x ->
    let r = ref 0L in
    (* printf "%Ld:\n" x; *)
    iteri (fun i v ->
      let floor = i64 i+1L in
      r += (floor-1L) * 2L * 2L * v;
      (* printf "  %d; %Ld = %Ld\n" i v !r; *)
    ) a;
    (* printf "  = %Ld: %Ld\n" x !r; *)
    res := min !res !r
  );
  printf "%Ld" @@ !res


Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

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

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

let () =
  let x = read_int 0 in
  let y = read_int 0 in
  let z = 7 - max x y in
  let d = gcd z 6 in
  Printf.printf "%d/%d\n" (z/d) (6/d)


Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.In the local council you were given an area map, where the granny's house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics:   it starts and ends in the same place — the granny's house;  the route goes along the forest paths only (these are the segments marked black in the picture);  the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);  the route cannot cross itself;  there shouldn't be any part of dense forest within the part marked out by this route; You should find the amount of such suitable oriented routes modulo 1000000009.  The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.

The input data contain the only even integer n (2 ≤ n ≤ 106).

Output the only number — the amount of Peter's routes modulo 1000000009.

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

let p = 1000000009L

open Int64
let ( ++ ) x y = add x y |> flip rem p
let ( -- ) x y = sub x y |> flip rem p
let ( ** ) x y = mul x y |> flip rem p

let () =
  let n = read_int 0 in
  let s = ref 2L in
  let lane = ref 1L in
  let lanes = ref 1L in
  for i = 1 to (n-2)/2 do
    s := !s ++ 4L ** !lanes;
    lane := 2L ** !lane ++ 3L;
    lanes := !lanes ** !lane
  done;
  (!s** !s++1L)**2L |> Printf.printf "%Ld\n"

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

let p = 1000000009L

open Int64
let ( ++ ) x y = add x y |> flip rem p
let ( -- ) x y = sub x y |> flip rem p
let ( ** ) x y = mul x y |> flip rem p

let () =
  let n = read_int 0 in
  let s = ref 2L in
  let lane = ref 1L in
  let lanes = ref 1L in
  for i = 1 to (n-2)/2 do
    s := !s ++ 4L ** !lane;
    lane := 2L ** !lane ++ 3L;
    lanes := !lanes ** !lane
  done;
  (!s** !s++1L)**2L |> Printf.printf "%Ld\n"


One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

The only line contains n (1 ≤ n ≤ 25) — the required sum of points.

Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.

NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points.

let n = read_int () - 10 in
print_int (if n = 10 then 15
else if n >= 1 && n <= 11 then 4
else 0)

(* http://codeforces.com/contest/104/problem/A *)

let f n =
  if 0 <= n && n <= 10 then 0
  else if 11 <= n && n <= 19 then 4
  else if n = 20 then 15
  else if n = 21 then 4
  else 0;;
Printf.printf "%d\n" (Scanf.scanf "%d" f);;

(* http://codeforces.com/contest/104/problem/A *)

let f n =
  if 0 <= n && n <= 10 then 0
  else if 11 <= n && n <= 19 then 4
  else if n = 20 then 15
  else if n = 21 then 1
  else 0;;
Printf.printf "%d\n" (Scanf.scanf "%d" f);;


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

The only line contains an integer n (1 ≤ n ≤ 1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".In the third sample there are no lucky digits, so the answer is "NO".

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

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

let is_lucky_numbers = function
    |'4' | '7'-> true
    |_ -> false

let count input = List.length(List.filter(is_lucky_numbers) input)

let solve input =
    if is_lucky_numbers(String.get (Pervasives.string_of_int(count input)) 0)
    then
        "YES"
    else
        "NO"

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

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

let n = read_line() in
let m = ref 0 in
let _ = String.iter (function
	| ('4'|'7') -> incr m
	| _ -> ()
) n in
print_string (if !m = 4 || !m = 7 then "YES" else "NO");

open Int64;;
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_ll () = Scanf.scanf " %Ld" (fun x -> x)
let pom = function (4 | 7) -> 1 | _ -> 0;;

let rec fart n =
	let rec lucky x acc = match x with
		|0L -> acc
		|_ -> lucky (div x 10L) (acc + (pom(to_int(rem x 10L))))
	in
lucky n 0;;

let n = scan_ll ()
let kek = fart n;;
(*print_int kek;;*)

let s = match kek with
	|(4 | 7) -> "YES"
	|_ ->"NO"
;;

print_string s;;

open Int64;;
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_ll () = Scanf.scanf " %Ld" (fun x -> x)
let ten = of_int(10);;
let zero = of_int(0);;
let pom = function (4 | 7) -> 1 | _ -> 0;;

let rec fart n =
	let rec lucky x acc =
		if x = zero then acc
		else lucky (div x ten) (acc + (pom(to_int(rem x ten))))
	in
lucky n 0;;

let n = scan_ll ()
let kek = fart n;;
(*print_int kek;;*)

let s = match kek with
	|(4 | 7) -> "YES"
	|_ ->"NO"
;;

print_string s;;

let n = String.length (read_line()) in
print_string (if n = 4 || n = 7 then "YES" else "NO")


You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.

A single line contains three space-separated integers a, b, r (1 ≤ a, b, r ≤ 100) — the table sides and the plates' radius, correspondingly.

If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes).

NoteIn the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.  In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move.

let ni = fun _ -> Scanf.scanf " %d" (fun x -> x) in
let a = ni () in
let b = ni () in
let d = 2 * ni () in
print_string (if a >= d && b >= d then "First" else "Second");;

let solve a b r =
  let diameter = 2 * r in
  if diameter <= a && diameter <= b then "First"
  else "Second"

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%d %d %d\n" solve)

module Std = struct

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

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

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

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

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

end

open Std
module L = List

(* entry point *)

let a = int ()
let b = int ()
let r = int ()

let () =
  Printf.printf "%s\n"
    (if r*2 <= a && r*2 <= b then "First"
     else "Second")

let solve a b r =
  let diam = 2 * r in
  let plate_in_a_row len r =
    len/(2*diam-1) + (len-(len/(2*diam-1))*(2*diam-1))/diam
  in
  if ((plate_in_a_row a r) * (plate_in_a_row b r)) mod 2 == 0 then "Second"
  else "First"

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%d %d %d\n" solve)

let solve a b r =
  let diam = 2 * r in
  let vdiam = 4*r - 1 in
  let max_in_a_row n r =
    ((n/vdiam) + (n-(a/vdiam))/diam)
  in
  if ( (max_in_a_row a r) * (max_in_a_row b r) ) mod 2 == 0 then "Second"
  else "First"

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%d %d %d\n" solve)

let solve a b r =
  let diam = 2 * r in
  let plate_in_a_row len r =
    len/(2*diam-1) + (len-(len/(2*diam-1)))/diam
  in
  if ((plate_in_a_row a r) * (plate_in_a_row b r)) mod 2 == 0 then "Second"
  else "First"

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%d %d %d\n" solve)

let solve a b r =
  let diameter = 2 * r in
  if ((a/diameter) * (b/diameter)) mod 2 == 0 then "Second"
  else "First"

let _ =
  Printf.printf "%s\n" (Scanf.scanf "%d %d %d\n" solve)


Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).  Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right.

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

let ident x = x ;;
let ident2 x y = (x, y) ;;
let ident3 x y z = (x, y, z) ;;
let ident4 x y z w = (x, y, z, w) ;;
let ident5 x y z w v = (x, y, z, w, v) ;;

let char_to_int x = int_of_char x - int_of_char '0' ;;
let int_to_char x = char_of_int (x + int_of_char '0') ;;

module List = struct
  include ListLabels ;;

  let rec iteri i f = function
    | [] -> ()
    | a::l -> f i a; iteri (i + 1) f l

  let iteri ~f l = iteri 0 f l
end
;;

module Array = struct
  include ArrayLabels ;;

  let reduce ~f xs =
    let acc = ref xs.(0) in
    for i = 1 to length xs - 1 do
      acc := f !acc xs.(i)
    done;
    !acc
  ;;
end
;;

module String = struct
  include StringLabels ;;

  let map_to_list ~f ss =
    let res = ref [] in
    iter ss ~f:(fun c -> res := f c :: !res);
    List.rev !res
  ;;

  let of_char_list ss =
    let res = String.create @@ List.length ss in
    List.iteri ss ~f:(fun i c -> res.[i] <- c);
    res
  ;;

  let iteri ~f a =
    for i = 0 to length a - 1 do f i (unsafe_get a i) done
  ;;
end
;;

module Float = struct
  let (+) = (+.)
  let (-) = (-.)
  let ( * ) = ( *. )
  let (/) = (/.)
end
;;

module Int64 = struct
  include Int64
  let (+) = add
  let (-) = sub
  let ( * ) = mul
  let (/) = div
end
;;

let fold_for ?(skip=1) min max ~init ~f =
  let acc = ref init in
  let cur = ref min in
  while !cur < max do
    acc := f !acc !cur;
    cur := !cur + skip;
  done;
  !acc
;;

let iter_for ?(skip=1) min max ~f =
  let cur = ref min in
  while !cur < max do
    f !cur;
    cur := !cur + skip;
  done
;;

let () =
  let n = Scanf.scanf "%d " ident in
  let xs = fold_for 0 n ~init:[] ~f:(fun acc x ->
    Scanf.scanf "%d " ident :: acc) |> List.rev in
  let rec iter ps prev = function
  | [] -> print_endline "no"
  | cur :: xs ->
    let x, y = (min cur prev, max cur prev) in
    List.iter ps ~f:(fun (x, y) -> Printf.eprintf "%d, %d\n" x y);
    prerr_endline "ok";
    if List.exists ps ~f:(fun (x', y') ->
      x < x' && x' < y && y < y' ||
        x' < x && x < y' && y' < y) then
      print_endline "yes"
    else iter ((x, y) :: ps) cur xs in
  match xs with
  | [] -> assert false
  | x :: xs -> iter [] x xs
;;

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

let rec loop n f acc =
  if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)

let next_int () = Scanf.scanf "%d%c" (fun x _ -> x)

let rec make_pair l acc =
  match l with
	[] -> acc
  | [x] -> acc
  | x :: ((y :: ys) as xs) -> make_pair xs ((if x <= y then (x, y) else (y, x) ):: acc)

let n = next_int()

let a = loop n (fun _ -> next_int ()) []
let b = make_pair a []
;;

let valid p =
  let intersect q =
	let x1 = fst p in
	let y1 = snd p in
	let x2 = fst q in
	let y2 = snd q in
	if x1 <= x2 then x2 > x1 && x2 < y1 && y2 > y1
	else y2 > x1 && y2 < y1 in
  List.exists intersect b
;;

let () =
(* List.iter (fun (x, y) -> print_int x; print_string " "; print_int y;
  print_string "\n") b; *)
if List.exists valid b then print_string "yes" else print_string "no"

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

let rec loop n f acc =
  if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)

let next_int () = Scanf.scanf "%d%c" (fun x _ -> x)

let rec make_pair l acc =
  match l with
	[]  -> acc
  | [x] -> acc
  | x :: ((y :: ys) as xs) -> make_pair xs ((x, y) :: acc)

let n = next_int()

let a = loop n (fun _ -> next_int ()) []
let b = make_pair a []

let valid p =
  let intersect q =
	let x1 = fst p in
	let y1 = snd p in
	let x2 = fst q in
	let y2 = snd q in
	if x1 <= x2 then x2 < y1 && y2 > y1
	else y2 > x1 && y2 < y1 in
  List.exists intersect b

let () = if List.exists valid b then print_string "yes" else print_string "no"

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

let rec loop n f acc =
  if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)

let next_int () = Scanf.scanf "%d%c" (fun x _ -> x)

let rec make_pair l acc =
  match l with
	[] -> acc
  | [x] -> acc
  | x :: ((y :: ys) as xs) -> make_pair xs ((if x <= y then (x, y) else (y, x) ):: acc)

let n = next_int()

let a = loop n (fun _ -> next_int ()) []
let b = make_pair a []
;;

let valid p =
  let intersect q =
	let x1 = fst p in
	let y1 = snd p in
	let x2 = fst q in
	let y2 = snd q in
	if x1 <= x2 then x2 < y1 && y2 > y1
	else y2 > x1 && y2 < y1 in
  List.exists intersect b
;;

let () = if List.exists valid b then print_string "yes" else print_string "no"


"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).  illustration by 猫屋 https://twitter.com/nekoyaliu Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.

The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.

Print a single integer — the number of subsequences "QAQ" in the string.

NoteIn the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".

open Printf
open Scanf

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

let read_string _ = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let s = read_string () in
  let n = String.length s in

  let to_left = Array.make n 0 in
  let to_right = Array.make n 0 in

  for i=1 to n-1 do
    to_left.(i) <- to_left.(i-1) + (if s.[i-1] = 'Q' then 1 else 0)
  done;

  for i=n-2 downto 0 do
    to_right.(i) <- to_right.(i+1) + (if s.[i+1] = 'Q' then 1 else 0)
  done;

  let answer = sum 0 (n-1) (
    fun i -> if s.[i] = 'A' then to_left.(i) * to_right.(i) else 0
  ) in

  printf "%d\n" answer