Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips x - 1 consecutive bricks, then he paints the x-th one. That is, he'll paint bricks x, 2·x, 3·x and so on red. Similarly, Floyd skips y - 1 consecutive bricks, then he paints the y-th one. Hence he'll paint bricks y, 2·y, 3·y and so on pink.After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question.

The input will have a single line containing four integers in this order: x, y, a, b. (1 ≤ x, y ≤ 1000, 1 ≤ a, b ≤ 2·109, a ≤ b).

Output a single integer — the number of bricks numbered no less than a and no greater than b that are painted both red and pink.

NoteLet's look at the bricks from a to b (a = 6, b = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.

open Printf
open Scanf
open String
open List
open Int64

let rec gcd a b =
	if b = zero then a
	else gcd b (rem a b);;

let solve x y a b =
	let l = (div (mul x y) (gcd x y))
	in printf "%Ld" (sub (div b l) (div (pred a) l))
in scanf "%Ld %Ld %Ld %Ld" solve;;

let lcm a b =
    let rec gcd a b = if b = Int32.zero then a else gcd b (Int32.rem a b)
    in (Int32.div (Int32.mul a b) (gcd a b)) in
let (x, y, a, b) = Scanf.scanf "%ld %ld %ld %ld\n" (fun x y a b -> (x, y, a, b)) in
let m = lcm x y in
(* determine number of m in interval [a,b] *)
let start = Int32.add a (Int32.rem (Int32.sub m (Int32.rem a m)) m)
and last  = Int32.sub b (Int32.rem b m) in
Printf.printf "%ld\n" (max (Int32.succ (Int32.div (Int32.sub last start) m))
Int32.zero) ;;

let rec gcd a = function 0 -> a | b -> gcd b (a mod b) in
let lcm a b = (a * b) / (gcd a b) in
let (x, y, a, b) = Scanf.scanf "%d %d %d %d\n" (fun x y a b -> (x, y, a, b)) in
let m = lcm x y in
(* determine number of m in interval [a,b] *)
let start = a + (a mod m)
and last  = b - (b mod m) in
Printf.printf "%d\n" (max ((last - start) / m + 1) 0) ;;


Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.Arithmetic progression is a sequence a1, a1 + d, a1 + 2d, ..., a1 + (n - 1)d, where a1 and d are any numbers.Geometric progression is a sequence b1, b2 = b1q, ..., bn = bn - 1q, where b1 ≠ 0, q ≠ 0, q ≠ 1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.

The first line contains exactly four integer numbers between 1 and 1000, inclusively.

Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.

NoteThis problem contains very weak pretests!

Scanf.scanf "%f %f %f %f\n" (fun a b c d ->
    let n =
        if a = 0. || b = 0. || c = 0. || a = b || b = c || c = d then
            if b -. a = c -. b && c -. b = d -. c then
                (* arithmetic *)
                d +. (b -. a)
            else 42.
        else if b /. a = c /. b && c /. b = d /. c then
            (* geometric *)
            let q = (b /. a) in
            let r = d *. q in
            if fst (modf r) <> 0. then 42.
            else r
        else if b -. a = c -. b && c -. b = d -. c then
            (* arithmetic *)
            d +. (b -. a)
        else 42. in
    Printf.printf "%d\n" (int_of_float n)) ;;


Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 50) — number ai stands for the number of sockets on the i-th supply-line filter.

Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.

NoteIn the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.

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

let () =
  let n = read_int() in
  let m = read_int() in
  let k = read_int() in
  let g = Array.init n (fun _ -> read_int() - 1) in

  let () = Array.sort (fun a b -> compare b a) g in

  let rec search i t = if k+t >= m then i else
    if i < n then search (i+1) (t+g.(i)) else -1
  in

    Printf.printf "%d\n" (search 0 0)

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

let () =
  let n = read_int() in
  let m = read_int() in
  let k = read_int() in
  let g = Array.init n (fun i -> read_int() - 1) in

  let () = Array.sort (fun a b -> compare b a) g in

  let rec search i t = if i=n then -1 else if k+t >= m then i else search (i+1) (t+g.(i)) in

    Printf.printf "%d\n" (search 0 0)


HQ9+ is a joke programming language which has only four one-character instructions: "H" prints "Hello, World!", "Q" prints the source code of the program itself, "9" prints the lyrics of "99 Bottles of Beer" song,  "+" increments the value stored in the internal accumulator.Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output "YES", if executing the program will produce any output, and "NO" otherwise.

NoteIn the first case the program contains only one instruction — "H", which prints "Hello, World!".In the second case none of the program characters are language instructions.

let rec p str n = if (n=String.length str) then "NO"
                else match str.[n] with 'H' | 'Q' | '9' -> "YES" | _ -> p str (n+1)

let main () = ((print_string (p (read_line ()) 0)); print_newline ();
);;

if !Sys.interactive then () else main ();;

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

let solve input =
    if String.contains input 'H' || String.contains input 'Q' || String.contains input '9'
    then
        "YES"
    else
        "NO"

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

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

let flag = ref "NO";;

exception Found;;

let vote = function
  | 'H' -> raise Found
  | 'Q' -> raise Found
  | '9' -> raise Found
  | _ -> ()
;;

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

try
  for i=0 to String.length s - 1 do
    vote (String.get s i)
  done
