open Batteries
open Printf

let ($) g f x = g (f x)

let swap = Tuple2.swap

let s2i = int_of_string
let i2s = string_of_int
let s2f = float_of_string
let f2s = string_of_float
let c2i = int_of_char
let i2c = char_of_int
let f2i = float_of_int
let i2f = int_of_float

let c2s = String.of_char
let s2cl = String.to_list
let cl2s = String.of_list

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ i2s i

let rep lb bnd ub f = match bnd with
  | `To -> for i = lb to ub do f i done
  | `Til -> for i = lb to (ub - 1) do f i done

let rep2 lb1 bnd1 ub1 () lb2 bnd2 ub2 f =
  match (bnd1, bnd2) with
  | (`To, `To) -> for i = lb1 to ub1 do for j = lb2 to ub2 do f i j done done
  | (`To, `Til) -> for i = lb1 to ub1 do for j = lb2 to (ub2 - 1) do f i j done done
  | (`Til, `To) -> for i = lb1 to (ub1 - 1) do for j = lb2 to ub2 do f i j done done
  | (`Til, `Til) -> for i = lb1 to (ub1 - 1) do for j = lb2 to (ub2 - 1) do f i j done done

module ToyList = struct
  include List

  let nmem x l = not @@ mem x l

  let len = length
  let size = length
  let nempty l = not @@ is_empty l

  (* let taker = drop *)
  let takewh = take_while

  (* let dropr = take *)
  let dropwh = drop_while

  let split_by = span

  let chunk = ntake

  let foldl = fold_left
  let foldli = fold_lefti
  let foldr f z l = fold_right f l z
  let foldri f z l = fold_righti f l z

  let partition_to_map f l =
    foldr (fun x m -> Map.modify_opt (f x) (function
      | None -> Some [x]
      | Some [] -> Some [x]
      | Some vl -> Some (x::vl)) m) Map.empty l;;

  (* let scanl = scan_left *)
  (* let scanli = scan_lefti *)
  (* let scanr = scan_right *)
  (* let scanri = scan_righti *)

  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = ToyList

module ToyArray = struct
  include Array

  let nmem x l = not @@ mem x l

  let len = length
  let size = length
  let is_empty r = len r = 0
  let nempty r = len r > 0

  let take n r = left r n
  let taker n r = right r n
  (* let takewh = take_while *)

  let drop n r = tail r n
  let dropr n r = take ((len r) - n) r
  (* let dropwh = drop_while *)

  (* let split_by = span *)

  (* let chunk = ntake *)

  let foldl = fold_left
  let foldli = fold_lefti
  let foldr f z l = fold_right f l z
  let foldri f z l = fold_righti f l z

  (* let partition_to_map f l = *)
  (*   foldr (fun x m -> Map.modify_opt (f x) (function *)
  (*     | None -> Some [x]  *)
  (*     | Some [] -> Some [x]  *)
  (*     | Some vl -> Some (x::vl)) m) Map.empty l;; *)

  (* let scanl = scan_left *)
  (* let scanli = scan_lefti *)
  (* let scanr = scan_right *)
  (* let scanri = scan_righti *)

  let concat2 = append

  let flatmap (f : 'a -> 'b array) a =
    map f a |> enum |> L.of_enum |> concat

  let zipf = map2
  (* let zipfi = map2i *)
end

module A = ToyArray

module ToyString = struct
  include String

  let len = length

  let replace_chars = map
  let map = replace

  let maptol f s = L.map f (s2cl s)
  let maptoli f s = L.map f (s2cl s)

  let zipf f a b = L.zipf f (s2cl a) (s2cl b)
  let zipfi f a b = L.zipfi f (s2cl a) (s2cl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)

end

module S = ToyString

let spsp s = S.split_on_char ' ' s

module ToySortedSet = struct
  include Set

  module Make (Ord : Set.OrderedType) = struct
    include Set.Make(Ord)

    let nmem x st = not @@ mem x st

    let foldl f s z = fold (fun x a -> f a x) z s

    let size = cardinal
  end

  let nmem x st = not @@ mem x st

  let foldl f s z = fold (fun x a -> f a x) z s

  let size = cardinal
end

module Ss = ToySortedSet

module ToySortedMap  = struct
  include Map

  module Make (Ord : Map.OrderedType) = struct
    include Map.Make(Ord)

    let nmem x st = not @@ mem x st

    let get = find
    let get_or x d m = find_default d x m

    let size = cardinal
  end

  let nmem x st = not @@ mem x st

  let get = find
  let get_or x d m = find_default d x m

  let size = cardinal
end

module Ms = ToySortedMap

let set_power ls =
  let rec loop ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> loop tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in loop ls [[]]

exception ArithmeticException of string

module ToyIntArithmetic = struct

  let rec to_bits_le n =
    if n = 0 then []
    else (n mod 2) :: to_bits_le (n lsr 1)

  let rec gcd x y =
    match x mod y with
    | 0 -> y
    | z -> gcd y z

  let ext_euclid a b =
    let rec next (r0, s0, t0) (r1, s1, t1) =
      match r1 with
      | 0 -> (r0, s0, t0)
      | r2 ->
        let q = r0 / r1 in
        next (r1, s1, t1) (r0 - q * r1, s0 - q * s1, t0 - q * t1)
    in
    if a < b then
      let (g, y, x) = next (b, 1, 0) (a, 0, 1) in (g, x, y)
    else
      next (a, 1, 0) (b, 0, 1)

  let modinv x m =
    let (g, y, z) = ext_euclid x m in
    match g with
    | 1 -> y mod m
    | _ -> raise @@ ArithmeticException "Not relatively prime"

end

module N = ToyIntArithmetic

module ToyMatrix = struct

  type 'a t = { w : int; h : int; e : 'a array array }

  let make w h e0 =
    { w = w; h = h; e = A.make_matrix w h e0 }

  let from_columns w h e0 elems =
    let matr = make w h e0 in
    elems |> L.iteri (fun j col ->
      col |> L.iteri (fun i x -> matr.e.(i).(j) <- x));
    matr

  let blit (mats, rs, cs, w, h) (matd, rd, cd) =
    rep2 0 `Til w () 0 `Til h (fun i j ->
        matd.e.(rd + i).(cd + j) <- mats.e.(rs + i).(cs + j))

  let expand (w1, h1) (w2, h2) e0 mat =
    let matr = make w2 h2 e0 in
    blit (mat, 0, 0, w1, h1) (matr, 0, 0);
    matr

end

module M = ToyMatrix

module type FieldOps = sig
  type elt
  val zero : elt
  val one : elt
  val neg : elt -> elt
  val rcp : elt -> elt
  val add : elt -> elt -> elt
  val sub : elt -> elt -> elt
  val mul : elt -> elt -> elt
  val div : elt -> elt -> elt
