let f,s=read_float,print_string in let f,i=modf(log(f())/.log(f())+.0.0000000000001)in if f<0.000000000000105 then(s"YES\n";print_int(int_of_float i-1))else(s"NO")


let () =
  let x, y = Scanf.scanf "%d %d" (fun i j -> (float_of_int i, float_of_int j)) in
  let exposant_xy = y *. (log x) in
  let exposant_yx = x *. (log y) in
  if (exposant_xy < exposant_yx) then print_string "<"
  else if (exposant_xy > exposant_yx) then print_string ">"
  else print_string "="


let _ =
  let sb = Scanf.Scanning.stdib in
  let a = Scanf.bscanf sb "%d " (fun s -> s) in
  let res =
    match a with
      | 1 -> 2				(* 2 *)
      | 2 -> 3
      | 3 -> 1				(* 1 *)
      | 4 -> 2				(* 3 *)
      | 5 -> 1
      | _ -> assert false
  in
    Printf.printf "%d\n" res;


let distribute c l =
  let rec insert a1 a2 = function
  | [] -> a2
  | h :: t ->
    insert (h :: a1) ((List.rev_append a1 (h :: c :: t)) :: a2) t
  in
  insert [] [c :: l] l

let rec permutation = function
  | [] -> [[]]
  | h :: t ->
    List.fold_left (fun acc x -> List.rev_append (distribute h x) acc)
        [] (permutation t)

let range =
  let rec aux a = function
    | 0 -> a
    | m -> aux (m :: a) (m - 1)
  in
  aux []

let fp l =
  let rec aux a = function
  | [] -> a
  | h :: t ->
    let s, _ = List.fold_left (fun (s, m) x ->
      let m = min m x in (s + m, m)
    ) (h, h) t
    in aux (a + s) t
  in
  aux 0 l

let () = Scanf.scanf "%d %d\n" (fun n m ->
  let p = permutation (range n) in
  let f = List.map fp p in
  let max = match f with
  | [] -> 0
  | h::t -> List.fold_left max h t
  in
  let p = List.fold_left2 (fun a p f -> if f = max then p :: a else a) [] p f in
  let p = List.sort compare p in
  Printf.printf "%s\n" (String.concat " " (List.map string_of_int (List.nth p (m - 1))))
)


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

let abs x =
        if x>0 then x
        else -x;;
let ans = ref 0;;
let x = read_int ();;
let y = read_int ();;

(*Printf.printf "%d %d\n" x y;; *)
if abs x > abs y then
         if x>0 then ans := 1 + (x - 1) * 4
         else ans := 3 + (abs x - 1) * 4
else
         if y>0 then ans := 2 + (y - 1) * 4
         else ans := 4 + (abs y - 1) * 4;;

if (x=0 && y=0) || (x=1 && y=0) then print_int 0
else if x=y && x*y>0 then print_int (!ans - 1)
else if x>0 && y<0 && abs x - abs y = 1 then print_int (!ans - 1)
else print_int !ans;;


(* open Scanf *)
(* open Printf *)

let main () =
  let a = read_int () in
  let b = read_int () in
  let c = read_int () in
    let ans = 7 * (min (min a (b / 2)) (c / 4)) in
      print_int ans

let _ = main ()


let rec fix f x = f (fix f) x;;
Scanf.scanf " %d %d %d %d %d %d" @@ fun w h u d v e ->
  print_int @@ fix (fun f h w ->
    if h=0 then w
    else
      let w = w+h in
      f (h-1) @@ max 0 @@
        if h=e then w-v
        else if h=d then w-u
        else w) h w


let (|>) x f = f x

let rec f i j a b : char list =
  if a = b then
    []
  else if a < b then
    j::f i j (a+1) b
  else
    f j i b a

let tl xs = try List.tl xs with _ -> []
let rec mhd = function
  | [] -> []
  | []::xss -> mhd xss
  | (x::xs)::xss -> x::mhd xss

let rec tr = function
  | [] -> []
  | []::xss -> tr xss
  | (x::xs)::xss ->
      (x::mhd xss) :: tr (xs::List.map tl xss)

let rec p = function
  | [] -> ()
  | [a]::xs -> Printf.printf "%c\n" a; p xs
  | [a;b]::xs -> Printf.printf "%c%c\n" a b; p xs

let () =
  let s = read_line () in
  let t = read_line () in
  tr [f 'L' 'R' (int_of_char s.[0]) (int_of_char t.[0]); f 'D' 'U' (int_of_char s.[1]) (int_of_char t.[1])]
  |> (fun xs -> Printf.printf "%d\n" (List.length xs); xs) |> p


let _ =
  let n = 3200000 in
  let prime = Array.make (n + 1) true in
  let p = Array.make 250000 0 in
  let pk = ref 0 in
  let _ =
    for i = 2 to n do
      if prime.(i) then (
	p.(!pk) <- i;
	incr pk;
	let j = ref (2 * i) in
          while !j <= n do
	    let jj = !j in
              prime.(jj) <- false;
              j := jj + i
          done
      )
    done;
  in
  let pk = !pk - 1 in
  let sb = Scanf.Scanning.stdib in
  let q = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let n = ref q in
  let sq = ref false in
  let sqp = ref 0L in
  let divs = ref 0 in
  let d = Array.make 2 0L in
    for i = 0 to pk do
      let p = p.(i) in
      let pl = Int64.of_int p in
	if Int64.rem !n pl = 0L then (
	  if !divs < 2
	  then d.(!divs) <- pl;
	  incr divs;
	  if Int64.rem (Int64.div !n pl) pl = 0L then (
	    sq := true;
	    sqp := Int64.mul pl (Int64.of_int p);
	  )
	);
	while Int64.rem !n pl = 0L do
	  n := Int64.div !n pl
	done
    done;
    (*Printf.printf "asd %d %Ld\n" !divs !n;*)
    if !n <> 1L
    then incr divs;
    if !sq && !sqp < q
    then Printf.printf "1\n%Ld\n" !sqp
    else if not !sq && !divs <= 1
    then Printf.printf "1\n0\n"
    else if !divs > 2
    then Printf.printf "1\n%Ld\n" (Int64.mul d.(0) d.(1))
    else Printf.printf "2\n"


open Scanf
open Printf
open Int64

let md = 1000000007L

let f n m k =
  if k = -1L && Int64.rem (Int64.add m n) 2L = 1L then 0L
    else let rec g x y =
      if y = 0L then 1L
        else if y = 1L then x
        else let tmp = g x (Int64.div y 2L) in
          if Int64.rem y 2L = 0L then Int64.rem (Int64.mul tmp tmp) md
          else Int64.rem (Int64.mul (Int64.rem (Int64.mul tmp tmp) md) x) md in
    g (g 2L (Int64.sub n 1L)) (Int64.sub m 1L)

let () =
  let ans = bscanf Scanning.stdin "%Ld %Ld %Ld" f in
    printf "%Ld\n" ans


module I = Int64

(* OCaml 这 ... 没个像样的库还真是垃圾 ... *)
module type IntType = sig
  type t
  val (+): t -> t -> t
  val compare: t -> t -> int
  val rem: t -> t -> t
  val of_int: int -> t
  val of_string: string -> t
end

module Int64M = struct
  type t = Int64.t
  let (+) = Int64.add
  let compare = Int64.compare
  let rem = Int64.rem
  let of_int = Int64.of_int
  let of_string = Int64.of_string
end

module IntM = struct
  type t = int
  let (+) = (+)
  let compare = compare
  let rem = Int64.rem
  let of_int v = v
  let of_string = string_of_int
end

module Make_Judge (Int: IntType) = struct

module SetInt = Set.Make(Int)

let judge_naive (n: Int.t) (k: Int.t): bool =
  let open Int in
  let rec attempt set i =
    let x = rem n i in
    if SetInt.mem x set then false
    else
      if i >= k then true
      else attempt (SetInt.add x set) (i + (Int.of_int 1))
  in
  attempt (SetInt.empty) (Int.of_int 1)

let judge_opt (n: Int.t) (k: Int.t): bool =
  if k > Int.of_int 42
  then false
  else judge_naive n k

end

let output_yn v =
  (match v with
  | true -> print_string "Yes"
  | false -> print_string "No");
  print_char '\n'

(*
let () =
  let limit = 65536 in
  let curmax = ref 1 in
  for n = 1 to limit do
    for k = 1 to limit do
      let ret = judge_naive n k in
      if ret && k > !curmax then begin
        curmax := k;
        Printf.printf "%d %d" n !curmax;
        print_endline "";
      end
    done
  done *)

module JudgeI64 = Make_Judge (Int64M)

let () =
  let f x y = Int64M.(JudgeI64.judge_opt (of_string x) (of_string y)) |> output_yn in
  Scanf.scanf "%s %s" f


open Int64

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

let pdt a b =
	Int64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))
;;

let rec pow a n =
	if n=0 then 1 else
	let b = pow a (n/2) in
	if (n mod 2) = 0 then pdt b b else pdt a (pdt b b)
 ;;

let n = read_int 0 in
let k = read_int 0 in
Printf.printf "%d\n" (pdt (pow k (k-1)) (pow (n-k) (n-k)))


let (|>) x f = f x

let modulo = 51123987

let () =
  let n = read_int () in
  let a = read_line () in
  let rec compress m i =
    if i >= n then
      m
    else if a.[m-1] <> a.[i] then (
      a.[m] <- a.[i];
      compress (m+1) (i+1)
    ) else
      compress m (i+1)
  in
  let m = compress 1 1 in

  let p = Array.make_matrix n 3 0 in
  for i = m-1 downto 0 do
    let t = int_of_char a.[i] - int_of_char 'a' in
    p.(i).(t) <- i;
    p.(i).((t+1) mod 3) <- if i+1 < m then p.(i+1).((t+1) mod 3) else m;
    p.(i).((t+2) mod 3) <- if i+1 < m then p.(i+1).((t+2) mod 3) else m
  done;

  let dp = Array.init 2 (fun _ -> Array.make_matrix (52*52) m 0) in
  dp.(0).(0).(0) <- 1;
  let add a x y = a.(x) <- (a.(x) + y) mod modulo in
  for i = 0 to n-1 do
    for u = min ((n+2)/3) (i+1) downto 0 do
      for v = min ((n+2)/3) (i+1) downto 0 do
        Array.fill dp.((i+1) land 1).(u*52+v) 0 m 0
      done
    done;
    for u = min ((n+2)/3) i downto 0 do
      for v = min ((n+2)/3) i downto 0 do
        for j = 0 to m-1 do
          let t = dp.(i land 1).(u*52+v).(j) in
          if t > 0 then (
            let ix = u*52+v in
            if p.(j).(0) < m then
              add dp.((i+1) land 1).(ix+52) p.(j).(0) t;
            if p.(j).(1) < m then
              add dp.((i+1) land 1).(ix+1) p.(j).(1) t;
            if p.(j).(2) < m then
              add dp.((i+1) land 1).(ix) p.(j).(2) t
          )
        done
      done
    done
  done;

  let ans = ref 0 in
  for u = (n+2)/3 downto 0 do
    for v = (n+2)/3 downto 0 do
      let w = n-u-v in
      if (max u v |> max w) - (min u v |> min w) <= 1 then
        for j = 0 to m-1 do
          ans := (!ans + dp.(n land 1).(u*52+v).(j)) mod modulo
        done
    done
  done;
  Printf.printf "%d\n" !ans


open Printf

