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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

let rec show_int_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_int x; print_string " "; show_int_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let calc x =
  let m = Int64.of_int m in
  let rec aux acc x =
	if x >= m then acc
	else aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in
  aux (Int64.zero) (Int64.of_int x)

let get_dvsr () =
  let up = iof (sqrt (foi d)) in
  let rec aux n acc =
	if n > up then acc
	else
	  if d mod n = 0 then
		if n * n <> d then aux (n + 1) (n :: (d/n) :: acc)
		else aux (n + 1) (n :: acc)
	  else
		aux (n + 1) acc
  in
  aux 1 []

let () =
  List.filter (fun x -> x mod 2 = 1) (get_dvsr () )
	|> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero
	|> Printf.printf "%Ld"

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

let rec show_int_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_int x; print_string " "; show_int_list xs

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

let rec gcd x y =
  if y = 0 then x else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let calc x =
  let m = Int64.of_int m in
  let rec aux acc x =
	if x >= m then acc
	else aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in
  aux (Int64.zero) (Int64.of_int x)

let get_dvsr () =
  let up = iof (sqrt (foi d)) in
  let rec aux n acc =
	if n > up then acc
	else
	  if d mod n = 0 then
		if n * n <> d then aux (n + 1) (n :: (d/n) :: acc)
		else aux (n + 1) (n :: acc)
	  else
		aux (n + 1) acc
  in
  aux 1 []

let () =
  List.filter (fun x -> x mod 2 = 1) (get_dvsr () )
	|> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero
	|> Printf.printf "%Ld"

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

let rec show_int_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_int x; print_string " "; show_int_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let m = Int64.of_int m in
  let rec aux acc x =
	if x >= m then acc
	else aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in
  aux (Int64.zero) (Int64.of_int x)

let get_dvsr () =
  let up = iof (sqrt (foi d)) in
  let rec aux n acc =
	if n > up then acc
	else
	  if d mod n = 0 then
		if n * n <> d then aux (n + 1) (n :: (d/n) :: acc)
		else aux (n + 1) (n :: acc)
	  else
		aux (n + 1) acc
  in
  aux 1 []

let () =
  Printf.printf "%Ld" (
	List.filter (fun x -> x mod 2 = 1) (get_dvsr () )
						  |> List.map calc
						  |> List.fold_left (fun x y -> Int64.add x y) Int64.zero)

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

let rec show_int_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_int x; print_string " "; show_int_list xs

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

let rec gcd x y =
  if y = 0 then x else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let calc x =
  let m = Int64.of_int m in
  let rec aux acc x =
	if x >= m then acc
	else aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in
  aux (Int64.zero) (Int64.of_int x)

let get_dvsr () =
  let up = iof (sqrt (foi d)) in
  let rec aux n acc =
	if n > up then acc
	else
	  if d mod n = 0 then
		if n * n <> d then aux (n + 1) (n :: (d/n) :: acc)
		else aux (n + 1) (n :: acc)
	  else
		aux (n + 1) acc
  in
  aux 1 []

let () =
  Printf.printf "%Ld" (
	List.filter (fun x -> x mod 2 = 1) (get_dvsr () )
						  |> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero)

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = Int64.of_int (min m 800000000) in
  let rec aux acc x =
	if x >= mm then acc
	else aux (Int64.add acc (Int64.sub mm x)) (Int64.add x x) in
  aux (Int64.zero) (Int64.of_int x)

let () =
  Printf.printf "%Ld" (List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (fun x y -> Int64.add x y) Int64.zero)

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 500000011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc +. foi (mm - x)) (2 * x) in
  aux 0. x

let () =
  Printf.printf "%.0f" (List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+.) 0.)

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 1000011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc + mm - x) (2 * x) in
  aux 0 x

let () =
  List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+) 0
	|> print_int

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 10011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc + mm - x) (2 * x) in
  aux 0 x

let () =
  List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+) 0
	|> print_int

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 100000011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc + mm - x) (2 * x) in
  aux 0 x

let () =
  List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+) 0
	|> print_int

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 500000011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc + mm - x) (2 * x) in
  aux 0 x

let () =
  List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+) 0
	|> print_int

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

let foi = float_of_int
let iof = int_of_float

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

let seq n =
  let rec aux n acc =
	if n = 0 then acc
	else aux (n-1) (n :: acc) in
  aux n []

let rec show_flt_list x =
  match x with
	  [] -> print_newline ()
	| x::xs -> print_float x; print_string " "; show_flt_list xs

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

let rec gcd x y =
  if x mod y = 0 then y else gcd y (x mod y)
;;

let n = next_int ()
let m = next_int ()

(* let () =
  print_newline(); print_int n; print_newline (); print_int m; print_newline()
*)

let a = loop n (fun _ -> (next_int()) - 1) []
let d = List.fold_left gcd (List.hd a) a

let chk y =
  let rec aux acc x =
	if x >= m then acc
	else aux (acc + m - x) (2 * x) in
  aux 0 y

let calc x =
  let mm = min m 100011 in
  let rec aux acc x =
	if x >= mm then acc
	else aux (acc + mm - x) (2 * x) in
  aux 0 x

let () =
  List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)
	|> List.map calc
	|> List.fold_left (+) 0
	|> print_int


open Printf
open Scanf

let () =
    let n =  read_int() in
    let arrv : bool array = Array.create n false in
    let arrh : bool array = Array.create n false in
    for i = 1 to n*n do
        let h, v = scanf "%d %d\n" (fun x y -> x, y) in
    if not (arrh.(h-1) || arrv.(v-1)) then begin
       arrh.(h-1) <- true;
       arrv.(v-1) <- true;
       printf "%d " i
    end;
    printf "\n%!"
done

let () = Scanf.scanf "%d\n" (fun n ->
    let h = Array.make n false
    and v = Array.make n false in
    for i = 1 to n*n do
        Scanf.scanf "%d %d\n" (fun x y ->
            if not (h.(x - 1) || v.(y - 1)) then begin
                h.(x - 1) <- true;
                v.(y - 1) <- true;
                Printf.printf "%d " i
            end)
    done)

open Printf
open Scanf

let () =
  let n = read_int () in
  let vert : bool array = Array.create n false in
  let horz : bool array = Array.create n false in
  for i = 1 to n * n do
    let h, v = scanf "%d %d\n" (fun x y -> x - 1, y - 1) in
    if not (horz.(h) || vert.(v)) then begin
      horz.(h) <- true;
      vert.(v) <- true;
      printf "%d " i
    end;
    printf "\n%!"
  done


let solve n ds =
  let beauty = List.fold_left ( + ) 0 ds in
  let rec loop best index i = function
    | [] -> index
    | d :: ds ->
      let b = abs (beauty - 2 * d) in
      if b > best then
        loop b i (i - 1) ds
      else
        loop best index (i - 1) ds
  in loop (abs beauty) 0 n ds

let () =
  Scanf.scanf "%d " @@ fun n ->
  let ds =
    let rec loop acc = function
      | 0 -> acc
      | n ->
        let d = Scanf.scanf "%d %d\n" @@ ( - ) in
        loop (d :: acc) (n - 1)
    in loop [] n in
  solve n ds |> string_of_int |> print_endline

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

let () =
  let n = read_int () in
  let rec loop
      neg_max neg_max_index neg_sum
      pos_max pos_max_index pos_sum i =
    if i > n then
      begin
        if (pos_max - neg_sum) > (pos_sum - neg_max) then pos_max_index
        else neg_max_index
      end
    else
      begin
        let l = read_int () and r = read_int () in
        let diff = l - r in
        if diff < 0 then
          begin
            if (diff < neg_max) then
              loop
                diff i (neg_sum + diff)
                pos_max pos_max_index pos_sum
                (i + 1)
            else
              loop
                neg_max neg_max_index (neg_sum + diff)
                pos_max pos_max_index pos_sum (i + 1)
          end
        else if diff > 0 then
          begin
            if (diff > pos_max) then
              loop
                neg_max neg_max_index neg_sum
                diff i (pos_sum + diff) (i + 1)
            else
              loop
                neg_max neg_max_index neg_sum
                pos_max pos_max_index (pos_sum + diff)
                (i + 1)
          end
        else
          loop
            neg_max neg_max_index neg_sum
            pos_max pos_max_index pos_sum (i + 1)
      end
  in
  loop 0 0 0 0 0 0 1 |> Printf.printf "%d"


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 read_pair () = let u = read_int () in (u, read_int ())

let () =
  let (n, m) = read_pair () in
  let board = Array.init n (fun _ -> read_string ()) in

  let count = ref 0 in

  let is_face l =
    let l = List.sort compare l in
    l = ['a'; 'c'; 'e'; 'f']
  in

  for i=0 to n-2 do
    for j = 0 to m-2 do
      if is_face [board.(i).[j]; board.(i+1).[j]; board.(i).[j+1]; board.(i+1).[j+1] ]
      then count := !count + 1
    done
  done;

  printf "%d\n" !count

(* iterate all 2x2 square *)
open Scanf
open Printf
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 m = read_int() in
  let img = Array.init n (fun _-> read_string()) in
  let ci c = int_of_char c in
  let face = 1 lsl (ci 'f') + 1 lsl (ci 'a') + 1 lsl (ci 'c') + 1 lsl (ci 'e') in
  let is_face a b c d = 1 lsl (ci a) + 1 lsl (ci b) + 1 lsl (ci c) + 1 lsl (ci d) == face in
  let count = ref 0 in
  for i=0 to n-2 do
	for j=0 to m-2 do
	  if is_face img.(i).[j] img.(i).[j+1] img.(i+1).[j] img.(i+1).[j+1] then
		count := !count + 1
	done
  done;
	printf "%d\n" !count

let ok mat =
	let compt = ref 0 in
	for i=0 to Array.length mat - 2 do
	for j=0 to String.length (mat.(0)) - 2 do
		if List.sort compare [(mat.(i)).[j];(mat.(i+1)).[j];(mat.(i)).[j+1];(mat.(i+1)).[j+1]] = ['a';'c';'e';'f']
			then incr compt;
	done;
	done;
	!compt