end

module ToyLinearAlgebra (Fop : FieldOps) = struct

  type t = Fop.elt M.t

  let zero w h = M.make w h Fop.zero

  let prod (mat1 : t) (mat2 : t) =
    let matr = zero mat1.w mat2.h in
    rep2 0 `Til mat1.w () 0 `Til mat2.h (fun i j ->
        matr.e.(i).(j) <-
          mat1.e.(i) |> A.foldli (fun
            acc k x -> Fop.add acc (Fop.mul x mat2.e.(k).(i)))
            Fop.zero);
    matr

  exception NotZero of int
  let is_zero (mat : t) =
    try (
      rep 0 `Til mat.w (fun i ->
        if mat.e.(i) |> A.for_all (fun x -> x <> Fop.zero)
          then raise (NotZero 1)
      );
      true
    ) with _ -> false

  let col_addmul c1 (c2, a) (mat : t) =
    rep 0 `Til mat.h (fun i ->
      mat.e.(i).(c1) <- Fop.add mat.e.(i).(c1) (Fop.mul a mat.e.(i).(c2)))

  let col_inner_prod c1 c2 (mat : t) =
    let sum = ref Fop.zero in
    rep 0 `Til mat.h (fun i ->
      sum := Fop.add !sum @@ Fop.mul mat.e.(i).(c1) mat.e.(i).(c2));
    !sum

  (* let orth_extend k0 k1 mat = *)
  (*   let matx = extend (k0, h) ((k0 + k1), h) 0 mat in *)
  (*   rep k0 `Til (k0 + k1) (fun t -> *)
  (*     rep 0 `Til t (fun s ->  *)
  (*       let ip = col_inner_prod s t h matx in *)
  (*       col_addmul t (s, ip) h matx)); *)
  (*   submat (k0, 0) (k0 + k1 - 1, h - 1) matx *)

end

module type OrderedData = sig
  type t
  val compare : t -> t -> int
  val default : t
end

module ToyGraph = struct

  type 'a v_t = int * 'a
  type 'a t = { vs : 'a v_t array; nb : int Ss.t array }

  let empty nv vd =
    let vs0 = Array.make nv (0, vd) in
    for i = 0 to (nv - 1) do vs0.(i) <- (i, vd) done;
    {
      vs = vs0;
      nb = A.make nv Ss.empty
    }

  let add_edge (e : int * int) vd g =
    let (v1, v2) = e in
    g.vs.(v1 - 1) <- (v1, vd);
    g.vs.(v2 - 1) <- (v2, vd);
    g.nb.(v1 - 1) <- g.nb.(v1 - 1) |> Ss.add v2;
    g

  let add_uedge e vd g =
    add_edge e vd (add_edge (swap e) vd g)

  let from_edges nv vd es =
    es |> L.foldl (fun g e -> add_edge e vd g) (empty nv vd)

  let from_uedges nv vd es =
    es |> L.foldl (fun g e -> add_uedge e vd g) (empty nv vd)

end

module G = ToyGraph

module ToyGraphAlgorithms (Vdt : OrderedData) = struct

  type t = Vdt.t G.t

  module V = struct
    type t = int * Vdt.t
    let compare (vi1, vd1) (vi2, vd2) =
      let c1 = Vdt.compare vd1 vd2 in
      if c1 = 0 then compare vi1 vi2
      else c1

    let default i = (i, Vdt.default)
    let index (v : t) = fst v
  end

  module Vset = Ss.Make(V)

  let print_vertices label vs =
    printf "%s: " label;
    vs |> Vset.iter (fun (vi, _) -> printf "%d " vi);
    puts ""

  let nbiter (upd : V.t -> V.t -> t -> t * bool)
    (ui : int) (fr : Vset.t) (cls : int Ss.t) (g : t) =
    let nb = g.nb.(ui - 1) in
    let result = nb |> Ss.foldl (fun (ga, nxfr, nxcls) vi ->
    (* puts "nxcls: "; *)
      (* Ss.iter (fun x -> printf "%d " x) nxcls; puts ""; *)
      if ui = vi || Ss.mem vi nxcls then
        (ga, nxfr, nxcls)
      else
        let ue = g.vs.(ui - 1) and ve = g.vs.(vi - 1) in
        let (gu, close) = upd ue ve ga in
        (gu,
          nxfr |> Vset.add ve,
          if close then nxcls |> Ss.add vi else nxcls)
    ) (g, fr, cls)
    in (* puts "";  *)result

  let traverse (upd : V.t -> V.t -> t -> t * bool)
    (fr0 : Vset.t) (cls0 : int Ss.t) (g : t) =

    let rec progress fr cls g' =
      let (ve, fr') = Vset.pop_min fr in
      let (vi, _) = ve in
      let (gu, nxfr, nxcls) = nbiter upd vi fr' cls g' in
      if Vset.is_empty nxfr then (gu, nxcls)
      else progress nxfr nxcls gu
    in
    progress fr0 cls0 g

  let frontier (upd : V.t -> V.t -> t -> t * bool)
    (fr0 : Vset.t) (cls0 : int Ss.t) (g : t) =

    let rec progress fr cls g' =
      let (gu, nxfr, nxcls) =
        fr |> Vset.foldl (fun (ga, nxfra, nxclsa) ve ->
          let (vi, _) = ve in
          nbiter upd vi nxfra nxclsa ga
        ) (g', Vset.empty, cls)
      in
      if Vset.is_empty nxfr then (gu, nxcls)
      else progress nxfr nxcls gu
    in
    progress fr0 cls0 g

  let bfs (upd : V.t -> V.t -> t -> t) =
    frontier (fun fr cls g' -> (upd fr cls g', true))

end

let rds () = read_line ()

let rdi () = s2i @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map s2i

let rdhf () = rdhs () |> L.map s2f

let rdf2 () = match rdhf () with
| a::b::_ -> (a, b)
| _ -> (0., 0.)

let rdf3 () = match rdhf () with
| a::b::c::_ -> (a, b, c)
| _ -> (0., 0., 0.)

let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)

let rds2 () = match rdhs () with
  | a::b::_ -> (a, b)
  | _ -> ("", "")

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rf =
  let rec loop n =
    if n <= 0 then []
    else (
      let s = rf () in
      s::(loop (n - 1))
    )
  in loop n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

module Galg = ToyGraphAlgorithms (
  struct
    type t = int
    let compare = compare
    let default = 0
  end)

module Aas = Ss.Make (struct
  type t = int * int
  let compare (x, _) (y, _) = compare x y
end)

let _ =
  let n = rdi () in
  let aa = L.mapi (fun i x -> (x, i)) @@ rdhi () in
  let aasl = L.sort (fun (x, _) (y, _) -> compare x y) aa in

  let rec part_consec z ces acc = function
  | [] -> (ces, acc)
  | h::t ->
    let (a, _) = h in
    if a = z then part_consec z (Aas.add h ces) acc t else part_consec a ces (h::acc) t
  in

  let (m, _) as mp = L.hd aasl in
  let (rs, aasl1) = part_consec m Aas.empty [mp] (L.tl aasl) in

  let rec redset acc aas1 =
    (* printf "[ "; aas1 |> Aas.iter (fun (a, _) -> printf "%d " a); puts "]"; *)
    let sz = Aas.size aas1 in
    if sz = 0 then []
    else (
      let (m, _) as mp = fst @@ Aas.pop_min aas1 in
      (* puti m; *)
      let aas2 = aas1 |> Aas.filter (fun (a, _) -> a mod m <> 0) in
      if Aas.size aas2 = sz - 1 then
        mp :: (L.concat [acc; (Aas.to_list aas2)])
      else redset (mp::acc) aas2
    )
  in

  let aas0 = Aas.of_list aasl1 in
  let rsrl = redset [] rs in
  let rec aas =
    rsrl |> L.foldl (fun s (m, _) -> s
         |> Aas.filter (fun (a, _) -> a mod m <> 0)) aas0 in
  (* puti @@ Aas.size aas; *)

  let result = redset [] aas in
    (* printf "[ "; result |> L.iter (fun (a, _) -> printf "%d " a); puts "]"; *)
  puti @@ L.len result
;;


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

module IntSet = Set.Int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let m = List.last ls in
  let arr = Array.make (succ m) true in
  ListL.iter (List.of_enum @@ Hashtbl.keys hcount) ~f:(fun v ->
      let rec aux i =
        if i*v > m then ()
        else (arr.(i*v) <- false; aux @@ succ i)
      in
      aux 2);
  ListL.map (Hashtbl.to_list hcount) ~f:(fun (v,n) ->
      if n >= 2 then 0
      else if arr.(v) then 1 else 0
    ) |> List.sum
  |> Printf.printf "%d\n"

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


open Batteries
open Printf

let ($) g f x = g (f x)

let swap = Tuple2.swap

let s2i = int_of_string
let i2s = string_of_int
let s2f = float_of_string
let f2s = string_of_float
let c2i = int_of_char
let i2c = char_of_int
let f2i = float_of_int
let i2f = int_of_float

let c2s = String.of_char
let s2cl = String.to_list
let cl2s = String.of_list

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ i2s i

let rep lb bnd ub f = match bnd with
  | `To -> for i = lb to ub do f i done
  | `Til -> for i = lb to (ub - 1) do f i done

let rep2 lb1 bnd1 ub1 () lb2 bnd2 ub2 f =
  match (bnd1, bnd2) with
  | (`To, `To) -> for i = lb1 to ub1 do for j = lb2 to ub2 do f i j done done
  | (`To, `Til) -> for i = lb1 to ub1 do for j = lb2 to (ub2 - 1) do f i j done done
  | (`Til, `To) -> for i = lb1 to (ub1 - 1) do for j = lb2 to ub2 do f i j done done
  | (`Til, `Til) -> for i = lb1 to (ub1 - 1) do for j = lb2 to (ub2 - 1) do f i j done done

module ToyList = struct
  include List

  let nmem x l = not @@ mem x l

  let len = length
  let size = length
  let nempty l = not @@ is_empty l

  (* let taker = drop *)
  let takewh = take_while

  (* let dropr = take *)
  let dropwh = drop_while

  let split_by = span

  let chunk = ntake

  let foldl = fold_left
  let foldli = fold_lefti
  let foldr f z l = fold_right f l z
  let foldri f z l = fold_righti f l z

  let partition_to_map f l =
    foldr (fun x m -> Map.modify_opt (f x) (function
      | None -> Some [x]
      | Some [] -> Some [x]
      | Some vl -> Some (x::vl)) m) Map.empty l;;

  (* let scanl = scan_left *)
  (* let scanli = scan_lefti *)
  (* let scanr = scan_right *)
  (* let scanri = scan_righti *)

  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = ToyList

module ToyArray = struct
  include Array

  let nmem x l = not @@ mem x l

  let len = length
  let size = length
  let is_empty r = len r = 0
  let nempty r = len r > 0

  let take n r = left r n
  let taker n r = right r n
  (* let takewh = take_while *)

  let drop n r = tail r n
  let dropr n r = take ((len r) - n) r
  (* let dropwh = drop_while *)

  (* let split_by = span *)

  (* let chunk = ntake *)

  let foldl = fold_left
  let foldli = fold_lefti
  let foldr f z l = fold_right f l z
  let foldri f z l = fold_righti f l z

  (* let partition_to_map f l = *)
  (*   foldr (fun x m -> Map.modify_opt (f x) (function *)
  (*     | None -> Some [x]  *)
  (*     | Some [] -> Some [x]  *)
  (*     | Some vl -> Some (x::vl)) m) Map.empty l;; *)

  (* let scanl = scan_left *)
  (* let scanli = scan_lefti *)
  (* let scanr = scan_right *)
  (* let scanri = scan_righti *)

  let concat2 = append

  let flatmap (f : 'a -> 'b array) a =
    map f a |> enum |> L.of_enum |> concat

  let zipf = map2
  (* let zipfi = map2i *)
end

module A = ToyArray

module ToyString = struct
  include String

  let len = length

  let replace_chars = map
  let map = replace

  let maptol f s = L.map f (s2cl s)
  let maptoli f s = L.map f (s2cl s)

  let zipf f a b = L.zipf f (s2cl a) (s2cl b)
  let zipfi f a b = L.zipfi f (s2cl a) (s2cl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)

end

module S = ToyString

let spsp s = S.split_on_char ' ' s

module ToySortedSet = struct
  include Set

  module Make (Ord : Set.OrderedType) = struct
    include Set.Make(Ord)

    let nmem x st = not @@ mem x st

    let foldl f s z = fold (fun x a -> f a x) z s

    let size = cardinal
  end

  let nmem x st = not @@ mem x st

  let foldl f s z = fold (fun x a -> f a x) z s

  let size = cardinal
end

module Ss = ToySortedSet

module ToySortedMap  = struct
  include Map

  module Make (Ord : Map.OrderedType) = struct
    include Map.Make(Ord)

    let nmem x st = not @@ mem x st

    let get = find
    let get_or x d m = find_default d x m

    let size = cardinal
  end

  let nmem x st = not @@ mem x st

  let get = find
  let get_or x d m = find_default d x m

  let size = cardinal
end

module Ms = ToySortedMap

let set_power ls =
  let rec loop ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> loop tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in loop ls [[]]

exception ArithmeticException of string

module ToyIntArithmetic = struct

  let rec to_bits_le n =
    if n = 0 then []
    else (n mod 2) :: to_bits_le (n lsr 1)

  let rec gcd x y =
    match x mod y with
    | 0 -> y
    | z -> gcd y z

  let ext_euclid a b =
    let rec next (r0, s0, t0) (r1, s1, t1) =
      match r1 with
      | 0 -> (r0, s0, t0)
      | r2 ->
        let q = r0 / r1 in
        next (r1, s1, t1) (r0 - q * r1, s0 - q * s1, t0 - q * t1)
    in
    if a < b then
      let (g, y, x) = next (b, 1, 0) (a, 0, 1) in (g, x, y)
    else
      next (a, 1, 0) (b, 0, 1)

  let modinv x m =
    let (g, y, z) = ext_euclid x m in
    match g with
    | 1 -> y mod m
    | _ -> raise @@ ArithmeticException "Not relatively prime"

end

module N = ToyIntArithmetic

module ToyMatrix = struct

  type 'a t = { w : int; h : int; e : 'a array array }

  let make w h e0 =
    { w = w; h = h; e = A.make_matrix w h e0 }

  let from_columns w h e0 elems =
    let matr = make w h e0 in
    elems |> L.iteri (fun j col ->
      col |> L.iteri (fun i x -> matr.e.(i).(j) <- x));
    matr

  let blit (mats, rs, cs, w, h) (matd, rd, cd) =
    rep2 0 `Til w () 0 `Til h (fun i j ->
        matd.e.(rd + i).(cd + j) <- mats.e.(rs + i).(cs + j))

  let expand (w1, h1) (w2, h2) e0 mat =
    let matr = make w2 h2 e0 in
    blit (mat, 0, 0, w1, h1) (matr, 0, 0);
    matr

end

module M = ToyMatrix

module type FieldOps = sig
  type elt
  val zero : elt
  val one : elt
  val neg : elt -> elt
  val rcp : elt -> elt
  val add : elt -> elt -> elt
  val sub : elt -> elt -> elt
  val mul : elt -> elt -> elt
  val div : elt -> elt -> elt
end

module ToyLinearAlgebra (Fop : FieldOps) = struct

  type t = Fop.elt M.t

  let zero w h = M.make w h Fop.zero

  let prod (mat1 : t) (mat2 : t) =
    let matr = zero mat1.w mat2.h in
    rep2 0 `Til mat1.w () 0 `Til mat2.h (fun i j ->
        matr.e.(i).(j) <-
          mat1.e.(i) |> A.foldli (fun
            acc k x -> Fop.add acc (Fop.mul x mat2.e.(k).(i)))
            Fop.zero);
    matr

  exception NotZero of int
  let is_zero (mat : t) =
    try (
      rep 0 `Til mat.w (fun i ->
        if mat.e.(i) |> A.for_all (fun x -> x <> Fop.zero)
          then raise (NotZero 1)
      );
      true
    ) with _ -> false

  let col_addmul c1 (c2, a) (mat : t) =
    rep 0 `Til mat.h (fun i ->
      mat.e.(i).(c1) <- Fop.add mat.e.(i).(c1) (Fop.mul a mat.e.(i).(c2)))

  let col_inner_prod c1 c2 (mat : t) =
    let sum = ref Fop.zero in
    rep 0 `Til mat.h (fun i ->
      sum := Fop.add !sum @@ Fop.mul mat.e.(i).(c1) mat.e.(i).(c2));
    !sum

  (* let orth_extend k0 k1 mat = *)
  (*   let matx = extend (k0, h) ((k0 + k1), h) 0 mat in *)
  (*   rep k0 `Til (k0 + k1) (fun t -> *)
  (*     rep 0 `Til t (fun s ->  *)
  (*       let ip = col_inner_prod s t h matx in *)
  (*       col_addmul t (s, ip) h matx)); *)
  (*   submat (k0, 0) (k0 + k1 - 1, h - 1) matx *)