let main =
    let values = Array.map (int_of_string) (Array.of_list (Str.split (Str.regexp "\\+") (read_line()))) in

    let ans = ref "" in

    Array.sort (fun a b -> a - b) values;
    Array.iter (fun x -> ans := sprintf "%s%d+" !ans x) values;
    printf "%s\n" (String.sub !ans 0 ((String.length !ans) - 1));


let presidents = [|
  "Washington";
  "Adams";
  "Jefferson";
  "Madison";
  "Monroe";
  "Adams";
  "Jackson";
  "Van Buren";
  "Harrison";
  "Tyler";
  "Polk";
  "Taylor";
  "Fillmore";
  "Pierce";
  "Buchanan";
  "Lincoln";
  "Johnson";
  "Grant";
  "Hayes";
  "Garfield";
  "Arthur";
  "Cleveland";
  "Harrison";
  "Cleveland";
  "McKinley";
  "Roosevelt";
  "Taft";
  "Wilson";
  "Harding";
  "Coolidge";
  "Hoover";
  "Roosevelt";
  "Truman";
  "Eisenhower";
  "Kennedy";
  "Johnson";
  "Nixon";
  "Ford";
  "Carter";
  "Reagan"; |]

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


open Printf

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

let min_cut = min a (min b c);;
let d = Array.make (n+1) 0;;

let flag = Array.make (n+1) false in
    flag.(0)<- true;

    for i = 0 to n do
      if (flag.(i)) then
        begin
          if (i+a<=n && d.(i)+1 > d.(i+a) ) then
            begin
              d.(i+a) <- d.(i)+1;
              flag.(i+a)<-true
            end;
          if (i+b<=n && d.(i)+1 > d.(i+b) ) then
            begin
              d.(i+b) <- d.(i)+1;
              flag.(i+b)<- true
            end;
          if (i+c<=n && d.(i)+1 > d.(i+c) ) then
            begin
              d.(i+c) <- d.(i)+1;
              flag.(i+c) <- true
            end;
        end;
     (* Array.iter (fun x -> printf "%d " x) d;
      printf "\n"
      *)
  done

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


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

let count () =
    let l = String.length word in
    let rec loop i lowers uppers =
        if i < l
        then
            if word.[i] = Char.uppercase word.[i]
            then
                loop (i + 1) lowers (uppers + 1)
            else
                loop (i + 1) (lowers + 1) uppers
        else
            (lowers, uppers)
    in loop 0 0 0

let solve (lowers, uppers) =
    if uppers > lowers
    then
        String.uppercase word
    else
        String.lowercase word

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

let () = print (solve (count ()))


let rec fix f x = f (fix f) x;;
Scanf.(
  let n = scanf " %d" @@ fun v -> v in
  let a = Array.init n @@ fun _ -> scanf " %d" @@ fun v -> v in
  fix (fun f i x ->
    if i=n then (
      if x mod 360 = 0 then (
        print_endline "YES"; exit 0
      )
    ) else (
      f (i+1) (x+a.(i));
      f (i+1) (x-a.(i));
    )
  ) 0 0;
  print_endline "NO"
)