with Found -> flag := "YES";;

print_endline !flag;;

let solve p =
  if String.contains p 'H' || String.contains p 'Q' || String.contains p '9'
  then "YES"
  else "NO"

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

let solve s len =
  let rec solve' i = match s.[i], i with
    | 'H', _ | 'Q', _ | '9', _ -> "YES"
    |   _, n when n = len -> "NO"
    |   _, n -> solve' (i + 1)
  in solve' 0

let () =
  let s = read_line () in
  Printf.printf "%s\n" (solve (s ^ " ") (String.length s))

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

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

exception Error of string

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

let charlist_of_string s =
  let rec inner rv = function
      0 -> rv
    | m -> inner (s.[m-1]::rv) (m-1) in
  inner [] (String.length s)
;;

let l = ['H'; 'Q'; '9'];;

let _ =
  let s = read_line() in
  let func c = List.memq c @@ charlist_of_string s in
  print_endline (if List.exists func l then "YES" else "NO")
;;


The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds. Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.

The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to. The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter. The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or ) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.

Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.

NoteIn the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds. In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.

let read_ints (n : int) : int array =
  let s = read_line () in
  let a = Array.make n 0 in
  let p = ref 0 (* position in a *) in
  begin
    for i = 0 to String.length s - 1 do
      match s.[i] with
        ' ' -> incr p
      | c ->  a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')
    done
  end;
  a

(* distance needed for train to travel from p to x *)
let f ((s, p, x, dir) : int * int * int * bool) : int =
  if p = x
  then 0
  else
    match p < x, dir with
      true, true -> x - p
    | true, false -> p + x
    | false, true -> 2*s - p - x
    | false, false -> p - x

(* distance needed for train to travel from x, dir to x, dir2 *)
let g ((s, x, dir, dir2) : int * int * bool * bool) : int =
  match dir, dir2 with
    true, true -> 0
  | true, false -> 2*(s-x)
  | false, true -> 2*x
  | false, false -> 0

let main () : unit =
  let [|s; x1; x2|]  = read_ints 3 in
  let [|t1; t2|] = read_ints 2 in
  let [|p; d|] = read_ints 2 in
    let dist = abs (x1 - x2) in
      let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, (if p = x1 then d = 1 else p < x1), x1 < x2) + dist) * t1) in
        print_int ans

let _ = main ()

let read_ints (n : int) : int array =
  let s = read_line () in
  let a = Array.make n 0 in
  let p = ref 0 (* position in a *) in
  begin
    for i = 0 to String.length s - 1 do
      match s.[i] with
        ' ' -> incr p
      | c ->  a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')
    done
  end;
  a

(* distance needed for train to travel from p to x *)
let f ((s, p, x, dir) : int * int * int * bool) : int =
  if p = x
  then 0
  else
    match p < x, dir with
      true, true -> x - p
    | true, false -> p + x
    | false, true -> 2*s - p - x
    | false, false -> p - x

(* distance needed for train to travel from x, dir to x, dir2 *)
let g ((s, x, dir, dir2) : int * int * bool * bool) : int =
  match dir, dir2 with
    true, true -> 0
  | true, false -> 2*(s-x)
  | false, true -> 2*x
  | false, false -> 0

let main () : unit =
  let [|s; x1; x2|]  = read_ints 3 in
  let [|t1; t2|] = read_ints 2 in
  let [|p; d|] = read_ints 2 in
    let dist = abs (x1 - x2) in
      let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, (if p = x1 then x1 < x2 else p < x1), x1 < x2) + dist) * t1) in
        print_int ans

let _ = main ()

let read_ints (n : int) : int array =
  let s = read_line () in
  let a = Array.make n 0 in
  let p = ref 0 (* position in a *) in
  begin
    for i = 0 to String.length s - 1 do
      match s.[i] with
        ' ' -> incr p
      | c ->  a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')
    done
  end;
  a

(* distance needed for train to travel from p to x *)
let f ((s, p, x, dir) : int * int * int * bool) : int =
  match p < x, dir with
    true, true -> x - p
  | true, false -> p + x
  | false, true -> 2*s - p - x
  | false, false -> p - x

(* distance needed for train to travel from x, dir to x, dir2 *)
let g ((s, x, dir, dir2) : int * int * bool * bool) : int =
  match dir, dir2 with
    true, true -> 0
  | true, false -> 2*(s-x)
  | false, true -> 2*x
  | false, false -> 0

let main () : unit =
  let [|s; x1; x2|]  = read_ints 3 in
  let [|t1; t2|] = read_ints 2 in
  let [|p; d|] = read_ints 2 in
    let dist = abs (x1 - x2) in
      let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, p < x1, x1 < x2) + dist) * t1) in
        print_int ans

let _ = main ()


As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

The first input line contains an integer n (1 ≤ n ≤ 109).

Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers.

let rec gao n a b = match a, b with
  | [], _ | _, [] -> "NO"
  | (x::xs), (y::ys) ->
      if x + y = n then "YES"
      else if x + y > n then gao n a ys
      else gao n xs b
;;

let triangular n =
  if n mod 2 = 0
  then n / 2 * (n + 1)
  else (n + 1) / 2 * n
;;

let a = Array.init 45000 triangular in
let l = List.tl (Array.to_list a) in
let n = Scanf.scanf "%d" (fun x -> x) in
print_endline (gao n l (List.rev l));;

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