end

module type OrderedData = sig
  type t
  val compare : t -> t -> int
  val default : t
end

module ToyGraph = struct

  type 'a v_t = int * 'a
  type 'a t = { vs : 'a v_t array; nb : int Ss.t array }

  let empty nv vd =
    let vs0 = Array.make nv (0, vd) in
    for i = 0 to (nv - 1) do vs0.(i) <- (i, vd) done;
    {
      vs = vs0;
      nb = A.make nv Ss.empty
    }

  let add_edge (e : int * int) vd g =
    let (v1, v2) = e in
    g.vs.(v1 - 1) <- (v1, vd);
    g.vs.(v2 - 1) <- (v2, vd);
    g.nb.(v1 - 1) <- g.nb.(v1 - 1) |> Ss.add v2;
    g

  let add_uedge e vd g =
    add_edge e vd (add_edge (swap e) vd g)

  let from_edges nv vd es =
    es |> L.foldl (fun g e -> add_edge e vd g) (empty nv vd)

  let from_uedges nv vd es =
    es |> L.foldl (fun g e -> add_uedge e vd g) (empty nv vd)

end

module G = ToyGraph

module ToyGraphAlgorithms (Vdt : OrderedData) = struct

  type t = Vdt.t G.t

  module V = struct
    type t = int * Vdt.t
    let compare (vi1, vd1) (vi2, vd2) =
      let c1 = Vdt.compare vd1 vd2 in
      if c1 = 0 then compare vi1 vi2
      else c1

    let default i = (i, Vdt.default)
    let index (v : t) = fst v
  end

  module Vset = Ss.Make(V)

  let print_vertices label vs =
    printf "%s: " label;
    vs |> Vset.iter (fun (vi, _) -> printf "%d " vi);
    puts ""

  let nbiter (upd : V.t -> V.t -> t -> t * bool)
    (ui : int) (fr : Vset.t) (cls : int Ss.t) (g : t) =
    let nb = g.nb.(ui - 1) in
    let result = nb |> Ss.foldl (fun (ga, nxfr, nxcls) vi ->
    (* puts "nxcls: "; *)
      (* Ss.iter (fun x -> printf "%d " x) nxcls; puts ""; *)
      if ui = vi || Ss.mem vi nxcls then
        (ga, nxfr, nxcls)
      else
        let ue = g.vs.(ui - 1) and ve = g.vs.(vi - 1) in
        let (gu, close) = upd ue ve ga in
        (gu,
          nxfr |> Vset.add ve,
          if close then nxcls |> Ss.add vi else nxcls)
    ) (g, fr, cls)
    in (* puts "";  *)result

  let traverse (upd : V.t -> V.t -> t -> t * bool)
    (fr0 : Vset.t) (cls0 : int Ss.t) (g : t) =

    let rec progress fr cls g' =
      let (ve, fr') = Vset.pop_min fr in
      let (vi, _) = ve in
      let (gu, nxfr, nxcls) = nbiter upd vi fr' cls g' in
      if Vset.is_empty nxfr then (gu, nxcls)
      else progress nxfr nxcls gu
    in
    progress fr0 cls0 g

  let frontier (upd : V.t -> V.t -> t -> t * bool)
    (fr0 : Vset.t) (cls0 : int Ss.t) (g : t) =

    let rec progress fr cls g' =
      let (gu, nxfr, nxcls) =
        fr |> Vset.foldl (fun (ga, nxfra, nxclsa) ve ->
          let (vi, _) = ve in
          nbiter upd vi nxfra nxclsa ga
        ) (g', Vset.empty, cls)
      in
      if Vset.is_empty nxfr then (gu, nxcls)
      else progress nxfr nxcls gu
    in
    progress fr0 cls0 g

  let bfs (upd : V.t -> V.t -> t -> t) =
    frontier (fun fr cls g' -> (upd fr cls g', true))

end

let rds () = read_line ()

let rdi () = s2i @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map s2i

let rdhf () = rdhs () |> L.map s2f

let rdf2 () = match rdhf () with
| a::b::_ -> (a, b)
| _ -> (0., 0.)

let rdf3 () = match rdhf () with
| a::b::c::_ -> (a, b, c)
| _ -> (0., 0., 0.)

let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)