let () =
	let n = Scanf.scanf "%d %d " (fun i _ -> i) in
	let tab = Array.init n (fun i -> Scanf.scanf " %s" (fun j -> j)) in
		Printf.printf "%d" (ok tab)

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 read_pair () = let u = read_int() in (u,read_int())
let () =
  let (n,m) = read_pair () in
  let board = Array.init n (fun _ -> read_string()) in

  let count = ref 0 in

  let is_face l =
    let l = List.sort compare l in
    l = ['a';'c';'e';'f']
  in

  for i=0 to n-2 do
    for j=0 to m-2 do
      if is_face [board.(i).[j]; board.(i+1).[j]; board.(i).[j+1]; board.(i+1).[j+1] ]
      then count := !count + 1
    done
  done;

  printf "%d\n" !count


open Int64;;
open Array;;
let da x = ();;
let is_digit c =
  if (int_of_char c) >= (int_of_char '0')
  then if (int_of_char c) <= (int_of_char '9') then true
    else false
  else false;;
let digit c = (int_of_char c) - (int_of_char '0');;
let digitInt64 c = of_int(digit c);;
let readLine() = input_line stdin;;
let print_number x = print_string (to_string x ^ " ");;
let print_char c = print_string (Char.escaped c);;
let readChar() =
  let s = Bytes.create 1 in
  let () = da (input stdin s 0 1) in
  Bytes.get s 0;;
let readLong() =
  let number = ref 0L in
  let () =
    let quit_loop = ref false in
    while not !quit_loop do
      let c = readChar() in
      if is_digit c then
        number := add (mul !number 10L) (digitInt64 c)
      else
        quit_loop := true
    done in
  !number;;

let merge a b =
  let n = length a in
  let m = length b in
  let ret = make (n+m) 0L in
  let i = ref 0 in
  let j = ref 0 in
  let who = ref false in
  let ptr = ref 0 in
  while !ptr < (n+m) do
    let () =
      if !i < n then
        if !j < m then who := a.(!i) < b.(!j)
        else who := true
      else who := false in
    let () =
      if !who = true then ret.(!ptr) <- a.(!i)
      else ret.(!ptr) <- b.(!j) in
    let () =
      if !who = true then i := !i + 1
      else j := !j + 1 in
    ptr := !ptr + 1
  done;
  ret;;
let rec merge_sort a =
  if (length a) = 1 then a
  else
    let l = init ((length a + 1) / 2) (fun i -> a.(i)) in
    let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in
    merge (merge_sort l) (merge_sort r);;
let n = readLong() in
let k = ref (readLong()) in
let x = readLong() in
let a = Array.init (to_int n) (fun i -> readLong()) in
if n = 1L then print_number n
else
  let sorted = merge_sort a in
  let cost = make (to_int n-1) 0L in
  let () =
    for i = 1 to (length a - 1) do
      let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in
      if cost.(i-1) < 0L then cost.(i-1) <- 0L
    done in
  let sorted_cost = merge_sort cost in
  let answer = ref 1L in
  let () =
    for i = 0 to (length cost - 1) do
      if !k >= sorted_cost.(i) then
        k := Int64.sub !k sorted_cost.(i)
      else
        answer := Int64.add !answer 1L
    done in
  print_number !answer;;

let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_lint () = Scanf.scanf " %Ld" (fun x -> x)
let n = scan_int()
let k = ref (scan_lint())
let x = scan_lint()

let () =
  let a = Array.make n 0L in
  for i = 0 to n - 1 do
    a.(i) <- scan_lint()
  done;
  Array.sort compare a;
  let d = Array.make (n - 1) 0L in
  for i = 0 to n - 2 do
    d.(i) <- Int64.sub a.(i + 1) a.(i)
  done;
  Array.sort compare d;
  let ans = ref n in
  for i = 0 to Array.length d - 1 do
    if d.(i) <= x then
      ans := !ans - 1
    else if !k > 0L then
      let di = Int64.sub d.(i) 1L in
      let c = Int64.div di x in
      let ok = !k >= c in
        if ok then k := (Int64.sub !k c);
        if ok then ans := !ans - 1;
  done;
  Printf.printf "%d\n" !ans;;

open Int64;;
open Array;;
let merge a b =
  let n = length a in
  let m = length b in
  let ret = make (n+m) 0L in
  let i = ref 0 in
  let j = ref 0 in
  let who = ref false in
  let ptr = ref 0 in
  while !ptr < (n+m) do
    let () =
      if !i < n then
        if !j < m then who := a.(!i) < b.(!j)
        else who := true
      else who := false in
    let () =
      if !who = true then ret.(!ptr) <- a.(!i)
      else ret.(!ptr) <- b.(!j) in
    let () =
      if !who = true then i := !i + 1
      else j := !j + 1 in
    ptr := !ptr + 1
  done;
  ret;;
let rec merge_sort a =
  if (length a) = 1 then a
  else
    let l = init ((length a + 1) / 2) (fun i -> a.(i)) in
    let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in
    merge (merge_sort l) (merge_sort r);;
let readLong () = Scanf.scanf " %Ld" (fun i -> i);;
let print_number x = print_string (to_string x);;
let n = readLong() in
let k = ref (readLong()) in
let x = readLong() in
let a = Array.init (to_int n) (fun i -> readLong()) in
if n = 1L then print_number n
else
  let sorted = merge_sort a in
  let cost = make (to_int n-1) 0L in
  let () =
    for i = 1 to (length a - 1) do
      let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in
      if cost.(i-1) < 0L then cost.(i-1) <- 0L
    done in
  let sorted_cost = merge_sort cost in
  let answer = ref 1L in
  let () =
    for i = 0 to (length cost - 1) do
      if !k >= sorted_cost.(i) then
        k := Int64.sub !k sorted_cost.(i)
      else
        answer := Int64.add !answer 1L
    done in
  print_number !answer;;

let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_lint () = Scanf.scanf " %Ld" (fun x -> x)
let n = scan_int()
let k = ref (scan_lint())
let x = scan_lint()

let () =
  let a = Array.make n 0L in
  for i = 0 to n - 1 do
    a.(i) <- scan_lint()
  done;
  let b = List.sort compare (Array.to_list a) in
  let d = Array.make (n - 1) 0L in
  for i = 1 to n - 2 do
    d.(i) <- Int64.sub (List.nth b i) (List.nth b (i - 1))
  done;
  let d = List.sort compare (Array.to_list d) in
  let ans = ref n in
  for i = 0 to List.length d - 1 do
    if (List.nth d i) <= x then
      ans := !ans - 1
    else if !k > 0L then
      let di = Int64.sub (List.nth d i) 1L in
      let c = Int64.div di x in
      let ok = !k >= c in
        if ok then k := (Int64.sub !k c);
        if ok then ans := !ans - 1;
  done;
  Printf.printf "%d\n" !ans;;

let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_lint () = Scanf.scanf " %Ld" (fun x -> x)
let rec init n =
  if n = 0 then []
  else scan_lint() :: (init (n - 1))
let rec cal_diff l pos =
  if pos = List.length l then []
  else if pos = 0 then
    cal_diff l (pos + 1)
  else Int64.sub (List.nth l pos)  (List.nth l (pos - 1)) :: cal_diff l (pos + 1)
let get_diff l =  let sl = List.fast_sort compare l in List.sort compare (cal_diff sl 0)
let n = scan_int()
let k = ref (scan_lint())
let x = scan_lint()
let d = get_diff (init n)

let () =
  let ans = ref n in
  for i = 0 to List.length d - 1 do
    if (List.nth d i) <= x then
      ans := !ans - 1
    else
      let c = Int64.div (List.nth d i) x in
      let ok = !k >= c in
        if ok then k := (Int64.sub !k c);
        if ok then ans := !ans - 1;
  done;
  Printf.printf "%d\n" !ans;;

open Int64;;
open Array;;
let size = 1000;;
let s = Bytes.create size;;
let pos = ref 0;;
let ptr = ref 0;;
let read cnt =
  if !pos + cnt < size then
    let () = pos := !pos + (input stdin s !pos cnt) in
    true
  else
    false;;
let restart() =
  let () =
    for i = 1 to !pos - !ptr do
      Bytes.set s (i - 1) (Bytes.get s (i + !ptr))
    done in
  let () =
    pos := !pos - !ptr in
  ptr := 0;;
let da x = ();;
let is_digit c =
  if (int_of_char c) >= (int_of_char '0')
  then if (int_of_char c) <= (int_of_char '9') then true
    else false
  else false;;
let digit c = (int_of_char c) - (int_of_char '0');;
let digitInt64 c = of_int(digit c);;
let readLine() = input_line stdin;;
let print_number x = print_string (to_string x ^ " ");;
let print_char c = print_string (Char.escaped c);;
let check_reader() =
  let () =
    if !pos < size then da (read (size - !pos - 1)) in
  if !ptr >= 980 then restart();;
let skip() =
  let () = check_reader() in
  let quit_loop = ref false in
  while not !quit_loop do
    let c = Bytes.get s !ptr in
    let () =
      if is_digit c then quit_loop := true
      else ptr := !ptr + 1 in check_reader()
  done;;
let readLong() =
  let () = skip() in
  let quit_loop = ref false in
  let number = ref 0L in
  let () =
    while not !quit_loop do
      let c = Bytes.get s !ptr in
      if is_digit c then
        let () = number := add (mul !number  10L) (digitInt64 c) in
        ptr := !ptr + 1
      else
        quit_loop := true
    done in
  !number;;
let merge a b =
  let n = length a in
  let m = length b in
  let ret = make (n+m) 0L in
  let i = ref 0 in
  let j = ref 0 in
  let who = ref false in
  let ptr = ref 0 in
  while !ptr < (n+m) do
    let () =
      if !i < n then
        if !j < m then who := a.(!i) < b.(!j)
        else who := true
      else who := false in
    let () =
      if !who = true then ret.(!ptr) <- a.(!i)
      else ret.(!ptr) <- b.(!j) in
    let () =
      if !who = true then i := !i + 1
      else j := !j + 1 in
    ptr := !ptr + 1
  done;
  ret;;
let rec merge_sort a =
  if (length a) = 1 then a
  else
    let l = init ((length a + 1) / 2) (fun i -> a.(i)) in
    let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in
    merge (merge_sort l) (merge_sort r);;