let tri k = k * (k + 1) / 2

let isTri n =
    let rec go l r =
        if r - l <= 1 then tri l == n
        else
        let m = l + (r - l) / 2 in
        if tri m <= n then go m r
        else go l m
    in go 0 (int_of_float (sqrt (float_of_int (2 * n)) +. 1.))

let isDoubleTri n =
    let rec go i sum =
        if sum >= n then false
        else if isTri (n - sum) then true
        else go (i + 1) (sum + i + 1)
    in go 1 1

let () =
    let n = readInt () in
    Printf.printf (if isDoubleTri n then "YES\n" else "NO\n")

let readInt64 () = Scanf.scanf " %Ld" (fun x -> x)

let tri k = Int64.(div (mul k (add k 1L)) 2L)

let isTri n =
    let rec lim k =
        if tri k <= n then lim (Int64.mul 2L k)
        else k
    in
    let rec go l r = Int64.(
        if sub r l <= 1L then tri l = n
        else
        let m = add l (div (sub r l) 2L) in
        if tri m <= n then go m r
        else go l m
    )
    in go 0L (lim 3L)

let isDoubleTri n =
    let rec go i sum = Int64.(
        if sum >= n then false
        else if isTri (sub n sum) then true
        else let ii = add i 1L in go ii (add sum ii)
    )
    in go 1L 1L

let () =
    let n = readInt64 () in
    Printf.printf (if isDoubleTri n then "YES\n" else "NO\n")

let readInt32 () = Scanf.scanf " %ld" (fun x -> x)

let tri k = Int32.(div (mul k (add k 1l)) 2l)

let isTri n =
    let rec lim k =
        if tri k <= n then lim Int32.(div (mul 14l k) 10l)
        else k
    in
    let rec go l r = Int32.(
        if sub r l <= 1l then tri l = n
        else
        let m = add l (div (sub r l) 2l) in
        if tri m <= n then go m r
        else go l m
    )
    in go 0l (lim 3l)

let isDoubleTri n =
    let rec go i sum = Int32.(
        if sum >= n then false
        else if isTri (sub n sum) then true
        else let ii = add i 1l in go ii (add sum ii)
    )
    in go 1l 1l

let () =
    let n = readInt32 () in
    Printf.printf (if isDoubleTri n then "YES\n" else "NO\n")

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

let tri k = k * (k + 1) / 2

let isTri n =
    let rec go l r =
        if r - l <= 1 then tri l == n
        else
        let m = l + (r - l) / 2 in
        if tri m <= n then go m r
        else go l m
    in go 0 n

let isDoubleTri n =
    let rec go i sum =
        if sum >= n then false
        else if isTri (n - sum) then true
        else go (i + 1) (sum + i + 1)
    in go 1 1

let () =
    let n = readInt () in
    Printf.printf (if isDoubleTri n then "YES\n" else "NO\n")


JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $$$n$$$, you can perform the following operations zero or more times:  mul $$$x$$$: multiplies $$$n$$$ by $$$x$$$ (where $$$x$$$ is an arbitrary positive integer).  sqrt: replaces $$$n$$$ with $$$\sqrt{n}$$$ (to apply this operation, $$$\sqrt{n}$$$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $$$n$$$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?Apparently, no one in the class knows the answer to this problem, maybe you can help them?

The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the initial number.

Print two integers: the minimum integer $$$n$$$ that can be achieved using the described operations and the minimum number of operations required.

NoteIn the first example, you can apply the operation mul $$$5$$$ to get $$$100$$$ and then sqrt to get $$$10$$$.In the second example, you can first apply sqrt to get $$$72$$$, then mul $$$18$$$ to get $$$1296$$$ and finally two more sqrt and you get $$$6$$$.Note, that even if the initial value of $$$n$$$ is less or equal $$$10^6$$$, it can still become greater than $$$10^6$$$ after applying one or more operations.

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

let factor n =
  let m,r = ref n,ref [] in
  rep 2L (n/2L) (fun i ->
    if !m mod i = 0L then (
      let k = ref 0L in
      while !m mod i = 0L do
        k += 1L; m /= i;
      done;
      r := (i,!k) :: !r));
  if !m>1L then (!m,1L)::!r else !r

let binary_search_opt ng ok f =
  let d = if ng < ok then 1L else -1L in
  let i = binary_search ng ok f in
  if i=ng-d || i=ok+d then None else Some i

let pow n k =
  let rec f a n = function
  | 0L -> a
  | 1L -> n*a
  | k when k mod 2L = 0L -> f a (n*n) (k/2L)
  | k -> f (a*n) n (k-1L)
  in f 1L n k

let () =
  let n = get_i64 0 in
  let ls = factor n in
  let ans,k_max = List.fold_left (fun (u,w) (v,x) -> (u*v,max w x)) (1L,0L) ls in
  let nibekies =
    let i = ref 1L in
    let r = ref [] in
    while !i <= 1000008L do
      r := !i :: !r;
      i *= 2L;
    done; !r |> List.rev |> of_list in
  let k_to = lower_bound nibekies k_max in
  if pow ans (nibekies.(i32 k_to)) = n then printf "%Ld %Ld\n" ans k_to
  else printf "%Ld %Ld\n" ans (k_to + 1L)

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

let factor n =
  let m,r = ref n,ref [] in
  rep 2L (n/2L) (fun i ->
    if !m mod i = 0L then (
      let k = ref 0L in
      while !m mod i = 0L do
        k += 1L; m /= i;
      done;
      r := (i,!k) :: !r));
  if !m>1L then (!m,1L)::!r else !r

let binary_search_opt ng ok f =
  let d = if ng < ok then 1L else -1L in
  let i = binary_search ng ok f in
  if i=ng-d || i=ok+d then None else Some i

let pow n k =
  let rec f a n = function
  | 0L -> a
  | 1L -> n*a
  | k when k mod 2L = 0L -> f a (n*n) (k/2L)
  | k -> f (a*n) n (k-1L)
  in f 1L n k

let () =
  let n = get_i64 0 in
  let ls = factor n in
  let ans,k_max = List.fold_left (fun (u,w) (v,x) -> (u*v,max w x)) (1L,0L) ls in
  let nibekies =
    let i = ref 1L in
    let r = ref [] in
    while !i <= 1000008L do
      r := !i :: !r;
      i *= 2L;
    done; !r |> List.rev |> of_list in
  let k_to = lower_bound nibekies k_max in
  if pow ans (pow 2L k_to) = n then printf "%Ld %Ld\n" ans k_to
  else printf "%Ld %Ld\n" ans (k_to + 1L)

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

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

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

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


Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all integers from $$$1$$$ to $$$n$$$.

The only input line contains the integer $$$n$$$ ($$$1 \le n \le 2\cdot10^9$$$).

Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.

NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\cdot8\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$).