let rds2 () = match rdhs () with
  | a::b::_ -> (a, b)
  | _ -> ("", "")

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rf =
  let rec loop n =
    if n <= 0 then []
    else (
      let s = rf () in
      s::(loop (n - 1))
    )
  in loop n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

module Galg = ToyGraphAlgorithms (
  struct
    type t = int
    let compare = compare
    let default = 0
  end)

module Aas = Ss.Make (struct
  type t = int * int
  let compare (x, _) (y, _) = compare x y
end)

let _ =
  let n = rdi () in
  let aa = L.mapi (fun i x -> (x, i)) @@ rdhi () in
  let aasl = L.sort (fun (x, _) (y, _) -> compare x y) aa in

  let rec delcsc z acc = function
  | [] -> acc
  | h::t ->
    let (a, _) = h in
    if a = z then delcsc z acc t else delcsc a (h::acc) t
  in

  let (m, _) as mp = L.hd aasl in
  let aas = Aas.of_list @@ delcsc m [mp] aasl in

  let rec redset acc aas1 =
    (* printf "[ "; aas1 |> Aas.iter (fun (a, _) -> printf "%d " a); puts "]"; *)
    let sz = Aas.size aas1 in
    if sz = 0 then []
    else (
      let (m, _) as mp = fst @@ Aas.pop_min aas1 in
      (* puti m; *)
      let aas2 = aas1 |> Aas.filter (fun (a, _) -> a mod m <> 0) in
      if Aas.size aas2 = sz - 1 then
        mp :: (L.concat [acc; (Aas.to_list aas2)])
      else redset (mp::acc) aas2
    )
  in

  let result = redset [] aas in
    (* printf "[ "; result |> L.iter (fun (a, _) -> printf "%d " a); puts "]"; *)
  puti @@ L.len result