let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( * ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( - ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( / ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( @@ ) f x = f x

let ( |> ) x f = f x

let mult (a : (int64 array) array) b =
  let a00 = a.(0).(0) in
  let a01 = a.(0).(1) in
  let a10 = a.(1).(0) in
  let a11 = a.(1).(1) in
  let b00 = b.(0).(0) in
  let b01 = b.(0).(1) in
  let b10 = b.(1).(0) in
  let b11 = b.(1).(1)
  in
    [|
      [|
        Int64.rem (Int64.add (Int64.mul a00 b00) (Int64.mul a01 b10))
          1000000007L;
        Int64.rem (Int64.add (Int64.mul a00 b01) (Int64.mul a01 b11))
          1000000007L
      |];
      [|
        Int64.rem (Int64.add (Int64.mul a10 b00) (Int64.mul a11 b10))
          1000000007L;
        Int64.rem (Int64.add (Int64.mul a10 b01) (Int64.mul a11 b11))
          1000000007L
      |]
    |]

let rec pow arr n =
  if n = 0L
  then [| [| 1L; 0L |]; [| 0L; 1L |] |]
  else
    if n = 1L
    then arr
    else
      if (Int64.rem n 2L) = 0L
      then pow (mult arr arr) (Int64.div n 2L)
      else (mult arr) @@ (pow arr (Int64.sub n 1L))

let solve x y n =
  let arr = [| [| 1L; (-1L) |]; [| 1L; 0L |] |] in
  let arr = pow arr (Int64.sub n 1L)
  in
    (Printf.eprintf "%Ld %Ld\n%Ld %Ld\n" arr.(0).(0) arr.(0).(1) arr.(1).(0)
       arr.(1).(1);
     let ans =
       Int64.rem
         (Int64.add (Int64.mul arr.(1).(0) y) (Int64.mul arr.(1).(1) x))
         1000000007L
     in
       (Printf.printf "%Ld\n") @@
         (if ans < 0L then Int64.add ans 1000000007L else ans))

let () = Scanf.scanf "%Ld %Ld %Ld " (fun x y n -> solve x y n)


module Array = ArrayLabels

module List = ListLabels

let pf = Printf.printf

let sf = Scanf.scanf

external uget : 'a array -> int -> 'a = "%obj_field"

external uset : 'a array -> int -> 'a -> unit = "%obj_set_field"

let ( |> ) x f = f x

let ps = [| 2; 3; 5; 7; 11; 13; 17; 19; 23; 29; 31; 37; 41; 43; 47; 53 |]

let rev_ps =
  let r = Array.create 60 (-1)
  in (Array.iteri ps ~f: (fun i x -> uset r x i); r)

let np = Array.length ps

let inf = 1_000_000

let p16 = 1 lsl (Array.length ps)

let dp = Array.create_matrix (100 + 1) p16 ((-1), (-1), inf)

let rec unique ls =
  match ls with
  | [] | [ _ ] -> ls
  | x :: y :: ls when x = y -> unique (x :: ls)
  | x :: ls -> x :: (unique ls)

let pd =
  Array.init 59
    ~f:
      (fun n ->
         if (n = 0) || (n = 1)
         then 0
         else
           (let rec iter n i =
              if i = n
              then [ n ]
              else
                if (n mod i) = 0
                then i :: (iter (n / i) 2)
                else iter n (i + 1) in
            let ps = (iter n 2) |> unique in
            let res = ref 0 in
            let cnt = ref 0
            in
              (List.iter ps
                 ~f:
                   (fun i ->
                      (res := !res lor (1 lsl (uget rev_ps i)); incr cnt));
               !res)))

let solve n arr =
  (uset (uget dp 0) 0 ((-1), (-1), 0);
   for i = 0 to n - 1 do
     (let cur = i in
      let next = i + 1
      in
        for state = 0 to p16 - 1 do
          for j = 1 to 58 do
            let (prev, _, cost) = uget (uget dp cur) state
            in
              if cost < inf
              then
                if (state land (uget pd j)) = 0
                then
                  (let state' = state lor (uget pd j) in
                   let (_, _, c) = uget (uget dp next) state'
                   in
                     if (cost + (abs ((uget arr i) - j))) < c
                     then
                       uset (uget dp next) state'
                         (state, j, (cost + (abs ((uget arr i) - j))))
                     else ())
                else ()
              else ()
          done
        done)
   done;
   let (min_idx, min) = ((ref (-1)), (ref inf))
   in
     (for i = 0 to p16 - 1 do
        (let (_, _, c) = uget (uget dp n) i
         in if !min > c then (min_idx := i; min := c) else ())
      done;
      let rec iter i s =
        if i <= 0
        then []
        else
          (let (prev, v, _) = uget (uget dp i) s in v :: (iter (i - 1) prev))
      in
        (((iter n !min_idx) |> List.rev) |>
           (List.iter ~f: (fun i -> pf "%d " i));
         pf "\n")))

let () =
  sf "%d "
    (fun n -> solve n (Array.init n ~f: (fun _ -> sf "%d " (fun i -> i))))


let [n; t] = read_line () |> Str.(split (regexp " ")) |> List.map int_of_string

let x = Array.init n (fun i -> Array.make (i+1) 0.)

let pour i j amount =
  x.(i).(j) <- x.(i).(j) +. amount

let () =
  for _t = 1 to t do
    x.(0).(0) <- x.(0).(0) +. 1.;
    for i = 0 to n - 2 do
      for j = 0 to i do
        if x.(i).(j) > 1. then
          let drop = (x.(i).(j) -. 1.) /. 2. in
          pour (i+1) j drop;
          pour (i+1) (j+1) drop;
          x.(i).(j) <- 1.
      done
    done
  done;
  let r = ref 0 in
  for i = 0 to n-1 do
    for j = 0 to i do
      if x.(i).(j) >= 1. then
        incr r
    done
  done;
  Printf.printf "%d\n" !r


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

let solve (s0, s1) = String.compare (String.lowercase s0) (String.lowercase s1)

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

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


let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( * ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( - ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( / ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false

let ( @@ ) f x = f x

let ( |> ) x f = f x

let solve n m k =
  let low = max 0L (Int64.add (Int64.sub k m) 1L) in
  let high = min k (Int64.sub n 1L)
  in
    if low > high
    then Printf.printf "-1\n"
    else
      (let x =
         Int64.mul (Int64.div n (Int64.add low 1L))
           (Int64.div m (Int64.add (Int64.sub k low) 1L)) in
       let y =
         Int64.mul (Int64.div n (Int64.add high 1L))
           (Int64.div m (Int64.add (Int64.sub k high) 1L))
       in (Printf.printf "%Ld\n") @@ (max x y))

let () = Scanf.scanf "%Ld %Ld %Ld " (fun n m k -> solve n m k)


(*************** Ocaml stdio functions **********************)
let stdin_stream = Stream.of_channel stdin;;
let stdout_buffer = Buffer.create 65536;;
let rec gi() =
  match Stream.next stdin_stream with
    '-' ->  - (ri 0)
  | '+' ->  ri 0
  | '0'..'9' as c -> ri ((int_of_char c) - 48)
  | _ -> gi ()
and ri x =
  match Stream.next stdin_stream with
    '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))
  | _ -> x
;;
let flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;
let putchar c =
  if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();
  Buffer.add_char stdout_buffer c;;
let rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;
let pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;
let pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\n' else ' ')) a;;
(*************** Ocaml solution ******************************)
open Array
let main() =
  let s = Scanf.scanf "%s" (fun i -> i) in
  let l = String.length s in
  let rec f i k ch =
    if i == l then 1
    else (match k with
            (1|2|3|4) -> (if s.[i] == ch then f (i+1) (k+1) ch else (1 + (f (i+1) 1 s.[i])))
          | _ -> 1 + (f (i + 1) 1 s.[i])
         )
   in
  Printf.printf "%d\n" (f 1 1 s.[0])
  ;;
main();;
flushout ()


let _ =
  let sb = Scanf.Scanning.stdib in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let b = Scanf.bscanf sb "%d " (fun s -> s) in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let t = Scanf.bscanf sb "%d " (fun s -> s) in
  let x = ref 1L in
  let d = ref 0 in
    while !x <= Int64.of_int t do
      x := Int64.add (Int64.mul !x (Int64.of_int k)) (Int64.of_int b);
      incr d;
    done;
    let res = max (n - !d + 1) 0 in
      Printf.printf "%d\n" res;


let func str ch=
    let cnt=ref 0 in
    for i=1 to String.length(str) do
        if (!cnt!=7 && str.[i-1]==ch) then cnt:=!cnt+1
        else if !cnt!=7 then cnt:=0
    done;

    if !cnt==7 then 1 else 0;;

let str=read_line();;
if ((func str '1')+(func str '0')>0) then print_endline("YES")
else print_endline("NO")


let i = Scanf.sscanf (read_line ()) "%i" (fun i -> i) in
print_int @@ i mod 2


let (n, k) = Scanf.scanf "%d %Ld" (fun n -> fun k -> (n, k));;

let b2i b = if b then 1 else 0;;

let rec count (memo: int64 array) str l r chki chkr =
	if l > r then 1L
	else
		let idx = (l * 2 + b2i chki) * 2 + b2i chkr in
		if memo.(idx) > -1L
		then memo.(idx)
		else
			let ans = ref 0L in
			for bl = 0 to 1 do
				if str.(l) = -1 || str.(l) = bl then
				for br = 0 to 1 do
					if l < r || bl = br then
					if str.(r) = -1 || str.(r) = br then
					if not (chki && bl = br && bl = 1) && not (chkr && bl > br) then
						ans := Int64.add !ans (count memo str (l + 1) (r - 1) (chki && not (bl = 0 && br = 0)) (chkr && not (bl < br)))
				done;
			done;
			memo.(idx) <- !ans;
			!ans
;;

let str = Array.create n (-1);;
let new_memo = Array.create (4*n) (-1L);;
let do_count () = count (Array.copy new_memo) str 0 (n - 1) true true;;

if do_count () <= k
then print_endline "-1"
else
	let rk = ref (k) in
		for i = 0 to n - 1 do
			str.(i) <- 0;
			let f = do_count () in begin
				if !rk >= f then begin
					rk := Int64.sub !rk f;
					str.(i) <- 1;
				end
			end
		done;

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


(* load str.cma *)
let n = int_of_string (input_line stdin);;
let a = List.map int_of_string (Str.split (Str.regexp " +") (input_line stdin));;

let calc a t = let a1 = t - (List.hd a) and
                   ar = List.filter (( < ) 0) (List.map (fun x -> x - t + 1) (List.tl a))
               in max a1 (List.fold_left ( + ) 0 ar);;

let rec range i j = if i > j then [] else i :: (range (i+1) j);;

let t1 = List.hd a and
    t2 = List.fold_left max 0 a
    in let x=List.map (calc a) (range t1 (t2+1))
    in print_int (List.fold_left min 1000 x);;
print_string "\n";;


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

let ident x = x ;;

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 m = Scanf.scanf "%d " ident in
  let cs = fold_for 0 m ~init:[] ~f:(fun acc _ ->
    Scanf.scanf "%d " ident :: acc) |> List.rev in
  let x, y = Scanf.scanf "%d %d " (fun x y -> x, y) in
  let sum = List.fold_left cs ~init:0 ~f:(+) in
  let res = ref (-1) in
  Printf.eprintf "%d %d %d\n" x y sum;
  try
    List.fold_left cs ~init:(1, 0, sum)  ~f:(fun (i, a, b) cur ->
      Printf.eprintf "x, a, b = %d, %d, %d\n" cur a b;
      if x <= a && a <= y && x <= b && b <= y then (res := i; raise Exit)
      else (i + 1, a + cur, b - cur));
    print_endline "0";
  with
  | Exit -> Printf.printf "%d\n" !res
;;


let [a; b]= List.map (Int64.of_string) (Str.split (Str.regexp " ") (read_line ())) and ans= ref 0L;;
let bb= Array.make 65 0 and x= ref 0L and p= ref 0L;;
for i= 2 to 63 do
	for j= 1 to i - 1  do
		for k= 1 to i do Array.set bb k 1 done;
		Array.set bb j 0;
		x := 0L; p := 1L;
		for k= 1 to i do
			if bb.(k) = 1 then x := Int64.add !x !p;
			p := Int64.mul !p 2L;
		done;
		if a <= !x && !x <= b then
			ans := Int64.add !ans 1L;
	done
done;;
print_endline (Int64.to_string !ans)


let ( + ) = Int64.add
let ( * ) = Int64.mul
let ( - ) = Int64.sub
let ( mod ) = Int64.rem
let two = Int64.one + Int64.one
let one = Int64.one
let zero = Int64.zero
let three = Int64.succ two

let mult arr1 arr2 =
  let norm n = n mod (Int64.of_int 1000000007) in
  let ((a1,a2),(a3,a4)) = arr1 in
  let ((b1,b2),(b3,b4)) = arr2 in
  (((norm (a1*b1+a2*b3)),(norm (a1*b2+a2*b4))),((norm (a3*b1+a4*b3)),(norm (a3*b2 + a4*b4))))
;;

let solve =
  let n = Scanf.scanf "%Ld\n" (fun n -> n) in
  let startarr = ((zero,three),(one,two)) in
  let rec doRest arr power =
    match (n - power) with
      | num when num = zero -> arr
      | _ -> doRest (mult arr startarr) (power+one)
  in
  let rec arrayPower arr power =
    match (two*power) with
      | nxtPower when (nxtPower > n) -> doRest arr  power
      | nxtPower -> arrayPower (mult arr arr) nxtPower
  in
  let ((sol,_),(_,_)) = arrayPower startarr one in
    Printf.printf "%Ld\n" sol
;;


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

let rep n f =
  let rec go i acc =
    if i >= n then
      List.rev acc
    else
      go (i+1) (f i::acc)
  in go 0 []

let () =
  let [a;b;c;d] = rep 4 read_int |> List.sort compare in
  (match max (a+b-c) (b+c-d) with
  | 0 -> "SEGMENT"
  | x when x > 0 -> "TRIANGLE"
  | _ -> "IMPOSSIBLE") |> print_endline


let [a; b]= List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()));;
Printf.printf "%d %d\n" (min a b) (((max a b)-(min a b))/2)


let rec digits n =
  if n <= 7 then
    1
  else
    1 + digits ((n + 6) / 7)

let show display offset digits number =
  let r = ref number in
  for i = offset + digits - 1 downto offset do
    display.(i) <- !r mod 7;
    r := !r / 7
  done

let distinct array =
  let r = ref true in
  let right = Array.length array - 1 in
  for i = 0 to right do
    for j = i + 1 to right do
      if array.(i) == array.(j) then
        r := false
    done
  done;
  !r

let () =
  match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
  | [n; m] ->
     let digits_h = digits n in
     let digits_m = digits m in
     let digits = digits_h + digits_m in
     if digits > 7 then
       print_endline "0"
     else
       let display = Array.make digits 0 in
       let r = ref 0 in
       for hour = 0 to n - 1 do
         for min = 0 to m - 1 do
           show display 0 digits_h hour;
           show display digits_h digits_m min;
           if distinct display then
             incr r
         done
       done;
       print_int !r;
       print_newline ()
  | _ -> assert false


let m = function "monday"->0 | "tuesday"->1 | "wednesday"->2 | "thursday"->3 | "friday"->4 | "saturday"->5 | "sunday" -> 6 and
ms = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30] in
let a = m @@ read_line () and
b = m @@ read_line () in
let c = List.filter (fun x -> ( a + x ) mod 7 == b ) ms in
print_string @@ if List.length c > 0 then "YES" else "NO"


let solve a = print_string "1"; for i= 1 to a-1 do print_string "0" done;;
let [n; m]= Str.split (Str.regexp " ") (read_line ());;
if n = "1" && m = "10" then
	print_string "-1"
else if m = "10" then
	solve (int_of_string n)
else
	for i= 1 to int_of_string n do print_string m done;;
print_endline ""


let rec ajoute_fin x y = function
	| []	-> [x;y]
	| t::q	-> t::(ajoute_fin x y q)

let rec joue res win t p1 p2 =
	try (let a = Hashtbl.find t (!p1,!p2) in win := 0)
	with Not_found  ->
	begin
		incr res;
		Hashtbl.add t (!p1,!p2) ();
		match (!p1,!p2) with
			| _,[]		-> win := 1
			| [],_		-> win := 2
			| (a::b),(c::d)	->
			begin
			if a > c
				then (p1 := ajoute_fin c a b; p2 := d)
				else (p2 := ajoute_fin a c d; p1 := b);
				joue res win t p1 p2;
			end
	end

let _ =
	let k1 = Scanf.scanf "%d %d " (fun _ i -> i) and l1 = ref [] in
		for i = 1 to k1 do
			Scanf.scanf "%d " (fun j -> l1 := j:: !l1);
		done;
	let k2 = Scanf.scanf "%d" (fun i -> i) and l2 = ref [] in
		for i = 1 to k2 do
			Scanf.scanf " %d" (fun j -> l2 := j :: !l2);
		done;
	let res = ref (-1) and win = ref 42 and p1 = ref (List.rev !l1)
	and p2 = ref (List.rev !l2) and t = Hashtbl.create 0 in
		joue res win t p1 p2;
	if !win = 0
		then Printf.printf "-1"
		else Printf.printf "%d %d" (!res) (!win)


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

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

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

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

let dajLiczbe x =
    (Char.code x) -
    (Char.code 'a') + 1;;

let naKrawedzi x =
    match x with
    | 1 -> 1
    | 8 -> 1
    | _ -> 0;;

let policz x y =
    let count = (naKrawedzi x) + (naKrawedzi y) in
        match count with
        | 0 -> 8
        | 1 -> 5
        | 2 -> 3
        | _ -> begin assert(false); 0 end;;

let readInput () = Scanf.scanf "%c%d\n" (fun x y -> x, y);;

let _ =
    let (a,b) = readInput () in
    Printf.printf "%d" (policz (dajLiczbe a) b);;


let words s = Str.split (Str.regexp " ") s;;

let check n lst =
  let threshold = List.nth lst (n - 1)
  in
  List.length (List.filter (fun m -> 0 < m && threshold <= m) lst)
;;

let rec take lst n =
  match (lst, n) with
    [], _ -> []
  | lst, 0 -> lst
  | x::xs, n -> x::(take xs (n - 1))
;;

let () =
  let nk = words (read_line ()) in
  let [n; k;] = List.map int_of_string nk in
  let score_line = take (words (read_line ())) n in
  let scores = List.map int_of_string score_line
  in
  Printf.printf "%d\n" (check k scores)
;;


let _ =
    let main () =
        let rev k =
            let rec loop i acc =
                if i = 0. then acc else loop (floor (i /. 10.)) (acc *. 10. +. (mod_float i 10.))
            in
            loop (float k) 0.
        in
        let f a b =
            Printf.printf "%.f\n" (float a +. rev b)
        in
        Scanf.sscanf (read_line ()) "%d %d" f
    in
    main ()


let read_int () = Scanf.scanf " %d " (fun x -> x);;
let read_long () = Scanf.scanf " %Ld " (fun x -> x);;
let read_pair () = let a = read_long () in ( a , read_long () );;

let n , k = read_pair ();;

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

let rec solve sum ans =
        (*Printf.printf "%Ld %Ld\n" sum ans;*)
        let a = sum ++ Int64.of_int 1 and b =  sum -- (k -- ans ++ Int64.of_int 2) ++ Int64.of_int 2 ** (k -- ans ++ Int64.of_int 1) in
        if ans >= k then Printf.printf "-1\n"
        else  if Int64.compare a n <=0  && Int64.compare b n >= 0 then
                Printf.printf "%Ld\n" ans
        else solve b (ans ++ Int64.of_int 1);;

let binary_search () =
        let left = ref (Int64.of_int 2) and right = ref (k -- Int64.of_int 1) in
        (*Printf.printf "%Ld %Ld\n" !left !right;*)
        while !left <= !right do
                let mid = ((!left ++ !right)//(Int64.of_int 2)) in let a = ((mid ** (Int64.of_int 2 ** k -- Int64.of_int 1
                -- mid)) // Int64.of_int 2 ++ Int64.of_int 1) in
                if  a < n then left := mid ++ (Int64.of_int 1)
                else right := mid -- (Int64.of_int 1)
        done;
        !left;;

if n = Int64.of_int 1 then Printf.printf "0\n"
else if n>= Int64.of_int 2 && n<=k then Printf.printf "1\n"
else let ans = binary_search () in if ans <= (k -- Int64.of_int 1) then
        Printf.printf "%Ld\n" ans
                                    else Printf.printf "-1\n";;


let rand_int()=Scanf.scanf " %d" (fun x->x);;
let n=rand_int();;
let tab=Array.init n (fun i->rand_int());;

let l=ref [];;

let rec inserer v=function
|[]->[v]
|h::t->if v<h then v::h::t else h::(inserer v t);;

for i=0 to n-1 do
   l:=inserer tab.(i) !l
done;;

let rec print_list=function
|[]->()
|h::t->print_int h;print_string " ";print_list t;;

print_list !l;;


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
  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 min = L.fold min max_int

let () =
  print_int
    begin
      match n_int 8 () with
          [n;k;l;c;d;p;nl;np] ->
            (min [di(k*l/nl); di(c*d); di(p/np)]) / n
        | _ -> assert false
    end


let list_1 = ["zero";"one";"two";"three";"four";"five";"six";"seven";"eight";"nine"];;
let list_2 = ["ten";"eleven";"twelve";"thirteen";"fourteen";"fifteen";"sixteen";"seventeen";"eighteen";"nineteen"];;
let list_3 = ["";"";"twenty-";"thirty-";"forty-";"fifty-";"sixty-";"seventy-";"eighty-";"ninety-"];;

let rec toInt s cur ten value =
  if cur < 0 then value
  else toInt s ( cur - 1 ) ( ten * 10 ) ( value + ten * ( Char.code ( String.get s cur ) - Char.code '0' ) );;

let getWord s =
  let x = ( toInt s ( String.length s - 1 ) 1 0 ) in
    if 0 <= x && x <= 9 then Printf.printf "%s\n" ( List.nth list_1 x )
    else if 10 <= x && x <= 19 then Printf.printf "%s\n" ( List.nth list_2 ( x - 10 ) )
    else if ( x mod 10 ) = 0 then Printf.printf "%s\n" ( String.sub ( List.nth list_3 ( x / 10 ) ) 0 ( String.length ( List.nth list_3 ( x / 10 ) ) - 1 ) )
    else Printf.printf "%s%s\n" ( List.nth list_3 ( Char.code ( String.get s 0 ) - Char.code '0' ) ) ( List.nth list_1 ( Char.code ( String.get s 1 ) - Char.code '0' ) ) ;;

let s = Scanf.scanf "%s\n" ( fun s -> s ) in getWord s;;


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

  let rec pow (x, y) =
    if y = 0 then 1 else x * pow (x, y - 1)
  in
  let ans_l = ["Sheldon"; "Leonard"; "Penny"; "Rajesh"; "Howard"] in
  let rec aux acc cnt n =
    if acc < n then aux (acc*2) (cnt+1) (n-acc)
    else
      let i = pow (2, (cnt-1)) in
      let ans_i = if n mod i = 0 then (n/i) else n/i+1 in
      List.nth ans_l (ans_i-1)

  in

  Printf.printf "%s\n" @@ aux 5 1 n


let s= Array.of_list (Str.split (Str.regexp " ") (read_line ())) and ans= ref 0;;
let x= int_of_string s.(0);;
if s.(2) = "week" then
	let day = ref 5 in
	begin
		for i = 1 to 366 do
			if !day = 8 then
				day := 1;
			if !day = x then
				ans := !ans + 1;
			day := !day + 1
		done;
		print_int (!ans);
	end
else
	let month= [|31; 29; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31 |] in
	begin
		for i = 0 to 11 do
			if month.(i) >= x then
				ans := !ans + 1
		done;
		print_int (!ans)
	end;;


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

let n = read_int()

let mmin = ref 0L
let mmax = ref 0L

let consider a b c =
  let aa = Int64.of_int (a+1) in
  let bb = Int64.of_int (b+2) in
  let cc = Int64.of_int (c+2) in
  let m = Int64.mul (Int64.mul aa bb) cc in
    if !mmin = 0L || m < !mmin then mmin := m;
    if !mmax = 0L || m > !mmax then mmax := m

let tryit a = (* we know that a divides into n *)
  let x = n/a in
  let rec loop b =
    let c = x/b in
      if c < b then () else (
	if b*c=x then consider a b c;
	loop (b+1)
      )
  in
    loop 1

let rec loop a =
  let x = n/a in
    if x < a then () else (
      if x*a=n then (
	tryit a;
	tryit x;
      );
      loop (a+1)
    )

let () =
  loop 1;
  let fix a = Int64.to_string (Int64.sub a (Int64.of_int n)) in
  Printf.printf "%s %s\n" (fix !mmin) (fix !mmax);


let min_max a c = match a, c with
  0, 0 -> print_string "0 0"
| a, 0 -> Printf.printf "%d %d\n" a a
| 0, c -> print_string "Impossible\n"
| a, c -> Printf.printf "%d %d\n" (max a c) (a + c - 1)
;;

Scanf.scanf "%d %d" min_max;;


let main () =
  let gr () = Scanf.scanf " %d" (fun i -> i) in
  let n = gr () in
  let k = gr () in
  let rec f x y =
      if y == 0
      then x
      else
          if x mod 10 == 0
          then f (x / 10) (y - 1)
          else f (x - 1) (y - 1)
  in
  Printf.printf "%d\n" (f n k)
  ;;
let _ = main();;


let () =
  let a = Array.init 3 (fun _ -> read_line ()) in
  print_endline (if List.for_all (fun (x,y) -> a.(1-x).[1-y] = a.(1+x).[1+y])
    [-1,0; -1,1; 0,1; 1,1] then "YES" else "NO")


let rec count_ring_amount k w h =
	if k = 0 then 0
	else 2*w + 2*h - 4 + count_ring_amount (k - 1) (w - 4) (h - 4);;
let (w, h, k) = Scanf.scanf "%i %i %i" (fun x y z -> (x, y, z));;
Printf.printf "%i" (count_ring_amount k w h);;


let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let a = Array.make n 0 in
  let _ =
    for i = 0 to n - 1 do
      a.(i) <-
	match s.[i] with
	  | 'R' -> 0
	  | 'B' -> 1
	  | 'Y' -> 2
	  | 'G' -> 3
	  | '!' -> -1
	  | _ -> assert false
    done;
  in
  let b = Array.make 4 0 in
  let res = Array.make 4 0 in
    for i = 0 to n - 1 do
      if a.(i) >= 0
      then b.(i mod 4) <- a.(i)
    done;
    for i = 0 to n - 1 do
      if a.(i) < 0
      then res.(b.(i mod 4)) <- res.(b.(i mod 4)) + 1
    done;
    Printf.printf "%d %d %d %d\n" res.(0) res.(1) res.(2) res.(3)


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

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

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

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

let inside (a,b) (c,d) (e,f) =
  let x1 = min c e
  and x2 = max c e
  and y1 = min d f
  and y2 = max d f in
  if x1 <= a && a <= x2 && ( b = y1 || b = y2 ) then true
  else if y1 <= b && b <= y2 && ( a = x1 || a = x2 ) then true
  else false;;

let wynik (a,b) (c,d) (e,f) =
  if a = c && c = e then 1
  else if b = d && d = f then 1
  else if inside (a,b) (c,d) (e,f) then 2
  else if inside (c,d) (a,b) (e,f) then 2
  else if inside (e,f) (a,b) (c,d) then 2
  else 3;;

let _ =
  let (a,b) = read2 ()
  and (c,d) = read2 ()
  and (e,f) = read2 () in
  Printf.printf "%d" ( wynik (a,b) (c,d) (e,f) );;


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

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

let (n,m) = (min n m, max n m)

let answer =
  if n=1 then m
  else if n=2 then 4*(m/4) +
    (if m mod 4 = 0 then 0 else if m mod 4 = 1 then 2 else 4)
  else (n*m - ((n*m)/2))
let () = Printf.printf "%d\n" answer


let () = Scanf.scanf "%d %d\n" (fun n k ->
  let i = Array.init n (fun i -> Scanf.scanf "%d%_c" (fun x -> (x, i + 1))) in
  Array.sort compare i;
  let _, l = Array.fold_left (fun (a, l) (t, i) ->
    if a + t <= k then (a + t, i :: l)
    else (a + t, l)
  ) (0, []) i
  in
  let len = List.length l in
  Printf.printf "%d\n" len;
  if len > 0 then
    print_endline (String.concat " " (List.map string_of_int l))
)


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

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

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

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

let rec licz n b a =
  if n = 1 then
    let x = Scanf.scanf "%Ld\n" (fun x -> x) in
    a *| b +| x
  else
    let x = Scanf.scanf "%Ld " (fun x -> x) in
    licz (n-1) b ( a *| b +| x );;

let _ =
  let (n,a) = Scanf.scanf "%d %Ld\n" (fun x y -> x, y) in
  let sa = licz n a Int64.zero
  and (n,b) = Scanf.scanf "%d %Ld\n" (fun x y -> x, y) in
  let sb = licz n b Int64.zero in
  Printf.printf "%c\n"
  (if compare sa sb < 0 then '<' else if compare sa sb = 0 then '=' else '>');;


Scanf.scanf "%s\n" (fun w ->
	let c = String.get w 0 in
	if (String.uppercase w = w) || (Char.lowercase c = c &&
		let ss = (String.sub w 1 (String.length w - 1)) in
			String.uppercase ss = ss
	) then
	String.iter (fun c ->
		if Char.uppercase c = c
			then print_char (Char.lowercase c)
			else print_char (Char.uppercase c)
	) w
	else print_string w
);;


let _ =
   let n,i = Scanf.scanf "%d %d" (fun j k -> (j,k-1)) in
   let tab = Array.init n (fun _ -> Scanf.scanf " %d" (fun j -> j)) in
   let cpt = ref (tab.(i)) in
      for j = 1 to max (n-i-1) i do
         let ok_l = j > i || tab.(i-j) = 1 in
         let ok_r = i+j >= n || tab.(i+j) = 1 in
            if ok_l && ok_r
            then cpt := !cpt + (if j > i then 0 else 1)
                             + (if i+j >= n then 0 else 1);
      done;
      Printf.printf "%d" !cpt


module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue
module S = String

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

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

let id x = x
let id2 x y = (x, y)
let id3 x y z = (x, y, z)
let id4 a b c d = (a, b, c, d)
let id5 a b c d e = (a, b, c, d, e)

let err s = raise (Failure s)

let inf = 1000000000
let eps = 1e-11

let _ =
  let n = sf "%d " id in
  let (a1, b1) = sf "%d %d " id2 in
  let (a2, b2) = sf "%d %d " id2 in
  let (a3, b3) = sf "%d %d " id2 in
  let rest = n - a1 - a2 - a3 in
  let u = min rest (b1 - a1) in
  let (rest, r1) = rest - u, a1 + u in
  let u = min rest (b2 - a2) in
  let (rest, r2) = rest - u, a2 + u in
  let u = min rest (b3 - a3) in
  let (rest, r3) = rest - u, a3 + u in
  pf "%d %d %d\n" r1 r2 r3
;;


(*  The test is: 3 RGR  Answer is: BG *)

open Printf
open Scanf

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

  let hist = Array.make 3 0 in

  for i=0 to n-1 do
    let c = match s.[i] with
      | 'B' -> 0
      | 'G' -> 1
      | 'R' -> 2
      | _ -> failwith "bad input"
    in
    hist.(c) <- 1 + hist.(c)
  done;

  let ar = [|(hist.(0), 0); (hist.(1), 1); (hist.(2),2)|] in

  Array.sort compare ar;

  let answer = if (fst ar.(0)) > 0 then [0;1;2]
    else if (fst ar.(1)) > 0 then (
      let k = fst ar.(1) in
      let l = fst ar.(2) in
      if (k,l) = (1,1) then [snd ar.(0)]
      else if k > 1 && l > 1 then [0;1;2]
      else if k = 1 then List.sort compare [snd ar.(0); snd ar.(1)]
      else failwith "impossible"
    )
    else [snd ar.(2)]
  in

  List.iter (fun i -> printf "%c" ("BGR".[i])) answer;
  print_newline()


open Scanf
open Printf

let n, b = scanf "%d %d" (fun n b -> n, b)

let l = Array.to_list (Array.init n (fun i -> scanf " %d" (fun i -> i)))

let cost x y = abs (x - y)

let order l = List.sort compare l

let cost_l l =
  let rec loop l o e out =
    match l with
    | [] -> order out
    | [h] -> order out
    | h::(h'::_ as t) ->
      let o, e = if h mod 2 = 0 then o, e+1 else o+1, e in
      if o = e && o <> 0 then
        loop t o e ((cost h h')::out)
      else loop t o e out
  in loop l 0 0 []

let aggreg l b =
  List.fold_left
    (fun (outi, outc) c ->
      if outc + c <= b then
        (outi + 1, outc + c)
      else
        (outi, outc))
    (0, 0) l

let () =
  let c_l = cost_l l in
  let outi, outc = aggreg c_l b in
  printf "%d\n" outi;
  ()


(* Codeforces 266A Kamni - very easy *)

open List;;
open String;;
open Array;;
open Int64;;
open Printf;;

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 grs () = Scanf.scanf " %s" (fun s -> s);;
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 printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string " ")) ai;;
let readpair () =
	let a = gr() in
	let b = gr() in
	(a, b);;

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

let rec countsame i n s acc =
	if i==(n-1) then acc
	else
		let nacc = (if s.[i]==s.[i+1] then acc+1 else acc) in
		countsame (i+1) n s nacc;;

let main () =
	let n = gr () in
	let s = grs() in
	let ns = countsame 0 n s 0 in
	(print_int ns; print_newline());;

main();;


let s=read_int() in
let rec find now =
 if s mod now=0 then Printf.printf "%d %d" now (s/now) else find (now-1) in
find  (int_of_float (sqrt (float_of_int s)))


let rec gcd n m =
    match m with
    | 0 -> n
    | _ -> gcd m (n mod m)
;;

let lcm n m = n * m / (gcd n m)

let handle_input n m z =
    let d = lcm n m in
    let count = z / d in
    begin
        print_int count;
        print_newline;
    end
;;

let read_ints () =
    Scanf.bscanf Scanf.Scanning.stdin "%i %i %i" handle_input
;;

read_ints ();;


open Big_int

let yolo = Big_int.big_int_of_int 1000000007;;

let rec pow p x = function
    | 0 -> Big_int.big_int_of_int 1
    | i -> let sq = pow p x (i/2) in
               if i mod 2 = 0
                   then Big_int.mod_big_int (Big_int.mult_big_int sq sq) p
                   else Big_int.mod_big_int (Big_int.mult_big_int (Big_int.mod_big_int (Big_int.mult_big_int sq sq) p) x) p

let rec find tab i =
    if tab.(i) = i
        then i
        else find tab (tab.(i))

let main () =
    let (p,k) = Scanf.scanf "%s %s" (fun i j -> (Big_int.big_int_of_string i,Big_int.big_int_of_string j)) in
    let tab = Array.init (Big_int.int_of_big_int p) (fun i -> i) and tab' = Array.make (Big_int.int_of_big_int p) false and res = ref (-1) in
        for i = 0 to (Big_int.int_of_big_int p)-1 do
             tab.(i) <- find tab (tab.(Big_int.int_of_big_int (Big_int.mod_big_int(Big_int.mult_big_int k (Big_int.big_int_of_int i)) p)));
        done;
        for i = 0 to (Big_int.int_of_big_int p)-1 do
            let a = find tab (tab.(i)) in
                if not (tab'.(a))
                    then (incr res; tab'.(a) <- true);
        done;
        match Big_int.int_of_big_int k with
            | 0 -> Printf.printf "%s" (Big_int.string_of_big_int (pow yolo p ((Big_int.int_of_big_int p) - 1)))
            | 1 -> Printf.printf "%s" (Big_int.string_of_big_int (pow yolo p (Big_int.int_of_big_int p)))
            | _ -> Printf.printf "%s" (Big_int.string_of_big_int (pow yolo p !res));;

main ();;


let readLine () : int * int =
  let makePair x y = (x,y) in
    Scanf.sscanf (read_line ()) "%d %d" makePair

let getInput () =
  let numDays, sumTime = readLine () in
  let rec helper currDay accum =
    if currDay > numDays
    then accum
    else helper (currDay + 1) ((readLine ()) :: accum)
  in
  let workMinMaxes = List.rev (helper 1 []) in
    (numDays, sumTime, workMinMaxes)

let homogenizeConstraints sumTime dayConstraints =
  let folder (min, max) (currSumTime, newMaxes) =
    (currSumTime - min, max - min :: newMaxes)
  in
    List.fold_right folder dayConstraints (sumTime, [])

(* this guy counts up *)
let getReducedWorkTimes reducedSum reducedMaxes =
  let folder reducedMax (currSum, workTimes) =
    let todaysWorkTime = min (reducedSum - currSum) reducedMax in
      (currSum + todaysWorkTime, todaysWorkTime :: workTimes)
  in
    List.fold_right folder reducedMaxes (0, [])

let negative = "NO\n"
let positive = "YES\n"

(* main part *)
let () =
  let numDays, sumTime, dayBounds = getInput () in
  let reducedSumTime, reducedMaxes = homogenizeConstraints sumTime dayBounds in
    if reducedSumTime < 0
    then print_string negative
    else
        let (reducedTotalSum, reducedTimes) = getReducedWorkTimes reducedSumTime reducedMaxes in
          if reducedTotalSum < reducedSumTime
          then print_string negative
          else
            let actualWorkTimes = List.map2 (fun reducedTime (min, max) -> reducedTime + min) reducedTimes dayBounds in
              print_string positive;
              List.iter (Printf.printf "%d ") actualWorkTimes;
              print_newline ();


(* Hungry Student Problem 903 A *)

(* 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 rec one_case n7 k =
	if k < 0 then false
	else if n7 < 0 then false
	else if (k mod 3) == 0 then true
	else one_case (n7 - 1) (k - 7);;

let main() =
	let n = gr() in
	begin
		for i = 1 to n do
			let x = gr() in
			let can = one_case 3 x in
			let ans = if can then "YES\n" else "NO\n" in
			print_string ans
		done
	end;;

main();;


let moy tab =
	let compt = ref 0. in
	for i=0 to Array.length tab -1 do
		compt := tab.(i) *. (float_of_int i) +. !compt;
	done;
	!compt;;

let f n t p =
	let mat = Array.make_matrix (t+1) (n+1) 0. in
	mat.(0).(0) <- 1.;
	for i=1 to t do
		mat.(i).(0) <- (1. -. p) *. mat.(i-1).(0);
	done;
	for i=1 to t do
		for j=1 to min i n do
			mat.(i).(j) <- p *. mat.(i-1).(j-1)
				      +. (if j=n then 1. else (1. -. p)) *. mat.(i-1).(j);
		done;
	done;
	moy (mat.(t));;

let formatte x =
	let partie_ent = int_of_float x in
	let partie_dec = int_of_float (100. *. (x -. float_of_int partie_ent)) in
	if partie_dec = 0
		then Printf.printf "%d" partie_ent
		else if partie_dec mod 10 = 0
			then Printf.printf "%d.%d" partie_ent (partie_dec / 10)
			else if partie_dec mod 100 = 0
				then Printf.printf "%d.%d" partie_ent (partie_dec / 100)
				else if partie_dec mod 1000 = 0
					then Printf.printf "%d.%d" partie_ent (partie_dec / 1000)
					else if partie_dec mod 10000 = 0
						then Printf.printf "%d.%d" partie_ent (partie_dec / 10000)
						else if partie_dec mod 100000 = 0
							then Printf.printf "%d.%d" partie_ent (partie_dec / 100000)
							else Printf.printf "%d.%d" partie_ent partie_dec;;

let main () =
	let (a,b,c) = Scanf.scanf "%d %f %d " (fun i j k -> (i,j,k)) in
	Printf.printf "%f " (f a c b);;

main ();;


open Scanf

let list_of_string (s: string): char list =
  let rec loop (i: int) (l: char list): char list =
    if i = 0
    then l
    else loop (i - 1) ((String.get s (i - 1)) :: l)
  in
  loop (String.length s) []

(* CFP: list_of_string, print_yn, fold w/ termination? *)

type color =
  | Cyan
  | Magenta
  | Yellow
  | WIP

let colors: color list = [ Cyan; Magenta; Yellow; ]

let colors_of_chars (s: char list): color list =
  let f = function
    | 'C' -> Cyan
    | 'M' -> Magenta
    | 'Y' -> Yellow
    | '?' -> WIP
    | _ -> raise Not_found
  in
  List.map f s

let rec try_find (prev: color) (l: color list): int =
  match l with
  | [] -> 1
  | x :: xs when x = WIP ->
    let rec f (ret: int) (ll: color list): int =
      if ret >= 2
      then ret
      else match ll with
        | [] -> ret
        | c :: cs when c != prev -> f (ret + try_find c xs) cs
        | c :: cs -> f ret cs
    in
    f 0 colors
  | x :: xs when x = prev -> 0
  | x :: xs -> try_find x xs

let rec pre_scan (prev: color) (l: color list): bool =
  match l with
  | [] -> true
  | x :: xs when x != WIP && prev = x -> false
  | x :: xs -> pre_scan x xs

let () =
  let n = scanf " %d" (fun a -> a) in
  let s = scanf " %s" (fun a -> a) in
  let l = list_of_string s in
  let ll = colors_of_chars l in
  let ret = pre_scan WIP ll && (try_find WIP ll >= 2) in
  print_endline (if ret then "Yes" else "No")


open List;;

let a n =

  let rec create x =

    if x = 0 then [] else

    if (x mod 2 = 0) then 0::(create (x/2)) else

    1::(create (x/2)) in

  let solution lis = fst (fold_left (fun (l, a) x -> ((a*x)::l), a+1) ([], 1) lis ) in

  filter (fun x -> x<>0) (solution (create n) );;

map (Printf.printf "%d ") (Scanf.bscanf Scanf.Scanning.stdin "%d" 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,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
  if n=2L then printf "2" else printf "1"


let s=read_line() and t=read_line();;
let v=ref 0;;
for i=0 to String.length(s)/2-1 do
   if (s.[2*i]='8')&&(t.[2*i]='[') then v:= !v+1
   else if (s.[2*i]='[')&&(t.[2*i]='(') then v:= !v+1
   else if (s.[2*i]='(')&&(t.[2*i]='8') then v:= !v+1
   else if (t.[2*i]='8')&&(s.[2*i]='[') then v:= !v-1
   else if (t.[2*i]='[')&&(s.[2*i]='(') then v:= !v-1
   else if (t.[2*i]='(')&&(s.[2*i]='8') then v:= !v-1
done;;
if !v>0 then print_string "TEAM 1 WINS"
else if !v<0 then print_string "TEAM 2 WINS"
else print_string "TIE";;


open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
	let (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64
let (%$) = Pervasives.(mod)
let n,m = get_2_i64 0
let a : [`done_ | `empty | `filled ] array array = Array.make_matrix (i32 n) (i32 m) `empty
let at i j = try a.(i).(j) = `filled || a.(i).(j) = `done_ with Invalid_argument _ -> false
let solve_ij i j w =
	let f = ref true in
	let u,v = w %$ 2, w /$ 2 in
	let u,v = let g v = if v = 0 then -1 else v in g u,g v in
	for p=0 to 2 do
		for q=0 to 2 do
			if not (p=1&&q=1) then f := !f && at (i+$p*$u) (j+$q*$v)
		done
	done;
	if !f then (
		for p=0 to 2 do
			for q=0 to 2 do
				if not (p=1&&q=1) then a.(i+$p*$u).(j+$q*$v) <- `done_
			done
		done;
	)
let solve _ =
	for i=0 to (i32 n) do
		for j=0 to (i32 m) do
			solve_ij i j 0;
			solve_ij i j 1;
			solve_ij i j 2;
			solve_ij i j 3;
		done
	done;
	let f = ref true in
	for i=0 to (i32 n -$ 1) do
		for j=0 to (i32 m -$ 1) do
			f := !f && a.(i).(j) <> `filled
		done
	done; !f

let () =
	repi 0 (i32 n -$ 1) (fun i ->
		let s = scanf " %s" (fun v -> v) in
		String.iteri (fun j c ->
			a.(i).(j) <- if c = '#' then `filled else `empty
		) s;
		`Ok
	);
	let r = solve 0 in
	(* repi 0 (i32 n -$ 1) (fun i ->
		repi 0 (i32 m -$ 1) (fun j ->
			printf "%c" (match a.(i).(j) with `filled -> '#' | `empty -> '.' | `done_ -> ',');
			`Ok
		);
		print_endline "";
		`Ok
	); *)
	printf "%s\n" (if r then "YES" else "NO");


(* must read 64-bit integer %Ld because OCaml int is 31-bit! *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %Ld" (fun x -> x)
let l = read_int ()
let r = read_int ()

(* repeatedly multiply a 2-3 integer by 3 and count how many are in [l, r] *)
let rec times_three num acc =
    if num > r then
        acc
    else if num < l then
        times_three (Int64.mul num 3L) acc
	else
        times_three (Int64.mul num 3L) (acc + 1)

(* repeatedly multiply a 2-3 integer by 2, then repeatedly multiply it by 3 *)
let rec times_two num acc =
    if num > r then
        acc
    else
        times_two (Int64.mul num 2L) (times_three num acc)

(* must use 64-bit integer 1L because OCaml int is 31-bit! *)
let () =
    print_int (times_two 1L 0);
    print_newline ()


(* Il y a 9*(10^(n-1)) nombres à n chiffres *)
open Big_int

let rec dixPuiss = function
	| 0	-> Big_int.big_int_of_int 1
	| n	-> let demi = dixPuiss (n/2) in
			 Big_int.mult_big_int (Big_int.mult_big_int (Big_int.big_int_of_int (1 + (n mod 2)*9)) demi) demi

let numb = function
	| 1	-> Big_int.big_int_of_int 9
	| n	-> Big_int.mult_big_int (Big_int.big_int_of_int 9)  (dixPuiss (n-1))

let f n =
let a = String.length (string_of_int n) and res = ref (Big_int.big_int_of_int 0) in
for i=1 to a-1 do
res := Big_int.add_big_int !res (Big_int.mult_big_int (Big_int.big_int_of_int i) (numb i));
done;
Big_int.add_big_int !res (Big_int.mult_big_int (Big_int.big_int_of_int a) (Big_int.sub_big_int (Big_int.big_int_of_int (n + 1)) (dixPuiss (a-1))));;

let () =
	Scanf.scanf "%d" (fun i -> Printf.printf "%s" (Big_int.string_of_big_int (f i)))


let solve =
  let rec loop n lst=
    if n = 0 then lst
    else
      let horseshoes = Scanf.scanf " %d" (fun x -> x) in
      if List.mem horseshoes lst then loop (n-1) lst
      else loop (n-1) (horseshoes :: lst)
  in
  4 - (List.length (loop 4 []))

let _ =
  Printf.printf "%d\n" solve


let () =
  let goodcount = ref 0 in

  let rec isgood s i = if i=7 then true else
    s.[i] <> s.[i+1] && (isgood s (i+1))
  in

    for i=0 to 7 do
      let r = read_line() in
	goodcount := !goodcount + (if isgood r 0 then 1 else 0)
    done;

      let ans = if !goodcount = 8 then "YES" else "NO" in
	Printf.printf "%s\n" ans


let _ =
 Scanf.scanf "%d" ( fun x -> Printf.printf "%d" ( (x+4) / 5 ) )


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

open Printf
open Scanf
open Array

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

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

let next_permutation arr =
  let len = Array.length arr in
  (* find largest index i that arr.(i) < arr.(i+1) *)
  let rec find_pivot i =
    if i = 0 then -1 else
    if arr.(i-1) > arr.(i) then find_pivot (i-1) else
    i
  in
  (* find index that is larger than n and minimum in [a,len) *)
  let find_swap n a =
    for_ a len a (fun i c -> if arr.(i) > n && arr.(c) > arr.(i) then i else c)
  in
  let rec reverse a b =
    if a < b then begin
      swap arr a b;
      reverse (a+1) (b-1)
    end
  in
  let p = find_pivot (len-1) in
  if p = -1 then begin
    reverse 0 (len-1);
    false
  end else begin
    swap arr (p-1) (find_swap arr.(p-1) p);
    reverse p (len-1);
    true
  end

let _ =
  let mat = init 5 (fun i -> init 5 (fun j -> read_int())) in
  let arr = init 5 (fun i -> i) in

  let check () =
    mat.(arr.(0)).(arr.(1)) + mat.(arr.(1)).(arr.(0)) +
    mat.(arr.(1)).(arr.(2)) + mat.(arr.(2)).(arr.(1)) +
    2*mat.(arr.(2)).(arr.(3)) + 2*mat.(arr.(3)).(arr.(2)) +
    2*mat.(arr.(3)).(arr.(4)) + 2*mat.(arr.(4)).(arr.(3))
  in

  let m = ref (check()) in
  while (next_permutation arr) do assign_max m (check()) done;
  printf "%d\n" !m


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

open Int64

let solve k2 k3 k5 k6 =
  let k256 = min k2 (min k5 k6) in
  let k32 = min k3 (k2 - k256) in
  256L * k256 + 32L * k32

let () =
  Scanf.scanf "%Ld %Ld %Ld %Ld " @@ fun k2 k3 k5 k6 ->
  solve k2 k3 k5 k6 |> Printf.printf "%Ld\n"


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

let ( / ) = Int64.div
let ( * ) = Int64.mul
let ( + ) = Int64.add
let ( - ) = Int64.sub
let ( mod ) = Int64.rem
let two = Int64.of_int 2

let division_rounding_up = (fun x y ->
    x / y + (match x mod y with
        | 0L -> 0L
        | _ -> 1L))

let solve (n, m) =
    let middle = division_rounding_up n two in
    if m > middle
    then
        (m - middle) * two
    else
        m * two - Int64.one

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

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


open Scanf
open Printf

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

let a = Array.make 27 0

let add_count c =
  let i = (Char.code c) - (Char.code 'a')
  in a.(i) <- a.(i) + 1

let () =
  String.iter add_count name

let flag = ref true

let flip c =
  if (c>0) then flag := (not (!flag))

let () =
  Array.iter flip a

let () =
  if (!flag) then print_endline "CHAT WITH HER!"
  else
    print_endline "IGNORE HIM!"


let cost_per_litre city = city

let rec cost_to_city accumulated current_city city max_fuel fuel =
  let fuel_needed_to_reach_city = city - current_city in
  if fuel >= fuel_needed_to_reach_city then accumulated
  else
    let litres_to_top_up = min (max_fuel - fuel) fuel_needed_to_reach_city in
    let cost_to_top_up = litres_to_top_up * cost_per_litre current_city in
    cost_to_city
      (accumulated + cost_to_top_up)
      (current_city + 1) city max_fuel (max_fuel - 1)
;;

let () =
  Scanf.scanf "%d %d" (fun n v ->
      print_string (string_of_int (cost_to_city 0 1 n v 0)) )
;;


let n = read_int()
let c = Array.make 101 0
let count c =
  let s = Str.split (Str.regexp " ") (read_line()) in
  let l = List.map int_of_string (s)
  and inc_arr i = c.(i) <- c.(i) + 1 in
  List.iter inc_arr l;;

let find_max c m =
  let f x =
    m := max !m x in
  Array.iter f c;;

count c;;
let m = ref 0;;
find_max c m;;
Printf.printf "%d" !m;;


let flip  f a b = f b a in
let n = read_line () |> Str.split (Str.regexp " +") |> (flip List.nth) 0 |> int_of_string in
try begin
   for i = 1 to n do
     let c = read_line () in
     if String.contains c 'C' || String.contains c 'M' || String.contains c 'Y' then failwith "Color" else ()
   done;
   print_string "#Black&White"
end
with e ->  print_string "#Color"


let bs = Scanf.Scanning.stdin
let xint() = Scanf.bscanf bs " %d" (fun x -> x)
let xint32() = Scanf.bscanf bs " %ld" (fun x -> x)
let xint64() = Scanf.bscanf bs " %Ld" (fun x -> x)
let xstr() = Scanf.bscanf bs " %s" (fun x -> x)
let xreal() = Scanf.bscanf bs " %f" (fun x -> x)
let printf = Printf.printf

let () =
  let n = xint() in
  let a = Array.make n 0 in
  for i = 0 to n - 1 do
    a.(i) <- xint();
  done;
  let ret = ref (Big_int.big_int_of_int 1) in
  let p = ref ~-1 in
  for i = 0 to n - 1 do
    if a.(i) = 1 then (
      let x = i - !p in
      if !p != ~-1 then
        ret := Big_int.mult_int_big_int x !ret;
      p := i;
    )
  done;
  if !p = ~-1 then printf "0\n"
  else print_endline (Big_int.string_of_big_int !ret);


let _ =
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in
    let main () =
        let rec game turn a b n =
            let k = gcd n (if turn = 0 then a else b) in
            if n >= k then game (1 - turn) a b (n - k) else Printf.printf "%d\n" (1 - turn)
        in
        Scanf.scanf " %d %d %d" (game 0)
    in
    main ()


Scanf.(Array.(
  let s = scanf " %s" @@ fun v -> v in
  init 5 (fun _ ->
    let t = scanf " %s" @@ fun v -> v in
    if s.[0]=t.[0] || s.[1]=t.[1] then
      (print_endline "YES"; exit 0)
  ); print_endline "NO"))


let rec is_lucky a =
  match a with
  | 0 -> false
  | 4 | 7 -> true
  | _
    -> match a mod 10 with
    | 4 | 7
      -> is_lucky (a / 10)
    | _
      -> false
in

let is_almost_lucky n =
  let rec helper n testing =
    if testing > n then false
    else
      if ((n mod testing == 0) && (is_lucky testing)) then true
      else helper n (testing + 1)
  in helper n 1
in

let n = read_int() in

if is_almost_lucky n then
  Printf.printf "YES\n"
else
  Printf.printf "NO\n"


open Printf
open Scanf

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

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

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

  let an = (n/5)*5 in
  let am = (m/5)*5 in

  let rem = sum (an+1) (an+(n mod 5)) (fun i ->
    sum (am+1) (am+(m mod 5)) (fun j ->
      if (i+j) mod 5 = 0 then 1 else 0))
  in

  let rem_n = sum (an+1) (an+(n mod 5)) (fun i -> am/5) in
  let rem_m = sum (am+1) (am+(m mod 5)) (fun i -> an/5) in

  printf "%Ld\n" (((long (an/5)) ** (long am)) ++ (long rem) ++ (long rem_n) ++ (long rem_m))


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

let rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)

let two_pile_game a b =
  let dp = Array.make_matrix (a+1) (b+1) (-1) in  (* 1 if first player win, 0 2nd player win *)

  let rec eval i j =
    let (i,j) = (min i j, max i j) in
    if dp.(i).(j) >= 0 then dp.(i).(j) = 1 else
      let myval =
	if i=0 then j<>0 else
	  (exists 1 i (fun k -> not (eval (i-k) j)))
	  || (exists 1 j (fun k -> not (eval i (j-k))))
	  || (exists 1 i (fun k -> not (eval (i-k) (j-k))))
      in
	dp.(i).(j) <- if myval then 1 else 0;
	myval
  in
    eval a b

let three_pile_game a b c =
  a lxor b lxor c <> 0

let () =
  let n = read_int() in
  let a = Array.init n (fun _ -> read_int()) in
  let () = Array.sort compare a in
  let answer =
    if n=1 then a.(0) > 0
    else if n=2 then two_pile_game a.(0) a.(1)
    else if n=3 then three_pile_game a.(0) a.(1) a.(2)
    else failwith "n>3"
  in
    print_string(if answer then "BitLGM\n" else "BitAryo\n")


let rec get x =	if x = 0 then 0
	else if x mod 2 != 0 then (get (x / 2)) + 1
	else get (x / 2);;
print_int (get (read_int ()));;


let _ =
    let main () =
        let rec f a b c =
            if c = 0 then Printf.printf "%d\n" a else f b (a + b) (c - 1)
        in
        Scanf.sscanf (read_line ()) "%d %d %d" f
    in
    main ()


(* O(n^3) solution, which is fine because n=100 -- could probably be done with
 * DP for larger n, but why bother! *)

let aux i j (sum, pos) el =
    if i <= pos && pos <= j then
        (sum + 1 - el, succ pos)
    else
        (sum + el, succ pos) ;;

let r = Str.regexp " " in
let n = read_int () in
let xs = Array.of_list (List.map int_of_string (Str.split r (read_line ()))) in
let m = ref 0 in
for i = 0 to n - 1 do
    for j = i to n - 1 do
        let (s, _) = Array.fold_left (aux i j) (0, 0) xs in
        m := max !m s
    done
done ;
Printf.printf "%d\n" !m ;;


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

let rotate (count, prev) goal =
    let p = Pervasives.int_of_char prev in
    let g = Pervasives.int_of_char goal in
    let min = Pervasives.min p g in
    let max = Pervasives.max p g in
    let rotate_right = max - min in
    let rotate_left = min + 26 - max in
    let r = Pervasives.min rotate_left rotate_right in
    (count + r, goal)

let solve str =
    let l = String.length str in
    let rec loop i (count, prev) =
        if i < l
        then
            let (count, prev) = rotate (count, prev) str.[i] in
            loop (i + 1) (count, prev)
        else
            count
    in loop 0 (0, 'a')

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


let solve n m =
  let dynarray = Array.make (max (m*2+1) (n+1)) false in
  let queue = Queue.create () in
  Queue.push (0,n) queue;
  let rec dfs () =
    let (i,v) = Queue.pop queue in
    if v = m then i
    else if dynarray.(v) then dfs ()
    else if v > m then begin
      Queue.push (i+1,v-1) queue;
      dynarray.(v) <- true;
      dfs ()
    end else begin
      Queue.push (i+1,v*2) queue;
      if v > 0 then
        Queue.push (i+1,v-1) queue;
      dynarray.(v) <- true;
      dfs ()
    end
  in dfs ()

let () =
  let s = read_line () in
  let v = Scanf.sscanf s "%i %i" solve in
  print_int v


open Printf
open Scanf

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

  let rec turn_count d n count = if n<0 then count else turn_count (d+2) (n-d) (count+1) in

  let vl_count = turn_count 1 vl 0 in
  let va_count = turn_count 2 va 0 in

  if vl_count <= va_count then printf "Vladik\n" else printf "Valera\n"


let ad, b = Scanf.scanf "%[0-9].%[0-9]e%d" (fun a d b -> ((if d = "0" then a else a^d), b)) in
let nd = String.length ad in
print_string (
    if b + 1 >= nd
        then ad ^ String.make (b + 1 - nd) '0'
        else String.sub ad 0 (b+1) ^ "." ^ String.sub ad (b+1) (nd-b-1)
)


open String

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

let is_sorted n arr =
  let res = ref true in
  if n = 1 then true else
    begin
      for i = 0 to (n-2)
      do
        if abs(arr.(i) - arr.(i+1)) > 1 then
          res := false
      done;
      !res
    end

let _ =
  let n = read_int () in
  let arr = Array.make n 0 in
  let line = read_line () in
  let list = split_on_char ' ' line in
  List.iteri (fun i x -> arr.(i) <- int_of_string x) list;
  if is_sorted n arr then
    Format.printf "YES@."
  else
    Format.printf "NO@."


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

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

let () =
    let first = read () in
    let second = read () in
    if first > second
    then
        print "First"
    else
        print "Second"


open Printf

exception Found

let r = ref 0

let c = ref 0

let () =
  try
    for i = 1 to 5 do
      for j = 1 to 5 do
        let n =  Scanf.scanf "%d " ( fun x -> x) in
        if(n==1) then begin r:=i; c:=j; raise Found end
      done
    done
  with Found -> ();;

let () = printf "%d \n" ( abs(!r-3) + abs(!c-3) )


let (n, k) = Scanf.scanf "%f %f" (fun x y -> (x, y));;
let num_put = (n +. k) *. 2. +. 2.25 |> sqrt |> (fun x -> x -. 1.5) |> ceil |> int_of_float;;
Printf.printf "%d\n" ((int_of_float n) - num_put);;


let _ =
    let sieve m =
        let lookup =
            let tab = [ 29, 128; 23, 64; 19, 32; 17, 16; 13, 8; 11, 4; 7, 2; 1, 1 ] in
            let arr = Array.init 30 (fun k -> try List.assoc k tab with _ -> 0) in
            fun k -> arr.(k mod 30) in
        let head k = k land 7 in
        let tail k = (k lsr 3) lor (head k) lsl 21 in

        let rec loop_k len arr i b k =
            if k >= len then arr else
                (arr.(k) <- arr.(k) land b; loop_k len arr i b (k+i)) in

        let rec loop_j len arr i j n del =
            if n = 0 then arr else
                let hd = head del and tl = tail del in
                loop_j len (loop_k len arr i (lnot (lookup j)) (j/30)) i (j + i * hd) (n-1) tl in

        let rec loop_i m len arr i del =
            if i * i >= m then arr else
                let hd = head del and tl = tail del in
                loop_i m len (loop_j len arr i (i * i) 8 del) (i+hd) tl in

        let len = (m + 29) / 30 in
        let arr = loop_i m len (Array.make len 255) 7 13321492 in
        fun k ->
            let t = 1 lsl (k mod 30) in
            (k < 7 && 44 land t <> 0) || (k >= 7 && (545925250 land t <> 0) && (arr.(k/30) land lookup k) <> 0)
    in
    let rev k =
        let rec loop i acc =
            if i = 0 then acc else loop (i / 10) (acc * 10 + (i mod 10))
        in
        loop k 0
    in
    let main () =
        let isprime = sieve 1000000 in
        let arr = Array.create 11185 0 in
        let rec loop c acc =
            if acc > 11184 then arr else
            if isprime c &&
                let k = rev c in
                k <> c && isprime k then (arr.(acc) <- c; loop (c + 1) (acc + 1))
                                    else loop (c + 1) acc
        in
        let a = read_int () in
        let _ = loop 2 1 in
        Printf.printf "%d\n" (arr.(a))
    in
    main ()


let solve n m k =
  let mod_const = 1000000007 in
  let safe_add a b = Int64.(to_int (rem (add (of_int a) (of_int b)) (of_int mod_const))) in
  let safe_mul a b = Int64.(to_int (rem (mul (of_int a) (of_int b)) (of_int mod_const))) in
  let scale = 10 + max n m in
  let c = Array.init scale (fun _ -> Array.make scale 1) in
  let () = for i = 2 to (scale-1) do
      for j = 1 to (i-1) do
        c.(i).(j) <- (safe_add c.(i-1).(j) c.(i-1).(j-1))
      done
    done
  in
  let k' = 2*k in
  if k' >= n || k' >= m then 0
  else safe_mul c.(n-1).(k') c.(m-1).(k')

let () =
  let n, m, k = Scanf.(scanf " %d %d %d " (fun a b c -> (a,b,c))) in
  Printf.printf "%d\n" (solve n m k)


let count = int_of_string(input_line stdin);;
let s = input_line stdin;;

let rec eights s i b =
    if i == -1 then b
    else if s.[i] == '8' then eights s (i - 1) (b + 1)
    else eights s (i - 1) b;;

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

let x = eights s (String.length(s) - 1) 0;;
Printf.printf "%d\n" (min x (count / 11))


let () =
  Scanf.scanf "%d %d " (fun n m ->
    let m = min n m in
    if m mod 2 = 0 then print_endline "Malvika"
    else print_endline "Akshat")
;;


let read_nums () =
    let s = read_line () in
    let nums = List.map int_of_string (Str.split (Str.regexp " ") s) in
    nums

;;

let is_possible (t, s, x) =
    let r = (x - t) mod s in
    (x = t) || ( x >= (t + s) && (r = 0 || r = 1))

;;

let main () =
    let l = read_nums () in
    match l with
    | [t; s; x] ->  if is_possible (t, s, x) then
                        print_string "YES\n"
                    else
                        print_string "NO\n"
    | _ -> ()
;;

main ()


open Big_int

let pgcd = Big_int.gcd_big_int
let (/) = Big_int.div_big_int
let (+) = Big_int.add_big_int
let ( * ) = Big_int.mult_big_int
let ( - ) = Big_int.sub_big_int
let min = Big_int.min_big_int
let un = Big_int.big_int_of_int 1

let min_sol x y =
	(x / (pgcd x y)) * y

let count_sol x y t =
	let m = min_sol x y and equalpas = min x y in
	let a = t/m in
		a*equalpas + min equalpas (t - a*m + un);;

let final x y t =
	let num = (count_sol x y t) - un in
		Printf.printf "%s/%s" (Big_int.string_of_big_int (num / pgcd num t)) (Big_int.string_of_big_int (t / pgcd num t));;

let main () =
	Scanf.scanf "%s %s %s" (fun i j k -> let [i';j';k'] = List.map Big_int.big_int_of_string [i;j;k] in final j' k' i');;

main ();;


let cao n m = if m > n then -1. else ceil(n /. 2.0 /. m) *. m;;
Printf.printf "%.0f\n" (Scanf.sscanf (read_line()) "%f %f" cao)


let list_init n =
    let rec loop i list =
        if i < n
        then
            let element = Scanf.scanf "%c" (fun c -> c) in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = Scanf.scanf "%d " (fun n -> n) in
    let letters = List.append (list_init n) ['W'] in
    (n, letters)

let solve (n, letters) =
    let rec loop flag count rest list =
        match (rest, flag) with
        | ('W' :: tail), false -> loop flag count tail list
        | ('W' :: tail), true -> loop false 0 tail (count :: list)
        | ('B' :: tail), _ -> loop true (count + 1) tail list
        | [], _ -> (List.length list, List.rev list)
    in loop false 0 letters []

let print (n, list) =
    Printf.printf "%d\n" n;
    List.iter (Printf.printf "%d ") list;
    Printf.printf "\n"

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


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 read_int () = bscanf Scanning.stdib " %Ld " (fun x -> x)

let () =
  let n = read_int () in

  printf "%Ld\n" (n**n -- 4L**n ++ 4L)


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

let if_divisible k l m n = fun int ->
    if int mod k = 0 || int mod l = 0 || int mod m = 0 || int mod n = 0
    then
        true
    else
        false

let get_list d =
    let rec loop i list =
    if i <= d
    then
        loop (i + 1) (i :: list)
    else
        List.rev list
    in loop 1 []

let solve (k, l, m, n, d) = List.length(List.filter(if_divisible k l m n) (get_list d))

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

let () = print (solve (k, l, m, n, d))


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

let fill_lists l =
    let rec loop i a b =
        if i < l
        then
            loop (i + 1) (read () :: a) (read () :: b)
        else
            (l, a, b)
    in loop 0 [] []

let count_duplicates (l, a, b) =
    let rec loop i count =
        if i < l
        then
            let duplicates = List.filter (fun n -> n = (List.nth a i)) b in
            loop (i + 1) (count + List.length duplicates)
        else
            count
    in loop 0 0

let solve () =
    let l = read () in
    count_duplicates (fill_lists l)

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


open Printf;;
open Int64;;

let n = of_string (read_line()) in
let two = add one one in
let ans = if ((compare (rem n two) zero) == 0) then (div n two) else (neg (div (add n one) two)) in
printf "%s\n" (to_string ans);;


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 read_long () = bscanf Scanning.stdib " %Ld " (fun x -> x)

let () =
  let n = read_long() in
  let m = n // 2L in
  if n %% 2L <> 0L then printf "0\n"
  else printf "%Ld\n" ((m -- 1L) // 2L)


Scanf.scanf "%s %s %s %s" @@ fun nn mm aa bb ->
    let open Big_int in
    let ( * ) = mult_big_int in
    let ( - ) = sub_big_int in
    let [n; m; a; b] = List.map big_int_of_string [nn; mm; aa; bb] in
    let c = mod_big_int n m in
    let aa = (m - c) * a in
    let bb = c * b in
        min_big_int aa bb
        |> string_of_big_int
        |> print_endline


let a = Array.create_matrix 8 8 0;;
for i = 0 to 7 do
	let s = read_line () in
	for j = 0 to 7 do
		Array.set a.(i) j
		(match (String.get s j) with
			| 'W' -> 1
			| 'B' -> 2;
			| _ -> 0;
		)
	done;
done;;
let min1 = ref 99 and min2 = ref 99;;
let ff = Array.create 8 0;;
for i = 0 to 7 do
	for j = 0 to 7 do
	begin
		if (a.(i).(j) = 1) && (ff.(j) = 0) then
		begin
			min1 := min !min1 (i);
			Array.set ff j 1;
		end;
		if (a.(i).(j) = 2) then Array.set ff j 1
	end;
	done;
done;;
let ff = Array.create 8 0;;
for i = 7 downto 0 do
	for j = 0 to 7 do
	begin
		if (a.(i).(j) = 2) && (ff.(j) = 0) then
		begin
			min2 := min !min2 (7- i);
			Array.set ff j 1;
		end;
		if (a.(i).(j) = 1) then Array.set ff j 1
	end;
	done;
done;;
if min1 <= min2 then print_char 'A'
	else print_char 'B';;
	(*
print_int !min1;;
print_endline "";;
print_int !min2;;
*)


(* 6:49 start        *)
open Printf
open Scanf

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 read_long () = bscanf Scanning.stdib " %Ld " (fun x -> x)

let () =
  let a = read_long () in
  let b = read_long () in
  let s = read_long () in

  let shortest = (Int64.abs a) ++ (Int64.abs b) in

  if s >= shortest && (s -- shortest) %% 2L = 0L then printf "Yes\n" else printf "No\n"


let main () =
   let (r,c,n,k) = Scanf.scanf "%d %d %d %d" (fun r c n k -> r,c,n,k) in
   let mat = Array.make_matrix r c 0 in
   let compt = ref 0 in
      for i = 1 to n do
         Scanf.scanf " %d %d" (fun x y -> mat.(x-1).(y-1) <- 1);
      done;
      for i=0 to r-1 do
      for i'=i to r-1 do
      for j=0 to c-1 do
      for j'=j to c-1 do
         let nb = ref 0 in
            for i'' = i to i' do
            for j'' = j to j' do
               nb := !nb + mat.(i'').(j'');
            done;
            done;
            if !nb >= k
               then incr compt;
      done;
      done;
      done;
      done;
   print_int !compt;;

main ()


let input () = Scanf.scanf "%d %d" (fun x y -> (x, y))

let solve (cost, coin) =
    let rec loop i =
        if i <= 10
        then
            let total = i * cost in
            let change = total mod 10 in
            if change = 0 || change = coin
            then
                i
            else
                loop (i + 1)
        else
            failwith "Invalid input"
    in loop 1

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


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

let solve () =
    let total = read () in
    let travel_time = read () in
    let spare_time = 240 - travel_time in
    let rec loop i time_left =
        if i <= total
        then
            let solving_time = 5 * i in
            if solving_time < time_left
            then
                loop (i + 1) (time_left - solving_time)
            else
                if solving_time = time_left
                then
                    i
                else
                    i - 1
        else
            i - 1
    in loop 1 spare_time

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


let ( / ) = Int64.div
let ( * ) = Int64.mul
let ( + ) = Int64.add
let ( - ) = Int64.sub
let zero = Int64.zero
let one = Int64.one
let two = Int64.of_int 2

let factorial n =
    let rec loop i acc =
        if i >= one
        then
            loop (i - one) (acc * i)
        else
            acc
    in loop n one

let solve () =
    let n = Scanf.scanf "%Ld %Ld " (fun a b -> Pervasives.min a b) in
    factorial n

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


let _ =
  let n = Scanf.scanf " %d" (fun x -> x) in
  let m = Scanf.scanf " %d" (fun x -> x) in
  let ans = ref 0 in
  for i = 0 to 100 do
    for j = 0 to 100 do
      if i * i + j = n && i + j * j = m then ans := !ans + 1
    done
  done;
  print_int !ans


let _ =
  let mm = 1000000007L in
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let res =
    if n = k then (
      let res = ref 1L in
      let ml = Int64.of_int m in
	for i = 1 to (n + 1) / 2 do
	  res := Int64.rem (Int64.mul !res ml) mm
	done;
	!res
    ) else if k = 1 || n < k then (
      let res = ref 1L in
      let ml = Int64.of_int m in
	for i = 1 to n do
	  res := Int64.rem (Int64.mul !res ml) mm
	done;
	!res
    ) else if k mod 2 = 0
    then Int64.of_int m
    else Int64.of_int (m * m)
  in
    Printf.printf "%Ld\n" res


let () =
  Scanf.scanf "%d %d " @@ fun n l ->
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x)) in
  let b = Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x)) in
  let rec shift s =
    if s = n then
      print_endline "NO"
    else
      let rec check i =
        if i = n then
          print_endline "YES"
        else if (a.(i) - b.((i + s) mod n) - a.(0) + b.(s)) mod l = 0 then
          check (i + 1)
        else
          shift (s + 1) in
      check 1 in
  shift 0


let n = read_int();;
let a = Array.make n [|0; 0|];;
for i = 0 to n -1 do
	Array.set a i (Array.of_list (List.map (int_of_string) ((Str.split (Str.regexp " ") (read_line ())))));
done;;
let ans = ref (0);;
for i = 0 to n - 1 do for j = i + 1 to n - 1 do
	if (a.(i).(0) != a.(j).(0)) && (a.(i).(1) != a.(j).(1)) then ans := (a.(i).(0) - a.(j).(0)) * (a.(i).(1) - a.(j).(1));
done done;;
if ((!ans) < 0) then
	ans := -(!ans);;
if !ans = 0 then ans := -1;;
print_int !ans;;


open Printf
open Scanf

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)
let () =
  let dir = read_string () in
  let input = read_string () in

  let row = Array.make 3 "" in
  row.(0) <- "qwertyuiop";
  row.(1) <- "asdfghjkl;";
  row.(2) <- "zxcvbnm,./";

  let findletter l =
    let p0 = try String.index row.(0) l with Not_found -> -1 in
    let p1 = try String.index row.(1) l with Not_found -> -1 in
    let p2 = try String.index row.(2) l with Not_found -> -1 in
    if p0 >= 0 then (0,p0)
    else if p1 >= 0 then (1,p1)
    else if p2 >= 0 then (2,p2)
    else failwith "character not found"
  in

  let offset = if dir = "L" then 1 else -1 in

  for i=0 to (String.length input) -1 do
    let (r,p) = findletter input.[i] in
    printf "%c" row.(r).[p+offset];
  done;
  print_newline()


let ss = "CODEFORCES"

let () = Scanf.scanf "%s" (fun s ->
			   let rec m pos =
			     if pos >= String.length ss || pos >= String.length s || s.[pos] <> ss.[pos]
			     then pos
			     else m (pos + 1)
			   in
			   let l = m 0 in
			   print_endline (if String.length s >= String.length ss && Str.string_after ss l = Str.last_chars s ((String.length ss) - l)
					  then "YES" else "NO"))


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

let () =
    let n = read_int () and k = read_int () in
    let a = Array.init n read_int in
    let sum = Array.fold_left (+) 0 a
    and ans = ref 0 in
    for i = 0 to k - 1 do
        let j = ref i
        and res = ref sum in
        while !j < n do
            res := !res - a.(!j);
            j := !j + k
        done;
        ans := max !ans (abs !res)
    done;
    printf "%d\n" !ans