{"source_code": "let f,s=read_float,print_string in let f,i=modf(log(f())/.log(f())+.0.0000000000001)in if f<0.000000000000105 then(s\"YES\\n\";print_int(int_of_float i-1))else(s\"NO\")\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"}
{"source_code": "let () =\n  let x, y = Scanf.scanf \"%d %d\" (fun i j -> (float_of_int i, float_of_int j)) in\n  let exposant_xy = y *. (log x) in\n  let exposant_yx = x *. (log y) in\n  if (exposant_xy < exposant_yx) then print_string \"<\"\n  else if (exposant_xy > exposant_yx) then print_string \">\"\n  else print_string \"=\"", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"}
{"source_code": "let distribute c l =\n  let rec insert a1 a2 = function\n  | [] -> a2\n  | h :: t ->\n    insert (h :: a1) ((List.rev_append a1 (h :: c :: t)) :: a2) t\n  in\n  insert [] [c :: l] l\n\nlet rec permutation = function\n  | [] -> [[]]\n  | h :: t ->\n    List.fold_left (fun acc x -> List.rev_append (distribute h x) acc)\n        [] (permutation t)\n\nlet range =\n  let rec aux a = function\n    | 0 -> a\n    | m -> aux (m :: a) (m - 1)\n  in\n  aux []\n\nlet fp l =\n  let rec aux a = function\n  | [] -> a\n  | h :: t ->\n    let s, _ = List.fold_left (fun (s, m) x ->\n      let m = min m x in (s + m, m)\n    ) (h, h) t\n    in aux (a + s) t\n  in\n  aux 0 l\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n  let p = permutation (range n) in\n  let f = List.map fp p in\n  let max = match f with\n  | [] -> 0\n  | h::t -> List.fold_left max h t\n  in\n  let p = List.fold_left2 (fun a p f -> if f = max then p :: a else a) [] p f in\n  let p = List.sort compare p in\n  Printf.printf \"%s\\n\" (String.concat \" \" (List.map string_of_int (List.nth p (m - 1))))\n)\n", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"}
{"source_code": "(*let read_int () = Scanf.bscanf Scanf.Scanning.stdin \"%d\" (fun x -> x);;*)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \"%d \" (fun x -> x);;\n\nlet abs x = \n        if x>0 then x \n        else -x;;\nlet ans = ref 0;;\nlet x = read_int ();;\nlet y = read_int ();;\n\n(*Printf.printf \"%d %d\\n\" x y;; *)\nif abs x > abs y then \n         if x>0 then ans := 1 + (x - 1) * 4\n         else ans := 3 + (abs x - 1) * 4\nelse \n         if y>0 then ans := 2 + (y - 1) * 4\n         else ans := 4 + (abs y - 1) * 4;;\n\nif (x=0 && y=0) || (x=1 && y=0) then print_int 0\nelse if x=y && x*y>0 then print_int (!ans - 1)\nelse if x>0 && y<0 && abs x - abs y = 1 then print_int (!ans - 1)\nelse print_int !ans;;\n", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"}
{"source_code": "(* open Scanf *)\n(* open Printf *)\n\n\nlet main () =\n  let a = read_int () in\n  let b = read_int () in\n  let c = read_int () in\n    let ans = 7 * (min (min a (b / 2)) (c / 4)) in\n      print_int ans\n\n\nlet _ = main ()\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"}
{"source_code": "let rec fix f x = f (fix f) x;;\nScanf.scanf \" %d %d %d %d %d %d\" @@ fun w h u d v e ->\n  print_int @@ fix (fun f h w ->\n    if h=0 then w\n    else\n      let w = w+h in\n      f (h-1) @@ max 0 @@\n        if h=e then w-v\n        else if h=d then w-u\n        else w) h w", "src_uid": "084a12eb3a708b43b880734f3ee51374"}
{"source_code": "let (|>) x f = f x\n\nlet rec f i j a b : char list =\n  if a = b then\n    []\n  else if a < b then\n    j::f i j (a+1) b\n  else\n    f j i b a\n\nlet tl xs = try List.tl xs with _ -> []\nlet rec mhd = function\n  | [] -> []\n  | []::xss -> mhd xss\n  | (x::xs)::xss -> x::mhd xss\n\nlet rec tr = function\n  | [] -> []\n  | []::xss -> tr xss\n  | (x::xs)::xss ->\n      (x::mhd xss) :: tr (xs::List.map tl xss)\n\nlet rec p = function\n  | [] -> ()\n  | [a]::xs -> Printf.printf \"%c\\n\" a; p xs\n  | [a;b]::xs -> Printf.printf \"%c%c\\n\" a b; p xs\n\nlet () =\n  let s = read_line () in\n  let t = read_line () in\n  tr [f 'L' 'R' (int_of_char s.[0]) (int_of_char t.[0]); f 'D' 'U' (int_of_char s.[1]) (int_of_char t.[1])]\n  |> (fun xs -> Printf.printf \"%d\\n\" (List.length xs); xs) |> p\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"}
{"source_code": "let _ =\n  let n = 3200000 in\n  let prime = Array.make (n + 1) true in\n  let p = Array.make 250000 0 in\n  let pk = ref 0 in\n  let _ =\n    for i = 2 to n do\n      if prime.(i) then (\n\tp.(!pk) <- i;\n\tincr pk;\n\tlet j = ref (2 * i) in\n          while !j <= n do\n\t    let jj = !j in\n              prime.(jj) <- false;\n              j := jj + i\n          done\n      )\n    done;\n  in\n  let pk = !pk - 1 in\n  let sb = Scanf.Scanning.stdib in\n  let q = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n  let n = ref q in\n  let sq = ref false in\n  let sqp = ref 0L in\n  let divs = ref 0 in\n  let d = Array.make 2 0L in\n    for i = 0 to pk do\n      let p = p.(i) in\n      let pl = Int64.of_int p in\n\tif Int64.rem !n pl = 0L then (\n\t  if !divs < 2\n\t  then d.(!divs) <- pl;\n\t  incr divs;\n\t  if Int64.rem (Int64.div !n pl) pl = 0L then (\n\t    sq := true;\n\t    sqp := Int64.mul pl (Int64.of_int p);\n\t  )\n\t);\n\twhile Int64.rem !n pl = 0L do\n\t  n := Int64.div !n pl\n\tdone\n    done;\n    (*Printf.printf \"asd %d %Ld\\n\" !divs !n;*)\n    if !n <> 1L\n    then incr divs;\n    if !sq && !sqp < q\n    then Printf.printf \"1\\n%Ld\\n\" !sqp\n    else if not !sq && !divs <= 1\n    then Printf.printf \"1\\n0\\n\"\n    else if !divs > 2\n    then Printf.printf \"1\\n%Ld\\n\" (Int64.mul d.(0) d.(1))\n    else Printf.printf \"2\\n\"\n", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"}
{"source_code": "\nopen Scanf\nopen Printf\nopen Int64\n\nlet md = 1000000007L\n\nlet f n m k =\n  if k = -1L && Int64.rem (Int64.add m n) 2L = 1L then 0L\n    else let rec g x y =\n      if y = 0L then 1L\n        else if y = 1L then x\n        else let tmp = g x (Int64.div y 2L) in\n          if Int64.rem y 2L = 0L then Int64.rem (Int64.mul tmp tmp) md \n          else Int64.rem (Int64.mul (Int64.rem (Int64.mul tmp tmp) md) x) md in\n    g (g 2L (Int64.sub n 1L)) (Int64.sub m 1L)\n\nlet () =\n  let ans = bscanf Scanning.stdin \"%Ld %Ld %Ld\" f in\n    printf \"%Ld\\n\" ans", "src_uid": "6b9eff690fae14725885cbc891ff7243"}
{"source_code": "\nmodule I = Int64\n\n(* OCaml 这 ... 没个像样的库还真是垃圾 ... *)\nmodule type IntType = sig\n  type t\n  val (+): t -> t -> t\n  val compare: t -> t -> int\n  val rem: t -> t -> t\n  val of_int: int -> t\n  val of_string: string -> t\nend\n\nmodule Int64M = struct\n  type t = Int64.t\n  let (+) = Int64.add\n  let compare = Int64.compare\n  let rem = Int64.rem\n  let of_int = Int64.of_int\n  let of_string = Int64.of_string\nend\n\nmodule IntM = struct\n  type t = int\n  let (+) = (+)\n  let compare = compare\n  let rem = Int64.rem\n  let of_int v = v\n  let of_string = string_of_int\nend\n\nmodule Make_Judge (Int: IntType) = struct\n\nmodule SetInt = Set.Make(Int)\n\nlet judge_naive (n: Int.t) (k: Int.t): bool =\n  let open Int in\n  let rec attempt set i =\n    let x = rem n i in\n    if SetInt.mem x set then false\n    else\n      if i >= k then true\n      else attempt (SetInt.add x set) (i + (Int.of_int 1))\n  in\n  attempt (SetInt.empty) (Int.of_int 1)\n\nlet judge_opt (n: Int.t) (k: Int.t): bool =\n  if k > Int.of_int 42\n  then false\n  else judge_naive n k\n\nend\n\nlet output_yn v =\n  (match v with\n  | true -> print_string \"Yes\"\n  | false -> print_string \"No\");\n  print_char '\\n'\n\n(* \nlet () =\n  let limit = 65536 in\n  let curmax = ref 1 in\n  for n = 1 to limit do\n    for k = 1 to limit do\n      let ret = judge_naive n k in\n      if ret && k > !curmax then begin\n        curmax := k;\n        Printf.printf \"%d %d\" n !curmax;\n        print_endline \"\";\n      end\n    done\n  done *)\n\nmodule JudgeI64 = Make_Judge (Int64M)\n\nlet () =\n  let f x y = Int64M.(JudgeI64.judge_opt (of_string x) (of_string y)) |> output_yn in\n  Scanf.scanf \"%s %s\" f", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"}
{"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n  \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \nlet n = read_int 0 in\nlet k = read_int 0 in\nPrintf.printf \"%d\\n\" (pdt (pow k (k-1)) (pow (n-k) (n-k)))", "src_uid": "cc838bc14408f14f984a349fea9e9694"}
{"source_code": "let (|>) x f = f x\n\nlet modulo = 51123987\n\nlet () =\n  let n = read_int () in\n  let a = read_line () in\n  let rec compress m i =\n    if i >= n then\n      m\n    else if a.[m-1] <> a.[i] then (\n      a.[m] <- a.[i];\n      compress (m+1) (i+1)\n    ) else\n      compress m (i+1)\n  in\n  let m = compress 1 1 in\n\n  let p = Array.make_matrix n 3 0 in\n  for i = m-1 downto 0 do\n    let t = int_of_char a.[i] - int_of_char 'a' in\n    p.(i).(t) <- i;\n    p.(i).((t+1) mod 3) <- if i+1 < m then p.(i+1).((t+1) mod 3) else m;\n    p.(i).((t+2) mod 3) <- if i+1 < m then p.(i+1).((t+2) mod 3) else m\n  done;\n\n  let dp = Array.init 2 (fun _ -> Array.make_matrix (52*52) m 0) in\n  dp.(0).(0).(0) <- 1;\n  let add a x y = a.(x) <- (a.(x) + y) mod modulo in\n  for i = 0 to n-1 do\n    for u = min ((n+2)/3) (i+1) downto 0 do\n      for v = min ((n+2)/3) (i+1) downto 0 do\n        Array.fill dp.((i+1) land 1).(u*52+v) 0 m 0\n      done\n    done;\n    for u = min ((n+2)/3) i downto 0 do\n      for v = min ((n+2)/3) i downto 0 do\n        for j = 0 to m-1 do\n          let t = dp.(i land 1).(u*52+v).(j) in\n          if t > 0 then (\n            let ix = u*52+v in\n            if p.(j).(0) < m then\n              add dp.((i+1) land 1).(ix+52) p.(j).(0) t;\n            if p.(j).(1) < m then\n              add dp.((i+1) land 1).(ix+1) p.(j).(1) t;\n            if p.(j).(2) < m then\n              add dp.((i+1) land 1).(ix) p.(j).(2) t\n          )\n        done\n      done\n    done\n  done;\n\n  let ans = ref 0 in\n  for u = (n+2)/3 downto 0 do\n    for v = (n+2)/3 downto 0 do\n      let w = n-u-v in\n      if (max u v |> max w) - (min u v |> min w) <= 1 then\n        for j = 0 to m-1 do\n          ans := (!ans + dp.(n land 1).(u*52+v).(j)) mod modulo\n        done\n    done\n  done;\n  Printf.printf \"%d\\n\" !ans\n", "src_uid": "64fada10630906e052ff05f2afbf337e"}
{"source_code": "open Printf\n\n\nlet main =\n    let values = Array.map (int_of_string) (Array.of_list (Str.split (Str.regexp \"\\\\+\") (read_line()))) in\n    \n    let ans = ref \"\" in\n    \n    Array.sort (fun a b -> a - b) values;\n    Array.iter (fun x -> ans := sprintf \"%s%d+\" !ans x) values;\n    printf \"%s\\n\" (String.sub !ans 0 ((String.length !ans) - 1));\n", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"}
{"source_code": "open Printf\n\nlet (n,a,b,c) = Scanf.scanf \"%d %d %d %d \" (fun x a b c -> (x,a,b,c));;\n\nlet min_cut = min a (min b c);;\nlet d = Array.make (n+1) 0;;\n\nlet flag = Array.make (n+1) false in\n    flag.(0)<- true;\n\n    for i = 0 to n do\n      if (flag.(i)) then\n        begin\n          if (i+a<=n && d.(i)+1 > d.(i+a) ) then\n            begin\n              d.(i+a) <- d.(i)+1;\n              flag.(i+a)<-true\n            end;\n          if (i+b<=n && d.(i)+1 > d.(i+b) ) then\n            begin\n              d.(i+b) <- d.(i)+1;\n              flag.(i+b)<- true\n            end;\n          if (i+c<=n && d.(i)+1 > d.(i+c) ) then\n            begin\n              d.(i+c) <- d.(i)+1;\n              flag.(i+c) <- true\n            end;\n        end;\n     (* Array.iter (fun x -> printf \"%d \" x) d;\n      printf \"\\n\"\n      *)\n  done\n\nlet () = printf \"%d\\n\" d.(n);;\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"}
{"source_code": "let word = Scanf.scanf \"%s\" (fun s -> s)\n\nlet count () = \n    let l = String.length word in\n    let rec loop i lowers uppers = \n        if i < l\n        then\n            if word.[i] = Char.uppercase word.[i]\n            then \n                loop (i + 1) lowers (uppers + 1)\n            else\n                loop (i + 1) (lowers + 1) uppers\n        else\n            (lowers, uppers)\n    in loop 0 0 0\n\nlet solve (lowers, uppers) =\n    if uppers > lowers\n    then\n        String.uppercase word\n    else\n        String.lowercase word\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (count ()))", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"}
{"source_code": "let rec fix f x = f (fix f) x;;\nScanf.(\n  let n = scanf \" %d\" @@ fun v -> v in\n  let a = Array.init n @@ fun _ -> scanf \" %d\" @@ fun v -> v in\n  fix (fun f i x ->\n    if i=n then (\n      if x mod 360 = 0 then (\n        print_endline \"YES\"; exit 0\n      )\n    ) else (\n      f (i+1) (x+a.(i));\n      f (i+1) (x-a.(i));\n    )\n  ) 0 0;\n  print_endline \"NO\"\n)", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"}
{"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( @@ ) f x = f x\n  \nlet ( |> ) x f = f x\n  \nlet mult (a : (int64 array) array) b =\n  let a00 = a.(0).(0) in\n  let a01 = a.(0).(1) in\n  let a10 = a.(1).(0) in\n  let a11 = a.(1).(1) in\n  let b00 = b.(0).(0) in\n  let b01 = b.(0).(1) in\n  let b10 = b.(1).(0) in\n  let b11 = b.(1).(1)\n  in\n    [|\n      [|\n        Int64.rem (Int64.add (Int64.mul a00 b00) (Int64.mul a01 b10))\n          1000000007L;\n        Int64.rem (Int64.add (Int64.mul a00 b01) (Int64.mul a01 b11))\n          1000000007L\n      |];\n      [|\n        Int64.rem (Int64.add (Int64.mul a10 b00) (Int64.mul a11 b10))\n          1000000007L;\n        Int64.rem (Int64.add (Int64.mul a10 b01) (Int64.mul a11 b11))\n          1000000007L\n      |]\n    |]\n  \nlet rec pow arr n =\n  if n = 0L\n  then [| [| 1L; 0L |]; [| 0L; 1L |] |]\n  else\n    if n = 1L\n    then arr\n    else\n      if (Int64.rem n 2L) = 0L\n      then pow (mult arr arr) (Int64.div n 2L)\n      else (mult arr) @@ (pow arr (Int64.sub n 1L))\n  \nlet solve x y n =\n  let arr = [| [| 1L; (-1L) |]; [| 1L; 0L |] |] in\n  let arr = pow arr (Int64.sub n 1L)\n  in\n    (Printf.eprintf \"%Ld %Ld\\n%Ld %Ld\\n\" arr.(0).(0) arr.(0).(1) arr.(1).(0)\n       arr.(1).(1);\n     let ans =\n       Int64.rem\n         (Int64.add (Int64.mul arr.(1).(0) y) (Int64.mul arr.(1).(1) x))\n         1000000007L\n     in\n       (Printf.printf \"%Ld\\n\") @@\n         (if ans < 0L then Int64.add ans 1000000007L else ans))\n  \nlet () = Scanf.scanf \"%Ld %Ld %Ld \" (fun x y n -> solve x y n)\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"}
{"source_code": "module Array = ArrayLabels\n  \nmodule List = ListLabels\n  \nlet pf = Printf.printf\n  \nlet sf = Scanf.scanf\n  \nexternal uget : 'a array -> int -> 'a = \"%obj_field\"\n  \nexternal uset : 'a array -> int -> 'a -> unit = \"%obj_set_field\"\n  \nlet ( |> ) x f = f x\n  \nlet ps = [| 2; 3; 5; 7; 11; 13; 17; 19; 23; 29; 31; 37; 41; 43; 47; 53 |]\n  \nlet rev_ps =\n  let r = Array.create 60 (-1)\n  in (Array.iteri ps ~f: (fun i x -> uset r x i); r)\n  \nlet np = Array.length ps\n  \nlet inf = 1_000_000\n  \nlet p16 = 1 lsl (Array.length ps)\n  \nlet dp = Array.create_matrix (100 + 1) p16 ((-1), (-1), inf)\n  \nlet rec unique ls =\n  match ls with\n  | [] | [ _ ] -> ls\n  | x :: y :: ls when x = y -> unique (x :: ls)\n  | x :: ls -> x :: (unique ls)\n  \nlet pd =\n  Array.init 59\n    ~f:\n      (fun n ->\n         if (n = 0) || (n = 1)\n         then 0\n         else\n           (let rec iter n i =\n              if i = n\n              then [ n ]\n              else\n                if (n mod i) = 0\n                then i :: (iter (n / i) 2)\n                else iter n (i + 1) in\n            let ps = (iter n 2) |> unique in\n            let res = ref 0 in\n            let cnt = ref 0\n            in\n              (List.iter ps\n                 ~f:\n                   (fun i ->\n                      (res := !res lor (1 lsl (uget rev_ps i)); incr cnt));\n               !res)))\n  \nlet solve n arr =\n  (uset (uget dp 0) 0 ((-1), (-1), 0);\n   for i = 0 to n - 1 do\n     (let cur = i in\n      let next = i + 1\n      in\n        for state = 0 to p16 - 1 do\n          for j = 1 to 58 do\n            let (prev, _, cost) = uget (uget dp cur) state\n            in\n              if cost < inf\n              then\n                if (state land (uget pd j)) = 0\n                then\n                  (let state' = state lor (uget pd j) in\n                   let (_, _, c) = uget (uget dp next) state'\n                   in\n                     if (cost + (abs ((uget arr i) - j))) < c\n                     then\n                       uset (uget dp next) state'\n                         (state, j, (cost + (abs ((uget arr i) - j))))\n                     else ())\n                else ()\n              else ()\n          done\n        done)\n   done;\n   let (min_idx, min) = ((ref (-1)), (ref inf))\n   in\n     (for i = 0 to p16 - 1 do\n        (let (_, _, c) = uget (uget dp n) i\n         in if !min > c then (min_idx := i; min := c) else ())\n      done;\n      let rec iter i s =\n        if i <= 0\n        then []\n        else\n          (let (prev, v, _) = uget (uget dp i) s in v :: (iter (i - 1) prev))\n      in\n        (((iter n !min_idx) |> List.rev) |>\n           (List.iter ~f: (fun i -> pf \"%d \" i));\n         pf \"\\n\")))\n  \nlet () =\n  sf \"%d \"\n    (fun n -> solve n (Array.init n ~f: (fun _ -> sf \"%d \" (fun i -> i))))\n  \n", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"}
{"source_code": "let [n; t] = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nlet x = Array.init n (fun i -> Array.make (i+1) 0.)\n\nlet pour i j amount =\n  x.(i).(j) <- x.(i).(j) +. amount\n\nlet () =\n  for _t = 1 to t do\n    x.(0).(0) <- x.(0).(0) +. 1.;\n    for i = 0 to n - 2 do\n      for j = 0 to i do\n        if x.(i).(j) > 1. then\n          let drop = (x.(i).(j) -. 1.) /. 2. in\n          pour (i+1) j drop;\n          pour (i+1) (j+1) drop;\n          x.(i).(j) <- 1.\n      done\n    done\n  done;\n  let r = ref 0 in\n  for i = 0 to n-1 do\n    for j = 0 to i do\n      if x.(i).(j) >= 1. then\n        incr r\n    done\n  done;\n  Printf.printf \"%d\\n\" !r\n", "src_uid": "b2b49b7f6e3279d435766085958fb69d"}
{"source_code": "let input () = Scanf.scanf \"%s %s\" (fun s0 s1 -> s0, s1) \n\nlet solve (s0, s1) = String.compare (String.lowercase s0) (String.lowercase s1)\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))", "src_uid": "ffeae332696a901813677bd1033cf01e"}
{"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n  \nlet ( @@ ) f x = f x\n  \nlet ( |> ) x f = f x\n  \nlet solve n m k =\n  let low = max 0L (Int64.add (Int64.sub k m) 1L) in\n  let high = min k (Int64.sub n 1L)\n  in\n    if low > high\n    then Printf.printf \"-1\\n\"\n    else\n      (let x =\n         Int64.mul (Int64.div n (Int64.add low 1L))\n           (Int64.div m (Int64.add (Int64.sub k low) 1L)) in\n       let y =\n         Int64.mul (Int64.div n (Int64.add high 1L))\n           (Int64.div m (Int64.add (Int64.sub k high) 1L))\n       in (Printf.printf \"%Ld\\n\") @@ (max x y))\n  \nlet () = Scanf.scanf \"%Ld %Ld %Ld \" (fun n m k -> solve n m k)\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"}
{"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n  match Stream.next stdin_stream with\n    '-' ->  - (ri 0)\n  | '+' ->  ri 0\n  | '0'..'9' as c -> ri ((int_of_char c) - 48)\n  | _ -> gi ()\nand ri x =\n  match Stream.next stdin_stream with\n    '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n  | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n  if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n  Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;\nlet pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) a;;\n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n  let s = Scanf.scanf \"%s\" (fun i -> i) in\n  let l = String.length s in\n  let rec f i k ch = \n    if i == l then 1\n    else (match k with\n            (1|2|3|4) -> (if s.[i] == ch then f (i+1) (k+1) ch else (1 + (f (i+1) 1 s.[i])))\n          | _ -> 1 + (f (i + 1) 1 s.[i])\n         )\n   in    \n  Printf.printf \"%d\\n\" (f 1 1 s.[0])\n  ;;\nmain();;\nflushout ()", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"}
{"source_code": "let _ =\n  let sb = Scanf.Scanning.stdib in\n  let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let b = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let x = ref 1L in\n  let d = ref 0 in\n    while !x <= Int64.of_int t do\n      x := Int64.add (Int64.mul !x (Int64.of_int k)) (Int64.of_int b);\n      incr d;\n    done;\n    let res = max (n - !d + 1) 0 in\n      Printf.printf \"%d\\n\" res;\n", "src_uid": "e2357a1f54757bce77dce625772e4f18"}
{"source_code": "\nlet func str ch=\n    let cnt=ref 0 in\n    for i=1 to String.length(str) do\n        if (!cnt!=7 && str.[i-1]==ch) then cnt:=!cnt+1\n        else if !cnt!=7 then cnt:=0\n    done;\n    \n    if !cnt==7 then 1 else 0;;\n\n\nlet str=read_line();;\nif ((func str '1')+(func str '0')>0) then print_endline(\"YES\")\nelse print_endline(\"NO\")\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"}
{"source_code": "let (n, k) = Scanf.scanf \"%d %Ld\" (fun n -> fun k -> (n, k));;\n\nlet b2i b = if b then 1 else 0;;\n\nlet rec count (memo: int64 array) str l r chki chkr = \n\tif l > r then 1L\n\telse \n\t\tlet idx = (l * 2 + b2i chki) * 2 + b2i chkr in\n\t\tif memo.(idx) > -1L\n\t\tthen memo.(idx)\n\t\telse\n\t\t\tlet ans = ref 0L in\n\t\t\tfor bl = 0 to 1 do\n\t\t\t\tif str.(l) = -1 || str.(l) = bl then\n\t\t\t\tfor br = 0 to 1 do\n\t\t\t\t\tif l < r || bl = br then\n\t\t\t\t\tif str.(r) = -1 || str.(r) = br then\n\t\t\t\t\tif not (chki && bl = br && bl = 1) && not (chkr && bl > br) then\n\t\t\t\t\t\tans := Int64.add !ans (count memo str (l + 1) (r - 1) (chki && not (bl = 0 && br = 0)) (chkr && not (bl < br)))\n\t\t\t\tdone;\n\t\t\tdone;\n\t\t\tmemo.(idx) <- !ans;\n\t\t\t!ans\n;;\n\nlet str = Array.create n (-1);;\nlet new_memo = Array.create (4*n) (-1L);;\nlet do_count () = count (Array.copy new_memo) str 0 (n - 1) true true;;\n\nif do_count () <= k\nthen print_endline \"-1\"\nelse \n\tlet rk = ref (k) in\n\t\tfor i = 0 to n - 1 do\n\t\t\tstr.(i) <- 0;\n\t\t\tlet f = do_count () in begin\n\t\t\t\tif !rk >= f then begin\n\t\t\t\t\trk := Int64.sub !rk f;\n\t\t\t\t\tstr.(i) <- 1;\n\t\t\t\tend\n\t\t\tend\n\t\tdone;\n\nfor i = 0 to n - 1 do\n\tPrintf.printf \"%d\" str.(i)\ndone;\nprint_newline ();;\n", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"}
{"source_code": "(* load str.cma *)\nlet n = int_of_string (input_line stdin);;\nlet a = List.map int_of_string (Str.split (Str.regexp \" +\") (input_line stdin));;\n\nlet calc a t = let a1 = t - (List.hd a) and\n                   ar = List.filter (( < ) 0) (List.map (fun x -> x - t + 1) (List.tl a))\n               in max a1 (List.fold_left ( + ) 0 ar);;\n\nlet rec range i j = if i > j then [] else i :: (range (i+1) j);;\n\nlet t1 = List.hd a and\n    t2 = List.fold_left max 0 a\n    in let x=List.map (calc a) (range t1 (t2+1))\n    in print_int (List.fold_left min 1000 x);;\nprint_string \"\\n\";;\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"}
{"source_code": "let (|>) x f = f x ;;\nlet (@@) f x = f x ;;\n\nlet ident x = x ;;\n\nlet char_to_int x = int_of_char x - int_of_char '0' ;;\nlet int_to_char x = char_of_int (x + int_of_char '0') ;;\n\nmodule List = struct\n  include ListLabels ;;\n\n  let rec iteri i f = function\n    | [] -> ()\n    | a::l -> f i a; iteri (i + 1) f l\n\n  let iteri ~f l = iteri 0 f l\nend\n;;\n\nmodule Array = struct\n  include ArrayLabels ;;\n\n  let reduce ~f xs =\n    let acc = ref xs.(0) in\n    for i = 1 to length xs - 1 do\n      acc := f !acc xs.(i)\n    done;\n    !acc\n  ;;\nend\n;;\n\nmodule String = struct\n  include StringLabels ;;\n\n  let map_to_list ~f ss =\n    let res = ref [] in\n    iter ss ~f:(fun c -> res := f c :: !res);\n    List.rev !res\n  ;;\n\n  let of_char_list ss =\n    let res = String.create @@ List.length ss in\n    List.iteri ss ~f:(fun i c -> res.[i] <- c);\n    res\n  ;;\n\n  let iteri ~f a =\n    for i = 0 to length a - 1 do f i (unsafe_get a i) done\n  ;;\nend\n;;\n\nmodule Float = struct\n  let (+) = (+.)\n  let (-) = (-.)\n  let ( * ) = ( *. )\n  let (/) = (/.)\nend\n;;\n\nmodule Int64 = struct\n  include Int64\n  let (+) = add\n  let (-) = sub\n  let ( * ) = mul\n  let (/) = div\nend\n;;\n\nlet fold_for ?(skip=1) min max ~init ~f =\n  let acc = ref init in\n  let cur = ref min in\n  while !cur < max do\n    acc := f !acc !cur;\n    cur := !cur + skip;\n  done;\n  !acc\n;;\n\nlet iter_for ?(skip=1) min max ~f =\n  let cur = ref min in\n  while !cur < max do\n    f !cur;\n    cur := !cur + skip;\n  done\n;;\n\nlet () =\n  let m = Scanf.scanf \"%d \" ident in\n  let cs = fold_for 0 m ~init:[] ~f:(fun acc _ ->\n    Scanf.scanf \"%d \" ident :: acc) |> List.rev in\n  let x, y = Scanf.scanf \"%d %d \" (fun x y -> x, y) in\n  let sum = List.fold_left cs ~init:0 ~f:(+) in\n  let res = ref (-1) in\n  Printf.eprintf \"%d %d %d\\n\" x y sum;\n  try \n    List.fold_left cs ~init:(1, 0, sum)  ~f:(fun (i, a, b) cur ->\n      Printf.eprintf \"x, a, b = %d, %d, %d\\n\" cur a b;\n      if x <= a && a <= y && x <= b && b <= y then (res := i; raise Exit)\n      else (i + 1, a + cur, b - cur));\n    print_endline \"0\";\n  with \n  | Exit -> Printf.printf \"%d\\n\" !res\n;;\n", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"}
{"source_code": "let [a; b]= List.map (Int64.of_string) (Str.split (Str.regexp \" \") (read_line ())) and ans= ref 0L;;\nlet bb= Array.make 65 0 and x= ref 0L and p= ref 0L;;\nfor i= 2 to 63 do\n\tfor j= 1 to i - 1  do\n\t\tfor k= 1 to i do Array.set bb k 1 done;\n\t\tArray.set bb j 0;\n\t\tx := 0L; p := 1L;\n\t\tfor k= 1 to i do \n\t\t\tif bb.(k) = 1 then x := Int64.add !x !p;\n\t\t\tp := Int64.mul !p 2L;\n\t\tdone;\n\t\tif a <= !x && !x <= b then\n\t\t\tans := Int64.add !ans 1L;\n\tdone\ndone;;\nprint_endline (Int64.to_string !ans)\n", "src_uid": "581f61b1f50313bf4c75833cefd4d022"}
{"source_code": "let ( + ) = Int64.add\nlet ( * ) = Int64.mul\nlet ( - ) = Int64.sub\nlet ( mod ) = Int64.rem\nlet two = Int64.one + Int64.one\nlet one = Int64.one\nlet zero = Int64.zero\nlet three = Int64.succ two\n\nlet mult arr1 arr2 =\n  let norm n = n mod (Int64.of_int 1000000007) in\n  let ((a1,a2),(a3,a4)) = arr1 in\n  let ((b1,b2),(b3,b4)) = arr2 in  \n  (((norm (a1*b1+a2*b3)),(norm (a1*b2+a2*b4))),((norm (a3*b1+a4*b3)),(norm (a3*b2 + a4*b4))))\n;;\n\nlet solve = \n  let n = Scanf.scanf \"%Ld\\n\" (fun n -> n) in\n  let startarr = ((zero,three),(one,two)) in\n  let rec doRest arr power =\n    match (n - power) with \n      | num when num = zero -> arr\n      | _ -> doRest (mult arr startarr) (power+one) \n  in\n  let rec arrayPower arr power =\n    match (two*power) with \n      | nxtPower when (nxtPower > n) -> doRest arr  power \n      | nxtPower -> arrayPower (mult arr arr) nxtPower\n  in\n  let ((sol,_),(_,_)) = arrayPower startarr one in\n    Printf.printf \"%Ld\\n\" sol\n;;", "src_uid": "77627cc366a22e38da412c3231ac91a8"}
{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet rep n f =\n  let rec go i acc =\n    if i >= n then\n      List.rev acc\n    else\n      go (i+1) (f i::acc)\n  in go 0 []\n\nlet () =\n  let [a;b;c;d] = rep 4 read_int |> List.sort compare in\n  (match max (a+b-c) (b+c-d) with\n  | 0 -> \"SEGMENT\"\n  | x when x > 0 -> \"TRIANGLE\"\n  | _ -> \"IMPOSSIBLE\") |> print_endline", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"}
{"source_code": "let [a; b]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nPrintf.printf \"%d %d\\n\" (min a b) (((max a b)-(min a b))/2)\n\n", "src_uid": "775766790e91e539c1cfaa5030e5b955"}
{"source_code": "let rec digits n =\n  if n <= 7 then\n    1\n  else\n    1 + digits ((n + 6) / 7)\n\nlet show display offset digits number =\n  let r = ref number in\n  for i = offset + digits - 1 downto offset do\n    display.(i) <- !r mod 7;\n    r := !r / 7\n  done\n\nlet distinct array =\n  let r = ref true in\n  let right = Array.length array - 1 in\n  for i = 0 to right do\n    for j = i + 1 to right do\n      if array.(i) == array.(j) then\n        r := false\n    done\n  done;\n  !r\n\nlet () =\n  match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n  | [n; m] ->\n     let digits_h = digits n in\n     let digits_m = digits m in\n     let digits = digits_h + digits_m in\n     if digits > 7 then\n       print_endline \"0\"\n     else\n       let display = Array.make digits 0 in\n       let r = ref 0 in\n       for hour = 0 to n - 1 do\n         for min = 0 to m - 1 do\n           show display 0 digits_h hour;\n           show display digits_h digits_m min;\n           if distinct display then\n             incr r\n         done\n       done;\n       print_int !r;\n       print_newline ()\n  | _ -> assert false\n", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"}
{"source_code": "let m = function \"monday\"->0 | \"tuesday\"->1 | \"wednesday\"->2 | \"thursday\"->3 | \"friday\"->4 | \"saturday\"->5 | \"sunday\" -> 6 and\nms = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30] in\nlet a = m @@ read_line () and\nb = m @@ read_line () in\nlet c = List.filter (fun x -> ( a + x ) mod 7 == b ) ms in \nprint_string @@ if List.length c > 0 then \"YES\" else \"NO\"", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"}
{"source_code": "let solve a = print_string \"1\"; for i= 1 to a-1 do print_string \"0\" done;;\nlet [n; m]= Str.split (Str.regexp \" \") (read_line ());;\nif n = \"1\" && m = \"10\" then\n\tprint_string \"-1\"\nelse if m = \"10\" then\n\tsolve (int_of_string n) \nelse\n\tfor i= 1 to int_of_string n do print_string m done;;\nprint_endline \"\"\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"}
{"source_code": "let rec ajoute_fin x y = function\n\t| []\t-> [x;y]\n\t| t::q\t-> t::(ajoute_fin x y q) \n\nlet rec joue res win t p1 p2 =\n\ttry (let a = Hashtbl.find t (!p1,!p2) in win := 0)\n\twith Not_found  ->\n\tbegin\n\t\tincr res;\n\t\tHashtbl.add t (!p1,!p2) ();\n\t\tmatch (!p1,!p2) with\n\t\t\t| _,[]\t\t-> win := 1\n\t\t\t| [],_\t\t-> win := 2\n\t\t\t| (a::b),(c::d)\t->\n\t\t\tbegin\n\t\t\tif a > c\n\t\t\t\tthen (p1 := ajoute_fin c a b; p2 := d)\n\t\t\t\telse (p2 := ajoute_fin a c d; p1 := b);\n\t\t\t\tjoue res win t p1 p2;\n\t\t\tend\n\tend\n\nlet _ =\n\tlet k1 = Scanf.scanf \"%d %d \" (fun _ i -> i) and l1 = ref [] in\n\t\tfor i = 1 to k1 do\n\t\t\tScanf.scanf \"%d \" (fun j -> l1 := j:: !l1);\n\t\tdone;\n\tlet k2 = Scanf.scanf \"%d\" (fun i -> i) and l2 = ref [] in\n\t\tfor i = 1 to k2 do\n\t\t\tScanf.scanf \" %d\" (fun j -> l2 := j :: !l2);\n\t\tdone;\n\tlet res = ref (-1) and win = ref 42 and p1 = ref (List.rev !l1)\n\tand p2 = ref (List.rev !l2) and t = Hashtbl.create 0 in\n\t\tjoue res win t p1 p2;\n\tif !win = 0\n\t\tthen Printf.printf \"-1\"\n\t\telse Printf.printf \"%d %d\" (!res) (!win)\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"}
{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n  if x > max_int - y then max_int\n  else x + y;;\n\nlet rec ( *$ ) x y =\n  if y = 0 then 0 else\n  if y mod 2 = 1 then x *$ (y-1) +$ x\n  else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet dajLiczbe x =\n    (Char.code x) -\n    (Char.code 'a') + 1;;\n    \nlet naKrawedzi x =\n    match x with\n    | 1 -> 1\n    | 8 -> 1\n    | _ -> 0;;\n    \nlet policz x y =\n    let count = (naKrawedzi x) + (naKrawedzi y) in\n        match count with\n        | 0 -> 8\n        | 1 -> 5\n        | 2 -> 3\n        | _ -> begin assert(false); 0 end;;\n\nlet readInput () = Scanf.scanf \"%c%d\\n\" (fun x y -> x, y);;\n\nlet _ =\n    let (a,b) = readInput () in\n    Printf.printf \"%d\" (policz (dajLiczbe a) b);;\n", "src_uid": "6994331ca6282669cbb7138eb7e55e01"}
{"source_code": "\nlet words s = Str.split (Str.regexp \" \") s;;\n\nlet check n lst =\n  let threshold = List.nth lst (n - 1)\n  in\n  List.length (List.filter (fun m -> 0 < m && threshold <= m) lst)\n;;\n\nlet rec take lst n = \n  match (lst, n) with\n    [], _ -> []\n  | lst, 0 -> lst\n  | x::xs, n -> x::(take xs (n - 1))\n;;               \n\nlet () =\n  let nk = words (read_line ()) in\n  let [n; k;] = List.map int_of_string nk in\n  let score_line = take (words (read_line ())) n in\n  let scores = List.map int_of_string score_line\n  in\n  Printf.printf \"%d\\n\" (check k scores)\n;;\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"}
{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\nlet read_long () = Scanf.scanf \" %Ld \" (fun x -> x);;\nlet read_pair () = let a = read_long () in ( a , read_long () );;\n\nlet n , k = read_pair ();;\n\nlet (++) a b = Int64.add a b\nlet (--) a b = Int64.sub a b\nlet ( ** ) a b = Int64.mul a b\nlet (//) a b = Int64.div a b\n\nlet rec solve sum ans =\n        (*Printf.printf \"%Ld %Ld\\n\" sum ans;*)\n        let a = sum ++ Int64.of_int 1 and b =  sum -- (k -- ans ++ Int64.of_int 2) ++ Int64.of_int 2 ** (k -- ans ++ Int64.of_int 1) in\n        if ans >= k then Printf.printf \"-1\\n\"\n        else  if Int64.compare a n <=0  && Int64.compare b n >= 0 then\n                Printf.printf \"%Ld\\n\" ans\n        else solve b (ans ++ Int64.of_int 1);;\n\nlet binary_search () =\n        let left = ref (Int64.of_int 2) and right = ref (k -- Int64.of_int 1) in\n        (*Printf.printf \"%Ld %Ld\\n\" !left !right;*)\n        while !left <= !right do\n                let mid = ((!left ++ !right)//(Int64.of_int 2)) in let a = ((mid ** (Int64.of_int 2 ** k -- Int64.of_int 1\n                -- mid)) // Int64.of_int 2 ++ Int64.of_int 1) in \n                if  a < n then left := mid ++ (Int64.of_int 1) \n                else right := mid -- (Int64.of_int 1)\n        done;\n        !left;;\n\nif n = Int64.of_int 1 then Printf.printf \"0\\n\"\nelse if n>= Int64.of_int 2 && n<=k then Printf.printf \"1\\n\"\nelse let ans = binary_search () in if ans <= (k -- Int64.of_int 1) then\n        Printf.printf \"%Ld\\n\" ans\n                                    else Printf.printf \"-1\\n\";;\n", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"}
{"source_code": "let rand_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=rand_int();;\nlet tab=Array.init n (fun i->rand_int());;\n\nlet l=ref [];;\n\nlet rec inserer v=function\n|[]->[v]\n|h::t->if v<h then v::h::t else h::(inserer v t);;\n\nfor i=0 to n-1 do\n   l:=inserer tab.(i) !l\ndone;;\n\nlet rec print_list=function\n|[]->()\n|h::t->print_int h;print_string \" \";print_list t;;\n\nprint_list !l;;", "src_uid": "ae20712265d4adf293e75d016b4b82d8"}
{"source_code": "module Std = struct\n\n  module List = struct\n    include List\n    module L = List\n    let map f lst = L.rev (L.rev_map f lst)\n    let map2 f l1 l2 = L.rev (L.rev_map2 f l1 l2)\n    let each_cons f lst = L.rev_map2 f (L.tl (L.rev lst)) (L.rev (L.tl lst))\n    let append x y = L.rev (L.rev_append x y)\n    let fold = L.fold_left\n  end\n\n  let ( |> ) x f = f x\n  let ( <| ) f x = f x\n  let ( ~. ) = float_of_int\n  let ( @ ) = List.append\n\n  let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n\n  let di x = prerr_endline (string_of_int x); x\n  let df f = prerr_endline (string_of_float f); f\n  let ds s = prerr_endline s; s\n    \n  let int () = Scanf.scanf \" %d\" (fun x -> x)\n  let read_int = int\n  let float () = Scanf.scanf \" %f\" (fun x -> x)\n  let read_float = float\n  let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []\n  let rec n_float n () = List.rev <| repeat n (fun lst -> float () :: lst) []\n\nend\n\nopen Std\nmodule L = List\n\n(* entry point *)\n\nlet min = L.fold min max_int\n\nlet () =\n  print_int\n    begin\n      match n_int 8 () with\n          [n;k;l;c;d;p;nl;np] ->\n            (min [di(k*l/nl); di(c*d); di(p/np)]) / n \n        | _ -> assert false\n    end\n", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"}
{"source_code": "\nlet list_1 = [\"zero\";\"one\";\"two\";\"three\";\"four\";\"five\";\"six\";\"seven\";\"eight\";\"nine\"];;\nlet list_2 = [\"ten\";\"eleven\";\"twelve\";\"thirteen\";\"fourteen\";\"fifteen\";\"sixteen\";\"seventeen\";\"eighteen\";\"nineteen\"];;\nlet list_3 = [\"\";\"\";\"twenty-\";\"thirty-\";\"forty-\";\"fifty-\";\"sixty-\";\"seventy-\";\"eighty-\";\"ninety-\"];;\n\nlet rec toInt s cur ten value =\n  if cur < 0 then value\n  else toInt s ( cur - 1 ) ( ten * 10 ) ( value + ten * ( Char.code ( String.get s cur ) - Char.code '0' ) );;\n\n\nlet getWord s =\n  let x = ( toInt s ( String.length s - 1 ) 1 0 ) in\n    if 0 <= x && x <= 9 then Printf.printf \"%s\\n\" ( List.nth list_1 x )\n    else if 10 <= x && x <= 19 then Printf.printf \"%s\\n\" ( List.nth list_2 ( x - 10 ) )\n    else if ( x mod 10 ) = 0 then Printf.printf \"%s\\n\" ( String.sub ( List.nth list_3 ( x / 10 ) ) 0 ( String.length ( List.nth list_3 ( x / 10 ) ) - 1 ) )\n    else Printf.printf \"%s%s\\n\" ( List.nth list_3 ( Char.code ( String.get s 0 ) - Char.code '0' ) ) ( List.nth list_1 ( Char.code ( String.get s 1 ) - Char.code '0' ) ) ;;\n\nlet s = Scanf.scanf \"%s\\n\" ( fun s -> s ) in getWord s;;\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"}
{"source_code": "let () =\n  let n = Scanf.scanf \"%d \" (fun a -> a) in\n\n  let rec pow (x, y) =\n    if y = 0 then 1 else x * pow (x, y - 1)\n  in\n  let ans_l = [\"Sheldon\"; \"Leonard\"; \"Penny\"; \"Rajesh\"; \"Howard\"] in\n  let rec aux acc cnt n =\n    if acc < n then aux (acc*2) (cnt+1) (n-acc)\n    else\n      let i = pow (2, (cnt-1)) in\n      let ans_i = if n mod i = 0 then (n/i) else n/i+1 in\n      List.nth ans_l (ans_i-1)\n\n  in\n\n  Printf.printf \"%s\\n\" @@ aux 5 1 n\n", "src_uid": "023b169765e81d896cdc1184e5a82b22"}
{"source_code": "let _ =\n  let sb = Scanf.Scanning.stdib in\n  let a = Array.make 4 0 in\n  let b = Array.make 4 0 in\n    for i = 0 to 3 do\n      a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n      b.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n    done;\n    if (a.(0) > b.(2) && b.(1) > a.(3)) &&\n      (a.(0) > b.(3) && b.(1) > a.(2)) ||\n      (a.(1) > b.(2) && b.(0) > a.(3)) &&\n      (a.(1) > b.(3) && b.(0) > a.(2))\n    then Printf.printf \"Team 1\\n\"\n    else if ((a.(0) < b.(2) && b.(1) < a.(3)) ||\n\t       (a.(0) < b.(3) && b.(1) < a.(2))) &&\n      ((a.(1) < b.(2) && b.(0) < a.(3)) ||\n\t (a.(1) < b.(3) && b.(0) < a.(2)))\n    then Printf.printf \"Team 2\\n\"\n    else Printf.printf \"Draw\\n\"\n", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"}
{"source_code": "let s= Array.of_list (Str.split (Str.regexp \" \") (read_line ())) and ans= ref 0;;\nlet x= int_of_string s.(0);;\nif s.(2) = \"week\" then\n\tlet day = ref 5 in\n\tbegin\n\t\tfor i = 1 to 366 do\n\t\t\tif !day = 8 then\n\t\t\t\tday := 1;\n\t\t\tif !day = x then\n\t\t\t\tans := !ans + 1;\n\t\t\tday := !day + 1\n\t\tdone;\n\t\tprint_int (!ans);\n\tend\nelse\n\tlet month= [|31; 29; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31 |] in\n\tbegin\n\t\tfor i = 0 to 11 do\n\t\t\tif month.(i) >= x then\n\t\t\t\tans := !ans + 1\n\t\tdone;\n\t\tprint_int (!ans)\n\tend;;\n", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"}
{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nlet n = read_int()\n\nlet mmin = ref 0L\nlet mmax = ref 0L\n\nlet consider a b c =\n  let aa = Int64.of_int (a+1) in\n  let bb = Int64.of_int (b+2) in\n  let cc = Int64.of_int (c+2) in\n  let m = Int64.mul (Int64.mul aa bb) cc in\n    if !mmin = 0L || m < !mmin then mmin := m;\n    if !mmax = 0L || m > !mmax then mmax := m\n\nlet tryit a = (* we know that a divides into n *)\n  let x = n/a in\n  let rec loop b = \n    let c = x/b in\n      if c < b then () else (\n\tif b*c=x then consider a b c;\n\tloop (b+1)\n      )\n  in\n    loop 1\n\nlet rec loop a = \n  let x = n/a in\n    if x < a then () else (\n      if x*a=n then (\n\ttryit a;\n\ttryit x;\n      );\n      loop (a+1)\n    )\n\nlet () = \n  loop 1;\n  let fix a = Int64.to_string (Int64.sub a (Int64.of_int n)) in\n  Printf.printf \"%s %s\\n\" (fix !mmin) (fix !mmax);\n", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"}
{"source_code": "let min_max a c = match a, c with\n  0, 0 -> print_string \"0 0\"\n| a, 0 -> Printf.printf \"%d %d\\n\" a a\n| 0, c -> print_string \"Impossible\\n\"\n| a, c -> Printf.printf \"%d %d\\n\" (max a c) (a + c - 1)\n;;\n\nScanf.scanf \"%d %d\" min_max;;\n\n", "src_uid": "1e865eda33afe09302bda9077d613763"}
{"source_code": "let main () =\n  let gr () = Scanf.scanf \" %d\" (fun i -> i) in \n  let n = gr () in\n  let k = gr () in\n  let rec f x y = \n      if y == 0 \n      then x\n      else \n          if x mod 10 == 0 \n          then f (x / 10) (y - 1) \n          else f (x - 1) (y - 1)  \n  in\n  Printf.printf \"%d\\n\" (f n k)\n  ;;\nlet _ = main();;\n", "src_uid": "064162604284ce252b88050b4174ba55"}
{"source_code": "let () =\n  let a = Array.init 3 (fun _ -> read_line ()) in\n  print_endline (if List.for_all (fun (x,y) -> a.(1-x).[1-y] = a.(1+x).[1+y])\n    [-1,0; -1,1; 0,1; 1,1] then \"YES\" else \"NO\")\n", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"}
{"source_code": "let rec count_ring_amount k w h = \n\tif k = 0 then 0\n\telse 2*w + 2*h - 4 + count_ring_amount (k - 1) (w - 4) (h - 4);;\nlet (w, h, k) = Scanf.scanf \"%i %i %i\" (fun x y z -> (x, y, z));;\nPrintf.printf \"%i\" (count_ring_amount k w h);;", "src_uid": "2c98d59917337cb321d76f72a1b3c057"}
{"source_code": "let _ =\n  let sb = Scanf.Scanning.stdib in\n  let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n  let n = String.length s in\n  let a = Array.make n 0 in\n  let _ =\n    for i = 0 to n - 1 do\n      a.(i) <-\n\tmatch s.[i] with\n\t  | 'R' -> 0\n\t  | 'B' -> 1\n\t  | 'Y' -> 2\n\t  | 'G' -> 3\n\t  | '!' -> -1\n\t  | _ -> assert false\n    done;\n  in\n  let b = Array.make 4 0 in\n  let res = Array.make 4 0 in\n    for i = 0 to n - 1 do\n      if a.(i) >= 0\n      then b.(i mod 4) <- a.(i)\n    done;\n    for i = 0 to n - 1 do\n      if a.(i) < 0\n      then res.(b.(i mod 4)) <- res.(b.(i mod 4)) + 1\n    done;\n    Printf.printf \"%d %d %d %d\\n\" res.(0) res.(1) res.(2) res.(3)\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"}
{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n  if x > max_int - y then max_int\n  else x + y;;\n\nlet rec ( *$ ) x y =\n  if y = 0 then 0 else\n  if y mod 2 = 1 then x *$ (y-1) +$ x\n  else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet inside (a,b) (c,d) (e,f) =\n  let x1 = min c e\n  and x2 = max c e\n  and y1 = min d f\n  and y2 = max d f in\n  if x1 <= a && a <= x2 && ( b = y1 || b = y2 ) then true\n  else if y1 <= b && b <= y2 && ( a = x1 || a = x2 ) then true\n  else false;;\n\nlet wynik (a,b) (c,d) (e,f) =\n  if a = c && c = e then 1\n  else if b = d && d = f then 1\n  else if inside (a,b) (c,d) (e,f) then 2\n  else if inside (c,d) (a,b) (e,f) then 2\n  else if inside (e,f) (a,b) (c,d) then 2\n  else 3;;\n\nlet _ = \n  let (a,b) = read2 ()\n  and (c,d) = read2 ()\n  and (e,f) = read2 () in\n  Printf.printf \"%d\" ( wynik (a,b) (c,d) (e,f) );;\n\n", "src_uid": "36fe960550e59b046202b5811343590d"}
{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nlet n = read_int()\nlet m = read_int()\n\nlet (n,m) = (min n m, max n m)\n\nlet answer = \n  if n=1 then m\n  else if n=2 then 4*(m/4) + \n    (if m mod 4 = 0 then 0 else if m mod 4 = 1 then 2 else 4)\n  else (n*m - ((n*m)/2))\nlet () = Printf.printf \"%d\\n\" answer\n", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9"}
{"source_code": "let () = Scanf.scanf \"%d %d\\n\" (fun n k ->\n  let i = Array.init n (fun i -> Scanf.scanf \"%d%_c\" (fun x -> (x, i + 1))) in\n  Array.sort compare i;\n  let _, l = Array.fold_left (fun (a, l) (t, i) ->\n    if a + t <= k then (a + t, i :: l)\n    else (a + t, l)\n  ) (0, []) i\n  in\n  let len = List.length l in\n  Printf.printf \"%d\\n\" len;\n  if len > 0 then\n    print_endline (String.concat \" \" (List.map string_of_int l))\n)\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"}
{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n  if x > max_int - y then max_int\n  else x + y;;\n\nlet rec ( *$ ) x y =\n  if y = 0 then 0 else\n  if y mod 2 = 1 then x *$ (y-1) +$ x\n  else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet rec licz n b a =\n  if n = 1 then\n    let x = Scanf.scanf \"%Ld\\n\" (fun x -> x) in\n    a *| b +| x\n  else\n    let x = Scanf.scanf \"%Ld \" (fun x -> x) in\n    licz (n-1) b ( a *| b +| x );;\n\nlet _ = \n  let (n,a) = Scanf.scanf \"%d %Ld\\n\" (fun x y -> x, y) in\n  let sa = licz n a Int64.zero\n  and (n,b) = Scanf.scanf \"%d %Ld\\n\" (fun x y -> x, y) in\n  let sb = licz n b Int64.zero in\n  Printf.printf \"%c\\n\" \n  (if compare sa sb < 0 then '<' else if compare sa sb = 0 then '=' else '>');;\n\n\n", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"}
{"source_code": "Scanf.scanf \"%s\\n\" (fun w ->\n\tlet c = String.get w 0 in\n\tif (String.uppercase w = w) || (Char.lowercase c = c &&\n\t\tlet ss = (String.sub w 1 (String.length w - 1)) in\n\t\t\tString.uppercase ss = ss\n\t) then\n\tString.iter (fun c ->\n\t\tif Char.uppercase c = c \n\t\t\tthen print_char (Char.lowercase c) \n\t\t\telse print_char (Char.uppercase c)\n\t) w\n\telse print_string w\n);;\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"}
{"source_code": "let _ =\n   let n,i = Scanf.scanf \"%d %d\" (fun j k -> (j,k-1)) in\n   let tab = Array.init n (fun _ -> Scanf.scanf \" %d\" (fun j -> j)) in\n   let cpt = ref (tab.(i)) in\n      for j = 1 to max (n-i-1) i do\n         let ok_l = j > i || tab.(i-j) = 1 in\n         let ok_r = i+j >= n || tab.(i+j) = 1 in\n            if ok_l && ok_r\n            then cpt := !cpt + (if j > i then 0 else 1)\n                             + (if i+j >= n then 0 else 1);\n      done;\n      Printf.printf \"%d\" !cpt\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"}
{"source_code": "module A = Array\nmodule C = Char\nmodule I = Int64\nmodule L = List\nmodule Q = Queue\nmodule S = String\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet ssf = Scanf.sscanf\n\nlet (|>) x f = f x\nlet (@@) f x = f x\n\nlet id x = x\nlet id2 x y = (x, y)\nlet id3 x y z = (x, y, z)\nlet id4 a b c d = (a, b, c, d)\nlet id5 a b c d e = (a, b, c, d, e)\n\nlet err s = raise (Failure s)\n\nlet inf = 1000000000\nlet eps = 1e-11\n\nlet _ =\n  let n = sf \"%d \" id in\n  let (a1, b1) = sf \"%d %d \" id2 in\n  let (a2, b2) = sf \"%d %d \" id2 in\n  let (a3, b3) = sf \"%d %d \" id2 in\n  let rest = n - a1 - a2 - a3 in\n  let u = min rest (b1 - a1) in\n  let (rest, r1) = rest - u, a1 + u in\n  let u = min rest (b2 - a2) in\n  let (rest, r2) = rest - u, a2 + u in\n  let u = min rest (b3 - a3) in\n  let (rest, r3) = rest - u, a3 + u in\n  pf \"%d %d %d\\n\" r1 r2 r3\n;;\n", "src_uid": "3cd092b6507079518cf206deab21cf97"}
{"source_code": "(*  The test is: 3 RGR  Answer is: BG *)\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n  let n = read_int () in\n  let s = read_string () in\n\n  let hist = Array.make 3 0 in\n\n  for i=0 to n-1 do\n    let c = match s.[i] with\n      | 'B' -> 0\n      | 'G' -> 1\n      | 'R' -> 2\n      | _ -> failwith \"bad input\"\n    in\n    hist.(c) <- 1 + hist.(c)\n  done;\n\n  let ar = [|(hist.(0), 0); (hist.(1), 1); (hist.(2),2)|] in\n\n  Array.sort compare ar;\n\n  let answer = if (fst ar.(0)) > 0 then [0;1;2]\n    else if (fst ar.(1)) > 0 then (\n      let k = fst ar.(1) in\n      let l = fst ar.(2) in\n      if (k,l) = (1,1) then [snd ar.(0)]\n      else if k > 1 && l > 1 then [0;1;2]\n      else if k = 1 then List.sort compare [snd ar.(0); snd ar.(1)]\n      else failwith \"impossible\"\n    )\n    else [snd ar.(2)]\n  in\n\n  List.iter (fun i -> printf \"%c\" (\"BGR\".[i])) answer;\n  print_newline()\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"}
{"source_code": "open Scanf\nopen Printf\n\nlet n, b = scanf \"%d %d\" (fun n b -> n, b)\n\nlet l = Array.to_list (Array.init n (fun i -> scanf \" %d\" (fun i -> i)))\n\nlet cost x y = abs (x - y)\n\nlet order l = List.sort compare l\n\nlet cost_l l =\n  let rec loop l o e out =\n    match l with\n    | [] -> order out\n    | [h] -> order out\n    | h::(h'::_ as t) ->\n      let o, e = if h mod 2 = 0 then o, e+1 else o+1, e in\n      if o = e && o <> 0 then\n        loop t o e ((cost h h')::out)\n      else loop t o e out\n  in loop l 0 0 []\n\nlet aggreg l b =\n  List.fold_left\n    (fun (outi, outc) c ->\n      if outc + c <= b then\n        (outi + 1, outc + c)\n      else\n        (outi, outc))\n    (0, 0) l\n\nlet () =\n  let c_l = cost_l l in\n  let outi, outc = aggreg c_l b in\n  printf \"%d\\n\" outi;\n  ()\n", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"}
{"source_code": "(* Codeforces 266A Kamni - very easy *)\n\nopen List;;\nopen String;;\nopen Array;;\nopen Int64;;\nopen Printf;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet grs () = Scanf.scanf \" %s\" (fun s -> s);;\nlet rdln() = input_line Pervasives.stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string \" \")) ai;;\nlet readpair () =\n\tlet a = gr() in\n\tlet b = gr() in\n\t(a, b);;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n - 1) (gr() :: acc);;\n\nlet rec countsame i n s acc = \n\tif i==(n-1) then acc\n\telse\n\t\tlet nacc = (if s.[i]==s.[i+1] then acc+1 else acc) in\n\t\tcountsame (i+1) n s nacc;;\t\n\nlet main () =\n\tlet n = gr () in\n\tlet s = grs() in\n\tlet ns = countsame 0 n s 0 in\n\t(print_int ns; print_newline());;\n\nmain();;\n", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"}
{"source_code": "let s=read_int() in\nlet rec find now = \n if s mod now=0 then Printf.printf \"%d %d\" now (s/now) else find (now-1) in\nfind  (int_of_float (sqrt (float_of_int s)))", "src_uid": "f52af273954798a4ae38a1378bfbf77a"}
{"source_code": "let rec gcd n m = \n    match m with\n    | 0 -> n\n    | _ -> gcd m (n mod m)\n;;\n\nlet lcm n m = n * m / (gcd n m)\n\nlet handle_input n m z = \n    let d = lcm n m in\n    let count = z / d in\n    begin\n        print_int count;\n        print_newline;\n    end\n;;\n        \n\nlet read_ints () =\n    Scanf.bscanf Scanf.Scanning.stdin \"%i %i %i\" handle_input\n;;\n\nread_ints ();;", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"}
{"source_code": "let _ =\n  Printf.printf \"25\\n\"\n", "src_uid": "dcaff75492eafaf61d598779d6202c9d"}
{"source_code": "open Big_int\n\nlet yolo = Big_int.big_int_of_int 1000000007;;\n\nlet rec pow p x = function\n    | 0 -> Big_int.big_int_of_int 1\n    | i -> let sq = pow p x (i/2) in\n               if i mod 2 = 0\n                   then Big_int.mod_big_int (Big_int.mult_big_int sq sq) p\n                   else Big_int.mod_big_int (Big_int.mult_big_int (Big_int.mod_big_int (Big_int.mult_big_int sq sq) p) x) p\n\nlet rec find tab i =\n    if tab.(i) = i\n        then i\n        else find tab (tab.(i))\n\nlet main () =\n    let (p,k) = Scanf.scanf \"%s %s\" (fun i j -> (Big_int.big_int_of_string i,Big_int.big_int_of_string j)) in\n    let tab = Array.init (Big_int.int_of_big_int p) (fun i -> i) and tab' = Array.make (Big_int.int_of_big_int p) false and res = ref (-1) in\n        for i = 0 to (Big_int.int_of_big_int p)-1 do\n             tab.(i) <- find tab (tab.(Big_int.int_of_big_int (Big_int.mod_big_int(Big_int.mult_big_int k (Big_int.big_int_of_int i)) p)));\n        done;\n        for i = 0 to (Big_int.int_of_big_int p)-1 do\n            let a = find tab (tab.(i)) in\n                if not (tab'.(a))\n                    then (incr res; tab'.(a) <- true);\n        done;\n        match Big_int.int_of_big_int k with\n            | 0 -> Printf.printf \"%s\" (Big_int.string_of_big_int (pow yolo p ((Big_int.int_of_big_int p) - 1)))\n            | 1 -> Printf.printf \"%s\" (Big_int.string_of_big_int (pow yolo p (Big_int.int_of_big_int p)))\n            | _ -> Printf.printf \"%s\" (Big_int.string_of_big_int (pow yolo p !res));;\n\nmain ();;\n", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"}
{"source_code": "let readLine () : int * int =\n  let makePair x y = (x,y) in\n    Scanf.sscanf (read_line ()) \"%d %d\" makePair\n\nlet getInput () = \n  let numDays, sumTime = readLine () in\n  let rec helper currDay accum =\n    if currDay > numDays\n    then accum\n    else helper (currDay + 1) ((readLine ()) :: accum)\n  in\n  let workMinMaxes = List.rev (helper 1 []) in\n    (numDays, sumTime, workMinMaxes)\n\nlet homogenizeConstraints sumTime dayConstraints =\n  let folder (min, max) (currSumTime, newMaxes) = \n    (currSumTime - min, max - min :: newMaxes)\n  in\n    List.fold_right folder dayConstraints (sumTime, [])\n\n(* this guy counts up *)\nlet getReducedWorkTimes reducedSum reducedMaxes =\n  let folder reducedMax (currSum, workTimes) =\n    let todaysWorkTime = min (reducedSum - currSum) reducedMax in\n      (currSum + todaysWorkTime, todaysWorkTime :: workTimes)\n  in\n    List.fold_right folder reducedMaxes (0, [])\n\nlet negative = \"NO\\n\"\nlet positive = \"YES\\n\"\n\n(* main part *)\nlet () =\n  let numDays, sumTime, dayBounds = getInput () in\n  let reducedSumTime, reducedMaxes = homogenizeConstraints sumTime dayBounds in\n    if reducedSumTime < 0\n    then print_string negative\n    else \n        let (reducedTotalSum, reducedTimes) = getReducedWorkTimes reducedSumTime reducedMaxes in\n          if reducedTotalSum < reducedSumTime\n          then print_string negative\n          else \n            let actualWorkTimes = List.map2 (fun reducedTime (min, max) -> reducedTime + min) reducedTimes dayBounds in\n              print_string positive;\n              List.iter (Printf.printf \"%d \") actualWorkTimes;\n              print_newline ();\n", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"}
{"source_code": "(* Hungry Student Problem 903 A *)\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet debug = false;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec one_case n7 k = \n\tif k < 0 then false\n\telse if n7 < 0 then false\n\telse if (k mod 3) == 0 then true \n\telse one_case (n7 - 1) (k - 7);;\n\nlet main() =\n\tlet n = gr() in\n\tbegin\n\t\tfor i = 1 to n do\n\t\t\tlet x = gr() in\n\t\t\tlet can = one_case 3 x in\n\t\t\tlet ans = if can then \"YES\\n\" else \"NO\\n\" in\n\t\t\tprint_string ans\n\t\tdone\n\tend;;\n\nmain();;", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"}
{"source_code": "let moy tab =\n\tlet compt = ref 0. in\n\tfor i=0 to Array.length tab -1 do\n\t\tcompt := tab.(i) *. (float_of_int i) +. !compt;\n\tdone;\n\t!compt;;\n\n\nlet f n t p =\n\tlet mat = Array.make_matrix (t+1) (n+1) 0. in\n\tmat.(0).(0) <- 1.;\n\tfor i=1 to t do\n\t\tmat.(i).(0) <- (1. -. p) *. mat.(i-1).(0);\n\tdone;\n\tfor i=1 to t do\n\t\tfor j=1 to min i n do\n\t\t\tmat.(i).(j) <- p *. mat.(i-1).(j-1) \n\t\t\t\t      +. (if j=n then 1. else (1. -. p)) *. mat.(i-1).(j);\n\t\tdone;\n\tdone;\n\tmoy (mat.(t));;\n\nlet formatte x =\n\tlet partie_ent = int_of_float x in\n\tlet partie_dec = int_of_float (100. *. (x -. float_of_int partie_ent)) in\n\tif partie_dec = 0\n\t\tthen Printf.printf \"%d\" partie_ent\n\t\telse if partie_dec mod 10 = 0\n\t\t\tthen Printf.printf \"%d.%d\" partie_ent (partie_dec / 10)\n\t\t\telse if partie_dec mod 100 = 0\n\t\t\t\tthen Printf.printf \"%d.%d\" partie_ent (partie_dec / 100)\n\t\t\t\telse if partie_dec mod 1000 = 0\n\t\t\t\t\tthen Printf.printf \"%d.%d\" partie_ent (partie_dec / 1000)\n\t\t\t\t\telse if partie_dec mod 10000 = 0\n\t\t\t\t\t\tthen Printf.printf \"%d.%d\" partie_ent (partie_dec / 10000)\n\t\t\t\t\t\telse if partie_dec mod 100000 = 0\n\t\t\t\t\t\t\tthen Printf.printf \"%d.%d\" partie_ent (partie_dec / 100000)\n\t\t\t\t\t\t\telse Printf.printf \"%d.%d\" partie_ent partie_dec;;\n\nlet main () =\n\tlet (a,b,c) = Scanf.scanf \"%d %f %d \" (fun i j k -> (i,j,k)) in\n\tPrintf.printf \"%f \" (f a c b);;\n\nmain ();;\n", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"}
{"source_code": "\nopen Scanf\n\nlet list_of_string (s: string): char list =\n  let rec loop (i: int) (l: char list): char list =\n    if i = 0\n    then l\n    else loop (i - 1) ((String.get s (i - 1)) :: l)\n  in\n  loop (String.length s) []\n\n(* CFP: list_of_string, print_yn, fold w/ termination? *)\n\ntype color =\n  | Cyan\n  | Magenta\n  | Yellow\n  | WIP\n\nlet colors: color list = [ Cyan; Magenta; Yellow; ]\n\nlet colors_of_chars (s: char list): color list =\n  let f = function\n    | 'C' -> Cyan\n    | 'M' -> Magenta\n    | 'Y' -> Yellow\n    | '?' -> WIP\n    | _ -> raise Not_found\n  in\n  List.map f s\n\nlet rec try_find (prev: color) (l: color list): int =\n  match l with\n  | [] -> 1\n  | x :: xs when x = WIP ->\n    let rec f (ret: int) (ll: color list): int =\n      if ret >= 2\n      then ret\n      else match ll with\n        | [] -> ret\n        | c :: cs when c != prev -> f (ret + try_find c xs) cs\n        | c :: cs -> f ret cs\n    in\n    f 0 colors\n  | x :: xs when x = prev -> 0\n  | x :: xs -> try_find x xs\n\nlet rec pre_scan (prev: color) (l: color list): bool =\n  match l with\n  | [] -> true\n  | x :: xs when x != WIP && prev = x -> false\n  | x :: xs -> pre_scan x xs\n\nlet () =\n  let n = scanf \" %d\" (fun a -> a) in\n  let s = scanf \" %s\" (fun a -> a) in\n  let l = list_of_string s in\n  let ll = colors_of_chars l in\n  let ret = pre_scan WIP ll && (try_find WIP ll >= 2) in\n  print_endline (if ret then \"Yes\" else \"No\")", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"}
{"source_code": "open List;;\n\nlet a n =\n\n  let rec create x = \n\n    if x = 0 then [] else\n\n    if (x mod 2 = 0) then 0::(create (x/2)) else\n\n    1::(create (x/2)) in\n\n  let solution lis = fst (fold_left (fun (l, a) x -> ((a*x)::l), a+1) ([], 1) lis ) in\n\n  filter (fun x -> x<>0) (solution (create n) );;\n\n\n\nmap (Printf.printf \"%d \") (Scanf.bscanf Scanf.Scanning.stdin \"%d\" a);;\n\n", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"}
{"source_code": "open Printf open Scanf\nmodule Lib = struct\n  let i32,i64,ist = Int64.(to_int,of_int,to_string)\n  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n  let labs = Int64.abs\n  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n  let (+=) r v = r := !r + v\n  let (-=) r v = r := !r - v\n  let ( *= ) r v = r := !r * v\n  let (/=) r v = r := !r / v\n  let (%=) r v = r := !r % v\n  let max_i64,min_i64 = Int64.(max_int,min_int)\n  (* math *)\n  let ceildiv p q = (p+q-1L) / q\n  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n  let lcm m n = m / gcd m n * n\n  module Int64_infix = struct\n    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n      let open Int64 in\n      (logand),(logor),(logxor),lognot,\n      (fun u v -> shift_left u (i32 v)),\n      (fun u v -> shift_right u (i32 v)),\n      (fun u v -> shift_right_logical u (i32 v))\n  end\n  let pow n k =\n    let rec f a n = function\n    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n    in f 1L n k\n  (* input *)\n  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n  let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n  let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n  let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n  let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n  let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n  let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n  (* utils *)\n  external id : 'a -> 'a = \"%identity\"\n  let ( *< ) f g x = f (g x)\n  let ( *> ) f g x = g (f x)\n  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n  let alen a = i64 @@ Array.length a\n  let llen l = i64 @@  List.length l\n  let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n  let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n  let fail _ = failwith \"fail\"\n  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n    let rec f0 ng ok =\n      if labs (ok - ng) <= 1L then ok\n      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n    in f0 (ng-1L*d) (ok+1L*d)\n  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)\n  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n  let rec fix f x = f (fix f) x\n  let fix_memo ?(size=10000) f x =\n    let tb = Hashtbl.create ~random:true size in\n    let rec f0 x =\n      try Hashtbl.find tb x with\n      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n    in f0 x\n  (* imperative *)\n  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n  let repm f t ?(stride=1L) m0 fbod =\n    let i,c,m = ref f,ref true,ref m0 in\n    while !i<=t && !c do match fbod !m !i with\n    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n  let repim f t ?(stride=1) m0 fbod =\n    let i,c,m = ref f,ref true,ref m0 in\n    while !i<=t && !c do match fbod !m !i with\n    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n  (* output *)\n  let print_list_mle f ls = string_of_list f ls |> print_endline\n  let print_array_mle f a = string_of_array f a |> print_endline\n  let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n  let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n  (* debug *)\n  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n  let dump_i64_list ls = print_list ist ls\n  let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n  let n = gi 0 in\n  if n=2L then printf \"2\" else printf \"1\"\n\n\n\n\n\n\n\n\n", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"}
{"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\n\tlet dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done\nend open MyInt64\nlet (%$) = Pervasives.(mod)\nlet n,m = get_2_i64 0\nlet a : [`done_ | `empty | `filled ] array array = Array.make_matrix (i32 n) (i32 m) `empty\nlet at i j = try a.(i).(j) = `filled || a.(i).(j) = `done_ with Invalid_argument _ -> false\nlet solve_ij i j w = \n\tlet f = ref true in\n\tlet u,v = w %$ 2, w /$ 2 in\n\tlet u,v = let g v = if v = 0 then -1 else v in g u,g v in\n\tfor p=0 to 2 do\n\t\tfor q=0 to 2 do\n\t\t\tif not (p=1&&q=1) then f := !f && at (i+$p*$u) (j+$q*$v)\n\t\tdone\n\tdone;\n\tif !f then (\n\t\tfor p=0 to 2 do\n\t\t\tfor q=0 to 2 do\n\t\t\t\tif not (p=1&&q=1) then a.(i+$p*$u).(j+$q*$v) <- `done_\n\t\t\tdone\n\t\tdone;\n\t)\nlet solve _ =\n\tfor i=0 to (i32 n) do\n\t\tfor j=0 to (i32 m) do\n\t\t\tsolve_ij i j 0;\n\t\t\tsolve_ij i j 1;\n\t\t\tsolve_ij i j 2;\n\t\t\tsolve_ij i j 3;\n\t\tdone\n\tdone;\n\tlet f = ref true in\n\tfor i=0 to (i32 n -$ 1) do\n\t\tfor j=0 to (i32 m -$ 1) do\n\t\t\tf := !f && a.(i).(j) <> `filled\n\t\tdone\n\tdone; !f\n\nlet () =\n\trepi 0 (i32 n -$ 1) (fun i ->\n\t\tlet s = scanf \" %s\" (fun v -> v) in\n\t\tString.iteri (fun j c ->\n\t\t\ta.(i).(j) <- if c = '#' then `filled else `empty\n\t\t) s;\n\t\t`Ok\n\t);\n\tlet r = solve 0 in\n\t(* repi 0 (i32 n -$ 1) (fun i ->\n\t\trepi 0 (i32 m -$ 1) (fun j ->\n\t\t\tprintf \"%c\" (match a.(i).(j) with `filled -> '#' | `empty -> '.' | `done_ -> ',');\n\t\t\t`Ok\n\t\t);\n\t\tprint_endline \"\";\n\t\t`Ok\n\t); *)\n\tprintf \"%s\\n\" (if r then \"YES\" else \"NO\");\n\n", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"}
{"source_code": "(* must read 64-bit integer %Ld because OCaml int is 31-bit! *)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %Ld\" (fun x -> x)\nlet l = read_int ()\nlet r = read_int ()\n\n(* repeatedly multiply a 2-3 integer by 3 and count how many are in [l, r] *)\nlet rec times_three num acc =\n    if num > r then\n        acc\n    else if num < l then\n        times_three (Int64.mul num 3L) acc\n\telse\n        times_three (Int64.mul num 3L) (acc + 1)\n\n(* repeatedly multiply a 2-3 integer by 2, then repeatedly multiply it by 3 *)\nlet rec times_two num acc =\n    if num > r then\n        acc\n    else\n        times_two (Int64.mul num 2L) (times_three num acc)\n\n(* must use 64-bit integer 1L because OCaml int is 31-bit! *)\nlet () =\n    print_int (times_two 1L 0);\n    print_newline ()\n", "src_uid": "05fac54ed2064b46338bb18f897a4411"}
{"source_code": "(* Il y a 9*(10^(n-1)) nombres à n chiffres *)\nopen Big_int\n\nlet rec dixPuiss = function\n\t| 0\t-> Big_int.big_int_of_int 1\n\t| n\t-> let demi = dixPuiss (n/2) in\n\t\t\t Big_int.mult_big_int (Big_int.mult_big_int (Big_int.big_int_of_int (1 + (n mod 2)*9)) demi) demi\n\nlet numb = function\n\t| 1\t-> Big_int.big_int_of_int 9\n\t| n\t-> Big_int.mult_big_int (Big_int.big_int_of_int 9)  (dixPuiss (n-1))\n\nlet f n =\nlet a = String.length (string_of_int n) and res = ref (Big_int.big_int_of_int 0) in\nfor i=1 to a-1 do\nres := Big_int.add_big_int !res (Big_int.mult_big_int (Big_int.big_int_of_int i) (numb i));\ndone;\nBig_int.add_big_int !res (Big_int.mult_big_int (Big_int.big_int_of_int a) (Big_int.sub_big_int (Big_int.big_int_of_int (n + 1)) (dixPuiss (a-1))));;\n\nlet () =\n\tScanf.scanf \"%d\" (fun i -> Printf.printf \"%s\" (Big_int.string_of_big_int (f i)))\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"}
{"source_code": "let solve =\n  let rec loop n lst=\n    if n = 0 then lst\n    else\n      let horseshoes = Scanf.scanf \" %d\" (fun x -> x) in\n      if List.mem horseshoes lst then loop (n-1) lst\n      else loop (n-1) (horseshoes :: lst)\n  in\n  4 - (List.length (loop 4 []))\n  \nlet _ =\n  Printf.printf \"%d\\n\" solve\n    \n", "src_uid": "38c4864937e57b35d3cce272f655e20f"}
{"source_code": "let () = \n  let goodcount = ref 0 in\n\n  let rec isgood s i = if i=7 then true else\n    s.[i] <> s.[i+1] && (isgood s (i+1))\n  in\n\n    for i=0 to 7 do\n      let r = read_line() in\n\tgoodcount := !goodcount + (if isgood r 0 then 1 else 0)\n    done;\n\n      let ans = if !goodcount = 8 then \"YES\" else \"NO\" in\n\tPrintf.printf \"%s\\n\" ans\n", "src_uid": "ca65e023be092b2ce25599f52acc1a67"}
{"source_code": "let _ =\n Scanf.scanf \"%d\" ( fun x -> Printf.printf \"%d\" ( (x+4) / 5 ) )", "src_uid": "4b3d65b1b593829e92c852be213922b6"}
{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule H = Hashtbl\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\nlet rec bsearch_min a b test =\n  if b - a = 1 then b else \n  let mid = (a-b)/2 + b in \n  if test mid then bsearch_min a mid test else \n  bsearch_min mid b test\nlet rec bsearch_max a b test = \n  if b - a = 1 then a else \n  let mid = (a-b)/2 + b in \n  if test mid then bsearch_max mid b test else \n  bsearch_max a mid test\n(* int *)\nlet sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)\nlet sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i) \n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* int, int *)\nlet (++) (a,b) (c,d) = (a+c,b+d)\nlet (--) (a,b) (c,d) = (a-c,b-d)\n(* number theory *)\nlet sieve_under len = (* len > 0 *)\n  let sieve  = Array.make len true in \n  Array.fill sieve 0 (min len 2) false;\n  let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in \n  for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;\n  sieve\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n  if b = 0 then 1,0,a else\n  let x,y,g = extgcd b (a mod b) in \n  y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n  let n' = n/2 in\n  let p = pow x n' in\n  if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n  if n = 0 then 1 else \n  let n' = n/2 in\n  let p = modpow m x n' in \n  if is_even n then (p*p mod m) else\n  (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n  let i = int_of_char c in\n  48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n  let c = read_char() in \n  if is_space c then read_letter() else c \nlet read_int () = \n  let digit c = int_of_char c - 48 in\n  let rec read n = \n    let c = read_char() in \n    if is_digit c then read (10*n + (digit c)) else \n    n \n  in\n  let rec run c = \n    if is_digit c then read (digit c) else \n    if c = '-' then begin \n      let c = read_char() in \n      if is_digit c then -read (digit c) else run c \n    end else \n    if c = '\\000' then 0 else \n    run (read_char())\n  in \n  run (read_char())\nlet read_float () = \n  let digit c = float (int_of_char c - 48) in\n  let rec read_decimial m f = \n    let c = read_char () in \n    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n  in \n  let rec read_integral n = \n    let c = read_char () in \n    if is_digit c then read_integral (10. *. n +. digit c) else \n    if c = '.' then n +. read_decimial 0.1 0.0 else \n    n \n  in \n  let rec run c = begin \n    if is_digit c then read_integral (digit c) else \n    if c = '-' then begin \n      let c = read_char() in \n      if is_digit c then -. read_integral (digit c) else \n      run c \n    end else \n    if c = '.' then read_decimial 0.1 0.0 else \n    if c = '\\000' then 0.0 else \n    run (read_char())\n  end in \n  run (read_char())\nlet read_word () = \n  let open Buffer in \n  let buf = create 128 in \n  let rec read c = \n    if is_space c || c = '\\000' then contents buf else begin  \n      add_char buf c; \n      read (read_char())\n    end \n  in\n  let rec run c = \n    if is_space c then run (read_char()) else \n    if c = '\\000' then \"\" else \n    read c \n  in \n  run (read_char())\nlet read_line () = \n  let open Buffer in \n  let buf = create (4*1024) in \n  let rec run c = \n    if c = '\\n' || c = '\\000' then contents buf else begin \n      add_char buf c;\n      run (read_char())\n    end \n  in\n  run (read_char()) \nlet newline () = print_newline()\nlet print_int n = printf \"%d\\n\" n\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\n\nlet next_permutation arr =\n  let len = Array.length arr in \n  (* find largest index i that arr.(i) < arr.(i+1) *)\n  let rec find_pivot i = \n    if i = 0 then -1 else \n    if arr.(i-1) > arr.(i) then find_pivot (i-1) else \n    i\n  in \n  (* find index that is larger than n and minimum in [a,len) *)\n  let find_swap n a = \n    for_ a len a (fun i c -> if arr.(i) > n && arr.(c) > arr.(i) then i else c)\n  in\n  let rec reverse a b = \n    if a < b then begin \n      swap arr a b; \n      reverse (a+1) (b-1)\n    end  \n  in \n  let p = find_pivot (len-1) in\n  if p = -1 then begin\n    reverse 0 (len-1); \n    false\n  end else begin\n    swap arr (p-1) (find_swap arr.(p-1) p);\n    reverse p (len-1);\n    true \n  end\n\nlet _ = \n  let mat = init 5 (fun i -> init 5 (fun j -> read_int())) in \n  let arr = init 5 (fun i -> i) in \n\n  let check () = \n    mat.(arr.(0)).(arr.(1)) + mat.(arr.(1)).(arr.(0)) +\n    mat.(arr.(1)).(arr.(2)) + mat.(arr.(2)).(arr.(1)) + \n    2*mat.(arr.(2)).(arr.(3)) + 2*mat.(arr.(3)).(arr.(2)) +\n    2*mat.(arr.(3)).(arr.(4)) + 2*mat.(arr.(4)).(arr.(3)) \n  in \n\n  let m = ref (check()) in \n  while (next_permutation arr) do assign_max m (check()) done;\n  printf \"%d\\n\" !m ", "src_uid": "be6d4df20e9a48d183dd8f34531df246"}
{"source_code": "module Int64 = struct\n  include Int64\n  let ( + ) = add\n  let ( - ) = sub\n  let ( * ) = mul\n  let ( / ) = div\n  let ( mod ) = rem\nend\n\nopen Int64\n\nlet solve k2 k3 k5 k6 =\n  let k256 = min k2 (min k5 k6) in\n  let k32 = min k3 (k2 - k256) in\n  256L * k256 + 32L * k32\n\nlet () =\n  Scanf.scanf \"%Ld %Ld %Ld %Ld \" @@ fun k2 k3 k5 k6 ->\n  solve k2 k3 k5 k6 |> Printf.printf \"%Ld\\n\"\n", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"}
{"source_code": "let input () = Scanf.scanf \"%Ld %Ld\" (fun n m -> (n, m))\n\nlet ( / ) = Int64.div\nlet ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( mod ) = Int64.rem\nlet two = Int64.of_int 2\n\nlet division_rounding_up = (fun x y ->\n    x / y + (match x mod y with\n        | 0L -> 0L\n        | _ -> 1L))\n\nlet solve (n, m) = \n    let middle = division_rounding_up n two in\n    if m > middle\n    then\n        (m - middle) * two\n    else\n        m * two - Int64.one\n\nlet print result = Printf.printf \"%Ld\\n\" result\n\nlet () = print (solve (input ()))", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"}
{"source_code": "open Scanf\nopen Printf\n\nlet name = Scanf.scanf \"%s \" ( fun x -> x)\n\nlet a = Array.make 27 0\n\nlet add_count c =\n  let i = (Char.code c) - (Char.code 'a')\n  in a.(i) <- a.(i) + 1\n\nlet () =\n  String.iter add_count name\n\nlet flag = ref true\n\nlet flip c = \n  if (c>0) then flag := (not (!flag))\n\n\nlet () = \n  Array.iter flip a\n\nlet () =\n  if (!flag) then print_endline \"CHAT WITH HER!\"\n  else\n    print_endline \"IGNORE HIM!\"\n\n\n\n\n", "src_uid": "a8c14667b94b40da087501fd4bdd7818"}
{"source_code": "let cost_per_litre city = city\n\nlet rec cost_to_city accumulated current_city city max_fuel fuel =\n  let fuel_needed_to_reach_city = city - current_city in\n  if fuel >= fuel_needed_to_reach_city then accumulated\n  else\n    let litres_to_top_up = min (max_fuel - fuel) fuel_needed_to_reach_city in\n    let cost_to_top_up = litres_to_top_up * cost_per_litre current_city in\n    cost_to_city\n      (accumulated + cost_to_top_up)\n      (current_city + 1) city max_fuel (max_fuel - 1)\n;;\n\nlet () =\n  Scanf.scanf \"%d %d\" (fun n v ->\n      print_string (string_of_int (cost_to_city 0 1 n v 0)) )\n;;\n", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"}
{"source_code": "let n = read_int()\nlet c = Array.make 101 0\nlet count c =\n  let s = Str.split (Str.regexp \" \") (read_line()) in\n  let l = List.map int_of_string (s)\n  and inc_arr i = c.(i) <- c.(i) + 1 in\n  List.iter inc_arr l;;\n\nlet find_max c m =\n  let f x = \n    m := max !m x in\n  Array.iter f c;;\n\ncount c;;\nlet m = ref 0;;\nfind_max c m;;\nPrintf.printf \"%d\" !m;;\n", "src_uid": "f30329023e84b4c50b1b118dc98ae73c"}
{"source_code": "let flip  f a b = f b a in\nlet n = read_line () |> Str.split (Str.regexp \" +\") |> (flip List.nth) 0 |> int_of_string in\ntry begin\n   for i = 1 to n do\n     let c = read_line () in\n     if String.contains c 'C' || String.contains c 'M' || String.contains c 'Y' then failwith \"Color\" else () \n   done;\n   print_string \"#Black&White\"\nend\nwith e ->  print_string \"#Color\"\n\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"}
{"source_code": "let bs = Scanf.Scanning.stdin\nlet xint() = Scanf.bscanf bs \" %d\" (fun x -> x)\nlet xint32() = Scanf.bscanf bs \" %ld\" (fun x -> x)\nlet xint64() = Scanf.bscanf bs \" %Ld\" (fun x -> x)\nlet xstr() = Scanf.bscanf bs \" %s\" (fun x -> x)\nlet xreal() = Scanf.bscanf bs \" %f\" (fun x -> x)\nlet printf = Printf.printf\n\nlet () = \n  let n = xint() in\n  let a = Array.make n 0 in\n  for i = 0 to n - 1 do\n    a.(i) <- xint();\n  done;\n  let ret = ref (Big_int.big_int_of_int 1) in\n  let p = ref ~-1 in\n  for i = 0 to n - 1 do\n    if a.(i) = 1 then (\n      let x = i - !p in\n      if !p != ~-1 then \n        ret := Big_int.mult_int_big_int x !ret;\n      p := i;\n    )\n  done;\n  if !p = ~-1 then printf \"0\\n\"\n  else print_endline (Big_int.string_of_big_int !ret);\n", "src_uid": "58242665476f1c4fa723848ff0ecda98"}
{"source_code": "let _ =\n    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in\n    let main () =\n        let rec game turn a b n =\n            let k = gcd n (if turn = 0 then a else b) in\n            if n >= k then game (1 - turn) a b (n - k) else Printf.printf \"%d\\n\" (1 - turn)\n        in\n        Scanf.scanf \" %d %d %d\" (game 0)\n    in\n    main ()\n", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"}
{"source_code": "Scanf.(Array.(\n  let s = scanf \" %s\" @@ fun v -> v in\n  init 5 (fun _ ->\n    let t = scanf \" %s\" @@ fun v -> v in\n    if s.[0]=t.[0] || s.[1]=t.[1] then\n      (print_endline \"YES\"; exit 0)\n  ); print_endline \"NO\"))", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"}
{"source_code": "let rec is_lucky a =\n  match a with\n  | 0 -> false\n  | 4 | 7 -> true\n  | _ \n    -> match a mod 10 with\n    | 4 | 7 \n      -> is_lucky (a / 10)\n    | _ \n      -> false\nin\n\nlet is_almost_lucky n =\n  let rec helper n testing =\n    if testing > n then false\n    else\n      if ((n mod testing == 0) && (is_lucky testing)) then true\n      else helper n (testing + 1)\n  in helper n 1\nin\n\nlet n = read_int() in\n\nif is_almost_lucky n then\n  Printf.printf \"YES\\n\"\nelse \n  Printf.printf \"NO\\n\"\n", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"}
{"source_code": "open Printf\nopen Scanf\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet long x = Int64.of_int x\n\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n  let (n,m) = read_pair () in\n\n  let an = (n/5)*5 in\n  let am = (m/5)*5 in\n\n  let rem = sum (an+1) (an+(n mod 5)) (fun i ->\n    sum (am+1) (am+(m mod 5)) (fun j ->\n      if (i+j) mod 5 = 0 then 1 else 0))\n  in\n\n  let rem_n = sum (an+1) (an+(n mod 5)) (fun i -> am/5) in\n  let rem_m = sum (am+1) (am+(m mod 5)) (fun i -> an/5) in  \n  \n  printf \"%Ld\\n\" (((long (an/5)) ** (long am)) ++ (long rem) ++ (long rem_n) ++ (long rem_m))\n", "src_uid": "df0879635b59e141c839d9599abd77d2"}
{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\n\nlet two_pile_game a b =\n  let dp = Array.make_matrix (a+1) (b+1) (-1) in  (* 1 if first player win, 0 2nd player win *)\n    \n  let rec eval i j =\n    let (i,j) = (min i j, max i j) in\n    if dp.(i).(j) >= 0 then dp.(i).(j) = 1 else\n      let myval = \n\tif i=0 then j<>0 else\n\t  (exists 1 i (fun k -> not (eval (i-k) j)))\n\t  || (exists 1 j (fun k -> not (eval i (j-k))))\n\t  || (exists 1 i (fun k -> not (eval (i-k) (j-k))))\n      in\n\tdp.(i).(j) <- if myval then 1 else 0;\n\tmyval\n  in\n    eval a b\n\nlet three_pile_game a b c =\n  a lxor b lxor c <> 0\n\nlet () = \n  let n = read_int() in\n  let a = Array.init n (fun _ -> read_int()) in\n  let () = Array.sort compare a in\n  let answer = \n    if n=1 then a.(0) > 0\n    else if n=2 then two_pile_game a.(0) a.(1)\n    else if n=3 then three_pile_game a.(0) a.(1) a.(2)\n    else failwith \"n>3\"\n  in\n    print_string(if answer then \"BitLGM\\n\" else \"BitAryo\\n\")\n", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7"}
{"source_code": "let rec get x =\tif x = 0 then 0\n\telse if x mod 2 != 0 then (get (x / 2)) + 1\n\telse get (x / 2);;\nprint_int (get (read_int ()));;\n", "src_uid": "03e4482d53a059134676f431be4c16d2"}
{"source_code": "(* O(n^3) solution, which is fine because n=100 -- could probably be done with\n * DP for larger n, but why bother! *)\n\nlet aux i j (sum, pos) el =\n    if i <= pos && pos <= j then\n        (sum + 1 - el, succ pos)\n    else\n        (sum + el, succ pos) ;;\n\nlet r = Str.regexp \" \" in\nlet n = read_int () in\nlet xs = Array.of_list (List.map int_of_string (Str.split r (read_line ()))) in\nlet m = ref 0 in\nfor i = 0 to n - 1 do\n    for j = i to n - 1 do\n        let (s, _) = Array.fold_left (aux i j) (0, 0) xs in\n        m := max !m s\n    done\ndone ;\nPrintf.printf \"%d\\n\" !m ;;\n", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"}
{"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\nlet print result = Printf.printf \"%d\\n\" result\n\nlet rotate (count, prev) goal =\n    let p = Pervasives.int_of_char prev in\n    let g = Pervasives.int_of_char goal in\n    let min = Pervasives.min p g in\n    let max = Pervasives.max p g in\n    let rotate_right = max - min in\n    let rotate_left = min + 26 - max in\n    let r = Pervasives.min rotate_left rotate_right in\n    (count + r, goal)\n    \nlet solve str = \n    let l = String.length str in \n    let rec loop i (count, prev) =\n        if i < l\n        then\n            let (count, prev) = rotate (count, prev) str.[i] in\n            loop (i + 1) (count, prev)\n        else\n            count\n    in loop 0 (0, 'a')\n    \nlet () = print (solve (input ()))", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"}
{"source_code": "let solve n m = \n  let dynarray = Array.make (max (m*2+1) (n+1)) false in\n  let queue = Queue.create () in\n  Queue.push (0,n) queue;\n  let rec dfs () = \n    let (i,v) = Queue.pop queue in\n    if v = m then i\n    else if dynarray.(v) then dfs ()\n    else if v > m then begin\n      Queue.push (i+1,v-1) queue;\n      dynarray.(v) <- true;\n      dfs ()\n    end else begin\n      Queue.push (i+1,v*2) queue;\n      if v > 0 then \n        Queue.push (i+1,v-1) queue;\n      dynarray.(v) <- true;\n      dfs ()\n    end\n  in dfs ()\n\nlet () = \n  let s = read_line () in \n  let v = Scanf.sscanf s \"%i %i\" solve in\n  print_int v\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"}
{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n  let vl = read_int () in\n  let va = read_int () in\n\n  let rec turn_count d n count = if n<0 then count else turn_count (d+2) (n-d) (count+1) in\n\n  let vl_count = turn_count 1 vl 0 in\n  let va_count = turn_count 2 va 0 in\n\n  if vl_count <= va_count then printf \"Vladik\\n\" else printf \"Valera\\n\"\n", "src_uid": "87e37a82be7e39e433060fd8cdb03270"}
{"source_code": "let ad, b = Scanf.scanf \"%[0-9].%[0-9]e%d\" (fun a d b -> ((if d = \"0\" then a else a^d), b)) in\nlet nd = String.length ad in\nprint_string (\n    if b + 1 >= nd\n        then ad ^ String.make (b + 1 - nd) '0'\n        else String.sub ad 0 (b+1) ^ \".\" ^ String.sub ad (b+1) (nd-b-1)\n)\n", "src_uid": "a79358099f08f3ec50c013d47d910eef"}
{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet print str = Printf.printf \"%s\\n\" str\n\nlet () =\n    let first = read () in\n    let second = read () in\n    if first > second\n    then\n        print \"First\"\n    else\n        print \"Second\"", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"}
{"source_code": "open Printf\n\nexception Found\n\nlet r = ref 0\n\nlet c = ref 0\n\nlet () =\n  try \n    for i = 1 to 5 do\n      for j = 1 to 5 do\n        let n =  Scanf.scanf \"%d \" ( fun x -> x) in\n        if(n==1) then begin r:=i; c:=j; raise Found end\n      done\n    done\n  with Found -> ();;\n\n\nlet () = printf \"%d \\n\" ( abs(!r-3) + abs(!c-3) )\n", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"}
{"source_code": "let (n, k) = Scanf.scanf \"%f %f\" (fun x y -> (x, y));;\nlet num_put = (n +. k) *. 2. +. 2.25 |> sqrt |> (fun x -> x -. 1.5) |> ceil |> int_of_float;;\nPrintf.printf \"%d\\n\" ((int_of_float n) - num_put);;", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"}
{"source_code": "let solve n m k =\n  let mod_const = 1000000007 in\n  let safe_add a b = Int64.(to_int (rem (add (of_int a) (of_int b)) (of_int mod_const))) in\n  let safe_mul a b = Int64.(to_int (rem (mul (of_int a) (of_int b)) (of_int mod_const))) in\n  let scale = 10 + max n m in\n  let c = Array.init scale (fun _ -> Array.make scale 1) in\n  let () = for i = 2 to (scale-1) do\n      for j = 1 to (i-1) do\n        c.(i).(j) <- (safe_add c.(i-1).(j) c.(i-1).(j-1))\n      done\n    done\n  in\n  let k' = 2*k in\n  if k' >= n || k' >= m then 0\n  else safe_mul c.(n-1).(k') c.(m-1).(k')\n\nlet () =\n  let n, m, k = Scanf.(scanf \" %d %d %d \" (fun a b c -> (a,b,c))) in\n  Printf.printf \"%d\\n\" (solve n m k)\n", "src_uid": "309d2d46086d526d160292717dfef308"}
{"source_code": "let count = int_of_string(input_line stdin);;\nlet s = input_line stdin;;\n\nlet rec eights s i b =\n    if i == -1 then b\n    else if s.[i] == '8' then eights s (i - 1) (b + 1)\n    else eights s (i - 1) b;;\n\nlet min a b =\n    if a < b then a else b;;\n\nlet x = eights s (String.length(s) - 1) 0;;\nPrintf.printf \"%d\\n\" (min x (count / 11))", "src_uid": "259d01b81bef5536b969247ff2c2d776"}
{"source_code": "let () =\n  Scanf.scanf \"%d %d \" (fun n m ->\n    let m = min n m in\n    if m mod 2 = 0 then print_endline \"Malvika\"\n    else print_endline \"Akshat\")\n;;\n", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"}
{"source_code": "\nlet read_nums () = \n    let s = read_line () in\n    let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n    nums\n\n;;\n\nlet is_possible (t, s, x) =\n    let r = (x - t) mod s in\n    (x = t) || ( x >= (t + s) && (r = 0 || r = 1))\n\n;;\n\nlet main () =\n    let l = read_nums () in\n    match l with\n    | [t; s; x] ->  if is_possible (t, s, x) then\n                        print_string \"YES\\n\"\n                    else\n                        print_string \"NO\\n\"\n    | _ -> ()\n;;\n\n\nmain ()\n", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"}
{"source_code": "open Big_int\n\nlet pgcd = Big_int.gcd_big_int\nlet (/) = Big_int.div_big_int\nlet (+) = Big_int.add_big_int\nlet ( * ) = Big_int.mult_big_int\nlet ( - ) = Big_int.sub_big_int\nlet min = Big_int.min_big_int\nlet un = Big_int.big_int_of_int 1\n\nlet min_sol x y =\n\t(x / (pgcd x y)) * y\n\nlet count_sol x y t =\n\tlet m = min_sol x y and equalpas = min x y in\n\tlet a = t/m in\n\t\ta*equalpas + min equalpas (t - a*m + un);;\n\nlet final x y t =\n\tlet num = (count_sol x y t) - un in\n\t\tPrintf.printf \"%s/%s\" (Big_int.string_of_big_int (num / pgcd num t)) (Big_int.string_of_big_int (t / pgcd num t));;\n\nlet main () =\n\tScanf.scanf \"%s %s %s\" (fun i j k -> let [i';j';k'] = List.map Big_int.big_int_of_string [i;j;k] in final j' k' i');;\n\nmain ();;\n", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"}
{"source_code": "let cao n m = if m > n then -1. else ceil(n /. 2.0 /. m) *. m;;\nPrintf.printf \"%.0f\\n\" (Scanf.sscanf (read_line()) \"%f %f\" cao)", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"}
{"source_code": "let list_init n =\n    let rec loop i list = \n        if i < n\n        then\n            let element = Scanf.scanf \"%c\" (fun c -> c) in\n            loop (i + 1) (element :: list)\n        else\n            List.rev list\n    in loop 0 []\n\nlet input () = \n    let n = Scanf.scanf \"%d \" (fun n -> n) in\n    let letters = List.append (list_init n) ['W'] in\n    (n, letters)\n\nlet solve (n, letters) = \n    let rec loop flag count rest list = \n        match (rest, flag) with\n        | ('W' :: tail), false -> loop flag count tail list\n        | ('W' :: tail), true -> loop false 0 tail (count :: list)\n        | ('B' :: tail), _ -> loop true (count + 1) tail list\n        | [], _ -> (List.length list, List.rev list)\n    in loop false 0 letters []\n\nlet print (n, list) = \n    Printf.printf \"%d\\n\" n;\n    List.iter (Printf.printf \"%d \") list;\n    Printf.printf \"\\n\"\n\nlet () = print (solve (input ()))", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"}
{"source_code": "open Printf\nopen Scanf\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet read_int () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n  let n = read_int () in\n\n  printf \"%Ld\\n\" (n**n -- 4L**n ++ 4L)\n", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"}
{"source_code": "let (k, l, m, n, d) = Scanf.scanf \"%d %d %d %d %d\" (fun k l m n d -> k, l, m, n, d)\n\nlet if_divisible k l m n = fun int ->\n    if int mod k = 0 || int mod l = 0 || int mod m = 0 || int mod n = 0\n    then\n        true\n    else\n        false\n\nlet get_list d = \n    let rec loop i list = \n    if i <= d\n    then\n        loop (i + 1) (i :: list)\n    else\n        List.rev list\n    in loop 1 []\n\nlet solve (k, l, m, n, d) = List.length(List.filter(if_divisible k l m n) (get_list d))\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (k, l, m, n, d)) ", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"}
{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet fill_lists l = \n    let rec loop i a b =\n        if i < l\n        then\n            loop (i + 1) (read () :: a) (read () :: b)\n        else\n            (l, a, b)\n    in loop 0 [] []\n\nlet count_duplicates (l, a, b) = \n    let rec loop i count = \n        if i < l\n        then\n            let duplicates = List.filter (fun n -> n = (List.nth a i)) b in\n            loop (i + 1) (count + List.length duplicates)\n        else\n            count\n    in loop 0 0\n\nlet solve () = \n    let l = read () in\n    count_duplicates (fill_lists l)\n    \nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())", "src_uid": "745f81dcb4f23254bf6602f9f389771b"}
{"source_code": "open Printf;;\nopen Int64;;\n\nlet n = of_string (read_line()) in\nlet two = add one one in\nlet ans = if ((compare (rem n two) zero) == 0) then (div n two) else (neg (div (add n one) two)) in\nprintf \"%s\\n\" (to_string ans);;", "src_uid": "689e7876048ee4eb7479e838c981f068"}
{"source_code": "open Printf\nopen Scanf\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n  let n = read_long() in\n  let m = n // 2L in\n  if n %% 2L <> 0L then printf \"0\\n\"\n  else printf \"%Ld\\n\" ((m -- 1L) // 2L)\n", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"}
{"source_code": "Scanf.scanf \"%s %s %s %s\" @@ fun nn mm aa bb ->\n    let open Big_int in\n    let ( * ) = mult_big_int in\n    let ( - ) = sub_big_int in\n    let [n; m; a; b] = List.map big_int_of_string [nn; mm; aa; bb] in\n    let c = mod_big_int n m in\n    let aa = (m - c) * a in\n    let bb = c * b in\n        min_big_int aa bb\n        |> string_of_big_int\n        |> print_endline\n", "src_uid": "c05d753b35545176ad468b99ff13aa39"}
{"source_code": "let a = Array.create_matrix 8 8 0;;\nfor i = 0 to 7 do \n\tlet s = read_line () in\n\tfor j = 0 to 7 do \n\t\tArray.set a.(i) j\n\t\t(match (String.get s j) with\n\t\t\t| 'W' -> 1\n\t\t\t| 'B' -> 2;\n\t\t\t| _ -> 0;\n\t\t)\n\tdone;\ndone;;\nlet min1 = ref 99 and min2 = ref 99;;\nlet ff = Array.create 8 0;;\nfor i = 0 to 7 do \n\tfor j = 0 to 7 do \n\tbegin\n\t\tif (a.(i).(j) = 1) && (ff.(j) = 0) then\n\t\tbegin\n\t\t\tmin1 := min !min1 (i);\n\t\t\tArray.set ff j 1;\n\t\tend;\n\t\tif (a.(i).(j) = 2) then Array.set ff j 1\n\tend;\n\tdone;\ndone;;\nlet ff = Array.create 8 0;;\nfor i = 7 downto 0 do \n\tfor j = 0 to 7 do \n\tbegin\n\t\tif (a.(i).(j) = 2) && (ff.(j) = 0) then\n\t\tbegin\n\t\t\tmin2 := min !min2 (7- i);\n\t\t\tArray.set ff j 1;\n\t\tend;\n\t\tif (a.(i).(j) = 1) then Array.set ff j 1\n\tend;\n\tdone;\ndone;;\nif min1 <= min2 then print_char 'A'\n\telse print_char 'B';;\n\t(*\nprint_int !min1;;\nprint_endline \"\";;\nprint_int !min2;;\n*)\n", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"}
{"source_code": "(* 6:49 start        *)\nopen Printf\nopen Scanf\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n  let a = read_long () in\n  let b = read_long () in\n  let s = read_long () in\n\n  let shortest = (Int64.abs a) ++ (Int64.abs b) in\n\n  if s >= shortest && (s -- shortest) %% 2L = 0L then printf \"Yes\\n\" else printf \"No\\n\"\n\n", "src_uid": "9a955ce0775018ff4e5825700c13ed36"}
{"source_code": "let main () =\n   let (r,c,n,k) = Scanf.scanf \"%d %d %d %d\" (fun r c n k -> r,c,n,k) in\n   let mat = Array.make_matrix r c 0 in\n   let compt = ref 0 in\n      for i = 1 to n do\n         Scanf.scanf \" %d %d\" (fun x y -> mat.(x-1).(y-1) <- 1);\n      done;\n      for i=0 to r-1 do\n      for i'=i to r-1 do\n      for j=0 to c-1 do\n      for j'=j to c-1 do\n         let nb = ref 0 in\n            for i'' = i to i' do\n            for j'' = j to j' do\n               nb := !nb + mat.(i'').(j'');\n            done;\n            done;\n            if !nb >= k\n               then incr compt;\n      done;\n      done;\n      done;\n      done;\n   print_int !compt;;\n\nmain ()\n", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"}
{"source_code": "let input () = Scanf.scanf \"%d %d\" (fun x y -> (x, y))\n\nlet solve (cost, coin) = \n    let rec loop i =\n        if i <= 10\n        then \n            let total = i * cost in\n            let change = total mod 10 in\n            if change = 0 || change = coin\n            then\n                i\n            else\n                loop (i + 1)\n        else\n            failwith \"Invalid input\"\n    in loop 1\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ())) ", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"}
{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet solve () = \n    let total = read () in\n    let travel_time = read () in\n    let spare_time = 240 - travel_time in\n    let rec loop i time_left = \n        if i <= total\n        then\n            let solving_time = 5 * i in\n            if solving_time < time_left\n            then\n                loop (i + 1) (time_left - solving_time)\n            else\n                if solving_time = time_left\n                then\n                    i\n                else\n                    i - 1\n        else\n            i - 1\n    in loop 1 spare_time\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())", "src_uid": "41e554bc323857be7b8483ee358a35e2"}
{"source_code": "let ( / ) = Int64.div\nlet ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet factorial n = \n    let rec loop i acc = \n        if i >= one\n        then\n            loop (i - one) (acc * i)\n        else\n            acc\n    in loop n one\n\nlet solve () =\n    let n = Scanf.scanf \"%Ld %Ld \" (fun a b -> Pervasives.min a b) in\n    factorial n\n\nlet print result = Printf.printf \"%Ld\\n\" result\nlet () = print (solve ())", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"}
{"source_code": "let _ =\n  let n = Scanf.scanf \" %d\" (fun x -> x) in\n  let m = Scanf.scanf \" %d\" (fun x -> x) in\n  let ans = ref 0 in\n  for i = 0 to 100 do\n    for j = 0 to 100 do\n      if i * i + j = n && i + j * j = m then ans := !ans + 1\n    done\n  done;\n  print_int !ans\n", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"}
{"source_code": "let _ =\n  let mm = 1000000007L in\n  let sb = Scanf.Scanning.stdib in\n  let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let res =\n    if n = k then (\n      let res = ref 1L in\n      let ml = Int64.of_int m in\n\tfor i = 1 to (n + 1) / 2 do\n\t  res := Int64.rem (Int64.mul !res ml) mm\n\tdone;\n\t!res\n    ) else if k = 1 || n < k then (\n      let res = ref 1L in\n      let ml = Int64.of_int m in\n\tfor i = 1 to n do\n\t  res := Int64.rem (Int64.mul !res ml) mm\n\tdone;\n\t!res\n    ) else if k mod 2 = 0\n    then Int64.of_int m\n    else Int64.of_int (m * m)\n  in\n    Printf.printf \"%Ld\\n\" res\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"}
{"source_code": "let () =\n  Scanf.scanf \"%d %d \" @@ fun n l ->\n  let a = Array.init n (fun _ -> Scanf.scanf \"%d \" (fun x -> x)) in\n  let b = Array.init n (fun _ -> Scanf.scanf \"%d \" (fun x -> x)) in\n  let rec shift s =\n    if s = n then\n      print_endline \"NO\"\n    else\n      let rec check i =\n        if i = n then\n          print_endline \"YES\"\n        else if (a.(i) - b.((i + s) mod n) - a.(0) + b.(s)) mod l = 0 then\n          check (i + 1)\n        else\n          shift (s + 1) in\n      check 1 in\n  shift 0\n", "src_uid": "3d931684ca11fe6141c6461e85d91d63"}
{"source_code": "let n = read_int();;\nlet a = Array.make n [|0; 0|];;\nfor i = 0 to n -1 do\n\tArray.set a i (Array.of_list (List.map (int_of_string) ((Str.split (Str.regexp \" \") (read_line ())))));\ndone;;\nlet ans = ref (0);;\nfor i = 0 to n - 1 do for j = i + 1 to n - 1 do\n\tif (a.(i).(0) != a.(j).(0)) && (a.(i).(1) != a.(j).(1)) then ans := (a.(i).(0) - a.(j).(0)) * (a.(i).(1) - a.(j).(1));\ndone done;;\nif ((!ans) < 0) then \t\n\tans := -(!ans);;\nif !ans = 0 then ans := -1;;\nprint_int !ans;;\n", "src_uid": "ba49b6c001bb472635f14ec62233210e"}
{"source_code": "open Printf\nopen Scanf\n\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n  let dir = read_string () in\n  let input = read_string () in\n\n  let row = Array.make 3 \"\" in\n  row.(0) <- \"qwertyuiop\";\n  row.(1) <- \"asdfghjkl;\";\n  row.(2) <- \"zxcvbnm,./\";\n\n  let findletter l =\n    let p0 = try String.index row.(0) l with Not_found -> -1 in\n    let p1 = try String.index row.(1) l with Not_found -> -1 in\n    let p2 = try String.index row.(2) l with Not_found -> -1 in\n    if p0 >= 0 then (0,p0)\n    else if p1 >= 0 then (1,p1)\n    else if p2 >= 0 then (2,p2)\n    else failwith \"character not found\"\n  in\n\n  let offset = if dir = \"L\" then 1 else -1 in\n\n  for i=0 to (String.length input) -1 do\n    let (r,p) = findletter input.[i] in\n    printf \"%c\" row.(r).[p+offset];\n  done;\n  print_newline()\n", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"}
{"source_code": "let ss = \"CODEFORCES\"\n\nlet () = Scanf.scanf \"%s\" (fun s ->\n\t\t\t   let rec m pos =\n\t\t\t     if pos >= String.length ss || pos >= String.length s || s.[pos] <> ss.[pos]\n\t\t\t     then pos\n\t\t\t     else m (pos + 1)\n\t\t\t   in\n\t\t\t   let l = m 0 in\n\t\t\t   print_endline (if String.length s >= String.length ss && Str.string_after ss l = Str.last_chars s ((String.length ss) - l)\n\t\t\t\t\t  then \"YES\" else \"NO\"))\n", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"}
{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n    let n = read_int () and k = read_int () in\n    let a = Array.init n read_int in\n    let sum = Array.fold_left (+) 0 a\n    and ans = ref 0 in\n    for i = 0 to k - 1 do\n        let j = ref i\n        and res = ref sum in\n        while !j < n do\n            res := !res - a.(!j);\n            j := !j + k\n        done;\n        ans := max !ans (abs !res)\n    done;\n    printf \"%d\\n\" !ans", "src_uid": "6119258322e06fa6146e592c63313df3"}
{"source_code": "open Printf\nopen Scanf\n\nlet () =\n    let n, m, a, b = bscanf Scanning.stdib \" %d %d %d %d \" (fun w x y z -> (w,x,y,z)) in\n    let answer = n * a in\n    let answer2 = (n / m) * b + (n - (n / m) * m) * a in\n    let answer3 = (n / m + 1) * b in\n    \n    let answer4 = if answer > answer2 then answer2 else answer in\n    let answer5 = if answer3 > answer4 then answer4 else answer3 in\n    printf \"%d\\n\" answer5\n", "src_uid": "faa343ad6028c5a069857a38fa19bb24"}
{"source_code": "let input () = Scanf.scanf \"%d %d %s\" (fun l n s -> n, s)\n\nlet str_to_list s =\n    let rec loop i l =\n        if i < 0 \n        then l \n        else loop (i - 1) (s.[i] :: l) in\n    loop (String.length s - 1) []\n \n\nlet rec move = function\n    |('B' :: 'G' :: tail) -> ('G' :: 'B' :: move tail)\n    |(head :: tail) -> (head :: move tail)\n    |[] -> []\n\nlet rec loop n queue = \n    if n > 0\n    then \n        loop (n - 1) (move queue)\n    else\n        queue\n\nlet solve (n, queue) = loop n (str_to_list queue)\n\nlet () = List.iter(Printf.printf \"%c\") (solve (input()))", "src_uid": "964ed316c6e6715120039b0219cc653a"}
{"source_code": "open Printf\nopen Scanf\nopen Big_int\n\nlet main () =\n  let input = input_line stdin in\n  let n_str, m_str, a_str = sscanf input \"%s %s %s\" (fun a b c -> (a, b, c)) in\n  let n = big_int_of_string n_str in\n  let m = big_int_of_string m_str in\n  let a = big_int_of_string a_str in\n  let result = \n    let additional d = \n      big_int_of_int (match int_of_big_int (mod_big_int d a) with 0 -> 0 | _ -> 1) in\n    let vertical = add_big_int (div_big_int m a) (additional m) in\n    let horizontal = add_big_int (div_big_int n a) (additional n) in\n    let res_int = mult_big_int vertical horizontal in\n    string_of_big_int res_int\n  in\n  printf \"%s\" result;\n  ()\n\nlet _ = main ()\n", "src_uid": "ef971874d8c4da37581336284b688517"}
{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n  let n = read_int() in\n  \n  let rec digits n = if n=0 then [] else (n mod 10) :: (digits (n/10)) in\n  let dig = Array.of_list (List.rev (digits n)) in\n  \n  let m = Array.length dig in\n  let final = Array.make m 0 in\n  \n  let rec loop ac = if dig = final then ac else\n      let num = Array.make m 0 in\n      for j=0 to m-1 do\n\tnum.(j) <- if dig.(j) > 0 then 1 else 0;\n\tdig.(j) <- dig.(j) - num.(j)\n      done;\n      loop (num::ac)\n  in\n  \n  let li = loop [] in\n  \n  printf \"%d\\n\" (List.length li);\n  \n  List.iter (\n    fun a -> \n      let rec build i ac = if i=m then ac else\n\t  build (i+1) (10*ac + a.(i))\n      in\n      printf \"%d \" (build 0 0)\n  ) li;\n  print_newline()\n", "src_uid": "033068c5e16d25f09039e29c88474275"}
{"source_code": "let minNum lst target =\n  let rec f' acc l cur =\n    match l with\n      | [] -> (-1)\n      | h :: t -> let c = acc + h in\n                  if c >= target then cur + 1\n\t\t  else f' c t (cur + 1)\n  in\n  match target with\n    | 0 -> 0\n    | _ -> f' 0 lst 0\nin\nlet cmp x y =\n  if x = y then 0\n  else begin\n    if x > y then 1 else -1\n  end\nin\nlet read_nums str =\n  let nstrings = Str.split (Str.regexp \" \") str in\n  List.map (fun x -> int_of_string x) nstrings\nin\nlet k = read_int () in\nlet grows_i = List.rev (List.sort cmp (read_nums (read_line ()))) in\nprint_int (minNum grows_i k)\n", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"}
{"source_code": "open Printf open Scanf\nopen Array\n\nlet i32,i64,i64st = Int64.(to_int,of_int,to_string)\nlet labs = Int64.abs\nlet (++),(--),( ** ),(//),(%%) = Int64.(add,sub,mul,div,rem)\nlet rec gcd_i64 m n = match m,n with | m,0L -> m | m,n -> gcd_i64 n (m %% n)\nlet lcm_i64 m n = (m // gcd_i64 m n) ** n\nlet pow_i64 n k =\n  let rec f a n = function\n  | 0 -> a | 1 -> n**a | k when k mod 2 = 0 -> f a (n**n) (k/2) | k -> f (a**n) (n**n) (k/2)\n  in f 1L n k\nlet rep l r f =\n  let rec f0 i =\n    if i>r then ()\n    else (f i; f0 (i++1L))\n  in f0 l\nlet factors n = (* O(sqrt n) *)\n  let m,r = ref n,ref [] in\n  rep 2L (2L ++ Int64.of_float (sqrt @@ Int64.to_float n)) (fun i ->\n    if !m %% i = 0L then (\n      let k = ref 0L in\n      while !m %% i = 0L do\n        k := !k ++ 1L; m := !m // i;\n      done;\n      r := (i,!k) :: !r));\n  if !m>1L then (!m,1L)::!r else !r\n\nmodule ModCalc_lightweight = struct\n  let md = 1000000007L\n  (* let md = 998244353L *)\n  let pow_mod n k =\n    let rec f a n = function\n    | 0L -> a %% md\n    | 1L -> (a ** n) %% md\n    | k when k %% 2L = 0L -> f a ((n ** n) %% md) (k//2L)\n    | k -> f ((a ** n) %% md) n (k--1L)\n    in f 1L n k\n  let posmod v =\n    if v<0L then\n      (v ++ (-1L ** v // md ++ 1L) ** md) %% md\n    else v\n  let rec extgcd a b =\n    if b = 0L then 1L,0L,a\n    else\n      let y,x,d = extgcd b (a %% b) in\n      x,(y -- (a//b) ** x),d\n  (* let inv v = pow_mod v (md--2L) *)\n  let inv v =\n    let x,_,_ = extgcd v md in\n    let x = posmod x in\n    (md ++ (x %% md)) %% md\n  let (/%) p q = (p ** (inv q)) %% md\nend open ModCalc_lightweight\n\nlet () = scanf \" %Ld %d\" @@ fun n k ->\n  let arr = factors n |> of_list in\n  let res = ref 1L in\n  iter (fun (p,q) ->\n    let q = i32 q in\n    let dp = make (q+1) 0L in\n    dp.(q) <- 1L;\n    for _=1 to k do\n      let acc = ref 0L in\n      for j=q downto 0 do\n        acc := (!acc ++ dp.(j) /% (i64 @@ j+1)) %% md;\n        dp.(j) <- !acc;\n      done;\n    done;\n    let r = ref 0L in\n    let pw = ref 1L in\n    for j=0 to q do\n      r := !r ++ (dp.(j) ** !pw) %% md;\n      pw := (!pw ** p) %% md;\n    done;\n    res := !res ** (!r %% md);\n    res := !res %% md;\n  ) arr;\n  printf \"%Ld\" !res\n\n\n", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"}
{"source_code": "(*\n    Author: sighduck\n    URL: https://codeforces.com/problemset/problem/4/A\n*)\n\nlet solve (w: int) : string =\n    if w mod 2 == 0 && w > 2 then \"YES\\n\"\n    else \"NO\\n\" ;;\n\nlet main =\n    read_int () |> solve |> print_string ;;\n", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"}
{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";;\nlet b2i x = if x == true then 1 else 0;;\n\nopen Int64;;\nlet n = Int64.of_int(scan_int()) and m = Int64.of_string(scan_string());;\nprint_int(Int64.to_int(max zero (sub n (mul (Int64.of_int 2) m)))); psp();\n\nfor i = 0 to Int64.to_int(n) do\n  let j = Int64.of_int(i) in\n  if div (mul j (pred j)) (Int64.of_int 2) >= m then begin\n    print_int(Int64.to_int(n) - i); exit 0;\n  end;\ndone;;\n", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"}
{"source_code": "open Printf\nopen Scanf\n\nlet l2n c = (int_of_char c) - (int_of_char 'a')\nlet n2l n = char_of_int ((int_of_char 'a') + n)\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n  let s = read_string () in\n  let t = read_string () in\n\n  let n = String.length s in\n\n  let ns = Array.init n (fun i -> l2n s.[i]) in\n  \n  let c = ref 1 in\n  for i=n-1 downto 0 do\n    ns.(i) <- ns.(i) + !c;\n    if ns.(i) = 26 then (\n      ns.(i) <- 0;\n      c := 1;\n    ) else (\n      c := 0;\n    )\n  done;\n\n  if forall 0 (n-1) (fun i -> n2l ns.(i) = t.[i]) then (\n    printf \"No such string\\n\"\n  ) else (\n    for i=0 to n-1 do\n      printf \"%c\" (n2l ns.(i))\n    done;\n    print_newline()\n  )\n", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"}
{"source_code": "open Printf\nopen Scanf\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n  let x = read_long() in\n\n  let rec digits x = if x=0L then [] else (Int64.to_int (x %% 10L))::(digits (x//10L)) in\n\n  List.iteri (fun i d -> \n    let d = if i=0 && d=9 then d else min (9-d) d in\n    printf \"%d\" d;\n  ) (List.rev (digits x));\n\n  print_newline()\n", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"}
{"source_code": "module SS = Set.Make(String);;\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x)\nlet read_line () = Scanf.scanf \" %s\" (fun x -> x)\n\nlet (--) i j = \n    let rec aux n acc =\n        if n < i then acc else aux (n-1) (n :: acc)\n    in aux j []\n\nlet break str i =\n    let n = String.length str in\n    let a = String.sub str 0 i in\n    let b = String.sub str i (n - i) in\n    (a,b)\n\nlet print_set s = SS.iter print_endline s\n\nlet () = \n    let set = SS.empty in\n    let str = read_line () in\n    let n = String.length str in\n    let alphabet = List.map Char.chr (Char.code('a') -- Char.code('z')) in\n    let set = List.fold_right (fun i set ->\n        List.fold_right (fun j set ->\n            let (a,b) = break str j in\n            SS.add (a ^ (Char.escaped i) ^ b) set\n        ) (0 -- n) set\n    ) alphabet set in\n    Printf.printf \"%d\\n\" (SS.cardinal set);\n", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"}
{"source_code": "let rec r a b n =\n    if a = Int64.zero then n\n    else\n        if a >= b then\n            r (Int64.sub a (Int64.mul (Int64.div a b) b)) b (Int64.add n (Int64.div a b))\n        else\n            r b a n ;;\n\nPrintf.printf \"%Ld\\n\" (Scanf.scanf \"%Ld %Ld\" (fun a b -> r a b Int64.zero)) ;;\n", "src_uid": "792efb147f3668a84c866048361970f8"}
{"source_code": "let permute n visit =\n  let a = Array.init n (fun i -> i + 0)\n  and b = Array.init n (fun i -> i)\n  and c = Array.make (n + 1) 0 in\n  let k = ref 1 in\n  let j = ref 1 in\n    try\n      while true do\n\tvisit a;\n\tk := 1;\n\twhile c.(!k) = !k do\n\t  c.(!k) <- 0;\n\t  incr k\n\tdone;\n\tif !k = n then\n\t  raise Not_found;\n\tc.(!k) <- c.(!k) + 1;\n\tlet t = a.(0) in\n\t  a.(0) <- a.(b.(!k));\n\t  a.(b.(!k)) <- t;\n\t  j := 1;\n\t  k := !k - 1;\n\t  while !j < !k do\n\t    let t = b.(!j) in\n\t      b.(!j) <- b.(!k);\n\t      b.(!k) <- t;\n\t      incr j;\n\t      k := !k - 1;\n\t  done\n      done\n    with\n      | Not_found -> ()\n\nexception Found\n\nlet _ =\n  let sb = Scanf.Scanning.stdib in\n  let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let a = Array.make (n * n) 0 in\n  let () =\n    for i = 0 to n * n - 1 do\n      let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- k\n    done\n  in\n  let s =\n    let s = ref 0 in\n      for i = 0 to n * n - 1 do\n\ts := !s + a.(i)\n      done;\n      !s / n\n  in\n  let b = Array.make_matrix n n 0 in\n  let visit p =\n    for i = 0 to n - 1 do\n      for j = 0 to n - 1 do\n\tb.(i).(j) <- a.(p.(i * n + j))\n      done\n    done;\n    try\n      for i = 0 to n - 1 do\n\tlet r = ref 0 in\n\t  for j = 0 to n - 1 do\n\t    r := !r + b.(i).(j)\n\t  done;\n\t  if !r <> s\n\t  then raise Not_found\n      done;\n      for i = 0 to n - 1 do\n\tlet r = ref 0 in\n\t  for j = 0 to n - 1 do\n\t    r := !r + b.(j).(i)\n\t  done;\n\t  if !r <> s\n\t  then raise Not_found\n      done;\n      (let r = ref 0 in\n\t for j = 0 to n - 1 do\n\t   r := !r + b.(j).(j)\n\t done;\n\t if !r <> s\n\t then raise Not_found\n      );\n      (let r = ref 0 in\n\t for j = 0 to n - 1 do\n\t   r := !r + b.(j).(n - 1 - j)\n\t done;\n\t if !r <> s\n\t then raise Not_found\n      );\n      raise Found\n    with\n      | Not_found -> ()\n  in\n    try\n      if n <= 3 then (\n\tpermute (n * n) visit;\n\tassert false\n      ) else (\n\t(*for i = 15 downto 1 do\n\t  let j = Random.int (i + 1) in\n\t  let t = a.(i) in\n\t    a.(i) <- a.(j);\n\t    a.(j) <- t;\n\tdone;*)\n\tArray.sort compare a;\n\tlet u = Array.make 16 false in\n\t  for i = 0 to 15 do\n\t    if not (Array.unsafe_get u i) && not (i > 0 && not u.(i - 1) && a.(i - 1) = a.(i)) then (\n\t      let i11 = i in\n\t      Array.unsafe_set u i true;\n\t      let a11 = Array.unsafe_get a i in\n\t\tfor i = 0 to 15 do\n\t\t  if not (Array.unsafe_get u i) && not (i > 0 && not u.(i - 1) && a.(i - 1) = a.(i)) then (\n\t\t    Array.unsafe_set u i true;\n\t\t    let a22 = Array.unsafe_get a i in\n\t\t      for i = 0 to 15 do\n\t\t\tif not (Array.unsafe_get u i) && not (i > 0 && not u.(i - 1) && a.(i - 1) = a.(i)) then (\n\t\t\t  Array.unsafe_set u i true;\n\t\t\t  let a33 = Array.unsafe_get a i in\n\t\t\t    for i = i11 + 1 to 15 do\n\t\t\t      if not (Array.unsafe_get u i) && not (i > 0 && not u.(i - 1) && a.(i - 1) = a.(i)) then (\n\t\t\t\tArray.unsafe_set u i true;\n\t\t\t\tlet a44 = Array.unsafe_get a i in\n\t\t\t\t  if a11 + a22 + a33 + a44 = s then (\n\t\tfor i = i11 + 1 to 15 do\n\t\t  let i41 = i in\n\t\t  if not (Array.unsafe_get u i) then (\n let f () =\n\t\t    Array.unsafe_set u i true;\n\t\t    let a41 = Array.unsafe_get a i in\n\t\t      for i = 0 to 15 do\n\t\t\tif not (Array.unsafe_get u i) then (\n\t\t\t  Array.unsafe_set u i true;\n\t\t\t  let a32 = Array.unsafe_get a i in\n\t\t\t    for i = 0 to 15 do\n\t\t\t      if not (Array.unsafe_get u i) then (\n\t\t\t\tArray.unsafe_set u i true;\n\t\t\t\tlet a23 = Array.unsafe_get a i in\n\t\t\t\t  for i = i11 + 1 to 15 do\n\t\t\t\t    if not (Array.unsafe_get u i) then (\n\t\t\t\t      Array.unsafe_set u i true;\n\t\t\t\t      let a14 = Array.unsafe_get a i in\n\t\t\t\t\tif i < i41 && a41 + a32 + a23 + a14 = s then (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a34 = Array.unsafe_get a i in\n\t\t\tfor i = 0 to 15 do\n\t\t\t  if not (Array.unsafe_get u i) then (\n\t\t\t    Array.unsafe_set u i true;\n\t\t\t    let a31 = Array.unsafe_get a i in\n\t\t\t      if a31 + a32 + a33 + a34 = s then (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a21 = Array.unsafe_get a i in\n\t\t\tif a11 + a21 + a31 + a41 = s then (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a24 = Array.unsafe_get a i in\n\t\t\tif a21 + a22 + a23 + a24 = s &&\n\t\t\t  a14 + a24 + a34 + a44 = s\n\t\t\tthen (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a12 = Array.unsafe_get a i in\n\t\t\tfor i = 0 to 15 do\n\t\t\t  if not (Array.unsafe_get u i) then (\n\t\t\t    Array.unsafe_set u i true;\n\t\t\t    let a42 = Array.unsafe_get a i in\n\t\t\t      if a12 + a22 + a32 + a42 = s then (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a43 = Array.unsafe_get a i in\n\t\t\tif a41 + a42 + a43 + a44 = s then (\n\t\t  for i = 0 to 15 do\n\t\t    if not (Array.unsafe_get u i) then (\n\t\t      Array.unsafe_set u i true;\n\t\t      let a13 = Array.unsafe_get a i in\n\t\t\tif a13 + a23 + a33 + a43 = s &&\n\t\t\t  a11 + a12 + a13 + a14 = s\n\t\t\tthen (\n\t\t\t  let bb =\n\t\t\t    [| [| a11; a12; a13; a14 |];\n\t\t\t       [| a21; a22; a23; a24 |];\n\t\t\t       [| a31; a32; a33; a34 |];\n\t\t\t       [| a41; a42; a43; a44 |]; |]\n\t\t\t  in\n\t\t\t    for i = 0 to 3 do\n\t\t\t      for j = 0 to 3 do\n\t\t\t\tb.(i).(j) <- bb.(i).(j)\n\t\t\t      done\n\t\t\t    done;\n\t\t\t    raise Found;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t);\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\tArray.unsafe_set u i false;\n\t\t    )\n\t\t  done;\n\t\t\t\t\t);\n\t\t\t\t\tArray.unsafe_set u i false;\n\t\t\t\t    )\n\t\t\t\t  done;\n\t\t\t\t  Array.unsafe_set u i false;\n\t\t\t      )\n\t\t\t    done;\n\t\t\t    Array.unsafe_set u i false;\n\t\t\t)\n\t\t      done;\n\t\t      Array.unsafe_set u i false;\n in f ()\n\t\t  )\n\t\tdone;\n\t\t\t\t  );\n\t\t\t\t  Array.unsafe_set u i false;\n\t\t\t      )\n\t\t\t    done;\n\t\t\t    Array.unsafe_set u i false;\n\t\t\t)\n\t\t      done;\n\t\t      Array.unsafe_set u i false;\n\t\t  )\n\t\tdone;\n\t\tArray.unsafe_set u i false;\n\t    )\n\t  done\n      )\n    with\n      | Found ->\n\t  Printf.printf \"%d\\n\" s;\n\t  for i = 0 to n - 1 do\n\t    for j = 0 to n - 1 do\n\t      Printf.printf \"%d \" b.(i).(j)\n\t    done;\n\t    Printf.printf \"\\n\";\n\t  done;\n", "src_uid": "7c806fb163aaf23e1eef3e6570aea436"}
{"source_code": "let readInput n =\n  let rec aux i acc =\n    match i with\n      | 0 -> List.rev acc\n      | i -> let v = Scanf.scanf \"%d \" (fun x -> x) in\n          aux (i-1) (v :: acc)\n  in\n    aux n []\n\nlet main = \n  let (n, s) = Scanf.scanf \"%d %d\\n\" (fun n s -> (n,s)) in\n  let volumes = readInput n in\n  let (total,maxV) = \n    List.fold_left (fun (sum,maxV) v -> (sum + v, max v maxV))\n      (0,0) volumes\n  in\n    if ((total - maxV) <= s) then Printf.printf \"YES\\n\" \n    else Printf.printf \"NO\\n\" \n      \n\n", "src_uid": "496baae594b32c5ffda35b896ebde629"}
{"source_code": "let input = read_line() |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\nlet n = List.nth input 0 and\nm = List.nth input 1 in\nlet count = ref (if m <= n then 1 else 0)  in\nbegin\nfor i = 2 to min m n do\n     if m mod i = 0 && m / i <= n then count := !count+1 else ()\ndone;\n!count |> print_int\nend\n\n", "src_uid": "c4b139eadca94201596f1305b2f76496"}
{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n  let n = read_int () in\n  let array = Array.init n (fun _ ->\n      read_int ()\n    )\n  in\n  let e = (Array.length array) - 1 in\n  if array.(e) = 0 then print_endline \"UP\"\n  else if array.(e) = 15 then print_endline \"DOWN\"\n  else if n = 1 then print_endline \"-1\"\n  else if array.(e) - array.(e - 1) > 0 then print_endline \"UP\"\n  else if array.(e) - array.(e - 1) < 0 then print_endline \"DOWN\"\n", "src_uid": "8330d9fea8d50a79741507b878da0a75"}
{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\n(* int *)\nlet intsqrt n = \n  if n < 0 then raise (Invalid_argument \"sqrt of negative int\") else \n  let rec bs a b = begin \n    if b - a = 1 then a else \n    let mid = (a+b)/2 in \n    if mid*mid <= n then bs mid b else bs a mid\n  end in \n  bs 0 (1 lsl 31)\n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* tuple *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n  if b = 0 then 1,0,a else\n  let x,y,g = extgcd b (a mod b) in \n  y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n  let n' = n/2 in\n  let p = pow x n' in\n  if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n  if n = 0 then 1 else \n  let n' = n/2 in\n  let p = modpow m x n' in \n  if is_even n then (p*p mod m) else\n  (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n  let i = int_of_char c in\n  48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n  let c = read_char() in \n  if is_space c then read_letter() else c \nlet read_int () = \n  let digit c = int_of_char c - 48 in\n  let rec read n = \n    let c = read_char() in \n    if is_digit c then read (10*n + (digit c)) else \n    n \n  in\n  let rec run c = \n    if is_digit c then read (digit c) else \n    if c = '-' then begin \n      let c = read_char() in \n      if is_digit c then -read (digit c) else run c \n    end else \n    if c = '\\000' then 0 else \n    run (read_char())\n  in \n  run (read_char())\nlet read_float () = \n  let digit c = float (int_of_char c - 48) in\n  let rec read_decimial m f = \n    let c = read_char () in \n    if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n  in \n  let rec read_integral n = \n    let c = read_char () in \n    if is_digit c then read_integral (10. *. n +. digit c) else \n    if c = '.' then n +. read_decimial 0.1 0.0 else \n    n \n  in \n  let rec run c = begin \n    if is_digit c then read_integral (digit c) else \n    if c = '-' then begin \n      let c = read_char() in \n      if is_digit c then -. read_integral (digit c) else \n      run c \n    end else \n    if c = '.' then read_decimial 0.1 0.0 else \n    if c = '\\000' then 0.0 else \n    run (read_char())\n  end in \n  run (read_char())\nlet read_word () = \n  let open Buffer in \n  let buf = create 1_000_000 in \n  let rec read c = \n    if is_space c || c = '\\000' then contents buf else begin  \n      add_char buf c; \n      read (read_char())\n    end \n  in\n  let rec run c = \n    if is_space c then run (read_char()) else \n    if c = '\\000' then \"\" else \n    read c \n  in \n  run (read_char())\nlet read_line () = \n  let open Buffer in \n  let buf = create 1_000_000 in \n  let rec run c = \n    if c = '\\n' || c = '\\000' then contents buf else begin \n      add_char buf c;\n      run (read_char())\n    end \n  in\n  run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n  let len = read_int() in \n  let _ = read_int() in \n  let arr = init len (fun i -> i,read_int()) in \n  sort (on compare snd) arr;\n  let ans = make len 0 in \n  for i = 0 to len -1 do ans.(fst arr.(i)) <- i land 1 done;\n  for i = 0 to len -1 do printf \"%d \" ans.(i) done", "src_uid": "692698d4b49ad446984f3a7a631f961d"}
{"source_code": "let _ =\n  let sb = Scanf.Scanning.stdib in\n  let a = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let c = Scanf.bscanf sb \"%d \" (fun s -> s) in\n  let p = ref 387420489 in\n  let b = ref 0l in\n    while !p > 0 do\n      let da = (a / !p) mod 3 in\n      let dc = (c / !p) mod 3 in\n      let db = (dc - da + 3) mod 3 in\n\tb := Int32.add !b (Int32.mul (Int32.of_int db) (Int32.of_int !p));\n\tp := !p / 3;\n    done;\n    Printf.printf \"%ld\\n\" !b\n", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"}
{"source_code": "let check_stairs a b =\n\tmatch (max a b) - (min a b) with\n\t\t|0 when a = 0 -> print_endline \"NO\";\n\t\t|0 |1 -> print_endline \"YES\";\n\t\t|_ -> print_endline \"NO\"\n;;\n\nScanf.bscanf Scanf.Scanning.stdin \" %i %i \" check_stairs\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"}
{"source_code": "\nlet dodaj_do_listy a x =\n    x :: a\n;;\n\nlet wczytaj () =\n    Scanf.scanf \" %d\" (fun i -> i)\n;;\n\nlet wczytaj_i_wypisz () =\n    Printf.printf \"%d\" (wczytaj ())\n;;\n\nlet wczytaj_liste () = \n    let n = wczytaj () in \n        let rec dodaj licznik =\n             match licznik with\n             | 0 -> []\n             | licznik -> \n                let x = wczytaj () in\n                    dodaj_do_listy (dodaj (licznik-1)) x\n        in dodaj n\n;;\n\nlet main () = \n    let moja_lista = wczytaj_liste () in\n        let sumka = List.fold_left ( + ) 0 moja_lista in\n            match sumka with\n            | 0 -> false\n            | sumka -> true\n;;\n\nlet sprawdz czy_nie_zero = \n    match czy_nie_zero with\n    | false -> \"EASY\"\n    | czy_nie_zero -> \"HARD\"\n;;\n\nlet _ = Printf.printf \"%s\" (sprawdz (main ()))\n            \n\n                        \n", "src_uid": "060406cd57739d929f54b4518a7ba83e"}
{"source_code": "let input () = Scanf.scanf \"%d\" (fun x -> x)\n\nlet solve input =\n    let rec loop i rest last = \n        if rest > 0\n        then \n            let layer = i + last in\n                if layer <= rest\n                then\n                    loop (i + 1) (rest - layer) layer\n                else\n                    (i - 1)\n        else\n            (i - 1) \n    in loop 1 input 0\n    \nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))\n         ", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"}
{"source_code": "print_int (Scanf.scanf \"%d %d %d\" (fun n a b -> \n\tlet i = ref 0 in\n\tlet _ = (for p = 1 to n do\n\t\tif p > a && (n-p-1) < b then incr i \n\tdone) in !i\n));;\n", "src_uid": "51a072916bff600922a77da0c4582180"}
{"source_code": "\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);; \nlet read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x);; \n\nlet pages = read_int();;\n\nlet r = Array.make 7 0;;\n\nlet () =\n  for i=0 to 6 do\n    r.(i) <- read_int()\n  done;;\n\nlet rec day left current = \n  if left <= r.(current) then current else day (left-r.(current)) ((current+1) mod 7)\n\n;;\nPrintf.printf \"%d\\n\" ((day pages 0) + 1)", "src_uid": "007a779d966e2e9219789d6d9da7002c"}
{"source_code": "let bs = Scanf.Scanning.stdin\nlet xint() = Scanf.bscanf bs \" %d\" (fun x -> x)\nlet xint32() = Scanf.bscanf bs \" %ld\" (fun x -> x)\nlet xint64() = Scanf.bscanf bs \" %Ld\" (fun x -> x)\nlet xstr() = Scanf.bscanf bs \" %s\" (fun x -> x)\nlet xreal() = Scanf.bscanf bs \" %f\" (fun x -> x)\nlet printf = Printf.printf\n\nlet () = \n  let n = xint() in\n  let mx = ref 0 and mi = ref n in\n  let check n = n mod 7 <= 1 in\n  for s = 0 to 6 do\n    let cnt = ref 0 in\n    for i = 0 to n - 1 do\n      cnt := !cnt + (if check (s + i) then 1 else 0)\n    done;\n    if !cnt > !mx then mx := !cnt;\n    if !cnt < !mi then mi := !cnt;\n  done;\n  printf \"%d %d\\n\" !mi !mx;\n\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"}
{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n  let n = read_int () in\n  let m = read_int () in\n\n  let rec form_team i j ac =\n    if i+j < 3 || i=0 || j=0 then ac else (\n      let (i,j) = (max i j, min i j) in\n      form_team (i-2) (j-1) (ac+1)\n    )\n  in\n  \n  printf \"%d\\n\" (form_team n m 0)\n", "src_uid": "0718c6afe52cd232a5e942052527f31b"}
{"source_code": "let main () =\n    let (a,b,c,x,y,z) = Scanf.scanf \"%d %d %d %d %d %d\" (fun i j k l m n -> (i,j,k,l,m,n)) in\n    let a' = a - x and b' = b - y and c' = c - z in\n    let too_much = List.fold_left (+) 0 (List.map (fun i -> if i > 0 then i / 2 else i) [a';b';c']) in\n        print_endline\n        (if too_much >= 0 then \"Yes\" else \"No\");;\n\nmain ();;\n \n", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"}
{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n  let n = read_int () in\n  let a = Array.init n (fun _ -> read_int()) in\n\n  let rec find i x = if a.(i) = x then i else find (i+1) x in\n\n  let one = find 0 1 in\n  let last = find 0 n in\n\n  let opt1 = max ((n-1) - last) last in\n  let opt2 = max ((n-1) - one) one in\n\n  printf \"%d\\n\" (max opt1 opt2)\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"}
{"source_code": "\nlet read_nums () = \n    let s = read_line () in\n    let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n    nums\n\n;;\n\n\nlet main () =\n    let lst = read_nums () in\n    let lst = List.sort compare lst in \n    let () = match lst with\n    | [a;b;c] -> print_int (c-a)\n    | _ -> () \n    in\n    print_string \"\\n\"\n;;\n\nmain ()\n", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"}
{"source_code": "let _ =\n  let sb = Scanf.Scanning.stdib in\n  let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n  let lc = ref false in\n  let uc = ref false in\n  let d = ref false in\n  let n = String.length s in\n    for i = 0 to n - 1 do\n      match s.[i] with\n\t| 'A'..'Z' -> uc := true\n\t| 'a'..'z' -> lc := true\n\t| '0'..'9' -> d := true\n\t| _ -> ()\n    done;\n    if n >= 5 && !uc && !lc && !d\n    then Printf.printf \"Correct\\n\"\n    else Printf.printf \"Too weak\\n\"\n", "src_uid": "42a964b01e269491975965860ec92be7"}
{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet n = scan_int() and  a = Array.make 100 1 and licz = ref 1 and dwa = ref 2 and wyn = ref 1 in begin\nwhile !wyn < n do\n  wyn := (!dwa * 2 - 1) * !dwa;\n  dwa := !dwa * 2;\n  a.(!licz) <- !wyn;\n  licz := !licz +1\ndone;\nlicz := !licz -1;\nwhile n mod a.(!licz) <> 0 do\n  licz := !licz - 1\ndone;\nprint_int a.(!licz)\nend\n", "src_uid": "339246a1be81aefe19290de0d1aead84"}
{"source_code": "let input () = Scanf.scanf \"%d %d\" (fun n m -> (n, m))\n\nlet add candles hours m = \n    if hours mod m = 0\n    then\n        candles + 1\n    else\n        candles\n\nlet solve (n, m) =\n    let rec loop candles hours =\n        if candles > 0\n        then\n            loop ((add candles hours m) - 1) (hours + 1)    \n        else\n            hours - 1\n    in loop n 1\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))", "src_uid": "a349094584d3fdc6b61e39bffe96dece"}
{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n  let n = read_int() in\n    if n<=2 then Printf.printf \"-1\\n\" else (\n      for i=n downto 1 do\n\tPrintf.printf \"%d \"i\n      done\n    )\n", "src_uid": "fe8a0332119bd182a0a5b7758716317e"}
{"source_code": "let n = read_int();;\nlet a = Array.append [|0; 0|] (Array.of_list (List.map \n\t(int_of_string) (Str.split (Str.regexp \" \") (read_line()))));;\nlet fl = ref false and ans = ref 0  and kol = ref 0;;\nfor i = 0 to Array.length a - 1 do\n\tif a.(i) = 1 then ans := !ans + 1;\n\tif (a.(i) = 0) && (!fl = false) then \n\tbegin\n\t\tfl := true;\n\t\tkol := 1;\n\tend else if (a.(i) = 0) then kol := !kol + 1;\n\tif (a.(i) = 1) && (!fl = true) then\n\tbegin\n\t\tif (!kol = 1) then ans := !ans + 1;\n\t\tfl := false;\n\tend;\ndone;;\nprint_int !ans;\n", "src_uid": "2896aadda9e7a317d33315f91d1ca64d"}
{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read4 () = Scanf.scanf \"%d %d %d %d\\n\" ( fun x y z a-> x, y, z, a);;\nlet read5 () = Scanf.scanf \"%d %d %d %d %d\\n\" ( fun x y z a b-> x, y, z, a, b);;\nlet read6 () = Scanf.scanf \"%d %d %d %d %d %d\\n\" ( fun x y z a b c-> x, y, z, a, b, c);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n  if x > max_int - y then max_int\n  else x + y;;\n\nlet rec ( *$ ) x y =\n  if y = 0 then 0 else\n  if y mod 2 = 1 then x *$ (y-1) +$ x\n  else let a = x *$ (y/2) in a +$ a;;\n\nlet check o p dod min =\n  if o > p then dod\n  else if o < 0 then min\n  else 0\n\nlet _ = \n  let (x, y, z) = read3() in\n  let (x1, y1, z1) = read3() in\n  let (a1, a2, a3, a4, a5, a6) = read6 () in\n  let suma = ( check y y1 a2 a1 ) + ( check z z1 a4 a3 ) + ( check x x1 a6 a5 ) in\n  Printf.printf \"%d\\n\" suma;;\n\n\n", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"}
{"source_code": "let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib \" %Ld\" (fun x -> x)\nlet (|>) x f = f x\n\nopen Int64\n\nlet rec gcd x y =\n  if y = 0L then\n    x\n  else\n    gcd y (rem x y)\n\nlet () =\n  let a = read_int64 0 in\n  let b = read_int64 0 in\n  let x = read_int64 0 in\n  let y = read_int64 0 in\n  let d = gcd x y in\n  let xx = div x d in\n  let yy = div y d in\n  let t = min (div a xx) (div b yy) in\n  Printf.printf \"%Ld %Ld\\n\" (mul xx t) (mul yy t)\n", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"}
{"source_code": "let (d, l, v1, v2) = Scanf.scanf \"%f %f %f %f\" (fun x y z w -> x, y, z, w)\n    in Printf.printf \"%.8f\\n\" ((l -. d) /. (v1 +. v2));;\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"}
{"source_code": "(* work on Fib http://www.codeforces.ru/problemset/problem/199/A *)\nopen Scanf;;\nopen Printf;;\nopen Str;;\n\nlet rec fib0 a b f = \n  if (a + b + b) == f then (a,b)\n  else fib0 b (a+b) f;;\n\nlet rec fib2 f = match f with\n  | 0 -> (0,0)\n  | 1 -> (0,1)\n  | fi ->\n    let a = 1 in\n    let b = 1 in \n    fib0 a b fi;;       \n  \nlet fib3 fi = match fi with\n  | 0 -> (0,0,0)\n  | 1 -> (0,0,1)\n  | 2 -> (0,1,1)\n  | 3 -> (1,1,1)\n  | 5 -> (1,2,2)\n  | fii ->\n    let (a,b) = fib2 fii in\n    (a, b, b);;\n\nlet main () =\n  let fn = \"codeforce.in\" in\n  let inchan = stdin in\n  let gr () = fscanf inchan \"%d\" (fun i -> i) in \n  let fi = gr () in\n  let a,b,c = fib3 fi in\n  Printf.printf \"%n %n %n\" a b c\n  ;;\nlet _ = main();;", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"}
{"source_code": "let n=read_int() and s=read_line();;\nlet tab=Array.make (n+1) (Int64.zero);;\ntab.(1)<-(Int64.one);;\nlet sum=ref (Int64.one);;\nfor i=2 to n do\n   tab.(i)<- Int64.succ( !sum);\n   sum:= Int64.add ( !sum) (tab.(i))\ndone;;\nlet sol=ref (Int64.zero);;\nfor i=1 to n do\n   if s.[i-1]='B' then sol:= Int64.add ( !sol) (tab.(i))\ndone;;\nprint_string (Int64.to_string( !sol));;", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"}
{"source_code": "let reverse s = \n\tlet len = String.length s - 1 in\n\tlet r = String.create (len+1) in\n\tfor i = 0 to len do\n\t\tr.[i] <- s.[len-i];\n\tdone;\n\tr\n;;\n\nprint_string (if (read_line()) = (reverse (read_line())) then \"YES\" else \"NO\")\n", "src_uid": "35a4be326690b58bf9add547fb63a5a5"}
{"source_code": "let tau = atan 1.0 *. 8.0\n\nlet (|>) x f = f x\n\ntype point = float * float\n\nlet read_points () =\n  let read_point () : point =\n    Scanf.scanf \"%f %f\\n\" (fun x y -> (x,y)) in\n  let a = read_point () in\n  let b = read_point () in\n  let c = read_point () in\n  (a,b,c)\n\nlet diff (ax,ay) (bx,by)        = (bx -. ax, by -. ay)\nlet dot (ax,ay) (bx,by)         = ax *. bx +. ay *. by\nlet length a                    = dot a a |> sqrt\nlet dist a b                    = diff a b |> length\nlet ortho (x,y)                 = (y, -.x)\nlet midpoint (ax,ay) (bx,by)    = (0.5 *. (ax +. bx), 0.5 *. (ay +. by))\nlet det (ax,ay) (bx,by)         = ax *. by -. ay *. bx\nlet angle a b                   = (dot a b /. (length a) /. (length b)) |> acos\nlet part a                      = a /. tau\nlet move (ax,ay) s (bx,by)      = (ax +. s *. bx, ay +. s *. by)\n\nlet rec gcd a b =\n  if a < b\n  then gcd b a\n  else if b < 0.0001\n  then a\n  else gcd b (mod_float a b)\n\nlet get_circumcenter a b c : point =\n  let p1 = midpoint a c\n  and d1 = diff a c |> ortho\n  and p2 = midpoint b c\n  and d2 = diff b c |> ortho in\n  let rhs = diff p1 p2 in\n  let det0 = det d1 d2\n  and det1 = det rhs d2 in\n  move p1 (det1 /. det0) d1\n\nlet get_corners m a b c =\n  let alpha = angle (diff m a) (diff m b) |> part\n  and beta = angle (diff m b) (diff m c) |> part in\n  let gamma = 1.0 -. alpha -. beta in\n  let (r,n) = 1.0 /. (gcd (gcd alpha beta) gamma) |> modf in\n  if r >= 0.5 then n +. 1.0 else n\n  \nlet get_area n r =\n  let alpha = tau /. n in\n  let a_tri = r *. r /. 2.0 *. (sin alpha) in\n  n *. a_tri\n\nlet _ =\n  let (a,b,c) = read_points () in\n  let center = get_circumcenter a b c in\n  let corners = get_corners center a b c in\n  Printf.eprintf \"  n=%f\\n\" corners;\n  get_area corners (dist center a) |> Printf.printf \"%f\\n\"\n\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"}
{"source_code": "open Scanf\nopen Num\nopen Printf\nopen String\n\nlet (w,h) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d \" ( fun x y -> x,y) ;;\n\nlet area = w * h;;\nlet ntotal = ref 0;;\n\nlet () =\n  if (area < 2) then\n    ntotal := 0\n  else\n    begin\n      if (w >= 2) then\n        let nw = w / 2 in\n        ntotal := !ntotal + (nw* h);\n        ntotal := !ntotal + ((w mod 2)*(h/2))\n      else\n        ntotal := !ntotal + (h/2)\n    end\n;;\n\nlet () = print_int !ntotal; print_endline \"\";;\n", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"}
{"source_code": "let _ =\n   let l = Scanf.scanf \"%d %d %d %d %d\" (fun a b c d e -> [a;b;c;d;e]) in\n   let tab = Array.of_list (List.sort compare l) in\n   let maxi = ref 0 in\n      for i = 0 to 3 do\n         if tab.(i) = tab.(i+1)\n         then maxi := max !maxi (2 * tab.(i));\n      done;\n      for i = 0 to 2 do\n         if tab.(i) = tab.(i+1) && tab.(i+1) = tab.(i+2)\n         then maxi := max !maxi (3 * tab.(i));\n      done;\n      Printf.printf \"%d\" (List.fold_left (+) (- !maxi) l)\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"}
{"source_code": "let input () = Scanf.scanf \"%d %d %d %d %d\" (fun a b c d e -> a + b + c + d + e)\nlet solve sum =\n    if sum mod 5 <> 0 || sum = 0\n    then\n        Printf.printf \"-1\\n\"\n    else\n        Printf.printf \"%d\\n\" (sum / 5)\n    \nlet () = solve(input())", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"}
{"source_code": "open Printf;;\n\nlet split_on_whitespace s =\n  Str.split (Str.regexp \"[ \\t]+\") s\n;;\n\nlet s = read_line() in\nlet three_numbers = split_on_whitespace s in\nlet int_list = List.map int_of_string three_numbers in\nlet k = List.nth int_list 0 in\nlet w = List.nth int_list 1 in\nlet n = List.nth int_list 2 in\nlet cost = k*(n*(n+1)/2) in\nprintf \"%d\\n\" (max 0 (cost - w))", "src_uid": "e87d9798107734a885fd8263e1431347"}
{"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet k=read_int();;\nlet x=read_int();;\nlet l=ref [];;\nfor i=1 to n-1 do\n   l:=(read_int(),1)::(!l)\ndone;;\nl:=(Scanf.scanf \"%d\" (fun x->x),1)::(!l);;\n\nlet rec avance=function\n|[]->[]\n|(h,a)::[]->(h,a)::[]\n|(h,a)::(g,b)::t->if h<>g then (h,a)::(avance ((g,b)::t))\n                  else if a+b>2 then avance t\n                  else (h,a+b)::(avance t);;\n                  \nlet rec est_fige=function\n|[]->true\n|(h,a)::[]->true\n|(h,a)::(g,b)::t->if h<>g then est_fige ((g,b)::t)\n                  else false;;\n\nlet rec taille=function\n|[]->0\n|(_,_)::t->1+taille t;;\n\nlet rec taille2=function\n|[]->0\n|(_,a)::t->a+taille2 t;;\n\nlet init=taille !l;;\n\nlet rec ajout i=function\n|[]->([],false)\n|(h,a)::t->if i>1 then let (m,b)=ajout (i-1) t in ((h,a)::m,b)\n           else if x=h then (if a=2 then (t,true) else ((h,a+1)::t,true))\n           else ([],false);;\n\nlet rec faire liste=\n   if est_fige liste then liste else faire (avance liste);;       \n                  \nlet maxi=ref 0;;\n\nfor i=1 to init do\n   let (m,b)=ajout i !l in\n   if b then maxi:=max !maxi (init-taille2 (faire m))\ndone;;\n\nprint_int !maxi;;\n", "src_uid": "d73d9610e3800817a3109314b1e6f88c"}
{"source_code": "open Printf open Scanf\nmodule Lib = struct\n  let i32,i64,ist = Int64.(to_int,of_int,to_string)\n  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n  let labs = Int64.abs\n  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n  let (+=) r v = r := !r + v\n  let (-=) r v = r := !r - v\n  let ( *= ) r v = r := !r * v\n  let (/=) r v = r := !r / v\n  let (%=) r v = r := !r % v\n  let max_i64_lim,min_i64_lim = Int64.(max_int,min_int)\n  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L\n  (* math *)\n  let ceildiv p q = (p+q-1L) / q\n  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n  let lcm m n = m / gcd m n * n\n  module Int64_infix = struct\n    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n      let open Int64 in\n      (logand),(logor),(logxor),lognot,\n      (fun u v -> shift_left u (i32 v)),\n      (fun u v -> shift_right u (i32 v)),\n      (fun u v -> shift_right_logical u (i32 v))\n  end\n  let pow n k =\n    let rec f a n = function\n    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n    in f 1L n k\n  (* input *)\n  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n  let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n  let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n  let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n  let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n  let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n  let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n  (* utils *)\n  external id : 'a -> 'a = \"%identity\"\n  let ( *< ) f g x = f (g x)\n  let ( *> ) f g x = g (f x)\n  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n  let alen a = i64 @@ Array.length a\n  let llen l = i64 @@  List.length l\n  let slen s = String.length s\n  let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n  let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n  let fail _ = failwith \"fail\"\n  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n    let rec f0 ng ok =\n      if labs (ok - ng) <= 1L then ok\n      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n    in f0 (ng-1L*d) (ok+1L*d)\n  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)\n  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n  let rec fix f x = f (fix f) x\n  let fix_memo ?(size=10000) f x =\n    let tb = Hashtbl.create ~random:true size in\n    let rec f0 x =\n      try Hashtbl.find tb x with\n      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n    in f0 x\n  (* imperative *)\n  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n  let repm f t ?(stride=1L) m0 fbod =\n    let i,c,m = ref f,ref true,ref m0 in\n    while !i<=t && !c do match fbod !m !i with\n    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n  let repim f t ?(stride=1) m0 fbod =\n    let i,c,m = ref f,ref true,ref m0 in\n    while !i<=t && !c do match fbod !m !i with\n    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n  (* output *)\n  let print_list_mle f ls = string_of_list f ls |> print_endline\n  let print_array_mle f a = string_of_array f a |> print_endline\n  let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n  let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n  (* debug *)\n  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n  let dump_i64_list ls = print_list ist ls\n  let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n  let n = gi 0 in\n  let a = fix (fun f i x ->\n    if i*i > 2000000000L then x\n    else f (i+1L) ((i*i)::x)\n  ) 1L [] |> List.sort compare |> of_list in\n  let k = lower_bound a n in\n  let p = Int64.(a.(i32 k) |> to_float |> sqrt |> of_float) in\n  let q = ceildiv n p in\n  (* printf \"%Ld :: %Ld :: %Ld :: %Ld\\n\" n k p q; *)\n  printf \"%Ld\" @@ p+q\n\n  (* let m = n |> Int64.to_float |> sqrt in\n  let p,q = m |> floor |> Int64.of_float,\n    m |> ceil |> Int64.of_float in\n  (* rep m (m+100L) (fun m ->\n    if m*m >\n  ) *)\n  printf \"%Ld %Ld %Ld\\n\" n p q *)\n\n\n\n\n\n\n\n\n", "src_uid": "eb8212aec951f8f69b084446da73eaf7"}