;;


let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.make 1000001 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      as_.(a) <- 1 + as_.(a)
  done;
  let dp = Array.make 1000001 1 in
  for a = 0 to 1000000 do
    if as_.(a) <> 1 then dp.(a) <- 0;
    if 0 < as_.(a) then
      let rec mark i =
        if i <= 1000000 then
          (as_.(i) <- 0; mark (i + a)) in
      mark (2 * a)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 dp


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

module IntSet = Set.Int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = IntSet.empty in
  ListL.fold_left ls ~init:(h,0) ~f:(fun (h, pred) v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (IntSet.add v h, pred)
      else
        let rec aux i =
          if i * i > v then (h, 1)
          else if v mod i = 0 && (IntSet.mem i h || IntSet.mem (v/i) h) then (h, 0)
          else aux @@ succ i in
        let (h,w) = aux 1 in (IntSet.add v h, pred + w))
  |> Tuple2.second |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ListL.fold_left ls ~init:0 ~f:(fun pred v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (Hashtbl.modify_def true v id h; pred)
      else
        let rec aux i =
          if i * i > v then 1
          else if v mod i = 0 && (Hashtbl.mem h i || Hashtbl.mem h (v/i)) then 0
          else aux @@ succ i in
        let w = aux 1 in
        Hashtbl.modify_def true v id h; pred + w)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

exception Found of int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ListL.fold_left ls ~init:0 ~f:(fun pred v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (Hashtbl.add h v true; pred)
      else
        let rec aux i =
          if i * i > v then 1
          else if v mod i = 0 &&
                  (Option.is_some @@ Hashtbl.find_option h i
                   || Option.is_some @@ Hashtbl.find_option h (v/i)) then 0
          else aux @@ succ i in
        let w = aux 1 in
        Hashtbl.add h v true; pred + w)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

exception Found of int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ListL.fold_left ls ~init:0 ~f:(fun pred v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (Hashtbl.add h v true; 0)
      else
        let rec aux i =
          if i * i > v then 1
          else if v mod i = 0 &&
                  (Option.is_some @@ Hashtbl.find_option h i
                   || Option.is_some @@ Hashtbl.find_option h (v/i)) then 0
          else aux @@ succ i in
        let w = aux 1 in
        Hashtbl.add h v true; pred + w)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

exception Found of int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ListL.map ls ~f:(fun v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (Hashtbl.add h v true; 0)
      else
        let rec aux i =
          if i * i > v then 1
          else if v mod i = 0 &&
                  (Option.is_some @@ Hashtbl.find_option h i
                   || Option.is_some @@ Hashtbl.find_option h (v/i)) then 0
          else aux @@ succ i in
        let w = aux 1 in
        Hashtbl.add h v true; w)
  |> List.sum
  |> Printf.printf "%d\n"


Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let hist = Array.make 1000001 0 in
    Array.iter (fun v -> hist.(v) <- hist.(v) + 1) a;
    let rec loop_i i acc =
        let rec loop_j v j acc =
            let check c =
                if hist.(c) = 0 then true else
                    if v <> c then false else
                        if hist.(c) = 1 then true else false
            in
            if j * j > v then acc else
                if v mod j <> 0 then loop_j v (j + 1) acc else
                if check j && check (v / j) then loop_j v (j + 1) acc else acc - 1
        in
        if i = n then acc else
            loop_i (i + 1) (loop_j a.(i) 1 acc)
    in
    loop_i 0 n |> Printf.printf "%d\n"
)


let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let vs = Array.make 1_000_001 false

let rec devideable i x =
  if i * i > x then false
  else if x mod i <> 0 then devideable (i + 1) x
  else vs.(i) || vs.(x / i) || devideable (i + 1) x