let scanf = Scanf.scanf

let printf = Printf.printf

let int64_to_nums (src: int64): int array =
  let str = Int64.to_string src in
  let ret = Array.make (String.length str) 0 in
  String.iteri (fun i c -> Array.set ret i ((Char.code c) - (Char.code '0'))) str;
  ret

let mul (src: int array): int =
  (* let rec f (begun: bool) (i: int) (ret: int): int =
   *   if i >= (Array.length src)
   *   then ret
   *   else
   *     let t = src.(i) in
   *     if begun || t != 0
   *     then f true (i + 1) (ret * t)
   *     else f false (i + 1) ret
   * in f false 0 1 *)
  Array.fold_left (fun (begun, ret) t ->
      if begun || t != 0 then (true, ret * t) else (false, ret)
  ) (false, 1) src |> (fun (a, b) -> b)

let strip_nums (pos: int) (src: int array): int array =
  Array.mapi (fun i v ->
      if i < pos then v else if i = pos then v - 1 else 9) src

let maximum_mul (src: int array): int =
  let rec f (i: int): int =
    if i >= (Array.length src)
    then 1
    else max (max (mul (strip_nums i src)) (f (i + 1))) (mul src)
  in f 0

let _ =
  let n = scanf "%Ld" (fun a -> a) in
  let nums = int64_to_nums n in
  printf "%d\n" (maximum_mul nums)


Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.Note that the game consisted of several complete sets.

The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).

If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.

NoteNote that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.

let (+) = Int64.add
and (/) = Int64.div
and rem = Int64.rem ;;

let n = Scanf.scanf "%Ld %Ld %Ld\n" (fun k a b ->
                      let t = (a / k) + (b / k) in
                      if ((a >= k && b >= k)
                          || ((rem a k) = Int64.zero && a > Int64.zero)
                          || ((rem b k) = Int64.zero && b > Int64.zero)) then t else Int64.minus_one) ;;

Printf.printf "%Ld\n" n

let n = Scanf.scanf "%d %d %d\n" (fun k a b ->
                      let t = (a / k) + (b / k) in
                      if t = 0 then -1 else t) ;;

Printf.printf "%d\n" n

let (+) = Int64.add
and (/) = Int64.div
and rem = Int64.rem ;;

let n = Scanf.scanf "%Ld %Ld %Ld\n" (fun k a b ->
                      let t = (a / k) + (b / k) in
                      if (a >= k && b >= k
                          || (rem a k) = Int64.zero
                          || (rem b k) = Int64.zero) then t else Int64.minus_one) ;;

Printf.printf "%Ld\n" n

let (+) = Int64.add
and (/) = Int64.div ;;

let n = Scanf.scanf "%Ld %Ld %Ld\n" (fun k a b ->
                      let t = (a / k) + (b / k) in
                      if t = Int64.zero then Int64.minus_one else t) ;;

Printf.printf "%Ld\n" n


Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.Two prime numbers are called neighboring if there are no other prime numbers between them.You are to help Nick, and find out if he is right or wrong.

The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).

Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.

NoteIn the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.

let is_prime n =
  if n = 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else
    let rec loop k =
      if k * k > n then true
      else if n mod k = 0 then false
      else loop (k+2)
    in loop 3
;;

print_string (Scanf.scanf "%d %d" (fun n k ->
	let m = ref 0 in
	let i = ref 3 in
	let last = ref 2 in
	let _ = while (!i) <= n-(!last)-1 do
		if is_prime(!i) then begin
			if !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)
			then (incr m);
			last := (!i)
		end;
		i := (!i) + 2;
	done in
	if (!m) < k then "NO" else "YES"
));;

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

