{"nl": {"description": "Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through $$$n \\cdot k$$$ cities. The cities are numerated from $$$1$$$ to $$$n \\cdot k$$$, the distance between the neighboring cities is exactly $$$1$$$ km.Sergey does not like beetles, he loves burgers. Fortunately for him, there are $$$n$$$ fast food restaurants on the circle, they are located in the $$$1$$$-st, the $$$(k + 1)$$$-st, the $$$(2k + 1)$$$-st, and so on, the $$$((n-1)k + 1)$$$-st cities, i.e. the distance between the neighboring cities with fast food restaurants is $$$k$$$ km.Sergey began his journey at some city $$$s$$$ and traveled along the circle, making stops at cities each $$$l$$$ km ($$$l > 0$$$), until he stopped in $$$s$$$ once again. Sergey then forgot numbers $$$s$$$ and $$$l$$$, but he remembers that the distance from the city $$$s$$$ to the nearest fast food restaurant was $$$a$$$ km, and the distance from the city he stopped at after traveling the first $$$l$$$ km from $$$s$$$ to the nearest fast food restaurant was $$$b$$$ km. Sergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.Now Sergey is interested in two integers. The first integer $$$x$$$ is the minimum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$. The second integer $$$y$$$ is the maximum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100\\,000$$$) — the number of fast food restaurants on the circle and the distance between the neighboring restaurants, respectively. The second line contains two integers $$$a$$$ and $$$b$$$ ($$$0 \\le a, b \\le \\frac{k}{2}$$$) — the distances to the nearest fast food restaurants from the initial city and from the city Sergey made the first stop at, respectively.", "output_spec": "Print the two integers $$$x$$$ and $$$y$$$.", "sample_inputs": ["2 3\n1 1", "3 2\n0 0", "1 10\n5 3"], "sample_outputs": ["1 6", "1 3", "5 5"], "notes": "NoteIn the first example the restaurants are located in the cities $$$1$$$ and $$$4$$$, the initial city $$$s$$$ could be $$$2$$$, $$$3$$$, $$$5$$$, or $$$6$$$. The next city Sergey stopped at could also be at cities $$$2, 3, 5, 6$$$. Let's loop through all possible combinations of these cities. If both $$$s$$$ and the city of the first stop are at the city $$$2$$$ (for example, $$$l = 6$$$), then Sergey is at $$$s$$$ after the first stop already, so $$$x = 1$$$. In other pairs Sergey needs $$$1, 2, 3$$$, or $$$6$$$ stops to return to $$$s$$$, so $$$y = 6$$$.In the second example Sergey was at cities with fast food restaurant both initially and after the first stop, so $$$l$$$ is $$$2$$$, $$$4$$$, or $$$6$$$. Thus $$$x = 1$$$, $$$y = 3$$$.In the third example there is only one restaurant, so the possible locations of $$$s$$$ and the first stop are: $$$(6, 8)$$$ and $$$(6, 4)$$$. For the first option $$$l = 2$$$, for the second $$$l = 8$$$. In both cases Sergey needs $$$x=y=5$$$ stops to go to $$$s$$$."}, "positive_code": [{"source_code": "\nmodule Prelude = struct\n let scanf = Scanf.scanf\n let printf = Printf.printf\n\n module Int = struct\n type t = int\n let compare = compare\n end\nend\n\nopen Prelude\n\nmodule IntSet = Set.Make(Int)\n\nlet gen_prime_t = Array.create 100000 0\nlet gen_prime (upto: int): int array =\n let rec f (n: int) (s: int): int =\n if n > upto\n then s\n else\n let rec is_prime i =\n if i >= s then true\n else\n let t = Array.get gen_prime_t i in\n if t > n / 2 then true\n else if n mod t = 0 then false\n else is_prime (i + 1)\n in f (n + 2) (if is_prime 0 then (Array.set gen_prime_t s n; s + 1) else s)\n in\n Array.set gen_prime_t 0 2;\n let l = f 3 1 in Array.sub gen_prime_t 0 l\n\nmodule PrimeFactors = struct\n type item = { factor: int; count: int; }\n type t = item list\n\n let to_string (src: t) =\n src |>\n List.map (fun { factor; count } -> Printf.sprintf \"(%d * %d)\" count factor) |>\n String.concat \" \"\n\n let get_all_factors (src: t): int list =\n let rec outer (n: int) (src: item list) (ret: int list): int list =\n match src with\n | [] -> n :: ret\n | item :: items ->\n let rec inner (i: int) (n: int) (ret: int list): int list =\n if i > item.count\n then ret\n else\n let ret = outer n items ret in\n inner (i + 1) (n * item.factor) ret\n in inner 0 n ret\n in outer 1 src []\n\nend\n\nlet factorize (primes: int array) (src: int64): PrimeFactors.t =\n let rec f (cur: int64) (i: int) (ret: PrimeFactors.t) =\n if i >= Array.length primes then ret else\n let rec g (cur: int64) (n: int): int64 * int = Int64.(\n let t = Array.get primes i in\n if (rem cur (of_int t)) = zero\n then g (div cur (of_int t)) (n + 1)\n else (cur, n)\n ) in\n let cur, t = g cur 0 in\n let ret = if t = 0 then ret else { factor = Array.get primes i; count = t } :: ret in\n f cur (i + 1) ret\n in f src 0 []\n\nlet rec gcd (lhs: int64) (rhs: int64): int64 =\n if rhs = Int64.zero\n then lhs\n (* NOTE: we don't need the second extra check, the rem will do it ... *)\n (* if lhs > rhs then gcd rhs Int64.(rem lhs rhs) *)\n else gcd rhs Int64.(rem lhs rhs)\n\nlet _ =\n (* let primes = gen_prime 100000 in *)\n (* printf \"gen complete\\n\";\n * let factors = factorize primes (Int64.of_int 720720) in\n * PrimeFactors.get_all_factors factors |> List.iter (printf \"%d\\n\")\n * printf \"%s\\n\" (factorize primes (Int64.of_int 8400) |> PrimeFactors.to_string) *)\n let n, k, a, b = scanf \"%d %d %d %d\" (fun a b c d -> a, b, c, d) in Int64.(\n let total = (mul (of_int n) (of_int k)) in\n let do_try (posb: int64) (maxv, minv): int64 * int64 =\n let time =\n let l = (sub posb (of_int a)) in\n let actual_l = gcd total l in\n (div total actual_l)\n in\n let maxv = if Int64.compare time maxv > 0 then time else maxv in\n let minv = if Int64.compare time minv < 0 then time else minv in\n (maxv, minv)\n in\n let rec test_cycle (posb: int64) (maxv, minv): int64 * int64 =\n if posb > (add total (of_int a))\n then (maxv, minv)\n else let tu = do_try posb (maxv, minv) in test_cycle (add posb (of_int k)) tu\n in\n let tu = (Int64.min_int, Int64.max_int) in\n let tu = test_cycle (sub (of_int k) (of_int b)) tu in\n let tu = test_cycle (add (of_int k) (of_int b)) tu in\n let (maxv, minv) = tu in\n printf \"%Ld %Ld\\n\" minv maxv)\n (* let factors = PrimeFactors.get_all_factors (factorize primes total) in\n * let rec f (factors: int list) (maxv: int64) (minv: int64): int64 * int64 =\n * match factors with\n * | [] -> maxv, minv\n * | l :: factors ->\n * let dist2 = (rem (add (of_int a) (of_int l)) (of_int k)) in\n * if (dist2 = (of_int b)) || (dist2 = (of_int (k - b)))\n * then\n * let time = (div total (of_int l)) in\n * let maxv = if Int64.compare time maxv > 0 then time else maxv in\n * let minv = if Int64.compare time minv < 0 then time else minv in\n * f factors maxv minv\n * else f factors maxv minv\n * in\n * let maxv, minv = f factors min_int max_int in *)\n"}, {"source_code": "\nmodule Prelude = struct\n let scanf = Scanf.scanf\n let printf = Printf.printf\n\n module Int = struct\n type t = int\n let compare = compare\n end\nend\n\nopen Prelude\n\nmodule IntSet = Set.Make(Int)\n\nlet gen_prime_t = Array.create 100000 0\nlet gen_prime (upto: int): int array =\n let rec f (n: int) (s: int): int =\n if n > upto\n then s\n else\n let rec is_prime i =\n if i >= s then true\n else\n let t = Array.get gen_prime_t i in\n if t > n / 2 then true\n else if n mod t = 0 then false\n else is_prime (i + 1)\n in f (n + 2) (if is_prime 0 then (Array.set gen_prime_t s n; s + 1) else s)\n in\n Array.set gen_prime_t 0 2;\n let l = f 3 1 in Array.sub gen_prime_t 0 l\n\nmodule PrimeFactors = struct\n type item = { factor: int; count: int; }\n type t = item list\n\n let to_string (src: t) =\n src |>\n List.map (fun { factor; count } -> Printf.sprintf \"(%d * %d)\" count factor) |>\n String.concat \" \"\n\n let get_all_factors (src: t): int list =\n let rec outer (n: int) (src: item list) (ret: int list): int list =\n match src with\n | [] -> n :: ret\n | item :: items ->\n let rec inner (i: int) (n: int) (ret: int list): int list =\n if i > item.count\n then ret\n else\n let ret = outer n items ret in\n inner (i + 1) (n * item.factor) ret\n in inner 0 n ret\n in outer 1 src []\n\nend\n\nlet factorize (primes: int array) (src: int64): PrimeFactors.t =\n let rec f (cur: int64) (i: int) (ret: PrimeFactors.t) =\n if i >= Array.length primes then ret else\n let rec g (cur: int64) (n: int): int64 * int = Int64.(\n let t = Array.get primes i in\n if (rem cur (of_int t)) = zero\n then g (div cur (of_int t)) (n + 1)\n else (cur, n)\n ) in\n let cur, t = g cur 0 in\n let ret = if t = 0 then ret else { factor = Array.get primes i; count = t } :: ret in\n f cur (i + 1) ret\n in f src 0 []\n\nlet rec gcd (lhs: int64) (rhs: int64): int64 =\n if rhs = Int64.zero\n then lhs\n (* NOTE: we don't need the second extra check, the rem will do it ... *)\n (* if lhs > rhs then gcd rhs Int64.(rem lhs rhs) *)\n else gcd rhs Int64.(rem lhs rhs)\n\nlet _ =\n (* let primes = gen_prime 100000 in *)\n (* printf \"gen complete\\n\";\n * let factors = factorize primes (Int64.of_int 720720) in\n * PrimeFactors.get_all_factors factors |> List.iter (printf \"%d\\n\")\n * printf \"%s\\n\" (factorize primes (Int64.of_int 8400) |> PrimeFactors.to_string) *)\n let n, k, a, b = scanf \"%d %d %d %d\" (fun a b c d -> a, b, c, d) in Int64.(\n let total = (mul (of_int n) (of_int k)) in\n let do_try (posb: int64) (maxv, minv): int64 * int64 =\n let time =\n let l = (sub posb (of_int a)) in\n let actual_l = gcd total l in\n (div total actual_l)\n in\n let maxv = if Int64.compare time maxv > 0 then time else maxv in\n let minv = if Int64.compare time minv < 0 then time else minv in\n (maxv, minv)\n in\n let rec test_cycle (posb: int64) (maxv, minv): int64 * int64 =\n if posb > (add total (of_int a))\n then (maxv, minv)\n else let tu = do_try posb (maxv, minv) in test_cycle (add posb (of_int k)) tu\n in\n let tu = (Int64.min_int, Int64.max_int) in\n let tu = test_cycle (sub (of_int k) (of_int b)) tu in\n let tu = test_cycle (add (of_int k) (of_int b)) tu in\n let (maxv, minv) = tu in\n (* let factors = PrimeFactors.get_all_factors (factorize primes total) in\n * let rec f (factors: int list) (maxv: int64) (minv: int64): int64 * int64 =\n * match factors with\n * | [] -> maxv, minv\n * | l :: factors ->\n * let dist2 = (rem (add (of_int a) (of_int l)) (of_int k)) in\n * if (dist2 = (of_int b)) || (dist2 = (of_int (k - b)))\n * then\n * let time = (div total (of_int l)) in\n * let maxv = if Int64.compare time maxv > 0 then time else maxv in\n * let minv = if Int64.compare time minv < 0 then time else minv in\n * f factors maxv minv\n * else f factors maxv minv\n * in\n * let maxv, minv = f factors min_int max_int in *)\n printf \"%Ld %Ld\\n\" minv maxv)\n"}, {"source_code": "\nmodule Prelude = struct\n let scanf = Scanf.scanf\n let printf = Printf.printf\n\n module Int = struct\n type t = int\n let compare = compare\n end\nend\n\nopen Prelude\n\nmodule IntSet = Set.Make(Int)\n\nlet gen_prime_t = Array.create 100000 0\nlet gen_prime (upto: int): int array =\n let rec f (n: int) (s: int): int =\n if n > upto\n then s\n else\n let rec is_prime i =\n if i >= s then true\n else\n let t = Array.get gen_prime_t i in\n if t > n / 2 then true\n else if n mod t = 0 then false\n else is_prime (i + 1)\n in f (n + 2) (if is_prime 0 then (Array.set gen_prime_t s n; s + 1) else s)\n in\n Array.set gen_prime_t 0 2;\n let l = f 3 1 in Array.sub gen_prime_t 0 l\n\nmodule PrimeFactors = struct\n type item = { factor: int; count: int; }\n type t = item list\n\n let to_string (src: t) =\n src |>\n List.map (fun { factor; count } -> Printf.sprintf \"(%d * %d)\" count factor) |>\n String.concat \" \"\n\n let get_all_factors (src: t): int list =\n let rec outer (n: int) (src: item list) (ret: int list): int list =\n match src with\n | [] -> n :: ret\n | item :: items ->\n let rec inner (i: int) (n: int) (ret: int list): int list =\n if i > item.count\n then ret\n else\n let ret = outer n items ret in\n inner (i + 1) (n * item.factor) ret\n in inner 0 n ret\n in outer 1 src []\n\nend\n\nlet factorize (primes: int array) (src: int64): PrimeFactors.t =\n let rec f (cur: int64) (i: int) (ret: PrimeFactors.t) =\n if i >= Array.length primes then ret else\n let rec g (cur: int64) (n: int): int64 * int = Int64.(\n let t = Array.get primes i in\n if (rem cur (of_int t)) = zero\n then g (div cur (of_int t)) (n + 1)\n else (cur, n)\n ) in\n let cur, t = g cur 0 in\n let ret = if t = 0 then ret else { factor = Array.get primes i; count = t } :: ret in\n f cur (i + 1) ret\n in f src 0 []\n\nlet rec gcd (lhs: int64) (rhs: int64): int64 =\n if rhs = Int64.zero\n then lhs\n (* NOTE: we don't need the second extra check, the rem will do it ... *)\n (* if lhs > rhs then gcd rhs Int64.(rem lhs rhs) *)\n else gcd rhs Int64.(rem lhs rhs)\n\nlet _ =\n (* let primes = gen_prime 100000 in *)\n (* printf \"gen complete\\n\";\n * let factors = factorize primes (Int64.of_int 720720) in\n * PrimeFactors.get_all_factors factors |> List.iter (printf \"%d\\n\")\n * printf \"%s\\n\" (factorize primes (Int64.of_int 8400) |> PrimeFactors.to_string) *)\n let n, k, a, b = scanf \"%d %d %d %d\" (fun a b c d -> a, b, c, d) in Int64.(\n let n, k, a, b = of_int n, of_int k, of_int a, of_int b in\n let total = (mul n k) in\n let do_try (posb: int64) (maxv, minv): int64 * int64 =\n let time =\n let l = (sub posb a) in\n let actual_l = gcd total l in\n (div total actual_l)\n in\n let maxv = if Int64.compare time maxv > 0 then time else maxv in\n let minv = if Int64.compare time minv < 0 then time else minv in\n (maxv, minv)\n in\n let rec test_cycle (posb: int64) (maxv, minv): int64 * int64 =\n if posb > (add total a)\n then (maxv, minv)\n else let tu = do_try posb (maxv, minv) in test_cycle (add posb k) tu\n in\n let tu = (Int64.min_int, Int64.max_int) in\n let tu = tu |> test_cycle (add k b) |> test_cycle (sub k b) in\n let (maxv, minv) = tu in\n printf \"%Ld %Ld\\n\" minv maxv)\n (* let factors = PrimeFactors.get_all_factors (factorize primes total) in\n * let rec f (factors: int list) (maxv: int64) (minv: int64): int64 * int64 =\n * match factors with\n * | [] -> maxv, minv\n * | l :: factors ->\n * let dist2 = (rem (add (of_int a) (of_int l)) (of_int k)) in\n * if (dist2 = (of_int b)) || (dist2 = (of_int (k - b)))\n * then\n * let time = (div total (of_int l)) in\n * let maxv = if Int64.compare time maxv > 0 then time else maxv in\n * let minv = if Int64.compare time minv < 0 then time else minv in\n * f factors maxv minv\n * else f factors maxv minv\n * in\n * let maxv, minv = f factors min_int max_int in *)\n"}, {"source_code": "\nmodule Prelude = struct\n let scanf = Scanf.scanf\n let printf = Printf.printf\n\n module Int = struct\n type t = int\n let compare = compare\n end\nend\n\nopen Prelude\n\nmodule IntSet = Set.Make(Int)\n\nlet gen_prime_t = Array.create 100000 0\nlet gen_prime (upto: int): int array =\n let rec f (n: int) (s: int): int =\n if n > upto\n then s\n else\n let rec is_prime i =\n if i >= s then true\n else\n let t = Array.get gen_prime_t i in\n if t > n / 2 then true\n else if n mod t = 0 then false\n else is_prime (i + 1)\n in f (n + 2) (if is_prime 0 then (Array.set gen_prime_t s n; s + 1) else s)\n in\n Array.set gen_prime_t 0 2;\n let l = f 3 1 in Array.sub gen_prime_t 0 l\n\nmodule PrimeFactors = struct\n type item = { factor: int; count: int; }\n type t = item list\n\n let to_string (src: t) =\n src |>\n List.map (fun { factor; count } -> Printf.sprintf \"(%d * %d)\" count factor) |>\n String.concat \" \"\n\n let get_all_factors (src: t): int list =\n let rec outer (n: int) (src: item list) (ret: int list): int list =\n match src with\n | [] -> n :: ret\n | item :: items ->\n let rec inner (i: int) (n: int) (ret: int list): int list =\n if i > item.count\n then ret\n else\n let ret = outer n items ret in\n inner (i + 1) (n * item.factor) ret\n in inner 0 n ret\n in outer 1 src []\n\nend\n\nlet factorize (primes: int array) (src: int64): PrimeFactors.t =\n let rec f (cur: int64) (i: int) (ret: PrimeFactors.t) =\n if i >= Array.length primes then ret else\n let rec g (cur: int64) (n: int): int64 * int = Int64.(\n let t = Array.get primes i in\n if (rem cur (of_int t)) = zero\n then g (div cur (of_int t)) (n + 1)\n else (cur, n)\n ) in\n let cur, t = g cur 0 in\n let ret = if t = 0 then ret else { factor = Array.get primes i; count = t } :: ret in\n f cur (i + 1) ret\n in f src 0 []\n\n (* NOTE: we don't need the second extra check, the rem will do it ... *)\n (* if lhs > rhs then gcd rhs Int64.(rem lhs rhs) *)\nlet rec gcd (lhs: int64) (rhs: int64): int64 =\n Int64.(if rhs = zero then lhs else gcd rhs (rem lhs rhs))\n\nlet _ =\n (* let primes = gen_prime 100000 in *)\n (* printf \"gen complete\\n\";\n * let factors = factorize primes (Int64.of_int 720720) in\n * PrimeFactors.get_all_factors factors |> List.iter (printf \"%d\\n\")\n * printf \"%s\\n\" (factorize primes (Int64.of_int 8400) |> PrimeFactors.to_string) *)\n let n, k, a, b = scanf \"%d %d %d %d\" (fun a b c d -> a, b, c, d) in Int64.(\n let n, k, a, b = of_int n, of_int k, of_int a, of_int b in\n let total = (mul n k) in\n let do_try (posb: int64) (maxv, minv): int64 * int64 =\n let time = (div total (gcd total (sub posb a))) in (* let l = (sub posb a) in let actual_l = gcd total l in *)\n ((if time > maxv then time else maxv), (if time < minv then time else minv))\n in\n let rec test_cycle (posb: int64) (maxv, minv): int64 * int64 =\n if posb > (add total a)\n then (maxv, minv)\n else test_cycle (add posb k) (do_try posb (maxv, minv))\n in\n let tu = (Int64.min_int, Int64.max_int) in\n let tu = tu |> test_cycle (add k b) |> test_cycle (sub k b) in\n let (maxv, minv) = tu in\n printf \"%Ld %Ld\\n\" minv maxv)\n (* let factors = PrimeFactors.get_all_factors (factorize primes total) in\n * let rec f (factors: int list) (maxv: int64) (minv: int64): int64 * int64 =\n * match factors with\n * | [] -> maxv, minv\n * | l :: factors ->\n * let dist2 = (rem (add (of_int a) (of_int l)) (of_int k)) in\n * if (dist2 = (of_int b)) || (dist2 = (of_int (k - b)))\n * then\n * let time = (div total (of_int l)) in\n * let maxv = if Int64.compare time maxv > 0 then time else maxv in\n * let minv = if Int64.compare time minv < 0 then time else minv in\n * f factors maxv minv\n * else f factors maxv minv\n * in\n * let maxv, minv = f factors min_int max_int in *)\n"}], "negative_code": [{"source_code": "\nmodule Prelude = struct\n let scanf = Scanf.scanf\n let printf = Printf.printf\n\n module Int = struct\n type t = int\n let compare = compare\n end\nend\n\nopen Prelude\n\nmodule IntSet = Set.Make(Int)\n\nlet gen_prime_t = Array.create 100000 0\nlet gen_prime (upto: int): int array =\n let rec f (n: int) (s: int): int =\n if n > upto\n then s\n else\n let rec is_prime i =\n if i >= s then true\n else\n let t = Array.get gen_prime_t i in\n if t > n / 2 then true\n else if n mod t = 0 then false\n else is_prime (i + 1)\n in f (n + 2) (if is_prime 0 then (Array.set gen_prime_t s n; s + 1) else s)\n in\n Array.set gen_prime_t 0 2;\n let l = f 3 1 in Array.sub gen_prime_t 0 l\n\nmodule PrimeFactors = struct\n type item = { factor: int; count: int; }\n type t = item list\n\n let to_string (src: t) =\n src |>\n List.map (fun { factor; count } -> Printf.sprintf \"(%d * %d)\" count factor) |>\n String.concat \" \"\n\n let get_all_factors (src: t): int list =\n let rec outer (n: int) (src: item list) (ret: int list): int list =\n match src with\n | [] -> n :: ret\n | item :: items ->\n let rec inner (i: int) (n: int) (ret: int list): int list =\n if i > item.count\n then ret\n else\n let ret = outer n items ret in\n inner (i + 1) (n * item.factor) ret\n in inner 0 n ret\n in outer 1 src []\n\nend\n\nlet factorize (primes: int array) (src: int64): PrimeFactors.t =\n let rec f (cur: int64) (i: int) (ret: PrimeFactors.t) =\n if i >= Array.length primes then ret else\n let rec g (cur: int64) (n: int): int64 * int = Int64.(\n let t = Array.get primes i in\n if (rem cur (of_int t)) = zero\n then g (div cur (of_int t)) (n + 1)\n else (cur, n)\n ) in\n let cur, t = g cur 0 in\n let ret = if t = 0 then ret else { factor = Array.get primes i; count = t } :: ret in\n f cur (i + 1) ret\n in f src 0 []\n\nlet _ =\n let primes = gen_prime 100000 in\n (* printf \"gen complete\\n\";\n * let factors = factorize primes (Int64.of_int 720720) in\n * PrimeFactors.get_all_factors factors |> List.iter (printf \"%d\\n\")\n * printf \"%s\\n\" (factorize primes (Int64.of_int 8400) |> PrimeFactors.to_string) *)\n let n, k, a, b = scanf \"%d %d %d %d\" (fun a b c d -> a, b, c, d) in Int64.(\n let total = (mul (of_int n) (of_int k)) in\n let factors = PrimeFactors.get_all_factors (factorize primes total) in\n let rec f (factors: int list) (maxv: int64) (minv: int64): int64 * int64 =\n match factors with\n | [] -> maxv, minv\n | l :: factors ->\n let dist2 = (rem (add (of_int a) (of_int l)) (of_int k)) in\n if (dist2 = (of_int b)) || (dist2 = (of_int (k - b)))\n then\n let time = (div total (of_int l)) in\n let maxv = if Int64.compare time maxv > 0 then time else maxv in\n let minv = if Int64.compare time minv < 0 then time else minv in\n f factors maxv minv\n else f factors maxv minv\n in\n let maxv, minv = f factors min_int max_int in\n printf \"%Ld %Ld\\n\" minv maxv)\n"}], "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"nl": {"description": "Let's write all the positive integer numbers one after another from $$$1$$$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...Your task is to print the $$$k$$$-th digit of this sequence.", "input_spec": "The first and only line contains integer $$$k$$$ ($$$1 \\le k \\le 10000$$$) — the position to process ($$$1$$$-based index).", "output_spec": "Print the $$$k$$$-th digit of the resulting infinite sequence.", "sample_inputs": ["7", "21"], "sample_outputs": ["7", "5"], "notes": null}, "positive_code": [{"source_code": "let (+) = Int64.add\nlet (--) = Int64.sub\nlet (/) = Int64.div\nlet ( * ) = Int64.mul\n\n\nlet () =\n\n let n = ref (Scanf.scanf \"%Ld\\n\" (fun x -> x)) in\n let i = ref 1 in\n let k = ref 0L in\n let res = ref 0L in\n while (!n >= 0L) do\n k := 9L;\n for _j = 1 to !i - 1 do\n k := !k * 10L\n done;\n\n res := !res + !k;\n n := !n -- !k * Int64.of_int !i;\n incr i;\n done;\n decr i;\n n := !n + !k * Int64.of_int !i;\n res := !res -- !k;\n\n while (!n > 0L) do\n n := !n -- Int64.of_int !i;\n res := !res + 1L;\n done;\n let res_str = string_of_int (Int64.to_int !res) in\n try\n Printf.printf \"%c\" res_str.[Int64.to_int (Int64.of_int !i + !n)-1]\n with _ -> Printf.printf \"%c\" res_str.[Int64.to_int (Int64.of_int !i + !n)-2]\n;;\n"}], "negative_code": [{"source_code": "let () =\n\n let n = ref (Scanf.scanf \"%d\\n\" (fun x -> x)) in\n let i = ref 1 in\n let k = ref 0 in\n let res = ref 0 in\n while (!n >= 0) do\n k := 9;\n for _j = 1 to !i - 1 do\n k := !k * 10\n done;\n\n res := !res + !k;\n n := !n - !k * !i;\n incr i;\n done;\n decr i;\n n := !n + !k * !i;\n res := !res - !k;\n\n Printf.printf \"%d %d %d\\n\" !n !res !i;\n let ref j = 0 in\n while (!n > 0) do\n n := !n - !i;\n incr res;\n done;\n (* n := !n + !i; *)\n (* decr res; *)\n (* Printf.printf \"%d %d %d\\n\" !n !res !i; *)\n (* Printf.printf \"%d \" !res; *)\n let res_str = string_of_int !res in\n Printf.printf \"%c\" res_str.[!i + !n-1]\n;;\n"}], "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"nl": {"description": "Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?", "input_spec": "The first line contains a number $$$t$$$ ($$$1 \\leq t \\leq 5$$$) — the number of test cases. Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \\leq b < a \\leq 10^{11})$$$ — the side length of Alice's square and the side length of the square that Bob wants.", "output_spec": "Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print \"YES\" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print \"NO\". You can print each letter in an arbitrary case (upper or lower).", "sample_inputs": ["4\n6 5\n16 13\n61690850361 24777622630\n34 33"], "sample_outputs": ["YES\nNO\nNO\nYES"], "notes": "NoteThe figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is \"YES\". In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$. In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \\cdot 86468472991 $$$.In the last case, the area is $$$34^2 - 33^2 = 67$$$."}, "positive_code": [{"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 (%$) = (mod) let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\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\n\nlet is_prime l =\n\t(* printf \"%Ld\\n\" l; *)\n\tif l = 2L then true else\n\tlet imax = 1L + (Int64.of_float @@ sqrt @@ Int64.to_float l)\n\tin let i = ref 3L\n\tin let f = ref true in\n\twhile !f && !i <= imax do\n\t\t(* printf \"%Ld: %Ld mod %Ld = %Ld: %Ld\\n\" !i l !i (l mod !i) imax; *)\n\t\tif l mod !i = 0L then (\n\t\t\tf := false;\n\t\t);\n\t\ti += 2L;\n\tdone;\n\t(* if !f then f := not (l mod 2L = 0L); *)\n\tf := !f && (l mod 2L <> 0L);\n\t!f\n\nlet () =\n\tlet t = get_i64 0 in\n\trep 1L t (fun i ->\n\t\tlet a,b = get_2_i64 0 in\n\t\t(\n\t\t\tif b = 0L && a = 1L then \"NO\"\n\t\t\telse if a - b = 1L && is_prime (a+b)\n\t\t\tthen \"YES\" else \"NO\"\n\t\t) |> print_endline; `Ok\n\t)"}], "negative_code": [{"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 (%$) = (mod) let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\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\n\n(* let is_prime l =\n\tprintf \"%Ld\\n\" l;\n\tlet imax = 1L + (Int64.of_float @@ sqrt @@ Int64.to_float l)\n\tin let i = ref 3L\n\tin let f = ref true in\n\twhile !f && !i <= imax do\n\t\tprintf \"%Ld: %Ld mod %Ld = %Ld: %Ld\\n\" !i l !i (l mod !i) imax;\n\t\tif l mod !i = 0L then (\n\t\t\tf := false;\n\t\t);\n\t\ti += 2L;\n\tdone;\n\tif !f then f := not (l mod 2L = 0L);\n\t!f *)\n\nlet () =\n\tlet t = get_i64 0 in\n\trep 1L t (fun i ->\n\t\tlet a,b = get_2_i64 0 in\n\t\tlet p,q = a+b, a-b in\n\t\t(\n\t\t\tif\n\t\t\t(* is_prime p && is_prime q *)\n\t\t\tq = 1L\n\t\t\tthen \"YES\" else \"NO\"\n\t\t) |> print_endline; `Ok\n\t)\n\n"}, {"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 (%$) = (mod) let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\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\n\n(* let is_prime l =\n\tprintf \"%Ld\\n\" l;\n\tlet imax = 1L + (Int64.of_float @@ sqrt @@ Int64.to_float l)\n\tin let i = ref 3L\n\tin let f = ref true in\n\twhile !f && !i <= imax do\n\t\tprintf \"%Ld: %Ld mod %Ld = %Ld: %Ld\\n\" !i l !i (l mod !i) imax;\n\t\tif l mod !i = 0L then (\n\t\t\tf := false;\n\t\t);\n\t\ti += 2L;\n\tdone;\n\tif !f then f := not (l mod 2L = 0L);\n\t!f *)\n\nlet () =\n\tlet t = get_i64 0 in\n\trep 1L t (fun i ->\n\t\tlet a,b = get_2_i64 0 in\n\t\t(\n\t\t\tif b = 0L && a = 1L then \"NO\"\n\t\t\telse if a - b = 1L\n\t\t\tthen \"YES\" else \"NO\"\n\t\t) |> print_endline; `Ok\n\t)"}], "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"nl": {"description": "Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).", "input_spec": "The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.", "output_spec": "Print single line: \"YES\" in case Ilya could have won by making single turn, and \"NO\" otherwise.", "sample_inputs": ["xx..\n.oo.\nx...\noox.", "x.ox\nox..\nx.o.\noo.x", "x..x\n..oo\no...\nx.xo", "o.x.\no...\n.x..\nooxx"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": "NoteIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.In the second example it wasn't possible to win by making single turn.In the third example Ilya could have won by placing X in the last row between two existing Xs.In the fourth example it wasn't possible to win by making single turn."}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let board = Array.init 4 (fun _ -> read_string()) in\n\n let isx i j = (0 <= i && i < 4) && (0 <= j && j < 4) && board.(i).[j] = 'x' in\n let isempty i j = board.(i).[j] = '.' in \n\n let dir = [|(0,1);(1,0);(0,-1);(-1,0);(1,1);(1,-1);(-1,-1);(-1,1)|] in\n\n let windir i j d =\n let (dx,dy) = dir.(d) in\n (isx (i+dx) (j+dy)) && (isx (i+2*dx) (j+2*dy)) ||\n (isx (i+dx) (j+dy)) && (isx (i-dx) (j-dy))\n in\n \n let win i j =\n if not (isempty i j) then false else\n exists 0 7 (fun d -> windir i j d)\n in\n\n if exists 0 3 (fun i -> exists 0 3 (fun j -> win i j)) then printf \"YES\\n\" else printf \"NO\\n\";\n"}], "negative_code": [], "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"nl": {"description": "There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).", "input_spec": "A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.", "output_spec": "In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).", "sample_inputs": ["7", "8"], "sample_outputs": ["0", "1440"], "notes": null}, "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet mval = 1_000_000_007L\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\n\n(*------------create binomial--------------*)\nlet init_binomial n m = \n (* compute an array b so that b.(p).(q) = (p choose q), \n where 0 <= p <= n and 0 <= q <= m. *)\n let b = Array.make_matrix (n+1) (m+1) 0 in\n for i=0 to n do for j=0 to min i m do \n b.(i).(j) <- if j=0 then 1 else b.(i-1).(j-1) + b.(i-1).(j)\n done done;\n b\nlet binomial = init_binomial 9 9\n\nlet rec power a i = \n if i=0 then 1 else \n let p = power a (i/2) in\n p * p * (if i land 1 = 0 then 1 else a)\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet sum64 i j f = fold i j (fun i a -> Int64.rem ((f i) ++ a) mval) 0L\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0\n\nlet m = read_int()\nlet rec dlist n = if n=0 then [] else (n mod 10)::(dlist (n/10))\nlet digits = List.rev (dlist m)\nlet ndigits = List.length digits\n(* Now make a table a.(l) that will store the number of numbers\n in the range 1...m with l lucky digits *)\nlet a = Array.make (ndigits+1) 0L\n\nlet f d l z_not_allowed =\n (* the number of numbers with d digits with l lucky digits *)\n (* z_not_allowed = true if zero is not an allowed choice *)\n if l<0 || l>d then 0 else\n let a = binomial.(d).(l) * (power 2 l) * (power 8 (d-l)) in\n if z_not_allowed && l=0 then a-1 else a\n\nlet lcount k = if k=4 || k=7 then 1 else 0\n\nlet rec dloop dlist l first = \n match dlist with [] -> if l=0 then 1 else 0\n | dig::dlist -> \n\tlet d = List.length dlist in\n\tlet a = sum 0 (dig-1) (fun k -> f d (l - (lcount k)) (first && k=0)) in\n\t a + (dloop dlist (l - (lcount dig)) false)\n\nlet () = \n for l=0 to ndigits do\n a.(l) <- Int64.of_int (dloop digits l true)\n done\n\n(* now we've computed the a.() as descrbed above *)\n\nlet rec loop el p = \n (* el = excess lucky you can use, p=parties left to do *)\n if el < 0 then 0L\n else if p=0 then 1L\n else\n let max_luckiness = if p=7 then ndigits else min el ndigits in\n sum64 0 max_luckiness (\n\tfun ml ->\n\t if a.(ml) = 0L then 0L else\n\t let aml = a.(ml) in\n\t a.(ml) <- a.(ml) -- 1L;\n\t let new_el = if p=7 then ml-1 else el-ml in\n\t let an = Int64.rem (aml ** (loop new_el (p-1))) mval in\n\t\ta.(ml) <- a.(ml) ++ 1L;\n\t\tan\n )\n\nlet () = Printf.printf \"%s\\n\" (Int64.to_string (loop 0 7))\n"}], "negative_code": [], "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"} {"nl": {"description": "An n × n table a is defined as follows: The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula ai, j = ai - 1, j + ai, j - 1. These conditions define all the values in the table.You are given a number n. You need to determine the maximum value in the n × n table defined by the rules above.", "input_spec": "The only line of input contains a positive integer n (1 ≤ n ≤ 10) — the number of rows and columns of the table.", "output_spec": "Print a single line containing a positive integer m — the maximum value in the table.", "sample_inputs": ["1", "5"], "sample_outputs": ["1", "70"], "notes": "NoteIn the second test the rows of the table look as follows: {1, 1, 1, 1, 1},  {1, 2, 3, 4, 5},  {1, 3, 6, 10, 15},  {1, 4, 10, 20, 35},  {1, 5, 15, 35, 70}."}, "positive_code": [{"source_code": "let solve () = \n let n = Scanf.scanf \"%d\" (fun n -> n) in\n let rec f i = \n if i = 0\n then\n 1\n else\n (f (i - 1) * (i * 2) * ((i * 2) - 1)/ i )/ i in\n f (n - 1)\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())"}, {"source_code": "let solve () = \n let n = Scanf.scanf \"%d\" (fun n -> n) in\n let rec loop i prev =\n if i < n \n then\n let rec looper j current = \n if j < n\n then\n (let element = (Array.get prev j) + (Array.get current (j - 1)) in\n Array.set current j element;\n looper (j + 1) current)\n else\n loop (i + 1) current\n in looper 1 (Array.make n 1)\n else\n Array.get prev (n - 1)\n in loop 1 (Array.make n 1)\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())"}, {"source_code": "open Printf\nopen Scanf\n\nlet ( ++ ) a b = Int64.add a b\n\n(*------------create binomial--------------*)\nlet init_binomial n m = \n (* compute an array b so that b.(p).(q) = (p choose q), \n where 0 <= p <= n and 0 <= q <= m. *)\n let b = Array.make_matrix (n+1) (m+1) 0L in\n for i=0 to n do for j=0 to min i m do \n b.(i).(j) <- if j=0 then 1L else b.(i-1).(j-1) ++ b.(i-1).(j)\n done done;\n b\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n\n let b = init_binomial (2*(n-1)) (2*(n-1)) in\n\n printf \"%Ld\\n\" (b.(2*(n-1)).(n-1))\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let arr = Array.make_matrix n n 1 in\n for i = 1 to n - 1 do\n for j = 1 to n - 1 do\n arr.(i).(j) <- arr.(i-1).(j) + arr.(i).(j-1)\n done\n done;\n Printf.printf \"%d\\n\" arr.(n-1).(n-1))\n"}, {"source_code": "\nlet rec a = function\n (_, 1) -> 1\n |(1, _) -> 1\n |(n, m) -> a (n - 1, m) + a (n, m - 1);;\n\nlet () =\n Printf.printf \"%d\\n\"\n (Scanf.scanf \"%d \"\n (fun n -> a (n, n)));;"}], "negative_code": [], "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"nl": {"description": "Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can equal either \"http\" (without the quotes) or \"ftp\" (without the quotes), <domain> is a non-empty string, consisting of lowercase English letters, the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character \"/\" isn't written. Thus, the address has either two characters \"/\" (the ones that go before the domain), or three (an extra one in front of the context).When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters \":\", \"/\", \".\".Help Vasya to restore the possible address of the recorded Internet resource.", "input_spec": "The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.", "output_spec": "Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.", "sample_inputs": ["httpsunrux", "ftphttprururu"], "sample_outputs": ["http://sun.ru/x", "ftp://http.ru/ruru"], "notes": "NoteIn the second sample there are two more possible answers: \"ftp://httpruru.ru\" and \"ftp://httpru.ru/ru\"."}, "positive_code": [{"source_code": "let substr str s e =\n String.sub str s (e - s)\n\nlet find str substr pos =\n let sub_len = String.length substr in \n let rec check i =\n if i + sub_len <= String.length str then\n if (String.sub str i sub_len) = substr then\n Some i\n else check (i + 1)\n else None\n in\n check pos\n\nlet punc str =\n let protocol = \n match substr str 0 3 with\n | \"ftp\" as p -> p | _ -> \"http\"\n in\n let p_size = String.length protocol in \n let domain =\n let ru_start = find str \"ru\" (p_size + 1) in \n match ru_start with \n | None -> assert false \n | Some pos -> substr str p_size pos \n in\n let contstart = p_size + String.length domain + 2 in \n let strlen = String.length str in \n let content =\n if strlen - contstart > 0 then\n String.concat \"\" [\"/\"; substr str contstart strlen]\n else \"\"\n in\n String.concat \"\" [protocol; \"://\"; domain; \".ru\"; content]\n\n\nlet () =\nread_line () |> punc |> print_endline"}], "negative_code": [], "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"nl": {"description": "Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.", "input_spec": "The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot. The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.", "output_spec": "Print the only integer d — the minimal number of steps to get the finish position.", "sample_inputs": ["0 0\n4 5", "3 4\n6 1"], "sample_outputs": ["5", "3"], "notes": "NoteIn the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times."}, "positive_code": [{"source_code": "let dist = function\n | [[x1; y1] ; [x2; y2]] ->\n begin\n let open Int64 in\n max\n (abs (sub x1 x2))\n (abs (sub y1 y2))\n end\n | _ -> Int64.zero\n\nlet () =\n let line1 = read_line () in\n let line2 = read_line () in\n [ line1; line2 ]\n |> List.map (fun x -> List.map Int64.of_string @@ Str.split (Str.regexp \" \") x)\n |> dist |> Int64.to_string\n |> print_string\n |> print_newline\n"}, {"source_code": "let xint() = Scanf.scanf \" %ld\" (fun x -> x)\n\nlet () = \n let x1 = xint() and y1 = xint() in\n let x2 = xint() and y2 = xint() in\n let abs x = \n if Int32.compare x 0l < 0 then Int32.sub 0l x\n else x\n in\n let x = abs (Int32.sub x2 x1) in\n let y = abs (Int32.sub y2 y1) in\n Printf.printf \"%ld\\n\" (\n if Int32.compare x y > 0 then x\n else y\n )\n"}, {"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let x1 = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let y1 = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let x2 = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let y2 = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let res = max (Int64.abs (x1 -| x2)) (Int64.abs (y1 -| y2)) in\n Printf.printf \"%Ld\\n\" res\n"}, {"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 abs = Int64.abs\n \nlet read_pair () = bscanf Scanning.stdib \" %Ld %Ld \" (fun x y -> (x,y))\nlet () = \n let (x1,y1) = read_pair () in\n let (x2,y2) = read_pair () in \n\n printf \"%Ld\\n\" (max (abs (x1--x2)) (abs (y1--y2)))\n"}], "negative_code": [{"source_code": "let dist = function\n | [[x1; y1] ; [x2; y2]] -> begin\n max\n (abs (x1 - x2))\n (abs (y1 - y2))\n end\n | _ -> -1\n\nlet () =\n let line1 = read_line () in\n let line2 = read_line () in\n [ line1; line2 ]\n |> List.map (fun x -> List.map int_of_string @@ Str.split (Str.regexp \" \") x)\n |> dist\n |> print_int\n |> print_newline\n"}, {"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let x1 = xint() and y1 = xint() in\n let x2 = xint() and y2 = xint() in\n let abs x = \n if x < 0 then -x\n else x\n in\n let x = abs (x2 - x1) in\n let y = abs (y2 - y1) in\n Printf.printf \"%d\\n\" (\n if x > y then x\n else y\n )\n"}], "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"nl": {"description": "Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.", "input_spec": "The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.", "output_spec": "Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.", "sample_inputs": ["48", "6"], "sample_outputs": ["9 42", "6 6"], "notes": "NoteIn the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.In more detail, after choosing X = 42 the process of building a tower is: Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15. The second added block has side 2, so the remaining volume is 15 - 8 = 7. Finally, Limak adds 7 blocks with side 1, one by one. So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42."}, "positive_code": [{"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 long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nlet cube x = x ** x ** x\n\nlet cube_lower_bound x =\n (* return the maximum number i such that i^3 <= x *)\n let rec bsearch lo hi = (* lo ^ 3 <= x < hi^3 *)\n if lo ++ 1L = hi then lo else\n let mid = (lo ++ hi) // 2L in\n if x < cube mid then bsearch lo mid else bsearch mid hi\n in\n bsearch 0L 1_000_000L\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let m = read_long () in\n\n let ntable = 1000 in\n let ftable = Array.make (ntable+1) 0 in\n let table = Array.make (ntable+1) (0,0L) in\n\n for j=1 to ntable do\n let x = long j in\n let i = cube_lower_bound x in\n ftable.(j) <- 1 + ftable.(short (x -- (cube i)));\n done;\n\n let rec scan i (best_len, best_x) =\n if i>ntable then () else (\n table.(i) <- if ftable.(i) >= best_len then (ftable.(i), long i) else (best_len, best_x);\n scan (i+1) table.(i)\n )\n in\n\n scan 1 (0, 0L);\n \n let rec g m full_range =\n if m <= long ntable then table.(short m) else\n let i = cube_lower_bound m in\n let (i1,x1) = g (m -- (cube i)) false in\n let i1 = i1+1 in\n let x1 = x1 ++ (cube i) in\n if full_range then (i1,x1) else\n\tlet (i2,x2) = g ((cube i)--1L) true in\n\tmax (i1,x1) (i2,x2)\n in\n\n let (len,x) = g m false in\n printf \"%d %Ld\\n\" len x\n"}], "negative_code": [], "src_uid": "385cf3c40c96f0879788b766eeb25139"} {"nl": {"description": "Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.", "input_spec": "The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol \"|\" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.", "output_spec": "If you cannot put all the weights on the scales so that the scales were in equilibrium, print string \"Impossible\". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.", "sample_inputs": ["AC|T\nL", "|ABC\nXYZ", "W|T\nF", "ABC|\nD"], "sample_outputs": ["AC|TL", "XYZ|ABC", "Impossible", "Impossible"], "notes": null}, "positive_code": [{"source_code": "exception Unbalanceable;;\nlet rec balance left right free =\n if String.length left > String.length right then\n let swap (a, b) = (b, a) in\n swap (balance right left free)\n else\n let diff = (String.length right) - (String.length left) in\n let rest = (String.length free) - diff in\n if (rest < 0) || (rest mod 2 <> 0) then\n raise Unbalanceable\n else\n let split_point = diff + rest / 2 in\n (String.concat \"\" [left; Str.string_before free split_point],\n String.concat \"\" [right; Str.string_after free split_point])\n;;\n\nlet split_on_delim s delim =\n let l = Str.split_delim (Str.regexp delim) s in\n match l with\n | h :: t -> (h, String.concat \"\" t)\n | _ -> failwith \"Delim not found\"\n;;\n\nlet main () = \n let (left, right) = split_on_delim (read_line ()) \"|\" in\n let free_weight = read_line () in\n try\n let (left, right) = balance left right free_weight in\n Printf.printf \"%s|%s\\n\" left right\n with Unbalanceable ->\n Printf.printf \"Impossible\\n\"\n;;\nlet _ = main ();;\n"}], "negative_code": [{"source_code": "exception Unbalanceable;;\nlet rec balance left right free =\n if String.length left > String.length right then\n let swap (a, b) = (b, a) in\n swap (balance right left free)\n else\n let diff = (String.length right) - (String.length left) in\n let rest = (String.length free) - diff in\n if (rest < 0) || (rest mod 2 <> 0) then\n raise Unbalanceable\n else\n let split_point = diff + rest / 2 in\n (String.concat \"\" [left; Str.string_before free split_point],\n String.concat \"\" [right; Str.string_after free split_point])\n;;\n\nlet explode s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l) in\n exp (String.length s - 1) [];;\n\nlet split_on_delim s delim =\n let l = Str.split (Str.regexp delim) s in\n match l with\n | h :: t -> (h, String.concat \"\" t)\n | _ -> failwith \"Delim not found\"\n;;\n\nlet main () = \n let (left, right) = split_on_delim (read_line ()) \"|\" in\n let free_weight = read_line () in\n try\n let (left, right) = balance left right free_weight in\n Printf.printf \"%s|%s\\n\" left right\n with Unbalanceable ->\n Printf.printf \"Impossible\\n\"\n;;\nlet _ = main ();;\n"}], "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"nl": {"description": "Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.Greg now only does three types of exercises: \"chest\" exercises, \"biceps\" exercises and \"back\" exercises. Besides, his training is cyclic, that is, the first exercise he does is a \"chest\" one, the second one is \"biceps\", the third one is \"back\", the fourth one is \"chest\", the fifth one is \"biceps\", and so on to the n-th exercise.Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 20). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 25) — the number of times Greg repeats the exercises.", "output_spec": "Print word \"chest\" (without the quotes), if the chest gets the most exercise, \"biceps\" (without the quotes), if the biceps gets the most exercise and print \"back\" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.", "sample_inputs": ["2\n2 8", "3\n5 1 10", "7\n3 3 2 7 9 6 8"], "sample_outputs": ["biceps", "back", "chest"], "notes": "NoteIn the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise."}, "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\n\nlet a =\n let rec loop i n f =\n if i = n then f []\n else let ai = read_int () in loop (i + 1) n (fun l -> f (ai :: l))\n in loop 0 n (fun x -> x) ;;\n\nlet count l = \n let rec loop i (chest, biceps, back) = function\n | [] -> (chest, biceps, back)\n | h :: t -> \n if i mod 3 = 0 then loop (i + 1) (chest + h, biceps, back) t\n else if i mod 3 = 1 then loop (i + 1) (chest, biceps + h, back) t\n else loop (i + 1) (chest, biceps, back + h) t\n in loop 0 (0, 0, 0) l ;;\n\nlet strongest_muscle (chest, biceps, back) =\n if chest > biceps && chest > back then \"chest\"\n else if biceps > chest && biceps > back then \"biceps\"\n else \"back\" ;;\n \nPrintf.printf \"%s\\n\" (strongest_muscle (count a)) ;;"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let a = Array.init n (fun i -> read_int()) in\n let c = Array.make 3 0 in\n for i=0 to n-1 do\n let e = i mod 3 in\n\tc.(e) <- c.(e) + a.(i);\n done;\n\n let m = max (max c.(0) c.(1)) c.(2) in\n let s = if c.(0) = m then \"chest\"\n else if c.(1) = m then \"biceps\"\n else \"back\" in\n \n Printf.printf \"%s\\n\" s\n\n"}], "negative_code": [], "src_uid": "579021de624c072f5e0393aae762117e"} {"nl": {"description": "Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to \"All World Classical Singing Festival\". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: The duration of the event must be no more than d minutes; Devu must complete all his songs; With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.", "input_spec": "The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).", "output_spec": "If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.", "sample_inputs": ["3 30\n2 2 1", "3 20\n2 1 1"], "sample_outputs": ["5", "-1"], "notes": "NoteConsider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: First Churu cracks a joke in 5 minutes. Then Devu performs the first song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now Devu performs second song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. "}, "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet get_sum songs = \n let rec loop i acc = \n if i < songs \n then\n let song = read () in\n loop (i + 1) (acc + song)\n else\n acc\n in loop 0 0 \n\nlet input () = \n let songs = read () in\n let time_limit = read () in\n let time_songs = get_sum songs in\n (songs, time_limit, time_songs)\n\nlet solve (songs, time_limit, time_songs) =\n let time_pauses = 10 * (songs - 1) in\n let time_needed = time_pauses + time_songs in\n if time_needed <= time_limit\n then\n (time_limit - time_songs) / 5\n else\n -1 \n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet d=read_int();;\nlet nb=ref 0;;\nlet j=ref 0;;\nfor i=1 to n-1 do\n let x=read_int() in\n nb:= !nb+10+x;\n j:= !j+2;\ndone;;\nlet x=Scanf.scanf \"%d\" (fun x->x);;\nnb:= !nb+x;;\nlet a=d- !nb;;\nif a<0 then print_int (-1) else print_int(!j+(a/5));;"}, {"source_code": "let (|>) x f = f x\n\nlet main = \n let (n, d) = Scanf.scanf \"%d %d\\n\" (fun n d -> (n,d)) in\n let rec aux n acc =\n match n with\n 0 -> acc\n | n -> aux (n-1) (acc + (Scanf.scanf \"%d \" (fun n -> n)))\n in\n let sum = aux n 0 in\n if (n-1)*10 + sum > d then Printf.printf \"-1\\n\"\n else Printf.printf \"%d\\n\" ((d-sum)/5)\n"}], "negative_code": [], "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"nl": {"description": "It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.", "input_spec": "The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.", "output_spec": "Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.", "sample_inputs": ["1987", "2013"], "sample_outputs": ["2013", "2014"], "notes": null}, "positive_code": [{"source_code": "let good year = \n let n1,n2,n3,n4=(year mod 10000)/1000,(year mod 1000)/100,(year mod 100)/10,(year mod 10) in\n if (n1<>n2) && (n1<>n3) && (n1<>n4) && (n2<>n3) && (n2<>n4) && (n3<>n4) then true\n else false;;\t\nlet rec solve year = \n\tif (good year) then year\n else solve (year+1);;\t\nlet year = read_int ();;\nprint_int (solve (year+1));;"}, {"source_code": "let str_to_list s =\n let rec loop i l =\n if i < 0 \n then l \n else loop (i - 1) ((Pervasives.int_of_char s.[i] - Pervasives.int_of_char '0') :: l) in\n loop (String.length s - 1) []\n\nlet input () = Scanf.scanf \"%s\" (fun s -> (List.rev (str_to_list s)))\n\nlet find_allowed year =\n let rec loop year allowed = \n match year with\n |(int :: tail) -> loop tail (List.filter((<>) int) allowed)\n |[] -> allowed\n in loop year [0;1;2;3;4;5;6;7;8;9]\n\nlet is_good year = \n List.length (find_allowed year) = 10 - List.length year \n\nlet rec increase year = \n let allowed = find_allowed year in\n match year with\n |(ones :: tail) -> (match (List.filter(fun a -> a > ones) allowed) with\n |(min :: _) when is_good tail -> (min :: tail)\n |_ -> let temp = increase tail in\n (List.hd(find_allowed temp) :: temp))\n |[] -> [1]\n\nlet solve input = List.rev (increase input)\n\nlet () = List.iter(Printf.printf \"%d\") (solve (input())) "}, {"source_code": "let rec dig n ak =\n\tif n = 0 then ak\n\telse dig (n / 10) ((n mod 10)::ak)\n;;\nlet good n =\n\tlet li = List.sort compare (dig n [])\n\tand krok (last, ans) e = \n\t\tif e = last then (e, false)\n\t\telse (e, ans)\n\tin snd (List.fold_left krok (10, true) li)\n;; \n\nlet rec solve n =\n\tif good n then n\n\telse solve (n + 1)\n;;\nlet year n = solve (n + 1);;\nlet x = read_int ();;\nprint_int (year x);;\n"}, {"source_code": "open Printf\n\nexception Found\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x)\n\nlet y = ref (n+1)\n\nlet not_distinct year =\n let flag = ref false in\n try\n let s = string_of_int year in\n let l = String.length s in\n for i = 0 to l-1 do\n for j =i+1 to l -1 do\n let x = String.get s i in\n let y1 = String.get s j in\n if(x==y1) then begin flag := true; raise Found end\n done;\n done; \n !flag;\n with Found -> !flag\n;;\n\nlet () =\n while( (not_distinct !y) ) do\n incr y\n done\n;;\n\nprintf \"%d\\n\" !y\n"}], "negative_code": [{"source_code": "let str_to_list s =\n let rec loop i l =\n if i < 0 \n then l \n else loop (i - 1) ((Pervasives.int_of_char s.[i] - Pervasives.int_of_char '0') :: l) in\n loop (String.length s - 1) []\n\nlet input () = Scanf.scanf \"%s\" (fun s -> (List.rev (str_to_list s)))\n\nlet find_allowed year =\n let rec loop year allowed = \n match year with\n |(int :: tail) -> loop tail (List.filter((<>) int) allowed)\n |[] -> allowed\n in loop year [0; 1; 2; 3; 4; 5; 6; 7; 8; 9]\n\nlet rec increase year = \n let allowed = find_allowed year in\n match year with\n |(ones :: tail) -> (match (List.filter(fun a -> a > ones) allowed) with\n |(min :: _) -> (min :: tail)\n |[] -> let temp = increase tail in\n (List.hd(find_allowed temp) :: temp))\n |[] -> [1]\n\nlet solve input = List.rev (increase input)\n\nlet () = List.iter(Printf.printf \"%d\") (solve (input())) "}], "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"nl": {"description": "You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \\ldots, x_n$$$ ($$$0 \\le x_i \\le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \\ldots, y_m$$$ ($$$0 \\le y_i \\le 9$$$) — the keys with fingerprints.", "output_spec": "In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.", "sample_inputs": ["7 3\n3 5 7 1 6 2 8\n1 2 7", "4 4\n3 4 1 0\n0 1 7 9"], "sample_outputs": ["7 1 2", "1 0"], "notes": "NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important."}, "positive_code": [{"source_code": "let split_on_char sep s =\n let r = ref [] in\n let j = ref (String.length s) in\n for i = String.length s - 1 downto 0 do\n if String.unsafe_get s i = sep then begin\n r := String.sub s (i + 1) (!j - i - 1) :: !r;\n j := i\n end\n done;\n String.sub s 0 !j :: !r\n;;\n\n\nlet _ = read_line () in\nlet seq = read_line () |> split_on_char ' ' |> List.map int_of_string in\nlet keys = read_line () |> split_on_char ' ' |> List.map int_of_string in\nList.iter (fun x -> if List.mem x keys then Printf.printf \"%i \" x) seq;\nprint_newline ();\n"}], "negative_code": [{"source_code": "let split_on_char sep s =\n let r = ref [] in\n let j = ref (String.length s) in\n for i = String.length s - 1 downto 0 do\n if String.unsafe_get s i = sep then begin\n r := String.sub s (i + 1) (!j - i - 1) :: !r;\n j := i\n end\n done;\n String.sub s 0 !j :: !r\n;;\n\n\nlet _ = read_line () in\nlet seq = read_line () |> split_on_char ' ' |> List.map int_of_string in\nlet keys = read_line () |> split_on_char ' ' |> List.map int_of_string in\nlet longest = ref [] in\nlet rec loop l = function\n | [] -> ()\n | h::t ->\n if List.mem h keys then loop (h::l) t\n else begin\n if List.length l > List.length !longest then longest := l;\n loop [] t\n end\nin\nloop [] seq;\nList.rev !longest |> List.iter (fun i -> Printf.printf \"%i \" i);\nprint_newline ();\n"}], "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"nl": {"description": "Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.", "input_spec": "The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. ", "output_spec": "Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number \"-1\" (without the quotes). If there are several solutions, output any.", "sample_inputs": ["3 7\n4 6\n5 5", "11 10\n13 8\n5 16", "1 2\n3 4\n5 6", "10 10\n10 10\n10 10"], "sample_outputs": ["1 2\n3 4", "4 7\n9 1", "-1", "-1"], "notes": "NotePay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number \"5\". However, Vasilisa only has one gem with each number from 1 to 9."}, "positive_code": [{"source_code": "let r1, r2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\nlet c1, c2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\nlet d1, d2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\n\nfor p00 = 1 to 9 do begin\n\tlet p01 = r1 - p00\n\tand p10 = c1 - p00\n\tand p11 = d1 - p00 in\n\tif (p00 <= 9) && (p00 >= 1) && (p01 <= 9) && (p01 >= 1) &&\n(p10 <= 9) && (p10 >= 1) &&\n(p11 <= 9) && (p11 >= 1) &&\n\n\t\t(p00 <> p01) && (p00 <> p10) && (p00 <> p11) &&\n\t\t(p01 <> p10) && (p01 <> p11) && (p10 <> p11) \n\t\t&& (p10 + p11 = r2) && (p01 + p11 = c2) && (p10 + p01 = d2) then begin\n\t\tprint_int p00; print_char ' '; print_int p01; print_string \"\\n\";\n\t\tprint_int p10; print_char ' '; print_int p11;\n\t\texit 0;\n\tend\nend done;;\n\nprint_int (0-1);;\n"}, {"source_code": "let 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 () =\n let r1 = read_int() in\n let r2 = read_int() in\n let c1 = read_int() in\n let c2 = read_int() in\n let d1 = read_int() in\n let d2 = read_int() in\n\n\n for i1 = 1 to 9 do\n for i2 = 1 to 9 do\n\tfor i3 = 1 to 9 do\n\t for i4 = 1 to 9 do\n\t if r1=i1+i2 && r2=i3+i4 && c1=i1+i3 && c2=i2+i4 && d1=i1+i4 && d2=i2+i3 \n\t && i1<>i2 && i1<>i3 && i1<>i4 && i2<>i3 && i2<>i4 && i3<>i4\n\t then (\n\t Printf.printf \"%d %d\\n%d %d\\n\" i1 i2 i3 i4;\n\t exit 1\n\t )\n\t done\n\tdone\n done\n done;\n \n Printf.printf \"-1\\n\"\n"}], "negative_code": [{"source_code": "let r1, r2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\nlet c1, c2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\nlet d1, d2 = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y));;\n\nfor p00 = 1 to 9 do begin\n\tlet p01 = r1 - p00\n\tand p10 = c1 - p00\n\tand p11 = d1 - p00 in\n\tif (p00 <> p01) && (p00 <> p10) && (p00 <> p11) &&\n\t\t(p01 <> p10) && (p01 <> p11) && (p10 <> p11) \n\t\t&& (p10 + p11 = r2) && (p01 + p11 = c2) && (p10 + p01 = d2) then begin\n\t\tprint_int p00; print_char ' '; print_int p01; print_string \"\\n\";\n\t\tprint_int p10; print_char ' '; print_int p11;\n\t\texit 0;\n\tend\nend done;;\n\nprint_int (0-1);;\n"}, {"source_code": "let 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 () =\n let r1 = read_int() in\n let r2 = read_int() in\n let c1 = read_int() in\n let c2 = read_int() in\n let d1 = read_int() in\n let d2 = read_int() in\n\n\n for i1 = 0 to 9 do\n for i2 = 0 to 9 do\n\tfor i3 = 0 to 9 do\n\t for i4 = 0 to 9 do\n\t if r1=i1+i2 && r2=i3+i4 && c1=i1+i3 && c2=i2+i4 && d1=i1+i4 && d2=i2+i3 \n\t && i1<>i2 && i1<>i3 && i1<>i4 && i2<>i3 && i2<>i4 && i3<>i4\n\t then (\n\t Printf.printf \"%d %d\\n%d %d\\n\" i1 i2 i3 i4;\n\t exit 1\n\t )\n\t done\n\tdone\n done\n done;\n \n Printf.printf \"-1\\n\"\n"}, {"source_code": "let 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 () =\n let r1 = read_int() in\n let r2 = read_int() in\n let c1 = read_int() in\n let c2 = read_int() in\n let d1 = read_int() in\n let d2 = read_int() in\n\n\n for i1 = 0 to 9 do\n for i2 = 0 to 9 do\n\tfor i3 = 0 to 9 do\n\t for i4 = 0 to 9 do\n\t if r1=i1+i2 && r2=i3+i4 && c1=i1+i3 && c2=i2+i4 && d1=i1+i4 && d2=i2+i3 then (\n\t Printf.printf \"%d %d\\n%d %d\\n\" i1 i2 i3 i4;\n\t exit 1\n\t )\n\t done\n\tdone\n done\n done;\n \n Printf.printf \"-1\\n\"\n"}], "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"nl": {"description": "Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?", "input_spec": "The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.", "output_spec": "Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.", "sample_inputs": ["4 7", "4 9", "1 1"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then."}, "positive_code": [{"source_code": "(*#load \"str.cma\"*)\nopen Printf;;\nlet [a; b] = List.map (ref) (List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nlet ans = ref 0;;\nwhile (!a <= !b) do\n\ta := !a * 3;\n\tb := !b * 2;\n\tans := !ans + 1;\ndone;;\nprintf \"%d\\n\" !ans;;\n"}, {"source_code": " let x, y = Scanf.scanf \"%d %d\" (fun x y -> float_of_int x, float_of_int y)\n \n let _ = \n print_int (int_of_float (ceil (log(y /. x) /. log(1.5) +. 0.00001)))"}, {"source_code": "let input () = Scanf.scanf \"%d %d\" (fun a b -> (a, b))\n\nlet solve (a, b) = \n let rec loop i a_mass b_mass = \n if a_mass > b_mass\n then\n i\n else\n loop (i + 1) (a_mass * 3) (b_mass * 2)\n in loop 0 a b\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let main () =\n let gr () = Scanf.scanf \" %d\" (fun i -> i) in \n let a = gr () in\n let b = gr() in \n let rec f x y ans = \n let newx = 3 * x in \n let newy = 2 * y in \n if newx > newy then (ans + 1) else f newx newy (ans + 1) \n in\n Printf.printf \"%d\\n\" (f a b 0)\n ;;\nlet _ = main();;\n"}, {"source_code": "let get_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n;;\nlet () =\n let x = get_int () in\n let y = get_int () in\n let rec f x y t =\n if x > y then t\n else f (3 * x) (2 * y) (t + 1) in\n Printf.printf \"%d\\n\" (f x y 0)\n;;\n"}, {"source_code": "let wczytaj () =\n Scanf.scanf \" %d\" (fun x -> x)\n;;\n\nlet rec kiedy a b cnt =\n let roznica = (a > b) in\n match roznica with\n | true -> cnt\n | false -> (kiedy (a*3) (b*2) (cnt+1))\n;;\n\nlet main () =\n let a = (wczytaj ()) in\n let b = (wczytaj ()) in\n (kiedy a b 0)\n;;\n\nlet _ = Printf.printf \"%d\" (main ())\n"}, {"source_code": "let min_time a b =\n let rec helper a b acc =\n if a > b then \n acc\n else helper (3 * a) (2 * b) (acc + 1)\n in helper a b 0\nin\n\nlet a = Scanf.scanf \" %d\" (fun x -> x) in\nlet b = Scanf.scanf \" %d\" (fun x -> x) in\nPrintf.printf \"%d\\n\" (min_time a b);\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (a,b) = read_pair () in\n\n let rec loop a b count = if a > b then count else loop (3*a) (2*b) (count+1) in\n\n printf \"%d\\n\" (loop a b 0)\n"}], "negative_code": [{"source_code": "let x, y = Scanf.scanf \"%d %d\" (fun x y -> float_of_int x, float_of_int y)\n \nlet _ = \n print_int (int_of_float (ceil (log(y /. x) /. log(1.5))))"}], "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"nl": {"description": "One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The picture corresponds to the first example. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.", "input_spec": "The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. ", "output_spec": "Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.", "sample_inputs": ["ABABBBACFEYUKOTT", "AAA"], "sample_outputs": ["4", "1"], "notes": null}, "positive_code": [{"source_code": "let input () = Scanf.scanf \"%s\\n\" (fun s -> s)\nlet print result = Printf.printf \"%d\\n\" result\n\nlet is_vovel char = \n match char with\n | 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' -> true\n | _ -> false\n\nlet solve str = \n let l = String.length str in\n let rec loop i prev max = \n if i < l \n then\n let char = str.[i] in\n if is_vovel char\n then\n let hop = Pervasives.max (i - prev) max in\n loop (i + 1) i hop\n else\n loop (i + 1) prev max\n else\n Pervasives.max (l - prev) max\n in loop 0 (-1) 0\n\nlet () = print (solve (input ()))"}, {"source_code": "\n\nlet solve s =\n let n = String.length s in\n let rec solve last_pos i acc =\n if i <= n then\n if s.[i-1] = 'A' || s.[i-1] = 'E' || s.[i-1] = 'I' ||\n s.[i-1] = 'O' || s.[i-1] = 'U' || s.[i-1] = 'Y' then\n solve i (i+1) (max acc (i - last_pos))\n else\n solve last_pos (i+1) acc\n else\n max acc (i - last_pos)\n in\n solve 0 1 0\n;;\n\n\nlet main () =\n let s = read_line () in\n let () = print_int (solve s) in\n print_string \"\\n\"\n;;\n\n\nmain ()\n"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet is_vowel c =\n List.mem c ['A'; 'E'; 'I'; 'O'; 'U'; 'Y']\n\nlet () =\n let s = read_string () in\n let len = String.length s in\n let rec loop i count max_sum =\n if i >= len then max (count + 1) max_sum\n else if is_vowel s.[i] then\n loop (i + 1) 0 (max (count + 1) max_sum)\n else loop (i + 1) (count + 1) max_sum\n in\n loop 0 0 0\n |> Printf.printf \"%d\"\n"}, {"source_code": "let is_vowel c =\n List.mem c ['A'; 'E'; 'I'; 'O'; 'U'; 'Y']\n\nlet () =\n let s = read_line () in\n let rec loop ability jump i =\n if i = String.length s then\n max jump ability\n else if is_vowel s.[i] then\n loop (max jump ability) 1 (i + 1)\n else\n loop ability (jump + 1) (i + 1) in\n loop 1 1 0 |> string_of_int |> print_endline\n"}, {"source_code": "let min_jump s =\n let len = String.length s in\n let rec jump i jumped m =\n if i = len then\n max m jumped\n else\n match s.[i] with\n 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' ->\n jump (i+1) 1 (max m jumped)\n | _ ->\n jump (i+1) (jumped+1) m\n in jump 0 1 0 ;;\n\nlet s = read_line ()\nin Printf.printf \"%d\\n\" (min_jump s) ;;\n"}], "negative_code": [{"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet is_vowel c =\n List.mem c ['A'; 'E'; 'I'; 'O'; 'U'; 'Y']\n\nlet () =\n let s = read_string () in\n let len = String.length s in\n let rec loop i count max_sum =\n if i >= len then max count max_sum\n else if is_vowel s.[i] then\n loop (i + 1) 0 (max (count + 1) max_sum)\n else loop (i + 1) (count + 1) max_sum\n in\n loop 0 0 0\n |> Printf.printf \"%d\"\n"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet is_vowel c =\n List.mem c ['A'; 'E'; 'I'; 'O'; 'U'; 'Y']\n\nlet () =\n let s = read_string () in\n let len = String.length s in\n let rec loop i count max_sum =\n if i >= len then max_sum\n else if is_vowel s.[i] then\n loop (i + 1) 0 (max (count + 1) max_sum)\n else loop (i + 1) (count + 1) max_sum\n in\n loop 0 0 0\n |> Printf.printf \"%d\"\n"}, {"source_code": "let is_vowel c =\n List.mem c ['A'; 'E'; 'I'; 'O'; 'U'; 'Y']\n\nlet () =\n let s = read_line () in\n let rec loop ability jump i =\n if i = String.length s then\n ability\n else if is_vowel s.[i] then\n loop (max jump ability) 1 (i + 1)\n else\n loop ability (jump + 1) (i + 1) in\n loop 1 1 0 |> string_of_int |> print_endline\n"}, {"source_code": "let min_jump s =\n let len = String.length s in\n let rec jump i jumped m =\n if i = len then\n max m jumped\n else\n match s.[i] with\n 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' ->\n jump (i+1) 1 (max m jumped)\n | _ ->\n jump (i+1) (jumped+1) m\n in jump 0 0 0 ;;\n\nlet s = read_line ()\nin Printf.printf \"%d\\n\" (min_jump s) ;;\n"}], "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"nl": {"description": "Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips x - 1 consecutive bricks, then he paints the x-th one. That is, he'll paint bricks x, 2·x, 3·x and so on red. Similarly, Floyd skips y - 1 consecutive bricks, then he paints the y-th one. Hence he'll paint bricks y, 2·y, 3·y and so on pink.After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question. ", "input_spec": "The input will have a single line containing four integers in this order: x, y, a, b. (1 ≤ x, y ≤ 1000, 1 ≤ a, b ≤ 2·109, a ≤ b).", "output_spec": "Output a single integer — the number of bricks numbered no less than a and no greater than b that are painted both red and pink.", "sample_inputs": ["2 3 6 18"], "sample_outputs": ["3"], "notes": "NoteLet's look at the bricks from a to b (a = 6, b = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. "}, "positive_code": [{"source_code": "open Printf\nopen Scanf\nopen String\nopen List\nopen Int64\n\nlet rec gcd a b =\n\tif b = zero then a\n\telse gcd b (rem a b);;\n\nlet solve x y a b =\n\tlet l = (div (mul x y) (gcd x y))\n\tin printf \"%Ld\" (sub (div b l) (div (pred a) l))\nin scanf \"%Ld %Ld %Ld %Ld\" solve;;\n"}, {"source_code": "let lcm a b =\n let rec gcd a b = if b = Int32.zero then a else gcd b (Int32.rem a b)\n in (Int32.div (Int32.mul a b) (gcd a b)) in\nlet (x, y, a, b) = Scanf.scanf \"%ld %ld %ld %ld\\n\" (fun x y a b -> (x, y, a, b)) in\nlet m = lcm x y in\n(* determine number of m in interval [a,b] *)\nlet start = Int32.add a (Int32.rem (Int32.sub m (Int32.rem a m)) m)\nand last = Int32.sub b (Int32.rem b m) in\nPrintf.printf \"%ld\\n\" (max (Int32.succ (Int32.div (Int32.sub last start) m))\nInt32.zero) ;;\n"}], "negative_code": [{"source_code": "let rec gcd a = function 0 -> a | b -> gcd b (a mod b) in\nlet lcm a b = (a * b) / (gcd a b) in\nlet (x, y, a, b) = Scanf.scanf \"%d %d %d %d\\n\" (fun x y a b -> (x, y, a, b)) in\nlet m = lcm x y in\n(* determine number of m in interval [a,b] *)\nlet start = a + (a mod m)\nand last = b - (b mod m) in\nPrintf.printf \"%d\\n\" (max ((last - start) / m + 1) 0) ;;\n"}], "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"nl": {"description": "Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.Arithmetic progression is a sequence a1, a1 + d, a1 + 2d, ..., a1 + (n - 1)d, where a1 and d are any numbers.Geometric progression is a sequence b1, b2 = b1q, ..., bn = bn - 1q, where b1 ≠ 0, q ≠ 0, q ≠ 1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.", "input_spec": "The first line contains exactly four integer numbers between 1 and 1000, inclusively.", "output_spec": "Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.", "sample_inputs": ["836 624 412 200", "1 334 667 1000"], "sample_outputs": ["-12", "1333"], "notes": "NoteThis problem contains very weak pretests!"}, "positive_code": [{"source_code": "Scanf.scanf \"%f %f %f %f\\n\" (fun a b c d ->\n let n =\n if a = 0. || b = 0. || c = 0. || a = b || b = c || c = d then\n if b -. a = c -. b && c -. b = d -. c then\n (* arithmetic *)\n d +. (b -. a)\n else 42.\n else if b /. a = c /. b && c /. b = d /. c then\n (* geometric *)\n let q = (b /. a) in\n let r = d *. q in\n if fst (modf r) <> 0. then 42.\n else r\n else if b -. a = c -. b && c -. b = d -. c then\n (* arithmetic *)\n d +. (b -. a)\n else 42. in\n Printf.printf \"%d\\n\" (int_of_float n)) ;;"}], "negative_code": [], "src_uid": "68a9508d49fec672f9c61766d6051047"} {"nl": {"description": "Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.", "input_spec": "The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 50) — number ai stands for the number of sockets on the i-th supply-line filter.", "output_spec": "Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.", "sample_inputs": ["3 5 3\n3 1 2", "4 7 2\n3 3 2 4", "5 5 1\n1 3 1 2 1"], "sample_outputs": ["1", "2", "-1"], "notes": "NoteIn the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter."}, "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n let k = read_int() in\n let g = Array.init n (fun _ -> read_int() - 1) in\n\n let () = Array.sort (fun a b -> compare b a) g in\n\n let rec search i t = if k+t >= m then i else \n if i < n then search (i+1) (t+g.(i)) else -1\n in\n\n Printf.printf \"%d\\n\" (search 0 0)\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n let k = read_int() in\n let g = Array.init n (fun i -> read_int() - 1) in\n\n let () = Array.sort (fun a b -> compare b a) g in\n\n let rec search i t = if i=n then -1 else if k+t >= m then i else search (i+1) (t+g.(i)) in\n\n Printf.printf \"%d\\n\" (search 0 0)\n"}], "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"nl": {"description": "HQ9+ is a joke programming language which has only four one-character instructions: \"H\" prints \"Hello, World!\", \"Q\" prints the source code of the program itself, \"9\" prints the lyrics of \"99 Bottles of Beer\" song, \"+\" increments the value stored in the internal accumulator.Instructions \"H\" and \"Q\" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.", "input_spec": "The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.", "output_spec": "Output \"YES\", if executing the program will produce any output, and \"NO\" otherwise.", "sample_inputs": ["Hi!", "Codeforces"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first case the program contains only one instruction — \"H\", which prints \"Hello, World!\".In the second case none of the program characters are language instructions."}, "positive_code": [{"source_code": "let rec p str n = if (n=String.length str) then \"NO\"\n else match str.[n] with 'H' | 'Q' | '9' -> \"YES\" | _ -> p str (n+1)\n\nlet main () = ((print_string (p (read_line ()) 0)); print_newline ();\n);;\n\nif !Sys.interactive then () else main ();;"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet solve input =\n if String.contains input 'H' || String.contains input 'Q' || String.contains input '9'\n then\n \"YES\"\n else\n \"NO\"\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let flag = ref \"NO\";;\n\nexception Found;;\n\nlet vote = function\n | 'H' -> raise Found\n | 'Q' -> raise Found\n | '9' -> raise Found\n | _ -> ()\n;;\n\nlet s = Scanf.scanf \"%s \" (fun x -> x)\n\ntry\n for i=0 to String.length s - 1 do\n vote (String.get s i)\n done\nwith Found -> flag := \"YES\";;\n\nprint_endline !flag;;\n"}, {"source_code": "let solve p =\n if String.contains p 'H' || String.contains p 'Q' || String.contains p '9'\n then \"YES\"\n else \"NO\"\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%s\" solve)\n\n"}, {"source_code": "\nlet solve s len =\n let rec solve' i = match s.[i], i with\n | 'H', _ | 'Q', _ | '9', _ -> \"YES\"\n | _, n when n = len -> \"NO\"\n | _, n -> solve' (i + 1)\n in solve' 0\n\nlet () =\n let s = read_line () in\n Printf.printf \"%s\\n\" (solve (s ^ \" \") (String.length s))\n"}, {"source_code": "let pf = Printf.printf;;\nlet sf = Scanf.scanf;;\nlet ssf = Scanf.sscanf;;\n\nlet (|>) x f = f x;;\nlet (@@) f x = f x;;\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\nlet charlist_of_string s =\n let rec inner rv = function\n 0 -> rv\n | m -> inner (s.[m-1]::rv) (m-1) in\n inner [] (String.length s)\n;;\n\nlet l = ['H'; 'Q'; '9'];;\n\nlet _ =\n let s = read_line() in\n let func c = List.memq c @@ charlist_of_string s in\n print_endline (if List.exists func l then \"YES\" else \"NO\")\n;;\n"}], "negative_code": [], "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"nl": {"description": "The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds. Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.", "input_spec": "The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to. The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter. The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or ) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.", "output_spec": "Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.", "sample_inputs": ["4 2 4\n3 4\n1 1", "5 4 0\n1 2\n3 1"], "sample_outputs": ["8", "7"], "notes": "NoteIn the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds. In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total."}, "positive_code": [{"source_code": "let read_ints (n : int) : int array =\n let s = read_line () in\n let a = Array.make n 0 in\n let p = ref 0 (* position in a *) in \n begin\n for i = 0 to String.length s - 1 do\n match s.[i] with\n ' ' -> incr p\n | c -> a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')\n done\n end;\n a\n \n\n(* distance needed for train to travel from p to x *)\nlet f ((s, p, x, dir) : int * int * int * bool) : int =\n if p = x\n then 0\n else\n match p < x, dir with\n true, true -> x - p\n | true, false -> p + x\n | false, true -> 2*s - p - x\n | false, false -> p - x\n\n\n(* distance needed for train to travel from x, dir to x, dir2 *)\nlet g ((s, x, dir, dir2) : int * int * bool * bool) : int =\n match dir, dir2 with\n true, true -> 0\n | true, false -> 2*(s-x)\n | false, true -> 2*x\n | false, false -> 0\n\n\nlet main () : unit =\n let [|s; x1; x2|] = read_ints 3 in\n let [|t1; t2|] = read_ints 2 in\n let [|p; d|] = read_ints 2 in\n let dist = abs (x1 - x2) in\n let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, (if p = x1 then d = 1 else p < x1), x1 < x2) + dist) * t1) in\n print_int ans\n\n\nlet _ = main ()\n"}], "negative_code": [{"source_code": "let read_ints (n : int) : int array =\n let s = read_line () in\n let a = Array.make n 0 in\n let p = ref 0 (* position in a *) in \n begin\n for i = 0 to String.length s - 1 do\n match s.[i] with\n ' ' -> incr p\n | c -> a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')\n done\n end;\n a\n \n\n(* distance needed for train to travel from p to x *)\nlet f ((s, p, x, dir) : int * int * int * bool) : int =\n if p = x\n then 0\n else\n match p < x, dir with\n true, true -> x - p\n | true, false -> p + x\n | false, true -> 2*s - p - x\n | false, false -> p - x\n\n\n(* distance needed for train to travel from x, dir to x, dir2 *)\nlet g ((s, x, dir, dir2) : int * int * bool * bool) : int =\n match dir, dir2 with\n true, true -> 0\n | true, false -> 2*(s-x)\n | false, true -> 2*x\n | false, false -> 0\n\n\nlet main () : unit =\n let [|s; x1; x2|] = read_ints 3 in\n let [|t1; t2|] = read_ints 2 in\n let [|p; d|] = read_ints 2 in\n let dist = abs (x1 - x2) in\n let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, (if p = x1 then x1 < x2 else p < x1), x1 < x2) + dist) * t1) in\n print_int ans\n\n\nlet _ = main ()\n"}, {"source_code": "let read_ints (n : int) : int array =\n let s = read_line () in\n let a = Array.make n 0 in\n let p = ref 0 (* position in a *) in \n begin\n for i = 0 to String.length s - 1 do\n match s.[i] with\n ' ' -> incr p\n | c -> a.(!p) <- (10 * a.(!p) + Char.code c - Char.code '0')\n done\n end;\n a\n \n\n(* distance needed for train to travel from p to x *)\nlet f ((s, p, x, dir) : int * int * int * bool) : int =\n match p < x, dir with\n true, true -> x - p\n | true, false -> p + x\n | false, true -> 2*s - p - x\n | false, false -> p - x\n\n\n(* distance needed for train to travel from x, dir to x, dir2 *)\nlet g ((s, x, dir, dir2) : int * int * bool * bool) : int =\n match dir, dir2 with\n true, true -> 0\n | true, false -> 2*(s-x)\n | false, true -> 2*x\n | false, false -> 0\n\n\nlet main () : unit =\n let [|s; x1; x2|] = read_ints 3 in\n let [|t1; t2|] = read_ints 2 in\n let [|p; d|] = read_ints 2 in\n let dist = abs (x1 - x2) in\n let ans = min (dist * t2) ((f (s, p, x1, d = 1) + g (s, x1, p < x1, x1 < x2) + dist) * t1) in\n print_int ans\n\n\nlet _ = main ()\n"}], "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"} {"nl": {"description": "As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!", "input_spec": "The first input line contains an integer n (1 ≤ n ≤ 109).", "output_spec": "Print \"YES\" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print \"NO\" (without the quotes).", "sample_inputs": ["256", "512"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers."}, "positive_code": [{"source_code": "let rec gao n a b = match a, b with\n | [], _ | _, [] -> \"NO\"\n | (x::xs), (y::ys) ->\n if x + y = n then \"YES\"\n else if x + y > n then gao n a ys\n else gao n xs b\n;;\n\nlet triangular n =\n if n mod 2 = 0\n then n / 2 * (n + 1)\n else (n + 1) / 2 * n\n;;\n\nlet a = Array.init 45000 triangular in\nlet l = List.tl (Array.to_list a) in\nlet n = Scanf.scanf \"%d\" (fun x -> x) in\nprint_endline (gao n l (List.rev l));;\n\n"}, {"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet tri k = k * (k + 1) / 2\n\nlet isTri n =\n let rec go l r =\n if r - l <= 1 then tri l == n\n else\n let m = l + (r - l) / 2 in\n if tri m <= n then go m r\n else go l m\n in go 0 (int_of_float (sqrt (float_of_int (2 * n)) +. 1.))\n\nlet isDoubleTri n =\n let rec go i sum =\n if sum >= n then false\n else if isTri (n - sum) then true\n else go (i + 1) (sum + i + 1)\n in go 1 1\n\nlet () =\n let n = readInt () in\n Printf.printf (if isDoubleTri n then \"YES\\n\" else \"NO\\n\")\n"}, {"source_code": "let readInt64 () = Scanf.scanf \" %Ld\" (fun x -> x)\n\nlet tri k = Int64.(div (mul k (add k 1L)) 2L)\n\nlet isTri n =\n let rec lim k =\n if tri k <= n then lim (Int64.mul 2L k)\n else k\n in\n let rec go l r = Int64.(\n if sub r l <= 1L then tri l = n\n else\n let m = add l (div (sub r l) 2L) in\n if tri m <= n then go m r\n else go l m\n )\n in go 0L (lim 3L)\n\nlet isDoubleTri n =\n let rec go i sum = Int64.(\n if sum >= n then false\n else if isTri (sub n sum) then true\n else let ii = add i 1L in go ii (add sum ii)\n )\n in go 1L 1L\n\nlet () =\n let n = readInt64 () in\n Printf.printf (if isDoubleTri n then \"YES\\n\" else \"NO\\n\")\n"}, {"source_code": "let readInt32 () = Scanf.scanf \" %ld\" (fun x -> x)\n\nlet tri k = Int32.(div (mul k (add k 1l)) 2l)\n\nlet isTri n =\n let rec lim k =\n if tri k <= n then lim Int32.(div (mul 14l k) 10l)\n else k\n in\n let rec go l r = Int32.(\n if sub r l <= 1l then tri l = n\n else\n let m = add l (div (sub r l) 2l) in\n if tri m <= n then go m r\n else go l m\n )\n in go 0l (lim 3l)\n\nlet isDoubleTri n =\n let rec go i sum = Int32.(\n if sum >= n then false\n else if isTri (sub n sum) then true\n else let ii = add i 1l in go ii (add sum ii)\n )\n in go 1l 1l\n\nlet () =\n let n = readInt32 () in\n Printf.printf (if isDoubleTri n then \"YES\\n\" else \"NO\\n\")\n"}], "negative_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet tri k = k * (k + 1) / 2\n\nlet isTri n =\n let rec go l r =\n if r - l <= 1 then tri l == n\n else\n let m = l + (r - l) / 2 in\n if tri m <= n then go m r\n else go l m\n in go 0 n\n\nlet isDoubleTri n =\n let rec go i sum =\n if sum >= n then false\n else if isTri (n - sum) then true\n else go (i + 1) (sum + i + 1)\n in go 1 1\n\nlet () =\n let n = readInt () in\n Printf.printf (if isDoubleTri n then \"YES\\n\" else \"NO\\n\")\n"}], "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"nl": {"description": "JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $$$n$$$, you can perform the following operations zero or more times: mul $$$x$$$: multiplies $$$n$$$ by $$$x$$$ (where $$$x$$$ is an arbitrary positive integer). sqrt: replaces $$$n$$$ with $$$\\sqrt{n}$$$ (to apply this operation, $$$\\sqrt{n}$$$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $$$n$$$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?Apparently, no one in the class knows the answer to this problem, maybe you can help them?", "input_spec": "The only line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$) — the initial number.", "output_spec": "Print two integers: the minimum integer $$$n$$$ that can be achieved using the described operations and the minimum number of operations required.", "sample_inputs": ["20", "5184"], "sample_outputs": ["10 2", "6 4"], "notes": "NoteIn the first example, you can apply the operation mul $$$5$$$ to get $$$100$$$ and then sqrt to get $$$10$$$.In the second example, you can first apply sqrt to get $$$72$$$, then mul $$$18$$$ to get $$$1296$$$ and finally two more sqrt and you get $$$6$$$.Note, that even if the initial value of $$$n$$$ is less or equal $$$10^6$$$, it can still become greater than $$$10^6$$$ after applying one or more operations."}, "positive_code": [{"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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 factor n =\n let m,r = ref n,ref [] in\n rep 2L (n/2L) (fun i ->\n if !m mod i = 0L then (\n let k = ref 0L in\n while !m mod i = 0L do\n k += 1L; m /= i;\n done;\n r := (i,!k) :: !r));\n if !m>1L then (!m,1L)::!r else !r\n\nlet binary_search_opt ng ok f =\n let d = if ng < ok then 1L else -1L in\n let i = binary_search ng ok f in\n if i=ng-d || i=ok+d then None else Some i\n\nlet pow n k =\n let rec f a n = function\n | 0L -> a\n | 1L -> n*a\n | k when k mod 2L = 0L -> f a (n*n) (k/2L)\n | k -> f (a*n) n (k-1L)\n in f 1L n k\n\nlet () =\n let n = get_i64 0 in\n let ls = factor n in\n let ans,k_max = List.fold_left (fun (u,w) (v,x) -> (u*v,max w x)) (1L,0L) ls in\n let nibekies =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000008L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n let k_to = lower_bound nibekies k_max in\n if pow ans (nibekies.(i32 k_to)) = n then printf \"%Ld %Ld\\n\" ans k_to\n else printf \"%Ld %Ld\\n\" ans (k_to + 1L)\n\n\n\n\n\n\n\n\n\n\n"}, {"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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 factor n =\n let m,r = ref n,ref [] in\n rep 2L (n/2L) (fun i ->\n if !m mod i = 0L then (\n let k = ref 0L in\n while !m mod i = 0L do\n k += 1L; m /= i;\n done;\n r := (i,!k) :: !r));\n if !m>1L then (!m,1L)::!r else !r\n\nlet binary_search_opt ng ok f =\n let d = if ng < ok then 1L else -1L in\n let i = binary_search ng ok f in\n if i=ng-d || i=ok+d then None else Some i\n\nlet pow n k =\n let rec f a n = function\n | 0L -> a\n | 1L -> n*a\n | k when k mod 2L = 0L -> f a (n*n) (k/2L)\n | k -> f (a*n) n (k-1L)\n in f 1L n k\n\nlet () =\n let n = get_i64 0 in\n let ls = factor n in\n let ans,k_max = List.fold_left (fun (u,w) (v,x) -> (u*v,max w x)) (1L,0L) ls in\n let nibekies =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000008L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n let k_to = lower_bound nibekies k_max in\n if pow ans (pow 2L k_to) = n then printf \"%Ld %Ld\\n\" ans k_to\n else printf \"%Ld %Ld\\n\" ans (k_to + 1L)\n\n\n\n\n\n\n\n\n\n\n"}, {"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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\nlet sieve n = (* includes 0, O(nloglogn) *)\n let prime = Array.make (n+$1) true in\n prime.(0) <- false;\n prime.(1) <- false;\n for i=2 to n do\n if prime.(i) then let j = ref @@ i*$2 in\n while !j <= n do prime.(!j) <- false; j := !j +$ i; done\n done; prime\n(* let pow n k = fix (fun f n k a ->\n if k=0L then a\n else if k=1L then n*a\n else if k mod 2L = 0L then f (n*n) (k/2L) a\n else f n (k-1L) (a*n)) n k 1L *)\nlet pow n k =\n let rec f a n = function\n | 0L -> a\n | 1L -> n*a\n | k when k mod 2L = 0L -> f a (n*n) (k/2L)\n | k -> f (a*n) n (k-1L)\n in f 1L n k\nlet () =\n let n = get_i64 0 in\n let pr = sieve (i32 n) in\n let i = ref 1L in\n let tp =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000000L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n (* print_array ist tp; *)\n let r = ref [] in\n while !i <= n do\n if n mod !i = 0L && pr.(i32 !i) then (\n r := !i :: !r;\n );\n i += 1L;\n done;\n (* print_list ist !r; *)\n let mx = ref 0L in\n let alltp = ref true in\n List.iter (fun p ->\n let m = ref n in\n let k = ref 0L in\n while !m>=1L && !m mod p = 0L do\n k += 1L;\n m := !m / p;\n done;\n let t = lower_bound tp !k |> i32 in\n if t<=0 || i64 t>alen tp || tp.(t) <> !k then alltp := false;\n (* printf \"%Ld %Ld : %d ::: %b\\n\" p !k t !alltp; *)\n mx := max !mx !k\n ) !r;\n (* printf \"%Ld\\n\" !mx; *)\n (* let mxv = tp.(i32 @@ upper_bound tp !mx) in *)\n let mxv = lower_bound tp !mx in\n let mxv = if mxv<=0L then (\n 1L\n ) else mxv in\n (* printf \"%Ld : %Ld\\n\" !mx mxv; *)\n let res = List.fold_left ( * ) 1L !r in\n if res = n then printf \"%Ld 0\" res\n else\n printf \"%Ld %Ld\\n\" res\n (* (mxv + if !alltp then 0L else 1L) *)\n (mxv + if pow res @@ pow 2L mxv = n then 0L else 1L)\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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\nlet sieve n = (* includes 0, O(nloglogn) *)\n let prime = Array.make (n+$1) true in\n prime.(0) <- false;\n prime.(1) <- false;\n for i=2 to n do\n if prime.(i) then let j = ref @@ i*$2 in\n while !j <= n do prime.(!j) <- false; j := !j +$ i; done\n done; prime\nlet () =\n let n = get_i64 0 in\n let pr = sieve (i32 n) in\n let i = ref 1L in\n let tp =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000000L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n (* print_array ist tp; *)\n let r = ref [] in\n while !i <= n / 2L do\n if n mod !i = 0L && pr.(i32 !i) then (\n r := !i :: !r;\n );\n i += 1L;\n done;\n (* print_list ist !r; *)\n let mx = ref 0L in\n let alltp = ref true in\n List.iter (fun p ->\n let m = ref n in\n let k = ref 0L in\n while !m>=1L && !m mod p = 0L do\n k += 1L;\n m := !m / p;\n done;\n let t = lower_bound tp !k |> i32 in\n if t<=0 || i64 t>alen tp || tp.(t) <> !k then alltp := false;\n (* printf \"%Ld %Ld : %d\\n\" p !k t; *)\n mx := max !mx !k\n ) !r;\n (* printf \"%Ld\\n\" !mx; *)\n (* let mxv = tp.(i32 @@ upper_bound tp !mx) in *)\n let mxv = lower_bound tp !mx in\n (* printf \"%Ld : %Ld\\n\" !mx mxv; *)\n printf \"%Ld %Ld\\n\" (List.fold_left ( * ) 1L !r)\n (mxv + if !alltp then 0L else 1L)\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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\nlet sieve n = (* includes 0, O(nloglogn) *)\n let prime = Array.make (n+$1) true in\n prime.(0) <- false;\n prime.(1) <- false;\n for i=2 to n do\n if prime.(i) then let j = ref @@ i*$2 in\n while !j <= n do prime.(!j) <- false; j := !j +$ i; done\n done; prime\nlet () =\n let n = get_i64 0 in\n let pr = sieve (i32 n) in\n let i = ref 1L in\n let tp =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000000L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n (* print_array ist tp; *)\n let r = ref [] in\n while !i <= n do\n if n mod !i = 0L && pr.(i32 !i) then (\n r := !i :: !r;\n );\n i += 1L;\n done;\n (* print_list ist !r; *)\n let mx = ref 0L in\n let alltp = ref true in\n List.iter (fun p ->\n let m = ref n in\n let k = ref 0L in\n while !m>=1L && !m mod p = 0L do\n k += 1L;\n m := !m / p;\n done;\n let t = lower_bound tp !k |> i32 in\n if t<=0 || i64 t>alen tp || tp.(t) <> !k then alltp := false;\n (* printf \"%Ld %Ld : %d\\n\" p !k t; *)\n mx := max !mx !k\n ) !r;\n (* printf \"%Ld\\n\" !mx; *)\n (* let mxv = tp.(i32 @@ upper_bound tp !mx) in *)\n let mxv = lower_bound tp !mx in\n let mxv = if mxv<=0L then (\n 1L\n ) else mxv in\n (* printf \"%Ld : %Ld\\n\" !mx mxv; *)\n let res = List.fold_left ( * ) 1L !r in\n if res = n then printf \"%Ld 0\" res\n else\n printf \"%Ld %Ld\\n\" res\n (mxv + if !alltp then 0L else 1L)\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"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 I64_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 (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\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\nlet sieve n = (* includes 0, O(nloglogn) *)\n let prime = Array.make (n+$1) true in\n prime.(0) <- false;\n prime.(1) <- false;\n for i=2 to n do\n if prime.(i) then let j = ref @@ i*$2 in\n while !j <= n do prime.(!j) <- false; j := !j +$ i; done\n done; prime\n(* let pow n k = fix (fun f n k a ->\n if k=0L then a\n else if k=1L then n*a\n else if k mod 2L = 0L then f (n*n) (k/2L) a\n else f n (k-1L) (a*n)) n k 1L *)\nlet pow n k =\n let rec f a n = function\n | 0L -> a\n | 1L -> n*a\n | k when k mod 2L = 0L -> f a (n*n) (k/2L)\n | k -> f (a*n) n (k-1L)\n in f 1L n k\nlet () =\n let n = get_i64 0 in\n let pr = sieve (i32 n) in\n let i = ref 1L in\n let tp =\n let i = ref 1L in\n let r = ref [] in\n while !i <= 1000000L do\n r := !i :: !r;\n i *= 2L;\n done; !r |> List.rev |> of_list in\n (* print_array ist tp; *)\n let r = ref [] in\n while !i <= n do\n if n mod !i = 0L && pr.(i32 !i) then (\n r := !i :: !r;\n );\n i += 1L;\n done;\n (* print_list ist !r; *)\n let mx = ref 0L in\n let alltp = ref true in\n List.iter (fun p ->\n let m = ref n in\n let k = ref 0L in\n while !m>=1L && !m mod p = 0L do\n k += 1L;\n m := !m / p;\n done;\n let t = lower_bound tp !k |> i32 in\n if t<=0 || i64 t>alen tp || tp.(t) <> !k then alltp := false;\n (* printf \"%Ld %Ld : %d ::: %b\\n\" p !k t !alltp; *)\n mx := max !mx !k\n ) !r;\n (* printf \"%Ld\\n\" !mx; *)\n (* let mxv = tp.(i32 @@ upper_bound tp !mx) in *)\n let mxv = lower_bound tp !mx in\n let mxv = if mxv<=0L then (\n 1L\n ) else mxv in\n (* printf \"%Ld : %Ld\\n\" !mx mxv; *)\n let res = List.fold_left ( * ) 1L !r in\n if res = n then printf \"%Ld 0\" res\n else\n printf \"%Ld %Ld\\n\" res\n (* (mxv + if !alltp then 0L else 1L) *)\n (mxv + if pow res mxv = n then 0L else 1L)\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"nl": {"description": "Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.Help Kurt find the maximum possible product of digits among all integers from $$$1$$$ to $$$n$$$.", "input_spec": "The only input line contains the integer $$$n$$$ ($$$1 \\le n \\le 2\\cdot10^9$$$).", "output_spec": "Print the maximum product of digits among all integers from $$$1$$$ to $$$n$$$.", "sample_inputs": ["390", "7", "1000000000"], "sample_outputs": ["216", "7", "387420489"], "notes": "NoteIn the first example the maximum product is achieved for $$$389$$$ (the product of digits is $$$3\\cdot8\\cdot9=216$$$).In the second example the maximum product is achieved for $$$7$$$ (the product of digits is $$$7$$$).In the third example the maximum product is achieved for $$$999999999$$$ (the product of digits is $$$9^9=387420489$$$)."}, "positive_code": [{"source_code": "\nlet scanf = Scanf.scanf\n\nlet printf = Printf.printf\n\nlet int64_to_nums (src: int64): int array =\n let str = Int64.to_string src in\n let ret = Array.make (String.length str) 0 in\n String.iteri (fun i c -> Array.set ret i ((Char.code c) - (Char.code '0'))) str;\n ret\n\nlet mul (src: int array): int =\n (* let rec f (begun: bool) (i: int) (ret: int): int =\n * if i >= (Array.length src)\n * then ret\n * else\n * let t = src.(i) in\n * if begun || t != 0\n * then f true (i + 1) (ret * t)\n * else f false (i + 1) ret\n * in f false 0 1 *)\n Array.fold_left (fun (begun, ret) t ->\n if begun || t != 0 then (true, ret * t) else (false, ret)\n ) (false, 1) src |> (fun (a, b) -> b)\n\nlet strip_nums (pos: int) (src: int array): int array =\n Array.mapi (fun i v ->\n if i < pos then v else if i = pos then v - 1 else 9) src\n\nlet maximum_mul (src: int array): int =\n let rec f (i: int): int =\n if i >= (Array.length src)\n then 1\n else max (max (mul (strip_nums i src)) (f (i + 1))) (mul src)\n in f 0\n\nlet _ =\n let n = scanf \"%Ld\" (fun a -> a) in\n let nums = int64_to_nums n in\n printf \"%d\\n\" (maximum_mul nums)\n"}], "negative_code": [], "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"nl": {"description": "Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.Note that the game consisted of several complete sets.", "input_spec": "The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).", "output_spec": "If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.", "sample_inputs": ["11 11 5", "11 2 3"], "sample_outputs": ["1", "-1"], "notes": "NoteNote that the rules of the game in this problem differ from the real table tennis game, for example, the rule of \"balance\" (the winning player has to be at least two points ahead to win a set) has no power within the present problem."}, "positive_code": [{"source_code": "let (+) = Int64.add\nand (/) = Int64.div\nand rem = Int64.rem ;;\n\nlet n = Scanf.scanf \"%Ld %Ld %Ld\\n\" (fun k a b ->\n let t = (a / k) + (b / k) in\n if ((a >= k && b >= k)\n || ((rem a k) = Int64.zero && a > Int64.zero)\n || ((rem b k) = Int64.zero && b > Int64.zero)) then t else Int64.minus_one) ;;\n\nPrintf.printf \"%Ld\\n\" n\n"}], "negative_code": [{"source_code": "let n = Scanf.scanf \"%d %d %d\\n\" (fun k a b ->\n let t = (a / k) + (b / k) in\n if t = 0 then -1 else t) ;;\n\nPrintf.printf \"%d\\n\" n\n"}, {"source_code": "let (+) = Int64.add\nand (/) = Int64.div\nand rem = Int64.rem ;;\n\nlet n = Scanf.scanf \"%Ld %Ld %Ld\\n\" (fun k a b ->\n let t = (a / k) + (b / k) in\n if (a >= k && b >= k\n || (rem a k) = Int64.zero\n || (rem b k) = Int64.zero) then t else Int64.minus_one) ;;\n\nPrintf.printf \"%Ld\\n\" n\n"}, {"source_code": "let (+) = Int64.add\nand (/) = Int64.div ;;\n\nlet n = Scanf.scanf \"%Ld %Ld %Ld\\n\" (fun k a b ->\n let t = (a / k) + (b / k) in\n if t = Int64.zero then Int64.minus_one else t) ;;\n\nPrintf.printf \"%Ld\\n\" n\n"}], "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"nl": {"description": "Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.Two prime numbers are called neighboring if there are no other prime numbers between them.You are to help Nick, and find out if he is right or wrong.", "input_spec": "The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).", "output_spec": "Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.", "sample_inputs": ["27 2", "45 7"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form."}, "positive_code": [{"source_code": "let is_prime n =\n if n = 2 then true\n else if n < 2 || n mod 2 = 0 then false\n else\n let rec loop k =\n if k * k > n then true\n else if n mod k = 0 then false\n else loop (k+2)\n in loop 3\n;;\n\nprint_string (Scanf.scanf \"%d %d\" (fun n k ->\n\tlet m = ref 0 in\n\tlet i = ref 3 in\n\tlet last = ref 2 in\n\tlet _ = while (!i) <= n-(!last)-1 do\n\t\tif is_prime(!i) then begin\n\t\t\tif !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)\n\t\t\tthen (incr m);\n\t\t\tlast := (!i)\n\t\tend;\n\t\ti := (!i) + 2;\n\tdone in\n\tif (!m) < k then \"NO\" else \"YES\"\n));;\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet () =\n let b = Array.make 1000 true in\n for i = 2 to 1000-1 do\n if b.(i) then\n let rec go j =\n if j < 1000 then (\n b.(j) <- false;\n go (j+i)\n )\n in\n go (i*i)\n done;\n let n = read_int 0 in\n let k = read_int 0 in\n let rec go acc last i =\n if i >= 504 then\n acc\n else if not b.(i) then\n go acc last (i+1)\n else if last > 0 && last+i+1 <= n && b.(last+i+1) then\n go (acc+1) i (i+1)\n else\n go acc i (i+1)\n in\n print_endline (if go 0 0 2 >= k then \"YES\" else \"NO\")\n"}], "negative_code": [{"source_code": "let is_prime n =\n if n = 2 then true\n else if n < 2 || n mod 2 = 0 then false\n else\n let rec loop k =\n if k * k > n then true\n else if n mod k = 0 then false\n else loop (k+2)\n in loop 3\n;;\n\nprint_string (Scanf.scanf \"%d %d\" (fun n k ->\n\tlet m = ref 0 in\n\tlet i = ref 3 in\n\tlet last = ref 2 in\n\tlet _ = while (!i) <= n/2+2 do\n\t\tif is_prime(!i) then begin\n\t\t\tif !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)\n\t\t\tthen (incr m);\n\t\t\tlast := (!i)\n\t\tend;\n\t\ti := (!i) + 2;\n\tdone in\n\tif (!m) < k then \"NO\" else \"YES\"\n));;\n"}, {"source_code": "let is_prime n =\n if n = 2 then true\n else if n < 2 || n mod 2 = 0 then false\n else\n let rec loop k =\n if k * k > n then true\n else if n mod k = 0 then false\n else loop (k+2)\n in loop 3\n;;\n\nprint_string (Scanf.scanf \"%d %d\" (fun n k ->\n\tlet m = ref 0 in\n\tlet i = ref 3 in\n\tlet last = ref 2 in\n\tlet _ = while (!i) <= n/2 do\n\t\tif is_prime(!i) then begin\n\t\t\tif (!i)+(!last)+1 < n && is_prime((!i)+(!last)+1)\n\t\t\tthen incr m;\n\t\t\tlast := (!i)\n\t\tend;\n\t\ti := (!i) + 2;\n\tdone in\n\tif (!m) < k then \"NO\" else \"YES\"\n));;\n"}, {"source_code": "let is_prime n =\n if n = 2 then true\n else if n < 2 || n mod 2 = 0 then false\n else\n let rec loop k =\n if k * k > n then true\n else if n mod k = 0 then false\n else loop (k+2)\n in loop 3\n;;\n\nprint_string (Scanf.scanf \"%d %d\" (fun n k ->\n\tlet m = ref 0 in\n\tlet i = ref 3 in\n\tlet last = ref 2 in\n\tlet _ = while (!i) < n/2 do\n\t\tif is_prime(!i) then begin\n\t\t\tif (!i)+(!last)+1 < n && is_prime((!i)+(!last)+1)\n\t\t\tthen incr m;\n\t\t\tlast := (!i)\n\t\tend;\n\t\ti := (!i) + 2;\n\tdone in\n\tif (!m) < k then \"NO\" else \"YES\"\n));;\n"}, {"source_code": "let is_prime n =\n if n = 2 then true\n else if n < 2 || n mod 2 = 0 then false\n else\n let rec loop k =\n if k * k > n then true\n else if n mod k = 0 then false\n else loop (k+2)\n in loop 3\n;;\n\nprint_string (Scanf.scanf \"%d %d\" (fun n k ->\n\tlet m = ref 0 in\n\tlet i = ref 3 in\n\tlet last = ref 2 in\n\tlet _ = while (!i) <= n/2+1 do\n\t\tif is_prime(!i) then begin\n\t\t\tif !i+ !last+ 1 <= n && is_prime(!i+ !last+ 1)\n\t\t\tthen (incr m);\n\t\t\tlast := (!i)\n\t\tend;\n\t\ti := (!i) + 2;\n\tdone in\n\tif (!m) < k then \"NO\" else \"YES\"\n));;\n"}], "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"nl": {"description": "For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight line from point si to point fi (si < fi).Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius r. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius r. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle.At the beginning each participant can choose any point bi, such that his bike is fully behind the starting line, that is, bi < si - r. After that, he starts the movement, instantly accelerates to his maximum speed and at time tsi, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time tfi), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time tfi - tsi. Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed v, but also on his choice of the initial point bi. Now Maxim is asking you to calculate for each of n competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to r.", "input_spec": "The first line contains three integers n, r and v (1 ≤ n ≤ 100 000, 1 ≤ r, v ≤ 109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively. Next n lines contain the descriptions of the contests. The i-th line contains two integers si and fi (1 ≤ si < fi ≤ 109) — the coordinate of the start and the coordinate of the finish on the i-th competition.", "output_spec": "Print n real numbers, the i-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10 - 6. Namely: let's assume that your answer equals a, and the answer of the jury is b. The checker program will consider your answer correct if .", "sample_inputs": ["2 1 2\n1 10\n5 9"], "sample_outputs": ["3.849644710502\n1.106060157705"], "notes": null}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet pi = 2.0 *. (acos 0.0)\nlet sq x = x *. x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let r = float (read_int ()) in\n let v = float (read_int ()) in\n\n let solve s f =\n let period = 2.0 *. pi *. r in\n let dist = f -. s in\n let ncycles = floor (dist /. period) in\n let dist = dist -. ncycles *. period in\n\n let dist_of alpha =\n (* increasing function of alpha *)\n let q = r *. (sin alpha) in\n let rolling_dist = 2.0 *. alpha *. r in\n rolling_dist +. 2.0 *. q\n in\n\n let rec bsearch lo hi =\n let a = (lo +. hi) /. 2.0 in\n if (hi -. lo) < 1e-15 then a else\n\tif dist_of a < dist then bsearch a hi else bsearch lo a\n in\n\n let alpha = bsearch 0.0 pi in\n let total_angular_dist = ncycles *. 2.0 *. pi +. 2.0 *. alpha in\n let angular_velocity = v /. r in\n total_angular_dist /. angular_velocity\n in\n\n for i=0 to n-1 do\n let s = float (read_int ()) in\n let f = float (read_int ()) in\n printf \"%.12f\\n\" (solve s f)\n done\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet pi = 2.0 *. (acos 0.0)\nlet sq x = x *. x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let r = float (read_int ()) in\n let v = float (read_int ()) in\n\n let solve s f =\n let period = 2.0 *. pi *. r in\n let dist = f -. s in\n let ncycles = floor (dist /. period) in\n let dist = dist -. ncycles *. period in\n\n let dist_of_h h =\n (* decreasing function of h *)\n let q = sqrt ((sq r) -. (sq (h -.r))) in\n let alpha = acos ((h -. r) /. r) in\n let rolling_dist = 2.0 *. alpha *. r in\n (rolling_dist +. 2.0 *. q, alpha)\n in\n\n let end_test lo hi =\n if hi >= 1.0 then (hi -. lo) /. hi < 1e-12 else hi -. lo < 1e-12\n in\n \n let rec bsearch lo hi =\n let h = (lo +. hi) /. 2.0 in\n if end_test lo hi then h else\n\tif fst (dist_of_h h) < dist then bsearch lo h else bsearch h hi\n in\n\n let h = bsearch 0.0 (r +. r) in\n let alpha = snd (dist_of_h h) in\n let total_angular_dist = ncycles *. 2.0 *. pi +. 2.0 *. alpha in\n let angular_velocity = v /. r in\n total_angular_dist /. angular_velocity\n in\n\n for i=0 to n-1 do\n let s = float (read_int ()) in\n let f = float (read_int ()) in\n printf \"%.12f\\n\" (solve s f)\n done\n"}], "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88"} {"nl": {"description": "Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x1, x2, x3 and three more integers y1, y2, y3, such that x1 < x2 < x3, y1 < y2 < y3 and the eight point set consists of all points (xi, yj) (1 ≤ i, j ≤ 3), except for point (x2, y2).You have a set of eight points. Find out if Gerald can use this set?", "input_spec": "The input consists of eight lines, the i-th line contains two space-separated integers xi and yi (0 ≤ xi, yi ≤ 106). You do not have any other conditions for these points.", "output_spec": "In a single line print word \"respectable\", if the given set of points corresponds to Gerald's decency rules, and \"ugly\" otherwise.", "sample_inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2"], "sample_outputs": ["respectable", "ugly", "ugly"], "notes": null}, "positive_code": [{"source_code": "(* Codeforces contest 327A - perevorachivania Wrong - have to turn at *)\n(* least one *)\n\nopen Filename;;\n\n(* you can use either gr or rdln but not both *)\nlet use_input_txt = false;;\nlet fn = (Filename.dirname Filename.current_dir_name);;\nlet filename = Filename.concat \".\" \"input.txt\";;\nlet cin = if use_input_txt then Scanf.Scanning.open_in filename\n\telse Scanf.Scanning.stdin;;\n\nlet cout = open_out \"output.txt\";;\nlet gr () = Scanf.bscanf cin \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\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 printlisti64 li = List.iter (fun i -> (print_string (Int64.to_string i); print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet rec readlist n acc = match n with | 0 -> List.rev acc | _ -> readlist (n -1) (gr() :: acc);;\nlet rec readpairs n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readpairs\n\t\t\t\t(n -1)\n\t\t\t\t(\n\t\t\t\t\tlet a = gr() in\n\t\t\t\t\tlet b = gr() in\n\t\t\t\t\t(* let _ = Printf.printf \"a,b = %d %d\\n\" a b in *)\n\t\t\t\t\t(a, b) :: acc\n\t\t\t\t);;\nlet debug = false;;\n\nlet m8 = Array.make_matrix 3 3 0;;\n\nlet rec unique last sls = match sls with (* find unique elements in sorted list *)\n\t| [] -> []\n\t| h :: t -> if (h == last) then unique last t\n\t\t\telse h :: (unique h t);;\n\nlet rec get_su l =\n\tlet sortl = List.sort compare l in\n\tlet uni = unique (-1) sortl in\n\tuni;;\n\nlet get_idx x a =\n\tif x == a.(0) then 0\n\telse if x == a.(1) then 1\n\telse if x == a.(2) then 2\n\telse -999;;\n\nlet rec setm8 aa bb pl = match pl with\n\t| [] -> ()\n\t| (a, b) :: t -> (\n\t\t\t\tlet ia = get_idx a aa in\n\t\t\t\tlet ib = get_idx b bb in\n\t\t\t\tif 0<=ia && ia<=2 && 0<=ib && ib<=2 \n\t\t\t\tthen m8.(ia).(ib) <- (m8.(ia).(ib) + 1);\n\t\t\t\tsetm8 aa bb t\n\t\t\t);;\n\nlet checkm8 () =\n\t(\n\t\tlet rok = ref true in\n\t\t(\n\t\t\tfor i = 0 to 2 do\n\t\t\t\tfor j = 0 to 2 do\n\t\t\t\t\tif (i =1) && (j =1) then\n\t\t\t\t\t\trok := !rok && (m8.(i).(j) = 0)\n\t\t\t\t\telse\n\t\t\t\t\t\trok := !rok && (m8.(i).(j) = 1)\n\t\t\t\tdone\n\t\t\tdone\n\t\t);\n\t\t!rok\n\t);;\n\nlet main() =\n\tlet prs = readpairs 8 [] in\n\tlet al = get_su (List.map (fun (a, b) -> a) prs) in\n\tlet bl = get_su (List.map (fun (a, b) -> b) prs) in\n\tlet aa = Array.of_list al in\n\tlet bb = Array.of_list bl in\n\tlet _ = setm8 aa bb prs in\n\t(\n\t\tif checkm8() then\tprint_string \"respectable\"\n\t\telse print_string \"ugly\";\n\t\tprint_newline ()\n\t);;\n\nmain();;\n"}], "negative_code": [], "src_uid": "f3c96123334534056f26b96f90886807"} {"nl": {"description": "Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: \"If you solve the following problem, I'll return it to you.\" The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.", "input_spec": "The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).", "output_spec": "Print the index of n among all lucky numbers.", "sample_inputs": ["4", "7", "77"], "sample_outputs": ["1", "2", "6"], "notes": null}, "positive_code": [{"source_code": "let nombre = ref (read_int ()) and nb_avant = ref 0 and puissance = ref 1;;\nwhile !nombre > 0 do\n\tif !nombre mod 10 = 7 then nb_avant := !nb_avant + !puissance;\n\tpuissance := !puissance * 2;\n\tnombre := !nombre / 10\ndone;;\nprint_int (!nb_avant + !puissance - 1);;\nprint_newline ();;\n"}, {"source_code": "let rec puiss = function\n\t|0\t-> 1\n\t|n\t-> let demi = puiss (n/2) in\n\t\t\t(1 + n mod 2) * demi * demi\n\nlet f = function '4' -> 1 | '7' -> 2\n\nlet rec place mot long n =\n\tif n = long\n\t\tthen 0\n\t\telse (f (mot.[n]))*(puiss (long-n-1)) + place mot long (n+1)\n\nlet final n =\n\tlet mot = string_of_int n in\n\tplace mot (String.length mot) 0\n\nlet () =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) in\n\t\tPrintf.printf \"%d\" (final n)\n"}], "negative_code": [], "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"nl": {"description": "Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.", "input_spec": "There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.", "output_spec": "Write one line — the corresponding answer. Do not omit the leading 0s.", "sample_inputs": ["1010100\n0100101", "000\n111", "1110\n1010", "01110\n01100"], "sample_outputs": ["1110001", "111", "0100", "00010"], "notes": null}, "positive_code": [{"source_code": "let solve () = \n let a = Pervasives.read_line () in\n let b = Pervasives.read_line () in\n let l = String.length a in\n let rec loop i result = \n if i < l\n then\n if a.[i] = b.[i]\n then\n loop (i + 1) (0 :: result)\n else\n loop (i + 1) (1 :: result)\n else\n List.rev result\n in loop 0 []\n\nlet () = List.iter(Printf.printf \"%d\") (solve ())"}, {"source_code": "(fun x y -> for i = 0 to String.length x - 1 do ( print_string(if String.get x i == String.get y i then \"0\" else \"1\") ) done ) (read_line()) (read_line())\n"}, {"source_code": "let a = read_line () in\nString.iter (fun c ->\n\tprint_char (if c <> (input_char stdin) then '1' else '0')\n) a;;\n"}], "negative_code": [], "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"nl": {"description": "The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.", "input_spec": "The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).", "output_spec": "Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.", "sample_inputs": ["1 3", "5 5"], "sample_outputs": ["0.500000000", "0.658730159"], "notes": "NoteLet's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins."}, "positive_code": [{"source_code": "(* codeforces 105. Danny Sleator *)\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 () =\n let wmax = read_int() in\n let bmax = read_int() in\n\n let p = Array.make_matrix (wmax+1) (bmax+1) 0.0 in\n let d = Array.make_matrix (wmax+1) (bmax+1) 0.0 in\n\n let compute_p w b = \n(* Printf.printf \"in compute_p %d %d\\n\" w b; *)\n if w=0 then 0.0 else \n let fw = float w in\n let fb = float b in\n let den = fw +. fb in\n fw /. den +. (if b=0 then 0.0 else (fb /. den) *. (1.0 -. d.(w).(b-1)))\n in\n\n\n let compute_d w b = \n(* Printf.printf \"in compute_d %d %d\\n\" w b; *)\n if w=0 then 1.0 else\n let fw = float w in\n let fb = float b in\n let den = fw +. fb in\n fw /. den +. (if b=0 then 0.0 else (fb /. den) *. (\n\t\t (1.0 -. p.(w-1).(b-1)) *. (fw /. (den -. 1.0)) +.\n\t\t\t(if b=1 then 0.0 else (1.0 -. p.(w).(b-2)) *. ((fb -. 1.0) /. (den -. 1.0)))))\n\t\t \n in\n\n for sum = 0 to wmax+bmax do\n for w = max 0 (sum-bmax) to min sum wmax do\n\tlet b = sum - w in\n\t p.(w).(b) <- compute_p w b;\n\t d.(w).(b) <- compute_d w b\n done\n done;\n Printf.printf \"%12.9f\\n\" p.(wmax).(bmax)\n \n"}], "negative_code": [], "src_uid": "7adb8bf6879925955bf187c3d05fde8c"} {"nl": {"description": "You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than ai times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. ", "input_spec": "The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet. The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.", "output_spec": "Print a single integer — the maximum length of the string that meets all the requirements.", "sample_inputs": ["3\n2 5 5", "3\n1 1 2"], "sample_outputs": ["11", "3"], "notes": "NoteFor convenience let's consider an alphabet consisting of three letters: \"a\", \"b\", \"c\". In the first sample, some of the optimal strings are: \"cccaabbccbb\", \"aabcbcbcbcb\". In the second sample some of the optimal strings are: \"acc\", \"cbc\"."}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet ( ++ ) a b = Int64.add a b\nlet long x = Int64.of_int x\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n\n Array.sort (fun p q -> compare q p) a;\n\n let b = Array.copy a in\n\n for i=1 to n-1 do\n b.(i) <- max 0 (min (b.(i-1) - 1) a.(i))\n done;\n\n let answer = sum 0 (n-1) (fun i -> long b.(i)) 0L in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [], "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"nl": {"description": "n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.", "input_spec": "The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively. ", "output_spec": "The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.", "sample_inputs": ["5 1", "3 2", "6 3"], "sample_outputs": ["10 10", "1 1", "3 6"], "notes": "NoteIn the first sample all the participants get into one team, so there will be exactly ten pairs of friends.In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people."}, "positive_code": [{"source_code": "let ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( / ) = Int64.div\nlet ( %% ) = Int64.rem\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet input () = Scanf.scanf \"%Ld %Ld \" (fun n m -> (n, m))\n\nlet choose_2 x =\n (x * (x - one)) / two\n\nlet solve (n, m) = \n let min = choose_2 (n / m + one) * (n %% m) + \n choose_2 (n / m) * (m - (n %% m)) in\n let max = choose_2 (n - (m - one)) in\n (min, max)\n\nlet print (a, b) = Printf.printf \"%Ld %Ld\\n\" a b\n\nlet () = print (solve (input ()))"}], "negative_code": [{"source_code": "let ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( / ) = Int64.div\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet input () = Scanf.scanf \"%Ld %Ld \" (fun n m -> (n, m))\n\nlet factorial n =\n let rec loop x =\n if x <= one \n then \n one \n else \n x * loop (x - one)\n in loop n\n\nlet count_pairs flag n m =\n let (y, z) =\n match flag with\n | `minimum -> (two, m - one)\n | `maximum -> (one, zero)\n in\n let x = n - y * (m - one) in\n (x, z)\n\nlet count_friends (x, z) =\n x * (x - one) + z\n\nlet solve (n, m) = \n let min = count_friends (count_pairs `minimum n m) in\n let max = count_friends (count_pairs `maximum n m) in\n (min, max)\n\nlet print (a, b) = Printf.printf \"%Ld %Ld\\n\" a b\n\nlet () = print (solve (input ()))"}, {"source_code": "let ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( / ) = Int64.div\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet input () = Scanf.scanf \"%Ld %Ld \" (fun n m -> (n, m))\n\nlet factorial n =\n let rec loop x =\n if x <= one \n then \n one \n else \n x * loop (x - one)\n in loop n\n\nlet count_pairs flag n m =\n let (y, z) =\n match flag with\n | `minimum -> (two, m - one)\n | `maximum -> (one, zero)\n in\n let x = n - y * (m - one) in\n (x, z)\n\nlet count_friends (x, z) =\n ((x * (x - one)) / two) + z\n\nlet solve (n, m) = \n let min = count_friends (count_pairs `minimum n m) in\n let max = count_friends (count_pairs `maximum n m) in\n (min, max)\n\nlet print (a, b) = Printf.printf \"%Ld %Ld\\n\" a b\n\nlet () = print (solve (input ()))"}, {"source_code": "let ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( / ) = Int64.div\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet input () = Scanf.scanf \"%Ld %Ld \" (fun n m -> (n, m))\n\nlet factorial x =\n (x * (x - one)) / two\n\nlet count_pairs flag n m =\n let z =\n match flag with\n | `minimum -> n / m\n | `maximum -> one\n in\n let y = m - one in\n let x = n - z * y in\n (x, y, z)\n\nlet count_friends (x, y, z) =\n factorial x + (factorial z) * y\n\nlet solve (n, m) = \n let min = count_friends (count_pairs `minimum n m) in\n let max = count_friends (count_pairs `maximum n m) in\n (min, max)\n\nlet print (a, b) = Printf.printf \"%Ld %Ld\\n\" a b\n\nlet () = print (solve (input ()))"}], "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"nl": {"description": "On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.", "input_spec": "The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).", "output_spec": "Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. ", "sample_inputs": ["1 3 8 1 1", "4 2 9 4 2", "5 5 25 4 3", "100 100 1000000000000000000 100 100"], "sample_outputs": ["3 2 3", "2 1 1", "1 1 1", "101010101010101 50505050505051 50505050505051"], "notes": "NoteThe order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table; "}, "positive_code": [{"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n if n = 1L then (\n let p = (k /| m) in\n let rmax =\n\tif Int64.rem k m = 0L\n\tthen p\n\telse p +| 1L\n in\n let rmin = p in\n let rser =\n\tif Int64.of_int y >= Int64.rem k m\n\tthen p\n\telse p +| 1L\n in\n\tPrintf.printf \"%Ld %Ld %Ld\\n\" rmax rmin rser\n ) else (\n let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in\n let t = (2L *| n -| 2L) *| m in\n let p = k /| t in\n let n = Int64.to_int n in\n let m = Int64.to_int m in\n\tfor i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t if i = 0 || i = n - 1\n\t then a.(i).(j) <- p\n\t else a.(i).(j) <- 2L *| p\n\t done;\n\tdone;\n\tfor i = 0 to Int64.to_int (Int64.rem k t) - 1 do\n\t let y' = i mod m in\n\t let x' = i / m in\n\t let x' =\n\t if x' >= n\n\t then 2 * n - 2 - x'\n\t else x'\n\t in\n\t a.(x').(y') <- a.(x').(y') +| 1L\n\tdone;\n\t(*for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t Printf.printf \" %Ld\" a.(i).(j)\n\t done;\n\t Printf.printf \"\\n\"\n\tdone;*)\n\tlet rmax = ref a.(0).(0) in\n\tlet rmin = ref a.(0).(0) in\n\tlet rser = ref a.(x).(y) in\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t rmax := max !rmax a.(i).(j);\n\t rmin := min !rmin a.(i).(j);\n\t done;\n\t done;\n\t Printf.printf \"%Ld %Ld %Ld\\n\" !rmax !rmin !rser\n )\n"}], "negative_code": [{"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n if n = 1L then (\n let p = (k /| m) in\n let rmax =\n\tif Int64.rem k m = 0L\n\tthen p\n\telse p +| 1L\n in\n let rmin = p in\n let rser =\n\tif Int64.of_int y >= Int64.rem k m\n\tthen p\n\telse p +| 1L\n in\n\tPrintf.printf \"%Ld %Ld %Ld\\n\" rmax rmin rser\n ) else (\n let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in\n let t = (2L *| n -| 2L) *| m in\n let p = k /| t in\n let n = Int64.to_int n in\n let m = Int64.to_int m in\n\tfor i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t if i = 0 || i = n - 1\n\t then a.(i).(j) <- p\n\t else a.(i).(j) <- 2L *| p\n\t done;\n\tdone;\n\tfor i = 0 to Int64.to_int (Int64.rem k t) - 1 do\n\t let y' = i mod m in\n\t let x' = i / m in\n\t let x' =\n\t if x' >= n\n\t then n - x'\n\t else x'\n\t in\n\t a.(x').(y') <- a.(x').(y') +| 1L\n\tdone;\n\tlet rmax = ref a.(0).(0) in\n\tlet rmin = ref a.(0).(0) in\n\tlet rser = ref a.(x).(y) in\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t rmax := max !rmax a.(i).(j);\n\t rmin := min !rmin a.(i).(j);\n\t done;\n\t done;\n\t Printf.printf \"%Ld %Ld %Ld\\n\" !rmax !rmin !rser\n )\n"}, {"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n if n = 1L then (\n let p = (k /| m) in\n let rmax =\n\tif Int64.rem k m = 0L\n\tthen p\n\telse p +| 1L\n in\n let rmin = p in\n let rser =\n\tif Int64.of_int x >= Int64.rem k m\n\tthen p\n\telse p +| 1L\n in\n\tPrintf.printf \"%Ld %Ld %Ld\\n\" rmax rmin rser\n ) else (\n let a = Array.make_matrix (Int64.to_int n) (Int64.to_int m) 0L in\n let t = (2L *| n -| 2L) *| m in\n let p = k /| t in\n let n = Int64.to_int n in\n let m = Int64.to_int m in\n\tfor i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t if i = 0 || i = n - 1\n\t then a.(i).(j) <- p\n\t else a.(i).(j) <- 2L *| p\n\t done;\n\tdone;\n\tfor i = 0 to Int64.to_int (Int64.rem k t) - 1 do\n\t let y' = i mod m in\n\t let x' = i / m in\n\t let x' =\n\t if x' >= n\n\t then n - x'\n\t else x'\n\t in\n\t a.(x').(y') <- a.(x').(y') +| 1L\n\tdone;\n\tlet rmax = ref a.(0).(0) in\n\tlet rmin = ref a.(0).(0) in\n\tlet rser = ref a.(x).(y) in\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t rmax := max !rmax a.(i).(j);\n\t rmin := min !rmin a.(i).(j);\n\t done;\n\t done;\n\t Printf.printf \"%Ld %Ld %Ld\\n\" !rmax !rmin !rser\n )\n"}], "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"} {"nl": {"description": "Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).Find the number on the n-th position of the sequence.", "input_spec": "The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "output_spec": "Print the element in the n-th position of the sequence (the elements are numerated from one).", "sample_inputs": ["3", "5", "10", "55", "56"], "sample_outputs": ["2", "2", "4", "10", "1"], "notes": null}, "positive_code": [{"source_code": "open Big_int\n\nlet (+|) = add_big_int\nlet (-|) = sub_big_int\nlet ( *| ) = mult_big_int\nlet (/|) = div_big_int\nlet bmod = mod_big_int\nlet (=|) = eq_big_int\nlet (/=|) a b = not (a =| b)\nlet (>|) = gt_big_int\nlet (<|) = lt_big_int\nlet (>=|) = ge_big_int\nlet (<=|) = le_big_int\n\nlet n0 = zero_big_int\nlet n1 = unit_big_int\nlet n2 = big_int_of_int 2\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = big_int_of_string n in\n let d = n1 +| big_int_of_int 8 *| (n -| n1) in\n let sd = sqrt_big_int d in\n let k = (sd -| n1) /| n2 in\n let res = n -| k *| (k +| n1) /| n2 in\n Printf.printf \"%s\\n\" (string_of_big_int res)\n"}], "negative_code": [], "src_uid": "1db5631847085815461c617854b08ee5"} {"nl": {"description": "Some country is populated by wizards. They want to organize a demonstration.There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.", "input_spec": "The first line contains three space-separated integers, n, x, y (1 ≤ n, x, y ≤ 104, x ≤ n) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n).", "output_spec": "Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). ", "sample_inputs": ["10 1 14", "20 10 50", "1000 352 146"], "sample_outputs": ["1", "0", "1108"], "notes": "NoteIn the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones."}, "positive_code": [{"source_code": "\nlet (|>) x f = f x\nlet identity = fun x -> x\n \nlet flip f y x = f x y\n \nlet readInStr _ = Scanf.scanf \"%d \" identity\nlet readIntLn _ = Scanf.scanf \"%d\\n\" identity\nlet main () =\n let n = readInStr () in\n let x = readInStr () in\n let y = readIntLn () in\n let b = (float (n * y) ) /. 100.0 |> ceil|>truncate in\n print_int (if b true\n | (r1 :: res1, r2 :: res2) ->\n if r1 = r2 then compare (res1, res2)\n else false\n | _ -> false\n in\n if compare (s5, s6) then\n print_endline \"YES\"\n else\n print_endline \"NO\";;\n\n"}, {"source_code": "let a = Scanf.scanf \"%s\\n\" (fun x->x);;\nlet b = Scanf.scanf \"%s\\n\" (fun x->x);;\nlet l = Scanf.scanf \"%s\\n\" (fun x->x);;\n\nlet letters = Hashtbl.create 0;;\n\nString.iter (fun c ->\n\tif Hashtbl.mem letters c then\n\t\tHashtbl.replace letters c (Hashtbl.find letters c + 1)\n\telse\n\t\tHashtbl.add letters c 1\n) l;;\n\nlet it c =\n\ttry\n\t\tHashtbl.replace letters c (Hashtbl.find letters c - 1)\n\twith _ -> (print_string \"NO\";exit 0)\n;;\n\nString.iter it a;;\nString.iter it b;;\n\nHashtbl.iter (fun _ x ->\n\tif x <> 0 then begin print_string \"NO\"; exit 0 end\n) letters;;\n\nprint_string \"YES\";;\n"}, {"source_code": "let list_of_string str =\n let rec loop i lst =\n match i with\n | -1 -> lst\n | i -> loop (i-1) ((String.get str i) :: lst)\n in\n loop ((String.length str)-1) []\n\nlet sort lst = List.sort compare lst\n\nlet equal lst1 lst2 =\n let rec loop lst1 lst2 =\n match lst1 with\n\t| [] -> lst2 = []\n\t| h :: t ->\n\t if h = List.hd lst2 then loop t (List.tl lst2)\n\t else false\n in\n if List.length lst1 < List.length lst2\n then loop lst1 lst2\n else loop lst2 lst1\n \nlet solve guest_name host_name shuffled_name =\n let guest_name = list_of_string guest_name in\n let host_name = list_of_string host_name in\n let shuffled_name = list_of_string shuffled_name in\n if equal (sort (guest_name @ host_name)) (sort shuffled_name)\n then \"YES\"\n else \"NO\"\n\nlet _ =\n let guest_name = Scanf.scanf \"%s\\n\" (fun s -> s) in\n let host_name = Scanf.scanf \"%s\\n\" (fun s -> s) in\n let shuffled_name = Scanf.scanf \"%s\\n\" (fun s -> s) in\n begin\n Printf.printf \"%s\\n\" (solve guest_name host_name shuffled_name)\n end\n"}, {"source_code": "\n(* Codeforces 141A *)\n\nlet string_to_char_list s =\n let len = String.length s in\n let rec inner l = function\n | 0 -> s.[0] :: l\n | i -> inner (s.[i] :: l) (i-1)\n in\n inner [] (len-1)\n\nlet _ =\n let guest = read_line() in\n let host = read_line() in\n let shuffled_letters = read_line() in\n let buf1 =\n List.sort compare ((string_to_char_list guest) @\n\t (string_to_char_list host)) in\n let buf2 = List.sort compare (string_to_char_list (shuffled_letters)) in\n let answer = \n if (buf1 = buf2)\n then \"YES\"\n else \"NO\"\n in\n print_endline answer\n \n"}, {"source_code": "\n(* Codeforces 141A *)\n\nlet string_to_char_list s =\n let len = String.length s in\n let rec inner l = function\n | 0 -> s.[0] :: l\n | i -> inner (s.[i] :: l) (i-1)\n in\n inner [] (len-1)\n\nlet _ =\n let guest = read_line() in\n let host = read_line() in\n let shuffled_letters = read_line() in\n let buf1 = List.sort Char.compare (string_to_char_list (guest^host)) in\n let buf2 = List.sort Char.compare (string_to_char_list (shuffled_letters)) in\n let answer = \n if (buf1 = buf2)\n then \"YES\"\n else \"NO\"\n in\n Printf.printf \"%s\\n\" answer\n \n"}, {"source_code": "let read () = Pervasives.read_line ()\n\nlet get_strings () = \n let host = read () in\n let guest = read () in\n let letters = read () in\n let names = host ^ guest in\n (letters, names)\n\nlet str_to_list s =\n let rec loop i l =\n if i < 0 \n then \n l \n else \n loop (i - 1) (s.[i] :: l)\n in loop (String.length s - 1) []\n\nlet solve (letters, names) = \n let letters_sorted = List.sort Pervasives.compare (str_to_list letters) in\n let names_sorted = List.sort Pervasives.compare (str_to_list names) in\n if (Pervasives.compare letters_sorted names_sorted) = 0\n then\n \"YES\"\n else\n \"NO\"\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (get_strings ()))"}], "negative_code": [{"source_code": "let a = Scanf.scanf \"%s\\n\" (fun x->x);;\nlet b = Scanf.scanf \"%s\\n\" (fun x->x);;\nlet l = Scanf.scanf \"%s\\n\" (fun x->x);;\n\nlet letters = Hashtbl.create 0;;\n\nString.iter (fun c ->\n\tif Hashtbl.mem letters c then\n\t\tHashtbl.replace letters c (Hashtbl.find letters c + 1)\n\telse\n\t\tHashtbl.add letters c 1\n) l;;\n\nlet it c =\n\ttry\n\t\tHashtbl.replace letters c (Hashtbl.find letters c - 1)\n\twith _ -> (print_string \"NO\";exit 0)\n;;\n\nString.iter it a;;\nString.iter it b;;\n\nHashtbl.iter (fun _ x ->\n\tif x < 0 then begin print_string \"NO\"; exit 0 end\n) letters;;\n\nprint_string \"YES\";;\n"}, {"source_code": "let x, y = Scanf.scanf \"%f %f %f\\n\" (fun a x y -> ( x /. a , y /. a -. 1.));;\n\nif (x < 0.5) && (x > -0.5) && (y < 0.0) && (y > -1.0) then begin\n\tprint_string \"1\";\n\texit 0;\nend;;\n\nif (y -. (floor y)) = 0. then begin\n\tprint_string \"-1\";\n\texit 0;\nend;;\n\nif (int_of_float (floor y)) mod 2 = 0 then begin\n\tif (x < 0.5) && (x > -0.5) then begin\n\t\tprint_int ((int_of_float (floor y)) / 2 * 3 + 2);\n\tend else begin\n\t\tprint_string \"-1\";\n\t\texit 0;\n\tend\nend else begin\n\tif ((x > 0.) && (x < 1.)) then begin\n\t\tprint_int ((int_of_float (floor y)) / 2 * 3 + 4);\n\tend else if ((x > -1.) && (x < 0.)) then begin\n\t\tprint_int ((int_of_float (floor y)) / 2 * 3 + 3);\n\tend else begin\n\t\tprint_string \"-1\";\n\t\texit 0;\n\tend\nend;;\n"}], "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"nl": {"description": "Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. ", "input_spec": "The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.", "output_spec": "Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.", "sample_inputs": ["2", "6"], "sample_outputs": ["462", "8080"], "notes": null}, "positive_code": [{"source_code": "\nopen Scanf\nopen Printf\n\nlet loops = [| 1; 0; 0; 0; 1; 0; 1; 0; 2; 1 |]\n\nlet compute k =\n if k > 2 * 18 then \"-1\" else\n let rec inner str = function\n | 0 -> str\n | 1 -> str ^ \"6\"\n | k -> inner (str ^ \"8\") (k - 2)\n in\n inner \"\" k\n\nlet () =\n let k = scanf \" %u\\n\" (fun x -> x) in\n compute k |> print_endline"}], "negative_code": [{"source_code": "\nopen Scanf\nopen Printf\n\nlet loops = [| 1; 0; 0; 0; 1; 0; 1; 0; 2; 1 |]\n\nlet compute k =\n if k > 144 then \"-1\" else\n let rec inner str = function\n | 0 -> str\n | 1 -> str ^ \"6\"\n | k -> inner (str ^ \"8\") (k - 2)\n in\n inner \"\" k\n\nlet () =\n let k = scanf \" %u\\n\" (fun x -> x) in\n compute k |> print_endline"}], "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"nl": {"description": "Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.A k-tree is an infinite rooted tree where: each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k. The picture below shows a part of a 3-tree. As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: \"How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?\".Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7). ", "input_spec": "A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).", "output_spec": "Print a single integer — the answer to the problem modulo 1000000007 (109 + 7). ", "sample_inputs": ["3 3 2", "3 3 3", "4 3 2", "4 5 2"], "sample_outputs": ["3", "1", "6", "7"], "notes": null}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet mm = 1000000007L\n\nlet ( ++ ) a b = \n let a = Int64.of_int a in\n let b = Int64.of_int b in\n let ans = Int64.rem (Int64.add a b) mm in\n Int64.to_int ans\n\nlet () = \n let n = read_int () in\n let k = read_int () in\n let d = read_int () in\n\n let a = Array.make_matrix (n+1) (n+k+1) 0 in\n let b = Array.make_matrix (n+1) (n+k+1) 0 in\n\n a.(0).(0) <- 1;\n\n let count = ref 0 in\n\n let rec pass i = \n (* job is to fill in the i+1 st position and continue *)\n if i+1 > n then () else (\n for s=0 to n do\n\tfor v = 1 to k do\n\t if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) ++ a.(i).(s);\n\t b.(i+1).(s+v) <- b.(i+1).(s+v) ++ b.(i).(s);\n\t if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) ++ a.(i).(s);\n\tdone\n done;\n count := !count ++ b.(i+1).(n);\n pass (i+1)\n )\n in\n\n pass 0;\n\n printf \"%d\\n\" !count\n"}, {"source_code": "open Printf\nopen String\nopen Bigarray\nopen Num\n \nlet (n1,k,d) = Scanf.scanf \"%d %d %d \" (fun x y z -> (x,y,z));;\n\nlet dp = Array.init (n1+2) (fun _ -> Array.make 3 (num_of_int (-10)) )\n\nlet modn = num_of_int 1000000007\n \nlet rec ways n flag =\n if n= 0 then\n if flag=1 then num_of_int 1\n else num_of_int 0\n else if n< 0 then\n num_of_int 0\n else\n begin\n let x = dp.(n).(flag) in\n if x >=/ num_of_int 0 then\n x\n else\n begin\n let cnt = ref (num_of_int 0) in\n for i = 1 to d-1 do\n cnt := !cnt +/ (ways (n-i) flag)\n done;\n for i = d to k do\n cnt := !cnt +/ (ways (n-i) 1)\n done; cnt:=mod_num !cnt modn; dp.(n).(flag)<- !cnt; !cnt\n end\n end\n \nlet rslt = ways n1 0\n \nlet _ = printf \"%s\\n\" (string_of_num rslt)\n"}, {"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(* 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\nlet read_int64 () = \n let digit c = Int64.of_int( int_of_char c - 48 )in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (Int64.add (Int64.mul 10L 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 Int64.neg (read (digit c)) else run c \n end else \n if c = '\\000' then 0L else \n run (read_char())\n in \n run (read_char())\n\nmodule LL = struct \n include Int64\n let (+) a b = add a b \n let (-) a b = sub a b \n let ( * ) a b = mul a b \n let (/) a b = div a b \n let (mod) a b = rem a b \n let (land) a b = logand a b \n let (lor) a b = logor a b \n let (lxor) a b = logxor a b \n let (lnot) a = lognot a \nend \n\nlet modulo = 1_000_000_007L\n\nlet isum n up = \n let arr = make (LL.to_int n + 1) (-1L) in\n let read n = arr.(LL.to_int n) in \n let save n v = arr.(LL.to_int n) <- v; v in \n\n let rec run (n: int64) = LL.(\n if read n <> -1L then read n else \n let ans = \n if n <= 1L then 1L else \n let t = 2L * run (n-1L) mod modulo in \n if n <= up then t else \n (t - run (n-1L-up)) mod modulo \n in \n save n ans \n ) in \n if up = 0L then 0L else LL.((run n + modulo) mod modulo)\n\nlet _ = \n let n = read_int64() in \n let k = read_int64() in \n let d = read_int64() in \n let ans = LL.( (isum n k - isum n (d-1L) + modulo) mod modulo) in \n printf \"%s\\n\" (LL.to_string ans) \n\n(* let _ = \n for i = 0 to 10 do \n let i = LL.of_int i in \n printf \"%s\\n\" (LL.to_string (isum i i))\n done *)"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet mm = 1000000007L\n\nlet ( ++ ) a b = \n let a = Int64.of_int a in\n let b = Int64.of_int b in\n let ans = Int64.rem (Int64.add a b) mm in\n Int64.to_int ans\n\nlet () = \n let n = read_int () in\n let k = read_int () in\n let d = read_int () in\n\n let a = Array.make_matrix (n+1) (n+k+1) 0 in\n let b = Array.make_matrix (n+1) (n+k+1) 0 in\n\n a.(0).(0) <- 1;\n\n let count = ref 0 in\n\n let rec pass i = \n (* job is to fill in the i+1 st position and continue *)\n if i+1 > n then () else (\n for s=0 to n do\n\tfor v = 1 to k do\n\t if v < d then a.(i+1).(s+v) <- a.(i+1).(s+v) + a.(i).(s);\n\t b.(i+1).(s+v) <- b.(i+1).(s+v) + b.(i).(s);\n\t if v >= d then b.(i+1).(s+v) <- b.(i+1).(s+v) + a.(i).(s);\n\tdone\n done;\n count := !count ++ b.(i+1).(n);\n pass (i+1)\n )\n in\n\n pass 0;\n\n printf \"%d\\n\" !count\n"}, {"source_code": "open Printf\nopen String\nopen Bigarray\n\nlet (n1,k,d) = Scanf.scanf \"%d %d %d \" (fun x y z -> (x,y,z));;\n\nlet dp = Array.init (n1+2) (fun _ -> Array.make 3 (-10) )\n \n \nlet rec ways n flag =\n if n= 0 then\n if flag=1 then 1\n else 0\n else if n<0 then\n 0\n else\n begin\n let x = dp.(n).(flag) in\n if x >=0 then\n x\n else\n begin\n let cnt = ref 0 in\n for i = 1 to d-1 do\n cnt := !cnt + (ways (n-i) flag)\n done;\n for i = d to k do\n cnt := !cnt + (ways (n-i) 1)\n done; dp.(n).(flag)<- !cnt; !cnt\n end\n end\n \nlet rslt = ways n1 0\n \nlet _ = printf \"%d\\n\" rslt\n"}, {"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(* 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\nlet read_int64 () = \n let digit c = Int64.of_int( int_of_char c - 48 )in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (Int64.add (Int64.mul 10L 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 Int64.neg (read (digit c)) else run c \n end else \n if c = '\\000' then 0L else \n run (read_char())\n in \n run (read_char())\n\nmodule LL = struct \n include Int64\n let (+) a b = add a b \n let (-) a b = sub a b \n let ( * ) a b = mul a b \n let (/) a b = div a b \n let (mod) a b = rem a b \n let (land) a b = logand a b \n let (lor) a b = logor a b \n let (lxor) a b = logxor a b \n let (lnot) a = lognot a \nend \n\nlet modulo = 1_000_000_007L\n\nlet isum n up = \n let arr = make (LL.to_int n + 1) (-1L) in\n let read n = arr.(LL.to_int n) in \n let save n v = arr.(LL.to_int n) <- v; v in \n\n let rec run (n: int64) = LL.(\n if read n <> -1L then read n else \n let ans = \n if n <= 1L then 1L else \n let t = 2L * run (n-1L) mod modulo in \n if n <= up then t else \n (t - run (n-1L-up)) mod modulo \n in \n save n ans \n ) in \n if up = 0L then 0L else run n\n\nlet _ = \n let n = read_int64() in \n let k = read_int64() in \n let d = read_int64() in \n let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in \n printf \"%s\\n\" (LL.to_string ans) \n\n(* let _ = \n for i = 0 to 10 do \n let i = LL.of_int i in \n printf \"%s\\n\" (LL.to_string (isum i i))\n done *)"}, {"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(* 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\nlet read_int64 () = \n let digit c = Int64.of_int( int_of_char c - 48 )in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (Int64.add (Int64.mul 10L 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 Int64.neg (read (digit c)) else run c \n end else \n if c = '\\000' then 0L else \n run (read_char())\n in \n run (read_char())\n\nmodule LL = struct \n include Int64\n let (+) a b = add a b \n let (-) a b = sub a b \n let ( * ) a b = mul a b \n let (/) a b = div a b \n let (mod) a b = rem a b \n let (land) a b = logand a b \n let (lor) a b = logor a b \n let (lxor) a b = logxor a b \n let (lnot) a = lognot a \nend \n\nlet modulo = 1_000_000_007L\n\nlet isum n up = \n let arr = make (LL.to_int n + 1) (-1L) in\n let read n = arr.(LL.to_int n) in \n let save n v = arr.(LL.to_int n) <- v; v in \n\n let rec run (n: int64) = LL.(\n if read n <> -1L then read n else \n let ans = \n if n <= 1L then 1L else \n if up < 1L then 0L else \n if n <= up then 2L * run (n-1L) mod modulo else \n (2L * run (n-1L) - run (n-1L-up)) mod modulo \n in \n save n ans \n ) in \n run n\n\nlet _ = \n let n = read_int64() in \n let k = read_int64() in \n let d = read_int64() in \n let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in \n printf \"%s\\n\" (LL.to_string ans) \n"}, {"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(* 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\nlet read_int64 () = \n let digit c = Int64.of_int( int_of_char c - 48 )in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (Int64.add (Int64.mul 10L 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 Int64.neg (read (digit c)) else run c \n end else \n if c = '\\000' then 0L else \n run (read_char())\n in \n run (read_char())\n\nmodule LL = struct \n include Int64\n let (+) a b = add a b \n let (-) a b = sub a b \n let ( * ) a b = mul a b \n let (/) a b = div a b \n let (mod) a b = rem a b \n let (land) a b = logand a b \n let (lor) a b = logor a b \n let (lxor) a b = logxor a b \n let (lnot) a = lognot a \nend \n\nlet modulo = 1_000_000_007L\n\nlet isum n up = \n let arr = make (LL.to_int n + 1) (-1L) in\n let read n = arr.(LL.to_int n) in \n let save n v = arr.(LL.to_int n) <- v; v in \n\n let rec run (n: int64) = LL.(\n if read n <> -1L then read n else \n let ans = \n if n <= 1L then 1L else \n if n <= up then 2L * run (n-1L) mod modulo else \n (2L * run (n-1L) - run (n-1L-up)) mod modulo \n in \n save n ans \n ) in \n if up = 0L then 0L else run n\n\nlet _ = \n let n = read_int64() in \n let k = read_int64() in \n let d = read_int64() in \n let ans = LL.( (isum n k - isum n (d-1L) ) mod modulo) in \n printf \"%s\\n\" (LL.to_string ans) \n\n(* let _ = \n for i = 0 to 10 do \n let i = LL.of_int i in \n printf \"%s\\n\" (LL.to_string (isum i i))\n done *)"}, {"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(* 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\nlet isum n up =\n let rec run n = \n if n <= 1 then 1 else \n if n <= up then 2 * run (n-1) else \n 2 * run (n-1) - run (n-1-up) \n in \n run n \n\nlet _ = \n let n = read_int() in \n let k = read_int() in \n let d = read_int() in \n let ans = isum n k - isum n (d-1) in \n printf \"%d\\n\" ans "}], "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"nl": {"description": "Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.", "input_spec": "The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.", "output_spec": "Print a single integer, denoting the minimum possible height of the tallest tower.", "sample_inputs": ["1 3", "3 2", "5 0"], "sample_outputs": ["9", "8", "10"], "notes": "NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks."}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int () in\n let m = read_int () in\n\n let test b =\n (* does the range [2...b] work *)\n let mult6 = b/6 in\n let mult2 = b/2 - mult6 in\n let mult3 = b/3 - mult6 in\n (max 0 (n - mult2)) + (max 0 (m - mult3)) <= mult6\n in\n\n let rec bsearch lo hi =\n (* lo fails, hi works *)\n if lo+1 = hi then hi else\n let mid = (lo + hi)/2 in\n if test mid then bsearch lo mid else bsearch mid hi\n in\n\n let answer = bsearch 1 10_000_000 in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "23f2c8cac07403899199abdcfd947a5a"} {"nl": {"description": "Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.So they play with each other according to following rules: Alex and Bob play the first game, and Carl is spectating; When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner. Alex, Bob and Carl play in such a way that there are no draws.Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!", "input_spec": "The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played. Then n lines follow, describing the game log. i-th line contains one integer ai (1 ≤ ai ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.", "output_spec": "Print YES if the situation described in the log was possible. Otherwise print NO.", "sample_inputs": ["3\n1\n1\n2", "2\n1\n2"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example the possible situation is: Alex wins, Carl starts playing instead of Bob; Alex wins, Bob replaces Carl; Bob wins. The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one."}, "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet n = scan_int() and gra = ref 1 and pom = ref 0 and gra2 = ref 2 and siedzi = ref 3 and czy = ref 1 in\nbegin\nfor i = 1 to n do\n\tlet x= scan_int() in \n if x = !siedzi then czy := 0\n else if !gra = x then begin pom:= !siedzi; siedzi := !gra2; gra2 := !pom end\n else begin pom := !siedzi; siedzi := !gra; gra := !pom end\ndone;\nif !czy = 1 then print_string(\"YES\")\nelse print_string(\"NO\")\nend \n"}, {"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\nlet n = scan_int();;\nlet stan = ref 3;;\nlet wyn = ref 1;;\n\nfor i = 0 to (n - 1) do\n let x = scan_int() in\n if((1 lsl (x - 1)) land (!stan) == 0) then wyn := 0;\n stan := (!stan - (1 lsl (x - 1))) lxor 7;\ndone;\n\nif !wyn = 1 then print_string(\"YES\") else print_string(\"NO\");;\n\n"}, {"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 w = Array.init n read_int in\n\n let rec loop (x,y) i = if i=n then true else (\n let z = 6 - x - y in\n if w.(i) = x then loop (x,z) (i+1)\n else if w.(i) = y then loop (y,z) (i+1)\n else false\n ) in\n\n\n if loop (1,2) 0 then printf \"YES\\n\" else printf \"NO\\n\"\n"}], "negative_code": [], "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"nl": {"description": "Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and the contest is not carried out; on this day the gym is closed and the contest is carried out; on this day the gym is open and the contest is not carried out; on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.", "input_spec": "The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where: ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.", "output_spec": "Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: to do sport on any two consecutive days, to write the contest on any two consecutive days. ", "sample_inputs": ["4\n1 3 2 0", "7\n1 3 3 2 1 2 3", "2\n2 2"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day."}, "positive_code": [{"source_code": "open Printf\n\nlet read_int () = Scanf.scanf \"%d \" (fun x -> x);;\nlet read_int3 () = Scanf.scanf \" %d %d %d \" (fun x y z -> (x,y,z) );;\n\nlet n = read_int ()\n\ntype action = Rest | Test | Sport | None;;\ntype day = A | B | C | D;; (* 0, 1, 2, 3*)\n\nlet itoa = function\n | 0 -> A\n | 1 -> B\n | 2 -> C\n | 3 -> D\n\nlet a = Array.init n (fun i -> (read_int () |> itoa))\n\nlet act_poss d act =\n match (d, act) with\n | (A, Sport) -> false\n | (A, Test) -> false\n | (B, Sport) -> false\n | (C, Test) -> false\n | (_, _) -> true\n\ntype rmin = { mutable rest : int; mutable sport : int; mutable test : int};;\n\n (*Note: should not use Array.make here*)\nlet r = Array.init (n+1) (fun i ->\n {rest = max_int; sport = max_int; test = max_int });;\n\nlet () = r.(0) <- {rest = 0; sport = 0; test = 0};;\n\nlet () =\n for i = 1 to n\n do\n let x = r.(i-1).sport in\n let y = r.(i-1).test in\n let z = r.(i-1).rest in\n begin\n if (act_poss a.(i-1) Rest) then\n let w = min x (min y z) in\n if(w x)\n\nlet () =\n let n = read_int () in\n let a = Array.init (n + 1) (fun i -> if i = 0 then 0 else read_int ())\n and dp = Array.make_matrix (n + 1) 4 1000000000 in\n dp.(0).(0) <- 0;\n for i = 1 to n do\n dp.(i).(0) <- 1 + (min dp.(i - 1).(0) (min dp.(i - 1).(1) dp.(i - 1).(2)));\n if a.(i) = 1 || a.(i) = 3 then\n dp.(i).(1) <- min dp.(i - 1).(0) dp.(i - 1).(2);\n if a.(i) = 2 || a.(i) = 3 then\n dp.(i).(2) <- min dp.(i - 1).(0) dp.(i - 1).(1)\n done;\n printf \"%d\\n\" (min dp.(n).(0) (min dp.(n).(1) dp.(n).(2)))"}, {"source_code": "let read_int () = Scanf.scanf \"%d \" (fun x -> x);;\nlet read_int3 () = Scanf.scanf \" %d %d %d \" (fun x y z -> (x,y,z) );;\n\nlet n = read_int ()\n\ntype action = Rest | Test | Sport | None;;\ntype day = A | B | C | D;; (* 0, 1, 2, 3*)\n\nlet itoa = function\n | 0 -> A\n | 1 -> B\n | 2 -> C\n | 3 -> D\n\nlet a = Array.init n (fun i -> (read_int () |> itoa))\n\nlet act_poss d act =\n match (d, act) with\n | (A, Sport) -> false\n | (A, Test) -> false\n | (B, Sport) -> false\n | (C, Test) -> false\n | (_, _) -> true\n\ntype rmin = { mutable rest : int; mutable sport : int; mutable test : int};;\n\n (*Note: should not use Array.make here*)\nlet r = Array.init (n+1) (fun i ->\n {rest = max_int; sport = max_int; test = max_int });;\n\nlet () = r.(0) <- {rest = 0; sport = 0; test = 0};;\n\nlet () =\n for i = 1 to n\n do\n let x = r.(i-1).sport in\n let y = r.(i-1).test in\n let z = r.(i-1).rest in\n begin\n if (act_poss a.(i-1) Rest) then\n let w = min x (min y z) in\n if(w x);;\nlet read_int3 () = Scanf.scanf \" %d %d %d \" (fun x y z -> (x,y,z) );;\n\nlet n = read_int ()\n\ntype action = Rest | Test | Sport | None;;\ntype day = A | B | C | D;; (* 0, 1, 2, 3*)\n\nlet itoa = function\n | 0 -> A\n | 1 -> B\n | 2 -> C\n | 3 -> D\n\nlet a = Array.init n (fun i -> (read_int () |> itoa))\n\nlet act_poss d act =\n match (d, act) with\n | (A, Sport) -> false\n | (A, Test) -> false\n | (B, Sport) -> false\n | (C, Test) -> false\n | (_, _) -> true\n\ntype rmin = { mutable rest : int; mutable sport : int; mutable test : int};;\n\n (*Note: should not use Array.make here*)\nlet r = Array.init (n+1) (fun i ->\n {rest = max_int; sport = max_int; test = max_int });;\n\nlet () = r.(0) <- {rest = 0; sport = 0; test = 0};;\n\nlet () =\n for i = 1 to n\n do\n let x = r.(i-1).sport in\n let y = r.(i-1).test in\n let z = r.(i-1).rest in\n begin\n if (act_poss a.(i-1) Rest) then\n let w = min x (min y z) in\n if(w x);;\nlet read_int3 () = Scanf.scanf \" %d %d %d \" (fun x y z -> (x,y,z) );;\n\nlet n = read_int ()\n\ntype action = Rest | Test | Sport | None;;\ntype day = A | B | C | D;; (* 0, 1, 2, 3*)\n\nlet itoa = function\n | 0 -> A\n | 1 -> B\n | 2 -> C\n | 3 -> D\n\nlet a = Array.init n (fun i -> (read_int () |> itoa))\n\nlet act_poss d act p_act =\n match (d, act, p_act) with\n | (A, Sport, _) -> false\n | (A, Test, _) -> false\n | (B, Sport, _) -> false\n | (B, Test, Test) -> false\n | (C, Test, _) -> false\n | (C, Sport, Sport) -> false\n | (D, Sport, Sport) -> false\n | (D, Test, Test) -> false\n | (_, _, _) -> true\n\nlet r = Array.make (n+1) max_int;;\n\nlet () = r.(0) <- 0 in\nlet act = Array.make (n+1) None in\nlet () = act.(0) <- Rest in\nlet () =\n for i = 1 to n \n do\n if (act_poss a.(i-1) Rest act.(i-1) ) then\n begin\n if ( r.(i) > r.(i-1)+1 ) then\n begin\n act.(i) <- Rest;\n r.(i) <- r.(i-1) + 1\n end\n end;\n if (act_poss a.(i-1) Test act.(i-1) ) then\n begin\n if ( r.(i) > r.(i-1) ) then\n begin\n act.(i) <- Test;\n r.(i) <- r.(i-1)\n end\n end;\n if (act_poss a.(i-1) Sport act.(i-1) ) then\n begin\n if ( r.(i) > r.(i-1) ) then\n begin\n act.(i) <- Sport;\n r.(i) <- r.(i-1) \n end\n end;\n done in ()\n;;\n\nlet () = printf \"%d\\n\" r.(n);;\n"}], "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"nl": {"description": "The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.", "input_spec": "The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.", "output_spec": "Print a single integer — the least possible difference the teacher can obtain.", "sample_inputs": ["4 6\n10 12 10 7 5 22"], "sample_outputs": ["5"], "notes": "NoteSample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5."}, "positive_code": [{"source_code": "let (no_of_ppl, no_of_puzzles) = Scanf.scanf \"%d %d \" (fun n m -> n, m)\n \nlet read m =\n let rec loop list m = \n if m > 0\n then\n let var = Scanf.scanf \"%d \" (fun v -> v) in\n loop (var :: list) (m - 1)\n else\n list\n in loop [] no_of_puzzles\n\nlet sort list = List.sort(Pervasives.compare) (List.rev list)\n\nlet find_min list n m = \n let rec traverse i min =\n if i + n - 1< m\n then\n let dif = List.nth list (i + n - 1) - List.nth list i in\n if dif < min\n then\n traverse (i + 1) dif\n else\n traverse (i + 1) min\n else\n min \n in traverse 0 1000\n\nlet solve (no_of_ppl, no_of_puzzles) = find_min (sort (read no_of_puzzles)) no_of_ppl no_of_puzzles\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (no_of_ppl, no_of_puzzles))"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet parse_list (n : int) : (int list) =\n let rec parse_list_helper acc = function\n | 0 -> acc\n | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)\n in\n parse_list_helper [] n\n\nlet () =\n let ans = ref 1001 in\n let n = read_int () in\n let m = read_int () in\n let lst = List.sort compare (parse_list m) in\n for k = 0 to m-n do\n let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in\n ans := min !ans diff\n done;\n print_int !ans\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet parse_list (n : int) : (int list) =\n let rec parse_list_helper acc = function\n | 0 -> acc\n | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)\n in\n parse_list_helper [] n\n\nlet () =\n let b = ref 1001 in\n let n = read_int () in\n let m = read_int () in\n let lst = parse_list m in\n let sorted_lst = List.sort compare lst in\n for k = 0 to m-n do\n let diff = (List.nth sorted_lst (k + n - 1)) - (List.nth sorted_lst k) in\n b := min !b diff\n done;\n print_int !b\n"}, {"source_code": "let (n, m) = Scanf.scanf \"%d %d\\n\" (fun n m -> n, m) in\nlet p = Array.make m 0 in\nfor i = 0 to m - 1 do\n Scanf.scanf \"%d%[ ]\" (fun x _ -> p.(i) <- x)\ndone ;\nArray.sort compare p ;\nlet b = ref max_int in\nfor i = 0 to m - n do\n b := min !b (p.(i + n - 1) - p.(i))\ndone ;\nPrintf.printf \"%d\\n\" !b ;;\n"}, {"source_code": "open Scanf;;\nopen String;;\n\n\nlet n = bscanf Scanning.stdin \"%d \" (fun x -> x);;\nlet m = bscanf Scanning.stdin \"%d \" (fun x -> x);;\n\nlet p = Array.init m (fun x -> 0);;\n\nfor i=0 to m-1 do\n let f = bscanf Scanning.stdin \"%d \" (fun x -> x) in\n p.(i) <- f\ndone;;\n\n(*Sort the array ascendingly*)\nArray.sort (fun x y -> x-y ) p;;\n\n(*Test the sorting result\nArray.iter (fun x -> Printf.printf \"%d \" x) p;;\n*)\n\nlet i = ref 0 in\nlet maxdiff = ref max_int in\nlet () = \n while (!i + n-1) <= (m-1) do\n let diff = p.(!i+n-1) -p.(!i) in\n if ( diff < !maxdiff) then maxdiff := diff ;\n i := !i + 1\n done in\nprint_int !maxdiff; print_endline \"\"\n;;\n"}, {"source_code": "open Scanf;;\nopen String;;\n\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\nlet m = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet p = Array.init m (fun x -> 0);;\n\nfor i=0 to m-1 do\n let f = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\n p.(i) <- f\ndone;;\n\n(*Sort the array ascendingly*)\nArray.sort (fun x y -> x-y ) p;;\n\n(*Test the sorting result\nArray.iter (fun x -> Printf.printf \"%d \" x) p;;\n*)\n\nlet i = ref 0 in\nlet maxdiff = ref max_int in\nlet () = \n while (!i + n-1) <= (m-1) do\n let diff = p.(!i+n-1) -p.(!i) in\n if ( diff < !maxdiff) then maxdiff := diff ;\n i := !i + 1\n done in\nprint_int !maxdiff; print_endline \"\"\n;;\n"}, {"source_code": "let (n, m) = Scanf.scanf \"%d %d\\n\" (fun n m -> n, m) in\n\nlet a = Array.make m 0 in\nfor i = 0 to m - 1 do\n Scanf.scanf \"%d%[ ]\" (fun x _ -> a.(i) <- x)\ndone ;\n\nArray.sort compare a ;\n\nlet ans = ref max_int in\nfor i = 0 to m - n do\n ans := min !ans (a.(i + n - 1) - a.(i))\ndone ;\n\nPrintf.printf \"%d\\n\" !ans ;;\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet parse_list (n : int) : (int list) =\n let rec parse_list_helper acc = function\n | 0 -> acc\n | n -> parse_list_helper (acc @ [read_int ()]) (n - 1)\n in\n parse_list_helper [] n\n\nlet () =\n let ans = ref 1001 in\n let n = read_int () in\n let m = read_int () in\n let lst = List.sort compare (parse_list m) in\n for k = 1 to m-n do\n let diff = (List.nth lst (k + n - 1)) - (List.nth lst k) in\n ans := min !ans diff\n done;\n print_int !ans\n"}, {"source_code": "open Scanf;;\nopen String;;\n\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\nlet m = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet p = Array.init m (fun x -> 0);;\n\nfor i=0 to m-1 do\n let f = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\n p.(i) <- f\ndone;;\n\n(*Sort the array ascendingly*)\nArray.sort (fun x y -> x-y ) p;;\n\n(*Test the sorting result\nArray.iter (fun x -> Printf.printf \"%d \" x) p;;\n*)\n\nlet i = ref 0 in\nlet maxdiff = ref max_int in\nlet () = \n while (!i + 3) <= (m-1) do\n let diff = p.(!i+3) -p.(!i) in\n if ( diff < !maxdiff) then maxdiff := diff ;\n i := !i + 1\n done in\nprint_int !maxdiff; print_endline \"\"\n;;\n"}], "src_uid": "7830aabb0663e645d54004063746e47f"} {"nl": {"description": "Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: deletes all the vowels, inserts a character \".\" before each consonant, replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters \"A\", \"O\", \"Y\", \"E\", \"U\", \"I\", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.", "input_spec": "The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.", "output_spec": "Print the resulting string. It is guaranteed that this string is not empty.", "sample_inputs": ["tour", "Codeforces", "aBAcAba"], "sample_outputs": [".t.r", ".c.d.f.r.c.s", ".b.c.b"], "notes": null}, "positive_code": [{"source_code": "let _ =\n let main () =\n let conv k =\n let s = String.lowercase k in\n\n let rec loop i acc =\n if i < 0 then acc else\n let k = try String.index \"aoyeui\" s.[i] with _ -> -1 in\n loop (i - 1) (if k >= 0 then acc else s.[i] :: acc)\n in\n loop (String.length s - 1) []\n in\n let s = read_line () in\n let result = conv s in\n List.iter (Printf.printf \".%c\") result;\n print_newline ()\n in\n main ()\n"}, {"source_code": "let 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\nlet word = Scanf.scanf \"%s\" (fun word -> str_to_list (String.lowercase(word)))\n\nlet is_consonant c = match c with\n |'a' | 'o' | 'y' | 'e' | 'u' | 'i' -> false\n | _ -> true\n\nlet remove_vowels l = List.filter(fun char -> is_consonant char) l\n\nlet add_dot = (fun l -> List.concat(List.map(fun char -> ['.'; char]) l))\n\nlet () = List.iter(Printf.printf \"%c\") (add_dot(remove_vowels word))\n"}, {"source_code": "String.iter (fun c ->\n\tif not (c = 'a' || c = 'o' || c = 'y' || c = 'e' || c = 'u' || c = 'i') then\n\t\t(print_char '.'; print_char c)\n) (String.lowercase (read_line()));;\n"}, {"source_code": "let stringToList str =\n let rec loop idx str =\n let len = String.length(str) in\n if idx >= len then\n []\n else\n str.[idx] :: loop (idx+1) str in\n loop 0 str;;\n\nlet isConsonant ch =\n match ch \n with 'a'|'o'|'y'|'e'|'u'|'i' -> false\n | _ -> true;;\n\nlet printWithDot ch =\n Printf.printf \".%c\" ch;;\n\nlet _ =\n let line = read_line() in\n let l = stringToList (String.lowercase line) in\n List.map printWithDot (List.filter isConsonant l) in\n print_newline()\n"}, {"source_code": "let s=read_line();;\nlet rec op t=\nif t=\"\" then [] else t.[0]::(op (String.sub t 1 (String.length(t)-1)));;\nlet l=op s;;\nlet letter char= match char with\n| 'a' | 'e' | 'i' | 'o' | 'u' | 'y' \n | 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' ->()\n|'a'..'z'->print_string \".\";print_char char\n|'A'..'Z'->print_string \".\";print_char (Char.chr(int_of_char(char)+32))\n|_->();;\nlet rec doo=function\n|[]->()\n|h::t->letter h;doo t;;\ndoo l;;"}, {"source_code": "let do_it c =\n\tmatch c with\n\t'a'|'o'|'y'|'e'|'u'|'i'|'A'|'O'|'Y'|'E'|'U'|'I' -> c\n\t|_ -> print_string (\".\" ^ String.make 1 c); c\n;;\n\nString.map do_it (String.lowercase (read_line()))"}, {"source_code": "let str=String.lowercase(read_line());;\nlet ans= ref \"\" ;;\nfor i=1 to String.length(str) do\n let va= str.[i-1] in\n if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)\ndone;;\nprint_endline(!ans)\n"}, {"source_code": "let atr=read_line();;\nlet str=String.lowercase(atr);;\nlet ans= ref \"\" ;;\nfor i=1 to String.length(str) do\n let va= str.[i-1] in\n if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u' && va!='y') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)\ndone;;\nprint_endline(!ans)\n"}, {"source_code": "\nlet consonants s =\n let regex_vowel = Str.regexp \"[aeiouy]\" in\n let vowel_deleted = Str.split regex_vowel (String.lowercase s)\n in\n String.concat \"\" vowel_deleted\n;;\n\nlet () =\n Scanf.scanf \"%s\" (fun s -> String.iter (fun c -> Printf.printf \".%c\" c)\n (consonants s));\n print_newline ()\n;;\n \n \n"}, {"source_code": "open Scanf\nopen Num\nopen Printf\nopen String\n\nlet s = Scanf.bscanf Scanf.Scanning.stdin \"%s \" ( fun x -> x) |> String.lowercase\n\nlet explode s =\n let r = ref [] in\n for i = 0 to (length s - 1) do\n let c = String.get s i in\n r := !r@[c]\n done; !r\n;;\n\nlet is_vowel = function\n | 'a' -> true\n | 'o' -> true\n | 'y' -> true\n | 'e' -> true\n | 'u' -> true\n | 'i' -> true\n | _ -> false\n\nlet l = ( explode s \n |> List.filter (fun x -> (not (is_vowel x)) )\n );;\n\nList.iter (fun x -> print_string (\".\"^(String.make 1 x)) ) l; print_endline \"\";;\n"}, {"source_code": "let solve =\n let s = read_line () in\n let terminated_s = s ^ \".\" in\n let rec parse_string i = match terminated_s.[i] with\n | '.' -> print_string \"\\n\"\n | 'a' | 'o' | 'y' | 'e' | 'u' | 'i'\n | 'A' | 'O' | 'Y' | 'E' | 'U' | 'I' -> parse_string (i+1)\n | c when c >= 'A' && c <= 'Z' ->\n print_char '.'; print_char (Char.lowercase c); parse_string (i+1)\n | c -> print_char '.'; print_char c; parse_string (i+1)\n in parse_string 0; ()\n\nlet () = solve\n"}, {"source_code": "let vowels = 'a'::'i'::'u'::'e'::'o'::'y'::[]\n\nlet petya c = \n let lower = Char.lowercase c in\n if List.exists (fun x -> x = lower) vowels then ()\n else Printf.printf \".%c\" lower\n\nlet main () =\n let gr () = Scanf.scanf \"%s\\n\" (fun i -> i) in\n let str = gr () in\n let () = String.iter petya str in\n Printf.printf(\"\\n\")\n;;\n\nlet _ = main();;\n\n"}, {"source_code": "\nopen String;;\nopen Printf;;\nopen Scanf;;\nopen Char;;\n \n\nlet convert ch =\n match ch with\n |'a'|'e'|'u'|'i'|'o'|'y'\n |'A'|'E'|'U'|'I'|'O'|'Y' -> None\n |_ -> Some (\".\" ^ String.make 1 (Char.lowercase ch))\n \n\nlet rec process inp =\n let res = ref \"\" in\n for i = 0 to length inp - 1 do\n let ch = convert inp.[i] in\n match ch with\n | Some x -> res := (!res ^ x)\n | None -> ()\n done;\n !res\n\nlet () =\n let inp = read_line () in\n printf \"%s\\n\" (process inp)\n ;;\n\n\n\n"}, {"source_code": "let pf = Printf.printf;;\nlet sf = Scanf.scanf;;\n\nlet (|>) x f = f x;;\nlet (@@) f x = f x;;\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\nlet f s =\n let t = Char.lowercase s in\n if List.memq t ['a'; 'i'; 'u'; 'e'; 'o'; 'y']\n then \"\"\n else \".\" ^ Char.escaped t\n;;\n\nlet _ =\n let str = read_line() in\n let res = ref \"\" in\n for i = 0 to String.length str - 1 do\n res := !res ^ f str.[i]\n done;\n print_endline !res\n;;\n"}], "negative_code": [{"source_code": "let atr=read_line();;\nlet str=String.lowercase(atr);;\nlet ans= ref \"\" ;;\nfor i=1 to String.length(str) do\n let va= str.[i-1] in\n if (va!='a' && va!='e' && va!='i' && va!='o' && va!='u') then ans:=(!ans)^(String.make 1 '.')^(String.make 1 va)\ndone;;\nprint_endline(!ans)\n"}, {"source_code": "let vowels = 'a'::'i'::'u'::'e'::'o'::[]\n\nlet petya c = \n let lower = Char.lowercase c in\n if List.exists (fun x -> x = lower) vowels then ()\n else Printf.printf \".%c\" lower\n\nlet main () =\n let gr () = Scanf.scanf \"%s\\n\" (fun i -> i) in\n let str = gr () in\n let () = String.iter petya str in\n Printf.printf(\"\\n\")\n;;\n\nlet _ = main();;\n\n"}], "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"nl": {"description": "Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.", "input_spec": "A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.", "output_spec": "Output the given word after capitalization.", "sample_inputs": ["ApPLe", "konjac"], "sample_outputs": ["ApPLe", "Konjac"], "notes": null}, "positive_code": [{"source_code": "print_string (String.capitalize (read_line()))\n"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet solve input = String.capitalize input\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "\nlet () =\n let s = read_line () in\n let len = String.length s in\n let head = String.sub s 0 1 in\n let tail = String.sub s 1 (len - 1)\n in\n print_endline (String.uppercase head ^ tail);;\n"}, {"source_code": "let read_int () = Scanf.scanf \"%s \" (fun x -> x);;\n\nlet () = read_int () |> String.capitalize\n|> print_endline ;;\n\n"}, {"source_code": "\n(* Codeforces 281A *)\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%s\" (fun s -> String.capitalize s))\n"}, {"source_code": "open Printf\n\nlet main =\n let s = read_line() in\n let h = s.[0] in\n let t = String.sub s 1 ((String.length s) - 1) in\n \n printf \"%c%s\\n\" (Char.uppercase h) t;\n"}, {"source_code": "\n\nlet () = \n let s = read_line() in\n let isupper c = int_of_char c <= int_of_char 'Z' && int_of_char c >= int_of_char 'A' in\n if not (isupper s.[0]) then\n s.[0] <- char_of_int ((int_of_char s.[0]) + (int_of_char 'A') - (int_of_char 'a'));\n\n Printf.printf \"%s\\n\" s\n"}], "negative_code": [], "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"nl": {"description": "In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: \"North\", \"South\", \"West\", \"East\".Limak isn’t sure whether the description is valid. You must help him to check the following conditions: If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. The journey must end on the North Pole. Check if the above conditions are satisfied and print \"YES\" or \"NO\" on a single line.", "input_spec": "The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.", "output_spec": "Print \"YES\" if the description satisfies the three conditions, otherwise print \"NO\", both without the quotes.", "sample_inputs": ["5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "2\n15000 South\n4000 East", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "3\n20000 South\n10 East\n20000 North", "2\n1000 North\n1000 South", "4\n50 South\n50 North\n15000 South\n15000 North"], "sample_outputs": ["YES", "NO", "YES", "NO", "NO", "YES"], "notes": "NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is \"NO\" because he doesn't end on the North Pole. "}, "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x)\n\nlet ( $ ) f x = f x\n\n\n\nlet main () = \n let n = ref (read_int ()) in\n let cur = ref 0 in\n let fail = ref false in\n let t = ref 0 in\n let str = ref \"\" in\n for i = 1 to !n do\n fail := !fail || not(0 <= !cur && !cur <= 20000);\n t := read_int ();\n str := read_string ();\n if !str = \"North\" then\n cur := !cur - !t\n else if !str = \"South\" then\n cur := !cur + !t\n else if (!str = \"East\" || !str = \"West\") && (!cur = 0 || !cur = 20000) then\n fail := true\n \n done;\n Printf.printf (if not !fail && !cur = 0 then \"YES\" else \"NO\")\n\n\n\n\nlet () = main ()"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n let n = read_int () in\n\n let rec loop i x = if i=n then x=0 else\n let t = read_int() in\n match (read_string()) with\n\t| \"South\" ->\n\t let x = x + t in\n\t if x > 20_000 then false\n\t else loop (i+1) x\n\t| \"North\" ->\n\t let x = x - t in\n\t if x < 0 then false\n\t else loop (i+1) x\n\t| _ ->\n\t if x = 0 || x = 20_000 then false\n\t else loop (i+1) x\n in\n\n if loop 0 0 then printf \"Yes\\n\" else printf \"No\\n\"\n"}], "negative_code": [], "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"nl": {"description": "A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.", "output_spec": "Output \"YES\", if the string is a pangram and \"NO\" otherwise.", "sample_inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog"], "sample_outputs": ["NO", "YES"], "notes": null}, "positive_code": [{"source_code": "let n = int_of_string (input_line stdin);;\nlet s = input_line stdin;;\nlet a = Array.make 26 false;;\n\nfor i = 0 to n - 1 do\n a.(Char.code (Char.lowercase s.[i]) - Char.code 'a') <- true;\ndone;;\n\nif List.mem false (Array.to_list a) then print_string \"NO\"\nelse print_string \"YES\";;\nprint_newline ();;\n"}, {"source_code": "let input () = \n let total = Scanf.scanf \"%d \" (fun n -> n) in\n let rec read i list =\n if i < total\n then\n let char = Char.lowercase (Scanf.scanf \"%c\" (fun c -> c)) in\n read (i + 1) (char :: list)\n else\n list\n in read 0 []\n\nlet rec get_uniques = function\n | head :: (middle :: _ as tail) -> \n if head = middle \n then \n get_uniques tail \n else \n (head :: get_uniques tail)\n | smaller -> smaller\n\nlet solve list =\n let uniques = List.length (get_uniques (List.sort(Pervasives.compare) list)) in\n if uniques = 26\n then\n \"YES\"\n else\n \"NO\"\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let answer s n = \n let a = Array.make 26 false in \n for i = 0 to n-1 do\n let c = Char.code s.[i] in\n if c >= 97 then a.(c-97) <- true\n else a.(c-65) <- true\n done;\n let b = ref true in\n for i = 0 to 25 do\n b := !b && a.(i)\n done;\n if !b then print_endline \"YES\" else print_endline \"NO\"\n\nlet () = \n let n = int_of_string (read_line ()) in\n let s = read_line () in\n answer s n\n\n"}], "negative_code": [], "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"nl": {"description": "Find the minimum number with the given sum of digits $$$s$$$ such that all digits in it are distinct (i.e. all digits are unique).For example, if $$$s=20$$$, then the answer is $$$389$$$. This is the minimum number in which all digits are different and the sum of the digits is $$$20$$$ ($$$3+8+9=20$$$).For the given $$$s$$$ print the required number.", "input_spec": "The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 45$$$) — the number of test cases. Each test case is specified by a line that contains the only integer $$$s$$$ ($$$1 \\le s \\le 45$$$).", "output_spec": "Print $$$t$$$ integers — the answers to the given test cases.", "sample_inputs": ["4\n\n20\n\n8\n\n45\n\n10"], "sample_outputs": ["389\n8\n123456789\n19"], "notes": null}, "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x-> x);;\r\n\r\nlet run_case = function\r\n| n ->\r\n let rec get_digits = function\r\n | (x, c) ->\r\n if (x<10) then begin\r\n if (x<=c) then [x]\r\n else c::get_digits((x-c),(c-1))\r\n end\r\n else c::get_digits((x-c),(c-1))\r\n in\r\n let ds = get_digits (n, 9) in\r\n List.iter (fun x-> print_int x) (List.rev ds);\r\n print_newline ()\r\n;;\r\n\r\nlet rec iter_cases = function\r\n| 0 -> ()\r\n| t ->\r\n let n = read_int () in\r\n run_case (n);\r\n iter_cases (t-1)\r\n;;\r\n\r\nlet c = read_int () in iter_cases (c);;"}], "negative_code": [], "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"nl": {"description": "Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.", "input_spec": "The first and only line of the input starts with a string with the format \"HH:MM\" where \"HH\" is from \"00\" to \"23\" and \"MM\" is from \"00\" to \"59\". Both \"HH\" and \"MM\" have exactly two digits.", "output_spec": "Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.", "sample_inputs": ["12:21", "23:59"], "sample_outputs": ["13:31", "00:00"], "notes": null}, "positive_code": [{"source_code": "open String;;\nopen Char;;\n\nlet check = fun s ->\nlet fhc = get s 0 and shc = get s 1\nand fmc = get s 3 and smc = get s 4 in\nlet fh = code (get s 0) - 48 and sh = code (get s 1) - 48 \nand fm = code (get s 3) - 48 and sm = code (get s 4) - 48 in\nlet minutes = fm * 10 + sm \nand potential_minutes = sh * 10 + fh in \nif fh < 2 then \n if sh > 5 || (sh = 5 && minutes >= 50 + fh) then \n begin\n print_int (fh + 1);\n print_string \"0:0\";\n print_int (fh + 1)\n end\n\n else if minutes < potential_minutes then begin\n print_int fh;\n print_int sh;\n print_string \":\";\n print_int sh;\n print_int fh;\n end\n else begin\n print_int fh;\n print_int (sh + 1);\n print_string \":\";\n print_int (sh + 1);\n print_int fh;\n end\nelse (* fh = 2 *)\n if sh = 3 && minutes >= 32 then print_string \"00:00\"\n else begin\n print_int fh;\n print_int sh;\n print_string \":\";\n print_int sh;\n print_int fh;\n end\n;;\n\nScanf.scanf \"%s\" (check);;\n"}], "negative_code": [], "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"nl": {"description": "You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.", "input_spec": "The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.", "output_spec": "Print the number of ways to choose a suitable problemset for the contest. ", "sample_inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20"], "sample_outputs": ["2", "2", "6"], "notes": "NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable."}, "positive_code": [{"source_code": "let rec f = function\n\t| t::q\t-> let lis = f q in\n\t\t\t(List.map (fun (sum,min,max) -> \n\t\t\t\t\tif sum = 0\n\t\t\t\t\t\tthen (t,t,t)\n\t\t\t\t\t\telse (t+sum,t,max)) \n\t\t\t\tlis)@lis\n\t| []\t-> [0,0,0]\n\nlet () =\n\tlet (n,l,r,x) = Scanf.scanf \"%d %d %d %d\" (fun i j k l -> (i,j,k,l)) and lis = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d\" (fun i -> lis := i::!lis);\n\tdone;\n\tPrintf.printf \"%d\" (List.length (List.filter (fun (i,j,k) -> i >= l && i <= r && k-j >= x) (f (List.sort compare !lis))))\n"}], "negative_code": [], "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"nl": {"description": "Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$).", "output_spec": "Output one integer — the answer to the problem.", "sample_inputs": ["7", "8", "9"], "sample_outputs": ["4", "5", "5"], "notes": "NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\\textbf 7$$$] Weight 2: [$$$\\textbf 3$$$, $$$\\textbf 3$$$, 1] Weight 3: [$$$\\textbf 2$$$, $$$\\textbf 2$$$, $$$\\textbf 2$$$, 1] Weight 7: [$$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$]"}, "positive_code": [{"source_code": "\nlet _ =\n let n = Scanf.scanf \" %d\" (fun i -> i) in\n Printf.printf \"%d\\n\" (n / 2 + 1)\n"}], "negative_code": [], "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"nl": {"description": "Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.", "input_spec": "First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning. Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.", "output_spec": "Print the only integer — maximum number of liters of kefir, that Kolya can drink.", "sample_inputs": ["10\n11\n9\n8", "10\n5\n6\n1"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir."}, "positive_code": [{"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 long x = Int64.of_int x\n\nlet ceil x y = (x++y--1L)//y\nlet floor x y = x//y\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let n = read_long () in\n let a = read_long () in\n let b = read_long () in\n let c = read_long () in \n\n let answer = \n if a <= b--c || n < b then (\n floor n a\n ) else (\n let k1 = ceil (n--b++1L) (b--c) in\n let n' = n -- k1 ** (b--c) in\n let k2 = floor n' a in\n k1 ++ k2\n )\n in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [{"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 long x = Int64.of_int x\n\nlet ceil x y = (x++y--1L)//y\nlet floor x y = x//y\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let n = read_long () in\n let a = read_long () in\n let b = read_long () in\n let c = read_long () in \n\n let answer = \n if a <= b--c then (\n floor n a\n ) else (\n let k1 = ceil (n--b++1L) (b--c) in\n let n' = n -- k1 ** (b--c) in\n let k2 = floor n' a in\n k1 ++ k2\n )\n in\n\n printf \"%Ld\\n\" answer\n"}, {"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 long x = Int64.of_int x\n\nlet ceil x y = (x++y--1L)//y\nlet floor x y = x//y\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let n = read_long () in\n let a = read_long () in\n let b = read_long () in\n let c = read_long () in \n\n let answer = \n if a <= b--c then (\n floor n a\n ) else (\n let k1 = floor (n--b) (b--c) in\n let n = n -- (k1 ** (b--c)) in\n\n let rec loop n k = if n < b then (n,k) else loop (n--b++c) (k++1L) in\n let (n,k2) = loop n 0L in\n let k3 = floor n a in\n k1 ++ k2 ++ k3\n )\n in\n\n printf \"%Ld\\n\" answer\n"}, {"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 long x = Int64.of_int x\n\nlet ceil x y = (x++y--1L)//y\nlet floor x y = x//y\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let n = read_long () in\n let a = read_long () in\n let b = read_long () in\n let c = read_long () in \n\n let answer = \n if a <= b--c then (\n floor n a\n ) else (\n let k1 = ceil (n--b) (b--c) in\n let n = n -- (k1 ** (b--c)) in\n let (n,k2) = if n >= b then (n--b++c, 1L) else (n,0L) in\n let k3 = floor n a in\n k1 ++ k2 ++ k3\n )\n in\n\n printf \"%Ld\\n\" answer\n"}], "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"nl": {"description": "There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.", "input_spec": "The single line of input contains one integer n (0  ≤  n  ≤  109).", "output_spec": "Print single integer — the last digit of 1378n.", "sample_inputs": ["1", "2"], "sample_outputs": ["8", "4"], "notes": "NoteIn the first example, last digit of 13781 = 1378 is 8.In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4."}, "positive_code": [{"source_code": "let input () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet solve n = \n if n = 0\n then\n 1\n else\n match (n mod 4) with\n | 1 -> 8\n | 2 -> 4\n | 3 -> 2\n | 4 | 0 -> 6 \n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))"}, {"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 answer = if n=0 then 1 else [|6;8;4;2|].(n mod 4) in\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"nl": {"description": "Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.Help Mister B to calculate how many days he needed to finish the book.", "input_spec": "First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.", "output_spec": "Print one integer — the number of days Mister B needed to finish the book.", "sample_inputs": ["5 5 10 5 4", "12 4 12 4 1", "15 1 100 0 0"], "sample_outputs": ["1", "3", "15"], "notes": "NoteIn the first sample test the book contains 5 pages, so Mister B read it right at the first day.In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.In third sample test every day Mister B read 1 page of the book, so he finished in 15 days."}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_5 _ = bscanf Scanning.stdib \" %d %d %d %d %d \" (fun a b c d e -> (a,b,c,d,e))\nlet () = \n let (c,v0,v1,a,l) = read_5() in\n\n let rec read current_page d = (* d = days already spent reading *)\n if current_page >= c then d\n else\n let new_page = (max (current_page - l) 0) + (min (v0 + (d*a)) v1) in\n read new_page (d+1)\n in\n printf \"%d\\n\" (read 0 0)\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_5 _ = bscanf Scanning.stdib \" %d %d %d %d %d \" (fun a b c d e -> (a,b,c,d,e))\nlet () = \n let (c,v0,v1,a,l) = read_5() in\n\n let rec read current_page d = (* d = days already spent reading *)\n if current_page >= c then d\n else\n let new_page = (max (current_page - l) 0) + v0 + (d*a) in\n read new_page (d+1)\n in\n printf \"%d\\n\" (read 0 0)\n"}], "src_uid": "b743110117ce13e2090367fd038d3b50"} {"nl": {"description": "Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: 1+2*3=7 1*(2+3)=5 1*2*3=6 (1+2)*3=9 Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.It's easy to see that the maximum value that you can obtain is 9.Your task is: given a, b and c print the maximum value that you can get.", "input_spec": "The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).", "output_spec": "Print the maximum value of the expression that you can obtain.", "sample_inputs": ["1\n2\n3", "2\n10\n3"], "sample_outputs": ["9", "60"], "notes": null}, "positive_code": [{"source_code": "let input = Scanf.scanf \"%d %d %d\" (fun a b c -> (a, b, c))\n\nlet get_max (a, b, c)= \n List.fold_left (Pervasives.max) 0 \n [a * (b + c);\n (a + b) * c;\n a * b * c;\n a * b + c;\n a + b * c;\n a + b + c]\n \nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (get_max (input))"}, {"source_code": "let () =\nlet a,b,c = Scanf.scanf \"%d %d %d \" (fun a b c -> a,b,c) in\nPrintf.printf \"%d\\n\" @@\nList.fold_left max 0 \n[\na+b+c;\na * b * c;\n(a+b) * c;\na+(b * c);\n(a * b)+c;\na * (b+c);\n]"}], "negative_code": [], "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"nl": {"description": "Alice and Bob are playing a game with $$$n$$$ piles of stones. It is guaranteed that $$$n$$$ is an even number. The $$$i$$$-th pile has $$$a_i$$$ stones.Alice and Bob will play a game alternating turns with Alice going first.On a player's turn, they must choose exactly $$$\\frac{n}{2}$$$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $$$\\frac{n}{2}$$$ nonempty piles).Given the starting configuration, determine who will win the game.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\leq n \\leq 50$$$) — the number of piles. It is guaranteed that $$$n$$$ is an even number. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$) — the number of stones in the piles.", "output_spec": "Print a single string \"Alice\" if Alice wins; otherwise, print \"Bob\" (without double quotes).", "sample_inputs": ["2\n8 8", "4\n3 1 4 1"], "sample_outputs": ["Bob", "Alice"], "notes": "NoteIn the first example, each player can only remove stones from one pile ($$$\\frac{2}{2}=1$$$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.In the second example, Alice can remove $$$2$$$ stones from the first pile and $$$3$$$ stones from the third pile on her first move to guarantee a win."}, "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int () in\n let a = Array.init n read_int in\n Array.sort compare a;\n\n if a.(n/2) = a.(0) then printf \"Bob\\n\" else printf \"Alice\\n\"\n"}], "negative_code": [], "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"nl": {"description": "The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.", "input_spec": "The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.", "output_spec": "In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).", "sample_inputs": ["LLUUUR", "RRUULLDD"], "sample_outputs": ["OK", "BUG"], "notes": null}, "positive_code": [{"source_code": "let (|>) x f = f x\n\nexception Bug\n\nlet () =\n let ds = ['U',(-1,0); 'R',(0,1); 'D',(1,0); 'L',(0,-1)] in\n let a = ref (0,0) in\n let h = Hashtbl.create 100 in\n Hashtbl.add h !a ();\n (try\n read_line () |> String.iter (fun c ->\n let xx,yy = List.assq c ds in\n let a' = fst !a + xx, snd !a + yy in\n let z = List.map snd ds |> List.fold_left (fun z (xx,yy) ->\n let a'' = fst a' + xx, snd a' + yy in\n (try Hashtbl.find h a''; z+1 with Not_found -> z)\n ) 0 in\n if z <> 1 || (try Hashtbl.find h a'; true with Not_found -> false) then\n raise Bug;\n a := a';\n Hashtbl.add h a' ();\n );\n \"OK\"\n with Bug ->\n \"BUG\")\n |> print_endline\n"}], "negative_code": [{"source_code": "let (|>) x f = f x\n\nlet scanl f e s =\n let n = String.length s in\n let rec go i e acc =\n if i >= n then\n acc\n else\n let e' = f e s.[i] in\n go (i+1) e' (e'::acc)\n in go 0 e [e]\n\nlet rec uniq = function\n | [] | [_] -> true\n | x::((y::zs) as xs) -> x <> y && uniq xs\n\nlet () =\n print_endline (if scanl (fun (x,y) c ->\n let xx,yy = List.assq c ['U',(-1,0); 'R',(0,1); 'D',(1,0); 'L',(0,-1)] in\n x+xx,y+yy) (0,0) (read_line ()) |> List.sort compare |> uniq then \"OK\" else \"BUG\")\n"}], "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"nl": {"description": "Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?", "input_spec": "The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["2 2", "9 3"], "sample_outputs": ["3", "13"], "notes": "NoteIn the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day."}, "positive_code": [{"source_code": "let pf = Printf.printf ;;\nlet epf = Printf.eprintf ;;\nlet sf = Scanf.scanf ;;\n\nlet (|>) x f = f x ;;\n\nmodule Array = struct\n include ArrayLabels\n let fold_lefti ~f ~init arr =\n let acc = ref init in\n for i = 0 to Array.length arr - 1 do\n acc := f i !acc arr.(i)\n done;\n !acc\n ;;\nend\nmodule String = StringLabels ;;\nmodule List = struct\n include ListLabels ;;\n let rec repeat n a = if n = 0 then [] else a :: repeat (n - 1) a ;;\n let rec drop n a =\n if n = 0 then a\n else match a with\n | [] -> failwith \"cannot take\"\n | x :: xs -> drop (n - 1) xs ;;\n\n let init ~f n =\n let res = ref [] in\n for i = 0 to n - 1 do\n res := f i :: !res\n done;\n List.rev !res\n ;;\nend ;;\nmodule H = Hashtbl ;;\n\nmodule SI = Set.Make (struct\n type t = int \n let compare = compare\nend)\n\nlet () =\n let n, m = sf \"%d %d \" (fun n m -> n, m) in\n let sock = ref n in\n let i = ref 1 in\n while !sock > 0 do\n epf \"i, sock = %d, %d\\n\" !i !sock;\n decr sock;\n if !i > 1 && !i mod m = 0 then incr sock;\n if !sock > 0 then incr i;\n done;\n pf \"%d\\n\" !i\n;;\n"}, {"source_code": "let input () = Scanf.scanf \"%d %d\" (fun n m -> (n, m))\n\nlet add socks days m = \n if days mod m = 0\n then\n socks + 1\n else\n socks\n\nlet solve (n, m) =\n let rec loop socks days =\n if socks > 0\n then\n loop ((add socks days m) - 1) (days + 1) \n else\n days - 1\n in loop n 1\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}], "negative_code": [], "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"nl": {"description": "In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.", "input_spec": "Four lines contain four characters each: the j-th character of the i-th line equals \".\" if the cell in the i-th row and the j-th column of the square is painted white, and \"#\", if the cell is black.", "output_spec": "Print \"YES\" (without the quotes), if the test can be passed and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["####\n.#..\n####\n....", "####\n....\n####\n...."], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column."}, "positive_code": [{"source_code": "\nlet data = Array.init 4 (fun i -> read_line () ) ;;\n\nlet solve i j = let cnt = ref 0 in \n for ii = 0 to 1 do for jj = 0 to 1 do \n if (data.(i+ii)).[j+jj] = '#' then cnt := !cnt + 1\n done\n done;\n !cnt <= 1;;\n\nlet solve2 i j = let cnt = ref 0 in \n for ii = 0 to 1 do for jj = 0 to 1 do \n if (data.(i+ii)).[j+jj] = '.' then cnt := !cnt + 1\n done\n done;\n !cnt <= 1;;\n\n(*for i = 0 to 3 do print_endline data.(i) done;;*)\n\nlet flag = ref false;;\n\nfor i = 0 to 2 do\n for j = 0 to 2 do\n flag := !flag || solve i j || solve2 i j\n done\ndone;;\n\nif !flag = false then print_string \"NO\\n\"\nelse print_string \"YES\\n\";;\n"}, {"source_code": "(* Codeforces 103A - UnilShtan *)\n\nopen Filename;;\n\n(* you can use either gr or rdln but not both *)\nlet use_input_txt = false;;\nlet fn = (Filename.dirname Filename.current_dir_name);;\nlet filename = Filename.concat \".\" \"input.txt\";;\nlet cin = if use_input_txt then Scanf.Scanning.open_in filename\n\telse Scanf.Scanning.stdin;;\n\nlet cout = open_out \"output.txt\";;\nlet gr () = Scanf.bscanf cin \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\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 printlisti64 li = List.iter (fun i -> (print_string (Int64.to_string 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 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet aa = Array.make 4 \"\";;\n\nlet rec readaa i n =\n\tif i == n then ()\n\telse (\n\t\taa.(i) <- rdln();\n\t\treadaa (i +1) n\n\t);;\n\nlet cntaa ii jj c =\n\tlet cnt = ref 0 in (\n\t\tfor i = ii to ii +1 do\n\t\t\tfor j = jj to jj +1 do\n\t\t\t\tif aa.(i).[j] == c then\n\t\t\t\t\tcnt := !cnt + 1\n\t\t\tdone\n\t\tdone;\n\t\t!cnt\n\t);;\n\nlet rec ifiq () =\n\tlet iqok = ref false in\n\tbegin\n\t\tfor ii = 0 to 2 do\n\t\t\tfor jj = 0 to 2 do\n\t\t\t\tbegin\n\t\t\t\t\tif (cntaa ii jj '#') >= 3 then iqok := true;\n\t\t\t\t\tif (cntaa ii jj '.') >= 3 then iqok := true\n\t\t\t\tend\n\t\t\tdone\n\t\tdone;\n\t\t!iqok\n\tend;;\n\nlet main() =\n\tbegin\n\t\treadaa 0 4;\n\t\tprint_string (if ifiq() then \"YES\" else \"NO\") \n\tend;;\n\nmain();;\n"}], "negative_code": [], "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"nl": {"description": "Andrey received a postcard from Irina. It contained only the words \"Hello, Andrey!\", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.For example, consider the following string: This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows: candy cane 1: remove the letter w, snowflake 1: repeat the letter p twice, candy cane 2: leave the letter n, snowflake 2: remove the letter w, snowflake 3: leave the letter e. Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.Andrey knows that messages from Irina usually have a length of $$$k$$$ letters. Help him to find out if a given string can encode a message of $$$k$$$ letters, and if so, give an example of such a message.", "input_spec": "The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $$$200$$$. The second line contains an integer number $$$k$$$ ($$$1 \\leq k \\leq 200$$$), the required message length.", "output_spec": "Print any message of length $$$k$$$ that the given string can encode, or «Impossible» if such a message does not exist.", "sample_inputs": ["hw?ap*yn?eww*ye*ar\n12", "ab?a\n2", "ab?a\n3", "ababb\n5", "ab?a\n1"], "sample_outputs": ["happynewyear", "aa", "aba", "ababb", "Impossible"], "notes": null}, "positive_code": [{"source_code": "let rec fix f x = f (fix f) x;;\nArray.(Scanf.scanf \" %s %d\" @@ fun s n ->\n let a = init (String.length s) (fun i -> s.[i]) in\n let undef = -7 in\n let p,q,r,_ = fold_left (fun (p,q,r,i) -> function\n | '*' -> (List.tl p, q,i,i+1)\n | '?' -> (List.tl p,i::q,r,i+1)\n | _ -> ( i::p, q,r,i+1)\n ) ([],[],undef,0) a in\n let p,q = List.(rev p, rev q) in\n if List.length p = n then\n (List.iter (fun i -> print_char a.(i)) p; exit 0)\n else if List.length p > n then\n (print_string \"Impossible\"; exit 0);\n let need = n - List.length p in\n let u = ref p in\n if r<>undef then (\n iteri (fun i c ->\n if List.length !u > 0 && List.hd !u = i then (\n print_char a.(i); u := List.tl !u\n ) else if i+1=r then\n for k=1 to need do print_char a.(i) done\n ) a\n ) else (\n if need > List.length q then\n (print_string \"Impossible\"; exit 0);\n let w = ref q in\n let rest = ref need in\n iteri (fun i c ->\n if List.length !u > 0 && List.hd !u = i then (\n print_char a.(i); u := List.tl !u\n ) else if List.length !w > 0 && List.hd !w = i+1 && !rest > 0 then (\n print_char a.(i); w := List.tl !w;\n rest := !rest - 1\n ) else if i+1=r then\n for k=1 to need do print_char a.(i) done\n ) a\n )\n)"}, {"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 s = scanf \" %s\" @@ id in\n let n = gi 0 in\n let hat,rep = ref [],ref [] in\n let a = fix (fun f i x ->\n if i>=String.length s then x\n else\n let c = s.[i] in\n if c='?' || c='*' then (\n if c='?' then hat := i::!hat;\n if c='*' then rep := i::!rep;\n f (i+$1) (List.tl x)\n ) else f (i+$1) (c::x)\n ) 0 [] |> List.rev in\n let l = List.length a in\n (* printf \"%d\\n\" l;\n print_list string_of_int !hat;\n print_list string_of_int !rep; *)\n (* print_list (String.make 1) a; *)\n rep := List.sort compare !rep;\n hat := List.sort compare !hat;\n if llen a > n then (\n print_endline \"Impossible\"; exit 0\n ) else if llen a = n then (\n print_endline @@ string_of_list ~separator:\"\" (String.make 1) a; exit 0\n );\n if List.length !rep = 0 then (\n if llen a + llen !hat < n then (\n print_endline \"Impossible\"; exit 0\n ) else (\n let cnt = ref @@ n - llen a in\n String.iteri (fun i c ->\n (* printf \"%d :: %d <> %d :: %Ld\\n\" (List.length !hat) (i+$1) (List.hd !hat) !cnt; *)\n if List.length !hat > 0 && i+$1=List.hd !hat && !cnt > 0L then (\n hat := List.tl !hat;\n print_char c;\n cnt -= 1L;\n ) else if c='?' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*'))\n then (\n\n ) else (\n print_char c;\n )\n ) s\n )\n ) else (\n let rest = i32 @@ n - llen a in\n let j = List.hd !rep in\n String.iteri (fun i c ->\n if i+$1=j then (\n repi 1 rest (fun _ -> printf \"%c\" c)\n )\n else\n if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()\n else (\n print_char c\n )\n ) s\n )\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"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 s = scanf \" %s\" @@ id in\n let n = gi 0 in\n let hat,rep = ref [],ref [] in\n let a = fix (fun f i x ->\n if i>=String.length s then x\n else\n let c = s.[i] in\n if c='?' || c='*' then (\n if c='?' then hat := i::!hat;\n if c='*' then rep := i::!rep;\n f (i+$1) (List.tl x)\n ) else f (i+$1) (c::x)\n ) 0 [] |> List.rev in\n let l = List.length a in\n (* printf \"%d\\n\" l;\n print_list string_of_int !hat;\n print_list string_of_int !rep; *)\n (* print_list (String.make 1) a; *)\n if llen a > n then (\n print_endline \"Impossible\"; exit 0\n ) else if llen a = n then (\n print_endline @@ string_of_list ~separator:\"\" (String.make 1) a; exit 0\n );\n if List.length !rep = 0 then (\n if llen a + llen !hat > n then (\n print_endline \"Impossible\"; exit 0\n ) else (\n let cnt = ref @@ List.length !hat in\n String.iteri (fun i c ->\n if c='?' then ()\n else (\n if List.length !rep > 0 && i+$1=List.hd !rep && !cnt > 0 then (\n rep := List.tl !rep;\n cnt := !cnt -$ 1;\n );\n print_char c;\n )\n ) s\n )\n ) else (\n let rest = i32 @@ n - llen a in\n let j = List.hd !rep in\n String.iteri (fun i c ->\n if i+$1=j then (\n repi 1 rest (fun _ -> printf \"%c\" c)\n )\n else\n if c='?' || c='*' || (i <= String.length s-$2 && (s.[i+$1]='?' || s.[i+$1]='*')) then ()\n else (\n print_char c\n )\n ) s\n )\n\n\n\n\n\n\n\n\n"}, {"source_code": "let rec fix f x = f (fix f) x;;\nArray.(Scanf.scanf \" %s %d\" @@ fun s n ->\n let p,q,r,_ = init (String.length s) (fun i -> s.[i])\n |> fold_left (fun (p,q,r,i) c ->\n if c = '?' then (List.tl p,i::q,r,i+1)\n else if c='*' then (List.tl p,q,i::r,i+1)\n else ((c,i)::p,q,r,i+1)\n ) ([],[],[],0) in\n let p,q,r = List.(rev p,rev q,rev r) in\n if List.length p = n then\n List.map fst p |> List.iter print_char\n else if List.length p > n then\n print_endline \"Impossible\"\n else (\n let need = n - List.length p in\n if List.length r <> 0 then (\n let j = List.hd r in\n List.iter (fun (c,i) ->\n print_char c;\n if i=j-2 then for k=0 to need do\n print_char s.[i+1]\n done\n ) p\n ) else (\n if List.length p + List.length q < n then\n print_endline \"Impossible\"\n else (\n List.fold_left (fun (rest,q) (c,i) ->\n print_char c;\n match q with\n | [] -> (rest,q)\n | h::t as q ->\n if i=h-2 then (\n print_char s.[h-1]; (rest-1,t)\n ) else (rest,q)\n ) (need,q) p |> ignore\n )\n )\n ))"}, {"source_code": "let rec fix f x = f (fix f) x;;\nArray.(Scanf.scanf \" %s %d\" @@ fun s n ->\n let p,q,r,_ = init (String.length s) (fun i -> s.[i])\n |> fold_left (fun (p,q,r,i) c ->\n if c = '?' then (List.tl p,i::q,r,i+1)\n else if c='*' then (List.tl p,q,i::r,i+1)\n else ((c,i)::p,q,r,i+1)\n ) ([],[],[],0) in\n let p,q,r = List.(rev p,rev q,rev r) in\n if List.length p = n then\n List.map fst p |> List.iter print_char\n else if List.length p > n then\n print_endline \"Impossible\"\n else (\n let need = n - List.length p in\n if List.length r <> 0 then (\n let j = List.hd r in\n List.iter (fun (c,i) ->\n print_char c;\n if i=j-2 then for k=1 to need do\n print_char s.[i+1]\n done\n ) p\n ) else (\n if List.length p + List.length q < n then\n print_endline \"Impossible\"\n else (\n List.fold_left (fun (rest,q) (c,i) ->\n print_char c;\n match q with\n | [] -> (rest,q)\n | h::t as q ->\n if i=h-2 then (\n print_char s.[h-1]; (rest-1,t)\n ) else (rest,q)\n ) (need,q) p |> ignore\n )\n )\n ))"}], "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"nl": {"description": "A and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board.As A doesn't like counting, he asked you to help him determine which player has the larger position weight.", "input_spec": "The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.", "output_spec": "Print \"White\" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print \"Black\" if the weight of the black pieces is more than the weight of the white pieces and print \"Draw\" if the weights of the white and black pieces are equal.", "sample_inputs": ["...QK...\n........\n........\n........\n........\n........\n........\n...rk...", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........"], "sample_outputs": ["White", "Draw", "Black"], "notes": "NoteIn the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.In the second test sample the weights of the positions of the black and the white pieces are equal to 39.In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16."}, "positive_code": [{"source_code": "let read () = Scanf.scanf \"%c \" (fun c -> c)\n\nlet colour char = \n if char != '.' && char != '\\n'\n then\n if Char.lowercase char = char\n then\n `Black\n else\n `White\n else\n `Pass\n\nlet count char score =\n match Char.lowercase char with\n | 'q' -> score + 9\n | 'r' -> score + 5\n | 'b' | 'n' -> score + 3\n | 'p' -> score + 1\n | 'k' -> score\n\nlet get_winner black white = \n if black > white\n then\n \"Black\"\n else\n if white > black\n then\n \"White\"\n else\n \"Draw\"\n\nlet solve () = \n let rec loop i score_black score_white =\n if i < 64\n then \n let char = read () in\n match (colour char) with\n | `Black -> loop (i + 1) (count char score_black) score_white\n | `White -> loop (i + 1) score_black (count char score_white)\n | `Pass -> loop (i + 1) score_black score_white\n else\n get_winner score_black score_white\n in loop 0 0 0\n \nlet print winner = Printf.printf \"%s\\n\" winner\nlet () = print (solve ())"}, {"source_code": "let evalue = function\n\t|'Q'\t-> (9,0)\n\t|'R'\t-> (5,0)\n\t|'B'\t-> (3,0)\n\t|'N'\t-> (3,0)\n\t|'P'\t-> (1,0)\n\t|'q'\t-> (0,9)\n\t|'r'\t-> (0,5)\n\t|'b'\t-> (0,3)\n\t|'n'\t-> (0,3)\n\t|'p'\t-> (0,1)\n\t|_\t-> (0,0);;\n\nlet main () =\n\tlet a = ref 0 and b = ref 0 and l= ref [] in\n\tfor i=0 to 7 do\n\t\tl := (Scanf.scanf \"%s\\n\" (fun j -> j))::!l;\n\tdone;\n\tList.iter (fun x ->\n\t\t\tfor i=0 to String.length x - 1 do\n\t\t\t\tlet (c,d) = evalue (x.[i]) in\n\t\t\t\t\ta:= !a + c;\n\t\t\t\t\tb:= !b + d;\n\t\t\tdone) !l;\n\tif !a < !b\n\t\tthen Printf.printf \"Black\"\n\t\telse if !a = !b\n\t\t\tthen Printf.printf \"Draw\"\n\t\t\telse Printf.printf \"White\";;\n\nmain ();;\n"}, {"source_code": "let score x = \n let check_upp = function \n | 'a' .. 'z' -> false\n | 'A' .. 'Z' -> true\n | _ -> false in\n let upper x = (if (check_upp x) then x else Char.uppercase x) in\n ((if (check_upp x) then 0 else 1) , match (upper x) with\n | 'Q' -> 9\n | 'R' -> 5\n | 'B' -> 3\n | 'N' -> 3\n | 'P' -> 1\n | _ -> 0);; \n\n(*Running Code*)\nlet ans = [|ref 0; ref 0|];;\nfor i = 1 to 8 do\n let a = ref (read_line ()) in\n for j = 0 to ((String.length !a) - 1) do \n let p = (score !a.[j]) in\n (ans.(fst p)) := !(ans.(fst p)) + (snd p);\n done;\ndone;;\nprint_string (if (!(ans.(0)) > !(ans.(1))) then \"White\" else (if (!(ans.(0)) = !(ans.(1))) then \"Draw\" else \"Black\"));;\nprint_string \"\\n\"\n"}, {"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 isupper c = c <= 'Z' && c >= 'A'\nlet toupper = Char.uppercase\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let board = Array.init 8 (fun _ -> read_string()) in\n\n let score p =\n let s = match toupper p with\n | 'K' -> 0\n | 'Q' -> 9\n | 'R' -> 5\n | 'B' -> 3\n | 'N' -> 3\n | 'P' -> 1\n | '.' -> 0\n | _ -> failwith \"bad input\"\n in\n \n if isupper p then s else -s\n in\n\n let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in\n\n if answer = 0 then printf \"Draw\\n\"\n else if answer > 0 then printf \"White\\n\"\n else printf \"Black\\n\"\n"}], "negative_code": [{"source_code": "let evalue = function\n\t|'Q'\t-> (9,0)\n\t|'R'\t-> (5,0)\n\t|'B'\t-> (3,0)\n\t|'N'\t-> (3,0)\n\t|'P'\t-> (1,0)\n\t|'q'\t-> (0,9)\n\t|'r'\t-> (0,5)\n\t|'b'\t-> (0,3)\n\t|'n'\t-> (0,3)\n\t|'p'\t-> (0,1)\n\t|_\t-> (0,0);;\n\nlet main () =\n\tlet a = ref 0 and b = ref 0 and l= ref [] in\n\tfor i=0 to 7 do\n\t\tl := (Scanf.scanf \"%s\" (fun j -> j))::!l;\n\tdone;\n\tList.iter (fun x ->\n\t\t\tfor i=0 to String.length x - 1 do\n\t\t\t\tlet (c,d) = evalue (x.[i]) in\n\t\t\t\t\ta:= !a + c;\n\t\t\t\t\tb:= !b + d;\n\t\t\tdone) !l;\n\tif !a < !b\n\t\tthen Printf.printf \"White\"\n\t\telse if !a = !b\n\t\t\tthen Printf.printf \"Draw\"\n\t\t\telse Printf.printf \"Black\";;\n\nmain ();;\n"}, {"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 isupper c = c <= 'Z' && c >= 'A'\nlet toupper = Char.uppercase\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let board = Array.init 8 (fun _ -> read_string()) in\n\n let score p =\n let s = match toupper p with\n | 'K' -> 0\n | 'Q' -> 8\n | 'R' -> 5\n | 'B' -> 3\n | 'N' -> 3\n | 'P' -> 1\n | '.' -> 0\n | _ -> failwith \"bad input\"\n in\n \n if isupper p then s else -s\n in\n\n let answer = sum 0 7 (fun i -> sum 0 7 (fun j -> score board.(i).[j])) in\n\n if answer = 0 then printf \"Draw\\n\"\n else if answer > 0 then printf \"White\\n\"\n else printf \"Black\\n\"\n"}], "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"nl": {"description": "PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: \"There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number\".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.", "input_spec": "The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis. ", "output_spec": "Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.", "sample_inputs": ["3", "4"], "sample_outputs": ["1", "2"], "notes": "NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number."}, "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\nlet solve n = if n > 2 then n - 2 else n + 2\n \nlet main () =\n let n = read_int () in\n let answer = if n > 2 then n - 2 else n + 2 in \n print_int answer;;\n\nmain ()\n\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m =\n if n + 2 <= 1000\n then n + 2\n else n - 2\n in\n Printf.printf \"%d\\n\" m\n"}], "negative_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = n + 2 in\n Printf.printf \"%d\\n\" m\n"}], "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"nl": {"description": "Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words \"WUB\" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including \"WUB\", in one string and plays the song at the club.For example, a song with words \"I AM X\" can transform into a dubstep remix as \"WUBWUBIWUBAMWUBWUBX\" and cannot transform into \"WUBWUBIAMWUBX\".Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.", "input_spec": "The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring \"WUB\" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.", "output_spec": "Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.", "sample_inputs": ["WUBWUBABCWUB", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB"], "sample_outputs": ["ABC", "WE ARE THE CHAMPIONS MY FRIEND"], "notes": "NoteIn the first sample: \"WUBWUBABCWUB\" = \"WUB\" + \"WUB\" + \"ABC\" + \"WUB\". That means that the song originally consisted of a single word \"ABC\", and all words \"WUB\" were added by Vasya.In the second sample Vasya added a single word \"WUB\" between all neighbouring words, in the beginning and in the end, except for words \"ARE\" and \"THE\" — between them Vasya added two \"WUB\"."}, "positive_code": [{"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> (s, String.length s))\n\nlet traverse (remix, l) = \n let rec loop i original =\n if i + 3 <= l\n then\n if remix.[i] = 'W'\n then\n if remix.[i + 1] = 'U'\n then\n if remix.[i + 2] = 'B'\n then\n loop (i + 3) (' ' :: original)\n else\n loop (i + 2) (remix.[i + 1] :: remix.[i] :: original)\n else\n loop (i + 1) (remix.[i] :: original)\n else\n loop (i + 1) (remix.[i] :: original)\n else\n if i + 2 <= l\n then\n (' ' :: remix.[i + 1] :: remix.[i] :: original)\n else\n if i + 1 <= l\n then\n (' ' :: remix.[i] :: original)\n else\n (' ' :: original)\n in loop 0 [' ']\n\nlet solve input = List.rev (traverse input)\n\nlet build result =\n let rec loop last list temp =\n (match (temp, last) with\n |(' ' :: tail), ' ' -> loop ' ' list tail\n |(x :: tail), _ -> \n loop x (x :: list) tail\n |[], _ -> List.rev list)\n in loop ' ' [] result\n\nlet rec print list = \n (match list with\n |[' '] -> ()\n |(x :: tail) -> \n Printf.printf \"%c\" x;\n print tail\n |[] -> ())\n\nlet () = print (build (solve (input())))"}, {"source_code": "let 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\nlet input () = Scanf.scanf \"%s\" (fun s -> str_to_list s)\n\nlet traverse input =\n let rec loop remix original = \n match remix with \n |('W' :: 'U' :: 'B' :: tail) -> loop tail (' ' :: original)\n |[] -> List.rev original\n |(x :: tail) -> loop tail (x :: original)\n in loop input [' ']\n\nlet build result =\n let rec loop last list temp =\n (match (temp, last) with\n |(' ' :: tail), ' ' -> loop ' ' list tail\n |(x :: tail), _ -> \n loop x (x :: list) tail\n |[], _ -> List.rev list)\n in loop ' ' [] result\n\nlet rec print list = \n (match list with\n |[' '] -> ()\n |(x :: tail) -> \n Printf.printf \"%c\" x;\n print tail\n |[] -> ())\n\nlet () = print (build (traverse (input())))"}, {"source_code": "let split_WUB s =\n Str.split (Str.regexp \"WUB\") s\n\nlet add_space words =\n let f word =\n if word = \"\" then word\n else \" \" ^ word\n in\n (List.hd words) :: (List.map f (List.tl words))\n\nlet solve s =\n List.iter (Printf.printf \"%s\") (add_space (split_WUB s))\n\nlet _ =\n Scanf.scanf \" %s\" solve\n \n"}], "negative_code": [], "src_uid": "edede580da1395fe459a480f6a0a548d"} {"nl": {"description": "Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.", "input_spec": "The first line of the input contains three integers d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths. d1 is the length of the path connecting Patrick's house and the first shop; d2 is the length of the path connecting Patrick's house and the second shop; d3 is the length of the path connecting both shops. ", "output_spec": "Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.", "sample_inputs": ["10 20 30", "1 1 5"], "sample_outputs": ["60", "4"], "notes": "NoteThe first sample is shown on the picture in the problem statement. One of the optimal routes is: house first shop second shop house.In the second sample one of the optimal routes is: house first shop house second shop house."}, "positive_code": [{"source_code": "let input () = Scanf.scanf \"%d %d %d\" (fun d1 d2 d3 -> d1, d2, d3)\nlet solve (d1, d2, d3) =\n let p1 = d1 + d2 + d3 in\n let p2 = 2 * d1 + 2 * d2 in\n let p3 = 2 * d1 + 2 * d3 in\n let p4 = 2 * d2 + 2 * d3 in\n let paths = (p1 :: p2 :: p3 :: p4 :: []) in\n let min = List.hd (List.sort (Pervasives.compare) paths) in\n min\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let ints = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\nlet d1 = List.nth ints 0 and\n d2 = List.nth ints 1 and\n d3 = List.nth ints 2 and\n max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in \nList.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d3+d2 ;d1+d3+d3+d1] max_int |> print_int \n"}, {"source_code": "\nopen 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 long x = Int64.of_int x\n\nlet read_int () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let d1 = read_int () in\n let d2 = read_int () in\n let d3 = read_int () in \n\n let answer = min (min ((d1++d2)**2L) (d1++d2++d3)) (min ((d1++d3)**2L) ((d2++d3)**2L)) in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [{"source_code": "let ints = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\nlet d1 = List.nth ints 0 and\n d2 = List.nth ints 1 and\n d3 = List.nth ints 2 and\n max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in \nList.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1] max_int |> print_int "}, {"source_code": "let ints = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\nlet d1 = List.nth ints 0 and\n d2 = List.nth ints 1 and\n d3 = List.nth ints 2 and\n max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in\nList.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1; d2+d3+d3+d2] max_int |> print_int\n"}, {"source_code": "let ints = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\nlet d1 = List.nth ints 0 and\n d2 = List.nth ints 1 and\n d3 = List.nth ints 2 and\n max_int = Int32.shift_right (Int32.max_int) 1 |> Int32.to_int in \nList.fold_right min [d1+d3+d2; d1+d1+d2+d2; d2+d3+d1; d2+d3+d3+d2] max_int |> print_int \n"}, {"source_code": "\nopen 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 long x = Int64.of_int x\n\nlet read_int () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let d1 = read_int () in\n let d2 = read_int () in\n let d3 = read_int () in \n\n let answer = min ((d1++d2)**2L) (d1++d2++d3) in\n\n printf \"%Ld\\n\" answer\n"}, {"source_code": "\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let d1 = read_int () in\n let d2 = read_int () in\n let d3 = read_int () in \n\n let answer = min ((d1+d2)*2) (d1+d2+d3) in\n\n printf \"%d\\n\" answer\n"}], "src_uid": "26cd7954a21866dbb2824d725473673e"} {"nl": {"description": "You are given two integer numbers, $$$n$$$ and $$$x$$$. You may perform several operations with the integer $$$x$$$.Each operation you perform is the following one: choose any digit $$$y$$$ that occurs in the decimal representation of $$$x$$$ at least once, and replace $$$x$$$ by $$$x \\cdot y$$$.You want to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$. What is the minimum number of operations required to do that?", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$x$$$ ($$$2 \\le n \\le 19$$$; $$$1 \\le x < 10^{n-1}$$$).", "output_spec": "Print one integer — the minimum number of operations required to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$, or $$$-1$$$ if it is impossible.", "sample_inputs": ["2 1", "3 2", "13 42"], "sample_outputs": ["-1", "4", "12"], "notes": "NoteIn the second example, the following sequence of operations achieves the goal: multiply $$$x$$$ by $$$2$$$, so $$$x = 2 \\cdot 2 = 4$$$; multiply $$$x$$$ by $$$4$$$, so $$$x = 4 \\cdot 4 = 16$$$; multiply $$$x$$$ by $$$6$$$, so $$$x = 16 \\cdot 6 = 96$$$; multiply $$$x$$$ by $$$9$$$, so $$$x = 96 \\cdot 9 = 864$$$. "}, "positive_code": [{"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 long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_long _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x)\nlet () = \n let goal_length = read_int () in\n let x = read_long () in\n\n let rec ndigits x = if x = 0L then 0 else 1 + ndigits (x // 10L) in\n let rec dlistx n = if n=0L then [] else (short(n %% 10L))::(dlistx (n // 10L)) in\n let dlist x =\n let li = List.sort_uniq compare (dlistx x) in\n List.filter (fun d -> d <> 0 && d <> 1) li\n in\n\n let grow x =\n (* apply the grow operator to x in all possible ways *)\n (* return the list of possible results *)\n List.map (fun d -> x ** (long d)) (dlist x)\n in\n\n let rec bfs li nops =\n if li = [] then -1\n else if List.exists (fun x -> ndigits x = goal_length) li then nops\n else bfs (List.sort_uniq compare (List.concat (List.map grow li))) (nops+1)\n in\n\n printf \"%d\\n\" (bfs [x] 0)\n"}], "negative_code": [], "src_uid": "cedcc3cee864bf8684148df93804d029"} {"nl": {"description": "Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.", "input_spec": "The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.", "output_spec": "Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.", "sample_inputs": ["2 10\n8 9", "3 5\n4 4 4"], "sample_outputs": ["4", "3"], "notes": "NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate."}, "positive_code": [{"source_code": "let read () = Scanf.scanf \" %d\" (fun x -> x) and\n foi = float_of_int in\nlet (k,n) = (read(), read()) in\nlet s = ref 0 in\nfor i = 0 to n-1 do s := !s + (read()) done;\nlet (fn , fs, fk ) = (foi n, foi !s, foi k) in\nprint_int @@ if fs /. fn > fk -. 0.5 then 0 else int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5"}, {"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 read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let k = read_int () in\n let a = Array.init n read_int in\n\n let s = sum 0 (n-1) (fun i -> a.(i)) in\n\n printf \"%d\\n\" (max 0 (2*n*k - n - 2 * s))\n"}], "negative_code": [{"source_code": "let read () = Scanf.scanf \" %d\" (fun x -> x) and\n foi = float_of_int in\nlet (k,n) = (read(), read()) in\nlet s = ref 0 in\nfor i = 0 to n-1 do s := !s + (read()) done;\nlet (fn , fs, fk ) = (foi n, foi !s, foi k) in\nprint_int @@ int_of_float @@ ((fn *. (fk -. 0.5)) -. fs) /. 0.5"}], "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"} {"nl": {"description": "One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.", "input_spec": "Input data contains the only number n (1 ≤ n ≤ 109).", "output_spec": "Output the only number — answer to the problem.", "sample_inputs": ["10"], "sample_outputs": ["2"], "notes": "NoteFor n = 10 the answer includes numbers 1 and 10."}, "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet f n =\n let rec go n ten sum =\n if n = 0 then\n sum\n else\n go (n/2) (ten*10) (sum+ten*(n mod 2))\n in go n 1 0\n\nlet () =\n let n = read_int 0 in\n let rec go i =\n if f i > n then\n i-1\n else\n go (i+1)\n in\n go 0 |> Printf.printf \"%d\\n\"\n"}], "negative_code": [], "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"nl": {"description": "You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.", "input_spec": "First line contains an integer n (6 ≤ n ≤ 8) – the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).", "output_spec": "Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).", "sample_inputs": ["7\nj......", "7\n...feon", "7\n.l.r.o."], "sample_outputs": ["jolteon", "leafeon", "flareon"], "notes": "NoteHere's a set of names in a form you can paste into your solution:[\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"]{\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"}"}, "positive_code": [{"source_code": "let ps = [\"vaporeon\"; \"jolteon\"; \"flareon\"; \"espeon\"; \"umbreon\"; \"leafeon\"; \"glaceon\"; \"sylveon\"]\n\nlet () =\n Scanf.scanf \"%d %s \" (fun n s ->\n let pat = Str.regexp (\"^\" ^ s ^ \"$\") in\n print_endline (List.find (fun p -> Str.string_match pat p 0) ps))\n;;"}, {"source_code": "let ps = [\"vaporeon\"; \"jolteon\"; \"flareon\"; \"espeon\"; \"umbreon\"; \"leafeon\"; \"glaceon\"; \"sylveon\"]\n\nlet () =\n Scanf.scanf \"%d %s \" (fun n s ->\n let pat = Str.regexp s in\n print_endline (List.find (fun p -> String.length s = String.length p && Str.string_match pat p 0) ps))\n;;"}], "negative_code": [{"source_code": "let ps = [\"vaporeon\"; \"jolteon\"; \"flareon\"; \"espeon\"; \"umbreon\"; \"leafeon\"; \"glaceon\"; \"sylveon\"]\n\nlet () =\n Scanf.scanf \"%d %s \" (fun n s ->\n let pat = Str.regexp s in\n print_endline (List.find (fun p -> Str.string_match pat p 0) ps))\n;;\n"}], "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"nl": {"description": "Recently you have received two positive integer numbers $$$x$$$ and $$$y$$$. You forgot them, but you remembered a shuffled list containing all divisors of $$$x$$$ (including $$$1$$$ and $$$x$$$) and all divisors of $$$y$$$ (including $$$1$$$ and $$$y$$$). If $$$d$$$ is a divisor of both numbers $$$x$$$ and $$$y$$$ at the same time, there are two occurrences of $$$d$$$ in the list.For example, if $$$x=4$$$ and $$$y=6$$$ then the given list can be any permutation of the list $$$[1, 2, 4, 1, 2, 3, 6]$$$. Some of the possible lists are: $$$[1, 1, 2, 4, 6, 3, 2]$$$, $$$[4, 6, 1, 1, 2, 3, 2]$$$ or $$$[1, 6, 3, 2, 4, 1, 2]$$$.Your problem is to restore suitable positive integer numbers $$$x$$$ and $$$y$$$ that would yield the same list of divisors (possibly in different order).It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers $$$x$$$ and $$$y$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 128$$$) — the number of divisors of $$$x$$$ and $$$y$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \\dots, d_n$$$ ($$$1 \\le d_i \\le 10^4$$$), where $$$d_i$$$ is either divisor of $$$x$$$ or divisor of $$$y$$$. If a number is divisor of both numbers $$$x$$$ and $$$y$$$ then there are two copies of this number in the list.", "output_spec": "Print two positive integer numbers $$$x$$$ and $$$y$$$ — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.", "sample_inputs": ["10\n10 2 8 1 2 4 1 20 4 5"], "sample_outputs": ["20 8"], "notes": null}, "positive_code": [{"source_code": "(* #require \"str\" *)\n\nlet divisors (n:int) : int list =\n let rec divhelper m lst =\n if m * m > n then lst\n else if m * m = n then m :: lst\n else if n mod m = 0 then divhelper (m+1) ((n/m)::m::lst)\n else divhelper (m+1) lst\n in List.sort compare (divhelper 1 [])\n\nlet rec remove lst1 lst2=\n match lst1, lst2 with\n | _, [] -> lst1\n | [], _ -> failwith \"Should not occur\"\n | (f1::r1), (f2::r2) -> if f1 = f2 then remove r1 r2 else\n f1 :: remove r1 lst2\n\nlet lmax = List.fold_left max 0\n\nlet split = Str.split (Str.regexp \" +\")\n\nlet main ()=\n let _ = read_line() in\n let lst1 = List.sort compare\n (List.map int_of_string (split (read_line()))) in\n let a1 = lmax lst1 in\n let fdiv = divisors a1 in\n let a2 = lmax (remove lst1 fdiv) in\n print_string (string_of_int a1 ^ \" \" ^ string_of_int a2 ^\"\\n\")\n\nlet () = main ()\n"}], "negative_code": [], "src_uid": "868407df0a93085057d06367aecaf9be"} {"nl": {"description": "User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >> When someone clicks the button \"<<\" he is redirected to page 1, and when someone clicks the button \">>\" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.There are some conditions in the navigation: If page 1 is in the navigation, the button \"<<\" must not be printed. If page n is in the navigation, the button \">>\" must not be printed. If the page number is smaller than 1 or greater than n, it must not be printed.  You can see some examples of the navigations. Make a program that prints the navigation.", "input_spec": "The first and the only line contains three integers n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n)", "output_spec": "Print the proper navigation. Follow the format of the output from the test samples.", "sample_inputs": ["17 5 2", "6 5 2", "6 1 2", "6 2 2", "9 6 3", "10 6 3", "8 5 4"], "sample_outputs": ["<< 3 4 (5) 6 7 >>", "<< 3 4 (5) 6", "(1) 2 3 >>", "1 (2) 3 4 >>", "<< 3 4 5 (6) 7 8 9", "<< 3 4 5 (6) 7 8 9 >>", "1 2 3 4 (5) 6 7 8"], "notes": null}, "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and k=read_int();;\nif m-k>1 then print_string \"<< \";;\nfor i=m-k to m+k do\n if (i>=1)&&(i<=n) then\n begin\n if i=m then print_string \"(\";\n print_int i;\n if i=m then print_string \")\";\n if i<>m+k then print_string \" \"\n end\ndone;;\nif m+k>\";;"}], "negative_code": [], "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"nl": {"description": "Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display). Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.", "input_spec": "The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.", "output_spec": "Print the only integer a — the total number of printed segments.", "sample_inputs": ["1 3", "10 15"], "sample_outputs": ["12", "39"], "notes": null}, "positive_code": [{"source_code": "let num_segs = function\n | 0 -> 6\n | 1 -> 2\n | 2 -> 5\n | 3 -> 5\n | 4 -> 4\n | 5 -> 5\n | 6 -> 6\n | 7 -> 3\n | 8 -> 7\n | 9 -> 6\n\nlet rec total_segs = function\n | 0 -> 0\n | n -> num_segs (n mod 10) + total_segs (n / 10)\n\nlet () =\n let [lo; hi] = read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string in\n let sum = ref 0 in\n for i = lo to hi do\n sum := !sum + total_segs i\n done;\n print_int !sum;\n print_newline ()\n"}, {"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let a = xint() and b = xint() in\n let s = Array.make 1000001 0 in\n s.(0) <- 6;\n s.(1) <- 2;\n s.(2) <- 5;\n s.(3) <- 5;\n s.(4) <- 4;\n s.(5) <- 5;\n s.(6) <- 6;\n s.(7) <- 3;\n s.(8) <- 7;\n s.(9) <- 6;\n for i = 10 to 1000000 do\n s.(i) <- s.(i / 10) + s.(i mod 10);\n done;\n let sum = ref 0 in\n for i = a to b do\n sum := !sum + s.(i);\n done;\n Printf.printf \"%d\\n\" !sum;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let a = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = a - 1 in\n let d = [| 6; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] in\n let t = 49 in\n let rec calc n =\n if n = 0\n then 0\n else (\n let r = ref 0 in\n let c = n mod 10 in\n\tif c = 0\n\tthen (\n\t let m = ref n in\n\t while !m > 0 do\n\t r := !r + d.(!m mod 10);\n\t m := !m / 10;\n\t done;\n\t (*Printf.printf \"qwe1 %d %d\\n\" n (!r - d.(0) + t * (n / 10));*)\n\t !r - d.(0) + t * (n / 10) + 10 * calc ((n - 1) / 10);\n\t) else (\n\t let m = ref n in\n\t while !m > 0 do\n\t r := !r + d.(!m mod 10);\n\t m := !m / 10;\n\t done;\n\t r := (!r - d.(c)) * c;\n\t for i = 1 to c do\n\t r := !r + d.(i);\n\t done;\n\t (*!r + t * (n / 10) + 10 * calc (n / 10)*)\n\t (*Printf.printf \"qwe2 %d %d\\n\" n !r;*)\n\t !r + calc (n - c)\n\t)\n )\n in\n let res = calc b - calc a in\n Printf.printf \"%d\\n\" res\n"}, {"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 read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (a,b) = read_pair () in\n\n let tab = [|6;2;5;5;4;5;6;3;7;6|] in\n (* 0 1 2 3 4 5 6 7 8 9 *)\n\n let score x = if x=0 then tab.(0) else\n let rec loop x = if x=0 then 0 else tab.(x mod 10) + loop (x/10) in\n loop x\n in\n \n printf \"%d\\n\" (sum a b score)\n"}], "negative_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n let _ =\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n in\n let ks = ref [] in\n let ht = Hashtbl.create 10 in\n let prev = ref (-1) in\n for i = 0 to n - 1 do\n if Hashtbl.mem ht a.(i) then (\n\tks := (!prev + 1, i) :: !ks;\n\tprev := i;\n\tHashtbl.clear ht;\n ) else (\n\tHashtbl.replace ht a.(i) ()\n )\n done;\n let ks =\n if !prev = n - 1\n then !ks\n else (\n\tmatch !ks with\n\t | [] ->\n\t Printf.printf \"-1\\n\";\n\t exit 0\n\t | (l, r) :: ks ->\n\t (l, n - 1) :: ks\n )\n in\n let ks = List.rev ks in\n Printf.printf \"%d\\n\" (List.length ks);\n List.iter\n\t(fun (l, r) ->\n\t Printf.printf \"%d %d\\n\" (l + 1) (r + 1)\n\t) ks\n"}], "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"nl": {"description": "Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.", "output_spec": "Print one integer — the maximum number of problems Mishka can solve.", "sample_inputs": ["8 4\n4 2 3 1 5 1 6 4", "5 2\n3 1 2 1 3", "5 100\n12 34 55 43 21"], "sample_outputs": ["5", "0", "5"], "notes": "NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6] \\rightarrow [3, 1, 5, 1, 6] \\rightarrow [1, 5, 1, 6] \\rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems."}, "positive_code": [{"source_code": "let ( */ ) = Big_int.mult_big_int;;\nlet ( +/ ) = Big_int.add_big_int;;\nlet ( -/ ) = Big_int.sub_big_int;;\nlet to_int = Big_int.int_of_big_int;;\nlet of_int = Big_int.big_int_of_int;;\nlet min = Big_int.min_big_int;;\nlet (modi) = Big_int.mod_big_int;;\nlet to_string = Big_int.string_of_big_int;;\nlet of_string = Big_int.big_int_of_string;;\nlet ( n,k) in\nlet problem = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in\nlet count = ref 0 in\nwhile !count < n && problem.(!count) <= k do\n incr count;\ndone;\nlet tmp = !count in\nbegin try\n for i = n - 1 downto tmp + 1 do\n if problem.(i) > k then raise End;\n incr count;\n done\n with End -> ();\nend;\nPrintf.printf \"%i\" !count;\nprint_newline ();\n"}, {"source_code": "(* Codeforces *)\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| 0 -> acc\n| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec head_cnt k cnt l = match l with\n| [] -> (cnt, [])\n| h :: tl ->\n\tif h > k then (cnt, l)\n\telse head_cnt k (cnt+1) tl;;\n\nlet main() =\n\tlet n = gr () in\n\tlet k = gr () in\n\tlet a = readlist n [] in\n\tlet ha, tl = head_cnt k 0 a in\n\tlet rev_tl = List.rev tl in\n\tlet ta, _ = head_cnt k 0 rev_tl in\t\n\tbegin\n\t\t(* print_string \"a = \"; printlisti a;\n\t\tprint_string \" ha = \";\n\t\tprint_int ha; print_string \" ta = \";\n\t\tprint_int ta; print_string \" \\n\"; *)\t\t\n\t\tprint_int (ha + ta);\n\t\tprint_string \"\\n\"\n end;;\n\nmain();;"}], "negative_code": [], "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"nl": {"description": "Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion: Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output \"YES\", otherwise \"NO\" (without quotes).The potion can be used infinite amount of times.", "input_spec": "The first line contains four integer numbers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively. The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.", "output_spec": "Print \"YES\" if it is possible for Captain to reach the treasure using the potion, otherwise print \"NO\" (without quotes).", "sample_inputs": ["0 0 0 6\n2 3", "1 1 3 6\n1 5"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example there exists such sequence of moves: — the first type of move — the third type of move "}, "positive_code": [{"source_code": "Scanf.scanf \"%d %d %d %d %d %d\" (fun x y tx ty cx cy -> print_string(\nlet mx,my=tx-x,ty-y in\nif mx mod cx=0 && my mod cy=0 && mx/cx land 1 = my/cy land 1 then \"YES\" else \"NO\"))"}], "negative_code": [{"source_code": "Scanf.scanf \"%d %d %d %d %d %d\" (fun x y tx ty cx cy -> print_string(\nlet mx=tx-x in let my=ty-y in\nif mx mod cx=0 && my mod cy=0 && mx/cx land 1 = my/cy land 1 then \"YES\" else \"NO\"))"}], "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"nl": {"description": "The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm: Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger. Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor). Moves from the $$$b$$$-th floor back to the $$$x$$$-th. The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor. ", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$) — the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\leq a_i \\leq 100$$$) — the number of people on each floor.", "output_spec": "In a single line, print the answer to the problem — the minimum number of electricity units.", "sample_inputs": ["3\n0 2 1", "2\n1 1"], "sample_outputs": ["16", "4"], "notes": "NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \\cdot 2 + 8 \\cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor."}, "positive_code": [{"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 let a = iia n in\n let res = ref max_i64 in\n rep 1L n (fun x ->\n let r = ref 0L in\n (* printf \"%Ld:\\n\" x; *)\n iteri (fun i v ->\n let floor = i64 i+1L in\n r += (floor-1L) * 2L * 2L * v;\n (* printf \" %d; %Ld = %Ld\\n\" i v !r; *)\n ) a;\n (* printf \" = %Ld: %Ld\\n\" x !r; *)\n res := min !res !r\n );\n printf \"%Ld\" @@ !res\n\n\n\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"nl": {"description": "Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.", "input_spec": "The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.", "output_spec": "Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». ", "sample_inputs": ["4 2"], "sample_outputs": ["1/2"], "notes": "NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points."}, "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet rec gcd a b =\n if b = 0 then\n a\n else\n gcd b (a mod b)\n\nlet () =\n let x = read_int 0 in\n let y = read_int 0 in\n let z = 7 - max x y in\n let d = gcd z 6 in\n Printf.printf \"%d/%d\\n\" (z/d) (6/d)\n"}], "negative_code": [], "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"nl": {"description": "Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.In the local council you were given an area map, where the granny's house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics: it starts and ends in the same place — the granny's house; the route goes along the forest paths only (these are the segments marked black in the picture); the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway); the route cannot cross itself; there shouldn't be any part of dense forest within the part marked out by this route; You should find the amount of such suitable oriented routes modulo 1000000009. The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.", "input_spec": "The input data contain the only even integer n (2 ≤ n ≤ 106).", "output_spec": "Output the only number — the amount of Peter's routes modulo 1000000009.", "sample_inputs": ["2", "4"], "sample_outputs": ["10", "74"], "notes": null}, "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\nlet flip f x y = f y x\n\nlet p = 1000000009L\n\nopen Int64\nlet ( ++ ) x y = add x y |> flip rem p\nlet ( -- ) x y = sub x y |> flip rem p\nlet ( ** ) x y = mul x y |> flip rem p\n\nlet () =\n let n = read_int 0 in\n let s = ref 2L in\n let lane = ref 1L in\n let lanes = ref 1L in\n for i = 1 to (n-2)/2 do\n s := !s ++ 4L ** !lanes;\n lane := 2L ** !lane ++ 3L;\n lanes := !lanes ** !lane\n done;\n (!s** !s++1L)**2L |> Printf.printf \"%Ld\\n\"\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\nlet flip f x y = f y x\n\nlet p = 1000000009L\n\nopen Int64\nlet ( ++ ) x y = add x y |> flip rem p\nlet ( -- ) x y = sub x y |> flip rem p\nlet ( ** ) x y = mul x y |> flip rem p\n\nlet () =\n let n = read_int 0 in\n let s = ref 2L in\n let lane = ref 1L in\n let lanes = ref 1L in\n for i = 1 to (n-2)/2 do\n s := !s ++ 4L ** !lane;\n lane := 2L ** !lane ++ 3L;\n lanes := !lanes ** !lane\n done;\n (!s** !s++1L)**2L |> Printf.printf \"%Ld\\n\"\n"}], "src_uid": "dbcb1077e7421554ba5d69b64d22c937"} {"nl": {"description": "One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.", "input_spec": "The only line contains n (1 ≤ n ≤ 25) — the required sum of points.", "output_spec": "Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.", "sample_inputs": ["12", "20", "10"], "sample_outputs": ["4", "15", "0"], "notes": "NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points."}, "positive_code": [{"source_code": "let n = read_int () - 10 in\nprint_int (if n = 10 then 15\nelse if n >= 1 && n <= 11 then 4\nelse 0)\n"}, {"source_code": "(* http://codeforces.com/contest/104/problem/A *)\n\nlet f n = \n if 0 <= n && n <= 10 then 0\n else if 11 <= n && n <= 19 then 4\n else if n = 20 then 15\n else if n = 21 then 4\n else 0;;\nPrintf.printf \"%d\\n\" (Scanf.scanf \"%d\" f);;\n\n\n"}], "negative_code": [{"source_code": "(* http://codeforces.com/contest/104/problem/A *)\n\nlet f n = \n if 0 <= n && n <= 10 then 0\n else if 11 <= n && n <= 19 then 4\n else if n = 20 then 15\n else if n = 21 then 1\n else 0;;\nPrintf.printf \"%d\\n\" (Scanf.scanf \"%d\" f);;\n"}], "src_uid": "5802f52caff6015f21b80872274ab16c"} {"nl": {"description": "Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.", "input_spec": "The only line contains an integer n (1 ≤ n ≤ 1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.", "output_spec": "Print on the single line \"YES\" if n is a nearly lucky number. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["40047", "7747774", "1000000000000000000"], "sample_outputs": ["NO", "YES", "NO"], "notes": "NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is \"NO\".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is \"YES\".In the third sample there are no lucky digits, so the answer is \"NO\"."}, "positive_code": [{"source_code": "let 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\nlet input () = Scanf.scanf \"%s\" (fun s -> (str_to_list s))\n\nlet is_lucky_numbers = function \n |'4' | '7'-> true\n |_ -> false\n\nlet count input = List.length(List.filter(is_lucky_numbers) input)\n\nlet solve input = \n if is_lucky_numbers(String.get (Pervasives.string_of_int(count input)) 0)\n then\n \"YES\"\n else\n \"NO\"\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ())) \n\n"}, {"source_code": "let n = read_line() in\nlet m = ref 0 in\nlet _ = String.iter (function\n\t| ('4'|'7') -> incr m\n\t| _ -> ()\n) n in\nprint_string (if !m = 4 || !m = 7 then \"YES\" else \"NO\");\n"}, {"source_code": "open Int64;;\nlet scan_int () = Scanf.scanf \" %d\" (fun x -> x)\nlet scan_ll () = Scanf.scanf \" %Ld\" (fun x -> x)\nlet pom = function (4 | 7) -> 1 | _ -> 0;;\n\nlet rec fart n =\n\tlet rec lucky x acc = match x with\n\t\t|0L -> acc \n\t\t|_ -> lucky (div x 10L) (acc + (pom(to_int(rem x 10L))))\n\tin\nlucky n 0;;\n\nlet n = scan_ll ()\nlet kek = fart n;;\n(*print_int kek;;*)\n\nlet s = match kek with\n\t|(4 | 7) -> \"YES\"\n\t|_ ->\"NO\"\n;;\n\nprint_string s;;\n\n"}, {"source_code": "open Int64;;\nlet scan_int () = Scanf.scanf \" %d\" (fun x -> x)\nlet scan_ll () = Scanf.scanf \" %Ld\" (fun x -> x)\nlet ten = of_int(10);;\nlet zero = of_int(0);;\nlet pom = function (4 | 7) -> 1 | _ -> 0;;\n\nlet rec fart n =\n\tlet rec lucky x acc =\n\t\tif x = zero then acc \n\t\telse lucky (div x ten) (acc + (pom(to_int(rem x ten))))\n\tin\nlucky n 0;;\n\nlet n = scan_ll ()\nlet kek = fart n;;\n(*print_int kek;;*)\n\nlet s = match kek with\n\t|(4 | 7) -> \"YES\"\n\t|_ ->\"NO\"\n;;\n\nprint_string s;;\n\n"}], "negative_code": [{"source_code": "let n = String.length (read_line()) in\nprint_string (if n = 4 || n = 7 then \"YES\" else \"NO\")\n"}], "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"nl": {"description": "You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.", "input_spec": "A single line contains three space-separated integers a, b, r (1 ≤ a, b, r ≤ 100) — the table sides and the plates' radius, correspondingly.", "output_spec": "If wins the player who moves first, print \"First\" (without the quotes). Otherwise print \"Second\" (without the quotes).", "sample_inputs": ["5 5 2", "6 7 4"], "sample_outputs": ["First", "Second"], "notes": "NoteIn the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses. In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. "}, "positive_code": [{"source_code": "let ni = fun _ -> Scanf.scanf \" %d\" (fun x -> x) in\nlet a = ni () in\nlet b = ni () in\nlet d = 2 * ni () in\nprint_string (if a >= d && b >= d then \"First\" else \"Second\");;\n"}, {"source_code": "let solve a b r =\n let diameter = 2 * r in\n if diameter <= a && diameter <= b then \"First\"\n else \"Second\"\n\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d %d %d\\n\" solve)\n \n\n"}, {"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 let permute_with lst p = L.map (Array.get (Array.of_list lst)) p\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 a = int ()\nlet b = int ()\nlet r = int ()\n\nlet () =\n Printf.printf \"%s\\n\"\n (if r*2 <= a && r*2 <= b then \"First\"\n else \"Second\")\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "let solve a b r =\n let diam = 2 * r in\n let plate_in_a_row len r =\n len/(2*diam-1) + (len-(len/(2*diam-1))*(2*diam-1))/diam\n in\n if ((plate_in_a_row a r) * (plate_in_a_row b r)) mod 2 == 0 then \"Second\"\n else \"First\"\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d %d %d\\n\" solve)\n \n\n"}, {"source_code": "let solve a b r =\n let diam = 2 * r in\n let vdiam = 4*r - 1 in\n let max_in_a_row n r =\n ((n/vdiam) + (n-(a/vdiam))/diam)\n in\n if ( (max_in_a_row a r) * (max_in_a_row b r) ) mod 2 == 0 then \"Second\"\n else \"First\"\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d %d %d\\n\" solve)\n \n\n"}, {"source_code": "let solve a b r =\n let diam = 2 * r in\n let plate_in_a_row len r =\n len/(2*diam-1) + (len-(len/(2*diam-1)))/diam\n in\n if ((plate_in_a_row a r) * (plate_in_a_row b r)) mod 2 == 0 then \"Second\"\n else \"First\"\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d %d %d\\n\" solve)\n \n\n"}, {"source_code": "let solve a b r =\n let diameter = 2 * r in\n if ((a/diameter) * (b/diameter)) mod 2 == 0 then \"Second\"\n else \"First\"\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d %d %d\\n\" solve)\n \n\n"}], "src_uid": "90b9ef939a13cf29715bc5bce26c9896"} {"nl": {"description": "Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.", "output_spec": "In the single line print \"yes\" (without the quotes), if the line has self-intersections. Otherwise, print \"no\" (without the quotes).", "sample_inputs": ["4\n0 10 5 15", "4\n0 15 5 10"], "sample_outputs": ["yes", "no"], "notes": "NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right."}, "positive_code": [{"source_code": "let (|>) x f = f x ;;\nlet (@@) f x = f x ;;\n\nlet ident x = x ;;\nlet ident2 x y = (x, y) ;;\nlet ident3 x y z = (x, y, z) ;;\nlet ident4 x y z w = (x, y, z, w) ;;\nlet ident5 x y z w v = (x, y, z, w, v) ;;\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 n = Scanf.scanf \"%d \" ident in\n let xs = fold_for 0 n ~init:[] ~f:(fun acc x ->\n Scanf.scanf \"%d \" ident :: acc) |> List.rev in\n let rec iter ps prev = function\n | [] -> print_endline \"no\"\n | cur :: xs ->\n let x, y = (min cur prev, max cur prev) in\n List.iter ps ~f:(fun (x, y) -> Printf.eprintf \"%d, %d\\n\" x y);\n prerr_endline \"ok\";\n if List.exists ps ~f:(fun (x', y') ->\n x < x' && x' < y && y < y' ||\n x' < x && x < y' && y' < y) then\n print_endline \"yes\"\n else iter ((x, y) :: ps) cur xs in\n match xs with\n | [] -> assert false\n | x :: xs -> iter [] x xs\n;;\n"}, {"source_code": "let (|>) x f = f x\nlet (<|) f x = f x\n\nlet rec loop n f acc = \n if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n\nlet rec make_pair l acc = \n match l with\n\t[] -> acc\n | [x] -> acc\n | x :: ((y :: ys) as xs) -> make_pair xs ((if x <= y then (x, y) else (y, x) ):: acc)\n\n\nlet n = next_int()\n\nlet a = loop n (fun _ -> next_int ()) []\nlet b = make_pair a []\n;;\n\n\nlet valid p = \n let intersect q = \n\tlet x1 = fst p in\n\tlet y1 = snd p in\n\tlet x2 = fst q in\n\tlet y2 = snd q in\n\tif x1 <= x2 then x2 > x1 && x2 < y1 && y2 > y1 \n\telse y2 > x1 && y2 < y1 in\n List.exists intersect b\n;;\n\nlet () = \n(* List.iter (fun (x, y) -> print_int x; print_string \" \"; print_int y;\n print_string \"\\n\") b; *)\nif List.exists valid b then print_string \"yes\" else print_string \"no\"\n"}], "negative_code": [{"source_code": "let (|>) x f = f x\nlet (<|) f x = f x\n\nlet rec loop n f acc = \n if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n\nlet rec make_pair l acc = \n match l with\n\t[] -> acc\n | [x] -> acc\n | x :: ((y :: ys) as xs) -> make_pair xs ((x, y) :: acc)\n\n\nlet n = next_int()\n\nlet a = loop n (fun _ -> next_int ()) []\nlet b = make_pair a []\n\nlet valid p = \n let intersect q = \n\tlet x1 = fst p in\n\tlet y1 = snd p in\n\tlet x2 = fst q in\n\tlet y2 = snd q in\n\tif x1 <= x2 then x2 < y1 && y2 > y1 \n\telse y2 > x1 && y2 < y1 in\n List.exists intersect b\n\nlet () = if List.exists valid b then print_string \"yes\" else print_string \"no\"\n"}, {"source_code": "let (|>) x f = f x\nlet (<|) f x = f x\n\nlet rec loop n f acc = \n if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n\nlet rec make_pair l acc = \n match l with\n\t[] -> acc\n | [x] -> acc\n | x :: ((y :: ys) as xs) -> make_pair xs ((if x <= y then (x, y) else (y, x) ):: acc)\n\n\nlet n = next_int()\n\nlet a = loop n (fun _ -> next_int ()) []\nlet b = make_pair a []\n;;\n\n\nlet valid p = \n let intersect q = \n\tlet x1 = fst p in\n\tlet y1 = snd p in\n\tlet x2 = fst q in\n\tlet y2 = snd q in\n\tif x1 <= x2 then x2 < y1 && y2 > y1 \n\telse y2 > x1 && y2 < y1 in\n List.exists intersect b\n;;\n\nlet () = if List.exists valid b then print_string \"yes\" else print_string \"no\"\n"}], "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"nl": {"description": "\"QAQ\" is a word to denote an expression of crying. Imagine \"Q\" as eyes with tears and \"A\" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of \"QAQ\" in the string (Diamond is so cute!). illustration by 猫屋 https://twitter.com/nekoyaliu Bort wants to know how many subsequences \"QAQ\" are in the string Diamond has given. Note that the letters \"QAQ\" don't have to be consecutive, but the order of letters should be exact.", "input_spec": "The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.", "output_spec": "Print a single integer — the number of subsequences \"QAQ\" in the string.", "sample_inputs": ["QAQAQYSYIOIWIN", "QAQQQZZYNOIWIN"], "sample_outputs": ["4", "3"], "notes": "NoteIn the first example there are 4 subsequences \"QAQ\": \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\"."}, "positive_code": [{"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 read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let s = read_string () in\n let n = String.length s in\n\n let to_left = Array.make n 0 in\n let to_right = Array.make n 0 in\n\n for i=1 to n-1 do\n to_left.(i) <- to_left.(i-1) + (if s.[i-1] = 'Q' then 1 else 0)\n done;\n\n for i=n-2 downto 0 do\n to_right.(i) <- to_right.(i+1) + (if s.[i+1] = 'Q' then 1 else 0)\n done;\n\n let answer = sum 0 (n-1) (\n fun i -> if s.[i] = 'A' then to_left.(i) * to_right.(i) else 0\n ) in\n\n printf \"%d\\n\" answer\n \n\n \n"}], "negative_code": [], "src_uid": "8aef4947322438664bd8610632fe0947"} {"nl": {"description": "Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.Your problem is to print the minimum possible length of the sequence of moves after the replacements.", "input_spec": "The first line of the input contains one integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains the sequence consisting of n characters U and R.", "output_spec": "Print the minimum possible length of the sequence of moves after all replacements are done.", "sample_inputs": ["5\nRUURU", "17\nUUURRRRRUUURURUUU"], "sample_outputs": ["3", "13"], "notes": "NoteIn the first test the shortened sequence of moves may be DUD (its length is 3).In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13)."}, "positive_code": [{"source_code": "\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet read_string () = Scanf.scanf \" %s\" (fun x -> x);;\n\nlet n = read_int();;\n\nlet s = read_string();;\n\nlet rec cut s = match (String.length s) with\n | 0 -> 0\n | 1 -> 1\n | _ ->\n if (String.get s 0 = String.get s 1) then 1 + cut(String.sub s 1 ((String.length s) - 1))\n else 1 + cut(String.sub s 2 ((String.length s) - 2));;\n\n\n\nPrintf.printf \"%d\\n\" (cut s);\n"}, {"source_code": "\nlet in_channel = stdin;;\n\nlet n = int_of_string (input_line in_channel);;\n\n\nlet s = input_line in_channel;;\n\nlet rec count a = match (String.length a) with\n| 0 -> 0\n| 1 -> 1\n| _ -> (\n\tif ((String.sub a 0 2) = \"RU\" || (String.sub a 0 2) = \"UR\") then\n\t\t1 + count (String.sub a 2 ((String.length a) - 2))\n\telse \n\t\t1 + count (String.sub a 1 ((String.length a) - 1))\n);;\n\nPrintf.printf \"%d\\n\" (count s);;\n\n\n"}], "negative_code": [{"source_code": "\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet read_string () = Scanf.scanf \" %s\" (fun x -> x);;\n\nlet s = read_string();;\n\nlet rec cut s = match (String.length s) with\n | 0 -> 0\n | 1 -> 1\n | _ ->\n if (String.get s 0 = String.get s 1) then 1 + cut(String.sub s 1 ((String.length s) - 1))\n else 1 + cut(String.sub s 2 ((String.length s) - 2));;\n\n\n\nPrintf.printf \"%d\\n\" (cut s);\n"}], "src_uid": "986ae418ce82435badadb0bd5588f45b"} {"nl": {"description": "Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m.The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max.", "input_spec": "The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.", "output_spec": "If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes).", "sample_inputs": ["2 1 1 2\n1", "3 1 1 3\n2", "2 1 1 3\n2"], "sample_outputs": ["Correct", "Correct", "Incorrect"], "notes": "NoteIn the first test sample one of the possible initial configurations of temperatures is [1, 2].In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3."}, "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and mi=Int64.(of_int(read_int())) and ma=Int64.(of_int(read_int()));;\nlet tab=Array.init m (fun i->Int64.(of_int(read_int())));;\nlet mini=ref tab.(0);;\nlet maxi=ref tab.(0);;\nfor i=0 to m-1 do\n if tab.(i)< !mini then mini:=tab.(i);\n if tab.(i)> !maxi then maxi:=tab.(i)\ndone;;\nif (!minima) then print_string \"Incorrect\"\nelse if n-m>=2 then print_string \"Correct\"\nelse if n-m=1 then\n begin\n if (!mini=mi)||(!maxi=ma)||(mi=ma)||(n<=1) then print_string \"Correct\" else print_string \"Incorrect\"\n end\nelse if ((!mini=mi)&&(!maxi=ma))||(n=0) then print_string \"Correct\" else print_string \"Incorrect\";;"}], "negative_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and mi=read_int() and ma=read_int();;\nlet tab=Array.init m (fun i->read_int());;\nlet mini=ref tab.(0);;\nlet maxi=ref tab.(0);;\nfor i=0 to m-1 do\n if tab.(i)< !mini then mini:=tab.(i);\n if tab.(i)> !maxi then maxi:=tab.(i)\ndone;;\nif n-m>=2 then print_string \"Correct\"\nelse if n-m=1 then\n begin\n if (!mini=mi)||(!maxi=ma)||(mi=ma)||(n<=1) then print_string \"Correct\" else print_string \"Incorrect\"\n end\nelse if ((!mini=mi)&&(!maxi=ma))||(n=0) then print_string \"Correct\" else print_string \"Incorrect\";;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and mi=Int64.(of_int(read_int())) and ma=Int64.(of_int(read_int()));;\nlet tab=Array.init m (fun i->Int64.(of_int(read_int())));;\nlet mini=ref tab.(0);;\nlet maxi=ref tab.(0);;\nfor i=0 to m-1 do\n if tab.(i)< !mini then mini:=tab.(i);\n if tab.(i)> !maxi then maxi:=tab.(i)\ndone;;\nif n-m>=2 then print_string \"Correct\"\nelse if n-m=1 then\n begin\n if (!mini=mi)||(!maxi=ma)||(mi=ma)||(n<=1) then print_string \"Correct\" else print_string \"Incorrect\"\n end\nelse if ((!mini=mi)&&(!maxi=ma))||(n=0) then print_string \"Correct\" else print_string \"Incorrect\";;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and mi=read_int() and ma=read_int();;\nlet tab=Array.init m (fun i->read_int());;\nlet mini=ref tab.(0);;\nlet maxi=ref tab.(0);;\nfor i=0 to m-1 do\n if tab.(i)< !mini then mini:=tab.(i);\n if tab.(i)> !maxi then maxi:=tab.(i)\ndone;;\nif n-m>=2 then print_string \"Correct\"\nelse if n-m=1 then\n begin\n if (!mini=mi)||(!maxi=ma) then print_string \"Correct\" else print_string \"Incorrect\"\n end\nelse if (!mini=mi)&&(!maxi=ma) then print_string \"Correct\" else print_string \"Incorrect\";;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and mi=read_int() and ma=read_int();;\nlet tab=Array.init m (fun i->read_int());;\nlet mini=ref tab.(0);;\nlet maxi=ref tab.(0);;\nfor i=0 to m-1 do\n if tab.(i)< !mini then mini:=tab.(i);\n if tab.(i)> !maxi then maxi:=tab.(i)\ndone;;\nif n-m>=2 then print_string \"Correct\"\nelse if n-m=1 then\n begin\n if (!mini=mi)||(!maxi=ma)||(mi=ma) then print_string \"Correct\" else print_string \"Incorrect\"\n end\nelse if (!mini=mi)&&(!maxi=ma) then print_string \"Correct\" else print_string \"Incorrect\";;"}], "src_uid": "99f9cdc85010bd89434f39b78f15b65e"} {"nl": {"description": "Little Elephant loves magic squares very much.A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.", "input_spec": "The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.", "output_spec": "Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.", "sample_inputs": ["0 1 1\n1 0 1\n1 1 0", "0 3 6\n5 0 5\n4 7 0"], "sample_outputs": ["1 1 1\n1 1 1\n1 1 1", "6 3 6\n5 5 5\n4 7 4"], "notes": null}, "positive_code": [{"source_code": "(* Codeforces 257B SlonMagSquare *)\n\nopen Filename;;\nopen String;;\n\n(* you can use either gr or rdln but not both *)\nlet use_input_txt = false;;\nlet fn = (Filename.dirname Filename.current_dir_name);;\nlet filename = Filename.concat \".\" \"input.txt\";;\nlet cin = if use_input_txt then Scanf.Scanning.open_in filename\n\telse Scanf.Scanning.stdin;;\n\nlet cout = open_out \"output.txt\";;\nlet gr () = Scanf.bscanf cin \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\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 debug = false;;\n\nlet mg = Array.make_matrix 3 3 0;;\n\nlet readmat () =\n\tbegin\n\t\tfor i = 0 to 2 do\n\t\t\tfor j = 0 to 2 do\n\t\t\t\tmg.(i).(j) <- gr()\n\t\t\tdone\n\t\tdone\n\tend;;\n\nlet solve() =\n\tlet cma = (mg.(0).(1) + mg.(0).(2) - mg.(2).(0) - mg.(2).(1)) in\n\tlet bma = mg.(0).(1) + mg.(0).(2) - mg.(1).(0) - mg.(1).(2) in\n\tlet cpa = mg.(2).(0) + mg.(0).(2) in\n\tlet c = (cpa + cma) / 2 in\n\tlet a = (cpa - cma) / 2 in\n\tlet b = a + bma in\n\tbegin\n\t\tmg.(0).(0) <- a;\n\t\tmg.(1).(1) <- b;\n\t\tmg.(2).(2) <- c;\n\tend;;\n\nlet printmat () =\n\tfor i = 0 to 2 do\n\t\tbegin\n\t\t\tfor j = 0 to 2 do\n\t\t\t\tbegin\n\t\t\t\t\tprint_int mg.(i).(j);\n\t\t\t\t\tprint_string \" \"\n\t\t\t\tend\n\t\t\tdone;\n\t\t\tprint_newline ()\n\t\tend\n\tdone;;\n\nlet main () =\n\tbegin\n\t\treadmat ();\n\t\tsolve();\n\t\tprintmat()\t\t\n\tend;;\n\nmain();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\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 () = \n let a = Array.make_matrix 3 3 0 in\n for i=0 to 2 do\n for j=0 to 2 do\n\ta.(i).(j) <- read_int()\n done\n done;\n\n let ismagic () =\n let s = sum 0 2 (fun i -> a.(i).(i)) in\n\tsum 0 2 (fun i -> a.(i).(2-i)) = s &&\n(*\tsum 0 2 (fun i -> a.(0).(i)) = s && \n\tsum 0 2 (fun i -> a.(1).(i)) = s &&\n\tsum 0 2 (fun i -> a.(2).(i)) = s && *)\n\tsum 0 2 (fun i -> a.(i).(0)) = s &&\n\tsum 0 2 (fun i -> a.(i).(1)) = s &&\n\tsum 0 2 (fun i -> a.(i).(2)) = s\n in\n\n let rec loop t = if t>100_000 then false else (\n a.(0).(0) <- t;\n let s = t + a.(0).(1) + a.(0).(2) in\n\ta.(1).(1) <- s - a.(1).(0) - a.(1).(2);\n\ta.(2).(2) <- s - a.(2).(0) - a.(2).(1);\n\tif ismagic () then true else loop (t+1)\n )\n in\n\n if loop 0 then (\n\tfor i=0 to 2 do\n\t for j=0 to 2 do\n\t Printf.printf \"%d \" a.(i).(j)\n\t done;\n\t print_newline()\n\tdone\n ) else (\n\tPrintf.printf \"impossible\\n\"\n )\n"}], "negative_code": [], "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"nl": {"description": "Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.", "input_spec": "The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.", "output_spec": "If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 1 2", "3 4 5", "4 1 1"], "sample_outputs": ["0 1 1", "1 3 2", "Impossible"], "notes": "NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond."}, "positive_code": [{"source_code": "let (a, b, c) = Scanf.scanf \"%d %d %d\" (fun a b c -> (a, b, c)) in\n (* iterate over number of bonds between a and b *)\n try\n for i = 0 to (min a b) do\n let (ba, bb, bc) = (i, b - i, a - i) in\n if bb < 0 || bc < 0 ||\n not (a = ba + bc && b = ba + bb && c = bb + bc) then ()\n else begin\n Printf.printf \"%d %d %d\\n\" ba bb bc ;\n raise Exit\n end\n done ;\n Printf.printf \"Impossible\\n\"\n with Exit -> () ;;\n"}], "negative_code": [], "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"nl": {"description": " Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.", "input_spec": "There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.", "output_spec": "Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.", "sample_inputs": ["^ >\n1", "< ^\n3", "^ v\n6"], "sample_outputs": ["cw", "ccw", "undefined"], "notes": null}, "positive_code": [{"source_code": "let id x = x and\n f = function\n '>' -> 0\n | '^' -> 90\n | '<' -> 180\n | 'v' -> 270 and \n g = function\n x when x < 0 -> 360 + x\n | x when x > 360 -> x - 360 \n | x -> x in \n\nlet a = f @@ Scanf.scanf \" %c\" id and\nb = f @@ Scanf.scanf \" %c\" id and\nn = (Scanf.scanf \" %d\" id) mod 4 in\n\nlet c = g (a-b) in\nprint_string (if c==180 || c == 0 then \"undefined\" else if c / 90 == n then \"cw\" else \"ccw\") \n "}], "negative_code": [{"source_code": "let id x = x and\n f = function\n '>' -> 0\n | '^' -> 90\n | '<' -> 180\n | 'v' -> 270 and \n g = function\n x when x < 0 -> 360 + x\n | x when x > 360 -> x - 360 \n | x -> x in \n\nlet a = f @@ Scanf.scanf \" %c\" id and\nb = f @@ Scanf.scanf \" %c\" id and\nn = (Scanf.scanf \" %d\" id) mod 4 in\n\nlet c = g (a-b) in\nprint_string (if c==180 then \"undefined\" else if c / 90 == n then \"cw\" else \"ccw\") \n "}], "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"nl": {"description": "Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word \"hello\". For example, if Vasya types the word \"ahhellllloou\", it will be considered that he said hello, and if he types \"hlelo\", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.", "input_spec": "The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.", "output_spec": "If Vasya managed to say hello, print \"YES\", otherwise print \"NO\".", "sample_inputs": ["ahhellllloou", "hlelo"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "let s = Scanf.scanf \"%s \" ( fun x -> x) |> String.lowercase\n\nlet h = \"hello\";;\nlet j = ref 0;;\nlet c = ref (String.get h !j);;\nlet flag = ref \"NO\";;\n\nexception Success;;\n try\nfor i = 0 to String.length s - 1 do\n let si = String.get s i in\n if(si == !c) then\n begin\n incr j;\n if (!j > 4) then raise Success;\n c := String.get h !j;\n end\ndone\n with Success -> flag := \"YES\";;\n\n print_endline !flag;;\n"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if i < String.length target\n then \n if n < String.length input\n then\n let char = String.get input n in\n if char = String.get target i\n then\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"NO\"\n else\n \"YES\"\n\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if n < String.length input\n then\n if i < String.length target\n then\n let char = String.get input n in\n if char = String.get target i\n then\n if i + 1 = String.length target\n then\n \"YES\"\n else\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"NO\"\n else\n \"NO\"\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let s = read_line () in\nlet a = try\n\tlet i = ref 0 in\n\tlet _ = String.iter (fun c ->\n\t\ti := String.index_from s (!i) c + 1\n\t) \"hello\" in \n\t\"YES\"\nwith _ -> \"NO\" in\nprint_string a;;\n"}, {"source_code": "open List;;\n\nlet chat = fun s -> \n let hello = ['h';'e';'l';'l';'o'] in\n\n let rec pom l i len =\n if i > len || (i = len && l != [] ) then \n print_string \"NO\"\n else\n match l with \n |[] -> print_string \"YES\"\n | hl::tl -> if s.[i] = hl then pom tl (i + 1) len\n else pom l (i + 1) len\n in pom hello 0 (String.length s)\n;;\n\nScanf.scanf \"%s\" chat;;\n\n"}], "negative_code": [{"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if n < String.length input\n then\n if i + 1 < String.length target\n then\n let char = String.get input n in\n if char = String.get target i\n then\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"YES\"\n else\n \"NO\"\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if n < String.length input\n then\n if i < String.length target\n then\n let char = String.get input n in\n if char = String.get target i\n then\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"YES\"\n else\n \"NO\"\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if n < String.length input\n then\n if i < String.length target\n then\n let char = String.get input n in\n if char = String.get target i\n then\n if i = String.length target\n then\n \"YES\"\n else\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"NO\"\n else\n \"NO\"\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let input () = Scanf.scanf \"%s\" (fun s -> s)\n\nlet rec traverse input target i n =\n if n < String.length input\n then\n if i = String.length target\n then\n \"YES\"\n else\n let char = String.get input n in\n if char = String.get target i\n then\n traverse input target (i + 1) (n + 1)\n else\n traverse input target i (n + 1)\n else\n \"NO\"\n\nlet solve input = traverse input \"hello\" 0 0\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let s = Scanf.scanf \"%s \" ( fun x -> x) |> String.lowercase\n\nlet h = \"hello\";;\nlet j = ref 0;;\nlet c = ref (String.get h !j);;\nlet flag = ref \"NO\";;\n\nexception Success;;\n try\nfor i = 0 to String.length s - 1 do\n let si = String.get s i in\n if(si == !c) then\n begin\n incr j;\n c := String.get h !j;\n if (!j>=4) then raise Success\n end\ndone\n with Success -> flag := \"YES\";;\n\n print_endline !flag;;\n"}], "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"nl": {"description": "Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure: if si = \"?\", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively); if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code; if the string contains letters from \"A\" to \"J\", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. The length of the safe code coincides with the length of the hint. For example, hint \"?JGJ9\" has such matching safe code variants: \"51919\", \"55959\", \"12329\", \"93539\" and so on, and has wrong variants such as: \"56669\", \"00111\", \"03539\" and \"13666\".After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show \"Beavers are on the trail\" on his favorite TV channel, or he should work for a sleepless night...", "input_spec": "The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): 1 ≤ |s| ≤ 5. The input limits for scoring 100 points are (subproblems A1+A2): 1 ≤ |s| ≤ 105. Here |s| means the length of string s.", "output_spec": "Print the number of codes that match the given hint.", "sample_inputs": ["AJ", "1?AA"], "sample_outputs": ["81", "100"], "notes": null}, "positive_code": [{"source_code": "open Big_int\n\nlet (+|) = add_big_int\nlet (-|) = sub_big_int\nlet ( *| ) = mult_big_int\nlet (/|) = div_big_int\nlet bmod = mod_big_int\nlet (=|) = eq_big_int\nlet (/=|) a b = not (a =| b)\nlet (>|) = gt_big_int\nlet (<|) = lt_big_int\nlet (>=|) = ge_big_int\nlet (<=|) = le_big_int\n\nlet n0 = zero_big_int\nlet n1 = unit_big_int\nlet n2 = big_int_of_int 2\nlet n9 = big_int_of_int 9\nlet n10 = big_int_of_int 10\n\nlet _ =\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 10 false in\n let cnt = ref 10 in\n let res = ref n1 in\n for i = 0 to n - 1 do\n let c = s.[i] in\n\tmatch c with\n\t | '0'..'9' -> ()\n\t | '?' ->\n\t if i = 0\n\t then res := !res *| n9\n\t else res := !res *| n10\n\t | 'A'..'J' ->\n\t let k = Char.code c - Char.code 'A' in\n\t\tif not a.(k) then (\n\t\t a.(k) <- true;\n\t\t if i = 0\n\t\t then res := !res *| n9\n\t\t else res := !res *| (big_int_of_int !cnt);\n\t\t decr cnt\n\t\t)\n\t | _ -> assert false\n done;\n Printf.printf \"%s\\n\" (string_of_big_int !res)\n\n"}, {"source_code": "open Big_int\n\nlet (+|) = add_big_int\nlet (-|) = sub_big_int\nlet ( *| ) = mult_big_int\nlet (/|) = div_big_int\nlet bmod = mod_big_int\nlet (=|) = eq_big_int\nlet (/=|) a b = not (a =| b)\nlet (>|) = gt_big_int\nlet (<|) = lt_big_int\nlet (>=|) = ge_big_int\nlet (<=|) = le_big_int\n\nlet n0 = zero_big_int\nlet n1 = unit_big_int\nlet n2 = big_int_of_int 2\nlet n9 = big_int_of_int 9\nlet n10 = big_int_of_int 10\n\nlet _ =\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 10 false in\n let b = Array.make 11 0 in\n let cnt = ref 10 in\n let res = ref n1 in\n for i = 0 to n - 1 do\n let c = s.[i] in\n\tmatch c with\n\t | '0'..'9' -> ()\n\t | '?' ->\n\t if i = 0\n\t then b.(9) <- b.(9) + 1\n\t else b.(10) <- b.(10) + 1\n\t | 'A'..'J' ->\n\t let k = Char.code c - Char.code 'A' in\n\t\tif not a.(k) then (\n\t\t a.(k) <- true;\n\t\t if i = 0\n\t\t then b.(9) <- b.(9) + 1\n\t\t else b.(!cnt) <- b.(!cnt) + 1;\n\t\t decr cnt\n\t\t)\n\t | _ -> assert false\n done;\n for i = 1 to 10 do\n res := !res *| power_int_positive_int i b.(i)\n done;\n Printf.printf \"%s\\n\" (string_of_big_int !res)\n\n"}], "negative_code": [], "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"} {"nl": {"description": "Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.In this problem you should implement the similar functionality.You are given a string which only consists of: uppercase and lowercase English letters, underscore symbols (they are used as separators), parentheses (both opening and closing). It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching \"opening-closing\" pair, and such pairs can't be nested.For example, the following string is valid: \"_Hello_Vasya(and_Petya)__bye_(and_OK)\".Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: \"Hello\", \"Vasya\", \"and\", \"Petya\", \"bye\", \"and\" and \"OK\". Write a program that finds: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses). ", "input_spec": "The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols. ", "output_spec": "Print two space-separated integers: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses). ", "sample_inputs": ["37\n_Hello_Vasya(and_Petya)__bye_(and_OK)", "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__", "27\n(LoooonG)__shOrt__(LoooonG)", "5\n(___)"], "sample_outputs": ["5 4", "2 6", "5 2", "0 0"], "notes": "NoteIn the first sample, the words \"Hello\", \"Vasya\" and \"bye\" are outside any of the parentheses, and the words \"and\", \"Petya\", \"and\" and \"OK\" are inside. Note, that the word \"and\" is given twice and you should count it twice in the answer."}, "positive_code": [{"source_code": "let 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 parse_sentence sentence length =\n let w_outside = ref [] in\n let w_inside = ref [] in\n let buffer = Buffer.create length in\n let in_flag = ref false in\n for i = 0 to length - 1 do\n let c = sentence.[i] in\n if c = '(' then\n begin\n in_flag := true;\n if Buffer.length buffer != 0 then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n end\n\n else if c = ')' then\n begin\n in_flag := false;\n if Buffer.length buffer != 0 then\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n\n else if c = '_' && Buffer.length buffer != 0 then\n begin\n if !in_flag = false then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n else\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n else if c = '_' then ()\n else if i = length - 1 then\n begin\n Buffer.add_char buffer c;\n w_outside := (Buffer.contents buffer)::!w_outside\n end\n else Buffer.add_char buffer c\n done;\n (!w_outside, !w_inside)\n\nlet () =\n let length = read_int () in\n let sentence = read_string () in\n let (w_outside, w_inside) = parse_sentence sentence length in\n let out_max_length = List.fold_left (fun acc ele ->\n max acc (String.length ele)) 0 w_outside in\n Printf.printf \"%d %d\" out_max_length (List.length w_inside)\n"}, {"source_code": "open Scanf\nopen Printf\nopen Char\n\nlet max a b = if a > b then a else b;;\n\nlet foo d = let a = lowercase d in if(a >= 'a' && a <= 'z') then 0 else 1;; \n\nlet () = \nlet n = scanf \" %d \" (fun x-> x) in\nlet s = scanf \" %s \" (fun x-> x) in\nlet rec calc i l typ len cnt = \nif i < n then match(s.[i]) with\n'(' -> calc (i + 1) 0 true (max len l) cnt\n| ')' -> calc (i + 1) 0 false len cnt\n| '_' -> calc (i + 1) 0 typ (if typ then len else (max len l)) cnt\n| _ -> calc (i + 1) (l + 1) typ len (if typ then cnt + foo s.[i - 1] else cnt) \nelse printf \"%d %d\\n\" (max len l) cnt in calc 0 0 false 0 0;;\n"}], "negative_code": [{"source_code": "let 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 parse_sentence sentence length =\n let w_outside = ref [] in\n let w_inside = ref [] in\n let buffer = Buffer.create length in\n let in_flag = ref false in\n let has_parentheses = ref false in\n for i = 0 to length - 1 do\n let c = sentence.[i] in\n if c = '(' then\n begin\n in_flag := true;\n has_parentheses := true;\n if Buffer.length buffer != 0 then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n end\n\n else if c = ')' then\n begin\n in_flag := false;\n if Buffer.length buffer != 0 then\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n\n else if c = '_' && Buffer.length buffer != 0 then\n begin\n if !in_flag = false then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n else\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n else if c = '_' then ()\n else if i = length - 1 && Buffer.length buffer != 0 then\n begin\n Buffer.add_char buffer c;\n w_outside := (Buffer.contents buffer)::!w_outside\n end\n else Buffer.add_char buffer c\n done;\n if !has_parentheses then (!w_outside, !w_inside) else ([], [])\n\nlet () =\n let length = read_int () in\n let sentence = read_string () in\n let (w_outside, w_inside) = parse_sentence sentence length in\n let out_max_length = List.fold_left (fun acc ele ->\n max acc (String.length ele)) 0 w_outside in\n Printf.printf \"%d %d\" out_max_length (List.length w_inside)\n"}, {"source_code": "let 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 parse_sentence sentence length =\n let w_outside = ref [] in\n let w_inside = ref [] in\n let buffer = Buffer.create length in\n let in_flag = ref false in\n for i = 0 to length - 1 do\n let c = sentence.[i] in\n if c = '(' then\n begin\n in_flag := true;\n if Buffer.length buffer != 0 then begin\n w_outside := (Buffer.contents buffer)::!w_outside;Buffer.clear buffer;\n end\n end\n else if c = ')' then\n begin\n in_flag := false;\n if Buffer.length buffer != 0 then begin\n w_inside := (Buffer.contents buffer)::!w_inside; Buffer.clear buffer;\n end\n end\n else if c = '_' && Buffer.length buffer != 0 then\n begin\n if !in_flag = false then begin\n w_outside := (Buffer.contents buffer)::!w_outside;Buffer.clear buffer;\n end\n else begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n else if c = '_' then ()\n else Buffer.add_char buffer c\n done;\n (!w_outside, !w_inside)\n\nlet () =\n let length = read_int () in\n let sentence = read_string () in\n let (w_outside, w_inside) = parse_sentence sentence length in\n let out_max_length = List.fold_left (fun acc ele ->\n max acc (String.length ele)) 0 w_outside in\n Printf.printf \"%d %d\" out_max_length (List.length w_inside)\n"}, {"source_code": "let 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 parse_sentence sentence length =\n let w_outside = ref [] in\n let w_inside = ref [] in\n let buffer = Buffer.create length in\n let in_flag = ref false in\n for i = 0 to length - 1 do\n let c = sentence.[i] in\n if c = '(' then\n begin\n in_flag := true;\n if Buffer.length buffer != 0 then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n end\n\n else if c = ')' then\n begin\n in_flag := false;\n if Buffer.length buffer != 0 then\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n\n else if c = '_' && Buffer.length buffer != 0 then\n begin\n if !in_flag = false then\n begin\n w_outside := (Buffer.contents buffer)::!w_outside;\n Buffer.clear buffer;\n end\n else\n begin\n w_inside := (Buffer.contents buffer)::!w_inside;\n Buffer.clear buffer;\n end\n end\n else if c = '_' then ()\n else if i = length - 1 && Buffer.length buffer != 0 then\n begin\n Buffer.add_char buffer c;\n w_outside := (Buffer.contents buffer)::!w_outside\n end\n else Buffer.add_char buffer c\n done;\n (!w_outside, !w_inside)\n\nlet () =\n let length = read_int () in\n let sentence = read_string () in\n let (w_outside, w_inside) = parse_sentence sentence length in\n let out_max_length = List.fold_left (fun acc ele ->\n max acc (String.length ele)) 0 w_outside in\n Printf.printf \"%d %d\" out_max_length (List.length w_inside)\n"}, {"source_code": "open Scanf\nopen Printf\nopen Char\n\nlet max a b = if a > b then a else b;;\n\nlet foo d = let a = lowercase d in if(a >= 'a' && a <= 'z') then 0 else 1;; \n\nlet () = \nlet n = scanf \" %d \" (fun x-> x) in\nlet s = scanf \" %s \" (fun x-> x) in\nlet rec calc i l typ len cnt = \nif i < n then match(s.[i]) with\n'(' -> calc (i + 1) 0 true (max len l) cnt\n| ')' -> calc (i + 1) 0 false len cnt\n| '_' -> calc (i + 1) 0 typ (if typ then len else (max len l)) cnt\n| _ -> calc (i + 1) (l + 1) typ len (if typ then cnt + foo s.[i - 1] else cnt) \nelse printf \"%d %d\\n\" len cnt in calc 0 0 false 0 0;;\n"}], "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"nl": {"description": "Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.", "input_spec": "The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).", "output_spec": "Print \"Yes\", if the desired configuration is possible, and \"No\" otherwise. You can print each letter in arbitrary case (upper or lower).", "sample_inputs": ["6 3", "4 2", "1000 1001"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first example, Imp has to apply the machine twice to original toys and then twice to copies."}, "positive_code": [{"source_code": "\nlet judge x y =\n let times_for_original = y - 1 in\n let copy_produced_by_copy = x - times_for_original in\n (times_for_original >= 0) &&\n (copy_produced_by_copy >= 0) &&\n (copy_produced_by_copy mod 2 == 0) &&\n (copy_produced_by_copy == 0 || times_for_original > 0)\n\nlet output_yn v =\n (match v with\n | true -> print_string \"Yes\"\n | false -> print_string \"No\");\n print_char '\\n'\n\nlet () =\n Scanf.scanf \"%u %u\" judge |> output_yn\n\n(* TODO: do test *)\n(* 1 0 *)\n(* 2 1 *)"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in if o = 0 then\n Printf.printf \"No\"\n else if o = 1\n then if c = 0 then\n Printf.printf \"Yes\"\n else\n Printf.printf \"No\"\n else if c - o >= -1 && (c - o + 1) mod 2 = 0 then\n Printf.printf \"Yes\"\n else\n Printf.printf \"No\"\n;;\n\nmain ();;"}, {"source_code": "(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)\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 grc () = Scanf.scanf \" %c\" (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);;\n\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet possible x y = \n\tif y <= 0 then false\n\telse if x > 0 && y==1 then false\n\telse if x < (y - 1) then false\n\telse if (x mod 2) == (y mod 2) then false\n\telse true;;\n\nlet main() =\n\tlet x = gr() in\n\tlet y = gr() in\n\tlet pos = possible x y in\n\tbegin\n\t\tprint_string (if pos then \"Yes\" else \"No\");\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}], "negative_code": [{"source_code": "\nlet judge x y =\n let times_for_original = y - 1 in\n let copy_produced_by_copy = x - times_for_original in\n (times_for_original >= 0) &&\n (copy_produced_by_copy >= 0) &&\n (copy_produced_by_copy mod 2 == 0)\n\nlet output_yn v =\n (match v with\n | true -> print_string \"Yes\"\n | false -> print_string \"No\");\n print_char '\\n'\n\nlet () =\n Scanf.scanf \"%u %u\" judge |> output_yn\n\n(* TODO: do test *)\n(* 1 0 *)"}, {"source_code": "\nlet judge x y =\n let times_for_original = y - 1 in\n let copy_produced_by_copy = x - times_for_original in\n (copy_produced_by_copy >= 0) && (copy_produced_by_copy mod 2 == 0)\n\nlet output_yn v =\n (match v with\n | true -> print_string \"Yes\"\n | false -> print_string \"No\");\n print_char '\\n'\n\nlet () =\n Scanf.scanf \"%u %u\" judge |> output_yn\n"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in let c1 = o - 1\n in let c2 = c - c1\n in let c2m = c2 mod 2\n in if c < 0 || o <= 0 || c - o < -1 || c2m = 1 then\n Printf.printf \"No\"\n else\n Printf.printf \"Yes\"\n;;\n\nmain ();;\n"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in if o = 0 then\n Printf.printf \"No\"\n else if o = 1\n then if c = 0 then\n Printf.printf \"Yes\"\n else\n Printf.printf \"No\"\n else if c - o >= -1 && c - o + 1 mod 2 = 0 then\n Printf.printf \"Yes\"\n else\n Printf.printf \"No\"\n;;\n\nmain ();;"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in let c1 = o - 1\n in let c2 = c - c1\n in let c2m = c2 mod 2\n in if c2m = 1 then\n Printf.printf \"No\"\n else\n Printf.printf \"Yes\"\n;;\n\nmain ();;\n"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in let c1 = o - 1\n in let c2 = c - c1\n in let c2m = c2 mod 2\n in if c < 0 || o <= 0 || c - o < -1 || c2m = 1 then\n Printf.printf \"No\"\n else\n Printf.printf \"Yes\"\n;;\n\nmain ();;\n"}, {"source_code": "let main () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let c = getNumber ()\n in let o = getNumber ()\n in let c1 = o - 1\n in let c2 = c - c1\n in let c2m = c2 mod 2\n in if c2 < 0 || o <= 0 || c - o < -1 || (c - o + 1) mod 2 = 1 then\n Printf.printf \"No\"\n else\n Printf.printf \"Yes\"\n;;\n\nmain ();;\n"}, {"source_code": "(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)\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 grc () = Scanf.scanf \" %c\" (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);;\n\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet possible x y = \n\tif x < (y - 1) then false\n\telse if (x mod 2) == (y mod 2) then false\n\telse true;;\n\nlet main() =\n\tlet x = gr() in\n\tlet y = gr() in\n\tlet pos = possible x y in\n\tbegin\n\t\tprint_string (if pos then \"Yes\" else \"No\");\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)\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 grc () = Scanf.scanf \" %c\" (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);;\n\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet possible x y = \n\tif y <= 0 then false\n\telse if x==2 && y==1 then false\n\telse if x < (y - 1) then false\n\telse if (x mod 2) == (y mod 2) then false\n\telse true;;\n\nlet main() =\n\tlet x = gr() in\n\tlet y = gr() in\n\tlet pos = possible x y in\n\tbegin\n\t\tprint_string (if pos then \"Yes\" else \"No\");\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "(* Codeforces 914 B Conan and Agasa play a Card Game - not done*)\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 grc () = Scanf.scanf \" %c\" (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);;\n\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet possible x y = \n\tif y <= 0 then false\n\telse if x < (y - 1) then false\n\telse if (x mod 2) == (y mod 2) then false\n\telse true;;\n\nlet main() =\n\tlet x = gr() in\n\tlet y = gr() in\n\tlet pos = possible x y in\n\tbegin\n\t\tprint_string (if pos then \"Yes\" else \"No\");\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}], "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"nl": {"description": "While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \\times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \\geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better). Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.", "input_spec": "The first and only input line contains integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$) — order of a rhombus whose numbers of cells should be computed.", "output_spec": "Print exactly one integer — the number of cells in a $$$n$$$-th order rhombus.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "5", "13"], "notes": "NoteImages of rhombus corresponding to the examples are given in the statement."}, "positive_code": [{"source_code": "let () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let n2 = n/2 in\n let res = ref 0 in\n for i = 0 to n-2 do\n res := !res + 2 * i + 1;\n done;\n Printf.printf \"%d\\n\" (!res * 2 + 2 * (n-1) + 1)\n;;\n"}], "negative_code": [], "src_uid": "758d342c1badde6d0b4db81285be780c"} {"nl": {"description": "Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.", "input_spec": "A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.", "output_spec": "In a single line print the number of times Manao has to push a button in the worst-case scenario.", "sample_inputs": ["2", "3"], "sample_outputs": ["3", "7"], "notes": "NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes."}, "positive_code": [{"source_code": "let ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\n\nlet input () = Scanf.scanf \"%Ld\" (fun n -> n)\n\nlet solve number = \n let rec loop i count correct = \n if i > one\n then\n let repress = (i - two) * correct in \n let temp_count = i + repress in \n loop (i - one) (count + temp_count) (correct + one)\n else\n count + one\n in loop number zero one\n\nlet print result = Printf.printf \"%Ld\\n\" result\nlet () = print (solve (input ())) "}, {"source_code": "let input () = Scanf.scanf \"%Ld\" (fun n -> n)\n\nlet solve number = \n let rec loop i count correct = \n if i > Int64.one\n then\n let repress = Int64.mul (Int64.sub i (Int64.of_int 2)) correct in \n let temp_count = Int64.add i repress in \n loop (Int64.pred i) (Int64.add count temp_count) (Int64.succ correct)\n else\n Int64.succ count\n in loop number Int64.zero Int64.one\n\nlet print result = Printf.printf \"%Ld\\n\" result\nlet () = print (solve (input ())) "}, {"source_code": "let ( +: ) = Int64.add in\nlet ( -: ) = Int64.sub in\nlet ( *: ) = Int64.mul in\nlet n = read_line () |> int_of_string |> Int64.of_int in\nlet rec count n i a = \n match n with\n | 1L -> 1L\n | 2L -> 3L\n | e -> if n-:i =2L then a+:n+:1L else count n (i+:1L) (a+:(i+:1L)*:(n-:i)-:i) in\ncount n 1L n |> Int64.to_string |> print_string\n"}], "negative_code": [{"source_code": "let input () = Scanf.scanf \"%d\" (fun n -> n)\n\nlet solve number = \n let rec loop i count correct = \n if i > 1\n then\n let repress = (i - 2) * correct in \n loop (i - 1) (count + i + repress) (correct + 1)\n else\n count + 1\n in loop number 0 1\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ())) "}, {"source_code": "let n = read_line () |> int_of_string in\nlet rec count n a = if n <= 1 then a else count (n-2) (a+n*(n-1)) in\ncount n (if n==2 || n mod 2 ==1 then 1 else 0) |> print_int\n"}, {"source_code": "let n = read_line () |> int_of_string in\nlet rec count n a = if n <= 1 then a else count (n-2) (a+n*(n-1)) in\nprint_int (if n==2 then 3 else count n 0)\n"}, {"source_code": "let n = read_line () |> int_of_string in\nlet rec count n i a = \n match n with\n | 1 -> 1\n | 2 -> 3\n | e -> if n-i=2 then a+n+1 else count n (i+1) (a+(i+1)*(n-i)-i) in\ncount n 1 n |> print_int\n"}, {"source_code": "let n = read_line () |> int_of_string in\nlet count = ref 0 in\nbegin\nfor i = 1 to n do\n count := !count + (i+1)*(n-i)\ndone;\nprint_int (if n == 2 then 3 else !count)\nend\n"}], "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"nl": {"description": "Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya was delivered a string s, containing only digits. He needs to find a string that represents a lucky number without leading zeroes, is not empty, is contained in s as a substring the maximum number of times.Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.", "input_spec": "The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.", "output_spec": "In the only line print the answer to Petya's problem. If the sought string does not exist, print \"-1\" (without quotes).", "sample_inputs": ["047", "16", "472747"], "sample_outputs": ["4", "-1", "7"], "notes": "NoteThe lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.In the first sample three conditions are fulfilled for strings \"4\", \"7\" and \"47\". The lexicographically minimum one is \"4\".In the second sample s has no substrings which are lucky numbers.In the third sample the three conditions are only fulfilled for string \"7\"."}, "positive_code": [{"source_code": "let m4, m7 = ref 0, ref 0 in\ntry while true do\n\tlet c = input_char stdin in\n\tif c = '4' then incr m4 else if c = '7' then incr m7\ndone with _ -> print_string (if !m4 = 0 && !m7 = 0 then \"-1\"\nelse if !m4 >= !m7 then \"4\" else \"7\");;\n"}], "negative_code": [{"source_code": "let m4, m7 = ref 0, ref 0 in\ntry while true do\n\tlet c = input_char stdin in\n\tif c = '4' then incr m4 else if c = '7' then incr m7\ndone with _ -> print_string (if !m4 = 0 && !m7 = 0 then \"-1\"\nelse if !m4 > !m7 then \"4\" else \"7\");;\n"}], "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"nl": {"description": "Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3 third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: any shelf cannot contain both cups and medals at the same time; no shelf can contain more than five cups; no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.", "input_spec": "The first line contains integers a1, a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1, b2 and b3 (0 ≤ b1, b2, b3 ≤ 100). The third line contains integer n (1 ≤ n ≤ 100). The numbers in the lines are separated by single spaces.", "output_spec": "Print \"YES\" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["1 1 1\n1 1 1\n4", "1 1 3\n2 3 4\n2", "1 0 0\n1 0 0\n1"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet sum () = Scanf.scanf \"%d %d %d \" (fun n m l -> n + m + l)\nlet print result = Printf.printf \"%s\\n\" result\n\nlet div_rounding_up = (fun x y ->\n x / y + (match x mod y with\n | 0 -> 0\n | _ -> 1))\n\nlet input () = \n let goblets = sum () in\n let medals = sum () in\n let shelves = read () in\n (goblets, medals, shelves)\n\nlet solve (goblets, medals, shelves) = \n let goblet_shelves = div_rounding_up goblets 5 in\n let medal_shelves = div_rounding_up medals 10 in\n let shelves_needed = goblet_shelves + medal_shelves in\n if shelves_needed <= shelves\n then\n \"YES\"\n else\n \"NO\"\n\nlet () = print (solve (input ()))"}, {"source_code": "\nlet ( |> ) v f = f v\nlet ( @@ ) f x = f x\nlet input_to_list ic =\n let buf = Buffer.create 0 in\n let rec aux acc =\n match input_char ic with\n | ' ' -> let v = int_of_string (Buffer.contents buf) in\n Buffer.clear buf; aux (v::acc)\n | '\\n' -> let v = int_of_string (Buffer.contents buf) in\n Buffer.clear buf; List.rev (v::acc)\n | c -> Buffer.add_char buf c; aux acc\n in aux []\n\nlet read_input () =\n let cups = input_to_list stdin |> List.fold_left (fun sum x -> sum + x) 0 in\n let medals = input_to_list stdin |> List.fold_left (fun sum x -> sum + x) 0 in\n let shelves = int_of_string (input_line stdin) in\n (cups, medals, shelves)\n\nlet check_ok (cups, medals, shelves) =\n let shelves_for_cups = cups / 5 + (if cups mod 5 > 0 then 1 else 0)\n in let shelves_for_medals = medals / 10 + (if medals mod 10 > 0 then 1 else 0)\n in shelves_for_cups + shelves_for_medals <= shelves\n\nlet () =\n print_endline (if (check_ok (read_input ())) then \"YES\" else \"NO\")\n"}], "negative_code": [{"source_code": "\nlet input_to_list ic =\n let buf = Buffer.create 0 in\n let rec aux acc =\n match input_char ic with\n | ' ' -> let v = int_of_string (Buffer.contents buf) in\n Buffer.clear buf; aux (v::acc)\n | '\\n' -> let v = int_of_string (Buffer.contents buf) in\n Buffer.clear buf; List.rev (v::acc)\n | c -> Buffer.add_char buf c; aux acc\n in aux []\n\nlet read_input () =\n let cups = input_to_list stdin in\n let medals = input_to_list stdin in\n let shelves = int_of_string (input_line stdin) in\n (cups, medals, shelves)\n\nlet check_ok (cups, medals, shelves) =\n let shelves_for_cups =\n (List.length cups) / 5 + (if List.length cups mod 5 > 0 then 1 else 0)\n in let shelves_for_medals =\n (List.length medals) / 10 + (if List.length medals mod 10 > 0 then 1 else 0)\n in shelves_for_cups + shelves_for_medals <= shelves\n\nlet () =\n print_endline (if (check_ok (read_input ())) then \"YES\" else \"NO\")\n"}], "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"nl": {"description": "You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.Write the program which finds the number of points in the intersection of two given sets.", "input_spec": "The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive.", "output_spec": "Print the number of points in the intersection or -1 if there are infinite number of points.", "sample_inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0"], "sample_outputs": ["-1", "1"], "notes": null}, "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet () =\n let a = read_int 0 in let b = read_int 0 in let c = read_int 0 in\n let u = read_int 0 in let v = read_int 0 in let w = read_int 0 in\n Printf.printf \"%d\\n\" (if a*v <> b*u then\n 1\n else if b*w <> c*v || a*w <> c*u || (a = 0 && b = 0 && c <> 0) || (u = 0 && v = 0 && w <> 0) then\n 0\n else\n -1)\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet () =\n let a = read_int 0 in let b = read_int 0 in let c = read_int 0 in\n let u = read_int 0 in let v = read_int 0 in let w = read_int 0 in\n Printf.printf \"%d\\n\" (if a*v <> b*u then\n 1\n else if b*w <> c*v || a*w <> c*u then\n 0\n else\n -1)\n"}], "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"nl": {"description": "Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like \"Special Offer! Super price 999 bourles!\". So Polycarpus decided to lower the price a little if it leads to the desired effect.Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.Note, Polycarpus counts only the trailing nines in a price.", "input_spec": "The first line contains two integers p and d (1 ≤ p ≤ 1018; 0 ≤ d < p) — the initial price of scissors and the maximum possible price reduction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.", "output_spec": "Print the required price — the maximum price that ends with the largest number of nines and that is less than p by no more than d. The required number shouldn't have leading zeroes.", "sample_inputs": ["1029 102", "27191 17"], "sample_outputs": ["999", "27189"], "notes": null}, "positive_code": [{"source_code": "open Scanf;;\nopen Printf;;\nopen Str;;\n\nlet split_by_space = split (regexp \" +\")\n\nlet rec head n ls =\n if n < 0 then invalid_arg \"head : passed negative integer\"\n else \n match (n, ls) with\n (0, _) -> []\n | (n, []) -> failwith \"head : list is too short\"\n | (n, x::xs) -> x :: (head (n - 1) xs)\n\nlet rec tail n ls =\n if n < 0 then invalid_arg \"tail : passed negative integer\"\n else\n match (n, ls) with\n (0, ls) -> ls\n | (n, []) -> failwith \"tail : list is too short\"\n | (n, x::xs) -> tail (n - 1) xs\n\nmodule UF = struct\n type t = int array\n\n let make n = Array.make n (-1)\n\n let rec root x uf =\n if uf.(x) < 0 then x \n else (uf.(x) <- root uf.(x) uf; uf.(x))\n\n let union_set x y uf =\n let x = root x uf and\n y = root y uf in\n begin\n if x != y then \n let x, y = if uf.(y) < uf.(x) then y, x else x, y in\n begin\n uf.(x) <- uf.(x) + uf.(y);\n uf.(y) <- x\n end\n end;\n x != y\n\n let find_set x y uf = root x uf = root y uf\n\n let size x uf = - uf.(x)\nend\n\nlet (+%) = Int64.add\nlet (-%) = Int64.sub\nlet ( *% ) = Int64.mul\nlet (/%) = Int64.div\nlet (mod) = Int64.rem\nlet (>%) x y = Int64.compare x y > 0\nlet (<%) x y = Int64.compare x y < 0\nlet input () = scanf \"%Ld %Ld \" (fun x y -> (x, y))\n\nlet max_with_9 n d =\n let r = n mod d in\n if r = (d -% 1L) then n\n else n -% r -% 1L\n\nlet solve (p, d) = \n let rec loop n mx =\n let res = max_with_9 p n in\n if p -% res >% d then mx \n else loop (n *% 10L) res in\n let mx = loop 10L (-1L) in\n if mx <% 0L then p else mx\n\nlet () =\n let inp = input () in\n let res = solve inp in\n printf \"%Ld\\n\" res\n"}], "negative_code": [], "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"}