let rec loop ans = function
  | [] -> Printf.printf "%d\n" ans
  | (x, cnt) :: xs ->
    let d = devideable 1 x in
    vs.(x) <- true;
    if cnt > 1 || d then loop ans xs
    else loop (ans + 1) xs

let () =
  let rec f = function
    | (acc, []) -> acc
    | ((v, cnt) :: accs as acc, x :: xs) ->
      if x = v then f ((v, cnt + 1) :: accs, xs)
      else f ((x, 1) :: acc, xs)
    | _ -> failwith ""
  in
  loop 0 (List.rev (f ([(List.hd a, 1)], List.tl a)))


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls =  scan_array ~sep:' ' Int.of_string

exception Found of bool

let () =
  Array.sort Int.compare ls;
  let hcount = Hashtbl.create n in
  ArrayL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ArrayL.map ls ~f:(fun v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then (Hashtbl.add h v true; false)
      else
        let b = try ListL.iter (1++v) ~f:(fun j ->
            if v mod j = 0 &&
               (Option.is_some @@ Hashtbl.find_option h j
                || Option.is_some @@ Hashtbl.find_option h (v/j)) then raise @@ Found false
            else if j * j > v then raise @@ Found true);
            true with Found b -> b in
        Hashtbl.add h v true; b)
  |> Array.filter ((=) true)
  |> Array.length
  |> Printf.printf "%d\n"


let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let vs = Array.make 1_000_001 false

let rec devideable i x =
  if i * i > x then false
  else if x mod i <> 0 then devideable (i + 1) x
  else vs.(i) || vs.(x / i) || devideable (i + 1) x

let rec loop ans = function
  | [] -> Printf.printf "%d\n" ans
  | x :: xs ->
    let d = devideable 1 x in
    vs.(x) <- true;
    loop (ans + if d then 0 else 1) xs

let () =
  let hd = List.hd a in
  if List.for_all ((=) hd) a then print_endline "0"
  else loop 0 a


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

exception Found of bool

let () =
  (if List.first ls = 1 then 0
   else
     let hcount = Hashtbl.create n in
     ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
     let h = Hashtbl.create n in
     ListL.map ls ~f:(fun v ->
         let n = Hashtbl.find hcount v in
         if n >= 2 then false
         else
           (let b = try ListL.iter (2++v) ~f:(fun j ->
                if v mod j = 0 && (Option.is_some @@ Hashtbl.find_option h j
                                   || Option.is_some @@ Hashtbl.find_option h (v/j)) then raise @@ Found false
                else if j * j > v then raise @@ Found (Option.is_none @@ Hashtbl.find_option h v)
              ); true with Found b -> b in
            Hashtbl.add h v true; b))
     |> List.filter ((=) true)
     |> List.length)
  |> Printf.printf "%d\n"


let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let vs = Array.make 1_000_001 false

let rec devideable i x =
  if i * i > x then false
  else if x mod i <> 0 then devideable (i + 1) x
  else vs.(i) || vs.(x / i) || devideable (i + 1) x

let rec loop ans = function
  | [] -> Printf.printf "%d\n" ans
  | x :: xs ->
    if devideable 1 x then loop ans xs
    else begin
      vs.(x) <- true;
      loop (ans + 1) xs
    end

let () =
  let hd = List.hd a in
  if List.for_all ((=) hd) a then print_endline "0"
  else loop 0 a


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int.of_string

exception Found of bool

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let h = Hashtbl.create n in
  ListL.map (List.sort Int.compare ls) ~f:(fun v ->
      let n = Hashtbl.find hcount v in
      if n >= 2 then false
      else
        (let b = try ListL.iter (2++v) ~f:(fun j ->
             if v mod j = 0 && (Option.is_some @@ Hashtbl.find_option h j
                                || Option.is_some @@ Hashtbl.find_option h (v/j)
                               ) then raise @@ Found false
             else if j * j > v then
               raise @@ Found (Option.is_none @@ Hashtbl.find_option h v)
           ); true with Found b -> b in
         Hashtbl.add h v true; b))
  |> List.filter ((=) true)
  |> List.length
  |> Printf.printf "%d\n"


Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let hist = Array.make 1000001 0 in
    Array.iter (fun v -> hist.(v) <- hist.(v) + 1) a;
    let rec loop_i i acc =
        let rec loop_j v j acc =
            if j * j > v then acc else
                if v mod j <> 0 then loop_j v (j + 1) acc else (
                    let j1 = j in
                    let j2 = v / j in
                    if v = j1 && hist.(j1) > 1 then acc - 1 else
                    if v = j2 && hist.(j2) > 1 then acc - 1 else
                    if v = j1 && hist.(j1) = 1 ||
                       v = j2 && hist.(j2) = 1 ||
                       hist.(j1) = 0 && hist.(j2) = 0 then loop_j v (j + 1) acc
                    else acc - 1
                )
        in
        if i = n then acc else
            loop_i (i + 1) (loop_j a.(i) 1 acc)
    in
    loop_i 0 n |> Printf.printf "%d\n"
)


let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let rec loop acc = function
  | [] -> Printf.printf "%d\n" @@ List.length acc
  | x :: xs -> loop (x :: acc) (List.filter (fun i -> i mod x <> 0) xs)

let () =
  if List.for_all (fun i -> i = List.hd a) a then print_endline "0"
  else loop [] a


let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let ans = ref 1 in
  for i = 1 to n do
    Scanf.scanf "%d " @@ fun x ->
    ans := !ans * x;
  done;
  Printf.printf "%d\n" (if !ans > 1000000000000000000 then -1 else !ans)

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0


open Scanf
open Printf

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if total > 1_000_000_000_000_000_000 / first then
                          (if List.mem 0 lst  then 0 else -1)
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if first = 0 then 0
                       else if float total > float (1_000_000_000_000_000_000 / first)  then -1
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if first = 0 then 0
                       else if total > (1_000_000_000_000_000_000 / first)  then -1
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf
open Big_int

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if first = 0 then 0
                       else if gt_big_int (mult_big_int (big_int_of_int first) (big_int_of_int total))
                                          (big_int_of_int 1_000_000_000_000_000_000) then -1
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf
open Big_int

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if gt_big_int (mult_big_int (big_int_of_int first) (big_int_of_int total))
                                     (big_int_of_int 1_000_000_000_000_000_000) then -1
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf

let multiplication lst =
  let rec loop total l = match l with
      [] -> total
    | first :: rest -> if float total > float 1_000_000_000_000_000_000 then -1
                       else loop (first * total) rest
  in loop 1 lst

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf
open Big_int

let multiplication lst =
  let rec loop lst total = match lst with
      [] -> big_int_of_int 1
    | first :: rest ->
        if gt_big_int total (big_int_of_int 1000000000000000000) then big_int_of_int (-1)
        else mult_big_int first (loop rest (mult_big_int total first))
  in int_of_big_int (loop lst (big_int_of_int 1))

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> big_int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf
open Big_int