let () =
  let b = Array.make 1000 true in
  for i = 2 to 1000-1 do
    if b.(i) then
      let rec go j =
        if j < 1000 then (
          b.(j) <- false;
          go (j+i)
        )
      in
      go (i*i)
  done;
  let n = read_int 0 in
  let k = read_int 0 in
  let rec go acc last i =
    if i >= 504 then
      acc
    else if not b.(i) then
      go acc last (i+1)
    else if last > 0 && last+i+1 <= n && b.(last+i+1) then
      go (acc+1) i (i+1)
    else
      go acc i (i+1)
  in
  print_endline (if go 0 0 2 >= k then "YES" else "NO")

let is_prime n =
  if n = 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else
    let rec loop k =
      if k * k > n then true
      else if n mod k = 0 then false
      else loop (k+2)
    in loop 3
;;

print_string (Scanf.scanf "%d %d" (fun n k ->
	let m = ref 0 in
	let i = ref 3 in
	let last = ref 2 in
	let _ = while (!i) <= n/2+2 do
		if is_prime(!i) then begin
			if !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)
			then (incr m);
			last := (!i)
		end;
		i := (!i) + 2;
	done in
	if (!m) < k then "NO" else "YES"
));;

let is_prime n =
  if n = 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else
    let rec loop k =
      if k * k > n then true
      else if n mod k = 0 then false
      else loop (k+2)
    in loop 3
;;

print_string (Scanf.scanf "%d %d" (fun n k ->
	let m = ref 0 in
	let i = ref 3 in
	let last = ref 2 in
	let _ = while (!i) <= n/2 do
		if is_prime(!i) then begin
			if (!i)+(!last)+1 < n && is_prime((!i)+(!last)+1)
			then incr m;
			last := (!i)
		end;
		i := (!i) + 2;
	done in
	if (!m) < k then "NO" else "YES"
));;

let is_prime n =
  if n = 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else
    let rec loop k =
      if k * k > n then true
      else if n mod k = 0 then false
      else loop (k+2)
    in loop 3
;;

print_string (Scanf.scanf "%d %d" (fun n k ->
	let m = ref 0 in
	let i = ref 3 in
	let last = ref 2 in
	let _ = while (!i) < n/2 do
		if is_prime(!i) then begin
			if (!i)+(!last)+1 < n && is_prime((!i)+(!last)+1)
			then incr m;
			last := (!i)
		end;
		i := (!i) + 2;
	done in
	if (!m) < k then "NO" else "YES"
));;

let is_prime n =
  if n = 2 then true
  else if n < 2 || n mod 2 = 0 then false
  else
    let rec loop k =
      if k * k > n then true
      else if n mod k = 0 then false
      else loop (k+2)
    in loop 3
;;

print_string (Scanf.scanf "%d %d" (fun n k ->
	let m = ref 0 in
	let i = ref 3 in
	let last = ref 2 in
	let _ = while (!i) <= n/2+1 do
		if is_prime(!i) then begin
			if !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)
			then (incr m);
			last := (!i)
		end;
		i := (!i) + 2;
	done in
	if (!m) < k then "NO" else "YES"
));;


For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight line from point si to point fi (si < fi).Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius r. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius r. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle.At the beginning each participant can choose any point bi, such that his bike is fully behind the starting line, that is, bi < si - r. After that, he starts the movement, instantly accelerates to his maximum speed and at time tsi, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time tfi), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time tfi - tsi.  Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed v, but also on his choice of the initial point bi. Now Maxim is asking you to calculate for each of n competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to r.