let n = readLong() in
let k = ref (readLong()) in
let x = readLong() in
let a = Array.init (to_int n) (fun i -> readLong()) in
if n = 1L then print_number n
else
  let sorted = merge_sort a in
  let cost = make (to_int n-1) 0L in
  let () =
    for i = 1 to (length a - 1) do
      let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in
      if cost.(i-1) < 0L then cost.(i-1) <- 0L
    done in
  let sorted_cost = merge_sort cost in
  let answer = ref 1L in
  let () =
    for i = 0 to (length cost - 1) do
      if !k >= sorted_cost.(i) then
        k := Int64.sub !k sorted_cost.(i)
      else
        answer := Int64.add !answer 1L
    done in
  print_number !answer;;

open Int64;;
open Array;;
let size = 1000;;
let s = Bytes.create size;;
let pos = ref 0;;
let ptr = ref 0;;
let read cnt =
  if !pos + cnt < size then
    let nums = (input stdin s !pos cnt) in
    let () = pos := !pos + nums in
    true
  else
    false;;
let restart() =
  let () =
    for i = 1 to !pos - !ptr do
      Bytes.set s (i - 1) (Bytes.get s (i + !ptr))
    done in
  let () =
    pos := !pos - !ptr in
  ptr := 0;;
let da x = ();;
let is_digit c =
  if (int_of_char c) >= (int_of_char '0')
  then if (int_of_char c) <= (int_of_char '9') then true
    else false
  else false;;
let digit c = (int_of_char c) - (int_of_char '0');;
let digitInt64 c = of_int(digit c);;
let readLine() = input_line stdin;;
let print_number x = print_string (to_string x ^ " ");;
let print_char c = print_string (Char.escaped c);;
let check_reader() =
  let () =
    if !pos < size then da (read (size - !pos - 1)) in
  if !ptr >= 980 then restart();;
let skip() =
  let quit_loop = ref false in
  while not !quit_loop do
    let c = Bytes.get s !ptr in
    if is_digit c then quit_loop := true
    else ptr := !ptr + 1
  done;;
let readInt() =
  let () = check_reader() in
  let () = skip() in
  let quit_loop = ref false in
  let number = ref 0 in
  let () =
    while not !quit_loop do
      let c = Bytes.get s !ptr in
      if is_digit c then
        let () = number := !number * 10 + (digit c) in
        ptr := !ptr + 1
      else
        quit_loop := true
    done in
  !number;;
let readLong() =
  let () = check_reader() in
  let () = skip() in
  let quit_loop = ref false in
  let number = ref 0L in
  let () =
    while not !quit_loop do
      let c = Bytes.get s !ptr in
      if is_digit c then
        let () = number := add (mul !number  10L) (digitInt64 c) in
        ptr := !ptr + 1
      else
        quit_loop := true
    done in
  !number;;
let merge a b =
  let n = length a in
  let m = length b in
  let ret = make (n+m) 0L in
  let i = ref 0 in
  let j = ref 0 in
  let who = ref false in
  let ptr = ref 0 in
  while !ptr < (n+m) do
    let () =
      if !i < n then
        if !j < m then who := a.(!i) < b.(!j)
        else who := true
      else who := false in
    let () =
      if !who = true then ret.(!ptr) <- a.(!i)
      else ret.(!ptr) <- b.(!j) in
    let () =
      if !who = true then i := !i + 1
      else j := !j + 1 in
    ptr := !ptr + 1
  done;
  ret;;
let rec merge_sort a =
  if (length a) = 1 then a
  else
    let l = init ((length a + 1) / 2) (fun i -> a.(i)) in
    let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in
    merge (merge_sort l) (merge_sort r);;
let n = readLong() in
let k = ref (readLong()) in
let x = readLong() in
let a = Array.init (to_int n) (fun i -> readLong()) in
if n = 1L then print_number n
else
  let sorted = merge_sort a in
  let cost = make (to_int n-1) 0L in
  let () =
    for i = 1 to (length a - 1) do
      let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in
      if cost.(i-1) < 0L then cost.(i-1) <- 0L
    done in
  let sorted_cost = merge_sort cost in
  let answer = ref 1L in
  let () =
    for i = 0 to (length cost - 1) do
      if !k >= sorted_cost.(i) then
        k := Int64.sub !k sorted_cost.(i)
      else
        answer := Int64.add !answer 1L
    done in
  print_number !answer;;

open Int64;;
open Array;;
let merge a b =
  let n = length a in
  let m = length b in
  let ret = make (n+m) 0L in
  let i = ref 0 in
  let j = ref 0 in
  let who = ref false in
  let ptr = ref 0 in
  while !ptr < (n+m) do
    let () =
      if !i < n then
        if !j < m then who := a.(!i) < b.(!j)
        else who := true
      else who := false in
    let () =
      if !who = true then ret.(!ptr) <- a.(!i)
      else ret.(!ptr) <- b.(!j) in
    let () =
      if !who = true then i := !i + 1
      else j := !j + 1 in
    ptr := !ptr + 1
  done;
  ret;;
let rec merge_sort a =
  if (length a) = 1 then a
  else
    let l = init ((length a + 1) / 2) (fun i -> a.(i)) in
    let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in
    merge (merge_sort l) (merge_sort r);;
let readLong () = Scanf.scanf " %Ld" (fun i -> i);;
let print_number x = print_string (to_string x);;
let n = readLong();;
let k = ref (readLong());;
let x = readLong();;
let a = Array.init (to_int n) (fun i -> readLong())
let sorted = merge_sort a;;
let cost = make (to_int n-1) 0L;;
for i = 1 to (length a - 1) do
  cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x)
done;;
let sorted_cost = merge_sort cost;;
let answer = ref 1L;;
for i = 0 to (length cost - 1) do
  if !k >= sorted_cost.(i) then
    k := Int64.sub !k sorted_cost.(i)
  else
    answer := Int64.add !answer 1L
done;;
print_number !answer;;


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

let () =
  let (n,k) = read_pair() in
  let best = ref 0 in
    for i=0 to n-1 do
      let (f,t) = read_pair() in
      let score = if t > k then f - (t-k) else f in
	if score > !best || i=0 then best := score
    done;
    Printf.printf "%d\n" !best

open Filename;;

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

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

let n = gr();;
let k = gr();;
let optv = ref (- 1001000000);;

let main() =
	begin
		for i = 1 to n do
				let f = gr () in
				let t = gr () in
				let v = if t > k then f - (t-k) else f in
				if v > !optv then
					optv := v
		done;
		print_int !optv; print_newline ()
	end;;

main();;


let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib " %Ld" (fun x -> x)
let read_str _ = Scanf.bscanf Scanf.Scanning.stdib " %s" (fun x -> x)
let (|>) x f = f x
let flip f x y = f y x

open Int64