let multiplication lst =
  let ans = List.fold_right mult_big_int lst (big_int_of_int 1) in
    if gt_big_int ans (big_int_of_int 1000000000000000000) then -1 else int_of_big_int ans

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> big_int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf

let multiplication lst =
  let ans = List.fold_right ( * ) lst 1 in
    if ans > 1000000000000000000 then -1 else ans

let n = sscanf (read_line ()) "%d" (fun n -> n)
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


open Scanf
open Printf

let multiplication lst =
  let ans = List.fold_right ( * ) lst 1 in
    if ans > 1000000000000000000 then -1 else ans

let n = read_int ()
let a_list = List.map (fun n -> int_of_string n) (String.split_on_char ' ' (read_line ()))
let () = printf "%d\n" (multiplication a_list)


let () = Scanf.scanf "%d\n" @@ fun n ->
  let array = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc a ->
    if a = 0 || acc = 0
    then 0
    else if acc = -1
    then -1
    else if acc <= 1000000000000000000 / a
    then acc * a
    else -1) 1 array


let () = Scanf.scanf "%d\n" @@ fun n ->
  let array = Array.init n @@ fun i -> if i<n-1 then Scanf.scanf "%d " @@ fun a -> a else Scanf.scanf "%d" @@ fun a -> a in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc a ->
    if a = 0 || acc = 0
    then 0
    else if acc = -1
    then -1
    else if acc <= 1000000000000000000 / a
    then acc * a
    else -1) 1 array


let () = Scanf.scanf "%d\n" @@ fun n ->
  let array = Array.init n @@ fun _ -> Scanf.scanf "%d" @@ fun a -> a in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc a ->
    if a = 0 || acc = 0
    then 0
    else if acc = -1
    then -1
    else if acc <= 1000000000000000000 / a
    then acc * a
    else -1) 1 array


let () = Scanf.scanf "%d\n" @@ fun n ->
  let array = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc a ->
    if a = 0 || acc = 0
    then 0
    else if acc = -1
    then -1
    else if acc <= 1000000000000000000 / a
    then acc * a
    else -1) 1 array


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int.of_string

let () =
  ListL.fold_left ls ~init:1 ~f:(fun pred v ->
      if v = 0 || pred = 0 then 0
      else if pred = -1 then -1
      else
      if log10 (Float.of_int pred) +. log10 (Float.of_int v) < 19.0 then
        if pred * v > 1_000_000_000_000_000_000 then -1
        else pred *v
      else -1)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Big_int.of_string

let () =
  List.reduce Big_int.mul ls
  |> (fun v -> if Big_int.gt_big_int
         (Big_int.of_string  "10000000000000000") v
       then -1 else Big_int.to_int v)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Big_int.of_string

let () =
  List.reduce Big_int.mul ls
  |> (fun v -> if v > Big_int.of_string "10000000000000000" then -1 else
         Big_int.to_int v)
  |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int64.of_string

let () =
  ListL.fold_left (List.sort Int64.compare ls) ~init:(Int64.of_int 1)
    ~f:(fun pred v ->
        let ( * ) =  Int64.( * ) in
        if pred = Int64.of_int (-1) then pred
        else if pred * v > 1_000_000_000_000_000_000L then Int64.of_int (-1)
        else pred * v)
  |> Printf.printf "%Ld\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int64.of_string

let () =
  List.reduce (Int64.( * )) ls
  |> (fun v -> if v > 1_000_000_000_000_000_000L then Int64.of_int (-1) else v)
  |> Printf.printf "%Ld\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int.of_string

let () =
  List.reduce ( * ) ls
  |> (fun v -> Printf.printf "%d\n" (if v > 1_000_000_000_000_000_000 then -1 else v))


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int.of_string

let () =
  ListL.fold_left ls ~init:1 ~f:(fun pred v ->
      if pred = -1 then -1
      else if pred *v > 1_000000_000000_000000 then -1
      else pred*v
    ) |> Printf.printf "%d\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int.of_string

let () =
  ListL.fold_left ls ~init:1 ~f:(fun pred v ->
      if pred = -1 then -1
      else if pred *v >= 1_000000_000000_000000 then -1
      else pred*v
    ) |> Printf.printf "%d\n"


let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Printf.printf "%d\n" @@
  (fun acc -> if 1000000000000000000 < acc then -1 else acc) @@
  Array.fold_left (fun acc a ->
    if a = 0
    then 0
    else if acc < 0 || (1000000000000000000 + a - 1) / a < acc
    then -1
    else acc * a) 1 as_


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" ( fun n -> n)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let rec log2 n =
        if n = 0 then
                0
        else
                1 + (log2 (n lsr 1))

let rec f lst ac =
        if ac > (Int.pow 10 18) then
                -1
        else
                match lst with
                          [] -> ac
                        | first :: rest ->
                                let bac = (log2 ac) - 1 in
                                let bfst = log2 first in
                                        if (bac + bfst) > 60 then
                                                -1
                                        else
                                                f rest (ac * first)

let () =
        (
                if List.exists (fun elmnt -> elmnt = 0) lst then
                        0
                else
                        f lst 1
        ) |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line ()
let a2 = a |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> if r > 1000000000000000000 then -1 else r
  | first :: rest ->
    if List.mem 0 a2 then 0 else
    if first <> 1 && 1000000000000000000 / 2 < r then -1 else
    loop rest (r*first)

let l = loop a2 1
let _ = l |> Printf.printf "%d\n"


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" ( fun n -> n)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let rec log2 n =
        if n = 0 then
                0
        else
                1 + (log2 (n lsr 1))

let rec f lst ac =
        if ac > (Int.pow 10 18) then
                -1
        else
                match lst with
                          [] -> ac
                        | first :: rest ->
                                let bac = log2 ac in
                                let bfst = log2 first in
                                        if bac + bfst > 60 then
                                                -1
                                        else
                                                f rest (ac * first)

let () =
        (
                if List.exists (fun elmnt -> elmnt = 0) lst then
                        0
                else
                        f lst 1
        ) |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line ()
let a2 = a |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> r
  | first :: rest ->
    if List.mem 0 a2 then 0 else
    if first <> 1 && 1000000000000000000 / 2 <= r then -1 else
    loop rest (r*first)

let l = loop a2 1
let _ = l |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line ()
let a2 = a |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> r
  | first :: rest ->
    if List.mem 0 a2 then 0 else
    if first = 0 then 0 else
    if first <> 1 && max_int / 2 <= r then -1 else
    loop rest (r*first)

let l = loop a2 1
let _ = (if l > 1000000000000000000 || l < 0 then -1 else l) |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line ()
let a2 = a |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> r
  | first :: rest ->
    if first = 0 then 0 else
    if first <> 1 && max_int / 2 <= r then -1 else
    loop rest (r*first)