The first line contains three integers n, r and v (1 ≤ n ≤ 100 000, 1 ≤ r, v ≤ 109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively.  Next n lines contain the descriptions of the contests. The i-th line contains two integers si and fi (1 ≤ si < fi ≤ 109) — the coordinate of the start and the coordinate of the finish on the i-th competition.

Print n real numbers, the i-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10 - 6.  Namely: let's assume that your answer equals a, and the answer of the jury is b. The checker program will consider your answer correct if .

open Printf
open Scanf

let pi = 2.0 *. (acos 0.0)
let sq x = x *. x

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let r = float (read_int ()) in
  let v = float (read_int ()) in

  let solve s f =
    let period = 2.0 *. pi *. r in
    let dist = f -. s in
    let ncycles = floor (dist /. period) in
    let dist = dist -. ncycles *. period in

    let dist_of alpha =
      (* increasing function of alpha *)
      let q = r *. (sin alpha) in
      let rolling_dist = 2.0 *. alpha *. r in
      rolling_dist +. 2.0 *. q
    in

    let rec bsearch lo hi =
      let a = (lo +. hi) /. 2.0 in
      if (hi -. lo) < 1e-15 then a else
	if dist_of a < dist then bsearch a hi else bsearch lo a
    in

    let alpha = bsearch 0.0 pi in
    let total_angular_dist = ncycles *. 2.0 *. pi +. 2.0 *. alpha in
    let angular_velocity = v /. r in
    total_angular_dist /. angular_velocity
  in

  for i=0 to n-1 do
    let s = float (read_int ()) in
    let f = float (read_int ()) in
    printf "%.12f\n" (solve s f)
  done

open Printf
open Scanf

let pi = 2.0 *. (acos 0.0)
let sq x = x *. x

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let r = float (read_int ()) in
  let v = float (read_int ()) in

  let solve s f =
    let period = 2.0 *. pi *. r in
    let dist = f -. s in
    let ncycles = floor (dist /. period) in
    let dist = dist -. ncycles *. period in

    let dist_of_h h =
      (* decreasing function of h *)
      let q = sqrt ((sq r) -. (sq (h -.r))) in
      let alpha = acos ((h -. r) /. r) in
      let rolling_dist = 2.0 *. alpha *. r in
      (rolling_dist +. 2.0 *. q, alpha)
    in

    let end_test lo hi =
      if hi >= 1.0 then (hi -. lo) /. hi < 1e-12 else hi -. lo < 1e-12
    in

    let rec bsearch lo hi =
      let h = (lo +. hi) /. 2.0 in
      if end_test lo hi then h else
	if fst (dist_of_h h) < dist then bsearch lo h else bsearch h hi
    in

    let h = bsearch 0.0 (r +. r) in
    let alpha = snd (dist_of_h h) in
    let total_angular_dist = ncycles *. 2.0 *. pi +. 2.0 *. alpha in
    let angular_velocity = v /. r in
    total_angular_dist /. angular_velocity
  in

  for i=0 to n-1 do
    let s = float (read_int ()) in
    let f = float (read_int ()) in
    printf "%.12f\n" (solve s f)
  done


Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x1, x2, x3 and three more integers y1, y2, y3, such that x1 < x2 < x3, y1 < y2 < y3 and the eight point set consists of all points (xi, yj) (1 ≤ i, j ≤ 3), except for point (x2, y2).You have a set of eight points. Find out if Gerald can use this set?

The input consists of eight lines, the i-th line contains two space-separated integers xi and yi (0 ≤ xi, yi ≤ 106). You do not have any other conditions for these points.

In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.

(* Codeforces contest 327A - perevorachivania Wrong - have to turn at      *)
(* least one                                                               *)

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 rec readlist n acc = match n with | 0 -> List.rev acc | _ -> readlist (n -1) (gr() :: acc);;
let rec readpairs n acc = match n with
	| 0 -> List.rev acc
	| _ -> readpairs
				(n -1)
				(
					let a = gr() in
					let b = gr() in
					(* let _ = Printf.printf "a,b = %d %d\n" a b in *)
					(a, b) :: acc
				);;
let debug = false;;

let m8 = Array.make_matrix 3 3 0;;

let rec unique last sls = match sls with (* find unique elements in sorted list *)
	| [] -> []
	| h :: t -> if (h == last) then unique last t
			else h :: (unique h t);;

let rec get_su l =
	let sortl = List.sort compare l in
	let uni = unique (-1) sortl in
	uni;;

let get_idx x a =
	if x == a.(0) then 0
	else if x == a.(1) then 1
	else if x == a.(2) then 2
	else -999;;

let rec setm8 aa bb pl = match pl with
	| [] -> ()
	| (a, b) :: t -> (
				let ia = get_idx a aa in
				let ib = get_idx b bb in
				if 0<=ia && ia<=2 && 0<=ib && ib<=2
				then m8.(ia).(ib) <- (m8.(ia).(ib) + 1);
				setm8 aa bb t
			);;

let checkm8 () =
	(
		let rok = ref true in
		(
			for i = 0 to 2 do
				for j = 0 to 2 do
					if (i =1) && (j =1) then
						rok := !rok && (m8.(i).(j) = 0)
					else
						rok := !rok && (m8.(i).(j) = 1)
				done
			done
		);
		!rok
	);;

let main() =
	let prs = readpairs 8 [] in
	let al = get_su (List.map (fun (a, b) -> a) prs) in
	let bl = get_su (List.map (fun (a, b) -> b) prs) in
	let aa = Array.of_list al in
	let bb = Array.of_list bl in
	let _ = setm8 aa bb prs in
	(
		if checkm8() then	print_string "respectable"
		else print_string "ugly";
		print_newline ()
	);;

main();;


Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."  The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Print the index of n among all lucky numbers.

let nombre = ref (read_int ()) and nb_avant = ref 0 and puissance = ref 1;;
while !nombre > 0 do
	if !nombre mod 10 = 7 then nb_avant := !nb_avant + !puissance;
	puissance := !puissance * 2;
	nombre := !nombre / 10
done;;
print_int (!nb_avant + !puissance - 1);;
print_newline ();;

let rec puiss = function
	|0	-> 1
	|n	-> let demi = puiss (n/2) in
			(1 + n mod 2) * demi * demi

let f = function '4' -> 1 | '7' -> 2

let rec place mot long n =
	if n = long
		then 0
		else (f (mot.[n]))*(puiss (long-n-1)) + place mot long (n+1)

let final n =
	let mot = string_of_int n in
	place mot (String.length mot) 0

let () =
	let n = Scanf.scanf "%d" (fun i -> i) in
		Printf.printf "%d" (final n)


Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Write one line — the corresponding answer. Do not omit the leading 0s.

let solve () =
    let a = Pervasives.read_line () in
    let b = Pervasives.read_line () in
    let l = String.length a in
    let rec loop i result =
        if i < l
        then
            if a.[i] = b.[i]
            then
                loop (i + 1) (0 :: result)
            else
                loop (i + 1) (1 :: result)
        else
            List.rev result
    in loop 0 []

let () = List.iter(Printf.printf "%d") (solve ())

(fun x y -> for i = 0 to  String.length x  - 1 do ( print_string(if String.get x i == String.get y i then "0" else "1") ) done )  (read_line())  (read_line())

let a = read_line () in
String.iter (fun c ->
	print_char (if c <> (input_char stdin) then '1' else '0')
) a;;


The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.

The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).

Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.