let ( ++ ) = add
let ( -- ) = sub
let ( ** ) = mul
let ( // ) = div
let ( %% ) = rem

let phi x =
  let rec go acc x i =
    if i**i > x then
      acc, x
    else if x%%i = 0L then
      let rec go2 x =
        if x%%i <> 0L then
          x
        else
          go2 (x//i)
      in
      go (acc--acc//i) (go2 x) (i++1L)
    else
      go acc x (i++1L)
  in
  let r,x = go x x 2L in
  if x > 1L then
    r--r//x
  else
    r

let f a p =
  let rec go acc i =
    if i >= String.length a then
      acc
    else
      let acc' = (acc**10L ++ (int_of_char a.[i] - 48 |> of_int)) %%p in
      go acc' (i+1)
  in
  go 0L 0

let powmod a n p =
  let rec go r a n =
    if n = 0L then
      r
    else if logand n 1L <> 0L then
      go (r**a%%p) (a**a%%p) (n//2L)
    else
      go r (a**a%%p) (n//2L)
  in
  go 1L a n

let () =
  let bb = read_str 0 in
  let nn = read_str 0 in
  let c = read_int64 0 in
  let phi_c = phi c in

  let b = f bb c in
  let n = if String.length nn >= 10 then
      f nn phi_c ++ phi_c
    else
      let n = of_string nn in
      if n--1L >= phi_c then
        n%%phi_c++phi_c
      else
        n
  in
  powmod b (n--1L) c ** (b++c--1L) %% c
  |> (fun x -> if x = 0L then c else x)
  |> Printf.printf "%Ld\n"

let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib " %Ld" (fun x -> x)
let read_str _ = Scanf.bscanf Scanf.Scanning.stdib " %s" (fun x -> x)
let (|>) x f = f x
let flip f x y = f y x

open Int64

let ( ++ ) = add
let ( -- ) = sub
let ( ** ) = mul
let ( // ) = div
let ( %% ) = rem

let phi x =
  let rec go acc x i =
    if i**i > x then
      acc, x
    else if x%%i = 0L then
      let rec go2 x =
        if x%%i <> 0L then
          x
        else
          go2 (x//i)
      in
      go (acc--acc//i) (go2 x) (i++1L)
    else
      go acc x (i++1L)
  in
  let r,x = go x x 2L in
  if x > 1L then
    r--r//x
  else
    r

let f a p =
  let rec go acc i =
    if i >= String.length a then
      acc
    else
      let acc' = (acc**10L ++ (int_of_char a.[i] - 48 |> of_int)) %%p in
      go acc' (i+1)
  in
  go 0L 0

let powmod a n p =
  let rec go r a n =
    if n = 0L then
      r
    else if logand n 1L <> 0L then
      go (r**a%%p) (a**a%%p) (n//2L)
    else
      go r (a**a%%p) (n//2L)
  in
  go 1L a n

let () =
  let bb = read_str 0 in
  let nn = read_str 0 in
  let c = read_int64 0 in
  let phi_c = phi c in

  let b = f bb c in
  let b1 = b++c--1L in
  let n = f nn phi_c in
  let n1 = n++phi_c--1L in
  powmod b n1 c ** b1 %% c
  |> (fun x -> if x = 0L then c else x)
  |> Printf.printf "%Ld\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.0

let comp x = 1.0 -. x

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

let () =
  let n = read_int () in
  let h = read_int () in
  let pl = read_float () in
  let x = Array.init n (fun _ -> read_int()) in
  Array.sort compare x;

  let pr = comp pl in

  let topple_left = Array.make n 0 in
  (* topple_left.(i) is the furthest one to the left that topples
     as a result of toppling i to the left *)
  let topple_right = Array.make n (n-1) in

  for i=1 to n-1 do
    topple_left.(i) <- if x.(i) - x.(i-1) < h then topple_left.(i-1) else i;
    let j = n-1-i in
    topple_right.(j) <- if x.(j+1) - x.(j) < h then topple_right.(j+1) else j;
  done;

  let p = Array.make_matrix n (4*n) 0.0 in
  (* p.(i).(j).(lfalldir).(rfalldir) is the probability of the situation
     where the upright trees are [i,j] and the one to the left of this
     fell in direction lfalldir (0=left, 1=right) and the one to the
     right fell in rfalldir. *)

  let int = Array.make ((n+1)*4) 0.0 in
  (* represents the interval (numbered starting from 0 on the left)
     Stores the probability for each of the four ways the interval
     can be resolved.  Actually, for short intervals only the
     resolution (0,1) i.e. (left, right) is used *)

  let inc i j ldir rdir x =
    if i <= j then
      let ind = 4*j + 2*ldir + rdir in
      p.(i).(ind) <- x +. p.(i).(ind)
  in

  let incx i ldir rdir x =
    let ind = 4*i + 2*ldir + rdir in
    int.(ind) <- x +. int.(ind)
  in

  let geti i ldir rdir = int.(4*i + 2*ldir + rdir) in
  let getp i j ldir rdir = p.(i).(4*j + 2*ldir + rdir) in

  inc 0 (n-1) 0 1 1.0;

  for d=n-1 downto 0 do
    for i=0 to n-1-d do
      let j = i+d in
      for ldir = 0 to 1 do
	for rdir = 0 to 1 do
	  let pstate = getp i j ldir rdir in
	  let xl = pstate *. 0.5 *. pl in
	  let xr = pstate *. 0.5 *. pr in
	  (* i falls to the left *)
	  inc (i+1) j 0 rdir xl;
	  incx i ldir 0 xl;
	  if i=j then incx (j+1) 0 rdir xl;
	  (* j falls to the right *)
	  inc i (j-1) ldir 1 xr;
	  incx (j+1) 1 rdir xr;
	  if i=j then incx i ldir 1 xr;
	  (* i falls to the right *)
	  inc (topple_right.(i)+1) j 1 rdir xr;
	  incx i ldir 1 xr;
	  if topple_right.(i) >= j then incx (j+1) 1 rdir xr;
	  (* j falls to the left *)
	  inc i (topple_left.(j)-1) ldir 0 xl;
	  incx (j+1) 0 rdir xl;
	  if topple_left.(j) <= i then incx i ldir 0 xl;
	done
      done
    done
  done;

  let evaluate_gap i =
    let d = if i=0 || i=n then h else x.(i) - x.(i-1) in
    if d < h then
      (comp (geti i 0 1)) *. (float d)
    else
      (geti i 1 0) *. (float (min d (2*h))) +. ((geti i 0 0) +. (geti i 1 1)) *. (float h)
  in

  printf "%1.9f\n" (sum 0 n evaluate_gap)

open Printf
open Scanf

let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac +. (f i))
let comp x = 1.0 -. x
let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_float () = bscanf Scanning.stdib " %f " (fun x -> x)

let () =
  let n = read_int () in
  let h = read_int () in
  let pl = read_float () in
  let x = Array.init n (fun _ -> read_int()) in
  Array.sort compare x;

  let pr = comp pl in

  let topple_left = Array.make n 0 in
  let topple_right = Array.make n (n-1) in

  for i=1 to n-1 do
    topple_left.(i) <- if x.(i) - x.(i-1) < h then topple_left.(i-1) else i;
    let j = n-1-i in
    topple_right.(j) <- if x.(j+1) - x.(j) < h then topple_right.(j+1) else j;
  done;

  let p = Array.make_matrix n (4*n) 0.0 in
  let int = Array.make ((n+1)*4) 0.0 in
  let inc i j ldir rdir x =
    if i <= j then
      let ind = 4*j + 2*ldir + rdir in
      p.(i).(ind) <- x +. p.(i).(ind)
  in

  let incx i ldir rdir x =
    let ind = 4*i + 2*ldir + rdir in
    int.(ind) <- x +. int.(ind)
  in

  let geti i ldir rdir = int.(4*i + 2*ldir + rdir) in
  let getp i j ldir rdir = p.(i).(4*j + 2*ldir + rdir) in

  inc 0 (n-1) 0 1 1.0;

  for i=0 to n-1 do
    for j=n-1 downto i do
      for ldir = 0 to 1 do
    for rdir = 0 to 1 do
      let pstate = getp i j ldir rdir in
      let xl = pstate *. 0.5 *. pl in
      let xr = pstate *. 0.5 *. pr in
      inc (i+1) j 0 rdir xl;
      incx i ldir 0 xl;
      if i=j then incx (j+1) 0 rdir xl;
      inc i (j-1) ldir 1 xr;
      incx (j+1) 1 rdir xr;
      if i=j then incx i ldir 1 xr;
      inc (topple_right.(i)+1) j 1 rdir xr;
      incx i ldir 1 xr;
      if topple_right.(i) >= j then incx (j+1) 1 rdir xr;
      inc i (topple_left.(j)-1) ldir 0 xl;
      incx (j+1) 0 rdir xl;
      if topple_left.(j) <= i then incx i ldir 0 xl;
    done
      done
    done
  done;

  let evaluate_gap i =
    let d = if i=0 || i=n then h else x.(i) - x.(i-1) in
    if d < h then
      (comp (geti i 0 1)) *. (float d)
    else
      (geti i 1 0) *. (float (min d (2*h))) +. ((geti i 0 0) +. (geti i 1 1)) *. (float h)
  in

  printf "%1.9f\n" (sum 0 n evaluate_gap 0.0)

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.0

let comp x = 1.0 -. x

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

let () =
  let n = read_int () in
  let h = read_int () in
  let pr = read_float () in
  let x = Array.init n (fun _ -> read_int()) in
  Array.sort compare x;

  let g = Array.make_matrix (n+1) (n+1) (-1.0) in
  (* g.(a).(b) is the probability that an interval with
     a trees on the left and b trees on the right survives. *)

  let pl = comp pr in

  g.(0).(1) <- pr;
  g.(1).(0) <- pl;
  g.(0).(0) <- 1.0;

  let rec compg a b =
    if g.(a).(b) >= 0.0 then g.(a).(b) else
      let answer = match (a,b) with
	| (0,_) -> 0.5 *. (pr *. (compg 0 (b-1)) +. pr)
	| (_,0) -> 0.5 *. (pl *. (compg (a-1) 0) +. pl)
	| (_,_) -> 0.5 *. (pl *. (compg (a-1) b) +. pr *. (compg a (b-1)))
      in
      g.(a).(b) <- answer;
      answer
  in

  let rec find_blocks i j ac = if j=n-1 then (i,j)::ac else
      (* i....j is an initial part of a block *)
      if x.(j+1) < h + x.(j)
      then find_blocks i (j+1) ac
      else find_blocks (j+1) (j+1) ((i,j)::ac)
  in

  let block = Array.of_list (List.rev (find_blocks 0 0 [])) in
  let nb = Array.length block in

  (*
  for i=0 to nb-1 do
    printf "block: (%d,%d) " (fst block.(i)) (snd block.(i))
  done;
  print_newline();

  for a=0 to n do
    for b=0 to n-a do
      printf "g.(%d).(%d) = %f\n" a b (compg a b)
    done
  done;
  *)
  let e_internal_coverage (i,j) =
    sum (i+1) j (fun k ->
      let len = float (x.(k) - x.(k-1)) in
      len *. (comp (compg (k-i) (j+1-k)))
    )
  in

  let e_total_coverage =
    sum 0 (nb-1) (fun k -> e_internal_coverage block.(k))
  in

  let e_boundary_coverage =
    sum 1 (nb-1) (fun k ->
      let (i,j) = block.(k) in
      let (i',j') = block.(k-1) in
      let lp = comp (compg 0 (j-i+1)) in
      let rp = comp (compg (j'-i'+1) 0) in
      lp *. rp *. (float (min (x.(i) - x.(j')) (2*h))) +.
	(comp lp) *. rp *. (float h) +.
	lp *. (comp rp) *. (float h)
    )
  in

  let e_ends =
    let (i,j) = block.(0) in
    let e_left_end = (comp (compg 0 (j-i+1))) *. (float h) in
    let (i,j) = block.(nb-1) in
    let e_right_end = (comp (compg (j-i+1) 0)) *. (float h) in
    e_left_end +. e_right_end
  in

  let answer = e_total_coverage +. e_boundary_coverage +. e_ends in

  printf "%1.9f\n" answer


open String
open Printf
open Scanf
let solve : (string -> int * int) = function
      | str when (not (contains str 'L')) -> (index str 'R' + 1, rindex str 'R' + 2)
      | str when (not (contains str 'R')) -> (rindex str 'L' + 1, index str 'L')
      | str -> (index str 'R' + 1, rindex str 'R' + 1);;
let (s,t) = scanf "%d %s" (fun _ -> solve);;
Printf.printf "%d %d\n" s t

open String
open Printf
open Scanf
let solve : (string -> int * int) = function
      | str when not (contains str 'L') -> index str 'R' + 1, rindex str 'R' + 2
      | str when not (contains str 'R') -> rindex str 'L' + 1, index str 'L'
      | str -> index str 'R' + 1, rindex str 'R' + 1;;
let s,t = scanf "%d %s" (fun _ -> solve);;
printf "%d %d\n" s t


let ( ++ ) = Int64.add
let ( %% ) = Int64.rem
let zero = Int64.zero
let two = Int64.of_int 2

let read () = Scanf.scanf "%d " (fun n -> n)
let read_l () = Scanf.scanf "%Ld " (fun n -> n)
let print int = Printf.printf "%Ld\n" int

let input () =
    let n = read () in
    let rec loop i even odd =
        if i < n
        then
            let int = read_l () in
            if int %% two = zero
            then
                loop (i + 1) (int :: even) odd
            else
                loop (i + 1) even (int :: odd)
        else
            (even, odd)
    in loop 0 [] []

let get_sum list =
    let l = List.length list in
    if l <= 1
    then
        zero
    else
        if l mod 2 = 0
        then
            List.fold_left (fun acc n -> acc ++ n) zero list
        else
            List.fold_left (fun acc n -> acc ++ n) zero (List.tl list)

let solve (even, odd)=
    let odd_sorted = List.sort (Pervasives.compare) odd in
    let sum_even = List.fold_left (fun acc n -> acc ++ n) zero even in
    let sum_odd = get_sum odd_sorted in
    sum_even ++ sum_odd

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 long x = Int64.of_int x

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

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

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

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

  let inf = Int64.max_int in

  let is_odd x = x%% 2L = 1L in

  let min_odd = minf 0 (n-1) (fun i -> if is_odd a.(i) then a.(i) else inf) in

  let answer = if not (is_odd total) then total else total -- min_odd in

  printf "%Ld\n" answer


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 pos = ref 0 in
  let push x =
    a.(!pos) <- x;
    incr pos
  in
  let res = ref 0 in
  let pop x =
    if !pos <= 0 then (
      Printf.printf "Impossible\n";
      exit 0;
    );
    if a.(!pos - 1) <> x
    then incr res;
    decr pos;
  in
    for i = 0 to n - 1 do
      let c = s.[i] in
	match c with
	  | '(' -> push 0
	  | '{' -> push 1
	  | '<' -> push 2
	  | '[' -> push 3
	  | ')' -> pop 0
	  | '}' -> pop 1
	  | '>' -> pop 2
	  | ']' -> pop 3
	  | _ -> assert false
    done;
    if !pos <> 0
    then Printf.printf "Impossible\n"
    else Printf.printf "%d\n" !res

open Printf

let rec over a b f k =
  if a >= b then k
  else over (a + 1) b f (f a k)

let group = function
  | '[' | ']' -> 0
  | '(' | ')' -> 1
  | '<' | '>' -> 2
  | '{' | '}' -> 3
  | _ -> assert false

let () =
  let s = input_line stdin in
  let x =
    over 0 (String.length s) (fun i x ->
        match s.[i], x with
        | _, None ->
          None
        | ('[' | '<' | '(' | '{'), Some (n, q) ->
          Some (n, group s.[i] :: q)
        | r, Some (n, []) ->
          None
        | r, Some (n, t :: ts) when group r = t ->
          Some (n, ts)
        | r, Some (n, t :: ts) when group r <> t ->
          Some ((n + 1), ts)
        | _ -> assert false
      ) (Some (0, []))
  in
  match x with
  | None -> printf "Impossible\n"
  | Some (_, _ :: _) -> printf "Impossible\n"
  | Some (n, []) -> printf "%d\n" n


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

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 () =
  let n = read_int() in
  let k = read_long() in
  let a = Array.init n (fun _ -> read_long()) in

  let () = Array.sort compare a in

  let h = Hashtbl.create 100 in

  let () =
    for i=0 to n-1 do
      Hashtbl.add h a.(i) false
    done in

  let rec mark_chain x i =
    if Hashtbl.mem h x then (
      if Hashtbl.find h x then 0 else (
	Hashtbl.replace h x true;
	mark_chain (x ** k) (i+1)
      )
    ) else i
  in

  let count = ref 0 in

    for i=0 to n-1 do
      let c = mark_chain a.(i) 0 in
	count := !count + ((c+1)/2)
    done;

    if k=1L then Printf.printf "%d\n" n
    else Printf.printf "%d\n" !count

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

let n = scan_int () and k = scan_int();;
let a = Array.make n 0;;

for i = 0 to n - 1 do a.(i) <- scan_int() done;
Array.sort compare a;

let cnt = ref 0 and q = Queue.create() in
for i = n - 1 downto 0 do
  while(not (Queue.is_empty q) && Queue.top q > a.(i)) do Queue.pop q; done;
  if(not (Queue.is_empty q) && Queue.top q = a.(i)) then incr cnt
  else if(a.(i) mod k = 0) then Queue.push (a.(i) / k) q;
done;

print_int(n - !cnt);

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

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 () =
  let n = read_int() in
  let k = read_long() in
  let a = Array.init n (fun _ -> read_long()) in

  let () = Array.sort compare a in

  let h = Hashtbl.create 100 in

  let () =
    for i=0 to n-1 do
      Hashtbl.add h a.(i) false
    done in

  let rec mark_chain x i =
    if Hashtbl.mem h x then (
      if Hashtbl.find h x then 0 else (
	Hashtbl.replace h x true;
	mark_chain (x ** k) (i+1)
      )
    ) else i
  in

  let count = ref 0 in

    for i=0 to n-1 do
      let c = mark_chain a.(i) 0 in
	count := !count + ((c+1)/2)
    done;

    Printf.printf "%d\n" !count

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

let n = scan_int () and k = scan_int();;
let a = Array.make n 0;;

for i = 0 to n - 1 do a.(i) <- scan_int() done;
Array.sort compare a;

let cnt = ref 0 and q = Queue.create() in
for i = n - 1 downto 0 do
  while(not (Queue.is_empty q) && Queue.top q > a.(i)) do Queue.pop q; done;
  if(not (Queue.is_empty q) && Queue.top q = a.(i)) then incr cnt;
  if(a.(i) mod k = 0) then Queue.push (a.(i) / k) q;
done;

print_int(n - !cnt);


(* module IntSet = Set.Make(
    struct
        let compare = Pervasives.compare
        type t = int
    end)  *)

module CharSet = Set.Make(Char)

let add s b =
    if String.length b == 0 then s
    else CharSet.add (String.get b 0) s

let x =
    let line = Str.split (Str.regexp "[{},] *") (read_line ()) in
    let s = List.fold_left add CharSet.empty line in
    print_int (CharSet.cardinal s);
    print_newline;

let get_list () =
    let letters = Pervasives.read_line () in
    let l = String.length letters in
    let rec loop i list =
        if i < 1
        then
            list
        else
            loop (i - 3) (letters.[i] :: list)
    in loop (l - 2) []

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

let solve () = List.length (get_uniques (List.sort (Pervasives.compare) (get_list ())))

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

let get_list () =
    let letters = Pervasives.read_line () in
    let l = String.length letters in
    let rec loop i list =
        if i < 1
        then
            list
        else
            loop (i - 3) (letters.[i] :: list)
    in loop (l - 2) []

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

let solve () = List.length (get_uniques (get_list ()))

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


let kikou tab =
   let red_even = ref 0
   and blu_even = ref 0
   and red_odd = ref 0
   and blu_odd = ref 0
   in
      for i = 0 to String.length tab - 1 do
         incr @@ match tab.[i] , i mod 2 with
            | 'b', 0 -> blu_even
            | 'b', 1 -> blu_odd
            | 'r', 0 -> red_even
            | 'r', 1 -> red_odd
      done;
      !red_even, !blu_even, !red_odd, !blu_odd

let solve tab =
   let n = String.length tab in
   let (re,be,ro,bo) = kikou tab in
   let a = min re bo in
   let (re',be',ro',bo') = (re-a,be+a,ro+a,bo-a) in
      a + (((n+1)/2) - be') + ((n/2) - ro')

let olol =
   String.map (fun x -> if x = 'b' then 'r' else 'b')

let _ =
   let w = Scanf.scanf "%d %s" (fun _ w -> w) in
      Printf.printf "%d" (min (solve w) (solve (olol w)))

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 comp c = match c with 'r' -> 'b' | 'b' -> 'r' | _ -> failwith "bad input" in

  let solve c =
  (* c is the goal color of position 0 *)
    let rec loop i c rtob btor =
      if i=n then (rtob, btor) else
	let rtob = rtob + (if s.[i] = 'r' && c = 'b' then 1 else 0) in
	let btor = btor + (if s.[i] = 'b' && c = 'r' then 1 else 0) in
	loop (i+1) (comp c) rtob btor
    in
    let (rtob, btor) = loop 0 c 0 0 in
    let swaps = min rtob btor in
    (rtob + btor) - swaps
  in

  let answer = min (solve 'r') (solve 'b') in

  printf "%d\n" answer

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 comp c = match c with 'r' -> 'b' | 'b' -> 'r' | _ -> failwith "bad input" in

  let rec color i c ac =
    (* position i is already correctly colored c *)
    (* continue coloring from i+1 to the end *)
    if i = n-1 then ac else (
      if s.[i+1] = comp c then color (i+1) (comp c) ac
      else if i+2 < n && s.[i+2] <> s.[i+1] then color (i+2) c (ac+1)
      else color (i+1) (comp c) (ac+1)
    )
  in

  let answer = min (color (-1) 'r' 0) (color (-1) 'b' 0) in

  printf "%d\n" answer


let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and x=read_int();;
let s=ref 0;;
for i=1 to n do
   s:= !s+read_int()
done;;
if !s<0 then s:= 0- !s;;
s:= !s+x-1;;
print_int ( !s/x);;

open Printf
open Scanf

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

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

let () =
  let n = read_int() in
  let x = read_int() in
  let input = Array.init n (fun _ -> read_int()) in
  let s = sum 0 (n-1) (fun i -> input.(i)) in

  (* want the minimum number of cards such that their sum when
     combined with s is zero.  *)

  let s = abs s in
  let k = s/x in
  let k = if k*x = s then k else k+1 in
  printf "%d\n" k

let k = int_of_string (List.nth (Str.split (Str.regexp_string " ") (read_line ())) 1);;
let s = List.map int_of_string (Str.split (Str.regexp_string " ") (read_line ()));;
let sum = abs (List.fold_left ( + ) 0 s);;
print_newline (print_int ((fun x -> if x * k < sum then (x + 1) else x) (sum / k)));;

let read_int()=Scanf.scanf " %d" (fun x->x);;
let n=read_int() and x=read_int();;
let s=ref 0;;
for i=1 to n do
   s:= !s+read_int()
done;;
if !s<0 then s:= 0- !s;;
print_int ( !s/x);;

let k = int_of_string (List.nth (Str.split (Str.regexp_string " ") (read_line ())) 1);;
let s = List.map int_of_string (Str.split (Str.regexp_string " ") (read_line ()));;
let sum = abs (List.fold_left ( + ) 0 s);;
print_newline (print_int ((fun x -> if x * k < sum then x + 1 else x) (sum mod k)));;


let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  (*let s = "gerald.agapov1991@gmail.com" in
  let s = "x@x.x@x.x_e_@r1.com" in*)
  let n = String.length s in
  let c = ref 0 in
  let c2 = ref 0 in
  let a = Array.make n 0 in
  let b = Array.make n 0 in
  let res = ref 0L in
    for i = 0 to n - 1 do
      match s.[i] with
	| '@' ->
	    a.(i) <- !c;
	    c := 0;
	| '.' -> c := 0;
	| 'a'..'z' -> incr c;
	| '0'..'9' -> ()
	| '_' -> ()
	| _ -> assert false
    done;
    c := 0;
    for i = n - 1 downto 0 do
      match s.[i] with
	| '@' ->
	    if !c2 <> 0 && s.[i + 1] <> '.'
	    then b.(i) <- !c2;
	    c2 := 0;
	    c := 0;
	| '.' ->
	    c2 := !c;
	    c := 0;
	| 'a'..'z' ->
	    incr c;
	| '0'..'9' ->
	    c := 0;
	| '_' ->
	    c := 0;
	    c2 := 0;
	| _ -> assert false
    done;
    for i = 0 to n - 1 do
      if s.[i] = '@'
      then res := Int64.add !res (Int64.mul (Int64.of_int a.(i))
				    (Int64.of_int b.(i)))
    done;
    Printf.printf "%Ld\n" !res;
    a, b

let s=read_line();;
let n=String.length(s)-1;;

let isvalid c=
if (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;

let isletter c=
if (c>='a')&&(c<='z') then true else false;;

let sol=ref Int64.zero;;

let rec faire i deb etape=
if i>n then ()
else if etape="debut" then
   begin
   if s.[i]='@' then
      begin
      if deb<>0 then faire (i+1) deb "arobase1"
      else faire (i+1) 0 "debut"
      end
   else if s.[i]='.' then faire (i+1) 0 "debut"
   else if (isletter s.[i]) then faire (i+1) (deb+1) "debut"
   else faire (i+1) deb "debut"
   end
else if etape="arobase1" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2" else faire (i+1) 0 "debut"
   end
else if etape="arobase2" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2"
   else if s.[i]='.' then faire (i+1) deb "point"
   else faire (i-1) 0 "retour_arobase"
   end
else if etape="point" then
   begin
   if (isletter s.[i]) then (sol:= Int64.add (!sol) (Int64.of_int deb);faire (i+1) deb "point")
   else faire (i-1) 0 "retour_point"
   end
else if etape="retour_point" then
   begin
   if s.[i]='.' then faire (i+1) 0 "debut"
   else faire (i-1) 0 "retour_point"
   end
else if s.[i]='@' then faire (i+1) 0 "debut"
else faire (i-1) 0 "retour_arobase";;

faire 0 0 "debut";;

print_string( Int64.to_string(!sol));;

let s=read_line();;
let n=String.length(s)-1;;

let isvalid c=
if (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;

let isletter c=
if (c>='a')&&(c<='z') then true else false;;

let sol=ref 0;;

let rec faire i deb etape=
if i>n then ()
else if etape="debut" then
   begin
   if s.[i]='@' then
      begin
      if deb<>0 then faire (i+1) deb "arobase1"
      else faire (i+1) 0 "debut"
      end
   else if s.[i]='.' then faire (i+1) 0 "debut"
   else if (isletter s.[i]) then faire (i+1) (deb+1) "debut"
   else faire (i+1) deb "debut"
   end
else if etape="arobase1" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2" else faire (i+1) 0 "debut"
   end
else if etape="arobase2" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2"
   else if s.[i]='.' then faire (i+1) deb "point"
   else faire (i-1) 0 "retour_arobase"
   end
else if etape="point" then
   begin
   if (isletter s.[i]) then (sol:= !sol+deb;faire (i+1) deb "point")
   else faire (i-1) 0 "retour_point"
   end
else if etape="retour_point" then
   begin
   if s.[i]='.' then faire (i+1) 0 "debut"
   else faire (i-1) 0 "retour_point"
   end
else if s.[i]='@' then faire (i+1) 0 "debut"
else faire (i-1) 0 "retour_arobase";;

faire 0 0 "debut";;

print_int( !sol);;

let s=read_line();;
let n=String.length(s)-1;;

let isvalid c=
if (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;

let isletter c=
if (c>='a')&&(c<='z') then true else false;;

let sol=ref 0;;

let rec faire i deb etape=
if i>n then ()
else if etape="debut" then
   begin
   if s.[i]='@' then
      begin
      if deb<>0 then faire (i+2) deb "arobase1"
      else faire (i+1) 0 "debut"
      end
   else if s.[i]='.' then faire (i+1) 0 "debut"
   else if (isletter s.[i]) then faire (i+1) (deb+1) "debut"
   else faire (i+1) deb "debut"
   end
else if etape="arobase1" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2" else faire (i+1) 0 "debut"
   end
else if etape="arobase2" then
   begin
   if (isvalid s.[i]) then faire (i+1) deb "arobase2"
   else if s.[i]='.' then faire (i+2) deb "point"
   else faire (i-1) 0 "retour_arobase"
   end
else if etape="point" then
   begin
   if (isletter s.[i]) then (sol:= !sol+deb;faire (i+1) deb "point")
   else faire (i-1) 0 "retour_point"
   end
else if etape="retour_point" then
   begin
   if s.[i]='.' then faire (i+1) 0 "debut"
   else faire (i-1) 0 "retour_point"
   end
else if s.[i]='@' then faire (i+1) 0 "debut"
else faire (i-1) 0 "retour_arobase";;

faire 0 0 "debut";;

print_int( !sol);;

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  (*let s = "gerald.agapov1991@gmail.com" in
  let s = "x@x.x@x.x_e_@r1.com" in*)
  let n = String.length s in
  let c = ref 0 in
  let c2 = ref 0 in
  let st = ref 0 in
  let a = Array.make n 0 in
  let b = Array.make n 0 in
  let res = ref 0L in
    for i = 0 to n - 1 do
      match s.[i] with
	| '@' ->
	    a.(i) <- !c;
	    c := 0;
	| '.' -> c := 0;
	| 'a'..'z' -> incr c;
	| '0'..'9' -> ()
	| '_' -> ()
	| _ -> assert false
    done;
    c := 0;
    for i = n - 1 downto 0 do
      match s.[i] with
	| '@' ->
	    b.(i) <- !c2;
	    c2 := 0;
	    c := 0;
	| '.' ->
	    c2 := !c;
	    c := 0;
	| 'a'..'z' ->
	    incr c;
	| '0'..'9' ->
	    c := 0;
	| '_' ->
	    c := 0;
	    c2 := 0;
	| _ -> assert false
    done;
    for i = 0 to n - 1 do
      if s.[i] = '@'
      then res := Int64.add !res (Int64.mul (Int64.of_int a.(i))
				    (Int64.of_int b.(i)))
    done;
    Printf.printf "%Ld\n" !res;
    a, b


let n = read_int ()
;;
let read_pair _ = Scanf.bscanf Scanf.Scanning.stdin " %d %d " (fun x y -> (x,y))
;;

for i = 1 to n do
  let (a,b) = read_pair () in
  Printf.printf "%d\n" (a*b)
done

open Printf
open Scanf

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


let r_long () = Int64.of_int (Scanf.scanf " %d" (fun x -> x)) in
let r_int () = Scanf.scanf " %d" (fun x -> x) in

let rec max_diff maxi = function
| 0 -> 0L
| nbNombres ->
   let nombre = r_long () in
   let nouvMax = max nombre maxi in
   max (Int64.sub maxi nombre) (max_diff nouvMax (nbNombres - 1))
in

let rec log = function
| 0L -> 0
| n -> 1 + log (Int64.div n 2L)
in

let nbTests = r_int () in
for iTest = 1 to nbTests do
   let nbNombres = r_int () in
   let diff = max_diff (r_long ()) (nbNombres - 1) in
   print_int (log diff);
   print_newline ()
done;

open Printf
open Scanf

let rec topbit d = if d lsr 1 = 0 then 0 else 1 + topbit (d lsr 1)

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

let () =
  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let a = Array.init n read_int in
    let rec loop i mb = if i=n-1 then mb else (
      if a.(i) <= a.(i+1) then loop (i+1) mb
      else (
	let d = a.(i) - a.(i+1) in
	a.(i+1) <- a.(i);
	let mb = max mb (1 + topbit d) in
	loop (i+1) mb
      )
    )
    in
    printf "%d\n" (if n = 1 then 0 else loop 0 0)
  done

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

let rec max_diff maxi = function
| 0 -> 0
| nbNombres ->
   let nombre = r_int () in
   let nouvMax = max nombre maxi in
   max (maxi - nombre) (max_diff nouvMax (nbNombres - 1))
in

let rec log = function
| 0 -> 0
| n -> 1 + log (n / 2)
in

let nbTests = r_int () in
for iTest = 1 to nbTests do
   let nbNombres = r_int () in
   let diff = max_diff (r_int ()) (nbNombres - 1) in
   print_int (log diff);
   print_newline ()
done;


module StringSet = Set.Make(String)

module StringMap = Map.Make(String)

let all_colors = (StringSet.of_list [
    "purple"; "green"; "blue"; "orange"; "red"; "yellow"
  ])

let gem_of_color = ref StringMap.empty

let () =
  List.iter
    (fun (k, v) -> gem_of_color := StringMap.add k v !gem_of_color)
    [
      ("purple", "Power");
      ("green", "Time");
      ("blue", "Space");
      ("orange", "Soul");
      ("red", "Reality");
      ("yellow", "Mind");
    ];
  let m = Scanf.scanf "%d" (fun i -> i) in
  let colors = ref all_colors in
  for i = 1 to m do
    let s = Scanf.scanf " %s" (fun i -> i) in
    colors := StringSet.remove s !colors
  done;
  Printf.printf "%d\n" (StringSet.cardinal !colors);
  StringSet.iter (fun s ->
      Printf.printf "%s\n" (StringMap.find s !gem_of_color)) !colors

let gems =
  [("purple", "Power");
  ("green", "Time");
  ("blue", "Space");
  ("orange", "Soul");
  ("red", "Reality");
  ("yellow", "Mind")]

let () =
  let n = int_of_string (input_line stdin) in
  let pr = ref [] in
  for i = 0 to n - 1 do
    pr := (input_line stdin) :: !pr
  done;
  let present = !pr in
  let p (gem_colour, gem_name) = not (List.mem gem_colour present) in
  let f (gem_colour, gem_name) = gem_name in
  let toprint = List.map f (List.filter p gems) in
  print_endline (string_of_int (List.length toprint));
  ignore (List.map print_endline toprint)


open Printf
open Scanf

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

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

  let det = (long a) ** (long d) -- (long b) ** (long c) in
  if det = 0L then printf "0.0\n" else

    let (a,b,c,d) = (float a, float b, float c, float d) in
    let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in
    let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in

    let lohi a b e =
      let x1 = (a -. e) *. (b -. e) in
      let x2 = (a +. e) *. (b -. e) in
      let x3 = (a -. e) *. (b +. e) in
      let x4 = (a +. e) *. (b +. e) in
      let hi = max (max x1 x2) (max x3 x4) in
      let lo = min (min x1 x2) (min x3 x4) in
      (lo,hi)
    in

    let intervals_intersect (lo1, hi1) (lo2, hi2) =
      if hi1 < lo2 then false
      else if hi2 < lo1 then false
      else true
    in

    let test e =
      intervals_intersect (lohi a d e) (lohi b c e)
    in

    let rec bsearch x y =
      let m = (x +. y) /. 2.0 in
      if abs_float (x -. y) < (1e-13) *. m then m
      else if test m then bsearch x m else bsearch m y
    in

    let answer = bsearch 0.0 1.0 in

    printf "%.10f\n" (answer *. big)

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let a = float (read_int()) in
  let b = float (read_int()) in
  let c = float (read_int()) in
  let d = float (read_int()) in

  let lohi a b e =
    let x1 = (a -. e) *. (b -. e) in
    let x2 = (a +. e) *. (b -. e) in
    let x3 = (a -. e) *. (b +. e) in
    let x4 = (a +. e) *. (b +. e) in
    let hi = max (max x1 x2) (max x3 x4) in
    let lo = min (min x1 x2) (min x3 x4) in
    (lo,hi)
  in

  let intervals_intersect (lo1, hi1) (lo2, hi2) =
    if hi1 < lo2 then false
    else if hi2 < lo1 then false
    else true
  in

  let test e =
    intervals_intersect (lohi a d e) (lohi b c e)
  in

  let rec bsearch x y n =
    let m = (x +. y) /. 2.0 in
    if n=0 then m
    else if test m then bsearch x m (n-1) else bsearch m y (n-1)
  in

  printf "%.10f\n" (bsearch 0.0 1e10 200)

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let a = float (read_int()) in
  let b = float (read_int()) in
  let c = float (read_int()) in
  let d = float (read_int()) in

  let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in

  let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in

  let lohi a b e =
    let x1 = (a -. e) *. (b -. e) in
    let x2 = (a +. e) *. (b -. e) in
    let x3 = (a -. e) *. (b +. e) in
    let x4 = (a +. e) *. (b +. e) in
    let hi = max (max x1 x2) (max x3 x4) in
    let lo = min (min x1 x2) (min x3 x4) in
    (lo,hi)
  in

  let intervals_intersect (lo1, hi1) (lo2, hi2) =
    if hi1 < lo2 then false
    else if hi2 < lo1 then false
    else true
  in

  let test e =
    intervals_intersect (lohi a d e) (lohi b c e)
  in

  let rec bsearch x y =
    let m = (x +. y) /. 2.0 in
    if abs_float (x -. y) < 1e-15 then m
    else if test m then bsearch x m else bsearch m y
  in

  let answer = bsearch 0.0 1.0 in

  printf "%.9f\n" (answer *. big)

open Printf
open Scanf

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

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

  let det = (long a) ** (long d) -- (long b) ** (long c) in
  if det = 0L then printf "0.0\n" else

    let (a,b,c,d) = (float a, float b, float c, float d) in
    let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in
    let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in

    let lohi a b e =
      let x1 = (a -. e) *. (b -. e) in
      let x2 = (a +. e) *. (b -. e) in
      let x3 = (a -. e) *. (b +. e) in
      let x4 = (a +. e) *. (b +. e) in
      let hi = max (max x1 x2) (max x3 x4) in
      let lo = min (min x1 x2) (min x3 x4) in
      (lo,hi)
    in

    let intervals_intersect (lo1, hi1) (lo2, hi2) =
      if hi1 < lo2 then false
      else if hi2 < lo1 then false
      else true
    in

    let test e =
      intervals_intersect (lohi a d e) (lohi b c e)
    in

    let rec bsearch x y =
      let m = (x +. y) /. 2.0 in
      if abs_float (x -. y) < 1e-13 then m
      else if test m then bsearch x m else bsearch m y
    in

    let answer = bsearch 0.0 1.0 in

    printf "%.9f\n" (answer *. big)


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 rec loop n tab =
  if n >= 0 then
  let x = read n in
  tab.(x) <- true;
  loop (n-1) tab
  else ();;

let _ =
  let (n, m) = read2 () in
  let tab = Array.make (m+1) false in
  tab.(0) <- true;
  for i=1 to n do
    let k = Scanf.scanf "%d " ( fun x -> x ) in
    loop (k-1) tab
  done;
  Printf.printf "%s\n" (Array.fold_left ( fun a x -> if not x then "NO" else a ) "YES" tab);;

open Printf
open Scanf

let rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)
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 (n,m) = read_pair () in
  let mark = Array.make m false in
  for i=0 to n-1 do
    let x = read_int () in
    for j=0 to x-1 do
      let y = -1 + read_int() in
      mark.(y) <- true;
    done
  done;

  if forall 0 (m-1) (fun i -> mark.(i)) then printf "YES\n" else printf "NO\n"

open Printf
open Scanf

let rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)
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 (n,m) = read_pair () in
  let mark = Array.make m false in
  for i=0 to n-1 do
    let x = read_int () in
    for j=0 to x-1 do
      let y = -1 + read_int() in
      mark.(y) <- true;
    done
  done;

  if forall 0 (n-1) (fun i -> mark.(i)) then printf "YES\n" else printf "NO\n"


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
end open MyInt64

module ModCalc = struct
	(* let md = 1000000007L *)
	let md = 998244353L
	let validate v =
		(v + (labs(v) / md + 1L) * md) mod md
	let _add_mod md u v = u mod md + v mod md |> validate
	let _sub_mod md u v = u mod md - v mod md |> validate
	let _mul_mod md u v = u mod md * v mod md |> validate
	let rec pw u v =
		if v=0L then 1L
		else if v=1L then u mod md
		else let p = pw u (v/2L) in
			if v mod 2L = 0L then _mul_mod md p p
			else _mul_mod md (_mul_mod md p p) u
	let _inv md v = pw v (md-2L)
	let _div_mod md u v =
		_mul_mod md u (_inv md v)

	let (+%)  u v = _add_mod md u v
	let (-%)  u v = _sub_mod md u v
	let ( *%) u v = _mul_mod md u v
	let (/%)  u v = _div_mod md u v
	let rec pow x n = if n = 0L then 1L
		else if n mod 2L = 1L then x *% pow x (n-1L)
		else let w = pow x (n/2L) in w *% w
	let fact n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L
end open ModCalc

let make_3darray p q r d = Array.init (~|p) (fun _ -> Array.make_matrix (~|q) (~|r) d)
let make_4darray p q r s d = Array.init (~|p) (fun _ -> make_3darray q r s d)
let (@~) a (i,j,k,l) = try a.(~|i).(~|j).(~|k).(~|l) with | Invalid_argument _ -> 0L
let (<@~) a (i,j,k,l,v) = a.(~|i).(~|j).(~|k).(~|l) <- v
let dp = make_4darray 1024L 2048L 2L 2L 0L

let () =
	let n,k = get_2_i64 0 in
	dp.(1).(1).(0).(0) <- 1L;
	dp.(1).(2).(0).(1) <- 1L;
	dp.(1).(2).(1).(0) <- 1L;
	dp.(1).(1).(1).(1) <- 1L;
	rep 2L n (fun i ->
		rep 1L (i*2L+2L) (fun j ->
			dp<@~(i,j,0L,0L,(
				(dp@~(i-1L,j,0L,0L))
				+% (dp@~(i-1L,j-1L,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,0L))
				+% (dp@~(i-1L,j-2L,1L,1L))
			));
			dp<@~(i,j,1L,1L,(
				(dp@~(i-1L,j,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,0L))
				+% (dp@~(i-1L,j-2L,0L,0L))
			));
			dp<@~(i,j,1L,0L,(
				(dp@~(i-1L,j,1L,0L))
				+% (dp@~(i-1L,j-1L,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,0L))
				+% (dp@~(i-1L,j-2L,0L,1L))
			));
			dp<@~(i,j,0L,1L,(
				(dp@~(i-1L,j,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,0L))
				+% (dp@~(i-1L,j-2L,1L,0L))
			));
			`Ok
		);
		`Ok
	);
	printf "%Ld\n" (
		(dp@~(n,k,0L,0L))
		+% (dp@~(n,k,0L,1L))
		+% (dp@~(n,k,1L,0L))
		+% (dp@~(n,k,1L,1L))
	)

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
end open MyInt64

module ModCalc = struct
	(* let md = 1000000007L *)
	let md = 998244353L
	let validate v =
		(v + (labs(v) / md + 1L) * md) mod md
	let _add_mod md u v = u mod md + v mod md |> validate
	let _sub_mod md u v = u mod md - v mod md |> validate
	let _mul_mod md u v = u mod md * v mod md |> validate
	let rec pw u v =
		if v=0L then 1L
		else if v=1L then u mod md
		else let p = pw u (v/2L) in
			if v mod 2L = 0L then _mul_mod md p p
			else _mul_mod md (_mul_mod md p p) u
	let _inv md v = pw v (md-2L)
	let _div_mod md u v =
		_mul_mod md u (_inv md v)

	let (+%)  u v = _add_mod md u v
	let (-%)  u v = _sub_mod md u v
	let ( *%) u v = _mul_mod md u v
	let (/%)  u v = _div_mod md u v
	let rec pow x n = if n = 0L then 1L
		else if n mod 2L = 1L then x *% pow x (n-1L)
		else let w = pow x (n/2L) in w *% w
	let fact n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L
end open ModCalc

let make_3darray p q r d = Array.init (~|p) (fun _ -> Array.make_matrix (~|q) (~|r) d)
let make_4darray p q r s d = Array.init (~|p) (fun _ -> make_3darray q r s d)
let (@~) a (i,j,k,l) = try a.(~|i).(~|j).(~|k).(~|l) with | Invalid_argument _ -> 0L
let (<@~) a (i,j,k,l,v) = a.(~|i).(~|j).(~|k).(~|l) <- v
let dp = make_4darray 1024L 2048L 2L 2L 0L

let () =
	let n,k = get_2_i64 0 in
	dp.(1).(1).(0).(0) <- 1L;
	dp.(1).(2).(0).(1) <- 1L;
	dp.(1).(2).(1).(0) <- 1L;
	dp.(1).(1).(1).(1) <- 1L;
	rep 2L n (fun i ->
		rep 1L (i*2L+2L) (fun j ->
			dp<@~(i,j,0L,0L,(
				(dp@~(i-1L,j,0L,0L))
				+% (dp@~(i-1L,j-1L,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,0L))
				+% (dp@~(i-1L,j-1L,1L,1L))
			));
			dp<@~(i,j,1L,1L,(
				(dp@~(i-1L,j,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,0L))
				+% (dp@~(i-1L,j-1L,0L,0L))
			));
			dp<@~(i,j,1L,0L,(
				(dp@~(i-1L,j,1L,0L))
				+% (dp@~(i-1L,j-1L,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,0L))
				+% (dp@~(i-1L,j-2L,0L,1L))
			));
			dp<@~(i,j,0L,1L,(
				(dp@~(i-1L,j,0L,1L))
				+% (dp@~(i-1L,j-1L,1L,1L))
				+% (dp@~(i-1L,j-1L,0L,0L))
				+% (dp@~(i-1L,j-2L,1L,0L))
			));
			`Ok
		);
		`Ok
	);
	printf "%Ld\n" (
		(dp@~(n,k,0L,0L))
		+% (dp@~(n,k,0L,1L))
		+% (dp@~(n,k,1L,0L))
		+% (dp@~(n,k,1L,1L))
	)


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

open Int64;;
let t = scan_int();;

let f s a b c =
  let c1 = mul a c in
  let ile = div s c1 in
  add (mul ile (add a b)) (div (sub s (mul ile c1)) c);;

for i = 0 to t - 1 do
  let a = Int64.of_int(scan_int()) and
      b = Int64.of_int(scan_int()) and
      c = Int64.of_int(scan_int()) and
      d = Int64.of_int(scan_int()) in
  print_string(Int64.to_string(f a b c d)); print_newline();
done;;

open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (%$) = (mod) 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 () =
	let t = get_i64 0 in
	rep 1L t (fun _ ->
		let s,a,b,c = get_4_i64 0 in
		let buy = s / c in
		let d = buy / a in
		(d*(a+b) + (buy - d*a)) |> printf "%Ld\n";
		(* printf "%Ld %Ld\n" buy d; *)
		`Ok
	)


(* Codeforces 252B RazborCode 255B *)

open Filename;;
open String;;

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

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

let rec cntxy s idx cntx cnty =
	if idx >= (length s) then (cntx, cnty)
	else begin
		let c = s.[idx] in
		let id1 = idx +1 in
		if c = 'x' then
			cntxy s id1 (cntx + 1) cnty
		else cntxy s id1 cntx (cnty + 1)
	end;;

let rec reppri s n = match n with
	| 0 -> ()
	| _ -> begin
				print_string s;
				reppri s (n -1)
			end;;

let main () =
	let s = rdln() in
	let (cx, cy) = cntxy s 0 0 0 in
	begin
		(* print_string " cx,cy = "; print_int cx; print_string " "; print_int *)
		(* cy;                                                                 *)
		if cx < cy then reppri "y" (cy - cx)
			else reppri "x" (cx - cy);
		print_newline()
	end;;

main();;

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

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

let s = explode (read_string ()) ;;

let count s =
    let rec loop (x, y) = function
        | [] -> (x, y)
        | h :: t ->
            if h = 'x' then loop (x + 1, y) t
            else loop (x, y + 1) t
    in loop (0, 0) s ;;

let result =
    let (x, y) = count s in
    if x > y then String.make (x - y) 'x'
    else String.make (y - x) 'y' ;;

Printf.printf "%s\n" result ;;

let () =
  let s = read_line() in
  let c = Array.make 2 0 in
    for i = 0 to (String.length s)-1 do
      let w = if s.[i] = 'x' then 0 else 1 in
	c.(w) <- c.(w) + 1
    done;

    let b = if c.(0) > c.(1) then 'x' else 'y' in
    let n = abs (c.(0) - c.(1)) in
      for i=0 to n-1 do
	print_char b
      done;
      print_newline()


(* #load "str.cma" *)
module Stdlib = Pervasives;;
(* let std_inp = Stdlib.open_in "input.txt";; *)
let std_inp = Stdlib.stdin;;
let std_outp = Stdlib.stdout;;

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

let rec slices n =
  if n mod 2 == 0 then 1 + slices (n / 2)
  else 0;;

let rec pow base = function
| 0 -> 1
| n -> base * (pow base (n - 1));;

let solution inp outp =
  let (w, h, n) = let line = input_line inp in Scanf.sscanf line "%d %d %d" tup3 in
  let w_count = slices w and h_count = slices h in
  (* let _ = Printf.printf "W: %d; H: %d; N: %d\n" w h n in *)
  (* let _ = Printf.printf "WC: %d; HC: %d\n" w_count h_count in *)
  let _ =
    if (pow 2 w_count) * (pow 2 h_count) >= n then Printf.printf "YES\n"
    else Printf.printf "NO\n"
  in
  ();;
let rec run_test = function
| (0, _, _) -> ()
| (t, inp, outp) ->
  let _ = solution inp outp in
  run_test (t - 1, inp, outp);;

let (_:unit) =
  let inp = std_inp and outp = std_outp in
  let tests_count = let line = input_line inp in Scanf.sscanf line "%d" identity in
  let _ = run_test (tests_count, inp, outp) in
  ();;

(** https://codeforces.com/problemset/problem/1472/A *)

let max_friends width height =
    let rec helper num i =
        if num land 1 = 1
        then i
        else helper (num lsr 1) (i+1) in
    let cut_width = helper width 0 and
    cut_height = helper height 0 in
    let rec pow2 i res =
        if i = 0
        then res
        else pow2 (i-1) (res lsl 1) in
    pow2 (cut_width+cut_height) 1

let solve_n nb_cases =
    let rec helper i =
        if i > 0
        then (
            let [width; height; friends] =
                read_line ()
                |> Str.split (Str.regexp " ")
                |> List.map int_of_string in
            (if max_friends width height >= friends then "YES" else "NO")
            |> print_endline;
            helper (i-1)
        ) in
    helper nb_cases

let () =
    let nb_cases = read_int () in
    solve_n nb_cases


let k = List.nth (read_line () |> Str.split (Str.regexp " +") ) 1 |> int_of_string and
    ys = read_line() |> Str.split (Str.regexp " +") |> List.map int_of_string in

    ys |> List.map (fun x -> x + k) |> List.filter (fun x -> x <=5) |> List.length |> fun x -> x / 3 |> print_int

let read_int()=Scanf.scanf "%d " (fun x->x);;
let n=read_int();;
let k=read_int();;
let nb=ref 0;;
for i=1 to n-1 do
   let x=read_int() in
   if x<=5-k then incr nb
done;;
let a=Scanf.scanf "%d" (fun x->x) in if a<=5-k then incr nb;;
print_int( (!nb)/3);;

(* 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 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
(* int *)
let intsqrt n =
  if n < 0 then raise (Invalid_argument "sqrt of negative int") else
  let rec bs a b = begin
    if b - a = 1 then a else
    let mid = (a+b)/2 in
    if mid*mid <= n then bs mid b else bs a mid
  end in
  bs 0 (1 lsl 31)
(* 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
(* tuple *)
let (+:) (a,b) (c,d) = (a+c,b+d)
let (-:) (a,b) (c,d) = (a-c,b-d)
(* Arithmetic *)
let negate x = -x
let rec factorial n = if n = 0 then 1 else n * factorial (n-1)
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec extgcd a b =
  if b = 0 then 1,0,a else
  let x,y,g = extgcd b (a mod b) in
  y,x-(a/b)*y,g
let rec pow x n = if n = 0 then 1 else
  let n' = n/2 in
  let p = pow x n' in
  if is_odd n then x*p*p else p*p
let rec modpow m x n =
  if n = 0 then 1 else
  let n' = n/2 in
  let p = modpow m x n' in
  if is_even n then (p*p mod m) else
  (x*(p*p mod m) mod m)
let modinv m i = let _,x,_ = extgcd m i in x
(* IO *)
let is_digit c =
  let i = int_of_char c in
  48 <= i && i < 58
let is_space c = c = ' ' || c = '\n' || c = '\t' || c = '\r'
let read_char () = try input_char stdin with End_of_file -> '\000'
let rec read_letter () =
  let c = read_char() in
  if is_space c then read_letter() else c
let read_int () =
  let digit c = int_of_char c - 48 in
  let rec read n =
    let c = read_char() in
    if is_digit c then read (10*n + (digit c)) else
    n
  in
  let rec run c =
    if is_digit c then read (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -read (digit c) else run c
    end else
    if c = '\000' then 0 else
    run (read_char())
  in
  run (read_char())
let read_float () =
  let digit c = float (int_of_char c - 48) in
  let rec read_decimial m f =
    let c = read_char () in
    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f
  in
  let rec read_integral n =
    let c = read_char () in
    if is_digit c then read_integral (10. *. n +. digit c) else
    if c = '.' then n +. read_decimial 0.1 0.0 else
    n
  in
  let rec run c = begin
    if is_digit c then read_integral (digit c) else
    if c = '-' then begin
      let c = read_char() in
      if is_digit c then -. read_integral (digit c) else
      run c
    end else
    if c = '.' then read_decimial 0.1 0.0 else
    if c = '\000' then 0.0 else
    run (read_char())
  end in
  run (read_char())
let read_word () =
  let open Buffer in
  let buf = create 1_000_000 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 1_000_000 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_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 _ =
  let len = read_int() in
  let k = read_int() in
  let arr = init len (fun i -> read_int() ) in
  sort compare arr;
  let rec upper_bound a b =
    if b - a = 1 then b else
    let mid = (a+b)/2 in
    if arr.(mid) <= 5-k then upper_bound mid b else upper_bound a mid
  in
  printf "%d\n" ((upper_bound (-1) len)/3)

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

let input () =
    let n = read () in
    let k = read () in
    let rec loop i list =
        if i < n
        then
            let temp = read () in
            loop (i + 1) (temp :: list)
        else
            (k, list)
    in loop 0 []

let solve (k, list) =
    let qualified = List.filter (fun m -> m + k <= 5) list in
    List.length qualified / 3

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