let l = loop a2 1
let _ = (if l > 1000000000000000000 || l < 0 then -1 else l) |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line () |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> r
  | first :: rest ->
    if first = 0 then 0 else
    loop rest (r*first)

let l = loop a 1
let _ = (if l > 1000000000000000000 || l < 0 then -1 else l) |> Printf.printf "%d\n"


open Batteries
let n = read_int ()
let a = read_line () |> String.split_on_char ' ' |> List.map int_of_string
let rec loop lst r=
  match lst with
  | [] -> r
  | first :: rest ->
    if first = 0 then 0 else
    loop rest (r*first)

let l = loop a 1
let _ = (if l > 1000000000000000000 then -1 else l) |> Printf.printf "%d\n"


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" ( fun n -> n)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let rec f lst ac =
        if ac > Int.pow 10 18 then
                -1
        else
                match lst with
                          [] -> if ac > Int.pow 10 18 then
                                        -1
                                else
                                        ac
                        | first :: rest ->
                                if ac > Int.pow 10 18 then
                                        -1
                                else
                                        f rest (ac * first)

let () =
        (
                if List.exists (fun elmnt -> elmnt = 0) lst then
                        0
                else
                        f lst 1
        ) |> Printf.printf "%d\n"


let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let ans = ref 0 in
  let ans2 = ref 0 in
  for i = 1 to n do
    Scanf.scanf "%d " @@ fun x ->
    ans := !ans * x;
    if !ans >= 1000000000000000000 then ans2 := -1
  done;
  Printf.printf "%d\n" (if !ans = -1 then -1 else !ans)


open Batteries
let n = read_int ()
let a = read_line () |> String.split_on_char ' ' |> List.map int_of_string |> List.fold_left (fun a b -> a * b) 1
let _ = (if a > 1000000000000000000 then -1 else a) |> Printf.printf "%d\n"


Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let rec loop i acc =
        if i = n then acc else
            if acc = 0 then 0 else
                if a.(i) > 1_000_000_000_000_000_000 / acc then -1
                else loop (i + 1) (acc * a.(i))
    in
    loop 1 a.(0) |> Printf.printf "%d\n"
)


let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let ans = Array.fold_left (fun a b -> a * b) 1 arr in
  Printf.printf "%d\n" (if ans >= 1000000000000000000 then -1 else ans)


let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let ax = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let i = int_of_float 1e18

let rec mul ans = function
  | [] -> Printf.printf "%d\n" @@ if ans > i then (-1) else ans
  | x :: xs ->
      if x = 0 then print_endline "0"
      else if int_of_float (float i /. float ans) < x then print_endline "-1"
      else mul (ans * x) xs

let () =
  if List.mem 0 ax then print_endline "0"
  else mul 1 ax


let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let ans = Array.fold_left (fun a b -> a * b) 1 arr in
  Printf.printf "%d\n" (if ans > 1000000000000000000 then -1 else ans)


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" ( fun n -> n)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let () =
        (
                let ans = List.fold_right (fun a b ->
                        a * b
                ) lst 1 in
                        if ans > (Int.pow 10 18) then
                                -1
                        else
                                ans
        ) |> Printf.printf "%d\n"


open Printf
open Scanf

let (n,m) = sscanf (read_line ()) "%f %f" (fun n m -> (n,m));;
let ans = int_of_float (floor (n*.m));;
printf ("%d\n") (ans);;

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


Scanf.scanf "%d %d.%d" (fun a b c -> Printf.printf "%d\n" (a * (100 * b + c) / 100))


Scanf.scanf "%d %d.%d" (fun a b c -> Printf.printf "%d\n" ((a * (100 * b + c) / 10 + 5) / 10))


Scanf.scanf "%d %f" (fun a b ->
  Printf.printf "%d\n" (a * (int_of_float (100. *. b)) / 100)
)


let () = Scanf.scanf "%d %d.%d" @@ fun a b1 b2 ->
  Printf.printf "%d\n" @@ a*b1 + a*b2/100


Scanf.scanf "%d %f" (fun a b -> print_int (a * int_of_float (b *. 100.) / 100))


Scanf.scanf "%d %f" (fun a b -> print_int (int_of_float (float_of_int a *. b)))


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b) = scan "%d %s" Tuple2.make

let () =
  let b = 100 * (atoi @@ String.get b 0) +
          10 * (atoi @@ String.get b 2) +
          1 * (atoi @@ String.get b 3) in
  Printf.printf "%d\n"  (a * b /100)


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_list ~sep:' ' Int64.of_string

let () =
  List.reduce (Int64.( * )) ls
  |> (fun v -> if v > 1_000_000_000_000_000_000L then Int64.of_int (-1) else v)
  |> Printf.printf "%Ld\n"


open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b) = scan "%s %s" Tuple2.make

let () =
  let a = Big_int.of_string a in
  let b = Big_int.of_string b in
  Big_int.mul a b
  |> Big_int.to_float
  |> Printf.printf "%f\n"


let (a, b) = Scanf.sscanf (read_line ()) "%d %s" @@ fun a b -> (a, b)
let b = int_of_string @@ Str.replace_first (Str.regexp "\\.") "" b

let () = Printf.printf "%d\n" @@ a * b / 100


let () = Scanf.scanf "%d %d.%d" @@ fun a b1 b2 ->
  Printf.printf "%d\n" @@ a * (100 * b1 + b2) / 100


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let f a b =
        (int_of_float a) * (int_of_float (100.0 *. b)) / 100

let () =
        Scanf.sscanf (read_line ()) "%f %f" (
                fun a b ->
                        f a b
        ) |> Printf.printf "%d\n"


(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let f a b =
        (int_of_float (a *. (100.0 *. b))) / 100

let () =
        Scanf.sscanf (read_line ()) "%f %f" (
                fun a b ->
                        f a b
        ) |> Printf.printf "%d\n"


let (a, b) = Scanf.sscanf (read_line ()) "%d %f" @@ fun a b -> (a, b)
let a = float a /. 10.
let b = b *. 10.

let () = Printf.printf "%d\n" @@ int_of_float @@ a *. b


let a,b = Scanf.sscanf (read_line()) "%d %f" (fun a b -> a,b)

let b2 = int_of_float @@ (b *. 100.)
let r = ((a * b2 |> float_of_int) /. 100.) |> int_of_float
let _ = Printf.printf "%d\n" r


let (a, b) = Scanf.sscanf (read_line ()) "%d %f" @@ fun a b -> (a, b)

let () = Printf.printf "%d\n" @@ int_of_float @@ (float a /. 10. *. b *. 10.)


let a,b = Scanf.sscanf (read_line()) "%f %f" (fun a b -> a,b)

let _ = Printf.printf "%d\n" @@ int_of_float (a *. b)