NoteLet's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins.

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let wmax = read_int() in
  let bmax = read_int() in

  let p = Array.make_matrix (wmax+1) (bmax+1) 0.0 in
  let d = Array.make_matrix (wmax+1) (bmax+1) 0.0 in

  let compute_p w b =
(*    Printf.printf "in compute_p %d %d\n" w b; *)
    if w=0 then 0.0 else
    let fw = float w in
    let fb = float b in
    let den = fw +. fb in
      fw /. den +. (if b=0 then 0.0 else (fb /. den) *. (1.0 -. d.(w).(b-1)))
  in

  let compute_d w b =
(*    Printf.printf "in compute_d %d %d\n" w b; *)
    if w=0 then 1.0 else
    let fw = float w in
    let fb = float b in
    let den = fw +. fb in
      fw /. den +. (if b=0 then 0.0 else (fb /. den) *. (
		      (1.0 -. p.(w-1).(b-1)) *. (fw /. (den -. 1.0)) +.
			(if b=1 then 0.0 else (1.0 -. p.(w).(b-2)) *. ((fb -. 1.0) /. (den -. 1.0)))))

  in

    for sum = 0 to wmax+bmax do
      for w = max 0 (sum-bmax) to min sum wmax do
	let b = sum - w in
	  p.(w).(b) <- compute_p w b;
	  d.(w).(b) <- compute_d w b
      done
    done;
    Printf.printf "%12.9f\n" p.(wmax).(bmax)


You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:   the i-th letter occurs in the string no more than ai times;  the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet. The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

Print a single integer — the maximum length of the string that meets all the requirements.

NoteFor convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".

open Printf
open Scanf

let ( ++ ) a b = Int64.add a b
let long x = Int64.of_int x
let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))
let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)

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

  Array.sort (fun p q -> compare q p) a;

  let b = Array.copy a in

  for i=1 to n-1 do
    b.(i) <- max 0 (min (b.(i-1) - 1) a.(i))
  done;

  let answer = sum 0 (n-1) (fun i -> long b.(i)) 0L in

  printf "%Ld\n" answer


n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

NoteIn the first sample all the participants get into one team, so there will be exactly ten pairs of friends.In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

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

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

let choose_2 x =
    (x * (x - one)) / two

let solve (n, m) =
    let min = choose_2 (n / m + one) * (n %% m) +
        choose_2 (n / m) * (m - (n %% m)) in
    let max = choose_2 (n - (m - one)) in
    (min, max)

let print (a, b) = Printf.printf "%Ld %Ld\n" a b

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

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

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

let factorial n =
    let rec loop x =
        if x <= one
        then
            one
        else
            x * loop (x - one)
    in loop n

let count_pairs flag n m =
    let (y, z) =
        match flag with
        | `minimum -> (two, m - one)
        | `maximum -> (one, zero)
    in
    let x = n - y * (m - one) in
    (x, z)

let count_friends (x, z) =
    x * (x - one) + z

let solve (n, m) =
    let min = count_friends (count_pairs `minimum n m) in
    let max = count_friends (count_pairs `maximum n m) in
    (min, max)

let print (a, b) = Printf.printf "%Ld %Ld\n" a b

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

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

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

let factorial n =
    let rec loop x =
        if x <= one
        then
            one
        else
            x * loop (x - one)
    in loop n

let count_pairs flag n m =
    let (y, z) =
        match flag with
        | `minimum -> (two, m - one)
        | `maximum -> (one, zero)
    in
    let x = n - y * (m - one) in
    (x, z)

let count_friends (x, z) =
    ((x * (x - one)) / two) + z

let solve (n, m) =
    let min = count_friends (count_pairs `minimum n m) in
    let max = count_friends (count_pairs `maximum n m) in
    (min, max)

let print (a, b) = Printf.printf "%Ld %Ld\n" a b

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

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

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

let factorial x =
    (x * (x - one)) / two

let count_pairs flag n m =
    let z =
        match flag with
        | `minimum -> n / m
        | `maximum -> one
    in
    let y = m - one in
    let x = n - z * y in
    (x, y, z)

let count_friends (x, y, z) =
    factorial x + (factorial z) * y

let solve (n, m) =
    let min = count_friends (count_pairs `minimum n m) in
    let max = count_friends (count_pairs `maximum n m) in
    (min, max)

let print (a, b) = Printf.printf "%Ld %Ld\n" a b

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


On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:  the maximum number of questions a particular pupil is asked,  the minimum number of questions a particular pupil is asked,  how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Print three integers:   the maximum number of questions a particular pupil is asked,  the minimum number of questions a particular pupil is asked,  how many times the teacher asked Sergei.

NoteThe order of asking pupils in the first test:   the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table;  the pupil from the first row who seats at the third table;  the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table;  the pupil from the first row who seats at the third table;  the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table; The order of asking pupils in the second test:   the pupil from the first row who seats at the first table;  the pupil from the first row who seats at the second table;  the pupil from the second row who seats at the first table;  the pupil from the second row who seats at the second table;  the pupil from the third row who seats at the first table;  the pupil from the third row who seats at the second table;  the pupil from the fourth row who seats at the first table;  the pupil from the fourth row who seats at the second table, it means it is Sergei;  the pupil from the third row who seats at the first table;

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let m = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let x = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
  let y = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
    if n = 1L then (
      let p = (k /| m) in
      let rmax =
	if Int64.rem k m = 0L
	then p
	else p +| 1L
      in
      let rmin = p in
      let rser =
	if Int64.of_int y >= Int64.rem k m
	then p
	else p +| 1L
      in
	Printf.printf "%Ld %Ld %Ld\n" rmax rmin rser
    ) else (
      let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in
      let t = (2L *| n -| 2L) *| m in
      let p = k /| t in
      let n = Int64.to_int n in
      let m = Int64.to_int m in
	for i = 0 to n - 1 do
	  for j = 0 to m - 1 do
	    if i = 0 || i = n - 1
	    then a.(i).(j) <- p
	    else a.(i).(j) <- 2L *| p
	  done;
	done;
	for i = 0 to Int64.to_int (Int64.rem k t) - 1 do
	  let y' = i mod m in
	  let x' = i / m in
	  let x' =
	    if x' >= n
	    then 2 * n - 2 - x'
	    else x'
	  in
	    a.(x').(y') <- a.(x').(y') +| 1L
	done;
	(*for i = 0 to n - 1 do
	  for j = 0 to m - 1 do
	    Printf.printf " %Ld" a.(i).(j)
	  done;
	  Printf.printf "\n"
	done;*)
	let rmax = ref a.(0).(0) in
	let rmin = ref a.(0).(0) in
	let rser = ref a.(x).(y) in
	  for i = 0 to n - 1 do
	    for j = 0 to m - 1 do
	      rmax := max !rmax a.(i).(j);
	      rmin := min !rmin a.(i).(j);
	    done;
	  done;
	  Printf.printf "%Ld %Ld %Ld\n" !rmax !rmin !rser
    )

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let m = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let x = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
  let y = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
    if n = 1L then (
      let p = (k /| m) in
      let rmax =
	if Int64.rem k m = 0L
	then p
	else p +| 1L
      in
      let rmin = p in
      let rser =
	if Int64.of_int y >= Int64.rem k m
	then p
	else p +| 1L
      in
	Printf.printf "%Ld %Ld %Ld\n" rmax rmin rser
    ) else (
      let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in
      let t = (2L *| n -| 2L) *| m in
      let p = k /| t in
      let n = Int64.to_int n in
      let m = Int64.to_int m in
	for i = 0 to n - 1 do
	  for j = 0 to m - 1 do
	    if i = 0 || i = n - 1
	    then a.(i).(j) <- p
	    else a.(i).(j) <- 2L *| p
	  done;
	done;
	for i = 0 to Int64.to_int (Int64.rem k t) - 1 do
	  let y' = i mod m in
	  let x' = i / m in
	  let x' =
	    if x' >= n
	    then n - x'
	    else x'
	  in
	    a.(x').(y') <- a.(x').(y') +| 1L
	done;
	let rmax = ref a.(0).(0) in
	let rmin = ref a.(0).(0) in
	let rser = ref a.(x).(y) in
	  for i = 0 to n - 1 do
	    for j = 0 to m - 1 do
	      rmax := max !rmax a.(i).(j);
	      rmin := min !rmin a.(i).(j);
	    done;
	  done;
	  Printf.printf "%Ld %Ld %Ld\n" !rmax !rmin !rser
    )

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

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let m = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let k = Scanf.bscanf sb "%Ld " (fun s -> s) in
  let x = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
  let y = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
    if n = 1L then (
      let p = (k /| m) in
      let rmax =
	if Int64.rem k m = 0L
	then p
	else p +| 1L
      in
      let rmin = p in
      let rser =
	if Int64.of_int x >= Int64.rem k m
	then p
	else p +| 1L
      in
	Printf.printf "%Ld %Ld %Ld\n" rmax rmin rser
    ) else (
      let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in
      let t = (2L *| n -| 2L) *| m in
      let p = k /| t in
      let n = Int64.to_int n in
      let m = Int64.to_int m in
	for i = 0 to n - 1 do
	  for j = 0 to m - 1 do
	    if i = 0 || i = n - 1
	    then a.(i).(j) <- p
	    else a.(i).(j) <- 2L *| p
	  done;
	done;
	for i = 0 to Int64.to_int (Int64.rem k t) - 1 do
	  let y' = i mod m in
	  let x' = i / m in
	  let x' =
	    if x' >= n
	    then n - x'
	    else x'
	  in
	    a.(x').(y') <- a.(x').(y') +| 1L
	done;
	let rmax = ref a.(0).(0) in
	let rmin = ref a.(0).(0) in
	let rser = ref a.(x).(y) in
	  for i = 0 to n - 1 do
	    for j = 0 to m - 1 do
	      rmax := max !rmax a.(i).(j);
	      rmin := min !rmin a.(i).(j);
	    done;
	  done;
	  Printf.printf "%Ld %Ld %Ld\n" !rmax !rmin !rser
    )