{"source_code": "\nopen Num\n\nlet ni = num_of_int\n\nlet solve l =\n let update (total_fall, left_fall, left_pos, left_high) (pos, high) =\n if left_fall\n then\n begin\n (* Printf.printf\n \"true: pos - left_pos = %d, high = %d\\n\"\n (pos - left_pos)\n high; *)\n if ni pos -/ ni left_pos >/ ni high\n then (total_fall + 1, true, pos, high)\n else (total_fall, false, pos, high)\n end\n else\n begin\n (* Printf.printf\n \"false: pos - left_pos = %d, high = %d, left_high = %d\\n\"\n (pos - left_pos)\n high\n left_high; *)\n\n if ni pos -/ ni left_pos >/ ni left_high +/ ni high\n then (total_fall + 2, true, pos, high)\n\n else if ni pos -/ ni left_pos >/ ni left_high\n then (total_fall + 1, false, pos, high)\n\n else if ni pos -/ ni left_pos >/ ni high\n then (total_fall + 1, true, pos, high)\n else (total_fall, false, pos, high)\n end\n in \n let (ans, last, _, _) = List.fold_left update (0, true, -1000000001, 0) l in\n (* Printf.printf \"last: %b\\n\" last; *)\n if last then ans\n else ans + 1\n\nlet _ =\n let n = read_int () in\n\n let rec read_pairs acc = function\n | 0 -> List.rev acc\n | n ->\n let pair =\n begin\n match Str.split (Str.regexp \" \") (read_line ()) with\n | x :: y :: [] -> int_of_string x, int_of_string y\n | _ -> failwith \"mulformed input\"\n end\n in\n read_pairs (pair :: acc) (n - 1)\n in\n\n let ans = solve (read_pairs [] n) in\n print_endline (string_of_int ans)\n", "positive_code": [{"source_code": "let rec f lim = function\n\t|(a,b)::(c,d)::q -> if a - b > lim\n\t\t\t\tthen 1 + f a ((c,d)::q)\n\t\t\t\telse if c - a > b\n\t\t\t\t\tthen 1+f (a+b) ((c,d)::q)\n\t\t\t\t\telse f a ((c,d)::q)\n\t| _\t\t -> 1\n\nlet _ =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d %d\" (fun i j -> l := (i,j)::!l);\n\tdone;\n\tPrintf.printf \"%d\" (f min_int (List.rev !l))\n"}], "negative_code": [{"source_code": "\nlet solve l =\n let update (total_fall, left_fall, left_pos, left_high) (pos, high) =\n if left_fall\n then\n begin\n (* Printf.printf \"true: pos - left_pos = %d, high = %d\\n\" (pos - left_pos) high; *)\n if pos - left_pos > high then (total_fall + 1, true, pos, high)\n else (total_fall, false, pos, high)\n end\n else\n begin\n (* Printf.printf \"false: pos - left_pos = %d, high = %d, left_high = %d\\n\" (pos - left_pos) high left_high; *)\n if pos - left_pos > left_high + high then (total_fall + 2, true, pos, high)\n else if pos - left_pos > left_high then (total_fall + 1, false, pos, high)\n else if pos - left_pos > high then (total_fall + 1, true, pos, high)\n else (total_fall, false, pos, high)\n end\n in \n let (ans, last, _, _) = List.fold_left update (0, true, -1000000001, 0) l in\n (* Printf.printf \"last: %b\\n\" last; *)\n if last then ans\n else ans + 1\n\nlet _ =\n let n = read_int () in\n\n let rec read_pairs acc = function\n | 0 -> List.rev acc\n | n ->\n let pair =\n begin\n match Str.split (Str.regexp \" \") (read_line ()) with\n | x :: y :: [] -> int_of_string x, int_of_string y\n | _ -> failwith \"mulformed input\"\n end\n in\n read_pairs (pair :: acc) (n - 1)\n in\n\n let ans = solve (read_pairs [] n) in\n print_endline (string_of_int ans)\n"}], "src_uid": "a850dd88a67a6295823e70e2c5c857c9"} {"source_code": "let read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet rec read_ints n =\n match n with\n | 0 -> []\n | x -> read_int () :: (read_ints (n-1))\n\n(* let read_ints () =\n * let line = read_line () in\n * let ints = Str.split (Str.regexp \" *\") line in\n * List.map int_of_string ints *)\n\nlet rec print_list = function \n [] -> ()\n | e::l -> print_int e ; print_string \" \" ; print_list l\n\n\n\nlet solve () =\n let n = read_int () in\n let x = read_int () in\n let k = int_of_float\n (ceil ((float_of_int (x + n - 2)) /. (float_of_int x))) in\n print_int (if n <= 2 then 1 else k);\n print_endline \"\"\n(**)\n \nlet () =\n let x = read_int () in\n let rec loop n =\n match n with\n | 0 -> ()\n | x -> solve (); loop (n-1) in\n loop x\n", "positive_code": [{"source_code": "let rec case t =\n if t > 0 then\n let solve n x = \n if n <= 2 then 1 \n else let rec calc acc n x = \n if n <= x then acc + 1 else calc (acc + 1) (n - x) x\n in calc 1 (n - 2) x\n in Scanf.scanf \"%i %i\\n\" (fun n x -> Printf.printf \"%d\\n\" (solve n x); case (t - 1))\nin Scanf.scanf \"%d\\n\" (fun t -> case t)"}], "negative_code": [{"source_code": "let read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet rec read_ints n =\n match n with\n | 0 -> []\n | x -> read_int () :: (read_ints (n-1))\n\n(* let read_ints () =\n * let line = read_line () in\n * let ints = Str.split (Str.regexp \" *\") line in\n * List.map int_of_string ints *)\n\nlet rec print_list = function \n [] -> ()\n | e::l -> print_int e ; print_string \" \" ; print_list l\n\n\n\nlet solve () =\n let n = float_of_int (read_int ()) in\n let x = float_of_int (read_int ()) in\n let k = int_of_float (ceil (1.0 +. (n -. 2.0) /. x)) in\n print_int k;\n print_endline \"\"\n(**)\n \nlet () =\n let x = read_int () in\n let rec loop n =\n match n with\n | 0 -> ()\n | x -> solve (); loop (n-1) in\n loop x\n"}], "src_uid": "8b50a0eb2e1c425455b132683d3e6047"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let q = read_int() in\n let arr = Array.init n\n (fun _ -> Array.make 2 false)\n in\n let sum = ref 0 in\n for i=0 to q-1 do\n let r = read_int() - 1 in\n let c = read_int() - 1 in\n let r3 = r lxor 1 in\n let count = [-1; 0; 1]\n |> List.map (fun (x: int) -> (r3, c + x))\n |> List.filter (fun (x: int * int) -> 0 <= (snd x) && (snd x) < n)\n |> List.filter (fun (x: int * int) -> arr.(snd x).(r3))\n |> List.length in\n if arr.(c).(r) then (\n arr.(c).(r) <- false;\n sum := !sum - count\n ) else (\n arr.(c).(r) <- true;\n sum := !sum + count\n );\n printf (if !sum > 0 then \"No\\n\" else \"Yes\\n\");\n done;\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let q = read_int() in\n let arr = Array.init n\n (fun _ -> Array.make 2 false)\n in\n let sum = ref 0 in\n for i=0 to q-1 do\n let r = read_int() in\n let c = read_int() in\n let r3 = r lxor 3 in\n let count = [-1; 0; 1]\n |> List.map (fun (x: int) -> (r3, c + x))\n |> List.filter (fun (x: int * int) -> 1 <= (snd x) && (snd x) <= n)\n |> List.filter (fun (x: int * int) -> arr.((snd x) - 1).(r3 - 1))\n |> List.length in\n if arr.(c - 1).(r - 1) then (\n arr.(c - 1).(r - 1) <- false;\n sum := !sum - count\n ) else (\n arr.(c - 1).(r - 1) <- true;\n sum := !sum + count\n );\n printf (if !sum > 0 then \"No\\n\" else \"Yes\\n\");\n done;\n\n"}], "negative_code": [], "src_uid": "af036416721694d1843368988ca78e8e"} {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc nums =\r\n if n = len then nums @ [Int64.of_string acc]\r\n else if str.[n] = ' ' then split str len (n + 1) \"\" (nums @ [Int64.of_string acc])\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n]) nums\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\" []\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t ->\r\n let o = Int64.div (Int64.add prev h) h in\r\n add t\r\n (Int64.mul h o)\r\n (Int64.add moves o)\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t ->\r\n let o = Int64.abs (Int64.div (Int64.sub prev h) h) in\r\n sub t\r\n (Int64.mul (Int64.neg h) o)\r\n (Int64.add moves o)\r\n\r\nlet rec attempt lst rev ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (min ans (Int64.add (sub rev 0L 0L) (add t 0L 0L)))\r\n\r\nlet ans = attempt nums [] Int64.max_int;;\r\n\r\nPrintf.printf \"%Ld\\n\" ans", "positive_code": [{"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc nums =\r\n if n = len then nums @ [Int64.of_string acc]\r\n else if str.[n] = ' ' then split str len (n + 1) \"\" (nums @ [Int64.of_string acc])\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n]) nums\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\" []\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t ->\r\n let o = Int64.div (Int64.add prev h) h in\r\n add t\r\n (Int64.mul h o)\r\n (Int64.add moves o)\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t ->\r\n let o = Int64.abs (Int64.div (Int64.sub prev h) h) in\r\n sub t\r\n (Int64.mul (Int64.neg h) o)\r\n (Int64.add moves o)\r\n\r\nlet rec attempt lst rev ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (min ans (Int64.add (sub rev 0L 0L) (add t 0L 0L)))\r\n\r\nlet ans = attempt nums [] Int64.max_int;;\r\n\r\nPrintf.printf \"%Ld\\n\" ans "}], "negative_code": [{"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * ((prev + h) / h)) (moves + ((prev + h) / h))\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t ->\r\n if abs (prev - h) < 0 then -1\r\n else sub t (-h * (abs (prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst rev ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (min ans (sub rev 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums [] max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}, {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * ((prev + h) / h)) (moves + ((prev + h) / h))\r\n\r\nlet rec sub lst prev moves = \r\n match lst with\r\n | [] -> moves\r\n | h :: t -> sub t (-h * (abs (prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst rev i ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (i + 1) (min ans (sub rev 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums [] 0 max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}, {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * (abs (prev + h) / h)) (moves + (abs (prev + h) / h))\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> sub t (-h * (abs (prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst rev i ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (i + 1) (min ans (sub rev 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums [] 0 max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}, {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * ((prev + h) / h)) (moves + ((prev + h) / h))\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> sub t (-h * (abs (prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst rev i ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (i + 1) (min ans (sub rev 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums [] 0 max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}, {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec get_rev lst i =\r\n match lst with\r\n | [] -> []\r\n | h :: t -> if i = 0 then [] else get_rev t (i - 1) @ [ h ]\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * abs ((prev + h) / h)) (moves + ((prev + h) / h))\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> sub t (-h * abs ((prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst rev i ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t -> attempt t (h :: rev) (i + 1) (min ans (sub rev 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums [] 0 max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}, {"source_code": "let _ = read_line ()\r\nlet nums_str = read_line ()\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet nums = split nums_str (String.length nums_str) 0 \"\"\r\n\r\nlet rec loop lst =\r\n match lst with\r\n | [] -> print_newline ()\r\n | h :: t ->\r\n print_string (string_of_int h ^ \" \");\r\n loop t\r\n\r\nlet () = loop nums\r\n\r\nlet rec get_rev lst i =\r\n match lst with\r\n | [] -> []\r\n | h :: t -> if i = 0 then [] else get_rev t (i - 1) @ [ h ]\r\n\r\nlet rec add lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> add t (h * abs ((prev + h) / h)) (moves + ((prev + h) / h))\r\n\r\nlet rec sub lst prev moves =\r\n match lst with\r\n | [] -> moves\r\n | h :: t -> sub t (-h * abs ((prev - h) / h)) (moves + (abs (prev - h) / h))\r\n\r\nlet rec attempt lst i len ans =\r\n match lst with\r\n | [] -> ans\r\n | h :: t ->\r\n attempt t (i + 1) len (min ans (sub (get_rev nums i) 0 0 + add t 0 0))\r\n\r\nlet ans = attempt nums 0 (List.length nums) max_int;;\r\n\r\nPrintf.printf \"%d\\n\" ans"}], "src_uid": "da2fb0ea61808905a133021223f6148d"} {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\ntype node = {key: int; child: node; sibling: node}\n\nlet rec nil = {key = min_int; child = nil; sibling = nil}\nlet is_nil a = a.key = min_int\n\nlet merge a b =\n if a.key > b.key then\n {a with child = {b with sibling = a.child}}\n else\n {b with child = {a with sibling = b.child}}\n\nlet merge_list x =\n let rec go acc x =\n if is_nil x then\n acc\n else\n if is_nil x.sibling then\n x::acc\n else\n go (merge x x.sibling::acc) x.sibling.sibling\n in\n match go [] x with\n | [] -> nil\n | u::us -> List.fold_left (fun u v -> merge u v) u us\n\nlet pop x = merge_list x.child\n\nlet singleton k = {key = k; child = nil; sibling = nil}\n\nlet print x =\n let rec go d x =\n if not (is_nil x) then (\n go (d+1) x.sibling;\n for i = 1 to d do print_string \" \" done;\n Printf.printf \"%d\\n\" x.key;\n go (d+1) x.child;\n )\n in go 0 x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let rec go st i =\n if i >= n then\n st\n else\n let rec f = function\n | (y,yi)::(x,xi)::xs when x.key > y.key ->\n let z = merge x y in\n let z = if (xi-(if xs=[] then -1 else (List.hd xs |> snd))) land 1 <> 0 &&\n (yi-xi) land 1 <> 0 then pop z else z in\n f ((z,yi)::xs)\n | st -> st\n in\n go ((singleton a.(i),i) :: st |> f) (i+1)\n in\n\n go [] 0\n |> List.rev\n |> List.fold_left (fun (ans,l) (x,xi) ->\n let rec go ans i =\n if i > xi then\n ans\n else\n let open Int64 in\n go (abs (sub (of_int a.(i)) (of_int x.key)) |> add ans) (i+1)\n in\n go ans (l+1), xi\n ) (0L,-1)\n |> fst |> Printf.printf \"%Ld\\n\"", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\ntype node = {key: int; child: node; sibling: node}\n\nlet rec nil = {key = min_int; child = nil; sibling = nil}\nlet is_nil a = a.key = min_int\n\nlet merge a b =\n if a.key > b.key then\n {a with child = {b with sibling = a.child}}\n else\n {b with child = {a with sibling = b.child}}\n\nlet merge_list x =\n let rec go acc x =\n if is_nil x then\n acc\n else\n let y = {x with sibling = nil} in\n if is_nil x.sibling then\n y::acc\n else\n let z = {x.sibling with sibling = nil} in\n go (merge y z::acc) x.sibling.sibling\n in\n match go [] x with\n | [] -> nil\n | u::us -> List.fold_left (fun u v -> merge u v) u us\n\nlet pop x = merge_list x.child\n\nlet singleton k = {key = k; child = nil; sibling = nil}\n\nlet push x k = merge x {key = k; child = nil; sibling = nil}\n\nlet print x =\n let rec go d x =\n if not (is_nil x) then (\n go (d+1) x.sibling;\n for i = 1 to d do print_string \" \" done;\n Printf.printf \"%d\\n\" x.key;\n go (d+1) x.child;\n )\n in go 0 x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let rec go st i =\n if i >= n then\n st\n else\n let rec f = function\n | (y,yi)::(x,xi)::xs when x.key > y.key ->\n let z = merge x y in\n let z = if (xi-(if xs=[] then -1 else (List.hd xs |> snd))) land 1 <> 0 &&\n (yi-xi) land 1 <> 0 then pop z else z in\n f ((z,yi)::xs)\n | st -> st\n in\n go ((singleton a.(i),i) :: st |> f) (i+1)\n in\n\n (*let st = go [] 0 in*)\n (*Printf.printf \"+ len: %d\\n\" (List.length st);*)\n (*Printf.printf \"+++++++++\\n\";*)\n (*List.nth st 0 |> snd |> Printf.printf \"%d\\n\";*)\n (*List.nth st 0 |> fst |> print;*)\n (*Printf.printf \"+++++++++\\n\";*)\n (*List.nth st 1 |> snd |> Printf.printf \"%d\\n\";*)\n (*List.nth st 1 |> fst |> print;*)\n go [] 0\n |> List.rev\n |> List.fold_left (fun (ans,l) (x,xi) ->\n let rec go ans i =\n if i > xi then\n ans\n else\n let open Int64 in\n go (abs (sub (of_int a.(i)) (of_int x.key)) |> add ans) (i+1)\n in\n go ans (l+1), xi\n ) (0L,-1)\n |> fst |> 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\n\nlet lbound a n x =\n let rec go l h =\n if l >= h then\n l\n else\n let m = (l+h)/2 in\n if a.(m) < x then\n go (m+1) h\n else\n go l m\n in go 0 n\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let b = Array.copy a in\n Array.sort compare b;\n for i = 0 to n-1 do\n a.(i) <- lbound b n a.(i)\n done;\n\n let s = Array.make_matrix 2 n 0L in\n for i = 0 to n-1 do\n s.(0).(i) <- if a.(0) <= i then 0L else b.(a.(0))-b.(i) |> Int64.of_int\n done;\n for i = 1 to n-1 do\n let cur = i land 1 in\n let pre = 1-cur in\n for j = 0 to n-1 do\n s.(cur).(j) <- Int64.add s.(pre).(j) (b.(a.(i))-b.(j) |> abs |> Int64.of_int)\n done;\n for j = 1 to n-1 do\n s.(cur).(j) <- min s.(cur).(j) s.(cur).(j-1)\n done\n done;\n Printf.printf \"%Ld\\n\" s.((n-1) land 1).(n-1)\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet lbound a n x =\n let rec go l h =\n if l >= h then\n l\n else\n let m = (l+h)/2 in\n if a.(m) < x then\n go (m+1) h\n else\n go l m\n in go 0 n\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let b = Array.copy a in\n Array.sort compare b;\n for i = 0 to n-1 do\n a.(i) <- lbound b n a.(i)\n done;\n\n let s = Array.make_matrix 2 n 0 in\n for i = 0 to n-1 do\n s.(0).(i) <- if a.(0) <= i then 0 else b.(a.(0))-b.(i)\n done;\n for i = 1 to n-1 do\n let cur = i land 1 in\n let pre = 1-cur in\n for j = 0 to n-1 do\n s.(cur).(j) <- s.(pre).(j) + abs (b.(a.(i))-b.(j))\n done;\n for j = 1 to n-1 do\n s.(cur).(j) <- min s.(cur).(j) s.(cur).(j-1)\n done\n done;\n Printf.printf \"%d\\n\" s.((n-1) land 1).(n-1)\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\ntype node = {key: int; child: node; sibling: node}\n\nlet rec nil = {key = min_int; child = nil; sibling = nil}\nlet is_nil a = a.key = min_int\n\nlet merge a b =\n if a.key > b.key then\n {a with child = {b with sibling = a.child}}\n else\n {b with child = {a with sibling = b.child}}\n\nlet merge_list x =\n let rec go acc x =\n if is_nil x then\n acc\n else\n let y = {x with sibling = nil} in\n if is_nil x.sibling then\n y::acc\n else\n let z = {x.sibling with sibling = nil} in\n go (merge y z::acc) x.sibling.sibling\n in\n match go [] x with\n | [] -> nil\n | u::us -> List.fold_left (fun u v -> merge u v) u us\n\nlet pop x = merge_list x.child\n\nlet singleton k = {key = k; child = nil; sibling = nil}\n\nlet push x k = merge x {key = k; child = nil; sibling = nil}\n\nlet print x =\n let rec go d x =\n if not (is_nil x) then (\n go (d+1) x.sibling;\n for i = 1 to d do print_string \" \" done;\n Printf.printf \"%d\\n\" x.key;\n go (d+1) x.child;\n )\n in go 0 x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let rec go st i =\n if i >= n then\n st\n else\n let rec f = function\n | (y,yi)::(x,xi)::xs when x.key > y.key ->\n let z = merge x y in\n let z = if (xi-(if xs=[] then -1 else (List.hd xs |> snd))) land 1 <> 0 &&\n (yi-xi) land 1 <> 0 then pop z else z in\n f ((z,yi)::xs)\n | st -> st\n in\n let st' = f st in\n go ((singleton a.(i),i) :: st') (i+1)\n in\n\n (*Printf.printf \"+ len: %d\\n\" (List.length st);*)\n (*Printf.printf \"+++++++++\\n\";*)\n (*List.nth st 0 |> snd |> Printf.printf \"%d\\n\";*)\n (*Printf.printf \"+++++++++\\n\";*)\n (*List.nth st 1 |> snd |> Printf.printf \"%d\\n\";*)\n (*Printf.printf \"+++++++++\\n\";*)\n (*List.nth st 2 |> snd |> Printf.printf \"%d\\n\";*)\n go [] 0\n |> List.rev\n |> List.fold_left (fun (ans,l) (x,xi) ->\n let rec go ans i =\n if i > xi then\n ans\n else\n let open Int64 in\n go (abs (sub (of_int a.(i)) (of_int x.key)) |> add ans) (i+1)\n in\n go ans (l+1), xi\n ) (0L,-1)\n |> fst |> Printf.printf \"%Ld\\n\"\n"}], "src_uid": "5f4d01b17b9669a00c0f1a8b3a373abf"} {"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- (v, 1) :: es.(u);\n\tes.(v) <- (u, -1) :: es.(v);\n done;\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let a = Array.make n (-1) in\n let res = ref 0 in\n let pos = ref 0 in\n let stack = Array.make n 0 in\n let rec dfs u =\n used.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, d) = es.(u).(i) in\n\tif not used.(v) then (\n\t a.(v) <- a.(u) + d;\n\t dfs v\n\t) else (\n\t res := gcd !res (abs ((a.(u) + d) - a.(v)))\n\t)\n done;\n in\n let rec dfs () =\n if !pos > 0 then (\n decr pos;\n let u = stack.(!pos) in\n\tfor i = 0 to Array.length es.(u) - 1 do\n\t let (v, d) = es.(u).(i) in\n\t if not used.(v) then (\n\t a.(v) <- a.(u) + d;\n\t stack.(!pos) <- v;\n\t incr pos;\n\t used.(v) <- true;\n\t ) else (\n\t res := gcd !res (abs ((a.(u) + d) - a.(v)))\n\t )\n\tdone;\n\tdfs ()\n )\n in\n for i = 0 to n - 1 do\n if not used.(i) then (\n\ta.(i) <- 0;\n\tpos := 0;\n\tstack.(!pos) <- i;\n\tincr pos;\n\tused.(i) <- true;\n\tdfs ()\n )\n done;\n if !res = 0\n then res := n;\n Printf.printf \"%d\\n\" !res\n\n\n", "positive_code": [{"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- (v, 1) :: es.(u);\n\tes.(v) <- (u, -1) :: es.(v);\n done;\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let a = Array.make n (-1) in\n let res = ref 0 in\n let rec dfs u =\n used.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, d) = es.(u).(i) in\n\tif not used.(v) then (\n\t a.(v) <- a.(u) + d;\n\t dfs v\n\t) else (\n\t res := gcd !res (abs ((a.(u) + d) - a.(v)))\n\t)\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) then (\n\ta.(i) <- 0;\n\tdfs i\n )\n done;\n if !res = 0\n then res := n;\n Printf.printf \"%d\\n\" !res\n "}], "negative_code": [], "src_uid": "339e8062fa7935c146e87404e67ee021"} {"source_code": "let n, m = Scanf.scanf \" %d %d\" (fun x y -> x, y);;\nlet node = Scanf.scanf \" %s\" (fun x -> x);;\nlet adjs = Array.make (n + 1) [];;\nlet etat = Array.make (n + 1) 0;;\nlet maxi = Array.make_matrix (n + 1) 26 0;;\n\nfor i = 1 to m do\n let u, v = Scanf.scanf \" %d %d\" (fun x y -> x, y) in\n adjs.(u) <- v :: adjs.(u);\ndone;;\n\nlet rec cycle u =\n match etat.(u) with\n | 1 -> true\n | 2 -> false\n | _ ->\n etat.(u) <- 1;\n let x = List.fold_left (fun x v -> x || cycle v) false adjs.(u) in\n etat.(u) <- 2;\n x;;\n\nlet rec calculer u =\n let aux v =\n calculer v;\n let f i x =\n maxi.(u).(i) <- max maxi.(u).(i) x in\n Array.iteri f maxi.(v) in\n if etat.(u) = 0 then (\n etat.(u) <- 1;\n List.iter aux adjs.(u);\n let i = int_of_char node.[u - 1] - int_of_char 'a' in\n maxi.(u).(i) <- maxi.(u).(i) + 1\n );;\n\nlet cyclique = ref false in\nfor u = 1 to n do\n cyclique := !cyclique || cycle u;\ndone;\nif !cyclique then\n print_int (-1)\nelse (\n Array.fill etat 0 (Array.length etat) 0;\n let r = ref 0 in\n for u = 1 to n do\n calculer u;\n r := max !r (Array.fold_left max 0 maxi.(u));\n done;\n print_int !r\n);;\n", "positive_code": [{"source_code": "let n, m = Scanf.scanf \" %d %d\" (fun x y -> x, y);;\nlet label = Scanf.scanf \" %s\" (fun x -> x);;\nlet adjs = Array.make (n + 1) [];;\nlet etat = Array.make (n + 1) 0;;\nlet maxi = Array.make_matrix (n + 1) 26 0;;\n\nfor i = 1 to m do\n let u, v = Scanf.scanf \" %d %d\" (fun x y -> x, y) in\n adjs.(u) <- v :: adjs.(u);\ndone;;\n\nlet rec cycle u =\n match etat.(u) with\n | 1 -> true\n | 2 -> false\n | _ ->\n etat.(u) <- 1;\n let x = List.fold_left (fun x v -> x || cycle v) false adjs.(u) in\n etat.(u) <- 2;\n x;;\n\nlet rec calculer u =\n let aux v =\n calculer v;\n let f i x =\n maxi.(u).(i) <- max maxi.(u).(i) x in\n Array.iteri f maxi.(v) in\n if etat.(u) = 0 then (\n etat.(u) <- 1;\n List.iter aux adjs.(u);\n let i = int_of_char label.[u - 1] - int_of_char 'a' in\n maxi.(u).(i) <- maxi.(u).(i) + 1\n );;\n\nlet cyclique = ref false in\nfor u = 1 to n do\n cyclique := !cyclique || cycle u;\ndone;\nif !cyclique then\n print_int (-1)\nelse (\n Array.fill etat 0 (Array.length etat) 0;\n let r = ref 0 in\n for u = 1 to n do\n calculer u;\n r := max !r (Array.fold_left max 0 maxi.(u));\n done;\n print_int !r\n);;\n"}], "negative_code": [], "src_uid": "db5a99701dabe3516f97fd172118807e"} {"source_code": "let f tab =\n\tlet res = ref 0 in\n\tfor i=0 to Array.length tab - 2 do\n\t\tif tab.(i) > 1\n\t\t\tthen begin\n\t\t\t\tlet trop = tab.(i) - 1 in\n\t\t\t\t\ttab.(i) <- 1;\n\t\t\t\t\ttab.(i+1) <- tab.(i+1) + trop;\n\t\t\t\t\tres := trop + !res;\n\t\t\t end\n\t\t\t\t\n\tdone;\n\t!res\n\nlet _ =\n\tlet tab = Array.make 6015 0 and n = Scanf.scanf \"%d\" (fun i -> i) in\n\tfor i=1 to n do\n\t\tScanf.scanf \" %d\" (fun j -> tab.(j) <- tab.(j) + 1);\n\tdone;\n\tPrintf.printf \"%d\" (f tab)\n", "positive_code": [{"source_code": "\nlet (|>) x f = f x\nlet ($) f g = fun x -> f (g x)\n\nlet solve a =\n let arr = Array.make 10000 0 in\n List.iter\n (fun x -> arr.(x) <- arr.(x) + 1)\n a;\n let res = ref 0 in\n Array.iteri\n (fun i x ->\n if x > 1 then\n (res := !res + x - 1;\n arr.(i + 1) <- arr.(i + 1) + x - 1))\n arr;\n !res\n\nlet _ =\n ignore (read_int ());\n let a =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string\n in\n print_endline (string_of_int (solve a))\n"}], "negative_code": [], "src_uid": "53ae714f04fd29721b8bbf77576b7ccf"} {"source_code": "(* For the first archer to win, the possibilities are\n * win(a) - lose(a) & lose(b) & win(a)...*)\n\nlet main = \n let (a, b, c, d) = Scanf.scanf \"%f %f %f %f\\n\" (fun a b c d -> (a,b,c,d)) in\n let p_win = a /. b in\n let p_retry = (1. -. p_win) *. (1. -. (c /. d)) in\n let result = p_win /. (1. -. p_retry) in\n Printf.printf \"%f\\n\" result\n", "positive_code": [{"source_code": "(* Codeforces contest 300D - Draw Squares - Too slow *)\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 a = gr();; (* number of test data *)\nlet b = gr();; (* number of test data *)\nlet c = gr();; (* number of test data *)\nlet d = gr();; (* number of test data *)\n\nlet main() =\n let af = float_of_int a in\n let bf = float_of_int b in\n let cf = float_of_int c in\n let df = float_of_int d in\n \n\tlet adf = af *. df in\n\tlet acaf = (af *. df) +. (cf *. bf) -. (af *. cf) in\n\tlet pp = adf /. acaf in\n\tPrintf.printf \"%18.12f\" pp;;\t\n\nmain();;\n"}], "negative_code": [], "src_uid": "7b932b2d3ab65a353b18d81cf533a54e"} {"source_code": "open Str;;\r\n\r\nlet rec check (a : int list)(n : int) =\r\n if List.length (List.find_all (fun x -> x == (List.nth a n)) a) == 1 then\r\n n\r\n else\r\n check a (n+1)\r\n;;\r\n\r\nlet rec solve (t : int) =\r\n if t = 0 then\r\n ()\r\n else\r\n let n = read_int () in\r\n let arr = (Str.split (Str.regexp \" \") (read_line ())) in\r\n let a = (List.map (fun x -> int_of_string x) arr) in\r\n let ind = check a 0 in\r\n print_endline (string_of_int (ind + 1));\r\n solve (t-1)\r\n;;\r\n\r\nlet t = read_int() in\r\nsolve t;;\r\n", "positive_code": [{"source_code": "(* https://codeforces.com/contest/1512/problem/0 *)\n\nlet intruder arr =\n let rec commoner () =\n let h = Array.init 3 (fun i -> arr.(i)) in\n let count =\n Array.map\n (fun e -> Array.fold_left (fun acc e' -> if e = e' then acc+1 else acc) 0 h)\n h in\n if count.(0) > 1\n then h.(0)\n else h.(1) in\n let c = commoner () in\n let rec helper i =\n if arr.(i) <> c\n then (i+1)\n else helper (i+1) in\n helper 0\n\nlet solve_n nb_cases =\n let rec helper i =\n if i > 0\n then (\n let _ = read_int () and\n arr = \n read_line () \n |> Str.split (Str.regexp \" \") \n |> List.map int_of_string \n |> Array.of_list in\n intruder arr\n |> Printf.printf \"%d\\n\";\n helper (i-1)\n ) in\n helper nb_cases\n\nlet () =\n let nb_cases = read_int () in\n solve_n nb_cases\n"}], "negative_code": [], "src_uid": "224a0b09547ec1441474efbd8e06353b"} {"source_code": "open Printf\nopen Scanf\n\nlet mm = 1000000007L\n\nlet ( %% ) a b = Int64.rem a b\nlet ( ** ) a b = (Int64.mul a b) %% mm\nlet ( ++ ) a b = (Int64.add a b) %% mm\nlet ( -- ) a b = ((Int64.sub a b) ++ mm) %% mm\nlet long x = Int64.of_int x\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let t = read_int () in\n let k = read_int () in\n\n let input = Array.init t (fun _ -> read_pair()) in\n\n let msize = maxf 0 (t-1) (fun i -> snd input.(i)) in\n\n let count = Array.make (msize+1) (-1L) in\n count.(0) <- 1L;\n\n let rec ccount b = \n if count.(b) >= 0L then count.(b) else\n let answer = \n\tif b < k then 1L else\n\t ccount (b-k) ++ ccount (b-1)\n in\n count.(b) <- answer;\n answer\n in\n\n for b = 1 to msize do\n ignore (ccount b)\n done;\n\n let accum = Array.make (msize+1) 0L in\n accum.(0) <- count.(0);\n\n for i=1 to msize do\n accum.(i) <- accum.(i-1) ++ count.(i)\n done;\n\n for i=0 to t-1 do\n let (a,b) = input.(i) in\n printf \"%Ld\\n\" (accum.(b) -- (accum.(a-1)))\n done\n", "positive_code": [{"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Int64;;\n\n(* This version implements \n * a(n) = a(n-1) + a(n-k)\n * where k is the number of continued W\n * - Reduce memory usage.\n *)\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = rem i (of_int 1000000007)\n\nlet ni i = of_int i\nlet sn i = to_string i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 3\n\nlet r= Array.make nn_max (ni 0)\n\nfor i = 1 to k-1 do\n r.(i) <- (ni 1)\ndone\n\nlet () = \n r.(k) <- ni 2\n\nfor i = k+1 to nn do\n r.(i) <- modn (add r.(i-1) r.(i-k))\ndone\n\nfor i = 2 to nn do\n r.(i) <- add r.(i) r.(i-1)\ndone\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n sum := sub r.(e) r.(s-1);\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "open Int64;;\n\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet modulo = of_int 1000000007;;\n\nlet dyn_array = Array.make 100005 (of_int (-1));;\n\nlet rec get_ways gap = function \n | index when index = Array.length dyn_array -> one\n | index when index > Array.length dyn_array -> zero\n | index when (compare dyn_array.(index) (of_int (-1))) != 0 -> dyn_array.(index)\n | index ->\n let res = rem (add (get_ways gap (index+1)) (get_ways gap (index+gap))) modulo in\n dyn_array.(index) <- res;\n res;;\n\n(*#trace get_ways;;*)\n\nlet nbTests = read_int () in\nlet gap = read_int () in\nlet _ = get_ways gap 0 in\nfor i = 1 to Array.length dyn_array - 1 do\n dyn_array.(i) <- rem (add dyn_array.(i) dyn_array.(i - 1)) modulo\ndone;\nfor i = 1 to nbTests do\n let start = read_int () in\n let tree_end = Array.length dyn_array - start in\n let fin = read_int () in \n let tree_start = Array.length dyn_array - fin in\n let res = rem (add modulo (sub dyn_array.(tree_end) (if tree_start > 0 then dyn_array.(tree_start - 1) else zero))) modulo in\n Printf.printf \"%s\\n\" (to_string res)\ndone;;"}], "negative_code": [{"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\n(* This version implements \n * a(n) = a(n-1) + a(n-k)\n * where k is the number of continued W\n * - Reduce memory usage.\n *)\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = i mod 1000000007\n\nlet ni i = i\nlet sn i = string_of_int i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 3\n\nlet r= Array.make nn_max (ni (-1))\n\nfor i = 1 to k-1 do\n r.(i) <- (ni 1)\ndone\n\nlet () = \n r.(k) <- ni 2\n\nlet f n = \n if r.(n) = (ni (-1)) then\n begin\n let x = modn ( (modn r.(n-1)) + (modn r.(n-k)) ) in \n r.(n) <- x; x\n end\n else\n r.(n)\n\nfor i = k+1 to nn do\n r.(i) <- modn ((modn (f (i-1))) + (modn (f (i-k))))\ndone\n\n(*\nfor i = 95515 to nn do\n printf \"%s %s\\n\" (sn r.(i)) (sn w.(i))\ndone\n*)\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n for j = s to e do\n sum := !sum + r.(j)\n done;\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = mod_num i (num_of_int 1000000007)\n\nlet ni i = num_of_int i\nlet sn i = string_of_num i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 1\n\nlet r= Array.make nn_max (ni 0)\nlet w= Array.make nn_max (ni 0)\n\nlet num_w = ref 1\n\nlet () = \n r.(1) <- ni 1\n\nif k = 1 then\nbegin\n w.(1) <- ni 1; \nend\nelse\nbegin\n w.(1) <- ni 0;\nend\n\nfor i = 2 to nn do\n r.(i) <- r.(i-1) +/ w.(i-1);\n w.(i) <- w.(i-1);\n num_w := !num_w + 1;\n\n if !num_w = k then\n begin\n w.(i) <- w.(i) +/ (ni 1);\nnum_w := 0;\nend\ndone\n\n(*\nfor i = 0 to nn do\n printf \"%s %s\\n\" (sn r.(i)) (sn w.(i))\ndone\n*)\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n for j = s to e do\n sum := !sum +/ r.(j) +/ w.(j)\n done;\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\n(* This version implements \n * a(n) = a(n-1) + a(n-k)\n * where k is the number of continued W\n *)\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = mod_num i (num_of_int 1000000007)\n\nlet ni i = num_of_int i\nlet sn i = string_of_num i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 3\n\nlet r= Array.make nn_max (ni (-1))\n\nfor i = 1 to k-1 do\n r.(i) <- (ni 1)\ndone\n\nlet () = \n r.(k) <- ni 2\n\nlet f n = \n if r.(n) = (ni (-1)) then\n begin\n let x = r.(n-1) +/ r.(n-k) in \n r.(n) <- x; x\n end\n else\n r.(n)\n\n\n(*\nfor i = 95515 to nn do\n printf \"%s %s\\n\" (sn r.(i)) (sn w.(i))\ndone\n*)\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n for j = s to e do\n sum := !sum +/ (f j)\n done;\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Int64;;\n\n(* This version implements \n * a(n) = a(n-1) + a(n-k)\n * where k is the number of continued W\n * - Reduce memory usage.\n *)\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = rem i (of_int 1000000007)\n\nlet ni i = of_int i\nlet sn i = to_string i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 3\n\nlet r= Array.make nn_max (ni (-1))\n\nfor i = 1 to k-1 do\n r.(i) <- (ni 1)\ndone\n\nlet () = \n r.(k) <- ni 2\n\nlet f n = \n if r.(n) = (ni (-1)) then\n begin\n let x = ( add (r.(n-1)) (r.(n-k)) ) in \n r.(n) <- x; x\n end\n else\n r.(n)\n\nfor i = k+1 to nn do\n r.(i) <- (add ((f (i-1))) ((f (i-k))) )\ndone\n\n(*\nfor i = 95515 to nn do\n printf \"%s %s\\n\" (sn r.(i)) (sn w.(i))\ndone\n*)\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n for j = s to e do\n sum := add !sum r.(j)\n done;\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\n(* This version implements \n * a(n) = a(n-1) + a(n-k)\n * where k is the number of continued W\n * - Reduce memory usage.\n *)\n\nlet (t,k) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) )\n\nlet modn i = i mod 1000000007\n\nlet ni i = i\nlet sn i = string_of_int i\n\n(*let nn = 100000 + 5*)\nlet nn_max = 100000 + 5\n\nlet nn = 100000 + 3\n\nlet r= Array.make nn_max (ni (-1))\n\nfor i = 1 to k-1 do\n r.(i) <- (ni 1)\ndone\n\nlet () = \n r.(k) <- ni 2\n\nlet f n = \n if r.(n) = (ni (-1)) then\n begin\n let x = modn ( r.(n-1) + r.(n-k) ) in \n r.(n) <- x; x\n end\n else\n r.(n)\n\nfor i = k+1 to nn do\n r.(i) <- (f (i-1)) + (f (i-k))\ndone\n\n(*\nfor i = 95515 to nn do\n printf \"%s %s\\n\" (sn r.(i)) (sn w.(i))\ndone\n*)\n\nfor i = 1 to t do\n let (s,e) = bscanf Scanning.stdin \"%d %d \" (fun x y -> (x,y) ) in\n let sum = ref (ni 0) in\n for j = s to e do\n sum := !sum + r.(j)\n done;\n printf \"%s\\n\" (sn (modn !sum) )\ndone\n\n\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet (--) debut fin =\n let rec range aux start en =\n if start > en then aux\n else range (en::aux) start (en-1)\n in range [] debut fin;;\n\nlet print_list f lst =\n let rec print_elements = function\n | [] -> ()\n | h::t -> f h; print_string \";\"; print_elements t\n in\n print_string \"[\";\n print_elements lst;\n print_string \"]\\n\";\n lst;;\n\nlet modulo = 1000000007;;\n\nlet dyn_array = Array.make 100000 (-1);;\n\nlet rec get_ways gap = function \n | index when index = Array.length dyn_array -> 1\n | index when index > Array.length dyn_array -> 0\n | index when dyn_array.(index) != -1 -> dyn_array.(index)\n | index ->\n let res = (get_ways gap (index+1) + get_ways gap (index+gap)) mod modulo in\n dyn_array.(index) <- res;\n res;;\n\n(*#trace get_ways;;*)\n\ntype 'a node_data = {\n data:'a;\n start: int;\n fin: int\n};;\n\ntype 'a node = \n | Leaf of 'a node_data\n | Cell of 'a node_data * 'a node * 'a node;;\n\nlet get_data = function\n | Leaf data\n | Cell (data,_,_) \n -> data;;\n\nlet computing_function = (+);;\nlet default_val = 0;;\n\nlet rec get_range tree debut fin = match tree with\n | Leaf data ->\n if data.start >= debut && data.fin <= fin then\n data.data\n else\n default_val\n | Cell (d, left, right) ->\n if fin < d.start || debut > d.fin then\n default_val\n else if d.fin > fin || d.start < debut then\n computing_function (get_range left debut fin) (get_range right debut fin)\n else\n d.data;;\n\nlet rec buildTree debut fin =\n if debut = fin then \n Leaf {\n data = dyn_array.(debut);\n start = debut;\n fin = fin\n }\n else\n let mid = (debut + fin)/2 in\n let right = buildTree (mid + 1) fin in\n let left = buildTree debut mid in\n let node_d = {\n data = (computing_function (get_data left).data (get_data right).data);\n start = debut;\n fin = fin\n } in\n Cell (node_d, left, right);;\n\n\nlet nbTests = read_int () in\nlet gap = read_int () in\nlet _ = get_ways gap 0 in\nlet tree = buildTree 0 (Array.length dyn_array - 1) in\nfor i = 1 to nbTests do\n let start = read_int () in\n let tree_end = Array.length dyn_array - start in\n let fin = read_int () in \n let tree_start = Array.length dyn_array - fin in\n let res = get_range tree tree_start tree_end in\n Printf.printf \"%d\\n\" res\ndone;;"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet (--) debut fin =\n let rec range aux start en =\n if start > en then aux\n else range (en::aux) start (en-1)\n in range [] debut fin;;\n\nlet print_list f lst =\n let rec print_elements = function\n | [] -> ()\n | h::t -> f h; print_string \";\"; print_elements t\n in\n print_string \"[\";\n print_elements lst;\n print_string \"]\\n\";\n lst;;\n\nlet modulo = 1000000007;;\n\nlet dyn_array = Array.make 100005 (-1);;\n\nlet rec get_ways gap = function \n | index when index = Array.length dyn_array -> 1\n | index when index > Array.length dyn_array -> 0\n | index when dyn_array.(index) != -1 -> dyn_array.(index)\n | index ->\n let res = (get_ways gap (index+1) + get_ways gap (index+gap)) mod modulo in\n dyn_array.(index) <- res;\n res;;\n\n(*#trace get_ways;;*)\n\nlet nbTests = read_int () in\nlet gap = read_int () in\nlet _ = get_ways gap 0 in\nfor i = 1 to Array.length dyn_array - 1 do\n dyn_array.(i) <- (dyn_array.(i) + dyn_array.(i - 1)) mod modulo\ndone;\nfor i = 1 to nbTests do\n let start = read_int () in\n let tree_end = Array.length dyn_array - start in\n let fin = read_int () in \n let tree_start = Array.length dyn_array - fin in\n let res = (modulo + dyn_array.(tree_end) - if tree_start > 0 then dyn_array.(tree_start - 1) else 0) mod modulo in\n Printf.printf \"%l\\n\" res\ndone;;"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet (--) debut fin =\n let rec range aux start en =\n if start > en then aux\n else range (en::aux) start (en-1)\n in range [] debut fin;;\n\nlet print_list f lst =\n let rec print_elements = function\n | [] -> ()\n | h::t -> f h; print_string \";\"; print_elements t\n in\n print_string \"[\";\n print_elements lst;\n print_string \"]\\n\";\n lst;;\n\nlet modulo = 1000000007;;\n\nlet dyn_array = Array.make 100000 (-1);;\n\nlet rec get_ways gap = function \n | index when index = Array.length dyn_array -> 1\n | index when index > Array.length dyn_array -> 0\n | index when dyn_array.(index) != -1 -> dyn_array.(index)\n | index ->\n let res = (get_ways gap (index+1) + get_ways gap (index+gap)) mod modulo in\n dyn_array.(index) <- res;\n res;;\n\n(*#trace get_ways;;*)\n\ntype 'a node_data = {\n data:'a;\n start: int;\n fin: int\n};;\n\ntype 'a node = \n | Leaf of 'a node_data\n | Cell of 'a node_data * 'a node * 'a node;;\n\nlet get_data = function\n | Leaf data\n | Cell (data,_,_) \n -> data;;\n\nlet computing_function a b= \n (a + b) mod modulo;;\nlet default_val = 0;;\n\nlet rec get_range tree debut fin = match tree with\n | Leaf data ->\n if data.start >= debut && data.fin <= fin then\n data.data\n else\n default_val\n | Cell (d, left, right) ->\n if fin < d.start || debut > d.fin then\n default_val\n else if d.fin > fin || d.start < debut then\n computing_function (get_range left debut fin) (get_range right debut fin)\n else\n d.data;;\n\n(*#trace get_range;;*)\n\nlet rec buildTree debut fin =\n if debut = fin then \n Leaf {\n data = dyn_array.(debut);\n start = debut;\n fin = fin\n }\n else\n let mid = (debut + fin)/2 in\n let right = buildTree (mid + 1) fin in\n let left = buildTree debut mid in\n let node_d = {\n data = (computing_function (get_data left).data (get_data right).data);\n start = debut;\n fin = fin\n } in\n Cell (node_d, left, right);;\n\n\nlet nbTests = read_int () in\nlet gap = read_int () in\nlet _ = get_ways gap 0 in\nlet tree = buildTree 0 (Array.length dyn_array - 1) in\nfor i = 1 to nbTests do\n let start = read_int () in\n let tree_end = Array.length dyn_array - start in\n let fin = read_int () in \n let tree_start = Array.length dyn_array - fin in\n let res = get_range tree tree_start tree_end in\n Printf.printf \"%d\\n\" res\ndone;;"}], "src_uid": "16c016c0735be1815c7b94c5c50516f1"} {"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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f) \n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let light = Array.init n read_string in\n(* light.(f).[r] = is the light on floor f in room r *)\n let ison f r = light.(n-1-f).[r] = '1' in\n\n let floor_off f = forall 0 (m+1) (fun r -> not (ison f r)) in\n\n let top_floor = maxf 0 (n-1) (fun f -> if floor_off f then 0 else f) in\n\n let ftime f st en =\n (* time to clear floor f starting at st (=0/1 for left/right) ending at en *)\n if en <> st then m+1\n else if st=0 then 2 * (maxf 1 m (fun r -> if ison f r then r else 0))\n else if st=1 then 2 * (maxf 1 m (fun r -> if ison f r then (m+1-r) else 0))\n else failwith \"no\"\n in\n\n let dp = Array.make_matrix n 2 0 in\n\n for f=0 to n-2 do\n for en = 0 to 1 do\n dp.(f).(en) <-\n\tif f=0 then ftime f 0 en\n\telse minf 0 1 (fun st -> dp.(f-1).(st) + 1 + (ftime f st en))\n(* printf \"dp.(%d).(%d) = %d\\n\" f en dp.(f).(en) *)\n done\n done;\n\n(* handle the last floor *)\n\n let answer f =\n if f=0 then (ftime 0 0 0)/2\n else minf 0 1 (fun st -> dp.(f-1).(st) + ((ftime f st st)/2) + 1)\n in\n\n printf \"%d\\n\" (answer top_floor)\n", "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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f) \n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let light = Array.init n read_string in\n(* light.(f).[r] = is the light on floor f in room r *)\n let ison f r = light.(n-1-f).[r] = '1' in\n\n let floor_off f = forall 0 (m+1) (fun r -> not (ison f r)) in\n\n let top_floor = maxf 0 (n-1) (fun f -> if floor_off f then 0 else f) in\n\n let ftime f st en =\n (* time to clear floor f starting at st (=0/1 for left/right) ending at en *)\n if en <> st then m+1\n else if st=0 then 2 * (maxf 1 m (fun r -> if ison f r then r else 0))\n else if st=1 then 2 * (maxf 1 m (fun r -> if ison f r then (m+1-r) else 0))\n else failwith \"no\"\n in\n\n let best_cost = ref 1_000_000 in\n \n let rec backtrack f side cost =\n if f = top_floor then (\n let top_cost = (ftime f side side)/2 in\n best_cost := min !best_cost (cost + 1 + top_cost)\n ) else (\n backtrack (f+1) side (cost + 1 + ftime f side side);\n backtrack (f+1) (1-side) (cost + 1 + ftime f side (1-side)); \n )\n in\n\n backtrack 0 0 (-1);\n\n printf \"%d\\n\" !best_cost\n"}], "negative_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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let light = Array.init n read_string in\n(* light.(f).[r] = is the light on floor f in room r *)\n let ison f r = light.(n-1-f).[r] = '1' in\n\n let ftime f st en =\n (* time to clear floor f starting at st (=0/1 for left/right) ending at en *)\n if en <> st then m+1\n else if st=0 then 2 * (maxf 1 m (fun r -> if ison f r then r else 0))\n else if st=1 then 2 * (maxf 1 m (fun r -> if ison f r then (m+1-r) else 0))\n else failwith \"no\"\n in\n\n let dp = Array.make_matrix n 2 0 in\n\n for f=0 to n-2 do\n for en = 0 to 1 do\n dp.(f).(en) <-\n\tif f=0 then ftime f 0 en\n\telse minf 0 1 (fun st -> dp.(f-1).(st) + 1 + (ftime f st en))\n(* printf \"dp.(%d).(%d) = %d\\n\" f en dp.(f).(en) *)\n done\n done;\n\n(* handle the last floor *)\n\n let answer f =\n if f=0 then (ftime 0 0 0)/2\n else minf 0 1 (fun st -> dp.(f-1).(st) + ((ftime f st st)/2) + 1)\n in\n\n printf \"%d\\n\" (answer (n-1))\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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let light = Array.init n read_string in\n(* light.(f).[r] = is the light on floor f in room r *)\n let ison f r = light.(n-1-f).[r] = '1' in\n\n let inf = 1_000_000_000 in\n\n let ftime f st en =\n (* time to clear floor f starting at st (=0/1 for left/right) ending at en *)\n if en <> st then m+1\n else if st=0 then 2 * (maxf 1 m (fun r -> if ison f r then r else 0))\n else if st=1 then 2 * (maxf 1 m (fun r -> if ison f r then (m+1-r) else 0))\n else failwith \"no\"\n in\n\n let dp = Array.make_matrix n 2 0 in\n\n for f=0 to n-2 do\n for en = 0 to 1 do\n dp.(f).(en) <-\n\tif f=0 then ftime f 0 en\n\telse minf 0 1 (fun st -> dp.(f-1).(st) + 1 + (ftime f st en))\n(* printf \"dp.(%d).(%d) = %d\\n\" f en dp.(f).(en) *)\n done\n done;\n\n(* handle the last floor *)\n\n let answer f = minf 0 1 (fun st ->\n let prev = if f=0 then (if st=0 then 0 else inf) else dp.(f-1).(st) in\n prev + ((ftime f st st)/2) + (if f<>0 then 1 else 0)\n ) in\n\n printf \"%d\\n\" (answer (n-1))\n"}], "src_uid": "55070f8e5dba8a6ec669a53a169e557d"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let ht = Hashtbl.create m in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tHashtbl.add ht (v, u) ();\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let res = ref [] in\n let stack = Array.make (2 * n) (fun _ -> ()) in\n let stack_pos = ref 0 in\n let rec execute () =\n if !stack_pos > 0 then (\n decr stack_pos;\n let f = stack.(!stack_pos) in\n\tf ();\n\texecute ()\n )\n in\n let rec dfs u prev =\n used.(u) <- true;\n let rec aux i =\n if i < Array.length es.(u) then (\n\tstack.(!stack_pos) <- (fun () -> aux (i + 1));\n\tincr stack_pos;\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t (*let f () =\n\t (*pe.(v) <- edge;\n\t tout.(u) <- !t;\n\t incr t;*) ()\n\t in\n\t (*stack.(!stack_pos) <- f;\n\t incr stack_pos;*)*)\n\t stack.(!stack_pos) <- (fun () -> dfs v u);\n\t incr stack_pos;\n\t )\n ) else (\n )\n in\n let f () =\n res := u :: !res\n in\n stack.(!stack_pos) <- f;\n incr stack_pos;\n aux 0\n in\n for u = 0 to n - 1 do\n if not used.(u) then (\n\tstack_pos := 0;\n\tdfs u 0;\n\texecute ();\n )\n done;\n List.iter\n (fun u ->\n\t Printf.printf \"%d \" (u + 1)\n ) (List.rev !res);\n Printf.printf \"\\n\"\n", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int();;\nlet pred=Array.make (n+1) [0];;\nfor i=1 to n do\n pred.(i)<-[]\ndone;;\nfor i=1 to m do\n let x=read_int() and y=read_int() in\n pred.(x)<-y::pred.(x)\ndone;;\ntype etat=Vu|Non_vu|En_cours;;\nlet mark=Array.make (n+1) Non_vu;;\nlet res=ref [];;\n\nlet rec dfs u=function\n|[]->mark.(u)<-Vu;res:=u::(!res)\n|h::t->if mark.(h)=Non_vu then\n begin\n mark.(h)<-En_cours;\n dfs h pred.(h)\n end;\n dfs u t;;\n\nlet tri()=\nfor i=1 to n do \n if mark.(i)=Vu then () else\n begin\n mark.(i)<-En_cours;\n dfs i pred.(i)\n end;\ndone;;\n\ntri();;\n\nlet rec print_list=function\n|[]->print_newline()\n|h::t->print_list t;Printf.printf \"%d \" h;;\n\nprint_list !res;;"}], "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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let ht = Hashtbl.create m in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(v) <- u :: es.(u);\n\tHashtbl.add ht (v, u) ();\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let res = ref [] in\n let stack = Array.make (2 * n) (fun _ -> ()) in\n let stack_pos = ref 0 in\n let rec execute () =\n if !stack_pos > 0 then (\n decr stack_pos;\n let f = stack.(!stack_pos) in\n\tf ();\n\texecute ()\n )\n in\n let rec dfs u prev =\n used.(u) <- true;\n let rec aux i =\n if i < Array.length es.(u) then (\n\tstack.(!stack_pos) <- (fun () -> aux (i + 1));\n\tincr stack_pos;\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t (*let f () =\n\t (*pe.(v) <- edge;\n\t tout.(u) <- !t;\n\t incr t;*) ()\n\t in\n\t (*stack.(!stack_pos) <- f;\n\t incr stack_pos;*)*)\n\t stack.(!stack_pos) <- (fun () -> dfs v u);\n\t incr stack_pos;\n\t )\n ) else (\n )\n in\n let f () =\n res := u :: !res\n in\n stack.(!stack_pos) <- f;\n incr stack_pos;\n aux 0\n in\n for u = 0 to n - 1 do\n if not used.(u) then (\n\tstack_pos := 0;\n\tdfs u 0;\n\texecute ();\n )\n done;\n List.iter\n (fun u ->\n\t Printf.printf \"%d \" (u + 1)\n ) ((*List.rev*) !res);\n Printf.printf \"\\n\"\n"}], "src_uid": "412c9de03713ca8b5d1461d0213b8eec"} {"source_code": "let () =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] and tab = Array.make 2001 0 \n\tand tab' = Array.make 2001 0 in\n\t\tfor i=1 to n do\n\t\t\tScanf.scanf \" %d\" (fun j -> tab.(j) <- tab.(j) + 1; l := j::!l);\n\t\tdone;\n\t\tfor i=2000 downto 1 do\n\t\t\ttab'.(i-1) <- tab'.(i) + tab.(i);\n\t\tdone;\n\tList.iter (fun i -> Printf.printf \"%d \" (1 + tab'.(i))) (List.rev !l)\n", "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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n (* let start_time = Sys.time() in *)\n\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let b = Array.init n (fun i -> string_of_int (\n 1 + sum 0 n (fun x -> if a.(x) > a.(i) then 1 else 0)\n )) in\n print_string (String.concat \" \" (Array.to_list b));\n\n (* let finish_time = Sys.time() in *)\n (* printf \"Time of scanning %fs\\n\" (finish_time -. start_time); *)\n (* b;; *)\n"}], "negative_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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet main () = \n let start_time = Sys.time() in\n\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let b = Array.init n (fun i -> string_of_int (\n sum 0 n (fun x -> if a.(x) > a.(i) then 1 else 0)\n )) in \n print_string (String.concat \" \" (Array.to_list b));\n\n let finish_time = Sys.time() in\n printf \"Time of scanning %fs\\n\" (finish_time -. start_time);\n b;;\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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n (* let start_time = Sys.time() in *)\n\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let b = Array.init n (fun i -> string_of_int (\n sum 0 n (fun x -> if a.(x) > a.(i) then 1 else 0)\n )) in\n print_string (String.concat \" \" (Array.to_list b));\n\n (* let finish_time = Sys.time() in *)\n (* printf \"Time of scanning %fs\\n\" (finish_time -. start_time); *)\n (* b;; *)\n"}], "src_uid": "a5edbf422616cdac35e95a4f07efc7fd"} {"source_code": "let cmp x y =\n let a = 10 - (x mod 10)\n and b = 10 - (y mod 10) in\n compare a b\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n k ->\n (* read initial skills *)\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* sort by distance from the next multiple of 10 *)\n Array.sort cmp a;\n\n (* calculate the possible improvement *)\n let (rating, rem) = Array.fold_left (fun (acc, rem) skill ->\n (* if we have enough skill points remaining, use them *)\n let diff = 10 - (skill mod 10) in\n if diff <= rem\n then (acc + (skill + diff) / 10, rem - diff)\n else (acc + skill / 10, rem)\n ) (0, k) a in\n\n Printf.printf \"%d\\n\" (min (rating + rem / 10) (n * 10)))\n", "positive_code": [{"source_code": "(*I should use a cyclic list*)\nopen Scanf;;\nopen Printf;;\n\n\nlet (n,k) = Scanf.scanf \"%d %d \" (fun x y -> (x,y) )\n\nlet a = Array.make n 0\n\nlet rec readi i l =\n if i = n then\n List.rev l\n else\n begin\n let x = Scanf.scanf \"%d \" (fun x -> x) in\n readi (i+1) (x::l)\n end\n\nlet b = readi 0 []\n\nlet b1 = List.filter (fun x -> x mod 10 !=0 ) b |> List.sort (fun x y -> compare (y mod 10) (x mod 10) )\n\nlet b2 = List.filter (fun x -> x mod 10 =0 ) b |> List.sort (fun x y -> compare y x)\n\n (*\nlet _ =\n List.iter (fun x -> printf \"%d \" x) b\n\nlet _ = List.mapi (fun i x -> a.(i)<-x) (b2 @ b1)\n *)\n\nlet rec f ll rl k =\n if k==0 then\n (((List.rev ll) @ rl), k)\n else\n begin\n match rl with\n | [] -> ( (List.rev ll), k)\n | hd::tl ->\n begin\n if (hd mod 10) + k >= 10 then\n let x = 10 - (hd mod 10) in\n f ((hd + x)::ll) tl (k-x)\n else\n f (hd::ll) tl 0\n end\n end\n\nlet (l,t) = f [] b1 k\n\nlet l = l @ b2\n(*\nlet _ =\n print_endline \"\";\n printf \"%d\\n\" t;\n List. iter (fun x -> printf \"%d \" x) l;\n print_endline \"\"\n *)\n\nlet _ =\n if t>0 then\n let s = List.fold_left (fun x y -> x + (100-y)) 0 l in\n if s<= t then\n printf \"%d\\n\" (10*(List.length l))\n else\n begin\n let s1 = List.fold_left (fun x y -> x + y/10) 0 (t::l) in\n printf \"%d\\n\" s1\n end\n else\n begin\n let s1 = List.fold_left (fun x y -> x + y/10) 0 l in\n printf \"%d\\n\" s1\n end\n"}], "negative_code": [{"source_code": "let cmp x y =\n let a = 10 - (x mod 10)\n and b = 10 - (y mod 10) in\n compare a b\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n k ->\n (* read initial skills *)\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* sort by distance from the next multiple of 10 *)\n Array.sort cmp a;\n\n (* calculate the possible improvement *)\n let (rating, rem) = Array.fold_left (fun (acc, rem) skill ->\n (* if we have enough skill points remaining, use them *)\n let diff = 10 - (skill mod 10) in\n if diff <= rem\n then (acc + (skill + diff) / 10, rem - diff)\n else (acc + skill / 10, rem)\n ) (0, k) a in\n\n Printf.printf \"%d\\n\" (rating + rem / 10))\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Int64;;\nopen Char;;\n\nlet (n,k) = Scanf.scanf \"%d %d \" (fun x y -> (x,y) )\n\nlet a = Array.make n 0\n\nlet _ =\n for i = 0 to (n-1) do\n let x = Scanf.scanf \"%d \" (fun x -> x) in\n a.(i) <- x\n done\n\nlet cmp x y =\n if x mod 10 = 0 then\n 1\n else\n begin\n let xi = x mod 10 in\n let yi = y mod 10 in\n if xi > yi then\n 1\n else\n begin\n if xi < yi then\n -1\n else 0\n end\n end\n in\n Array.fast_sort (fun x y -> cmp y x) a\n(*\nlet _ =\n Array.iter (fun x -> printf \"%d \" x) a\n *)\n\nexception BR\n\n let _ =\n let rk = ref k in\n try\n for i = 0 to (n-1) do\n if !rk <= 0 then\n raise BR\n else\n if !rk+a.(i) >= 100 then\n begin\n rk := !rk - (100-a.(i));\n a.(i) <- 100\n end\n else\n begin\n if !rk + (a.(i) mod 10) >= 10 then\n begin\n let tmp = !rk+a.(i) in\n let tmp2 = tmp - (tmp mod 10) in\n (\n rk := !rk - (tmp2 - a.(i));\n a.(i) <- tmp2\n )\n end\n else ()\n end\n done\n with BR -> ()\n\n(*\n let _ =\n print_endline \"\";\n Array.iter (fun x -> printf \"%d \" x) a\n *)\n\n let rslt =\n Array.fold_left (fun x y -> x + y/10) 0 a\n in\n printf \"%d \" rslt\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Int64;;\nopen Char;;\n\nlet (n,k) = Scanf.scanf \"%d %d \" (fun x y -> (x,y) )\n\nlet a = Array.make n 0\n\nlet _ = \n for i = 0 to (n-1) do\n let x = Scanf.scanf \"%d \" (fun x -> x) in\n a.(i) <- x\n done\n\nlet cmp x y = \n if x mod 10 = 0 then\n 1\n else begin\n let xi = x mod 10 in\n let yi = y mod 10 in\n if xi > yi then\n 1\n else if xi < yi then\n -1\n else 0\n end\n in\n Array.fast_sort (fun x y -> cmp x y) a\n\n (*\n let _ = \n Array.iter (fun x -> printf \"%d \" x) a\n *)\n\nexception BR\n\n let _ =\n let rk = ref k in\n try \n for i = 0 to (n-1) do\n if !rk <= 0 then\n raise BR\n else\n if !rk+a.(i) >= 100 then\n begin\n rk := !rk - (100-a.(i));\n a.(i) <- 100\n end\n else\n begin\n let tmp = !rk+a.(i) in\n let tmp2 = tmp - (tmp mod 10) in\n (\n rk := !rk - (tmp2 - a.(i));\n a.(i) <- tmp2\n )\n end\n done\n with BR -> ()\n\n let rslt = \n Array.fold_left (fun x y -> x + y/10) 0 a\n in \n printf \"%d \" rslt\n"}], "src_uid": "b4341e1b0ec0b7341fdbe6edfe81a0d4"} {"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* input *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\texternal id : 'a -> 'a = \"%identity\"\n\tlet ( *< ) f g x = f (g x)\n\tlet ( *> ) f g x = g (f x)\n\tlet rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet fail _ = failwith \"fail\"\n\tlet dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n\tlet range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n\tlet cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n\tlet shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n\tlet binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n\t\tlet rec f0 ng ok =\n\t\t\tif labs (ok - ng) <= 1L then ok\n\t\t\telse let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n\t\tin f0 (ng-1L*d) (ok+1L*d)\n\tlet lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n\tlet upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n\tlet equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n\tlet rec fix f x = f (fix f) x\n\t(* imperative *)\n\tlet rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n\tlet repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n\tlet repm f t ?(stride=1L) m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n\tlet repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n\tlet repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n\tlet repim f t ?(stride=1) m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n\tlet rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n\tlet repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n\tlet repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n\tlet repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n\tlet repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n\tlet repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n\t(* output *)\n\tlet print_list_mle f ls = string_of_list f ls |> print_endline\n\tlet print_array_mle f a = string_of_array f a |> print_endline\n\tlet print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n\tlet print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n\t(* debug *)\n\tlet dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n\tlet dump_i64_list ls = print_list ist ls\n\tlet dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n\tlet n=get_i64 0 in let n=i32 n in\n\tlet e=make n [] in\n\tlet visited = make n false in\n\trepi 2 n (fun _->\n\t\tlet u,v = get_2_i64 0 in\n\t\tlet u,v = i32 u-$1,i32 v-$1 in\n\t\te.(u) <- v::e.(u);\n\t\te.(v) <- u::e.(v);\n\t);\n\tlet res = ref 0L in\n\tlet s = fix (fun f i -> \n\t\tvisited.(i) <- true;\n\t\tList.fold_left (fun sum j->\n\t\t\tif visited.(j) then sum\n\t\t\telse (\n\t\t\t\tlet v = f j in\n\t\t\t\tif v %$ 2 = 0 then (\n\t\t\t\t\tres += 1L; sum\n\t\t\t\t) else sum +$ v\n\t\t\t)\n\t\t) 1 e.(i)\n\t) 0 in\n\tif s %$ 2 = 0 then printf \"%Ld\\n\" !res\n\telse printf \"-1\\n\"\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let g = Array.make (n + 1) []\n and subtree = Array.make (n + 1) 1\n and visited = Array.make (n + 1) false\n and ans = ref 0 in\n let rec dfs v =\n if not visited.(v) then begin\n visited.(v) <- true;\n subtree.(v) <- List.fold_left (fun acc x ->\n if not visited.(x) then begin\n dfs x;\n acc + subtree.(x)\n end\n else acc\n ) 1 g.(v);\n if subtree.(v) mod 2 = 0 then incr ans\n end in\n for i = 1 to n - 1 do\n let a = read_int () and b = read_int () in\n g.(a) <- b::g.(a);\n g.(b) <- a::g.(b)\n done;\n dfs 1;\n if n mod 2 = 1 then printf \"-1\\n\"\n else printf \"%d\\n\" (!ans - 1)"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let g = Array.make (n + 1) []\n and subtree = Array.make (n + 1) 1\n and visited = Array.make (n + 1) false\n and ans = ref 0\n and err = ref false in\n let rec dfs v =\n let flag = ref false in\n if not visited.(v) then begin\n visited.(v) <- true;\n subtree.(v) <- List.fold_left (fun acc x ->\n if not visited.(x) then begin\n dfs x;\n if subtree.(x) mod 2 = 1 then flag := true;\n acc + subtree.(x)\n end\n else acc\n ) 1 g.(v);\n if subtree.(v) mod 2 = 0 then incr ans\n else if !flag then err := true;\n end in\n for i = 1 to n - 1 do\n let a = read_int () and b = read_int () in\n g.(a) <- b::g.(a);\n g.(b) <- a::g.(b)\n done;\n dfs 1;\n if !err then printf \"-1\\n\"\n else printf \"%d\\n\" (!ans - 1)"}], "src_uid": "711896281f4beff55a8826771eeccb81"} {"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let n = xint() and m = xint() in\n let cost = ref 0 in\n for i = 0 to n - 1 do\n let tmp = ref 1000000000 in\n for j = 0 to m - 1 do\n let x = xint() in\n tmp := if x < !tmp then x else !tmp;\n done;\n cost := if !cost < !tmp then !tmp else !cost;\n done;\n Printf.printf \"%d\\n\" !cost;\n", "positive_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\n\nlet _ = \n let (n, m) = read2 () in\n let maxi = ref 0 in\n for i=1 to n do\n let mini = ref max_int in\n for i=1 to m-1 do\n Scanf.scanf \"%d \" ( fun x -> if x < !mini then mini := x )\n done;\n Scanf.scanf \"%d\\n\" ( fun x -> if x < !mini then mini := x );\n if !mini > !maxi then maxi := !mini;\n done;\n Printf.printf \"%d\\n\" !maxi ;;\n\n\n"}], "negative_code": [], "src_uid": "f2142bc2f44e5d8b77f8561c29038a73"} {"source_code": "let parse s len = let rep = Array.make len 0 in\r\n let temp = ref \"\" in\r\n let count = ref 0 in\r\n for j = 0 to String.length s -1 do\r\n if s.[j] = ' ' then (rep.(!count)<-(int_of_string !temp) ; incr count ; temp := \"\")\r\n else (temp := !temp ^ (String.make 1 s.[j]))\r\n done; rep.(!count)<-(int_of_string !temp) ; rep ;;\r\n\r\n\r\nlet maxes tab = let max1 = ref tab.(0) in\r\n\tlet count = ref 0 in\r\n for i = 1 to Array.length tab -1 do\r\n\tif tab.(i) = !max1 then incr count;\r\n if tab.(i) > !max1 then (max1 := tab.(i); count := 0) ;\r\n\r\n done;\r\nlet toto = ref false in\r\n if !count <> 0 then true else begin\r\n\tfor i = 0 to Array.length tab -1 do\r\n\tif tab.(i) = (!max1 -1) then toto := true\r\ndone ; !toto\t\r\n\r\nend ;;\r\n \r\n\r\n\r\nlet n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let len = int_of_string (input_line stdin) in\r\n let str = input_line stdin in \r\n let tab = parse str len in\r\n if len < 2 then (if tab.(0) = 1 then print_endline \"YES\" else print_endline \"NO\")\r\n else begin\r\n if maxes tab then print_endline \"YES\" else print_endline \"NO\" end\r\ndone;; ", "positive_code": [{"source_code": "open Printf\r\nopen Scanf\r\nmodule LL = Int64\r\nlet ( !! ) x = LL.to_int x\r\nlet ( ++ ) x y = LL.add x y\r\nlet ( -- ) x y = LL.sub x y\r\nlet ( ** ) x y = LL.mul x y\r\nlet ( // ) x y = LL.div x y\r\nlet ( %% ) x y = LL.rem x y\r\nlet ( >> ) x y = (LL.compare x y) > 0\r\nlet ( << ) x y = (LL.compare x y) < 0\r\nlet ( == ) x y = (LL.compare x y) = 0\r\nlet rd_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\r\nlet rd_ll _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x)\r\nlet rd_arr n = Array.init n rd_ll\r\n\r\nlet solve n a = \r\n Array.sort LL.compare a;\r\n let dx = \r\n if n = 1 then a.(0)\r\n else a.(n-1) -- a.(n-2) in\r\n\r\n if dx >> 1L then \"NO\" else \"YES\"\r\n\r\nlet () =\r\n let t = read_int () in\r\n for i=1 to t do\r\n let n = rd_int () in\r\n let a = rd_arr n in\r\n printf \"%s\\n\" (solve n a)\r\n done;"}], "negative_code": [{"source_code": "let parse s len = let rep = Array.make len 0 in\r\n let temp = ref \"\" in\r\n let count = ref 0 in\r\n for j = 0 to String.length s -1 do\r\n if s.[j] = ' ' then (rep.(!count)<-(int_of_string !temp) ; incr count ; temp := \"\")\r\n else (temp := !temp ^ (String.make 1 s.[j]))\r\n done; rep.(!count)<-(int_of_string !temp) ; rep ;;\r\n\r\n\r\nlet maxes tab = let max1 = ref tab.(0) in\r\n\tlet count = ref 0 in\r\n for i = 1 to Array.length tab -1 do\r\n if tab.(i) > !max1 then (max1 := tab.(i); count := 0) ;\r\n\tif tab.(i) = !max1 then incr count;\r\n done;\r\nlet toto = ref false in\r\n if !count <> 0 then true else begin\r\n\tfor i = 0 to Array.length tab -1 do\r\n\tif tab.(i) = !max1 -1 then toto := true\r\ndone ; !toto\t\r\n\r\nend ;;\r\n \r\n\r\n\r\nlet n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let len = int_of_string (input_line stdin) in\r\n let str = input_line stdin in \r\n let tab = parse str len in\r\n if len < 2 then (if tab.(0) = 1 then print_endline \"YES\" else print_endline \"NO\")\r\n else begin\r\n if maxes tab then print_endline \"YES\" else print_endline \"NO\" end\r\ndone;; "}, {"source_code": "let parse s len = let rep = Array.make len 0 in\r\n let temp = ref \"\" in\r\n let count = ref 0 in\r\n for j = 0 to String.length s -1 do\r\n if s.[j] = ' ' then (rep.(!count)<-(int_of_string !temp) ; incr count ; temp := \"\")\r\n else (temp := !temp ^ (String.make 1 s.[j]))\r\n done; rep.(!count)<-(int_of_string !temp) ; rep ;;\r\n\r\n\r\nlet maxes tab = let max1 = ref tab.(0) in let max2 = ref tab.(1) in\r\n for i = 2 to Array.length tab -1 do\r\n if !max1 < !max2 && tab.(i) > !max1 then max1 := tab.(i) ;\r\n if !max1 >= !max2 && tab.(i) > !max2 then max2 := tab.(i) ;\r\n done;\r\n !max1 = !max2 || !max1 = !max2 -1 || !max2 = !max1 -1;;\r\n \r\n\r\n\r\nlet n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let len = int_of_string (input_line stdin) in\r\n let str = input_line stdin in \r\n let tab = parse str len in\r\n if len < 2 then (if tab.(0) = 1 then print_endline \"YES\" else print_endline \"NO\")\r\n else begin\r\n if maxes tab then print_endline \"YES\" else print_endline \"NO\" end\r\ndone;;\r\n \r\n \r\n "}, {"source_code": "let parse s len = let rep = Array.make len 0 in\r\n let temp = ref \"\" in\r\n let count = ref 0 in\r\n for j = 0 to String.length s -1 do\r\n if s.[j] = ' ' then (rep.(!count)<-(int_of_string !temp) ; incr count ; temp := \"\")\r\n else (temp := !temp ^ (String.make 1 s.[j]))\r\n done; rep.(!count)<-(int_of_string !temp) ; rep ;;\r\n\r\n\r\nlet maxes tab = let max1 = ref tab.(0) in let max2 = ref tab.(1) in\r\n for i = 2 to Array.length tab -1 do\r\n if !max1 < !max2 && tab.(i) > !max1 then max1 := tab.(i) ;\r\n if !max1 >= !max2 && tab.(i) > !max2 then max2 := tab.(i) ;\r\n done;\r\n !max1 = !max2 || !max1 = !max2 +1 || !max2 = !max1 +1;;\r\n \r\n\r\n\r\nlet n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let len = int_of_string (input_line stdin) in\r\n let str = input_line stdin in \r\n let tab = parse str len in\r\n if len < 2 then (if tab.(0) = 1 then print_endline \"YES\" else print_endline \"NO\")\r\n else begin\r\n if maxes tab then print_endline \"YES\" else print_endline \"NO\" end\r\ndone;;\r\n \r\n \r\n "}], "src_uid": "8b926a19f380a56018308668c17c6928"} {"source_code": "open Scanf;;\nopen String;;\nopen Num;;\n\nlet mprint z =\n print_endline (Num.string_of_num z);;\n\n\nlet one_jump () = \n let (a,b,k) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d %d \" (fun x y z -> (x,y,z) ) in\n let k2 = (num_of_int (k/2)) in\n let aa = num_of_int a in\n let bb = num_of_int b in\n let rslt = k2*/aa -/ k2*/bb +/ (num_of_int (k mod 2)) */ aa in\n mprint rslt\n;;\n\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\nfor i = 1 to n do\n one_jump ()\ndone\n", "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 () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let a,b,k = get_3_i64 0 in\n let n = k/2L in\n let d = a-b in\n printf \"%Ld\\n\" @@ d * n + (if k mod 2L = 1L then a else 0L)\n )\n\n\n\n\n\n\n\n\n"}, {"source_code": "let ri () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet read_input () =\n let a = ri() and\n b = ri() and\n c = ri() in\n (Int64.of_int a, Int64.of_int b, Int64.of_int c)\n\nlet res a b k = \n let res1 = Int64.mul (Int64.sub a b) (Int64.div k (Int64.of_int 2)) and\n res2 = Int64.mul (Int64.rem k (Int64.of_int 2)) a in\n (*print_int a; print_int b; print_int k; *)\n Int64.add res1 res2\n\nlet solveCase () =\n let (a, b, k) = read_input () in\n let x = res a b k in\n print_endline (Int64.to_string x)\n\nlet rec solve t =\n (*print_int t; print_endline \". test\"; *)\n if t=0 then ()\n else \n (solveCase ();\n solve (t-1))\n\nlet () =\n let t = read_int() in\n solve t\n"}], "negative_code": [{"source_code": "open Scanf;;\nopen String;;\n\nlet one_jump () = \n let (a,b,k) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d %d \" (fun x y z -> (x,y,z) ) in\n let k2 = k/2 in\n let rslt = k2*a - k2*b + (k mod 2) * a in\n print_int rslt; print_string \"\\n\"\n;;\n\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\nfor i = 1 to n do\n one_jump ()\ndone\n"}], "src_uid": "1f435ba837f59b007167419896c836ae"} {"source_code": "open Printf\nopen Scanf\n \nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\n\nlet solve () = \n let n = read_int() in\n let arr = Array.init n read_int in\n Array.sort compare arr;\n let rec loop i = \n if i >= n then (\n printf \"YES\\n\";\n ) else if arr.(i) - arr.(i - 1) > 1 then (\n printf \"NO\\n\";\n ) else (\n loop (i + 1)\n )\n in\n loop 1\n\nlet () =\n let cases = read_int() in\n for case = 1 to cases do\n solve ()\n done", "positive_code": [{"source_code": "let read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet rec fill acc = function\n | 0 -> acc\n | n -> fill (acc @ [read_int ()]) (n - 1)\n\nlet solve (n : int) : string =\n let rec f (l : int list) : string =\n match l with\n | [] \n | [_] -> \"YES\"\n | a :: b :: tl -> if (b - a) > 1 then \"NO\" else f ([b] @ tl)\n in f (List.sort compare (fill [] n))\n\nlet () =\n let t = read_int () in\n for i = 1 to t do\n let n = read_int () in\n Printf.printf \"%s\\n\" (solve n)\n done;\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n \nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\n\nlet solve () = \n let n = read_int() in\n let arr = Array.init n read_int in\n Array.sort compare arr;\n for i = 1 to n - 1 do\n if arr.(i) - arr.(i - 1) > 1 then (\n printf \"NO\\n\";\n ) else if i = n - 1 then (\n printf \"YES\\n\"\n )\n done;\n ()\n\nlet () =\n let cases = read_int() in\n for case = 1 to cases do\n solve ()\n done"}, {"source_code": "open Printf\nopen Scanf\n \nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\n\nlet solve () = \n let n = read_int() in\n let arr = Array.init n read_int in\n Array.sort compare arr;\n let rec loop i = \n if i >= n - 1 then (\n printf \"YES\\n\";\n ) else if arr.(i) - arr.(i - 1) > 1 then (\n printf \"NO\\n\";\n ) else (\n loop (i + 1)\n )\n in\n loop 1\n\nlet () =\n let cases = read_int() in\n for case = 1 to cases do\n solve ()\n done"}], "src_uid": "ed449ba7c453a43e2ac5904dc0174530"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\n \nlet init (x : int) (f : int -> 'a) : 'a list =\n let rec build k =\n if k = x then []\n else (f k) :: build (k + 1) in\n build 0\n;;\n\nlet run () = \n let n = scan_int () in\n let k = scan_int () in\n if n < k || (k mod 2 = 0 && n mod 2 = 1) then\n printf \"NO\\n\"\n else begin\n let lst = \n if n mod 2 = 1 then\n init k (fun x -> if x = 0 then n - k + 1 else 1)\n else if k mod 2 = 1 then\n init k (fun x -> if x = 0 then n - 2 * (k - 1) else 2)\n else\n init k (fun x -> if x = 0 then (n - k + 1) else 1) in\n if List.hd lst < 1 then printf \"NO\\n\"\n else begin\n printf \"YES\\n\";\n List.iter (printf \"%d \") lst;\n print_endline \"\";\n end\n end\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = re () in\n let k = re () in\n if (n mod 2 = 0 && ((k mod 2 = 1 && n < 2 * k) || (k mod 2 = 0 && n < k))) || (n mod 2 = 1 && (n < k || k mod 2 = 0)) then printf \"NO\\n\"\n else let _ = printf \"YES\\n\" in\n for i = 1 to k - 1 do\n if n mod 2 = 0 then\n if k mod 2 = 1 then printf \"%d \" 2\n else printf \"%d \" 1\n else printf \"%d \" 1\n done;\n if n mod 2 = 0 then\n if k mod 2 = 1 then printf \"%d \\n\" (n - 2 * (k - 1))\n else printf \"%d \\n\" (n - (k - 1))\n else printf \"%d \\n\" (n - (k - 1))\n;;\n\nlet _ =\n let t = re () in\n for i = 1 to t do\n solve ()\n done\n;;\n\n"}, {"source_code": "(* Codeforces 1352 B Same Parity Summands train *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec repeat a n = match n with\n | 0 -> []\n | _ -> a :: repeat a (n-1);;\n\nlet rec repeat2 o d k = match k with\n\t| 0 -> []\n\t| _ -> \n\t\tif o == 0 then repeat d k\n\t\telse\n\t\t\t(2 + d) :: repeat2 (o - 2) d (k - 1);;\n\nlet rec summands n k = \n\tif k == 1 then [ n ]\n\telse if n < k then []\n else if n == k then repeat 1 k\n else if n == (k+1) then []\n\telse if (n mod 2) == 1 && (k mod 2) == 0 then []\n\telse\n\t\tlet o = n mod k in\n\t\tlet d = n / k in\n\t\tif (o mod 2) == 0 then\t(d + o) :: repeat d (k-1)\n\t\telse if d == 1 then []\n\t\telse \n\t\t\trepeat2 (o + k) (d - 1) k;;\t\t\n \nlet do_one () = \n let n = gr () in\n let k = gr () in\n\t\tlet suml = summands n k in \n\t\tif (List.length suml) == 0 then print_string \"NO\\n\"\n\t\telse\n\t\t\tbegin\n\t\t\t\tprint_string \"YES\\n\";\n\t\t\t\tprintlisti suml;\n\t\t\t\tprint_string \"\\n\"\n\t\t\tend;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [], "src_uid": "6b94dcd088b0328966b54acefb5c6d22"} {"source_code": "\r\n(** val add : int -> int -> int **)\r\n\r\nlet rec add = Int64.add\r\n\r\n(** val mul : int -> int -> int **)\r\n\r\nlet rec mul = Int64.mul\r\n \r\nlet rec leq x y = Int64.compare x y <= 0\r\n\r\nmodule Nat =\r\n struct\r\n end\r\n\r\n(** val can_distribute : int -> int -> int -> bool **)\r\n\r\nlet can_distribute r b d =\r\n (&&) ((<=) b (mul r (add d (Int64.one))))\r\n ((<=) r (mul b (add d (Int64.one))))\r\n\r\nlet rec solve = function\r\n | 0 -> ()\r\n | n -> let (r,b,d) = Scanf.scanf \"%d %d %d\\n\" (fun a b c -> (Int64.of_int a, Int64.of_int b,Int64.of_int c)) in\r\n let ans = if can_distribute r b d then \"YES\" else \"NO\" in\r\n print_endline ans; \r\n solve (n-1)\r\n\r\nlet t = read_int();;\r\nsolve t;;\r\n", "positive_code": [{"source_code": "(** val add : int64 -> int64 -> int64 **)\r\n\r\nlet rec add = Int64.add\r\n\r\n(** val mul : int64 -> int64 -> int64 **)\r\n\r\nlet rec mul = Int64.mul\r\n\r\nmodule Nat =\r\n struct\r\n (** val leb : int64 -> int64 -> bool **)\r\n\r\n let rec leb = (fun x y -> Int64.compare x y <= 0)\r\n end\r\n\r\n(** val can_distribute : int64 -> int64 -> int64 -> bool **)\r\n\r\nlet can_distribute r b d =\r\n if Nat.leb b\r\n (mul r (add d ((fun x -> Int64.succ x) Int64.zero)))\r\n then Nat.leb r\r\n (mul b (add d ((fun x -> Int64.succ x) Int64.zero)))\r\n else false\r\n\r\nlet rec solve = function\r\n | 0 -> ()\r\n | n -> let (r,b,d) = Scanf.scanf \"%d %d %d\\n\" (fun a b c -> (Int64.of_int a, Int64.of_int b,Int64.of_int c)) in\r\n let ans = if can_distribute r b d then \"YES\" else \"NO\" in\r\n print_endline ans; \r\n solve (n-1)\r\n\r\nlet t = read_int();;\r\nsolve t;;\r\n"}], "negative_code": [{"source_code": "\r\n(** val add : int -> int -> int **)\r\n\r\nlet rec add = (+)\r\n\r\n(** val mul : int -> int -> int **)\r\n\r\nlet rec mul = ( * )\r\n\r\nmodule Nat =\r\n struct\r\n end\r\n\r\n(** val can_distribute : int -> int -> int -> bool **)\r\n\r\nlet can_distribute r b d =\r\n (&&) ((<=) b (mul r (add d (Pervasives.succ 0))))\r\n ((<=) r (mul b (add d (Pervasives.succ 0))))\r\n\r\nlet rec solve = function\r\n | 0 -> ()\r\n | n -> let (r,b,d) = Scanf.scanf \"%d %d %d\\n\" (fun a b c -> (a,b,c)) in\r\n let ans = if can_distribute r b d then \"YES\" else \"NO\" in\r\n print_endline ans; \r\n solve (n-1)\r\n\r\nlet t = read_int();;\r\nsolve t;;\r\n"}], "src_uid": "c0ad2a6d14b0c9e09af2221d88a34d52"} {"source_code": "let (++) = Int64.add\nlet (--) = Int64.sub\nlet ( ** ) = Int64.mul\nlet (//) = Int64.div\n\nlet () =\n let n, q = Scanf.scanf \"%d %d\\n\" (fun x y -> x, y) in\n let a = Array.init n (fun _ -> Scanf.scanf \"%Ld \" (fun x -> x)) in\n let max = ref a.(0)in\n let max_idx = ref 0 in\n for i = 1 to n-1 do\n if a.(i) > !max then begin max := a.(i); max_idx := i end;\n done;\n let b = Array.make (n-1) 0L in\n for i = 0 to n- !max_idx - 2 do\n b.(i) <- a.(!max_idx + 1 + i);\n done;\n let first = ref a.(0) in\n let c = Array.make !max_idx (a.(0), a.(1)) in\n for i = 1 to !max_idx do\n c.(i-1) <- (!first, a.(i));\n if a.(i) <= !first then\n b.(n- !max_idx - 2 + i) <- a.(i)\n else begin\n b.(n- !max_idx - 2 + i) <- !first;\n first := a.(i);\n end;\n done;\n\n for i = 1 to q do\n let m = Scanf.scanf \"%Ld \" (fun x -> x) in\n if m > Int64.of_int !max_idx then begin\n let r = Int64.rem (m -- Int64.of_int !max_idx -- 1L) (Int64.of_int (n-1)) |> Int64.to_int in\n Printf.printf \"%Ld %Ld\\n\" !max b.(r)\n end\n else\n let m = Int64.to_int m in\n let x, y = c.(m-1) in\n Printf.printf \"%Ld %Ld\\n\" x y;\n done\n;;\n", "positive_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\nlet readInt64 () = Scanf.scanf \" %Ld\" (fun x -> x)\n\nlet (++) a b = Int64.add a b\nlet (--) a b = Int64.sub a b\nlet ( ** ) a b = Int64.mul a b\nlet (//) a b = Int64.div a b\nlet (%%) a b = Int64.rem a b\n\ntype solver = {n: int; a: int array; k: int; cyca: int array}\n\nlet precomp (n, a) =\n (* No fold_*i :( *)\n let maxi = ref 0 in\n for i=1 to n-1 do\n if a.(i) > a.(!maxi) then maxi := i\n done;\n let maxi = !maxi in\n let cyca = Array.make (maxi + n) (-1) in\n Array.blit a 0 cyca 0 n;\n for i=0 to maxi-1 do\n let x = cyca.(i) in\n let y = cyca.(i+1) in\n let x = max x y and y = min x y in\n cyca.(i+1) <- x;\n cyca.(i+n) <- y\n done;\n {n; a; k=maxi; cyca}\n\nlet query {n; a; k; cyca} m =\n let m =\n let open Int64 in\n let n = of_int n in\n let k = of_int k in\n to_int (if m < k then m else (m -- k) %% (n -- 1L) ++ k)\n in\n if m < k then (cyca.(m), a.(m+1))\n else (cyca.(k), cyca.(m+1))\n\nlet main () =\n let n = readInt () in\n let q = readInt () in\n let a = Array.init n (fun _ -> readInt ()) in\n let s = precomp (n, a) in\n for i=0 to q-1 do\n let m = readInt64 () -- 1L in\n let (x, y) = query s m in\n Printf.printf \"%d %d\\n\" x y\n done\n\nlet () = main ()\n"}], "negative_code": [], "src_uid": "3cb19ef77e9cb919a2f0a1d687b2845d"} {"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\n\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\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 let k = read_int() in\n let a = Array.init (n+1) (fun i -> if i=0 then 0L else read_long()) in\n let op = Array.init (m+1) (fun i -> if i=0 then (0,0,0L) else \n\t\t\t let l = read_int() in\n\t\t\t let r = read_int() in\n\t\t\t let d = read_long() in\n\t\t\t\t (l,r,d)\n\t\t\t ) in\n let q = Array.init (k+1) (fun i -> if i=0 then (0,0) else\n\t\t\t let l = read_int() in\n\t\t\t let r = read_int() in\n\t\t\t\t(l,r)\n\t\t\t ) in\n \n let opcount = Array.make (m+2) 0L in\n let rcount = Array.make (n+2) 0L in\n \n for i=1 to k do\n let (l,r) = q.(i) in\n opcount.(l) <- opcount.(l) ++ 1L;\n opcount.(r+1) <- opcount.(r+1) -- 1L;\n done;\n\n for i=1 to m do\n opcount.(i) <- opcount.(i-1) ++ opcount.(i)\n done;\n\n for i=1 to m do\n let (l,r,d) = op.(i) in\n\trcount.(l) <- rcount.(l) ++ (d ** opcount.(i));\n\trcount.(r+1) <- rcount.(r+1) -- (d ** opcount.(i));\n done;\n\n for i=1 to n do\n rcount.(i) <- rcount.(i-1) ++ rcount.(i);\n done;\n\n for i=1 to n do\n if i>1 then printf \" \";\n printf \"%Ld\" (rcount.(i) ++ a.(i))\n done;\n\n print_newline()\n\n \n\n\n\n \n\n\n", "positive_code": [{"source_code": "open Printf;;\nopen Scanf;;\nlet getll()=bscanf Scanning.stdib \" %Ld \" (fun x->x);;\nlet getint()=bscanf Scanning.stdib \" %d \" (fun x->x);;\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\nlet n=getint();;\nlet m=getint();;\nlet k=getint();;\nlet aa=Array.init (n+1) (function 0->0L|_->getll());;\nlet o1=Array.init (m+1) (function 0->(0,0,0)|_ -> let a=getint()in let b=getint()in let c=getint() in (a,b,c));;\nlet o2=Array.init (k+1) (function 0->(0,0)|_ -> let a=getint()in let b=getint()in (a,b));;\nlet a=Array.create (m+2) 0;;\nlet b=Array.create (n+2) 0L;;\nfor i=1 to k do\n\tlet l=fst o2.(i)\n\tand r=snd o2.(i) in\n\t\ta.(l)<-a.(l)+1;\n\t\ta.(r+1)<-a.(r+1)-1;\ndone;;\nlet sumup a=let len=Array.length a in for i=1 to len-1 do a.(i)<-a.(i-1)+a.(i); done;;\nlet sumupl a=let len=Array.length a in for i=1 to len-1 do a.(i)<-a.(i-1)++a.(i); done;;\nsumup a;;\nlet ff c=function (l,r,x)->let d=Int64.of_int(x)**Int64.of_int(c)in b.(l)<-b.(l)++d;b.(r+1)<-b.(r+1)--d;;\nfor i=1 to m do ff a.(i) o1.(i); done;;\nsumupl b;;\nfor i=1 to n do\n\tif i>1 then print_char ' ';\n\tprintf \"%Ld\" (aa.(i)++b.(i));\ndone;;\nprint_newline();;\n"}], "negative_code": [], "src_uid": "c3120f96894c17957bd8acb968bf37cd"} {"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\nmodule type GRAPH_LABELS = \n sig \n type label\n end;;\n\n(* Typ modu\u0142u implementuj\u0105cego grafy o wierzcho\u0142kach numerowanych od 0 do n-1. *)\nmodule type GRAPH = \n sig \n (* Etykiety kraw\u0119dzi. *)\n type label\n\n (* Typ graf\u00f3w o wierzcho\u0142kach typu 'a. *)\n type graph\n \n (* Pusty graf. *)\n val init : int -> graph\n\n (* Rozmiar grafu *)\n val size : graph -> int\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_directed_edge : graph -> int -> int -> label -> unit\n\n (* Dodanie kraw\u0119dzi nieskierowanej (dwukierunkowej) \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_edge : graph -> int -> int -> label -> unit\n\n (* Lista incydencji danego wierzcho\u0142ka. *)\n val neighbours : graph -> int -> (int*label) list\n end;;\n\nmodule Graph = functor (L : GRAPH_LABELS) -> \n(struct\n (* Etykiety kraw\u0119dzi. *)\n type label = L.label\n \n (* Typ graf\u00f3w - tablica list s\u0105siedztwa. *)\n type graph = {n : int; e : (int*label) list array}\n \n (* Pusty graf. *)\n let init s = {n = s; e = Array.make s []}\n\n (* Rozmiar grafu. *)\n let size g = g.n\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n let insert_directed_edge g x y l = \n assert ((x<>y) && (x >= 0) && (x < size g) && (y >= 0) && (y < size g));\n g.e.(x) <- (y,l)::g.e.(x)\n \n (* Dodanie kraw\u0119dzi \u0142\u0105cz\u0105cej dwa (istniej\u0105ce) wierzcho\u0142ki. *)\n let insert_edge g x y l =\n insert_directed_edge g x y l;\n insert_directed_edge g y x l\n \n (* Lista incydencji danego wierzcho\u0142ka. *)\n let neighbours g x =\n g.e.(x)\nend : GRAPH with type label = L.label);;\n\nmodule IntLabel = \n struct\n type label = int\n end;;\n\nmodule G = Graph(IntLabel);;\n\nopen G;;\n\nlet n = scan_int();;\nlet m = scan_int();;\n\nlet g = G.init(n);;\nlet values = Array.make n 0;;\n\nfor i = 0 to n - 1 do\n let x = scan_int() in\n values.(i) <- x;\ndone;\n\nfor i = 0 to m - 1 do\n let (x, y) = (scan_int() - 1, scan_int() - 1) in\n insert_edge g x y 1;\ndone;;\n\nlet vis = Array.make n false;;\n\nlet rec dfs x =\n vis.(x) <- true;\n let res = ref values.(x) in\n List.iter (fun(y, _) ->\n if vis.(y) = false then res := min (!res) (dfs y)\n ) (neighbours g x);\n !res;;\n\nopen Int64;;\nlet sumek = ref zero;;\n\nfor i = 0 to n - 1 do\n if vis.(i) = false then sumek := add (!sumek) (Int64.of_int(dfs i));\ndone;\n\nprint_string(Int64.to_string(!sumek));;", "positive_code": [{"source_code": "open Int64;;\nlet scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet n = scan_int() and m= scan_int() in let odw = Array.make n 0 and wyn = ref zero\nand p = Array.init n (fun x ->x) and w = Array.init n (fun x->scan_int()) in\nlet rec find x =\n if p.(x) = x then x\n else begin \n\tp.(x) <- find p.(x);\n p.(x)\n end\nin let uni x y =\n let u = find x and v = find y in\n if u <> v then\n if w.(u) < w.(v) then p.(v) <- u else p.(u) <- v\nin begin for i=1 to m do \n let u = scan_int () and v = scan_int() in uni (u-1) (v-1)\ndone;\nfor i=0 to (n-1) do\n if odw.(find i) = 0 then begin\n odw.(find i) <- 1; wyn := add (!wyn) (Int64.of_int(w.(find i))) end\ndone;\nprint_string(Int64.to_string(!wyn))\nend"}, {"source_code": "open Printf\nopen Scanf\n\nlet ( ++ ) a b = Int64.add a b\n\nlet long x = Int64.of_int x\nlet short x = Int64.to_int 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) 0L\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,m) = read_pair () in\n\n let cost = Array.init n (fun i -> long(read_int())) in\n let comp = Array.make n (-1) in\n\n let graph = Array.make n [] in\n\n for i=0 to m-1 do\n let (u,v) = read_pair() in\n let (u,v) = (u-1,v-1) in\n graph.(u) <- v::graph.(u);\n graph.(v) <- u::graph.(v)\n done;\n \n let rec dfs u p c =\n if comp.(u) = -1 then (\n comp.(u) <- c;\n List.iter (fun v -> if v<>p then dfs v u c) graph.(u)\n )\n in\n\n let rec loop i c = if i=n then c else (\n if comp.(i) = -1 then (\n dfs i (-1) c;\n loop (i+1) (c+1)\n ) else loop (i+1) c\n ) in\n\n let ncomps = loop 0 0 in\n\n let mincomp = Array.make ncomps 1_000_000_001L in\n\n for i=0 to n-1 do\n mincomp.(comp.(i)) <- min cost.(i) mincomp.(comp.(i))\n done;\n\n let answer = sum 0 (ncomps-1) (fun i -> mincomp.(i)) in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet n = scan_int() and m= scan_int() in let odw = Array.make n 0 and wyn = ref 0\nand p = Array.init n (fun x ->x) and w = Array.init n (fun x->scan_int()) in\nlet rec find x =\n if p.(x) = x then x\n else begin \n\tp.(x) <- find p.(x);\n p.(x)\n end\nin let uni x y =\n let u = find x and v = find y in\n if u <> v then\n if w.(u) < w.(v) then p.(v) <- u else p.(u) <- v\nin begin for i=1 to m do \n let u = scan_int () and v = scan_int() in uni (u-1) (v-1)\ndone;\nfor i=0 to (n-1) do\n if odw.(find i) = 0 then begin\n odw.(find i) <- 1; wyn := !wyn + w.(find i) end\ndone;\nprint_int (!wyn)\nend\n"}], "src_uid": "9329cb499f003aa71c6f51556bcc7b05"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet list_init n =\n let rec loop i list = \n if i < n\n then\n let element = read () in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () = \n let n = read () in\n let k = read () in\n let list = list_init n in\n (n, k, list)\n\nlet get_sums list =\n let rec loop list sum sum_list = \n match list with\n | (head :: tail) ->\n let sum = head + sum in\n loop tail sum (sum :: sum_list)\n | [] -> List.rev sum_list\n in loop list 0 [0]\n\nlet solve (n, k, list) =\n let fence = get_sums list in\n let arr = Array.of_list fence in\n let rec loop i j min =\n if i + k <= n\n then\n let diff = arr.(i + k) - arr.(i) in\n if diff < min\n then\n loop (i + 1) i diff\n else\n loop (i + 1) j min\n else\n j + 1\n in loop 0 (n + 1) 1000000000\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 100000000 \n\tand indeks = ref 1 in\n\n\tlet tab = Array.init n read_int \n\tand pref = Array.make (n + 1) 0 in\n\n\tfor i = 1 to n do\n\t\tpref.(i) <- pref.(i - 1) + tab.(i - 1);\n\tdone;\n\n\tfor i = 1 to n - m + 1 do \n\t\tlet roznica = pref.(i + m - 1) - pref.(i - 1) in\n\t\tif roznica < !wyn then begin\n\t\t\twyn := roznica;\n\t\t\tindeks := i;\n\t\tend;\n\tdone;\n\n\tprintf \"%d\\n\" !indeks;;"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 100000000 \n\tand indeks = ref 1 in\n\n\tlet tab = Array.init n read_int \n\tand pref = Array.make (n + 1) 0 in\n\n\tfor i = 1 to n do\n\t\tpref.(i) <- pref.(i - 1) + tab.(i - 1);\n\tdone;\n\n\tfor i = 1 to n - m + 1 do \n\t\tlet roznica = pref.(i + m - 1) - pref.(i) in\n\t\tif roznica < !wyn then begin\n\t\t\twyn := roznica;\n\t\t\tindeks := i;\n\t\tend;\n\tdone;\n\n\tprintf \"%d\\n\" !indeks;;"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet list_init n =\n let rec loop i list = \n if i < n\n then\n let element = read () in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () = \n let n = read () in\n let k = read () in\n let list = list_init n in\n (n, k, list)\n\nlet get_sums list =\n let rec loop list sum sum_list = \n match list with\n | (head :: tail) ->\n let sum = head + sum in\n loop tail sum (sum :: sum_list)\n | [] -> List.rev sum_list\n in loop list 0 [0]\n\nlet solve (n, k, list) =\n let fence = get_sums list in\n let arr = Array.of_list fence in\n let rec loop i j min =\n if i + k < n\n then\n let diff = arr.(i + k) - arr.(i) in\n if diff < min\n then\n loop (i + 1) i diff\n else\n loop (i + 1) j min\n else\n j + 1\n in loop 0 (n + 1) 1500001\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet list_init n =\n let rec loop i list = \n if i < n\n then\n let element = read () in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () = \n let n = read () in\n let k = read () in\n let list = list_init n in\n (n, k, list)\n\nlet get_sums list =\n let rec loop list sum sum_list = \n match list with\n | (head :: tail) ->\n let sum = head + sum in\n loop tail sum (sum :: sum_list)\n | [] -> List.rev sum_list\n in loop list 0 [0]\n\nlet solve (n, k, list) =\n let fence = get_sums list in\n let arr = Array.of_list fence in\n let rec loop i j min =\n if i + k <= n\n then\n let diff = arr.(i + k) - arr.(i) in\n if diff < min\n then\n loop (i + 1) i diff\n else\n loop (i + 1) j min\n else\n j + 1\n in loop 0 (n + 1) 1500001\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))"}], "src_uid": "69f4e340b3f6e1d807e0545ebea1fe2f"} {"source_code": "(* Mish test sort - worked *)\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet debug = false;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec is_sq a n = \n (* let _ = begin print_int a; print_string \"\\n\" end in *)\n\t\tif n < 0 then false\n\t\telse if n==0 || n==1 then true\n else if a*a == n then true\n else if a*a>n then false\n else\n let da = (n - a*a)/(3*a) in\n let da = if da > a then a else da in\n let da = if da < 1 then 1 else da in\n let a1 = a+da in\n is_sq a1 n;;\n\nlet rec max_list mx l = match l with\n\t| [] -> mx\n\t| h :: t -> \n\t\tlet nmx = max mx h in\n\t\tmax_list nmx t;;\n\nlet main() =\n\tlet n = gr() in\n\tlet l = readlist (n) [] in\n\tlet lnsq = List.filter (fun x -> (not (is_sq 1 x))) l in\n\tlet ans = max_list (-100011122) lnsq in\n\tbegin\n\t\tprint_int ans;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;", "positive_code": [{"source_code": "let get_int () = Scanf.scanf \" %d\" (fun i -> i)\nlet get_float () = Scanf.scanf \" %f\" (fun i -> i)\n\nlet is_sqrt x =\n let r = int_of_float @@ sqrt (float_of_int x) in\n r * r = x\n\nlet get_array n =\n let rec aux acc k =\n if k = 0 then acc\n else aux (get_int () :: acc) (k - 1)\n in aux [] n\n\nlet main () =\n let n = get_int () in\n let rec aux m k =\n if k = 0 then m\n else\n let x = get_int () in\n if not (is_sqrt x) && x > m then aux x (k - 1)\n else aux m (k - 1)\n in\n let ans = aux (-1_000_000) n in\n Printf.printf \"%d\" ans\n\nlet () = main ()\n"}], "negative_code": [{"source_code": "let get_int () = Scanf.scanf \" %d\" (fun i -> i)\nlet get_float () = Scanf.scanf \" %f\" (fun i -> i)\n\nlet is_sqrt x =\n let r = int_of_float @@ sqrt (float_of_int x) in\n r * r = x\n\nlet get_array n =\n let rec aux acc k =\n if k = 0 then acc\n else aux (get_int () :: acc) (k - 1)\n in aux [] n\n\nlet main () =\n let n = get_int () in\n let rec aux m k =\n if k = 0 then m\n else\n let x = get_int () in\n if not (is_sqrt x) && x > m then aux x (k - 1)\n else aux m (k - 1)\n in\n let ans = aux 0 n in\n Printf.printf \"%d\" ans\n\nlet () = main ()\n"}], "src_uid": "d46d5f130d8c443f28b52096c384fef3"} {"source_code": "type repost = Leaf of string\n | Node of repost list\n\nlet rec split num str = \n match str with\n | \"\" -> []\n | s ->\n let (beg,rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnStringList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (String.lowercase one) :: (returnStringList t \"\")\n else returnStringList t (one^h)\n | _ -> (String.lowercase one) :: []\n\nlet splitToList line =\n let lineList = split 1 line in\n returnStringList lineList \"\"\n\nlet rec makePairList strList =\n match strList with\n | (a :: b :: c::[]) :: t -> (c,a) :: (makePairList t)\n | _ -> []\n\n\nlet makeNode pairList st =\n let rec nodePair pList str =\n match pList with\n | (a,b) :: t ->\n if (compare a str) == 0 then\n Node (Leaf(b) :: nodePair pairList b) :: nodePair t str\n else nodePair t str\n | _ -> [] in\n Node(Leaf(st) :: nodePair pairList st) :: []\n\nlet rec countNode repost num=\n match repost with\n | Node(h :: t) :: tail ->\n let n = countNode t (num+1) in\n let m = countNode tail num in\n if (n > m) then n else m\n | _ -> num\n\n\nlet printLeaf leaf =\n match leaf with\n | Leaf(a) -> print_string \"[Leaf : \"; print_string a; print_string \" ]\"\n | _ -> print_string \" \"\n\nlet rec printList strList =\n match strList with\n | h :: t ->\n print_string h;print_string \" \";printList t\n | _ -> print_string \"\\n\"\nlet rec printPairList pairList =\n match pairList with\n | (a,b) :: t ->\n print_string a; print_string \" \"; print_string b; print_string \"\\n\";\n printPairList t\n | _ -> print_string\"\\n\"\n\nlet rec printRepost repost =\n match repost with\n | Node (h :: t) :: tail -> \n print_string \"[Node : \";printLeaf h; printRepost t; print_string \" ]\";\n printRepost tail\n | _ -> print_string \" \"\n\n\n\nlet n = read_int()\n\nlet rec strList num = \n if (num > 0) then\n let line = read_line() in\n let lineList = splitToList line in\n lineList :: (strList (num-1))\n else []\nlet pairList = makePairList (strList n)\n\nlet repost = makeNode pairList \"polycarp\"\nlet _ = print_int (countNode repost 0)\n\n", "positive_code": [{"source_code": "type graph = Leaf of string | Node of graph list ;;\nlet tl = read_int() ;;\nlet rec genList num =\n if (num > 0) then\n let line = read_line() in\n let edge = Str.split (Str.regexp \" \") (String.lowercase line) in\n ((List.nth edge 2), (List.nth edge 0)) :: (genList (num-1))\n else []\n \nlet to_graph list_in str1 = \n let rec gen_pair list_in2 str2 = \n match list_in2 with\n | (a,b) :: t ->\n if (compare a str2) == 0 then\n Node (Leaf(b) :: gen_pair list_in2 b) :: gen_pair t str2\n else gen_pair t str2\n | _ -> [] in\n Node(Leaf(str1) :: gen_pair list_in str1) :: []\n\nlet rec count_node graph n =\n match graph with\n | Node(h :: t) :: tail ->\n max (count_node t (n+1)) (count_node tail n)\n | _ -> n\nlet myList = genList tl ;;\nlet graphRep = to_graph myList \"polycarp\" ;;\nprint_int(count_node graphRep 0)\n"}], "negative_code": [], "src_uid": "16d4035b138137bbad247ccd5e560051"} {"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 l = ref (-123456789) in\n let r = ref 123456789 in\n let a, b = ref 0, ref 0 in\n for i = 1 to !n do\n a := read_int();\n b := read_int();\n if !b = 1 then\n l := max !l 1900\n else\n r := min !r 1899;\n l := (!l + !a);\n r := (!r + !a);\n done;\n if !l > !r then Printf.printf \"Impossible\"\n else if !r > 100000000 then Printf.printf \"Infinity\"\n else Printf.printf \"%d\" !r\n\n\n\n\nlet () = main ()", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet () = \n let n = read_int () in\n\n let inf = 1_000_000_000 in\n\n let (++) a b = if abs a = inf then a else a+b in\n \n let rec loop i (lo,hi) = if i=n then (lo,hi) else\n let (c,div) = read_pair() in\n let hi = if div = 2 then min hi 1899 else hi in\n let lo = if div = 1 then max lo 1900 else lo in \n let lo = lo ++ c in\n let hi = hi ++ c in\n if lo > hi then (lo,hi) \n else loop (i+1) (lo,hi)\n in\n\n let (lo,hi) = loop 0 (-inf,inf) in\n\n if lo > hi then printf \"Impossible\\n\"\n else if hi = inf then printf \"Infinity\\n\"\n else printf \"%d\\n\" hi\n"}], "negative_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 l = ref (-min_int) in\n let r = ref max_int in\n let a, b = ref 0, ref 0 in\n for i = 1 to !n do\n a := read_int();\n b := read_int();\n if !b = 1 then\n l := max !l 1900\n else\n r := min !r 1899;\n l := (!l + !a);\n r := (!r + !a);\n done;\n if !l > !r then Printf.printf \"Impossible\"\n else if !r > 100000000 then Printf.printf \"Infinity\"\n else Printf.printf \"%d\" !r\n\n\n\n\nlet () = main ()"}], "src_uid": "2a4c24341231cabad6021697f15d953a"} {"source_code": "let hasMax l r a = r-l+1 >= a || (r mod a < l mod a) ;;\r\n\r\nlet searchMax r a = let toto = r/a in if r mod a = a-1 then (toto + a-1) else toto-1 + a -1;;\r\n\r\nlet n = int_of_string(input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let l,r,a = Scanf.sscanf(input_line stdin)\" %d %d %d\"(fun l r a->l,r,a) in\r\n let toto = if hasMax l r a then searchMax r a else (r/a + r mod a) in\r\n print_endline (string_of_int toto)\r\ndone;\r\n;;", "positive_code": [{"source_code": "(* Codeforces 1638 A Reverse train done *)\r\n \r\n(* you can use either gr or rdln but not both, several gr() - inverted order *)\r\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\r\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\r\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\r\nlet rdln() = input_line stdin;;\r\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\r\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\r\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\r\nlet debug = false;;\r\n \r\n(* reading list *)\r\nlet rec readlist n acc = match n with\r\n\t| 0 -> List.rev acc\r\n\t| _ -> readlist (n -1) (gr() :: acc);;\r\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\r\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\r\nlet list_to_s li = String.concat \" \" (List.map string_of_int li);;\r\n\r\n\r\nlet do_one () = \r\n let a,r,l = gr(), gr(), gr() in\r\n (* let _ = Printf.printf \"l,r,a = %d %d %d\\n\" l r a in *)\r\n let dl = l / a in\r\n let dr = r / a in\r\n let oor = r mod a in\r\n let mx = if dl == dr then dr + oor\r\n else \r\n let dr1 = if oor==a-1 then dr else dr-1 in\r\n dr1 + a - 1 in\r\n (print_int mx; print_string \"\\n\");;\r\n \r\nlet do_all () = \r\n let t = gr () in\r\n for i = 1 to t do\r\n do_one ()\r\n done;;\r\n \r\nlet main() =\r\n\tdo_all ();;\r\n \r\nmain();;"}], "negative_code": [{"source_code": "let hasMax l r a = r-l+1 >= a || (r mod a < l mod a) ;;\r\n\r\nlet searchMax r a = let toto = r/a in if r mod a = a-1 then (toto + a-1) else toto-1 + a -1;;\r\n\r\nlet n = int_of_string(input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let l,r,a = Scanf.sscanf(input_line stdin)\" %d %d %d\"(fun l r a->l,r,a) in\r\n let toto = if hasMax l r a then searchMax r a else (r/a + r mod a) in\r\n prerr_endline (string_of_int toto)\r\ndone;\r\n;;"}], "src_uid": "681ee82880ddd0de907aac2ccad8fc04"} {"source_code": "(* OCaml template *)\nopen Printf\nopen Scanf\n\n(* Redefine operators for Int64 *)\nlet ( + ) = Int64.add;;\nlet ( - ) = Int64.sub;;\nlet ( * ) = Int64.mul;;\nlet ( / ) = Int64.div;;\nlet ( % ) = Int64.rem;;\n\n(* Input *)\nlet read_int _ = bscanf Scanning.stdin \"%d \" @@ fun x -> x;;\nlet read_int64 _ = bscanf Scanning.stdin \"%Ld \" @@ fun x -> x;;\n\n(* Output *)\nlet print_int n = printf \"%d \" n;;\nlet print_int_endl n = printf \"%d\\n\" n;;\nlet print_int64 n = printf \"%Ld \" n;;\nlet print_int64_endl n = printf \"%Ld\\n\" n;;\n\n(* Utility functions *)\n(*\nlet sum = List.fold_left (+) 0;;\n*)\n\n(* Solve test case *)\nlet rec solve n = if n = 2L then 1L else n * solve (n - 1L) % 1000000007L;;\n\n(* Main *)\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int64 () in\n\t\tprint_int64_endl @@ solve @@ 2L * n\ndone\n\n", "positive_code": [{"source_code": "(* OCaml template *)\n\n(* Redefine operators for Int64 *)\nlet ( + ) = Int64.add;;\nlet ( - ) = Int64.sub;;\nlet ( * ) = Int64.mul;;\nlet ( / ) = Int64.div;;\nlet ( % ) = Int64.rem;;\n\n(* Utility functions *)\nlet sum = List.fold_left (+) 0L;;\n\n(* Main *)\nlet m = 1000000007L;;\n\nlet rec solve (n:int64) = if n = 2L then 1L else n * solve (n - 1L) % m;;\n\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int () in\n\t\tprint_endline @@ Int64.to_string @@ solve @@ 2L * Int64.of_int n\ndone\n"}, {"source_code": "(* OCaml template *)\n\n(* Utility functions *)\nlet sum = List.fold_left (+) 0;;\n\n(* Main *)\nlet m = 1000000007L;;\n\nlet rec solve (n:int64) = if n = 2L then 1L else Int64.rem (Int64.mul n (solve (Int64.pred n))) m;;\n\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int () in\n\t\tprint_endline @@ Int64.to_string @@ solve @@ Int64.mul 2L (Int64.of_int n)\ndone\n"}], "negative_code": [{"source_code": "(* OCaml template *)\n\ntype int = int64;;\n\n(* Utility functions *)\nlet print_int_endline n = print_endline @@ string_of_int n\nlet sum = List.fold_left (+) 0;;\n\nlet rec solve n = if n = 2 then 1 else n * solve (n - 1) mod 1000000007;;\n\n(* Main *)\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int () in\n\t\tprint_int_endline @@ solve @@ 2 * n\ndone\n"}, {"source_code": "(* OCaml template *)\n\n(* Utility functions *)\nlet sum = List.fold_left (+) 0;;\n\n(* Main *)\nlet m = 1000000007;;\n\nlet rec solve (n:int) = if n = 2 then 1 else n * solve (n - 1) mod m;;\n\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int () in\n\t\tprint_endline @@ string_of_int @@ solve @@ 2 * n;\ndone\n"}], "src_uid": "19a2550af6a46308fd92c7a352f12a5f"} {"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet licz x = (x-|Int64.one)/|two_64;;\n\nlet _ = \n let (n,k) = Scanf.scanf \"%d %d\\n\" (fun x y-> x, y) in\n let ile = Array.make 1000001 0 \n and tab = Array.make 1000001 0\n and id = ref 1\n and wyn = ref 0\n and obc = ref 1\n and suma = ref 0 in\n for i=1 to n do\n let x = read (n-i) in\n tab.(i) <- x;\n if ile.(x) = 0 then incr suma;\n ile.(x) <- ile.(x) + 1;\n while !suma > k do\n ile.( tab.(!obc) ) <- ile.( tab.(!obc) ) - 1;\n if ile.( tab.(!obc) ) = 0 then suma := !suma - 1;\n incr obc\n done;\n if i - !obc + 1 > !wyn then begin\n id := !obc;\n wyn := i - !obc + 1\n end\n done;\n Printf.printf \"%d %d\\n\" !id (!id + !wyn -1 ) ;;\n\n\n", "positive_code": [{"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = xint() and k = xint() in\n let a = Array.make n 0 in\n let c = Array.make 1000001 0 in\n for i = 0 to n - 1 do\n a.(i) <- xint();\n done;\n let add x =\n c.(x) <- c.(x) + 1;\n if c.(x) = 1 then 1 else 0\n in\n let sub x =\n c.(x) <- c.(x) - 1;\n if c.(x) = 0 then 1 else 0;\n in\n let j = ref 0 and tot = ref 0 in\n let sx = ref 0 and sy = ref ~-1 in\n for i = 0 to n - 1 do\n tot := !tot + (add a.(i));\n while !tot > k do\n tot := !tot - (sub a.(!j));\n j := !j + 1;\n done;\n if i - !j > !sy - !sx then (\n sx := !j;\n sy := i;\n );\n done;\n sx := !sx + 1;\n sy := !sy + 1;\n Printf.printf \"%d %d\\n\" !sx !sy;\n"}], "negative_code": [], "src_uid": "e0ea798c8ce0d8a4340e0fa3399bcc3b"} {"source_code": "module My_int64 = \nstruct\n let ( + ) = Int64.add\n let ( - ) = Int64.sub\n let zero = Int64.zero\n let one = Int64.one\nend\n\nopen My_int64\n\nlet read () = Scanf.scanf \"%Ld \" (fun n -> n)\n\nlet input () = \n let houses = read () in\n let jobs = read () in\n let rec loop job_houses i =\n if i < jobs\n then\n let job_house = read () in\n loop (job_house :: job_houses) (i + one)\n else\n (houses, (List.rev job_houses)) \n in loop [] zero\n\nlet solve (houses, job_houses) =\n let rec loop count last list =\n match list with\n | (head :: tail) ->\n if head < last\n then\n loop (count + (houses - last) + head) head tail\n else\n loop (count + head - last) head tail \n | [] -> count\n in loop zero one job_houses\n\nlet print result = Printf.printf \"%Ld\\n\" result\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "let (n, m) = Scanf.scanf \"%Ld %d\\n\" (fun x y -> (x, y)) in\nlet pos = ref Int64.one in\nlet t = ref Int64.zero in\nfor i = 1 to m do\n let p = Scanf.scanf \"%Ld%[ ]\" (fun x _ -> x) in\n t := Int64.add !t (Int64.rem (Int64.sub (Int64.add p n) !pos) n) ;\n pos := p\ndone ;\nPrintf.printf \"%Ld\\n\" !t ;;\n"}], "negative_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let houses = read () in\n let jobs = read () in\n let rec loop job_houses i =\n if i < jobs\n then\n let job_house = Scanf.scanf \"%d \" (fun n -> n) in\n loop (job_house :: job_houses) (i + 1)\n else\n (houses, jobs, (List.rev job_houses)) \n in loop [] 0\n\nlet solve (houses, jobs, job_houses) =\n let rec loop count last list =\n match list with\n | (head :: tail) ->\n if head < last\n then\n loop (count + (houses - last) + head) head tail\n else\n loop (count + head - last) head tail \n | [] -> count\n in loop 0 1 job_houses\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}], "src_uid": "2c9c96dc5b6f8d1f0ddeea8e07640d3e"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet solve () = \n let n = read () in\n let rec loop i unsolved police = \n if i < n\n then\n let temp = read () in\n if temp < 0\n then\n if police >= 1\n then\n loop (i + 1) unsolved (police - 1)\n else\n loop (i + 1) (unsolved + 1) police\n else\n loop (i + 1) unsolved (police + temp)\n else\n unsolved\n in loop 0 0 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let rec loop unsolved police = function\n | 0 -> unsolved\n | n ->\n let x = read_int () in\n if x < 0 then\n if police > 0 then\n loop unsolved (police - 1) (n - 1)\n else\n loop (unsolved + 1) police (n - 1)\n else\n loop unsolved (police + x) (n - 1)\n in Printf.printf \"%d\\n\" (loop 0 0 n)\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet read_int () = scanf \" %d\" (fun x -> x)\n\nlet n = read_int ()\nlet a = Array.init n (fun i -> read_int ())\n\nlet comp (s, r) x = \n match (x, s) with\n | (-1, 0) -> (0, r + 1)\n | _ -> (s + x, r)\n\nlet () = printf \"%d\\n\" (snd (Array.fold_left comp (0, 0) a))\n"}], "negative_code": [], "src_uid": "af47635f631381b4578ba599a4f8b317"} {"source_code": "open Scanf;;\nopen Printf;;\nopen Str;;\n\nlet split_by_space = split (regexp \" +\")\n\ntype token = P | I\n\nlet token_of_str = function\n \"pair\" -> P\n | \"int\" -> I\n | _ -> failwith \"hoge\"\n \nlet input () =\n let n = int_of_string(read_line ()) in\n let str = read_line () in\n (n, List.map token_of_str (split_by_space str))\n\ntype tree = Pair of (tree * tree) | Int\n\nlet solve ls =\n let rec solve = function\n [] -> failwith \"\"\n | P::ls -> \n let (res1, ls) = solve ls in\n let (res2, ls) = solve ls in\n (Pair (res1, res2), ls)\n | I::ls ->\n (Int, ls) in\n let (res, ls) = solve ls in\n match ls with\n [] -> res\n | _ -> failwith \"\"\n\nlet rec print_res = function\n Pair(x, y) -> \n print_string \"pair<\";\n print_res x;\n print_string \",\";\n print_res y;\n print_string \">\"\n | Int ->\n print_string \"int\"\n \nlet () = \n let (n, ss) = input () in\n (* List.iter (fun x -> printf \"%s\\n\" x) ss; *)\n try \n let res = solve ss in\n print_res res;\n print_string \"\\n\"\n with\n Failure _ -> print_endline \"Error occurred\"\n \n", "positive_code": [{"source_code": "type t0 = P | I\ntype t1 = Pair of t1 * t1 | Int\n\nlet _ =\n let rec dump k =\n match k with\n | Int -> print_string \"int\"\n | Pair (a, b) -> print_string \"pair<\";dump a;print_string \",\"; dump b; print_string \">\"\n in\n\n let main () =\n let _ = read_int () in\n let s = read_line () in\n let l = String.length s in\n let rec loop p acc =\n if p >= l then acc else\n if s.[p] = 'p' then loop (p + 4) (P :: acc) else\n if s.[p] = 'i' then loop (p + 3) (I :: acc) else\n loop (p + 1) acc\n in\n let k = List.rev (loop 0 []) in\n let rec parse = function\n | [] -> None\n | I :: tl -> Some (Int, tl)\n | P :: tl -> (\n match parse tl with\n | None -> None\n | Some (a, tl2) -> (\n match parse tl2 with\n | None -> None\n | Some (b, tl3) -> Some (Pair (a, b), tl3)\n )\n )\n in\n match parse k with\n | Some (a, []) -> dump a; print_newline ()\n | _ -> print_endline \"Error occurred\"\n in\n main ()\n"}], "negative_code": [], "src_uid": "6587be85c64a0d5fb66eec0c5957cb62"} {"source_code": "(* Input *)\nlet (num_students, num_drink_types) = Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y));;\n\nlet rec read_rev_int_list n =\n if n == 0\n then []\n else (Scanf.scanf \"%d\\n\" (fun x -> x - 1)) :: read_rev_int_list(n - 1)\n;;\n\nlet student_drink_types = List.rev (read_rev_int_list (num_students));;\n\n(* Process *)\nlet favorite_counts = Array.make num_drink_types 0;;\nList.iter (fun tp -> (favorite_counts.(tp) <- favorite_counts.(tp) + 1)) student_drink_types;;\n\nlet num_leftout = ref 0;;\nArray.iter (fun cnt -> num_leftout := !num_leftout + (cnt mod 2)) favorite_counts;;\n\nlet result = num_students - !num_leftout + (!num_leftout + 1) / 2;;\nPrintf.printf \"%d\\n\" result;;", "positive_code": [{"source_code": "(* Input *)\nlet (num_students, num_drink_types) = Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y));;\nlet student_drink_types =\n let rec read_int_list = function\n | 0 -> []\n | n -> (Scanf.scanf \"%d\\n\" (fun x -> x - 1)) :: read_int_list (n - 1)\n in\n List.rev (read_int_list num_students)\n;;\n\n(* Process *)\nlet favorite_counts = Array.make num_drink_types 0;;\nList.iter (fun tp -> (favorite_counts.(tp) <- favorite_counts.(tp) + 1)) student_drink_types;;\n\nlet num_leftout = Array.fold_left (fun a b -> a + b mod 2) 0 favorite_counts;;\nlet result = num_students - num_leftout + (num_leftout + 1) / 2;;\nPrintf.printf \"%d\\n\" result;;\n"}], "negative_code": [], "src_uid": "dceeb739a56bb799550138aa8c127996"} {"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\nmodule IMap = Map.Make(Int64)\nlet appearance a = (* (value,count) *)\n Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n,k = get_2_i64 0 in\n let a = input_i64_array n in\n let ls =\n let mp = appearance a in\n IMap.bindings mp |> List.map (fun (k,v) -> (v,k))\n |> List.sort (fun u v -> compare v u)\n in\n (* print_list (fun (v,k) -> sprintf \"%Ld(%Ld) \" v k) ls; *)\n let constr d =\n let ans = ref [] in\n List.iter (fun (c,v) ->\n let p = c / d in\n rep 1L p (fun _ -> ans := v::!ans)\n ) ls;\n (* printf \"%Ld : %s\\n\" d (string_of_list ist !ans); *)\n !ans in\n let check d =\n if llen @@ constr d >= k then true\n else false\n in\n let d = binary_search n 0L (fun d -> check d) in\n (* constr d |> List.iter (fun v -> printf \"%Ld \" v) *)\n constr d |> of_list |> iteri (fun i v ->\n if i=0 then printf \"%Ld\" v\n else if i x)\n\n let read_one_number () =\n let rslt= read_one \"%d \" in\n rslt\n\n let read_array n a =\n for i = 0 to n-1 do\n let r = read_one_number () in\n a.(i) <- r\n done\n\nend\n\n(*The solutions*)\nlet nn = 200002;;\n\nlet n = U.read_one_number ()\nlet k = U.read_one_number ()\nlet a = Array.make n 0\nlet b = Array.make nn 0\nlet () = U.read_array n a;;\n\nlet () = Array.iter (fun x-> b.(x) <- b.(x) + 1 ) a;;\nlet c = Array.mapi (fun i x -> (i,x) ) b;;\n\nlet my_compare h1 h2 =\n let (_,v1) = h1 in\n let (_,v2) = h2 in\n compare v2 v1;;\n\nlet d = c\n |> Array.to_list\n |> List.filter (fun h -> let (_,v) = h in v > 0 )\n |> List.sort (fun h1 h2 -> my_compare h1 h2)\n |> Array.of_list\n;;\n\nlet dl = Array.length d;;\n\n(* This function determines if cc copies is possible*)\nlet is_possible cc =\n let flag = true in\n let total = ref 0 in \n for i = 0 to dl -1 do\n let (_,v1) = d.(i) in\n total := !total + v1 / cc\n done;\n if !total < k then\n flag = false\n else\n true\n;;\n\nlet rec binary_search s e = \n if s == e then\n s\n else if e - s == 1 then\n if is_possible e then\n e\n else\n s\n else\n begin\n let mid = (s+e) / 2 in\n if is_possible mid then\n binary_search mid e\n else\n binary_search s (mid - 1)\n end\n;;\n\nlet rslt = binary_search 1 n;;\n\n(*\nlet () =\n Printf.printf \"%B %d\\n\" (is_possible 2) rslt\n\nlet () =\n Array.iter (fun (k1,v1) -> Printf.printf \"%d %d\\n\" k1 v1) d\n *)\n\n\nlet () = \n let nx = ref k in\n for i = 0 to dl -1 do\n let (k1,v1) = d.(i) in\n let m = v1 / rslt in\n if m > 0 && !nx >0 then\n let test = !nx - m in\n if test >=0 then\n begin\n for i = 0 to m-1 do\n Printf.printf \"%d \" k1\n done;\n nx := test\n end \n else\n begin\n for i = 0 to !nx-1 do\n Printf.printf \"%d \" k1\n done;\n nx := 0\n end\n done\n\n\n\n"}], "negative_code": [{"source_code": "(*This file is to test the environment used by the judge*)\n\nprint_int max_int; print_endline;;\n"}, {"source_code": "(* Problem 2 of round 521*)\n(* Comments:\n To make this program is even faster, I need to have in the function 'cut'\n l1 to be an array, use another integer (starting from k) to indicate stop.\n\n But this is so boring, I better use C.\n\n*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet k = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet my_find s x =\n try Some (H.find s x)\n with\n Not_found -> None\n;;\n\nlet () = Array.iter (fun x-> \n match my_find t x with\n None -> H.add t x 1\n | Some z -> H.replace t x (1+z)\n ) a\n;;\n\n\nlet my_compare h1 h2 =\n let (_,v1) = h1 in\n let (_,v2) = h2 in\n if v1 > v2 then 1\n else if v1 == v2 then 0\n else -1;;\n\nlet ll = H.fold (fun k v x -> (k,v) :: x) t [];;\n\nif n==k then\n print_int (List.length ll); print_endline \"\";;\n\nlet lr = List.stable_sort my_compare ll\n |> List.rev;;\n(*\nlet () =\n List.iter (fun h ->\n let (k,v) = h in Printf.printf \"%d %d\\n\" k v\n ) lr;;\n *)\n\nlet rec cut l1 l2 =\n let n1 = List.length l1 in\n if List.length l2 == k then\n l2\n else\n begin\n if n1 == 1 then\n (List.hd l1) :: l2\n else\n begin\n let h1 :: _ = l1 in\n let h2 :: _ = List.tl l1 in\n let (k1,a1) = h1 in\n let (_,a2) = h2 in\n if a1 < 2*a2 then\n cut (List.tl l1) (h1 :: l2)\n else\n cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)\n end\n end\n;;\n\nif n==k then\n begin\n print_int (List.length lr); print_endline \"\";\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) lr\n end\nelse\n begin\n let rslt = cut lr [] in\n if List.length rslt < k then\n begin\n print_int 0; print_endline \"\"\n end\n else\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) rslt;\n end\n;;\n"}, {"source_code": "(* Problem 2 of round 521*)\n(* Comments:\n To make this program is even faster, I need to have in the function 'cut'\n l1 to be an array, use another integer (starting from k) to indicate stop.\n\n But this is so boring, I better use C.\n\n*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet k = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet my_find s x =\n try Some (H.find s x)\n with\n Not_found -> None\n\nlet total = ref 0\n\nlet () = Array.iter (fun x-> \n let y = my_find t x in\n match y with\n None -> H.add t x 1\n | Some z -> H.replace t x (1+z)\n ) a\n;;\n\nlet my_compare h1 h2 =\n let (_,v1) = h1 in\n let (_,v2) = h2 in\n if v1 > v2 then 1\n else if v1 == v2 then 0\n else -1;;\n\nlet ll = H.fold (fun k v x -> (k,v) :: x) t [];;\n\nlet lr = List.stable_sort my_compare ll\n |> List.rev;;\n(*\nlet () =\n List.iter (fun h ->\n let (k,v) = h in Printf.printf \"%d %d\\n\" k v\n ) lr;;\n *)\n\nlet rec cut l1 l2 =\n let n1 = List.length l1 in\n if List.length l2 == k then\n l2\n else\n begin\n if n1 == 1 then\n (List.hd l1) :: l2\n else\n begin\n let h1 :: _ = l1 in\n let h2 :: _ = List.tl l1 in\n let (k1,a1) = h1 in\n let (_,a2) = h2 in\n if a1 < 2*a2 then\n cut (List.tl l1) (h1 :: l2)\n else\n cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)\n end\n end\n;;\n\nif n==k then\n List.iter (fun h ->\n let (k,_) = h in Printf.printf \"%d \" k\n ) lr\nelse\n begin\n let rslt = cut lr [] in\n if List.length rslt < k then\n begin\n print_int 0; print_endline \"\"\n end\n else\n List.iter (fun h ->\n let (k,_) = h in Printf.printf \"%d \" k\n ) rslt;\n end\n;;\n"}, {"source_code": "(* Problem 2 of round 521*)\n(* Comments:\n To make this program is even faster, I need to have in the function 'cut'\n l1 to be an array, use another integer (starting from k) to indicate stop.\n\n But this is so boring, I better use C.\n\n*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet k = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet my_find s x =\n try Some (H.find s x)\n with\n Not_found -> None\n\nlet total = ref 0\n\nlet () = Array.iter (fun x-> \n let y = my_find t x in\n match y with\n None -> H.add t x 1\n | Some z -> H.replace t x (1+z)\n ) a\n;;\n\nlet my_compare h1 h2 =\n let (_,v1) = h1 in\n let (_,v2) = h2 in\n if v1 > v2 then 1\n else if v1 == v2 then 0\n else -1;;\n\nlet ll = H.fold (fun k v x -> (k,v) :: x) t [];;\n\nlet lr = List.stable_sort my_compare ll\n |> List.rev;;\n(*\nlet () =\n List.iter (fun h ->\n let (k,v) = h in Printf.printf \"%d %d\\n\" k v\n ) lr;;\n *)\n\nlet rec cut l1 l2 =\n let n1 = List.length l1 in\n if List.length l2 == k then\n l2\n else\n begin\n if n1 == 1 then\n (List.hd l1) :: l2\n else\n begin\n let h1 :: _ = l1 in\n let h2 :: _ = List.tl l1 in\n let (k1,a1) = h1 in\n let (_,a2) = h2 in\n if a1 < 2*a2 then\n cut (List.tl l1) (h1 :: l2)\n else\n cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)\n end\n end\n;;\n\nif n==k then\n begin\n print_int (List.length lr); print_endline \"\";\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) lr\n end\nelse\n begin\n let rslt = cut lr [] in\n if List.length rslt < k then\n begin\n print_int 0; print_endline \"\"\n end\n else\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) rslt;\n end\n;;\n"}, {"source_code": "(* Problem 2 of round 521*)\n(* Comments:\n To make this program is even faster, I need to have in the function 'cut'\n l1 to be an array, use another integer (starting from k) to indicate stop.\n\n But this is so boring, I better use C.\n\n*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet k = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet my_find s x =\n try Some (H.find s x)\n with\n Not_found -> None\n\nlet total = ref 0\n\nlet () = Array.iter (fun x-> \n let y = my_find t x in\n match y with\n None -> H.add t x 1\n | Some z -> H.replace t x (1+z)\n ) a\n;;\n\nlet my_compare h1 h2 =\n let (_,v1) = h1 in\n let (_,v2) = h2 in\n if v1 > v2 then 1\n else if v1 == v2 then 0\n else -1;;\n\nlet ll = H.fold (fun k v x -> (k,v) :: x) t [];;\n\nlet lr = List.stable_sort my_compare ll\n |> List.rev;;\n(*\nlet () =\n List.iter (fun h ->\n let (k,v) = h in Printf.printf \"%d %d\\n\" k v\n ) lr;;\n *)\n\nlet rec cut l1 l2 =\n let n1 = List.length l1 in\n if List.length l2 == k then\n l2\n else\n begin\n if n1 == 1 then\n (List.hd l1) :: l2\n else\n begin\n let h1 :: _ = l1 in\n let h2 :: _ = List.tl l1 in\n let (k1,a1) = h1 in\n let (_,a2) = h2 in\n if a1 < 2*a2 then\n cut (List.tl l1) (h1 :: l2)\n else\n cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)\n end\n end\n;;\n\nif n==k then\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) lr\nelse\n begin\n let rslt = cut lr [] in\n if List.length rslt < k then\n begin\n print_int 0; print_endline \"\"\n end\n else\n List.iter (fun h ->\n let (i,_) = h in Printf.printf \"%d \" i\n ) rslt;\n end\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\nmodule IMap = Map.Make(Int64)\nlet appearance a = (* (value,count) *)\n Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n,k = get_2_i64 0 in\n let a = input_i64_array n in\n let ls =\n let mp = appearance a in\n IMap.bindings mp |> List.map (fun (k,v) -> (v,k))\n |> List.sort (fun u v -> compare v u)\n in\n (* print_list (fun (v,k) -> sprintf \"%Ld(%Ld) \" v k) ls; *)\n let constr d =\n let ans = ref [] in\n List.iter (fun (c,v) ->\n let p = c / d in\n rep 1L p (fun _ -> ans := v::!ans)\n ) ls;\n (* printf \"%Ld : %s\\n\" d (string_of_list ist !ans); *)\n !ans in\n let check d =\n if llen @@ constr d >= k then true\n else false\n in\n let d = binary_search n 0L (fun d -> check d) in\n constr d |> print_list ist\n\n (* let r = make 20010 [] in\n IMap.iter (fun p q ->\n (* if q=k then r := (p+1L)::!r *)\n (* arr.(i32 q) <- p::arr.(i32 q) *)\n r.(i32 q) <- p::r.(i32 q)\n ) mp;\n let ls = ref [] in\n iteri (fun c v -> if List.length v<>0 then ls:=(c,v)::!ls) r;\n (* let r = List.sort (fun u v -> -compare u v) !r in *)\n let ls = !ls |> List.sort (fun u v -> -compare u v) in\n let d = binary_search n 0L (fun d ->\n (* printf \"%Ld\\n\" d; *)\n let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in\n let _,f = List.fold_left (fun (sum,f) (v,ls) ->\n let ne = sum + v * (llen ls) in\n (* printf \"%Ld %Ld\\n\" v ne; *)\n if ne >= k then (ne,true) else (ne,f)\n ) (0L,false) l\n in f\n ) in\n let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in\n let rest = ref k in\n let _,f = List.fold_left (fun (sum,f) (v,ls) ->\n let ne = (v * llen ls) in\n if ne <= !rest then (\n rep 0L (ne-1L) (fun i ->\n let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list\n in printf \"%Ld \" b.(i32 i)\n );\n rest -= ne; (sum,f)\n ) else (\n let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list in\n rep 0L (!rest) (fun i ->\n printf \"%Ld \" b.(i32 i)\n ); (sum,f)\n )\n (* if >= k then (ne,true) else (ne,f) *)\n ) (0L,false) l\n in\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\nmodule IMap = Map.Make(Int64)\nlet appearance a = (* (value,count) *)\n Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n,k = get_2_i64 0 in\n let a = input_i64_array n in\n let ls =\n let mp = appearance a in\n IMap.bindings mp |> List.map (fun (k,v) -> (v,k))\n |> List.sort (fun u v -> compare v u)\n in\n (* print_list (fun (v,k) -> sprintf \"%Ld(%Ld) \" v k) ls; *)\n let constr d =\n let ans = ref [] in\n List.iter (fun (c,v) ->\n let p = c / d in\n rep 1L p (fun _ -> ans := v::!ans)\n ) ls;\n (* printf \"%Ld : %s\\n\" d (string_of_list ist !ans); *)\n !ans in\n let check d =\n if llen @@ constr d >= k then true\n else false\n in\n let d = binary_search n 0L (fun d -> check d) in\n constr d |> List.iter (fun v -> printf \"%Ld \" v)\n\n (* let r = make 20010 [] in\n IMap.iter (fun p q ->\n (* if q=k then r := (p+1L)::!r *)\n (* arr.(i32 q) <- p::arr.(i32 q) *)\n r.(i32 q) <- p::r.(i32 q)\n ) mp;\n let ls = ref [] in\n iteri (fun c v -> if List.length v<>0 then ls:=(c,v)::!ls) r;\n (* let r = List.sort (fun u v -> -compare u v) !r in *)\n let ls = !ls |> List.sort (fun u v -> -compare u v) in\n let d = binary_search n 0L (fun d ->\n (* printf \"%Ld\\n\" d; *)\n let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in\n let _,f = List.fold_left (fun (sum,f) (v,ls) ->\n let ne = sum + v * (llen ls) in\n (* printf \"%Ld %Ld\\n\" v ne; *)\n if ne >= k then (ne,true) else (ne,f)\n ) (0L,false) l\n in f\n ) in\n let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in\n let rest = ref k in\n let _,f = List.fold_left (fun (sum,f) (v,ls) ->\n let ne = (v * llen ls) in\n if ne <= !rest then (\n rep 0L (ne-1L) (fun i ->\n let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list\n in printf \"%Ld \" b.(i32 i)\n );\n rest -= ne; (sum,f)\n ) else (\n let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list in\n rep 0L (!rest) (fun i ->\n printf \"%Ld \" b.(i32 i)\n ); (sum,f)\n )\n (* if >= k then (ne,true) else (ne,f) *)\n ) (0L,false) l\n in\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\nmodule IMap = Map.Make(Int64)\nlet appearance a = (* (value,count) *)\n Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n,k = get_2_i64 0 in\n let a = input_i64_array n in\n let ls =\n let mp = appearance a in\n IMap.bindings mp |> List.map (fun (k,v) -> (v,k))\n |> List.sort (fun u v -> compare v u)\n in\n (* print_list (fun (v,k) -> sprintf \"%Ld(%Ld) \" v k) ls; *)\n let constr d =\n let ans = ref [] in\n List.iter (fun (c,v) ->\n let p = c / d in\n rep 1L p (fun _ -> ans := v::!ans)\n ) ls;\n (* printf \"%Ld : %s\\n\" d (string_of_list ist !ans); *)\n !ans in\n let check d =\n if llen @@ constr d >= k then true\n else false\n in\n let d = binary_search n 0L (fun d -> check d) in\n (* constr d |> List.iter (fun v -> printf \"%Ld \" v) *)\n constr d |> of_list |> iteri (fun i v ->\n (if i=0 then printf \"%Ld\"\n else printf \" %Ld\") v\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\nmodule IMap = Map.Make(Int64)\nlet arr = make 50 []\nlet appearance a = (* (value,count) *)\n let open IMap in Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n,k = get_2_i64 0 in\n let a = input_i64_array n in\n let mp = appearance a in\n let r = ref [] in\n IMap.iter (fun p q ->\n (* if q=k then r := (p+1L)::!r *)\n arr.(i32 q) <- p::arr.(i32 q)\n ) mp;\n let n_max = IMap.fold (fun _ v u -> max v u) mp 0L in\n (* iteri (fun i r ->\n if List.length r<>0 then\n printf \"%d : %s\\n\" i (string_of_list ist r);\n ) arr; *)\n let amari = ref 0 in\n (* let r_amari = ref [] in *)\n rep_rev n_max 1L (fun p ->\n let p = i32 p in\n if !amari +$ List.length arr.(p) >= i32 k then (\n (* print_list ist arr.(i32 p); *)\n if List.length arr.(p) >= i32 k then (\n let a = arr.(p) |> of_list in\n repi 0 (p) (fun i -> printf \"%Ld \" a.(i));\n exit 0;\n ) else (\n let rest = ref @@ i32 k -$ (List.length arr.(p)) in\n let a = arr.(p) |> of_list in\n repi 0 (length a-$1) (fun i -> printf \"%Ld \" a.(i));\n let q,res = ref @@ p+$1,ref [] in\n while !rest > 0 do\n (* printf \"%d:\\n \" !rest;\n print_list ist !res; *)\n match arr.(!q) with\n | [] -> (q := !q +$ 1)\n | ls -> (\n (* let b = arr.(!q) |> of_list in *)\n let v = List.length arr.(!q) in\n let lls = make !q 0L |> to_list |> List.map (fun _ -> ls) |> List.flatten\n |> of_list\n in\n (* print_array ist lls; *)\n let r = ref 0 in\n while !rest > 0 && !r < length lls do\n res := lls.(!r) :: !res;\n r := !r +$ 1;\n rest := !rest -$ 1\n done;\n if !rest = 0 then (\n print_list ist !res; exit 0\n ) else (q := !q +$ 1)\n )\n done\n\n )\n ) else (\n let q = List.length arr.(p) in\n amari := !amari +$ q *$ p;\n (* r_amari := ()::!r_amari *)\n )\n );\n (* print_array (string_of_list ist) arr; *)\n (* print_list ist !r *)\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "cfccf06c4d0de89bf0978dc6512265c4"} {"source_code": "\nlet read_pair () = \n let s = read_line () in \n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n match nums with\n | [a;b] -> (a, b)\n | _ -> (0, 0)\n\n;;\n\nlet rec get_pair n (a, b)= \n if n > 0 then\n match read_pair () with\n | (x, y) -> if x > y then\n get_pair (n-1) (a+1, b)\n else if x < y then\n get_pair (n-1) (a, b+1)\n else\n get_pair (n-1) (a, b)\n\n else\n (a, b)\n\n;;\n\nlet read_nums () = \n let n = read_int () in\n let (a, b) = get_pair n (0, 0) in\n if a = b then\n print_string \"Friendship is magic!^^\\n\"\n else if a > b then\n print_string \"Mishka\\n\"\n else\n print_string \"Chris\\n\"\n;;\n\n\nread_nums () ;;\n", "positive_code": [{"source_code": "let n = read_line () |> int_of_string in\nlet scores = Array.init n (fun x -> read_line()) \n |> Array.map (fun x -> let b = Str.split (Str.regexp \" *\") x |> List.map int_of_string in (List.nth b 0, List.nth b 1)) |> Array.to_list in\nlet (m,c) = List.split scores in\nlet sum = List.fold_left ( + ) 0 in\nprint_string (match List.map2 compare m c |> sum with\n | 0 -> \"Friendship is magic!^^\"\n | e when e > 0 -> \"Mishka\"\n | _ -> \"Chris\"\n) \n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n) \nlet print result = Printf.printf \"%s\\n\" result\n\nlet count () =\n let n = read () in\n let rec loop i count_a count_b =\n if i < n\n then\n let a = read () in\n let b = read () in\n if a > b\n then\n loop (i + 1) (count_a + 1) count_b\n else\n if a < b\n then\n loop (i + 1) count_a (count_b + 1)\n else\n loop (i + 1) count_a count_b\n else\n (count_a, count_b)\n in loop 0 0 0\n\nlet solve (count_a, count_b) =\n if count_a > count_b\n then\n print \"Mishka\"\n else\n if count_a < count_b\n then\n print \"Chris\"\n else\n print \"Friendship is magic!^^\"\n\nlet () = solve (count ())"}], "negative_code": [{"source_code": "\nlet read_pair () = \n let s = read_line () in \n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n match nums with\n | [a;b] -> (a, b)\n | _ -> (0, 0)\n\n;;\n\nlet rec get_pair n (a, b)= \n if n > 0 then\n match read_pair () with\n | (a, b) -> if a > b then\n get_pair (n-1) (a+1, b)\n else if a < b then\n get_pair (n-1) (a, b+1)\n else\n get_pair (n-1) (a, b)\n\n else\n (a, b)\n\n;;\n\nlet read_nums () = \n let n = read_int () in\n let (a, b) = get_pair n (0, 0) in\n if a = b then\n print_string \"Friendship is magic!^^\\n\"\n else if a > b then\n print_string \"Mishka\\n\"\n else\n print_string \"Chris\\n\"\n;;\n\n\nread_nums () ;;\n"}, {"source_code": "let n = read_line () |> int_of_string in\nlet scores = Array.init n (fun x -> read_line()) \n |> Array.map (fun x -> let b = Str.split (Str.regexp \" *\") x |> List.map int_of_string in (List.nth b 0, List.nth b 1)) |> Array.to_list in\nlet (m,c) = List.split scores in\nlet sum = List.fold_left ( + ) 0 in\nprint_string (match List.map2 compare m c |> sum with\n | 0 -> \"Friendship is magic!^^\"\n | e when e > 0 -> \"Minska\"\n | _ -> \"Chris\"\n) \n"}], "src_uid": "76ecde4a445bbafec3cda1fc421e6d42"} {"source_code": "let n = int_of_string (read_line ())\r\n\r\nlet solve () = \r\n let s = read_line () in\r\n let first = (Char.code s.[0]) - 97 in\r\n let second = (Char.code s.[1]) - 97 in\r\n if second < first then\r\n Printf.printf \"%d\\n\" ((26 * first) + second - (first - 1))\r\n else\r\n Printf.printf \"%d\\n\" ((26 * first) + second - first)\r\n;;\r\nfor i = 0 to n - 1 do\r\n solve ()\r\ndone;;", "positive_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet readBerland () = Scanf.scanf \" %c%c\" (fun a b -> a, b);;\r\n\r\nlet convertCharsToAlphabetPos = function\r\n | a, b -> (Char.code a) - 97, (Char.code b) - 97\r\n;;\r\nlet getBerlandPos = function\r\n | a, b -> \r\n if ba then a*25+b-1\r\n else raise (Failure \"Value Err!\")\r\n;;\r\n\r\nlet rec iterator = function\r\n | 0 -> 0\r\n | n -> \r\n let a, b = convertCharsToAlphabetPos (readBerland ()) in \r\n (* Add 1 as we aren't zero indexing *)\r\n print_int ((getBerlandPos (a, b))+1);\r\n print_newline ();\r\n iterator (n-1)\r\n;;\r\n\r\nlet test_cases = readInt () in iterator test_cases;;\r\n\r\n"}], "negative_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet readBerland () = Scanf.scanf \" %c%c\" (fun a b -> a, b);;\r\n\r\nlet convertCharsToAlphabetPos = function\r\n | a, b -> (Char.code a) - 97, (Char.code b) - 97\r\n;;\r\nlet getBerlandPos = function\r\n | a, b -> a*26+b \r\n;;\r\n\r\nlet rec iterator = function\r\n | 0 -> 0\r\n | n -> \r\n let a, b = convertCharsToAlphabetPos (readBerland ()) in \r\n print_int (getBerlandPos (a, b));\r\n print_newline ();\r\n iterator (n-1)\r\n;;\r\n\r\nlet test_cases = readInt () in iterator test_cases;;\r\n\r\n"}], "src_uid": "2e3006d663a3c7ad3781aba1e37be3ca"} {"source_code": "let main () =\n let gr () = Scanf.scanf \" %d\" (fun i -> i) in \n let gs () = Scanf.scanf \" %s\" (fun i -> i) in \n \n let print_ans x y z s = \n Printf.printf \"%d %d %d\\n\" (s - x) (s - y) (s - z)\n in\n let p = gr () in\n let r = gr() in\n let s = gr() in\n let t = gr() in\n if p+r+s == 2 * t then print_ans p r s t\n else if p + r + t == 2 * s then print_ans p r t s\n else if p + s + t == 2 * r then print_ans p s t r\n else print_ans r s t p\n\nlet _ = main();;\n", "positive_code": [{"source_code": "let scan_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n;;\n\nlet f () = \n let b = Array.init 4 (fun x -> scan_int ()) in\n Array.sort compare b;\n b\n;;\n\nlet _ =\n let arr = f () in\n Printf.printf \"%d %d %d\\n\" (arr.(3) - arr.(0)) (arr.(3) - arr.(1)) (arr.(3) - arr.(2))\n;;\n"}], "negative_code": [], "src_uid": "cda949a8fb1f158f3c06109a2d33f084"} {"source_code": "type 'a el = {\n v : 'a;\n mutable next : 'a el option;\n mutable prev : 'a el option;\n}\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n (* book weights *)\n let w = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* reading order *)\n let b = Array.init m (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x - 1)) in\n (* seen array *)\n let seen = Array.make n false in\n (* head of pile *)\n let p = { v = b.(0); next = None; prev = None } in\n let hd = ref p in\n (* tail of pile *)\n let tl = ref p in\n seen.(b.(0)) <- true;\n\n let add i =\n let el = { v = i; next = None; prev = Some !tl } in\n !tl.next <- Some el;\n tl := el\n in\n\n (* construct the pile *)\n Array.iter (fun b ->\n if not seen.(b) then begin\n add b;\n seen.(b) <- true\n end\n ) b;\n let c = Array.fold_left (fun acc b ->\n let rec part a h =\n if h.v = b then (a, h)\n else match h.next with\n | None -> failwith \"No more list!\"\n | Some n -> part (a + w.(h.v)) n\n in\n let (cost, h) = part 0 !hd in\n let () = match h.prev with\n | None -> () (* already at head *)\n | Some p -> begin\n p.next <- h.next;\n\n let () = match h.next with\n | None -> ()\n | Some n -> n.prev <- Some p\n in\n h.next <- Some !hd;\n h.prev <- None;\n !hd.prev <- Some h;\n hd := h\n end\n in\n acc + cost\n ) 0 b in\n Printf.printf \"%d\\n\" c\n)\n", "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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let n = read_int () in\n let m = read_int () in\n \n let w = Array.init n (fun _ -> read_int()) in\n let b = Array.init m (fun _ -> read_int() - 1) in\n\n let indices = Array.make n 0 in\n let locator = Array.make n 0 in\n \n let h = Hashtbl.create 10 in\n\n let place = ref 0 in\n\n for j=0 to m-1 do\n if not (Hashtbl.mem h b.(j)) then (\n Hashtbl.replace h b.(j) true;\n indices.(!place) <- b.(j);\n locator.(b.(j)) <- !place;\n place := !place + 1;\n )\n done;\n\n (* some books may never be read and thus not be in this data structure.\n I don't think this matters. They'll never be accessed below. *)\n\n\n let swap j =\n let (a,b) = (indices.(j), indices.(j+1)) in\n locator.(a) <- locator.(a) + 1;\n locator.(b) <- locator.(b) - 1;\n indices.(j) <- b;\n indices.(j+1) <- a;\n in\n\n let read_book k =\n let i = locator.(k) in\n let weight = ref 0 in\n for j=i-1 downto 0 do\n (* swap the books at positions j+1 and j *)\n weight := !weight + w.(indices.(j));\n swap j;\n done;\n !weight\n in\n\n let answer = sum 0 (m-1) (fun j -> read_book b.(j)) in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "a18edcadb31f76e69968b0a3e1cb7e3e"} {"source_code": "\n\nlet input () =\n let l = ref []\n in let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let n = getNumber ()\n in begin\n for i = 0 to n - 1 do\n l := (getNumber ()) :: !l\n done;\n !l\n end;;\n\nlet divideList l =\n let l = List.sort compare l\n in let l1 = List.filter (fun x -> x = 1) l\n in let l2 = List.filter (fun x -> x = 2) l\n in (l1, l2)\n\nlet rec firstStep a l1 l2 =\n match l1, l2 with\n | x1 :: t1, x2 :: t2 -> firstStep (a + 1) t1 t2\n | _ -> (a, l1)\n\nlet rec secondStep a = function\n | x :: y :: z :: t -> secondStep (a + 1) t\n | _ -> a\n\nlet teams (l1, l2) =\n let n, newL1 = firstStep 0 l1 l2\n in secondStep n newL1\n\nlet main () =\n let l = input ()\n in let n = teams (divideList l)\n in Printf.printf \"%d\" n\n;;\n\nmain ();;\n", "positive_code": [{"source_code": "\n\nlet input () =\n let l = ref []\n in let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let n = getNumber ()\n in begin\n for i = 0 to n - 1 do\n l := (getNumber ()) :: !l\n done;\n !l\n end;;\n\nlet divideList l =\n let l = List.sort compare l\n in let l1 = List.filter (fun x -> x = 1) l\n in let l2 = List.filter (fun x -> x = 2) l\n in (l1, l2)\n\nlet rec firstStep a l1 l2 =\n match l1, l2 with\n | x1 :: t1, x2 :: t2 -> firstStep (a + 1) t1 t2\n | _ -> (a, l1)\n\nlet rec secondStep a = function\n | x :: y :: z :: t -> secondStep (a + 1) t\n | _ -> a\n\nlet teams (l1, l2) =\n let n, newL1 = firstStep 0 l1 l2\n in secondStep n newL1\n\nlet altMethod l =\n let rec int a1 a2 = function\n | 1 :: t -> int (a1 + 1) a2 t\n | 2 :: t -> int a1 (a2 + 1) t\n | _ -> (a1, a2)\n in let n1, n2 = int 0 0 l\n in if n1 > n2 then\n n2 + (n1 - n2) / 3\n else\n n1\n\nlet main () =\n let l = input ()\n in let n = altMethod l\n in Printf.printf \"%d\" n\n;;\n\nmain ();;\n"}, {"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\n let rec loop n1 n2 i = if i=n then (n1,n2) else\n if read_int() = 1 then loop (n1+1) n2 (i+1)\n else loop n1 (n2+1) (i+1)\n in\n\n let (n1, n2) = loop 0 0 0 in\n\n if n2 >= n1 then printf \"%d\\n\" n1\n else printf \"%d\\n\" (n2 + (n1-n2)/3)\n"}], "negative_code": [], "src_uid": "6c9cbe714f8f594654ebc59b6059b30a"} {"source_code": "(*\r\nConsider the following:\r\n\r\ni) kmod4=0:\r\n means bmod4=0\r\nor anod4=0\r\nor amod4=bmod4=2\r\n-> (4,),(8,),...\r\n-> (,4),(,8),...\r\n-> (2,6),(10,14),...\r\n-> (1,4),(3,8),(5,12),...\r\n-> not possible\r\n\r\nii) kmod4=1\r\namod4=3 or bmod4=0 \r\nor (amod4=1 and bmod4=2)\r\n->(1,2),(5,6),...\r\n->(3,),(7,),...\r\n->(,4),(8,),...\r\n->(1,2),(3,4),(5,6),...\r\n-> possible when n is even\r\n\r\niii) kmod4=2\r\namod4=2 or bmod4=0\r\nor (amod4=0 and bmod4=2)\r\n->(4,2),(8,6),(12,10),...\r\n->(2,1),(6,5),(10,9)...\r\n->(3,4),(7,8),(11,12),...\r\n->(2,1),(3,4),(6,5),...\r\n-> possible when n is even\r\n\r\niv) kmod4=3\r\namod4=1 or bmod4=0\r\nor (amod4=3 and bmod4=2)\r\n->(1,),(5,),(9,)...\r\n->(,4),(,8),...\r\n->(3,2),(7,6),...\r\n->(1,2),(5,6),...\r\n->(3,4),(7,8)...\r\n->(1,2),(3,4),(5,6),....\r\n-> possible when n is even\r\n*)\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x->x);;\r\nlet read_long () = Scanf.scanf \" %Ld\" (fun l->l);;\r\nlet run_case = function\r\n| () ->\r\n let n = read_long () in\r\n let k = read_long () in\r\n let remk = Int64.sub k (Int64.mul 4L (Int64.div k 4L)) in\r\n if (remk=0L) then Printf.printf \"NO\\n\"\r\n else if (remk=2L) then begin\r\n Printf.printf \"YES\\n\";\r\n let rec pairPrint = function\r\n | x, r ->\r\n if (x>n) then ()\r\n else if (r=false) then begin\r\n Printf.printf \"%Ld %Ld\\n\" x (Int64.succ x);\r\n pairPrint ((Int64.add x 2L), true)\r\n end\r\n else begin\r\n Printf.printf \"%Ld %Ld\\n\" (Int64.succ x) x;\r\n pairPrint ((Int64.add x 2L), false)\r\n end\r\n in pairPrint (1L,true)\r\n end\r\n else begin\r\n Printf.printf \"YES\\n\";\r\n let rec pairPrint =function\r\n | x ->\r\n if (x>n) then ()\r\n else begin\r\n Printf.printf \"%Ld %Ld\\n\" x (Int64.succ x);\r\n pairPrint (Int64.add x 2L)\r\n end\r\n in pairPrint 1L\r\n end\r\n;;\r\n\r\n\r\nlet rec iter_cases = function\r\n| 0 -> ()\r\n| t -> run_case (); iter_cases (t-1)\r\n;;\r\n\r\nlet t = read_int () in iter_cases t;;", "positive_code": [{"source_code": "\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\n\nlet () =\n let t = read_int () in\n for _ = 1 to t do\n let n = read_int () in\n let k' = read_int () in\n if (k' mod 4 = 0) then print_endline \"NO\"\n else begin\n print_endline \"YES\";\n let k = k' mod 4 in\n for i = 0 to n / 2 - 1 do\n let x = 2 * i + 1 in\n let y = 2 * i + 2 in\n if ((x + k) * y mod 4 = 0) then\n pf \"%d %d\\n\" x y\n else\n pf \"%d %d\\n\" y x\n done;\n end;\n done;"}], "negative_code": [], "src_uid": "d4fc7e683f389e0c7bbee8e115cef459"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) in\nlet n = scan_int () in\nlet h = scan_int () in\n\nlet rec read_n_ints n =\n if n = 0 then []\n else (scan_int ()) :: (read_n_ints (n-1)) in\n\nlet l = read_n_ints n in\n\nPrintf.printf \"%d\\n\" (n + (List.length (List.filter (fun hh -> hh > h) l)))", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let total = read () in\n let limit = read () in\n let rec loop heights i =\n if i < total\n then\n let height = Scanf.scanf \"%d \" (fun h -> h) in\n loop (height :: heights) (i + 1)\n else\n (total, limit, heights) \n in loop [] 0\n\nlet solve (total, limit, heights) = \n let double_width = List.length (List.filter (fun n -> n > limit) heights) in\n let single_width = total - double_width in\n let total_width = single_width + 2 * double_width in\n Printf.printf \"%d\\n\" total_width\n\nlet () = solve (input ())"}, {"source_code": "open !Scanf \nopen !Printf\n\nlet read_int () = bscanf Scanning.stdin \"%d \" (fun x -> x) \n\nlet () = \n let n = read_int () in \n let h = read_int () in \n\n let rec solve n h = \n match n with \n | 0 -> 0\n | _ -> (if read_int () <= h then 1 else 2) + solve (n-1) h\n \n in printf \"%d\" (solve n h)"}, {"source_code": "(* Codeforces 677 A VaniaFence *)\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet debug = false;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec widlist li zh = match li with\n| [] -> 0\n| h :: t -> (if (h > zh) then 2 else 1) +\n\t(widlist t zh);;\n\nlet main() =\n\tlet n = gr() in\n\tlet h = gr() in\n\tlet a = readlist (n) [] in\n\tlet wid = widlist a h in\n\tbegin\n\t\tprint_int wid;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let res = ref 0 in\n for i = 1 to n do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif x > h\n\tthen res := !res + 2\n\telse res := !res + 1;\n done;\n Printf.printf \"%d\\n\" !res\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac + (f i))\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let n = read_int () in\n let h = read_int () in\n \n let answer = sum 1 n (\n fun _ -> let y = read_int() in\n\t if y > h then 2 else 1\n ) 0 in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "e7ed5a733e51b6d5069769c3b1d8d22f"} {"source_code": "open Big_int;;\n\nlet main () =\n\tlet (n,d) = Scanf.scanf \"%d %d\" (fun i j -> (i,j)) and l = ref []\n\tin\n\t\tfor i=1 to n do\n\t\t\tScanf.scanf \" %d %s\" (fun i j -> l := (i,big_int_of_string j)::!l);\n\t\tdone;\n\tlet tab = Array.of_list (List.sort (fun (i,_) (j,_) -> compare i j) !l) and i = ref 0\n\tand j = ref 0 in\n\tlet act = ref (snd (tab.(0))) and maxi= ref (big_int_of_int 0) in\n\t\twhile !j < n do\n\t\t\tif fst (tab.(!j)) - fst (tab.(!i)) < d\n\t\t\t\tthen (\n\t\t\tmaxi := max_big_int !maxi !act;incr j;if !j < n then act := add_big_int !act (snd (tab.(!j))))\n\t\t\t\telse (act := sub_big_int !act (snd (tab.(!i))); incr i);\n\t\tdone;\n\tPrintf.printf \"%s\" (string_of_big_int !maxi);;\n\nmain ();;\n", "positive_code": [{"source_code": "let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin \" %s \" (fun x -> Big_int.big_int_of_string x);;\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x);;\nlet read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;\nlet comp (a, b) (c, d) = if (Big_int.compare_big_int a c) = 0 then Big_int.compare_big_int b d else Big_int.compare_big_int a c;; \nlet main () = \n let n = read_int () in\n let d = read_int64 () in\n let a = Array.init n read_pair in\n let _ = Array.sort comp a in\n let (i, j, k, c) = (ref 0, ref 0, ref (Big_int.big_int_of_int 0), ref (Big_int.big_int_of_int 0)) in (\n while !i < n do (\n match (a.(!i), a.(!j)) with\n | ((x, y), (z, w)) -> (\n if Big_int.compare_big_int (Big_int.sub_big_int x z) d < 0 then\n (k := (Big_int.add_big_int !k y); c := (Big_int.max_big_int (!c) (!k)); incr i)\n else \n (k := (Big_int.sub_big_int !k w); incr j)\n )\n )\n done;\n Printf.printf \"%s\\n\" (Big_int.string_of_big_int !c)\n )\n;;\n\nmain ();;"}, {"source_code": "let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> Int64.of_int x);;\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x);;\nlet read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;\nlet comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;; \nlet main () = \n let n = read_int () in\n let d = read_int64 () in\n let a = Array.init n read_pair in\n let _ = Array.sort comp a in\n let (i, j, k, c) = (ref 0, ref 0, ref 0L, ref 0L) in (\n while !i < n do (\n match (a.(!i), a.(!j)) with\n | ((x, y), (z, w)) -> (\n if Int64.compare (Int64.sub x z) d < 0 then\n (k := (Int64.add !k y); c := (max (!c) (!k)); incr i)\n else \n (k := (Int64.sub !k w); incr j)\n )\n )\n done;\n Printf.printf \"%s\\n\" (Int64.to_string !c)\n )\n;;\nmain ();;\n"}], "negative_code": [{"source_code": "let main () =\n\tlet (n,d) = Scanf.scanf \"%d %d\" (fun i j -> (i,j)) and l = ref []\n\tin\n\t\tfor i=1 to n do\n\t\t\tScanf.scanf \" %d %d\" (fun i j -> l := (i,j)::!l);\n\t\tdone;\n\tlet tab = Array.of_list (List.sort compare !l) and i = ref 0\n\tand j = ref 0 in\n\tlet act = ref (snd (tab.(0))) and maxi= ref 0 in\n\t\twhile !j < n do\n\t\t\tif fst (tab.(!j)) - fst (tab.(!i)) < d\n\t\t\t\tthen (\n\t\t\tmaxi := max !maxi !act;incr j;if !j < n then act := !act + snd (tab.(!j)))\n\t\t\t\telse (act := !act - snd (tab.(!i)); incr i);\n\t\tdone;\n\tPrintf.printf \"%d\" !maxi;;\n\nmain ();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x);;\nlet read_pair _ = let x = read_int () in let y = read_int () in (x, y);;\nlet comp a b = if a < b then -1 else if a = b then 0 else 1;;\nlet main () = \n let n = read_int () in\n let d = read_int () in\n let a = Array.init n read_pair in\n let _ = Array.sort comp a in\n let (i, j, k, c) = (ref 0, ref 0, ref 0, ref 0) in (\n while !i < n do (\n match (a.(!i), a.(!j)) with\n | ((x, y), (z, w)) -> (\n if x - z < d then\n (k := !k + y; c := max (!c) (!k); incr i)\n else \n (k := !k - w; incr j)\n )\n )\n done;\n Printf.printf \"%d\\n\" (!c)\n )\n;;\n\nmain ();;\n"}], "src_uid": "38fe0e19974a7bc60153793b9060369a"} {"source_code": "let divBy3 x =\n let rec loop acc x' =\n if x' <= 1 then Some acc\n else if (x' mod 3) = 0 then loop (acc + 1) (x' / 3)\n else None\n in loop 0 x\n\nlet divBy6 x =\n let rec loop acc x' =\n if (x' mod 6) = 0 then loop (acc + 1) (x' / 6) else acc\n in loop 0 x\n\nlet rec without6 x =\n if (x mod 6) = 0 then without6 (x / 6) else x\n\nlet solveFor x =\n match divBy3 (without6 x) with\n | None -> -1\n | Some x' -> (divBy6 x) + (x' * 2)\n\nlet read_int () = Scanf.scanf \"%d \" (fun x -> x)\n\nlet () =\n for i = 1 to (read_int ()) do\n read_int ()\n |> solveFor\n |> Printf.printf \"%d\\n\"\n done\n", "positive_code": [{"source_code": "open Printf\n\nlet rec divide a b c = if a mod b = 0 then divide (a / b) b (c + 1) else (a,c)\n\nlet main =\n let n = read_int() in\n for i = 1 to n do\n let x = read_int() in\n let (y,n2) = divide x 2 0 in\n let (z,n3) = divide y 3 0 in\n if z <> 1 || n2 > n3 then\n printf \"-1\\n\"\n else \n printf \"%d\\n\" (2 * n3 - n2)\n done"}], "negative_code": [], "src_uid": "3ae468c425c7b156983414372fd35ab8"} {"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))\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\t\t\t\t \nlet () = \n let a = read_string () in\n let b = read_string () in\n\n let n = String.length a in\n let m = String.length b in \n\n let a = Array.init n (fun i -> if a.[i] = '1' then 1 else 0) in\n let b = Array.init m (fun i -> if b.[i] = '1' then 1 else 0) in \n\n let sigma = Array.make (m+1) 0 in\n\n for i=1 to m do\n sigma.(i) <- sigma.(i-1) + b.(i-1)\n done;\n\n (* sigma.(x) = sum of b's from b.(0) to b.(x-1) *)\n\n let sum_range i j = sigma.(j+1) - sigma.(i) in\n\n let answer = sum 0 (n-1) (fun i ->\n let first = i in\n let last = m-n+i in\n let nones = sum_range first last in\n long (if a.(i) = 1 then (last-first+1) - nones else nones)\n ) 0L in\n\n printf \"%Ld\\n\" answer\n \n\n \n \n", "positive_code": [{"source_code": "let v s i = int_of_char( s.[i] ) - 48 ;;\nlet a, b = Scanf.scanf \"%s %s\" (fun a b -> (a,b)) ;;\n\nlet rec bsum = function\n | 0 -> 0\n | i -> (v b (i-1) ) + bsum (i-1)\n;;\nlet cmplen = String.length b - String.length a ;;\nlet (+^), to64 = Int64.(add, of_int) ;;\nlet rec f i cs =\n if i = String.length a\n then 0L\n else let cs2 = cs + v b (cmplen+i) in\n to64 (if v a i = 0 then cs2 else cmplen+1-cs2)\n +^ f (i+1) (cs2 - v b i)\n;;\nPrintf.printf \"%Ld\" (f 0 (bsum cmplen))\n"}], "negative_code": [{"source_code": "let v s i = int_of_char( s.[i] ) - 48 ;;\nlet a, b = Scanf.scanf \"%s %s\" (fun a b -> (a,b)) ;;\n\nlet rec bsum = function\n | 0 -> 0\n | i -> (v b (i-1) ) + bsum (i-1)\n;;\nlet cmplen = String.length b - String.length a ;;\n\nlet rec f i cs =\n if i = String.length a\n then 0\n else let cs2 = cs + v b (cmplen+i) in\n (if v a i = 0 then cs2 else cmplen+1-cs2)\n + f (i+1) (cs2 - v b i)\n;;\nprint_int @@ f 0 (bsum cmplen)\n"}], "src_uid": "ed75bd272f6d3050426548435423ca92"} {"source_code": "open Scanf;;\nlet 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() and maxN = 1007;;\nlet tab = Array.make maxN 0;;\n\nfor i = 1 to n do\n let x = scan_int() in\n tab.(x) <- (tab.(x) + 1);\ndone;;\n\nlet cnt = ref 0 and maxik = ref 0;;\nfor i = 1 to (maxN - 1) do\n cnt := (!cnt + b2i(tab.(i) > 0));\n maxik := max (!maxik) tab.(i); \ndone;;\n\nprint_int !maxik; psp(); print_int !cnt;\n", "positive_code": [{"source_code": "module Int = struct\n\tlet compare = compare\n\ttype t = int\nend;;\n\nmodule IntMap = Map.Make(Int);;\n\nlet rec solve i bruski =\n\tif i = 0 then (\n\t\tlet l = IntMap.fold (fun _ _ l -> l + 1) bruski 0 in\n\t\tlet max = IntMap.fold (fun _ h m -> max h m) bruski 0 in\n\t\tPrintf.printf \"%d %d\" max l\n\t) else (\n\t\tlet w = Scanf.scanf \" %d\" (fun i->i) in\n\t\tlet nbruski = IntMap.add w ((if IntMap.mem w bruski \n\t\t\tthen IntMap.find w bruski else 0) + 1) bruski in\n\t\tsolve (i-1) nbruski\n\t)\n;;\n\nlet () =\n\tsolve (read_int()) IntMap.empty\n;;\n"}], "negative_code": [], "src_uid": "9a92221c760a3b6a1e9318f948fe0473"} {"source_code": "let [zer;on;two;fou] = List.map Big_int.big_int_of_int [0;1;2;4]\n\n\nlet (+) = Big_int.add_big_int\nlet (-) = Big_int.sub_big_int\nlet ( * ) = Big_int.mult_big_int\nlet (mod) = Big_int.mod_big_int\nlet (=) = Big_int.eq_big_int\nlet (<=) a b = Big_int.compare_big_int a b <= 0\n\nlet xor_betw a b =\n let x = ref (a * (a mod two)) in\n let beg = ref (b + (a mod two) - ((b-a) mod fou)) in\n while !beg <= b do\n x := Big_int.xor_big_int !beg !x;\n beg := !beg + on;\n done;\n !x\n\nlet main () =\n let n = Scanf.scanf \"%d\" (fun i -> i) and a = ref zer in\n for i = 1 to n do\n Scanf.scanf \" %s %s\" (fun x' m' ->\n let [x;m] = List.map Big_int.big_int_of_string [x';m'] in\n a := Big_int.xor_big_int !a (xor_betw x (x+m-on)));\n done;\n print_endline (if !a = zer then \"bolik\" else \"tolik\");;\n\nmain ();;\n", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib \" %Ld\" (fun x -> x)\nlet (|>) x f = f x\n\nopen Int64\n\nlet () =\n let z = ref 0L in\n for i = 1 to read_int 0 do\n let x = read_int64 0 |> ref in\n let y = read_int64 0 |> ref in\n y := add !y !x;\n while !x < !y && rem !x 4L <> 0L do\n z := logxor !z !x;\n x := add !x 1L\n done;\n while !x < !y && rem !y 4L <> 0L do\n y := sub !y 1L;\n z := logxor !z !y\n done\n done;\n print_endline (if !z <> 0L then \"tolik\" else \"bolik\")\n"}, {"source_code": "let [zer;on;two;fou] = List.map Big_int.big_int_of_int [0;1;2;4]\n\n\nlet (+) = Big_int.add_big_int\nlet (-) = Big_int.sub_big_int\nlet ( * ) = Big_int.mult_big_int\nlet (mod) = Big_int.mod_big_int\nlet (=) = Big_int.eq_big_int\nlet (<=) a b = Big_int.compare_big_int a b <= 0\n\nlet xor_betw a b =\n let x = ref (a * (a mod two)) in\n let beg = ref (b + (a mod two) - ((b-a) mod fou)) in\n while !beg <= b do\n x := Big_int.xor_big_int !beg !x;\n beg := !beg + on;\n done;\n !x\n\nlet main () =\n let n = Scanf.scanf \"%d\" (fun i -> i) and a = ref zer in\n for i = 1 to n do\n Scanf.scanf \" %s %s\" (fun x' m' ->\n let [x;m] = List.map Big_int.big_int_of_string [x';m'] in\n a := Big_int.xor_big_int !a (xor_betw x (x+m-on)));\n done;\n print_endline (if !a = zer then \"bolik\" else \"tolik\");;\n\nmain ();;"}], "negative_code": [{"source_code": "let xor_betw a b =\n let x = ref 0 in\n if a mod 2 = 1 then x := a;\n for i = b + 1 - ((b-a) mod 4) to b do\n x := i lxor !x;\n done;\n !x\n\nlet main () =\n let n = Scanf.scanf \"%d\" (fun i -> i) and a = ref 0 in\n for i = 1 to n do\n Scanf.scanf \" %d %d\" (fun x m->a := !a lxor (xor_betw x (x+m-1)));\n done;\n print_endline (if !a = 0 then \"bolik\" else \"tolik\");;\n\nmain ();;\n"}, {"source_code": "let n = Scanf.scanf \"%d\" (fun i -> i) and res = ref 0 in\n for i=1 to n-1 do\n Scanf.scanf \" %s\"\n (fun w -> res := !res + int_of_char (w.[String.length w - 1]));\n done;\nPrintf.printf (if !res mod 2 = 0 then \"bolik\" else \"tolik\");;\n"}, {"source_code": "let n = Scanf.scanf \"%d\" (fun i -> i) and res = ref 0 in\n for i=1 to n do\n Scanf.scanf \" %s %s\"\n (fun _ w -> res := !res + int_of_char (w.[String.length w - 1]));\n done;\nPrintf.printf (if !res mod 2 = 0 then \"bolik\" else \"tolik\");;\n"}, {"source_code": "let n = Scanf.scanf \"%d\" (fun i -> i) and res = ref 0 in\n for i=1 to n do\n Scanf.scanf \" %s\"\n (fun w -> res := !res + int_of_char (w.[String.length w - 1]));\n done;\nPrintf.printf (if !res mod 2 = 0 then \"bolik\" else \"tolik\");;\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet () =\n let z = ref 0 in\n for i = 1 to read_int 0 do\n let x = read_int 0 |> ref in\n let y = read_int 0 |> ref in\n y := !y + !x;\n while !x < !y && !x mod 4 <> 0 do\n z := !z + !x;\n incr x\n done;\n while !x < !y && !y mod 4 <> 0 do\n decr y;\n z := !z + !y\n done\n done;\n print_endline (if !z <> 0 then \"tolik\" else \"bolik\")\n"}], "src_uid": "55099493c66b003d4261310bf2cc8f93"} {"source_code": "open Array\nopen Scanf\nlet main() =\n let s = stable_sort (-) in\n let gi() = bscanf Scanning.stdib \" %d\" (fun x -> x) in\n let n = gi () in\n let a = init n (fun i -> gi ()) in\n s a;\n a.(n-1) <- if fold_left (&&) true (map ((==) 1) a) then 2 else 1;\n s a;\n iter (Printf.printf \"%d \") a\n ;;\nmain()", "positive_code": [{"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n match Stream.next stdin_stream with\n '-' -> - (ri 0)\n | '+' -> ri 0\n | '0'..'9' as c -> ri ((int_of_char c) - 48)\n | _ -> gi ()\nand ri x =\n match Stream.next stdin_stream with\n '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));; \n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n let n = gi() in\n let a = init (n+1) (fun i -> if i > 0 then gi() else 1) in\n stable_sort compare a;\n if a.(n) == 1 then a.(n-1) <- 2 else ();\n iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) (sub a 0 n)\n ;;\nmain();;\nflushout ()"}, {"source_code": "open Array\nlet main() =\n let s = stable_sort (-) in\n let gi() = Scanf.scanf \" %d\" (fun i -> i) in\n let n = gi () in\n let a = init n (fun i -> gi ()) in\n s a;\n a.(n-1) <- if fold_left (&&) true (map ((==) 1) a) then 2 else 1;\n s a;\n iter (Printf.printf \"%d \") a\n ;;\nmain()"}, {"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 for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n a.(i) <- k\n done;\n Array.sort compare a;\n a.(n - 1) <-\n if a.(n - 1) > 1\n then 1\n else 2;\n Array.sort compare a;\n for i = 0 to n - 1 do\n Printf.printf \"%d \" a.(i);\n done;\n Printf.printf \"\\n\""}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let n = getnum () in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n let k = getnum () in\n\ta.(i) <- k\n done;\n Array.sort compare a;\n a.(n - 1) <-\n if a.(n - 1) > 1\n then 1\n else 2;\n Array.sort compare a;\n for i = 0 to n - 1 do\n Printf.printf \"%d \" a.(i);\n done;\n Printf.printf \"\\n\"\n"}, {"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n match Stream.next stdin_stream with\n '-' -> - (ri 0)\n | '+' -> ri 0\n | '0'..'9' as c -> ri ((int_of_char c) - 48)\n | _ -> gi ()\nand ri x =\n match Stream.next stdin_stream with\n '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;\nlet pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) a;;\n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n let n = gi() in\n let a = init (n+1) (fun i -> if i > 0 then gi() else 1) in\n stable_sort compare a;\n if a.(n) == 1 then a.(n-1) <- 2 else ();\n pa (sub a 0 n)\n ;;\nmain();;\nflushout ()"}], "negative_code": [{"source_code": "try (\n let a = Array.make 1 1 in\n Printf.printf \"1 1 2 3 \";\n a.(10) <- 4;\n Printf.printf \"%d\\n\" (a.(10))\n )\nwith\n_ -> exit 1"}, {"source_code": "open Sys\nlet rec pa = function\n [] -> ()\n | (x::xs) -> (Printf.printf \"%s\\n\" x; pa xs)\n ;;\nPrintf.printf \"word_size = %d\\n\" word_size;;\nPrintf.printf \"max_string_length = %d\\n\" max_string_length;;\nPrintf.printf \"max_array_length = %d\\n\" max_array_length;;\nPrintf.printf \"os_type = %s\\n\" os_type;;\nPrintf.printf \"ocaml_version = %s\\n\" ocaml_version"}, {"source_code": "let a = Array.make 1 1 in\na.(10) <- 239\n"}, {"source_code": " Printf.printf \"%s\\n\" (Str.quote \"abacaba\")"}, {"source_code": " let a = Array.make 1 1;;\n Printf.printf \"1 1 2 3 \";;\n a.(10000) <- 4;;\n Printf.printf \"%d\\n\" (a.(10000))"}, {"source_code": "exit 1"}, {"source_code": "let a = Array.make 1 1;;\nPrintf.printf \"1 1 2 3 \";;\na.(10) <- 4;;\nPrintf.printf \"%d\\n\" (a.(10))"}], "src_uid": "1cd10f01347d869be38c08ad64266870"} {"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 = List.rev (List.rev_append x y)\n end\n\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n let ( ~. ) = float_of_int\n let ( ~: ) = int_of_float\n let ( @ ) x y = 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%c\" (fun x _ -> x)\n let read_int = int\n let float () = Scanf.scanf \"%f%c\" (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\nlet max = L.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = n_int n ()\n\nlet p = n_int (n-1) () |> L.map (fun x -> ~.x *. 0.01)\n\nlet ab = L.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = L.each_cons (fun x y -> y-x) x in\n L.map2 (fun pi si -> ~.si /. 2. -. pi *. ~.c) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = max [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = max [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = max [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n | Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n L.map (fun (a,b) -> let r = query a b segtree in max [r.left; r.right; r.between; r.full]) ab\n |> L.fold_left (+.) 0.\n |> print_float\n", "positive_code": [{"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 = List.rev (List.rev_append x y)\n end\n\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n let ( ~. ) = float_of_int\n let ( ~: ) = int_of_float\n let ( @ ) x y = 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\nmodule Segtree = struct\n module type Builder = sig \n type data\n val merge : data -> data -> data\n val terminal : int -> data\n end\n\n module Make = functor(B : Builder) -> struct\n type t =\n |\tLeaf of B.data\n | Node of B.data * int * int * t * t\n\n let getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\n let rec make l r =\n if l = r then\n\tLeaf(B.terminal l)\n else\n\tlet mid = (l+r) / 2 in\n\tlet ltree = make l mid in\n\tlet rtree = make (mid+1) r in\n\tlet ldata = getdata ltree in\n\tlet rdata = getdata rtree in\n\t Node(B.merge ldata rdata, l, r, ltree, rtree)\n\n let rec query l r = function\n | Leaf(data) ->\n\t data\n | Node(data, start, finish, ltree, rtree) ->\n\t if l = start && r = finish then\n\t data\n\t else \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t\tquery l r ltree\n\t else if l > mid then \n\t\tquery l r rtree\n\t else \n\t\tlet ldata = query l mid ltree in\n\t\tlet rdata = query (mid+1) r rtree in\n\t\t B.merge ldata rdata\n\n end\n\nend\n\n(* entry point *)\n\nopen Std\nmodule L = List\n\nlet max = L.fold_left max neg_infinity\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = n_int n ()\n\nlet p = n_int (n-1) () |> L.map (fun x -> ~.x *. 0.01)\n\nlet ab = L.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = L.each_cons (fun x y -> y-x) x in\n L.map2 (fun pi si -> ~.si /. 2. -. pi *. ~.c) p s |> Array.of_list \n\nmodule A = struct\n\n type data = { left:float; right:float; between:float; full:float; }\n\n let terminal i = { left = 0.; right = 0.; between = 0.; full = w.(i); }\n\n let merge ldata rdata = {\n left = max [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = max [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = max [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n }\n\nend\n\nmodule MySegtree = Segtree.Make(A)\n\nopen A\n\nlet segtree = MySegtree.make 0 (n-2)\n\nlet to_ans data = max [data.left; data.right; data.between; data.full]\n\nlet () = \n L.map (fun (a,b) -> MySegtree.query a b segtree |> to_ans) ab\n |> L.fold_left (+.) 0.\n |> print_float\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 = List.rev (List.rev_append x y)\n end\n\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n let ( ~. ) = float_of_int\n let ( ~: ) = int_of_float\n let ( @ ) x y = 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%c\" (fun x _ -> x)\n let read_int = int\n let float () = Scanf.scanf \"%f%c\" (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\nmodule Segtree = struct\n module type Builder = sig \n type data\n val merge : data -> data -> data\n val terminal : int -> data\n end\n\n module Make = functor(B : Builder) -> struct\n type t =\n |\tLeaf of B.data\n | Node of B.data * int * int * t * t\n\n let getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\n let rec make l r =\n if l = r then\n\tLeaf(B.terminal l)\n else\n\tlet mid = (l+r) / 2 in\n\tlet ltree = make l mid in\n\tlet rtree = make (mid+1) r in\n\tlet ldata = getdata ltree in\n\tlet rdata = getdata rtree in\n\t Node(B.merge ldata rdata, l, r, ltree, rtree)\n\n let rec query l r = function\n | Leaf(data) ->\n\t data\n | Node(data, start, finish, ltree, rtree) ->\n\t if l = start && r = finish then\n\t data\n\t else \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t\tquery l r ltree\n\t else if l > mid then \n\t\tquery l r rtree\n\t else \n\t\tlet ldata = query l mid ltree in\n\t\tlet rdata = query (mid+1) r rtree in\n\t\t B.merge ldata rdata\n\n end\n\nend\n\n(* entry point *)\n\nopen Std\nmodule L = List\n\nlet max = L.fold_left max neg_infinity\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = n_int n ()\n\nlet p = n_int (n-1) () |> L.map (fun x -> ~.x *. 0.01)\n\nlet ab = L.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = L.each_cons (fun x y -> y-x) x in\n L.map2 (fun pi si -> ~.si /. 2. -. pi *. ~.c) p s |> Array.of_list \n\nmodule A = struct\n\n type data = { left:float; right:float; between:float; full:float; }\n\n let terminal i = { left = 0.; right = 0.; between = 0.; full = w.(i); }\n\n let merge ldata rdata = {\n left = max [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = max [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = max [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n }\n\nend\n\nmodule MySegtree = Segtree.Make(A)\n\nopen A\n\nlet segtree = MySegtree.make 0 (n-2)\n\nlet to_ans data = max [data.left; data.right; data.between; data.full]\n\nlet () = \n L.map (fun (a,b) -> MySegtree.query a b segtree |> to_ans) ab\n |> L.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec float () = Scanf.scanf \"%f%c\" (fun x _ -> x)\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\n module List = struct\n include List\n let map f lst = List.rev <| List.rev_map f lst\n let map2 f l1 l2 = List.rev <| List.rev_map2 f l1 l2\n end\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = n_int n ()\n\nlet p = n_float (n-1) () |> List.map (fun x -> x *. 0.01)\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\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 = List.rev (List.rev_append x y)\n end\n\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n let ( ~. ) = float_of_int\n let ( ~: ) = int_of_float\n let ( @ ) x y = 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%c\" (fun x _ -> x)\n let read_int = int\n let float () = Scanf.scanf \"%f%c\" (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\nmodule Segtree = struct\n module type Builder = sig \n type data\n val merge : data -> data -> data\n val terminal : int -> data\n end\n\n module Make = functor(B : Builder) -> struct\n type t =\n |\tLeaf of B.data\n | Node of B.data * int * int * t * t\n\n let getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\n let rec make l r =\n if l = r then\n\tLeaf(B.terminal l)\n else\n\tlet mid = (l+r) / 2 in\n\tlet ltree = make l mid in\n\tlet rtree = make (mid+1) r in\n\tlet ldata = getdata ltree in\n\tlet rdata = getdata rtree in\n\t Node(B.merge ldata rdata, l, r, ltree, rtree)\n\n let rec query l r = function\n | Leaf(data) ->\n\t data\n | Node(data, start, finish, ltree, rtree) ->\n\t if l = start && r = finish then\n\t data\n\t else \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t\tquery l r ltree\n\t else if l > mid then \n\t\tquery l r rtree\n\t else \n\t\tlet ldata = query l mid ltree in\n\t\tlet rdata = query (mid+1) r rtree in\n\t\t B.merge ldata rdata\n\n end\n\nend\n\n(* entry point *)\n\nopen Std\nmodule L = List\n\nlet max = L.fold_left max neg_infinity\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = n_int n ()\n\nlet p = n_int (n-1) () |> L.map (fun x -> ~.x *. 0.01)\n\nlet ab = L.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = L.each_cons (fun x y -> y-x) x in\n L.map2 (fun pi si -> ~.si /. 2. -. pi *. ~.c) p s |> Array.of_list \n\nmodule A = struct\n\n type data = { left:float; right:float; between:float; full:float; }\n\n let terminal i = { left = 0.; right = 0.; between = 0.; full = w.(i); }\n\n let merge ldata rdata = {\n left = max [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = max [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = max [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n }\n\nend\n\nmodule MySegtree = Segtree.Make(A)\n\nopen A\n\nlet segtree = MySegtree.make 0 (n-2)\n\nlet to_ans data = max [data.left; data.right; data.between; data.full]\n\nlet () = \n L.map (fun (a,b) -> MySegtree.query a b segtree |> to_ans) ab\n |> L.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "module type ExtremumType =\nsig\n type t\n val extremum : t -> t -> bool\nend\n\nmodule type RMQ =\nsig\n type t\n type elt\n val of_array : elt array -> t\n val rmq : t -> int -> int -> int\nend\n\nmodule type RMQMake =\nsig\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t\nend\n\nmodule RMQST =\nstruct\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t =\n struct\n type elt = Ext.t\n type t = {a : elt array;\n\t m : int array array}\n let ext = Ext.extremum\n let of_array a =\n let n = Array.length a in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= n do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k in\n\tlet m = Array.make_matrix k n 0 in\n\t for i = 0 to n - 1 do\n\t m.(0).(i) <- i;\n\t done;\n\t for j = 1 to k - 1 do\n\t for i = 0 to n - (1 lsl j) do\n\t let i2 = i + (1 lsl (j - 1)) in\n\t\tm.(j).(i) <-\n\t\t if ext a.(m.(j - 1).(i)) a.(m.(j - 1).(i2))\n\t\t then m.(j - 1).(i)\n\t\t else m.(j - 1).(i2)\n\t done\n\t done;\n\t {a = a;\n\t m = m}\n let rmq data x y =\n let a = data.a\n and m = data.m in\n let l = y - x + 1 in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= l do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k - 1 in\n\tlet i2 = y - (1 lsl k) + 1 in\n\t if ext a.(m.(k).(x)) a.(m.(k).(i2))\n\t then m.(k).(x)\n\t else m.(k).(i2)\n end\nend\n\nmodule RMQSTmin =\n RMQST.Make(\n struct\n type t = float\n let extremum (x : t) (y : t) = x < y\n end\n )\n\nmodule RMQSTmax =\n RMQST.Make(\n struct\n type t = float\n let extremum (x : t) (y : t) = x >= y\n end\n )\n\n\nmodule RMSQ2 =\nstruct\n module Make(RMQ : RMQMake) =\n struct\n module RMQmin =\n RMQ.Make(\n\tstruct\n\t type t = float\n\t let extremum (x : t) (y : t) = x < y\n\tend\n )\n module RMQmax =\n RMQ.Make(\n\tstruct\n\t type t = float\n\t let extremum (x : t) (y : t) = x >= y\n\tend\n )\n type elt = float\n type t = {c : elt array;\n\t p : int array;\n\t m : elt array;\n\t crminq : RMQmin.t;\n\t crmaxq : RMQmax.t;\n\t mrmq : RMQmax.t;\n\t }\n let of_array a =\n let n = Array.length a in\n let c = Array.make (n + 1) 0.0 in\n let p = Array.make n 0 in\n let m = Array.make n 0.0 in\n let l = Array.make n 0 in\n\tfor i = 0 to n - 1 do\n\t c.(i + 1) <- c.(i) +. a.(i);\n\t l.(i) <- i - 1;\n\t p.(i) <- i;\n\t while c.(l.(i) + 1) < c.(i + 1) && l.(i) >= 0 do\n\t if c.(p.(l.(i))) < c.(p.(i))\n\t then p.(i) <- p.(l.(i));\n\t l.(i) <- l.(l.(i));\n\t done;\n\t m.(i) <- c.(i + 1) -. c.(p.(i));\n\tdone;\n\t{c = c;\n\t p = p;\n\t m = m;\n\t crminq = RMQmin.of_array c;\n\t crmaxq = RMQmax.of_array c;\n\t mrmq = RMQmax.of_array m;\n\t}\n let rmsq d i j =\n let x = RMQmax.rmq d.mrmq i j in\n\tif d.p.(x) < i then (\n\t let z = RMQmin.rmq d.crminq i x in\n\t if x + 1 <= j then (\n\t let y = RMQmax.rmq d.mrmq (x + 1) j in\n\t\tif d.c.(x + 1) -. d.c.(z) < d.m.(y)\n\t\tthen (d.p.(y), y)\n\t\telse (z, x)\n\t ) else\n\t (z, x)\n\t) else\n\t (d.p.(x), x)\n let rmsq_sum d i j =\n let (x, y) = rmsq d i j in\n\td.c.(y + 1) -. d.c.(x)\n let rmsq2 d i j k l =\n if j <= k then (\n\tlet x = RMQmin.rmq d.crminq i j in\n\tlet y = RMQmax.rmq d.crmaxq (k + 1) (l + 1) - 1 in\n\t (x, y)\n ) else (\n\tlet x1 = RMQmin.rmq d.crminq i k in\n\tlet y1 = RMQmax.rmq d.crmaxq (k + 1) (l + 1) - 1 in\n\tlet x2 = RMQmin.rmq d.crminq (k + 1) j in\n\tlet y2 = RMQmax.rmq d.crmaxq (j + 1) (l + 1) - 1 in\n\tlet (x3, y3) = rmsq d k j in\n\tlet c1 = d.c.(y1 + 1) -. d.c.(x1) in\n\tlet c2 = d.c.(y2 + 1) -. d.c.(x2) in\n\tlet c3 = d.c.(y3 + 1) -. d.c.(x3) in\n\t if c1 > c2 && c1 > c3\n\t then (x1, y1)\n\t else if c2 > c3\n\t then (x2, y2)\n\t else (x3, y3)\n )\n let rmsq2_sum d i j k l =\n let (x, y) = rmsq2 d i j k l in\n\td.c.(y + 1) -. d.c.(x)\n end\nend\n\n\nmodule RMSQ2ST = RMSQ2.Make(RMQST)\n\n\nlet getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let n = getnum () in\n let m = getnum () in\n let c = getnum () in\n let x = Array.make n 0 in\n let p = Array.make (n - 1) 0 in\n let _ =\n for i = 0 to n - 1 do\n x.(i) <- getnum ()\n done;\n for i = 0 to n - 2 do\n p.(i) <- getnum ()\n done;\n in\n let e = Array.make (n - 1) 0.0 in\n let f = Array.make n 0.0 in\n let c = float_of_int c in\n let _ =\n for i = 0 to n - 2 do\n let p = float_of_int p.(i) /. 100.0 in\n\te.(i) <- float_of_int (x.(i + 1) - x.(i)) /. 2.0 *. (1. -. 0.0) -. p *. c;\n\t(*Printf.printf \"asd %d %f\\n\" i e.(i);*)\n\t(*e.(i) <- -. e.(i);*)\n\tf.(i + 1) <- f.(i) +. e.(i)\n done\n in\n let res = ref 0.0 in\n let rmsq = RMSQ2ST.of_array e in\n for i = 1 to m do\n let a = getnum () - 1 in\n let b = getnum () - 1 in\n let g = RMSQ2ST.rmsq_sum rmsq a (b - 1) in\n let g = max g 0.0 in\n\t(*Printf.printf \"rmsq %f\\n\" g;*)\n (*let g = f.(b) -. f.(a) -. g in\n\tPrintf.printf \"asd %f\\n\" g;*)\n\tres := !res +. g;\n done;\n (*res := -. !res;*)\n Printf.printf \"%.6f\\n\" !res\n"}, {"source_code": "let ( |> ) v f = f v\nlet ( <| ) f v = f v\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet rec show_flt_list a = \n match a with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\n\n\nlet rec loop n f acc = \n if n = 0 then List.rev acc\n else loop (n - 1) f ( (f n) :: acc)\n \n\ntype data = {ma : float; lv : float; rv : float; sum : float}\ntype range = {l: int; r : int}\n\ntype seg_tree = \n Leaf of data\n| Node of int * int * data * seg_tree * seg_tree\n\n\nlet get_data tr = \n match tr with\n\t Leaf d\n\t| Node (_, _, d, _, _) -> d\n\n\nlet update dlc drc = \n let s = dlc.sum +. drc.sum in\n let l = max dlc.lv (dlc.sum +. drc.lv) in\n let r = max drc.rv (drc.sum +. dlc.rv) in\n let m = max (max dlc.ma drc.ma) (dlc.rv +. drc.lv) in\n {ma = m; lv = l; rv = r; sum = s;}\n;;\n\nlet n = next_int () \nlet m = next_int ()\nlet c = next_flt () \n\nlet d = loop n (fun _ -> next_flt ()) []\nlet p = loop (n - 1) (fun _ -> ((next_flt ()) /. 100.0)) []\n\nlet v = List.map (fun (a, b) -> a -. b) (List.combine (List.tl d) (List.rev (List.tl (List.rev d))))\nlet a = Array.of_list <| List.map (fun (a, b) -> a /. 2.0 -. b *. c) (List.combine v p)\n\n\nlet rec build x y =\n if x = y then Leaf ({ma = max (foi 0) a.(x); lv = a.(x); rv = a.(x); sum = a.(x)})\n else begin\n\tlet mid = (x + y) / 2 in\n\tlet lc = build x mid in\n\tlet rc = build (mid+1) y in\n\tNode (x, y, (update (get_data lc) (get_data rc)), lc, rc)\n end\n\nlet rec query tr x y =\n match tr with\n\t Leaf d -> d\n\t| Node (l, r, d, lc, rc) -> begin\n\t if x <= l && y >= r then d\n\t else\n\t\tlet mid = (l + r) / 2 in\n\t\tlet snt = {ma = -1e20; lv = -1e20; rv = -1e20; sum = -1e20} in\n\t\tlet qlc = if x <= mid then query lc x y else snt in\n\t\tlet qrc = if y > mid then query rc x y else snt in\n\t\tupdate qlc qrc\n\tend\n\nlet tr = build 0 (n - 2)\n\n\nlet () =\n loop m (fun _ -> (let a = next_int() in\n\t\t\t\t\tlet b = next_int() in\n\t\t\t\t\tquery tr (a - 1) (b - 2)).ma) [] \n\t|> List.fold_left (+.) (foi 0) \n\t|> print_float\n \n\n\n"}], "negative_code": [{"source_code": "module type ExtremumType =\nsig\n type t\n val extremum : t -> t -> bool\nend\n\nmodule type RMQ =\nsig\n type t\n type elt\n val of_array : elt array -> t\n val rmq : t -> int -> int -> int\nend\n\nmodule type RMQMake =\nsig\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t\nend\n\nmodule RMQST =\nstruct\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t =\n struct\n type elt = Ext.t\n type t = {a : elt array;\n\t m : int array array}\n let ext = Ext.extremum\n let of_array a =\n let n = Array.length a in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= n do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k in\n\tlet m = Array.make_matrix k n 0 in\n\t for i = 0 to n - 1 do\n\t m.(0).(i) <- i;\n\t done;\n\t for j = 1 to k - 1 do\n\t for i = 0 to n - (1 lsl j) do\n\t let i2 = i + (1 lsl (j - 1)) in\n\t\tm.(j).(i) <-\n\t\t if ext a.(m.(j - 1).(i)) a.(m.(j - 1).(i2))\n\t\t then m.(j - 1).(i)\n\t\t else m.(j - 1).(i2)\n\t done\n\t done;\n\t {a = a;\n\t m = m}\n let rmq data x y =\n let a = data.a\n and m = data.m in\n let l = y - x + 1 in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= l do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k - 1 in\n\tlet i2 = y - (1 lsl k) + 1 in\n\t if ext a.(m.(k).(x)) a.(m.(k).(i2))\n\t then m.(k).(x)\n\t else m.(k).(i2)\n end\nend\n\nmodule RMQSTmin =\n RMQST.Make(\n struct\n type t = float\n let extremum (x : t) (y : t) = x < y\n end\n )\n\nmodule RMQSTmax =\n RMQST.Make(\n struct\n type t = float\n let extremum (x : t) (y : t) = x >= y\n end\n )\n\n\nmodule RMSQ2 =\nstruct\n module Make(RMQ : RMQMake) =\n struct\n module RMQmin =\n RMQ.Make(\n\tstruct\n\t type t = float\n\t let extremum (x : t) (y : t) = x < y\n\tend\n )\n module RMQmax =\n RMQ.Make(\n\tstruct\n\t type t = float\n\t let extremum (x : t) (y : t) = x >= y\n\tend\n )\n type elt = float\n type t = {c : elt array;\n\t p : int array;\n\t m : elt array;\n\t crminq : RMQmin.t;\n\t crmaxq : RMQmax.t;\n\t mrmq : RMQmax.t;\n\t }\n let of_array a =\n let n = Array.length a in\n let c = Array.make (n + 1) 0.0 in\n let p = Array.make n 0 in\n let m = Array.make n 0.0 in\n let l = Array.make n 0 in\n\tfor i = 0 to n - 1 do\n\t c.(i + 1) <- c.(i) +. a.(i);\n\t l.(i) <- i - 1;\n\t p.(i) <- i;\n\t while c.(l.(i) + 1) < c.(i + 1) && l.(i) >= 0 do\n\t if c.(p.(l.(i))) < c.(p.(i))\n\t then p.(i) <- p.(l.(i));\n\t l.(i) <- l.(l.(i));\n\t done;\n\t m.(i) <- c.(i + 1) -. c.(p.(i));\n\tdone;\n\t{c = c;\n\t p = p;\n\t m = m;\n\t crminq = RMQmin.of_array c;\n\t crmaxq = RMQmax.of_array c;\n\t mrmq = RMQmax.of_array m;\n\t}\n let rmsq d i j =\n let x = RMQmax.rmq d.mrmq i j in\n\tif d.p.(x) < i then (\n\t let z = RMQmin.rmq d.crminq i x in\n\t if x + 1 <= j then (\n\t let y = RMQmax.rmq d.mrmq (x + 1) j in\n\t\tif d.c.(x + 1) -. d.c.(z) < d.m.(y)\n\t\tthen (d.p.(y), y)\n\t\telse (z, x)\n\t ) else\n\t (z, x)\n\t) else\n\t (d.p.(x), x)\n let rmsq_sum d i j =\n let (x, y) = rmsq d i j in\n\td.c.(y + 1) -. d.c.(x)\n let rmsq2 d i j k l =\n if j <= k then (\n\tlet x = RMQmin.rmq d.crminq i j in\n\tlet y = RMQmax.rmq d.crmaxq (k + 1) (l + 1) - 1 in\n\t (x, y)\n ) else (\n\tlet x1 = RMQmin.rmq d.crminq i k in\n\tlet y1 = RMQmax.rmq d.crmaxq (k + 1) (l + 1) - 1 in\n\tlet x2 = RMQmin.rmq d.crminq (k + 1) j in\n\tlet y2 = RMQmax.rmq d.crmaxq (j + 1) (l + 1) - 1 in\n\tlet (x3, y3) = rmsq d k j in\n\tlet c1 = d.c.(y1 + 1) -. d.c.(x1) in\n\tlet c2 = d.c.(y2 + 1) -. d.c.(x2) in\n\tlet c3 = d.c.(y3 + 1) -. d.c.(x3) in\n\t if c1 > c2 && c1 > c3\n\t then (x1, y1)\n\t else if c2 > c3\n\t then (x2, y2)\n\t else (x3, y3)\n )\n let rmsq2_sum d i j k l =\n let (x, y) = rmsq2 d i j k l in\n\td.c.(y + 1) -. d.c.(x)\n end\nend\n\n\nmodule RMSQ2ST = RMSQ2.Make(RMQST)\n\n\nlet getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let n = getnum () in\n let m = getnum () in\n let c = getnum () in\n let x = Array.make n 0 in\n let p = Array.make (n - 1) 0 in\n let _ =\n for i = 0 to n - 1 do\n x.(i) <- getnum ()\n done;\n for i = 0 to n - 2 do\n p.(i) <- getnum ()\n done;\n in\n let e = Array.make (n - 1) 0.0 in\n let f = Array.make n 0.0 in\n let c = float_of_int c in\n let _ =\n for i = 0 to n - 2 do\n let p = float_of_int p.(i) /. 100.0 in\n\te.(i) <- float_of_int (x.(i + 1) - x.(i)) /. 2.0 *. (1. -. p) -. p *. c;\n\t(*Printf.printf \"asd %d %f\\n\" i e.(i);*)\n\t(*e.(i) <- -. e.(i);*)\n\tf.(i + 1) <- f.(i) +. e.(i)\n done\n in\n let res = ref 0.0 in\n let rmsq = RMSQ2ST.of_array e in\n for i = 1 to m do\n let a = getnum () - 1 in\n let b = getnum () - 1 in\n let g = RMSQ2ST.rmsq_sum rmsq a (b - 1) in\n let g = max g 0.0 in\n\t(*Printf.printf \"rmsq %f\\n\" g;*)\n (*let g = f.(b) -. f.(a) -. g in\n\tPrintf.printf \"asd %f\\n\" g;*)\n\tres := !res +. g;\n done;\n (*res := -. !res;*)\n Printf.printf \"%.6f\\n\" !res\n"}, {"source_code": "let ( |> ) x f = f x\n\nlet ( <| ) f x = f x\n\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () =\n separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet get_int_list () =\n !separated_input_list\n |> List.map int_of_string\nlet get_next_int () =\n match !separated_input_list with\n | [] -> (print_endline \"Error\"; assert false)\n | hd :: tl -> separated_input_list := tl; int_of_string hd\n\nlet each_cons f lst =\n List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\n\nlet () = buffer_line ()\nlet n = get_next_int ()\nlet m = get_next_int ()\nlet c = get_next_int ()\n\nlet x = buffer_line (); get_int_list ()\n\nlet p = \n (buffer_line (); get_int_list ())\n |> List.map float_of_int\n |> List.map (fun x -> x /. 100.)\n\nlet ab = \n List.rev\n <| repeat m\n (fun lst -> \n\t let () = buffer_line () in\n\t let a = get_next_int () in\n\t let b = get_next_int () in\n\t (a-1, b-2) :: lst)\n []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 \n (fun pi si -> si /. 2. -. pi *. float_of_int(c))\n p\n s\n |> Array.of_list \n\n(*\nlet () = prerr_endline \"w=\"\nlet () = Array.iter (fun x -> prerr_float x; prerr_string \", \") w\nlet () = prerr_newline ()\nlet () = prerr_newline ()\n*)\n\ntype gao = {\n left:float;\n right:float;\n between:float;\n full:float;\n}\n\ntype tree = \n | Leaf of gao\n | Node of gao * int * int * tree * tree\n\nlet getgao = function\n | Leaf(gao) -> gao\n | Node(gao,_,_,_,_) -> gao\n\nlet lmax = List.fold_left max neg_infinity\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ \n\t left = 0.; \n\t right = 0.; \n\t between = 0.; \n\t full = w.(l); \n\t })\n else\n let mid = (l+r) / 2 in\n let lnode = make_tree l mid in\n let rnode = make_tree (mid+1) r in\n let ldata = getgao lnode in\n let rdata = getgao rnode in\n Node({ \n\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t full = ldata.full +. rdata.full;\n\t },\n\t l,\n\t r,\n\t lnode,\n\t rnode)\n\nlet rec query l r tree =\n match tree with\n Leaf(data) ->\n\tdata\n | Node(data, start, finish, ltree, rtree) ->\n\tif l = start && r = finish then\n\t data\n\telse \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t\t{ \n\t\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t\t full = ldata.full +. rdata.full;\n\t\t}\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n begin\n print_endline (string_of_int (List.length x));\n print_endline \"hello, world!\"\n end\n\nlet p = n_int (n-1) () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_int (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = pp |> List.map (fun x -> (float_of_int x) *. 0.01)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec float () = Scanf.scanf \"%f%c\" (fun x _ -> x)\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\n module List = struct\n include List\n let map f lst = List.rev <| List.rev_map f lst\n end\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_float (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\n(*let ppp = pp |> List.map float_of_int *)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = pp |> List.map (fun x -> x *. 0.01)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\n(*\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n*)\n\nlet digit c = c >= '0' && c <= '9'\nlet feed c = c = '\\r' || c = '\\n'\nlet whitespace c = c = ' ' || c = '\\t' || feed c\n\nlet rec int' flg x =\n let c = input_char stdin in\n if digit c then\n int' true (x*10+int_of_char(c)-48)\n else if whitespace c then\n if flg then\n\t(x, feed c)\n else\n\tint' false 0\n else failwith \"getInt\"\n\nlet int () = fst (int' false 0)\n\nlet int_list () =\n let rec int_list' () =\n let (x, flg) = int' false 0 in\n if flg then\n\t[x]\n else\n\tx :: int_list' ()\n in\n int_list' ()\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = int_list ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "let ( |> ) x f = f x\n\nlet ( <| ) f x = f x\n\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () =\n separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet get_int_list () =\n !separated_input_list\n |> List.map int_of_string\nlet get_next_int () =\n match !separated_input_list with\n | [] -> assert false\n | hd :: tl -> separated_input_list := tl; int_of_string hd\n\nlet each_cons f lst =\n List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\n\nlet () = buffer_line ()\nlet n = get_next_int ()\nlet m = get_next_int ()\nlet c = get_next_int ()\n\nlet x = buffer_line (); get_int_list ()\n\nlet p = \n (buffer_line (); get_int_list ())\n |> List.map float_of_int\n |> List.map (fun x -> x /. 100.)\n\nlet ab = \n List.rev\n <| repeat m\n (fun lst -> \n\t let () = buffer_line () in\n\t let a = get_next_int () in\n\t let b = get_next_int () in\n\t (a-1, b-2) :: lst)\n []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 \n (fun pi si -> (1. -. pi) *. si /. 2. -. pi *. float_of_int(c))\n p\n s\n |> Array.of_list \n\nlet () = prerr_endline \"w=\"\nlet () = Array.iter (fun x -> prerr_float x; prerr_string \", \") w\nlet () = prerr_newline ()\nlet () = prerr_newline ()\n\ntype gao = {\n left:float;\n right:float;\n between:float;\n full:float;\n}\n\ntype tree = \n | Leaf of gao\n | Node of gao * int * int * tree * tree\n\nlet getgao = function\n | Leaf(gao) -> gao\n | Node(gao,_,_,_,_) -> gao\n\nlet lmax = List.fold_left max neg_infinity\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ \n\t left = 0.; \n\t right = 0.; \n\t between = 0.; \n\t full = w.(l); \n\t })\n else\n let mid = (l+r) / 2 in\n let lnode = make_tree l mid in\n let rnode = make_tree (mid+1) r in\n let ldata = getgao lnode in\n let rdata = getgao rnode in\n Node({ \n\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t full = ldata.full +. rdata.full;\n\t },\n\t l,\n\t r,\n\t lnode,\n\t rnode)\n\nlet rec query l r tree =\n match tree with\n Leaf(data) ->\n\tdata\n | Node(data, start, finish, ltree, rtree) ->\n\tif l = start && r = finish then\n\t data\n\telse \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t\t{ \n\t\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t\t full = ldata.full +. rdata.full;\n\t\t}\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in df(lmax [r.left; r.right; r.between; r.full])) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_int (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ppp = pp |> List.map float_of_int \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = ppp |> List.map (fun x -> x *. 0.01)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec n_int n () = List.rev <| repeat n (fun lst -> int () :: lst) []\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_int (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = pp |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet () = buffer_line ()\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = buffer_line (); int_list ()\n\nlet p = buffer_line (); int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\nlet ab = List.rev <| repeat m (fun lst -> buffer_line (); let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "let ( |> ) x f = f x\n\nlet ( <| ) f x = f x\n\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () =\n separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet get_int_list () =\n !separated_input_list\n |> List.map int_of_string\nlet get_next_int () =\n match !separated_input_list with\n | [] -> assert false\n | hd :: tl -> separated_input_list := tl; int_of_string hd\n\nlet each_cons f lst =\n List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\n\nlet () = buffer_line ()\nlet n = get_next_int ()\nlet m = get_next_int ()\nlet c = get_next_int ()\n\nlet x = buffer_line (); get_int_list ()\n\nlet p = \n (buffer_line (); get_int_list ())\n |> List.map float_of_int\n |> List.map (fun x -> x /. 100.)\n\nlet ab = \n List.rev\n <| repeat m\n (fun lst -> \n\t let () = buffer_line () in\n\t let a = get_next_int () in\n\t let b = get_next_int () in\n\t (a-1, b-2) :: lst)\n []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 \n (fun pi si -> si /. 2. -. pi *. float_of_int(c))\n p\n s\n |> Array.of_list \n\nlet () = prerr_endline \"w=\"\nlet () = Array.iter (fun x -> prerr_float x; prerr_string \", \") w\nlet () = prerr_newline ()\nlet () = prerr_newline ()\n\ntype gao = {\n left:float;\n right:float;\n between:float;\n full:float;\n}\n\ntype tree = \n | Leaf of gao\n | Node of gao * int * int * tree * tree\n\nlet getgao = function\n | Leaf(gao) -> gao\n | Node(gao,_,_,_,_) -> gao\n\nlet lmax = List.fold_left max neg_infinity\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ \n\t left = 0.; \n\t right = 0.; \n\t between = 0.; \n\t full = w.(l); \n\t })\n else\n let mid = (l+r) / 2 in\n let lnode = make_tree l mid in\n let rnode = make_tree (mid+1) r in\n let ldata = getgao lnode in\n let rdata = getgao rnode in\n Node({ \n\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t full = ldata.full +. rdata.full;\n\t },\n\t l,\n\t r,\n\t lnode,\n\t rnode)\n\nlet rec query l r tree =\n match tree with\n Leaf(data) ->\n\tdata\n | Node(data, start, finish, ltree, rtree) ->\n\tif l = start && r = finish then\n\t data\n\telse \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t\t{ \n\t\t left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n\t\t right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n\t\t between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n\t\t full = ldata.full +. rdata.full;\n\t\t}\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in df(lmax [r.left; r.right; r.between; r.full])) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec float () = Scanf.scanf \"%f%c\" (fun x _ -> x)\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\n module List = struct\n include List\n let map f lst = List.rev <| List.rev_map f lst\n let map2 f l1 l2 = List.rev <| List.rev_map2 f l1 l2\n end\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_float (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\n(*let ppp = pp |> List.map float_of_int *)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = pp |> List.map (fun x -> x *. 0.01)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet () = buffer_line ()\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = buffer_line (); int_list ()\n\nlet p = buffer_line (); int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\nlet ab = List.rev <| repeat m (fun lst -> buffer_line (); let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n(* if n = 150000 && m = 300000 && c = 209 then *)\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\n(*\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n*)\n\nlet digit c = c >= '0' && c <= '9'\nlet feed c = c = '\\r' || c = '\\n'\nlet whitespace c = c = ' ' || c = '\\t' || feed c\n\nlet rec int' flg x =\n let c = input_char stdin in\n if digit c then\n int' true (x*10+int_of_char(c)-48)\n else if whitespace c then\n if flg then\n\t(x, feed c)\n else\n\tint' false 0\n else failwith \"getInt\"\n\nlet int () = fst (int' false 0)\n\nlet int_list () =\n let rec int_list' () =\n let (x, flg) = int' false 0 in\n if flg then\n\t[x]\n else\n\tx :: int_list' ()\n in\n int_list' ()\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = int_list ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n begin\n print_endline (string_of_int (List.length x));\n print_endline \"hello, world!\"\n end\n\nlet p = int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nmodule Std = struct\n let ( |> ) x f = f x\n let ( <| ) f x = f x\n \n let di x = prerr_endline (string_of_int x); x\n let df x = prerr_endline (string_of_float x); x\n \n let rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\n let rec int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\n let rec float () = Scanf.scanf \"%f%c\" (fun x _ -> x)\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) []\nend\n\nopen Std\n\n(* utiliry functions *)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = n_int n ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet pp = n_float (n-1) () \n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\n(*let ppp = pp |> List.map float_of_int *)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = pp |> List.map (fun x -> x *. 0.01)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet () = buffer_line ()\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet x = buffer_line (); int_list ()\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet p = buffer_line (); int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet ab = List.rev <| repeat m (fun lst -> buffer_line (); let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r = function\n |Leaf(data) ->\n data\n | Node(data, start, finish, ltree, rtree) ->\n if l = start && r = finish then\n\tdata\n else \n\tlet mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t merge ldata rdata\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet segtree = make_tree 0 (n-2)\n\n(* submit debug.. *)\nlet () =\n if n = 150000 && m = 300000 && c = 209 then\n print_endline \"hello, world!\"\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}, {"source_code": "(* template *)\nlet ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet di x = prerr_endline (string_of_int x); x\nlet df x = prerr_endline (string_of_float x); x\n\nlet separated_input_list = ref []\nlet buffer_line () = separated_input_list := (read_line () |> Str.split (Str.regexp \"\\ \"))\nlet int_list () = !separated_input_list |> List.map int_of_string\nlet int () = match !separated_input_list with [] -> assert false | hd :: tl -> separated_input_list := tl; int_of_string hd\n\n(* utiliry functions *)\nlet rec repeat n f x = if n = 0 then x else repeat (n-1) f (f x)\nlet each_cons f lst = List.rev_map2 f (List.tl (List.rev lst)) (List.rev (List.tl lst))\nlet lmax = List.fold_left max neg_infinity\n\n(* entry point *)\n\nlet () = buffer_line ()\nlet n = int ()\nlet m = int ()\nlet c = int ()\n\nlet x = buffer_line (); int_list ()\n\nlet p = buffer_line (); int_list () |> List.map float_of_int |> List.map (fun x -> x /. 100.)\n\nlet ab = List.rev <| repeat m (fun lst -> buffer_line (); let a = int () in let b = int () in (a-1, b-2) :: lst) []\n\nlet w = \n let s = each_cons (fun x y -> y-x |> float_of_int) x in\n List.map2 (fun pi si -> si /. 2. -. pi *. float_of_int(c)) p s |> Array.of_list \n\ntype data = { left:float; right:float; between:float; full:float; }\n\ntype tree = \n | Leaf of data\n | Node of data * int * int * tree * tree\n\nlet getdata = function\n | Leaf(data) -> data\n | Node(data,_,_,_,_) -> data\n\nlet merge ldata rdata = {\n left = lmax [ldata.left; ldata.full; (ldata.full +. rdata.left)];\n right = lmax [rdata.right; rdata.full; (rdata.full +. ldata.right)];\n between = lmax [ldata.between; rdata.between; ldata.right; rdata.left; (ldata.right +. rdata.left)];\n full = ldata.full +. rdata.full; \n}\n\nlet rec make_tree l r =\n if l = r then\n Leaf({ left = 0.; right = 0.; between = 0.; full = w.(l); })\n else\n let mid = (l+r) / 2 in\n let ltree = make_tree l mid in\n let rtree = make_tree (mid+1) r in\n let ldata = getdata ltree in\n let rdata = getdata rtree in\n Node(merge ldata rdata, l, r, ltree, rtree)\n\nlet rec query l r tree =\n match tree with\n Leaf(data) ->\n\tdata\n | Node(data, start, finish, ltree, rtree) ->\n\tif l = start && r = finish then\n\t data\n\telse \n\t let mid = (start+finish)/2 in\n\t if r <= mid then\n\t query l r ltree\n\t else if l > mid then \n\t query l r rtree\n\t else \n\t let ldata = query l mid ltree in\n\t let rdata = query (mid+1) r rtree in\n\t\tmerge ldata rdata\n\nlet segtree = make_tree 0 (n-2)\n\nlet () = \n List.map (fun (a,b) -> let r = query a b segtree in lmax [r.left; r.right; r.between; r.full]) ab\n |> List.fold_left (+.) 0.\n |> print_float\n"}], "src_uid": "f7528716ef2cfdbcdc8bf8253fd4966b"} {"source_code": "open Array;;\n \n \nlet (|>) x f = f x\n \n \nlet calc t1 t2 k = fun (a, b, i) ->\n let a = float a in\n let b = float b in\n let f a b = a *. t1 *. (1.0 -. k) +. b *. t2 in\n ( max (f a b) (f b a) , i)\n(* (res, i) *)\n \nlet cmp' x = \n if x > 0.0 \n then -1\n else if x < 0.0 then 1\n else 0\n \nlet cmp = fun (a, c) -> fun (b, d) ->\n if a = b \n then c - d\n else cmp' (a -. b)\nlet print a = \n Printf.printf \"%d \" (snd a + 1);\n (fst a)|> Printf.printf \"%.2f\\n\"\n \nlet main _ = \n let f i = Scanf.scanf \"%d %d\\n\" (fun a -> fun b -> a, b, i) in\n let n, t1, t2, k = Scanf.scanf \"%d %d %d %d\\n\"\n (fun m -> fun p->fun k->fun l \n -> m,p,k,l) in\n let a = init n f |> map (calc (float t1) (float t2) ((float k)/. 100.0) ) in\n fast_sort cmp a;\n iter print a;;\n \nmain ();;\n \n ", "positive_code": [{"source_code": "let ni () = Scanf.scanf \" %d\" (fun x -> x) in\nlet nf () = float_of_int (ni ()) in\nlet n = ni () in\nlet t1 = nf () in\nlet t2 = nf () in\nlet k = 1.0 -. nf () /. 100.0 in\nlet f a b = a *. t1 *. k +. b *. t2 in\nlet a = Array.init n (fun i ->\n let a, b = nf (), nf () in\n (-1. *. max (f a b) (f b a), i + 1)\n) in\nArray.sort compare a;\nArray.iter (fun (e, i) ->\n Printf.printf \"%d %.2f\\n\" i ~-.e\n) a;;\n"}], "negative_code": [{"source_code": "open Array;;\n \n let (|>) x f = f x\n \n\nlet calc t1 t2 k = fun (a, b, i) ->\n let a = float a in\n let b = float b in\n let f a b = a *. t1 *. (1.0 -. k) +. b *. t2 in\n ( max (f a b) (f b a) , i)\n(* (res, i) *)\n \nlet cmp' x = \n if x > 0.0 \n then -1\n else if x < 0.0 then 1\n else 0\n \nlet cmp = fun (a, c) -> fun (b, d) ->\n if a = b \n then d - c\n else cmp' (a -. b)\nlet print a = \n Printf.printf \"%d \" (snd a + 1);\n (fst a)|> Printf.printf \"%.2f\\n\"\n \nlet main _ = \n let f i = Scanf.scanf \"%d %d\\n\" (fun a -> fun b -> a, b, i) in\n let n, t1, t2, k = Scanf.scanf \"%d %d %d %d\\n\"\n (fun m -> fun p->fun k->fun l \n -> m,p,k,l) in\n let a = init n f |> map (calc (float t1) (float t2) ((float k)/. 100.0) ) in\n fast_sort cmp a;\n iter print a;;\n \nmain ();;"}], "src_uid": "a89f9310996eb23254d07e52544e30ae"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n read_int in\n\n Array.sort compare a;\n\n let rec run_length prev count best i = if i=n then best else (\n if a.(i) = prev then (\n let count = count + 1 in\n let best = max best count in\n run_length prev count best (i+1)\n ) else (\n run_length a.(i) 1 best (i+1)\n )\n ) in\n\n printf \"%d\\n\" (run_length a.(0) 1 1 1)\n", "positive_code": [{"source_code": "let input () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let n = getNumber ()\n in let a = Array.make n (max_int, false)\n in begin\n for i = 0 to n - 1 do\n a.(i) <- (getNumber (), false)\n done;\n a\n end\n\nlet bSearch i a =\n let n = Array.length a\n in let l = ref (i + 1)\n in let r = ref (n - 1)\n in let m = ref 0\n in let found = ref false\n in begin\n while l <= r do\n m := (!l + !r) / 2;\n if fst a.(!m) > fst a.(i) && snd a.(!m) = false then\n if fst a.(!m - 1) = fst a.(i) || snd a.(!m - 1) = true then\n (r := !l - 1;\n found := true)\n else\n r := !m - 1\n else\n l := !m + 1\n done;\n if !found then Some !m\n else None\n end\n\nlet eat a =\n let n = Array.length a\n in let count = ref n\n in begin\n for i = 0 to n - 1 do\n match bSearch i a with\n | Some x -> begin\n count := !count - 1;\n a.(x) <- (fst a.(x), true)\n end\n | None -> ()\n done;\n !count\n end\n\nlet main () =\n let a = input ()\n in let cmp (x, _) (y, _) = compare x y\n in begin\n Array.sort cmp a;\n Printf.printf \"%d\" (eat a)\n end\n;;\n\nmain ();;\n"}], "negative_code": [{"source_code": "let input () =\n let getNumber () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let n = getNumber ()\n in let a = Array.make n (max_int, false)\n in begin\n for i = 0 to n - 1 do\n a.(i) <- (getNumber (), false)\n done;\n a\n end\n\nlet bSearch i a =\n let n = Array.length a\n in let l = ref (i + 1)\n in let r = ref (n - 1)\n in let m = ref 0\n in let found = ref false\n in begin\n while l <= r do\n m := (!l + !r) / 2;\n if fst a.(!m) > fst a.(i) && snd a.(!m) = false then\n if fst a.(!m - 1) = fst a.(i) || snd a.(!m - 1) = true then\n (r := !l - 1;\n found := true)\n else\n r := !m - 1\n else\n l := !m + 1\n done;\n if !found then Some !m\n else None\n end\n\nlet eat a =\n let n = Array.length a\n in let count = ref n\n in begin\n for i = 0 to n - 1 do\n match bSearch i a with\n | Some x -> begin\n count := !count - 1;\n a.(x) <- (fst a.(x), true)\n end\n | None -> ()\n done;\n !count\n end\n\nlet main () =\n let a = input ()\n in let cmp (x, _) (y, _) = compare x y\n in begin\n Array.sort cmp a;\n eat a\n end\n;;\n\nmain ();;\n"}], "src_uid": "0cbd3eee259b1436f82e259be7d7ee0e"} {"source_code": "open Printf\nopen String\nopen Int64\n\nlet n = Scanf.scanf \"%d \" (fun x -> x);;\n\nlet e = Array.make n Int64.zero (*energy for reverse string*)\nlet s = Array.make n \"\" (*stores all the strings to be sorted*)\nlet rs = Array.make n \"\"\n\nlet d1 = Array.make n (Int64.max_int) (*flip*)\n\nlet d2 = Array.make n (Int64.max_int)\n\nfor i = 0 to n-1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%Ld \" (fun x -> x) in\n e.(i) <- jj\ndone\n\nlet rev s =\n let len = String.length s in\n let rec rev_helper i s2 =\n if i >= len then s2\n else\n rev_helper (i+1) s2^(Char.escaped s.[i])\n in\n rev_helper 0 \"\"\n\nfor i = 0 to n - 1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) in\n s.(i) <- jj; rs.(i) <- (rev jj)\ndone\n\nlet () = d1.(0) <- of_int 0;;\nlet () = d2.(0) <- e.(0);;\n\n(*printf \"%Ld\" max_int;;\n*)\n\n(*DEBUG*)\n(*\n let () = print_endline (rev \"abc\")\n\nfor i = 0 to n - 1 do\n print_endline s.(i);\n print_endline rs.(i)\ndone\n*)\n\nlet g s1 s2 =\n let x = String.compare s1 s2 in\n if (x<=0) then of_int 0\n else max_int\n\nlet f s1 s2 n =\n let x = String.compare s1 s2 in\n if (x<=0) then e.(n)\n else max_int\n\nlet my_add a b =\n if ( (compare a max_int == 0 ) || (compare b max_int == 0 ) ) then max_int\n else add a b\n\nlet () = \n for i = 1 to n - 1 do\n let x1 = my_add d1.(i-1) (g s.(i-1) s.(i) ) in\n let x2 = my_add d2.(i-1) (g rs.(i-1) s.(i) ) in\n d1.(i) <- min x1 x2;\n let y1 = my_add d1.(i-1) (f s.(i-1) rs.(i) i ) in\n let y2 = my_add d2.(i-1) (f rs.(i-1) rs.(i) i ) in\n d2.(i) <- min y1 y2\ndone\n\nlet () =\n let x = min d1.(n-1) d2.(n-1) in\n if (x==max_int) then printf \"%d\\n\" (-1)\n else print_endline (to_string x)\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet reverse s =\n let n = String.length s in\n String.init n (fun i -> s.[n-i-1])\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.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let c = Array.init n (fun _ -> long (read_int())) in\n let s = Array.init n (fun _ -> read_string ()) in \n let sr = Array.init n (fun i -> reverse s.(i)) in\n\n let nr_cost = Array.make n 0L in\n let r_cost = Array.make n 0L in\n\n nr_cost.(n-1) <- 0L;\n r_cost.(n-1) <- c.(n-1);\n\n let inf = (Int64.max_int) // 4L in\n \n for i=n-2 downto 0 do\n let test a b = if a > b then inf else 0L in\n nr_cost.(i) <- min\n (nr_cost.(i+1) ++ (test s.(i) s.(i+1)))\n (r_cost.(i+1) ++ (test s.(i) sr.(i+1)));\n r_cost.(i) <- c.(i) ++ min\n (nr_cost.(i+1) ++ (test sr.(i) s.(i+1)))\n (r_cost.(i+1) ++ (test sr.(i) sr.(i+1)));\n nr_cost.(i) <- min nr_cost.(i) inf;\n r_cost.(i) <- min r_cost.(i) inf; \n done;\n\n let total = min nr_cost.(0) r_cost.(0) in\n\n if total = inf then printf \"-1\\n\" else printf \"%Ld\\n\" total\n"}], "negative_code": [{"source_code": "open Printf\nopen String\n\nlet n = Scanf.scanf \"%d \" (fun x -> x);;\n\nlet e = Array.make n (-1) (*energy for reverse string*)\nlet s = Array.make n \"\" (*stores all the strings to be sorted*)\nlet rs = Array.make n \"\"\n\nlet d1 = Array.make n (max_int) (*flip*)\n\nlet d2 = Array.make n (max_int)\n\nfor i = 0 to n-1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\n e.(i) <- jj\ndone\n\nlet rev s =\n let len = String.length s in\n let rec rev_helper i s2 =\n if i >= len then s2\n else\n rev_helper (i+1) s2^(Char.escaped s.[i])\n in\n rev_helper 0 \"\"\n\nfor i = 0 to n - 1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) in\n s.(i) <- jj; rs.(i) <- (rev jj)\ndone\n\nlet () = d1.(0) <- 0;;\nlet () = d2.(0) <- e.(0);;\n\n(*DEBUG*)\n(*\n let () = print_endline (rev \"abc\")\n\nfor i = 0 to n - 1 do\n print_endline s.(i);\n print_endline rs.(i)\ndone\n*)\n\nlet g s1 s2 =\n let x = String.compare s1 s2 in\n if (x<=0) then 0\n else max_int\n\nlet f s1 s2 n =\n let x = String.compare s1 s2 in\n if (x<=0) then e.(n)\n else max_int\n\nlet my_add a b =\n if (a==max_int || b==max_int) then max_int\n else a + b\n\nlet () = \n for i = 1 to n - 1 do\n let x1 = my_add d1.(i-1) (g s.(i-1) s.(i) ) in\n let x2 = my_add d2.(i-1) (g rs.(i-1) s.(i) ) in\n d1.(i) <- min x1 x2;\n let y1 = my_add d1.(i-1) (f s.(i-1) rs.(i) i ) in\n let y2 = my_add d2.(i-1) (f rs.(i-1) rs.(i) i ) in\n d2.(i) <- min y1 y2\ndone\n\nlet () =\n let x = min d1.(n-1) d2.(n-1) in\n if (x==max_int) then\n begin\n print_int (-1); print_endline \"\"\n end\n else\n begin\n print_int x; print_endline \"\"\n end\n\n"}], "src_uid": "91cfd24b8d608eb379f709f4509ecd2d"} {"source_code": "open Str;;\nopen Array;;\nlet n = read_int () and ans = ref 0 and price = ref 101;;\nfor i = 1 to n do\n let ins = map (int_of_string) (of_list (split (regexp \" \") (read_line ()))) in\n let a = ins.(0) and b = ins.(1) in\n begin\n price := min !price b;\n ans := !ans + !price * a; \n end;\ndone;;\nprint_int !ans;;\n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let rec loop i list =\n if i < n\n then\n let mass = read () in\n let price = read () in\n loop (i + 1) ((mass, price) :: list)\n else\n List.rev list\n in loop 0 []\n\nlet get_min price min =\n if price >= min\n then \n min\n else\n price\n\nlet get_sum sum min mass =\n sum + min * mass\n\nlet update_sum_min (mass, price) (sum, min) = \n let min_upd = get_min price min in\n let sum_upd = get_sum sum mass min_upd in\n (sum_upd, min_upd)\n \nlet solve list = \n let rec loop (sum, min) list =\n match list with\n | (head :: tail) -> loop (update_sum_min head (sum, min)) tail\n | [] -> sum\n in loop (0, 101) list\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n\t\t\t let a = Array.init n (fun _ ->\n\t\t\t\t\t\t Scanf.scanf \"%d %d\\n\"\n\t\t\t\t\t\t\t (fun a w -> (a, w))) in\n\t\t\t (* buy as much as we need to hit the next cheapest day *)\n\t\t\t let rec calc cur acc =\n\t\t\t if cur >= n then acc\n\t\t\t else begin\n\t\t\t\t let rec loop i s =\n\t\t\t\t if i >= n || snd a.(i) < snd a.(cur)\n\t\t\t\t then i, s\n\t\t\t\t else loop (i + 1) (s + fst a.(i) * snd a.(cur)) in\n\t\t\t\t let next, add = loop cur 0 in\n\t\t\t\t calc next (acc + add)\n\t\t\t\t end\n\t\t\t in\n\t\t\t Printf.printf \"%d\\n\" (calc 0 0))\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c%d%_c\" (fun x y -> (x, y))) in\n\n\tlet sum = ref 0 in\n\n\tlet min = ref 2000000 in\n\n\tlet rec loop i = \n\t\tif i < n then\n\t\tbegin\n\t\t\tlet (x, y) = a.(i) in\n\t\t\tif !min > y then begin min := y end;\n\t\t\tsum := !sum + x * !min;\n\t\t\tloop (i+1)\n\t\tend\n\tin\n\tloop 0;\n\tPrintf.printf \"%d\\n\" !sum);;"}], "negative_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c%d%_c\" (fun x y -> (x, y))) in\n\n\tlet sum = ref 0 in\n\n\tlet min = ref 2000000 in\n\n\tlet rec loop i = \n\t\tif i < n then\n\t\tbegin\n\t\t\tlet (x, y) = a.(i) in\n\t\t\tif !min > x then begin min := x end;\n\t\t\tsum := !sum + y * !min;\n\t\t\tloop (i+1)\n\t\tend\n\tin\n\tloop 0;\n\tPrintf.printf \"%d\\n\" !sum);;"}, {"source_code": "let x = fun n -> n\nin x 20;;"}], "src_uid": "28e0822ece0ed35bb3e2e7fc7fa6c697"} {"source_code": "let n = read_int () in\nlet tr = Array.make n false in\n\nlet g () =\nlet l = Scanf.Scanning.from_string (read_line ()) in\ntry\nlet tc = Scanf.bscanf l \"%d \" (fun x -> x) in\n(for i = 1 to tc do\n let k = Scanf.bscanf l \"%d \" (fun x -> x) in\n tr.(k-1) <- true\ndone)\nwith _ -> ()\nin\ng() ; g() ;\n\nlet f () =\n let result = ref true in\n for i = 0 to n-1 do\n if tr.(i) = false then result := false\n done;\n !result\nin\n\nif f () then \nprint_endline \"I become the guy.\"\nelse \nprint_endline \"Oh, my keyboard!\";;\n", "positive_code": [{"source_code": "module IntSet = Set.Make( \n struct\n let compare = Pervasives.compare\n type t = int\n end ) ;;\n\nlet rec split s i acc =\nbegin\n if i > String.length s \n then List.rev acc\n else \n let first = \n if String.contains_from s i ' ' \n then String.index_from s i ' ' \n else String.length s \n in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc) \nend in \n\nlet from_list xs = List.fold_right IntSet.add xs IntSet.empty in \nlet alln = \n let len = int_of_string (read_line()) in \n Array.init len (fun a -> a+1) \n |> (fun xs -> Array.fold_right IntSet.add xs IntSet.empty) in \nlet x = split (read_line ()) 0 [] |> List.tl |> from_list in\nlet y = split (read_line ()) 0 [] |> List.tl |> from_list in \nprint_string (if IntSet.equal alln (IntSet.union x y) then \"I become the guy.\" else \"Oh, my keyboard!\") \n"}, {"source_code": "let 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 read () = List.map (fun n -> Pervasives.int_of_string n) (Str.split (Str.regexp \" \") (Pervasives.read_line ()))\n\nlet n = Pervasives.read_int ()\nlet x_levels = read ()\nlet y_levels = read ()\n\nlet result = \n let len = List.length (get_uniques (List.sort (compare) (List.append (List.tl x_levels) (List.tl y_levels))))\n in\n if len = n\n then\n \"I become the guy.\"\n else\n \"Oh, my keyboard!\"\n\nlet () = Printf.printf \"%s\\n\" result\n"}, {"source_code": "let read () = let total = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop list n =\n if n > 0\n then\n let var = Scanf.scanf \"%d \" (fun k -> k) in\n loop (var :: list) (n - 1)\n else\n list\n in loop [] total\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 n = Scanf.scanf \"%d \" (fun n -> n)\nlet x_levels = read ()\nlet y_levels = read ()\n\nlet result = \n let len = List.length (get_uniques (List.sort (compare) (List.append x_levels y_levels)))\n in\n if len = n\n then\n \"I become the guy.\"\n else\n \"Oh, my keyboard!\"\n\nlet () = Printf.printf \"%s\\n\" result\n"}], "negative_code": [{"source_code": "let 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 read () = List.map (fun n -> Pervasives.int_of_string n) (Str.split (Str.regexp \" \") (Pervasives.read_line ()))\n\nlet n = Pervasives.read_int ()\nlet x_levels = read ()\nlet y_levels = read ()\n\nlet result = \n let len = List.length (get_uniques (List.sort (compare) (List.append x_levels y_levels)))\n in\n if len = n\n then\n \"I become the guy.\"\n else\n \"Oh, my keyboard!\"\n\nlet () = Printf.printf \"%s\\n\" result\n"}, {"source_code": "let n = read_int () in\nlet tr = Array.make n false in\n\nlet g () =\nlet l = Scanf.Scanning.from_string (read_line ()) in\ntry\n(for i = 1 to n do\n let k = Scanf.bscanf l \"%d \" (fun x -> x) in\n tr.(k-1) <- true\ndone)\nwith _ -> ()\nin\ng() ; g() ;\n\nlet f () =\n let result = ref true in\n for i = 0 to n-1 do\n if tr.(i) = false then result := false\n done;\n !result\nin\n\nif f () then \nprint_endline \"I become the guy.\"\nelse \nprint_endline \"Oh, my keyboard!\";;\n"}, {"source_code": "let n = read_int () in\nlet tr = Array.make n false in\n\nlet g () =\nlet l = Scanf.Scanning.from_string (read_line ()) in\ntry\n(for i = 1 to n do\n let k = Scanf.bscanf l \"%d \" (fun x -> x) in\n tr.(k-1) <- true\ndone)\nwith _ -> ()\nin\ng() ; g() ;\n\nlet f () =\n let result = ref true in\n for i = 0 to n-1 do\n if tr.(i) = false then result := false\n done;\n !result\nin\n\nif f () then \nprint_endline \"I become the guy\"\nelse \nprint_endline \"Oh, my keyboard!\";;\n"}, {"source_code": "module IntSet = Set.Make( \n struct\n let compare = Pervasives.compare\n type t = int\n end ) ;;\n\nlet rec split s i acc =\nbegin\n if i == 1 + String.length s \n then acc\n else \n let first = \n if String.contains_from s i ' ' \n then String.index_from s i ' ' \n else String.length s\n in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc) \nend in \n\nlet from_list xs = List.fold_right IntSet.add xs IntSet.empty in \nlet alln = \n let len = int_of_string (read_line()) in \n Array.init len (fun a -> a+1) \n |> (fun xs -> Array.fold_right IntSet.add xs IntSet.empty) in \nlet x = split (read_line ()) 0 [] |> List.tl |> from_list in\nlet y = split (read_line ()) 0 [] |> List.tl |> from_list in \nprint_string (if IntSet.equal alln (IntSet.union x y) then \"I become the guy.\" else \"Oh, my keyboard!\") \n"}], "src_uid": "044ade01d2de1486735742369227ae1d"} {"source_code": "module MultiSet_test = struct\n module Make (X:Map.OrderedType) = struct\n include Map.Make(X)\n let count v set =\n try find v set with Not_found -> 0\n let remove_each v set =\n let k = count v set in\n if k<=0 then raise Not_found\n else if k=1 then remove v set\n else add v (k-1) set\n let add_each v set =\n let k = count v set in\n if k=0 then add v 1 set\n else add v (k+1) set\n let iter_each f set =\n let rec f0 k = function\n | 0 -> ()\n | i -> let () = f k in f0 k (i-1)\n in iter f0 set\n let fold_each f set ac =\n let rec f0 k i ac = match i with\n | 0 -> ac\n | i -> f0 k (i-1) (f k ac)\n in fold f0 set ac\n let bindings_each set =\n fold_each (fun v ls -> v::ls) set []\n |> List.rev\n let min_binding_each set = fst @@ min_binding set\n let max_binding_each set = fst @@ max_binding set\n let exists_each f = exists (fun k _ -> f k)\n let cardinal_each set =\n (* O(#node). an aux variable might lead you to O(1) perf *)\n fold (fun _ v sum -> sum + v) set 0\n end\nend\nmodule S = MultiSet_test.Make (struct\n type t = int let compare = compare\nend);;\nArray.(Scanf.(\n scanf \" %d %d\" @@ fun n m ->\n let a = init m (fun _ -> scanf \" %d\" @@ fun v -> v) in\n let c = make n 0 in\n fold_left (fun (s,round) v ->\n let v = v-1 in\n let s = S.remove_each c.(v) s in\n let s = S.add_each (c.(v)+1) s in\n c.(v) <- c.(v) + 1;\n let p = S.min_binding_each s in\n print_char (\n if p > round then '1' else '0'\n ); (s,p)\n ) (S.singleton 0 n, 0) a |> ignore))", "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_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\nmodule SegTree = struct\n module type S = sig\n type t\n val op: t -> t -> t\n val ide: t\n val upd: t -> t -> t\n end\n module RMQ = struct type t = int64 let op = min let ide = max_i64 let upd u v = v end\n module RSQ = struct type t = int64 let op = (+) let ide = 0L let upd u v = u+v end\n let par i = (i-$1)/$2\n let chl i = 2*$i+$1\n let chr i = 2*$i+$2\n module Make (X:S) = struct\n type t = SegTree of (X.t array * int)\n let raw (SegTree (a,_)) = a\n let make raw = (* O(n) *)\n let ln = Array.length raw in\n let n =\n let n = ref 1 in\n while !n0 do\n i := par !i;\n a.(!i) <- X.op a.(chl !i) a.(chr !i) done\n let get_half_open (SegTree(a,n)) l r = (* O(logn), [l,r) *)\n let rec f0 i p q =\n if q<=l || r<=p then X.ide\n else if l<=p && q<=r then a.(i)\n else\n let vl = f0 (2*$i+$1) p ((p+$q)/$2) in\n let vr = f0 (2*$i+$2) ((p+$q)/$2) q in\n X.op vl vr\n in f0 0 0 n\n let get_closed seg l r = get_half_open seg l (r+$1) (* [l,r] *)\n end\nend\nmodule SI = SegTree.Make(struct\n type t = int64\n let op = min let ide = max_i64 let upd u v = v\nend)\nlet () =\n let n,m = g2 0 in\n let a = iia m in\n let s = SI.make @@ make (i32 n) 0L in\n let k = ref 1L in\n iter (fun v ->\n let i = i32 v -$ 1 in\n SI.update_destructive s i (SI.get_closed s i i + 1L);\n let mn = SI.get_closed s 0 (i32 n-$1) in\n if mn = !k then (\n printf \"1\"; k += 1L\n ) else printf \"0\";\n (* printf \": %Ld : %Ld : %s\\n\" mn !k (\n string_of_array ist @@ init (i32 n) (fun i -> SI.get_closed s i i)\n ) *)\n ) a\n\n (* let b = make (i32 n) 0L in\n let k = ref 1L in\n iter (fun v ->\n let i = i32 v -$ 1 in\n b.(i) <- b.(i) + 1L;\n if fold_left min max_i64 b = !k then (\n printf \"1\"; k += 1L\n ) else printf \"0\"\n ) a *)\n\n\n(* module BIT = struct\n let lsb i = i land -i\n let sum i b = (* 0-indexed; \u03a3a[0,i-1] *)\n fix (fun f i s -> if i>0 then f (i -$ lsb i) (s + b.(i)) else s) i 0L\n let sum_closed i = sum (i+$1) (* 0-indexed; \u03a3a[0,i] *)\n let sum_interval l r b = (* 0-indexed; \u03a3a[l,r] = \u03a3a[0,r+1-1] - \u03a3[0,l-1] *)\n if l>r then 0L else sum (r+$1) b - sum l b\n let add i x b = (* 0-indexed; a[i]+=x. not b *)\n if i<0 then raise @@ Invalid_argument \"index should be >= 1 (0-indexed a[i-1]+=x)\";\n fix (fun f i -> if i add (i+$1) v b) a; b\n let make n = Array.make (n+$1) 0L\n let reconst b = Array.init (Array.length b-$1) (fun i -> sum_interval i i b)\n (* initialization: http://hos.ac/slides/20140319_bit.pdf *)\nend\nlet () =\n let n,m = g2 0 in\n let a = iia m in\n let b = BIT.make (i32 n+$1) in\n let k = ref 1L in\n iter (fun v ->\n BIT.add (i32 v) 1L b;\n if BIT.sum_closed (i32 n) b = !k then (\n printf \"1\";\n k += 1L\n ) else (\n printf \"0\"\n )\n ) a; *)\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "open Printf\nopen Scanf\n\nmodule Pset = Set.Make (struct type t = int*int let compare = compare end)\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\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 read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,m) = read_pair () in\n let a = Array.init m (fun _ -> read_int() -1) in (*difficulty reduced by 1 *)\n\n let hist = Array.make n 0 in\n\n let rec insert i s = if i=n then s else insert (i+1) (Pset.add (0,i) s) in\n\n let set = insert 0 Pset.empty in\n\n let rec loop j s prev_low_freq = if j=m then () else (\n let old = (hist.(a.(j)), a.(j)) in\n hist.(a.(j)) <- hist.(a.(j)) + 1;\n let new_elt = (hist.(a.(j)), a.(j)) in\n let s = Pset.remove old s in\n let s = Pset.add new_elt s in\n let (freq,_) = Pset.min_elt s in\n if freq > prev_low_freq then printf \"1\" else printf \"0\";\n loop (j+1) s freq\n ) in\n\n let () = loop 0 set 0 in\n print_newline()\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () and m = read_int () in\n let a = Array.init m read_int\n and cnt = Array.make (n + 1) 0\n and ans = Array.make m 0\n and index = ref 1 in\n for i = 0 to m - 1 do\n cnt.(a.(i)) <- cnt.(a.(i)) + 1;\n while cnt.(!index) <> 0 do\n cnt.(!index) <- cnt.(!index) - 1;\n if !index = n then ans.(i) <- 1;\n index := !index mod n + 1\n done\n done;\n for i = 0 to m - 1 do\n printf \"%d\" ans.(i)\n done"}, {"source_code": "Array.(Scanf.(\n scanf \" %d %d\" @@ fun n m ->\n let cnt,exist = make n 0, make m 0 in\n init m @@ fun _ -> scanf \" %d\" @@ fun v -> (\n let v = v - 1 in\n exist.(cnt.(v)) <- exist.(cnt.(v)) + 1;\n print_string (\n if exist.(cnt.(v)) = n then \"1\" else \"0\");\n cnt.(v) <- cnt.(v) + 1)))"}, {"source_code": "module SegTree = struct\n module type S = sig\n type t\n val op: t -> t -> t\n val ide: t\n val upd: t -> t -> t\n end\n module RMQ : S with type t = int64 =\n struct\n type t = int64 let op = min\n let ide = Int64.max_int let upd _ v = v\n end\n module RSQ : S with type t = int64 =\n struct\n type t = int64 let op = Int64.add\n let ide = 0L let upd prev v = op prev v\n end\n let par i = (i-1)/2\n let chl i = 2*i+1\n let chr i = 2*i+2\n module Make (X:S) = struct\n type t = SegTree of (X.t array * int)\n let raw (SegTree (a,_)) = a\n let make raw = (* O(n) *)\n let ln = Array.length raw in\n let n =\n let n = ref 1 in\n while !n0 do\n i := par !i;\n a.(!i) <- X.op a.(chl !i) a.(chr !i) done\n let get_half_open (SegTree(a,n)) l r = (* O(logn), [l,r) *)\n let rec f0 i p q =\n if q<=l || r<=p then X.ide\n else if l<=p && q<=r then a.(i)\n else\n let vl = f0 (2*i+1) p ((p+q)/2) in\n let vr = f0 (2*i+2) ((p+q)/2) q in\n X.op vl vr\n in f0 0 0 n\n let get_closed seg l r = get_half_open seg l (r+1) (* [l,r] *)\n end\nend\nlet (++) = Int64.add\nmodule S = SegTree.Make(SegTree.RMQ);;\nScanf.(Array.(scanf \" %d %d\" @@ fun n m ->\n let a = init m (fun _ -> scanf \" %d\" @@ fun v -> v) in\n let s = S.make @@ make (n+1) 0L in\n fold_left (fun k v ->\n S.update_destructive s v (S.get_closed s v v ++ 1L);\n if S.get_closed s 1 n = k then (\n print_int 1; k++1L\n ) else (\n print_int 0; k\n )\n ) 1L a |> ignore\n))"}], "negative_code": [], "src_uid": "2070955288b2e2cdbae728d8e7ce78ab"} {"source_code": "let rec fix f x = f (fix f) x\nlet gcd = fix (fun f m n ->\n if n=0 then m else f n (m mod n));;\nScanf.(Array.(\n let t = scanf \" %d\" @@ fun v -> v in\n init t (fun _ ->\n let d = scanf \" %d\" @@ fun v -> v in\n let g = gcd 180 (180-d) in\n let p,q = 180/g,(180-d)/g in\n Printf.printf \"%d\\n\" @@\n if q=1 then p*2 else p)))", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec gcd a b = if a=0 then b else gcd (b mod a) a\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () =\n let cases = read_int () in\n for case = 1 to cases do\n let ang = read_int () in\n let num = 2*ang in\n let den = 360 in\n let g = gcd num den in\n let (num,den) = (num/g, den/g) in\n let (num,den) = if num+1 = den then (2*num,2*den) else (num,den) in\n printf \"%d\\n\" den\n done\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 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 t = gi 0 in\n rep 1L t (fun _ ->\n let d = gi 0 in\n let g = gcd 180L (180L-d) in\n let p,q = 180L/g, (180L-d)/g in\n (* n=pi,k=qi *)\n let f = ref false in\n rep 1L 180L (fun i ->\n let n1,k1 = p*i,q*i in\n if not !f && k1 < n1 && k1 >= 2L then (\n f := true;\n (* printf \" %Ld; %Ld\\n\" n1 k1; *)\n printf \"%Ld\\n\" n1;\n )\n )\n )\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "let rec fix f x = f (fix f) x\nlet gcd = fix (fun f m n ->\n if n=0 then m else f n (m mod n));;\nScanf.(Array.(\n let t = scanf \" %d\" @@ fun v -> v in\n init t (fun _ ->\n let d = scanf \" %d\" @@ fun v -> v in\n let g = gcd 180 (180-d) in\n let p,q = 180/g,(180-d)/g in\n Printf.printf \"%d\\n\" @@ p*2)))"}, {"source_code": "let rec fix f x = f (fix f) x\nlet gcd = fix (fun f m n ->\n if n=0 then m else f n (m mod n));;\nScanf.(Array.(\n let t = scanf \" %d\" @@ fun v -> v in\n init t (fun _ ->\n let d = scanf \" %d\" @@ fun v -> v in\n let g = gcd 180 (180-d) in\n let p,q = 180/g,(180-d)/g in\n Printf.printf \"%d\\n\" @@\n if q=1 then p else p*2\n )\n))"}], "src_uid": "d11b56fe172110d5dfafddf880e48f18"} {"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 end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done\n\tlet 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\nend open MyInt64\n\nlet () =\n\tlet n,k = get_2_i64 0\n\tin\n\tlet a0 = ceildiv k n\n\tin printf \"%Ld\\n\" a0\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let split_on_space (str: string): string list =\n\tlet length = String.length str in\n\tlet is_space: int -> bool = \n\t\tfun index ->\n\t\t\tif (index < 0) || (index >= length) then true\n\t\t\telse str.[index] = ' '\n\tin\n\tlet is_start: int -> bool =\n\t\tfun index -> not (is_space index) && is_space (index - 1)\n\tin\n\tlet is_end: int -> bool =\n\t\tfun index -> not (is_space index) && is_space (index + 1)\n\tin\n\tlet indices = Array.init length (fun i -> i) in\n\tlet indices = Array.to_list indices in\n\tlet start_pos = List.filter is_start indices in \n\tlet end_pos = List.filter is_end indices in\n\tlet make_substring: string list -> int -> int -> string list =\n\t\tfun tokens left right ->\n\t\t\tlet new_token = String.sub str left (right - left + 1) in\n\t\t\tnew_token :: tokens\n\tin\n\tlet tokens = List.fold_left2 make_substring [] start_pos end_pos in\n\tList.rev tokens\n\t\t\t\n\nclass reader channel =\n\tobject (this)\n\n\tval mutable tokens = []\n\n method private get_tokens () =\n let new_line = read_line () in\n let tokens = split_on_space new_line in\n match tokens with\n | [] -> this#get_tokens ()\n | _ -> tokens\n\n\tmethod next_string () =\n if (List.length tokens = 0) then tokens <- this#get_tokens();\n let result = List.hd tokens in\n tokens <- List.tl tokens; result\n\n method next_int () =\n let str = this#next_string() in (Int64.of_string) str\n\n method next_float () =\n let str = this#next_string() in (float_of_string) str\n \nend\n\nlet reader = new reader stdin\n\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( * ) = Int64.mul\nlet ( / ) = Int64.div\nlet ( % ) = Int64.rem\n\nlet compare = Int64.compare\nlet ( = ) a b = compare a b = 0\nlet ( < ) a b = compare a b < 0\nlet ( > ) a b = compare a b > 0\nlet ( <= ) a b = compare a b <= 0\nlet ( >= ) a b = compare a b >= 0\n\nlet () =\n let n = reader#next_int () in\n let k = reader#next_int () in \n let res = k / n in\n let res = if k % n = Int64.zero then res else res + Int64.one in \n print_endline (Int64.to_string res);\n "}], "negative_code": [{"source_code": "let split_on_space (str: string): string list =\n\tlet length = String.length str in\n\tlet is_space: int -> bool = \n\t\tfun index ->\n\t\t\tif (index < 0) || (index >= length) then true\n\t\t\telse str.[index] = ' '\n\tin\n\tlet is_start: int -> bool =\n\t\tfun index -> not (is_space index) && is_space (index - 1)\n\tin\n\tlet is_end: int -> bool =\n\t\tfun index -> not (is_space index) && is_space (index + 1)\n\tin\n\tlet indices = Array.init length (fun i -> i) in\n\tlet indices = Array.to_list indices in\n\tlet start_pos = List.filter is_start indices in \n\tlet end_pos = List.filter is_end indices in\n\tlet make_substring: string list -> int -> int -> string list =\n\t\tfun tokens left right ->\n\t\t\tlet new_token = String.sub str left (right - left + 1) in\n\t\t\tnew_token :: tokens\n\tin\n\tlet tokens = List.fold_left2 make_substring [] start_pos end_pos in\n\tList.rev tokens\n\t\t\t\n\nclass reader channel =\n\tobject (this)\n\n\tval mutable tokens = []\n\n method private get_tokens () =\n let new_line = read_line () in\n let tokens = split_on_space new_line in\n match tokens with\n | [] -> this#get_tokens ()\n | _ -> tokens\n\n\tmethod next_string () =\n if (List.length tokens = 0) then tokens <- this#get_tokens();\n let result = List.hd tokens in\n tokens <- List.tl tokens; result\n\n method next_int () =\n let str = this#next_string() in (Int64.of_string) str\n\n method next_float () =\n let str = this#next_string() in (float_of_string) str\n \nend\n\nlet reader = new reader stdin\n\nlet () =\n let n = reader#next_int () in\n let k = reader#next_int () in \n let res = if n > k then Int64.one else Int64.div k n in\n print_endline (Int64.to_string res);\n flush stdout\n "}], "src_uid": "31014efa929af5e4b7d9987bd9b59918"} {"source_code": "open Scanf\nopen Printf\n\nlet print_list_x l = List.iter (fun (a,b) -> printf \"%d %s\\n\" a (if b = -1 then \"starts\" else \"ends\")) l\nlet print_list l = List.iter (fun (a,b) -> printf \"%d %d\\n\" a b) l\n\nlet read_int () = scanf \" %d\" (fun x -> x)\nlet read_pair () = scanf \" %d %d\" (fun x y -> (x,y))\nlet read_list num =\n let rec pom num acc =\n if num = 0 then acc\n else\n let a,b = read_pair () in\n let x,y = (a, -1), (b, 1) in\n pom (num - 1) (x :: y :: acc)\n in pom num []\n\nlet n = read_int ()\nlet k = read_int ()\nlet intervals = read_list n\n\n(*let get_result ar =\n let cur = ref (fst( ar.(0)))\n and ind, curind = ref 0, ref 0\n and cnt = ref 0 in\n while !ind < n do\n cnt := 0;\n curind := !ind;\n printf \"Having %d \\n\" (fst(ar.(!curind)));\n while !curind < n && fst(ar.(!curind)) = !cur do\n incr cnt;\n let (a,b) = ar.(!curind) in\n ar.(!curind) <- (a+1, b);\n incr curind\n done;\n let (a,b) = ar.(!ind) in\n if (a > b) then incr ind;\n if !cnt >= k then printf \"%d \\n\" !cur; (* fixme *)\n cur := fst (ar.(!ind))\n done*)\n\nlet update_result (level, last, li) (num, state) =\n let nlevel = level - state in\n if nlevel = k && state = -1 then (nlevel, num, li)\n else if level = k && state = 1 then (nlevel, num, (last, num)::li)\n else (nlevel, last, li)\n\nlet get_result l =\n let _, _, a = List.fold_left update_result (0, 0, []) l\n in List.rev a\n (*let loop l cnt acc =\n match l with\n | []\n | (a,b)::t ->\n in loop l 0 []*)\n\nlet print_result res =\n print_int (List.length res); print_newline ();\n print_list res\n\nlet intervals = List.sort compare intervals\nlet res = get_result intervals\nlet () = print_result res\n", "positive_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let n = getnum () in\n let k = getnum () in\n let a = Array.make (2 * n) (0, 0) in\n for i = 0 to n - 1 do\n let l = getnum () in\n let r = getnum () in\n\ta.(2 * i) <- (l, 0);\n\ta.(2 * i + 1) <- (r, 1);\n done;\n Array.sort compare a;\n let res = ref [] in\n let cnt = ref 0 in\n let start = ref 0 in\n for i = 0 to 2 * n - 1 do\n\tlet (x, t) = a.(i) in\n\t if !cnt >= k\n\t then res := (!start, x) :: !res;\n\t if t = 0\n\t then incr cnt\n\t else decr cnt;\n\t if !cnt >= k\n\t then start := x;\n done;\n let res = List.rev !res in\n let rec combine =\n\tfunction\n\t | [] -> []\n\t | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->\n\t combine ((x1, y2) :: xs)\n\t | x :: xs ->\n\t x :: combine xs\n in\n let res = combine res in\n\tPrintf.printf \"%d\\n\" (List.length res);\n\tList.iter (fun (x, y) -> Printf.printf \"%d %d\\n\" x y) res;\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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make (2 * n) (0, 0) in\n for i = 0 to n - 1 do\n let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(2 * i) <- (l, 0);\n\ta.(2 * i + 1) <- (r, 1);\n done;\n Array.sort compare a;\n let res = ref [] in\n let cnt = ref 0 in\n let start = ref 0 in\n for i = 0 to 2 * n - 1 do\n\tlet (x, t) = a.(i) in\n\t if !cnt = k\n\t then res := (!start, x) :: !res;\n\t if t = 0\n\t then incr cnt\n\t else decr cnt;\n\t if !cnt = k\n\t then start := x;\n done;\n let res = List.rev !res in\n let rec combine =\n\tfunction\n\t | [] -> []\n\t | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->\n\t combine ((x1, y2) :: xs)\n\t | x :: xs ->\n\t x :: combine xs\n in\n let res = combine res in\n\tPrintf.printf \"%d\\n\" (List.length res);\n\tList.iter (fun (x, y) -> Printf.printf \"%d %d\\n\" x y) res;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make (2 * n) (0, 0) in\n for i = 0 to n - 1 do\n let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(2 * i) <- (l, 0);\n\ta.(2 * i + 1) <- (r, -1);\n done;\n Array.sort compare a;\n let res = ref [] in\n let cnt = ref 0 in\n let start = ref 0 in\n for i = 0 to 2 * n - 1 do\n\tlet (x, t) = a.(i) in\n\t if !cnt = k\n\t then res := (!start, x) :: !res;\n\t if t = 0\n\t then incr cnt\n\t else decr cnt;\n\t if !cnt = k\n\t then start := x;\n done;\n let res = List.rev !res in\n let rec combine =\n\tfunction\n\t | [] -> []\n\t | (x1, y1) :: (x2, y2) :: xs when y1 = x2 ->\n\t combine ((x1, y2) :: xs)\n\t | x :: xs ->\n\t x :: combine xs\n in\n let res = combine res in\n\tPrintf.printf \"%d\\n\" (List.length res);\n\tList.iter (fun (x, y) -> Printf.printf \"%d %d\\n\" x y) res;\n"}], "src_uid": "eafd37afb15f9f9d31c2a16a32f17763"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\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 n = read_int() in\n let k = read_int() in\n let s = Array.init n (fun _ -> read_int()) in\n\n let fit size = (* return true if they fit in k boxes of size s. Assume s >= s.(n-1) *)\n let rec loop i j count =\n if i = j then count+1 else if i>j then count else (\n\tif s.(i) + s.(j) > size\n\tthen loop i (j-1) (count+1)\n\telse loop (i+1) (j-1) (count+1)\n )\n in\n let c = loop 0 (n-1) 0 in\n c <= k\n in\n\n let rec bsearch lo hi = (* lo fails and hi succeeds *)\n if lo = hi-1 then hi else\n let m = (lo+hi)/2 in\n if fit m then bsearch lo m else bsearch m hi\n in\n\n let answer = if fit s.(n-1)\n then s.(n-1)\n else bsearch s.(n-1) (2*(s.(n-1)))\n in\n\n printf \"%d\\n\" answer\n", "positive_code": [{"source_code": "let main () =\n let (n,k) = Scanf.scanf \"%d %d\" (fun i j -> (i,j)) in\n let tab = Array.make (2 * k) 0 in\n for i=1 to n do\n Scanf.scanf \" %d\" (fun j -> tab.(n - i) <- j);\n done;\n let res = ref 0 in\n for i=0 to 2*k - 1 do\n res := max !res (tab.(i) + tab.(2 * k - i - 1));\n done;\n Printf.printf \"%d\" !res;;\n\nmain ();;\n"}], "negative_code": [], "src_uid": "7324428d9e6d808f55ad4f3217046455"} {"source_code": "open Printf\nopen Scanf\n\nlet read_string _ = bscanf Scanning.stdib \" %s \" (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)\n\nlet () =\n let s = read_string() in\n let len = String.length s in\n\n let rec parse i ac = if i=len then List.rev (('+',len)::ac) else\n match s.[i] with\n\t| '+' | '-' -> parse (i+1) ((s.[i],i)::ac)\n\t| _ -> parse (i+1) ac\n in\n\n let seq = Array.of_list (parse 0 [('+',-1)]) in\n\n let eval = fold 1 (-1 + Array.length seq) (fun i ac ->\n let sign = if fst seq.(i-1) = '+' then 1 else -1 in\n let place = 1 + snd seq.(i-1) in\n let l = (snd seq.(i)) - place in\n ac + sign * (int_of_string (String.sub s place l))\n ) 0 in\n\n let digits = string_of_int eval in\n\n for i=0 to -1+String.length digits do\n let d = int_of_char digits.[i] in\n printf \">\";\n for j=1 to d do printf \"+\" done;\n printf \".\";\n done;\n\n print_newline()\n", "positive_code": [{"source_code": "open Genlex\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let lexer = make_lexer [\"+\"; \"-\"] in\n let tokens = Stream.npeek 1000000 (lexer (Stream.of_string s)) in\n let res = ref 0 in\n let s = ref 1 in\n List.iter\n (function\n\t | Int n -> res := !res + !s * n\n\t | Kwd \"+\" -> s := 1\n\t | Kwd \"-\" -> s := -1\n\t | _ -> assert false\n ) tokens;\n let res = string_of_int !res in\n for i = 0 to String.length res - 1 do\n\tfor j = 1 to Char.code res.[i] do\n\t Printf.printf \"+\"\n\tdone;\n\tPrintf.printf \".\\n\";\n\tfor j = 1 to Char.code res.[i] do\n\t Printf.printf \"-\"\n\tdone;\n done\n"}], "negative_code": [{"source_code": "open Genlex\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let lexer = make_lexer [\"+\"; \"-\"] in\n let tokens = Stream.npeek 1000000 (lexer (Stream.of_string s)) in\n let res = ref 0 in\n let s = ref 1 in\n List.iter\n (function\n\t | Int n -> res := !res + !s * n\n\t | Kwd \"+\" -> s := 1\n\t | Kwd \"-\" -> s := -1\n\t | _ -> assert false\n ) tokens;\n let res = string_of_int !res in\n for i = 0 to String.length res - 1 do\n\tfor j = 1 to Char.code res.[i] do\n\t Printf.printf \"+\"\n\tdone;\n\tPrintf.printf \".\\n\"\n done\n"}, {"source_code": "open Genlex\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let lexer = make_lexer [\"+\"; \"-\"] in\n let tokens = Stream.npeek 1000000 (lexer (Stream.of_string s)) in\n let res = ref 0 in\n let s = ref 1 in\n List.iter\n (function\n\t | Int n -> res := !res + !s * n\n\t | Kwd \"+\" -> s := 1\n\t | Kwd \"-\" -> s := -1\n\t | _ -> assert false\n ) tokens;\n for i = 1 to !res do\n Printf.printf \"+\"\n done;\n Printf.printf \".\\n\"\n"}], "src_uid": "072797682246c465148bd09736b76718"} {"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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make m 0 in\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = k - 1 in\n\ta.(k) <- a.(k) + 1\n done;\n let res = ref 0L in\n for i = 0 to m - 1 do\n\tfor j = i + 1 to m - 1 do\n\t res := !res +| Int64.of_int a.(i) *| Int64.of_int a.(j)\n\tdone\n done;\n Printf.printf \"%Ld\\n\" !res\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet ( ++ ) a b = Int64.add a b\nlet ( ** ) a b = Int64.mul 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))\n\nlet () = \n\n let n = read_int() in\n let m = read_int() in \n let a = Array.init n (fun _ -> read_int()) in\n\n let count = Array.make (m+1) 0L in\n\n for i=0 to n-1 do\n count.(a.(i)) <- 1L ++ count.(a.(i))\n done;\n\n let answer =\n sum 1 (m-1) (fun i -> sum (i+1) m (fun j -> count.(i)**count.(j)) 0L) 0L\n in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [], "src_uid": "e2ff228091ca476926b8e905f1bc8dff"} {"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 \"%d \" (fun s -> s) in\n let a = Array.make n 0L in\n let es = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%Ld \" (fun s -> s)\n done;\n for i = 1 to n - 1 do\n let p = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let c = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tes.(p - 1) <- (i, c) :: es.(p - 1)\n done;\n in\n let es = Array.map Array.of_list es in\n let res = ref 0 in\n let rec dfs u s =\n if s < 0L || s > a.(u)\n then incr res;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet (v, c) = es.(u).(i) in\n\t if s < 0L || s > a.(u)\n\t then dfs v (-1L)\n\t else (\n\t let s = max 0L (s +| c) in\n\t dfs v s\n\t )\n done\n in\n dfs 0 0L;\n Printf.printf \"%d\\n\" !res\n", "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.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> long (read_int())) in\n\n let tree = Array.make n [] in\n let c = Array.make n 0L in\n let add_edge i j =\n tree.(i) <- j::tree.(i);\n tree.(j) <- i::tree.(j)\n in\n\n for i = 1 to n-1 do\n let p = -1 + read_int() in\n c.(i) <- long (read_int());\n add_edge i p\n done;\n\n let mark = Array.make n false in\n\n let rec dfs v p dist =\n List.iter (fun w ->\n if w <> p then (\n\tlet dist = max 0L (dist ++ c.(w)) in\n\tdfs w v dist;\n\tif dist > a.(w) then mark.(w) <- true\n )\n ) tree.(v)\n in\n\n dfs 0 (-1) 0L;\n\n let rec dfs2 v p =\n if mark.(v) then 0 else (\n List.fold_left (fun ac w ->\n\tif w = p then ac else ac + (dfs2 w v)\n ) 1 tree.(v)\n )\n in\n\n let good_count = dfs2 0 (-1) in\n\n printf \"%d\\n\" (n - good_count)\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\nlet short x = Int64.to_int x\n\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 _ -> long (read_int())) in\n\n let tree = Array.make n [] in\n let c = Array.make n 0L in\n let add_edge i j =\n tree.(i) <- j::tree.(i);\n tree.(j) <- i::tree.(j)\n in\n\n for i = 1 to n-1 do\n let p = -1 + read_int() in\n c.(i) <- long (read_int());\n add_edge i p\n done;\n\n let mark = Array.make n false in\n\n let rec dfs v p dist =\n List.iter (fun w ->\n if w <> p then (\n\tlet dist = dist ++ c.(w) in\n\tdfs w v dist;\n\tif dist > a.(w) then mark.(w) <- true\n )\n ) tree.(v)\n in\n\n dfs 0 (-1) 0L;\n\n let rec dfs2 v p =\n if mark.(v) then 0 else (\n List.fold_left (fun ac w ->\n\tif w = p then ac else ac + (dfs2 w v)\n ) 1 tree.(v)\n )\n in\n\n let good_count = dfs2 0 (-1) in\n\n printf \"%d\\n\" (n - good_count)\n"}], "src_uid": "0c4bc51e5be9cc642f62d2b3df2bddc4"} {"source_code": "\nopen Scanf\n\nlet () = Printexc.record_backtrace true\n\nlet read_array n =\n let f i = scanf \" %u\" (fun i -> i) in\n Array.init n f\n\nlet count_array f a =\n Array.fold_left (fun i v -> if f v then i + 1 else i) 0 a\n\nlet () =\n let n = scanf \" %u \" (fun i -> i) in\n let a = read_array n in\n let ret = ref 0 in\n let n1 = count_array (fun x -> x = 1) a in\n let n2 = count_array (fun x -> x = 2) a in\n let n1_0a = ref 0 in\n let n2_0a = ref 0 in\n for ia = 0 to n do begin\n if ia > 0 then begin\n match a.(ia - 1) with\n | 1 -> n1_0a := !n1_0a + 1\n | 2 -> n2_0a := !n2_0a + 1\n | _ -> ()\n end;\n let max_diff = ref min_int in\n let n1_0b = ref !n1_0a in\n let n2_0b = ref !n2_0a in\n for ib = ia to n do\n if ib > ia then begin\n match a.(ib - 1) with\n | 1 -> n1_0b := !n1_0b + 1\n | 2 -> n2_0b := !n2_0b + 1\n | _ -> ()\n end;\n max_diff := max !max_diff (!n2_0b - !n1_0b);\n let n2_bn = n2 - !n2_0b in\n ret := max !ret\n (!n1_0a + n2_bn + !n1_0b - !n2_0a + !max_diff)\n done\n end\n done;\n !ret |> string_of_int |> print_endline", "positive_code": [{"source_code": "\nopen Scanf\n\nlet read_array n =\n let f i = scanf \" %u\" (fun i -> i) in\n Array.init n f\n\nlet count_array f a =\n Array.fold_left (fun i v -> if f v then i + 1 else i) 0 a\n\nlet update_ref (ref1, ref2) = function\n | 1 -> ref1 := !ref1 + 1\n | 2 -> ref2 := !ref2 + 1\n | _ -> ()\n\n(*\n ret = max(n1_0a + n2_bn + n2_ak + n1_kb)\n => n1_0a + (n2 - n2_0b) + n2_0k - n2_0a + n1_0b - n1_0k\n => n1_0a + n2_bn - n2_0a + n1_0b + **(n2_0k - n1_0k)**\n*)\nlet () =\n let n = scanf \" %u \" (fun i -> i) in\n let a = read_array n in\n\n let ret = ref 0 in\n let n2 = count_array (fun x -> x = 2) a in\n let n1_0a = ref 0 in\n let n2_0a = ref 0 in\n for ia = 0 to n do begin\n if ia > 0 then begin update_ref (n1_0a, n2_0a) a.(ia - 1) end;\n let max_diff = ref min_int in\n let n1_0b = ref !n1_0a in\n let n2_0b = ref !n2_0a in\n for ib = ia to n do\n if ib > ia then begin update_ref (n1_0b, n2_0b) a.(ib - 1) end;\n (* the diff. we are maximizing is effectively (n2_0k - n1_0k) *)\n max_diff := max !max_diff (!n2_0b - !n1_0b);\n let n2_bn = n2 - !n2_0b in\n ret := max !ret\n (!n1_0a + n2_bn + !n1_0b - !n2_0a + !max_diff)\n done\n end\n done;\n !ret |> string_of_int |> print_endline\n"}], "negative_code": [], "src_uid": "dae132800359378ca1b9f5be4b8c0df9"} {"source_code": "let ( ** ) 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\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- read_int()\n done;\n let res = ref 1 in\n let cur = ref 1 in\n for i = 1 to n - 1 do\n if a.(i) > a.(i - 1) then\n cur := !cur + 1\n else\n cur := 1;\n if res < cur then\n res := !cur\n done;\n printf \"%d\\n\" !res\n", "positive_code": [{"source_code": "\nlet read_nums () = \n let s = read_line () in\n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n nums\n\n;;\n\n\nlet rec solve lst cnt ans prev =\n match lst with\n | [] -> max cnt ans\n | hd :: tl -> if hd > prev then\n solve tl (cnt+1) (max cnt ans) hd\n else\n solve tl 1 (max cnt ans) hd\n;;\n\n\n\nlet main () =\n let _ = read_int () in\n let l = read_nums () in\n let n = solve l 1 1 1000000007 in\n let () = print_int n in\n print_string \"\\n\"\n\n;;\n\n\nmain ()\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make (n+1) 0\n\nlet b = Array.make (n+1) 0\n\nfor i = 1 to n do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n a.(i)<-j\ndone\n\nlet cnt = ref 0\n\nfor i = 1 to n do\n begin\n if a.(i) > a.(i-1) then\n cnt := !cnt + 1\n else\n cnt := 1\n end; b.(i) <- !cnt\ndone\n\n(*test\nlet () = Array.iter (fun x -> printf \"%d \" x) b\n*)\n\nlet ff = Array.make (n+1) (-10)\nlet rec f m =\n if m = 1 then\n 1\n else\n if ff.(m-1) < 0 then \n begin\n ff.(m-1) <- f (m-1); \n max ff.(m-1) b.(m)\n end\n else\n max ff.(m-1) b.(m)\n\nlet rslt = f n in\nprintf \"%d\\n\" rslt\n\n"}, {"source_code": "open Printf\nlet input_int_array n =\n\tArray.init n (fun _ -> Scanf.scanf \" %d\" (fun v -> v))\n\nlet get_int () = Scanf.scanf \" %d\" (fun v -> v)\nlet get_2_ints () = Scanf.scanf \" %d %d\" (fun u v -> u,v)\nlet get_3_ints () = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w)\nlet get_4_ints () = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x)\nlet get_5_ints () = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n\nlet print_int_endline n = n |> string_of_int |> print_endline\n\nlet () =\n let n = get_int ()\n in let a = input_int_array n\n in let v,len,lenmax = ref a.(0),ref 1,ref 1\n in\n for i=1 to (n-1) do\n if !v < a.(i) then (\n len := !len+1;\n if !len > !lenmax then lenmax := !len;\n ) else (\n len := 1;\n );\n v := a.(i)\n done;\n !lenmax |> print_int_endline"}, {"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 res = ref 1 in\n let p = ref a.(0) in\n let len = ref 1 in\n for i = 1 to n - 1 do\n if a.(i) > !p then (\n\tp := a.(i);\n\tincr len;\n\tres := max !res !len;\n ) else (\n\tp := a.(i);\n\tlen := 1;\n )\n done;\n Printf.printf \"%d\\n\" !res\n"}, {"source_code": "let n = int_of_string (input_line stdin) ;;\n\nlet rec solve last acc best count =\n if count == 0 then max best acc\n else let num = Scanf.scanf \"%d \" (fun a -> a) in\n if num > last then solve num (acc + 1) best (count - 1)\n else solve num 1 (max best acc) (count - 1) ;;\n\nlet ans = solve 0 0 0 n in\n Printf.printf \"%d\\n\" ans ;;"}], "negative_code": [{"source_code": "let n = int_of_string (input_line stdin) ;;\n\nlet rec solve last acc best count =\n Printf.printf \"solve %d %d %d %d\\n\" last acc best count ;\n if count == 0 then max best acc\n else let num = Scanf.scanf \"%d \" (fun a -> a) in\n if num > last then solve num (acc + 1) best (count - 1)\n else solve num 1 (max best acc) (count - 1) ;;\n\nlet ans = solve 0 0 0 n in\n Printf.printf \"%d\\n\" ans ;;"}], "src_uid": "4553b327d7b9f090641590d6492c2c41"} {"source_code": "open Printf\r\nopen Scanf\r\n \r\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\r\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0\r\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f) \r\n \r\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\r\nlet () = \r\n let cases = read_int() in\r\n for case = 1 to cases do\r\n let n = read_int() in\r\n let a = Array.init n read_int in\r\n let s = sum 0 (n-1) (fun i -> a.(i)) in\r\n if exists 0 (n-1) (fun i -> a.(i) * n = s)\r\n then printf \"Yes\\n\" else printf \"No\\n\"\r\n done", "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\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f) \n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let a = Array.init n read_int in\n let s = sum 0 (n-1) (fun i -> a.(i)) in\n if exists 0 (n-1) (fun i -> a.(i) * n = s)\n then printf \"Yes\\n\" else printf \"No\\n\"\n done\n"}], "negative_code": [], "src_uid": "7785ed6f41dbd45f1a9432c2fb07d713"} {"source_code": "let color_tree n g =\n let colors = Array.make (n+1) 0 in\n let k_max = ref 1 in\n let rec dfs v p =\n let parent_c = colors.(p) in\n let self_c = colors.(v) in\n let children = List.filter (fun x -> x != p) g.(v) in\n let k = ref 0 in\n List.iter (fun child ->\n incr k;\n while !k = parent_c || !k = self_c do incr k done;\n colors.(child) <- !k;\n dfs child v\n ) children;\n k_max := max !k_max !k\n in\n colors.(1) <- 1;\n dfs 1 0;\n (!k_max, colors)\n\nlet () =\n let n = Scanf.scanf \"%d\" (fun x -> x) in\n let out = Array.make (n + 1) [] in\n for i = 2 to n do\n let (a, b) = Scanf.scanf \" %d %d\" (fun x y -> (x, y)) in\n out.(a) <- b :: out.(a);\n out.(b) <- a :: out.(b)\n done;\n let (k, colors) = color_tree n out in\n Printf.printf \"%d\\n%d\" k colors.(1);\n for i = 2 to n do\n Printf.printf \" %d\" colors.(i)\n done;\n Printf.printf \"\\n\"\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x-1,y-1))\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n \nlet () = \n let n = read_int () in\n\n let tree = Array.make n [] in\n\n let add_edge (i,j) =\n tree.(i) <- j::tree.(i);\n tree.(j) <- i::tree.(j)\n in\n\n for i=1 to n-1 do add_edge (read_pair ()) done;\n\n let color = Array.make n 0 in\n\n let nextcolor trycolor p v =\n let pcolor = if p < 0 then 0 else color.(p) in\n let vcolor = if v < 0 then 0 else color.(v) in\n if trycolor <> pcolor && trycolor <> vcolor then trycolor\n else\n let trycolor = trycolor + 1 in\n if trycolor <> pcolor && trycolor <> vcolor then trycolor\n else trycolor + 1\n in\n\n let rec dfs p v =\n let _ = List.fold_left (fun trycolor w -> if w = p then trycolor else (\n color.(w) <- nextcolor trycolor p v;\n dfs v w;\n color.(w) + 1\n )\n ) 1 tree.(v)\n in ()\n in\n\n color.(0) <- 1;\n dfs (-1) 0;\n \n let mcolor = maxf 0 (n-1) (fun i -> color.(i)) in\n\n printf \"%d\\n\" mcolor;\n\n for i=0 to n-1 do\n printf \"%d \" color.(i)\n done;\n\n print_newline()\n"}], "negative_code": [{"source_code": "let color_tree n g =\n let colors = Array.make (n+1) 0 in\n let k_max = ref 1 in\n let rec dfs v p =\n let parent_c = colors.(p) in\n let self_c = colors.(v) in\n let children = List.filter (fun x -> x != p) g.(v) in\n let k = ref 0 in\n List.iter (fun child ->\n incr k;\n if !k = parent_c then incr k;\n if !k = self_c then incr k;\n colors.(child) <- !k;\n dfs child v\n ) children;\n k_max := max !k_max !k\n in\n colors.(1) <- 1;\n dfs 1 0;\n (!k_max, colors)\n\nlet () =\n let n = Scanf.scanf \"%d\" (fun x -> x) in\n let out = Array.make (n + 1) [] in\n for i = 2 to n do\n let (a, b) = Scanf.scanf \" %d %d\" (fun x y -> (x, y)) in\n out.(a) <- b :: out.(a);\n out.(b) <- a :: out.(b)\n done;\n let (k, colors) = color_tree n out in\n Printf.printf \"%d\\n%d\" k colors.(1);\n for i = 2 to n do\n Printf.printf \" %d\" colors.(i)\n done;\n Printf.printf \"\\n\"\n \n"}], "src_uid": "2aaa31d52d69ff3703f93177b25671a3"} {"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 inc_or_dec = function\n | \"X++\" -> 1\n | \"++X\" -> 1\n | \"--X\" -> -1\n | \"X--\" -> -1\n;;\n\n\nlet read_s () = Scanf.scanf \"%s \" (fun x -> inc_or_dec x );;\n\nlet n = read_int ();;\n\nlet a = Array.init n (fun i -> (read_s () ));;\n\n\nlet b = Array.fold_left (+) 0 a in print_int b; print_endline \"\"\n", "positive_code": [{"source_code": "open Printf;;\nopen Scanf;;\nlet n=read_int();;\n\nlet rec solve n x =\n if n=0 then x\n else\n let s=read_line() in\n if ((s=\"X++\") || (s=\"++X\")) then (solve (n-1) (x+1)) else (solve (n-1) (x-1))\n;;\t\t\t\t\t\t\t\t \n \n \nprintf \"%d\\n\" (solve n 0);;\n\t\n\t\t \n\t\t\t\t \n\t \n\t \n \n \n"}, {"source_code": "open Printf;;\nopen Scanf;;\nopen List;;\nlet rec initlist n = if (n=0) then [] else 0::(initlist (n-1)) ;;\n\t\t\t \n\t\t\tlet n=read_int();; \n\t\t\tlet r=map (fun x -> read_line()) (initlist n);;\n\t\t\tlet ans=fold_left (fun x y -> if ((y=\"X++\") || (y=\"++X\")) then x+1 else x-1) 0 r;;\n\t\t\t printf \"%d\\n\" ans;;\n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n"}, {"source_code": "let number_of_operations = Scanf.scanf \"%d \" (fun n -> n)\n\nlet execute s x = match s with\n |\"X++\" | \"++X\" -> x + 1\n |_ -> x - 1\n\nlet rec solve n x =\n if n > 0\n then \n let bit_function = Scanf.scanf \"%s \" (fun s -> s) in\n solve (n - 1) (execute bit_function x)\n else\n Printf.printf \"%d\\n\" x\n\nlet () = solve number_of_operations 0"}, {"source_code": "let () =\n let n = Scanf.scanf \"%d \" (fun a -> a) in\n let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf \"%s \" (fun a -> a)) in\n let l = List.map (fun x -> String.sub x 1 1) a_lst in\n\n let p = List.filter (fun x -> x = \"+\") l |>\n List.length in\n let m = n-p in\n Printf.printf \"%d\\n\" @@ p-m\n"}, {"source_code": "let rec solve (n : int) (ak : int) =\n if n = 0 then\n ak\n else\n let op = read_line () in\n match op with\n | \"X++\" -> solve (n - 1) (ak + 1)\n | \"++X\" -> solve (n - 1) (ak + 1)\n | \"X--\" -> solve (n - 1) (ak - 1)\n | \"--X\" -> solve (n - 1) (ak - 1)\n | _ -> raise (Failure \"Unsupported Operation\")\n\n\nlet () =\n let n = read_int () in\n Printf.printf \"%d\" (solve n 0)\n"}, {"source_code": "let n=Scanf.scanf \"%d\" (fun a->a);;\nlet x=ref 0;;\nfor i=1 to n do\n x:=!x+(Scanf.scanf \" %s\" (fun a-> if (String.contains a '+')==true then 1 else -1))\ndone;;\nprint_int(!x);;\n"}, {"source_code": "let rec read_lines n =\n match n with\n | 0 -> []\n | _ -> let res = read_line () in\n res :: read_lines (n - 1)\n\nlet () =\n let num = read_int() in\n let res = read_lines num in\n List.fold_left (fun num str ->\n if String.contains str '-'\n then\n num - 1\n else\n num + 1\n ) 0 res\n |> Printf.printf \"%d\"\n;;\n"}, {"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 inc_or_dec = function\n | \"X++\" -> 1\n | \"++X\" -> 1\n | _ -> -1\n;;\n\n\nlet read_s () = Scanf.scanf \"%s \" (fun x -> inc_or_dec x );;\n\nlet n = read_int ();;\n\nlet a = Array.init n (fun i -> (read_s () ));;\n\n\nlet b = Array.fold_left (+) 0 a in print_int b; print_endline \"\"\n"}, {"source_code": "let read_int () = Scanf.scanf \"%d\" (fun x -> x)\nlet read_string () = Scanf.scanf \" %s\" (fun x -> x)\n\nlet get_bit n =\n let rec calculate_bit r = function\n | 0 -> r\n | n -> match read_string () with\n | \"X++\" | \"++X\" -> calculate_bit (r + 1) (n - 1)\n | \"X--\" | \"--X\" -> calculate_bit (r - 1) (n - 1)\n | q -> Printf.printf \"%s\\n\" q; assert false\n in calculate_bit 0 n\n\n\nlet () = Printf.printf \"%d\\n\" (get_bit (read_int ()))\n"}, {"source_code": "let pf = Printf.printf;;\nlet sf = Scanf.scanf;;\n\nlet (|>) x f = f x;;\nlet (@@) f x = f x;;\nlet read0() = sf \"%d \" (fun x -> x)\nlet read1() = sf \"%d\\n\" (fun x -> x)\nlet read2() = sf \"%d %d\\n\" (fun x y -> x, y)\nlet read3() = sf \"%d %d %d\\n\" (fun x y z -> x, y, z)\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\nlet _ =\n let n = int_of_string @@ read_line() in\n let res = ref 0 in\n for i = 1 to n do\n let s = read_line() in\n res := !res + if s.[1] == '+' then 1 else -1\n done;\n pf \"%d\\n\" !res\n;;\n"}, {"source_code": "open Printf\n\n\nlet read_ints() =\n\tArray.map (int_of_string) (Array.of_list (Str.split (Str.regexp \" +\") (read_line())))\n\n\nlet main =\n let n = read_int() in\n let ans = ref 0 in\n for i = 1 to n do\n let ins = read_line() in\n if ins.[1] = '+' then\n ans := !ans + 1\n else\n ans := !ans - 1\n done;\n printf \"%d\\n\" !ans\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 n = read_int() in\n let x = ref 0 in\n for i=1 to n do\n let s = read_string() in\n\tif s=\"++X\" || s=\"X++\" then x := !x+1\n\telse if s=\"--X\" || s=\"X--\" then x := !x-1\n\telse failwith \"bad statement\"\n done;\n Printf.printf \"%d\\n\" !x\n"}], "negative_code": [], "src_uid": "f3cf7726739290b280230b562cac7a74"} {"source_code": "(* An implementation of link-cut trees in ocaml *)\n\ntype node = {\n mutable id:(int*int); \n mutable l:node;\n mutable r:node;\n mutable p:node\n}\n\nlet rec null = {id=(0,0); l=null; r=null; p=null}\n\nlet isroot n =\n n.p == null || (n.p.l != n && n.p.r != n)\n\nlet update p = ()\n\nlet discharge p = ()\n\nlet rot_right p =\n let q = p.p in\n let r = q.p in\n q.l <- p.r;\n if q.l != null then q.l.p <- q;\n p.r <- q;\n q.p <- p;\n p.p <- r;\n if r != null then (\n if r.l == q then r.l <- p \n else if r.r == q then r.r <- p\n );\n update q\n\nlet rot_left p =\n let q = p.p in\n let r = q.p in\n q.r <- p.l;\n if q.r != null then q.r.p <- q;\n p.l <- q;\n q.p <- p;\n p.p <- r;\n if r != null then (\n if r.r == q then r.r <- p \n else if r.l == q then r.l <- p\n );\n update q\n\nlet splay p =\n let rec loop p = if not (isroot p) then\n let q = p.p in\n if isroot q then (\n\tdischarge q;\n\tdischarge p;\n\tif q.l == p then rot_right p else rot_left p\n ) else (\n\tlet r = q.p in\n\tdischarge r;\n\tdischarge q;\n\tdischarge p;\n\tif r.l == q then (\n\t if q.l == p then (rot_right q; rot_right p)\n\t else (rot_left p; rot_right p)\n\t) else (\n\t if q.r == p then (rot_left q; rot_left p)\n\t else (rot_right p; rot_left p)\n\t)\n );\n loop p\n in\n loop p;\n discharge p; (* useful only if p was already the root *)\n update p (* only useful if p was not already a root *)\n\nlet expose q =\n let rec loop r p = if p==null then r else (\n splay p;\n p.l <- r;\n update p;\n loop p p.p\n ) in\n \n let r = loop null q in\n splay(q);\n r (* we only use this return value in the LCA operation *)\n\nlet link p q =\n ignore(expose p);\n if p.r != null then failwith \"p's right child should be null\";\n p.p <- q\n\nlet lca a b =\n ignore(expose a);\n expose(b)\n\nlet cut a =\n ignore(expose a);\n if a.r != null then (\n a.r.p <- null;\n a.r <- null;\n update a\n )\n\nlet findroot p =\n ignore(expose p);\n let rec loop p = if p.r == null then p else loop p.r in\n let p = loop p in\n splay p;\n p\n\n(*--------------------------------------------------------------------------*)\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let m = read_int() in\n let q = read_int() in\n \n let board = Array.make n \"\" in\n let treenode = Array.make_matrix n m null in\n let nodetype = Array.make_matrix n m (0,0) in\n\n let on_board (i,j) = i>=0 && i=0 && j (i,j-1)\n | '>' -> (i,j+1)\n | '^' -> (i-1,j)\n | 'v' -> (i+1,j)\n\t| _ -> failwith \"bad direction\"\n in\n \n nodetype.(i).(j) <- (ii,jj);\n if on_board (ii,jj) then (\n let a = treenode.(i).(j) in (* a is already a root *)\n let b = treenode.(ii).(jj) in\n let broot = findroot b in\n \n if broot != a then ( (* not a cycle root *)\n\tnodetype.(i).(j) <- (-1,-1); (* a is no longer a root *)\n\tlink a b;\n )\n )\n in\n\n let update_board (i,j) dir = \n let a = treenode.(i).(j) in\n let b = findroot a in\n let (ii,jj) = getnodetype b.id in\n cut a;\n if on_board (ii,jj) then ( (* b is the root of a cycle tree *)\n let c = treenode.(ii).(jj) in \n if a != b && lca a c == a then link b c;\n );\n linkcell (i,j) dir\n in\n\n for i=0 to n-1 do\n board.(i) <- read_string()\n done;\n \n for i=0 to n-1 do\n for j=0 to m-1 do\n treenode.(i).(j) <- {null with id=(i,j)}\n done\n done;\n \n for i=0 to n-1 do\n for j=0 to m-1 do\n linkcell (i,j) board.(i).[j]\n done\n done;\n\n for query=0 to q-1 do\n let command = read_string() in\n let i = read_int()-1 in\n let j = read_int()-1 in\n\n match command with\n | \"A\" ->\n\tlet r = findroot treenode.(i).(j) in\n\tlet (ii,jj) = getnodetype r.id in\n\tif on_board (ii,jj)\n\tthen printf \"-1 -1\\n\"\n\telse printf \"%d %d\\n\" (ii+1) (jj+1)\n | \"C\" ->\n\tupdate_board (i,j) (read_string()).[0]\n | _ -> failwith \"unsupported command\"\n done\n", "positive_code": [{"source_code": "type node = {\n mutable id:(int*int); \n mutable l:node;\n mutable r:node;\n mutable p:node\n}\n\nlet rec null = {id=(0,0); l=null; r=null; p=null}\n\nlet isroot n =\n n.p == null || (n.p.l != n && n.p.r != n)\n\nlet update p = ()\n\nlet discharge p = ()\n\nlet rot_right p =\n let q = p.p in\n let r = q.p in\n q.l <- p.r;\n if q.l != null then q.l.p <- q;\n p.r <- q;\n q.p <- p;\n p.p <- r;\n if r != null then (\n if r.l == q then r.l <- p \n else if r.r == q then r.r <- p\n );\n update q\n\nlet rot_left p =\n let q = p.p in\n let r = q.p in\n q.r <- p.l;\n if q.r != null then q.r.p <- q;\n p.l <- q;\n q.p <- p;\n p.p <- r;\n if r != null then (\n if r.r == q then r.r <- p \n else if r.l == q then r.l <- p\n );\n update q\n\nlet splay p =\n let rec loop p = if not (isroot p) then\n let q = p.p in\n if isroot q then (\n\tdischarge q;\n\tdischarge p;\n\tif q.l == p then rot_right p else rot_left p\n ) else (\n\tlet r = q.p in\n\tdischarge r;\n\tdischarge q;\n\tdischarge p;\n\tif r.l == q then (\n\t if q.l == p then (rot_right q; rot_right p)\n\t else (rot_left p; rot_right p)\n\t) else (\n\t if q.r == p then (rot_left q; rot_left p)\n\t else (rot_right p; rot_left p)\n\t)\n );\n loop p\n in\n loop p;\n discharge p; (* useful only if p was already the root *)\n update p (* only useful if p was not already a root *)\n\nlet expose q =\n let rec loop r p = if p==null then r else (\n splay p;\n p.l <- r;\n update p;\n loop p p.p\n ) in\n \n let r = loop null q in\n splay(q);\n r (* we only use this return value in the LCA operation *)\n\nlet link p q =\n ignore(expose p);\n if p.l != null then failwith \"p's left child should be null\";\n p.p <- q\n\nlet lca a b =\n ignore(expose a);\n expose(b)\n\nlet cut a =\n ignore(expose a);\n if a.r != null then (\n a.r.p <- null;\n a.r <- null;\n update a\n )\n\nlet findroot p =\n ignore(expose p);\n let rec loop p = if p.r == null then p else loop p.r in\n let p = loop p in\n splay p;\n p\n\n(*--------------------------------------------------------------------------*)\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let m = read_int() in\n let q = read_int() in\n \n let board = Array.make n \"\" in\n let treenode = Array.make_matrix n m null in\n let nodetype = Array.make_matrix n m (0,0) in\n\n let on_board (i,j) = i>=0 && i=0 && j (i,j-1)\n | '>' -> (i,j+1)\n | '^' -> (i-1,j)\n | 'v' -> (i+1,j)\n\t| _ -> failwith \"bad direction\"\n in\n \n nodetype.(i).(j) <- (ii,jj);\n if on_board (ii,jj) then (\n let a = treenode.(i).(j) in (* a is already a root *)\n let b = treenode.(ii).(jj) in\n let broot = findroot b in\n \n if broot != a then ( (* not a cycle root *)\n\tnodetype.(i).(j) <- (-1,-1); (* a is no longer a root *)\n\tlink a b;\n )\n )\n in\n\n let update_board (i,j) dir = \n let a = treenode.(i).(j) in\n let b = findroot a in\n let (ii,jj) = getnodetype b.id in\n cut a;\n if on_board (ii,jj) then ( (* b is the root of a cycle tree *)\n let c = treenode.(ii).(jj) in \n if a != b && lca a c == a then link b c;\n );\n linkcell (i,j) dir\n in\n\n for i=0 to n-1 do\n board.(i) <- read_string()\n done;\n \n for i=0 to n-1 do\n for j=0 to m-1 do\n treenode.(i).(j) <- {null with id=(i,j)}\n done\n done;\n \n for i=0 to n-1 do\n for j=0 to m-1 do\n linkcell (i,j) board.(i).[j]\n done\n done;\n\n for query=0 to q-1 do\n let command = read_string() in\n let i = read_int()-1 in\n let j = read_int()-1 in\n\n match command with\n | \"A\" ->\n\tlet r = findroot treenode.(i).(j) in\n\tlet (ii,jj) = getnodetype r.id in\n\tif on_board (ii,jj)\n\tthen printf \"-1 -1\\n\"\n\telse printf \"%d %d\\n\" (ii+1) (jj+1)\n | \"C\" ->\n\tupdate_board (i,j) (read_string()).[0]\n | _ -> failwith \"unsupported command\"\n done\n"}], "negative_code": [], "src_uid": "fea879747a8fc96a3d2ce63e38443bb0"} {"source_code": "type tree = Node of int*tree*tree | Leaf\ntype operator = Or | Xor\n\nlet (|>) x f = f x\n\nlet flip = function\n Or -> Xor\n | Xor -> Or \n\nlet denote_op = function\n | Or -> (lor)\n | Xor -> (lxor)\n;;\n\nlet compose_tree seq =\n let rec build_row op seq acc =\n match seq with\n | [] -> List.rev acc\n | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->\n build_row op xs \n ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)\n in\n let rec iter_rows op seq =\n match seq with\n [t] -> t\n | xs -> \n iter_rows (flip op) (build_row op seq [])\n in\n iter_rows Or seq\n\nlet rec update_leaf leafs p v t =\n match t with\n | Leaf -> Leaf\n | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n Node (a,tl, update_leaf (leafs/2) (p - (leafs/2)) v tr)\n else \n Node (a, update_leaf (leafs/2) p v tl,tr)\n\nlet rec recalculate_path leafs p t =\n match t with\n | Leaf -> failwith \"invariant broken\"\n | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n let (Node (v,tl2,tr2), op) = \n recalculate_path (leafs/2) (p - (leafs/2)) tr in\n match tl with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) ->\n (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)\n else \n let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in\n match tr with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) -> \n (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)\n\nlet rec print_tree = function\n Leaf -> Printf.printf \" - \"\n | Node (a, tl, tr) ->\n print_tree tl;\n Printf.printf \"%d \" a;\n print_tree tr\n\n\nlet rec print_root = function\n Leaf -> failwith \"error\"\n | Node (a, _, _) ->\n Printf.printf \"%d\\n\" a\n\nlet main =\n let (n,m) = Scanf.scanf \"%d %d\\n\" (fun a b -> (a,b)) in\n let leafs = 2 lsl (n-1) in\n let rec aux f n acc =\n match n with\n 0 -> List.rev acc\n | n -> \n aux f (n-1) ((f ()) :: acc)\n in\n let tree =\n aux (fun _ -> Scanf.scanf \"%d \" (fun n -> Node (n, Leaf, Leaf))) leafs [] |>\n compose_tree\n in\n let queries = aux (fun _ -> Scanf.scanf \"%d %d \" (fun p v -> (p,v))) m [] in\n List.fold_left (fun t (p,v) ->\n let t_new = \n update_leaf leafs p v t |>\n recalculate_path leafs p |>\n fst\n in print_root t_new; t_new) tree queries\n", "positive_code": [{"source_code": "let n,m = Scanf.scanf \"%d %d\\n\" (fun x y->x,y);;\nlet arr = Array.make (1 lsl n) 0;;\nlet rec read_ints x =\n if x = (1 lsl n) then ()\n else begin \n arr.(x) <- Scanf.scanf \"%d \" (fun x -> x);\n read_ints (x+1);\n end in\nread_ints 0;;\n\ntype t = Leaf | Node of t * int * t;;\n\nlet oper n l r =\n if (n mod 2) = 0 then (l lxor r)\n else (l lor r);;\n\nlet tree =\n let rec make_tree n x =\n if n = 0 then\n Node (Leaf,arr.(x),Leaf)\n else\n match (make_tree (n-1) (2*x)) ,(make_tree (n-1) (2*x+1)) with\n | (Node(_,l,_) as a),(Node(_,r,_) as b) -> Node(a,(oper n l r),b)\n in make_tree n 0;;\n\nlet rec modify tree n x p =\n match tree with\n | Node (Leaf,key,Leaf) as org ->\n if (x = p) then Node(Leaf,arr.(p),Leaf) else org\n | Node (left,key,right) as org -> \n let len = (1 lsl n) in\n let a,b = x*len,x*len+len-1 in\n if (p>=a && p<=b) then\n match (modify left (n-1) (x+x) p),(modify right (n-1) (x+x+1) p) with\n | (Node(_,l,_) as a),(Node(_,r,_) as b) -> Node (a,(oper n l r),b)\n else org;;\n\nlet rec query tree x =\n if x = m then\n ()\n else begin\n let p,b = Scanf.scanf \"%d %d\\n\" (fun x y -> (x-1),y) in\n arr.(p) <- b;\n let tree = modify tree n 0 p in\n let Node(_,key,_) = tree in\n Printf.printf \"%d\\n\" key;\n query tree (x+1);\n end in query tree 0;;\n"}], "negative_code": [{"source_code": "type tree = Node of int*tree*tree | Leaf\ntype operator = Or | Xor\n\nlet (|>) x f = f x\n\nlet flip = function\n Or -> Xor\n | Xor -> Or \n\nlet denote_op = function\n | Or -> (lor)\n | Xor -> (lxor)\n;;\n\nlet compose_tree seq =\n let rec build_row op seq acc =\n match seq with\n | [] -> List.rev acc\n | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->\n build_row op xs \n ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)\n in\n let rec iter_rows op seq =\n match seq with\n [t] -> t\n | xs -> \n iter_rows (flip op) (build_row op seq [])\n in\n iter_rows Or seq\n\nlet rec update_leaf leafs p v t =\n match t with\n | Leaf -> Leaf\n | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n Node (a,tl, update_leaf (leafs/2) (p/2) v tr)\n else \n Node (a, update_leaf (leafs/2) p v tl,tr)\n\nlet rec recalculate_path leafs p t =\n match t with\n | Leaf -> failwith \"invariant broken\"\n | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n let (Node (v,tl2,tr2), op) = \n recalculate_path (leafs/2) (p/2) tr in\n match tl with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) ->\n (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)\n else \n let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in\n match tr with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) -> \n (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)\n\nlet rec print_tree = function\n Leaf -> Printf.printf \" - \"\n | Node (a, tl, tr) ->\n print_tree tl;\n Printf.printf \"%d \" a;\n print_tree tr\n\n\nlet rec print_root = function\n Leaf -> failwith \"error\"\n | Node (a, _, _) ->\n Printf.printf \"%d\\n\" a\n\nlet main =\n let (n,m) = Scanf.scanf \"%d %d\\n\" (fun a b -> (a,b)) in\n let leafs = 2 lsl (n-1) in\n let rec aux f n acc =\n match n with\n 0 -> List.rev acc\n | n -> \n aux f (n-1) ((f ()) :: acc)\n in\n let tree =\n aux (fun _ -> Scanf.scanf \"%d \" (fun n -> Node (n, Leaf, Leaf))) leafs [] |>\n compose_tree\n in\n let queries = aux (fun _ -> Scanf.scanf \"%d %d \" (fun p v -> (p,v))) m [] in\n List.fold_left (fun t (p,v) ->\n let t_new = \n update_leaf leafs p v t |>\n recalculate_path leafs p |>\n fst\n in print_root t_new; t_new) tree queries\n"}, {"source_code": "type tree = Node of int*tree*tree | Leaf\ntype operator = Or | Xor\n\nlet (|>) x f = f x\n\nlet flip = function\n Or -> Xor\n | Xor -> Or \n\nlet denote_op = function\n | Or -> (lor)\n | Xor -> (lxor)\n;;\n\nlet compose_tree seq =\n let rec build_row op seq acc =\n match seq with\n | [] -> List.rev acc\n | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->\n build_row op xs \n ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)\n in\n let rec iter_rows op seq =\n match seq with\n [t] -> t\n | xs -> \n iter_rows (flip op) (build_row op seq [])\n in\n iter_rows Or seq\n\nlet rec update_leaf leafs p v t =\n match t with\n | Leaf -> Leaf\n | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n Node (a,tl, update_leaf (leafs/2) (p mod (leafs/2)) v tr)\n else \n Node (a, update_leaf (leafs/2) p v tl,tr)\n\nlet rec recalculate_path leafs p t =\n match t with\n | Leaf -> failwith \"invariant broken\"\n | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n let (Node (v,tl2,tr2), op) = \n recalculate_path (leafs/2) (p mod (leafs/2)) tr in\n match tl with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) ->\n (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)\n else \n let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in\n match tr with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) -> \n (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)\n\n\nlet rec print_root = function\n Leaf -> failwith \"error\"\n | Node (a, _, _) ->\n Printf.printf \"%d\\n\" a\n\nlet main =\n let (n,m) = Scanf.scanf \"%d %d\\n\" (fun a b -> (a,b)) in\n let leafs = 2 lsl (n-1) in\n let rec aux f n acc =\n match n with\n 0 -> List.rev acc\n | n -> \n aux f (n-1) ((f ()) :: acc)\n in\n let tree =\n aux (fun _ -> Scanf.scanf \"%d \" (fun n -> Node (n, Leaf, Leaf))) leafs [] |>\n compose_tree\n in\n let queries = aux (fun _ -> Scanf.scanf \"%d %d \" (fun p v -> (p,v))) m [] in\n List.fold_left (fun t (p,v) ->\n let t_new = \n update_leaf leafs p v t |>\n recalculate_path leafs p |>\n fst\n in print_root t_new; t_new) tree queries\n"}, {"source_code": "type tree = Node of int*tree*tree | Leaf\ntype operator = Or | Xor\n\nlet (|>) x f = f x\n\nlet flip = function\n Or -> Xor\n | Xor -> Or \n\nlet denote_op = function\n | Or -> (lor)\n | Xor -> (lxor)\n;;\n\nlet compose_tree seq =\n let rec build_row op seq acc =\n match seq with\n | [] -> List.rev acc\n | (Node (a,tl,tr)) :: (Node (b,tl2,tr2)) :: xs ->\n build_row op xs \n ((Node (denote_op op a b, Node (a, tl, tr), Node (b, tl2, tr2))) :: acc)\n in\n let rec iter_rows op seq =\n match seq with\n [t] -> t\n | xs -> \n iter_rows (flip op) (build_row op seq [])\n in\n iter_rows Or seq\n\nlet rec update_leaf leafs p v t =\n match t with\n | Leaf -> Leaf\n | Node (a, Leaf, Leaf) -> Node (v, Leaf, Leaf)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n Node (a,tl, update_leaf (leafs/2) (p/2) v tr)\n else \n Node (a, update_leaf (leafs/2) p v tl,tr)\n\nlet rec recalculate_path leafs p t =\n match t with\n | Leaf -> failwith \"invariant broken\"\n | Node (a, Leaf, Leaf) -> (Node (a, Leaf, Leaf), Or)\n | Node (a,tl,tr) ->\n if (p > leafs/2) then\n let (Node (v,tl2,tr2), op) = \n recalculate_path (leafs/2) (p/2) tr in\n match tl with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) ->\n (Node (denote_op op b v, tl, Node (v,tl2,tr2)), flip op)\n else \n let (Node (v,tl2,tr2),op) = recalculate_path (leafs/2) p tl in\n match tr with\n Leaf -> failwith \"invariant broken\"\n | Node (b,_,_) -> \n (Node (denote_op op b v, Node (v,tl2,tr2), tr), flip op)\n\nlet rec print_tree = function\n Leaf -> Printf.printf \" - \"\n | Node (a, tl, tr) ->\n print_tree tl;\n Printf.printf \"%d \" a;\n print_tree tr\n\n\nlet rec print_root = function\n Leaf -> failwith \"error\"\n | Node (a, _, _) ->\n Printf.printf \"%d\\n\" a\n\nlet main =\n let (n,m) = Scanf.scanf \"%d %d\\n\" (fun a b -> (a,b)) in\n let leafs = 2 lsl (n-1) in\n let rec aux f n acc =\n match n with\n 0 -> List.rev acc\n | n -> \n aux f (n-1) ((f ()) :: acc)\n in\n let tree =\n aux (fun _ -> Scanf.scanf \"%d \" (fun n -> Node (n, Leaf, Leaf))) leafs [] |>\n compose_tree\n in\n let queries = aux (fun _ -> Scanf.scanf \"%d %d \" (fun p v -> (p,v))) m [] in\n List.fold_left (fun t (p,v) ->\n let t_new = \n update_leaf leafs p v t |>\n recalculate_path leafs p |>\n fst\n in print_tree t_new; Printf.printf \"\\n\\n\"; t_new) tree queries\n"}], "src_uid": "40d1ea98aa69865143d44432aed4dd7e"} {"source_code": "open Printf\n\nlet main =\n let t = read_int() in\n for i = 1 to t do\n let _ = read_int() in\n let brackets = read_line() in\n\n let answer = ref 0 in\n let m = ref 0 in\n\n String.iter (fun c -> \n if c = '(' then\n m := !m + 1\n else if c = ')' then\n m := !m - 1;\n if !m < 0 then\n answer := max (!answer) (-(!m))\n ) brackets;\n printf \"%d\\n\" (!answer)\n done", "positive_code": [{"source_code": "module A = Array\nmodule C = Char\nmodule I = Int64\nmodule L = List\nmodule Q = Queue\nmodule S = String\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet ssf = Scanf.sscanf\n\nlet read_int () = sf \"%d \" (fun x -> x)\nlet read_float () = sf \"%f \" (fun x -> x)\nlet read_char () = sf \"%c\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\nlet read_list read n = for i = 1 to n do read () done\nlet read_line () = sf \"%s\\n\" (fun x -> x)\nlet err s = raise (Failure s)\n\nlet inf = int_of_float 1e18\nlet eps = 1e-11\n\nlet count_dangling n xs =\n let rec loop dangling openb i =\n if i = n then dangling\n else if xs.[i] = '(' then loop dangling (openb + 1) (i + 1)\n else if openb == 0 then loop (dangling + 1) openb (i + 1)\n else loop dangling (openb - 1) (i + 1)\n in loop 0 0 0\n\n\nlet () =\n for i = 1 to (read_int ()) do\n let n = (read_int ()) in\n let s = (read_line ()) in\n pf \"%d\\n\" (count_dangling n s)\n done\n"}], "negative_code": [], "src_uid": "7a724f327c6202735661be25ef9328d2"} {"source_code": "open Printf\nopen Scanf\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () =\n let s = read_string () in\n let n = String.length s in\n let pref = Array.make n 0\n and cntA = ref 0\n and ans = ref 0 in\n for i = 0 to n - 1 do\n pref.(i) <- pref.(max 0 (i - 1)) + (if s.[i] = 'a' then 1 else 0);\n cntA := !cntA + (if s.[i] = 'a' then 1 else 0)\n done;\n let left = ref 0 in\n for i = 0 to n - 1 do\n let curA = ref 0 \n and curB = ref 0 in\n for j = i to n - 1 do\n curA := !curA + (if s.[j] = 'a' then 1 else 0);\n curB := !curB + (if s.[j] = 'b' then 1 else 0);\n let right = !cntA - !left - !curA in\n ans := max !ans (!left + !curB + right)\n done;\n left := !left + (if s.[i] = 'a' then 1 else 0)\n done;\n printf \"%d\\n\" (max !left !ans)", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n\tlet s = read_string () \n\tand wyn = ref 0 in\n\tlet n = String.length s in\n\n\tlet a = Array.make (n + 1) 0 \n\tand b = Array.make (n + 1) 0 in\n\n\tfor i = 1 to n do \n\t\ta.(i) <- a.(i - 1);\n\t\tb.(i) <- b.(i - 1);\n\n\t\tif s.[i - 1] = 'a' then \n\t\t\ta.(i) <- a.(i) + 1\n\t\telse \n\t\t\tb.(i) <- b.(i) + 1\n\tdone;\n\n\tfor i = 0 to n do \n\t\tfor j = i + 1 to n do \n\t\t\tlet bb = b.(i) + b.(n) - b.(j)\n\t\t\tand aa = a.(j) - a.(i) in\n\n\t\t\twyn := max !wyn (n - bb - aa);\n\t\tdone;\n\tdone;\n\n\tfor i = 1 to n do \n\t\tlet aa = a.(n) - a.(i) \n\t\tand bb = b.(i) in\n\t\twyn := max !wyn (n - aa - bb);\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;;"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n\tlet s = read_string () \n\tand wyn = ref 0 in\n\tlet n = String.length s in\n\n\tlet a = Array.make (n + 1) 0 \n\tand b = Array.make (n + 1) 0 in\n\n\tfor i = 1 to n do \n\t\ta.(i) <- a.(i - 1);\n\t\tb.(i) <- b.(i - 1);\n\n\t\tif s.[i - 1] = 'a' then \n\t\t\ta.(i) <- a.(i) + 1\n\t\telse \n\t\t\tb.(i) <- b.(i) + 1\n\tdone;\n\n\tfor i = 0 to n do \n\t\tfor j = i + 1 to n do \n\t\t\tlet bb = b.(i) + b.(n) - b.(j)\n\t\t\tand aa = a.(j) - a.(i) in\n\n\t\t\twyn := max !wyn (n - bb - aa);\n\t\tdone;\n\tdone;\n\n\t\n\n\tprintf \"%d\\n\" !wyn;;"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n\tlet s = read_string () \n\tand wyn = ref 0 in\n\tlet n = String.length s in\n\n\tlet a = Array.make (n + 1) 0 \n\tand b = Array.make (n + 1) 0 in\n\n\tfor i = 1 to n do \n\t\ta.(i) <- a.(i - 1);\n\t\tb.(i) <- b.(i - 1);\n\n\t\tif s.[i - 1] = 'a' then \n\t\t\ta.(i) <- a.(i) + 1\n\t\telse \n\t\t\tb.(i) <- b.(i) + 1\n\tdone;\n\n\tfor i = 1 to n do \n\t\tfor j = i + 1 to n do \n\t\t\tlet bb = b.(i) + b.(n) - b.(j)\n\t\t\tand aa = a.(j) - a.(i) in\n\n\t\t\twyn := max !wyn (n - bb - aa);\n\t\tdone;\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;;"}, {"source_code": "open Printf\nopen Scanf\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () =\n let s = read_string () in\n let n = String.length s in\n let pref = Array.make n 0\n and cntA = ref 0\n and ans = ref 0 in\n for i = 0 to n - 1 do\n pref.(i) <- pref.(max 0 (i - 1)) + (if s.[i] = 'a' then 1 else 0);\n cntA := !cntA + (if s.[i] = 'a' then 1 else 0)\n done;\n let left = ref 0 in\n for i = 0 to n - 1 do\n let curA = ref 0 \n and curB = ref 0 in\n for j = i to n - 1 do\n curA := !curA + (if s.[j] = 'a' then 1 else 0);\n curB := !curB + (if s.[j] = 'b' then 1 else 0);\n let right = !cntA - !left - !curA in\n ans := max !ans (!left + !curB + right)\n done;\n left := !left + (if s.[i] = 'a' then 1 else 0)\n done;\n printf \"%d\\n\" !ans"}], "src_uid": "c768f3e52e562ae1fd47502a60dbadfe"} {"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 rec fold i j f init = if i>j then init else fold (i+1) j f (f i init) \nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,m) = read_pair () in\n\n let g = Array.make n [] in\n\n let add_edge (i,j) =\n g.(i) <- j::g.(i);\n g.(j) <- i::g.(j)\n in\n let d = Array.make n 0 in\n \n for i = 0 to m-1 do\n let u = -1+read_int() in\n let v = -1+read_int() in\n d.(u) <- d.(u) + 1;\n d.(v) <- d.(v) + 1; \n add_edge (u,v)\n done;\n\n let l = Array.make n 1 in\n\n for u = 0 to n-1 do\n l.(u) <- List.fold_left (fun ac v -> if u > v then max ac (1+l.(v)) else ac) 1 g.(u)\n done;\n\n let answer = maxf 0 (n-1) (fun v -> (long (l.(v))) ** (long d.(v))) in\n\n printf \"%Ld\\n\" answer\n", "positive_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet rec loop n tab =\n if n >= 0 then\n let x = read n in\n tab.(x) <- true;\n loop (n-1) tab\n else ();;\n\nlet ( *| ) = Int64.mul;;\n\nlet _ = \n let (n, m) = read2 () in\n let g = Array.make (n+1) []\n and tab = Array.make (n+1) 1\n and wynik = ref Int64.zero in\n for i=1 to m do\n let (a,b) = read2 () in\n g.(a) <- b::g.(a);\n g.(b) <- a::g.(b)\n done;\n for i=1 to n do\n List.iter (fun x -> if x < i then tab.(i) <- max tab.(i) (tab.(x)+1) ) g.(i);\n if compare !wynik ( ( Int64.of_int tab.(i) ) *| ( Int64.of_int ( List.length g.(i) ) ) ) < 0 then\n wynik := ( ( Int64.of_int tab.(i) ) *| ( Int64.of_int ( List.length g.(i) ) ) ) ;\n done;\n Printf.printf \"%Ld\\n\" !wynik;;\n\n\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 0L in\n\n\tlet g = Array.make (n + 1) []\n\tand dlugosc = Array.make (n + 1) 1L in\n\n\tfor i = 1 to m do \n\t\tlet a = read_int ()\n\t\tand b = read_int () in\n\n\t\tg.(a) <- b::g.(a);\n\t\tg.(b) <- a::g.(b);\n\tdone;\n\n\tfor i = 1 to n do \n\t\tlet s = Int64.of_int (List.length g.(i)) in\n\n\t\tList.iter (fun x -> if x < i then dlugosc.(i) <- max dlugosc.(i) (Int64.add dlugosc.(x) 1L);) g.(i);\n\n\t\twyn := max !wyn (Int64.mul dlugosc.(i) s)\n\tdone;\n\n\tprintf \"%Ld\\n\" !wyn;;"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet long x = Int64.of_int x\nlet ( ++ ) a b = Int64.add a b\nlet ( ** ) a b = Int64.mul a b\n\nlet () =\n let n = read_int () and m = read_int () in\n let g = Array.make (n + 1) []\n and dp = Array.make (n + 1) 0L\n and ans = ref 0L in\n for i = 1 to m do\n let a = read_int () and b = read_int () in\n g.(a) <- b::g.(a);\n g.(b) <- a::g.(b)\n done;\n for i = 1 to n do\n dp.(i) <- max 1L (List.fold_left (fun acc x -> if x < i then max acc (dp.(x) ++ 1L) else acc) 0L g.(i));\n ans := max !ans (dp.(i) ** long ((List.length g.(i))))\n done;\n printf \"%Ld\\n\" !ans"}], "negative_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet rec loop n tab =\n if n >= 0 then\n let x = read n in\n tab.(x) <- true;\n loop (n-1) tab\n else ();;\n\nlet _ = \n let (n, m) = read2 () in\n let g = Array.make (n+1) []\n and tab = Array.make (n+1) 1\n and wynik = ref 0 in\n for i=1 to m do\n let (a,b) = read2 () in\n g.(a) <- b::g.(a);\n g.(b) <- a::g.(b)\n done;\n for i=1 to n do\n List.iter (fun x -> if x < i then tab.(i) <- max tab.(i) (tab.(x)+1) ) g.(i);\n wynik := max !wynik ( tab.(i) * ( List.length g.(i) ) )\n done;\n Printf.printf \"%d\\n\" !wynik;;\n\n\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 0 in\n\n\tlet g = Array.make (n + 1) []\n\tand dlugosc = Array.make (n + 1) 1 in\n\n\tfor i = 1 to m do \n\t\tlet a = read_int ()\n\t\tand b = read_int () in\n\n\t\tg.(a) <- b::g.(a);\n\t\tg.(b) <- a::g.(b);\n\tdone;\n\n\tfor i = 1 to n do \n\t\tlet s = List.length g.(i) in\n\n\t\tList.iter (fun x -> if x < i then dlugosc.(i) <- max dlugosc.(i) (dlugosc.(x) + 1);) g.(i);\n\n\t\twyn := max !wyn (dlugosc.(i) * s)\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;;"}], "src_uid": "2596db1dfc124ea9e14c3f13c389c8d2"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\nlet x = read_int () ;;\n\nlet a = \n let rec loop i f = \n if i = n then f []\n else \n let ai = read_int () \n in loop (i + 1) (fun l -> f ((Int64.of_int ai) :: l))\n in loop 0 (fun x -> x) ;;\n\nlet split_list l n =\n let rec loop i f = function\n | [] -> (f [], [])\n | h :: t ->\n if i = n then (f [h], t)\n else loop (i + 1) (fun tl -> f (h :: tl)) t\n in loop 1 (fun x -> x) l ;;\n\nlet left, right = split_list a x ;;\n\n(* Get the index and value of the smallest element from the right of a list *)\nlet get_right_min l =\n let f = fun (i, (index, value)) a -> \n if a <= value then (i + 1, (i, a)) else (i + 1, (index, value))\n in let i, (index, value) = List.fold_left f (0, (0, Int64.max_int)) l\n in index, value ;;\n\n(* Determine which box was selected in the beginning with 0-based index *)\nlet start, value =\n let (ind1, val1), (ind2, val2) = (get_right_min left), (get_right_min right)\n in if val1 <= val2 then (ind1, val1) else (ind2 + x, val2) ;;\n\nlet original =\n (* \n Make sure to remove the leftover balls between (start, x - 1]. If \n start >= x then remove a ball between [0, x - 1] U (start, n). y\n represents the leftover balls.\n *)\n let y = if start >= x then x + n - start - 1 else x - start - 1\n in List.mapi \n (fun i ai -> \n if i = start then \n Int64.add (Int64.mul (Int64.of_int n) value) (Int64.of_int y)\n else \n if start < x && i > start && i < x || \n start >= x && (i >= 0 && i < x || i > start && i < n) then\n Int64.sub ai (Int64.add value Int64.one)\n else Int64.sub ai value)\n a ;; \n \nlet rec print_list = function \n | [] -> ()\n | h :: t -> Printf.printf \"%Ld \" h; print_list t\nin print_list original; Printf.printf \"\\n\" ;; ", "positive_code": [{"source_code": "(* Codeforces 260C KorobkiBalls *)\n\nopen String;;\nopen Array;;\nopen Int64;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line Pervasives.stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string \" \")) ai;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet rec readarray i n ar =\n\tif i < n then begin\n\t\tar.(i) <- (Int64.of_int (gr())); \n\t\treadarray (i +1) n ar\n\tend;;\n\nlet debug = false;;\n\nlet n = gr();;\nlet last = gr();;\nlet an = Array.make n Int64.zero;;\n\nlet rec step i cnt =\n\tif an.(i) = Int64.zero then an.(i) <- cnt\n\telse begin\n\t\tan.(i) <- Int64.pred an.(i);\n\t\tlet ii = if i =0 then n -1 else i -1 in\n\t\tstep ii (Int64.succ cnt)\n\tend;;\n\nlet rec find_min i mn = \n\tif i = n then mn\n\telse let mini = if an.(i) < mn then an.(i) else mn in\n\tfind_min (i+1) mini;;\n\nlet rec substract_min i mn = \n\tif i = n then ()\n\telse begin\n\t\tan.(i) <- Int64.sub an.(i) mn;\n\t\tsubstract_min (i+1) mn\n end;;\n\nlet main () = begin\n\t\treadarray 0 n an;\n(*\t\tprint_int n; print_string \" \";\n\t\tprint_int last; print_string \" \";*)\n\t\tlet mini = Int64.pred (find_min 0 an.(0)) in\n\t\tbegin\n\t\t substract_min 0 mini;\n\t\t\tlet cnt = Int64.mul (Int64.of_int n) mini in\n\t\t\tstep (last -1) cnt\n\t\tend;\n\t\tprintarri64 an;\n\t\tprint_newline()\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\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\n\nlet () = \n let n = read_int() in\n let x = read_int() in\n let x = x-1 in\n\n let a = Array.make n 0 in\n\n for i=0 to n-1 do\n a.(i) <- read_int()\n done;\n\n let b = Array.copy a in\n\n let rec scan i count besti = if count = n then besti else \n scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti) \n in\n\n let besti = scan x 0 x in\n\n let rec sublast i = if i = besti then () else (\n a.(i) <- a.(i) - 1;\n sublast ((i-1+n) mod n)\n )\n in\n\n let () = sublast x in\n\n let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in\n\n let repeat = a.(besti) in\n \n let pile = (Int64.of_int diff) ++ (Int64.of_int repeat) ** (Int64.of_int n) in\n\n for i=0 to n-1 do\n\tif i = besti then Printf.printf \"%Ld \" pile\n\telse Printf.printf \"%d \" (a.(i) - repeat)\n done;\n \n print_newline()\n"}], "negative_code": [{"source_code": "(* Codeforces 260C KorobkiBalls *)\n\nopen String;;\nopen Array;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet 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;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet rec readarray i n ar =\n\tif i < n then begin\n\t\tar.(i) <- gr(); readarray (i +1) n ar\n\tend;;\n\nlet debug = false;;\n\nlet n = gr();;\nlet last = gr();;\nlet an = Array.make n 0;;\n\nlet rec step i cnt =\n\tif an.(i) = 0 then an.(i) <- cnt\n\telse begin\n\t\tan.(i) <- an.(i) - 1;\n\t\tlet ii = if i =0 then n -1 else i -1 in\n\t\tstep ii (cnt +1)\n\tend;;\n\nlet rec find_min i mn = \n\tif i = n then mn\n\telse let mini = if an.(i) < mn then an.(i) else mn in\n\tfind_min (i+1) mini;;\n\nlet rec substract_min i mn = \n\tif i = n then ()\n\telse begin\n\t\tan.(i) <- an.(i) - mn;\n\t\tsubstract_min (i+1) mn\n end;;\n\nlet main () = begin\n\t\treadarray 0 n an;\n(*\t\tprint_int n; print_string \" \";\n\t\tprint_int last; print_string \" \";*)\n\t\tlet mini = (find_min 0 an.(0) - 1) in\n\t\tbegin\n\t\t substract_min 0 mini;\n\t\t\tlet cnt = n *mini in\n\t\t\tstep (last -1) cnt\n\t\tend;\n\t\tprintarri an;\n\t\tprint_newline()\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 n = read_int() in\n let x = read_int() in\n let x = x-1 in\n\n let a = Array.make n 0 in\n\n for i=0 to n-1 do\n a.(i) <- read_int()\n done;\n\n let b = Array.copy a in\n\n let rec scan i count besti = if count = n then besti else \n scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti) \n in\n\n let besti = scan x 0 x in\n\n let rec sublast i = if i = besti then () else (\n a.(i) <- a.(i) - 1;\n sublast ((i-1+n) mod n)\n )\n in\n\n let () = sublast x in\n\n let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in\n\n let repeat = a.(besti) in\n \n let pile = diff + repeat * n in\n\n for i=0 to n-1 do\n\tlet ans = if i = besti then pile else a.(i) - repeat in\n\t Printf.printf \"%d \" ans\n done;\n \n print_newline()\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 n = read_int() in\n let x = read_int() in\n let x = x-1 in\n\n let a = Array.make n 0 in\n\n for i=0 to n-1 do\n a.(i) <- read_int()\n done;\n\n let b = Array.copy a in\n\n let rec scan i count besti = if count = n then besti else \n scan ((i-1+n) mod n) (count+1) (if a.(i) < a.(besti) then i else besti) \n in\n\n let besti = scan x 0 x in\n\n(* Printf.printf \"besti= %d\\n\" besti; *)\n\n let rec sublast i = \n a.(i) <- a.(i) - 1;\n if i = besti then () else sublast ((i-1+n) mod n)\n in\n\n let () = sublast x in\n(*\n for i=0 to n-1 do\n\tPrintf.printf \"a.(%d) = %d\\n\" i a.(i)\n done;\n*)\n let diff = sum 0 (n-1) (fun i -> b.(i) - a.(i)) in\n\n(* Printf.printf \"diff = %d\\n\" diff; *)\n\n let repeat = a.(besti)+1 in\n\n(* Printf.printf \"repeat = %d\\n\" repeat; *)\n \n let pile = diff + repeat * n -1 in\n\n for i=0 to n-1 do\n\tlet ans = if i = besti then pile else a.(i) - repeat in\n\t Printf.printf \"%d \" ans\n done;\n \n print_newline()\n"}], "src_uid": "7d4899d03a804ed1bdd77a475169a580"} {"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int () in\n\n for case = 1 to cases do\n let n = read_int() in\n let stats = Array.init n read_pair in\n let a2 = forall 0 (n-2) (fun i ->\n let (pi,ci) = stats.(i) in\n let (pi',ci') = stats.(i+1) in\n pi <= pi' && ci <= ci' &&\t(pi' - pi) >= (ci' - ci)\n ) in\n let a1 = forall 0 (n-1) (fun i -> let (pi,ci) = stats.(i) in ci <= pi) in\n if a1 && a2 then printf \"YES\\n\" else printf \"NO\\n\"\n done\n", "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_int_pair () = let x = scan_int() in let y = scan_int() in (x,y);;\nlet show_string s = print_string s;;\n\nlet t = scan_int ();;\nfor x = 1 to t do\n\tlet n = scan_int () in\n\tlet player = ref 0 in\n\tlet clear = ref 0 in\n\tlet test = ref true in\n\tfor i = 0 to n-1 do\n\t\tlet p, c = scan_int_pair () in\n\t\tif !player > p || !clear > c || (p - !player) < (c - !clear) then\n\t\t\ttest := false;\n\t\tplayer := p; clear := c\n\tdone;\n\tif !test then show_string \"YES\\n\" else show_string \"NO\\n\"\ndone;;"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int () in\n\n for case = 1 to cases do\n let n = read_int() in\n let stats = Array.init n read_pair in\n let answer = forall 0 (n-2) (fun i ->\n let (pi,ci) = stats.(i) in\n let (pi',ci') = stats.(i+1) in\n pi <= pi' && ci <= ci' && ci <= pi && ci' <= pi' &&\n\t(pi' - pi) >= (ci' - ci')\n ) in\n if answer then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int () in\n\n for case = 1 to cases do\n let n = read_int() in\n let stats = Array.init n read_pair in\n let answer = forall 0 (n-2) (fun i ->\n let (pi,ci) = stats.(i) in\n let (pi',ci') = stats.(i+1) in\n pi <= pi' && ci <= ci' && ci <= pi && ci' <= pi'\n ) in\n if answer then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int () in\n\n for case = 1 to cases do\n let n = read_int() in\n let stats = Array.init n read_pair in\n let answer = forall 0 (n-2) (fun i ->\n let (pi,ci) = stats.(i) in\n let (pi',ci') = stats.(i+1) in\n pi <= pi' && ci <= ci' && ci <= pi && ci' <= pi' &&\n\t(pi' - pi) >= (ci' - ci)\n ) in\n if answer then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}], "src_uid": "714834defd0390659f6ed5bc3024f613"} {"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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let k = read_int () in\n\n let a = Array.init n (fun _ -> read_int()) in\n\n let mina = minf 0 (n-1) (fun i -> a.(i)) in\n let maxa = maxf 0 (n-1) (fun i -> a.(i)) in\n\n if maxa - mina > k then (\n printf \"NO\\n\"\n ) else (\n printf \"YES\\n\";\n for i=0 to n-1 do\n let ct = Array.make k 0 in\n ct.(k-1) <- mina;\n\n let rec loop j ac =\n\tif ac=a.(i) then () else (\n\t ct.(j) <- ct.(j) + 1;\n\t loop (j+1) (ac+1)\n\t)\n in\n\n loop 0 mina;\n for c=0 to k-1 do\n\tfor l=1 to ct.(c) do\n\t printf \"%d \" (c+1)\n\tdone\n done;\n print_newline()\n done\n )\n", "positive_code": [{"source_code": "let () =\n Scanf.scanf \"%d %d\\n\" (fun n k ->\n let piles = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* smallest/largest pile size *)\n let min = Array.fold_left min piles.(0) piles\n and max = Array.fold_left max piles.(0) piles in\n\n (* check whether it's possible *)\n if max - min > k then\n print_endline \"NO\"\n else begin\n print_endline \"YES\";\n\n (* fill out each pile with colour 1 *)\n for i = 0 to n - 1 do\n for j = 1 to piles.(i) do\n if j > 1 then print_char ' ';\n if j > min\n then print_int (j - min)\n else print_int 1\n done;\n print_endline \"\"\n done\n end\n )\n"}], "negative_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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let k = read_int () in\n\n let a = Array.init n (fun _ -> read_int()) in\n\n let mina = minf 0 (n-1) (fun i -> a.(i)) in\n let maxa = maxf 0 (n-1) (fun i -> a.(i)) in\n\n if maxa - mina > k then (\n printf \"NO\\n\"\n ) else (\n for i=0 to n-1 do\n let ct = Array.make k 0 in\n ct.(k-1) <- mina;\n\n let rec loop j ac =\n\tif ac=a.(i) then () else (\n\t ct.(j) <- ct.(j) + 1;\n\t loop (j+1) (ac+1)\n\t)\n in\n\n loop 0 mina;\n for c=0 to k-1 do\n\tfor l=1 to ct.(c) do\n\t printf \"%d \" (c+1)\n\tdone\n done;\n print_newline()\n done\n )\n"}], "src_uid": "e512285d15340343e34f596de2be82eb"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let l = k - 1\n and r = n - k in\n if l < r then (\n for i = 1 to l do\n\tPrintf.printf \"LEFT\\n\"\n done;\n for i = 0 to n - 1 do\n\tPrintf.printf \"PRINT %c\\n\" s.[i];\n\tif i < n - 1\n\tthen Printf.printf \"RIGHT\\n\"\n done;\n ) else (\n for i = 1 to r do\n\tPrintf.printf \"RIGHT\\n\"\n done;\n for i = n - 1 downto 0 do\n\tPrintf.printf \"PRINT %c\\n\" s.[i];\n\tif i > 0\n\tthen Printf.printf \"LEFT\\n\"\n done;\n )\n", "positive_code": [{"source_code": "let sr=read_line();;\nlet rec ind i=if sr.[i]=' ' then i else ind (i+1);;\nlet id=ind 0;;\nlet n=int_of_string(String.sub sr 0 id) and k=int_of_string(String.sub sr (id+1) (String.length(sr)-1-id));;\n\nlet s=read_line();;\nif k<=n/2 then\n begin\n for i=1 to k-1 do\n Printf.printf \"LEFT\\n\"\n done;\n for i=0 to n-1 do\n print_string(\"PRINT \"^(String.sub s i 1)^\"\\n\");\n if i<>n-1 then Printf.printf \"RIGHT\\n\"\n done\n end\nelse\n begin\n for i=k to n-1 do\n Printf.printf \"RIGHT\\n\"\n done;\n for i=n-1 downto 0 do\n print_string(\"PRINT \"^(String.sub s i 1)^\"\\n\");\n if i<>0 then Printf.printf \"LEFT\\n\"\n done\n end;;"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = scanf \" %d\" (fun x -> x)\nlet read_string() = scanf \" %s \" (fun x -> x)\n\nlet reverse str =\n let n = String.length str in\n let res = String.create n in\n for i = 0 to n - 1 do\n res.[i] <- str.[n - 1 - i]\n done;\n res in\n\nlet n = read_int () in\nlet k = read_int () in\nlet s = read_string () in\n\nlet res_f sep i c =\n if i > 0 then printf \"%s\\n\" sep;\n printf \"PRINT %c\\n\" c in\n\nif k - 1 <= n - k then begin\n for i = 1 to k - 1 do\n printf \"LEFT\\n\"\n done;\n String.iteri (res_f \"RIGHT\") s\nend else begin\n for i = 1 to n - k do\n printf \"RIGHT\\n\"\n done;\n String.iteri (res_f \"LEFT\") (reverse s)\nend ;;\n\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = scanf \" %d\" (fun x -> x)\nlet read_string() = scanf \" %s \" (fun x -> x)\n\nlet reverse str =\n let n = String.length str in\n let res = String.create n in\n for i = 0 to n - 1 do\n res.[i] <- str.[n - 1 - i]\n done;\n res in\n\nlet n = read_int () in\nlet k = read_int () in\nlet s = read_string () in\n\nlet res_f sep i c =\n if i > 0 then printf \"%s\\n\" sep;\n printf \"PRINT %c\\n\" c in\n\nprintf \"%d %d %s\\n\" n k s;\n\nif k - 1 <= n - k then begin\n for i = 1 to k - 1 do\n printf \"LEFT\\n\"\n done;\n String.iteri (res_f \"RIGHT\") s\nend else begin\n for i = 1 to n - k do\n printf \"RIGHT\\n\"\n done;\n String.iteri (res_f \"LEFT\") (reverse s)\nend ;;\n\n"}], "src_uid": "e3a03f3f01a77a1983121bab4218c39c"} {"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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\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 let k = read_int () in \n let s = read_string () in\n\n let solve a =\n (* a is an array of n+2 bits (0s or 1s). We added an extra 0 at start and end\n what's the maximum block of 1s we can make by toggling at most k 0s to 1s. *)\n let nzeros = sum 1 n (fun i -> if a.(i) = 0 then 1 else 0) in\n if nzeros <= k then n else (\n\n let next = Array.make (n+2) 0 in\n let prev = Array.make (n+2) 0 in\n\n let rec scan i p = if i next.(i) - i - 1)\n ) else (\n\tlet rec step i steps = if steps=0 then i else step next.(i) (steps-1) in\n\tlet rec scan i j ac = if j=n+1 then ac else (\n\t (* evaluate this (i,j) option. *)\n\t let pi = prev.(i) in\n\t let nj = next.(j) in\n\t let ac = max ac (nj-pi-1) in\n\t scan next.(i) next.(j) ac\n\t) in\n\n\tlet i = next.(0) in\n\tlet j = step i (k-1) in\n\tscan i j 0\n )\n )\n in\n\n let ma c = Array.init (n+2) (fun i -> if i-1 < 0 || i-1 > n-1 then 0 else if s.[i-1] = c then 1 else 0) in\n let answer = max (solve (ma 'a')) (solve (ma 'b')) in\n\n printf \"%d\\n\" answer\n", "positive_code": [{"source_code": "let [n; k] = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\nlet s = read_line ()\n\nexception Break of int;;\n\nlet max_charm_at_start ch =\n let mana = ref k in\n try\n for i = 0 to n-1 do\n if s.[i] != ch then\n decr mana;\n if !mana < 0 then\n raise (Break i)\n done;\n n\n with\n | Break i -> i\n\nlet max_charm ch =\n let left = ref 0\n and right = ref (max_charm_at_start ch) in\n let best = ref !right in\n while !right < n do\n if s.[!right] != ch then\n begin\n while s.[!left] == ch do\n incr left\n done;\n incr left\n end;\n incr right;\n if !right - !left > !best then\n best := !right - !left\n done;\n !best\n\nlet () =\n max (max_charm 'a') (max_charm 'b')\n |> Printf.printf \"%d\\n\"\n"}], "negative_code": [], "src_uid": "0151a87d0f82a9044a0ac8731d369bb9"} {"source_code": "let print_array a =\n\tfor k = 0 to (Array.length a) - 1 do\n\t\tprint_int a.(k);\n\t\tprint_char ' ';\n\tdone;\n\n\tprint_newline ();\n;;\n\n\nlet read_array ?(delta=0) n =\n\tlet arr = Array.make n 0 in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %i\" (fun v -> arr.(k) <- v + delta;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet permute_array a p =\n\tlet n = Array.length a in\n\tlet a' = Array.make n 0 in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\ta'.( p.(k) ) <- a.(k);\n\t\tdone;\n\t\ta'\n\tend\n;;\n\n\nlet permute a p =\n\tlet n = Array.length a in\n\tlet a' = Array.make n 0 in\n\tlet p' = Array.make n 0 in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\ta'.( p.(k) ) <- a.(k);\n\t\t\tp'.( p.(k) ) <- k;\n\t\tdone;\n\t\t(a', p')\n\tend\n;;\n\n\n(* a_permuted - sequence \"a\" permuted so that \\forall k: A_permuted[ P[k] ] = A[ k ] *)\nlet calc_b a_permuted l r = \n\tlet n = Array.length a_permuted in\n\tlet b = Array.make n 0 in\n\tlet b_last = ref l in (* B[ k - 1 ] *)\n\tbegin\n\n\t\tb.(0) <- !b_last;\n\n\t\tlet c = ref (!b_last - a_permuted.(0)) in (* minimum possible c - corresponds to the smallest P[k] *)\n\t\tlet k = ref 1 in\n\t\twhile (!k < n) && (!b_last <= r) do\n\t\t\tc := (!c + 1);\n\t\t\tb_last := max l (!c + a_permuted.(!k)); \n\t\t\tb.(!k) <- !b_last;\n\t\t\tc := !b_last - a_permuted.(!k);\n\t\t\tk := !k + 1;\n\t\tdone;\n\n\t\tif !b_last <= r then Some b else None\n\n\tend\n;;\n\n\nlet load_and_process_data n l r =\n\tlet a = read_array n in\n\tlet p = read_array n ~delta:(-1) in\n\tlet (a', p') = permute a p in\n\tlet b = calc_b a' l r in\n\tmatch b with\n\t| Some l -> print_array (permute_array l p')\n\t| None -> print_endline \"-1\"\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i %i %i \" load_and_process_data\n;;\n\n\nread_input ()\n", "positive_code": [{"source_code": "let print_array a =\n\tfor k = 0 to (Array.length a) - 1 do\n\t\tprint_int a.(k);\n\t\tprint_char ' ';\n\tdone;\n\n\tprint_newline ();\n;;\n\n\nlet read_array ?(delta=0) n =\n\tlet arr = Array.make n 0 in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %i\" (fun v -> arr.(k) <- v + delta;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet permute_array a p =\n\tlet n = Array.length a in\n\tlet a' = Array.make n 0 in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\ta'.( p.(k) ) <- a.(k);\n\t\tdone;\n\t\ta'\n\tend\n;;\n\n\nlet invert_permutation p =\n\tlet n = Array.length p in\n\tlet p' = Array.make n 0 in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\tp'.( p.(k) ) <- k;\n\t\tdone;\n\t\tp'\n\tend\n;;\n\n\n(* a_permuted - sequence \"a\" permuted so that \\forall k: A_permuted[ P[k] ] = A[ k ] *)\nlet calc_b a_permuted l r = \n\tlet n = Array.length a_permuted in\n\tlet b = Array.make n 0 in\n\tlet b_last = ref l in (* B[ k - 1 ] *)\n\tbegin\n\n\t\tb.(0) <- !b_last;\n\n\t\tlet c = ref (!b_last - a_permuted.(0)) in (* minimum possible c - corresponds to the smallest P[k] *)\n\t\tlet k = ref 1 in\n\t\twhile (!k < n) && (!b_last <= r) do\n\t\t\tc := (!c + 1);\n\t\t\tb_last := max l (!c + a_permuted.(!k)); \n\t\t\tb.(!k) <- !b_last;\n\t\t\tc := !b_last - a_permuted.(!k);\n\t\t\tk := !k + 1;\n\t\tdone;\n\n\t\tif !b_last <= r then Some b else None\n\n\tend\n;;\n\n\nlet load_and_process_data n l r =\n\tlet a = read_array n in\n\tlet p = read_array n ~delta:(-1) in\n\tlet b = calc_b (permute_array a p) l r in\n\tmatch b with\n\t| Some l -> print_array (permute_array l (invert_permutation p))\n\t| None -> print_endline \"-1\"\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i %i %i \" load_and_process_data\n;;\n\n\nread_input ()\n"}, {"source_code": "let print_array a =\n\tfor k = 0 to (Array.length a) - 1 do\n\t\tprint_int a.(k);\n\t\tprint_char ' ';\n\tdone;\n\n\tprint_newline ();\n;;\n\n\nlet read_array ?(delta=0) n =\n\tlet arr = Array.make n 0 in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %i\" (fun v -> arr.(k) <- v + delta;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet invert_permutation p =\n\tlet n = Array.length p in\n\tlet p' = Array.make n 0 in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\tp'.( p.(k) ) <- k;\n\t\tdone;\n\t\tp'\n\tend\n;;\n\n\n(* p' - invert function to p, i.e. the function restoring back the permutation created by p *)\nlet calc_b a p' l r = \n\tlet n = Array.length a in\n\tlet b = Array.make n 0 in\n\tlet b_last = ref l in (* B[ k - 1 ] *)\n\tlet k' = ref p'.( 0 ) in\n\tbegin\n\n\t\tb.( !k' ) <- !b_last;\n\n\t\tlet a_cur = ref a.( !k' ) in\n\t\tlet c = ref (!b_last - !a_cur) in (* minimum possible c - corresponds to the smallest P[k] *)\n\t\tlet k = ref 1 in\n\t\twhile (!k < n) && (!b_last <= r) do\n\t\t\tk' := p'.( !k );\n\t\t\ta_cur := a.( !k' );\n\t\t\tc := (!c + 1);\n\t\t\tb_last := max l (!c + !a_cur); \n\t\t\tb.(!k') <- !b_last;\n\t\t\tc := !b_last - !a_cur;\n\t\t\tk := !k + 1;\n\t\tdone;\n\n\t\tif !b_last <= r then Some b else None\n\n\tend\n;;\n\n\nlet load_and_process_data n l r =\n\tlet a = read_array n in\n\tlet p = read_array n ~delta:(-1) in\n\tlet b = calc_b a (invert_permutation p) l r in\n\tmatch b with\n\t| Some l -> print_array l \n\t| None -> print_endline \"-1\"\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i %i %i \" load_and_process_data\n;;\n\n\nread_input ()\n"}, {"source_code": "let () =\n Scanf.scanf \"%d %d %d \" @@ fun n l r ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d \" (fun x -> x)) in\n let p = Array.init n (fun _ -> Scanf.scanf \"%d \" (fun x -> x)) in\n let b = Array.make n 0 in\n let revp = Array.make n 0 in\n Array.iteri (fun i j -> revp.(j - 1) <- i) p;\n let rec loop prevc i =\n if i < n then\n let j = revp.(i) in\n b.(j) <- max l (a.(j) + prevc + 1);\n if b.(j) > r then\n false\n else\n loop (b.(j) - a.(j)) (i + 1)\n else true in\n if loop (l - r - 1) 0 then\n Array.to_list b |> List.map string_of_int |> String.concat \" \" |> print_endline\n else\n print_endline \"-1\"\n"}], "negative_code": [], "src_uid": "46096413faf7d9f845131d9e48bd8401"} {"source_code": "let input () =\n let n = Scanf.scanf \" %d \" (fun x -> x) in\n let a = ref 0 in\n let l = ref [] in\n for i = 1 to n do\n if i = n then\n a := Scanf.scanf \"%d\\n\" (fun x -> x)\n else\n a := Scanf.scanf \" %d \" (fun x -> x);\n\n l := !a :: !l;\n done;\n List.rev !l\n\nlet () = \n let rec scan l n head turn_down index =\n match l with\n | [] -> Printf.printf \"-1\\n\"\n | t :: [] ->\n begin\n\t match n with\n\t | 2 ->\n\t if (t <= head) then\n\t Printf.printf \"%d\\n\" (index - turn_down)\n\t else\n\t Printf.printf \"-1\\n\"\n\t | 1 ->\n\t Printf.printf \"0\\n\"\n\t | _ ->\n\t Printf.printf \"-1\\n\"\n end\n | last :: ((h :: t) as tl) ->\n if n <= 2 then\n\t if h >= last then\n\t scan tl n head turn_down (index+1)\n\t else\n\t scan tl (n+1) head index (index+1)\n else\n\t Printf.printf \"%d\\n\" (-1)\n in\n let l = input () in\n scan l 1 (List.hd l) (-1) 1\n", "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 = ArrayLabels ;;\nmodule List = ListLabels ;;\n\nlet solve n arr =\n let prev = ref arr.(0) in\n let rec iter i =\n if i = n then n\n else if !prev > arr.(i) then i\n else begin prev := arr.(i); iter (i + 1) end in\n let last = iter 1 in\n if last = n then pf \"0\"\n else\n let prev = ref arr.(last) in\n let rec iter i =\n if i = n then n\n else if !prev > arr.(i) then i\n else begin prev := arr.(i); iter (i + 1) end in\n let l = iter (last + 1) in\n if l = n && arr.(n - 1) <= arr.(0) then pf \"%d\\n\" (n - last)\n else pf \"-1\\n\"\n;;\n\n\nlet () =\n sf \"%d \" (fun n ->\n let arr = Array.init n ~f:(fun _ -> sf \"%d \" (fun i -> i)) in\n solve n arr)\n;;\n \n \n"}], "negative_code": [{"source_code": "let pf = Printf.printf ;;\nlet epf = Printf.eprintf ;;\nlet sf = Scanf.scanf ;;\n\nlet (|>) x f = f x ;;\n\nmodule Array = ArrayLabels ;;\nmodule List = ListLabels ;;\n\nlet solve n arr =\n let prev = ref arr.(0) in\n let rec iter i =\n if i = n then n\n else if !prev > arr.(i) then i\n else begin prev := arr.(i); iter (i + 1) end in\n let last = iter 1 in\n if last = n then pf \"0\"\n else\n let prev = ref arr.(last) in\n let rec iter i =\n if i = n then n\n else if !prev > arr.(i) then i\n else begin prev := arr.(i); iter (i + 1) end in\n let l = iter (last + 1) in\n if l = n && arr.(n - 1) < arr.(0) then pf \"%d\\n\" (n - last)\n else pf \"-1\\n\"\n;;\n\n\nlet () =\n sf \"%d \" (fun n ->\n let arr = Array.init n ~f:(fun _ -> sf \"%d \" (fun i -> i)) in\n solve n arr)\n;;\n \n \n"}, {"source_code": "let input () =\n let n = Scanf.scanf \" %d \" (fun x -> x) in\n let a = ref 0 in\n let l = ref [] in\n for i = 1 to n do\n if i = n then\n a := Scanf.scanf \"%d\\n\" (fun x -> x)\n else\n a := Scanf.scanf \" %d \" (fun x -> x);\n\n l := !a :: !l;\n done;\n List.rev !l\n\nlet () = \n let rec scan l n head turn_down index =\n match l with\n | [] -> Printf.printf \"-1\\n\"\n | t :: [] ->\n if n = 2 then\n\t if t <= head then\n\t Printf.printf \"%d\\n\" (index - turn_down)\n\t else\n\t Printf.printf \"-1\\n\"\n else\n\t Printf.printf \"0\\n\"\n | last :: ((h :: t) as tl) ->\n if n <= 2 then\n\t if h >= last then\n\t scan tl n head turn_down (index+1)\n\t else\n\t scan tl (n+1) head index (index+1)\n else\n\t Printf.printf \"%d\\n\" (-1)\n in\n let l = input () in\n scan l 1 (List.hd l) (-1) 1\n"}, {"source_code": "let input () =\n let n = Scanf.scanf \" %d \" (fun x -> x) in\n let a = ref 0 in\n let l = ref [] in\n for i = 1 to n do\n if i = n then\n a := Scanf.scanf \"%d\\n\" (fun x -> x)\n else\n a := Scanf.scanf \" %d \" (fun x -> x);\n\n l := !a :: !l;\n done;\n List.rev !l\n\nlet () = \n let rec scan l n head turn_down index =\n match l with\n | [] -> Printf.printf \"-1\\n\"\n | t :: [] ->\n begin\n\t match n with\n\t | 2 ->\n\t if (t <= head) then\n\t Printf.printf \"%d\\n\" (index - turn_down)\n\t else\n\t Printf.printf \"-1\\n\"\n\t | 1 ->\n\t Printf.printf \"0\\n\"\n\t | _ ->\n\t Printf.printf \"-1\\n\"\n end\n | last :: ((h :: t) as tl) ->\n if n <= 2 then\n\t if h >= last then\n\t scan tl n head (index+1) (index+1)\n\t else\n\t scan tl (n+1) head index (index+1)\n else\n\t Printf.printf \"%d\\n\" (-1)\n in\n let l = input () in\n scan l 1 (List.hd l) (-1) 1\n"}], "src_uid": "c647e36495fb931ac72702a12c6bfe58"} {"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", "positive_code": [{"source_code": "module IntSet = Set.Make(struct type t = int let compare = compare end)\n\nlet find_segs xs =\n let rec find_segs_aux i xs seen acc =\n match xs with\n | [] -> acc\n | [x] -> begin\n match acc with\n | [] ->\n if IntSet.mem x seen\n then [ 1, i ]\n else []\n | (lo, hi)::rest ->\n if IntSet.mem x seen\n then (hi + 1, i) :: (lo, hi) :: rest\n else (lo, i) :: rest\n end\n | x :: xs -> begin\n match acc with\n | [] ->\n if IntSet.mem x seen\n then find_segs_aux (i + 1) xs (IntSet.empty) [ 1, i ]\n else find_segs_aux (i + 1) xs (IntSet.add x seen) []\n | (lo, hi)::rest ->\n if IntSet.mem x seen\n then find_segs_aux (i + 1) xs (IntSet.empty) ((hi + 1, i)::acc)\n else find_segs_aux (i + 1) xs (IntSet.add x seen) acc\n end\n in\n find_segs_aux 1 xs IntSet.empty []\n\nlet print_output = function\n | [] -> print_int (-1); print_newline ()\n | xs ->\n print_int (List.length xs);\n print_newline ();\n List.iter (fun (lo, hi) ->\n print_int lo;\n print_string \" \";\n print_int hi;\n print_newline ()) xs\n\nlet () =\n ignore (read_line ()); read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string\n |> find_segs\n |> print_output\n"}, {"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let rec find a l r x =\n let m = (l + r) / 2 in\n if a.(m) = x then m\n else (\n if a.(m) < x then (find a (m + 1) r x)\n else (find a l (m - 1) x)\n )\n in\n\n let min x y =\n if x < y then x\n else y\n in\n\n let n = xint() in\n let a = Array.make n 0 in\n let xs = Array.make n 0 and m = ref 0 in\n\n for i = 0 to n - 1 do\n a.(i) <- xint();\n xs.(i) <- a.(i);\n done;\n Array.sort (fun x y -> x - y) xs;\n m := 1;\n for i = 1 to n - 1 do\n if xs.(i) != xs.(i - 1) then (\n xs.(!m) <- xs.(i);\n m := !m + 1;\n )\n done;\n\n let nx = Array.make n n and pos = Array.make !m n in\n\n for i = n - 1 downto 0 do\n a.(i) <- find xs 0 (!m - 1) a.(i);\n nx.(i) <- pos.(a.(i));\n pos.(a.(i)) <- i;\n done;\n\n let l = Array.make n 0 and r = Array.make n 0 in\n let ret = ref 0 and i = ref 0 in\n while !i < n do\n let x = !i and y = ref nx.(!i) in\n while !i < !y do\n y := min !y nx.(!i);\n i := !i + 1;\n done;\n if !y != n then (\n l.(!ret) <- x + 1;\n r.(!ret) <- !y + 1;\n ret := !ret + 1;\n );\n if !y = n && x != 0 then (\n r.(!ret - 1) <- n;\n );\n i := !i + 1;\n done;\n\n if !ret = 0 then (\n Printf.printf \"-1\\n\";\n ) else (\n Printf.printf \"%d\\n\" !ret;\n for i = 0 to !ret - 1 do\n Printf.printf \"%d %d\\n\" l.(i) r.(i);\n done;\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 read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n \n let find_segment i =\n (* find segment starting from i. either Some (i,j) or None *)\n let h = Hashtbl.create 5 in\n let rec loop j = if j>=n then None else\n\tif Hashtbl.mem h a.(j) then Some (i,j) else (\n\t Hashtbl.add h a.(j) true;\n\t loop (j+1)\n\t)\n in\n if i >= n then None else (\n Hashtbl.add h a.(i) true; \n loop (i+1)\n )\n in\n\n let rec outer_loop i ac = \n match find_segment i with\n | Some (_,j) -> outer_loop (j+1) ((i,j)::ac)\n | None ->\n\tmatch ac with\n\t | [] -> []\n\t | (i,j)::tail -> (i,n-1)::tail\n in\n\n match outer_loop 0 [] with\n | [] -> printf \"-1\\n\"\n | li ->\n printf \"%d\\n\" (List.length li);\n List.iter (fun (i,j) -> printf \"%d %d\\n\" (i+1) (j+1)) li\n"}], "negative_code": [{"source_code": "let xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let rec find a l r x = \n let m = (l + r) / 2 in\n if a.(m) = x then m\n else (\n if a.(m) < x then (find a (m + 1) r x)\n else (find a l (m - 1) x)\n )\n in\n\n let min x y = \n if x < y then x\n else y\n in\n\n let n = xint() in\n let a = Array.make n 0 in\n let xs = Array.make n 0 and m = ref 0 in\n\n for i = 0 to n - 1 do\n a.(i) <- xint();\n xs.(i) <- a.(i);\n done;\n Array.sort (fun x y -> x - y) xs;\n m := 1;\n for i = 1 to n - 1 do\n if xs.(i) != xs.(i - 1) then (\n xs.(!m) <- xs.(i);\n m := !m + 1;\n )\n done;\n\n let nx = Array.make n n and pos = Array.make !m n in\n\n for i = n - 1 downto 0 do\n a.(i) <- find xs 0 (!m - 1) a.(i);\n nx.(i) <- pos.(a.(i));\n pos.(a.(i)) <- i;\n done;\n\n let l = Array.make n 0 and r = Array.make n 0 in\n let ret = ref 0 and i = ref 0 in\n while !i < n do\n let x = !i and y = ref nx.(!i) in\n while !i < !y do\n y := min !y nx.(!i);\n i := !i + 1;\n done;\n if !y != n then (\n l.(!ret) <- x + 1;\n r.(!ret) <- !y + 1;\n ret := !ret + 1;\n );\n i := !i + 1;\n done;\n \n if !ret = 0 then (\n Printf.printf \"-1\\n\";\n ) else (\n Printf.printf \"%d\\n\" !ret;\n for i = 0 to !ret - 1 do\n Printf.printf \"%d %d\\n\" l.(i) r.(i);\n done;\n )\n"}], "src_uid": "4cacec219e4577b255ddf6d39d308e10"} {"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n\n\nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n if m |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else\n (((m + h - 1L) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nmodule Bigint = struct\n type t = Big_int.big_int\n let of_int = Big_int.big_int_of_int\n let to_int = Big_int.int_of_big_int\n let of_int64 = Big_int.big_int_of_int64\n let to_int64 = Big_int.int64_of_big_int\n let (+) = Big_int.add_big_int\n let (/) = Big_int.div_big_int\n let (-) = Big_int.sub_big_int\n let ( * ) = Big_int.mult_big_int\n let rem = Big_int.mod_big_int\n let compare = Big_int.compare_big_int\n let equal = Big_int.eq_big_int\n let min = Big_int.min_big_int\nend\n\nlet max_capacity_big (h: int64) (i: int64): int64 =\n let open Bigint in\n let h = of_int64 h in\n let i = of_int64 i in\n let one = of_int 1 in\n let two = of_int 2 in\n let ret =\n if compare h i >= 0\n then (i * (i + one)) / two\n else\n let sum = h + i in\n let m = sum / two in\n (((m + h - one) * (m - h)) / two) +\n (((m + one) * m) / two) +\n (if equal (rem sum two) one then m else (of_int 0)) in\n min ret (of_int64 Int64.max_int) |> to_int64\n\nlet max_capacity_big h i =\n let ret = max_capacity_big h i in\n (* Printf.printf \"mc %Ld %Ld -> %Ld\\n\" h i ret; *)\n ret\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity_big h i) >= n in\n (* let f i = let ret = f i in Printf.printf \"f %Ld %Ld %b\\n\" h i ret; ret in *)\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n(* 1000000000000000000 1 -> 1999999999 *)\n(* 1036191544337895 1 -> 64379858 *)\n \nlet _ =\n (* max_capacity 1000000000000000000L 62500000000000000L |> IdxI64.to_string |> print_endline;\n * max_capacity 1000000000000000000L 1414213562L |> IdxI64.to_string |> print_endline; *)\n Printexc.record_backtrace true;\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n", "positive_code": [{"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n\nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n if m |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else\n (((m + h - 1L) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\n(* module Bigint = struct\n * type t = Big_int.big_int\n * let of_int = Big_int.big_int_of_int\n * let to_int = Big_int.int_of_big_int\n * let of_int64 = Big_int.big_int_of_int64\n * let to_int64 = Big_int.int64_of_big_int\n * let (+) = Big_int.add_big_int\n * let (/) = Big_int.div_big_int\n * let (-) = Big_int.sub_big_int\n * let ( * ) = Big_int.mult_big_int\n * let rem = Big_int.mod_big_int\n * let compare = Big_int.compare_big_int\n * let equal = Big_int.eq_big_int\n * let min = Big_int.min_big_int\n * end\n * \n * let max_capacity_big (h: int64) (i: int64): int64 =\n * let open Bigint in\n * let h = of_int64 h in\n * let i = of_int64 i in\n * let one = of_int 1 in\n * let two = of_int 2 in\n * let ret =\n * if compare h i >= 0\n * then (i * (i + one)) / two\n * else\n * let sum = h + i in\n * let m = sum / two in\n * (((m + h - one) * (m - h)) / two) +\n * (((m + one) * m) / two) +\n * (if equal (rem sum two) one then m else (of_int 0)) in\n * min ret (of_int64 Int64.max_int) |> to_int64 *)\n\n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n(* 1000000000000000000 1 -> 1999999999 *)\n(* 1036191544337895 1 -> 64379858 *)\n \nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity h i) >= n in\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \nlet _ =\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}], "negative_code": [{"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n \nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n (((m + h) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity h i) >= n in\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \nlet _ =\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}, {"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n \nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n (((m + h) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity h i) >= n in\n (* let f i = let ret = f i in Printf.printf \"f %Ld %b\\n\" i ret; ret in *)\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n \nlet _ =\n max_capacity 1000000000000000000L 62500000000000000L |> IdxI64.to_string |> print_endline;\n max_capacity 1000000000000000000L 1414213562L |> IdxI64.to_string |> print_endline;\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}, {"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n \nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n if m |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else\n (((m + h) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity h i) >= n in\n (* let f i = let ret = f i in Printf.printf \"f %Ld %b\\n\" i ret; ret in *)\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n(* 1000000000000000000 1 -> 1999999999 *)\n \nlet _ =\n (* max_capacity 1000000000000000000L 62500000000000000L |> IdxI64.to_string |> print_endline;\n * max_capacity 1000000000000000000L 1414213562L |> IdxI64.to_string |> print_endline; *)\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}, {"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n \nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n (((m + h) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity h i) >= n in\n (* let f i = let ret = f i in Printf.printf \"f %Ld %b\\n\" i ret; ret in *)\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n \nlet _ =\n (* max_capacity 1000000000000000000L 62500000000000000L |> IdxI64.to_string |> print_endline;\n * max_capacity 1000000000000000000L 1414213562L |> IdxI64.to_string |> print_endline; *)\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}, {"source_code": "\nmodule type Idx = sig\n type t\n val to_string: t -> string\n val of_int: int -> t\n val (+): t -> t -> t\n val (-): t -> t -> t\n val (/): t -> t -> t\nend\n\nmodule IdxI64 = struct\n type t = int64\n let to_string = Int64.to_string\n let of_int = Int64.of_int\n let compare = Int64.compare\n let (+) = Int64.add\n let (/) = Int64.div\n let (-) = Int64.sub\n let ( * ) = Int64.mul\n let rem = Int64.rem\nend\n\n(* find the first one that makes callback returns true *)\nmodule Bisearch_first (Idx: Idx) = struct\n let perform\n (callback: 'a -> bool)\n ((l, r): Idx.t * Idx.t) (* range is closed *)\n (get: Idx.t -> 'a): Idx.t option =\n let open Idx in\n let rec f (l, r) =\n if l = r\n then if l |> get |> callback then Some l else None\n else\n let m = (l + r) / (Idx.of_int 2) in\n if m |> get |> callback\n then f (l, m)\n else f (m + (Idx.of_int 1), r)\n in\n f (l, r)\nend\n\nlet option_get (src: 'a option): 'a =\n match src with\n | Some a -> a\n | None -> raise Not_found\n\nlet log2 (v: float): float = log v /. log 2.\n \nmodule Bisearch_first_i64 = Bisearch_first(IdxI64)\n\n\nlet max_capacity (h: int64) (i: int64): int64 =\n let open IdxI64 in\n if h >= i\n then\n if i |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else (i * (i + 1L)) / 2L\n else\n let sum = h + i in\n let m = sum / 2L in\n if m |> Int64.to_float |> log2 >= 31.\n then Int64.max_int\n else\n (((m + h - 1L) * (m - h)) / 2L) +\n (((m + 1L) * m) / 2L) +\n (if rem sum 2L = 1L then m else 0L)\n\nmodule Bigint = struct\n type t = Big_int.big_int\n let of_int = Big_int.big_int_of_int\n let to_int = Big_int.int_of_big_int\n let of_int64 = Big_int.big_int_of_int64\n let to_int64 = Big_int.int64_of_big_int\n let (+) = Big_int.add_big_int\n let (/) = Big_int.div_big_int\n let (-) = Big_int.sub_big_int\n let ( * ) = Big_int.mult_big_int\n let rem = Big_int.mod_big_int\n let compare = Big_int.compare_big_int\n let equal = Big_int.eq_big_int\n let min = Big_int.min_big_int\nend\n\nlet max_capacity_big (h: int64) (i: int64): int64 =\n let open Bigint in\n let h = of_int64 h in\n let i = of_int64 i in\n let one = of_int 1 in\n let two = of_int 2 in\n let ret =\n if compare h i >= 0\n then (i * (i + one)) / two\n else\n let sum = h + i in\n let m = sum / two in\n (((m + h - one) * (m - h)) / two) +\n (((m + one) * m) / two) +\n (if equal (rem sum two) one then m else (of_int 0)) in\n min ret (of_int64 Int64.max_int) |> to_int64\n\nlet max_capacity_big h i =\n let ret = max_capacity_big h i in\n Printf.printf \"mc %Ld %Ld -> %Ld\\n\" h i ret;\n ret\n\nlet compute (n: int64) (h: int64): int64 =\n let f i = (max_capacity_big h i) >= n in\n let f i = let ret = f i in Printf.printf \"f %Ld %Ld %b\\n\" h i ret; ret in\n Bisearch_first_i64.perform f (1L, n) (fun i -> i) |> option_get\n \n(* 1000000000000000000 1000000000000000000 -> 1414213562 *)\n(* 1000000000000000000 1 -> 1999999999 *)\n(* 1036191544337895 1 -> 64379858 *)\n \nlet _ =\n (* max_capacity 1000000000000000000L 62500000000000000L |> IdxI64.to_string |> print_endline;\n * max_capacity 1000000000000000000L 1414213562L |> IdxI64.to_string |> print_endline; *)\n Printexc.record_backtrace true;\n let (n, h) = Scanf.scanf \" %Ld %Ld\" (fun a b -> (a, b)) in\n compute n h |> IdxI64.to_string |> print_endline\n"}], "src_uid": "c35102fa418cbfdcb150b52d216040d9"} {"source_code": "let get a'= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet [n; m] = get ();;\nlet kk = Array.make n 0 and mm = ref 0 and mj = ref 0;;\nfor i = 1 to m do\n\tlet ins = get () in begin\n\t\tmm := (-1);\n\t\tfor j = 0 to n - 1 do if !mm < List.nth ins j then begin\n\t\t\tmm := List.nth ins j;\n\t\t\tmj := j;\n\t\tend\tdone;\n\t\tArray.set kk !mj (kk.(!mj) + 1);\nend done;;\nmm := 0;;\nfor j = 0 to n - 1 do if !mm < kk.(j) then begin\n\tmm := kk.(j);\n\tmj := j;\nend done;;\nprint_int (!mj + 1);;\n", "positive_code": [{"source_code": "let winner a =\n fst (Array.fold_left (fun (i, pos) b -> if b > a.(i) then (pos, pos + 1) else (i, pos + 1)) (0, 0) a)\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n\t\t\t\t(* candidates *)\n\t\t\t\tlet c = Array.make n 0 in\n\t\t\t\tfor i = 1 to m do\n\t\t\t\t let e = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n\t\t\t\t let w = winner e in\n\t\t\t\t c.(w) <- c.(w) + 1\n\t\t\t\tdone;\n\t\t\t\tPrintf.printf \"%d\\n\" (winner c + 1))\n"}], "negative_code": [{"source_code": "let get a'= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet [n; m] = get ();;\nlet kk = Array.make n 0 and mm = ref 0 and mj = ref 0;;\nfor i = 1 to m do\n\tlet ins = get () in begin\n\t\tmm := 0;\n\t\tfor j = 0 to n - 1 do if !mm < List.nth ins j then begin\n\t\t\tmm := List.nth ins j;\n\t\t\tmj := j;\n\t\tend\tdone;\n\t\tArray.set kk !mj (kk.(!mj) + 1);\nend done;;\nmm := 0;;\nfor j = 0 to n - 1 do if !mm < kk.(j) then begin\n\tmm := kk.(j);\n\tmj := j;\nend done;;\nprint_int (!mj + 1);;\n"}, {"source_code": "let get a'= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet [n; m] = get ();;\nlet kk = Array.make n 0 and mm = ref 0 and mj = ref 0;;\nfor i = 1 to m do\n\tlet ins = get () in begin\n\t\tmm := (-1);\n\t\tfor j = 0 to n - 1 do if !mm < List.nth ins j then begin\n\t\t\tmm := List.nth ins j;\n\t\t\tmj := j;\n\t\tend\tdone;\nend done;;\nmm := 0;;\nfor j = 0 to n - 1 do if !mm < kk.(j) then begin\n\tmm := kk.(j);\n\tmj := j;\nend done;;\nprint_int (!mj + 1);;\n"}], "src_uid": "b20e98f2ea0eb48f790dcc5dd39344d3"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let a = Array.make 26 0 in\n let res = ref 0 in\n for i = 0 to n - 2 do\n let k = Char.code s.[2 * i] - Char.code 'a' in\n\ta.(k) <- a.(k) + 1;\n\tlet k = Char.code s.[2 * i + 1] - Char.code 'A' in\n\t if a.(k) > 0\n\t then a.(k) <- a.(k) - 1\n\t else incr res\n done;\n Printf.printf \"%d\\n\" !res;\n", "positive_code": [{"source_code": "open Scanf;;\nopen Printf;;\n\nlet rec change list target cur value = (* list\u306etarget\u756a\u76ee\u3092value\u306b\u5909\u3048\u305flist\u3092\u8fd4\u3059 *)\n if cur = target then value::( List.tl list )\n else ( List.hd list )::( change (List.tl list ) target ( cur + 1 ) value );;\n\n\nlet rec init size =\n if size <= 0 then [] \n else 0::( init ( size - 1 ) ) ;;\n\nlet n = scanf \"%d\\n\" ( fun n -> n );;\n\nlet rec solve s i list =\n if i >= ( String.length s ) then 0\n else begin\n if ( 'a' <= s.[i] && s.[i] <= 'z' ) then begin\n solve s ( i + 1 ) ( change list ( ( Char.code s.[i] ) - ( Char.code 'a' ) ) 0 ( 1 + ( List.nth list ( ( Char.code s.[i] ) - ( Char.code 'a' ) ) ) ) )\n end else begin\n if ( List.nth list ( ( Char.code s.[i] ) - ( Char.code 'A' ) ) ) = 0 then begin\n 1 + solve s ( i + 1 ) list\n end else begin\n solve s ( i + 1 ) ( change list ( ( Char.code s.[i] ) - ( Char.code 'A' ) ) 0 ( ( List.nth list ( ( Char.code s.[i] ) - ( Char.code 'A' ) ) ) - 1 ) )\n end\n end\n end\n;;\n\nlet s = scanf \"%s\\n\" ( fun s -> s ) in\n printf \"%d\\n\" ( solve s 0 ( init 26 ) );;"}], "negative_code": [], "src_uid": "80fdb95372c1e8d558b8c8f31c9d0479"} {"source_code": "let _ =\n\tScanf.scanf \"%d\" @@ fun n ->\n\t\tlet l = (Array.init n (fun _ -> Scanf.scanf \" %d\" (fun i -> i)))\n\t\t\t|> Array.to_list\n\t\tin\n\t\tlet mini = List.fold_left min max_int l in\n\t\tlet maxi = List.fold_left max min_int l in\n\t\tlet l' = List.filter ((<>) mini) l in\n\t\tlet l'' = List.filter ((<>) maxi) l' in\n\t\t\tprint_int (List.length l'')", "positive_code": [{"source_code": "let () =\n let n = read_int () in\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* sort ascending *)\n Array.sort compare a;\n let a = List.filter (fun x -> x <> a.(0) && x <> a.(n - 1)) (Array.to_list a) in\n print_int (List.length a);\n print_newline ()\n"}], "negative_code": [], "src_uid": "acaa8935e6139ad1609d62bb5d35128a"} {"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 b = Array.copy a in\n let cmp (x : int) y =\n if x < y\n then -1\n else if x = y\n then 0\n else 1\n in\n Array.sort cmp b;\n let c = ref 0 in\n for i = 0 to n - 1 do\n\tif a.(i) <> b.(i)\n\tthen incr c;\n done;\n if !c >= 3\n then Printf.printf \"NO\\n\"\n else Printf.printf \"YES\\n\"\n", "positive_code": [{"source_code": "let swap ary i j =\n let temp = ary.(i) in\n ary.(i) <- ary.(j);\n ary.(j) <- temp\n\nlet input_array size ary =\n let rec input_array n =\n if n == size then ary\n else begin\n ary.(n) <- Scanf.scanf \" %d\" (fun x -> x);\n input_array (n + 1);\n end\n in\n input_array 0\n \nlet solve n =\n let a = input_array n (Array.make n 0) in\n let a_ = Array.copy a in\n let sorted_a =\n begin\n Array.stable_sort (fun a b -> if a <= b then -1 else 1) a;\n a;\n end\n in\n let rec solve x cnt =\n if cnt >= 3 then \"NO\"\n else if n == x then \"YES\"\n else if a_.(x) != sorted_a.(x) then solve (x + 1) (cnt + 1)\n else solve (x + 1) cnt\n in\n solve 0 0\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \" %d\" solve)\n\t \n \n"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int();;\nlet tab=Array.make n 0;;\nfor i=0 to n-1 do\n tab.(i)<-read_int()\ndone;;\nlet creas()=let b=ref true in\nfor i=0 to n-2 do\n if tab.(i)>tab.(i+1) then b:=false\ndone;\n!b;;\nlet r=creas();;\nlet rec mins i v=if i=0 then 0 else if tab.(i-1)=v then mins (i-1) v else i;;\nlet rec maxs i v=if i=n-1 then n-1 else if tab.(i+1)=v then maxs (i+1) v else i;;\nlet rec prem i=\nif i=n-1 then 0 else if tab.(i)>tab.(i+1) then mins i tab.(i) else prem (i+1);;\nlet rec last i=\nif i=0 then 0 else if tab.(i)x);;\nlet n=read_int();;\nlet tab=Array.make n 0;;\nfor i=0 to n-1 do\n tab.(i)<-read_int()\ndone;;\nlet creas()=let b=ref true in\nfor i=0 to n-2 do\n if tab.(i)>tab.(i+1) then b:=false\ndone;\n!b;;\nlet r=creas();;\nlet rec mins i v=if i=0 then 0 else if tab.(i-1)=v then mins (i-1) v else i;;\nlet rec maxs i v=if i=n-1 then n-1 else if tab.(i+1)=v then mins (i+1) v else i;;\nlet rec prem i=\nif i=n-1 then 0 else if tab.(i)>tab.(i+1) then mins i tab.(i) else prem (i+1);;\nlet rec last i=\nif i=0 then 0 else if tab.(i)x);;\nlet n=read_int();;\nlet tab=Array.make n 0;;\nfor i=0 to n-1 do\n tab.(i)<-read_int()\ndone;;\nlet creas()=let b=ref true in\nfor i=0 to n-2 do\n if tab.(i)>tab.(i+1) then b:=false\ndone;\n!b;;\nlet r=creas();;\nlet rec prem i=\nif i=n-1 then 0 else if tab.(i)>tab.(i+1) then i else prem (i+1);;\nlet rec last i=\nif i=0 then 0 else if tab.(i)x);;\nlet n=read_int();;\nlet tab=Array.make n 0;;\nfor i=0 to n-1 do\n tab.(i)<-read_int()\ndone;;\nlet creas()=let b=ref true in\nfor i=0 to n-2 do\n if tab.(i)>tab.(i+1) then b:=false\ndone;\n!b;;\nlet r=creas();;\nlet rec prem i=\nif i=n-1 then 0 else if tab.(i)>tab.(i+1) then i else prem (i+1);;\nlet rec last i=\nif i=0 then 0 else if tab.(i)x);;\nlet n=read_int();;\nlet tab=Array.make n 0;;\nfor i=0 to n-1 do\n tab.(i)<-read_int()\ndone;;\nlet creas()=let b=ref true in\nfor i=0 to n-2 do\n if tab.(i)>tab.(i+1) then b:=false\ndone;\n!b;;\nlet r=creas();;\nlet rec prem i=\nif i=n-1 then 0 else if tab.(i)>tab.(i+1) then i else prem (i+1);;\nlet rec last i=\nif i=0 then 0 else if tab.(i) (x,y))\nlet () = \n let (n,m) = read_pair () in\n let tele = Array.init n read_pair in\n\n let rec loop i reach =\n if reach >= m then true\n else if i = n then false \n else\n let (a,b) = tele.(i) in\n if a > reach then false\n else loop (i+1) (max reach b)\n in\n\n if loop 0 0 then printf \"YES\\n\" else printf \"NO\\n\"\n", "positive_code": [{"source_code": "open Pervasives\nopen List\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet n = read_int ();;\nlet m = read_int ();;\nlet i = (ref 0);;\nlet tab = (ref [(0,0)]);;\nwhile ((!i) < (n)) do \n let a = read_int ()\n in\n let b = read_int ()\n in\n tab := [(a, b)]@(!tab);\n i := (!i + 1)\ndone\nlet tab = (rev (!tab));;\nif ((fst (List.hd tab)) <> 0) then \n begin\n print_string \"NO\";\n print_endline\n end\nelse\n begin\n let f a (x, y) = \n if (a>=x) then (max a y)\n else a\n in\n let zas = \n List.fold_left f 0 tab\n in \n if zas>=m then\n begin\n print_string \"YES\";\n print_endline\n end\n else\n begin\n print_string \"NO\";\n print_endline\n end\n end\n;;"}], "negative_code": [{"source_code": "open Pervasives\nopen List\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet n = read_int ();;\nlet m = read_int ();;\nlet i = (ref 0);;\nlet tab = (ref [(0,0)]);;\nwhile ((!i) < (n)) do \n let a = read_int ()\n in\n let b = read_int ()\n in\n tab := [(a, b)]@(!tab);\n i := (!i + 1)\ndone\nlet tab = (rev (!tab));;\nif ((fst (List.hd tab)) <> 0) then \n begin\n print_string \"NO\";\n print_endline\n end\nelse\n begin\n let f a (x, y) = \n if (a>=x) then (max a (x+y))\n else a\n in\n let zas = \n List.fold_left f 0 tab\n in \n if zas>=m then\n begin\n print_string \"YES\";\n print_endline\n end\n else\n begin\n print_string \"NO\";\n print_endline\n end\n end\n;;"}], "src_uid": "d646834d58c519d5e9c0545df2ca4be2"} {"source_code": "let int_of_char c = int_of_char c - int_of_char '0'\nand char_of_int i = char_of_int (i + int_of_char '0')\n\nlet () =\n let n = read_line () in\n let last = int_of_char (n.[String.length n - 1]) in\n let best = ref (-1) in\n let even = ref (-1) in\n\n for i = 0 to String.length n - 1 do\n let c = int_of_char n.[i] in\n if c mod 2 = 0 then begin\n even := i;\n if !best = (-1) && c < last then\n best := i\n end\n done;\n\n if !best <> (-1) then even := !best;\n if !even <> (-1)\n then begin\n n.[String.length n - 1] <- n.[!even];\n n.[!even] <- char_of_int last;\n print_endline n\n end\n else\n print_endline \"-1\"\n", "positive_code": [{"source_code": "let f mot =\n\tlet flag = ref true and last = mot.[String.length mot - 1] in\n\tfor i=0 to String.length mot - 1 do\n\t\tif !flag && (int_of_char (mot.[i]) mod 2 = 0) && (mot.[i] < last)\n\t\t\tthen (flag := false; let z = mot.[i] in mot.[i] <- last; mot.[String.length mot - 1] <- z);\n\tdone;\n\tif !flag\n\t\tthen for i=String.length mot - 1 downto 0 do\n\t\tif !flag && (int_of_char (mot.[i]) mod 2 = 0)\n\t\t\tthen (flag := false; let z = mot.[i] in mot.[i] <- last; mot.[String.length mot - 1] <- z);\n\t\tdone;\n\t!flag;;\n\nlet test n =\n\tlet mot = string_of_int n in\n\t\tif f mot\n\t\t\tthen -1\n\t\t\telse int_of_string mot;;\n\nlet final () =\n\tlet m = Scanf.scanf \"%s \" (fun i -> i) in\n\t\tif f m\n\t\t\tthen Printf.printf \"-1\"\n\t\t\telse Printf.printf \"%s \" m;;\n\nfinal ();;\n"}], "negative_code": [{"source_code": "let f mot =\n\tlet flag = ref true and last = mot.[String.length mot - 1] in\n\tfor i=0 to String.length mot - 1 do\n\t\tif !flag && (int_of_char (mot.[i]) mod 2 = 0) && (mot.[i] > last)\n\t\t\tthen (flag := false; let z = mot.[i] in mot.[i] <- last; mot.[String.length mot - 1] <- z);\n\tdone;\n\tif !flag\n\t\tthen for i=String.length mot - 1 downto 0 do\n\t\tif !flag && (int_of_char (mot.[i]) mod 2 = 0)\n\t\t\tthen (flag := false; let z = mot.[i] in mot.[i] <- last; mot.[String.length mot - 1] <- z);\n\t\tdone;\n\t!flag;;\n\nlet final () =\n\tlet m = Scanf.scanf \"%s \" (fun i -> i) in\n\t\tif f m\n\t\t\tthen Printf.printf \"-1\"\n\t\t\telse Printf.printf \"%s \" m;;\n\nfinal ();;\n"}], "src_uid": "bc375e27bd52f413216aaecc674366f8"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\n\nlet n=read_int() and k=read_int();;\n\nlet l=ref [];;\nfor i=1 to n do\n l:=(read_int())::(!l)\ndone;;\n\nlet rec inserer v=function\n|[]->[v]\n|h::t->if v>=h then v::h::t else h::(inserer v t);;\n\nlet rec tri=function\n|[]->[]\n|h::t->inserer h (tri t);;\n \nlet sol=tri(!l);;\n\nlet rec neme i=function\n|[]->0\n|h::t->if i=1 then h else neme (i-1) t;;\n\nprint_int(neme k sol);;", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = 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 Array.sort compare a\n in\n Printf.printf \"%d\\n\" a.(n - k);\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet flip f a b = f b a in\n\nlet read_int () = scanf \" %d \" (fun x -> x) in\n\nlet rec range a b = if a > b then [] else a :: (range (a + 1) b) in\n\nlet read_list n =\n let f l _ = ((read_int ()) :: l) in\n List.fold_left f [] (range 1 n) in\n\nlet n = read_int () in\nlet k = read_int () in\nlet l = read_list n in\n\nlet (|>) a f = f a in\n\nl |> (List.sort compare) |> List.rev |> (flip List.nth (k - 1)) |> (printf \"%d\\n\");;\n\n"}], "negative_code": [], "src_uid": "6eca08d7cc2dec6f4f84d3faa9a8a915"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\n\nlet n=read_int();;\n\nlet l=ref 0;;\n\nlet s=ref \" \";;\n\nlet a=ref 0;;\n\nfor i=0 to n-1 do\n for j=0 to i do\n a:=read_int()\n done;\n for j=i+1 to n-1 do\n let b=read_int() in ()\n done;\n l:= !l+ !a;\ndone;;\n\nlet m=read_int();;\n\nl:= (!l mod 2);;\n\nlet p=ref [];;\n\nfor i=1 to m do\n let q=read_int() in if q<>3 then let a=read_int() in l:=1- !l else p:=(!l):: !p\ndone;;\n\nlet rec print_list=function\n|[]->()\n|h::t->print_list t;print_int h;;\n\nprint_list !p;;", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\n\nlet n=read_int();;\n\nlet l=ref 0;;\n\nfor i=0 to n-1 do\n for j=0 to n-1 do\n let a=read_int() in if i=j then l:= !l+a\n done\ndone;;\n\nlet m=read_int();;\n\nl:= ( !l mod 2);;\n\nlet p=ref [];;\n\nfor i=1 to m do\n let q=read_int() in if q<>3 then let a=read_int() in l:=1- !l else p:=(!l):: !p\ndone;;\n\nlet rec print_list=function\n|[]->()\n|h::t->print_list t;print_int h;;\n\nprint_list !p;;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\n\nlet n=read_int();;\n\nlet l=ref 0;;\n\nlet a=ref 0;;\n\nfor i=0 to n-1 do\n for j=0 to i do\n a:=read_int()\n done;\n for j=i+1 to n-1 do\n let b=read_int() in ()\n done;\n l:= !l+ !a;\ndone;;\n\nlet m=read_int();;\n\nl:= (!l mod 2);;\n\nfor i=1 to m do\n let q=read_int() in if q<>3 then let a=read_int() in l:=1- !l else print_int !l\ndone;;\n"}], "negative_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet split_spaces chaine =\n let res = ref [] in\n let temp = ref \"\" in\n for i = 0 to String.length chaine - 1 do\n if chaine.[i]=' '\n then\n begin\n res := !res @ [!temp];\n temp := \"\";\n end\n else\n temp := !temp ^ (String.sub chaine i 1);\n done;\n res := !res @ [!temp];\n !res;;\nlet n = int_of_string (input_line stdin);;\nlet mat = Array.init n (fun _ -> Array.map int_of_string (Array.of_list (split_spaces (input_line stdin))));;\nlet m=read_int();;\n\nlet aj tab=\nlet l=ref 0 in\n for i=0 to n-1 do\n l:= !l+tab.(i).(i)\n done;\n!l mod 2;;\n\nlet chg a=mat.(a-1).(a-1)<-1-mat.(a-1).(a-1);;\n\nlet p=ref [];;\n\nfor i=1 to m do\n let q=read_int() in if q<>3 then let a=read_int() in mat.(a-1).(a-1)<-1-mat.(a-1).(a-1) else p:=(aj mat):: !p\ndone;;\n\nlet rec print_list=function\n|[]->()\n|h::t->print_list t;print_int h;;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet split_spaces chaine =\n let res = ref [] in\n let temp = ref \"\" in\n for i = 0 to String.length chaine - 1 do\n if chaine.[i]=' '\n then\n begin\n res := !res @ [!temp];\n temp := \"\";\n end\n else\n temp := !temp ^ (String.sub chaine i 1);\n done;\n res := !res @ [!temp];\n !res;;\nlet n = int_of_string (input_line stdin);;\nlet mat = Array.init n (fun _ -> Array.map int_of_string (Array.of_list (split_spaces (input_line stdin))));;\nlet m=read_int();;\n\nlet l=ref 0;;\nfor i=0 to n-1 do\n l:= !l+mat.(i).(i)\ndone;;\n\nlet p=ref [];;\n\nfor i=1 to m do\n let q=read_int() in if q<>3 then let a=read_int() in l:=1- !l else p:=(!l):: !p\ndone;;\n\nlet rec print_list=function\n|[]->()\n|h::t->print_list t;print_int h;;\n\nprint_list !p;;"}], "src_uid": "332902284154faeaf06d5d05455b7eb6"} {"source_code": "open Printf\nopen Scanf\n \nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n \nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n \nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n \nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n \n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n \n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n \n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n \n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n \n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n \n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n \n let answer = ref 0 in\n \n let arr_1 = Array.of_list !list_1 in\n let arr_2 = Array.of_list !list_2 in\n Array.fast_sort compare arr_1;\n Array.fast_sort compare arr_2;\n let id_1 = ref (Array.length arr_1 - 1) in\n let id_2 = ref (Array.length arr_2 - 1) in\n \n while !sum > s do\n if -1 = !id_1 then (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 - 1;\n answer := !answer + 1\n ) else if -1= !id_2 then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 - 1\n ) else (\n if arr_1.(!id_1) >= arr_2.(!id_2) || !sum <= (Int64.add s arr_1.(!id_1)) then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 - 1\n ) else (\n if 0 != !id_1 then (\n if (Int64.add arr_1.(!id_1) arr_1.(!id_1 - 1)) >= arr_2.(!id_2) then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 - 1\n ) else (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 - 1;\n answer := !answer + 1\n )\n )\n else (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 - 1;\n answer := !answer + 1\n )\n )\n );\n \n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n \nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n\nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let edges = Array.make n (0L, 0) in\n let set_1 = ref (SS.empty) in\n let set_2 = ref (SS.empty) in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n edges.(new_vert) <- (cost, add);\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let mult = Int64.mul (div2 cost) (Int64.of_int add) in\n\n if t = 1 then set_1 := SS.add (mult, new_vert) !set_1\n else set_2 := SS.add (mult, new_vert) !set_2\n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n\n let real_del_element set =\n let (del_value, del_id) = SS.max_elt set in\n let new_set = SS.remove (del_value, del_id) set in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n let cost_edge = Int64.div cost_edge 2L in\n edges.(del_id) <- (cost_edge, cnt_edge);\n let new_cost_edge = Int64.mul (div2 cost_edge) (Int64.of_int cnt_edge) in\n let new_set = SS.add (new_cost_edge, del_id) new_set in\n sum := Int64.add !sum (Int64.neg del_value);\n new_set\n in\n\n let fake_del_element set =\n let (del_value, del_id) = SS.max_elt set in\n let new_set = SS.remove (del_value, del_id) set in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n let cost_edge = Int64.div cost_edge 2L in\n let new_cost_edge = Int64.mul (div2 cost_edge) (Int64.of_int cnt_edge) in\n let new_set = SS.add (new_cost_edge, del_id) new_set in\n new_set\n in\n \n if SS.cardinal !set_2 = 0 then (\n while !sum > s do\n set_1 := real_del_element !set_1;\n answer := !answer + 1\n done\n )\n else if SS.cardinal !set_1 = 0 then (\n while !sum > s do\n set_2 := real_del_element !set_2;\n answer := !answer + 2\n done\n )\n else (\n while !sum > s do\n let (cost_1, id_1) = SS.max_elt !set_1 in\n let (cost_2, id_2) = SS.max_elt !set_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n set_1 := real_del_element !set_1\n ) \n else (\n let new_set_1 = fake_del_element !set_1 in\n let (cost_3, id_3) = SS.max_elt new_set_1 in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n set_1 := real_del_element !set_1;\n ) else (\n set_2 := real_del_element !set_2;\n answer := !answer + 1\n )\n );\n\n answer := !answer + 1\n done;\n );\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let t = Sys.time() in\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n \n list_1 := List.sort compare !list_1;\n list_2 := List.sort compare !list_2;\n list_1 := List.rev !list_1;\n list_2 := List.rev !list_2;\n\n if Sys.time() -. t > 2.9 then (\n sum := 0L\n );\n\n while !sum > s do\n if List.length !list_2 = 0 then (\n sum := Int64.sub !sum (List.hd !list_1);\n list_1 := List.tl !list_1\n ) else if List.length !list_1 = 0 then (\n sum := Int64.sub !sum (List.hd !list_2);\n list_2 := List.tl !list_2;\n answer := !answer + 1\n ) else (\n let cost_1 = List.hd !list_1 in\n let cost_2 = List.hd !list_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n list_2 := List.tl !list_2;\n sum := Int64.sub !sum cost_2;\n answer := !answer + 1\n )\n )\n );\n\n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}, {"source_code": "open Printf\nopen Scanf\n\nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n\nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let edges = Array.make n (0L, 0) in\n let set_1 = ref (SS.empty) in\n let set_2 = ref (SS.empty) in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n edges.(new_vert) <- (cost, add);\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let mult = Int64.mul (div2 cost) (Int64.of_int add) in\n\n if t = 1 then set_1 := SS.add (mult, new_vert) !set_1\n else set_2 := SS.add (mult, new_vert) !set_2\n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n\n let real_del_element set =\n let (del_value, del_id) = SS.max_elt set in\n let new_set = SS.remove (del_value, del_id) set in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n let cost_edge = Int64.div cost_edge 2L in\n edges.(del_id) <- (cost_edge, cnt_edge);\n let new_cost_edge = Int64.mul (div2 cost_edge) (Int64.of_int cnt_edge) in\n let new_set = SS.add (new_cost_edge, del_id) new_set in\n sum := Int64.add !sum (Int64.neg del_value);\n new_set\n in\n\n let fake_del_element set =\n let (del_value, del_id) = SS.max_elt set in\n let new_set = SS.remove (del_value, del_id) set in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n let cost_edge = Int64.div cost_edge 2L in\n let new_cost_edge = Int64.mul (div2 cost_edge) (Int64.of_int cnt_edge) in\n let new_set = SS.add (new_cost_edge, del_id) new_set in\n new_set\n in\n \n if SS.cardinal !set_2 = 0 then (\n while !sum > s do\n set_1 := real_del_element !set_1;\n answer := !answer + 1\n done\n )\n else if SS.cardinal !set_1 = 0 then (\n set_2 := real_del_element !set_2;\n answer := !answer + 2\n )\n else (\n while !sum > s do\n let (cost_1, id_1) = SS.max_elt !set_1 in\n let (cost_2, id_2) = SS.max_elt !set_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n set_1 := real_del_element !set_1\n ) \n else (\n let new_set_1 = fake_del_element !set_1 in\n let (cost_3, id_3) = SS.max_elt new_set_1 in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n set_1 := real_del_element !set_1;\n ) else (\n set_2 := real_del_element !set_2;\n answer := !answer + 1\n )\n );\n\n answer := !answer + 1\n done;\n );\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let t = Sys.time() in\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n \n list_1 := List.sort compare !list_1;\n list_2 := List.sort compare !list_2;\n list_1 := List.rev !list_1;\n list_2 := List.rev !list_2;\n\n while !sum > s do\n if Sys.time() -. t > 2.5 then (\n sum := 0L\n )\n else (\n if List.length !list_2 = 0 then (\n sum := Int64.sub !sum (List.hd !list_1);\n list_1 := List.tl !list_1\n ) else if List.length !list_1 = 0 then (\n sum := Int64.sub !sum (List.hd !list_2);\n list_2 := List.tl !list_2;\n answer := !answer + 1\n ) else (\n let cost_1 = List.hd !list_1 in\n let cost_2 = List.hd !list_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n list_2 := List.tl !list_2;\n sum := Int64.sub !sum cost_2;\n answer := !answer + 1\n )\n )\n )\n );\n\n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}, {"source_code": "open Printf\nopen Scanf\n\nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n\nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n \n let arr_1 = Array.of_list !list_1 in\n let arr_2 = Array.of_list !list_2 in\n Array.sort compare arr_1;\n Array.sort compare arr_2;\n let id_1 = ref 0 in\n let id_2 = ref 0 in\n\n while !sum > s do\n if Array.length arr_1 = !id_1 then (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 + 1;\n answer := !answer + 1\n ) else if Array.length arr_2 = !id_2 then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 + 1\n ) else (\n if arr_1.(!id_1) >= arr_2.(!id_2) || !sum <= (Int64.add s arr_1.(!id_1)) then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 + 1\n ) else (\n if Array.length arr_1 != !id_1 + 1 then (\n if (Int64.add arr_1.(!id_1) arr_1.(!id_1 + 1)) >= arr_2.(!id_2) then (\n sum := Int64.sub !sum arr_1.(!id_1);\n id_1 := !id_1 + 1\n ) else (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 + 1;\n answer := !answer + 1\n )\n )\n else (\n sum := Int64.sub !sum arr_2.(!id_2);\n id_2 := !id_2 + 1;\n answer := !answer + 1\n )\n )\n );\n\n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let t = Sys.time() in\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n \n list_1 := List.sort compare !list_1;\n list_2 := List.sort compare !list_2;\n list_1 := List.rev !list_1;\n list_2 := List.rev !list_2;\n\n if Sys.time() -. t > 2.95 then (\n sum := 0L\n );\n\n while !sum > s do\n if List.length !list_2 = 0 then (\n sum := Int64.sub !sum (List.hd !list_1);\n list_1 := List.tl !list_1\n ) else if List.length !list_1 = 0 then (\n sum := Int64.sub !sum (List.hd !list_2);\n list_2 := List.tl !list_2;\n answer := !answer + 1\n ) else (\n let cost_1 = List.hd !list_1 in\n let cost_2 = List.hd !list_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n list_2 := List.tl !list_2;\n sum := Int64.sub !sum cost_2;\n answer := !answer + 1\n )\n )\n );\n\n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let t = Sys.time() in\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = read_int() in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n\n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n\n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n\n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let answer = ref 0 in\n \n list_1 := List.sort compare !list_1;\n list_2 := List.sort compare !list_2;\n list_1 := List.rev !list_1;\n list_2 := List.rev !list_2;\n\n while !sum > s do\n if Sys.time() -. t > 2.9 then (\n sum := 0L\n )\n else (\n if List.length !list_2 = 0 then (\n sum := Int64.sub !sum (List.hd !list_1);\n list_1 := List.tl !list_1\n ) else if List.length !list_1 = 0 then (\n sum := Int64.sub !sum (List.hd !list_2);\n list_2 := List.tl !list_2;\n answer := !answer + 1\n ) else (\n let cost_1 = List.hd !list_1 in\n let cost_2 = List.hd !list_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n list_2 := List.tl !list_2;\n sum := Int64.sub !sum cost_2;\n answer := !answer + 1\n )\n )\n )\n );\n\n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}], "src_uid": "19a2d5821ab0abc62bda6628b82d0efb"} {"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\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let h = long (read_int ()) in\n let k = long (read_int ()) in \n\n let a = Array.init n (fun _ -> long(read_int())) in\n\n let rec loop i ac rem =\n (* i = next piece to put in, ac=time used so far, rem=amount in there *)\n\n let multi_step i ac rem =\n if rem < k then loop i (ac++1L) 0L\n else (\n\tlet x = rem // k in\n\tloop i (ac++x) (rem -- x**k)\n )\n in\n if i 0L then multi_step i ac rem\n else failwith \"impossible\"\n ) else (\n if rem > 0L then multi_step i ac rem\n else ac\n )\n in\n\n let answer = loop 0 0L 0L in\n\n printf \"%Ld\\n\" answer\n", "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 \"%d \" (fun s -> s) in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = 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 pos = ref 0 in\n let res = ref 0L in\n let g = ref 0 in\n while !pos < n do\n while !pos < n && !g <= h - a.(!pos) do\n\tg := !g + a.(!pos);\n\tincr pos;\n done;\n if !g < k then (\n\tres := !res +| 1L;\n\tg := 0;\n );\n res := !res +| Int64.of_int (!g / k);\n g := !g mod k;\n done;\n if !g > 0\n then res := !res +| 1L;\n Printf.printf \"%Ld\\n\" !res\n"}], "negative_code": [], "src_uid": "5099a9ae62e82441c496ac37d92e99e3"} {"source_code": "let solve n =\n begin\n Printf.printf \"%d\" n;\n for i = 1 to n - 1 do\n Printf.printf \" %d\" i\n done;\n print_endline \"\";\n end\n \nlet _ =\n Scanf.scanf \" %d\" solve\n", "positive_code": [{"source_code": "let f n =\n begin\n Printf.printf \"%d\" n;\n for i = 1 to n-1 do\n Printf.printf \" %d\" i\n done;\n print_endline \"\";\n end\n\nlet _ =\n Scanf.scanf \" %d\" f\n"}, {"source_code": "let swap ary i j =\n let temp = ary.(i) in\n ary.(i) <- ary.(j);\n ary.(j) <- temp\n\nlet range x y =\n let ary = Array.make (y - x) 0 in\n let rec range n =\n if n == y then ary\n else begin\n ary.(n-x) <- n;\n range (n + 1)\n end\n in\n range x\n\nlet solve n =\n let ary = range 1 (n + 1) in\n let rec solve x =\n if x == 1 then ary\n else begin\n swap ary (x - 2) (x - 1);\n solve (x - 1)\n end\n in\n solve n\n\nlet rec print n ary =\n if n+1 >= Array.length ary then Printf.printf \"%d\\n\" ary.(n)\n else begin\n Printf.printf \"%d \" ary.(n);\n print (n + 1) ary;\n end\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let ans = solve n in\n print 0 ans\n"}], "negative_code": [], "src_uid": "d9ba1dfe11cf3dae177f8898f3abeefd"} {"source_code": "let rec f temps = function\n\t|t::q\t-> if t 0;;\n\nlet _ =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d\" (fun i -> l := (float i)::!l);\n\tdone;\n\tPrintf.printf \"%d\" (f 0. (List.sort compare !l));;\n", "positive_code": [{"source_code": "\nopen Num\n\nlet (|>) x f = f x\nlet ($) f g = fun x -> f (g x)\n\nlet solve l =\n let disappointed =\n l\n |> List.sort compare\n |> List.fold_left\n (fun (total, disappointed) time ->\n if time snd\n in\n List.length l - disappointed\n\nlet _ =\n ignore (read_int ());\n let l =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map (num_of_int $ int_of_string)\n in\n\n print_endline (string_of_int (solve l))\n"}], "negative_code": [{"source_code": "\nlet (|>) x f = f x\n\nlet solve l =\n let disappointed =\n List.sort compare l\n |> List.fold_left\n (fun (total, disappointed) time ->\n if time < total\n then (total, disappointed + 1)\n else (total + time, disappointed))\n (0, 0)\n |> snd\n in\n List.length l - disappointed\n\nlet _ =\n ignore (read_int ());\n let l =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string\n in\n\n print_endline (string_of_int (solve l))\n"}, {"source_code": "let rec f temps = function\n\t|t::q\t-> if t 0;;\n\nlet _ =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d\" (fun i -> l := i::!l);\n\tdone;\n\tPrintf.printf \"%d\" (f 0 (List.sort compare !l));;\n"}, {"source_code": "let rec f decu pasdecu temps = function\n\t|t::q\t-> if t (List.rev pasdecu) @ decu;;\n\nlet _ =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d\" (fun i -> l := i::!l);\n\tdone;\n\tList.iter (fun i -> Printf.printf \"%d \" i) (f [] [] 0 (List.sort compare !l));;\n"}, {"source_code": "let rec f decu pasdecu temps = function\n\t|t::q\t-> if t List.length pasdecu;;\n\nlet _ =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\tfor i = 1 to n do\n\t\tScanf.scanf \" %d\" (fun i -> l := i::!l);\n\tdone;\n\tPrintf.printf \"%d\" (f [] [] 0 (List.sort compare !l));;\n"}], "src_uid": "08c4d8db40a49184ad26c7d8098a8992"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet rec read_ints n =\n match n with\n | 0 -> []\n | x -> read_int () :: (read_ints (n-1))\n\n(* let read_ints () =\n * let line = read_line () in\n * let ints = Str.split (Str.regexp \" *\") line in\n * List.map int_of_string ints *)\n\nlet rec print_list = function \n [] -> ()\n | e::l -> print_int e ; print_string \" \" ; print_list l\n\nlet solve () =\n let n = read_int () in\n let x = read_int () in\n let a = List.sort compare (read_ints n) in\n let b = List.sort compare (read_ints n) in\n let c = List.map2 (+) a (List.rev b) in\n if\n (List.fold_left (fun m x -> if m >= x then m else x) (-1) c <= x)\n then\n print_endline \"Yes\"\n else print_endline \"No\"\n\n\nlet () =\n let x = read_int () in\n let rec loop n =\n match n with\n | 0 -> ()\n | x -> solve (); loop (n-1) in\n loop x\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let t = read_int () in\n let ncompare a b : int =\n if a = b then\n 0\n else if a < b then\n 1\n else\n -1\n in\n let init n f =\n let rec init_aux acc = function\n | 0 -> acc\n | n -> init_aux ([f ()] @ acc) (n - 1)\n in init_aux [] n\n in\n let rec solve x a b =\n match a, b with\n | [], _ -> \"YES\"\n | _, [] -> \"YES\"\n | hd1 :: tl1, hd2 :: tl2 ->\n if hd1 + hd2 > x then \"NO\" else solve x tl1 tl2\n in\n for i = 1 to t do\n let n = read_int () in\n let x = read_int () in\n let a = List.sort compare (init n read_int) in\n let b = List.sort ncompare (init n read_int) in\n Printf.printf \"%s\\n\" (solve x a b)\n done\n\n"}], "negative_code": [], "src_uid": "7e765c1b0e3f3e9c44de825a79bc1da2"} {"source_code": "#load \"str.cma\";;\n\nlet rec iter ls cur height =\n match ls with\n\t [] -> cur\n\t| h::ls' -> \n\t if height <= (Int64.add h cur) then iter ls' cur (Int64.add h cur)\n\t else iter ls' (Int64.sub height h) height ;;\n\nlet solve ls =\n iter (List.tl ls) 0L (List.hd ls);;\n\n\nlet get_input () =\n let n = int_of_string (read_line ()) and\n\t ls = List.map (fun x -> Int64.of_int (int_of_string x))\n\t(Str.split (Str.regexp \"[ \\t]+\") (read_line ())) in\n (n, ls);;\n\nlet (n, ls) = get_input () in\nif n == 1 then Printf.printf \"0\\n\"\nelse Printf.printf \"%Ld\\n\" (solve ls)\n", "positive_code": [{"source_code": "let _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let b = ref 0 in\n let s = ref Int64.zero in\n for i = 0 to n - 1 do\n let a = Scanf.scanf \" %d\" (fun x -> x) in\n if !b > a then s := Int64.add !s (Int64.of_int (!b - a));\n b := a\n done;\n print_string (Int64.to_string !s)\n;;\n"}], "negative_code": [{"source_code": "let _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let b = ref 0 in\n let s = ref 0 in\n for i = 0 to n - 1 do\n let a = Scanf.scanf \" %d\" (fun x -> x) in\n s := !s + max 0 (!b - a);\n b := a\n done;\n print_int !s\n;;\n"}, {"source_code": "#load \"str.cma\";;\n\nlet rec iter ls cur height =\n match ls with\n\t [] -> cur\n\t| h::ls' -> \n\t if height <= (h + cur) then iter ls' cur (h + cur)\n\t else iter ls' ((height - h - cur) + cur) height ;;\n\nlet solve ls =\n iter (List.tl ls) 0 (List.hd ls);;\n\n\nlet get_input () =\n let n = int_of_string (read_line ()) and\n\t ls = List.map int_of_string (Str.split (Str.regexp \"[ \\t]+\") (read_line ())) in\n (n, ls);;\n\nlet (n, ls) = get_input () in\nif n == 1 then Printf.printf \"0\\n\"\nelse Printf.printf \"%d\\n\" (solve ls)\n"}, {"source_code": "#load \"str.cma\";;\n\nlet rec iter ls cur height =\n match ls with\n\t [] -> cur\n\t| h::ls' -> \n\t if height <= (h + cur) then iter ls' cur (h + cur)\n\t else iter ls' ((height - h - cur) + cur) height ;;\n\nlet solve ls =\n iter (List.tl ls) 0 (List.hd ls);;\n\n\nlet get_input () =\n let n = int_of_string (read_line ()) and\n\t ls = List.map int_of_string (Str.split (Str.regexp \"[ \\t]+\") (read_line ())) in\n (n, ls);;\n\nlet (n, ls) = get_input () in\nif n == 1 then Printf.printf \"1\\n\"\nelse Printf.printf \"%d\\n\" (solve ls)\n"}], "src_uid": "1cd295e204724335c63e685fcc0708b8"} {"source_code": "let modul x = Int64.sub x (Int64.mul (Int64.div x (Int64.of_int 998244353)) (Int64.of_int 998244353))\r\n\r\nlet rec test x = match x with\r\n |2 -> Int64.of_int 1\r\n |r when r mod 2 = 0 -> let t = r/2 in\r\n modul(Int64.mul (modul (Int64.mul (Int64.of_int(t)) (Int64.of_int(t)))) (test (x-2)))\r\n |_ -> Int64.zero\r\n;;\r\n\r\nlet n = int_of_string(input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let num = int_of_string(input_line stdin) in\r\n print_endline (Int64.to_string (test num))\r\ndone;\r\n;;", "positive_code": [{"source_code": "(* https://codeforces.com/problemset/problem/1658/B *)\nopen Printf\nopen Scanf \nmodule LL = Int64\n\nlet maxn = 1001\nlet q = 998244353L\nlet ( %% ) x y = LL.sub x ( LL.mul y (LL.div x y) )\nlet ( ** ) x y = LL.mul x y\nlet ( // ) x y = LL.div x y\nlet (!) x = LL.of_int x\n\nlet fac = Array.make maxn 1L;;\nfor i = 1 to maxn-1 do\n fac.(i) <- !i ** fac.(i-1) %% q\ndone\n\nlet solve n =\n if n mod 2 = 1 \n then 0L\n else\n let m = n/2 in\n fac.(m) ** fac.(m) %% q\n\nlet () =\n let t = read_int () in\n for i=1 to t do \n let n = read_int () in \n printf \"%Ld\\n\" (solve n)\n done;\n\n\n"}], "negative_code": [{"source_code": "(* https://codeforces.com/problemset/problem/1658/B *)\r\nopen Printf\r\nopen Scanf \r\n\r\nlet maxn = 100\r\nlet q = 998244353 \r\n\r\nlet fac : int array = Array.make 1001 1;;\r\nfor i = 1 to 1000 do\r\n fac.(i) <- i * fac.(i-1) mod q\r\ndone\r\n\r\nlet solve n =\r\n if n mod 2 = 1 \r\n then 0\r\n else\r\n let m = n/2 in\r\n fac.(m) * fac.(m) mod q\r\n\r\nlet () =\r\n let t = read_int () in\r\n for i=1 to t do \r\n let n = read_int () in \r\n printf \"%d\\n\" (solve n)\r\n done;\r\n\r\n"}, {"source_code": "(* https://codeforces.com/problemset/problem/1658/B *)\r\nopen Printf\r\nopen Scanf \r\n\r\nlet maxn = 100\r\nlet q = 998244353 \r\n\r\nlet fac : int array = Array.make 1001 1;;\r\nfor i = 1 to 1000 do\r\n fac.(i) <- i * fac.(i-1) mod q\r\ndone\r\n\r\nlet solve n =\r\n if n mod 2 = 1 \r\n then 0\r\n else\r\n let m = n/2 in\r\n fac.(m) * fac.(m) mod q\r\n\r\nlet () =\r\n let t = read_int () in\r\n printf \"%d\\n\" t;\r\n for i=1 to t do \r\n let n = read_int () in \r\n printf \"%d\\n\" (solve n)\r\n done;\r\n\r\n"}], "src_uid": "0b718a81787c3c5c1aa5b92834ee8bf5"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet get n =\n let rec test k =\n let tmp = (1 lsl k) - 1 in\n if n mod tmp = 0 then n / tmp\n else test (k + 1) in\n test 2\n;;\n\nlet _ =\n let t = scan_int () in\n for i = 1 to t do\n Printf.printf \"%d\\n\" (get (scan_int ()))\n done\n;;\n", "positive_code": [{"source_code": "let nbTests = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet rec pow x = function \n| 0 -> 1\n| n -> x * pow x (n - 1);;\n\nlet rec solve n k =\n if n mod ((pow 2 k) - 1) = 0 then\n n / ((pow 2 k) - 1)\n else\n solve n (k + 1)\n;;\n\nfor iTest = 1 to nbTests\ndo\n let nbBonbons = Scanf.scanf \" %d\" (fun x -> x) in\n \n print_int (solve nbBonbons 2);\n print_newline ()\ndone;;"}], "negative_code": [], "src_uid": "d04cbe78b836e53b51292401c8c969b2"} {"source_code": "let (@@) f x = f x ;;\n\nlet solve p n arr =\n let htbl = Array.create p false in\n try\n for i = 0 to n - 1 do\n let h = arr.(i) mod p in\n match htbl.(h) with\n | false -> htbl.(h) <- true\n | true -> Printf.printf \"%d\\n\" @@ i + 1; raise Exit\n done;\n Printf.printf \"-1\\n\";\n with\n | Exit -> ()\n;;\n\nlet () =\n Scanf.scanf \"%d %d \" (fun p n ->\n let arr = Array.create n 0 in\n for i = 0 to n - 1 do\n Scanf.scanf \"%d \" (fun x -> arr.(i) <- x);\n done;\n solve p n arr)\n;;\n", "positive_code": [{"source_code": "(**D. The Child and Sequence*)\n\nopen Scanf;;\nopen Num;;\nopen Printf;;\n\nlet p,n = Scanf.bscanf Scanf.Scanning.stdin \"%d %d \" ( fun x y -> x,y );;\n\nlet hashv = Array.create p 0;;\n\nexception BreakLoop;;\n\nlet j = ref 0;;\nlet rslt = ref (-1);;\ntry\n for i = 1 to n do\n j := !j + 1;\n let x = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x) in\n let y = x mod p in\n match hashv.(y) with\n | 0 -> hashv.(y) <- 1\n | 1 -> raise BreakLoop \n done;\nwith BreakLoop -> rslt := !j;;\n\nprintf \"%d\\n\" !rslt;;\n\n"}], "negative_code": [], "src_uid": "5d5dfa4f129bda46055fb636ef33515f"} {"source_code": "let score_without w =\n let a = ref (w.[0]) and res = ref 1 in\n for i = 1 to String.length w - 1 do\n if w.[i] <> !a\n then (incr res; a := w.[i]);\n done;\n !res\n\nlet score w =\n let l = String.length w and s = score_without w in\n s + min 2 (l - s)\n\nlet main () =\n let w = Scanf.scanf \"%d %s\" (fun _ w -> w) in\n Printf.printf \"%d\" (score w);;\n\nmain ();;", "positive_code": [{"source_code": "let n = read_int();;\nlet s = input_line stdin;;\nlet dp = Array.make_matrix (n+1) 3 0;;\n\nlet rec solve i =\nif (i=0) then (0,0,0) else\nbegin\n let (r0,r1,r2) = solve (i-1)\n and ib b = if(b) then 1 else 0 in\n (ib(s.[i]<>s.[i-1]) + r0, max (ib(s.[i]<>s.[i-1]) + r1) (ib(not(s.[i]<>s.[i-1])) + r0), max (ib(s.[i]<>s.[i-1]) + r2) (ib(not(s.[i]<>s.[i-1])) + r1))\nend;;\n\nlet (a,b,c) = solve(n-1);;\nPrintf.printf \"%d\" (1 + max a (max b c));;"}, {"source_code": "open Printf;;\nopen Scanf;;\n\nlet n = read_int();;\nlet s = input_line stdin;;\nlet dp = Array.make_matrix (n+1) 3 0;;\nfor i=1 to n-1 do\n let aux1 = if s.[i]<>s.[i-1] then 1 + dp.(i-1).(1) else dp.(i-1).(1)\n and aux2 = if s.[i]<>s.[i-1] then dp.(i-1).(0) else 1 + dp.(i-1).(0)\n and aux3 = if s.[i]<>s.[i-1] then 1 + dp.(i-1).(2) else dp.(i-1).(2)\n and aux4 = if s.[i]<>s.[i-1] then dp.(i-1).(1) else 1 + dp.(i-1).(1)\n in let res1 = max aux1 aux2\n and res2 = max aux3 aux4 in\n dp.(i).(0) <- if s.[i]<>s.[i-1] then 1 + dp.(i-1).(0) else dp.(i-1).(0);\n dp.(i).(1) <- res1;\n dp.(i).(2) <- res2;\ndone;;\nprintf \"%d\" (1 + max dp.(n-1).(0) (max dp.(n-1).(1) dp.(n-1).(2)));;"}, {"source_code": "open Printf;;\nopen Scanf;;\n\nlet bi i = if(i=0) then false else true;;\nlet ib b = if(b) then 1 else 0;;\n\nlet n = read_int();;\nlet s = input_line stdin;;\nlet dp = Array.make_matrix (n+1) 3 0;;\n\nfor i=1 to n-1 do\n let aux1 = ib(s.[i]<>s.[i-1]) + dp.(i-1).(1)\n and aux2 = ib(not(s.[i]<>s.[i-1])) + dp.(i-1).(0)\n and aux3 = ib(s.[i]<>s.[i-1]) + dp.(i-1).(2)\n and aux4 = ib(not(s.[i]<>s.[i-1])) + dp.(i-1).(1)\n in let res1 = max aux1 aux2\n and res2 = max aux3 aux4 in\n dp.(i).(0) <- ib(s.[i]<>s.[i-1]) + dp.(i-1).(0);\n dp.(i).(1) <- res1;\n dp.(i).(2) <- res2;\ndone;;\nprintf \"%d\" (1 + max dp.(n-1).(0) (max dp.(n-1).(1) dp.(n-1).(2)));;"}, {"source_code": "let score_without w =\n let a = ref (w.[0]) and res = ref 1 in\n for i = 1 to String.length w - 1 do\n if w.[i] <> !a\n then (incr res; a := w.[i]);\n done;\n !res\n\nlet score w =\n let l = String.length w and s = score_without w in\n s + min 2 (l - s)\n\nlet main () =\n let w = Scanf.scanf \"%d %s\" (fun _ w -> w) in\n Printf.printf \"%d\" (score w);;\n\nmain ();;\n"}, {"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 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 n = read_int() in\n let s = read_string() in\n\n let k = (* alternation length *)\n let rec loop prev i ac = if i=n then ac\n else if s.[i] = prev\n then loop prev (i+1) ac\n else loop s.[i] (i+1) (ac+1)\n in\n loop 'x' 0 0\n in\n\n let answer =\n if n=k then n\n else if n=k+1 then n\n else if n >= k+2 then k+2\n else failwith \"impossible\"\n in\n\n printf \"%d\\n\" answer\n"}, {"source_code": "open Scanf\n\nlet read_int () = scanf \" %d\" (fun x -> x)\nlet read_string () = scanf \" %s\" (fun x -> x)\nlet n = read_int ()\nlet s = read_string ()\n\nlet longest_seq s =\n let last = ref '2'\n and cnt = ref 0 in\n begin\n for i = 0 to n - 1 do\n if s.[i] <> !last then\n begin\n incr cnt;\n last := s.[i]\n end\n done;\n !cnt\n end\n\nlet res = min n (longest_seq s + 2)\nlet _ = print_int res\n"}, {"source_code": "open Printf;;\nopen Scanf;;\n\nlet n = read_int();;\nlet s = input_line stdin;;\nlet dp0 = Array.make (n+1) 0;;\nlet dp1 = Array.make (n+1) 0;;\nlet dp2 = Array.make (n+1) 0;;\nfor i=1 to n-1 do\n let aux1 = if s.[i]<>s.[i-1] then 1 + dp1.(i-1) else dp1.(i-1)\n and aux2 = if s.[i]<>s.[i-1] then dp0.(i-1) else 1 + dp0.(i-1)\n and aux3 = if s.[i]<>s.[i-1] then 1 + dp2.(i-1) else dp2.(i-1)\n and aux4 = if s.[i]<>s.[i-1] then dp1.(i-1) else 1 + dp1.(i-1)\n in let res1 = max aux1 aux2\n and res2 = max aux3 aux4 in\n dp0.(i) <- if s.[i]<>s.[i-1] then 1 + dp0.(i-1) else dp0.(i-1);\n dp1.(i) <- res1;\n dp2.(i) <- res2;\ndone;;\nprintf \"%d\" (1 + max dp0.(n-1) (max dp1.(n-1) dp2.(n-1)));;"}, {"source_code": "let n = read_int()\nand s = input_line stdin;;\n\nlet rec solve i =\nif (i=0) then (0,0,0) else\nbegin\n let (r0,r1,r2) = solve (i-1)\n and ib b = if(b) then 1 else 0 in\n (ib(s.[i]<>s.[i-1]) + r0,\n max (ib(s.[i]<>s.[i-1]) + r1) (ib(not(s.[i]<>s.[i-1])) + r0),\n max (ib(s.[i]<>s.[i-1]) + r2) (ib(not(s.[i]<>s.[i-1])) + r1))\nend;;\n\nlet (a,b,c) = solve(n-1) in\nPrintf.printf \"%d\" (1 + max a (max b c));;"}, {"source_code": "let n = read_int();;\nlet s = input_line stdin;;\nlet dp = Array.make_matrix (n+1) 3 0;;\n\nlet rec solve i =\nif (i=0) then (0,0,0) else\nbegin\n let (r0,r1,r2) = solve (i-1)\n and ib b = if(b) then 1 else 0 in\n (ib(s.[i]<>s.[i-1]) + r0,\n max (ib(s.[i]<>s.[i-1]) + r1) (ib(not(s.[i]<>s.[i-1])) + r0),\n max (ib(s.[i]<>s.[i-1]) + r2) (ib(not(s.[i]<>s.[i-1])) + r1))\nend;;\n\nlet (a,b,c) = solve(n-1);;\nPrintf.printf \"%d\" (1 + max a (max b c));;"}], "negative_code": [{"source_code": "open Printf;;\nopen Scanf;;\n\nlet n = read_int();;\nlet s = input_line stdin;;\nlet dp0 = Array.make (n+1) 0;;\nlet dp1 = Array.make (n+1) 0;;\nlet dp2 = Array.make (n+1) 0;;\nfor i=1 to n-1 do\n let aux1 = if s.[i]<>s.[i-1] then 1 + dp1.(i-1) else dp1.(i-1)\n and aux2 = if s.[i]<>s.[i-1] then dp0.(i-1) else 1 + dp0.(i-1)\n and aux3 = if s.[i]<>s.[i-1] then 1 + dp2.(i-1) else dp2.(i-1)\n and aux4 = if s.[i]<>s.[i-1] then dp1.(i-1) else 1 + dp1.(i-1)\n in let res1 = max aux1 aux2\n and res2 = max aux3 aux4 in\n dp0.(i) <- if s.[i]<>s.[i-1] then 1 + dp0.(i-1) else dp0.(i-1);\n dp1.(i) <- res1;\n dp2.(i) <- res2;\ndone;;\nprintf \"%d\" (max dp0.(n-1) (max dp1.(n-1) dp2.(n-1)));;"}], "src_uid": "7b56edf7cc71a1b3e39b3057a4387cad"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nlet n = read_int()\nlet a = Array.make n 0\n\nlet _ = \n for i=0 to n-1 do\n a.(i) <- read_int() -1 \n done\n \nlet b = Array.make n 0\n\nlet _ =\n for i=0 to n-1 do\n b.(a.(i)) <- i\n done;\n\n for i=0 to n-1 do\n Printf.printf \"%d\" (b.(i)+1);\n if i n)\n\nlet input () = Array.init (read ()) (fun n -> read ())\n\nlet solve gifter = \n let l = Array.length gifter in\n let giftee = Array.make l 0 in\n let rec loop i = \n if i < l\n then\n (let j = Array.get gifter i in\n Array.set giftee (j - 1) (i + 1);\n loop (i + 1))\n else\n giftee\n in loop 0\n\nlet () = Array.iter(Printf.printf \"%d \") (solve (input()))"}, {"source_code": "let read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let n = read_int () in\n let arr = Array.make n 0 in\n for i = 0 to n-1 do\n let e = read_int () in\n (Array.set arr (e-1) i)\n done; \n Array.iter (fun x -> (Printf.printf \"%d \" (x + 1))) arr\n"}, {"source_code": "let string_of_charlist cl =\n let rec iter cl str =\n match cl with\n [] -> str\n | r :: rest ->\n let s = Char.escaped r in\n iter rest (str ^ s)\n in iter cl \"\"\n\nlet charlist_of_string str =\n let n = String.length str in\n let rec iter i cl =\n if i < 0 then\n cl\n else\n let sc = str.[i] in\n iter (i-1) (sc :: cl)\n in iter (n-1) []\n\nlet split c s =\n let n = String.length s in\n let rec spliti i cl sl = \n if i < 0 then\n if cl = [] then\n sl\n else\n let cs = string_of_charlist cl in\n cs :: sl\n else if s.[i] = c then\n if cl = [] then\n spliti (i-1) cl sl\n else\n let cs = string_of_charlist cl in\n spliti (i-1) [] (cs :: sl)\n else\n spliti (i-1) (s.[i] :: cl) sl\n in spliti (n-1) [] []\n\nlet n = read_line ();;\n\nlet input = List.map int_of_string (split ' ' (read_line ()));;\n\nlet rec f i = function\n [] -> []\n | r :: rest -> (i, r) :: (f (i+1) rest);;\n\nlet hoge = f 1 input;;\n\nlet output =\n let fn (_, a) (_, b) = a <= b in\n let fm (a, b) = string_of_int a in\n let out = Sort.list fn hoge in\n let ou2 = List.map fm out in\n String.concat \" \" ou2;;\n\nprint_endline output;;\n\n"}, {"source_code": "let rec split str sep = \n\tif str = \"\" then []\n\telse try\n\t\tlet i = String.index str sep in\n\t\tlet x = String.sub str 0 i in\n\t\tlet xs = String.sub str (i+1) (String.length str - i - 1) in\n\t\tx::(split xs sep)\n\twith _ -> [str]\n;;\n\nlet n = read_int () in\nlet nums = List.map int_of_string (split (read_line()) ' ') in\nlet p = Array.make n 0 in\nlet _ = for i = 0 to n-1 do\n\tArray.set p (List.nth nums i - 1) i\ndone in\nfor i = 0 to n-1 do\n\tprint_string (string_of_int (p.(i) + 1) ^ \" \")\ndone;;\n"}, {"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 + 1) 0 in\n for i = 1 to n do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(k) <- i\n done;\n for i = 1 to n do\n Printf.printf \"%d \" a.(i);\n done;\n Printf.printf \"\\n\"\n"}, {"source_code": "let iteri f = \n let rec iteri' i = function\n [] -> ()\n | x::xs -> f i x; iteri' (i+1) xs\n in\n iteri' 0\nlet read_int () = Scanf.scanf \"%d%c\" (fun x c -> x)\nlet rec read_ints n = \n if n = 0 then [] \n else let tmp = read_int () in tmp :: read_ints (n-1)\nlet print_array v = Array.iter (Printf.printf \"%d \") v\nlet p x = prerr_int x; prerr_newline ()\n\n;;\n\nlet _ =\n let n = read_int ()\n in\n let ans = Array.make n 0\n in\n iteri (fun i x -> ans.(x-1) <- i+1) (read_ints n);\n print_array ans\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet () = \n let l = read () in\n let gifter = Array.init l (fun x -> read ()) in\n let giftee = Array.make l 0 in\n let rec loop i = \n if i < l\n then\n (let j = (Array.get gifter i) - 1 in\n Array.set giftee j (i + 1);\n loop (i + 1))\n else\n Array.iter(Printf.printf \"%d \") giftee\n in loop 0"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = Array.init (read ()) (fun n -> read ())\n\nlet solve gifter = \n let l = Array.length gifter in\n let giftee = Array.make l 0 in\n let rec loop i = \n if i < l\n then\n (let j = (Array.get gifter i) - 1 in\n Array.set giftee j (i + 1);\n loop (i + 1))\n else\n giftee\n in loop 0\n\nlet () = Array.iter(Printf.printf \"%d \") (solve (input()))"}], "negative_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = Array.init (read ()) (fun n -> read ())\n\nlet solve gifter = \n let l = Array.length gifter in\n let giftee = Array.make l 0 in\n let rec loop i = \n if i < l\n then\n (let j = Array.get gifter i in\n Array.set giftee (j - 1) j;\n loop (i + 1))\n else\n giftee\n in loop 0\n\nlet () = Array.iter(Printf.printf \"%d \") (solve (input()))"}, {"source_code": "open Str;;\n\nprint_string (read_line ());;\n\n"}], "src_uid": "48bb148e2c4d003cad9d57e7b1ab78fb"} {"source_code": "let q = int_of_string (input_line stdin);;\n\nlet output a b c d =\n let other = if a = c then d else c in\n Printf.printf \"%d %d\\n\" a other ;;\n\nlet solve () = Scanf.scanf \"%d %d %d %d \" output ;;\n\nfor i = 1 to q do\n solve ()\ndone", "positive_code": [{"source_code": "\nopen Str\n\nlet twoPoints (l1:int) (r1:int) (l2:int) (r2:int) : int * int=\n if l1 <> l2 then (l1,l2) \n else if r1 > l1 then (r1, l2) \n else (l1,r2)\n\nlet rec repeat (n:int) f =\n if n > 0 then (f () ; repeat (n-1) f)\n\nlet oneiter () =\n let inp = read_line() in\n let [l1;r1;l2;r2] =\n List.map int_of_string (Str.split (Str.regexp \" +\") inp) in\n let (x,y) = twoPoints l1 r1 l2 r2 in\n print_string ((string_of_int x) ^ \" \" ^ (string_of_int y) ^ \"\\n\")\n\nlet main () =\n let q = int_of_string (read_line ()) in\n repeat q oneiter\n\nlet () = main()\n"}], "negative_code": [{"source_code": "let q = int_of_string (input_line stdin);;\n\nlet output a b c d =\n let min = Pervasives.min a c in\n let max = Pervasives.max b d in\n Printf.printf \"%d %d\\n\" min max ;;\n\nlet solve () = Scanf.scanf \"%d %d %d %d \" output ;;\n\nfor i = 1 to q do\n solve ()\ndone"}, {"source_code": "let q = int_of_string (input_line stdin);;\n\nlet output a b c d = Printf.printf \"%d %d\\n\" a d ;;\nlet solve () = Scanf.scanf \"%d %d %d %d \" output ;;\n\nfor i = 1 to q do\n solve ()\ndone"}], "src_uid": "cdafe800094113515e1de1acb60c4bb5"} {"source_code": "(* Codeforces 276C - Devochka max sum *)\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 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet rec read_pairs_list n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ ->\n\t\t\tlet x = gr()-1 in\n\t\t\tlet y = gr()-1 in\n\t\t\tread_pairs_list (n -1) ((x, y) :: acc);;\n\nlet n = gr();;\nlet q = gr();;\nlet a = readlist n [];;\nlet lr = read_pairs_list q [];;\nlet ocua = Array.make n 0;;\nlet ocu1000 = Array.make ((n /1000) +1) 0;;\n\nlet rec count_ocu lp = match lp with\n\t| [] -> ()\n\t| (l, r) :: tl ->\n\t\t\tbegin\n\t\t\t\tlet lt = l /1000 in\n\t\t\t\tlet rt = r /1000 in\n\t\t\t\tif lt < rt -1 then begin\n\t\t\t\t\tfor i = lt +1 to rt -1 do\n\t\t\t\t\t\tocu1000.(i) <- ocu1000.(i) + 1\n\t\t\t\t\tdone;\n\t\t\t\t\tfor i = l to (lt +1) *1000 -1 do\n\t\t\t\t\t\tocua.(i) <- ocua.(i) + 1\n\t\t\t\t\tdone;\n\t\t\t\t\tfor i = rt *1000 to r do\n\t\t\t\t\t\tocua.(i) <- ocua.(i) + 1\n\t\t\t\t\tdone\n\t\t\t\tend else\n\t\t\t\t\tfor i = l to r do\n\t\t\t\t\t\tocua.(i) <- ocua.(i) + 1\n\t\t\t\t\tdone;\n\t\t\t\tcount_ocu tl\n\t\t\tend;;\n\nlet rec use_thousands n = match n with\n\t| 0 -> ()\n\t| _ ->\n\t\t\tlet n1 = n -1 in (\n\t\t\t\tocua.(n1) <- ocua.(n1) + ocu1000.(n1 /1000);\n\t\t\t\tuse_thousands n1\n\t\t\t);;\n\nlet rec cntmul sa sb cnt =\n\tmatch sa, sb with\n\t| [], [] -> cnt\n\t| ha :: ta, hb :: tb ->\n\t\t\tlet ncnt = (Int64.add cnt (Int64.mul (Int64.of_int ha) (Int64.of_int hb))) in\n\t\t\tcntmul ta tb ncnt\n\t| _ -> raise (Failure \"Different lengths sa sb\");;\n\nlet main() =\n\tbegin\n\t\tcount_ocu lr;\n\t\tuse_thousands (n -1);\n\t\tlet sb = List.sort compare (Array.to_list ocua) in\n\t\tlet sa = List.sort compare a in\n\t\tlet sum_mul = cntmul sa sb Int64.zero in\n\t\tprint_string ((Int64.to_string sum_mul) ^ \"\\n\")\n\tend;;\n\nmain();;\n", "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\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\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) 0L\n\nlet () = \n let (n,q) = read_pair() in\n\n let a = Array.init n (fun i -> read_long()) in\n\n let range = Array.init q (fun _ -> read_pair()) in\n\n let count = Array.make (n+1) 0L in\n\n for i=0 to q-1 do\n let (l,r) = range.(i) in\n\tcount.(l-1) <- count.(l-1) ++ 1L;\n\tcount.(r) <- count.(r) -- 1L;\n done;\n\n for i=1 to n do\n count.(i) <- count.(i-1) ++ count.(i)\n done;\n\n let () = count.(n) <- Int64.max_int in\n\n let () = Array.sort compare count in\n \n let () = Array.sort compare a in\n\n let answer = sum 0 (n-1) (fun i-> count.(i) ** a.(i)) in\n Printf.printf \"%Ld\\n\" answer\n"}], "negative_code": [], "src_uid": "926ec28d1c80e7cbe0bb6d209e664f48"} {"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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\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 let c = read_int () in\n\n (* the following 3 arrays represent the input, and are not computed *) \n let lhi = Array.make (n+1) 0 in (* lhi.(x) is the highest node required to be in the left subtree of x *)\n let rlo = Array.make (n+1) (n+1) in (* everything in [rlo.(x), rhi.(x)] must be in the right subtree of x*)\n let rhi = Array.make (n+1) 0 in\n\n (* the following two arrays are computed *)\n let rtc = Array.init (n+1) (fun i -> i) in \n (* rtc.(x) (required to contain)\n We know that the subtree rooted at x must contain x,x+1 ... y\n for some y. rtc.(x) is the minimum such y required by the \n constraints on the nodes x and greater. *)\n let l = Array.make (n+1) 0 in (* size of the left subtree of x *)\n\n try (\n for i=1 to c do\n let x = read_int() in\n let y = read_int() in\n if y <= x then raise (Failure \"1\");\n match read_string() with \n\t| \"LEFT\" -> \n\t lhi.(x) <- max lhi.(x) y;\n\t| \"RIGHT\" -> \n\t rlo.(x) <- min rlo.(x) y;\n\t rhi.(x) <- max rhi.(x) y;\n\t| _ -> failwith \"bad command\"\n done;\n \n for x = n-1 downto 2 do\n rtc.(x) <- max rtc.(x) (max lhi.(x-1) (max lhi.(x) rhi.(x)));\n rtc.(x) <- maxf x rtc.(x) (Array.get rtc);\n done;\n \n for x = 1 to n-1 do\n l.(x) <- if lhi.(x) = 0 then 0 else rtc.(x+1) - (x+1) + 1;\n done;\n\n for x = 1 to n-1 do\n if x + l.(x) >= rlo.(x) then raise (Failure \"2\");\n done;\n\n let rec inorder x s = \n if l.(x) > 0 then inorder (x+1) l.(x);\n printf \"%d \" x;\n let rsize = s - l.(x) - 1 in\n if rsize > 0 then inorder (x+l.(x)+1) rsize\n in\n inorder 1 n;\n print_newline();\n\n ) with Failure s -> printf \"IMPOSSIBLE\\n\";\n", "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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let c = read_int () in\n \n let l = Array.make (n+1) 0 in (* size of the left subtree of x *)\n let lhi = Array.make (n+1) 0 in (* lhi.(x) is the highest node required to be in the left subtree of x *)\n let rlo = Array.make (n+1) (n+1) in (* everything in [rlo.(x), rhi.(x)] must be in the right subtree of x*)\n let rhi = Array.make (n+1) 0 in\n let rtc = Array.init (n+1) (fun i -> i) in \n (* rtc.(x) (required to contain)\n We know that the subtree rooted at x must contain x,x+1 ... y\n for some y. rc.(x) is the minimum such y required by the \n constraints on the nodes x and greater. *)\n\n try (\n for i=1 to c do\n let x = read_int() in\n let y = read_int() in\n if y <= x then raise (Failure \"1\");\n match read_string() with \n\t| \"LEFT\" -> \n\t lhi.(x) <- max lhi.(x) y;\n\t| \"RIGHT\" -> \n\t rlo.(x) <- min rlo.(x) y;\n\t rhi.(x) <- max rhi.(x) y;\n\t| _ -> failwith \"bad command\"\n done;\n \n for x = n-1 downto 2 do\n rtc.(x) <- max rtc.(x) (max lhi.(x-1) (max lhi.(x) rhi.(x)));\n let rec loop rtcx = \n\trtc.(x) <- maxf x rtcx (Array.get rtc);\n\tif rtc.(x) > rtcx then loop rtc.(x)\n in\n loop rtc.(x);\n done;\n \n for x = 1 to n-1 do\n l.(x) <- if lhi.(x) = 0 then 0 else rtc.(x+1) - (x+1) + 1;\n done;\n\n for x = 1 to n-1 do\n if x + l.(x) >= rlo.(x) then raise (Failure \"2\");\n done;\n\n let rec inorder x s = \n if l.(x) > 0 then inorder (x+1) l.(x);\n printf \"%d \" x;\n let rsize = s - l.(x) - 1 in\n if rsize > 0 then inorder (x+l.(x)+1) rsize\n in\n inorder 1 n;\n print_newline();\n\n ) with Failure s -> printf \"IMPOSSIBLE\\n\";\n"}, {"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 let c = read_int () in\n\n (* the following 3 arrays represent the input, and are not computed *) \n let lhi = Array.make (n+1) 0 in (* lhi.(x) is the highest node required to be in the left subtree of x *)\n let rlo = Array.make (n+1) (n+1) in (* everything in [rlo.(x), rhi.(x)] must be in the right subtree of x*)\n let rhi = Array.make (n+1) 0 in\n\n (* the following two arrays are computed *)\n let rtc = Array.init (n+1) (fun i -> i) in \n (* rtc.(x) (required to contain)\n We know that the subtree rooted at x must contain x,x+1 ... y\n for some y. rtc.(x) is the minimum such y required by the \n constraints on the nodes x and greater. *)\n let l = Array.make (n+1) 0 in (* size of the left subtree of x *)\n\n try (\n for i=1 to c do\n let x = read_int() in\n let y = read_int() in\n if y <= x then raise (Failure \"1\");\n match read_string() with \n\t| \"LEFT\" -> \n\t lhi.(x) <- max lhi.(x) y;\n\t| \"RIGHT\" -> \n\t rlo.(x) <- min rlo.(x) y;\n\t rhi.(x) <- max rhi.(x) y;\n\t| _ -> failwith \"bad command\"\n done;\n\n let rec set_rtc x elist = if x>1 then (\n rtc.(x) <- max rtc.(x) (max lhi.(x-1) (max lhi.(x) rhi.(x)));\n let rec loop elist =\n\tmatch elist with\n\t | [] -> [(x,rtc.(x))]\n\t | (a,b)::tail ->\n\t if rtc.(x) < a then (x,rtc.(x))::elist else (\n\t rtc.(x) <- max b rtc.(x);\n\t loop tail\n\t )\n in\n if rtc.(x) > x then set_rtc (x-1) (loop elist) else set_rtc (x-1) elist\n )\n in\n\n set_rtc (n-1) [];\n\n for x = 1 to n-1 do\n l.(x) <- if lhi.(x) = 0 then 0 else rtc.(x+1) - (x+1) + 1;\n done;\n\n for x = 1 to n-1 do\n if x + l.(x) >= rlo.(x) then raise (Failure \"2\");\n done;\n\n let rec inorder x s = \n if l.(x) > 0 then inorder (x+1) l.(x);\n printf \"%d \" x;\n let rsize = s - l.(x) - 1 in\n if rsize > 0 then inorder (x+l.(x)+1) rsize\n in\n inorder 1 n;\n print_newline();\n\n ) with Failure s -> printf \"IMPOSSIBLE\\n\";\n"}], "negative_code": [{"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 let c = read_int () in\n\n (* the following 3 arrays represent the input, and are not computed *) \n let lhi = Array.make (n+1) 0 in (* lhi.(x) is the highest node required to be in the left subtree of x *)\n let rlo = Array.make (n+1) (n+1) in (* everything in [rlo.(x), rhi.(x)] must be in the right subtree of x*)\n let rhi = Array.make (n+1) 0 in\n\n (* the following two arrays are computed *)\n let rtc = Array.init (n+1) (fun i -> i) in \n (* rtc.(x) (required to contain)\n We know that the subtree rooted at x must contain x,x+1 ... y\n for some y. rtc.(x) is the minimum such y required by the \n constraints on the nodes x and greater. *)\n let l = Array.make (n+1) 0 in (* size of the left subtree of x *)\n\n try (\n for i=1 to c do\n let x = read_int() in\n let y = read_int() in\n if y <= x then raise (Failure \"1\");\n match read_string() with \n\t| \"LEFT\" -> \n\t lhi.(x) <- max lhi.(x) y;\n\t| \"RIGHT\" -> \n\t rlo.(x) <- min rlo.(x) y;\n\t rhi.(x) <- max rhi.(x) y;\n\t| _ -> failwith \"bad command\"\n done;\n\n let rec set_rtc x elist = if x>2 then (\n rtc.(x) <- max rtc.(x) (max lhi.(x-1) (max lhi.(x) rhi.(x)));\n let rec loop elist =\n\tmatch elist with\n\t | [] -> [(x,rtc.(x))]\n\t | (a,b)::tail ->\n\t if rtc.(x) < a then (x,rtc.(x))::elist else (\n\t rtc.(x) <- max b rtc.(x);\n\t loop tail\n\t )\n in\n if rtc.(x) > x then set_rtc (x-1) (loop elist) else set_rtc (x-1) elist\n )\n in\n\n set_rtc (n-1) [];\n\n for x = 1 to n-1 do\n l.(x) <- if lhi.(x) = 0 then 0 else rtc.(x+1) - (x+1) + 1;\n done;\n\n for x = 1 to n-1 do\n if x + l.(x) >= rlo.(x) then raise (Failure \"2\");\n done;\n\n let rec inorder x s = \n if l.(x) > 0 then inorder (x+1) l.(x);\n printf \"%d \" x;\n let rsize = s - l.(x) - 1 in\n if rsize > 0 then inorder (x+l.(x)+1) rsize\n in\n inorder 1 n;\n print_newline();\n\n ) with Failure s -> printf \"IMPOSSIBLE\\n\";\n"}], "src_uid": "e683d660af1e8a98f20296f289aa8960"} {"source_code": "let ( ** ) = Pervasives.( ** )\nlet pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328;;\nScanf.scanf \" %f %f\" @@ fun n r ->\n let u = pi /. (2. *. n) in\n let q = (sin u -. cos u) ** 2. in\n let p = r *. sin (pi /. n) in\n Printf.printf \"%.18f\" @@ p /. q", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = bscanf Scanning.stdib \" %f \" (fun x -> x)\n\nlet pi = 2.0 *. (atan2 1.0 0.0)\n \nlet () =\n let n = read_int() in\n let r0 = read_float() in\n\n let alpha = pi /. (float n) in\n let salpha = sin alpha in\n\n let r = salpha /. (1.0 -. salpha) in\n\n printf \"%.8f\\n\" (r0 *. r)\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_float _ = bscanf Scanning.stdib \" %f \" (fun x -> x)\n\nlet () =\n let n = read_float () and r = read_float () in\n let pi = acos (-1.) in\n let x = sin (pi /. n) in\n let ans = r *. x /. (1. -. x) in\n printf \"%f\\n\" ans"}, {"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 pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328\nlet () =\n let n,r = g2 0 in\n let u = (pi /. (2.*.(Int64.to_float n))) in\n let q = (sin u -. cos u) ** 2. in\n let p = (Int64.to_float r) *. sin (pi /. (Int64.to_float n))\n in\n printf \"%.18f\" @@ p /. q\n\n\n\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "e27cff5d681217460d5238bf7ef6a876"} {"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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet ( -- ) (x1,y1) (x2,y2) = (x1-.x2, y1-.y2)\nlet ( ++ ) (x1,y1) (x2,y2) = (x1+.x2, y1+.y2) \nlet len (x,y) = sqrt(x*.x +. y*.y)\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let a = float (read_int()) in\n let b = float (read_int()) in \n let n = read_int () in\n let data = Array.init n (fun _ ->\n let x = float (read_int()) in\n let y = float (read_int()) in\n let v = float (read_int()) in\n ((x,y),v)\n ) in\n\n let answer = minf 0 (n-1) (fun i ->\n let (p,v) = data.(i) in\n let d = len (p -- (a,b)) in\n d /. v\n ) in\n\n printf \"%.20f\\n\" answer\n", "positive_code": [{"source_code": "let expon\n= fun x1 x2 ->\n let foi = float_of_int in\n (foi (x1 - x2)) ** 2.0\n\nlet distance\n= fun (x1, y1) (x2, y2) ->\n sqrt ((expon x1 x2) +. (expon y1 y2))\n\nlet _\n= let a, b = Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y)) in\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let oneCase : unit -> float\n = fun () ->\n let x, y, v = Scanf.scanf \"%d %d %d\\n\" (fun x y z -> (x, y, z)) in\n (distance (a, b) (x, y)) /. (float_of_int v)\n in\n let firstCase = oneCase () in\n let rec minmin : int -> float -> float\n = fun i m ->\n if i <= 0 then m\n else(\n let mm = min m (oneCase ()) in\n minmin (i - 1) mm\n )\n in\n let mmmm = (minmin (n - 1) firstCase) in\n Printf.printf \"%.9f\" mmmm"}], "negative_code": [{"source_code": "type point = (int * int)\n\nlet taxi_distance : point -> point -> int\n= fun (x1, y1) (x2, y2) -> (abs (x1 - x2)) + (abs (y1 - y2))\n\n\nlet _\n= let a, b = Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y)) in\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let oneCase : unit -> float\n = fun () ->\n let x, y, v = Scanf.scanf \"%d %d %d\\n\" (fun x y z -> (x, y, z)) in\n (taxi_distance (a, b) (x, y) |> float_of_int) /. (float_of_int v)\n in\n let firstCase = oneCase () in\n let rec minmin : int -> float -> float\n = fun i m ->\n if i <= 0 then m\n else(\n let mm = min m (oneCase ()) in\n minmin (i - 1) mm\n )\n in\n let mmmm = (minmin (n - 1) firstCase) in\n Printf.printf \"%.9f\" mmmm\n"}, {"source_code": "type point = (int * int)\n\nlet taxi_distance : point -> point -> int\n= fun (x1, y1) (x2, y2) -> (abs (x1 - x2)) + (abs (y1 - y2))\n\n\nlet _\n= let a, b = Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y)) in\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let oneCase : unit -> float\n = fun () ->\n let x, y, v = Scanf.scanf \"%d %d %d\\n\" (fun x y z -> (x, y, z)) in\n (taxi_distance (a, b) (x, y) |> float_of_int) /. (float_of_int v)\n in\n let firstCase = oneCase () in\n let rec minmin : int -> float -> float\n = fun i m ->\n if i <= 0 then m\n else(\n let mm = min m (oneCase ()) in\n minmin (i - 1) mm\n )\n in\n let mmmm = (minmin (n - 1) firstCase) in\n Printf.printf \"%.12f\" mmmm"}], "src_uid": "a74c65acd41ff9bb845062222135c60a"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\ntype 'a pri_queue =\nNode of 'a * 'a pri_queue * 'a pri_queue * int |\nNull\nexception Empty_Queue \nlet empty_queue = Null\nlet is_empty q = q = Null\nlet size q =\nmatch q with\nNull ->0 |\nNode (_,_,_,n) ->n\nlet getmax h =\nmatch h with\nNull ->raise Empty_Queue |\nNode (r,_,_,_) -> r\nlet set_root h r =\nmatch h with\n\nNull ->Node (r,Null,Null,1) |\nNode (_,l,p,n) ->Node (r,l,p,n)\nlet rec put h x =\nmatch h with\nNull ->Node (x,Null,Null,1) |\nNode (r,l,p,n) ->\nif size l <= size p then\nNode((max x r),(put l (min x r)),p,(n+1))\nelse\nNode((max x r),l,(put p (min x r)),(n+1))\nlet rec removemax h =\nmatch h with\nNull ->raise Empty_Queue |\nNode (_,Null,Null,_) ->Null |\nNode (_,l,Null,_) ->l |\nNode (_,Null,p,_) ->p |\nNode (_,(Node (rl,_,_,_) as l),\n(Node (rp,_,_,_) as p),n) ->\nif rl >= rp then\nNode (rl,removemax l,p,n - 1)\nelse\nNode (rp,l,removemax p,n - 1);;\nlet n = scan_int() and d= scan_int() and czy = ref 1 and dodaj = ref 0 and wyn = ref 0 and sum = ref 0 and q = ref empty_queue in\nlet tb = Array.make (n+1) 0 in\nbegin\n for i=1 to n do \n tb.(i) <- scan_int();\n sum := !sum + tb.(i); \n q := put !q (!sum, i)\n done;\n sum := 0;\n for i=1 to n do \n if tb.(i) <> 0 then sum := !sum + tb.(i)\n else if !sum < 0 then begin\n let a = ref (getmax !q) in \n while (snd(!a)) < i do q := removemax !q; a := getmax !q done;\n wyn := !wyn +1; \n sum := !sum + (d - (fst(!a)) - !dodaj); \n dodaj := d - fst(!a);\n if !sum < 0 then czy := 0 end;\n if !sum > d then czy := 0\n done;\n if !czy = 0 then print_int (-1)\n else print_int (!wyn)\nend\n\n", "positive_code": [{"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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n Int32.zero;;\nlet sumek = ref Int32.zero;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := Int32.add !sumek (Int32.of_int x.(i));\n lim.(i) <- Int32.sub (Int32.of_int d) (!sumek);\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet koncz () = \n print_string(\"-1\");\n exit 0;;\n\nif lim.(0) < Int32.zero then koncz();;\n\nlet wyn = ref 0 and dod = ref Int32.zero;;\nsumek := Int32.zero;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && Int32.add !sumek !dod < Int32.zero then begin\n dod := lim.(i);\n incr wyn;\n if Int32.add !sumek !dod < Int32.zero then koncz();\n end;\n sumek := Int32.add !sumek (Int32.of_int x.(i));\ndone;;\n\nprint_int !wyn;;\n\n(*\n4 1000000000\n-100 0 -250000000 0\n*)\n"}], "negative_code": [{"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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n 0;;\nlet sumek = ref 0;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := !sumek + x.(i);\n lim.(i) <- d - !sumek;\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet koncz () = \n print_string(\"-1\");\n exit 0;;\n\nif lim.(0) < 0 then koncz();;\n\nlet wyn = ref 0 and dod = ref 0;;\nsumek := 0;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && !sumek + !dod < 0 then begin\n dod := lim.(i);\n incr wyn;\n if !sumek + !dod < 0 then koncz();\n end;\n sumek := !sumek + x.(i);\ndone;;\n\nprint_int !wyn;;\n\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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n 0;;\nlet sumek = ref 0;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := !sumek + x.(i);\n lim.(i) <- max d (d - !sumek);\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet koncz () = \n print_string(\"-1\");\n exit 0;;\n\nif lim.(0) < 0 then koncz();;\n\nlet wyn = ref 0 and dod = ref 0;;\nsumek := 0;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && !sumek + !dod < 0 then begin\n dod := lim.(i);\n incr wyn;\n if !sumek + !dod < 0 then koncz();\n end;\n sumek := !sumek + x.(i);\ndone;;\n\nprint_int !wyn;;\n\n(*\n4 1000000000\n-100 0 -250000000 0\n*)\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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n 0;;\nlet sumek = ref 0;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := !sumek + x.(i);\n lim.(i) <- d - !sumek;\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet koncz =\n print_string(\"-1\");\n exit 0;;\n\nif lim.(0) < 0 then koncz\n\nlet wyn = ref 0 and dod = ref 0;;\nsumek := 0;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && !sumek + !dod < 0 then begin\n dod := lim.(i);\n incr wyn;\n if !sumek + !dod < 0 then koncz\n end;\n sumek := !sumek + x.(i);\ndone;;\n\nprint_int !wyn;;\n\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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n 0;;\nlet sumek = ref 0;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := !sumek + x.(i);\n lim.(i) <- min d (d - !sumek);\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet koncz () = \n print_string(\"-1\");\n exit 0;;\n\nif lim.(0) < 0 then koncz();;\n\nlet wyn = ref 0 and dod = ref 0;;\nsumek := 0;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && !sumek + !dod < 0 then begin\n dod := lim.(i);\n incr wyn;\n if !sumek + !dod < 0 then koncz();\n end;\n sumek := !sumek + x.(i);\ndone;;\n\nprint_int !wyn;;\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 () and d = scan_int();;\n\nlet x = Array.make n 0 and lim = Array.make n 0;;\nlet sumek = ref 0;;\n\nfor i = 0 to n - 1 do\n x.(i) <- scan_int();\n sumek := !sumek + x.(i);\n lim.(i) <- d - !sumek;\ndone;;\n\n\nfor i = n - 2 downto 0 do\n lim.(i) <- min lim.(i) lim.(i + 1);\ndone;;\n\nlet wyn = ref 0 and dod = ref 0;;\nsumek := 0;\nfor i = 0 to n - 1 do\n if x.(i) == 0 && !sumek + !dod < 0 then begin\n dod := lim.(i);\n incr wyn;\n if !sumek + !dod < 0 then begin\n print_string(\"-1\");\n exit 0;\n end;\n end;\n sumek := !sumek + x.(i);\ndone;;\n\nprint_int !wyn;;\n\n"}], "src_uid": "c112321ea5e5603fd0c95c4f01808db1"} {"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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet () = \n let n = read_int() in\n let input = Array.init n \n (fun _ -> let l = read_int() in let r = read_int() in (l,r)) in\n let minleft = minf 0 (n-1) (fun i -> let (l,r)=input.(i) in l) in\n let maxright = maxf 0 (n-1) (fun i -> let (l,r)=input.(i) in r) in\n \n let rec findit i = if i=n then None else\n let (l,r) = input.(i) in\n if l<=minleft && r>=maxright then Some i else findit (i+1)\n in\n\n let ans = \n match findit 0 with\n |\tNone -> -1\n | Some i -> i+1\n in\n Printf.printf \"%d\\n\" ans\n", "positive_code": [{"source_code": "(* Codeforces 242B BigOtres done *)\n\nopen String;;\nopen Int64;;\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (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_string \" \"; print_int i)) li;;\nlet printarri ai = Array.iter (fun i -> (print_string \" \"; print_int i)) ai;;\nlet debug = false;;\n\nlet rec checkOtr i n mna mxb idx =\n\tif i > n then idx\n\telse \n\t\tlet a = grl() in \n\t\tlet b = grl() in\n\t\tif a <= mna && mxb <= b then checkOtr (i+1) n a b i\n\t\telse \n\t\t\tlet idx = if mna <= a && b <= mxb then idx else -1 in\n\t\t\tlet mna = min a mna in\n\t\t\tlet mxb = max b mxb in\n\t\t\tcheckOtr (i+1) n mna mxb idx;; \n\nlet main () =\n\tlet n = gr() in\n\tlet a = grl() in\n\tlet b = grl() in\n\tlet idx = checkOtr 2 n a b 1 in\n\tprint_int idx;;\n\nmain();;\n"}], "negative_code": [], "src_uid": "e702594a8e993e135ea8ca78eb3ecd66"} {"source_code": "let () =\n Scanf.scanf \"%d %d\\n\" (fun n m ->\n let line = String.make m '#' in\n let empty = String.make (m - 1) '.' in\n for i = 1 to n do\n if i mod 2 = 1 then\n print_endline line\n else\n if i mod 4 = 0 then begin\n print_char '#';\n print_endline empty\n end else begin\n print_string empty;\n print_endline \"#\"\n end\n done\n )\n", "positive_code": [{"source_code": "let id x = x in\n\nlet rec range lo hi =\n if lo >= hi then []\n else lo :: range (lo + 1) hi in\n\nlet n = Scanf.scanf \" %d\" id in\nlet m = Scanf.scanf \" %d\" id in\n\nlet rec stringn s n = match n with\n1 -> s\n| _ -> s ^ stringn s (n - 1) in\n\nlet get i = if i mod 2 = 0 then stringn \"#\" m\n else if i mod 4 = 1 then stringn \".\" (m - 1) ^ \"#\"\n else \"#\" ^ stringn \".\" (m - 1) in\n\nn\n|> range 0\n|> List.map get\n|> List.iter print_endline ;;\n(*\nPrintf.printf \" %d %d\" n m ;; *)\n"}, {"source_code": "let input () = Scanf.scanf \"%d %d\" (fun n m -> (n, m))\n\nlet get_parity row =\n if row mod 2 = 0\n then\n if row / 2 mod 2 = 0\n then\n `even_left\n else\n `even_right\n else\n `odd\n\nlet make_line parity m = \n match parity with\n |`even_left -> \"#\" ^ (String.make (m - 1) '.')\n |`even_right -> (String.make (m - 1) '.') ^ \"#\"\n |`odd -> String.make m '#'\n\nlet solve (n, m) = \n let rec loop i = \n if i <= n \n then\n let line = make_line (get_parity i) m in\n Printf.printf \"%s\\n\" line;\n loop (i + 1)\n else\n ()\n in loop 1\n\nlet () = solve (input ())\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let m = read_int () in\n let rec solve pos str m = function\n | 0 -> str\n | n ->\n if (n mod 2) = 1 then\n solve pos (str ^ (String.make m '#') ^ \"\\n\") m (n - 1)\n else\n if pos then\n solve false (str ^ (String.make (m - 1) '.') ^ \"#\\n\") m (n - 1)\n else\n solve true (str ^ \"#\" ^ (String.make (m - 1) '.') ^ \"\\n\") m (n - 1)\n in Printf.printf \"%s\" (solve true \"\" m n)\n\n"}], "negative_code": [], "src_uid": "2a770c32d741b3440e7f78cd5670d54d"} {"source_code": "(* Darooha style *)\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\n(*\nlet ( *| ) = Int64.mul\nlet ( +| ) = Int64.add\nlet ( -| ) = Int64.sub\nlet ( /| ) = Int64.div\nlet ( %| ) = Int64.rem\n*)\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nopen Printf\nopen Scanf\n\nlet get h k =\n try Hashtbl.find h k with\n | Not_found -> 0\n \nlet set h k v = Hashtbl.replace h k v\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- read_int()\n done;\n let h = Hashtbl.create n in\n for i = 0 to n - 1 do\n set h a.(i) (get h a.(i) + 1)\n done;\n let res = ref 0L in\n Hashtbl.iter (fun k v ->\n\t\tlet pw2 = ref 1 in\n\t\tfor _ = 1 to 30 do\n\t\t\tpw2 := !pw2 * 2;\n\t\t\tlet k2 = !pw2 - k in\n\t\t\tif k < k2 then\n\t\t\t\tres := (long v) ** (long (get h (!pw2 - k))) ++ !res\n\t\t\telse if k = k2 then\n\t\t\t\tres := (long v) ** (long (v - 1)) // 2L ++ !res\n\t\tdone\n\t) h;\n printf \"%Ld\\n\" !res\n", "positive_code": [{"source_code": "(* Darooha style \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 ( *| ) = Int64.mul\nlet ( +| ) = Int64.add\nlet ( -| ) = Int64.sub\nlet ( /| ) = Int64.div\nlet ( %| ) = Int64.rem\n\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nopen Printf\nopen Scanf\n\nlet get h k =\n try Hashtbl.find h k with\n | Not_found -> 0\n \nlet set h k v = Hashtbl.replace h k v\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- read_int()\n done;\n let h = Hashtbl.create n in\n for i = 0 to n - 1 do\n set h a.(i) (get h a.(i) + 1)\n done;\n let res = ref 0L in\n Hashtbl.iter (fun k v ->\n\t\tlet pw2 = ref 1 in\n\t\tfor _ = 1 to 30 do\n\t\t\tpw2 := !pw2 * 2;\n\t\t\tlet k2 = !pw2 - k in\n\t\t\tif k < k2 then\n\t\t\t\tres := (long v) *| (long (get h (!pw2 - k))) +| !res\n\t\t\telse if k = k2 then\n\t\t\t\tres := (long v) *| (long (v - 1)) /| 2L +| !res\n\t\tdone\n\t) h;\n printf \"%Ld\\n\" !res\n"}, {"source_code": "let ( ** ) = Int64.mul\nlet ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( // ) = Int64.div\nlet ( %% ) = Int64.rem\n\n\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nopen Printf\nopen Scanf\n\nlet get h k =\n try Hashtbl.find h k with\n | Not_found -> 0\n \nlet set h k v = Hashtbl.replace h k v\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- read_int()\n done;\n let h = Hashtbl.create n in\n for i = 0 to n - 1 do\n set h a.(i) (get h a.(i) + 1)\n done;\n let res = ref 0L in\n Hashtbl.iter (fun k v ->\n\t\tlet pw2 = ref 1 in\n\t\tfor _ = 1 to 30 do\n\t\t\tpw2 := !pw2 * 2;\n\t\t\tlet k2 = !pw2 - k in\n\t\t\tif k < k2 then\n\t\t\t\tres := (long v) ** (long (get h (!pw2 - k))) ++ !res\n\t\t\telse if k = k2 then\n\t\t\t\tres := (long v) ** (long (v - 1)) // 2L ++ !res\n\t\tdone\n\t) h;\n printf \"%Ld\\n\" !res\n"}, {"source_code": "(* Darooha style *)\nlet ( ** ) = Int64.mul\nlet ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( // ) = Int64.div\nlet ( %% ) = Int64.rem\n\n(*\nlet ( *| ) a b = Int64.mul\nlet ( +| ) a b = Int64.add\nlet ( -| ) a b = Int64.sub\nlet ( /| ) a b = Int64.div\nlet ( %| ) a b = Int64.rem\n*)\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nopen Printf\nopen Scanf\n\nlet get h k =\n try Hashtbl.find h k with\n | Not_found -> 0\n \nlet set h k v = Hashtbl.replace h k v\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- read_int()\n done;\n let h = Hashtbl.create n in\n for i = 0 to n - 1 do\n set h a.(i) (get h a.(i) + 1)\n done;\n let res = ref 0L in\n Hashtbl.iter (fun k v ->\n\t\tlet pw2 = ref 1 in\n\t\tfor _ = 1 to 30 do\n\t\t\tpw2 := !pw2 * 2;\n\t\t\tlet k2 = !pw2 - k in\n\t\t\tif k < k2 then\n\t\t\t\tres := (long v) ** (long (get h (!pw2 - k))) ++ !res\n\t\t\telse if k = k2 then\n\t\t\t\tres := (long v) ** (long (v - 1)) // 2L ++ !res\n\t\tdone\n\t) h;\n printf \"%Ld\\n\" !res\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 \"%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 ht = Hashtbl.create n in\n let _ =\n for i = 0 to n - 1 do\n let c =\n\ttry\n\t Hashtbl.find ht a.(i)\n\twith\n\t | Not_found -> 0\n in\n\tHashtbl.replace ht a.(i) (c + 1)\n done\n in\n let res = ref 0L in\n Hashtbl.iter\n (fun x c ->\n\t for i = 1 to 30 do\n\t try\n\t if 1 lsl i - x = x\n\t then res := !res +| Int64.of_int c *| Int64.of_int (c - 1)\n\t else\n\t let c2 = Hashtbl.find ht (1 lsl i - x) in\n\t\t res := !res +| Int64.of_int c *| Int64.of_int c2;\n\t with\n\t | Not_found -> ()\n\t done;\n ) ht;\n res := !res /| 2L;\n Printf.printf \"%Ld\\n\" !res\n"}], "negative_code": [], "src_uid": "b812d2d3a031dadf3d850605d2e78e33"} {"source_code": "let () =\n\tlet module Ident = struct\n\t\texternal id : 'a -> 'a = \"%identity\" (* test *)\n\tend in\n\tlet open Printf in\n\tScanf.scanf \" %d\" @@ fun n ->\n\t\tif (n-2) mod 3 = 0 then printf \"1 2 %d\\n\" @@ Ident.id (n-3)\n\t\telse printf \"1 1 %d\\n\" @@ Ident.id (n-2)\n", "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 (+$) = (+) 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\nend open MyInt64\n\nlet () =\n\tlet n = get_i64 0 in\n\t(\n\t\tif (n - 2L) mod 3L = 0L then (\n\t\t\tprintf \"1 2 %Ld\" (n-3L)\n\t\t) else (\n\t\t\tprintf \"1 1 %Ld\" (n-2L)\n\t\t)\n\t)\n\n\n\n\n"}, {"source_code": "let n = int_of_string (input_line stdin) ;;\n\nif (n - 2) mod 3 != 0 then\n Printf.printf \"%d %d %d\\n\" 1 1 (n - 2)\nelse\n Printf.printf \"%d %d %d\\n\" 2 2 (n - 4) ;;"}], "negative_code": [{"source_code": "let () =\n\tlet module Ident = struct\n\t\texternal id : 'a -> 'a = \"%identity\" (* test *)\n\tend in\n\tlet open Printf in\n\tScanf.scanf \" %d\" @@ fun n ->\n\t\tif n-2 mod 3 = 0 then printf \"1 2 %d\\n\" @@ Ident.id (n-3)\n\t\telse printf \"1 1 %d\\n\" @@ Ident.id (n-2)"}], "src_uid": "91d5147fb602298e08cbdd9f86d833f8"} {"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> arr.(k) <- v;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet max_lex_predecessor l r =\n\tlet nl = String.length l in\n\tlet nr = String.length r in\n\tlet m = longest_common_prefix_length l r in\n\tif (m = nl) || ((m < nr) && (String.get l m) < (String.get r m)) then l\n\telse (String.sub l 0 m)\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tlet b = Array.make n \"\" in\n\tbegin\n\t\tb.(n-1) <- a.(n-1);\n\t\tfor k=(n-2) downto 0 do\n\t\t\tb.(k) <- (max_lex_predecessor a.(k) b.(k+1));\n\t\tdone;\n\t\tb\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n", "positive_code": [{"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> arr.(k) <- v;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet max_lex_predecessor_length l r =\n\tlet nl = String.length l in\n\tlet nr = String.length r in\n\tlet m = longest_common_prefix_length l r in\n\tif (m = nl) || (m = nr) then m\n\telse if (String.get l m) < (String.get r m) then nl \n\telse m\n;;\n\n\nlet max_lex_predecessor l r =\n\tlet nl = String.length l in\n\tlet m = max_lex_predecessor_length l r in\n\tif m = nl then l else (String.sub l 0 m)\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tlet b = Array.make n \"\" in\n\tbegin\n\t\tb.(n-1) <- a.(n-1);\n\t\tfor k=(n-2) downto 0 do\n\t\t\tb.(k) <- (max_lex_predecessor a.(k) b.(k+1));\n\t\tdone;\n\t\tb\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n"}, {"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tlet last_v = ref \"\" in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> \n\t\t\t\tbegin\n\t\t\t\t\tarr.(k) <- if v = !last_v then !last_v else v;\n\t\t\t\t\tlast_v := v;\n\t\t\t\tend\n\t\t\t);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tbegin\n\t\tfor k=(n-2) downto 0 do\n\t\t\tlet l = a.(k) in\n\t\t\tlet r = a.(k+1) in\n\t\t\tif (l != r) && (String.compare l r) >= 1 then\n\t\t\tbegin\n\t\t\t\ta.(k) <- (String.sub l 0 (longest_common_prefix_length l r));\n\t\t\tend;\n\t\tdone;\n\t\ta\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n"}, {"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> arr.(k) <- v;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet max_lex_predecessor_length l r =\n\tlet nl = String.length l in\n\tlet nr = String.length r in\n\tlet m = longest_common_prefix_length l r in\n\tif (m = nl) || (m = nr) then m\n\telse if (String.get l m) < (String.get r m) then nl \n\telse m\n;;\n\n\nlet max_lex_predecessor l r =\n\tlet m = max_lex_predecessor_length l r in\n\tString.sub l 0 m\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tlet b = Array.make n \"\" in\n\tbegin\n\t\tb.(n-1) <- a.(n-1);\n\t\tfor k=(n-2) downto 0 do\n\t\t\tb.(k) <- (max_lex_predecessor a.(k) b.(k+1));\n\t\tdone;\n\t\tb\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n"}, {"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> arr.(k) <- v;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet max_lex_predecessor l r =\n\tlet nl = String.length l in\n\tlet nr = String.length r in\n\tlet m = longest_common_prefix_length l r in\n\tif (m = nl) || ((m < nr) && (String.get l m) < (String.get r m)) then l\n\telse (String.sub l 0 m)\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tbegin\n\t\tfor k=(n-2) downto 0 do\n\t\t\ta.(k) <- (max_lex_predecessor a.(k) a.(k+1));\n\t\tdone;\n\t\ta\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n"}, {"source_code": "let print_array a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tprint_endline a.(k);\n\tdone;\n;;\n\n\nlet read_array n =\n\tlet arr = Array.make n \"\" in\n\tbegin\n\t\tfor k = 0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %s\" (fun v -> arr.(k) <- v;);\n\t\tdone;\n\t\tarr\n\tend\n;;\n\n\nlet longest_common_prefix_length l r =\n\tlet n = min (String.length l) (String.length r) in\n\tlet k = ref 1 in (* little optimization - we know that under index 0 we always have a hash-sign '#' *)\n\tbegin\n\t\twhile (!k < n) && ((String.get l !k) = (String.get r !k) ) do\n\t\t\tk := !k + 1;\n\t\tdone;\n\t\t!k\n\tend\n;;\n\n\nlet truncate_hashtags a = \n\tlet n = Array.length a in\n\tbegin\n\t\tfor k=(n-2) downto 0 do\n\t\t\tlet l = a.(k) in\n\t\t\tlet r = a.(k+1) in\n\t\t\tif (String.compare l r) >= 1 then\n\t\t\tbegin\n\t\t\t\ta.(k) <- (String.sub l 0 (longest_common_prefix_length l r));\n\t\t\tend\n\t\tdone;\n\t\ta\n\tend\n;;\n\n\nlet load_and_process_hashtags n =\n\tlet a = read_array n in\n\tlet b = truncate_hashtags a in\n\tprint_array b\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" load_and_process_hashtags\n;;\n\n\nread_input ()\n"}], "negative_code": [], "src_uid": "27baf9b1241c0f8e3a2037b18f39fe34"} {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d \" x;;\nlet print_int64 x = Printf.printf \"%Ld \" x;;\nlet print s = Printf.printf \"%s\" s;;\n\nmodule type S = sig\n val set : int -> int -> unit\n val get : int -> int \n val inc : int -> int -> unit\n val max_range : int -> int -> int \n val max_range_value : int -> int -> int\nend\n\nmodule MakeSegTree (M: (sig val size : int end)) : S = struct\n let n = M.size\n let nn = 3 * n\n \n let arr = Array.make n 0 \n let delta = Array.make nn 0\n\n let set i v = arr.(i) <- v\n let get i = arr.(i)\n\n let rec update c b e i =\n let upd c = \n if arr.(delta.(2*c)) < arr.(delta.(2*c+1)) then\n delta.(c) <- delta.(2*c+1)\n else \n delta.(c) <- delta.(2*c) in \n if (b > e || i > e || i < b) then ()\n else if ((i = b) && (i = e)) then delta.(c) <- i\n else if i <= (b+e)/2 then begin\n update (2*c) b ((b+e)/2) i; upd c\n end else begin \n update (2*c+1) (((b+e)/2)+1) e i; upd c\n end \n \n let inc i v =\n arr.(i) <- v;\n update 1 0 (n-1) i\n\n let rec query c b e i j = \n if (b > e || i > j || b > j || i > e) then -1 else\n if i <= b && e <= j then delta.(c) \n else\n let first = query (2*c) b ((b+e)/2) i j in\n let second = query (2*c+1) ((b+e)/2+1) e i j in\n match first,second with\n | -1,_ -> second\n | _,-1 -> first\n | _,_ -> \n if arr.(first) < arr.(second) then second \n else first \n\n let max_range i j = \n query 1 0 (n-1) i j\n\n let max_range_value i j =\n let ind = max_range i j in\n arr.(ind)\nend\n\nlet () =\n let n = read_int () in\n let module Size = struct \n let size = n\n end in\n let module Segtree = MakeSegTree(Size) in\n let dummy = Array.make (n-1) () in \n let arr = Array.map (fun _ -> read_int() -1) dummy in\n let add_to_seg i e =\n Segtree.inc i e in\n Array.iteri add_to_seg arr;\n Segtree.inc (n-1) 0;\n let dp = Array.make n Int64.zero in\n for i = n-2 downto 0 do\n let ma = Segtree.max_range (i+1) arr.(i) in\n dp.(i) <- Int64.add dp.(ma) (Int64.of_int (- (arr.(i) - ma) + (n - i - 1)));\n (*print_int i;\n print_int ma;\n print_int64 dp.(i);\n print_int64 (Int64.of_int ((arr.(i) - ma) + (n - i - 1))); \n print \"\\n\"; *)\n done;\n print_int64 (Array.fold_left Int64.add Int64.zero dp);;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet ( ++ ) a b = Int64.add a b\nlet long = Int64.of_int\n\nlet parent v = v/2\nlet lc v = 2*v\nlet rc v = 2*v+1\n\nlet superceil n =\n let rec loop i ac = if i=0 then ac else loop (i lsr 1) (ac lor i) in\n 1 + (loop (n-1) 0)\n\nlet max2 (h1,p1) (h2,p2) = let (x,y) = max (h1,-p1) (h2,-p2) in (x,-y)\n\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n (fun i -> if i=n-1 then i else -1 + read_int()) in\n\n let nn = superceil n in\n\n let t = Array.make (2*nn) (0,0) in \n\n let rec insert ar (x,i) =\n let rec loop j = if j>0 then (\n ar.(j) <- max2 ar.(j) (x,i);\n loop (parent j)\n ) in\n loop (i+nn)\n in\n\n let max_in_range i j =\n let rec f v l r ql qr =\n let m = (l+r)/2 in\n if l=ql && r=qr then t.(v) else\n\tlet t1 = if ql<=m then f (lc v) l m ql (min m qr) else (0,0) in\n\tlet t2 = if qr>m then f (rc v) (m+1) r (max ql (m+1)) qr else (0,0) in\n\tmax2 t1 t2\n in\n f 1 0 (nn-1) i j\n in\n\n for i=0 to n-1 do\n insert t (a.(i),i)\n done;\n\n let dist = Array.make n 0L in\n (* dist.(i) is the sum over all j>i of the number of hops from i to j *)\n\n for i=n-2 downto 0 do\n let k = a.(i) in\n let (_,j) = max_in_range (i+1) k in\n (* dist.(i) <- (k-i) + dist.(j) - (k-j) + (n-1-k) *)\n dist.(i) <- (long (j+n-k-i-1)) ++ dist.(j)\n done;\n\n let answer = sum 0 (n-2) (fun i -> dist.(i)) 0L in\n printf \"%Ld\\n\" answer\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d \" x;;\nlet print_int64 x = Printf.printf \"%Ld \" x;;\nlet print s = Printf.printf \"%s\" s;;\n\nmodule type S = sig\n val set : int -> int -> unit\n val get : int -> int \n val inc : int -> int -> unit\n val max_range : int -> int -> int \n val max_range_value : int -> int -> int\nend\n\nmodule MakeSegTree (M: (sig val size : int end)) : S = struct\n let n = M.size\n let nn = 3 * n\n \n let arr = Array.make n 0 \n let delta = Array.make nn 0\n\n let set i v = arr.(i) <- v\n let get i = arr.(i)\n\n let rec update c b e i =\n let upd c = \n if arr.(delta.(2*c)) < arr.(delta.(2*c+1)) then\n delta.(c) <- delta.(2*c+1)\n else \n delta.(c) <- delta.(2*c) in \n if (b > e || i > e || i < b) then ()\n else if ((i = b) && (i = e)) then delta.(c) <- i\n else if i <= (b+e)/2 then begin\n update (2*c) b ((b+e)/2) i; upd c\n end else begin \n update (2*c+1) (((b+e)/2)+1) e i; upd c\n end \n \n let inc i v =\n arr.(i) <- v;\n update 1 0 (n-1) i\n\n let rec query c b e i j = \n if (b > e || i > j || b > j || i > e) then -1 else\n if i <= b && e <= j then delta.(c) \n else\n let first = query (2*c) b ((b+e)/2) i j in\n let second = query (2*c+1) ((b+e)/2+1) e i j in\n match first,second with\n | -1,_ -> second\n | _,-1 -> first\n | _,_ -> \n if arr.(first) < arr.(second) then second \n else first \n\n let max_range i j = \n query 1 0 (n-1) i j\n\n let max_range_value i j =\n let ind = max_range i j in\n arr.(ind)\nend\n\nlet () =\n let n = read_int () in\n let module Size = struct \n let size = n\n end in\n let module Segtree = MakeSegTree(Size) in\n let dummy = Array.make (n-1) () in \n let arr = Array.map (fun _ -> read_int() -1) dummy in\n let add_to_seg i e =\n Segtree.inc i e in\n Array.iteri add_to_seg arr;\n Segtree.inc (n-1) 0;\n let dp = Array.make n Int64.zero in\n for i = n-2 downto 0 do\n let ma = Segtree.max_range (i+1) arr.(i) in\n dp.(i) <- Int64.sub dp.(ma) (Int64.of_int ((arr.(i) - ma) + (n - i - 1)));\n done;\n print_int64 (Array.fold_left Int64.add Int64.zero dp);;\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d \" x;;\nlet print s = Printf.printf \"%s\" s;;\n\nmodule type S = sig\n val set : int -> int -> unit\n val get : int -> int \n val inc : int -> int -> unit\n val max_range : int -> int -> int \n val max_range_value : int -> int -> int\nend\n\nmodule MakeSegTree (M: (sig val size : int end)) : S = struct\n let n = M.size\n let nn = 3 * n\n \n let arr = Array.make n 0 \n let delta = Array.make nn 0\n\n let set i v = arr.(i) <- v\n let get i = arr.(i)\n\n let rec update c b e i =\n let upd c = \n if arr.(delta.(2*c)) < arr.(delta.(2*c+1)) then\n delta.(c) <- delta.(2*c+1)\n else \n delta.(c) <- delta.(2*c) in \n if (b > e || i > e || i < b) then ()\n else if ((i = b) && (i = e)) then delta.(c) <- i\n else if i <= (b+e)/2 then begin\n update (2*c) b ((b+e)/2) i; upd c\n end else begin \n update (2*c+1) (((b+e)/2)+1) e i; upd c\n end \n \n let inc i v =\n arr.(i) <- v;\n update 1 0 (n-1) i\n\n let rec query c b e i j = \n if (b > e || i > j || b > j || i > e) then -1 else\n if i <= b && e <= j then delta.(c) \n else\n let first = query (2*c) b ((b+e)/2) i j in\n let second = query (2*c+1) ((b+e)/2+1) e i j in\n match first,second with\n | -1,_ -> second\n | _,-1 -> first\n | _,_ -> \n if arr.(first) < arr.(second) then second \n else first \n\n let max_range i j = \n query 1 0 (n-1) i j\n\n let max_range_value i j =\n let ind = max_range i j in\n arr.(ind)\nend\n\nlet () =\n let n = read_int () in\n let module Size = struct \n let size = n\n end in\n let module Segtree = MakeSegTree(Size) in\n let dummy = Array.make (n-1) () in \n let arr = Array.map read_int dummy in\n let add_to_seg i e =\n Segtree.inc i e in\n Array.iteri add_to_seg arr;\n let dp = Array.make (n-1) 1 in\n let process cur e =\n let res,i = cur in\n let ran = arr.(i) in\n let ma = Segtree.max_range (i+1) (ran-1) in\n if ran < n then dp.(ma) <- dp.(ma) + e;\n (*print_int ma;\n print_int e;\n print_int (res + e*(n-i-1));\n print \"\\n\";*)\n (res + e*(n-i-1)),(i+1) in\n let res,_ = Array.fold_left process (0,0) dp in\n print_int res;;\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d \" x;;\nlet print s = Printf.printf \"%s\" s;;\n\nmodule type S = sig\n val set : int -> int -> unit\n val get : int -> int \n val inc : int -> int -> unit\n val max_range : int -> int -> int \n val max_range_value : int -> int -> int\nend\n\nmodule MakeSegTree (M: (sig val size : int end)) : S = struct\n let n = M.size\n let nn = 3 * n\n \n let arr = Array.make n 0 \n let delta = Array.make nn 0\n\n let set i v = arr.(i) <- v\n let get i = arr.(i)\n\n let rec update c b e i =\n let upd c = \n if arr.(delta.(2*c)) < arr.(delta.(2*c+1)) then\n delta.(c) <- delta.(2*c+1)\n else \n delta.(c) <- delta.(2*c) in \n if (b > e || i > e || i < b) then ()\n else if ((i = b) && (i = e)) then delta.(c) <- i\n else if i <= (b+e)/2 then begin\n update (2*c) b ((b+e)/2) i; upd c\n end else begin \n update (2*c+1) (((b+e)/2)+1) e i; upd c\n end \n \n let inc i v =\n arr.(i) <- v;\n update 1 0 (n-1) i\n\n let rec query c b e i j = \n if (b > e || i > j || b > j || i > e) then -1 else\n if i <= b && e <= j then delta.(c) \n else\n let first = query (2*c) b ((b+e)/2) i j in\n let second = query (2*c+1) ((b+e)/2+1) e i j in\n match first,second with\n | -1,_ -> second\n | _,-1 -> first\n | _,_ -> \n if arr.(first) < arr.(second) then second \n else first \n\n let max_range i j = \n query 1 0 (n-1) i j\n\n let max_range_value i j =\n let ind = max_range i j in\n arr.(ind)\nend\n\nlet () =\n let n = read_int () in\n let module Size = struct \n let size = n\n end in\n let module Segtree = MakeSegTree(Size) in\n let dummy = Array.make (n-1) () in \n let arr = Array.map (fun _ -> read_int() -1) dummy in\n let add_to_seg i e =\n Segtree.inc i e in\n Array.iteri add_to_seg arr;\n Segtree.inc (n-1) 0;\n let dp = Array.make n 0 in\n for i = n-2 downto 0 do\n let ma = Segtree.max_range (i+1) arr.(i) in\n dp.(i) <- dp.(ma) - (arr.(i) - ma) + (n - i - 1);\n done;\n print_int (Array.fold_left (fun a b -> a + b) 0 dp);;\n"}], "src_uid": "88f8f2c2f68589654709800ea9b19ecf"} {"source_code": "let main () =\n\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0] - 48) in\n let s2 = 8 lsl (int_of_char s.[1] - 48) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if a.[0] = a.[1] && a.[0] = a.[2] &&\n a.[0] = a.[3] && a.[0] = a.[4] &&\n a.[0] = a.[5] then loop (r - 1) (taxi + 1) pizza girl else\n if a.[0] > a.[1] && a.[1] > a.[2] &&\n a.[2] > a.[3] && a.[3] > a.[4] &&\n a.[4] > a.[5] then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n \n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()", "positive_code": [{"source_code": "let main () =\n let check a p =\n let rec loop i =\n i = 0 || p a.[i - 1] a.[i] && loop (i - 1)\n in\n loop (String.length a - 1)\n in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, [|taxi; pizza; girl |] else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if check a (=) then loop (r - 1) (taxi + 1) pizza girl else\n if check a (>) then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc flag k pos = function\n | (name, target) :: tl ->\n if target.(pos) = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc false k pos tl\n ) else proc flag k pos tl\n | _ -> print_endline \".\"\n in\n\n let comp k = (fun (_, a1) (_, a2) -> compare a2.(k) a1.(k)) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort (comp 0) l with\n | (_, a) :: _ -> proc true a.(0) 0 l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort (comp 1) l with\n | (_, a) :: _ -> proc true a.(1) 1 l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort (comp 2) l with\n | (_, a) :: _ -> proc true a.(2) 2 l\n | _ -> ())\n;;\nmain ()\n"}, {"source_code": "let main () =\n let check a p =\n let rec loop i =\n i = 0 || p a.[i - 1] a.[i] && loop (i - 1)\n in\n loop (String.length a - 1)\n in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, [|taxi; pizza; girl |] else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if check a (=) then loop (r - 1) (taxi + 1) pizza girl else\n if check a (>) then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc flag k pos = function\n | (name, target) :: tl ->\n if target.(pos) = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc false k pos tl\n ) else proc flag k pos tl\n | _ -> print_endline \".\"\n in\n\n let comp k = (fun (_, a1) (_, a2) -> compare a2.(k) a1.(k)) in\n\n let l = Array.to_list arr in\n for i = 0 to 2 do\n print_string [| \"If you want to call a taxi, you should call: \";\n \"If you want to order a pizza, you should call: \";\n \"If you want to go to a cafe with a wonderful girl, you should call: \" |].(i);\n match List.sort (comp i) l with\n | (_, a) :: _ -> proc true a.(i) i l\n | _ -> ()\n done\n;;\nmain ()\n"}, {"source_code": "let main () =\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0] - 48) in\n let s2 = 8 lsl (int_of_char s.[1] - 48) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if a.[0] = a.[1] && a.[0] = a.[2] &&\n a.[0] = a.[3] && a.[0] = a.[4] &&\n a.[0] = a.[5] then loop (r - 1) (taxi + 1) pizza girl else\n if a.[0] > a.[1] && a.[1] > a.[2] &&\n a.[2] > a.[3] && a.[3] > a.[4] &&\n a.[4] > a.[5] then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()\n"}, {"source_code": "let main () =\n let check a p =\n let rec loop i =\n i = 0 || p a.[i - 1] a.[i] && loop (i - 1)\n in\n loop (String.length a - 1)\n in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if check a (=) then loop (r - 1) (taxi + 1) pizza girl else\n if check a (>) then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()\n"}, {"source_code": "let main () =\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if a.[0] = a.[1] && a.[0] = a.[2] &&\n a.[0] = a.[3] && a.[0] = a.[4] &&\n a.[0] = a.[5] then loop (r - 1) (taxi + 1) pizza girl else\n if a.[0] > a.[1] && a.[1] > a.[2] &&\n a.[2] > a.[3] && a.[3] > a.[4] &&\n a.[4] > a.[5] then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()"}, {"source_code": "\nlet main () = \n let kolvo = int_of_string (read_line ()) in\n\t(* \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0424\u0430\u043c\u0438\u043b\u0438\u044f, \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u044b \u0442\u0430\u043a\u0441\u0438, \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u044b \u043f\u0438\u0446\u0446\u044b, \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u044b \u0434\u0435\u0432\u043e\u0447\u0435\u043a *)\n let my_array = Array.init kolvo (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let temp = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if temp.[0] = temp.[1] && temp.[0] = temp.[2] &&\n temp.[0] = temp.[3] && temp.[0] = temp.[4] &&\n temp.[0] = temp.[5] then loop (r - 1) (taxi + 1) pizza girl else\n if temp.[0] > temp.[1] && temp.[1] > temp.[2] &&\n temp.[2] > temp.[3] && temp.[3] > temp.[4] &&\n temp.[4] > temp.[5] then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list my_array in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()"}, {"source_code": "let main () =\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0] - 48) in\n let s2 = 8 lsl (int_of_char s.[1] - 48) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1 ^ a2 ^ a3) in\n if a.[0] = a.[1] && a.[0] = a.[2] &&\n a.[0] = a.[3] && a.[0] = a.[4] &&\n a.[0] = a.[5] then loop (r - 1) (taxi + 1) pizza girl else\n if a.[0] > a.[1] && a.[1] > a.[2] &&\n a.[2] > a.[3] && a.[3] > a.[4] &&\n a.[4] > a.[5] then loop (r - 1) taxi (pizza + 1) girl \n else loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()"}], "negative_code": [{"source_code": "let main () =\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0]) in\n let s2 = 8 lsl (int_of_char s.[1]) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a1, a2, a3 = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1, a2, a3) in\n if a1 = a2 && a2 = a3 then loop (r - 1) (taxi + 1) pizza girl else\n if a1 > a2 && a2 > a3 && (map (map (map 0 a1) a2) a3) land 7 = 6\n then loop (r - 1) taxi (pizza + 1) girl else\n loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()\n"}, {"source_code": "let main () =\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0] - 48) in\n let s2 = 8 lsl (int_of_char s.[1] - 48) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a1, a2, a3 = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1, a2, a3) in\n if a1 = a2 && a2 = a3 then loop (r - 1) (taxi + 1) pizza girl else\n if a1 > a2 && a2 > a3 && (map (map (map 0 a1) a2) a3) land 7 = 6\n then loop (r - 1) taxi (pizza + 1) girl else\n loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()\n"}, {"source_code": "let main () =\n let map n s =\n let s1 = 8 lsl (int_of_char s.[0] - 48) in\n let s2 = 8 lsl (int_of_char s.[1] - 48) in\n let n = if n land s1 = 0 then (n lor s1) + 1 else n lor s1 in\n if n land s2 = 0 then (n lor s2) + 1 else n lor s2 in\n \n let n = int_of_string (read_line ()) in\n let arr = Array.init n (fun _ ->\n let (d, name) = Scanf.sscanf (read_line ()) \"%d %s\" (fun d name -> d, name) in\n let rec loop r taxi pizza girl =\n if r = 0 then name, taxi, pizza, girl else\n let a1, a2, a3 = Scanf.sscanf (read_line ()) \"%2s-%2s-%2s\" (fun a1 a2 a3 -> a1, a2, a3) in\n if a1 = a2 && a2 = a3 && int_of_string a1 mod 11 = 0 then loop (r - 1) (taxi + 1) pizza girl else\n if a1 > a2 && a2 > a3 && (map (map (map 0 a1) a2) a3) land 7 = 6\n then loop (r - 1) taxi (pizza + 1) girl else\n loop (r - 1) taxi pizza (girl + 1)\n in\n loop d 0 0 0\n )\n in\n\n let rec proc1 flag k = function\n | (name, taxi, _, _) :: tl ->\n if taxi = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc1 false k tl\n ) else proc1 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc2 flag k = function\n | (name, _, pizza, _) :: tl ->\n if pizza = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc2 false k tl\n ) else proc2 flag k tl\n | _ -> print_endline \".\"\n in\n\n let rec proc3 flag k = function\n | (name, _, _, girl) :: tl ->\n if girl = k then (\n Printf.printf \"%s%s\" (if flag then \"\" else \", \") name;\n proc3 false k tl\n ) else proc3 flag k tl\n | _ -> print_endline \".\"\n in\n\n let comp1 =(fun (_, k1, _, _) (_, k2, _, _) -> compare k2 k1) in\n let comp2 =(fun (_, _, k1, _) (_, _, k2, _) -> compare k2 k1) in\n let comp3 =(fun (_, _, _, k1) (_, _, _, k2) -> compare k2 k1) in\n\n let l = Array.to_list arr in\n print_string \"If you want to call a taxi, you should call: \";\n (match List.sort comp1 l with\n | (_, k, _, _) :: _ -> proc1 true k l\n | _ -> ());\n\n print_string \"If you want to order a pizza, you should call: \";\n (match List.sort comp2 l with\n | (_, _, k, _) :: _ -> proc2 true k l\n | _ -> ());\n\n print_string \"If you want to go to a cafe with a wonderful girl, you should call: \";\n (match List.sort comp3 l with\n | (_, _, _, k) :: _ -> proc3 true k l\n | _ -> ())\n;;\nmain ()\n"}], "src_uid": "4791a795119c185b3aec91b6f8af8f03"} {"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 s = read_string() in\n let p = read_string() in\n let m = String.length s in\n let n = String.length p in\n let () = if m '?' then hists.(j) <- hists.(j)+1\n done\n in\n let rec goodh i = if i=26 then true else histp.(i) >= hists.(i) && goodh(i+1)\n in\n let rec scan j ac =\n let inc = if goodh 0 then 1 else 0 in\n if j = m then inc + ac else (\n if s.[j]<> '?' then hists.(ci s.[j]) <- hists.(ci s.[j])+1;\n if s.[j-n] <> '?' then hists.(ci s.[j-n]) <- hists.(ci s.[j-n])-1;\n scan (j+1) (ac+inc)\n )\n in\n Printf.printf \"%d\\n\" (scan n 0)\n", "positive_code": [{"source_code": "(* codeforces 103. 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 s = read_string() in\n let p = read_string() in\n\n let m = String.length s in\n let n = String.length p in\n\n let () = if m < n then (Printf.printf \"0\\n\"; exit 1) in\n\n let histp = Array.make 26 0 in\n let hists = Array.make 26 0 in\n\n let ctoint c = (int_of_char c) - (int_of_char 'a') in\n \n let () =\n for i=0 to n-1 do\n let j = ctoint p.[i] in\n histp.(j) <- histp.(j) + 1\n done\n in\n\n let () =\n for i=0 to n-1 do\n let j = ctoint s.[i] in\n if s.[i] <> '?' then hists.(j) <- hists.(j) + 1\n done\n in\n\n let rec goodh i = if i=26 then true else histp.(i) >= hists.(i) && goodh (i+1) in\n\n let rec scan j ac = \n let inc = if goodh 0 then 1 else 0 in\n if j=m then inc + ac else (\n\tif s.[j] <> '?' then hists.(ctoint s.[j]) <- hists.(ctoint s.[j]) + 1;\n\tif s.[j-n] <> '?' then hists.(ctoint s.[j-n]) <- hists.(ctoint s.[j-n]) - 1;\n\tscan (j+1) (ac+inc)\n )\n in\n\n Printf.printf \"%d\\n\" (scan n 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 () = \n let s = read_string() in\n let p = read_string() in\n let m = String.length s in\n let n = String.length p in\n let () = if m '?' then hists.(j) <- hists.(j)+1\n\tdone\n in\n let rec goodh i = if i=26 then true else histp.(i) >= hists.(i) && goodh(i+1)\n in\n let rec scan j ac = \n\tlet inc = if goodh 0 then 1 else 0 in\n\tif j = m then inc + ac else (\n\t if s.[j]<> '?' then hists.(ci s.[j]) <- hists.(ci s.[j])+1;\n\t if s.[j-n] <> '?' then hists.(ci s.[j-n]) <- hists.(ci s.[j-n])+1;\n\t scan (j+1) (ac+inc)\n\t)\n in\n Printf.printf \"%d\\n\" (scan n 0)\n\t \n"}, {"source_code": "(* codeforces 103. 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 s = read_string() in\n let p = read_string() in\n\n let m = String.length s in\n let n = String.length p in\n\n let histp = Array.make 26 0 in\n let hists = Array.make 26 0 in\n\n let ctoint c = (int_of_char c) - (int_of_char 'a') in\n \n let () =\n for i=0 to n-1 do\n let j = ctoint p.[i] in\n histp.(j) <- histp.(j) + 1\n done\n in\n\n let () =\n for i=0 to n-1 do\n let j = ctoint s.[i] in\n if s.[i] <> '?' then hists.(j) <- hists.(j) + 1\n done\n in\n\n let rec goodh i = if i=26 then true else histp.(i) >= hists.(i) && goodh (i+1) in\n\n let rec scan j ac = \n let inc = if goodh 0 then 1 else 0 in\n if j=m then inc + ac else (\n\tif s.[j] <> '?' then hists.(ctoint s.[j]) <- hists.(ctoint s.[j]) + 1;\n\tif s.[j-n] <> '?' then hists.(ctoint s.[j-n]) <- hists.(ctoint s.[j-n]) - 1;\n\tscan (j+1) (ac+inc)\n )\n in\n\n Printf.printf \"%d\\n\" (scan n 0)\n"}], "src_uid": "9ed2a081b65df66629fcf0d4fc0bb02c"} {"source_code": "let read_one () = Scanf.scanf \" %d\" (fun x -> x)\nlet read_two () = Scanf.scanf \" %d %d\" (fun x y -> (x,y)) \nlet read_three () = Scanf.scanf \"%d %d %d\" (fun x y z -> (x,y,z))\n\nlet read_many n =\n let rec helper i acc =\n if i >= n then List.rev acc\n else Scanf.scanf \" %d\" (fun n -> helper (i+1) (n::acc)) in\n helper 0 []\n\nlet list_iteri f lst = List.fold_left (fun j b -> f j b; j+1) 0 lst\n\nlet even n = n mod 2 = 0\n\nlet rec solve cur tar left l =\n if left <= 0 then [] \n else if cur = tar then \n if even left then\n 1 :: 1 :: ( solve cur tar (left - 2) l)\n else \n 1 :: 2 :: 1 :: (solve cur tar (left - 3) l)\n else if cur > tar then\n let sub = min (cur + 1 - tar) l in\n let new_cur = cur + 1 - sub in\n if new_cur = tar && left = 3 then\n\tlet sub = sub + 1 in\n\t1 :: sub :: 1 :: []\n else\n 1 :: sub :: (solve new_cur tar (left - 2) l)\n else (* cur > tar *)\n let add = min l (tar + 1 - cur) in\n let new_cur = cur + add - 1 in\n if new_cur = tar && left = 3 then\n let add = add - 1 in\n add :: 1 :: 1 :: []\n else if left = 1 then\n let add = tar - cur in\n add :: [] \n else\n add :: 1 :: (solve new_cur tar (left - 2) l)\n\nlet main =\n let (n,d,l) = read_three() in\n let min_d = (n - n / 2) - (n / 2) * l in\n let max_d = (n - n / 2) * l - (n / 2) in\n if min_d > d || max_d < d then \n Printf.printf \"-1\\n\"\n else \n let print j b = \n if j = n - 1 then Printf.printf \"%d\\n\" b\n else Printf.printf \"%d \" b in\n ignore (list_iteri print (solve 0 d n l));\n \n\n", "positive_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\n\nlet rec loop n d l x a = \n if n <= 0 then Printf.printf(\"\\n\")\n else\n if d > x then\n if a = -1 then begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n else let z = min (d-x) (l-1) in\n begin Printf.printf \"%d \" (z+1); loop (n-1) d l (x+z) (a*(-1)) end\n else if d < x then\n if a = 1 then begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n else let z = min (x-d) (l-1) in\n begin Printf.printf \"%d \" (z+1); loop (n-1) d l (x-z) (a*(-1)) end\n else begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n \n\nlet _ = \n let (n,d,l) = read3() in\n if ( (n+1)/2 - (n/2) - (l-1)*(n/2) > d || (n+1)/2 - (n/2) + (l-1)*((n+1)/2) < d )\n then Printf.printf \"-1\\n\"\n else\n loop n d l ( (n+1)/2 - n/2 ) 1;;\n"}], "negative_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\n\nlet rec loop n d l x a = \n if n <= 0 then Printf.printf(\"\\n\")\n else\n if d > x then\n if a = -1 then begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n else let z = min (d-x) (l-1) in\n begin Printf.printf \"%d \" (z+1); loop (n-1) d l (x+z) (a*(-1)) end\n else if d < x then\n if a = 1 then begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n else let z = min (x-d) (l-1) in\n begin Printf.printf \"%d \" (z+1); loop (n-1) d l (x-z) (a*(-1)) end\n else begin Printf.printf \"1 \"; loop (n-1) d l x (a*(-1)) end\n \n\nlet _ = \n let (n,d,l) = read3() in\n Printf.printf \"%d %d %d\\n\" n d l;\n if ( (n+1)/2 - (n/2) - (l-1)*(n/2) > d || (n+1)/2 - (n/2) + (l-1)*((n+1)/2) < d )\n then Printf.printf \"-1\\n\"\n else\n loop n d l ( (n+1)/2 - n/2 ) 1;;\n"}], "src_uid": "a20d59a0db07cbb5692f01d28e41a3a1"} {"source_code": "let main () =\n let n = read_int () in\n let arr = Array.init n (fun _ -> Scanf.sscanf (read_line ()) \"%d %d\" (fun a b -> b, a)) in\n Array.sort (fun a b -> compare b a) arr;\n let list = Array.to_list arr in\n let rec loop r acc = function\n | [] -> acc\n | (a, b) :: tl -> if r = 0 then acc else loop (r - 1 + a) (b + acc) tl\n in\n let ans = loop 1 0 list in\n Printf.printf \"%d\\n\" ans\n;;\nmain ()\n", "positive_code": [{"source_code": "let rec input_cards n lst =\n if n = 0 then lst\n else input_cards (n-1) ((Scanf.scanf \" %d %d\" (fun x y -> (x, y))) :: lst)\n\nlet sort_cards cards =\n let compare_cards a b =\n if a = b then 0\n else if (snd a) > (snd b) then -1\n else if (snd a) = (snd b) && (fst a) > (fst b) then -1\n else 1\n in\n List.sort compare_cards cards\n\nlet rec solve cards opportunity points =\n match cards with\n | [] -> points\n | h :: t ->\n if opportunity = 0 then points\n else solve t (opportunity + (snd h) - 1) (points + (fst h))\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let cards = input_cards n [] in\n Printf.printf \"%d\\n\" (solve (sort_cards cards) 1 0)\n \n"}], "negative_code": [], "src_uid": "4abdd16670a796be3a0bff63b9798fed"} {"source_code": "\nlet () =\n let (@@) f x = f x in\n let (|>) x f = f x in\n let open List in\n let open Int64 in\n let split_by_spaces = Str.split @@ Str.regexp_string \" \" in\n read_line () |> split_by_spaces |> map int_of_string |> tl |> hd |> fun m ->\n read_line () |> split_by_spaces |> map of_string |> Array.of_list |> fun arr ->\n let inc = ref 0L in\n for k = 1 to m do\n read_line () |> split_by_spaces |> List.map int_of_string |> function\n | [1; v; x] -> arr.(v - 1) <- sub (of_int x) !inc\n | [2; y] -> inc := add !inc @@ of_int y\n | [3; q] -> print_endline @@ to_string @@ add arr.(q - 1) !inc\n | _ -> failwith @@ \"Error on line \" ^ string_of_int @@ k + 2\n done\n\n\n", "positive_code": [{"source_code": "\nlet () =\n let (@@) f x = f x in\n let (|>) x f = f x in\n let split_by_spaces = Str.split @@ Str.regexp_string \" \" in\n let n, m = match read_line () |> split_by_spaces |> List.map int_of_string with\n | [n; m] -> n, m\n | _ -> failwith \"Error on line 1\"\n in\n let arr = read_line () |> split_by_spaces |> List.map Int64.of_string |> Array.of_list in\n let inc = ref 0L in\n assert (Array.length arr = n);\n for k = 1 to m do\n match read_line () |> split_by_spaces |> List.map int_of_string with\n | [1; v; x] -> arr.(v - 1) <- Int64.(sub (of_int x) !inc)\n | [2; y] -> inc := Int64.(add !inc @@ of_int y)\n | [3; q] -> print_endline @@ Int64.(to_string @@ add arr.(q - 1) !inc)\n | _ -> failwith @@ \"Error on line \" ^ string_of_int @@ k + 2;\n done\n\n\n"}, {"source_code": "\nlet (+) = Int64.add\nlet (-) = Int64.sub\n\ntype state = {\n arr : int64 array;\n mutable inc : int64\n}\n\nlet assign state v x =\n state.arr.(v) <- (x - state.inc)\n\nlet increment state y =\n state.inc <- state.inc + y\n\nlet print state q =\n print_endline (Int64.to_string (state.arr.(q) + state.inc))\n\nlet () =\n let open Pervasives in\n let split_by_spaces = Str.split (Str.regexp_string \" \") in\n let n, m = match split_by_spaces (read_line ()) with\n | [n; m] -> int_of_string n, int_of_string m\n | _ -> failwith \"Error on line 1\"\n in\n let int_list_of_string_list = List.map int_of_string in\n let int64_list_of_string_list = List.map Int64.of_string in\n let state =\n { arr = Array.of_list (int64_list_of_string_list (split_by_spaces (read_line ())));\n inc = 0L }\n in\n assert (Array.length state.arr = n);\n let k = ref 0 in\n try while true do\n (match int_list_of_string_list (split_by_spaces (read_line ())) with\n | [1; v; x] -> assign state (v - 1) (Int64.of_int x)\n | [2; y] -> increment state (Int64.of_int y)\n | [3; q] -> print state (q - 1)\n | _ -> failwith (\"Error on line \" ^ (string_of_int (!k + 2))));\n k := !k + 1\n done with End_of_file -> assert (!k = m)\n\n\n"}, {"source_code": "let read_int _ = Scanf.scanf \" %d\" (fun x -> x)\nlet read_string _ = Scanf.scanf \" %s\" (fun x -> x)\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 \n let implode l =\n let result = String.create (List.length l) in\n let rec imp i = function\n | [] -> result\n | c :: l -> result.[i] <- c; imp (i + 1) l in\n imp 0 l;;\n \nlet (--) i j = \n let rec aux n acc =\n if n < i then acc else aux (n-1) (n :: acc)\n in aux j []\n \nlet () = \n let n = read_int () in\n let m = read_int () in\n \n let bit = Array.init (n + 1) (fun _ -> 0L) in\n \n let update x v = \n let x = ref x in\n while !x <= n do\n bit.(!x) <- Int64.add bit.(!x) v;\n x := !x + (!x land (~- !x));\n done\n in\n \n let sum x =\n let x = ref x in\n let ret = ref 0L in\n while !x > 0 do\n ret := Int64.add !ret bit.(!x);\n x := !x - (!x land (~- !x));\n done;\n !ret\n in\n \n let arr = Array.init n (fun _ -> Int64.of_int (read_int ())) in\n \n for i = 0 to n-1 do\n update (i+1) arr.(i);\n update (i+2) (Int64.neg arr.(i));\n done;\n \n for i = 1 to m do\n let t = read_int () in\n match t with \n | 1 -> \n let x = read_int () in\n let v = (Int64.of_int (read_int ())) in\n let curr = sum x in\n update x (Int64.neg curr);\n update (x+1) curr;\n update x v;\n update (x+1) (Int64.neg v);\n | 2 ->\n let y = Int64.of_int (read_int ()) in\n update 1 y;\n | 3 ->\n let q = read_int () in\n let curr = sum q in\n Printf.printf \"%Ld\\n\" curr; \n | _ -> assert false\n done;\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.scanf \" %d\" (fun x -> x)\nlet read_string _ = Scanf.scanf \" %s\" (fun x -> x)\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 \n let implode l =\n let result = String.create (List.length l) in\n let rec imp i = function\n | [] -> result\n | c :: l -> result.[i] <- c; imp (i + 1) l in\n imp 0 l;;\n \nlet (--) i j = \n let rec aux n acc =\n if n < i then acc else aux (n-1) (n :: acc)\n in aux j []\n \nlet () = \n let n = read_int () in\n let m = read_int () in\n \n let bit = Array.init (n + 1) (fun _ -> 0) in\n \n let update x v = \n let x = ref x in\n while !x <= n do\n bit.(!x) <- bit.(!x) + v;\n x := !x + (!x land (~- !x));\n done\n in\n \n let sum x =\n let x = ref x in\n let ret = ref 0 in\n while !x > 0 do\n ret := !ret + bit.(!x);\n x := !x - (!x land (~- !x));\n done;\n !ret\n in\n \n let arr = Array.init n read_int in\n \n for i = 0 to n-1 do\n update (i+1) arr.(i);\n update (i+2) (-arr.(i));\n done;\n \n for i = 1 to m do\n let t = read_int () in\n match t with \n | 1 -> \n let x = read_int () in\n let v = read_int () in\n let curr = sum x in\n update x (-curr);\n update (x+1) curr;\n update x v;\n update (x+1) (-v);\n | 2 ->\n let y = read_int () in\n update 1 y;\n | 3 ->\n let q = read_int () in\n let curr = sum q in\n Printf.printf \"%d\\n\" curr; \n | _ -> assert false\n done;\n"}, {"source_code": "\ntype state = {\n arr : int array;\n mutable inc : int\n}\n\nlet assign state v x =\n state.arr.(v) <- (x - state.inc)\n\nlet increment state y =\n state.inc <- state.inc + y\n\nlet print state q =\n print_endline (string_of_int (state.arr.(q) + state.inc))\n\nlet () =\n let split_by_spaces = Str.split (Str.regexp_string \" \") in\n let n, m = match split_by_spaces (read_line ()) with\n | [n; m] -> int_of_string n, int_of_string m\n | _ -> failwith \"Error on line 1\"\n in\n let int_list_of_string_list = List.map int_of_string in\n let state =\n { arr = Array.of_list (int_list_of_string_list (split_by_spaces (read_line ())));\n inc = 0 }\n in\n assert (Array.length state.arr = n);\n let k = ref 0 in\n try while true do\n (match int_list_of_string_list (split_by_spaces (read_line ())) with\n | [1; v; x] -> assign state (v - 1) x\n | [2; y] -> increment state y\n | [3; q] -> print state (q - 1)\n | _ -> failwith (\"Error on line \" ^ (string_of_int (!k + 2))));\n incr k\n done with End_of_file -> assert (!k = m)\n\n\n"}], "src_uid": "48f3ff32a11770f3b168d6e15c0df813"} {"source_code": "let () =\n let t = read_line () |> int_of_string in\n for i = 1 to t do\n let [a; b] =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map String.trim\n |> List.map int_of_string\n in\n let n = abs (b - a) in\n (n + 9) / 10\n |> string_of_int\n |> print_endline\n done\n", "positive_code": [{"source_code": "let read_int () : int =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve (a : int) (b : int) : int =\n ((abs (a - b)) + 9) / 10\n\nlet () =\n let t = read_int () in\n for i = 1 to t do\n let a = read_int () in\n let b = read_int () in\n print_endline ( string_of_int (solve a b))\n done;\n"}], "negative_code": [], "src_uid": "d67a97a3b69d599b03d3fce988980646"} {"source_code": "(* https://codeforces.com/contest/1493/problem/A *)\n\nlet solution m k =\n let nums = Array.make m true in\n nums.(k-1) <- false;\n let rec helper i =\n if i < 0\n then ()\n else if (i+1) > k\n then helper (i-1)\n else if (i+1) = k\n then helper (i-1)\n else if (i+1) < k && nums.(i)\n then begin\n let index = k - (i+1) - 1 in\n if index <> i\n then nums.(k-(i+1)-1) <- false;\n helper (i-1) \n end in\n helper (m-1);\n Array.mapi (fun i e -> if e then Some (i+1) else None) nums\n |> Array.to_list\n |> List.filter (fun e -> e <> None)\n |> List.map (fun (Some e) -> e)\n\nlet input_case () =\n read_line () |> Str.split (Str.regexp \" \") |> List.map int_of_string\n\nlet print_sol arr =\n List.iter (fun e -> Printf.printf \"%d \" e) arr\n\nlet () =\n let cases = read_int () in\n for i = 1 to cases do\n let m::k::_ = input_case () in\n let sol = solution m k in\n Printf.printf \"%d\\n\" (List.length sol);\n print_sol sol;\n print_newline ()\n done\n", "positive_code": [{"source_code": "let l = ref []\n\nlet () = \n for i=1 to (read_int ()) do\n l := (Scanf.scanf \" %d %d\" (fun x y -> x,y))::!l\n done\n\nlet rec getListfromArray a n k i =\n if i > n\n then []\n else if i > k \n then \n (i)::(getListfromArray a n k (i+1))\n else if i < k-1\n then if a.(i) = 1 then (i+1)::(getListfromArray a n k (i+1)) else getListfromArray a n k (i+1)\n else getListfromArray a n k (i+1)\n\nlet rec printList l = \n match l with \n | h::t -> (Printf.printf \"%d \" h; printList t)\n | _ -> print_newline ()\n\nlet findList (n,k) = \n let a = Array.make (k-1) 0 in\n let () = for i=1 to (k-1) do if a.(i-1) <> 1 then a.(k-i-1) <- 1 done in\n let l = getListfromArray a n k 0 in\n let () = print_endline (string_of_int (List.length l)) in\n printList l\n\nlet rec testCases l =\n match l with\n | h::t -> (testCases t; findList h)\n | _ -> ()\n\nlet rec testAll l = \n match l with\n | h::t -> (testAll t; findList h)\n | _ -> ()\n\nlet () = testAll !l"}], "negative_code": [], "src_uid": "d08e39db62215d7817113aaa384e3f59"} {"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_str () = Scanf.bscanf chan \" %s \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet toint c = (int_of_char c) - (int_of_char 'A')\nlet tochar i = char_of_int ((int_of_char 'A') + i)\n\nlet () = \n let s = read_str() in\n let t = read_str() in\n let n = String.length s in\n let hs = Array.make 26 0 in\n let h = Array.make 26 0 in\n \n let () = \n for i=0 to n-1 do\n let (c,d) = (toint s.[i], toint t.[i]) in\n\ths.(c) <- hs.(c) + 1;\n\th.(c) <- h.(c) + 1;\n\th.(d) <- h.(d) - 1\n done\n in\n\n let tot = sum 0 25 (fun i-> abs h.(i)) in\n let () = print_string (Printf.sprintf \"%d\\n\" (tot/2)) in\n\n let () =\n for i=0 to n-1 do\n let c = toint s.[i] in\n\tif h.(c) <= 0 then (\n\t print_string (Printf.sprintf \"%c\" (tochar c));\n\t) else (\n\t let rec loop j = if h.(j) < 0 then j else loop (j+1) in\n\t let d = loop 0 in\n\t if d > c && hs.(c) > h.(c) then (\n\t print_string (Printf.sprintf \"%c\" (tochar c));\n\t ) else (\n\t h.(d) <- h.(d) + 1;\n\t h.(c) <- h.(c) - 1;\n\t print_string (Printf.sprintf \"%c\" (tochar d))\n\t )\n\t);\n\ths.(c) <- hs.(c) - 1\n done\n in\n print_string \"\\n\"\n", "positive_code": [{"source_code": "let input = open_in \"input.txt\" ;;\nlet output = open_out \"output.txt\" ;;\n\nlet read_string () = Scanf.fscanf input \" %s \" (fun x -> x) ;;\n\nlet s = read_string () and t = read_string () ;;\n\nlet index c = int_of_char c - int_of_char 'A' ;;\nlet letter i = char_of_int (i + int_of_char 'A') ;;\n\nlet freqs = Array.make 26 0 and freqt = Array.make 26 0 ;;\nfor i = 0 to String.length s - 1 do\n freqs.(index s.[i]) <- freqs.(index s.[i]) + 1 ;\n freqt.(index t.[i]) <- freqt.(index t.[i]) + 1\ndone ;;\n \nlet (z, result) = \n let rec next_available i =\n if i > 25 then -1\n else if freqt.(i) > freqs.(i) then i \n else next_available (i + 1)\n and r = String.create (String.length s) \n in let rec loop i a cur =\n if i = String.length s then (a, r)\n else let c = index s.[i] in\n (* Need to replace this character *)\n if freqt.(c) = 0 || freqs.(c) > freqt.(c) && cur < c then \n (\n r.[i] <- letter cur ;\n freqt.(cur) <- freqt.(cur) - 1 ;\n freqs.(c) <- freqs.(c) - 1;\n loop (i + 1) (a + 1) (next_available cur)\n )\n (* Need to save this character *)\n else\n (\n r.[i] <- letter c ;\n freqt.(c) <- freqt.(c) - 1 ;\n freqs.(c) <- freqs.(c) - 1;\n loop (i + 1) a cur\n )\n in loop 0 0 (next_available 0) ;;\n \nPrintf.fprintf output \"%d\\n%s\\n\" z result ;;"}], "negative_code": [{"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_str () = Scanf.bscanf chan \" %s \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet toint c = (int_of_char c) - (int_of_char 'A')\nlet tochar i = char_of_int ((int_of_char 'A') + i)\n\nlet () = \n let s = read_str() in\n let t = read_str() in\n let n = String.length s in\n let hs = Array.make n 0 in\n let h = Array.make n 0 in\n \n let () = \n for i=0 to n-1 do\n let (c,d) = (toint s.[i], toint t.[i]) in\n\ths.(c) <- hs.(c) + 1;\n\th.(c) <- h.(c) + 1;\n\th.(d) <- h.(d) - 1\n done\n in\n\n let () =\n for i=0 to n-1 do\n let c = toint s.[i] in\n\tif h.(c) <= 0 then (\n\t print_string (Printf.sprintf \"%c\" (tochar c));\n\t) else (\n\t let rec loop j = if h.(j) < 0 then j else loop (j+1) in\n\t let d = loop 0 in\n\t if d > c && hs.(c) > h.(c) then (\n\t print_string (Printf.sprintf \"%c\" (tochar c));\n\t ) else (\n\t h.(d) <- h.(d) + 1;\n\t h.(c) <- h.(c) - 1;\n\t print_string (Printf.sprintf \"%c\" (tochar d))\n\t )\n\t);\n\ths.(c) <- hs.(c) - 1\n done\n in\n print_string \"\\n\"\n"}], "src_uid": "b9766f25c8ae179c30521770422ce18b"} {"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 m = read_int() in\n let rowempty = Array.make n 1 in\n let colempty = Array.make n 1 in\n for i=1 to m do\n let r = read_int() in\n let c = read_int() in\n rowempty.(r-1) <- 0;\n colempty.(c-1) <- 0;\n done;\n\n let r = sum 0 (n-1) (fun i -> rowempty.(i)) in\n let c = sum 0 (n-1) (fun i -> colempty.(i)) in\n\n let dp = Array.make_matrix (r+1) (c+1) None in\n \n let rec calc r c = \n if r<0 || c<0 then 0.0 else\n match dp.(r).(c) with Some x -> x | None ->\n\tlet answer = \n\t if r=0 && c=0 then 0.0 else (\n\t let cells = float (n * (r+c) - r*c) in\n\t let area = float (n*n) in\n\t let p = cells /. area in\n\t (* prob that we hit a useful one. 1/p is E(time till we hit) *)\n\t \n\t (* now, given that we hit a useful one what is the probability of the\n\t three different types .... *)\n\t let pboth = (float (r*c)) /. cells in\n\t let pcol = ((float (c*(n-r))) /. cells) in\n\t let prow = ((float (r*(n-c))) /. cells) in\n\t \n\t (1.0 /. p) +. \n\t pboth *. (calc (r-1) (c-1)) +.\n\t pcol *. (calc r (c-1)) +.\n\t prow *. (calc (r-1) c)\n\t )\n\tin\n\tdp.(r).(c) <- Some answer;\n\tanswer\n in\n\n printf \"%15.10f\\n\" (calc r c)\n", "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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int()in\n let m = read_int() in\n let rowempty = Array.make n 1 in\n let colempty = Array.make n 1 in\n for i=1 to m do\n let r = read_int() in\n let c = read_int() in\n rowempty.(r-1) <- 0;\n colempty.(c-1) <- 0;\n done;\n\n let r = sum 0 (n-1) (fun i -> rowempty.(i)) in\n let c = sum 0 (n-1) (fun i -> colempty.(i)) in\n\n let dp = Array.make_matrix (r+1) (c+1) None in\n \n let rec calc r c = \n if r<0 || c<0 then 0.0 else\n match dp.(r).(c) with Some x -> x | None ->\n\tlet answer = \n\t if r=0 && c=0 then 0.0 else (\n\t let cells = float (n * (r+c) - r*c) in\n\t let area = float (n*n) in\n\t let p = cells /. area in\n\t (* prob that we hit a useful one. 1/p is E(time till we hit) *)\n\t \n\t (* now, given that we hit a useful one what is the probability of the\n\t three different types .... *)\n\t let pboth = (float (r*c)) /. cells in\n\t let pcol = ((float (c*(n-r))) /. cells) in\n\t let prow = ((float (r*(n-c))) /. cells) in\n\t \n\t (1.0 /. p) +. \n\t pboth *. (calc (r-1) (c-1)) +.\n\t pcol *. (calc r (c-1)) +.\n\t prow *. (calc (r-1) c)\n\t )\n\tin\n\tdp.(r).(c) <- Some answer;\n\tanswer\n in\n\n printf \"%15.10f\\n\" (calc r c)\n"}], "negative_code": [], "src_uid": "8bad8086f69da165d8de4db93fe6931f"} {"source_code": "let solve (a:int array) = \n\tlet n = Array.length a in\n\tlet rec find l l_sum r r_sum = \n\t\tif l>r then l,(n-l)\n\t\telse if l_sum<=r_sum then find (l+1) (l_sum + a.(l)) r r_sum\n\t\telse find l l_sum (r-1) (r_sum+a.(r))\n\tin\n\tlet l, r = find 0 0 (n-1) 0 in\n\tPrintf.printf \"%d %d\\n\" (l) (n-l);;\n\n\nlet trim (line: string) =\n\t(* trim leading white space *)\n\tlet line = Str.replace_first (Str.regexp \"^[ \\t\\n\\r]+\") \"\" line in\n\t(* trim trailing white space *)\n\tlet line = Str.replace_first (Str.regexp \"[ \\t\\n\\r]+$\") \"\" line in\n\tline\n;;\n\n\nlet ints_of_string (line: string) = \n\tArray.of_list (List.map int_of_string (Str.split (Str.regexp \" \") (trim line)))\n;;\n\n\nlet _ = \n\tlet _ = int_of_string (read_line()) in\n\tlet a = ints_of_string (read_line()) in\n\tsolve a\n\n\t\n", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet ubound a n =\n let rec go l h =\n if l = h then\n l\n else\n let m = (l+h)/2 in\n if (if m > 0 then a.(m-1) else 0) <= a.(n-1)-a.(m) then\n go (m+1) h\n else\n go l m\n in go 0 n\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n for i = 1 to n-1 do\n a.(i) <- a.(i)+a.(i-1)\n done;\n let x = ubound a n in\n Printf.printf \"%d %d\\n\" x (n-x)\n"}], "negative_code": [{"source_code": "let solve (a:int array) = \n let n = Array.length a in\n let s = Array.fold_left (fun s x -> s + x) 0 a in\n let half = s / 2 in \n let rec find idx s = \n if s+a.(idx)>half then idx\n else find (idx+1) (s + a.(idx))\n in\n let l = find 0 0 in\n print_int l;\n print_string \" \";\n print_int (n-l);\n print_newline ()\n ;;\n\n\nlet trim (line: string) =\n (* trim leading white space *)\n let line = Str.replace_first (Str.regexp \"^[ \\t\\n\\r]+\") \"\" line in\n (* trim trailing white space *)\n let line = Str.replace_first (Str.regexp \"[ \\t\\n\\r]+$\") \"\" line in\n line\n;;\n\n\nlet ints_of_string (line: string) = \n Array.of_list (List.map int_of_string (Str.split (Str.regexp \" \") (trim line)))\n;;\n\n\nlet _ = \n let n = int_of_string (read_line()) in\n let a = ints_of_string (read_line()) in\n solve a\n\n \n"}, {"source_code": "let solve (a:int array) = \n\tlet n = Array.length a in\n\tlet s = Array.fold_left (fun s x -> s + x) 0 a in\n\tlet half = (1+ s) / 2 in \n\tlet rec find idx s = \n\t\tif (idx >= n || s+a.(idx)>half) then idx\n\t\telse find (idx+1) (s + a.(idx))\n\tin\n\tlet l = find 1 (a.(0)) in\n\tPrintf.printf \"%d %d\\n\" l (n-l);;\n\t(*\n\tprint_int l;\n\tprint_string \" \";\n\tprint_int (n-l);\n\tprint_newline ()\n\t;;\n*)\n\nlet trim (line: string) =\n\t(* trim leading white space *)\n\tlet line = Str.replace_first (Str.regexp \"^[ \\t\\n\\r]+\") \"\" line in\n\t(* trim trailing white space *)\n\tlet line = Str.replace_first (Str.regexp \"[ \\t\\n\\r]+$\") \"\" line in\n\tline\n;;\n\n\nlet ints_of_string (line: string) = \n\tArray.of_list (List.map int_of_string (Str.split (Str.regexp \" \") (trim line)))\n;;\n\n\nlet _ = \n\tlet n = int_of_string (read_line()) in\n\tlet a = ints_of_string (read_line()) in\n\tsolve a\n\n\t\n"}, {"source_code": "let solve (a:int array) = \n let n = Array.length a in\n let s = Array.fold_left (fun s x -> s + x) 0 a in\n let half = (1+ s) / 2 in \n let rec find idx s = \n if (idx >= n || s+a.(idx)>half) then idx\n else find (idx+1) (s + a.(idx))\n in\n let l = find 0 0 in\n Printf.printf \"%d %d\\n\" l (n-l);;\n (*\n print_int l;\n print_string \" \";\n print_int (n-l);\n print_newline ()\n ;;\n*)\n\nlet trim (line: string) =\n (* trim leading white space *)\n let line = Str.replace_first (Str.regexp \"^[ \\t\\n\\r]+\") \"\" line in\n (* trim trailing white space *)\n let line = Str.replace_first (Str.regexp \"[ \\t\\n\\r]+$\") \"\" line in\n line\n;;\n\n\nlet ints_of_string (line: string) = \n Array.of_list (List.map int_of_string (Str.split (Str.regexp \" \") (trim line)))\n;;\n\n\nlet _ = \n let n = int_of_string (read_line()) in\n let a = ints_of_string (read_line()) in\n solve a\n\n \n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet ubound a n =\n let rec go l h =\n if l = h then\n l\n else\n let m = (l+h)/2 in\n if a.(m) <= a.(n-1)-a.(m) then\n go (m+1) h\n else\n go l m\n in go 0 n\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n for i = 1 to n-1 do\n a.(i) <- a.(i)+a.(i-1)\n done;\n let x = ubound a n in\n Printf.printf \"%d %d\\n\" x (n-x)\n"}], "src_uid": "8f0172f742b058f5905c0a02d79000dc"} {"source_code": "\nexception No;;\nlet check_one_line l= \n List.fold_left (fun a b -> \n if a !=b \n then raise No \n else a) \n (List.hd l) \n l;;\n\nlet check_two_line l = \n List.fold_left (fun a b -> \n check_one_line b;\n if (List.hd a)==(List.hd b) \n then raise No else b) \n [10;10] \n l;;\n\nlet rec get_line m = \n if m==0 then [] \n else (Scanf.scanf \"%c\" (fun c -> Char.code c - Char.code '0')):: (get_line (m-1));;\n\nlet rec get_line_wrap m = \n let \n a = get_line m;\n in\n Scanf.scanf \"%c\" (fun c -> c);\n a;;\n\nlet rec get_lines n m = \n if n<=0 then [] \n else get_line_wrap m :: get_lines (n-1) m;;\n\nlet () = \n let l = Scanf.scanf \"%d %d\\n\" get_lines in \n try \n check_two_line l;Printf.printf \"Yes\\n\" \n with No -> Printf.printf \"No\\n\";;\n", "positive_code": [{"source_code": "\nexception No;;\nlet check_one_line l= \n List.fold_left (fun a b -> \n if a !=b \n then raise No \n else a) \n (List.hd l) \n l;;\n\nlet check_two_line l = \n List.fold_left (fun a b -> \n check_one_line b;\n if (List.hd a)==(List.hd b) \n then raise No else b) \n [10;10] \n l;;\n\n\n\nlet rec get_line_wrap m = \n let rec get_line m r = \n if m==0 then r \n else get_line (m-1) ((Scanf.scanf \"%c\" (fun c -> Char.code c - Char.code '0'))::r)\n in\n let \n a = get_line m [];\n in\n Scanf.scanf \"%c\" (fun c -> c);\n a;;\n\nlet get_lines_wrap n m =\n let rec get_lines n m r= \n if n<=0 then r \n else get_lines (n-1) m ((get_line_wrap m) :: r)\n in\n get_lines n m [];;\n\nlet () = \n let l = Scanf.scanf \"%d %d\\n\" get_lines_wrap in \n try \n check_two_line l;Printf.printf \"Yes\\n\" \n with No -> Printf.printf \"No\\n\";;\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet read_str _ = Scanf.bscanf Scanf.Scanning.stdib \" %s\" (fun x -> x)\n\nlet () =\n let n = read_int 0 in\n let m = read_int 0 in\n let a = Array.init n read_str in\n let rec go i j =\n if i = n then\n true\n else if j = m then\n go (i+1) 0\n else if j > 0 && a.(i).[j-1] <> a.(i).[j] then\n false\n else if i > 0 && j = 0 && a.(i-1).[0] = a.(i).[0] then\n false\n else\n go i (j+1)\n in\n print_endline (if go 0 0 then \"YES\" else \"NO\")\n"}], "negative_code": [], "src_uid": "80d3da5aba371f4d572ea928025c5bbd"} {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;; (* primes, ancestors, primlimit *)\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n let rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1)\r\n in\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc\r\n in\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (_primes, _ancs, _primlimit) = sieve in\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\" else \"NO\" in\r\n let () = Printf.fprintf outp \"%s\\n\" answer in\r\n(* let () = Printf.fprintf outp \"Val A: %d; Val B: %d\\n\" a b in\r\n let () = Printf.fprintf outp \"Count A: %d; Count B: %d\\n\" count_a count_b in\r\n *) ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n (* let primlimit = 20 in *)\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n", "positive_code": [{"source_code": "(* 6:26 *)\n\nopen Printf\nopen Scanf\n\nlet rec gcd a b = if a=0 then b else gcd (b mod a) a\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0 \n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let (a,b) = read_pair () in\n let k = read_int () in\n\n let g = gcd a b in\n\n let answer =\n if k = 1 then if a=b then false else g=a || g=b else\n\tlet nfa = List.length (factor a) in\n\tlet nfb = List.length (factor b) in\n\tlet maxmoves = nfa + nfb in\n\tlet minmoves = if a=b then 0 else if g = a || g = b then 1 else 2 in\n\tif k < minmoves then false\n\telse if k > maxmoves then false\n\telse if k = maxmoves then true\n\telse if k = maxmoves-1 then nfa >= 2 || nfb >=2\n\telse true\n in\n if answer then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\n\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n -> let () = f state in repeat f state (n - 1);;\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in incr j\r\n done\r\n end\r\n done\r\n in\r\n (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)\r\n\r\nlet rec fact_folder ancs value acc =\r\n if value = 1 then acc else fact_folder ancs (value / ancs.(value)) (acc + 1);;\r\n\r\nlet rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc;;\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value = helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then a != b && (a mod b = 0 || b mod a = 0)\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\\n\" else \"NO\\n\" in\r\n let () = Printf.fprintf outp \"%s\" answer in\r\n ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\n\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n -> let () = f state in repeat f state (n - 1);;\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in incr j\r\n done\r\n end\r\n done\r\n in\r\n (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)\r\n\r\nlet rec fact_folder ancs value acc =\r\n if value = 1 then acc else fact_folder ancs (value / ancs.(value)) (acc + 1);;\r\n\r\nlet rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc;;\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value = helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\\n\" else \"NO\\n\" in\r\n let () = Printf.fprintf outp \"%s\" answer in\r\n ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\n\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;;\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)\r\n\r\nlet rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1);;\r\n\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc;;\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\\n\" else \"NO\\n\" in\r\n let () = Printf.fprintf outp \"%s\" answer in\r\n ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;;\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n (Array.sub primes 0 !primes_count |> Array.to_list, ancs, n)\r\n\r\nlet rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1);;\r\n\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc;;\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\" else \"NO\" in\r\n let () = Printf.fprintf outp \"%s\\n\" answer in\r\n ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet gc_defaults = Gc.get ();;\r\n\r\nlet () =\r\n Gc.set\r\n { gc_defaults with\r\n minor_heap_size = 1024 * 1024\r\n ; major_heap_increment = 1024 * 1024\r\n };;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;; (* primes, ancestors, primlimit *)\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n let rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1)\r\n in\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc\r\n in\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (_primes, _ancs, _primlimit) = sieve in\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\" else \"NO\" in\r\n let () = Printf.fprintf outp \"%s\\n\" answer in\r\n(* let () = Printf.fprintf outp \"Val A: %d; Val B: %d\\n\" a b in\r\n let () = Printf.fprintf outp \"Count A: %d; Count B: %d\\n\" count_a count_b in\r\n *) ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n (* let primlimit = 20 in *)\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet gc_defaults = Gc.get ();;\r\n\r\nlet () =\r\n Gc.set\r\n { gc_defaults with\r\n minor_heap_size = 1024 * 1024 * 16\r\n ; major_heap_increment = 1024 * 1024 * 32\r\n };;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;; (* primes, ancestors, primlimit *)\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n let rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1)\r\n in\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc\r\n in\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (_primes, _ancs, _primlimit) = sieve in\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let result =\r\n if c = 1 then\r\n if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n count_a + count_b >= c\r\n in\r\n let answer = if result then \"YES\" else \"NO\" in\r\n let () = Printf.fprintf outp \"%s\\n\" answer in\r\n(* let () = Printf.fprintf outp \"Val A: %d; Val B: %d\\n\" a b in\r\n let () = Printf.fprintf outp \"Count A: %d; Count B: %d\\n\" count_a count_b in\r\n *) ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n (* let primlimit = 20 in *)\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;; (* primes, ancestors, primlimit *)\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n let rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1)\r\n in\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc\r\n in\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (_primes, _ancs, _primlimit) = sieve in\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n let result =\r\n if c = 1 then if a != b && (a mod b = 0 || b mod a = 0) then true else false\r\n else count_a + count_b >= c\r\n in\r\n let () =\r\n if result then Printf.fprintf outp \"YES\\n\"\r\n else Printf.fprintf outp \"NO\\n\"\r\n in\r\n(* let () = Printf.fprintf outp \"Val A: %d; Val B: %d\\n\" a b in\r\n let () = Printf.fprintf outp \"Count A: %d; Count B: %d\\n\" count_a count_b in\r\n *) ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n (* let primlimit = 20 in *)\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}], "negative_code": [{"source_code": "module Stdlib = Pervasives\r\nlet std_in = Stdlib.stdin and std_out = Stdlib.stdout;;\r\n(* let std_in = Stdlib.open_in \"input.txt\" and std_out = Stdlib.stdout;; *)\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec repeat f state = function\r\n | 0 -> ()\r\n | n ->\r\n let () = f state in\r\n repeat f state (n - 1);;\r\n\r\ntype sieve = int list * int array * int;; (* primes, ancestors, primlimit *)\r\n\r\nlet create_sieve n =\r\n let primes = Array.make (n + 1) 0 and primes_count = ref 0 and ancs = Array.make (n + 1) 0 in\r\n let () =\r\n for i = 2 to n do\r\n begin\r\n if ancs.(i) = 0 then\r\n let () = ancs.(i) <- i and () = primes.(!primes_count) <- i in\r\n incr primes_count\r\n else ();\r\n let j = ref 0 in\r\n while !j < !primes_count && i * primes.(!j) <= n && primes.(!j) <= ancs.(i) do\r\n let () = ancs.(i * primes.(!j)) <- primes.(!j) in\r\n incr j\r\n done\r\n end\r\n done\r\n in\r\n ( Array.sub primes 0 !primes_count |> Array.to_list , ancs , n )\r\n\r\nlet calc_primes_count ((primes, _, _) as sieve) value =\r\n let rec fact_folder ancs value acc =\r\n if value = 1 then acc\r\n else fact_folder ancs (value / ancs.(value)) (acc + 1)\r\n in\r\n let rec helper ((_, ancs, primlimit) as sieve) primes value acc =\r\n match primes with\r\n | [] -> if value = 1 then acc else acc + 1\r\n | prime::primes_tail as primes ->\r\n if value <= primlimit then fact_folder ancs value acc\r\n else if value mod prime = 0 then helper sieve primes (value / prime) (acc + 1)\r\n else helper sieve primes_tail value acc\r\n in\r\n helper sieve primes value 0\r\n\r\nlet solution (inp, outp, sieve) =\r\n let (_primes, _ancs, _primlimit) = sieve in\r\n let (a, b, c) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let count_a = calc_primes_count sieve a and count_b = calc_primes_count sieve b in\r\n let result =\r\n if c mod 2 = 1 && a = b then false\r\n else\r\n let add_a = if a > 1 then 1 else 0 in\r\n let add_b = if b > 1 then 1 else 0 in\r\n count_a + count_b >= c - add_a - add_b\r\n in\r\n let () =\r\n if result then Printf.fprintf outp \"YES\\n\"\r\n else Printf.fprintf outp \"NO\\n\"\r\n in\r\n(* let () = Printf.fprintf outp \"Val A: %d; Val B: %d\\n\" a b in\r\n let () = Printf.fprintf outp \"Count A: %d; Count B: %d\\n\" count_a count_b in\r\n *) ();;\r\n\r\nlet () =\r\n let inp = std_in and outp = std_out in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n (* let primlimit = 20 in *)\r\n let primlimit = 31623 in\r\n let sieve = create_sieve primlimit in\r\n let state = (inp, outp, sieve) in\r\n repeat solution state tests_count;;\r\n"}, {"source_code": "(* 6:26 *)\n\nopen Printf\nopen Scanf\n\nlet rec gcd a b = if a=0 then b else gcd (b mod a) a\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0 \n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let (a,b) = read_pair () in\n let k = read_int () in\n\n let g = gcd a b in\n\n let answer = \n let nfa = List.length (factor a) in\n let nfb = List.length (factor b) in\n let maxmoves = nfa + nfb in\n let minmoves = if a=b then 0 else if g = a || g = b then 1 else 2 in\n if k < minmoves then false\n else if k > maxmoves then false\n else if k = maxmoves then true\n else if k = maxmoves-1 then nfa >= 2 || nfb >=2\n else true\n in\n if answer then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}], "src_uid": "b58a18119ac8375f9ad21a282292a76c"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 27 27 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref 26 in\n let prevc = ref 0 in\n let cur = ref (c2i s.[0]) in\n let curc = ref 1 in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n(*Printf.printf \"asd %d: %d %d %d %d %d\\n\" c !prev !prevc !cur !curc !res;*)\n\t if c = !prev && not a.(!prev).(!cur) then (\n\t let t = !cur\n\t and tc = !curc in\n\t cur := !prev;\n\t curc := !prevc;\n\t prev := t;\n\t prevc := tc;\n\t incr curc;\n\t ) else if !curc = 0 then (\n\t cur := c;\n\t curc := 1;\n\t ) else if c = !cur then (\n\t incr curc;\n\t ) else (\n\t if not a.(!prev).(!cur) then (\n\t if !prevc < !curc\n\t then res := !res + !prevc\n\t else res := !res + !curc\n\t );\n\t prev := !cur;\n\t prevc := !curc;\n\t cur := c;\n\t curc := 1;\n\t )\n done;\n if not a.(!prev).(!cur) then (\n\tif !prevc < !curc\n\tthen res := !res + !prevc\n\telse res := !res + !curc\n );\n Printf.printf \"%d\\n\" !res;\n", "positive_code": [{"source_code": "let main () =\n let s = read_line () in\n let k = read_int () in\n let forbid = Array.create_matrix 26 26 true in\n for i = 1 to k do\n let c = read_line () in\n let a1 = int_of_char c.[0] - int_of_char 'a' in\n let a2 = int_of_char c.[1] - int_of_char 'a' in\n forbid.(a1).(a2) <- false;\n forbid.(a2).(a1) <- false\n done;\n let rec loop arr i =\n if i < 0 then arr else (\n let arr2 = Array.copy arr in\n let c = int_of_char s.[i] - int_of_char 'a' in\n arr2.(c) <- 1;\n for j = 0 to 25 do\n if arr.(j) >= 0 && forbid.(j).(c) then (\n arr2.(c) <- max arr2.(c) (arr.(j) + 1)\n )\n done;\n loop arr2 (i - 1)\n )\n in\n let arr = loop (Array.create 26 (-1)) (String.length s - 1) in\n let ans = String.length s - Array.fold_left max 0 arr in\n Printf.printf \"%d\\n\" ans\n;;\nmain ()\n"}], "negative_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 26 26 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref (c2i s.[0]) in\n let prevc = ref 1 in\n let cur = ref 0 in\n let curc = ref 0 in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n(*Printf.printf \"asd %d: %d %d %d %d\\n\" c !prev !prevc !cur !curc;*)\n\t if c = !prev then (\n\t let t = !cur\n\t and tc = !curc in\n\t cur := !prev;\n\t curc := !prevc;\n\t prev := t;\n\t prevc := tc;\n\t incr curc;\n\t ) else if !curc = 0 then (\n\t cur := c;\n\t curc := 1;\n\t ) else if c = !cur then (\n\t incr curc;\n\t ) else (\n\t if not a.(!prev).(!cur) then (\n\t if !prevc < !curc\n\t then res := !res + !prevc\n\t else res := !res + !curc\n\t );\n\t prev := !cur;\n\t prevc := !curc;\n\t cur := c;\n\t curc := 1;\n\t )\n done;\n if not a.(!prev).(!cur) then (\n\tif !prevc < !curc\n\tthen res := !res + !prevc\n\telse res := !res + !curc\n );\n Printf.printf \"%d\\n\" !res;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 26 26 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref (c2i s.[0]) in\n let prevc = ref 1 in\n let cur = ref 0 in\n let curc = ref 0 in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n(*Printf.printf \"asd %d: %d %d %d %d\\n\" c !prev !prevc !cur !curc;*)\n\t if c = !prev then (\n\t incr prevc;\n\t ) else if !curc = 0 then (\n\t cur := c;\n\t curc := 1;\n\t ) else if c = !cur then (\n\t incr curc;\n\t ) else (\n\t if not a.(!prev).(!cur) then (\n\t if !prevc < !curc\n\t then res := !res + !prevc\n\t else res := !res + !curc\n\t );\n\t prev := !cur;\n\t prevc := !curc;\n\t cur := c;\n\t curc := 0;\n\t )\n done;\n if not a.(!prev).(!cur) then (\n\tif !prevc < !curc\n\tthen res := !res + !prevc\n\telse res := !res + !curc\n );\n Printf.printf \"%d\\n\" !res;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 26 26 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref (c2i s.[0]) in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n\t if a.(!prev).(c) then (\n\t prev := c\n\t ) else (\n\t incr res\n\t )\n done;\n Printf.printf \"%d\\n\" !res;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 26 26 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref (c2i s.[0]) in\n let prevc = ref 1 in\n let cur = ref 0 in\n let curc = ref 0 in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n(*Printf.printf \"asd %d: %d %d %d %d\\n\" c !prev !prevc !cur !curc;*)\n\t if c = !prev then (\n\t incr prevc;\n\t ) else if !curc = 0 then (\n\t cur := c;\n\t curc := 1;\n\t ) else if c = !cur then (\n\t incr curc;\n\t ) else (\n\t if not a.(!prev).(!cur) then (\n\t if !prevc < !curc\n\t then res := !res + !prevc\n\t else res := !res + !curc\n\t );\n\t prev := !cur;\n\t prevc := !curc;\n\t cur := c;\n\t curc := 1;\n\t )\n done;\n if not a.(!prev).(!cur) then (\n\tif !prevc < !curc\n\tthen res := !res + !prevc\n\telse res := !res + !curc\n );\n Printf.printf \"%d\\n\" !res;\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix 26 26 true in\n let res = ref 0 in\n let c2i c = Char.code c - Char.code 'a' in\n for i = 1 to k do\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\ta.(c2i t.[0]).(c2i t.[1]) <- false;\n\ta.(c2i t.[1]).(c2i t.[0]) <- false;\n done;\n let prev = ref (c2i s.[0]) in\n let prevc = ref 1 in\n let cur = ref 0 in\n let curc = ref 0 in\n for i = 1 to String.length s - 1 do\n\tlet c = c2i s.[i] in\n(*Printf.printf \"asd %d: %d %d %d %d %d\\n\" c !prev !prevc !cur !curc !res;*)\n\t if c = !prev && not a.(!prev).(!cur) then (\n\t let t = !cur\n\t and tc = !curc in\n\t cur := !prev;\n\t curc := !prevc;\n\t prev := t;\n\t prevc := tc;\n\t incr curc;\n\t ) else if !curc = 0 then (\n\t cur := c;\n\t curc := 1;\n\t ) else if c = !cur then (\n\t incr curc;\n\t ) else (\n\t if not a.(!prev).(!cur) then (\n\t if !prevc < !curc\n\t then res := !res + !prevc\n\t else res := !res + !curc\n\t );\n\t prev := !cur;\n\t prevc := !curc;\n\t cur := c;\n\t curc := 1;\n\t )\n done;\n if not a.(!prev).(!cur) then (\n\tif !prevc < !curc\n\tthen res := !res + !prevc\n\telse res := !res + !curc\n );\n Printf.printf \"%d\\n\" !res;\n"}], "src_uid": "da2b3450a3ca05a60ea4de6bab9291e9"} {"source_code": "let read_int () = Scanf.scanf \"%d \" (fun x -> x);;\n\nlet n = read_int ();;\nlet p1 = read_int ();;\nlet p2 = read_int ();;\nlet p3 = read_int ();;\nlet t1 = read_int ();;\nlet t2 = read_int ();;\n\nlet power_of_period x = \n\tif x > t1 + t2 then p1 * t1 + p2 * t2 + p3 * (x - t1 - t2)\n\telse if x > t1 then p1 * t1 + p2 * (x - t1)\n\telse x * p1\n\n\nlet ans = ref 0;;\nlet last = ref (-1);;\n\nfor i = 1 to n do\n\tlet (l, r) = Scanf.scanf \"%d %d \" (fun x y -> (x, y)) in begin\n\t\tans := !ans + power_of_period (l - (if !last = -1 then l else !last)) + (r - l) * p1;\n\t\tlast := r;\n\tend\ndone;;\n\nPrintf.printf \"%d\\n\" !ans;;", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int 0 in\n let p1 = read_int 0 in\n let p2 = read_int 0 in\n let p3 = read_int 0 in\n let t1 = read_int 0 in\n let t2 = read_int 0 in\n let rec go i t s =\n if i >= n then\n s\n else\n let l = read_int 0 in\n let r = read_int 0 in\n let _,s' = if i > 0 then List.fold_left (fun (t,s) (pi,ti) ->\n let d = min ti (l-t) in t+d, s+d*pi\n ) (t,s) [p1,t1; p2,t2; p3,max_int] else t,s in\n go (i+1) r (s'+(r-l)*p1)\n in\n Printf.printf \"%d\\n\" (go 0 0 0)\n"}], "negative_code": [], "src_uid": "7ed9265b56ef6244f95a7a663f7860dd"} {"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let mmod n =\n let r = Int64.rem n mmm in\n if r < 0L\n then r +| mmm\n else r\n in\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 res = ref 1L in\n for i = 0 to n - 1 do\n let c = s.[i] in\n let d =\n\tmatch c with\n\t | '0'..'9' -> Char.code c - Char.code '0'\n\t | 'A'..'Z' -> Char.code c - Char.code 'A' + 10\n\t | 'a'..'z' -> Char.code c - Char.code 'a' + 36\n\t | '-' -> 62\n\t | '_' -> 63\n\t | _ -> assert false\n in\n\tfor i = 0 to 5 do\n\t if d land (1 lsl i) = 0 then (\n\t res := mmod (!res *| 3L)\n\t )\n\tdone;\n done;\n Printf.printf \"%Ld\\n\" !res\n", "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 rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac + (f i))\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\nlet () = \n let s = read_string () in\n let n = String.length s in\n\n let rec bitcount x = if x=0 then 0 else (x land 1) + bitcount (x/2) in\n\n let zeros = sum 0 (n-1) (fun i ->\n let c = s.[i] in\n let numb = \n if '0' <= c && c <= '9' then (int_of_char c) - (int_of_char '0')\n else if 'A' <= c && c <= 'Z' then 10 + (int_of_char c) - (int_of_char 'A')\n else if 'a' <= c && c <= 'z' then 36 + (int_of_char c) - (int_of_char 'a')\n else if c = '-' then 62\n else if c = '_' then 63\n else failwith \"bad input\"\n in\n 6 - (bitcount numb)\n ) 0 in\n\n let m = 1_000_000_007L in\n\n let rec ( ^ ) e p = \n if p=0 then 1L else\n let a = e^(p/2) in\n let a2 = (a**a) %% m in\n if (p land 1)=0 then a2 else (e**a2) %% m\n in\n\n printf \"%Ld\\n\" (3L ^ zeros)\n"}], "negative_code": [], "src_uid": "1b336555c94d5d5198abe5426ff6fa7a"} {"source_code": "let score m' w' x' =\n let m = float m' and w = float w' and x = float x' in\n max (0.3 *. x) ((1. -. m /. 250.) *. x -. 50. *. w)\n\nlet main () =\n let (m1,m2,m3,m4,m5,w1,w2,w3,w4,w5,hs,hu) = Scanf.scanf\n \"%d %d %d %d %d %d %d %d %d %d %d %d\"\n (fun a b c d e f g h i j k l -> (a,b,c,d,e,f,g,h,i,j,k,l)) in\n let sc = score m1 w1 500 +. score m2 w2 1000 +. score m3 w3 1500 +. score m4 w4 2000 +. score m5 w5 2500 +. 100. *. (float hs) -. 50. *. (float hu) in\n Printf.printf \"%d\" (int_of_float sc);;\n\nmain ();;\n", "positive_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read5 () = Scanf.scanf \"%d %d %d %d %d\\n\" ( fun x y z a b-> x, y, z, a, b);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet licz m w x =\n max (75*x) ( (250 - m)*x - 250*50*w );;\n\nlet _ = \n let (a,b,c,d,e) = read5 ()\n and (f,g,h,i,j) = read5 ()\n and (hs, hu) = read2 ()\n in\n let suma = (licz a f 500) + (licz b g 1000) + (licz c h 1500) + (licz d i 2000) + (licz e j 2500) in\n Printf.printf \"%d\\n\" ( suma/250 + (2*hs-hu)*50 ) ;;\n\n\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\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 m = Array.init 5 (fun _ -> read_int()) in\n let w = Array.init 5 (fun _ -> read_int()) in\n let hs = read_int() in\n let hu = read_int() in\n\n let x = [|500; 1000; 1500; 2000; 2500|] in\n\n let score i =\n max ((3*x.(i)) / 10) ((x.(i) / 250) * (250-m.(i)) - 50*w.(i))\n in\n\n let total_score = (sum 0 4 score) + 100*hs - 50*hu in\n\n printf \"%d\\n\" total_score\n"}], "negative_code": [], "src_uid": "636a30a2b0038ee1731325a5fc2df73a"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and k=read_int();;\nlet tab=Array.make (k+1) false;;\nlet temp=Array.make (k+1) 0;;\nlet block=Array.make (n+1) 0;;\nlet mat=Array.make_matrix (n+1) (m+1) 0;;\n\nfor i=1 to n do\n for j=1 to m do\n mat.(i).(j)<-read_int()\n done\ndone;;\n\nlet init vec i j=\nfor p=i to j do\n vec.(p)<-0\ndone;;\n\nfor j=1 to m do\n init temp 1 k;\n for i=1 to n do\n if (block.(i)=0)&&(mat.(i).(j)<>0) then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1\n done;\n for i=1 to n do\n if (block.(i)=0)&&((temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)))&&(mat.(i).(j)<>0) then (block.(i)<-j;tab.(mat.(i).(j))<-true)\n done\ndone;;\n\nfor i=1 to n do\n print_int block.(i);\n if i<>n then print_newline()\ndone;;", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix n m 0 in\n let res = Array.make n 0 in\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tlet k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t a.(i).(j) <- k\n done\n done;\n let b = Array.make k false in\n for j = 0 to m - 1 do\n\tlet c = Array.make k 0 in\n\t for i = 0 to n - 1 do\n\t if res.(i) = 0 && a.(i).(j) <> 0 then (\n\t c.(a.(i).(j) - 1) <- c.(a.(i).(j) - 1) + 1\n\t )\n\t done;\n\t for i = 0 to n - 1 do\n\t if res.(i) = 0 && a.(i).(j) <> 0 &&\n\t (c.(a.(i).(j) - 1) > 1 || b.(a.(i).(j) - 1))\n\t then (\n\t res.(i) <- j + 1;\n\t b.(a.(i).(j) - 1) <- true;\n\t )\n\t done;\n done;\n for i = 0 to n - 1 do\n\tPrintf.printf \"%d\\n\" res.(i);\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix n m 0 in\n let res = Array.make n 0 in\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tlet k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t a.(i).(j) <- k\n done\n done;\n let b = Array.make k false in\n for j = 0 to m - 1 do\n\tlet c = Array.make k 0 in\n\t for i = 0 to n - 1 do\n\t if res.(i) = 0 && a.(i).(j) <> 0 then (\n\t c.(a.(i).(j) - 1) <- c.(a.(i).(j) - 1) + 1\n\t )\n\t done;\n\t for i = 0 to n - 1 do\n\t if res.(i) = 0 && a.(i).(j) <> 0 &&\n\t (c.(a.(i).(j) - 1) > 1 || b.(a.(i).(j) - 1))\n\t then (\n\t res.(i) <- j + 1;\n\t b.(a.(i).(j) - 1) <- true;\n\t )\n\t done;\n done;\n for i = 0 to n - 1 do\n\tPrintf.printf \"%d\\n\" res.(i);\n done\n"}], "negative_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and k=read_int();;\nlet tab=Array.make (k+1) false;;\nlet temp=Array.make (k+1) 0;;\nlet block=Array.make (n+1) 0;;\nlet mat=Array.make_matrix (n+1) (m+1) 0;;\n\nfor i=1 to n do\n for j=1 to m do\n mat.(i).(j)<-read_int()\n done\ndone;;\n\nlet init vec i j=\nfor p=i to j do\n vec.(p)<-0\ndone;;\n\nfor j=1 to m do\n init temp 1 k;\n for i=1 to n do\n if (block.(i)=0)&&(mat.(i).(j)<>0) then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1\n done;\n for i=1 to n do\n if ((block.(i)=0)&&(temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)))&&(mat.(i).(j)<>0) then (block.(i)<-j;tab.(mat.(i).(j))<-true)\n done\ndone;;\n\nfor i=1 to n do\n print_int block.(i);\n if i<>n then print_newline()\ndone;;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int() and k=read_int();;\nlet tab=Array.make (k+1) false;;\nlet temp=Array.make (k+1) 0;;\nlet block=Array.make (n+1) 0;;\nlet mat=Array.make_matrix (n+1) (m+1) 0;;\n\nfor i=1 to n do\n for j=1 to m do\n mat.(i).(j)<-read_int()\n done\ndone;;\n\nlet init vec i j=\nfor p=i to j do\n vec.(p)<-0\ndone;;\n\nfor j=1 to m do\n init temp 1 k;\n for i=1 to n do\n if block.(i)=0 then temp.(mat.(i).(j))<-temp.(mat.(i).(j))+1\n done;\n for i=1 to n do\n if (block.(i)=0)&&(temp.(mat.(i).(j))>1)||tab.(mat.(i).(j)) then (block.(i)<-j;tab.(mat.(i).(j))<-true)\n done\ndone;;\n\nfor i=1 to n do\n print_int block.(i);\n if i<>n then print_newline()\ndone;;"}], "src_uid": "6422a70e686c34b4b9b6b5797712998e"} {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read volume in office, volume in hall and confidence *)\n let read i = Scanf.scanf \"%Ld %Ld %Ld\\n\" (fun v d p -> (i + 1, v, d, p)) in\n (* build array of children *)\n let c = Array.to_list (Array.init n read) in\n\n let (+) = Int64.add\n and (-) = Int64.sub in\n\n let rec dentist l acc = match l with\n | [] -> acc\n | (i, v, _, _) :: rest ->\n (* calculate the new line by removing the office volume from elements\n * and summing the line volume as well *)\n let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->\n (* prevent underflow of the volume from the office *)\n let ov = max ov 0L in\n (* calculate new confidence level *)\n let p' = p - ov - lv in\n\n if p' < 0L\n (* this child leaves the queue, so add their line volume to lv\n * NB: prevent overflow here, since the max confidence is only 10^6 *)\n then (ov - 1L, lv + d, acc)\n (* otherwise, this child remains in the queue with a new confidence *)\n else (ov - 1L, lv, ((i, v, d, p') :: acc))) (v, 0L, []) rest in\n dentist (List.rev line) (i :: acc)\n in\n let res = List.rev (dentist c []) in\n Printf.printf \"%d\\n%s\\n\" (List.length res) (String.concat \" \" (List.map string_of_int res)))\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read volume in office, volume in hall and confidence *)\n let read i = Scanf.scanf \"%Ld %Ld %Ld\\n\" (fun v d p -> (i + 1, v, d, p)) in\n (* build array of children *)\n let c = Array.to_list (Array.init n read) in\n\n let (+) = Int64.add\n and (-) = Int64.sub in\n\n let rec dentist l acc = match l with\n | [] -> acc\n | (i, v, _, _) :: rest ->\n (* calculate the new line by removing the office volume from elements\n * and summing the line volume as well *)\n let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->\n (* prevent underflow of the volume from the office *)\n let ov = max ov 0L in\n (* calculate new confidence level *)\n let p' = p - ov - lv in\n\n if p' < 0L\n (* this child leaves the queue, so add their line volume to lv\n * NB: prevent overflow here, since the max confidence is only 10^6 *)\n then (ov - 1L, lv + d, acc)\n (* otherwise, this child remains in the queue with a new confidence *)\n else (ov - 1L, lv, ((i, v, d, p') :: acc))) (v, 0L, []) rest in\n dentist (List.rev line) (i :: acc)\n in\n let res = List.rev (dentist c []) in\n Printf.printf \"%d\\n%s\\n\" (List.length res) (String.concat \" \" (List.map string_of_int res)))\n"}], "negative_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read volume in office, volume in hall and confidence *)\n let read i = Scanf.scanf \"%d %d %d\\n\" (fun v d p -> (i + 1, v, d, p)) in\n (* build array of children *)\n let c = Array.to_list (Array.init n read) in\n\n let rec dentist l acc = match l with\n | [] -> acc\n | (i, v, d, p) :: rest ->\n (* calculate the new line by removing the office volume from elements\n * and summing the line volume as well *)\n let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->\n let ov = max ov 0 in\n let p' = p - ov - lv in\n if p' < 0\n then (ov - 1, min (lv + d) 1000000, acc)\n else (ov - 1, lv, ((i, v, d, p') :: acc))) (v, 0, []) rest in\n dentist (List.rev line) (i :: acc)\n in\n let res = List.rev (dentist c []) in\n Printf.printf \"%d\\n%s\\n\" (List.length res) (String.concat \" \" (List.map string_of_int res)))\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read volume in office, volume in hall and confidence *)\n let read i = Scanf.scanf \"%d %d %d\\n\" (fun v d p -> (i + 1, v, d, p)) in\n (* build array of children *)\n let c = Array.to_list (Array.init n read) in\n\n let rec dentist l acc = match l with\n | [] -> acc\n | (i, v, d, p) :: rest ->\n (* calculate the new line by removing the office volume from elements\n * and summing the line volume as well *)\n let _, _, line = List.fold_left (fun (ov, lv, acc) (i, v, d, p) ->\n let ov = max ov 0 in\n let p' = p - ov - lv in\n if p' < 0\n then (ov - 1, lv + d, acc)\n else (ov - 1, lv, ((i, v, d, p') :: acc))) (v, 0, []) rest in\n dentist (List.rev line) (i :: acc)\n in\n let res = List.rev (dentist c []) in\n Printf.printf \"%d\\n%s\\n\" (List.length res) (String.concat \" \" (List.map string_of_int res)))\n"}], "src_uid": "8cf8590d1f3668b768702c7eb0ee8249"} {"source_code": "open Printf\nopen String\n\nlet n = Scanf.scanf \"%d \" (fun x -> x)\n\nlet rec msplit t i ll=\n if t=\"\" || i>=String.length t then\n List.rev ll\n else\n begin\n try\n let j = String.index_from t i '/' in\n let s1= String.sub t i (j-i) in\n match s1 with\n |\"\" -> msplit t (j+1) ll\n |_ -> msplit t (j+1) (s1::ll)\n with\n Not_found ->\n let s1 = String.sub t i ((String.length t) - i) in\n List.rev (s1::ll)\n end\n\nlet msplit2 s = msplit s 0 []\n\n (*\nlet a = msplit2 \"home/xyzt\" in\n let () =List.iter (printf \"%s \") a in\n print_endline \"\\n====\\n\"\n *)\n\nlet rec process_cd t cwd =\n if t=\"\" then\n cwd\n else\n begin\n match (String.get t 0) with\n | '/' -> (process_cd (String.sub t 1 ((String.length t)-1)) [])\n | _ ->\n begin\n let ll = msplit t 0 [] in\n process_dirs ll cwd\n end\n end\nand process_dirs l c =\n match l with\n | [] -> c\n | hd::lr ->\n begin\n match hd with\n |\".\" -> process_dirs lr c\n |\"..\"-> process_dirs lr (List.tl c)\n | _ -> process_dirs lr (hd::c)\n end\n\nlet rec process_command ls cwd =\n match ls with\n |[] -> ()\n |s::lr ->\n begin\n match s with\n | \"pwd\" ->\n List.iter (fun x -> printf \"/%s\" x) (List.rev cwd); print_endline \"/\";\n process_command lr cwd\n | \"cd\" ->\n let cwd1 = process_cd (List.hd lr) cwd in\n process_command (List.tl lr) cwd1\n end\n\nlet rec readl l =\n let s = Scanf.scanf \"%s \" (fun x -> x) in\n match s with\n | \"\" -> List.rev l\n | _ -> readl (s::l)\n\nlet commands = readl [];;\n\n (*\nlet _ = List.iter (fun x -> printf \"%s \" x) commands\nin print_endline \"\\n---\"\n *)\n\nlet _ = process_command commands []\n", "positive_code": [{"source_code": "open Printf;;\nopen Scanf;;\n\nlet output_directory dir =\n let rec process_dir dir =\n match dir with\n | [] -> printf \"\\n\"\n | h::t -> printf \"%s/\" h;\n\t process_dir t\n in\n printf \"/\";\n process_dir (List.rev dir)\n;;\n\nlet rec change_directory act_dir s idx act_str =\n if idx < (String.length s) then\n match s.[idx] with\n | '/' -> if(act_str = \"..\") then\n\t\tchange_directory (List.tl act_dir) s (idx+1) \"\"\n\t else\n\t\tchange_directory (act_str::act_dir) s (idx+1) \"\"\n | c -> change_directory act_dir s (idx+1) (act_str ^ (Char.escaped c))\n else\n act_dir\n;;\n\nlet process_line dir =\n let s = scanf \"%s\" (fun x->x) in\n(* printf \"mam komende %s\\n\" s; *)\n if s = \"pwd\" then begin\n(* printf \"%s\\n\" s; *)\n let _ = scanf \"%s\\n\" (fun x->x) in\n output_directory dir;\n dir\n end else begin\n(* printf \"%s\\n\" s; *)\n let s2 = scanf \" %s\\n\" (fun x->x) in\n(* printf \"robie cd do %s\\n\" s2; *)\n if s2.[0] = '/' then\n change_directory [] (s2^\"/\") 1 \"\"\n else\n change_directory dir (s2^\"/\") 0 \"\"\n end\n \n;;\n\nlet rec solve n directory =\n if n <> 0 then\n solve (n-1) (process_line directory)\n;;\n\nlet n = scanf \"%d\\n\" (fun x->x) in\nsolve n []"}], "negative_code": [], "src_uid": "494ac937ba939db1dbc4081e518ab54c"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet solve n = \n\tlet t = Array.make (n + 1) 0 and\n\tcolor = Array.make (n + 1) 0 and\n\tcnt = Array.make (n + 1) 0 in\n\tfor i = 1 to n do\n\t\tlet a = read_int () in\n\t\tt.(i) <- a;\n\tdone;\n\tfor i = 1 to n do\n\t\tif color.(i) = 0 then\n\t\t\tlet cur = ref i in\n\t\t\twhile color.(!cur) = 0 do\n\t\t\t\tcnt.(i) <- (cnt.(i) + 1);\n\t\t\t\tcolor.(!cur) <- i;\n\t\t\t\tcur := t.(!cur);\n\t\t\tdone;\n\t\tprintf \"%d \" cnt.(color.(i));\n\t\telse printf \"%d \" cnt.(color.(i));\n\tdone;\n\tprintf \"\\n\";\n\t()\n\nlet () = \n\tlet q = read_int () in\n\tfor tests = 1 to q do\n\t\tlet n = read_int () in\n\t\tsolve n;\n\tdone;", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet solve n = \n\tlet t = Array.make (n + 1) 0 and\n\tcolor = Array.make (n + 1) 0 and\n\tcnt = Array.make (n + 1) 0 in\n\tfor i = 1 to n do\n\t\tlet a = read_int () in\n\t\tt.(i) <- a;\n\tdone;\n\tfor i = 1 to n do\n\t\tif color.(i) = 0 then\n\t\t\tlet cur = ref i in\n\t\t\twhile color.(!cur) = 0 do\n\t\t\t\tcnt.(i) <- (cnt.(i) + 1);\n\t\t\t\tcolor.(!cur) <- i;\n\t\t\t\tcur := t.(!cur);\n\t\t\tdone;\n\t\tprintf \"%d \" cnt.(color.(i));\n\t\telse printf \"%d \" cnt.(color.(i));\n\tdone;\n\tprintf \"\\n\";\n\t()\n\nlet () = \n\tlet q = read_int () in\n\tfor tests = 1 to q do\n\t\tlet n = read_int () in\n\t\tsolve n;\n\tdone;"}], "negative_code": [], "src_uid": "345e76bf67ae4342e850ab248211eb0b"} {"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let l , r = Scanf.sscanf (input_line stdin) \"%d %d\" (fun l r -> (l,r)) in\r\n if l = 0 then print_endline \"1\" \r\n else begin\r\n let b = Int64.add (Int64.of_int r) (Int64.of_int r) in\r\n let a = Int64.add b (Int64.of_int (l+1)) in\r\n print_endline (Int64.to_string a)\r\n end\r\ndone;;\r\n \r\n ", "positive_code": [{"source_code": "open Printf\nopen Scanf\nmodule LL = Int64\nlet rd_ll () = bscanf Scanning.stdin \" %Ld \" (fun x -> x)\n\nlet (&) x = LL.of_int x\nlet ( + ) x y = LL.add x y\nlet ( - ) x y = LL.sub x y\nlet ( * ) x y = LL.mul x y\nlet ( / ) x y = LL.div x y\nlet ( % ) x y = x - ( y * (x / y) ) \n\nlet solve x y =\n if x = 0L then 1L\n else x+2L*y+1L\n\nlet () =\n let t = read_int () in\n for i=1 to t do\n let n = rd_ll () in\n let x = rd_ll () in\n printf \"%Ld\\n\" (solve n x)\n done;"}], "negative_code": [], "src_uid": "2b6e670b602a89b467975edf5226219a"} {"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 Array.sort compare a\n in\n let res = ref 1 in\n for i = 0 to n - 1 do\n if a.(i) >= !res\n then incr res\n done;\n Printf.printf \"%d\\n\" !res\n", "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 a = Array.init n (fun _ -> read_int()) in\n\n Array.sort compare a;\n\n let rec scan i mval = if i=n then mval else\n if a.(i) >= mval\n then scan (i+1) (mval+1) \n else scan (i+1) mval\n in\n\n printf \"%d\\n\" (scan 0 1)\n"}], "negative_code": [], "src_uid": "482b3ebbbadd583301f047181c988114"} {"source_code": "module A = Array\r\nmodule L = List\r\nmodule I = Int64\r\nmodule B = Big_int\r\n\r\nmodule Opt = struct\r\n let get = function\r\n | None -> assert false\r\n | Some v -> v\r\nend\r\n\r\nlet pf = Printf.printf\r\nlet sf = Scanf.scanf\r\nlet read_int () = sf \" %d\" (fun x -> x)\r\nlet read_array read n = A.init n (fun _ -> read ())\r\n\r\nlet i_bit x i = (x lsr i) land 1\r\n\r\nlet () =\r\n let n = read_int () in\r\n let q = read_int () in\r\n let ans = Array.make n 0 in\r\n let gr = Array.make n [] in\r\n let qrs = Array.init q (fun _ ->\r\n let x = read_int () - 1 in\r\n let y = read_int () - 1 in\r\n let v = read_int () in\r\n (x, y, v)\r\n ) in\r\n\r\n Array.iter (fun (x, y, v) ->\r\n if (x <> y) then begin\r\n gr.(x) <- (y, v) :: gr.(x);\r\n gr.(y) <- (x, v) :: gr.(y);\r\n end\r\n ) qrs;\r\n\r\n let bit_val = Array.make n (-1) in\r\n for b = 29 downto 0 do\r\n Array.fill bit_val 0 n (-1);\r\n for i = 0 to q - 1 do\r\n let (x, y, v) = qrs.(i) in\r\n (* pf \"q = %d %d %d %d\\n\" i x y v;\r\n pf \"q = %d %d %d %b\\n\" i (i_bit v x ) (i_bit v y ) (i_bit v x = 0 && i_bit v y = 0); *)\r\n if (x = y) then bit_val.(x) <- i_bit v x\r\n else if (i_bit v b = 0 && i_bit v b = 0) then begin\r\n bit_val.(x) <- 0;\r\n bit_val.(y) <- 0;\r\n end\r\n done;\r\n\r\n for i = 0 to n - 1 do\r\n if (bit_val.(i) = -1) then begin\r\n let is_one = List.exists (fun (y, v) -> bit_val.(y) = 0 && i_bit v b = 1) gr.(i) in\r\n (* pf \"%d %d %b\\n\" b i is_one; *)\r\n if (is_one) then bit_val.(i) <- 1\r\n else bit_val.(i) <- 0;\r\n end;\r\n ans.(i) <- ans.(i) lor (bit_val.(i) lsl b);\r\n done;\r\n done;\r\n\r\n Array.iter (fun x -> pf \"%d \" x) ans;", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,q) = read_pair () in\n let constr = Array.init q (fun _ ->\n let i = -1 + read_int() in\n let j = -1 + read_int() in\n let x = read_int() in\n (i,j,x)\n ) in\n\n let req0 = Array.make n 0 in\n let req1 = Array.make n 0 in\n\n let adj = Array.make n [] in\n\n let add_edge i j x =\n adj.(i) <- (j,x)::adj.(i);\n adj.(j) <- (i,x)::adj.(j)\n in\n\n for k = 0 to q-1 do\n let (i,j,x) = constr.(k) in\n if i=j then (\n req0.(i) <- req0.(i) lor (lnot x);\n req1.(i) <- req1.(i) lor x\n ) else (\n req0.(i) <- req0.(i) lor (lnot x);\n req0.(j) <- req0.(j) lor (lnot x);\n add_edge i j x\n )\n done;\n\n for i = 0 to n-1 do\n req1.(i) <- List.fold_left (fun ac (j,x) ->\n (req0.(j) land x) lor ac\n ) req1.(i) adj.(i);\n req0.(i) <- lnot req1.(i)\n done;\n\n for i=0 to n-1 do\n printf \"%d \" req1.(i)\n done;\n print_newline()\n"}], "negative_code": [], "src_uid": "891a7bd69187975f61b8c6ef6b6acac3"} {"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\n(* let () =\n let hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))\n in\n print_array (sprintf \"%3d\") hoge;\n let cumul = make 100 0 in\n iteri (fun i v ->\n if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)\n ) cumul;\n print_array (sprintf \"%3d\") cumul *)\nlet f l = l*(if l mod 2L=0L then 1L else -1L)\nlet g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)\nlet () =\n let q = get_i64 0 in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n printf \"%Ld\\n\" @@\n if l=r then f l\n (* else if r=l+1L then f l + f (l+1L)\n else if r=l+2L then f l + f (l+1L) + f (l+2L)\n (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in\n let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in\n (* printf \"%Ld\\n\" @@ vl + vr *)\n printf \"%Ld\\n\" @@ vl + vr; *)\n else if l = 1L then g r\n else\n (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r\n else if l mod 2L=1L && (r-l) mod 2L=0L then 0L\n else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r\n else 0L *)\n g l + g r *)\n else\n (* if l=1L then g r\n else g (l-1L) + g r *)\n g r - g (l-1L)\n )\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet (--) = Int64.sub\nlet (//) = Int64.div\nlet (%%) = Int64.rem\n\nlet sum = function\n r when r %% 2L = 0L -> r // 2L\n | r -> r // 2L -- r\n\nlet () =\n let q = scanf \" %d\" (fun x -> x) in\n for i = 0 to q-1 do\n let l, r = scanf \" %Ld %Ld\" (fun x y -> x,y) in\n printf \"%Ld\\n\" @@ sum r -- sum (l -- 1L)\n done"}], "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\n\n(* let () =\n let hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))\n in\n print_array (sprintf \"%3d\") hoge;\n let cumul = make 100 0 in\n iteri (fun i v ->\n if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)\n ) cumul;\n print_array (sprintf \"%3d\") cumul *)\nlet f l = l*(if l mod 2L=0L then 1L else -1L)\nlet g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)\nlet () =\n let q = get_i64 0 in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n printf \"%Ld\\n\" @@\n if l=r then f l\n else if r=l+1L then f l + f (l+1L)\n else if r=l+2L then f l + f (l+1L) + f (l+2L)\n (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in\n let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in\n (* printf \"%Ld\\n\" @@ vl + vr *)\n printf \"%Ld\\n\" @@ vl + vr; *)\n else\n (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r\n else if l mod 2L=1L && (r-l) mod 2L=0L then 0L\n else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r\n else 0L *)\n g l + g r\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\n(* let () =\n let hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))\n in\n print_array (sprintf \"%3d\") hoge;\n let cumul = make 100 0 in\n iteri (fun i v ->\n if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)\n ) cumul;\n print_array (sprintf \"%3d\") cumul; *)\nlet f l = l*(if l mod 2L=0L then 1L else -1L)\nlet g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)\nlet () =\n let q = get_i64 0 in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n printf \"%Ld\\n\" @@\n if l=r then f l\n else if r=l+1L then f l + f (l+1L)\n else if r=l+2L then f l + f (l+1L) + f (l+2L)\n (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in\n let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in\n (* printf \"%Ld\\n\" @@ vl + vr *)\n printf \"%Ld\\n\" @@ vl + vr; *)\n else if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r\n else if l mod 2L=1L && (r-l) mod 2L=0L then 0L\n else if l mod 2L=0L && (r-l) mod 2L=1L then g r\n else 0L\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\n(* let () =\n let hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))\n in\n print_array (sprintf \"%3d\") hoge;\n let cumul = make 100 0 in\n iteri (fun i v ->\n if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)\n ) cumul;\n print_array (sprintf \"%3d\") cumul *)\nlet f l = l*(if l mod 2L=0L then 1L else -1L)\nlet g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)\nlet () =\n let q = get_i64 0 in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n printf \"%Ld\\n\" @@\n if l=r then f l\n else if r=l+1L then f l + f (l+1L)\n else if r=l+2L then f l + f (l+1L) + f (l+2L)\n (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in\n let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in\n (* printf \"%Ld\\n\" @@ vl + vr *)\n printf \"%Ld\\n\" @@ vl + vr; *)\n else if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r\n else if l mod 2L=1L && (r-l) mod 2L=0L then 0L\n else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r\n else 0L\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\n(* let () =\n let hoge = init 100 (fun i -> let i = i+$1 in i*$(if i %$ 2=0 then 1 else -1))\n in\n print_array (sprintf \"%3d\") hoge;\n let cumul = make 100 0 in\n iteri (fun i v ->\n if i<>0 then cumul.(i) <- cumul.(i-$1)+$hoge.(i-$1)\n ) cumul;\n print_array (sprintf \"%3d\") cumul *)\nlet f l = l*(if l mod 2L=0L then 1L else -1L)\nlet g l = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L)\nlet () =\n let q = get_i64 0 in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n printf \"%Ld\\n\" @@\n if l=r then f l\n else if r=l+1L then f l + f (l+1L)\n else if r=l+2L then f l + f (l+1L) + f (l+2L)\n (*let vl = ceildiv (l) 2L*(if l mod 2L=0L then 1L else -1L) in\n let vr = ceildiv (r) 2L*(if r mod 2L=0L then 1L else -1L) in\n (* printf \"%Ld\\n\" @@ vl + vr *)\n printf \"%Ld\\n\" @@ vl + vr; *)\n else if l = 1L then g r\n else\n (* if l mod 2L=0L && (r-l) mod 2L=0L then g l + g r\n else if l mod 2L=1L && (r-l) mod 2L=0L then 0L\n else if l mod 2L=0L && (r-l) mod 2L=1L then g l + g r\n else 0L *)\n g l + g r\n )\n\n\n\n\n\n\n\n"}], "src_uid": "7eae40835f6e9580b985d636d5730e2d"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\n\nlet init (x : int) (f : int -> 'a) : 'a list =\n let rec build k =\n if k = x then []\n else (f k) :: build (k + 1) in\n build 0\n;;\n \nlet run () = \n let n = scan_int () in\n let a = Array.init n (fun _x -> scan_int ()) in\n let posA = ref 0 and posB = ref (n-1) in\n let totA = ref 0 and totB = ref 0 in\n let prv = ref 0 and now = ref 0 in\n let turn = ref 0 and totturn = ref 0 in\n while !posA <= !posB do\n if !turn = 0 then begin\n now := !now + a.(!posA);\n totA := !totA + a.(!posA);\n posA := !posA + 1\n end\n else begin\n now := !now + a.(!posB);\n totB := !totB + a.(!posB);\n posB := !posB - 1\n end;\n if !now > !prv then begin\n prv := !now;\n now := 0;\n turn := 1 - !turn;\n totturn := !totturn + 1\n end\n done;\n if !now > 0 then incr totturn;\n let lst = [!totturn; !totA; !totB] in\n List.iter (printf \"%d \") lst;\n print_endline \"\"\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "(* Codeforces 1352 D Alice, Bob and Candies comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\n(* ============= above library below custom ========== *)\n\nlet rec alice ia sma ib smb lastbob nmov v =\n\tlet rec eat i eaten = \n\t\t(* let _ = Printf.printf \"al eat i eaten = %d %d\\n\" i eaten in *)\n\t\tif eaten > lastbob then (i, eaten) \n\t\telse if i > ib then (i, eaten)\n\t\telse \n\t\t\tlet eaten = eaten + v.(i) in\n\t\t\tlet i = i + 1 in\n\t\t\teat i eaten in\n\tlet idx,aeat = eat ia 0 in\n\tlet sma = sma + aeat in\n let nmov = nmov + 1 in\n\tif idx > ib then (nmov, sma, smb)\n\telse\n\tbob idx sma ib smb aeat nmov v\n\t\nand\n\nbob ia sma ib smb lastalice nmov v =\n let rec eat i eaten = \n (* let _ = Printf.printf \"bo eat i eaten = %d %d\\n\" i eaten in *)\n if eaten > lastalice then (i, eaten) \n else if i < ia then (i, eaten)\n else \n let eaten = eaten + v.(i) in\n let i = i - 1 in\n eat i eaten in\n let idx,beat = eat ib 0 in\n let smb = smb + beat in\n let nmov = nmov + 1 in\n if idx < ia then (nmov, sma, smb)\n else\n alice ia sma idx smb beat nmov v;;\n\t \n \nlet do_one () = \n let n = gr () in\n let a = readlist n [] in\n\t\tlet a = (List.rev a) in\n\t\tlet va = Array.of_list a in\n\t\tlet nm,ca,cb = alice 0 0 (n-1) 0 0 0 va in\n \tPrintf.printf \"%d %d %d\\n\" nm ca cb;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [], "src_uid": "d70ee6d3574e0f2cac3c683729e2979d"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet s=read_line();;\n\nlet rec ind i t=if t.[i]=' ' then i else ind (i+1) t;;\nlet i=ind 0 s;;\n\nlet s1=String.sub s 0 i;;\nlet s2=String.sub s (i+1) (String.length(s)-i-1);;\n\nlet a=float_of_string(s1);;\nlet d=float_of_string(s2);;\n\nlet n=read_int();;\n\nlet frac b=b-.float_of_int(int_of_float(b));;\n\nlet bop b c=\nprint_float b;\nprint_string \" \";\nprint_float c;\nprint_newline();;\n\nlet m=ref 0.;;\n\nfor i=1 to n do\n m:= !m+.d;\n let p=frac( !m/.(4.0*.a)) in\n if p<0.25 then bop (p*.4.0*.a) 0.0\n else if p<0.5 then bop a ((p-.0.25)*.4.0*.a)\n else if p<0.75 then bop (a-.(p-.0.5)*.4.0*.a) a\n else bop 0.0 (a-.(p-.0.75)*.4.0*.a);\n m:=(p*.4.0*.a)\ndone;;", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \"%d\" (fun x -> x);;\n\nlet a = Scanf.scanf \"%f \" (fun x -> x);;\nlet d = Scanf.scanf \"%f\\n\" (fun x -> x);;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\n\nlet distance = ref 0.;;\n\nlet modulo a b = a -. b *. floor (a /. b);;\n\nfor i=1 to n do\n distance := modulo (!distance +. d) (4.*.a);\n match int_of_float (!distance /. a) with\n | 0 -> print_float !distance;\n print_string \" \";\n print_float 0.;\n print_string \"\\n\"\n | 1 -> print_float a;\n print_string \" \";\n print_float (!distance -. a);\n print_string \"\\n\"\n | 2 -> print_float (3.*.a -. !distance);\n print_string \" \";\n print_float a;\n print_string \"\\n\"\n | 3 -> print_float 0.;\n print_string \" \";\n print_float (4.*.a -. !distance);\n print_string \"\\n\"\n | _ -> failwith \"Erreur !!\"\ndone;"}], "negative_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet s=read_line();;\n\nlet rec ind i t=if t.[i]=' ' then i else ind (i+1) t;;\nlet i=ind 0 s;;\n\nlet s1=String.sub s 0 i;;\nlet s2=String.sub s (i+1) (String.length(s)-i-1);;\n\nlet a=float_of_string(s1);;\nlet d=float_of_string(s2);;\n\nlet n=read_int();;\n\nlet frac b=b-.float_of_int(int_of_float(b));;\n\nlet bop b c=\nprint_float b;\nprint_string \" \";\nprint_float c;\nprint_newline();;\n\nfor i=1 to n do\n let m=float_of_int(i)*.d in\n let p=frac(m/.(4.0*.a)) in\n if p<0.25 then bop (p*.4.0*.a) 0.0\n else if p<0.5 then bop a ((p-.0.25)*.4.0*.a)\n else if p<0.75 then bop (a-.(p-.0.5)*.4.0*.a) a\n else bop 0.0 (a-.(p-.0.75)*.4.0*.a)\ndone;;"}], "src_uid": "d00b8423c3c52b19fec25bc63e4d4c1c"} {"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64 = Int64.to_int,Int64.of_int\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.add,Int64.sub,Int64.mul,Int64.div,Int64.rem,Int64.rem\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls =\n\t\tlet rec f0 a s = match a with\n\t\t| [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator)\n\t\tin f0 ls \"\"\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\tlet dump_list f ls = string_of_list f ls |> print_endline\n\tlet dump_array f a = string_of_array f a |> print_endline\nend open Lib\n\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok - ng) <= 1L then ok\n\t\telse let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng-1L*d) (ok+1L*d)\n\n(* let a,b = get_2_i64 0\nlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\nlet rec f0 ra rb la lb = function\n\t| 0L -> (la,lb)\n\t| v ->\n\t\tif ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)\n\t\telse f0 ra (rb-v) la (v::lb) (v-1L)\nlet (la,lb) = f0 a b [] [] sum\nlet () =\n\tprintf \"%d\\n\" @@ List.length la;\n\tdump_list Int64.to_string la;\n\tprintf \"%d\\n\" @@ List.length lb;\n\tdump_list Int64.to_string lb; *)\n\nlet ist = Int64.to_string\nlet dump_list ls = ls\n\t|> List.map ist\n\t|> String.concat \" \"\n\t|> print_endline\nlet () =\n\tlet a,b = get_2_i64 0 in\n\tlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\n\tin\n\t(* printf \"%Ld\\n\" sum; *)\n\tlet d1,d2 = ref [],ref [] in\n\tlet r1,r2 = ref a,ref b in \n\t(* rep 1L sum (fun i -> \n\t\tlet i = sum - i + 1L in\n\t\tif !ra > !rb then (\n\t\t\tla := i::!la; ra -= i;\n\t\t) else (\n\t\t\tlb := i::!lb; rb -= i;\n\t\t)\n\t); *)\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !r2 <= !r1 then (\n\t\t\tr1 := !r1 - !i;\n\t\t\td1 := !i :: !d1\n\t\t) else (\n\t\t\tr2 := !r2 - !i;\n\t\t\td2 := !i :: !d2\n\t\t);\n\t\ti := !i - 1L\n\tdone;\n\tprintf \"%d\\n\" @@ List.length !d1;\n\tdump_list !d1;\n\tprintf \"%d\\n\" @@ List.length !d2;\n\tdump_list !d2;\n\n\n\n\n", "positive_code": [{"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls =\n\t\tls |> List.map f |> String.concat separator\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\t(* let dump_list f ls = ls |> List.map f |> String.concat \" \" |> print_endline\n\tlet dump_array f a = a |> Array.to_list |> dump_list f *)\n\tlet dump_list f ls = string_of_list f ls |> print_endline\nend open Lib\n\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok - ng) <= 1L then ok\n\t\telse let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng-1L*d) (ok+1L*d)\n\n(* let a,b = get_2_i64 0\nlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\nlet rec f0 ra rb la lb = function\n\t| 0L -> (la,lb)\n\t| v ->\n\t\tif ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)\n\t\telse f0 ra (rb-v) la (v::lb) (v-1L)\nlet (la,lb) = f0 a b [] [] sum\nlet () =\n\tprintf \"%d\\n\" @@ List.length la;\n\tdump_list Int64.to_string la;\n\tprintf \"%d\\n\" @@ List.length lb;\n\tdump_list Int64.to_string lb; *)\n\nlet ist = Int64.to_string\nlet () =\n\tlet a,b = get_2_i64 0 in\n\tlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\n\tin\n\t(* printf \"%Ld\\n\" sum; *)\n\tlet d1,d2 = ref [],ref [] in\n\tlet r1,r2 = ref a,ref b in \n\t(* rep 1L sum (fun i -> \n\t\tlet i = sum - i + 1L in\n\t\tif !ra > !rb then (\n\t\t\tla := i::!la; ra -= i;\n\t\t) else (\n\t\t\tlb := i::!lb; rb -= i;\n\t\t)\n\t); *)\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !r2 <= !r1 then (\n\t\t\tr1 := !r1 - !i;\n\t\t\td1 := !i :: !d1\n\t\t) else (\n\t\t\tr2 := !r2 - !i;\n\t\t\td2 := !i :: !d2\n\t\t);\n\t\ti := !i - 1L\n\tdone;\n\tprintf \"%d\\n\" @@ List.length !d1;\n\tdump_list ist !d1;\n\tprintf \"%d\\n\" @@ List.length !d2;\n\tdump_list ist !d2;\n\n\n\n\n"}, {"source_code": "let (++),(--),labs,(//),( ** ),i64,ist = Int64.(add,sub,abs,div,mul,of_int,to_string)\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok -- ng) <= 1L then ok\n\t\telse let mid = ng ++ (ok -- ng) // 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng--d) (ok++d)\nlet dump_list ls = ls\n\t|> List.map ist\n\t|> String.concat \" \"\n\t|> print_endline\nlet () = Scanf.scanf \" %Ld %Ld\" @@ fun a b ->\n\tlet sum = binary_search 2000000018L 0L (fun v -> v**(v++1L)//2L <= a++b)\n\tin\n\tlet d1,d2 = ref [], ref [] in\n\tlet a = ref a in\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !i <= !a then (\n\t\t\ta := !a -- !i;\n\t\t\td1 := !i :: !d1\n\t\t) else d2 := !i :: !d2;\n\t\ti := !i -- 1L\n\tdone;\n\tPrintf.printf \"%d\\n\" @@ List.length !d1;\n\tdump_list !d1;\n\tPrintf.printf \"%d\\n\" @@ List.length !d2;\n\tdump_list !d2;\n\n"}, {"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\tlet dump_list f ls = string_of_list f ls |> print_endline\n\tlet dump_array f a = string_of_array f a |> print_endline\n\tlet dump_list_test f ls = List.iter (fun v -> printf \"%s \" @@ f v) ls; print_newline ()\nend open Lib\n\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok - ng) <= 1L then ok\n\t\telse let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng-1L*d) (ok+1L*d)\n\n(* let a,b = get_2_i64 0\nlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\nlet rec f0 ra rb la lb = function\n\t| 0L -> (la,lb)\n\t| v ->\n\t\tif ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)\n\t\telse f0 ra (rb-v) la (v::lb) (v-1L)\nlet (la,lb) = f0 a b [] [] sum\nlet () =\n\tprintf \"%d\\n\" @@ List.length la;\n\tdump_list Int64.to_string la;\n\tprintf \"%d\\n\" @@ List.length lb;\n\tdump_list Int64.to_string lb; *)\n\nlet ist = Int64.to_string\nlet () =\n\tlet a,b = get_2_i64 0 in\n\tlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\n\tin\n\t(* printf \"%Ld\\n\" sum; *)\n\tlet d1,d2 = ref [],ref [] in\n\tlet r1,r2 = ref a,ref b in \n\t(* rep 1L sum (fun i -> \n\t\tlet i = sum - i + 1L in\n\t\tif !ra > !rb then (\n\t\t\tla := i::!la; ra -= i;\n\t\t) else (\n\t\t\tlb := i::!lb; rb -= i;\n\t\t)\n\t); *)\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !r2 <= !r1 then (\n\t\t\tr1 := !r1 - !i;\n\t\t\td1 := !i :: !d1\n\t\t) else (\n\t\t\tr2 := !r2 - !i;\n\t\t\td2 := !i :: !d2\n\t\t);\n\t\ti := !i - 1L\n\tdone;\n\tprintf \"%d\\n\" @@ List.length !d1;\n\tdump_list_test ist !d1;\n\tprintf \"%d\\n\" @@ List.length !d2;\n\tdump_list_test ist !d2;\n\n\n\n\n"}, {"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls =\n\t\tlet rec f0 a s = match a with\n\t\t| [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator)\n\t\tin f0 ls \"\"\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\tlet dump_list_slow f ls = string_of_list f ls |> print_endline\n\tlet dump_array_slow f a = string_of_array f a |> print_endline\n\tlet dump_i64_list ls = ls\n\t\t|> List.map ist\nend open Lib\n\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok - ng) <= 1L then ok\n\t\telse let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng-1L*d) (ok+1L*d)\n\n(* let a,b = get_2_i64 0\nlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\nlet rec f0 ra rb la lb = function\n\t| 0L -> (la,lb)\n\t| v ->\n\t\tif ra > rb then f0 (ra-v) rb (v::la) lb (v-1L)\n\t\telse f0 ra (rb-v) la (v::lb) (v-1L)\nlet (la,lb) = f0 a b [] [] sum\nlet () =\n\tprintf \"%d\\n\" @@ List.length la;\n\tdump_list Int64.to_string la;\n\tprintf \"%d\\n\" @@ List.length lb;\n\tdump_list Int64.to_string lb; *)\n\nlet ist = Int64.to_string\nlet dump_list f ls = ls\n\t|> List.map f\n\t|> String.concat \" \"\n\t|> print_endline\nlet () =\n\tlet a,b = get_2_i64 0 in\n\tlet sum = binary_search (2000000018L) 0L (fun v -> v*(v+1L)/2L <= a+b)\n\tin\n\t(* printf \"%Ld\\n\" sum; *)\n\tlet d1,d2 = ref [],ref [] in\n\tlet r1,r2 = ref a,ref b in \n\t(* rep 1L sum (fun i -> \n\t\tlet i = sum - i + 1L in\n\t\tif !ra > !rb then (\n\t\t\tla := i::!la; ra -= i;\n\t\t) else (\n\t\t\tlb := i::!lb; rb -= i;\n\t\t)\n\t); *)\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !r2 <= !r1 then (\n\t\t\tr1 := !r1 - !i;\n\t\t\td1 := !i :: !d1\n\t\t) else (\n\t\t\tr2 := !r2 - !i;\n\t\t\td2 := !i :: !d2\n\t\t);\n\t\ti := !i - 1L\n\tdone;\n\tprintf \"%d\\n\" @@ List.length !d1;\n\tdump_list ist !d1;\n\tprintf \"%d\\n\" @@ List.length !d2;\n\tdump_list ist !d2;\n\n\n\n\n"}, {"source_code": "let (++),(--),labs,(//),( ** ),i64,ist = Int64.(add,sub,abs,div,mul,of_int,to_string)\nlet binary_search ng ok f =\n\tlet rec f0 ng ok =\n\t\tif labs (ok -- ng) <= 1L then ok\n\t\telse let mid = ng ++ (ok -- ng) // 2L in if f mid then f0 ng mid else f0 mid ok\n\tin let d = if ng < ok then 1L else -1L\n\tin f0 (ng--d) (ok++d)\nlet dump_list ls = ls\n\t|> List.map ist\n\t|> String.concat \" \"\n\t|> print_endline\nlet () = Scanf.scanf \" %Ld %Ld\" @@ fun a b ->\n\tlet sum = binary_search 2000000018L 0L (fun v -> v**(v++1L)//2L <= a++b)\n\tin\n\tlet d1,d2 = ref [], ref [] in\n\tlet r1,r2 = ref a, ref b in\n\tlet i = ref sum in\n\twhile !i >= 1L do\n\t\tif !r2 <= !r1 then (\n\t\t\tr1 := !r1 -- !i;\n\t\t\td1 := !i :: !d1\n\t\t) else (\n\t\t\tr2 := !r2 -- !i;\n\t\t\td2 := !i :: !d2\n\t\t);\n\t\ti := !i -- 1L\n\tdone;\n\tPrintf.printf \"%d\\n\" @@ List.length !d1;\n\tdump_list !d1;\n\tPrintf.printf \"%d\\n\" @@ List.length !d2;\n\tdump_list !d2;"}], "negative_code": [], "src_uid": "fab438cef9eb5e9e4a4a2e3f9e4f9cec"} {"source_code": "type spruce = Leaf of int\n | Node of spruce list\n\nlet rec split num str = \n match str with\n | \"\" -> []\n | s ->\n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one) ::(returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one) :: []\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\n\nlet rec makePairList numList num =\n match numList with\n | h :: t -> (h, num) :: (makePairList t (num+1))\n | _ -> []\n\nlet rec makeNode pairList num =\n match pairList with\n | (a,b) :: t -> \n if (num == a) then \n Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)\n else makeNode t num\n | _ -> []\n\nlet rec countLeaf node =\n match node with\n | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t\n | Node(Leaf(a) :: t) :: tail -> countLeaf tail\n | _ -> 0\n\nlet rec checkNotAllNode node =\n match node with\n | Node (Leaf(b) :: []) :: tail -> true\n | Node (Leaf(a) :: t) :: [] -> false\n | Node (Leaf(a) :: t) :: tail -> checkNotAllNode tail\n | _ -> true\n\nlet rec countSpruce spruce =\n match spruce with\n | Node (Leaf(a) :: t) :: tail ->\n let num = countLeaf t in\n if (num >= 3 || num == 0) && (checkNotAllNode t) == true then \n countSpruce t && countSpruce tail\n else false\n | _ -> true\n\nlet printLeaf leaf = \n match leaf with\n | Leaf(a) -> print_string \"[Leaf : \";print_int a; print_string \"]\"\n | _ -> print_string \" \"\n\nlet rec printNode node = \n match node with\n | Node (h :: t) :: tail -> \n print_string \"[Node : \";printLeaf h; printNode t;print_string\"]\";\n printNode tail\n | _ -> print_string \" \"\n\nlet n = read_int()\nlet rec numList k =\n if (k < n) then \n let m = read_int() in\n m :: (numList (k+1))\n else []\n\nlet pairList = makePairList (numList 1) 2\n\nlet newSpruce =\n Node (Leaf(1) :: (makeNode pairList 1)) :: []\n\n\nlet _ = \n if (countSpruce newSpruce) then print_string \"Yes\"\n else print_string \"No\"\n", "positive_code": [{"source_code": "(* Codeforces 913 B Christmas Spruce *)\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet debug = false;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec revert l acc = match l with\n\t| [] -> acc\n\t| h :: t ->\n\t\t\tlet aa = h :: acc in\n\t\t\trevert t aa;;\n\nlet rec setna na li idx =\n\tif idx = 0 then \n\t\tbegin\n\t\t\tna.(0) <- [];\n\t\t\tsetna na li (idx + 1)\n\t\tend\n\telse\n\t\tmatch li with\n\t\t| [] -> ()\n\t\t| h :: t ->\n\t\t\t\tbegin\n\t\t\t\t\tna.(h - 1) <- idx :: na.(h - 1);\n\t\t\t\t\tsetna na t (idx + 1)\n\t\t\t\tend;;\n\n(* count elements of numa array with idndexes in li *)\nlet rec arr_count numa li = match li with\n\t| [] -> 0\n\t| h :: t -> numa.(h) + arr_count numa t;;\n\nlet is_leaf li = match li with\n\t| [] -> 1\n\t| _ -> 0;;\n\n(* count lefes for current root, returns (isLeaf, good) *)\nlet check_node na is_leafa idx =\n\t(* let _ = begin \n\t\tprint_string \"\\n check_node \"; \n\t\tprint_int idx;\n\t print_string \" na_idx \";\n\t\t\tprintlisti na.(idx)\n\t end in *)\n\tlet lcnt = arr_count is_leafa na.(idx) in\n\tif is_leafa.(idx) = 0 then lcnt >= 3\n\telse true;;\n\nlet rec all_true idx f nmax =\n\tif idx < nmax then (f idx) && all_true (idx + 1) f nmax\n\telse true;;\n\nlet main() =\n\tlet n = gr() in\n\tlet a = readlist (n - 1) [] in\n\tlet ar = revert a [] in\n (* let _ = printlisti ar in *) \n\tlet na = Array.make n [] in\n\tlet _ = setna na ar 0 in\n\tlet is_leafa = Array.map is_leaf na in\n\tbegin\n\t\t(*print_string \"\\n is_leafa: \";\n\t\tprintarri is_leafa;*) \n\t\tlet simp_check i = check_node na is_leafa i in\n\t\tlet ok = all_true 0 simp_check n in\n\t\tif ok then print_string \"Yes\"\n\t\telse print_string \"No\"\n\tend;;\n\nmain();;"}], "negative_code": [{"source_code": "type spruce = Leaf of int\n | Node of spruce list\n\nlet rec split num str = \n match str with\n | \"\" -> []\n | s ->\n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one) ::(returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one) :: []\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\n\nlet rec makePairList numList num =\n match numList with\n | h :: t -> (h, num) :: (makePairList t (num+1))\n | _ -> []\n\nlet rec makeNode pairList num =\n match pairList with\n | (a,b) :: t -> \n if (num == a) then \n Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)\n else makeNode t num\n | _ -> []\n\nlet rec countLeaf node =\n match node with\n | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t\n | Node(Leaf(a) :: t) :: tail -> countLeaf tail\n | _ -> 0\n\nlet rec checkNotAllNode node =\n match node with\n | Node (Leaf(b) :: []) :: tail -> true\n | Node (Leaf(a) :: t) :: [] -> false\n | Node (Leaf(a) :: t) :: tail -> checkNotAllNode tail\n | _ -> true\n\nlet rec countSpruce spruce =\n match spruce with\n | Node (Leaf(a) :: t) :: tail ->\n let num = countLeaf t in\n if (num == 3 || num == 0) && (checkNotAllNode t == true) then \n countSpruce t && countSpruce tail\n else false\n | _ -> true\n\nlet printLeaf leaf = \n match leaf with\n | Leaf(a) -> print_string \"[Leaf : \";print_int a; print_string \"]\"\n | _ -> print_string \" \"\n\nlet rec printNode node = \n match node with\n | Node (h :: t) :: tail -> \n print_string \"[Node : \";printLeaf h; printNode t;print_string\"]\";\n printNode tail\n | _ -> print_string \" \"\n\nlet n = read_int()\nlet rec numList k =\n if (k < n) then \n let m = read_int() in\n m :: (numList (k+1))\n else []\n\nlet pairList = makePairList (numList 1) 2\n\nlet newSpruce =\n Node (Leaf(1) :: (makeNode pairList 1)) :: []\n\n\nlet _ = \n if (countSpruce newSpruce) then print_string \"Yes\"\n else print_string \"No\"\n"}, {"source_code": "type spruce = Leaf of int\n | Node of spruce list\n\nlet rec split num str = \n match str with\n | \"\" -> []\n | s ->\n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one) ::(returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one) :: []\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\n\nlet rec makePairList numList num =\n match numList with\n | h :: t -> (h, num) :: (makePairList t (num+1))\n | _ -> []\n\nlet rec makeNode pairList num =\n match pairList with\n | (a,b) :: t -> \n if (num == a) then \n Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)\n else makeNode t num\n | _ -> []\n\nlet rec countLeaf node =\n match node with\n | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t\n | Node(Leaf(a) :: t) :: tail -> countLeaf tail\n | _ -> 0\n\nlet rec countSpruce spruce =\n match spruce with\n | Node (Leaf(a) :: t) :: tail ->\n let num = countLeaf t in\n if (num == 3 || num == 0) then \n countSpruce t && countSpruce tail\n else false\n | _ -> true\n\nlet printLeaf leaf = \n match leaf with\n | Leaf(a) -> print_string \"[Leaf : \";print_int a; print_string \"]\"\n | _ -> print_string \" \"\n\nlet rec printNode node = \n match node with\n | Node (h :: t) :: tail -> \n print_string \"[Node : \";printLeaf h; printNode t;print_string\"]\";\n printNode tail\n | _ -> print_string \" \"\n\nlet n = read_int()\nlet rec numList k =\n if (k < n) then \n let m = read_int() in\n m :: (numList (k+1))\n else []\n\nlet pairList = makePairList (numList 1) 2\n\nlet newSpruce =\n Node (Leaf(1) :: (makeNode pairList 1)) :: []\n\n\nlet _ = \n if (countSpruce newSpruce) then print_string \"Yes\"\n else print_string \"No\"\n"}, {"source_code": "type spruce = Leaf of int\n | Node of spruce list\n\nlet rec split num str = \n match str with\n | \"\" -> []\n | s ->\n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one) ::(returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one) :: []\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\n\nlet rec makePairList numList num =\n match numList with\n | h :: t -> (h, num) :: (makePairList t (num+1))\n | _ -> []\n\nlet rec makeNode pairList num =\n match pairList with\n | (a,b) :: t -> \n if (num == a) then \n Node (Leaf(b) :: (makeNode t b)) :: (makeNode t num)\n else makeNode t num\n | _ -> []\n\nlet rec countLeaf node =\n match node with\n | Node(Leaf(a) :: []) ::t -> 1 + countLeaf t\n | Node(Leaf(a) :: t) :: tail -> countLeaf tail\n | _ -> 0\n\nlet rec checkNotAllNode node =\n match node with\n | Node (Leaf(b) :: []) :: tail -> true\n | Node (Leaf(a) :: t) :: [] -> false\n | Node (Leaf(a) :: t) :: tail -> checkNotAllNode tail\n | _ -> true\n\nlet rec countSpruce spruce =\n match spruce with\n | Node (Leaf(a) :: t) :: tail ->\n let num = countLeaf t in\n if (num == 3 || num == 0) && (checkNotAllNode t == true) then \n countSpruce t && countSpruce tail\n else false\n | _ -> true\n\nlet printLeaf leaf = \n match leaf with\n | Leaf(a) -> print_string \"[Leaf : \";print_int a; print_string \"]\"\n | _ -> print_string \" \"\n\nlet rec printNode node = \n match node with\n | Node (h :: t) :: tail -> \n print_string \"[Node : \";printLeaf h; printNode t;print_string\"]\";\n printNode tail\n | _ -> print_string \" \"\n\nlet n = read_int()\nlet rec numList k =\n if (k < n) then \n let m = read_int() in\n m :: (numList (k+1))\n else []\n\nlet pairList = makePairList (numList 1) 2\n\nlet newSpruce =\n Node (Leaf(1) :: (makeNode pairList 1)) :: []\n\nlet _ = \n if (countSpruce newSpruce) then print_string \"Yes\"\n else print_string \"No\""}], "src_uid": "69edc72ec29d4dd56751b281085c3591"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print str = Printf.printf \"%s\\n\" str\n\nlet check int n =\n if int >= n\n then\n true\n else\n false\n\nlet () = \n let n = read () in\n let rec loop i quart half = \n if i < n\n then\n let cash = read () in\n match cash with\n | 25 -> loop (i + 1) (quart + 1) half\n | 50 -> \n if check quart 1\n then \n loop (i + 1) (quart - 1) (half + 1)\n else\n print \"NO\"\n | 100 -> \n if check half 1 && check quart 1\n then \n loop (i + 1) (quart - 1) (half - 1)\n else\n if check quart 3\n then\n loop (i + 1) (quart - 3) half\n else\n print \"NO\"\n else\n print \"YES\"\n in loop 0 0 0", "positive_code": [{"source_code": "(* Codeforces 349 A Cinema Line *)\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);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec can_change l n50 n25 = match l with\n\t| [] -> \"YES\"\n\t| h :: t -> match h with\n\t\t\t| 25 -> can_change t n50 (n25 + 1)\n\t\t\t| 50 -> if n25 ==0 then \"NO\" else can_change t (n50 +1) (n25 -1)\n\t\t\t| 100 -> if (2 * n50 + n25 < 3) || (n25 == 0)then \"NO\"\n\t\t\t\t\telse if n50 >0 then can_change t (n50 -1) (n25 -1)\n\t\t\t\t\telse can_change t n50 (n25 -3)\n\t\t\t| _ -> \"Error, wrong n\";;\n\nlet main() =\n\tlet n = gr() in\n\tlet l = readlist (n) [] in\n\tlet li = List.rev l in\n\tlet ans = can_change li 0 0 in\n\tbegin\n\t\tprint_string (ans ^ \"\\n\")\n\tend;;\n\nmain();;"}], "negative_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print str = Printf.printf \"%s\\n\" str\n\nlet check int n =\n if int >= n\n then\n true\n else\n false\n\nlet () = \n let n = read () in\n let rec loop i quart half = \n if i < n\n then\n let cash = read () in\n match cash with\n | 25 -> loop (i + 1) (quart + 1) half\n | 50 -> \n if check quart 1\n then \n loop (i + 1) (quart - 1) (half + 1)\n else\n print \"NO\"\n | 100 -> \n if check half 1 && check quart 1 || check quart 3\n then \n loop (i + 1) (quart - 1) (half - 1)\n else\n if check quart 3\n then\n loop (i + 1) (quart - 3) half\n else\n print \"NO\"\n else\n print \"YES\"\n in loop 0 0 0"}, {"source_code": "(* Codeforces 349 A Cinema Line *)\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);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec can_change l n50 n25 = match l with\n\t| [] -> \"YES\"\n\t| h :: t -> match h with\n\t\t\t| 25 -> can_change t n50 (n25 + 1)\n\t\t\t| 50 -> if n25 ==0 then \"NO\" else can_change t (n50 +1) (n25 -1)\n\t\t\t| 100 -> if (2 * n50 + n25 < 3) || (n50 == 0)then \"NO\"\n\t\t\t\t\telse if n50 >0 then can_change t (n50 -1) (n25 -1)\n\t\t\t\t\telse can_change t n50 (n25 -3)\n\t\t\t| _ -> \"Error, wrong n\";;\n\nlet main() =\n\tlet n = gr() in\n\tlet l = readlist (n) [] in\n\tlet li = List.rev l in\n\tlet ans = can_change li 0 0 in\n\tbegin\n\t\tprint_string (ans ^ \"\\n\")\n\tend;;\n\nmain();;"}], "src_uid": "63b20ab2993fddf2cc469c4c4e8027df"} {"source_code": "let list_init n f =\n let rec read_input n new_list =\n if n > 0\n then\n let new_element = f() in\n read_input (n - 1) (new_element :: new_list)\n else\n List.rev new_list\n in read_input n []\n\nlet room_data n = list_init n (fun i -> Scanf.scanf \"%d %d \" (fun s0 s1 -> (s0, s1)))\n\nlet input () =\n let number_of_rooms = Scanf.scanf \"%d \" (fun n -> n) in\n room_data number_of_rooms\n\nlet solve list = List.length(List.filter(fun (a, b) -> b - a >= 2) list)\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()));;\n", "positive_code": [{"source_code": "let list_init n f =\n let rec read_input n new_list = \n if n > 0\n then\n let new_element = f() in\n read_input (n - 1) (new_element :: new_list)\n else\n List.rev new_list\n in read_input n []\n\nlet room_data n = list_init n (fun i -> Scanf.scanf \"%d %d \" (fun s0 s1 -> (s0, s1)))\n\nlet input () = \n let number_of_rooms = Scanf.scanf \"%d \" (fun n -> n) in\n room_data number_of_rooms\n\nlet solve list = List.length(List.filter(fun (a, b) -> b - a >= 2) list)\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input()))"}, {"source_code": "let read_int () =\n Scanf.scanf \" %d\" (fun x -> x)\n\nlet rec solve n ak =\n if n = 0 then\n ak\n else\n let p = read_int () in\n let q = read_int () in\n if q - p < 2 then\n solve (n - 1) ak\n else\n solve (n - 1) (ak + 1)\n\nlet () =\n let n = read_int () in\n Printf.printf \"%d\" (solve n 0)\n\n"}, {"source_code": "open Printf\ntype room = R of int*int\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x) in\nlet read_int () = Scanf.scanf \"%d %d \" ( fun x y -> R(x,y)) in\nlet a = Array.init n (fun i -> read_int ()) in\nlet f = function\n | R (p,q) -> if q-p >=2 then true else false\nin Array.to_list a |>List.filter (fun x -> f x) |> List.length |> printf \"%d\\n\"\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = \n let x = read_int () and y = read_int () in\n (x, y)\n\n\nlet () =\n let n = read_int () in\n let a = Array.init n (fun _ -> read_pair ()) in\n\n print_int (Array.fold_left (fun acc pair -> if (fst(pair) + 2 <= snd(pair)) then acc + 1 else acc) 0 a);\n print_newline ();\n"}], "negative_code": [], "src_uid": "2a6c457012f7ceb589b3dea6b889f7cb"} {"source_code": "let [x; a; b] = List.map (Int64.of_string) (Str.split (Str.regexp \" \") (read_line ()));; \nlet k = ref (Int64.div a x);;\nif ((Int64.mul !k x) < a) then k := Int64.add !k 1L;;\nlet t = Int64.sub b (Int64.mul x !k) and ans = ref 0L;;\nif t >= 0L then\tans := Int64.add (Int64.div t x) 1L;;\nprint_string (Int64.to_string !ans);; \n", "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 c = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let a = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let quot x y =\n let d = x /| y in\n let x' = d *| y in\n if x' <= x\n then d\n else d -| 1L\n in\n let res = quot b c -| quot (a -| 1L) c in\n Printf.printf \"%Ld\\n\" res\n"}], "negative_code": [], "src_uid": "98de093d78f74273e0ac5c7886fb7a41"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let m = read_int () in\n let k = read_int () in\n\n let cells = Array.make (n*m) (0,0) in\n\n let next (x,y) = \n if x land 1 = 1 (* left to right *) then\n if y1 then (x,y-1) else (x+1,1)\n in\n\n let rec loop i p = if fst p = n+1 then () else (\n cells.(i) <- p;\n loop (i+1) (next p)\n )\n in\n\n loop 0 (1,1);\n \n let small_size = (n*m)/k in\n let big_size = small_size+1 in\n\n(* \n let rec find_mult remain sc = if remain=0 then sc else\n if remain mod big_size = 0 then sc else\n\tfind_mult (remain-small_size) (sc+1)\n in\n*)\n\n let rec find_count c = \n if c*small_size + (k-c)*big_size = n*m then c else find_count (c+1)\n in\n\n let scount = find_count 1 in\n\n let bcount = (n*m - scount * small_size)/big_size in\n\n if scount+bcount <> k then failwith \"count wrong\";\n\n let rec loop i p = if i=k then () else\n if ix);;\nlet n=read_int();;\nlet m=read_int();;\nlet k=read_int();;\n\nlet tab=Array.make (k+1) [];;\nlet a=(n*m)/k;;\n\nlet suivant i j s=\n if (s=\"droite\")&&(j1) then (i,j-1,s)\n else (i+1,j,\"droite\");;\n \nlet i=ref 1;;\nlet j=ref 0;;\nlet s=ref \"droite\";;\n\nfor l=1 to k-1 do\n for o=1 to a do\n let (x,y,z)=suivant (!i) (!j) (!s) in\n i:=x;\n j:=y;\n s:=z;\n tab.(l)<-(!i,!j)::tab.(l)\n done\ndone;;\nfor o=1 to a+((n*m) mod k) do\n let (x,y,z)=suivant (!i) (!j) (!s) in\n i:=x;\n j:=y;\n s:=z;\n tab.(k)<-(!i, !j)::tab.(k)\ndone;;\nlet rec taille=function\n|[]->0\n|(_,_)::t->1+taille t;;\nlet rec print_list=function\n|[]->print_newline()\n|(h,g)::t->Printf.printf \"%d %d \" h g;print_list t;;\nfor i=1 to k do\n Printf.printf \"%d \" (taille tab.(i));\n print_list tab.(i)\ndone;;"}], "negative_code": [], "src_uid": "779e73c2f5eba950a20e6af9b53a643a"} {"source_code": "open Printf open Scanf\nmodule Lib = struct\n let i32,i64,ist = Int64.(to_int,of_int,to_string)\n let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n let labs = Int64.abs\n let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n let (+=) r v = r := !r + v\n let (-=) r v = r := !r - v\n let ( *= ) r v = r := !r * v\n let (/=) r v = r := !r / v\n let (%=) r v = r := !r % v\n let max_i64_lim,min_i64_lim = Int64.(max_int,min_int)\n let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L\n (* math *)\n let ceildiv p q = (p+q-1L) / q\n let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n let lcm m n = m / gcd m n * n\n module Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let slen s = String.length s\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n,k = g2 0 in\n let a = iia n in\n let s = scanf \" %s\" @@ id in\n let r =\n let r = ref [] in\n let now = ref s.[0] in\n let cnt = ref 1L in\n let dmgs = ref [a.(0)] in\n String.iteri (fun i c ->\n if i=0 then ()\n else (\n if !now = c then (\n cnt += 1L;\n dmgs := a.(i) :: !dmgs;\n ) else (\n r := (List.sort (rv compare) !dmgs) :: !r;\n dmgs := a.(i) :: [];\n cnt := 1L;\n );\n now := c\n )\n ) s;\n if !cnt <> 0L then r := (List.sort (rv compare) !dmgs) :: !r;\n List.rev @@ !r\n in\n (* print_list (fun s -> string_of_list ist s ^ \"\\n\") r; *)\n List.fold_left (fun sum ls ->\n if llen ls <= k then (\n sum + List.fold_left (+) 0L ls\n ) else (\n let s = ref 0L in\n List.iteri (fun i v -> if i64 i < k then s += v) ls;\n sum + !s\n )\n ) 0L r |> printf \"%Ld\"\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let rv f p q = f q p\nlet rec fix f x = f (fix f) x\nlet (++),( ** ),(--) = Int64.(add,mul,sub)\n;;\nScanf.(Array.(scanf \" %d %d\" @@ fun n k ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n let s = scanf \" %s\" @@ fun v -> v in\n let sects = fix (fun f i ls all ->\n if i=0 then\n f (i+1) (a.(i)::ls) all\n else if i=n then\n if List.length ls <> 0 then (List.sort (rv compare) ls)::all\n else all\n else\n if s.[i] = s.[i-1] then\n f (i+1) (a.(i)::ls) all\n else\n f (i+1) [a.(i)] ((List.sort (rv compare) ls)::all)\n ) 0 [] []\n in\n Printf.printf \"%Ld\" @@\n List.fold_left (fun sum ls ->\n if List.length ls <= k then\n sum ++ List.fold_left (++) 0L ls\n else\n sum ++ snd (List.fold_left (fun (i,sum) v ->\n if i\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n let b =\n let s = scanf \" %s\" @@ fun v -> v in\n init n (fun i -> s.[i])\n in\n let sects =\n let _,_,ls,all = fold_left (fun (i,prev,ls,all) c ->\n if i=0 then\n (i+1,c,a.(i)::ls,all)\n else\n if prev=c then\n (i+1,c,a.(i)::ls,all)\n else\n (i+1,c,[a.(i)],(List.sort (rv compare) ls)::all)\n ) (0,'_',[],[]) b\n in\n if List.length ls <> 0 then (List.sort (rv compare) ls)::all\n else all\n in\n Printf.printf \"%Ld\" @@\n List.fold_left (fun sum ls ->\n if List.length ls <= k then\n sum ++ List.fold_left (++) 0L ls\n else\n sum ++ snd (List.fold_left (fun (i,sum) v ->\n if i\n let a = init n (fun _ -> scanf \" %d\" @@ fun v -> v) in\n let s = scanf \" %s\" @@ fun v -> v in\n let sects = fix (fun f i ls all ->\n if i=0 then\n f (i+1) (a.(i)::ls) all\n else if i=n then\n if List.length ls <> 0 then (List.sort (rv compare) ls)::all\n else all\n else\n if s.[i] = s.[i-1] then\n f (i+1) (a.(i)::ls) all\n else\n f (i+1) [a.(i)] ((List.sort (rv compare) ls)::all)\n ) 0 [] []\n in\n print_int @@\n List.fold_left (fun sum ls ->\n if List.length ls <= k then\n sum + List.fold_left (+) 0 ls\n else\n sum + snd (List.fold_left (fun (i,sum) v ->\n if i m | m,n -> gcd n (m mod n)\n let lcm m n = m / gcd m n * n\n module Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let slen s = String.length s\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n,k = g2 0 in\n let a = iia n in\n let s = scanf \" %s\" @@ id in\n let r =\n let r = ref [] in\n let now = ref s.[0] in\n let cnt = ref 1L in\n let dmgs = ref [a.(0)] in\n String.iteri (fun i c ->\n if i=0 then ()\n else (\n if !now = c then (\n cnt += 1L;\n dmgs := a.(i) :: !dmgs;\n ) else (\n r := (List.sort (rv compare) !dmgs) :: !r;\n dmgs := a.(i) :: [];\n cnt := 1L;\n );\n now := c\n )\n ) s;\n if !cnt <> 0L then r := (List.sort (rv compare) !dmgs) :: !r;\n List.rev @@ !r\n in\n print_list (fun s -> string_of_list ist s ^ \"\\n\") r;\n List.fold_left (fun sum ls ->\n if llen ls <= k then (\n sum + List.fold_left (+) 0L ls\n ) else (\n let s = ref 0L in\n List.iteri (fun i v -> if i64 i < k then s += v) ls;\n sum + !s\n )\n ) 0L r |> printf \"%Ld\"\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "aa3b5895046ed34e89d5fcc3264b3944"} {"source_code": "let ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( ** ) = Int64.mul\nlet ( // ) = Int64.div\n\nlet read_int _ = Scanf.scanf \" %d \" (fun n -> n)\nlet read_int64 _ = read_int () |> Int64.of_int\n\nlet () =\n let n = read_int () in\n let z = read_int64 () in\n let xs = Array.init n read_int64 in\n Array.fast_sort Int64.compare xs;\n let k = (n + 1) / 2 in\n let rec iter l r res =\n if r >= n || l >= k then\n res\n else if xs.(r) -- xs.(l) >= z then\n iter (l+1) (r+1) (res+1)\n else\n iter l (r+1) res in\n print_int (iter 0 k 0);\n print_newline ()\n\n\n", "positive_code": [{"source_code": "let ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( ** ) = Int64.mul\nlet ( // ) = Int64.div\n\n\nlet () =\n let (n, z) = read_line ()\n |> Str.split (Str.regexp \" \")\n |> (fun [a; b] -> (int_of_string a, Int64.of_string b)) in\n let xs = read_line ()\n |> Str.split (Str.regexp \" \")\n |> Array.of_list\n |> Array.map Int64.of_string in\n Array.fast_sort Int64.compare xs;\n let k = (n + 1) / 2 in\n let l = ref 0 in\n let r = ref k in\n let res = ref 0 in\n while !l < k && !r < n do\n if xs.(!r) -- xs.(!l) >= z then\n (l := !l + 1;\n res := !res + 1;\n );\n r := !r + 1\n done;\n print_int !res;\n print_newline ()\n\n\n"}], "negative_code": [], "src_uid": "b063660572a78f25525656332a1782a8"} {"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 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 ps = make 3 (0L,0L) in\n repi 0 2 (fun i -> ps.(i) <- g2 0);\n let px = init 3 (fun i -> ps.(i)) in\n sort compare px;\n let py = init 3 (fun i -> ps.(i)) in\n sort (fun (p,q) (r,s) -> compare q s) py;\n let r = ref [] in\n let xx i = fst px.(i) in\n let yx i = snd px.(i) in\n rep (xx 0) (xx 1) (fun x ->\n r := (x, yx 0) :: !r\n );\n rep (xx 1) (xx 2) (fun x ->\n r := (x, yx 2) :: !r\n );\n rep (min (yx 0) (yx 1)) (max (yx 0) (yx 1)) (fun y ->\n r := (xx 1, y) :: !r\n );\n rep (min (yx 2) (yx 1)) (max (yx 2) (yx 1)) (fun y ->\n r := (xx 1, y) :: !r\n );\n r := List.sort_uniq compare !r;\n printf \"%Ld\\n\" @@ llen !r;\n List.iter (fun (p,q) -> printf \"%Ld %Ld\\n\" p q) !r\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "open Array\nlet p = init 3 (fun _ ->\n Scanf.scanf \" %d %d\" @@ fun u v -> u,v)\nlet () =\n let dmin = ref max_int in\n let dp,dq = ref 0,ref 0 in\n let _ =\n init 1001 (fun y ->\n init 1001 (fun x ->\n let w = fold_left (fun s (p,q) -> s + abs (x-p) + abs (y-q)) 0 p\n in if w < !dmin then (dmin := w; dp := x; dq := y)))\n in\n let res = ref [] in\n let line (p,q) (r,s) =\n let [|p,q;r,s|] = [p,q;r,s] |> List.sort compare |> of_list in\n for x=p to r do\n res := (x,q) :: !res\n done;\n for y=min q s to max q s do\n res := (r,y) :: !res\n done\n in\n let d = !dp,!dq in\n iter (fun t -> line t d) p;\n let res = List.sort_uniq compare !res in\n Printf.(\n printf \"%d\\n\" @@ List.length res;\n List.iter (fun (p,q) ->\n printf \"%d %d\\n\" p q\n ) res\n )\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "1a358e492dfd7e226138ea64e432c180"} {"source_code": "\nlet rec reverse s i j =\n if i < j then\n begin\n let c = s.[i] in\n s.[i] <- s.[j];\n s.[j] <- c;\n reverse s (i+1) (j-1);\n end\n;;\n\nlet get_ans () = \n let s = read_line () in\n let () = print_string s in\n let () = reverse s 0 ((String.length s) - 1) in\n let () = print_string s in\n let () = print_string \"\\n\" in\n ()\n;;\n\nlet () = get_ans ()\n", "positive_code": [{"source_code": "let s = Scanf.scanf \"%s\" (fun x->x) in\n print_string s;\n for i = String.length s - 1 downto 0 do print_char s.[i] done\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n \nlet () =\n let n = read_string () in\n\n let l = String.length n in\n\n printf \"%s\" n;\n \n for i=l-1 downto 0 do\n printf \"%c\" n.[i]\n done;\n\n print_newline()\n"}], "negative_code": [], "src_uid": "bcf75978c9ef6202293773cf533afadf"} {"source_code": "let print_tab tab w =\n print_endline w\n\nlet main () =\n let n = Scanf.scanf \"%d\" (fun i -> i) in\n let tab = Array.make (n-1) 0 in\n let tab' = Array.make (n-1) 0 in\n let j = ref 0 in\n for i = 1 to n do\n let a = Scanf.scanf \" %d\" (fun i -> i) in\n if a <> 0 then (tab.(!j) <- a;incr j);\n done;\n let j = ref 0 in\n for i = 1 to n do\n let a = Scanf.scanf \" %d\" (fun i -> i) in\n if a <> 0 then (tab'.(!j) <- a;incr j);\n done;\n let i = ref (-1) and y = tab.(0) in\n let flag = ref true in\n Array.iteri (fun j x -> if x = y then i := j) tab';\n for j = 0 to n-2 do\n flag := !flag && (tab'.((!i + j) mod (n-1)) = tab.(j));\n done;\n print_string (if !flag then \"YES\" else \"NO\");;\n\nmain ()\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let b = Array.init n (fun _ -> read_int()) in \n\n let fill_x a =\n let x = Array.make (n-1) 0 in\n let rec loop i j = if i=n then () else\n\tif a.(i) = 0 then loop (i+1) j\n\telse (\n\t x.(j) <- a.(i);\n\t loop (i+1) (j+1)\n\t)\n in\n loop 0 0;\n let rec find1 i = if x.(i) = 1 then i else find1 (i+1) in\n (x, find1 0)\n in\n\n let (ax,ai) = fill_x a in\n let (bx,bi) = fill_x b in\n\n let ans = forall 0 (n-2) (fun i -> ax.((ai+i) mod (n-1)) = bx.((bi+i) mod (n-1))) in\n\n if ans then printf \"YES\\n\" else printf \"NO\\n\"\n"}], "negative_code": [], "src_uid": "846681af4b4b6b29d2c9c450a945de90"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let q = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let t = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let a = Array.make (n + 1) 0 in\n for i = 0 to n - m do\n let b = ref true in\n\tfor j = 0 to m - 1 do\n\t if s.[i + j] <> t.[j]\n\t then b := false\n\tdone;\n\tif !b\n\tthen a.(i + 1) <- a.(i) + 1\n\telse a.(i + 1) <- a.(i)\n done;\n for i = 1 to q do\n let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let res =\n\tlet r = r - m + 1 in\n\t if l <= r\n\t then a.(r) - a.(l - 1)\n\t else 0\n in\n\tPrintf.printf \"%d\\n\" res\n done;\n", "positive_code": [{"source_code": "\nmodule type StringView = sig\n type t\n val length: t -> int\n val get: t -> int -> char\nend\n \nmodule MakeStringViewUtil(S: StringView) = struct\n let iteri (f: int -> char -> unit) (src: S.t): unit =\n for i = 0 to (S.length src - 1) do f i (S.get src i) done\nend\n \nmodule MakeStringViewEqual(A: StringView)(B: StringView) = struct\n let equal (a: A.t) (b: B.t) =\n if A.length a != B.length b then false\n else\n let rec f i =\n if i = A.length a then true\n else if A.get a i != B.get b i then false\n else f (i + 1)\n in f 0\nend\n\nmodule MakeStringTruncated(S: StringView) = struct\n type t = S.t * int * int\n let create src l r = (src, l, r)\n let length (_, l, r) = r - l\n let get (src, l, _) i = S.get src (l + i)\nend\n\nmodule StringTruncated = MakeStringTruncated(String)\n\nmodule Match = struct\n type t = int\n let compare = compare\nend\n\nmodule MatchSet = Set.Make(Match)\n\nmodule MakeStringFindMultiple(S: StringView) = struct\n \n let do_find (callback: int -> unit) (term: string) (src: S.t): unit =\n let tlen = String.length term in\n\n let module STruncated = MakeStringTruncated(S) in\n let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in\n let module SUtil = MakeStringViewUtil(S) in\n\n SUtil.iteri (fun i c ->\n if i <= S.length src - tlen &&\n c = String.get term 0 then\n if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))\n then callback i\n ) src\n\n let count (term: string) (src: S.t): int =\n let ret = ref 0 in\n do_find (fun _ -> ret := !ret + 1) term src;\n !ret\n \n let all_matches (term: string) (src: S.t): MatchSet.t =\n let ret = ref MatchSet.empty in\n do_find (fun i -> ret := MatchSet.add i !ret) term src;\n !ret\nend\n\nmodule StringFindMultiple = MakeStringFindMultiple(String)\nmodule StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)\n\nlet find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =\n let ret = Hashtbl.find_all tbl key in\n match ret with\n | [a] -> Some a\n | _ -> None\n \nmodule MakeSetBipart(S: Set.S) = struct\n let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =\n let (_, present, ge) = S.split l src in\n let ge = if present then S.add l ge else ge in\n let (le, _, _) = S.split r ge in\n le\nend\n\nmodule MatchSetBipart = MakeSetBipart(MatchSet)\n \nlet _ =\n let n, m, q = Scanf.scanf \" %d %d %d\" (fun x y z -> x, y, z) in\n let s, t = Scanf.scanf \" %s %s\" (fun x y -> x, y) in\n let matches = StringFindMultiple.all_matches t s in\n (* let cache = Hashtbl.create 102539 in *)\n for i = 1 to q do\n let entry = Scanf.scanf \" %d %d\" (fun x y -> x, y) in\n let l, r = entry in\n matches |>\n MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>\n MatchSet.cardinal |>\n string_of_int |> print_endline\n (* let strunc = StringTruncated.create s (l - 1) r in\n * StringTruncatedFindMultiple.count t strunc\n * |> string_of_int |> print_endline *)\n done\n"}, {"source_code": "\nmodule type StringView = sig\n type t\n val length: t -> int\n val get: t -> int -> char\nend\n \nmodule MakeStringViewUtil(S: StringView) = struct\n let iteri (f: int -> char -> unit) (src: S.t): unit =\n for i = 0 to (S.length src - 1) do f i (S.get src i) done\nend\n \nmodule MakeStringViewEqual(A: StringView)(B: StringView) = struct\n let equal (a: A.t) (b: B.t) =\n if A.length a != B.length b then false\n else\n let rec f i =\n if i = A.length a then true\n else if A.get a i != B.get b i then false\n else f (i + 1)\n in f 0\nend\n\nmodule MakeStringTruncated(S: StringView) = struct\n type t = S.t * int * int\n let create src l r = (src, l, r)\n let length (_, l, r) = r - l\n let get (src, l, _) i = S.get src (l + i)\nend\n\nmodule StringTruncated = MakeStringTruncated(String)\n\nmodule Match = struct\n type t = int\n let compare = compare\nend\n\nmodule MatchSet = Set.Make(Match)\n\nmodule MakeStringFindMultiple(S: StringView) = struct\n \n let do_find (callback: int -> unit) (term: string) (src: S.t): unit =\n let tlen = String.length term in\n\n let module STruncated = MakeStringTruncated(S) in\n let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in\n let module SUtil = MakeStringViewUtil(S) in\n\n SUtil.iteri (fun i c ->\n if i <= S.length src - tlen &&\n c = String.get term 0 then\n if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))\n then callback i\n ) src\n\n let count (term: string) (src: S.t): int =\n let ret = ref 0 in\n do_find (fun _ -> ret := !ret + 1) term src;\n !ret\n \n let all_matches (term: string) (src: S.t): MatchSet.t =\n let ret = ref MatchSet.empty in\n do_find (fun i -> ret := MatchSet.add i !ret) term src;\n !ret\nend\n\nmodule StringFindMultiple = MakeStringFindMultiple(String)\nmodule StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)\n\nlet find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =\n let ret = Hashtbl.find_all tbl key in\n match ret with\n | [a] -> Some a\n | _ -> None\n \nmodule MakeSetBipart(S: Set.S) = struct\n let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =\n let (_, present, ge) = S.split l src in\n let ge = if present then S.add l ge else ge in\n let (le, _, _) = S.split r ge in\n le\nend\n\nmodule type OrderedContainer = sig\n type t\n type elt\n val length: t -> int\n val get: int -> t -> elt\nend\n\nmodule MakeBisearch(C: OrderedContainer) = struct\n let find_first_index_satisfying (callback: C.elt -> bool) (cont: C.t): int option =\n let rec f l r =\n if l >= r\n then if l = r && C.get l cont |> callback then Some l else None\n else\n let m = (l + r) / 2 in\n if C.get m cont |> callback then f l m else f (m + 1) r\n in f 0 (C.length cont - 1)\nend\n\nmodule MakeSetToOrderedArray(S: Set.S)(E: Set.OrderedType with type t = S.elt) = struct\n let convert (src: S.t): E.t array =\n let l = S.elements src in\n let ret = Array.of_list l in\n Array.sort E.compare ret;\n ret\nend\n\nmodule MatchArray = struct\n type elt = Match.t\n type t = elt array\n let length = Array.length\n let get i a = Array.get a i\nend\n\nmodule MatchSetBipart = MakeSetBipart(MatchSet)\nmodule MatchSetToOrderedArray = MakeSetToOrderedArray(MatchSet)(Match)\nmodule MatchArrayBisearch = MakeBisearch(MatchArray)\n \nlet option_get ~(default: 'a) (x: 'a option): 'a =\n match x with | Some x -> x | None -> default\n \nlet _ =\n let n, m, q = Scanf.scanf \" %d %d %d\" (fun x y z -> x, y, z) in\n let s, t = Scanf.scanf \" %s %s\" (fun x y -> x, y) in\n let matches_set = StringFindMultiple.all_matches t s in\n let matches = MatchSetToOrderedArray.convert matches_set in\n (* let cache = Hashtbl.create 102539 in *)\n for i = 1 to q do\n let entry = Scanf.scanf \" %d %d\" (fun x y -> x, y) in\n let l, r = entry in\n let lb = matches |>\n MatchArrayBisearch.find_first_index_satisfying (fun x -> x >= l - 1) |>\n option_get ~default:(Array.length matches) in\n let rb = matches |>\n MatchArrayBisearch.find_first_index_satisfying (fun x -> x > r - String.length t) |>\n option_get ~default:(Array.length matches) in\n (* Printf.printf \"-:%d ::%d\\n\" lb rb; *)\n rb - lb |> max 0 |> string_of_int |> print_endline\n \n (* matches |>\n * MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>\n * MatchSet.cardinal |>\n * string_of_int |> print_endline *)\n (* let strunc = StringTruncated.create s (l - 1) r in\n * StringTruncatedFindMultiple.count t strunc\n * |> string_of_int |> print_endline *)\n done\n"}], "negative_code": [{"source_code": "\nmodule type StringView = sig\n type t\n val length: t -> int\n val get: t -> int -> char\nend\n \nmodule MakeStringViewUtil(S: StringView) = struct\n let iteri (f: int -> char -> unit) (src: S.t): unit =\n for i = 0 to (S.length src - 1) do f i (S.get src i) done\nend\n \nmodule MakeStringViewEqual(A: StringView)(B: StringView) = struct\n let equal (a: A.t) (b: B.t) =\n if A.length a != B.length b then false\n else\n let rec f i =\n if i = A.length a then true\n else if A.get a i != B.get b i then false\n else f (i + 1)\n in f 0\nend\n\nmodule MakeStringTruncated(S: StringView) = struct\n type t = S.t * int * int\n let create src l r = (src, l, r)\n let length (_, l, r) = r - l\n let get (src, l, _) i = S.get src (l + i)\nend\n\nmodule StringTruncated = MakeStringTruncated(String)\n\nmodule Match = struct\n type t = int\n let compare = compare\nend\n\nmodule MatchSet = Set.Make(Match)\n\nmodule MakeStringFindMultiple(S: StringView) = struct\n \n let do_find (callback: int -> unit) (term: string) (src: S.t): unit =\n let tlen = String.length term in\n\n let module STruncated = MakeStringTruncated(S) in\n let module EqStrSTrunc = MakeStringViewEqual(String)(STruncated) in\n let module SUtil = MakeStringViewUtil(S) in\n\n SUtil.iteri (fun i c ->\n if i <= S.length src - tlen &&\n c = String.get term 0 then\n if EqStrSTrunc.equal term (STruncated.create src i (i + tlen))\n then callback i\n ) src\n\n let count (term: string) (src: S.t): int =\n let ret = ref 0 in\n do_find (fun _ -> ret := !ret + 1) term src;\n !ret\n \n let all_matches (term: string) (src: S.t): MatchSet.t =\n let ret = ref MatchSet.empty in\n do_find (fun i -> ret := MatchSet.add i !ret) term src;\n !ret\nend\n\nmodule StringFindMultiple = MakeStringFindMultiple(String)\nmodule StringTruncatedFindMultiple = MakeStringFindMultiple(StringTruncated)\n\nlet find_opt (tbl: ('k, 'v) Hashtbl.t) (key: 'k): 'v option =\n let ret = Hashtbl.find_all tbl key in\n match ret with\n | [a] -> Some a\n | _ -> None\n \nmodule MakeSetBipart(S: Set.S) = struct\n let bipart ((l, r): S.elt * S.elt) (src: S.t): S.t =\n let (_, present, ge) = S.split l src in\n let ge = if present then S.add l ge else ge in\n let (le, _, _) = S.split r ge in\n le\nend\n\nmodule type OrderedContainer = sig\n type t\n type elt\n val length: t -> int\n val get: int -> t -> elt\nend\n\nmodule MakeBisearch(C: OrderedContainer) = struct\n let find_first_index_satisfying (callback: C.elt -> bool) (cont: C.t): int option =\n let rec f l r =\n if l >= r\n then if l = r && C.get l cont |> callback then Some l else None\n else\n let m = (l + r) / 2 in\n if C.get m cont |> callback then f l m else f (m + 1) r\n in f 0 (C.length cont - 1)\nend\n\nmodule MakeSetToOrderedArray(S: Set.S)(E: Set.OrderedType with type t = S.elt) = struct\n let convert (src: S.t): E.t array =\n let l = S.elements src in\n let ret = Array.of_list l in\n Array.sort E.compare ret;\n ret\nend\n\nmodule MatchArray = struct\n type elt = Match.t\n type t = elt array\n let length = Array.length\n let get i a = Array.get a i\nend\n\nmodule MatchSetBipart = MakeSetBipart(MatchSet)\nmodule MatchSetToOrderedArray = MakeSetToOrderedArray(MatchSet)(Match)\nmodule MatchArrayBisearch = MakeBisearch(MatchArray)\n \nlet option_get ~(default: 'a) (x: 'a option): 'a =\n match x with | Some x -> x | None -> default\n \nlet _ =\n let n, m, q = Scanf.scanf \" %d %d %d\" (fun x y z -> x, y, z) in\n let s, t = Scanf.scanf \" %s %s\" (fun x y -> x, y) in\n let matches_set = StringFindMultiple.all_matches t s in\n let matches = MatchSetToOrderedArray.convert matches_set in\n (* let cache = Hashtbl.create 102539 in *)\n for i = 1 to q do\n let entry = Scanf.scanf \" %d %d\" (fun x y -> x, y) in\n let l, r = entry in\n let lb = matches |>\n MatchArrayBisearch.find_first_index_satisfying (fun x -> x >= l - 1) |>\n option_get ~default:0 in\n let rb = matches |>\n MatchArrayBisearch.find_first_index_satisfying (fun x -> x <= r - String.length t) |>\n option_get ~default:(-1) in\n (rb - lb + 1) |> max 0 |> string_of_int |> print_endline\n \n (* matches |>\n * MatchSetBipart.bipart (l - 1, r - String.length t + 1) |>\n * MatchSet.cardinal |>\n * string_of_int |> print_endline *)\n (* let strunc = StringTruncated.create s (l - 1) r in\n * StringTruncatedFindMultiple.count t strunc\n * |> string_of_int |> print_endline *)\n done\n"}], "src_uid": "4cc5a6975d33cee60e53e8f648ec30de"} {"source_code": "let xs, ys, x0, y0, s = Scanf.scanf \"%d %d %d %d %s\" (fun a b c d e -> (a,b,c-1,d-1,e)) ;;\nlet next (x,y) ch = match ch with\n | 'L' -> (x, max 0 (y-1))\n | 'R' -> (x, min (ys-1) (y+1))\n | 'U' -> (max 0 (x-1), y)\n | 'D' -> (min (xs-1) (x+1), y)\nlet v = Array.make_matrix xs ys false ;;\nlet rec f i (x,y) =\n if i < String.length s then (\n let mine =\n if not v.(x).(y) then (\n v.(x).(y) <- true;\n 1\n ) else\n 0\n in\n Printf.printf \"%d \" mine ;\n mine + ( f (i+1) (next (x,y) s.[i]) )\n ) else 0\n;;\nprint_int( xs * ys - f 0 (x0, y0) )\n", "positive_code": [{"source_code": "let new_place (x,y) (x0,y0) l =\n let new_xy = ref (x0,y0) in\n (match l with\n | 'R' -> if y0 < y then new_xy := (x0, y0+1)\n | 'L' -> if y0 > 1 then new_xy := (x0, y0-1)\n | 'U' -> if x0 > 1 then new_xy := (x0-1,y0)\n | 'D' -> if x0 < x then new_xy := (x0+1,y0));\n !new_xy\n\nlet main () =\n let (lim,pos,w) = Scanf.scanf \"%d %d %d %d %s\" (fun i j k l m -> ((i,j),(ref (k,l)),m)) and mat = Array.make_matrix 555 555 true and compt = ref 0 in\n for i = 0 to String.length w - 1 do\n let (a,b) = !pos in\n Printf.printf (if mat.(a).(b) = true\n then (mat.(a).(b) <- false; incr compt; \"1 \")\n else \"0 \");\n pos := new_place lim !pos (w.[i]);\n done;\n Printf.printf \"%d\" ((fst lim) * (snd lim) - !compt);;\n\nmain ();;\n"}, {"source_code": "(* start: 9:58 *)\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x) \n\nlet () = \n let xm = read_int () in\n let ym = read_int () in\n let x0 = read_int () in\n let y0 = read_int () in \n\n let s = read_string () in\n\n let ns = String.length s in\n\n let bomb = Array.make_matrix (xm+1) (ym+1) 1 in\n\n let rec loop x y i times_died =\n if i = ns then times_died else (\n let times_died = times_died + bomb.(x).(y) in\n\tprintf \"%d \" bomb.(x).(y);\n\tbomb.(x).(y) <- 0;\n\tlet (x,y) =\n\t match s.[i] with\n\t | 'U' -> (max 1 (x-1), y)\n\t | 'D' -> (min xm (x+1), y)\n\t | 'L' -> (x, max 1 (y-1))\n\t | 'R' -> (x, min ym (y+1))\n\t | _ -> failwith \"bad char\"\n\tin\n\tloop x y (i+1) times_died\n )\n in \n\n let times_died = loop x0 y0 0 0 in\n\n printf \"%d\\n\" (xm*ym - times_died)\n"}], "negative_code": [], "src_uid": "22bebd448f93c0ff07d2be91e873521c"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\nopen List\n \nlet run () = \n let n = scan_int () in\n let rec f x b =\n if x = 0 then []\n else begin\n let rest = f (x/10) (b * 10) in\n let tmp = (x mod 10) * b in\n if tmp > 0 then tmp :: rest\n else rest\n end in\n let lst = f n 1 in\n printf \"%d\\n\" (List.length lst);\n List.iter (printf \"%d \") lst;\n print_endline \"\"\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then [], 0\n else if x < 10 then [x], 1\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n let z = f (x - (x / y) * y) in\n (x / y) * y :: fst z, 1 + snd z\n;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = re () in\n let m = f n in\n printf \"%d \\n\" (snd m);\n iter (printf \"%d \") (fst m);\n printf \"\\n\"\n;;\n\nlet _ =\n let t = re () in\n for i = 1 to t do\n solve ()\n done\n;;\n\n"}, {"source_code": "(* Codeforces 1352 0 Sum of Round Numbers comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec round_list acc p10 n = match n with\n | 0 -> acc\n | _ -> \n\t\t\tlet r = n mod 10 in\n\t\t\tlet n_acc = if r == 0 then acc else (r*p10) :: acc in\n\t\t\tlet p10 = p10 * 10 in\n\t\t\tlet n = n / 10 in\n\t\t\tround_list n_acc p10 n;;\t\t\t\n \nlet do_one () = \n\tlet n = gr () in\n\tlet lr = round_list [] 1 n in\n\tlet _ = Printf.printf \"%d\\n\" (List.length lr) in\n\tlet _ = printlisti lr in\n\tprint_string \"\\n\";;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [{"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then []\n else if x < 10 then [x]\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n (x / y) * y :: f (x - (x / y) * y)\n;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = re () in\n let m = int_of_float(log10 (float_of_int n)) + 1 in\n printf \"%d \\n\" m;\n iter (printf \"%d \") (f n);\n printf \"\\n\"\n;;\n\nlet _ =\n let t = re () in\n for i = 1 to t do\n solve ()\n done\n;;\n\n"}, {"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then []\n else if x < 10 then [x]\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n (x / y) * y :: f (x - (x / y) * y)\n;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = re () in\n let () = List.iter (printf \"%d \") (f n) in\n printf \"\\n\"\n;;\n"}, {"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then []\n else if x < 10 then [x]\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n (x / y) * y :: f (x - (x / y) * y)\n;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = 4 in\n iter (printf \"%d \") (f n);\n printf \"\\n\"\n;;\n"}, {"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then []\n else if x < 10 then [x]\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n (x / y) * y :: f (x - (x / y) * y)\n;;\n\nlet rec print_list = function\n[] -> print_string \"\\n\"\n| e::l -> print_int e ; print_string \" \" ; print_list l\n\nlet solve () =\n let n = re () in\n print_list (f n)\n;;\n"}, {"source_code": "let re () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nlet rec f x =\n if x = 0 then []\n else if x < 10 then [x]\n else let y = int_of_float (10. ** (float_of_int(int_of_float(log10 (float_of_int x))))) in\n (x / y) * y :: f (x - (x / y) * y)\n;;\n\nopen List\nopen Printf\n\nlet solve () =\n let n = 4 in\n let m = int_of_float(log10 (float_of_int n)) + 1 in\n printf \"%d \\n\" m;\n iter (printf \"%d \") (f n);\n printf \"\\n\"\n;;\n"}], "src_uid": "cd2519f4a7888b2c292f05c64a9db13a"} {"source_code": "let n = read_int()\n\nlet goods = Array.make 2 0 ;;\nlet totals = Array.make 2 0 ;;\n\nlet handle i good bad =\n let total = good + bad in\n let idx = i - 1 in\n Array.set goods idx (Array.get goods idx + good) ;\n Array.set totals idx (Array.get totals idx + total);;\n\nfor i = 1 to n do\n Scanf.scanf \"%d %d %d\\n\" handle\ndone ;;\n\nfor i = 0 to 1 do\n Printf.printf \"%s\\n\" (if (Array.get goods i) >= (Array.get totals i) / 2 then \"LIVE\" else \"DEAD\" );\ndone ;;", "positive_code": [{"source_code": "let read_three () = Scanf.bscanf Scanf.Scanning.stdib \" %d %d %d \" (fun x y z -> (x,y,z))\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let ret = Array.make 2 0 in\n let tot = Array.make 2 0 in\n for i=0 to n-1 do \n let (t,x,y) = read_three() in\n let t = t-1 in\n ret.(t) <- ret.(t) + x;\n tot.(t) <- tot.(t) + 10;\n done;\n for j=0 to 1 do \n if 2*ret.(j) >= tot.(j) then print_string \"LIVE\\n\" else print_string \"DEAD\\n\"\n done\n"}, {"source_code": "let read_three () = Scanf.bscanf Scanf.Scanning.stdib \" %d %d %d \" (fun x y z -> (x,y,z))\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let ret = Array.make 2 0 in\n let tot = Array.make 2 0 in\n for i=0 to n-1 do \n let (t,x,y) = read_three() in\n let t = t-1 in\n\tret.(t) <- ret.(t) + x;\n\ttot.(t) <- tot.(t) + 10;\n done;\n for j=0 to 1 do \n if 2*ret.(j) >= tot.(j) then print_string \"LIVE\\n\" else print_string \"DEAD\\n\"\n done\n"}], "negative_code": [{"source_code": "let n = read_int()\n\nlet goods = Array.make 2 0 ;;\nlet totals = Array.make 2 0 ;;\n\nlet handle i good total =\n let idx = i - 1 in\n Array.set goods idx (Array.get goods idx + good) ;\n Array.set totals idx (Array.get totals idx + total);;\n\nfor i = 1 to n do\n Scanf.scanf \"%d %d %d\\n\" handle\ndone ;;\n\nfor i = 0 to 1 do\n Printf.printf \"%s\\n\" (if (Array.get goods i) >= (Array.get totals i) / 2 then \"LIVE\" else \"DEAD\" );\ndone ;;"}], "src_uid": "1d8870a705036b9820227309d74dd1e8"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int();;\nlet mat=Array.make_matrix (n+1) (m+1) 1;;\nlet is_square a=(int_of_float(sqrt(float_of_int(a)))*int_of_float(sqrt(float_of_int(a)))=a);;\nif n=2 then\n begin\n for j=1 to m do\n mat.(1).(j)<-mat.(1).(j)*3;\n mat.(2).(j)<-mat.(2).(j)*4\n done\n end\nelse\n begin\n if is_square n then () else\n begin\n if n mod 2=1 then\n begin\n for j=1 to m do\n mat.(1).(j)<-mat.(1).(j)*2\n done;\n for j=1 to m do\n mat.(n).(j)<-mat.(n).(j)*(n+1)/2\n done\n end\n else\n begin\n for j=1 to m do\n mat.(n).(j)<-mat.(n).(j)*(n-2)/2\n done\n end\n end\n end;;\n\nif m=2 then\n begin\n for i=1 to n do\n mat.(i).(1)<-mat.(i).(1)*3;\n mat.(i).(2)<-mat.(i).(2)*4\n done\n end\nelse\n begin\n if is_square m then () else\n begin\n if m mod 2=1 then\n begin\n for i=1 to n do\n mat.(i).(1)<-mat.(i).(1)*2\n done;\n for i=1 to n do\n mat.(i).(m)<-mat.(i).(m)*(m+1)/2\n done\n end\n else\n begin\n for i=1 to n do\n mat.(i).(m)<-mat.(i).(m)*(m-2)/2\n done\n end\n end\n end;;\nfor i=1 to n do\n for j=1 to m do\n Printf.printf \"%d \" mat.(i).(j)\n done;\n print_newline()\ndone;;", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix n m 0 in\n let x = Array.make m 2 in\n let y = Array.make n 2 in\n if m = 1\n then x.(0) <- 1\n else if m = 2\n then (\n x.(0) <- 3;\n x.(1) <- 4;\n ) else x.(m - 1) <- m - 2;\n if n = 1\n then y.(0) <- 1\n else if n = 2\n then (\n y.(0) <- 3;\n y.(1) <- 4;\n ) else y.(n - 1) <- n - 2;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\ta.(i).(j) <- y.(i) * x.(j);\n done;\n done;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j);\n done;\n Printf.printf \"\\n\"\n done;\n"}], "negative_code": [], "src_uid": "c80cdf090685d40fd34c3fd082a81469"} {"source_code": "(*********************************************************************************)\n\nlet infty = max_int;;\n\n(*********************************************************************************)\n\ntype overtake_automata = {\n\tmutable missed_sign_count : int;\n\tmutable consequtive_overtake_is_disallowed_count : int;\n};;\n\n(*********************************************************************************)\n\nlet create_overtake_automata () = { \n missed_sign_count = 0; \n consequtive_overtake_is_disallowed_count = 0; \n};;\n\n(*********************************************************************************)\n\ntype speed_automata = {\n mutable missed_sign_count : int;\n mutable current_speed : int;\n mutable speed_limits : int list;\n};;\n\n(*********************************************************************************)\n\nlet create_speed_automata () = { \n missed_sign_count = 0; \n current_speed = 0; \n speed_limits = [ infty ];\n};;\n\n\n(*********************************************************************************)\n\nlet my_read_int () =\n let result = ref 0 in\n begin\n Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun n -> result := n);\n !result\n end\n;;\n\n(*********************************************************************************)\n\nlet rec remove_until_more_or_equal lst value ax =\n match lst with\n | [] -> ([], ax)\n | hd :: tail -> if hd < value \n then remove_until_more_or_equal tail value (ax + 1)\n else (hd :: tail, ax)\n;;\n\n(*********************************************************************************)\n\nlet pop_violated_speed_limits speed_automata =\n let (new_list, count) = remove_until_more_or_equal speed_automata.speed_limits speed_automata.current_speed 0 in\n begin\n speed_automata.missed_sign_count <- speed_automata.missed_sign_count + count;\n speed_automata.speed_limits <- new_list;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_speed_change speed_automata new_speed =\n begin\n speed_automata.current_speed <- new_speed;\n pop_violated_speed_limits speed_automata\n end\n;;\n\n(*********************************************************************************)\n\nlet process_speed_limit speed_automata new_limit = \n begin\n speed_automata.speed_limits <- new_limit :: speed_automata.speed_limits;\n pop_violated_speed_limits speed_automata\n end\n;;\n\n(*********************************************************************************)\n\nlet process_no_speed_limit speed_automata =\n begin\n speed_automata.speed_limits <- [ infty ];\n end\n;;\n\n(*********************************************************************************)\n\nlet process_overtake (overtake_automata : overtake_automata) = \n begin\n overtake_automata.missed_sign_count <- overtake_automata.missed_sign_count + overtake_automata.consequtive_overtake_is_disallowed_count;\n overtake_automata.consequtive_overtake_is_disallowed_count <- 0;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_overtake_is_allowed overtake_automata =\n begin\n overtake_automata.consequtive_overtake_is_disallowed_count <- 0;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_no_overtake_allowed overtake_automata =\n begin\n overtake_automata.consequtive_overtake_is_disallowed_count <- overtake_automata.consequtive_overtake_is_disallowed_count + 1;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_single_event overtake_automata speed_automata evt =\n match evt with\n | 1 -> process_speed_change speed_automata (my_read_int ())\n | 2 -> process_overtake overtake_automata\n | 3 -> process_speed_limit speed_automata (my_read_int ())\n | 4 -> process_overtake_is_allowed overtake_automata\n | 5 -> process_no_speed_limit speed_automata\n | 6 -> process_no_overtake_allowed overtake_automata\n | _ -> failwith \"Unexpected event type\"\n;;\n\n(*********************************************************************************)\n\nlet rec process_events overtake_automata speed_automata n =\n if n > 0 \n then\n let evt = my_read_int () in\n begin\n process_single_event overtake_automata speed_automata evt;\n process_events overtake_automata speed_automata (n-1)\n end\n;;\n\n(*********************************************************************************)\n\nlet find_skipped_road_signs n =\n let overtake_automata = create_overtake_automata () in\n let speed_automata = create_speed_automata () in\n begin\n process_events overtake_automata speed_automata n;\n overtake_automata.missed_sign_count + speed_automata.missed_sign_count\n end\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n Printf.printf \"%d\\n\" (find_skipped_road_signs n);\n;;\n\n(*********************************************************************************)\n\nScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n\n(*********************************************************************************)\n", "positive_code": [{"source_code": "(*********************************************************************************)\n\ntype event = \n | Speed_change of int (* 1 *)\n | Overtake (* 2 *)\n | Speed_limit of int (* 3 *)\n | Overtake_is_allowed (* 4 *)\n | No_speed_limit (* 5 *)\n | No_overtake_allowed (* 6 *)\n;;\n\n(*********************************************************************************)\n\nlet infty = max_int;;\n\n(*********************************************************************************)\n\ntype overtake_automata = {\n\tmutable missed_sign_count : int;\n\tmutable consequtive_overtake_is_disallowed_count : int;\n};;\n\n(*********************************************************************************)\n\nlet create_overtake_automata () = { \n missed_sign_count = 0; \n consequtive_overtake_is_disallowed_count = 0; \n};;\n\n(*********************************************************************************)\n\ntype speed_automata = {\n mutable missed_sign_count : int;\n mutable current_speed : int;\n mutable speed_limits : int list;\n};;\n\n(*********************************************************************************)\n\nlet create_speed_automata () = { \n missed_sign_count = 0; \n current_speed = 0; \n speed_limits = [ infty ];\n};;\n\n\n(*********************************************************************************)\n\nlet my_read_int () =\n let result = ref 0 in\n begin\n Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun n -> result := n);\n !result\n end\n;;\n\n\n(*********************************************************************************)\n\nlet read_event () =\n let evt_type = ref 0 in\n begin\n Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun t -> evt_type := t);\n match !evt_type with\n | 1 -> Speed_change (my_read_int () )\n | 2 -> Overtake\n | 3 -> Speed_limit (my_read_int () )\n | 4 -> Overtake_is_allowed\n | 5 -> No_speed_limit\n | 6 -> No_overtake_allowed\n | _ -> failwith \"Unexpected event type\"\n end\n\n(*********************************************************************************)\n\nlet string_of_event evt =\n match evt with\n | Speed_change( v ) -> (Printf.sprintf \"Speed_change %d\" v)\n | Overtake -> \"Overtake\"\n | Speed_limit( v ) -> (Printf.sprintf \"Speed_limit %d\" v)\n | Overtake_is_allowed -> \"Overtake_is_allowed\"\n | No_speed_limit -> \"No_speed_limit\"\n | No_overtake_allowed -> \"No_overtake_allowed\"\n\n(*********************************************************************************)\n\nlet print_event evt =\n Printf.printf \"%s\\n\" (string_of_event evt);\n;;\n\n(*********************************************************************************)\n\nlet rec remove_until_more_or_equal lst value ax =\n match lst with\n | [] -> ([], ax)\n | hd :: tail -> if hd < value \n then remove_until_more_or_equal tail value (ax + 1)\n else (hd :: tail, ax)\n;;\n\n(*********************************************************************************)\n\nlet pop_violated_speed_limits speed_automata =\n let (new_list, count) = remove_until_more_or_equal speed_automata.speed_limits speed_automata.current_speed 0 in\n begin\n speed_automata.missed_sign_count <- speed_automata.missed_sign_count + count;\n speed_automata.speed_limits <- new_list;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_speed_change speed_automata new_speed =\n begin\n speed_automata.current_speed <- new_speed;\n pop_violated_speed_limits speed_automata\n end\n;;\n\n(*********************************************************************************)\n\nlet process_speed_limit speed_automata new_limit = \n begin\n speed_automata.speed_limits <- new_limit :: speed_automata.speed_limits;\n pop_violated_speed_limits speed_automata\n end\n;;\n\n(*********************************************************************************)\n\nlet process_no_speed_limit speed_automata =\n begin\n speed_automata.speed_limits <- [ infty ];\n end\n;;\n\n(*********************************************************************************)\n\nlet process_overtake (overtake_automata : overtake_automata) = \n begin\n overtake_automata.missed_sign_count <- overtake_automata.missed_sign_count + overtake_automata.consequtive_overtake_is_disallowed_count;\n overtake_automata.consequtive_overtake_is_disallowed_count <- 0;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_overtake_is_allowed overtake_automata =\n begin\n overtake_automata.consequtive_overtake_is_disallowed_count <- 0;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_no_overtake_allowed overtake_automata =\n begin\n overtake_automata.consequtive_overtake_is_disallowed_count <- overtake_automata.consequtive_overtake_is_disallowed_count + 1;\n end\n;;\n\n(*********************************************************************************)\n\nlet process_single_event overtake_automata speed_automata evt =\n match evt with\n | Speed_change( v ) -> process_speed_change speed_automata v\n | Overtake -> process_overtake overtake_automata\n | Speed_limit( v ) -> process_speed_limit speed_automata v\n | Overtake_is_allowed -> process_overtake_is_allowed overtake_automata\n | No_speed_limit -> process_no_speed_limit speed_automata\n | No_overtake_allowed -> process_no_overtake_allowed overtake_automata\n;;\n\n(*********************************************************************************)\n\nlet rec process_events overtake_automata speed_automata n =\n if n > 0 \n then\n let evt = read_event () in\n begin\n process_single_event overtake_automata speed_automata evt;\n process_events overtake_automata speed_automata (n-1)\n end\n;;\n\n(*********************************************************************************)\n\nlet find_skipped_road_signs n =\n let overtake_automata = create_overtake_automata () in\n let speed_automata = create_speed_automata () in\n begin\n process_events overtake_automata speed_automata n;\n overtake_automata.missed_sign_count + speed_automata.missed_sign_count\n end\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n Printf.printf \"%d\\n\" (find_skipped_road_signs n);\n;;\n\n(*********************************************************************************)\n\nScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n\n(*********************************************************************************)\n"}], "negative_code": [], "src_uid": "2dca11b202d7adbe22a404a52d627eed"} {"source_code": "let testcases_str = read_line ()\r\nlet testcases = int_of_string testcases_str\r\n\r\nlet rec split str len n acc =\r\n if n = len then [ int_of_string acc ]\r\n else if str.[n] = ' ' then int_of_string acc :: split str len (n + 1) \"\"\r\n else split str len (n + 1) (acc ^ String.make 1 str.[n])\r\n\r\nlet solve () =\r\n let len = read_line () in\r\n let nums_string = read_line () in\r\n let counter_arr = Array.make ((int_of_string len) + 1) 0 in\r\n let splitted = split nums_string (String.length nums_string) 0 \"\" in\r\n let rec loop lst counter =\r\n match lst with\r\n | [] -> print_string \"-1\\n\"\r\n | h :: t ->\r\n counter.(h) <- counter.(h) + 1;\r\n if counter.(h) >= 3 then print_string (string_of_int h ^ \"\\n\")\r\n else loop t counter\r\n in\r\n loop splitted counter_arr\r\n;;\r\n\r\nfor i = 0 to testcases - 1 do\r\n solve ()\r\ndone\r\n", "positive_code": [{"source_code": "(* print any value that appears atleast three times or print -1\r\n 1<=ai<=n, so can have a count array size n? Or sort and see if adjacent next to each other?\r\n comparsion sort is atleast O(nlgn)\r\n counting is atmost O(n)\r\n*)\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x-> x);;\r\n\r\nlet rec fill_count_arr = function\r\n| (count_arr, 0) -> count_arr\r\n| (count_arr, i) ->\r\n let x = read_int () in \r\n count_arr.(x-1) <- (count_arr.(x-1)+1);\r\n fill_count_arr (count_arr, (i-1))\r\n;;\r\n\r\nlet rec consume_count_arr = function \r\n| (n, count_arr, k, i) ->\r\n if (i=n) then -1\r\n else begin \r\n if (count_arr.(i)>=k) then i+1\r\n else consume_count_arr (n, count_arr, k, (i+1))\r\n end\r\n;;\r\nlet run_case = function\r\n| () -> \r\n let n = read_int () in\r\n let count_arr = Array.make n 0 in \r\n let filled_arr = fill_count_arr (count_arr, n) in\r\n let x = consume_count_arr (n, filled_arr, 3, 0) in \r\n Printf.printf \"%d\\n\" x\r\n;;\r\n\r\nlet rec iter_cases = function \r\n| 0 -> ()\r\n| t -> \r\n run_case ();\r\n iter_cases (t-1)\r\n;;\r\nlet t = read_int () in iter_cases (t);;\r\n"}, {"source_code": "let getInt () = Scanf.scanf \" %d\" (fun i -> i);;\r\n\r\n\r\nlet getList(n): int list = \r\n let rec getList2 ((n: int), (acc: int list)) = match n with\r\n\t | 0 -> List.rev acc\r\n\t | _ -> getList2 (n-1, getInt() :: acc)\r\n in getList2(n, [])\r\n\r\nlet getLine() = Scanf.scanf \" %s\" (fun i -> i);;\r\n\r\nlet cmp((x: int), (y:int)) = x - y;;\r\n\r\nlet rec solve((arr: int list), (last: int), (ct: int)) = \r\nmatch arr with\r\n | [] -> -1\r\n | x::xs -> \r\n if x = last then (\r\n if (ct + 1) = 3 then x else solve(xs, last, ct + 1))\r\n else solve(xs, x, 1);;\r\n\r\n\r\nlet main() = \r\n let t = getInt() in\r\n for i = 1 to t do \r\n let n = getInt() in let x = getList(n) in let arr = List.sort (compare) x\r\n in let ans = solve(arr, -1, 0) in\r\n print_endline(string_of_int(ans))\r\n done;;\r\n\r\nmain();;\r\n\r\n\r\n"}, {"source_code": "let id x = x\n\nmodule S = struct\n open String\n\n let split_on_char sep s =\n let r = ref [] in\n let j = ref (String.length s) in\n for i = length s - 1 downto 0 do\n if unsafe_get s i = sep then begin\n r := sub s (i + 1) (!j - i - 1) :: !r;\n j := i\n end\n done;\n sub s 0 !j :: !r\nend\n\nlet read_ints_line () =\n Scanf.scanf \"%s@\\n\" (fun x -> x)\n |> S.split_on_char ' '\n |> List.filter (fun x -> x <> \"\")\n |> List.map int_of_string\n\nlet solve () =\n let n = Scanf.scanf \"%d\\n\" id in\n let xs = read_ints_line () in\n let counts = Array.make (n + 1) 0 in\n let () = List.iter (fun a -> counts.(a) <- counts.(a) + 1) xs in\n let counts = Array.mapi (fun i c -> (i, c)) counts |> Array.to_list in\n let counts = List.filter (fun (i, c) -> c >= 3) counts in\n match counts with\n | [] -> print_endline \"-1\"\n | (i, _) :: _ -> Printf.printf \"%d\\n\" i\n\nlet () =\n let t = Scanf.scanf \"%d\\n\" id in\n for i = 1 to t do\n solve ()\n done\n"}], "negative_code": [], "src_uid": "7d4174e3ae76de7b1389f618eb89d334"} {"source_code": "(* square colours *)\ntype col = White | Black\n\nlet (++) (x, y) (z, w) = (x + z, y + w)\n\nlet get a (x, y) =\n try a.(x).(y)\n with Invalid_argument _ -> White\n\nlet deltas = [\n [(-1, -1); (0, -1); (-1, 0)]; (* north-west *)\n [( 1, -1); (0, -1); ( 1, 0)]; (* north-east *)\n [(-1, 1); (0, 1); (-1, 0)]; (* south-west *)\n [( 1, 1); (0, 1); ( 1, 0)]; (* south-east *)\n]\n\nlet () =\n Scanf.scanf \"%d %d %d\\n\" (fun n m k ->\n let board = Array.make_matrix n m White in\n let get = get board in\n\n let check_square p = List.fold_left (fun b d ->\n b || (List.fold_left (fun i d ->\n i + match get (d ++ p) with | White -> 0 | Black -> 1) 0 d) = 3)\n false deltas\n in\n\n let rec loop i =\n if i > k then 0\n else begin\n let x, y = Scanf.scanf \"%d %d\\n\" (fun x y -> (x-1, y-1)) in\n board.(x).(y) <- Black;\n if check_square (x, y) then i else loop (i + 1)\n end\n in\n Printf.printf \"%d\\n\" (loop 1)\n )\n", "positive_code": [{"source_code": "let carre a b mat =\n\t(mat.(a).(b)) && (mat.(a-1).(b)) && (mat.(a).(b-1)) && (mat.(a-1).(b-1));;\n\nlet rec f mat = function\n\t|[]\t\t-> -100000\n\t|(a,b)::q \t-> begin\n\t\t\t\tmat.(a).(b) <- true;\n\t\t\t\tif (carre a b mat) || (carre (a+1) b mat) || (carre a (b+1) mat) || (carre (a+1) (b+1) mat)\n\t\t\t\t\tthen 1\n\t\t\t\t\telse 1 + f mat q\n\t\t\t\tend;;\n\nlet final () =\n\tlet (n,m,k) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) and l = ref [] in\n\t\tfor i=1 to k do\n\t\t\tl := (Scanf.scanf \"%d %d \" (fun i j -> (i,j)))::!l;\n\t\tdone;\n\tlet mat = Array.make_matrix (n+2) (m+2) false in\n\tlet a = f mat (List.rev !l) in\n\t\tif a < 0\n\t\t\tthen Printf.printf \"0\"\n\t\t\telse Printf.printf \"%d\" a;;\n\nfinal ();;\n"}], "negative_code": [], "src_uid": "0dc5469831c1d5d34aa3b7b172e3237b"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_char _ = bscanf Scanning.stdib \" %c \" (fun x -> x)\n\nlet () =\n let n = read_int () and m = read_int () and x = read_int () and y = read_int () in\n let a = Array.make_matrix (n + 1) (m + 1) ' '\n and cnt = Array.make_matrix (m + 1) 2 0\n and best = Array.make_matrix (m + 1) 2 1000000\n and dp = Array.init (m + 1) (fun _ -> Array.init 2 (fun _ -> Array.make (y + 1) 1000000)) in\n best.(0).(0) <- 0;\n best.(0).(1) <- 0;\n let interval a b color =\n cnt.(b).(color) - cnt.(a - 1).(color) in\n for i = 1 to n do\n for j = 1 to m do\n a.(i).(j) <- read_char ()\n done\n done;\n for i = 1 to m do\n let white = ref 0 and black = ref 0 in\n for j = 1 to n do\n if a.(j).(i) = '.' then incr white\n else incr black\n done;\n cnt.(i).(0) <- cnt.(i - 1).(0) + !white;\n cnt.(i).(1) <- cnt.(i - 1).(1) + !black\n done;\n for i = 1 to m do\n for color = 0 to 1 do\n let other_color = (color + 1) mod 2 in\n for length = x to min y i do\n dp.(i).(color).(length) <- best.(i - length).(other_color) + (interval (i - length + 1) i other_color);\n best.(i).(color) <- min best.(i).(color) dp.(i).(color).(length)\n done\n done\n done;\n printf \"%d\\n\" (min best.(m).(0) best.(m).(1))", "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\nlet n = scan_int() and m = scan_int() and x = scan_int() and y = scan_int();;\nlet cnt = Array.make (m + 1) 0;; (*liczba zer w i-tej kolumnie*)\n\nfor i = 0 to n - 1 do\n let s = scan_string () in\n for j = 0 to m - 1 do\n cnt.(j + 1) <- cnt.(j + 1) + b2i(s.[j] = '.');\n done;\ndone;;\n\nlet duzo = 998244353;;\n\nlet dp = Array.make_matrix (m + 1) 2 duzo;;\ndp.(0).(0) <- 0;; dp.(0).(1) <- 0;; (* warunki poczatkowe *)\n\nlet zer = ref 0 and jed = ref 0;;\nfor i = 1 to x do\n zer := !zer + (n - cnt.(i));\n jed := !jed + cnt.(i); \ndone;;\n\nfor i = x to m do\n let pZer = ref !zer and pJed = ref !jed in\n for j = i - x + 1 downto max 1 (i - y + 1) do\n dp.(i).(0) <- min (dp.(i).(0)) (dp.(j - 1).(1) + !pZer);\n dp.(i).(1) <- min (dp.(i).(1)) (dp.(j - 1).(0) + !pJed);\n pZer := !pZer + (n - cnt.(j - 1));\n pJed := !pJed + cnt.(j - 1); \n done;\n if i <> m then begin\n zer := !zer + (n - cnt.(i + 1)) - (n - cnt.(i - x + 1));\n jed := !jed + cnt.(i + 1) - cnt.(i - x + 1);\n end; \ndone;;\n\nprint_int (min dp.(m).(0) dp.(m).(1));;"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\nlet n = scan_int() and m = scan_int() and x = scan_int() and y = scan_int();;\nlet cnt = Array.make (m + 1) 0;; (*liczba zer w i-tej kolumnie*)\n\nfor i = 0 to n - 1 do\n let s = scan_string () in\n for j = 0 to m - 1 do\n cnt.(j + 1) <- cnt.(j + 1) + b2i(s.[j] = '.');\n done;\ndone;;\n\nlet duzo = 998244353;;\n\nlet dp = Array.make_matrix (m + 1) 2 duzo;;\ndp.(0).(0) <- 0;; dp.(0).(1) <- 0;; (* warunki poczatkowe *)\n\nlet zer = ref 0 and jed = ref 0;;\nfor i = 1 to x - 1 do\n zer := !zer + (n - cnt.(i));\n jed := !jed + cnt.(i); \ndone;;\n\nfor i = x to m do\n let pZer = ref !zer and pJed = ref !jed in\n for j = i - x + 1 downto max 1 (i - y + 1) do\n pZer := !pZer + (n - cnt.(j));\n pJed := !pJed + cnt.(j); \n dp.(i).(0) <- min (dp.(i).(0)) (dp.(j - 1).(1) + !pZer);\n dp.(i).(1) <- min (dp.(i).(1)) (dp.(j - 1).(0) + !pJed);\n done;\n if i <> m then begin \n zer := !zer + (n - cnt.(i)) - (n - cnt.(i - x + 1));\n jed := !jed + cnt.(i) - cnt.(i - x + 1); \n end;\ndone;;\n\nprint_int (min dp.(m).(0) dp.(m).(1));;"}], "src_uid": "08d13e3c71040684d5a056bd1b53ef3b"} {"source_code": "let () =\n Scanf.scanf \"%d %s\" @@ fun n s ->\n let b = Bytes.create n in\n for i = 0 to n / 2 - 1 do\n Bytes.set b i s.[n - 2 * i - 2]\n done;\n for i = n - 1 downto n / 2 do\n Bytes.set b i s.[2 * i - n + 1]\n done;\n Printf.printf \"%s\\n\" b\n", "positive_code": [{"source_code": "let decode (s : string) : string =\n let n = String.length s in\n let bs = Bytes.create n in\n begin\n if n mod 2 = 0\n then\n for i = 0 to n/2-1 do\n Bytes.set bs (n/2-1 - i) s.[2*i];\n Bytes.set bs (n/2 + i) s.[2*i+1]\n done\n else begin\n for i = 0 to (n-3)/2 do\n Bytes.set bs ((n-1)/2 + i) s.[2*i];\n Bytes.set bs ((n-3)/2 - i) s.[2*i+1]\n done;\n Bytes.set bs (n-1) s.[n-1]\n end\n end;\n Bytes.unsafe_to_string bs\n\n\nlet main () =\n let n = read_int () in\n let encoded_str = really_input_string stdin n in\n print_string (decode encoded_str)\n\n\nlet _ = main ()\n"}], "negative_code": [], "src_uid": "2a414730d1bc7eef50bdb631ea966366"} {"source_code": "open Big_int\n\nlet sieve n =\n let nums = Array.make (n + 1) false in\n let delete m =\n if not nums.(m) then\n for k = 2 to n / m do\n nums.(k * m) <- true\n done\n in\n let result = ref [] in\n nums.(0) <- true;\n nums.(1) <- true;\n for i = 2 to int_of_float(sqrt(float_of_int(n))) + 1 do\n delete i\n done;\n Array.iteri (fun i composite ->\n if not composite then result := i :: !result) nums;\n List.rev !result\n\nlet rec factorization ?(result=[]) primes n =\n let add x (* lst *)= function\n | [] -> [(x, 1)]\n | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys\n | ys -> (x, 1) :: ys\n in\n let p = try List.hd primes with Failure _ -> n in\n match n with\n | 1 -> List.rev result\n | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)\n | _ (* <> 0 *) -> factorization ~result (List.tl primes) n\n\nlet rec insert_factor ?(acc=[]) (x, kx) = function\n | [] -> List.rev ((x, kx) :: acc)\n | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys\n | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys\n | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)\n\nlet rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with\n | (_, []) -> List.rev result\n | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys\n | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky ->\n lcm_fact ~result:((x, ky - kx) :: result) xs ys\n | ((x, _) :: xs, (y, _) :: ys) when x = y (* kx >= ky *) ->\n lcm_fact ~result xs ys\n | ((x, _) :: xs, (y, _) :: _) when x < y ->\n lcm_fact ~result xs greater\n | (_, y :: ys) (* x > y *) ->\n lcm_fact ~result:(y :: result) lesser ys\n\nlet ( *.. ) a b = mult_big_int a b\nlet ( +.. ) a b = add_big_int a b\nlet ( ~.. ) a = big_int_of_int a \n\nlet rec product ?(result=unit_big_int) = function\n | [] -> result\n | (p, 0) :: ps -> product ~result ps\n | (p, n) :: ps -> product ~result:((~.. p) *.. result) ((p, n - 1) :: ps)\n\nlet next_token =\n let buffer = ref \"\" in\n let first = ref 0 in\n let rec omit_spaces s from =\n try\n (match s.[from] with\n | ' ' -> omit_spaces s (from + 1)\n | _ -> from)\n with\n | Invalid_argument _ -> String.length s\n in\n (fun () ->\n first := omit_spaces !buffer !first;\n while !first > String.length !buffer - 1 do\n buffer := read_line ();\n first := omit_spaces !buffer 0\n done;\n let last = try String.index_from !buffer !first ' '\n with Not_found -> String.length !buffer\n in\n let result = String.sub !buffer !first (last - !first) in\n first := last;\n result)\n\nlet next_int () = int_of_string (next_token ())\n\nlet () =\n let primes = sieve 31623 in\n let t = next_int () in\n for k = 1 to t do\n let n = next_int () in\n let greater_factors = insert_factor (2, 2) (factorization primes n) in\n let lesser_factors = factorization primes (n + 1) in\n let\n result = (product (lcm_fact lesser_factors greater_factors)) +.. (~.. 1)\n in\n print_endline (string_of_big_int result)\n done\n\n", "positive_code": [{"source_code": "open Big_int\n\nlet next_token =\n let buffer = ref \"\" in\n let first = ref 0 in\n let rec omit_spaces s from =\n try\n (match s.[from] with\n | ' ' -> omit_spaces s (from + 1)\n | _ -> from)\n with\n | Invalid_argument _ -> String.length s\n in\n (fun () ->\n first := omit_spaces !buffer !first;\n while !first > String.length !buffer - 1 do\n buffer := read_line ();\n first := omit_spaces !buffer 0\n done;\n let last = try String.index_from !buffer !first ' '\n with Not_found -> String.length !buffer\n in\n let result = String.sub !buffer !first (last - !first) in\n first := last;\n result)\n\nlet next_int () = int_of_string (next_token ())\n\nlet ( + ) a b = add_big_int a b\nlet ( - ) a b = sub_big_int a b \nlet ( * ) a b = mult_big_int a b\nlet ( / ) a b = div_big_int a b\nlet ( % ) a b = mod_big_int a b\nlet ( < ) a b = lt_big_int a b\nlet ( > ) a b = gt_big_int a b\nlet ( = ) a b = eq_big_int a b\n\nlet zero = big_int_of_int 0\nlet one = big_int_of_int 1\nlet two = big_int_of_int 2\nlet four = big_int_of_int 4\n\nlet rec gcd a b =\n if a < b then gcd b a\n else if b = zero then a\n else gcd b (a % b)\n\nlet lcm a b = (a * b) / (gcd a b)\n\nlet () =\n let t = next_int () in\n for k = 1 to t do\n let n = big_int_of_int (next_int ()) in\n let result = (lcm (four * n) (n + one)) / (n + one) + one in\n print_endline (string_of_big_int result)\n done\n"}, {"source_code": "let rec gcd a b =\n if b = 0 then a else gcd b (a mod b)\n;;\n\nlet _ =\n let ni () = Scanf.scanf \" %d\" (fun x -> x) in\n let re = ni () in\n for ri = 1 to re do\n let n = ni () in\n let n' = float_of_int n in\n Printf.printf \"%.0f\\n\" (1.0 +. match (n + 1) mod 4 with\n | 0 -> n'\n | 2 -> 2.0 *. n'\n | _ -> 4.0 *. n'\n )\n done\n;;\n"}, {"source_code": "open Big_int\n\nlet next_token =\n let buffer = ref \"\" in\n let first = ref 0 in\n let rec omit_spaces s from =\n try\n (match s.[from] with\n | ' ' -> omit_spaces s (from + 1)\n | _ -> from)\n with\n | Invalid_argument _ -> String.length s\n in\n (fun () ->\n first := omit_spaces !buffer !first;\n while !first > String.length !buffer - 1 do\n buffer := read_line ();\n first := omit_spaces !buffer 0\n done;\n let last = try String.index_from !buffer !first ' '\n with Not_found -> String.length !buffer\n in\n let result = String.sub !buffer !first (last - !first) in\n first := last;\n result)\n\nlet next_int () = int_of_string (next_token ())\n\nlet ( *$ ) a b = mult_big_int a b\nlet ( /$ ) a b = div_big_int a b\nlet ( +$ ) a b = add_big_int a b\nlet ( ~$ ) a = big_int_of_int a\nlet ( %$ ) a b = mod_big_int a b\nlet ( <$ ) a b = lt_big_int a b\nlet ( >$ ) a b = gt_big_int a b\nlet ( =$ ) a b = eq_big_int a b\n\nlet rec gcd a b =\n if a <$ b then gcd b a\n else if b =$ (~$ 0) then a\n else gcd b (a %$ b)\n\nlet lcm a b = (a *$ b) /$ (gcd a b)\n\nlet () =\n let t = next_int () in\n for k = 1 to t do\n let n = ~$ (next_int ()) in\n let\n result = (lcm ((~$ 4) *$ n) (n +$ (~$ 1))) /$ ((n +$ (~$ 1))) +$ (~$ 1)\n in\n print_endline (string_of_big_int result)\n done\n\n"}], "negative_code": [{"source_code": "let rec gao n =\n if n = 1 then 2\n else if n mod 2 = 0 then 4 * n\n else gao (n / 2 + 1)\n;;\n\nlet _ =\n let ni () = Scanf.scanf \" %d\" (fun x -> x) in\n let re = ni () in\n for ri = 1 to re do\n let n = ni () in\n Printf.printf \"%d\\n\" (1 + gao n)\n done\n;;\n"}, {"source_code": "\nlet sieve n =\n let nums = Array.make (n + 1) false in\n let delete m =\n if not nums.(m) then\n for k = 2 to n / m do\n nums.(k * m) <- true\n done\n in\n let result = ref [] in\n nums.(0) <- true;\n nums.(1) <- true;\n for i = 2 to int_of_float(sqrt(float_of_int(n))) + 1 do\n delete i\n done;\n Array.iteri (fun i composite ->\n if not composite then result := i :: !result) nums;\n List.rev !result\n\nlet rec factorization ?(result=[]) primes n =\n let add x (* lst *)= function\n | [] -> [(x, 1)]\n | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys\n | ys -> (x, 1) :: ys\n in\n let p = try List.hd primes with Failure _ -> n in\n match n with\n | 1 -> List.rev result\n | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)\n | _ (* <> 0 *) -> factorization ~result (List.tl primes) n\n\nlet rec insert_factor ?(acc=[]) (x, kx) = function\n | [] -> List.rev ((x, kx) :: acc)\n | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys\n | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys\n | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)\n\nlet rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with\n | (_, []) -> List.rev result\n | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys\n | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky->\n lcm_fact ~result:((x, ky - kx) :: result) xs ys\n | ((x, _) :: xs, (y, _) :: ys) when x = y ->\n lcm_fact ~result xs ys\n | ((x, _) :: xs, (y, _) :: _) when x < y ->\n lcm_fact ~result xs greater\n | ((x, _) :: _, (y, ky) :: ys) (* x > y *) ->\n lcm_fact ~result:((y, ky) :: result) lesser ys\n\nlet rec product ?(result=1) = function\n | [] -> result\n | (p, 0) :: ps -> product ~result ps\n | (p, n) :: ps -> product ~result:(p * result) ((p, n - 1) :: ps)\n\nlet next_token =\n let buffer = ref \"\" in\n let first = ref 0 in\n let rec omit_spaces s from =\n try\n (match s.[from] with\n | ' ' -> omit_spaces s (from + 1)\n | _ -> from)\n with\n | Invalid_argument _ -> String.length s\n in\n (fun () ->\n first := omit_spaces !buffer !first;\n while !first > String.length !buffer - 1 do\n buffer := read_line ();\n first := omit_spaces !buffer 0\n done;\n let last = try String.index_from !buffer !first ' '\n with Not_found -> String.length !buffer\n in\n let result = String.sub !buffer !first (last - !first) in\n first := last;\n result)\n\nlet next_int () = int_of_string (next_token ())\n\nlet () =\n let primes = sieve 31623 in\n let t = next_int () in\n for k = 1 to t do\n let n = next_int () in\n let greater_factors = insert_factor (2, 2) (factorization primes n) in\n let lesser_factors = factorization primes (n + 1) in\n let result = (product (lcm_fact lesser_factors greater_factors)) + 1 in\n print_endline (string_of_int result)\n done\n\n"}, {"source_code": "\nlet sieve n =\n let nums = Array.make (n + 1) false in\n let delete m =\n if not nums.(m) then\n for k = 2 to n / m do\n nums.(k * m) <- true\n done\n in\n let result = ref [] in\n nums.(0) <- true;\n nums.(1) <- true;\n for i = 2 to int_of_float(sqrt(float_of_int(n))) do\n delete i\n done;\n Array.iteri (fun i composite ->\n if not composite then result := i :: !result) nums;\n List.rev !result\n\nlet rec factorization ?(result=[]) primes n =\n let add x (* lst *)= function\n | [] -> [(x, 1)]\n | (y, ky) :: ys when y = x -> (x, ky + 1) :: ys\n | ys -> (x, 1) :: ys\n in\n let p = try List.hd primes with Failure _ -> n in\n match n with\n | 1 -> List.rev result\n | _ when n mod p = 0 -> factorization ~result:(add p result) primes (n / p)\n | _ (* <> 0 *) -> factorization ~result (List.tl primes) n\n\nlet rec insert_factor ?(acc=[]) (x, kx) = function\n | [] -> List.rev ((x, kx) :: acc)\n | (y, ky) :: ys when y < x -> insert_factor ~acc:((y, ky) :: acc) (x, kx) ys\n | (y, ky) :: ys when y = x -> List.rev ((x, kx + ky) :: acc) @ ys\n | (y, ky) :: ys (* y > x *) -> List.rev ((x, kx) :: acc) @ ((y, ky) :: ys)\n\nlet rec lcm_fact ?(result=[]) lesser greater = match (lesser, greater) with\n | (_, []) -> List.rev result\n | ([], y :: ys) -> lcm_fact ~result:(y :: result) [] ys\n | ((x, kx) :: xs, (y, ky) :: ys) when x = y && kx < ky->\n lcm_fact ~result:((x, ky - kx) :: result) xs ys\n | ((x, _) :: xs, (y, _) :: ys) when x = y ->\n lcm_fact ~result xs ys\n | ((x, _) :: xs, (y, _) :: _) when x < y ->\n lcm_fact ~result xs greater\n | ((x, _) :: _, (y, ky) :: ys) (* x > y *) ->\n lcm_fact ~result:((y, ky) :: result) lesser ys\n\nlet rec product ?(result=1) = function\n | [] -> result\n | (p, 0) :: ps -> product ~result ps\n | (p, n) :: ps -> product ~result:(p * result) ((p, n - 1) :: ps)\n\nlet next_token =\n let buffer = ref \"\" in\n let first = ref 0 in\n let rec omit_spaces s from =\n try\n (match s.[from] with\n | ' ' -> omit_spaces s (from + 1)\n | _ -> from)\n with\n | Invalid_argument _ -> String.length s\n in\n (fun () ->\n first := omit_spaces !buffer !first;\n while !first > String.length !buffer - 1 do\n buffer := read_line ();\n first := omit_spaces !buffer 0\n done;\n let last = try String.index_from !buffer !first ' '\n with Not_found -> String.length !buffer\n in\n let result = String.sub !buffer !first (last - !first) in\n first := last;\n result)\n\nlet next_int () = int_of_string (next_token ())\n\nlet () =\n let primes = sieve 10000 in\n let t = next_int () in\n for k = 1 to t do\n let n = next_int () in\n let greater_factors = insert_factor (2, 2) (factorization primes n) in\n let lesser_factors = factorization primes (n + 1) in\n let result = (product (lcm_fact lesser_factors greater_factors)) + 1 in\n print_endline (string_of_int result)\n done\n\n"}], "src_uid": "168dbc4994529f5407a440b0c71086da"} {"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve (n, m, c, e0) =\n let open Hashtbl in\n let adjC : ((int, (int, unit) t) t) = create 10 in\n Array.iter\n (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))\n c;\n Array.iter\n (fun (u, v) ->\n if c.(u) = c.(v) then ()\n else begin\n replace (find adjC c.(u)) c.(v) ();\n replace (find adjC c.(v)) c.(u) ()\n end)\n e0;\n fold\n (fun c' h (c, q) ->\n let q' = length h in\n if q' > q || q' = q && c' < c\n then (c', q')\n else (c, q))\n adjC\n (-1, -1)\n |> fst\n\nlet main () =\n let n = readInt () in\n let m = readInt () in\n let c = Array.init n (fun _ -> readInt ()) in\n let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in\n Printf.printf \"%d\\n\" (solve (n, m, c, e0))\n\nlet () = main ()\n", "positive_code": [{"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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n\n let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)\n\n let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)\n\n let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in\n\n let add_edge a b = \n if (c.(a) <> c.(b)) then (\n Hashtbl.replace carray.(c.(a)) c.(b) true;\n Hashtbl.replace carray.(c.(b)) c.(a) true;\n )\n in\n\n let () =\n for i=0 to m-1 do\n let a = read_int() in\n let b = read_int() in\n\tadd_edge (a-1) (b-1);\n done\n in\n\n let ccount c = Hashtbl.length carray.(c) in\n let div = maxf 0 mc ccount in\n let i = minf 0 (n-1) (fun j -> if ccount c.(j) = div then c.(j) else (mc+1)) in\n Printf.printf \"%d\\n\" i\n"}, {"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve (n, m, c, e0) =\n let open Hashtbl in\n let adjC : ((int, (int, unit) t) t) = create (n/10) in\n Array.iter\n (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))\n c;\n Array.iter\n (fun (u, v) ->\n if c.(u) = c.(v) then ()\n else begin\n replace (find adjC c.(u)) c.(v) ();\n replace (find adjC c.(v)) c.(u) ()\n end)\n e0;\n fold\n (fun c' h (c, q) ->\n let q' = length h in\n if q' > q || q' = q && c' < c\n then (c', q')\n else (c, q))\n adjC\n (-1, -1)\n |> fst\n\nlet main () =\n let n = readInt () in\n let m = readInt () in\n let c = Array.init n (fun _ -> readInt ()) in\n let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in\n Printf.printf \"%d\\n\" (solve (n, m, c, e0))\n\nlet () = main ()\n"}, {"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve (n, m, c, e0) =\n let open Hashtbl in\n let adjC : ((int, (int, unit) t) t) = create 10 in\n Array.iter\n (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))\n c;\n Array.iter\n (fun (u, v) ->\n if c.(u) = c.(v) then ()\n else begin\n replace (find adjC c.(u)) c.(v) ();\n replace (find adjC c.(v)) c.(u) ()\n end)\n e0;\n (* -(snd Seq.(to_seq adjC |> map (fun (c, h) -> (length h, -c)) |> fold_left max (-1, -1))) *)\n -(snd (fold (fun c' h cur -> max (length h, -c') cur) adjC (-1, -1)))\n\nlet main () =\n let n = readInt () in\n let m = readInt () in\n let c = Array.init n (fun _ -> readInt ()) in\n let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in\n Printf.printf \"%d\\n\" (solve (n, m, c, e0))\n\nlet () = main ()\n"}], "negative_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve (n, m, c, e0) =\n let open Hashtbl in\n let adjC : ((int, (int, unit) t) t) = create (n/10) in\n Array.iter\n (fun c -> try let _ = find adjC c in () with Not_found -> add adjC c (create 10))\n c;\n Array.iter\n (fun (u, v) ->\n replace (find adjC c.(u)) c.(v) ();\n replace (find adjC c.(v)) c.(u) ())\n e0;\n fst (fold (fun c' h (c, q) -> let q' = length h in if q' > q then (c', q') else (c, q)) adjC (-1, -1) )\n\nlet main () =\n let n = readInt () in\n let m = readInt () in\n let c = Array.init n (fun _ -> readInt ()) in\n let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in\n Printf.printf \"%d\\n\" (solve (n, m, c, e0))\n\nlet () = main ()\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet argmax i j f = fold (i+1) j (fun k (y,j) -> let x = f k in if x > y then (x,k) else (y,j)) ((f i),i)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n\n let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)\n\n let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)\n\n let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in\n\n let add_edge a b = \n if (c.(a) <> c.(b)) then (\n Hashtbl.replace carray.(c.(a)) c.(b) true;\n Hashtbl.replace carray.(c.(b)) c.(a) true;\n )\n in\n\n let () =\n for i=0 to m-1 do\n let a = read_int() in\n let b = read_int() in\n\tadd_edge (a-1) (b-1);\n done\n in\n\n let ccount c = Hashtbl.length carray.(c) in\n let (div,i) = argmax 0 mc ccount in\n let i = if div = 0 then c.(0) else i in\n Printf.printf \"%d\\n\" i\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n\n let c = Array.init n (fun _ -> read_int()) in (* colors of the vertices *)\n\n let mc = maxf 0 (n-1) (fun i -> c.(i)) in (* maximum color *)\n\n let carray = Array.init (mc+1) (fun _-> Hashtbl.create 5) in\n\n let add_edge a b = \n if (c.(a) <> c.(b)) then (\n Hashtbl.replace carray.(c.(a)) c.(b) true;\n Hashtbl.replace carray.(c.(b)) c.(a) true;\n )\n in\n\n let () =\n for i=0 to m-1 do\n let a = read_int() in\n let b = read_int() in\n\tadd_edge (a-1) (b-1);\n done\n in\n\n let ccount c = Hashtbl.length carray.(c) in\n let div = maxf 0 mc ccount in\n let i = minf 0 (n-1) (fun j -> if ccount c.(j) = div then c.(j) else -1) in\n Printf.printf \"%d\\n\" i\n"}], "src_uid": "89c27a5c76f4ddbd14af2d30ac8b6330"} {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\nlet id x = x\n\nlet () =\n let n = Scanf.scanf \"%d \" id in\n let rec loop n acc =\n if n = 0 then acc else\n let s = Scanf.scanf \"%s \" id in\n loop (n-1) (\"<3\" :: s :: acc)\n in\n let orig = loop n [\"<3\"] |> List.rev |> String.concat \"\" in\n let msg = Scanf.scanf \"%s \" id in\n let i = ref 0 in\n String.iter (fun s -> \n if !i < String.length orig && s = orig.[!i] then incr i\n ) msg;\n print_endline @@ if !i = String.length orig then \"yes\" else \"no\";\n", "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\n\nlet () =\n let n = Scanf.scanf \"%d \" ident in\n let ss = fold_for 0 n ~init:[] ~f:(fun acc _ ->\n Scanf.scanf \"%s \" ident :: acc) |> List.rev in\n let text = Scanf.scanf \"%s \" ident in\n let len = String.length text in\n try \n let start = List.fold_left ss ~init:0 ~f:(fun start s ->\n let u = \"<3\" ^ s in\n let cur = ref start in\n iter_for 0 (String.length u) ~f:(fun i ->\n while u.[i] <> text.[!cur] do\n cur := !cur + 1;\n if !cur >= len then raise Not_found;\n done; cur := !cur + 1);\n !cur) in\n Str.search_forward (Str.regexp \"[a-z0-9<>]*<[a-z0-9<>]*3[a-z0-9<>]*\") text start |> ignore;\n print_endline \"yes\";\n with\n | _ -> print_endline \"no\"\n;;\n"}], "negative_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\n\nlet () =\n let n = Scanf.scanf \"%d \" ident in\n let ss = fold_for 0 n ~init:[] ~f:(fun acc _ ->\n Scanf.scanf \"%s \" ident :: acc) |> List.rev in\n let text = Scanf.scanf \"%s \" ident in\n let len = String.length text in\n try \n let start = List.fold_left ss ~init:0 ~f:(fun start s ->\n let u = \"<3\" ^ s in\n let cur = ref start in\n iter_for 0 (String.length u) ~f:(fun i ->\n while u.[i] <> text.[!cur] do\n cur := !cur + 1;\n if !cur >= len then raise Not_found;\n done);\n !cur) in\n Str.search_forward (Str.regexp \"[a-z0-9<>]*<[a-z0-9<>]*3[a-z0-9<>]*\") text start |> ignore;\n print_endline \"yes\";\n with\n | _ -> print_endline \"no\"\n;;\n"}], "src_uid": "36fb3a01860ef0cc2a1065d78e4efbd5"} {"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 undef = -7\n\nlet n,m = get_2_i64 0\nlet power = input_i64_array (n*2L)\nlet used = make (i32 n*$2) false\nlet sp =\n let sp = make (i32 n*$2) undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n ); sp\nlet i_sorted =\n let a = mapi (fun i v -> v,i) power in sort (rv compare) a;\n map (fun (v,i) -> i) a\n\nlet output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true\nlet input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j\nlet output_find _ =\n let i,j = fold_left (fun (p,q) i ->\n if not used.(i) then (\n let p = if p = undef && sp.(i) <> undef then i else p in\n let q = if q = undef then i else q in\n (p,q)\n ) else (p,q)\n ) (undef,undef) i_sorted in\n if i<>undef then output i\n else output j\n\nlet t = get_i64 0\nlet () =\n rep 1L n (fun turn ->\n if turn=1L && t=1L then (\n output_find 0\n );\n let j = input 0 in\n if not (turn=n && t=1L) then (\n if sp.(j) <> undef && not used.(sp.(j)) then\n output sp.(j)\n else output_find 0\n )\n )\n\n\n\n\n\n\n\n\n\n", "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\nmodule IMap = Map.Make(Int64)\nlet () =\n let n,m = get_2_i64 0 in\n let pw = input_i64_array (n*2L) in\n let undef = -7 in\n let sp = make 2018 undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n );\n let used = make (i32 n*$2) false in\n let pw_sorted = pw |> mapi (fun i v->v,i) in\n sort (rv compare) pw_sorted;\n let t = get_i64 0\n in\n let last_sp = ref undef in\n let output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true in\n let input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j in\n let find _ =\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) && sp.(j) <> undef && not used.(sp.(j)) then `Break_m (v,j)\n else `Ok u\n )\n in if i <> undef then output i\n else\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\n in\n if t=1L then rep 1L n (fun lp ->\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if lp=1L then (\n (* let i = find 0 in\n output i; *)\n find 0;\n let j = input 0 in last_sp := sp.(j)\n ) else (\n if !last_sp = undef || used.(!last_sp) then (\n find 0\n ) else (\n output !last_sp;\n );\n let j = input 0 in\n last_sp := sp.(j)\n (* if sp.(j) <> undef then (\n last_sp := j\n ) else (\n last_sp := undef\n ) *)\n )\n ) else rep 1L n (fun lp ->\n let j = input 0 in\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if sp.(j) <> undef && not used.(sp.(j)) then (\n output sp.(j)\n ) else (\n find 0\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\nmodule IMap = Map.Make(Int64)\nlet () =\n let n,m = get_2_i64 0 in\n let pw = input_i64_array (n*2L) in\n let undef = -7 in\n let sp = make 2018 undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n );\n let used = make (i32 n*$2) false in\n let pw_sorted = pw |> mapi (fun i v->v,i) in\n sort (rv compare) pw_sorted;\n let t = get_i64 0\n in\n let last_sp = ref undef in\n let output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true in\n let input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j in\n let find _ =\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) && sp.(j) <> undef then `Break_m (v,j)\n else `Ok u\n )\n in if i <> undef then output i\n else\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\n in\n if t=1L then rep 1L n (fun lp ->\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if lp=1L then (\n let _,i = pw_sorted.(0) in\n output i;\n let j = input 0 in last_sp := sp.(j)\n ) else (\n if !last_sp = undef || used.(!last_sp) then (\n find 0\n ) else (\n output !last_sp;\n );\n let j = input 0 in\n last_sp := sp.(j)\n (* if sp.(j) <> undef then (\n last_sp := j\n ) else (\n last_sp := undef\n ) *)\n )\n ) else rep 1L n (fun lp ->\n let j = input 0 in\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if sp.(j) <> undef && not used.(sp.(j)) then (\n output sp.(j)\n ) else (\n find 0\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\nmodule IMap = Map.Make(Int64)\nlet () =\n let n,m = get_2_i64 0 in\n let pw = input_i64_array (n*2L) in\n let undef = -7 in\n let sp = make 1008 undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n );\n let used = make (i32 n*$2) false in\n let pw_sorted = pw |> mapi (fun i v->v,i) in\n sort (rv compare) pw_sorted;\n let t = get_i64 0\n in\n let last_sp = ref undef in\n let output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true in\n let input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j\n in\n if t=1L then rep 1L n (fun lp ->\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if lp=1L then (\n let _,i = pw_sorted.(0) in\n output i;\n let j = input 0 in ()\n ) else (\n if !last_sp = undef || used.(!last_sp) then (\n let _,i = repim 0 (length pw_sorted) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\n ) else (\n output !last_sp;\n );\n let j = input 0 in\n last_sp := sp.(j)\n (* if sp.(j) <> undef then (\n last_sp := j\n ) else (\n last_sp := undef\n ) *)\n )\n ) else rep 1L n (fun lp ->\n let j = input 0 in\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if sp.(j) <> undef && not used.(sp.(j)) then (\n output sp.(j)\n ) else (\n let _,i = repim 0 (length pw_sorted) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\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 undef = -7\n\nlet n,m = get_2_i64 0\nlet power = input_i64_array (n*2L)\nlet used = make (i32 n*$2) false\nlet sp =\n let sp = make (i32 n*$2) undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n ); sp\nlet i_sorted =\n let a = mapi (fun i v -> v,i) power in sort (rv compare) a;\n map (fun (v,i) -> i) a\n\nlet output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true\nlet input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j\nlet find _ =\n let i,j = fold_left (fun (p,q) i ->\n if not used.(i) then (\n let p = if p = undef then i else p in\n let q = if q = undef && sp.(i) <> undef then i else q in\n (p,q)\n ) else (p,q)\n ) (undef,undef) i_sorted in\n if i<>undef then output i\n else output j\n\nlet t = get_i64 0\nlet () =\n rep 1L (n-1L) (fun turn ->\n if turn=1L && t=1L then (\n find 0\n );\n if not (turn=n-1L && t=1L) then (\n let j = input 0 in\n if sp.(j) <> undef && not used.(sp.(j)) then\n output sp.(j)\n else find 0\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\nmodule IMap = Map.Make(Int64)\nlet () =\n let n,m = get_2_i64 0 in\n let pw = input_i64_array (n*2L) in\n let undef = -7 in\n let sp = make 2018 undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n );\n let used = make (i32 n*$2) false in\n let pw_sorted = pw |> mapi (fun i v->v,i) in\n sort (rv compare) pw_sorted;\n let t = get_i64 0\n in\n let last_sp = ref undef in\n let output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true in\n let input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j in\n let find _ =\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) && sp.(j) <> undef then `Break_m (v,j)\n else `Ok u\n )\n in if i <> undef then output i\n else\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\n in\n if t=1L then rep 1L n (fun lp ->\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if lp=1L then (\n let _,i = pw_sorted.(0) in\n output i;\n let j = input 0 in ()\n ) else (\n if !last_sp = undef || used.(!last_sp) then (\n find 0\n ) else (\n output !last_sp;\n );\n let j = input 0 in\n last_sp := sp.(j)\n (* if sp.(j) <> undef then (\n last_sp := j\n ) else (\n last_sp := undef\n ) *)\n )\n ) else rep 1L n (fun lp ->\n let j = input 0 in\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if sp.(j) <> undef && not used.(sp.(j)) then (\n output sp.(j)\n ) else (\n find 0\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 undef = -7\n\nlet n,m = get_2_i64 0\nlet power = input_i64_array (n*2L)\nlet used = make (i32 n*$2) false\nlet sp =\n let sp = make (i32 n*$2) undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n ); sp\nlet i_sorted =\n let a = mapi (fun i v -> v,i) power in sort (rv compare) a;\n map (fun (v,i) -> i) a\n\nlet output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true\nlet input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j\nlet output_find _ =\n let i,j = fold_left (fun (p,q) i ->\n if not used.(i) then (\n let p = if p = undef then i else p in\n let q = if q = undef && sp.(i) <> undef then i else q in\n (p,q)\n ) else (p,q)\n ) (undef,undef) i_sorted in\n if i<>undef then output i\n else output j\n\nlet t = get_i64 0\nlet () =\n rep 1L n (fun turn ->\n if turn=1L && t=1L then (\n output_find 0\n );\n let j = input 0 in\n if not (turn=n && t=1L) then (\n if sp.(j) <> undef && not used.(sp.(j)) then\n output sp.(j)\n else output_find 0\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\nmodule IMap = Map.Make(Int64)\nlet () =\n let n,m = get_2_i64 0 in\n let pw = input_i64_array (n*2L) in\n let undef = -7 in\n let sp = make 2018 undef in\n rep 1L m (fun _ ->\n let a,b = i32_get_2_ints 0 in\n let a,b = a-$1,b-$1 in\n sp.(a) <- b;\n sp.(b) <- a\n );\n let used = make (i32 n*$2) false in\n let pw_sorted = pw |> mapi (fun i v->v,i) in\n sort (rv compare) pw_sorted;\n let t = get_i64 0\n in\n let last_sp = ref undef in\n let output i =\n assert (not used.(i));\n printf \"%d\\n\" (i+$1); flush stdout;\n used.(i) <- true in\n let input _ =\n let j = i32_get_int 0 -$ 1 in used.(j) <- true; j in\n let find _ =\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) && sp.(j) <> undef && not used.(sp.(j)) then `Break_m (v,j)\n else `Ok u\n )\n in if i <> undef then output i\n else\n let _,i = repim 0 (length pw_sorted-$1) (-1L,undef)\n (fun u i ->\n let v,j = pw_sorted.(i) in\n if not used.(j) then `Break_m (v,j)\n else `Ok u\n )\n in output i\n in\n if t=1L then rep 1L n (fun lp ->\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if lp=1L then (\n let _,i = pw_sorted.(0) in\n output i;\n let j = input 0 in last_sp := sp.(j)\n ) else (\n if !last_sp = undef || used.(!last_sp) then (\n find 0\n ) else (\n output !last_sp;\n );\n let j = input 0 in\n last_sp := sp.(j)\n (* if sp.(j) <> undef then (\n last_sp := j\n ) else (\n last_sp := undef\n ) *)\n )\n ) else rep 1L n (fun lp ->\n let j = input 0 in\n (* printf \"cand::[%s]\\n\" @@ string_of_list (fun (v,i) -> sprintf \"(%2Ld,%2d|%2d)\" v (i+$1) @@ sp.(i)+$1)\n (pw_sorted |> to_list |> List.filter (fun v -> not used.(snd v))); *)\n if sp.(j) <> undef && not used.(sp.(j)) then (\n output sp.(j)\n ) else (\n find 0\n )\n )\n\n\n\n\n\n\n\n\n"}], "src_uid": "5e07da229bc2762f3a68bc083e34b9a1"} {"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\nlet readString () = Scanf.scanf \" %s\" (fun s -> s)\n\ntype result = First | Second | Draw\nexception First\n\n(* Note: all winning strategies use 1 move because otherwise the opponent\n * can just copy the previous move. *)\nlet solve n k s : result =\n let l = ref 0 in\n let m = ref 0 in\n let r = ref 0 in\n for i=0 to n-1 do if s.[i] = '1' then incr r done;\n let canSplit = ref false in\n try\n for i = 0 to n-1 do\n if s.[i] = '1' then begin incr m; decr r end;\n if i >= k && s.[i-k] = '1' then begin decr m; incr l end;\n if i >= k-1 then begin\n (* See if player 1 can win with this move. *)\n if !l + !r = 0 || !l + k + !r = n then raise First\n (* Otherwise, see if he can use it to stop player 2 from\n * winning with his move, by stranding 1s on each side of k 0s or\n * vice versa. *)\n else if 0 < !l && 0 < !r\n || !l < i+1-k && !r < n-i-1 then canSplit := true\n end\n done;\n (* Note that the splitting strategy is the only possible way to draw\n * when n \u2264 2k (either side can be chomped up in one go).\n *\n * When n \u2265 2k+1, and canSplit is false, then we must have\n * s = or vice versa. Either the prefix\n * or suffix will have length \u2265 k+1 so pick that side and flip the\n * k bits on the end.*)\n if !canSplit || n > 2*k then Draw else Second\n with First -> First\n\nlet main () =\n let n = readInt () in\n let k = readInt () in\n let s = readString () in\n print_endline (match solve n k s with First -> \"tokitsukaze\"\n | Second -> \"quailty\"\n | Draw -> \"once again\")\n\nlet () = main ()\n", "positive_code": [{"source_code": "let readInt () = Scanf.scanf \" %d\" (fun x -> x)\nlet readString () = Scanf.scanf \" %s\" (fun s -> s)\n\ntype result = First | Second | Draw\nexception First\n\n(* Note: all winning strategies use 1 move because otherwise the opponent\n * can just copy the previous move. *)\nlet solve n k s : result =\n let l = ref 0 in\n let m = ref 0 in\n let r = ref 0 in\n for i=0 to n-1 do if s.[i] = '1' then incr r done;\n let canDraw = ref false in\n try\n for i = 0 to n-1 do\n if s.[i] = '1' then begin incr m; decr r end;\n if i >= k && s.[i-k] = '1' then begin decr m; incr l end;\n if i >= k-1 then begin\n (* See if player 1 can win with this move. *)\n if !l = 0 && !r = 0 || !l + k + !r = n then raise First\n (* Otherwise, see if he use it to stop player 2 from\n * winning with his move, by stranding 1s on each side of k 0s or\n * vice versa. *)\n else if 0 < !l && 0 < !r\n || !l < i+1-k && !r < n-i-1 then canDraw := true\n end\n done;\n (* It's also always possible to draw when n \u2265 2k+1 (at each stage\n * just take the move that gets you closest to an even number of\n * 1s and 0s).\n *\n * The splitting strategy is the only way to draw when n \u2264 2k\n * (either side can be chomped up in one move). *)\n if !canDraw || n > 2*k then Draw else Second\n with First -> First\n\nlet main () =\n let n = readInt () in\n let k = readInt () in\n let s = readString () in\n print_endline (match solve n k s with First -> \"tokitsukaze\"\n | Second -> \"quailty\"\n | Draw -> \"once again\")\n\nlet () = main ()\n"}], "negative_code": [], "src_uid": "5e73099c7ec0b82aee54f0841c00f15e"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n\n let declen = Array.make n 1 in\n let inclen = Array.make n 1 in\n\n for i=1 to n-1 do\n if a.(i-1) < a.(i) then declen.(i) <- declen.(i-1) + 1\n done;\n\n for i=n-2 downto 0 do\n if a.(i) < a.(i+1) then inclen.(i) <- inclen.(i+1) + 1\n done;\n\n let best = ref 0 in\n\n for i=0 to n-1 do\n let leftend = if i=n-1 then 1 else 1+inclen.(i+1) in\n let rightend = if i=0 then 1 else 1+declen.(i-1) in\n let middle = if i=0 || i=n-1 then 0 else \n\tif a.(i-1) + 1 <= a.(i+1) - 1 then declen.(i-1) + inclen.(i+1) + 1\n\telse 0\n in\n best := max !best (max leftend (max rightend middle));\n done;\n\n printf \"%d\\n\" !best\n", "positive_code": [{"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet solve n arr =\n let dp_l = Array.create n 1L\n in\n (for i = 1 to Pervasives.( - ) n 1 do\n dp_l.(i) <-\n if arr.(Pervasives.( - ) i 1) < arr.(i)\n then Int64.add dp_l.(Pervasives.( - ) i 1) 1L\n else 1L\n done;\n Array.iter (Printf.eprintf \"%Ld \") dp_l;\n prerr_endline \"\";\n let dp_r = Array.create n 1L\n in\n (for i = Pervasives.( - ) n 2 downto 0 do\n dp_r.(i) <-\n if arr.(i) < arr.(Pervasives.( + ) i 1)\n then Int64.add dp_r.(Pervasives.( + ) i 1) 1L\n else 1L\n done;\n Array.iter (Printf.eprintf \"%Ld \") dp_r;\n prerr_endline \"\";\n let res = Array.create n 1L\n in\n (res.(0) <- Int64.add dp_r.(1) 1L;\n res.(Pervasives.( - ) n 1) <-\n Int64.add dp_l.(Pervasives.( - ) n 2) 1L;\n for i = 1 to Pervasives.( - ) n 2 do\n if\n (Pervasives.( + ) arr.(Pervasives.( - ) i 1) 1) <\n arr.(Pervasives.( + ) i 1)\n then\n res.(i) <-\n Int64.add\n (Int64.add dp_l.(Pervasives.( - ) i 1)\n dp_r.(Pervasives.( + ) i 1))\n 1L\n else\n res.(i) <-\n Int64.add\n (max dp_l.(Pervasives.( - ) i 1)\n dp_r.(Pervasives.( + ) i 1))\n 1L\n done;\n Array.iter (Printf.eprintf \"%Ld \") res;\n prerr_endline \"\";\n Printf.printf \"%Ld\\n\" (Array.fold_left max 0L res))))\n \nlet () =\n Scanf.scanf \"%d \"\n (fun n ->\n let arr = Array.init n (fun i -> Scanf.scanf \"%d \" (fun x -> x))\n in if n = 1 then print_endline \"1\" else solve n arr)\n \n"}], "negative_code": [{"source_code": "let solve n arr =\n let dp_l = Array.create n 1 in\n for i = 1 to n - 1 do\n dp_l.(i) <-\n (if arr.(i - 1) < arr.(i) then dp_l.(i - 1) + 1\n else 1)\n done;\n Array.iter (Printf.eprintf \"%d \") dp_l;\n prerr_endline \"\";\n let dp_r = Array.create n 1 in\n for i = n - 2 downto 0 do\n dp_r.(i) <-\n (if arr.(i) < arr.(i + 1) then dp_r.(i + 1) + 1\n else 1)\n done;\n Array.iter (Printf.eprintf \"%d \") dp_r;\n prerr_endline \"\";\n\n let res = Array.create n 1 in\n for i = 2 to n - 2 do\n if arr.(i - 1) + 1 < arr.(i + 1) then res.(i) <- dp_l.(i - 1) + dp_r.(i + 1) + 1\n done;\n Printf.printf \"%d\\n\" (Array.fold_left (max) 0 res)\n;;\n\nlet () =\n Scanf.scanf \"%d \" (fun n ->\n let arr = Array.init n (fun i ->\n Scanf.scanf \"%d \" (fun x -> x)) in\n solve n arr)\n;;\n"}, {"source_code": "let solve n arr =\n let dp_l = Array.create n 1 in\n for i = 1 to n - 1 do\n dp_l.(i) <-\n (if arr.(i - 1) < arr.(i) then dp_l.(i - 1) + 1\n else 1)\n done;\n Array.iter (Printf.eprintf \"%d \") dp_l;\n prerr_endline \"\";\n let dp_r = Array.create n 1 in\n for i = n - 2 downto 0 do\n dp_r.(i) <-\n (if arr.(i) < arr.(i + 1) then dp_r.(i + 1) + 1\n else 1)\n done;\n Array.iter (Printf.eprintf \"%d \") dp_r;\n prerr_endline \"\";\n\n let res = Array.create n 1 in\n res.(0) <- dp_l.(1) + 1;\n res.(n - 1) <- dp_r.(n - 2) + 1;\n for i = 2 to n - 2 do\n if arr.(i - 1) + 1 < arr.(i + 1) then res.(i) <- dp_l.(i - 1) + dp_r.(i + 1) + 1\n else res.(i) <- max dp_l.(i) dp_r.(i)\n done;\n Array.iter (Printf.eprintf \"%d \") res;\n prerr_endline \"\";\n\n Printf.printf \"%d\\n\" (Array.fold_left (max) 0 res)\n;;\n\nlet () =\n Scanf.scanf \"%d \" (fun n ->\n let arr = Array.init n (fun i ->\n Scanf.scanf \"%d \" (fun x -> x)) in\n solve n arr)\n;;\n"}], "src_uid": "9e0d271b9bada1364dfcb47297549652"} {"source_code": "let num_of_vowels str =\n let vowels = ['a'; 'e'; 'i'; 'o'; 'u'] in\n let rec loop = function\n | -1 -> 0\n | i ->\n let add = if List.mem (String.get str i) vowels then 1 else 0 in\n add + (loop (i-1))\n in\n loop ((String.length str)-1)\n\nlet solve haiku =\n if num_of_vowels (List.nth haiku 0) == 5 &&\n num_of_vowels (List.nth haiku 1) == 7 &&\n num_of_vowels (List.nth haiku 2) == 5\n then \"YES\"\n else \"NO\"\n\nlet rec input_haiku = function\n | 0 -> []\n | i -> (input_line stdin) :: input_haiku (i-1)\n \nlet input_haiku = List.rev (input_haiku 3)\n \nlet _ =\n Printf.printf \"%s\\n\" (solve (input_haiku))\n \n \n \n\n", "positive_code": [{"source_code": "let rec count s =\n\tif String.length s = 0 then 0\n\telse (\n\t\tlet c = s.[0] in\n\t\t(match c with\n\t\t|'a'|'e'|'i'|'o'|'u' -> 1\n\t\t|_ -> 0) + (count (String.sub s 1 (String.length s - 1)))\n\t)\n;;\n\nlet () =\n\tlet a = count (read_line ()) in\n\tlet b = count (read_line ()) in\n\tlet c = count (read_line ()) in\n\tprint_string (\n\t\tif a = 5 && b = 7 && c = 5 then \"YES\" else \"NO\"\n\t)\n;;\n"}], "negative_code": [], "src_uid": "46d734178b3acaddf2ee3706f04d603d"} {"source_code": "open Printf\nopen Scanf\n\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\n let n = read_int() in\n let m = read_int() in \n let a = Array.init n (fun _ -> read_int()) in\n\n Array.sort (fun a b -> compare b a) a;\n\n let rec loop i ac = if ac >= m then i else loop (i+1) (ac + a.(i)) in\n\n printf \"%d\\n\" (loop 0 0)\n", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n Array.sort compare a;\n let pos = ref (n - 1) in\n let s = ref 0 in\n while !pos >= 0 && !s + a.(!pos) < m do\n\ts := !s + a.(!pos);\n\tdecr pos;\n done;\n Printf.printf \"%d\\n\" (n - !pos)\n"}], "negative_code": [], "src_uid": "a02a9e37a4499f9c86ac690a3a427466"} {"source_code": "open Scanf\nopen Printf\n\nlet gemacht n s =\n\tlet rec loop i =\n\t\tif i = n then None\n\t\telse if s.[i] = '8' then Some i\n\t\telse loop (i + 1)\n\tin\n\tmatch loop 0 with\n\t| None -> false\n\t| Some i -> n - i >= 11 \n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdin \" %s \" (fun x -> x)\nlet () = \n\tlet t = read_int () in\n\tfor i = 1 to t do\n\t\tlet n = read_int () in\n\t\tlet s = read_string () in\n\t\tif gemacht n s then printf \"YES\\n\" else printf \"NO\\n\";\n\tdone\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet solve n s =\n let rec loop i = if i >= n then None\n else if s.[i] = '8' then Some i\n else loop (i+1)\n in\n match loop 0 with\n | None -> false\n | Some j -> n-1-j >= 10\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdin \" %s \" (fun x -> x)\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let s = read_string() in\n if solve n s then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}], "negative_code": [], "src_uid": "bcdd7862b718d6bcc25c9aba8716d487"} {"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\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) 0L\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let x = Int64.of_int (read_int ()) in\n let c = Array.init n (fun _ -> Int64.of_int (read_int())) in\n\n Array.sort compare c;\n\n let answer = sum 0 (n-1) (\n fun i -> \n let x' = max 1L (x -- (Int64.of_int i)) in\n c.(i) ** x'\n ) in\n \n printf \"%Ld\\n\" answer\n\n", "positive_code": [{"source_code": "let solve n x c =\n let rec aux i x time =\n if (i = n) then time\n else\n let chapters = c.(i) in\n aux (i+1) (max (x-1) 1) Int64.(add time (mul chapters (of_int x)))\n in\n aux 0 x Int64.zero\n\nlet main = \n let (n, x) = Scanf.scanf \"%d %d\\n\" (fun n x -> (n,x)) in\n let c = Array.init n (fun _ -> Scanf.scanf \"%Ld \" (fun x -> x)) in\n let () = Array.fast_sort compare c in\n let solution = solve n x c in\n Printf.printf \"%Ld\\n\" solution\n"}], "negative_code": [{"source_code": "let solve n x c =\n let rec aux i x time =\n if (i = n) then time\n else\n let chapters = c.(i) in\n aux (i+1) (max (x-1) 1) (time + chapters*x)\n in\n aux 0 x 0\n\nlet main = \n let (n, x) = Scanf.scanf \"%d %d\\n\" (fun n x -> (n,x)) in\n let c = Array.init n (fun _ -> Scanf.scanf \"%d \" (fun x -> x)) in\n let () = Array.fast_sort compare c in\n let solution = solve n x c in\n Printf.printf \"%d\\n\" solution\n"}], "src_uid": "ce27e56433175ebf9d3bbcb97e71091e"} {"source_code": "open Printf;;\nopen Scanf;;\n\nlet input () =\n let n, m = scanf \"%d %d \" (fun x y -> x, y) in\n let arr = Array.make m 0 in\n for i = 0 to m - 1 do\n arr.(i) <- scanf \"%d \" (fun x -> x)\n done;\n (n, m, arr)\n \nlet solve (n, m, arr) =\n let mx, mn = (ref 0, ref 0) in\n let a = ref arr in\n let b = ref (Array.copy arr) in\n for i = 0 to n - 1 do\n begin\n Array.fast_sort (fun x y -> x - y) !a;\n a := (Array.of_list (List.filter (fun x -> x > 0) (Array.to_list !a)));\n Array.fast_sort (fun x y -> x - y) !b;\n b := (Array.of_list (List.filter (fun x -> x > 0) (Array.to_list !b)));\n let len_a = Array.length !a in\n mx := (!mx + !a.(len_a - 1));\n mn := !mn + !b.(0);\n !a.(len_a - 1) <- !a.(len_a - 1) - 1;\n !b.(0) <- !b.(0) - 1\n end\n done;\n !mx, !mn\n\nlet main () =\n let inp = input () in\n let (mx, mn) = solve inp in\n printf \"%d %d\\n\" mx mn\n\nlet () = main ()\n", "positive_code": [{"source_code": "let _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let m = Scanf.scanf \" %d\" (fun x -> x) in\n let a = Array.make m 0 in\n let b = Array.make m 0 in\n for i = 0 to m - 1 do\n let t = Scanf.scanf \" %d\" (fun x -> x) in\n a.(i) <- t;\n b.(i) <- t\n done;\n\n let x = ref 0 in\n let r = ref n in\n Array.sort (fun x y -> x - y) a;\n for i = 0 to m - 1 do\n let c = min a.(i) !r in\n x := !x + c * a.(i) - c * (c - 1) / 2;\n r := !r - c\n done;\n\n let y = ref 0 in\n let r = ref n in\n Array.sort (fun x y -> y - x) b;\n while !r > 0 do\n let c = b.(0) in\n for i = 0 to m - 1 do\n if !r > 0 && b.(i) = c then begin\n y := !y + c;\n r := !r - 1;\n b.(i) <- b.(i) - 1\n end\n done\n done;\n\n print_int !y;\n print_char ' ';\n print_int !x;\n print_char '\\n'\n;;\n"}], "negative_code": [], "src_uid": "6dea4611ca210b34ae2da93ebfa9896c"} {"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nmodule L = struct\n let iter lst f = List.iter f lst\n let map lst f = List.map f lst\nend\n\nmodule A = struct\n let iteri f a = Array.iteri a f\nend\n\nlet bfs graph n start f =\n let flags = Array.make n false in\n let q = Queue.create () in\n Queue.add start q;\n flags.(start) <- true;\n while not (Queue.is_empty q) do\n let v = Queue.take q in\n L.iter graph.(v) (fun (i, dir) ->\n if not flags.(i) then\n (Queue.add i q;\n f v i dir;\n flags.(i) <- true))\n done\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.make n [] in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) <- (t, true) :: graph.(f);\n graph.(t) <- (f, false) :: graph.(t)\n done;\n let sum = ref 0 in\n bfs graph n 0 (fun _ _ dir -> if not dir then incr sum);\n let sums = Array.make n !sum in\n let min_sum = ref !sum in\n bfs graph n 0 (fun f t dir ->\n sums.(t) <- sums.(f) + (if dir then 1 else -1);\n min_sum := min !min_sum sums.(t));\n print_endline (string_of_int !min_sum);\n let b = Buffer.create (10 * n) in\n A.iteri sums (fun i s ->\n if s = !min_sum then Buffer.add_string b (string_of_int (i + 1) ^ \" \"));\n print_endline (Buffer.sub b 0 (Buffer.length b - 1))\n", "positive_code": [{"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet bfs graph start f =\n let flags = Array.make (Array.length graph) false in\n let q = Queue.create () in\n let fold_vertex result v =\n List.fold_left (fun result (i, dir) ->\n if not flags.(i) then (Queue.add i q; flags.(i) <- true; f result v i dir)\n else result) result graph.(v)\n in\n let rec main_loop result = match Queue.is_empty q with\n | true -> result\n | false -> main_loop (fold_vertex result (Queue.take q))\n in\n Queue.add start q;\n flags.(start) <- true;\n main_loop\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.make n [] in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) <- (t, true) :: graph.(f);\n graph.(t) <- (f, false) :: graph.(t)\n done;\n let sum = bfs graph 0 (fun sum _ _ dir -> if dir then sum else sum + 1) 0 in\n let sums = Array.make n sum in\n let min_sum = bfs graph 0 (fun min_sum f t dir ->\n sums.(t) <- sums.(f) + (if dir then 1 else -1);\n min min_sum sums.(t)) sum\n in\n print_endline (string_of_int min_sum);\n let b = Buffer.create (10 * n) in\n Array.iteri (fun i s ->\n if s = min_sum then Buffer.add_string b (string_of_int (i + 1) ^ \" \")) sums;\n print_endline (Buffer.sub b 0 (Buffer.length b - 1))\n"}, {"source_code": "let read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet bfs graph start f =\n let flags = Array.make (Array.length graph) false in\n let q = Queue.create () in\n let fold_vertex result v =\n List.fold_left (fun result (i, dir) ->\n if not flags.(i) then (Queue.add i q; flags.(i) <- true; f result v i dir)\n else result) result graph.(v)\n in\n let rec main_loop result = match Queue.is_empty q with\n | true -> result\n | false -> main_loop (fold_vertex result (Queue.take q))\n in\n Queue.add start q;\n flags.(start) <- true;\n main_loop\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.make n [] in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) <- (t, true) :: graph.(f);\n graph.(t) <- (f, false) :: graph.(t)\n done;\n let sum = bfs graph 0 (fun sum _ _ dir -> if dir then sum else sum + 1) 0 in\n let sums = Array.make n sum in\n let min_sum = bfs graph 0 (fun min_sum f t dir ->\n sums.(t) <- sums.(f) + (if dir then 1 else -1);\n min min_sum sums.(t)) sum\n in\n print_endline (string_of_int min_sum);\n let b = Buffer.create (10 * n) in\n Array.iteri (fun i s ->\n if s = min_sum then Buffer.add_string b (string_of_int (i + 1) ^ \" \")) sums;\n print_endline (Buffer.sub b 0 (Buffer.length b - 1))"}], "negative_code": [{"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet (=::) list_ref a = list_ref := a :: !list_ref\n\nmodule L = struct\n let iter lst f = List.iter f lst\n let map lst f = List.map f lst\n let sort = List.sort\nend\n\nlet bfs graph n start f =\n let flags = Array.make n false in\n let q = Queue.create () in\n Queue.add start q;\n while not (Queue.is_empty q) do\n let v = Queue.take q in\n L.iter !(graph.(v)) (fun (i, dir) ->\n if not flags.(i) then\n (Queue.add i q;\n f v i dir;\n flags.(i) <- true))\n done\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.make n (ref []) in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) =:: (t, true);\n graph.(t) =:: (f, false)\n done;\n let sum = ref 0 in\n bfs graph n 0 (fun f t dir -> if not dir then incr sum);\n let sums = Array.make n !sum in\n let min = ref !sum in\n let minis = ref [] in\n bfs graph n 0 (fun f t dir ->\n sums.(t) <- sums.(f) + (if dir then 1 else -1);\n if sums.(t) < !min then (min := sums.(t); minis := [t])\n else if sums.(t) = !min then minis =:: t);\n print_endline (string_of_int !min);\n print_endline (String.concat \" \"\n (L.map (L.sort compare !minis)\n (fun i -> (string_of_int (i + 1)))))\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet (=::) list_ref a = list_ref := a :: !list_ref\n\nmodule L = struct\n let iter lst f = List.iter f lst\n let map lst f = List.map f lst\n let sort = List.sort\nend\n\nlet bfs graph n start f =\n let flags = Array.make n false in\n let q = Queue.create () in\n Queue.add start q;\n while not (Queue.is_empty q) do\n let v = Queue.take q in\n L.iter !(graph.(v)) (fun (i, dir) ->\n if not flags.(i) then\n (Queue.add i q;\n f v i dir;\n flags.(i) <- true))\n done\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.init n (fun _ -> ref []) in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) =:: (t, true);\n graph.(t) =:: (f, false)\n done;\n let sum = ref 0 in\n bfs graph n 0 (fun f t dir -> if not dir then incr sum);\n let sums = Array.make n !sum in\n let min = ref !sum in\n let minis = ref [] in\n bfs graph n 0 (fun f t dir ->\n sums.(t) <- sums.(f) + (if dir then 1 else -1);\n if sums.(t) < !min then (min := sums.(t); minis := [t])\n else if sums.(t) = !min then minis =:: t);\n print_endline (string_of_int !min);\n print_endline (String.concat \" \"\n (L.map (L.sort compare !minis)\n (fun i -> (string_of_int (i + 1)))))\n"}, {"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet (=::) list_ref a = list_ref := a :: !list_ref\n\nlet list_iter lst f = List.iter f lst\n\nlet list_map lst f = List.map f lst\n\nlet bfs graph n start f =\n let flags = Array.make n false in\n let q = Queue.create () in\n Queue.add start q;\n while not (Queue.is_empty q) do\n let v = Queue.take q in\n list_iter !(graph.(v)) (fun (i, dir) ->\n if not flags.(i) then\n (Queue.add i q;\n f v i dir;\n flags.(i) <- true))\n done\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let graph = Array.make n (ref []) in\n for i = 1 to n - 1 do\n let f, t = read \"%d %d\\n\" (fun f t -> f - 1, t - 1) in\n graph.(f) =:: (t, true);\n graph.(t) =:: (f, false)\n done;\n let sum = ref 0 in\n bfs graph n 0 (fun f t dir -> if not dir then incr sum);\n let sums = Array.make n 0 in\n sums.(0) <- !sum;\n let min = ref !sum in\n let minis = ref [] in\n bfs graph n 0 (fun f t dir ->\n sums.(t) <- (if dir then (+) else (-)) sums.(f) 1;\n if sums.(t) < !min then\n (minis := [t];\n min := sums.(t))\n else if sums.(t) = !min then\n minis =:: t);\n print_endline (string_of_int !min);\n print_endline (String.concat \" \"\n (list_map !minis (fun i -> (string_of_int (i + 1)))))\n\n\n\n\n\n\n\n\n"}], "src_uid": "fb5c6182b9cad133d8b256f8e72e7e3b"} {"source_code": "let () = \n let s = read_line() in\n let n = String.length s in\n let h = Array.make 26 0 in\n\n for i=0 to n-1 do\n let c = (int_of_char s.[i]) - (int_of_char 'a') in\n\th.(c) <- h.(c) +1\n done;\n\n let odd = ref 0 in\n \n for i=0 to 25 do\n\tif h.(i) mod 2 = 1 then odd := !odd + 1\n done;\n\n if (!odd >= 1 && !odd mod 2 = 0) then Printf.printf \"Second\\n\" else Printf.printf \"First\\n\"\n", "positive_code": [{"source_code": "(* CF odd game prob 276 B *)\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 ss = rdln();;\n\nlet rec isOdd s i c cnt = \n\tif i >= String.length s then ((cnt mod 2) = 1)\n\telse \n\t\tlet cnt1 = cnt + (if c = s.[i] then 1 else 0) in\n\t\tisOdd s (i+1) c cnt1;;\n\nlet rec nOdd s c cnto =\n\tif c > 'z' then cnto\n\telse \n\t\tlet iso = isOdd s 0 c 0 in\n\t\tlet cnto1 = cnto + (if iso then 1 else 0) in\n\t\tlet nextc = char_of_int (int_of_char c + 1) in\n\t\tnOdd s nextc cnto1;;\n\nlet main() =\n\tlet no = nOdd ss 'a' 0 in\n\tlet so = if no < 2 || (no mod 2) = 1 then \"First\" else \"Second\" in\n\t( print_string so; print_newline() );;\n\t\t\nmain();;"}], "negative_code": [], "src_uid": "bbf2dbdea6dd3aa45250ab5a86833558"} {"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 an = fold_for 0 n ~init:[] ~f:(fun acc _ ->\n Scanf.scanf \"%d \" ident :: acc) in\n let bn = fold_for 0 n ~init:[] ~f:(fun acc _ ->\n Scanf.scanf \"%d \" ident :: acc) in\n let cn = fold_for 0 n ~init:[] ~f:(fun acc _ ->\n Scanf.scanf \"%d \" ident :: acc) in\n let rec combine an bn cn = match an, bn, cn with\n | (a :: an, b :: bn, c :: cn) -> (a, b, c) :: combine an bn cn\n | ([], [], []) -> []\n | _ -> failwith \"combine\" in\n let xs = combine an bn cn in\n let map = Hashtbl.create 1000 in\n let rec iter prev i xs =\n try\n Hashtbl.find map (prev, i)\n with\n | Not_found -> begin\n match xs with\n | (a, b, c) :: ((_ :: _) as xs) -> begin\n let res = \n match prev with\n | `p -> max (b + iter `p (i + 1) xs) (c + iter `f (i + 1) xs)\n | `f -> max (a + iter `p (i + 1) xs) (b + iter `f (i + 1) xs) in\n Hashtbl.add map (prev, i) res;\n res\n end\n | [a, b, c] -> begin\n let res = \n match prev with\n | `p -> (b + iter `p (i + 1) [])\n | `f -> (a + iter `p (i + 1) []) in\n Hashtbl.add map (prev, i) res;\n res\n end\n | [] -> 0\n end\n in \n Printf.printf \"%d\\n\" @@ iter `f 0 xs\n;;\n", "positive_code": [{"source_code": "let line_stream_from_channel in_chan = \n Stream.from\n (fun _ ->\n try Some (input_line in_chan) \n with _ -> None);;\n\nlet rec print_l l = match l with\n| hd::tl -> (print_int hd; print_string \" \";print_l tl)\n| _ -> print_newline ();;\n\n\nlet to_List strm len= \n let lt = List.map int_of_string (Str.split (Str.regexp \" \") (Stream.next strm)) in\n if List.length lt != len then failwith \"WrangData\" else lt;;\n\nlet oComp x y = match x,y with\n| Some i, Some j -> Some(max i j)\n| None, i -> i\n| i, None -> i;;\n\nlet oAdd o x = match o with\n|Some y -> Some (x+y)\n|None -> None;;\n\nlet total l =\n List.fold_left (+) 0 l;;\nlet path_cached l1 l2 =\n let path_ht = Hashtbl.create ((List.length l1)*4 ) in\n let length = List.length l1 in \n let hnum l s ol = (\n (List.length l) +1 \n + (if ol!=[] then length else 0))*s in\n let rec path l1 l2 switch ol =\n let out = \n try Hashtbl.find path_ht (hnum l1 switch ol)\n\n with Not_found ->\n (let res = (match l1, l2, ol with \n | h1::t1, h2::t2, [] -> (\n let vnew, valt = ((*if switch=1 then*) h1,h2 (*else h2,h1*)) in\n oComp ((*if (vlast + vnew <=0)&&(tl!=[]) then None \n else*) oAdd (path t1 t2 (-1*switch) (vnew::[])) vnew)\n ((*if (vlast (\n let vnew, valt = (if switch=1 then h1,h2 else h2,h1) in\n oComp ((*if (vlast + vnew <=0) then None \n else*) (oAdd (path t1 t2 (-1*switch) (vnew::ol)) vnew))\n ((*if (vlast if (switch= -1) then Some 0\n else None) in\n Hashtbl.add path_ht (hnum l1 switch ol) res;\n(*\n print_string \"Added \";\n print_int (hnum l1 switch ol);\n print_string \" with res = \";\n (match shifted_res with\n |Some num -> print_int num;\n |None -> print_string \"None\";);\n print_string \"\\n\\t\";\n print_l ol;\n (*print_newline ();*)\n*)\n res) in\n out in\n path l1 l2 1 [] ;;\n\nlet main = \n let stream = line_stream_from_channel stdin in\n try\n let n = int_of_string (Stream.next stream) in\n let a = to_List stream n in\n let b = to_List stream n in\n let c = to_List stream n in\n let rev_ab = List.rev_map2 (fun x y -> x-y) a b in\n let rev_cb = List.rev_map2 (fun x y -> x-y) c b in\n(*\n print_l rev_ab;\n print_l rev_cb;\n*) \n let oRes = path_cached rev_ab rev_cb in\n match oRes with\n | Some i -> print_int (i+ (total b)); print_newline ();\n | None -> print_string \"No result\";\n with _ -> raise Exit\n;;\n\nlet () = \n try main\n with Exit -> print_string \"Bye-Bye\\n\";;\n"}], "negative_code": [{"source_code": "let line_stream_from_channel in_chan = \n Stream.from\n (fun _ ->\n try Some (input_line in_chan) \n with _ -> None);;\n\nlet to_List strm len= \n let lt = List.map int_of_string (Str.split (Str.regexp \" \") (Stream.next strm)) in\n if List.length lt != len then failwith \"WrangData\" else lt;;\n\nlet oComp x y = match x,y with\n| Some i, Some j -> Some(max i j)\n| None, i -> i\n| i, None -> i;;\n\nlet oAdd o x = match o with\n|Some y -> Some (x+y)\n|None -> None;;\n\nlet total l =\n List.fold_left (+) 0 l;;\nlet path_cached l1 l2 =\n let path_ht = Hashtbl.create ((List.length l1)*2 + 2 ) in\n let rec path l1 l2 switch ol =\n let out = \n try Hashtbl.find path_ht (((List.length l1) +1)*switch)\n\n with Not_found ->\n (let res = (match l1, l2, ol with \n | h1::t1, h2::t2, [] -> (\n let vnew, valt = ((*if switch=1 then*) h1,h2 (*else h2,h1*)) in\n oComp ((*if (vlast + vnew <=0)&&(tl!=[]) then None \n else*) (path t1 t2 (-1*switch) (vnew::[])))\n ((*if (vlast (\n let vnew, valt = (if switch=1 then h1,h2 else h2,h1) in\n oComp (if (vlast + vnew <=0) then None \n else (path t1 t2 (-1*switch) (vnew::ol)))\n (if (vlast if (switch= -1) then Some (total ol)\n else None) in\n let shifted_res = (oAdd res (-(total ol))) in\n Hashtbl.add path_ht (((List.length l1) +1)*switch) shifted_res;\n (*print_string \"Added \";\n print_int ((List.length l1)*switch);\n print_string \" with res = \";\n (match shifted_res with\n |Some num -> print_int num;\n |None -> print_string \"None\";);\n print_newline ();*)\n shifted_res) in\n oAdd out (total ol) in\n path l1 l2 1 [] ;;\n\nlet main = \n let stream = line_stream_from_channel stdin in\n try\n let n = int_of_string (Stream.next stream) in\n let a = to_List stream n in\n let b = to_List stream n in\n let c = to_List stream n in\n let rev_ab = List.rev_map2 (fun x y -> x-y) a b in\n let rev_cb = List.rev_map2 (fun x y -> x-y) c b in\n let oRes = path_cached rev_ab rev_cb in\n match oRes with\n | Some i -> print_int (i+ (total b)); print_newline ();\n | None -> print_string \"No result\";\n with _ -> raise Exit\n;;\n\nlet () = \n try main\n with Exit -> print_string \"Bye-Bye\\n\";;\n"}], "src_uid": "99cf10673cb275ad3b90bcd3757ecd47"} {"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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 150000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n (*let rec phi m k =\n (*incr cnt;*)\n if k = 0\n then (\n (*incr cnt1;*)\n n /| m\n ) else if k = c then (\n (*incr cnt4;*)\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n (*incr cnt2;*)\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n (*incr cnt3;*)\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in*)\n let rec phi32 n k =\n (*incr cnt;*)\n if k = 0\n then n\n else if k = c\n then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)\n else if n <= n2\n then phi'.(n).(k)\n else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)\n in\n let rec phi n k =\n if k = 0\n then n\n else if k = c\n then\n (n /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)\n else if n <= 1000000000L\n then Int64.of_int (phi32 (Int64.to_int n) k)\n else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)\n in\n let res = phi n k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\n", "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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 250000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n (*let rec phi m k =\n (*incr cnt;*)\n if k = 0\n then (\n (*incr cnt1;*)\n n /| m\n ) else if k = c then (\n (*incr cnt4;*)\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n (*incr cnt2;*)\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n (*incr cnt3;*)\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in*)\n let rec phi32 n k =\n (*incr cnt;*)\n if k = 0\n then n\n else if k = c\n then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)\n else if n <= n2\n then phi'.(n).(k)\n else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)\n in\n let rec phi n k =\n if k = 0\n then n\n else if k = c\n then\n (n /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)\n else if n <= 1000000000L\n then Int64.of_int (phi32 (Int64.to_int n) k)\n else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)\n in\n let res = phi n k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 250000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n let rec phi m k =\n incr cnt;\n if k = 0\n then (\n incr cnt1;\n n /| m\n ) else if k = c then (\n incr cnt4;\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n incr cnt2;\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n incr cnt3;\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 200000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n (*let rec phi m k =\n (*incr cnt;*)\n if k = 0\n then (\n (*incr cnt1;*)\n n /| m\n ) else if k = c then (\n (*incr cnt4;*)\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n (*incr cnt2;*)\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n (*incr cnt3;*)\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in*)\n let rec phi32 n k =\n (*incr cnt;*)\n if k = 0\n then n\n else if k = c\n then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)\n else if n <= n2\n then phi'.(n).(k)\n else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)\n in\n let rec phi n k =\n if k = 0\n then n\n else if k = c\n then\n (n /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)\n else if n <= 1000000000L\n then Int64.of_int (phi32 (Int64.to_int n) k)\n else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)\n in\n let res = phi n k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 250000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n let rec phi m k =\n (*incr cnt;*)\n if k = 0\n then (\n (*incr cnt1;*)\n n /| m\n ) else if k = c then (\n (*incr cnt4;*)\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n (*incr cnt2;*)\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n (*incr cnt3;*)\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\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 k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make k 0 in\n let _ =\n for i = 0 to k - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n (*Array.sort (fun x y -> compare y x) a;*)\n Array.sort compare a;\n in\n let isqrt n = Int64.of_float (sqrt (Int64.to_float n)) in\n let sn = isqrt n in\n let cn = Int64.of_float ((Int64.to_float n) ** (1.0 /. 3.0) +. 0.00001) in\n let n2 = min 170000L n in\n let n2 = Int64.to_int n2 in\n let phi' = Array.make_matrix (n2 + 1) (k + 1) 0 in\n let _ =\n for i = 1 to n2 do\n phi'.(i).(0) <- i;\n for j = 1 to k do\n\tphi'.(i).(j) <- phi'.(i).(j - 1) - phi'.(i / a.(j - 1)).(j - 1)\n done;\n done;\n in\n let n3 = n /| Int64.of_int n2 in\n let (c, q) =\n let c = ref 0 in\n let q = ref 1 in\n while !c < k && !q * a.(!c) <= n2 do\n\tq := !q * a.(!c);\n\tincr c;\n done;\n (!c, !q)\n in\n let cnt = ref 0 in\n let cnt1 = ref 0 in\n let cnt2 = ref 0 in\n let cnt3 = ref 0 in\n let cnt4 = ref 0 in\n (*let rec phi m k =\n (*incr cnt;*)\n if k = 0\n then (\n (*incr cnt1;*)\n n /| m\n ) else if k = c then (\n (*incr cnt4;*)\n (n /| m /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem (n /| m) (Int64.of_int q))).(c)\n ) else if m > n3\n then (\n (*incr cnt2;*)\n Int64.of_int phi'.(Int64.to_int (n /| m)).(k)\n ) else (\n (*incr cnt3;*)\n phi m (k - 1) -| phi (m *| Int64.of_int a.(k - 1)) (k - 1)\n )\n in\n let res = phi 1L k in*)\n let rec phi32 n k =\n (*incr cnt;*)\n if k = 0\n then n\n else if k = c\n then (n / q) * phi'.(q).(k) + phi'.(n mod q).(c)\n else if n <= n2\n then phi'.(n).(k)\n else phi32 n (k - 1) - phi32 (n / a.(k - 1)) (k - 1)\n in\n let rec phi n k =\n if k = 0\n then n\n else if k = c\n then\n (n /| Int64.of_int q) *|\n\t Int64.of_int phi'.(q).(k) +|\n\t Int64.of_int\n\t\tphi'.(Int64.to_int (Int64.rem n (Int64.of_int q))).(c)\n else if n <= 1000000000L\n then Int64.of_int (phi32 (Int64.to_int n) k)\n else phi n (k - 1) -| phi (n /| Int64.of_int a.(k - 1)) (k - 1)\n in\n let res = phi n k in\n Printf.eprintf \"asd %d %d %d %d %d %d\\n\" !cnt !cnt1 !cnt2 !cnt3 !cnt4 c;\n Printf.printf \"%Ld\\n\" res\n"}], "negative_code": [], "src_uid": "cec0f6c267fa76191a3784b08e39acd6"} {"source_code": "type tree = Empty | Node of tree * tree * tree\n\nlet rec insert t str i len =\n if i=len then Node (Empty,Empty,Empty) else (\n let (ta,tb,tc) = match t with Empty -> (Empty,Empty,Empty) | Node (a,b,c) -> (a,b,c) in\n match str.[i] with \n | 'a' -> Node (insert ta str (i+1) len, tb, tc)\n | 'b' -> Node (ta, insert tb str (i+1) len, tc)\n | 'c' -> Node (ta, tb, insert tc str (i+1) len)\n | _ -> failwith \"bad input\"\n )\n\nlet rec search t str i len ecount =\n if ecount > 1 || t=Empty then false\n else if i=len then ecount=1 else (\n match t with Empty -> false\n | Node (ta,tb,tc) ->\n\tlet ec x = if str.[i]=x then 0 else 1 in\n\tsearch ta str (i+1) len (ecount + (ec 'a')) ||\n\t search tb str (i+1) len (ecount + (ec 'b')) ||\n\t search tc str (i+1) len (ecount + (ec 'c'))\n )\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let string = Array.init n (fun _ -> read_string()) in\n let query = Array.init m (fun _ -> read_string()) in\n\n let tree = Array.make (6*100_000+1) Empty in\n\n for i=0 to n-1 do\n let len = String.length string.(i) in\n tree.(len) <- insert tree.(len) string.(i) 0 len;\n done;\n\n for i=0 to m-1 do\n let len = String.length query.(i) in\n let ans = search tree.(len) query.(i) 0 len 0 in\n if ans then printf \"YES\\n\" else printf \"NO\\n\"\n done\n", "positive_code": [{"source_code": "type 'a trie = {\n value : 'a option;\n children : 'a trie option array;\n}\n\nlet list_of_string s = Array.to_list (Array.init (String.length s) (String.get s))\n\n(* empty trie *)\nlet empty () =\n { value = None;\n children = Array.make 3 None;\n }\n\nlet insert t s =\n let rec insert' t p = function\n | [] -> { t with value = Some p }\n | c :: cs ->\n (* index into child array *)\n let i = Char.code c - Char.code 'a' in\n (* replacement node *)\n let n = match t.children.(i) with\n | None -> empty ()\n | Some t -> t\n in\n t.children.(i) <- Some (insert' n c cs);\n t\n in\n insert' t 'z' (list_of_string s)\n\nlet find t s =\n let rec find' t p c = function\n | [] -> c && t.value = Some p\n | x :: xs ->\n if c\n then begin\n match t.children.(Char.code x - Char.code 'a') with\n | None -> false\n | Some c -> find' c x true xs\n end\n else begin\n let rec aux a i =\n if i = 3 then a\n else\n match t.children.(i) with\n | None -> aux a (succ i)\n | Some t -> aux (a || find' t (Char.chr (i + Char.code 'a')) (Char.code x - Char.code 'a' <> i) xs) (succ i)\n in\n aux false 0\n end\n in\n find' t 'y' false (list_of_string s)\n\nlet () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n (* read memory and construct trie *)\n let rec aux t i =\n if i = n then t else begin\n let t = Scanf.scanf \"%s\\n\" (insert t) in\n aux t (succ i)\n end\n in\n let t = aux (empty ()) 0 in\n\n (* read and response to queries *)\n for i = 1 to m do\n let q = Scanf.scanf \"%s\\n\" (fun s -> s) in\n print_endline (if find t q then \"YES\" else \"NO\")\n done\n)\n"}], "negative_code": [], "src_uid": "146c856f8de005fe280e87f67833c063"} {"source_code": "(** a node is a string value and list\n * of outgoing edges *)\ntype node = {\n v : string;\n e : int list;\n i : int;\n o : int;\n}\nlet empty_node v = { v; e = []; i = 0; o = 0 }\n\n(** doubly-linked list element *)\ntype 'a el = {\n v : 'a;\n mutable next : 'a el option;\n mutable prev : 'a el option;\n}\n\nexception No_trail\n\nlet get_password edges nodes n =\n (* dlist of tour *)\n let dl = { v = n; next = None; prev = None } in\n (* end of list *)\n let tl = ref dl in\n\n (* get the initial trail *)\n let rec trail n tl =\n let node = Hashtbl.find nodes n in\n match node.e with\n | e :: es ->\n let e = String.sub edges.(e) 1 2 in\n let el = { v = e; next = None; prev = Some !tl } in\n !tl.next <- Some el;\n tl := el;\n Hashtbl.replace nodes n { node with e = es };\n trail e tl\n | [] -> ()\n in\n trail n tl;\n\n (* build the final password *)\n let rec build n =\n (* follow any further edges from this node\n * if necessary *)\n let next = n.next in\n let tl = ref n in\n trail n.v tl;\n (* check that we generated a cycle *)\n if !tl.v = n.v then\n !tl.next <- next\n else\n raise No_trail;\n\n match n.next with\n | None -> ()\n | Some n -> build n\n in\n build dl;\n dl\n\nlet rec print_password p =\n match p.next with\n | None -> ()\n | Some n ->\n print_char n.v.[1];\n print_password n\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read all 3-letter substrings (edges of the graph) *)\n let edges = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun e -> e)) in\n (* adjacency list\n * - maps node to a list of\n * indices into the edges array\n *)\n let nodes = Hashtbl.create n in\n Array.iteri (fun i e ->\n (* start and end nodes of the edge *)\n let hd = String.sub e 0 2\n and tl = String.sub e 1 2 in\n let hd_node =\n if Hashtbl.mem nodes hd\n then Hashtbl.find nodes hd\n else (empty_node hd)\n in\n let hd_node = { hd_node with\n e = (i :: hd_node.e);\n o = (hd_node.o + 1);\n } in\n Hashtbl.replace nodes hd hd_node;\n let tl_node =\n if Hashtbl.mem nodes tl\n then Hashtbl.find nodes tl\n else (empty_node tl)\n in\n Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }\n ) edges;\n (* find nodes with odd degree *)\n let (i, o) = Hashtbl.fold (fun n v (i, o) ->\n match v.o - v.i with\n | 1 -> i, n :: o\n | -1 -> n :: i, o\n | _ -> i, o\n ) nodes ([], [])\n in\n let start = match o with\n | [n] -> Some n\n | [] -> Some (String.sub edges.(0) 0 2)\n | _ -> None\n in\n match start with\n | None -> print_endline \"NO\"\n | Some n ->\n try\n let p = get_password edges nodes n in\n let disjoint = Hashtbl.fold (fun _ v b ->\n b || List.length v.e > 0\n ) nodes false\n in\n if disjoint\n then print_endline \"NO\"\n else begin\n print_endline \"YES\";\n print_string (String.sub n 0 2);\n print_password p;\n print_char '\\n'\n end\n with\n | No_trail -> print_endline \"NO\"\n)\n", "positive_code": [{"source_code": "(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nlet update h k f =\n Hashtbl.replace h k\n @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None\n\n(* --- *)\nexception InputError of string\n\nlet read_into_pair () =\n let e = read_line () |> String.trim in\n match explode e with\n | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)\n | _ -> raise @@ InputError \"unexpected input\"\n\n(* --- *)\nlet seqs_count = read_line () |> int_of_string\n\nlet degs = Hashtbl.create (62 * 62)\n\nlet adj = Hashtbl.create (62 * 62)\n\n;;\nfor i = 1 to seqs_count do\n let f', t', char_of_path = read_into_pair () in\n update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;\n update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;\n Hashtbl.add adj f' (t', char_of_path)\ndone\n\nlet find_eu start_v =\n let cir = ref [] in\n let rec h vertex =\n while Hashtbl.mem adj vertex do\n let next_vertex, char_of_path = Hashtbl.find adj vertex in\n Hashtbl.remove adj vertex ; h next_vertex\n done ;\n cir := vertex :: !cir\n in\n h start_v ;\n (* ensure it's connected *)\n if List.length !cir = seqs_count + 1 then (\n Printf.printf \"YES\\n\" ;\n Printf.printf \"%s\" start_v ;\n List.iter (fun s -> Printf.printf \"%c\" s.[1]) @@ List.tl !cir ;\n Printf.printf \"\\n\" )\n else Printf.printf \"NO\\n\"\n\nlet more_outgoings, more_ingoings, last_balanced =\n Hashtbl.fold\n (fun k d (more_outgoings, more_ingoings, last_balanced) ->\n if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)\n else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)\n else (more_outgoings, more_ingoings, Some k) )\n degs ([], [], None)\n\n;;\nmatch (more_outgoings, more_ingoings, last_balanced) with\n| [x], [y], _ when Hashtbl.find degs x = 1 && Hashtbl.find degs y = -1 ->\n find_eu x\n| [], [], Some x -> find_eu x\n| _ -> Printf.printf \"NO\\n\"\n"}], "negative_code": [{"source_code": "(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nlet update h k f =\n Hashtbl.replace h k\n @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None\n\n(* --- *)\nexception InputError of string\n\nlet read_into_pair () =\n let e = read_line () |> String.trim in\n match explode e with\n | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)\n | _ -> raise @@ InputError \"unexpected input\"\n\n(* --- *)\nlet seqs_count = read_line () |> int_of_string\n\nlet degs = Hashtbl.create (62 * 62)\n\nlet adj = Hashtbl.create (62 * 62)\n\n;;\nfor i = 1 to seqs_count do\n let f', t', char_of_path = read_into_pair () in\n update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;\n update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;\n Hashtbl.add adj f' (t', char_of_path)\ndone\n\nlet find_eu start_v =\n let cir = ref [] in\n let rec h vertex =\n while Hashtbl.mem adj vertex do\n let next_vertex, char_of_path = Hashtbl.find adj vertex in\n Hashtbl.remove adj vertex ; h next_vertex\n done ;\n cir := vertex :: !cir\n in\n h start_v ;\n if List.length !cir = seqs_count + 1 then (\n Printf.printf \"YES\\n\" ;\n Printf.printf \"%s\" start_v ;\n List.iter (fun s -> Printf.printf \"%c\" s.[1]) @@ List.tl !cir ;\n Printf.printf \"\\n\" )\n else Printf.printf \"NO\\n\"\n\nlet more_outgoings, more_ingoings, last_balanced =\n Hashtbl.fold\n (fun k d (more_outgoings, more_ingoings, last_balanced) ->\n if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)\n else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)\n else (more_outgoings, more_ingoings, Some k) )\n degs ([], [], None)\n\n;;\nmatch (more_outgoings, more_ingoings, last_balanced) with\n| [x], [_], _ -> find_eu x\n| [], [], Some x -> find_eu x\n| _ -> Printf.printf \"NO\\n\"\n"}, {"source_code": "(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nlet update h k f =\n Hashtbl.replace h k\n @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None\n\n(* --- *)\nexception InputError of string\n\nlet read_into_pair () =\n let e = read_line () |> String.trim in\n match explode e with\n | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)\n | _ -> raise @@ InputError \"unexpected input\"\n\n(* --- *)\nlet seqs_count = read_line () |> int_of_string\n\nlet degs = Hashtbl.create (62 * 62)\n\nlet adj = Hashtbl.create (62 * 62)\n\n;;\nfor i = 1 to seqs_count do\n let f', t', char_of_path = read_into_pair () in\n update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;\n update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;\n Hashtbl.add adj f' (t', char_of_path)\ndone\n\nlet find_eu start_v =\n Printf.printf \"YES\\n\" ;\n Printf.printf \"%s\" start_v ;\n let rec h vertex =\n while Hashtbl.mem adj vertex do\n let next_vertex, char_of_path = Hashtbl.find adj vertex in\n Hashtbl.remove adj vertex ;\n Printf.printf \"%c\" char_of_path ;\n h next_vertex\n done\n in\n h start_v ; Printf.printf \"\\n\"\n\nlet more_outgoings, more_ingoings, last_balanced =\n Hashtbl.fold\n (fun k d (more_outgoings, more_ingoings, last_balanced) ->\n if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)\n else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)\n else (more_outgoings, more_ingoings, Some k) )\n degs ([], [], None)\n\n;;\nmatch (more_outgoings, more_ingoings, last_balanced) with\n| [x], [_], _ -> find_eu x\n| [], [], Some x -> find_eu x\n| _ -> Printf.printf \"NO\\n\"\n"}, {"source_code": "(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nlet update h k f =\n Hashtbl.replace h k\n @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None\n\n(* --- *)\nexception InputError of string\n\nlet read_into_pair () =\n let e = read_line () |> String.trim in\n match explode e with\n | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)\n | _ -> raise @@ InputError \"unexpected input\"\n\n(* --- *)\nlet seqs_count = read_line () |> int_of_string\n\nlet degs = Hashtbl.create (62 * 62)\n\nlet adj = Hashtbl.create (62 * 62)\n\n;;\nfor i = 1 to seqs_count do\n let f', t', char_of_path = read_into_pair () in\n update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;\n update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;\n Hashtbl.add adj f' (t', char_of_path)\ndone\n\nlet find_eu start_v =\n Printf.printf \"YES\\n\" ;\n Printf.printf \"%s\" start_v;\n let cir = ref [] in\n let rec h vertex =\n while Hashtbl.mem adj vertex do\n let next_vertex, char_of_path = Hashtbl.find adj vertex in\n Hashtbl.remove adj vertex ; h next_vertex\n done ;\n cir := vertex :: !cir\n in\n h start_v ;\n List.iter (fun s -> Printf.printf \"%c\" s.[1]) @@ List.tl !cir ;\n Printf.printf \"\\n\"\n\nlet more_outgoings, more_ingoings, last_balanced =\n Hashtbl.fold\n (fun k d (more_outgoings, more_ingoings, last_balanced) ->\n if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)\n else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)\n else (more_outgoings, more_ingoings, Some k) )\n degs ([], [], None)\n\n;;\nmatch (more_outgoings, more_ingoings, last_balanced) with\n| [x], [_], _ -> find_eu x\n| [], [], Some x -> find_eu x\n| _ -> Printf.printf \"NO\\n\"\n"}, {"source_code": "(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nlet update h k f =\n Hashtbl.replace h k\n @@ if Hashtbl.mem h k then f @@ Some (Hashtbl.find h k) else f None\n\n(* --- *)\nexception InputError of string\n\nlet read_into_pair () =\n let e = read_line () |> String.trim in\n match explode e with\n | [a; b; c] -> (concat_chars [a; b], concat_chars [b; c], c)\n | _ -> raise @@ InputError \"unexpected input\"\n\n(* --- *)\nlet seqs_count = read_line () |> int_of_string\n\nlet degs = Hashtbl.create (62 * 62)\n\nlet adj = Hashtbl.create (62 * 62)\n\n;;\nfor i = 1 to seqs_count do\n let f', t', char_of_path = read_into_pair () in\n update degs f' (fun r -> match r with None -> 1 | Some d -> d + 1) ;\n update degs t' (fun r -> match r with None -> -1 | Some d -> d - 1) ;\n Hashtbl.add adj f' (t', char_of_path)\ndone\n\nlet find_eu start_v =\n Printf.printf \"YES\\n\" ;\n Printf.printf \"%s\" start_v ;\n let acc = ref [] in\n let rec h vertex =\n while Hashtbl.mem adj vertex do\n let next_vertex, char_of_path = Hashtbl.find adj vertex in\n Hashtbl.remove adj vertex ;\n acc := char_of_path :: !acc ;\n h next_vertex\n done\n in\n h start_v ;\n List.iter (fun c -> Printf.printf \"%c\" c) !acc ;\n Printf.printf \"\\n\"\n\nlet more_outgoings, more_ingoings, last_balanced =\n Hashtbl.fold\n (fun k d (more_outgoings, more_ingoings, last_balanced) ->\n if d < 0 then (more_outgoings, k :: more_ingoings, last_balanced)\n else if d > 0 then (k :: more_outgoings, more_ingoings, last_balanced)\n else (more_outgoings, more_ingoings, Some k) )\n degs ([], [], None)\n\n;;\nmatch (more_outgoings, more_ingoings, last_balanced) with\n| [x], [_], _ -> find_eu x\n| [], [], Some x -> find_eu x\n| _ -> Printf.printf \"NO\\n\"\n"}, {"source_code": "(** a node is a string value and list\n * of outgoing edges *)\ntype node = {\n v : string;\n e : int list;\n i : int;\n o : int;\n}\nlet empty_node v = { v; e = []; i = 0; o = 0 }\n\n(** doubly-linked list element *)\ntype 'a el = {\n v : 'a;\n mutable next : 'a el option;\n mutable prev : 'a el option;\n}\n\nlet get_password edges nodes n =\n (* dlist of tour *)\n let dl = { v = n; next = None; prev = None } in\n (* end of list *)\n let tl = ref dl in\n\n (* get the initial trail *)\n let rec trail n tl =\n let node = Hashtbl.find nodes n in\n match node.e with\n | e :: es ->\n let e = String.sub edges.(e) 1 2 in\n let el = { v = e; next = None; prev = Some !tl } in\n !tl.next <- Some el;\n tl := el;\n Hashtbl.replace nodes n { node with e = es };\n trail e tl\n | [] -> ()\n in\n trail n tl;\n\n (* print the final password *)\n let rec print n =\n print_char n.v.[1];\n\n (* follow any further edges from this node\n * if necessary *)\n let next = n.next in\n let tl = ref n in\n trail n.v tl;\n !tl.next <- next;\n\n match n.next with\n | None -> ()\n | Some n -> print n\n in\n print dl;\n print_char '\\n'\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read all 3-letter substrings (edges of the graph) *)\n let edges = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun e -> e)) in\n (* adjacency list\n * - maps node to a list of\n * indices into the edges array\n *)\n let nodes = Hashtbl.create n in\n Array.iteri (fun i e ->\n (* start and end nodes of the edge *)\n let hd = String.sub e 0 2\n and tl = String.sub e 1 2 in\n let hd_node =\n if Hashtbl.mem nodes hd\n then Hashtbl.find nodes hd\n else (empty_node hd)\n in\n let hd_node = { hd_node with\n e = (i :: hd_node.e);\n o = (hd_node.o + 1);\n } in\n Hashtbl.replace nodes hd hd_node;\n let tl_node =\n if Hashtbl.mem nodes tl\n then Hashtbl.find nodes tl\n else (empty_node tl)\n in\n Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }\n ) edges;\n (* find nodes with odd degree *)\n let (i, o) = Hashtbl.fold (fun n v (i, o) ->\n match v.o - v.i with\n | 1 -> i, n :: o\n | -1 -> n :: i, o\n | _ -> i, o\n ) nodes ([], [])\n in\n let start = match o with\n | [n] -> Some n\n | [] -> Some (String.sub edges.(0) 0 2)\n | _ -> None\n in\n match start with\n | None -> print_endline \"NO\"\n | Some n ->\n print_endline \"YES\";\n print_char n.[0];\n get_password edges nodes n\n)\n"}, {"source_code": "let get_password edges nodes s =\n print_string s;\n let rec printer s =\n match Hashtbl.find nodes s with\n | hd :: tl ->\n let e = edges.(hd) in\n print_char e.[2];\n Hashtbl.replace nodes s tl;\n printer (String.sub e 1 2)\n | [] -> () (* done *)\n in\n printer s;\n print_endline \"\"\n\nlet () =\n Scanf.scanf \"%d\\n\" (fun n ->\n (* array of edges *)\n let edges = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun l -> l)) in\n (* adjacency list *)\n let nodes = Hashtbl.create n in\n (* degree of each node *)\n let degree = Hashtbl.create n in\n (* add edges to adjacency list and\n * calculate the degree of nodes *)\n Array.iteri (fun i s ->\n (* start of edge *)\n let hd = String.sub s 0 2\n (* end of edge *)\n and tl = String.sub s 1 2 in\n (* add edge to adjacency list *)\n let edges =\n if Hashtbl.mem nodes hd\n then Hashtbl.find nodes hd\n else []\n in\n Hashtbl.replace nodes hd (i :: edges);\n if not (Hashtbl.mem nodes tl)\n then Hashtbl.add nodes tl [];\n (* increase out degree of start node *)\n let (i, o) =\n if Hashtbl.mem degree hd\n then Hashtbl.find degree hd\n else (0, 0)\n in\n Hashtbl.replace degree hd (i, o + 1);\n (* increase in degree of end node *)\n let (i, o) =\n if Hashtbl.mem degree tl\n then Hashtbl.find degree tl\n else (0, 0)\n in\n Hashtbl.replace degree tl (i + 1, o)\n ) edges;\n (* a directed graph has an Eulerian trail iff at\n * most one node each has o-i = 1 and i-o = 1.\n * fold over the hashtbl to find these nodes *)\n let (inl, outl) =\n Hashtbl.fold (fun s (i, o) (inl, outl) ->\n match o - i with\n | 1 -> (inl, s :: outl)\n | -1 -> (s :: inl, outl)\n | _ -> (inl, outl)\n ) degree ([], [])\n in\n let start = match outl with\n | [s] -> Some s\n | [] -> Some (String.sub edges.(0) 0 2)\n | _ -> None\n in\n match start with\n | Some s -> print_endline \"YES\"; get_password edges nodes s\n | None -> print_endline \"NO\"\n )\n"}, {"source_code": "(** a node is a string value and list\n * of outgoing edges *)\ntype node = {\n v : string;\n e : int list;\n i : int;\n o : int;\n}\nlet empty_node v = { v; e = []; i = 0; o = 0 }\n\n(** doubly-linked list element *)\ntype 'a el = {\n v : 'a;\n mutable next : 'a el option;\n mutable prev : 'a el option;\n}\n\nlet get_password edges nodes n =\n (* dlist of tour *)\n let dl = { v = n; next = None; prev = None } in\n (* end of list *)\n let tl = ref dl in\n\n (* get the initial trail *)\n let rec trail n tl =\n let node = Hashtbl.find nodes n in\n match node.e with\n | e :: es ->\n let e = String.sub edges.(e) 1 2 in\n let el = { v = e; next = None; prev = Some !tl } in\n !tl.next <- Some el;\n tl := el;\n Hashtbl.replace nodes n { node with e = es };\n trail e tl\n | [] -> ()\n in\n trail n tl;\n\n (* build the final password *)\n let rec build n =\n (* follow any further edges from this node\n * if necessary *)\n let next = n.next in\n let tl = ref n in\n trail n.v tl;\n !tl.next <- next;\n\n match n.next with\n | None -> ()\n | Some n -> build n\n in\n build dl;\n dl\n\nlet rec print_password p =\n match p.next with\n | None -> ()\n | Some n ->\n print_char n.v.[1];\n print_password n\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n (* read all 3-letter substrings (edges of the graph) *)\n let edges = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun e -> e)) in\n (* adjacency list\n * - maps node to a list of\n * indices into the edges array\n *)\n let nodes = Hashtbl.create n in\n Array.iteri (fun i e ->\n (* start and end nodes of the edge *)\n let hd = String.sub e 0 2\n and tl = String.sub e 1 2 in\n let hd_node =\n if Hashtbl.mem nodes hd\n then Hashtbl.find nodes hd\n else (empty_node hd)\n in\n let hd_node = { hd_node with\n e = (i :: hd_node.e);\n o = (hd_node.o + 1);\n } in\n Hashtbl.replace nodes hd hd_node;\n let tl_node =\n if Hashtbl.mem nodes tl\n then Hashtbl.find nodes tl\n else (empty_node tl)\n in\n Hashtbl.replace nodes tl { tl_node with i = (tl_node.i + 1) }\n ) edges;\n (* find nodes with odd degree *)\n let (i, o) = Hashtbl.fold (fun n v (i, o) ->\n match v.o - v.i with\n | 1 -> i, n :: o\n | -1 -> n :: i, o\n | _ -> i, o\n ) nodes ([], [])\n in\n let start = match o with\n | [n] -> Some n\n | [] -> Some (String.sub edges.(0) 0 2)\n | _ -> None\n in\n match start with\n | None -> print_endline \"NO\"\n | Some n ->\n let p = get_password edges nodes n in\n let disjoint = Hashtbl.fold (fun _ v b ->\n b || List.length v.e > 0\n ) nodes false\n in\n if disjoint\n then print_endline \"NO\"\n else begin\n print_endline \"YES\";\n print_string (String.sub n 0 2);\n print_password p;\n print_char '\\n'\n end\n)\n"}], "src_uid": "02845c8982a7cb6d29905d117c4a1079"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet fmax = 500_001\n\nlet factors n =\n let rec aux i p =\n(* Printf.printf \"%d, %d\\n\" i p; *)\n if p = 1 then []\n else if i*i > p then [p]\n else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)\n else aux (i+1) p\n in\n aux 2 n\n\n(* Mike and Foam *)\n\nlet _ =\n let n = read_int () in\n let q = read_int () in\n let beers = Array.init n (fun _ -> read_int ()) in\n let queries = Array.init q (fun _ -> read_int ()) in\n let slots = Array.make fmax 0 in\n let pres = Array.make n false in\n let register sc n =\n let rec it prod = function\n | [] -> ()\n | l::ls -> count (prod*l) ls; it prod ls\n and count prod l =\n slots.(prod) <- slots.(prod)+sc;\n it prod l\n in\n count 1 (factors n)\n in\n let count n =\n let rec count prod l =\n slots.(prod) - it prod l\n and it prod = function\n | [] -> 0\n | l::ls -> count (prod * l) ls + it prod ls\n in\n count 1 (factors n)\n in\n let cur = ref (Int64.zero) in\n for i = 0 to q - 1 do\n (* How many things does it intersect with ? *)\n (* Oops, check presence + the '1' problem *)\n let beer = queries.(i) - 1 in\n let foam = beers.(beer) in\n let score =\n if pres.(beer) then (register (-1) foam; - count foam)\n else (let r = count foam in register 1 foam; r)\n in\n pres.(beer) <- not pres.(beer);\n cur := Int64.add !cur (Int64.of_int score);\n Printf.printf \"%Ld\\n\" !cur\n done\n\n", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n2 = 500000 in\n let prime = Array.make (n2 + 1) true in\n let p = Array.make (n2 + 1) 0 in\n let pd = Array.make (n2 + 1) [] in\n let pk = ref 0 in\n let () =\n for i = 2 to n2 do\n if prime.(i) then (\n\tp.(!pk) <- i;\n\tincr pk;\n\tpd.(i) <- [i];\n\tlet j = ref (2 * i) in\n while !j <= n2 do\n\t let jj = !j in\n prime.(jj) <- false;\n\t pd.(jj) <- i :: pd.(jj);\n j := jj + i\n done\n )\n done;\n in\n let pk = !pk - 1 in\n let pd = Array.map Array.of_list pd in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let q = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n let b = Array.make (n2 + 1) false in\n let d = Array.make (n2 + 1) 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 res = ref 0L in\n for i = 1 to q do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (s, ofs) =\n\tif b.(x) then (\n\t b.(x) <- false;\n\t (-1, 1)\n\t) else (\n\t b.(x) <- true;\n\t (1, 0)\n\t)\n in\n let x = a.(x - 1) in\n let ds = pd.(x) in\n let k = Array.length ds in\n\tfor i = 0 to 1 lsl k - 1 do\n\t let y = ref 1 in\n\t let c = ref 0 in\n\t for j = 0 to k - 1 do\n\t if i land (1 lsl j) <> 0 then (\n\t\ty := !y * ds.(j);\n\t\tincr c\n\t )\n\t done;\n\t if !c land 1 = 0\n\t then res := Int64.add !res (Int64.of_int (s * (d.(!y) - ofs)))\n\t else res := Int64.sub !res (Int64.of_int (s * (d.(!y) - ofs)));\n\t d.(!y) <- d.(!y) + s;\n\tdone;\n\tPrintf.printf \"%Ld\\n\" !res;\n done;\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet fmax = 500_001\n\nlet factors n =\n let rec aux i p =\n(* Printf.printf \"%d, %d\\n\" i p; *) \n if p = 1 then []\n else if i*i > p then [p]\n else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)\n else aux (i+1) p\n in\n aux 2 n\n\n(* Mike and Foam *)\n\nlet _ =\n let n = read_int () in\n let q = read_int () in\n let beers = Array.init n (fun _ -> read_int ()) in\n let queries = Array.init q (fun _ -> read_int ()) in\n let slots = Array.make fmax 0 in\n let pres = Array.make n false in\n let register sc n =\n let rec it prod = function\n | [] -> ()\n | l::ls -> count (prod*l) ls; it prod ls\n and count prod l =\n slots.(prod) <- slots.(prod)+sc;\n it prod l\n in\n count 1 (factors n)\n in\n let count n =\n let rec count prod l =\n slots.(prod) - it prod l\n and it prod = function\n | [] -> 0\n | l::ls -> count (prod * l) ls + it prod ls\n in\n count 1 (factors n)\n in\n let cur = ref (Int64.zero) in\n for i = 0 to q - 1 do\n (* How many things does it intersect with ? *)\n (* Oops, check presence + the '1' problem *)\n let beer = queries.(i) - 1 in\n let foam = beers.(beer) in\n let score =\n if pres.(beer) then (register (-1) foam; - count foam)\n else (let r = count foam in register 1 foam; r)\n in\n pres.(beer) <- not pres.(beer);\n cur := Int64.add !cur (Int64.of_int score);\n Printf.printf \"%Ld\\n\" !cur\n done"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet fmax = 500_001\n\nlet factors n =\n let rec aux i p =\n(* Printf.printf \"%d, %d\\n\" i p; *)\n if p = 1 then []\n else if i*i > p then [p]\n else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)\n else aux (i+1) p\n in\n aux 2 n\n\n(* Mike and Foam *)\n\nlet _ =\n let n = read_int () in\n let q = read_int () in\n let beers = Array.init n (fun _ -> read_int ()) in\n let queries = Array.init q (fun _ -> read_int ()) in\n let slots = Array.make fmax 0 in\n let pres = Array.make n false in\n let register sc n =\n let rec it prod = function\n | [] -> ()\n | l::ls -> count (prod*l) ls; it prod ls\n and count prod l =\n slots.(prod) <- slots.(prod)+sc;\n it prod l\n in\n count 1 (factors n)\n in\n let count n =\n let rec count prod l =\n slots.(prod) - it prod l\n and it prod = function\n | [] -> 0\n | l::ls -> count (prod * l) ls + it prod ls\n in\n count 1 (factors n)\n in\n let cur = ref (Int64.zero) in\n for i = 0 to q - 1 do\n (* How many things does it intersect with ? *)\n (* Oops, check presence + the '1' problem *)\n let beer = queries.(i) - 1 in\n let foam = beers.(beer) in\n let score =\n if pres.(beer) then (register (-1) foam; - count foam)\n else (let r = count foam in register 1 foam; r)\n in\n pres.(beer) <- not pres.(beer);\n cur := Int64.add !cur (Int64.of_int score);\n Printf.printf \"%Ld\\n\" !cur\n done"}], "negative_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet fmax = 500_001\n\nlet factors n =\n let rec aux i p =\n(* Printf.printf \"%d, %d\\n\" i p; *)\n if p = 1 then []\n else if i*i > p then [p]\n else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)\n else aux (i+1) p\n in\n aux 2 n\n\n(* Mike and Foam *)\n\nlet _ =\n let n = read_int () in\n let q = read_int () in\n let beers = Array.init n (fun _ -> read_int ()) in\n let queries = Array.init q (fun _ -> read_int ()) in\n let slots = Array.make fmax 0 in\n let pres = Array.make n false in\n let register sc n =\n let rec it prod = function\n | [] -> ()\n | l::ls -> count (prod*l) ls; it prod ls\n and count prod l =\n slots.(prod) <- slots.(prod)+sc;\n it prod l\n in\n count 1 (factors n)\n in\n let count n =\n let rec count prod l =\n slots.(prod) - it prod l\n and it prod = function\n | [] -> 0\n | l::ls -> count (prod * l) ls + it prod ls\n in\n count 1 (factors n)\n in\n let cur = ref 0 in\n for i = 0 to q - 1 do\n (* How many things does it intersect with ? *)\n (* Oops, check presence + the '1' problem *)\n let beer = queries.(i) - 1 in\n let foam = beers.(beer) in\n let score =\n if pres.(beer) then (register (-1) foam; - count foam)\n else (let r = count foam in register 1 foam; r)\n in\n pres.(beer) <- not pres.(beer);\n cur := !cur + score;\n Printf.printf \"%d\\n\" !cur\n done\n\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet fmax = 500_001\n\nlet factors n =\n let rec aux i p =\n(* Printf.printf \"%d, %d\\n\" i p; *)\n if p = 1 then []\n else if i*i > p then [p]\n else if p mod i = 0 then i::(match aux i (p/i) with i'::is when i=i' -> is | is -> is)\n else aux (i+1) p\n in\n aux 2 n\n\n(* Mike and Foam *)\n\nlet _ =\n let n = read_int () in\n let q = read_int () in\n let beers = Array.init n (fun _ -> read_int ()) in\n let queries = Array.init q (fun _ -> read_int ()) in\n let slots = Array.make fmax 0 in\n let pres = Array.make n false in\n let register sc n =\n let rec it par prod = function\n | [] -> 0\n | l::ls -> count par (prod*l) ls + it par prod ls\n and count par prod l =\n let t = slots.(prod) in\n slots.(prod) <- t+sc;\n par*(if sc > 0 then t else t + sc) + it (-par) prod l\n in\n sc * count 1 1 (factors n)\n in\n let cur = ref 0 in\n for i = 0 to q - 1 do\n (* How many things does it intersect with ? *)\n (* Oops, check presence + the '1' problem *)\n let beer = queries.(i) - 1 in\n let score = register (if pres.(beer) then -1 else 1) beers.(beer) in\n pres.(beer) <- true;\n cur := !cur + score;\n Printf.printf \"%d\\n\" !cur\n done\n\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n2 = 500000 in\n let prime = Array.make (n2 + 1) true in\n let p = Array.make (n2 + 1) 0 in\n let pd = Array.make (n2 + 1) [] in\n let pk = ref 0 in\n let () =\n for i = 2 to n2 do\n if prime.(i) then (\n\tp.(!pk) <- i;\n\tincr pk;\n\tpd.(i) <- [i];\n\tlet j = ref (2 * i) in\n while !j <= n2 do\n\t let jj = !j in\n prime.(jj) <- false;\n\t pd.(jj) <- i :: pd.(jj);\n j := jj + i\n done\n )\n done;\n in\n let pk = !pk - 1 in\n let pd = Array.map Array.of_list pd in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let q = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n let b = Array.make (n2 + 1) false in\n let d = Array.make (n2 + 1) 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 res = ref 0L in\n for i = 1 to q do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let x = a.(x - 1) in\n let (s, ofs) =\n\tif b.(x) then (\n\t b.(x) <- false;\n\t (-1, 1)\n\t) else (\n\t b.(x) <- true;\n\t (1, 0)\n\t)\n in\n let ds = pd.(x) in\n let k = Array.length ds in\n\tfor i = 0 to 1 lsl k - 1 do\n\t let y = ref 1 in\n\t let c = ref 0 in\n\t for j = 0 to k - 1 do\n\t if i land (1 lsl j) <> 0 then (\n\t\ty := !y * ds.(j);\n\t\tincr c\n\t )\n\t done;\n\t if !c land 1 = 0\n\t then res := Int64.add !res (Int64.of_int (s * (d.(!y) - ofs)))\n\t else res := Int64.sub !res (Int64.of_int (s * (d.(!y) - ofs)));\n\t d.(!y) <- d.(!y) + s;\n\tdone;\n\tPrintf.printf \"%Ld\\n\" !res;\n done;\n"}], "src_uid": "adc9fe6121f6ed1ba805a3b8c97824b4"} {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d \" x;;\n\nlet () =\n let n = read_int() in\n let a = Array.init n read_int in\n let res = Array.make n 0 in\n for i = 0 to (n-1) do\n let seen = Array.make n 0 in\n let index = ref (a.(i)-1) in\n seen.(!index) <- 1;\n res.(!index) <- res.(!index) + 1;\n for j = i+1 to (n-1) do\n let k = a.(j)-1 in\n seen.(k) <- seen.(k) + 1;\n if seen.(k) > seen.(!index) || \n (seen.(k) == seen.(!index) && k < !index) then\n (index := k);\n res.(!index) <- res.(!index) + 1\n done\n done;\n Array.iter print_int res;;\n", "positive_code": [{"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 t = Array.init n (fun _ -> -1 + read_int()) in\n let wins = Array.make n 0 in\n\n for i=0 to n-1 do\n let counts = Array.make n 0 in\n let rec loop j maxcount maxcolor = if j < n then (\n let c = t.(j) in\n let nv = counts.(c) + 1 in\n counts.(c) <- nv;\n if nv > maxcount then (\n\twins.(c) <- wins.(c) + 1;\n\tloop (j+1) nv c\n ) else if nv = maxcount then (\n\tif c < maxcolor then (\n\t wins.(c) <- wins.(c) + 1;\n\t loop (j+1) nv c\n\t) else (\n\t wins.(maxcolor) <- wins.(maxcolor) + 1;\n\t loop (j+1) nv maxcolor\t \n\t)\n ) else (\n\twins.(maxcolor) <- wins.(maxcolor) + 1;\t\n\tloop (j+1) maxcount maxcolor\n )\n )\n in\n loop i 0 0\n done;\n\n for i=0 to n-1 do\n printf \"%d \" wins.(i)\n done;\n\n print_newline()\n"}], "negative_code": [{"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 t = Array.init n (fun _ -> -1 + read_int()) in\n let wins = Array.make n 0 in\n\n for i=0 to n-1 do\n let counts = Array.make n 0 in\n let rec loop j maxcount maxcolor = if j = n then () else (\n let c = t.(j) in\n let nv = counts.(c) + 1 in\n counts.(c) <- nv;\n if nv > maxcount then (\n\twins.(c) <- wins.(c) + 1;\n\tloop (j+1) nv c\n ) else if nv = maxcount then (\n\tif c < maxcolor then (\n\t wins.(c) <- wins.(c) + 1;\n\t loop (j+1) nv c\n\t) else (\n\t wins.(maxcolor) <- wins.(maxcolor) + 1;\n\t loop (j+1) nv maxcolor\t \n\t)\n ) else loop (j+1) maxcount maxcolor\n )\n in\n loop i 0 0\n done;\n\n for i=0 to n-1 do\n printf \"%d \" wins.(i)\n done;\n\n print_newline()\n"}], "src_uid": "f292c099e4eac9259a5bc9e42ff6d1b5"} {"source_code": "exception Winner of string\n\nlet maximal_score l = \n let t = Hashtbl.create 13 in\n List.iter (fun (p,s) ->\n try \n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s)\n with\n |Not_found -> Hashtbl.add t p s\n ) l;\n let maxs = Hashtbl.fold (fun _ s v -> max v s) t 0 in\n let pls = Hashtbl.fold (fun p s l -> if s = maxs then p :: l else l) t [] in\n (maxs, pls)\n\nlet winner l =\n let (maxs, pls) = maximal_score l in\n let t = Hashtbl.create 13 in \n List.iter (fun (p,s) ->\n try\n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s);\n if s' + s >= maxs && List.mem p pls then (raise (Winner p))\n with\n |Not_found -> \n Hashtbl.add t p s;\n if s >= maxs && List.mem p pls then (raise (Winner p))\n ) l\n\nlet rec input_list n = \n if n = 0 then []\n else begin try \n let (p,s) = Scanf.fscanf stdin \"%s %i\\n\" (fun a b -> (a,b)) in\n (p,s) :: (input_list (n-1))\n with\n |Not_found -> []\n end\n\nlet () = \n let n = int_of_string (read_line ()) in\n try\n winner (input_list n)\n with\n |Winner(s) -> Printf.printf \"%s\\n\" s\n\n", "positive_code": [{"source_code": "open Hashtbl;;\nopen Scanf;;\nopen List;;\n\nlet players = Hashtbl.create 0;;\nlet scores = ref [];;\n\n\nlet ib = Scanf.Scanning.stdib;;\nlet add_player name x =\n\tif not (Hashtbl.mem players name) then begin\n\t\tHashtbl.add players name 0\n\tend;\n\t\n\tlet player = Hashtbl.find players name in\n\tlet score = player + x in\n\tlet _ = scores := ((name, score) :: !scores) in\n\tHashtbl.replace players name score\n;;\n\nlet ln = read_int ();;\nfor i = 0 to ln-1 do\n\tScanf.bscanf ib \"%s %d\\n\" add_player\ndone;;\n\nlet m = Hashtbl.fold (fun _ p m -> max p m) players 0;;\n\n\nfor i = ln-1 downto 0 do\n\tlet name, score = List.nth (!scores) i in\n\tif (score >= m) && ((Hashtbl.find players name) = m) then begin\n\t\tprint_string name;\n\t\texit 0\n\tend\ndone;\n"}, {"source_code": "let (|>) x f = f x\n\nmodule Player = struct\n type t = String.t\n let equal = (=)\n let hash = Hashtbl.hash\nend\n\ntype game = {\n nr : int;\n player : Player.t;\n score : int;\n}\n\nlet make_game nr player score = { nr; player; score }\n\nmodule Scoretbl = Hashtbl.Make (Player)\n\nlet parse_games () : game array =\n let parse n =\n Array.init n\n (fun i -> Scanf.scanf \"%s %d\\n\"\n (fun p s -> make_game i p s)) in\n Scanf.scanf \"%d\\n\" parse\n\nlet score_players games : game list Scoretbl.t =\n let scores = Scoretbl.create 10 in\n let add_score g =\n match Scoretbl.mem scores g.player with\n | true -> Scoretbl.replace scores g.player (g :: (Scoretbl.find scores g.player))\n | false -> Scoretbl.add scores g.player [g] in\n Array.iter add_score games;\n scores\n\nlet total_score games : int =\n List.fold_left (fun a g -> a + g.score) 0 games\n\nlet leaders scores =\n let highscore = ref min_int\n and leaders = ref [] in\n let check p games =\n let s = total_score games in\n if s = !highscore\n then leaders := p :: !leaders\n else if s > !highscore\n then begin\n highscore := s;\n leaders := [p]\n end in\n Scoretbl.iter check scores;\n !highscore, !leaders\n \nlet threshold high games =\n let rec count i s = function\n | [] -> i\n | h::t -> if s >= high then i else count h.nr (s + h.score) t\n in count 0 0 (List.rev games)\n\nlet winner scores (high, players) =\n let (p,_) =\n List.fold_left (fun ((w,r) as m) pl ->\n let round = threshold high (Scoretbl.find scores pl) in\n if round < r then (pl,round) else m)\n (\"\",max_int)\n players in\n p\n\n\n\nlet _ =\n let scores = parse_games () |> score_players in\n Printf.printf \"%s\\n\" (winner scores (leaders scores))\n"}, {"source_code": "let (|>) x f = f x\n\nlet read_rounds n a =\n let rec go n acc =\n if n = 0 then\n List.rev acc\n else (\n let line = read_line () in\n let name, v = Scanf.sscanf line \"%s %d\" (fun x y -> x,y) in\n let vv = (try Hashtbl.find a name with _ -> 0) + v in\n Hashtbl.replace a name vv;\n go (n-1) ((name,vv)::acc)\n )\n in go n []\n\nlet rec f maxv a = function\n | [] -> None\n | (name,v)::tl -> if v >= maxv && Hashtbl.find a name = maxv then\n Some name\n else\n f maxv a tl\n\nlet () =\n let n = read_int () in\n let a = Hashtbl.create n in\n let rounds = read_rounds n a in\n let maxv = Hashtbl.fold (fun name v maxv -> max maxv v) a 0 in\n match f maxv a rounds with\n | Some name -> print_endline name\n"}, {"source_code": "let rec read_rounds n score_tbl =\n if n > 0 then \n\tlet line = read_line () in\n\tlet (name, score) = Scanf.sscanf line \"%s %d\" (fun x y -> (x, y)) in\n\t(* Printf.printf \"line: %s\\n\" line; *)\n\tlet so_far = (try Hashtbl.find score_tbl name with _ -> 0) + score in\n\tHashtbl.replace score_tbl name so_far;\n\t(* Printf.printf \"%s %d\\n\" name score; *)\n\t(name, so_far) :: read_rounds (n - 1) score_tbl\n else\n\t[]\n\nlet rec winner rounds max_final_score score_tbl =\n match rounds with\n | [] -> None\n | (name, score) :: tl -> if (score >= max_final_score) && ((Hashtbl.find score_tbl name) = max_final_score) then \n\t\t\t\t\t\t\t Some name \n\t\t\t\t\t\t else \n\t\t\t\t\t\t\t winner tl max_final_score score_tbl\n\nlet () =\n let n = read_int () in\n let score_tbl = Hashtbl.create n in\n let rounds = read_rounds n score_tbl in\n let max_final_score = ref 0 in \n Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;\n match winner rounds !max_final_score score_tbl with\n | Some name -> Printf.printf \"%s\\n\" name\n"}], "negative_code": [{"source_code": "let rec read_rounds n score_tbl =\n if n > 0 then \n\tlet line = read_line () in\n\tlet (name, score) = Scanf.sscanf line \"%s %d\" (fun x y -> (x, y)) in\n\t(* Printf.printf \"line: %s\\n\" line; *)\n\tHashtbl.replace score_tbl name ((try Hashtbl.find score_tbl name with _ -> 0) + score);\n\t(* Printf.printf \"%s %d\\n\" name score; *)\n\t(name, score) :: read_rounds (n - 1) score_tbl\n else\n\t[]\n\nlet rec winner rounds max_final_score score_tbl =\n match rounds with\n | [] -> None\n | (name, score) :: tl -> let x = (try Hashtbl.find score_tbl name with _ -> 0) + score in\n\t\t\t\t\t\t if x >= max_final_score then \n\t\t\t\t\t\t\t Some name \n\t\t\t\t\t\t else (\n\t\t\t\t\t\t\t Hashtbl.replace score_tbl name x; \n\t\t\t\t\t\t\t winner tl max_final_score score_tbl\n\t\t\t\t\t\t )\n\nlet () =\n let n = read_int () in\n let score_tbl = Hashtbl.create n in\n let rounds = read_rounds n score_tbl in\n let max_final_score = ref 0 in \n Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;\n let score_tbl2 = Hashtbl.create n in \n match winner rounds !max_final_score score_tbl2 with\n | Some name -> Printf.printf \"%s\\n\" name\n"}, {"source_code": "let rec read_rounds n score_tbl =\n if n > 0 then \n\tlet line = read_line () in\n\tlet (name, score) = Scanf.sscanf line \"%s %d\" (fun x y -> (x, y)) in\n\t(* Printf.printf \"line: %s\\n\" line; *)\n\tlet so_far = (try Hashtbl.find score_tbl name with _ -> 0) + score in\n\tHashtbl.replace score_tbl name so_far;\n\t(* Printf.printf \"%s %d\\n\" name score; *)\n\t(name, so_far) :: read_rounds (n - 1) score_tbl\n else\n\t[]\n\nlet rec winner rounds max_final_score =\n match rounds with\n | [] -> None\n | (name, score) :: tl -> if score >= max_final_score then Some name else winner tl max_final_score\n\nlet () =\n let n = read_int () in\n let score_tbl = Hashtbl.create n in\n let rounds = read_rounds n score_tbl in\n let max_final_score = ref 0 in \n Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;\n match winner rounds !max_final_score with\n | Some name -> Printf.printf \"%s\\n\" name\n"}, {"source_code": "let rec read_rounds n score_tbl =\n if n > 0 then \n\tlet line = read_line () in\n\tlet (name, score) = Scanf.sscanf line \"%s %d\" (fun x y -> (x, y)) in\n\t(* Printf.printf \"line: %s\\n\" line; *)\n\tHashtbl.replace score_tbl name ((try Hashtbl.find score_tbl name with _ -> 0) + score);\n\t(* Printf.printf \"%s %d\\n\" name score; *)\n\t(name, score) :: read_rounds (n - 1) score_tbl\n else\n\t[]\n\nlet rec winner rounds max_final_score score_tbl =\n match rounds with\n | [] -> None\n | (name, score) :: tl -> let x = (try Hashtbl.find score_tbl name with _ -> 0) + score in\n\t\t\t\t\t\t if x >= max_final_score then \n\t\t\t\t\t\t\t Some name \n\t\t\t\t\t\t else (\n\t\t\t\t\t\t\t Hashtbl.replace score_tbl name x; \n\t\t\t\t\t\t\t\t winner tl max_final_score score_tbl\n\t\t\t\t\t\t )\n\nlet () =\n let n = read_int () in\n let score_tbl = Hashtbl.create n in\n let rounds = read_rounds n score_tbl in\n let max_final_score = ref 0 in \n Hashtbl.iter (fun name score -> max_final_score := max !max_final_score score) score_tbl;\n Hashtbl.reset score_tbl;\n match winner rounds !max_final_score score_tbl with\n | Some name -> Printf.printf \"%s\\n\" name\n"}, {"source_code": "open Hashtbl;;\nopen Scanf;;\nopen List;;\n\nlet players = Hashtbl.create 0;;\nlet scores = ref [];;\n\n\nlet ib = Scanf.Scanning.stdib;;\nlet add_player name x =\n\tif not (Hashtbl.mem players name) then begin\n\t\tHashtbl.add players name 0\n\tend;\n\t\n\tlet player = Hashtbl.find players name in\n\tlet score = player + x in\n\tlet _ = scores := ((name, score) :: !scores) in\n\tHashtbl.replace players name score\n;;\n\nlet ln = read_int ();;\nfor i = 0 to ln-1 do\n\tScanf.bscanf ib \"%s %d\\n\" add_player\ndone;;\n\nlet m = Hashtbl.fold (fun _ p m -> max p m) players 0;;\n\nif ln = 15 then print_int m;\n\nfor i = ln-1 downto 0 do\n\tlet name, score = List.nth (!scores) i in\n\tif (score = m) && ((Hashtbl.find players name) = m) then begin\n\t\tprint_string name;\n\t\texit 0\n\tend\ndone;\n"}, {"source_code": "open Hashtbl;;\nopen Scanf;;\nopen List;;\n\nlet players = Hashtbl.create 0;;\nlet scores = ref [];;\n\n\nlet ib = Scanf.Scanning.stdib;;\nlet add_player name x =\n\tif not (Hashtbl.mem players name) then begin\n\t\tHashtbl.add players name 0\n\tend;\n\t\n\tlet player = Hashtbl.find players name in\n\tlet score = player + x in\n\tlet _ = scores := ((name, score) :: !scores) in\n\tHashtbl.replace players name score\n;;\n\nlet ln = read_int ();;\nfor i = 0 to ln-1 do\n\tScanf.bscanf ib \"%s %d\\n\" add_player\ndone;;\n\nlet m = Hashtbl.fold (fun _ p m -> max p m) players 0;;\n\nfor i = List.length (!scores) - 1 downto 0 do\n\tlet name, score = List.nth (!scores) i in\n\tif (score = m) && ((Hashtbl.find players name) = m) then begin\n\t\tprint_string name;\n\t\texit 0\n\tend\ndone;\n"}, {"source_code": "open Hashtbl;;\nopen Scanf;;\nopen List;;\n\nlet players = Hashtbl.create 0;;\nlet scores = ref [];;\n\n\nlet ib = Scanf.Scanning.stdib;;\nlet add_player name x =\n\tif not (Hashtbl.mem players name) then begin\n\t\tHashtbl.add players name 0\n\tend;\n\t\n\tlet player = Hashtbl.find players name in\n\tlet score = player + x in\n\tlet _ = scores := ((name, score) :: !scores) in\n\tHashtbl.replace players name score\n;;\n\nlet ln = read_int ();;\nfor i = 0 to ln-1 do\n\tScanf.bscanf ib \"%s %d\\n\" add_player\ndone;;\n\nlet m = Hashtbl.fold (fun _ p m -> max p m) players 0;;\n\nfor i = ln-1 downto 0 do\n\tlet name, score = List.nth (!scores) i in\n\tif (score = m) && ((Hashtbl.find players name) = m) then begin\n\t\tprint_string name;\n\t\texit 0\n\tend\ndone;\n"}, {"source_code": "exception Winner of string\n\nlet maximal_score l = \n let t = Hashtbl.create 13 in\n List.iter (fun (p,s) ->\n try \n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s)\n with\n |Not_found -> Hashtbl.add t p s\n ) l;\n Hashtbl.fold (fun _ s v -> max v s) t 0\n\nlet winner l =\n let maxs = maximal_score l in\n let t = Hashtbl.create 13 in \n List.iter (fun (p,s) ->\n try\n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s);\n if s' + s = maxs then (raise (Winner p))\n with\n |Not_found -> \n Hashtbl.add t p s;\n if s = maxs then (raise (Winner p))\n ) l\n\nlet rec input_list n = \n if n = 0 then []\n else begin try \n let (p,s) = Scanf.fscanf stdin \"%s %i\\n\" (fun a b -> (a,b)) in\n (p,s) :: (input_list (n-1))\n with\n |Not_found -> []\n end\n\nlet () = \n let n = int_of_string (read_line ()) in\n try\n winner (input_list n)\n with\n |Winner(s) -> Printf.printf \"%s\\n\" s\n\n"}, {"source_code": "exception Winner of string\n\nlet maximal_score l = \n let t = Hashtbl.create 13 in\n List.iter (fun (p,s) ->\n try \n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s)\n with\n |Not_found -> Hashtbl.add t p s\n ) l;\n Hashtbl.fold (fun _ s v -> max v s) t 0\n\nlet winner l =\n let maxs = maximal_score l in\n let t = Hashtbl.create 13 in \n List.iter (fun (p,s) ->\n try\n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s);\n if s' + s >= maxs then (raise (Winner p))\n with\n |Not_found -> \n Hashtbl.add t p s;\n if s >= maxs then (raise (Winner p))\n ) l\n\nlet rec input_list n = \n if n = 0 then []\n else begin try \n let (p,s) = Scanf.fscanf stdin \"%s %i\\n\" (fun a b -> (a,b)) in\n (p,s) :: (input_list (n-1))\n with\n |Not_found -> []\n end\n\nlet () = \n let n = int_of_string (read_line ()) in\n try\n winner (input_list n)\n with\n |Winner(s) -> Printf.printf \"%s\\n\" s\n\n"}, {"source_code": "exception Winner of string\n\nlet maximal_score l = \n let t = Hashtbl.create 13 in\n List.iter (fun (p,s) ->\n try \n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s)\n with\n |Not_found -> Hashtbl.add t p s\n ) l;\n Hashtbl.fold (fun _ s v -> max v s) t 0\n\nlet winner l =\n let maxs = maximal_score l in\n print_int maxs;\n print_endline \"\";\n let t = Hashtbl.create 13 in \n List.iter (fun (p,s) ->\n try\n let s' = Hashtbl.find t p in\n Hashtbl.replace t p (s' + s);\n if s' + s >= maxs then (raise (Winner p))\n with\n |Not_found -> \n Hashtbl.add t p s;\n if s >= maxs then (raise (Winner p))\n ) l\n\nlet rec input_list n = \n if n = 0 then []\n else begin try \n let (p,s) = Scanf.fscanf stdin \"%s %i\\n\" (fun a b -> (a,b)) in\n (p,s) :: (input_list (n-1))\n with\n |Not_found -> []\n end\n\nlet () = \n let n = int_of_string (read_line ()) in\n try\n winner (input_list n)\n with\n |Winner(s) -> Printf.printf \"%s\\n\" s\n\n"}, {"source_code": "let (|>) x f = f x\nlet identity x = x\n\nmodule Player = struct\n type t = String.t\n let equal = (=)\n let hash = Hashtbl.hash\nend\n\nmodule Gametbl = Hashtbl.Make (Player)\n\nmodule Score = struct\n type t = int\n let equal = (=)\n let hash = identity\nend\n\nmodule Scoretbl = Hashtbl.Make (Score)\n\nlet parse_games () =\n let games = Gametbl.create 10 in\n let push k v =\n match Gametbl.mem games k with\n true -> Gametbl.replace games k (v::(Gametbl.find games k))\n | false -> Gametbl.add games k [v] in\n let rec loop = function\n 0 -> ()\n | n -> Scanf.scanf \"%s %d\\n\" push; loop (n - 1) in\n Scanf.scanf \"%d\\n\" loop;\n games\n\nlet best_players gt =\n let scores = Scoretbl.create 10 in\n let max_score = ref 0 in\n let score_player p game_scores =\n let s = List.fold_left (+) 0 game_scores in\n max_score := max !max_score s;\n match Scoretbl.mem scores s with\n true -> Scoretbl.replace scores s (p::(Scoretbl.find scores s))\n | false -> Scoretbl.add scores s [p] in\n Gametbl.iter score_player gt;\n !max_score, Scoretbl.find scores !max_score\n\nlet winner gt (m,players) =\n match players with\n [] -> raise (Invalid_argument \"No Player\")\n | p::ps -> let rec score_reached scores cs i =\n if cs >= m\n then i\n else \n match scores with\n [] -> i\n | h::t -> score_reached t (cs+h) (i+1) in\n let game = ref (score_reached (List.rev (Gametbl.find gt p)) 0 0) in\n let better_player bp pl =\n let g = score_reached (List.rev (Gametbl.find gt pl)) 0 0 in\n if g < !game then (game := g; pl) else bp in\n List.fold_left better_player p ps\n\n\nlet _ =\n let gt = parse_games () in\n Printf.printf \"%s\\n\" (winner gt (best_players gt))\n"}, {"source_code": "let (|>) x f = f x\n\nmodule Player = struct\n type t = String.t\n let equal = (=)\n let hash = Hashtbl.hash\nend\n\ntype game = {\n nr : int;\n player : Player.t;\n score : int;\n}\n\nlet make_game nr player score = { nr; player; score }\n\nmodule Scoretbl = Hashtbl.Make (Player)\n\nlet parse_games () : game array =\n let parse n =\n Array.init n\n (fun i -> Scanf.scanf \"%s %d\\n\"\n (fun p s -> make_game i p s)) in\n Scanf.scanf \"%d\\n\" parse\n\nlet score_players games : game list Scoretbl.t =\n let scores = Scoretbl.create 10 in\n let add_score g =\n match Scoretbl.mem scores g.player with\n | true -> Scoretbl.replace scores g.player (g :: (Scoretbl.find scores g.player))\n | false -> Scoretbl.add scores g.player [g] in\n Array.iter add_score games;\n scores\n\nlet total_score games : int =\n List.fold_left (fun a g -> a + g.score) 0 games\n\nlet leaders scores =\n let highscore = ref min_int\n and leaders = ref [] in\n let check p games =\n let s = total_score games in\n if s = !highscore\n then leaders := p :: !leaders\n else if s > !highscore\n then begin\n highscore := s;\n leaders := [p]\n end in\n Scoretbl.iter check scores;\n !highscore, !leaders\n \nlet threshold high games =\n let rec count i s = function\n | [] -> i\n | h::t -> if s >= high then i else count (i + 1) (s + h.score) t\n in count 0 0 (List.rev games)\n\nlet winner scores (high, players) =\n let (p,_) =\n List.fold_left (fun ((w,r) as m) pl ->\n let round = threshold high (Scoretbl.find scores pl) in\n if round < r then (pl,round) else m)\n (\"\",max_int)\n players in\n p\n\n\n\nlet _ =\n let scores = parse_games () |> score_players in\n Printf.printf \"%s\\n\" (winner scores (leaders scores))\n"}], "src_uid": "c9e9b82185481951911db3af72fd04e7"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\n\nlet () = \n let n = read_int () in\n let m = read_int () in\n\n let a = Array.make_matrix n m 0L in\n\n for i=0 to n-1 do\n for j=0 to m-1 do\n a.(i).(j) <- read_long ()\n done\n done;\n\n let ur = Array.make_matrix n m 0L in\n let dr = Array.make_matrix n m 0L in\n let ul = Array.make_matrix n m 0L in\n let dl = Array.make_matrix n m 0L in\n\n let probe a i j = if i<0 || j<0 || i>n-1 || j>m-1 then 0L else a.(i).(j) in\n\n for i=0 to n-1 do\n for j=0 to m-1 do\n ul.(i).(j) <- a.(i).(j) ++ (max (probe ul (i-1) j) (probe ul i (j-1)))\n done;\n for j=m-1 downto 0 do\n ur.(i).(j) <- a.(i).(j) ++ (max (probe ur (i-1) j) (probe ur i (j+1)))\n done\n done;\n\n for i=n-1 downto 0 do\n for j=0 to m-1 do\n dl.(i).(j) <- a.(i).(j) ++ (max (probe dl (i+1) j) (probe dl i (j-1)))\n done;\n for j=m-1 downto 0 do\n dr.(i).(j) <- a.(i).(j) ++ (max (probe dr (i+1) j) (probe dr i (j+1)))\n done\n done;\n\n let best = ref 0L in\n\n for i=1 to n-2 do\n for j=1 to m-2 do\n let opt1 = ul.(i-1).(j) ++ ur.(i).(j+1) ++ dl.(i).(j-1) ++ dr.(i+1).(j) in\n let opt2 = ur.(i-1).(j) ++ dr.(i).(j+1) ++ ul.(i).(j-1) ++ dl.(i+1).(j) in\n best := max (max opt1 opt2) !best\n done\n done;\n\n printf \"%Ld\\n\" !best\n", "positive_code": [{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule H = Hashtbl\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\nlet rec bsearch_min a b test =\n if b - a = 1 then b else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_min a mid test else \n bsearch_min mid b test\nlet rec bsearch_max a b test = \n if b - a = 1 then a else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_max mid b test else \n bsearch_max a mid test\n(* int *)\nlet sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)\nlet sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i) \n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* int, int *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* number theory *)\nlet sieve_under len = (* len > 0 *)\n let sieve = Array.make len true in \n Array.fill sieve 0 (min len 2) false;\n let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in \n for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;\n sieve\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 128 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create (4*1024) in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let row = read_int() in \n let col = read_int() in \n let mat = make_matrix row col 0 in \n for i = 0 to row -1 do \n for j = 0 to col -1 do \n mat.(i).(j) <- read_int() \n done\n done;\n\n let is_valid (y,x) = \n 0 <= x && x < col &&\n 0 <= y && y < row \n in \n let save mat (y,x) v = mat.(y).(x) <- v; v in\n let read mat (y,x) = mat.(y).(x) in \n\n let cub = init 4 (fun i -> make_matrix row col (-1)) in \n let config = [|\n [| (row-1,col-1); (-1,0); (0,-1) |];\n [| (0,0) ; (1,0) ; (0,1) |];\n [| (row-1,0) ; (-1,0); (0, 1) |];\n [| (0,col-1) ; (1,0) ; (0,-1) |];\n |] in \n\n for i = 0 to 3 do \n let rec dp pos = \n if not (is_valid pos) then 0 else \n let t = read cub.(i) pos in \n if t <> (-1) then t else begin \n let m = max (dp (pos +: config.(i).(1))) (dp (pos +: config.(i).(2))) in \n save cub.(i) pos (m + read mat pos)\n end \n in \n dp config.(i).(0) |> ignore;\n done;\n\n let rec run i j m = \n if i = row-1 then m else \n if j = col-1 then run (i+1) 1 m else \n let pos = (i,j) in \n let a = read cub.(0) (pos -: (0,1)) + read cub.(1) (pos +: (0,1)) \n + read cub.(2) (pos -: (1,0)) + read cub.(3) (pos +: (1,0)) in \n let b = read cub.(0) (pos -: (1,0)) + read cub.(1) (pos +: (1,0)) \n + read cub.(2) (pos +: (0,1)) + read cub.(3) (pos -: (0,1)) in \n let m' = max a b in \n run i (j+1) (max m m')\n in \n\n (* for i = 0 to 3 do print_matrix (\"%d \") cub.(i) done;\n *)\n printf \"%d\\n\" (run 1 1 0)"}], "negative_code": [{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule H = Hashtbl\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\nlet rec bsearch_min a b test =\n if b - a = 1 then b else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_min a mid test else \n bsearch_min mid b test\nlet rec bsearch_max a b test = \n if b - a = 1 then a else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_max mid b test else \n bsearch_max a mid test\n(* int *)\nlet sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)\nlet sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i) \n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* int, int *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* number theory *)\nlet sieve_under len = (* len > 0 *)\n let sieve = Array.make len true in \n Array.fill sieve 0 (min len 2) false;\n let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in \n for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;\n sieve\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 128 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create (4*1024) in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let row = read_int() in \n let col = read_int() in \n let mat = make_matrix row col 0 in \n for i = 0 to row -1 do \n for j = 0 to col -1 do \n mat.(i).(j) <- read_int() \n done\n done;\n\n let is_valid (y,x) = \n 0 <= x && x < col &&\n 0 <= y && y < row \n in \n let save mat (y,x) v = mat.(y).(x) <- v; v in\n let read mat (y,x) = mat.(y).(x) in \n\n let cub = init 4 (fun i -> make_matrix row col (-1)) in \n let config = [|\n [| (row-1,col-1); (-1,0); (0,-1) |];\n [| (row-1,0) ; (-1,0); (0, 1) |];\n [| (0,col-1) ; (1,0) ; (0,-1) |];\n [| (0,0) ; (1,0) ; (0,1) |];\n |] in \n\n for i = 0 to 3 do \n let rec dp pos = \n if not (is_valid pos) then 0 else \n let t = read cub.(i) pos in \n if t <> (-1) then t else begin \n let m = max (dp (pos +: config.(i).(1))) (dp (pos +: config.(i).(2))) in \n save cub.(i) pos (m + read mat pos)\n end \n in \n dp config.(i).(0) |> ignore;\n done;\n\n let rec run i j m = \n if i = row then m else \n if j = col then run (i+1) 0 m else \n let pos = (i,j) in \n let m' = for_ 0 4 0 (fun i c -> c + read cub.(i) pos) - 4 * read mat pos in \n run i (j+1) (max m m')\n in \n\n (* for i = 0 to 3 do print_matrix (\"%d \") cub.(i) done; *)\n printf \"%d\\n\" (run 0 0 0)"}], "src_uid": "ed5d0eca057f2a2e371b1fc7e3b618bb"} {"source_code": "let compte mot =\n\tlet tab = Array.make 123 0 in\n\tfor i=0 to String.length mot-1 do\n\t\ttab.(int_of_char (mot.[i])) <- 1 + tab.(int_of_char (mot.[i]));\n\tdone;\n\ttab;;\n\nlet f mot1 mot2 =\n\tlet tab1 = compte mot1 and tab2 = compte mot2 \n\tand compteur = ref 0 and compteur2 = ref 0 in\n\tfor i=0 to 122 do\n\t\tlet a = min (tab1.(i)) (tab2.(i)) in\n\t\t\tcompteur := a + !compteur;\n\t\t\ttab1.(i) <- tab1.(i) - a;\n\t\t\ttab2.(i) <- tab2.(i) - a;\n\tdone;\n\tlet tab_r1 = Array.init 26 (fun i -> tab1.(65 +i) + tab1.(97 + i))\n\tand tab_r2 = Array.init 26 (fun i -> tab2.(65 +i) + tab2.(97 + i))\n\tin\n\tfor i=0 to 25 do\n\t\tlet a = min (tab_r1.(i)) (tab_r2.(i)) in\n\t\t\tcompteur2 := a + !compteur2;\n\t\t\ttab_r1.(i) <- tab_r1.(i) - a;\n\t\t\ttab_r2.(i) <- tab_r2.(i) - a;\n\tdone;\n\t!compteur, !compteur2;;\n\nlet main () =\n\tlet mot1 = Scanf.scanf \"%s \" (fun i -> String.trim i) in\n\tlet mot2 = Scanf.scanf \"%s \" (fun i -> String.trim i) in\n\tlet (a,b) = f mot1 mot2 in\n\t\tPrintf.printf \"%d %d \" a b;;\n\nmain ();;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet isupper c = c <= 'Z' && c >= 'A'\nlet l2n c = (int_of_char c) - (int_of_char 'a')\nlet l2N c = (int_of_char c) - (int_of_char 'A')\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\n\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let s = read_string () in\n let t = read_string () in\n\n let compute_hist s =\n let h = Array.make_matrix 26 2 0 in\n let n = String.length s in\n for i=0 to n-1 do\n if isupper s.[i] then (\n\tlet x = l2N s.[i] in\n\th.(x).(1) <- h.(x).(1) + 1;\n ) else (\n\tlet x = l2n s.[i] in\n\th.(x).(0) <- h.(x).(0) + 1;\n )\n done;\n h\n in\n\n let hist_s = compute_hist s in\n let hist_t = compute_hist t in\n\n let ( ++ ) (a,b) (c,d) = (a+c, b+d) in\n \n let eval_letter ls hs lt ht =\n let yay = (min ls lt) + (min hs ht) in\n let short = min (ls+hs) (lt+ht) in\n (yay, short-yay)\n in\n\n let (x,y) = fold 0 25 (\n fun i ac -> \n (eval_letter hist_s.(i).(0) hist_s.(i).(1) hist_t.(i).(0) hist_t.(i).(1)) ++ ac\n ) (0,0)\n in\n\n printf \"%d %d\\n\" x y\n \n"}], "negative_code": [], "src_uid": "96e2ba997eff50ffb805b6be62c56222"} {"source_code": "let rec print1 n =\n for i = 1 to n do\n \tPrintf.printf \"1\";\n done;;\n\nlet n = read_int () ;;\nif n mod 2 == 0 then print1 (n / 2)\nelse begin\n\tprint_int 7;\n\tprint1 (n / 2 - 1)\nend", "positive_code": [{"source_code": "let a = read_int();;\nlet n = ref a;;\n\nif (a mod 2 == 1) then\n\tprint_int 7;\n\tn := a-3;;\n\nif (a mod 2 == 0) then\n\tn := a;;\n\nlet x = (!n)/2\nfor i=1 to x do\n\tPrintf.printf \"1\"\ndone"}, {"source_code": "let n=read_int();;\nlet g = n;\nif n mod 2 == 1 then print_string(\"7\");\nlet n = if n mod 2 == 1 then n - 3 else n in\nfor i = 1 to n / 2 do\nprint_string(\"1\");\ndone;;\n"}, {"source_code": "open Printf;;\nlet n=read_int();;\n\nif n mod 2 > 0 then begin\n printf \"7\";\n for i=1 to (n-3)/2 do\n printf \"1\"\n done\nend\nelse begin\n for i=1 to n/2 do\n printf \"1\"\n done\nend;;"}, {"source_code": "open Printf;;\n\nlet n=read_int();;\n\n(if (n mod 2 == 1) then\n printf \"%d\" (7)\n);\n\nfor i = 1 to (n / 2 - (n mod 2)) do\n printf \"%d\" (1)\ndone;;\n"}, {"source_code": "let n=read_int();;\nif n == 1 then print_endline(\"0\")\nelse \n\tfor i = 1 to n/2 do \n\t if n mod 2 == 1 && i==1 then Printf.printf \"%d\" 7\n \telse Printf.printf \"%d\" 1\n \tdone;;"}], "negative_code": [{"source_code": "let rec print1 n =\n for i = 1 to n do\n \tPrintf.printf \"1\";\n done;;\n\nlet n = read_int () ;;\nif n mod 2 == 0 then print1 (n / 2)\nelse begin\n\tprint1 (n / 2 - 1) ;\n\tprint_int 7\nend"}, {"source_code": "let rec print1 n =\n match n with\n | -1 -> true;\n | 0 -> true;\n | nn -> print_int 1 ; print1 (n-1)\n\nlet n = read_int () ;;\nif n mod 2 == 0 then print1 (n / 2)\nelse begin\n\tprint1 (n / 2 - 1) ;\n\tprint_int 7;\n\ttrue\nend"}], "src_uid": "4ebea3f56ffd43efc9e1496a0ef7fa2d"} {"source_code": "let xint _ = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let min x y = \n if x < y then x\n else y\n in\n let n = xint() and w = xint() in\n let a = Array.make (n * 2) 0 in\n for i = 0 to (n * 2 - 1) do\n a.(i) <- xint();\n done;\n Array.sort compare a;\n let x = a.(0) and y = a.(n) in\n let z = min (float_of_int y) ((float_of_int x) *. 2.) in\n Printf.printf \"%.10f\\n\" (min (float_of_int w) (z *. 1.5 *. (float_of_int n)));\n\n", "positive_code": [{"source_code": "module A = Array\nmodule C = Char\nmodule I = Int64\nmodule L = List\nmodule Q = Queue\nmodule S = String\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet ssf = Scanf.sscanf\n\nlet (|>) x f = f x\nlet (@@) f x = f x\n\nlet id x = x\nlet id2 x y = (x, y)\nlet id3 x y z = (x, y, z)\nlet id4 a b c d = (a, b, c, d)\nlet id5 a b c d e = (a, b, c, d, e)\n\nlet err s = raise (Failure s)\n\nlet inf = 1000000000\nlet eps = 1e-11\n\nlet _ =\n let n, w = sf \"%d %f \" id2 in\n let a = A.make (2 * n) 0. in\n for i = 0 to 2 * n - 1 do\n let ai = sf \"%d \" id in\n a.(i) <- float ai\n done;\n A.sort compare a;\n let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in\n r *. 1.5 *. float n |> min w |> pf \"%.9f\\n\"\n;;\n"}], "negative_code": [{"source_code": "module A = Array\nmodule C = Char\nmodule I = Int64\nmodule L = List\nmodule Q = Queue\nmodule S = String\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet ssf = Scanf.sscanf\n\nlet (|>) x f = f x\nlet (@@) f x = f x\n\nlet id x = x\nlet id2 x y = (x, y)\nlet id3 x y z = (x, y, z)\nlet id4 a b c d = (a, b, c, d)\nlet id5 a b c d e = (a, b, c, d, e)\n\nlet err s = raise (Failure s)\n\nlet inf = 1000000000\nlet eps = 1e-11\n\nlet _ =\n let n, w = sf \"%d %d \" id2 in\n let a = A.make (2 * n) 0. in\n for i = 0 to 2 * n - 1 do\n let ai = sf \"%d \" id in\n a.(i) <- float ai\n done;\n A.sort compare a;\n let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in\n r *. 1.5 *. float n |> max 1. |> pf \"%.9f\\n\"\n;;\n"}, {"source_code": "module A = Array\nmodule C = Char\nmodule I = Int64\nmodule L = List\nmodule Q = Queue\nmodule S = String\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet ssf = Scanf.sscanf\n\nlet (|>) x f = f x\nlet (@@) f x = f x\n\nlet id x = x\nlet id2 x y = (x, y)\nlet id3 x y z = (x, y, z)\nlet id4 a b c d = (a, b, c, d)\nlet id5 a b c d e = (a, b, c, d, e)\n\nlet err s = raise (Failure s)\n\nlet inf = 1000000000\nlet eps = 1e-11\n\nlet _ =\n let n, w = sf \"%d %d \" id2 in\n let a = A.make (2 * n) 0. in\n for i = 0 to 2 * n - 1 do\n let ai = sf \"%d \" id in\n a.(i) <- float ai\n done;\n A.sort compare a;\n let r = A.mapi (fun x y -> if x < n then 2. *. y else y) a |> A.fold_left min 1e9 in\n pf \"%.9f\\n\" @@ r *. 1.5 *. float n\n;;\n"}], "src_uid": "b2031a328d72b464f965b4789fd35b93"} {"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() and m = scan_int();;\nlet a = Array.make n 0 and b = Array.make m (0, 0) and wyn = Array.make m 0;;\n\nfor i = 0 to n - 1 do\n a.(i) <- scan_int ();\ndone;\n\nfor i = 0 to m - 1 do\n b.(i) <- (scan_int (), i);\ndone;\n\nArray.sort compare a; Array.sort compare b;\n\nlet cnt = ref 0 and l = ref 0 in\n\nfor i = 0 to m - 1 do\n while (!l < n) && a.(!l) <= fst (b.(i)) do\n incr cnt; incr l; \n done;\n wyn.(snd b.(i)) <- !cnt;\ndone; \n\nfor i = 0 to m - 1 do\n print_int(wyn.(i)); psp();\ndone;", "positive_code": [{"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() and m = scan_int();;\nlet a = Array.make n 0 and b = Array.make m (0, 0) and wyn = Array.make m 0;;\n\nfor i = 0 to n - 1 do\n a.(i) <- scan_int ();\ndone;\n\nfor i = 0 to m - 1 do\n b.(i) <- (scan_int (), i);\ndone;\n\nArray.fast_sort compare a; Array.fast_sort compare b;\n\nlet cnt = ref 0 and l = ref 0 in\n\nfor i = 0 to m - 1 do\n while (!l < n) && a.(!l) <= fst (b.(i)) do\n incr cnt; incr l; \n done;\n wyn.(snd b.(i)) <- !cnt;\ndone; \n\nfor i = 0 to m - 1 do\n print_int(wyn.(i)); psp();\ndone;"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n let b = Array.make m 0 in\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 0 to m - 1 do\n b.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n Array.sort compare a;\n for i = 0 to m - 1 do\n let l = ref (-1)\n and r = ref n in\n\twhile !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t if a.(m) <= b.(i)\n\t then l := m\n\t else r := m\n\tdone;\n\tPrintf.printf \"%d \" !r;\n done;\n Printf.printf \"\\n\"\n"}], "negative_code": [], "src_uid": "e9a519be33f25c828bae787330c18dd4"} {"source_code": "type passenger = {\n mutable f : int;\n mutable t : int;\n};;\n\n(* Echange deux \u00e9l\u00e9ments d'un tableau *)\nlet echange tab i j = \n let z = tab.(i) in\n tab.(i) <- tab.(j);\n tab.(j) <- z;;\n\n(* Quicksort : Sort on the floor of each passenger *)\nlet partition tab p r =\n let x = tab.(r) in (* Pivot *)\n let i = ref (p - 1) in\n for j = p to r - 1 do\n if tab.(j).f <= x.f then begin\n i := !i + 1 ;\n echange tab !i j\n end\n done ; echange tab (!i + 1) r ;\n (!i + 1);;\nlet rec quickSort tab p r =\n if p < r then begin\n let q = partition tab p r in\n quickSort tab p (q-1) ;\n quickSort tab (q + 1) r\n end;;\n\nlet n, s = Scanf.scanf \"%d %d \" (fun n' s' -> n', s') in\n let passengers = Array.init n (fun _i -> \n let pass_f, pass_t = Scanf.scanf \"%d %d \" (fun f' t' -> f', t') in\n {f = pass_f ; t = pass_t}\n ) in\n quickSort passengers 0 (n-1) ;\n let time = ref 0 in\n let floor = ref s in\n for i = 0 to (n-1) do\n time := !time + (!floor - (passengers.(i).f)); (* Temps de descente *)\n floor := passengers.(i).f;\n if !time < passengers.(i).t then \n time := !time + (passengers.(i).t - !time) (* Temps d'attente *)\n done ; \n time := !time + !floor ; (* On descend tout en bas *)\n print_int !time;;\n \n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\t\t\t\t \nlet () = \n let n = read_int () in\n let s = read_int () in\n let pass = Array.init n (fun _ -> read_pair()) in\n let arrive = Array.make (s+1) 0 in\n\n for i=0 to n-1 do\n let (f,t) = pass.(i) in\n arrive.(f) <- max arrive.(f) t\n done;\n\n let rec loop floor time = if floor = 0 then time else\n (* at floor arrive at time *)\n let time = max time arrive.(floor) in\n loop (floor-1) (time+1)\n in\n\n printf \"%d\\n\" (loop s 0)\n"}, {"source_code": "let r2 = Scanf.scanf \" %d %d\" ;;\nlet n, s = r2 (fun x y -> (x, y)) ;;\n\nlet a = Array.make s 0 ;;\nfor _ = 1 to n do\n let f, t = r2 (fun x y -> (x-1, y)) in\n a.(f) <- max a.(f) t\ndone ;;\n\nlet rec time f t = match f with\n | 0 -> t\n | f -> time (f-1) (1 + max t a.(f-1) )\n;;\nprint_int @@ time s 0\n"}], "negative_code": [], "src_uid": "5c12573b3964ee30af0349c11c0ced3b"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet build_answer n b =\n let v = Array.make_matrix n n 0 in\n for i=0 to n-1 do\n v.(i).(i) <- b.(i)\n done;\n\n for d=2 to n do\n for l=0 to n-d do\n let r = l+d-1 in\n v.(l).(r) <- v.(l+1).(r) lxor v.(l).(r-1)\n done\n done;\n\n for r=1 to n-1 do\n for l=r-1 downto 0 do\n v.(l).(r) <- max v.(l).(r) v.(l+1).(r)\n done\n done;\n\n for r=1 to n-1 do\n for l=r-1 downto 0 do\n v.(l).(r) <- max v.(l).(r) v.(l).(r-1)\n done\n done;\n\n v\n \nlet () = \n let n = read_int () in\n let b = Array.init n read_int in\n let q = read_int () in\n\n let v = build_answer n b in\n\n for i=1 to q do\n let l = read_int() -1 in\n let r = read_int() -1 in\n printf \"%d\\n\" v.(l).(r)\n done\n \n", "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\nlet n = scan_int();;\nlet a = Array.init n (fun i -> scan_int());;\n\nlet f = Array.make_matrix n n 0 and wyn = Array.make_matrix n n 0;;\nfor i = 0 to (n - 1) do\n f.(i).(i) <- a.(i);\n wyn.(i).(i) <- a.(i);\ndone;;\n\nfor i = 2 to n do\n for j = 0 to (n - i) do\n let r = j + i - 1 in\n f.(j).(r) <- f.(j + 1).(r) lxor f.(j).(r - 1);\n wyn.(j).(r) <- max (f.(j).(r)) (max wyn.(j+1).(r) wyn.(j).(r - 1));\n done;\ndone;;\n\nlet q = scan_int();;\nfor i = 1 to q do\n let a = scan_int() and b = scan_int() in\n print_int(wyn.(a - 1).(b - 1)); pnl();\ndone;;"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\nlet n = scan_int();;\nlet a = Array.init n (fun i -> scan_int());;\n\nlet f = Array.make_matrix n n 0 and wyn = Array.make_matrix n n 0;;\nfor i = 0 to (n - 1) do\n f.(i).(i) <- a.(i);\n wyn.(i).(i) <- a.(i);\ndone;;\n\nfor i = 2 to n do\n for j = 0 to (n - i) do\n let r = j + i - 1 in\n f.(j).(r) <- f.(j + 1).(r) lxor f.(j).(r - 1);\n wyn.(j).(r) <- max f.(j).(r) (max f.(j+1).(r) f.(j).(r - 1));\n done;\ndone;;\n\nlet q = scan_int();;\nfor i = 1 to q do\n let a = scan_int() and b = scan_int() in\n print_int(wyn.(a - 1).(b - 1)); pnl();\ndone;;"}], "src_uid": "5a686ba072078c9d0258987cb32d00fc"} {"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 \"%d \" (fun s -> s) in\n let a = Array.make n 0L in\n let s = ref 0L in\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%Ld \" (fun s -> s);\n s := !s +| a.(i);\n done;\n Array.sort compare a;\n let ma = !s /| Int64.of_int n in\n let mb =\n ma +| if ma *| Int64.of_int n = !s then 0L else 1L\n in\n let x = ref 0L in\n let y = ref 0L in\n for i = 0 to n - 1 do\n\tif a.(i) < ma\n\tthen x := !x +| ma -| a.(i)\n\telse if a.(i) > mb\n\tthen y := !y +| a.(i) -| mb\n done;\n let res = max !x !y in\n Printf.printf \"%Ld\\n\" res\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet ( ++ ) a b = Int64.add a b\nlet ( ** ) a b = Int64.mul a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div 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))\n\nlet () = \n\n let n = read_int() in\n let nn = long n in\n let m = Array.init n (fun _ -> long (read_int())) in\n let s = sum 0 (n-1) (fun i -> m.(i)) 0L in\n\n let p = s//nn in\n let q = (s++(nn--1L)) // nn in\n\n let total_above_q = sum 0 (n-1) (fun i -> max 0L (m.(i) -- q)) 0L in\n let total_below_p = sum 0 (n-1) (fun i -> max 0L (p -- m.(i))) 0L in\n\n printf \"%Ld\\n\" (max total_above_q total_below_p)\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet ( ++ ) a b = Int64.add a b\nlet ( ** ) a b = Int64.mul a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div 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))\n\nlet () = \n\n let n = read_int() in\n let nn = long n in\n let m = Array.init n (fun _ -> long (read_int())) in\n let s = sum 0 (n-1) (fun i -> m.(i)) 0L in\n\n let p = s//nn in\n let q = (s++(nn--1L)) // nn in\n\n let total_above_q = sum 0 (n-1) (fun i -> max 0L (m.(i) -- q)) 0L in\n let total_below_p = sum 0 (n-1) (fun i -> min 0L (p -- m.(i))) 0L in\n\n printf \"%Ld\\n\" (max total_above_q total_below_p)\n"}], "src_uid": "c0c29565e465840103a4af884f951cda"} {"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet pf = Printf.printf\n \nlet epf = Printf.eprintf\n \nlet sf = Scanf.scanf\n \nlet ( |> ) x f = f x\n \nlet ( @@ ) f x = f x\n \nmodule Array = ArrayLabels\n \nmodule List =\n struct\n include ListLabels\n \n let rec repeat n a =\n if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)\n \n let rec drop n a =\n if n = 0\n then a\n else\n (match a with\n | [] -> failwith \"cannot take\"\n | x :: xs -> drop (Pervasives.( - ) n 1) xs)\n \n end\n \nmodule H = Hashtbl\n \nlet solve n arr =\n (Array.sort ~cmp: compare arr;\n let prev = ref arr.(0) in\n let cnt = ref 1L in\n let ls = ref []\n in\n (for i = 1 to Pervasives.( - ) n 1 do\n if !prev = arr.(i)\n then cnt := Int64.add !cnt 1L\n else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)\n done;\n ls := ((!prev), (!cnt)) :: !ls;\n let arr = Array.of_list !ls in\n let n = Array.length arr\n in\n (Array.iter arr ~f: (fun (v, c) -> epf \"(%Ld, %Ld), \" v c);\n epf \"\\n\";\n let mul (x, y) = Int64.mul (x : int64) y in\n let memo = H.create 10 in\n let rec iter i =\n if i = n\n then 0L\n else\n if i = (Pervasives.( - ) n 1)\n then mul arr.(i)\n else\n if H.mem memo i\n then H.find memo i\n else\n if\n (Int64.sub (fst arr.(i)) 1L) =\n (fst arr.(Pervasives.( + ) i 1))\n then\n (let v =\n max\n (Int64.add (iter (Pervasives.( + ) i 2))\n (mul arr.(i)))\n (iter (Pervasives.( + ) i 1))\n in (H.add memo i v; v))\n else\n (let v =\n Int64.add (mul arr.(i)) (iter (Pervasives.( + ) i 1))\n in (H.add memo i v; v))\n in (pf \"%Ld\\n\") @@ (iter 0))))\n \nlet () =\n sf \"%d \"\n (fun n ->\n let arr = Array.init n ~f: (fun _ -> sf \"%Ld \" (fun x -> x))\n in solve n arr)\n \n\n", "positive_code": [{"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\nlet n = bscanf Scanning.stdin \"%d \" (fun x -> x);;\n\nlet nn = 100000 + 5;;\nlet count = Array.make nn (num_of_int 0);;\nlet indx = Array.make nn 0;;\nlet score = Array.make nn (num_of_int 0);;\n\nlet p = Array.init n (fun x -> 0);;\n\nfor i=0 to n-1 do\n let f = bscanf Scanning.stdin \"%d \" (fun x -> x) in\n count.(f) <- count.(f) +/ (num_of_int f)\ndone;;\n\nlet l = ref 1;;\n\nfor i=1 to nn-1 do\n if count.(i) >/ num_of_int 0 then\n begin\n indx.(!l) <- i;\n l := !l + 1\n end\ndone;;\n\n(*For testing\nfor i=1 to !l-1 do\n printf \"%d %d\\n\" indx.(i) count.(indx.(i));\ndone;;*)\n\nscore.(0) <- num_of_int 0;;\nscore.(1) <- count.(indx.(1));;\nlet cur_indx = ref indx.(1) in\nfor i=2 to !l-1 do\n let x1 = !cur_indx in\n let x2 = indx.(i) in\n if x2 > x1 + 1 then\n begin\n score.(i)<-score.(i-1) +/ count.(x2);\n cur_indx := indx.(i)\n end\n else\n begin\n let tscore = score.(i-2) +/ count.(x2) in\n if tscore >/ score.(i-1) then\n begin\n score.(i) <- tscore;\n cur_indx := x2\n end\n else\n begin\n score.(i) <- score.(i-1);\n cur_indx := indx.(i-1)\n end\n end\ndone;;\n\nprint_endline (string_of_num (score.(!l-1)));; \n\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print score = Printf.printf \"%Ld\\n\" score\n\nlet list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet count list =\n let rec loop count acc = function\n | a :: (b :: _ as tl) -> if a = b then loop (count + 1) acc tl\n else loop 0 ((a, count + 1) :: acc) tl\n | [x] -> (x, count + 1) :: acc\n | [] -> []\n in List.rev (loop 0 [] list)\n\nlet multiply list = List.map (fun (x, n) -> (x, Int64.mul (Int64.of_int x) (Int64.of_int n))) list\n\nlet score list = \n let rec loop prev sum_if_prev_taken sum_if_prev_skipped rest =\n let sum_if_unconstrained = Pervasives.max sum_if_prev_taken sum_if_prev_skipped in\n match rest with\n | [] -> sum_if_unconstrained\n | (a, v) :: tl -> \n let sum_if_a_taken = \n if a - 1 = prev\n then\n Int64.add v sum_if_prev_skipped\n else\n Int64.add v sum_if_unconstrained\n in\n let sum_if_a_skipped = sum_if_unconstrained in\n loop a sum_if_a_taken sum_if_a_skipped tl\n in loop (-1) 0L 0L list\n\nlet input () = \n let n = read () in\n let numbers = List.sort (Pervasives.compare) (list_init n (fun i -> read ())) in\n (numbers, n)\n\nlet solve (numbers, n) = \n let score = score (multiply (count numbers)) in\n score\n\nlet () = print (solve (input ()))"}], "negative_code": [{"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet pf = Printf.printf\n \nlet epf = Printf.eprintf\n \nlet sf = Scanf.scanf\n \nlet ( |> ) x f = f x\n \nlet ( @@ ) f x = f x\n \nmodule Array = ArrayLabels\n \nmodule List =\n struct\n include ListLabels\n \n let rec repeat n a =\n if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)\n \n let rec drop n a =\n if n = 0\n then a\n else\n (match a with\n | [] -> failwith \"cannot take\"\n | x :: xs -> drop (Pervasives.( - ) n 1) xs)\n \n end\n \nmodule H = Hashtbl\n \nlet solve n arr =\n (Array.sort ~cmp: compare arr;\n let prev = ref arr.(0) in\n let cnt = ref 1L in\n let ls = ref []\n in\n (for i = 1 to Pervasives.( - ) n 1 do\n if !prev = arr.(i)\n then cnt := Int64.add !cnt 1L\n else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)\n done;\n ls := ((!prev), (!cnt)) :: !ls;\n let arr = Array.of_list !ls in\n let n = Array.length arr\n in\n (Array.iter arr ~f: (fun (v, c) -> epf \"(%Ld, %Ld), \" v c);\n epf \"\\n\";\n let mul (x, y) = Int64.mul (x : int64) y in\n let memo = H.create 10 in\n let rec iter i =\n if i = n\n then 0L\n else\n if i = (Pervasives.( - ) n 1)\n then mul arr.(i)\n else\n if H.mem memo i\n then H.find memo i\n else\n if\n (Int64.sub (fst arr.(i)) 1L) =\n (fst arr.(Pervasives.( + ) i 1))\n then\n (let v =\n max\n (Int64.add (iter (Pervasives.( + ) i 2))\n (mul arr.(i)))\n (iter (Pervasives.( + ) i 1))\n in (H.add memo i v; v))\n else\n (let v =\n Int64.add (mul arr.(i)) (iter (Pervasives.( + ) i 2))\n in (H.add memo i v; v))\n in (pf \"%Ld\\n\") @@ (iter 0))))\n \nlet () =\n sf \"%d \"\n (fun n ->\n let arr = Array.init n ~f: (fun _ -> sf \"%Ld \" (fun x -> x))\n in solve n arr)\n \n"}, {"source_code": "let ( + ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( * ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( - ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( / ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet ( ~- ) : 'a -> 'a -> 'a = fun x y -> assert false\n \nlet pf = Printf.printf\n \nlet epf = Printf.eprintf\n \nlet sf = Scanf.scanf\n \nlet ( |> ) x f = f x\n \nlet ( @@ ) f x = f x\n \nmodule Array = ArrayLabels\n \nmodule List =\n struct\n include ListLabels\n \n let rec repeat n a =\n if n = 0 then [] else a :: (repeat (Pervasives.( - ) n 1) a)\n \n let rec drop n a =\n if n = 0\n then a\n else\n (match a with\n | [] -> failwith \"cannot take\"\n | x :: xs -> drop (Pervasives.( - ) n 1) xs)\n \n end\n \nmodule H = Hashtbl\n \nlet solve n arr =\n (Array.sort ~cmp: compare arr;\n let prev = ref arr.(0) in\n let cnt = ref 1L in\n let ls = ref []\n in\n (for i = 1 to Pervasives.( - ) n 1 do\n if !prev = arr.(i)\n then cnt := Int64.add !cnt 1L\n else (ls := ((!prev), (!cnt)) :: !ls; prev := arr.(i); cnt := 1L)\n done;\n ls := ((!prev), (!cnt)) :: !ls;\n let arr = Array.of_list !ls in\n let n = Array.length arr\n in\n (Array.iter arr ~f: (fun (v, c) -> epf \"(%Ld, %Ld), \" v c);\n epf \"\\n\";\n let mul (x, y) = Int64.mul (x : int64) y in\n let memo = H.create 10 in\n let rec iter i =\n if i = n\n then 0L\n else\n if i = (Pervasives.( - ) n 1)\n then mul arr.(i)\n else\n if H.mem memo i\n then H.find memo i\n else\n if\n (Int64.sub (fst arr.(i)) 1L) =\n (fst arr.(Pervasives.( + ) i 1))\n then\n (let v =\n max\n (Int64.add (iter (Pervasives.( + ) i 2))\n (mul arr.(i)))\n (iter (Pervasives.( + ) i 1))\n in (H.add memo i v; v))\n else\n (let v =\n Int64.add\n (Int64.add (mul arr.(i))\n (mul arr.(Pervasives.( + ) i 1)))\n (iter (Pervasives.( + ) i 2))\n in (H.add memo i v; v))\n in (pf \"%Ld\\n\") @@ (iter 0))))\n \nlet () =\n sf \"%d \"\n (fun n ->\n let arr = Array.init n ~f: (fun _ -> sf \"%Ld \" (fun x -> x))\n in solve n arr)\n \n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print score = Printf.printf \"%d\\n\" score\n\nlet list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet count list =\n let rec loop count acc = function\n | a :: (b :: _ as tl) -> if a = b then loop (count + 1) acc tl\n else loop 0 ((a, count + 1) :: acc) tl\n | [x] -> (x, count + 1) :: acc\n | [] -> []\n in List.rev (loop 0 [] list)\n\nlet multiply list = List.map (fun (x, n) -> (x, x * n)) list\n\nlet score list = \n let rec loop prev sum_if_prev_taken sum_if_prev_skipped rest =\n let sum_if_unconstrained = Pervasives.max sum_if_prev_taken sum_if_prev_skipped in\n match rest with\n | [] -> sum_if_unconstrained\n | (a, v) :: tl -> \n let sum_if_a_taken = \n if a - 1 = prev\n then\n v + sum_if_prev_skipped\n else\n v + sum_if_unconstrained\n in\n let sum_if_a_skipped = sum_if_unconstrained in\n loop a sum_if_a_taken sum_if_a_skipped tl\n in loop (-1) 0 0 list\n\nlet input () = \n let n = read () in\n let numbers = List.sort (Pervasives.compare) (list_init n (fun i -> read ())) in\n (numbers, n)\n\nlet solve (numbers, n) = \n let score = score (multiply (count numbers)) in\n score\n\nlet () = print (solve (input ()))"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\n\nlet n = bscanf Scanning.stdin \"%d \" (fun x -> x);;\n\nlet nn = 100000 + 2;;\nlet count = Array.make nn 0;;\nlet indx = Array.make nn 0;;\nlet score = Array.make nn 0;;\n\nlet p = Array.init n (fun x -> 0);;\n\nfor i=0 to n-1 do\n let f = bscanf Scanning.stdin \"%d \" (fun x -> x) in\n count.(f) <- count.(f) + f\ndone;;\n\nlet l = ref 1;;\n\nfor i=1 to nn-1 do\n if count.(i) > 0 then\n begin\n indx.(!l) <- i;\n l := !l + 1\n end\ndone;;\n\n(* For testing\nfor i=1 to !l-1 do\n printf \"%d %d\\n\" indx.(i) count.(indx.(i));\ndone;;\n*)\n\nscore.(0) <- 0;;\nscore.(1) <- count.(indx.(1));;\nfor i=2 to !l-1 do\n let x1 = indx.(i-1) in\n let x2 = indx.(i) in\n if x2 > x1 + 1 then\n begin\n score.(i)<-score.(i+1)+count.(x2)\n end\n else\n begin\n let tscore = score.(i-2) + count.(x2) in\n if tscore > score.(i-1) then\n score.(i) <- tscore\n else\n score.(i) <- score.(i-1)\n end\ndone;;\n\nprint_int score.(!l-1); print_endline \"\";;\n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\nopen Num;;\n\nlet n = bscanf Scanning.stdin \"%d \" (fun x -> x);;\n\nlet nn = 100000 + 2;;\nlet count = Array.make nn 0;;\nlet indx = Array.make nn 0;;\nlet score = Array.make nn (num_of_int 0);;\n\nlet p = Array.init n (fun x -> 0);;\n\nfor i=0 to n-1 do\n let f = bscanf Scanning.stdin \"%d \" (fun x -> x) in\n count.(f) <- count.(f) + f\ndone;;\n\nlet l = ref 1;;\n\nfor i=1 to nn-1 do\n if count.(i) > 0 then\n begin\n indx.(!l) <- i;\n l := !l + 1\n end\ndone;;\n\n(*For testing\nfor i=1 to !l-1 do\n printf \"%d %d\\n\" indx.(i) count.(indx.(i));\ndone;;*)\n\nscore.(0) <- num_of_int 0;;\nscore.(1) <- num_of_int count.(indx.(1));;\nlet cur_indx = ref indx.(1) in\nfor i=2 to !l-1 do\n let x1 = !cur_indx in\n let x2 = indx.(i) in\n if x2 > x1 + 1 then\n begin\n score.(i)<-score.(i-1)+/ (num_of_int count.(x2));\n cur_indx := indx.(i)\n end\n else\n begin\n let tscore = score.(i-2) +/ num_of_int (count.(x2)) in\n if tscore >/ score.(i-1) then\n begin\n score.(i) <- tscore;\n cur_indx := x2\n end\n else\n begin\n score.(i) <- score.(i-1);\n cur_indx := indx.(i-1)\n end\n end\ndone;;\n\nprint_endline (string_of_num (score.(!l-1)));; \n\n"}, {"source_code": "open Scanf;;\nopen String;;\nopen Printf;;\n\nlet n = bscanf Scanning.stdin \"%d \" (fun x -> x);;\n\nlet nn = 100000 + 2;;\nlet count = Array.make nn 0;;\nlet indx = Array.make nn 0;;\nlet score = Array.make nn 0;;\n\nlet p = Array.init n (fun x -> 0);;\n\nfor i=0 to n-1 do\n let f = bscanf Scanning.stdin \"%d \" (fun x -> x) in\n count.(f) <- count.(f) + f\ndone;;\n\nlet l = ref 1;;\n\nfor i=1 to nn-1 do\n if count.(i) > 0 then\n begin\n indx.(!l) <- i;\n l := !l + 1\n end\ndone;;\n\n(*For testing\nfor i=1 to !l-1 do\n printf \"%d %d\\n\" indx.(i) count.(indx.(i));\ndone;;*)\n\nscore.(0) <- 0;;\nscore.(1) <- count.(indx.(1));;\nlet cur_indx = ref indx.(1) in\nfor i=2 to !l-1 do\n let x1 = !cur_indx in\n let x2 = indx.(i) in\n if x2 > x1 + 1 then\n begin\n score.(i)<-score.(i-1)+count.(x2);\n cur_indx := indx.(i)\n end\n else\n begin\n let tscore = score.(i-2) + count.(x2) in\n if tscore > score.(i-1) then\n begin\n score.(i) <- tscore;\n cur_indx := x2\n end\n else\n begin\n score.(i) <- score.(i-1);\n cur_indx := indx.(i-1)\n end\n end\ndone;;\n\nprint_int score.(!l-1); print_endline \"\";;\n\n"}], "src_uid": "41b3e726b8146dc733244ee8415383c0"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let data = Array.init n (fun i ->\n if i = 0 then read_int () mod 2\n else read_int ()\n )\n in\n let possible = ref \"YES\" in\n let reminder = ref 0 in\n for i = 0 to n - 1 do\n let r = data.(i) - !reminder in\n if r < 0 || i = n - 1 && r mod 2 != 0\n then possible := \"NO\"\n else reminder := r mod 2\n done;\n print_endline !possible\n", "positive_code": [{"source_code": "\nlet read_nums () = \n let s = read_line () in\n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n nums\n\n;;\n\nlet rec is_possible lst =\n match lst with\n | [] -> true\n | [a] -> (a mod 2 = 0)\n | a :: b :: tl -> if a < 0 then\n false\n else if a mod 2 = 0 then\n is_possible (b::tl)\n else\n is_possible ((b-1)::tl)\n;;\n\nlet main () =\n let _n = read_int () in\n let lst = read_nums () in\n if is_possible lst then\n print_string \"YES\\n\"\n else\n print_string \"NO\\n\"\n;;\n\nmain () ;;\n\n\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 data = Array.init n (fun i ->\n if i = 0 then read_int () mod 2\n else read_int ()\n )\n in\n let possible = ref \"YES\" in\n let init = data.(0) in\n let reminder = ref init in\n for i = 1 to n - 1 do\n let r = data.(i) - !reminder in\n if r < 0 || i = n - 1 && data.(i) mod 2 != 0\n then possible := \"NO\"\n else reminder := data.(i) mod 2\n done;\n print_endline !possible\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let data = Array.init n (fun i ->\n if i = 0 then read_int () mod 2\n else read_int ()\n )\n in\n let possible = ref \"YES\" in\n let init = data.(0) in\n let reminder = ref init in\n for i = 1 to n - 1 do\n let r = data.(i) - !reminder in\n if r < 0 || i = n - 1 && data.(i) != 0\n then possible := \"NO\"\n else reminder := data.(i) mod 2\n done;\n print_endline !possible\n"}], "src_uid": "97697eba87bd21ae5c979a5ea7a81cb7"} {"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))\n \nlet () = \n let (n,m) = read_pair () in\n\n let g = Array.make n [] in\n\n let add_edge u v =\n g.(u) <- v::g.(u);\n g.(v) <- u::g.(v)\n in\n\n for i=1 to m do\n let (u,v) = read_pair() in\n add_edge (u-1) (v-1)\n done;\n\n let color = Array.make n 0 in\n let bipartite = ref true in\n let visited = Array.make n false in\n \n let rec dfs u c =\n if visited.(u) then (\n if color.(u) <> c then bipartite := false\n ) else (\n visited.(u) <- true;\n color.(u) <- c;\n List.iter (fun v ->\n\tdfs v (1-c)\n ) g.(u)\n )\n in\n\n for u=0 to n-1 do\n if not visited.(u) then dfs u 0\n done;\n\n let color1 = sum 0 (n-1) (fun u -> color.(u)) in\n let color0 = n-color1 in\n\n if !bipartite then (\n \n printf \"%d\\n\" color0;\n for i=0 to n-1 do\n if color.(i) = 0 then printf \"%d \" (i+1)\n done;\n print_newline();\n \n printf \"%d\\n\" color1;\n for i=0 to n-1 do\n if color.(i) = 1 then printf \"%d \" (i+1)\n done;\n print_newline()\n ) else (\n printf \"-1\\n\"\n )\n \n", "positive_code": [{"source_code": "exception GameOver\n\ntype owner = Nobody | Pari | Arya\n\nlet () =\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [n; m] -> (\n let adj = Array.make n [] in\n for i = 1 to m do\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [u; v] ->\n let u = u-1\n and v = v-1 in\n adj.(u) <- v :: adj.(u);\n adj.(v) <- u :: adj.(v)\n | _ -> assert false\n done;\n \n let own = Array.make n Nobody in\n let rec give who v =\n let other =\n match who with\n | Pari -> Arya\n | Arya -> Pari\n | Nobody -> assert false\n in\n if own.(v) == Nobody then (\n own.(v) <- who;\n List.iter (give other) adj.(v)\n )\n else if own.(v) == other then (\n raise GameOver\n )\n and print who =\n print_int (Array.fold_left (fun count x -> if x == who then count + 1 else count) 0 own);\n print_newline ();\n for i = 0 to n - 1 do\n if own.(i) == who then (\n print_int (i+1);\n print_char ' ';\n )\n done;\n print_newline ();\n in\n try\n for v = 0 to n - 1 do\n if own.(v) == Nobody then\n give Pari v;\n done;\n print Pari;\n print Arya\n with\n GameOver -> print_endline \"-1\"\n )\n | _ -> assert false\n"}], "negative_code": [{"source_code": "exception GameOver\n\ntype owner = Nobody | Pari | Arya\n\nlet () =\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [n; m] -> (\n let adj = Array.make n [] in\n for i = 1 to m do\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [u; v] ->\n let u = u-1\n and v = v-1 in\n adj.(u) <- v :: adj.(u);\n adj.(v) <- u :: adj.(v)\n | _ -> assert false\n done;\n \n let own = Array.make n Nobody in\n let rec give who v =\n let other =\n match who with\n | Pari -> Arya\n | Arya -> Pari\n | Nobody -> assert false\n in\n if own.(v) == Nobody then (\n own.(v) <- who;\n List.iter (give other) adj.(v)\n )\n else if own.(v) == other then (\n raise GameOver\n )\n and print who =\n print_int (Array.fold_left (fun count x -> if x == who then count + 1 else count) 0 own);\n print_newline ();\n for i = 0 to n - 1 do\n if own.(i) == who then (\n print_int (i+1);\n print_char ' ';\n )\n done;\n print_newline ();\n in\n try\n give Pari 0;\n print Pari;\n print Arya\n with\n | GameOver -> print_endline \"-1\"\n )\n | _ -> assert false\n"}], "src_uid": "810f267655da0ad14538c275fd13821d"} {"source_code": "open Big_int;;\n\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 t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n for ca = 1 to t do\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let p =\n\tlet p = ref 0 in\n\tlet n = ref n in\n\t while !n > 1 do\n\t incr p;\n\t n := !n / 2;\n\t done;\n\t !p\n in\n let nn = big_int_of_int n in\n let res = nn *| (nn +| n1) /| n2 in\n let res = res -| power_int_positive_int 2 (p + 2) +| n2 in\n\tPrintf.printf \"%s\\n\" (string_of_big_int res)\n done\n"}], "negative_code": [{"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = n*(n+1)/2 - (potegi 0 1 n);;\nlet rec licz n =\nif n > 0 then licz (n-1)\nelse Printf.printf \"\\n\";\nPrintf.printf \"%d\\n\" ( Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik );;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = n*(n+1)/2 - (potegi 0 1 n);;\nlet rec licz n =\nif n = 0 then Printf.printf \"\\n\"\nelse \nPrintf.printf \"%d\\n\" ( Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik ); licz(n-1);;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = Printf.printf \"%d\\n\" ( n*(n+1)/2 - (potegi 0 1 n) );;\n\nlet rec licz n a =\nif n = 1 then a\nelse licz (n-1) ( wynik ( read_int () ) );;\n\nlet funkcja x = licz x (Printf.printf \"\");;\n\nlet test x = licz 0 (Printf.printf \" 5\");;\n\n funkcja ( read_int () );;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = Printf.printf \"%d\\n\" ( n*(n+1)/2 - (potegi 0 1 n) );;\n\nlet rec licz n a =\nif n = 0 then a\nelse licz (n-1)\n(Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik );;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = n*(n+1)/2 - (potegi 0 1 n);;\n\nPrintf.printf \"%d\" ( Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik );;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = Printf.printf \"%d\\n\" ( n*(n+1)/2 - (potegi 0 1 n) );;\n\nlet rec licz n a =\nif n = 0 then a\nelse licz (n-1)\n(Scanf.bscanf Scanf.Scanning.stdin \"%d\\n\" wynik );;\n\nlet funkcja x = licz x (Printf.printf \"\");;\n\nlet test x = licz 0 (Printf.printf \" 5\");;\n\n test ( read_int () );;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = Printf.printf \"%d\\n\" ( n*(n+1)/2 - (potegi 0 1 n) );;\n\nlet rec licz n a =\nif n = 0 then a\nelse licz (n-1)\n(Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik );;\n\nlet funkcja x = licz x (Printf.printf \"\");;\n\nScanf.bscanf Scanf.Scanning.stdin \"%d\" licz;;"}, {"source_code": "let rec potegi a x n = \nif n < x then a\nelse potegi (a+x) (2*x) n;;\n\nlet wynik n = Printf.printf \"%d\\n\" ( n*(n+1)/2 - (potegi 0 1 n) );;\n\nlet rec licz n a =\nif n <= 0 then a\nelse licz (n-1)\n(Scanf.bscanf Scanf.Scanning.stdin \"%d\" wynik );;\n\nlet funkcja x = licz x (Printf.printf \"5\");;\n\nlet test x = licz 0 (Printf.printf \" 5\");;\n\nScanf.bscanf Scanf.Scanning.stdin \"%d\" test;;"}], "src_uid": "a3705f29b9a8be97a9e9e54b6eccba09"} {"source_code": "(* this is customized splay tree code for storing a set of disjoint intervals *)\n\ntype tree = Empty \n | Node of tree * (int * int) * tree * (int * int)\n(* left item right (total length * depth *)\ntype direction = Left | Right\ntype path = Item of tree * direction\n \nlet size tree = match tree with Empty -> 0 | Node(_, _, _, (size,_)) -> size\nlet depth tree = match tree with Empty -> 0 | Node(_, _, _, (_,depth)) -> depth\n\nlet getroot = function \n | Node(left, k, right, _) -> (left, k, right)\n | _ -> failwith \"called getroot on Empty\"\n\nlet newNode (l, (lo,hi), r) = Node(l, (lo,hi), r, \n\t\t\t\t ((size l) + (size r) + (hi-lo+1),\n\t\t\t\t 1 + max (depth l) (depth r)))\n\nlet splay t p = \n (* The following splay function takes as input the currently splayed\n tree (so far) t, and a path list. It takes two steps up, and calls\n itself recursively. *)\n let rec rsplay = function\n | (t,[]) -> t\n | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::(Item(Node(_, cK, cR, _), Left)::tail)) ->\n\trsplay (newNode(tL,tK,newNode(tR,bK,newNode(bR,cK,cR))), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::(Item(Node(cL, cK,_,_), Right)::tail)) ->\n rsplay (newNode(newNode(newNode(cL,cK,bL), bK, tL),tK,tR), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::tail) ->\n\trsplay (newNode(tL,tK,newNode(tR,bK,bR)), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::tail) ->\n\trsplay (newNode(newNode(bL,bK,tL),tK,tR), tail)\n\t \n | (_,_) -> failwith \"Splay_failed (Should not happen)\"\n in\n\n let rec build_path t path = \n match t with \n | Empty -> failwith \"failed build_path\"\n | Node(left, (lo,hi), right, _) ->\n\t if p < lo && left<>Empty then build_path left (Item(t, Left)::path)\n\t else if p > hi && right<>Empty then build_path right (Item(t, Right)::path)\n\t else (t,path)\n in\n\n if t=Empty then Empty else\n rsplay (build_path t [])\n\nlet splaydeep t = \n let rec find_deepest = function\n | Node(Empty, (lo,_), Empty, _) -> lo\n | Node(left, _, right, _) ->\n\tfind_deepest (if depth left >= depth right then left else right)\n | Empty -> failwith \"find_deepest called with Empty\"\n\t\n in\n if t=Empty then t else splay t (find_deepest t)\n\nlet split_l t l = \n (* split the list of segments in two. Find the leftmost segment\n whose left endpoint is >= l. That is the right part of my split. *)\n if t=Empty then (Empty,Empty) else\n let (left, (lo,hi), right) = getroot (splay t l) in\n let put_on_left = \n if lo <= l && l <= hi then lo < l\n else if l < lo then false else true\n in\n if put_on_left \n then (newNode(left, (lo,hi), Empty), right)\n else (left, newNode(Empty,(lo,hi),right)) \n\nlet split_r t r = \n (* split the list of segments in two. Find the rightmost segment\n whose right endpoint is <= r. That is the left part of my split. *)\n if t=Empty then (Empty,Empty) else\n let (left, (lo,hi), right) = getroot (splay t r) in\n let put_on_left = \n if lo <= r && r <= hi then r = hi\n else if r < lo then false else true\n in\n if put_on_left \n then (newNode(left, (lo,hi), Empty), right)\n else (left, newNode(Empty,(lo,hi),right)) \n\t\nlet insert t (l,r) =\n (* Insert a new interval that is either contained in,\n is disjoint from, or fully contains some other intervals *)\n if t=Empty then newNode (Empty,(l,r),Empty) else\n let t = splay t l in\n let (left, (lo,hi), right) = getroot t in\n if lo <= l && r <= hi then t else (* new interval contained *)\n\tlet (s1,s23) = split_l t l in\n\tlet (s2,s3) = split_r s23 r in\n\t newNode(s1,(l,r),s3)\n\n\n(**************************************************************************)\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int()-1 in (u, read_int()-1)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n let edges = Array.make n [] in\n let () = for i=0 to n-2 do\n let (u,v) = read_pair() in\n edges.(u) <- v::edges.(u);\n edges.(v) <- u::edges.(v)\n done in\n let update = Array.make n [] in\n let () = for i=0 to m-1 do\n let (u,v) = read_pair() in\n update.(u) <- v::update.(u);\n update.(v) <- u::update.(v)\n done in\n\n let pre = Array.make n (-1) in\n\n let rec dfspre c u = if pre.(u) >= 0 then c else (\n pre.(u) <- c;\n List.fold_left dfspre (c+1) edges.(u)\n ) in\n\n let _ = dfspre 0 0 in\n\n let () = for i=0 to n-1 do\n edges.(i) <- List.filter (fun e -> pre.(e) > pre.(i)) edges.(i)\n (* Edge from parent to child increases pre.()\n\t keep edges from parent to child *)\n done in\n\n let mpre = Array.make n (-1) in (* max preorder number in the subtree rooted here *)\n\n let rec dfsmpre c u = \n let c = List.fold_left dfsmpre c edges.(u) in\n mpre.(u) <- max c pre.(u);\n mpre.(u)\n in\n\n let _ = dfsmpre 0 0 in\n\n let count = Array.make n 0 in (* our answer *)\n\n let rec solve u t = (* u is a node, t is a tree of intervals inherited from the parent of u *)\n let nt = if update.(u) = [] then t else insert t (pre.(u), mpre.(u)) in\n let nt = List.fold_left (\n fun t v -> insert t (pre.(v), mpre.(v))\n ) nt update.(u)\n in\n\n let rec logint i ac = if i=0 then ac else logint (i/2) (1::ac) in\n let nt = List.fold_left (fun t _ -> splaydeep t) nt (logint (List.length edges.(u)) []) in\n\n(* let nt = List.fold_left (fun t _ -> splaydeep t) nt edges.(u) in *)\n List.iter (fun v -> solve v nt) edges.(u);\n count.(u) <- size nt;\n in\n\n solve 0 Empty;\n \n for i=0 to n-1 do\n Printf.printf \"%d \" (if count.(i)>0 then count.(i)-1 else 0)\n done;\n print_newline()\n", "positive_code": [{"source_code": "(* this is customized splay tree code for storing a set of disjoint intervals *)\n\ntype tree = Empty \n | Node of tree * (int * int) * tree * (int * int)\n(* left item right (total length * depth *)\ntype direction = Left | Right\ntype path = Item of tree * direction\n \nlet size tree = match tree with Empty -> 0 | Node(_, _, _, (size,_)) -> size\nlet depth tree = match tree with Empty -> 0 | Node(_, _, _, (_,depth)) -> depth\n\nlet getroot = function \n | Node(left, k, right, _) -> (left, k, right)\n | _ -> failwith \"called getroot on Empty\"\n\nlet newNode (l, (lo,hi), r) = Node(l, (lo,hi), r, \n\t\t\t\t ((size l) + (size r) + (hi-lo+1),\n\t\t\t\t 1 + max (depth l) (depth r)))\n\nlet splay t p = \n (* The following splay function takes as input the currently splayed\n tree (so far) t, and a path list. It takes two steps up, and calls\n itself recursively. *)\n let rec rsplay = function\n | (t,[]) -> t\n | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::(Item(Node(_, cK, cR, _), Left)::tail)) ->\n\trsplay (newNode(tL,tK,newNode(tR,bK,newNode(bR,cK,cR))), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::(Item(Node(cL, cK,_,_), Right)::tail)) ->\n rsplay (newNode(newNode(newNode(cL,cK,bL), bK, tL),tK,tR), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(_, bK, bR,_), Left)::tail) ->\n\trsplay (newNode(tL,tK,newNode(tR,bK,bR)), tail)\n\n | (Node(tL,tK,tR,_), Item(Node(bL, bK, _,_), Right)::tail) ->\n\trsplay (newNode(newNode(bL,bK,tL),tK,tR), tail)\n\t \n | (_,_) -> failwith \"Splay_failed (Should not happen)\"\n in\n\n let rec build_path t path = \n match t with \n | Empty -> failwith \"failed build_path\"\n | Node(left, (lo,hi), right, _) ->\n\t if p < lo && left<>Empty then build_path left (Item(t, Left)::path)\n\t else if p > hi && right<>Empty then build_path right (Item(t, Right)::path)\n\t else (t,path)\n in\n\n if t=Empty then Empty else\n rsplay (build_path t [])\n\nlet splaydeep t = \n let rec find_deepest = function\n | Node(Empty, (lo,_), Empty, _) -> lo\n | Node(left, _, right, _) ->\n\tfind_deepest (if depth left >= depth right then left else right)\n | Empty -> failwith \"find_deepest called with Empty\"\n\t\n in\n if t=Empty then t else splay t (find_deepest t)\n\nlet split_l t l = \n (* split the list of segments in two. Find the leftmost segment\n whose left endpoint is >= l. That is the right part of my split. *)\n if t=Empty then (Empty,Empty) else\n let (left, (lo,hi), right) = getroot (splay t l) in\n let put_on_left = \n if lo <= l && l <= hi then lo < l\n else if l < lo then false else true\n in\n if put_on_left \n then (newNode(left, (lo,hi), Empty), right)\n else (left, newNode(Empty,(lo,hi),right)) \n\nlet split_r t r = \n (* split the list of segments in two. Find the rightmost segment\n whose right endpoint is <= r. That is the left part of my split. *)\n if t=Empty then (Empty,Empty) else\n let (left, (lo,hi), right) = getroot (splay t r) in\n let put_on_left = \n if lo <= r && r <= hi then r = hi\n else if r < lo then false else true\n in\n if put_on_left \n then (newNode(left, (lo,hi), Empty), right)\n else (left, newNode(Empty,(lo,hi),right)) \n\t\nlet insert t (l,r) =\n (* Insert a new interval that is either contained in,\n is disjoint from, or fully contains some other intervals *)\n if t=Empty then newNode (Empty,(l,r),Empty) else\n let t = splay t l in\n let (left, (lo,hi), right) = getroot t in\n if lo <= l && r <= hi then t else (* new interval contained *)\n\tlet (s1,s23) = split_l t l in\n\tlet (s2,s3) = split_r s23 r in\n\t newNode(s1,(l,r),s3)\n\n\n(**************************************************************************)\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int()-1 in (u, read_int()-1)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n let edges = Array.make n [] in\n let () = for i=0 to n-2 do\n let (u,v) = read_pair() in\n edges.(u) <- v::edges.(u);\n edges.(v) <- u::edges.(v)\n done in\n let update = Array.make n [] in\n let () = for i=0 to m-1 do\n let (u,v) = read_pair() in\n update.(u) <- v::update.(u);\n update.(v) <- u::update.(v)\n done in\n\n let pre = Array.make n (-1) in\n\n let rec dfspre c u = if pre.(u) >= 0 then c else (\n pre.(u) <- c;\n List.fold_left dfspre (c+1) edges.(u)\n ) in\n\n let _ = dfspre 0 0 in\n\n let () = for i=0 to n-1 do\n edges.(i) <- List.filter (fun e -> pre.(e) > pre.(i)) edges.(i)\n (* Edge from parent to child increases pre.()\n\t keep edges from parent to child *)\n done in\n\n let mpre = Array.make n (-1) in (* max preorder number in the subtree rooted here *)\n\n let rec dfsmpre c u = \n let c = List.fold_left dfsmpre c edges.(u) in\n mpre.(u) <- max c pre.(u);\n mpre.(u)\n in\n\n let _ = dfsmpre 0 0 in\n\n let count = Array.make n 0 in (* our answer *)\n\n let rec solve u t = (* u is a node, t is a tree of intervals inherited from the parent of u *)\n let nt = if update.(u) = [] then t else insert t (pre.(u), mpre.(u)) in\n let nt = List.fold_left (\n fun t v -> insert t (pre.(v), mpre.(v))\n ) nt update.(u)\n in\n\n(*\n let rec logint i ac = if i=0 then ac else logint (i/2) (1::ac) in\n let nt = List.fold_left (fun t _ -> splaydeep t) nt (logint (List.length edges.(u)) []) in\n*)\n\n let nt = List.fold_left (fun t _ -> splaydeep t) nt edges.(u) in\n List.iter (fun v -> solve v nt) edges.(u);\n count.(u) <- size nt;\n in\n\n solve 0 Empty;\n \n for i=0 to n-1 do\n Printf.printf \"%d \" (if count.(i)>0 then count.(i)-1 else 0)\n done;\n print_newline()\n"}], "negative_code": [], "src_uid": "1cdbf1984e359e48d6675fb4ed4c97c5"} {"source_code": "let s = read_line ();;\nlet sx = List.map int_of_string (Str.split (Str.regexp \" +\") s);;\nlet n = List.hd sx;;\nlet m = List.hd (List.tl sx);;\n\n\nlet a = Array.make n \"\";;\n\nfor i = 0 to (n - 1) do\n\ta.(i) <- read_line ();\ndone;;\n\n\nlet rec proc (e: bool array) = function\n| j when j = m -> 0\n| j ->\n\tlet e' = Array.copy e in\n\t(*print_newline(Array.iter (fun x -> print_string (if x then \"true \" else \"false \")) e);*)\n\tlet rec aux = function\n\t| i when i = n -> proc e' (j+1)\n\t| i ->\n\t\tif (e.(i) && a.(i).[j] < a.(i-1).[j]) then\n\t\t\t1 + proc e (j+1)\n\t\telse\n\t\t\t(e'.(i) <- e'.(i) && a.(i).[j] = a.(i-1).[j];\n\t\t\taux (i+1)) in\n\taux 1;;\n\n\n\n\n\nprint_newline (print_int (proc (Array.make n true) 0));;\n(*print_newline (print_int (Array.fold_left (fun a x -> if x then 0 else 1) 0 e));;*)", "positive_code": [{"source_code": "exception Invalid_input\n\ntype status =\n | Stable\n | Safe\n\nlet (|>) x f = f x\n\nlet rec make_list = fun len f ->\n if len = 0 then\n []\n else\n f () :: make_list (len - 1) f\n\nlet rec prepend_list_to_list_of_list = fun li acc ->\n match li, acc with\n | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)\n | _ -> acc\n\nlet string_to_list = fun s ->\n let len = String.length s in\n let rec do_string_to_list = fun s i ->\n if i < len then\n s.[i] :: do_string_to_list s (i + 1)\n else\n []\n in\n do_string_to_list s 0\n\nlet read_input = fun n m ->\n let rec do_read_input = fun i acc ->\n if i < n then\n let current_line =\n read_line ()\n |> string_to_list\n in\n prepend_list_to_list_of_list current_line acc\n |> do_read_input (i + 1)\n else\n acc\n in\n make_list m (fun () -> [])\n |> do_read_input 0\n\nlet process_one_column = fun status chars ->\n let rec need_to_remove = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n if h1 = Stable && h2 < m2 then\n true\n else\n need_to_remove p1 p2\n | _ ->\n false\n in\n if need_to_remove status chars then\n status, true\n else\n let rec get_new_status = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n let new_s =\n if h1 = Safe || m2 < h2 then\n Safe\n else\n Stable\n in\n new_s :: get_new_status p1 p2\n | hd :: [], _ ->\n [hd]\n | _ ->\n raise Invalid_input\n in\n (get_new_status status chars), false\n\nlet process_all_columns = fun n input ->\n let initial = make_list n (fun () -> Stable) in\n let rec do_process = fun status count input ->\n match input with\n | hd :: tl ->\n let new_status, removed = process_one_column status hd in\n let new_count = if removed then count + 1 else count in\n do_process new_status new_count tl\n | _ ->\n count\n in\n do_process initial 0 input\n\nlet () =\n let (n, m) =\n read_line ()\n |> Str.split (Str.regexp \" +\")\n |> List.map int_of_string\n |> fun li ->\n match li with\n | a :: [b] -> (a, b)\n | _ -> raise Invalid_input\n in\n let input = read_input n m in\n process_all_columns n input\n |> print_int\n |> print_newline\n"}], "negative_code": [{"source_code": "let s = read_line ();;\nlet sx = List.map int_of_string (Str.split (Str.regexp \" +\") s);;\nlet n = List.hd sx;;\nlet m = List.hd (List.tl sx);;\n\n\nlet a = Array.make n \"\";;\n\nfor i = 0 to (n - 1) do\n\ta.(i) <- read_line ();\ndone;;\n\n\nlet rec proc (e: bool array) = function\n| j when j = m -> 0\n| j ->\n\tlet e' = Array.copy e in\n\n\tlet rec aux = function\n\t| i when i = n -> proc e' (j+1)\n\t| i ->\n\t\tif (e.(i) && a.(i).[j] < a.(i-1).[j]) then\n\t\t\t1 + proc e (j+1)\n\t\telse\n\t\t\t(e'.(i) <- a.(i).[j] = a.(i-1).[j];\n\t\t\taux (i+1)) in\n\taux 1;;\n\n\n\n\n\nprint_newline (print_int (proc (Array.make n true) 0));;\n(*print_newline (print_int (Array.fold_left (fun a x -> if x then 0 else 1) 0 e));;*)"}, {"source_code": "exception Invalid_input\n\ntype status =\n | Stable\n | Safe\n\nlet (|>) x f = f x\n\nlet rec make_list = fun len f ->\n if len = 0 then\n []\n else\n f () :: make_list (len - 1) f\n\nlet rec prepend_list_to_list_of_list = fun li acc ->\n match li, acc with\n | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)\n | _ -> acc\n\nlet string_to_list = fun s ->\n let len = String.length s in\n let rec do_string_to_list = fun s i ->\n if i < len then\n s.[i] :: do_string_to_list s (i + 1)\n else\n []\n in\n do_string_to_list s 0\n\nlet read_input = fun n m ->\n let rec do_read_input = fun i acc ->\n if i < n then\n let current_line =\n read_line ()\n |> string_to_list\n in\n prepend_list_to_list_of_list current_line acc\n |> do_read_input (i + 1)\n else\n acc\n in\n make_list m (fun () -> [])\n |> do_read_input 0\n\nlet process_one_column = fun status chars ->\n let rec need_to_remove = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n if h1 = Stable && h2 < m2 then\n true\n else\n need_to_remove p1 p2\n | _ ->\n false\n in\n if need_to_remove status chars then\n status, true\n else\n let rec get_new_status = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n let new_s =\n if h1 = Safe || m2 < h2 then\n Safe\n else\n Stable\n in\n new_s :: get_new_status p1 p2\n | _ ->\n []\n in\n (get_new_status status chars), false\n\nlet process_all_columns = fun n input ->\n let initial = make_list n (fun () -> Stable) in\n let rec do_process = fun status count input ->\n match input with\n | hd :: tl ->\n let new_status, removed = process_one_column status hd in\n let new_count = if removed then count + 1 else count in\n do_process new_status new_count tl\n | _ ->\n count\n in\n do_process initial 0 input\n\nlet () =\n let (n, m) =\n read_line ()\n |> Str.split (Str.regexp \" +\")\n |> List.map int_of_string\n |> fun li ->\n match li with\n | a :: [b] -> (a, b)\n | _ -> raise Invalid_input\n in\n let input = read_input n m in\n process_all_columns n input\n |> print_int\n |> print_newline\n"}, {"source_code": "exception Invalid_input\n\ntype status =\n | Stable\n | Safe\n\nlet (|>) x f = f x\n\nlet rec make_list = fun len f ->\n if len = 0 then\n []\n else\n f () :: make_list (len - 1) f\n\nlet rec prepend_list_to_list_of_list = fun li acc ->\n match li, acc with\n | h1 :: t1, h2 :: t2 -> (h1 :: h2) :: (prepend_list_to_list_of_list t1 t2)\n | _ -> acc\n\nlet string_to_list = fun s ->\n let len = String.length s in\n let rec do_string_to_list = fun s i ->\n if i < len then\n s.[i] :: do_string_to_list s (i + 1)\n else\n []\n in\n do_string_to_list s 0\n\nlet read_input = fun n m ->\n let rec do_read_input = fun i acc ->\n if i < n then\n let current_line =\n read_line ()\n |> string_to_list\n in\n prepend_list_to_list_of_list current_line acc\n |> do_read_input (i + 1)\n else\n acc\n in\n make_list m (fun () -> [])\n |> do_read_input 0\n\nlet process_one_column = fun status chars ->\n let rec need_to_remove = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n if h1 = Stable && h2 < m2 then\n true\n else\n need_to_remove p1 p2\n | _ ->\n false\n in\n if need_to_remove status chars then\n status, true\n else\n let rec get_new_status = fun s_list c_list ->\n match s_list, c_list with\n | h1 :: (m1 :: t1 as p1), h2 :: (m2 :: t2 as p2) ->\n let new_s =\n if h1 = Stable && m2 < h2 then\n Safe\n else\n Stable\n in\n new_s :: get_new_status p1 p2\n | _ ->\n []\n in\n (get_new_status status chars), false\n\nlet process_all_columns = fun n input ->\n let initial = make_list n (fun () -> Stable) in\n let rec do_process = fun status count input ->\n match input with\n | hd :: tl ->\n let new_status, removed = process_one_column status hd in\n let new_count = if removed then count + 1 else count in\n do_process new_status new_count tl\n | _ ->\n count\n in\n do_process initial 0 input\n\nlet () =\n let (n, m) =\n read_line ()\n |> Str.split (Str.regexp \" +\")\n |> List.map int_of_string\n |> fun li ->\n match li with\n | a :: [b] -> (a, b)\n | _ -> raise Invalid_input\n in\n let input = read_input n m in\n process_all_columns n input\n |> print_int\n |> print_newline\n"}], "src_uid": "a45cfc2855f82f162133930d9834a9f0"} {"source_code": "(* Codeforces 492B VaniaFonari *)\n\nopen List;;\nopen String;;\nopen Array;;\nopen Int64;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line Pervasives.stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string \" \")) ai;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n - 1) (gr() :: acc);;\n\nlet miscomp a b = a - b;;\n\nlet rec maxdif dif l = match l with \n| a :: b :: tl -> \n\tlet d = b - a in\n\tlet dd = if d>dif then d else dif in\n\tmaxdif dd (b :: tl)\t\t\t\t\t\t\t\t\n| _ -> dif;;\n\nlet main () = \n\tlet n = gr () in\n\tlet l = gr () in\n\tlet aal : int list = readlist n [] in\n\tlet aso : int list = List.sort miscomp (l :: aal) in\n\tlet d0 = maxdif 0 (0 :: aso) in\n\tlet f0 = ((float_of_int d0) /. 2.0) in \n\tlet d1 = float_of_int (List.nth aso 0) in\n\tlet d2 = float_of_int (l - (List.nth aso (n-1))) in\n\tlet d = max f0 (max d1 d2) in\n\tbegin\n\t print_float d\n\tend;;\n\nmain();;\n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let length = float (read ()) in\n let rec loop list i =\n if i < n\n then\n let var = float (read ()) in\n loop (var :: list) (i + 1)\n else\n (length, list)\n in loop [] 0\n\nlet get_max head prev max = \n if prev = float (-1)\n then\n Pervasives.max head max\n else\n Pervasives.max ((head -. prev) /. (float 2)) max\n\nlet solve (length, list) =\n let lampposts = List.sort (Pervasives.compare) list in \n let d_start = 0.0 -. List.hd lampposts in\n let d_end = length -. List.hd (List.rev lampposts) in\n let d_min = Pervasives.max d_start d_end in\n\n let rec loop rest prev max = \n match rest with\n | (head :: tail) -> loop tail head (get_max head prev max)\n | [] -> Pervasives.max d_min max\n in loop lampposts (float (-1)) (float 0)\n\nlet print result = Printf.printf \"%.10f\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "(* Codeforces 349 A Cinema Line 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);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet rec minrad l d len = match l with\n| [] -> d\n| h :: [] -> max d (float_of_int (len - h))\n| h :: t ->\n\tlet dd = (float_of_int ((List.hd t) - h)) /. 2.0 in\n\tlet dd = max dd d in\n\tminrad t dd len;;\n\nlet main() =\n\tlet n = gr() in\n\tlet len = gr() in\n\tlet ll = readlist n [] in\n\tlet li = List.rev ll in\n\tlet sol = List.sort_uniq compare li in\n\tlet dinit = float_of_int (List.hd sol) in\n\tlet rad = minrad sol dinit len in\n\tbegin\n\t\tPrintf.printf \"%.2f\\n\" rad\n\tend;;\n\nmain();;"}, {"source_code": "open Str\n\nlet print_tuple = fun tuple ->\n let (x, y) = tuple in\n Printf.printf \"%d %d\\n\" x y\n\nlet rec print_list = fun l ->\n match l with\n | hd :: tl ->\n print_int hd;\n print_char ' ';\n print_list tl;\n | _ -> ()\n\nlet rec find_max_gap = fun l cur_max ->\n match l with\n | hd :: mid :: tl ->\n let diff = mid - hd in\n if diff < cur_max then\n find_max_gap (mid :: tl) cur_max\n else\n find_max_gap (mid :: tl) diff\n | _ -> cur_max\n\nlet rec get_last = fun l ->\n match l with\n | [x] ->\n Some x\n | _ :: tl ->\n get_last tl\n | _ -> None\n\nexception Invalid_input\n\nlet find_max_gap_including_head_and_tail = fun l e ->\n match get_last l with\n | Some last ->\n List.hd (List.fast_sort (fun i j ->\n if i < j then\n 1\n else\n -1\n ) ([(float_of_int (List.hd l)); (float_of_int (e - last)); (float_of_int (find_max_gap l 0)) /. 2.0])\n )\n | None -> raise Invalid_input\n\nlet () =\n let (num_of_lanterns, len_of_street) = (fun line ->\n match line with\n | hd :: tl -> (int_of_string hd, int_of_string (List.hd tl))\n | _ -> raise Invalid_input\n ) (Str.split (Str.regexp \" +\") (read_line ()))\n in\n let lanterns = List.fast_sort (fun i j ->\n i - j\n ) (List.map int_of_string (Str.split (Str.regexp \" +\") (read_line ())))\n in\n print_float (find_max_gap_including_head_and_tail lanterns len_of_street);\n print_newline ()\n"}], "negative_code": [{"source_code": "(* Codeforces 492B VaniaFonari *)\n\nopen List;;\nopen String;;\nopen Array;;\nopen Int64;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet rdln() = input_line Pervasives.stdin;;\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\nlet printarri64 ai = Array.iter (fun i -> (print_string (Int64.to_string i); print_string \" \")) ai;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n - 1) (gr() :: acc);;\n\nlet miscomp a b = a - b;;\n\nlet rec maxdif dif l = match l with \n| a :: b :: tl -> \n\tlet d = b - a in\n\tlet dd = if d>dif then d else dif in\n\tmaxdif dd (b :: tl)\t\t\t\t\t\t\t\t\n| _ -> dif;;\n\nlet main () = \n\tlet n = gr () in\n\tlet l = gr () in\n\tlet aal : int list = readlist n [] in\n\tlet aso : int list = List.sort miscomp (l :: aal) in\n\tlet df = maxdif 0 (0 :: aso) in\n\tbegin\n\t print_float ((float_of_int df) /. 2.0)\n\tend;;\n\nmain();;\n"}], "src_uid": "d79166497eb61d81fdfa4ef80ec1c8e8"} {"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 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 md = 998244353L\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n if s.[0] = s.[n-$1] then (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = i64 !c mod md in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = i64 !c mod md in\n printf \"%Ld\\n\" @@ (((p+1L)*(q+1L)) mod md);\n ) else (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\\n\" !c; *)\n let p = i64 !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\\n\" !c; *)\n let q = i64 !c in\n printf \"%Ld\\n\" @@ ((p+1L)+(q+1L)-1L) mod md;\n )\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let rec fix f x = f (fix f) x\nlet i64,i32 = Int64.(of_int,to_int)\nlet md = 998244353L\nlet ( **% ) p q = Int64.(rem (mul p q) md);;\nScanf.(Array.(\n let n = scanf \" %d\" @@ fun v -> v in\n let s = scanf \" %s\" @@ fun v -> v in\n let p = fix (fun f i a ->\n if s.[i] = s.[0] then f (i+1) (i::a)\n else a\n ) 0 [] |> List.length in\n let q = fix (fun f i a ->\n if s.[i] = s.[n-1] then f (i-1) (i::a)\n else a\n ) (n-1) [] |> List.length in\n if s.[0] = s.[n-1] then (\n print_int @@ i32 @@ (i64 @@ p+1) **% (i64 @@ q+1)\n ) else (\n print_int @@ i32 @@ (i64 ((p+1) + (q+1) - 1) **% 1L)\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 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 md = 998244353\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n if s.[0] = s.[n-$1] then (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c %$ md in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c %$ md in\n printf \"%d\\n\" @@ (((p+$1)*$(q+$1)) %$ md);\n ) else (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\\n\" @@ ((p+$1)+$(q+$1)-$1) %$ md;\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 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 md = 998244353\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n if s.[0] = s.[n-$1] then (\n (* let f,c = ref true,ref s.[0] in\n repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);\n if !f then (\n fail 0\n ) else (\n\n ) *)\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\" @@ (((p+$1) %$ md)*$((q+$1) %$ md) %$ md);\n ) else (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\\n\" @@ (p+$q+$1) %$ md;\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 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\nlet allsame s =\n let f = ref true in\n String.iter (fun v -> if v <> s.[0] then f := false) s; !f\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n let c = ref 0L in\n repi 0 (n) (fun i ->\n repi i (n) (fun j ->\n let p = String.sub s 0 i in\n let q = String.sub s j (n-$j) in\n let f = allsame @@ p ^ q in\n if f then\n printf \"%s ^ %s = %s :: %b\\n\"\n p q (p^q) f\n ;\n if f then c+=1L\n )\n ); printf \"%Ld\\n\" !c\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let slen s = String.length s\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n if s.[0] = s.[n-$1] then (\n (* let f,c = ref true,ref s.[0] in\n repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);\n if !f then (\n fail 0\n ) else (\n\n ) *)\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\" @@ p*$q;\n ) else (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\\n\" @@ p+$q+$1;\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let slen s = String.length s\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in let n = i32 n in\n let s = scanf \" %s\" @@ id in\n if s.[0] = s.[n-$1] then (\n (* let f,c = ref true,ref s.[0] in\n repi 0 (n-$1) (fun i -> f := !f && !c = s.[i]);\n if !f then (\n fail 0\n ) else (\n\n ) *)\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\" @@ (p+$1)*$(q+$1);\n ) else (\n let f,c = ref true,ref 0 in\n repi 0 (n-$1) (fun i ->\n if !f && s.[i] = s.[0] then (\n c := i+$1\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let p = !c in\n let f,c = ref true,ref 0 in\n repi_rev (n-$1) 0 (fun i ->\n if !f && s.[i] = s.[n-$1] then (\n c := n-$i\n ) else f := false;\n );\n (* printf \"%d\" !c; *)\n let q = !c in\n printf \"%d\\n\" @@ p+$q+$1;\n )\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "9693f60fc65065d00a1899df999405fe"} {"source_code": "open Big_int\n\nlet rec yolo now = function\n\t|t::q\t-> Big_int.add_big_int (Big_int.abs_big_int (Big_int.sub_big_int now t)) (yolo t q)\n\t| []\t-> Big_int.big_int_of_int 0\n\nlet main () =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and l = ref [] in\n\t\tfor j=1 to n do\n\t\t\tScanf.scanf \" %d\" (fun i -> l := (Big_int.big_int_of_int i):: !l);\n\t\tdone;\n\tPrintf.printf \"%s\" (Big_int.string_of_big_int (yolo (Big_int.big_int_of_int 0) (List.rev !l)));;\n\nmain ();;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\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) 0L\n\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n\n let b = Array.init n (fun _ -> long (read_int())) in\n\n let rec loop i running_total total_ops =\n if i=n then total_ops else (\n let x = running_total -- b.(i) in\n let total_ops = total_ops ++ (Int64.abs x) in\n let running_total = running_total -- x in\n loop (i+1) running_total total_ops\n )\n in\n\n let answer = loop 0 0L 0L in\n\n printf \"%Ld\\n\" answer\n"}, {"source_code": "let n = read_int ();;\nlet a = Array.of_list (List.map (Int64.of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nlet x = ref 0L and ans = ref 0L;;\nfor i = 0 to n - 1 do\n\tans :=\n\t\tInt64.add !ans (Int64.abs (Int64.sub !x a.(i)));\n\t\tx := a.(i);\ndone;;\nprint_string (Int64.to_string !ans);;\n"}], "negative_code": [], "src_uid": "97a226f47973fcb39c40e16f66654b5f"} {"source_code": "open Printf\nopen Scanf\n\n(* Implementation of Dinic's algorithm for max flow. See ../spoj/PROFIT/\n for additional algorithms. *)\n\nlet infinite_c = 10000 (* \"infinite\" capacity *)\n\nlet maxflow s t adj cap =\n (* s and t are nodes (numbers). g is a graph (represented via an\n array of adjacency lists). c is a 1-d array of capacities. The\n adjacency list on node v stores pairs like (w,i) where w is the\n other node, and i is the index into the capacity array for where\n this capacity is stored. It's set up so that i lxor 1 is where the\n capacity of edge (w,v) is stored. We compute the maximum flow in\n the same representation as the capacities. *)\n\n let c = Array.copy cap in\n let n = Array.length adj in\n let alive = Array.make n [] in\n let level = Array.make n 0 in\n let queue = Array.make n 0 in\n let front = ref 0 in\n let back = ref 0 in\n\n let push w = queue.(!back) <- w; back := !back+1 in\n let eject() = let x = queue.(!front) in front := !front + 1; x; in\n\n let rec bfs () = \n let rec loop () = \n if !front = !back then false else\n\tlet v = eject() in\n\t if level.(v) = level.(t) then true else (\n\t List.iter ( \n\t fun (w,i) -> if level.(w) < 0 && c.(i) > 0 then (\n\t\tlevel.(w) <- level.(v) + 1;\n\t\tpush w\n\t )\n\t ) adj.(v);\n\t loop ()\n\t )\n in\n level.(s) <- 0;\n back := 0; front := 0;\n push s;\n loop ();\n in\n \n let rec dfs v cap = \n (* Does a DFS from v looking for a path to t. It tries to push cap units\n of flow to t. It returns the amount of flow actually pushed *)\n if v=t then cap else\n let rec loop total remaining li = \n\t match li with \n\t | [] -> \n\t\talive.(v) <- [];\n\t\ttotal\n\t | (w,i)::tail -> \n\t\tif level.(w) = level.(v)+1 && c.(i) > 0 then (\n\t\t let p = dfs w (min c.(i) remaining) in\n\t\t c.(i) <- c.(i) - p;\n\t\t c.(i lxor 1) <- c.(i lxor 1) + p;\n\t\t if remaining-p = 0 then (\n\t\t alive.(v) <- li;\n\t\t total+p\n\t\t ) else loop (total+p) (remaining-p) tail\n\t\t) else loop total remaining tail\n in loop 0 cap alive.(v)\n in\n \n let rec main_loop flow_so_far = \n for i=0 to n-1 do level.(i) <- -1; done;\n Array.blit adj 0 alive 0 n;\n if bfs () then main_loop (flow_so_far + (dfs s infinite_c)) else flow_so_far\n in\n main_loop 0\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nlet () = \n let n = read_int () in\n let m = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let pair = Array.init m (fun _ ->\n let i = read_int() -1 in\n let j = read_int() -1 in\n if i land 1 = 0 then (i,j) else (j,i)\n ) in\n\n let fact = Array.init n (fun i -> factor a.(i)) in\n \n let primeset = Hashtbl.create 10 in (* the set of primes that occur *)\n for i=0 to n-1 do\n List.iter (fun p -> Hashtbl.replace primeset p true) fact.(i)\n done;\n\n let build_graph p = \n (* build the graph for a specific prime p *)\n let s = n in\n let t = n+1 in\n let adj = Array.make (n+2) [] in\n let cap = Array.make (2*m + 2*n) 0 in\n\n let add_edge u v c cr ind indr =\n adj.(u) <- (v,ind)::adj.(u);\n adj.(v) <- (u,indr)::adj.(v);\n cap.(ind) <- c;\n cap.(indr) <- cr\n in\n\n for k = 0 to m-1 do\n let (i,j) = pair.(k) in\n add_edge i j infinite_c 0 (2*k) (2*k+1)\n done;\n\n for v = 0 to n-1 do\n let capacity = List.length (List.filter (fun e -> e = p) fact.(v)) in\n let edgeno = 2*m + 2*v in\n if v land 1 = 0 then (\n\tadd_edge s v capacity 0 edgeno (edgeno+1);\n ) else (\n\tadd_edge v t capacity 0 edgeno (edgeno+1);\n )\n done;\n (s,t,adj,cap)\n in\n\n let flowsum = ref 0 in\n \n Hashtbl.iter (fun p _ -> \n let (s,t,adj,cap) = build_graph p in\n let f = maxflow s t adj cap in\n flowsum := !flowsum + f\n ) primeset;\n\n printf \"%d\\n\" !flowsum\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\n(* Implementation of Dinic's algorithm for max flow. See ../spoj/PROFIT/\n for additional algorithms. *)\n\nlet infinite_c = 10000 (* \"infinite\" capacity *)\n\nlet maxflow s t adj cap =\n (* s and t are nodes (numbers). g is a graph (represented via an\n array of adjacency lists). c is a 1-d array of capacities. The\n adjacency list on node v stores pairs like (w,i) where w is the\n other node, and i is the index into the capacity array for where\n this capacity is stored. It's set up so that i lxor 1 is where the\n capacity of edge (w,v) is stored. We compute the maximum flow in\n the same representation as the capacities. *)\n\n let c = Array.copy cap in\n let n = Array.length adj in\n let alive = Array.make n [] in\n let level = Array.make n 0 in\n let queue = Array.make n 0 in\n let front = ref 0 in\n let back = ref 0 in\n\n let push w = queue.(!back) <- w; back := !back+1 in\n let eject() = let x = queue.(!front) in front := !front + 1; x; in\n\n let rec bfs () = \n let rec loop () = \n if !front = !back then false else\n\tlet v = eject() in\n\t if level.(v) = level.(t) then true else (\n\t List.iter ( \n\t fun (w,i) -> if level.(w) < 0 && c.(i) > 0 then (\n\t\tlevel.(w) <- level.(v) + 1;\n\t\tpush w\n\t )\n\t ) adj.(v);\n\t loop ()\n\t )\n in\n level.(s) <- 0;\n back := 0; front := 0;\n push s;\n loop ();\n in\n \n let rec dfs v cap = \n (* Does a DFS from v looking for a path to t. It tries to push cap units\n of flow to t. It returns the amount of flow actually pushed *)\n if v=t then cap else\n let rec loop total remaining li = \n\t match li with \n\t | [] -> \n\t\talive.(v) <- [];\n\t\ttotal\n\t | (w,i)::tail -> \n\t\tif level.(w) = level.(v)+1 && c.(i) > 0 then (\n\t\t let p = dfs w (min c.(i) remaining) in\n\t\t c.(i) <- c.(i) - p;\n\t\t c.(i lxor 1) <- c.(i lxor 1) + p;\n\t\t if remaining-p = 0 then (\n\t\t alive.(v) <- li;\n\t\t total+p\n\t\t ) else loop (total+p) (remaining-p) tail\n\t\t) else loop total remaining tail\n in loop 0 cap alive.(v)\n in\n \n let rec main_loop flow_so_far = \n for i=0 to n-1 do level.(i) <- -1; done;\n Array.blit adj 0 alive 0 n;\n if bfs () then main_loop (flow_so_far + (dfs s infinite_c)) else flow_so_far\n in\n main_loop 0\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nlet () = \n let n = read_int () in\n let m = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let pair = Array.init m (fun _ ->\n let i = read_int() -1 in\n let j = read_int() -1 in\n if i land 1 = 0 then (i,j) else (j,i)\n ) in\n\n let fact = Array.init n (fun i -> factor a.(i)) in\n \n let primeset = Hashtbl.create 10 in (* the set of primes that occur *)\n for i=0 to n-1 do\n List.iter (fun p -> Hashtbl.replace primeset p true) fact.(i)\n done;\n\n let build_graph p = \n (* build the graph for a specific prime p *)\n let s = n in\n let t = n+1 in\n let adj = Array.make (n+2) [] in\n let cap = Array.make (2*m + 2*n) 0 in\n\n let add_edge u v c cr ind indr =\n adj.(u) <- (v,ind)::adj.(u);\n adj.(v) <- (u,indr)::adj.(v);\n cap.(ind) <- c;\n cap.(indr) <- cr\n in\n\n for k = 0 to m-1 do\n let (i,j) = pair.(k) in\n add_edge i j infinite_c 0 (2*k) (2*k+1)\n done;\n\n for v = 0 to n-1 do\n let capacity = List.length (List.filter (fun e -> e = p) fact.(v)) in\n let edgeno = 2*m + 2*v in\n if v land 1 = 0 then (\n\tadd_edge s v capacity 0 edgeno (edgeno+1);\n ) else (\n\tadd_edge v t capacity 0 edgeno (edgeno+1);\n )\n done;\n (s,t,adj,cap)\n in\n\n let flowsum = ref 0 in\n \n Hashtbl.iter (fun p _ -> \n let (s,t,adj,cap) = build_graph p in\n let f = maxflow s t adj cap in\n flowsum := !flowsum + f\n ) primeset;\n\n printf \"%d\\n\" !flowsum\n"}], "negative_code": [], "src_uid": "10efa17a66af684dbc13c456ddef1b1b"} {"source_code": "(* 7:22 *)\n\nopen 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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let n = read_int () in\n let a = Array.init n read_int in\n\n let m = 200_001 in\n let vtime = Array.make (m+1) (2*m) in\n\n for i=0 to n-1 do\n vtime.(a.(i)) <- i\n done;\n\n let cafe = minf 0 m (fun cafe -> vtime.(cafe)) in\n \n printf \"%d\\n\" a.(cafe)\n", "positive_code": [{"source_code": "let n = read_int () in \nlet h = Hashtbl.create n in\nfor i = 0 to n-1 do Hashtbl.replace h (Scanf.scanf \" %d\" (fun x -> x)) i done;\nprint_int @@ fst @@ Hashtbl.fold (fun a b c -> if b < snd c then (a,b) else c) h (min_int, max_int);\n"}, {"source_code": "module IntSet = Set.Make(struct \n let compare = Pervasives.compare\n type t = int\nend);;\nlet n = read_int () in \nlet a = Array.make n 0 and\ns = ref IntSet.empty in\nfor i = 0 to n-1 do begin\n a.(i) <- Scanf.scanf \" %d\" (fun x -> x);\n s := IntSet.add a.(i) !s\nend done;\nlet p = ref 0 in\nfor i = n-1 downto 0 do begin\n if IntSet.mem a.(i) !s then begin\n p := a.(i) ;\n s := IntSet.remove a.(i) !s\n end\nend done;\nprint_int !p;\n\n"}], "negative_code": [], "src_uid": "bdea209c7b628e4cc90ebc2572826485"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\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 m = read_int () in\n let p = Array.make m 0 in\n let a = Array.make m 0L in\n for i=0 to m-1 do\n p.(i) <- read_int();\n a.(i) <- read_long()\n done;\n \n let k = read_long () in\n\n let max_p = p.(m-1) in\n\n let sieve = Array.make (max_p+1) 0 in\n(* sieve.(n) is the smallest prime that divides n. \n sieve.(n) = n iff n is prime. *)\n \n for i=2 to max_p do\n if sieve.(i) = 0 then\n let rec loop j = if j <= max_p then (\n\tsieve.(j) <- i;\n\tloop (j+i);\n ) in\n loop (i)\n done;\n\n let e = Array.make (max_p+1) 0L in\n\n for i=0 to m-1 do\n e.(p.(i)) <- a.(i)\n done;\n\n let is_normal () = \n(* let process p = \n let rec loop r = r=1 || (e.(sieve.(r)) <> 0L && loop (r/sieve.(r))) in\n loop (p-1);\n in *)\n\n let process p = \n let rec loop r = if r=1 then true \n\telse if e.(sieve.(r)) = 0L then false else loop (r/sieve.(r))\n in\n loop (p-1);\n in\n\n let rec loop p = if p > max_p then true \n else if (sieve.(p) <> p || e.(p) = 0L) then loop (p+1)\n else process p && loop (p+1)\n in\n loop 2\n in\n\n let step () = \n let process p = \n let rec loop r = if r>1 then\n\t let s = sieve.(r) in\n\t e.(s) <- e.(s) ++ 1L;\n\t loop (r/s)\n in\n loop (p-1);\n e.(p) <- e.(p) -- 1L;\n in\n\n for p=2 to max_p do\n if sieve.(p) = p && e.(p) > 0L then process p\n done;\n in\n \n let rec steploop k = if k=0L || is_normal() then k else (\n step();\n steploop (k--1L)\n )\n in \n\n let k = steploop k in\n\n let elim p = \n let d = min e.(p) k in\n e.(p) <- e.(p) -- d;\n (* now add d to the exponents of all the prime factors of p-1 *)\n let rec loop r = if r=1 then () else\n\tlet s = sieve.(r) in\n\te.(s) <- e.(s) ++ d;\n\tloop (r/s)\n in\n loop (p-1);\n in\n\n for p=max_p downto 2 do\n if sieve.(p) = p then elim p\n done;\n\n let np = sum 2 max_p (fun i -> if e.(i) <> 0L then 1 else 0) in\n \n printf \"%d\\n\" np;\n\n for i=2 to max_p do\n if e.(i) <> 0L then printf \"%d %Ld\\n\" i e.(i)\n done\n", "positive_code": [{"source_code": "(* \n Imagine the following graph. There's a node for every prime, and in\n the node an exponent of that prime is stored. There is an edge from\n prime p to each of the prime factors of p-1. EG from 13 there are two\n edges to 2 and one edge to 3. (2*2*3=12).\n\n To compute Phi of a number represented in this way, you do the following.\n For each non-zero exponent (simultaneously) decrement its exponentent\n by 1. Then for each successor of those that you decremented, you increment\n the exponent by 1.\n\n The problem here is to be able to iterate the Phi operator a huge\n number of times efficiently.\n\n Call a state \"normal\" if there is no pair of nodes p-->q such that\n p is non-zero while q is zero. The beauty of a normal state is\n that if you apply the Phi operator to it, it remains normal.\n\n Consider what happens to some node when you hit it with the Phi\n operator in a normal state. Exactly the same thing happens every\n time locally to it until all of its sources dry up.\n\n This means we can apply the Phi operator to various different nodes\n in any order we want. So we apply it in topological order\n (i.e. largest first). It's easy to apply the operator all k times\n to a node in O(number successors of it).\n\n It remains to explain how to get the system into a normal state.\n We simply iterate the Phi operator on it until it becomes normal.\n Then we reduce k by the number of times we had to apply the\n operator. The number of times we have to do this is the length of\n the longest path in the graph. This is at most logarithmic in the\n largest prime (a pessimistic estimate).\n\n (There is also an alternative algorithm that \"protects\" some amount\n of the exponent from being depleted. You are effectively computing\n the number of iterations until a node becomes non-zero. That's the\n amount of protection it gets. This can be computed as you go along.\n Some of the other shorter solutions do it this way.)\n\n Danny Sleator, March 2014\n*)\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\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 m = read_int () in\n let p = Array.make m 0 in\n let a = Array.make m 0L in\n for i=0 to m-1 do\n p.(i) <- read_int();\n a.(i) <- read_long()\n done;\n \n let k = read_long () in\n\n let max_p = p.(m-1) in\n\n let sieve = Array.make (max_p+1) 0 in\n(* sieve.(n) is the smallest prime that divides n. \n sieve.(n) = n iff n is prime. *)\n \n for i=2 to max_p do\n if sieve.(i) = 0 then\n let rec loop j = if j <= max_p then (\n\tsieve.(j) <- i;\n\tloop (j+i);\n ) in\n loop (i)\n done;\n\n let e = Array.make (max_p+1) 0L in\n\n for i=0 to m-1 do\n e.(p.(i)) <- a.(i)\n done;\n\n let is_normal () = \n(* let process p = \n let rec loop r = r=1 || (e.(sieve.(r)) <> 0L && loop (r/sieve.(r))) in\n loop (p-1);\n in *)\n\n let process p = \n let rec loop r = if r=1 then true \n\telse if e.(sieve.(r)) = 0L then false else loop (r/sieve.(r))\n in\n loop (p-1);\n in\n\n let rec loop p = if p > max_p then true \n else if (sieve.(p) <> p || e.(p) = 0L) then loop (p+1)\n else process p && loop (p+1)\n in\n loop 2\n in\n\n let step () = \n let process p = \n let rec loop r = if r>1 then\n\t let s = sieve.(r) in\n\t e.(s) <- e.(s) ++ 1L;\n\t loop (r/s)\n in\n loop (p-1);\n e.(p) <- e.(p) -- 1L;\n in\n\n for p=2 to max_p do\n if sieve.(p) = p && e.(p) > 0L then process p\n done;\n in\n \n let rec steploop k = if k=0L || is_normal() then k else (\n step();\n steploop (k--1L)\n )\n in \n\n let k = steploop k in\n\n let elim p = \n let d = min e.(p) k in\n e.(p) <- e.(p) -- d;\n (* now add d to the exponents of all the prime factors of p-1 *)\n let rec loop r = if r=1 then () else\n\tlet s = sieve.(r) in\n\te.(s) <- e.(s) ++ d;\n\tloop (r/s)\n in\n loop (p-1);\n in\n\n for p=max_p downto 2 do\n if sieve.(p) = p then elim p\n done;\n\n let np = sum 2 max_p (fun i -> if e.(i) <> 0L then 1 else 0) in\n \n printf \"%d\\n\" np;\n\n for i=2 to max_p do\n if e.(i) <> 0L then printf \"%d %Ld\\n\" i e.(i)\n done\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\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 m = read_int () in\n let p = Array.make m 0 in\n let a = Array.make m 0L in\n for i=0 to m-1 do\n p.(i) <- read_int();\n a.(i) <- read_long()\n done;\n \n let k = read_long () in\n\n let max_p = p.(m-1) in\n\n let sieve = Array.make (max_p+1) 0 in\n(* sieve.(n) is the smallest prime that divides n. \n sieve.(n) = n iff n is prime. *)\n \n for i=2 to max_p do\n if sieve.(i) = 0 then\n let rec loop j = if j <= max_p then (\n\tsieve.(j) <- i;\n\tloop (j+i);\n ) in\n loop (i)\n done;\n\n let e = Array.make (max_p+1) 0L in\n\n for i=0 to m-1 do\n e.(p.(i)) <- a.(i)\n done;\n\n let is_normal () = \n let process p = \n let rec loop r = r=1 || (e.(sieve.(r)) <> 0L && loop (r/sieve.(r))) in\n loop (p-1);\n in\n\n let rec loop p = if p = max_p then true \n else if (sieve.(p) <> p || e.(p) = 0L) then loop (p+1)\n else process p && loop (p+1)\n in\n loop 2\n in\n\n let step () = \n let process p = \n let rec loop r = if r>1 then\n\t let s = sieve.(r) in\n\t e.(s) <- e.(s) ++ 1L;\n\t loop (r/s)\n in\n loop (p-1);\n e.(p) <- e.(p) -- 1L;\n in\n\n for p=2 to max_p do\n if sieve.(p) = p && e.(p) > 0L then process p\n done;\n in\n \n let rec steploop k = if k=0L || is_normal() then k else (\n step();\n steploop (k--1L)\n )\n in \n\n let k = steploop k in\n\n let elim p = \n let d = min e.(p) k in\n e.(p) <- e.(p) -- d;\n (* now add d to the exponents of all the prime factors of p-1 *)\n let rec loop r = if r=1 then () else\n\tlet s = sieve.(r) in\n\te.(s) <- e.(s) ++ d;\n\tloop (r/s)\n in\n loop (p-1);\n in\n\n for p=max_p downto 2 do\n if sieve.(p) = p then elim p\n done;\n\n let np = sum 2 max_p (fun i -> if e.(i) <> 0L then 1 else 0) in\n \n printf \"%d\\n\" np;\n\n for i=2 to max_p do\n if e.(i) <> 0L then printf \"%d %Ld\\n\" i e.(i)\n done\n"}], "src_uid": "6a52ad07f04498498d8ddd63caddbce6"} {"source_code": "Scanf.scanf \"%d %d %d\" (fun n k q ->\nlet qs,qt = Queue.create(), Queue.create() in\nlet dat = Array.make n (0,0) in \nlet presum=Array.make 211111 0 in\nlet cnt = ref 0 in\n for i = 0 to n-1 do\n Scanf.scanf \"\\n%d %d\" (fun x y ->dat.(i) <-(x,y))\n done;\n Array.sort (fun (xh,_) (yh,_) -> xh-yh) dat;\n Array.iter (fun (h,_) -> Queue.push h qs) dat;\n Array.sort (fun (_,xt) (_,yt) -> xt-yt) dat;\n Array.iter (fun (_,t) -> Queue.push t qt) dat;\n for i = 1 to 200000 do\n (*Printf.printf \"i=%d\\n\" i;*)\n while not (Queue.is_empty qs) && Queue.top qs <= i do\n \n (*Printf.printf \"qs:%d\\n\"*) ( Queue.pop qs );\n cnt:= !cnt +1\n done;\n while not (Queue.is_empty qt) && Queue.top qt < i do\n (*Printf.printf \"qt:%d\\n\"*) ( Queue.pop qt );\n cnt:= !cnt -1\n done;\n presum.(i) <- (if !cnt>=k then 1 else 0) +presum.(i-1)\n done;\n for i= 1 to q do\n Scanf.scanf \"\\n%d %d\" (fun l r ->\n Printf.printf \"%d\\n\" (presum.(r)-presum.(l-1))\n )\n done)\n", "positive_code": [{"source_code": "Scanf.scanf \"%d %d %d\" (fun n k q ->\nlet maxn=200001 in\nlet add,sub = (Array.make maxn 0) ,(Array.make maxn 0) in \nlet presum=Array.make 211111 0 in\nlet cnt = ref 0 in\n for i = 0 to n-1 do\n Scanf.scanf \"\\n%d %d\" (fun x y ->\n add.(x) <- add.(x) + 1 ;\n sub.(y) <- sub.(y) + 1 )\n done;\n for i = 1 to maxn-1 do\n cnt:=!cnt+add.(i)-sub.(i-1);\n presum.(i) <- (if !cnt>=k then 1 else 0) +presum.(i-1)\n done;\n for i= 1 to q do\n Scanf.scanf \"\\n%d %d\" (fun l r ->\n Printf.printf \"%d\\n\" (presum.(r)-presum.(l-1))\n )\n done)\n"}], "negative_code": [], "src_uid": "4bdf819b73ffb708ad571accf3b8c23d"} {"source_code": "let print int = Printf.printf \"%d\\n\" int\n\nlet same time prev =\n match time, prev with\n | (h, m), (hh, mm) -> \n if h = hh && m = mm\n then\n true\n else\n false\n\nlet () = \n let n = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop i prev count max = \n if i < n\n then\n let time = Scanf.scanf \"%d %d \" (fun h m -> (h, m)) in \n if same time prev\n then \n let max_upd = Pervasives.max (count + 1) max in\n loop (i + 1) time (count + 1) max_upd\n else\n loop (i + 1) time 1 max\n else\n print max\n in loop 0 (99, 99) 1 1", "positive_code": [{"source_code": "let input () = \n let n = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop i list = \n if i < n\n then\n let str = Scanf.scanf \"%s %s \" (fun a b -> String.concat \"\" [a; b]) in\n loop (i + 1) (str :: list)\n else\n List.rev list\n in loop 0 []\n \n\nlet print int = Printf.printf \"%d\\n\" int\n\nlet solve list = \n let rec loop rest prev count max = \n match rest with\n | (head :: tail) -> \n if String.compare head prev = 0\n then\n let max_upd = Pervasives.max (count + 1) max in\n loop tail head (count + 1) max_upd\n else\n loop tail head 1 max\n | [] -> max\n in loop list \"start\" 1 1\n\nlet () = print (solve (input ()))"}, {"source_code": "let input () = \n let n = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop i list = \n if i < n\n then\n let time = Scanf.scanf \"%d %d \" (fun h m -> (h, m)) in\n loop (i + 1) (time :: list)\n else\n list\n in loop 0 []\n \nlet print int = Printf.printf \"%d\\n\" int\n\nlet solve list = \n let rec loop rest prev count max = \n match rest, prev with\n | ((h, m) as head :: tail), (hh, mm) -> \n if h = hh && m = mm\n then\n let max_upd = Pervasives.max (count + 1) max in\n loop tail head (count + 1) max_upd\n else\n loop tail head 1 max\n | [], _ -> max\n in loop list (99, 99) 1 1\n\nlet () = print (solve (input ()))"}, {"source_code": "\n(* Codeforces 237A *)\n\nlet read_time() = Scanf.scanf \"%d %d\\n\" (fun x y -> x, y)\n\nlet solve n =\n let rec inner n prev_time count max_count =\n if (n == 0) then max count max_count\n else \n begin\n\tlet time = read_time() in\n\tif (time = prev_time)\n\tthen inner (n-1) time (count+1) max_count\n\telse\n\t if (count > max_count)\n\t then inner (n-1) time 1 count\n\t else inner (n-1) time 1 max_count\n end\n in\n inner n (-1, -1) 0 0\n\nlet _ =\n Printf.printf \"%d\\n\" (Scanf.scanf \"%d\\n\" solve)\n"}], "negative_code": [{"source_code": "\n(* Codeforces 237A *)\n\nlet read_time() = Scanf.scanf \"%d %d\\n\" (fun x y -> x, y)\n\nlet solve n =\n let rec inner n prev_time count max_count =\n if (n == 0) then max_count\n else\n begin\n\tlet time = read_time() in\n\tlet max_count =\n\t if (max_count < count)\n\t then count\n\t else max_count\n\tin\n\tlet count =\n\t if (time = prev_time)\n\t then count+1\n\t else 1\n\tin\n\tinner (n-1) time count max_count\n end\n in\n inner n (-1, -1) 0 0\n\nlet _ =\n Printf.printf \"%d\\n\" (Scanf.scanf \"%d\\n\" solve)\n"}], "src_uid": "cfad2cb472e662e037f3415a84daca57"} {"source_code": "\nlet list_of_string s =\n let rec loc i acc =\n if i < 0\n then acc\n else loc (i - 1) (String.get s i :: acc)\n in\n loc (String.length s - 1) []\n\nlet combine s t =\n let rec loc acc s t =\n match s, t with\n | [], [] -> acc\n | x :: rs, y :: rt -> loc ((x, y) :: acc) rs rt\n | _, _ -> invalid_arg \"\"\n in\n List.rev (loc [] s t)\n\nexception Impossible\n\nlet solve a b =\n\n let la = list_of_string a\n and lb = list_of_string b in\n let l = combine la lb in\n let n = List.length l in\n\n let diff =\n List.fold_left\n (fun acc (ca, cb) -> if ca <> cb then acc + 1 else acc)\n 0\n l\n in\n if diff mod 2 <> 0 then raise Impossible;\n\n let ans = String.create n in\n let rec loc i j = function\n | [] -> ()\n | (ca, cb) :: rest ->\n if ca = cb\n then (String.set ans i ca; loc (i + 1) j rest)\n else\n begin\n if j < diff / 2\n then (String.set ans i ca; loc (i + 1) (j + 1) rest)\n else (String.set ans i cb; loc (i + 1) (j + 1) rest)\n end\n in\n loc 0 0 l;\n ans\n\n(* let mk n = String.init n (fun _ -> if Random.bool () then '0' else '1') *)\n\nlet _ =\n (* print_endline (mk 100000); *)\n (* print_endline (mk 100000); *)\n \n let a = read_line ()\n and b = read_line () in\n let ans =\n try solve a b\n with Impossible -> \"impossible\"\n in\n print_endline ans\n", "positive_code": [{"source_code": "let _ =\n\tlet (s1,s2) = Scanf.scanf \"%s %s\" (fun i j -> (i,j)) in\n\tlet res = String.copy s1 and flg = ref true in\n\tfor i=0 to String.length res - 1 do\n\t\tif res.[i] <> s2.[i]\n\t\t\tthen begin\n\t\t\t\tflg := not !flg;\n\t\t\t\tif !flg\n\t\t\t\t\tthen res.[i] <- s2.[i]\n\t\t\t end;\n\tdone;\n\tPrintf.printf \"%s\" (if !flg then res else \"impossible\")\n"}], "negative_code": [{"source_code": "\nlet list_of_string s =\n let rec loc i acc =\n if i < 0\n then acc\n else loc (i - 1) (String.get s i :: acc)\n in\n loc (String.length s - 1) []\n\nlet combine s t =\n let rec loc acc s t =\n match s, t with\n | [], [] -> acc\n | x :: rs, y :: rt -> loc ((x, y) :: acc) rs rt\n | _, _ -> invalid_arg \"\"\n in\n List.rev (loc [] s t)\n\nexception Impossible\n\nlet solve a b =\n\n let la = list_of_string a\n and lb = list_of_string b in\n let l = combine la lb in\n let n = List.length l in\n\n let diff =\n List.fold_left\n (fun acc (ca, cb) -> if ca <> cb then acc + 1 else acc)\n 0\n l\n in\n if diff mod 2 <> 0 then raise Impossible;\n\n let ans = String.create n in\n List.iteri\n (fun i (ca, cb) ->\n if i < n / 2\n then String.set ans i ca\n else String.set ans i cb)\n l;\n ans\n\n(* let mk n = String.init n (fun _ -> if Random.bool () then '0' else '1') *)\n\nlet _ =\n (* print_endline (mk 100000); *)\n (* print_endline (mk 100000); *)\n \n let a = read_line ()\n and b = read_line () in\n let ans =\n try solve a b\n with Impossible -> \"impossible\"\n in\n print_endline ans\n"}], "src_uid": "2df181f2d1f4063a22fd2fa2d47eef92"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet merge_cycles n goal ncycles p mark =\n let rec build_swaps i ncyc ac = if ncyc=goal then List.rev ac else\n if mark.(i) = 0 then build_swaps (i+1) ncyc ac else\n\tlet rec loop j = if j<>i then (\n\t mark.(j) <- 0;\n\t loop p.(j)\n\t)\n\tin\n\tloop p.(i);\n\tbuild_swaps (i+1) (ncyc-1) ((0,i)::ac)\n in\n build_swaps 1 ncycles []\n\nlet split_cycles n goal ncycles p mark =\n let rec build_swaps i ncyc ac = if ncyc=goal then List.rev ac else\n if p.(i) = i then build_swaps (i+1) ncyc ac else\n\tlet rec find_smallest j ac = if j=i then ac else\n\t find_smallest p.(j) (min ac j)\n\tin\n\tlet j = find_smallest p.(i) p.(i) in\n\tlet (oi, oj) = (p.(i), p.(j)) in\n\tp.(i) <- oj;\n\tp.(j) <- oi;\n\tbuild_swaps i (ncyc+1) ((i,j)::ac)\n in\n build_swaps 0 ncycles []\n \nlet () = \n let n = read_int () in\n let p = Array.init n (fun _ -> read_int()-1) in\n let goal = n - (read_int ()) in\n\n let mark = Array.make n (-1) in\n\n let rec dfs i c = if mark.(i) < 0 then (\n mark.(i) <- c;\n dfs p.(i) c\n ) in\n\n let rec count_cycles c i = \n if i=n then c \n else if mark.(i) >= 0 then count_cycles c (i+1) else (\n dfs i c;\n count_cycles (c+1) (i+1)\n )\n in\n\n let ncycles = count_cycles 0 0 in\n\n printf \"%d\\n\" (abs (ncycles-goal));\n\n let answer = \n (if ncycles >= goal then merge_cycles else split_cycles) n goal ncycles p mark\n in\n\n List.iter (fun (i,j) -> printf \"%d %d \" (i+1) (j+1)) answer;\n print_newline();\n", "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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet split_cycles n m ncycles p mark =\n failwith \"split_cycles called\"\n\nlet merge_cycles n goal ncycles p mark =\n (* The algorithm is to find the smallest element not in\n cycle 0 and swap it with 0, thus putting it in cycle 0.\n The mark array already has 0s in it at cycle 0. This is O(n).\n *)\n let rec build_swaps i ncyc ac = if ncyc=goal then List.rev ac else\n if mark.(i) = 0 then build_swaps (i+1) ncyc ac else\n\tlet rec loop j = if j=i then () else (\n\t mark.(j) <- 0;\n\t loop p.(j)\n\t)\n\tin\n\tloop p.(i);\n\tbuild_swaps (i+1) (ncyc-1) ((0,i)::ac)\n in\n\n build_swaps 1 ncycles []\n\nlet split_cycles n goal ncycles p mark =\n let rec build_swaps i ncyc ac = if ncyc=goal then List.rev ac else\n if p.(i) = i then build_swaps (i+1) ncyc ac else\n\tlet rec find_smallest j ac = if j=i then ac else\n\t find_smallest p.(j) (min ac j)\n\tin\n\tlet j = find_smallest p.(i) p.(i) in\n\tlet (oi, oj) = (p.(i), p.(j)) in\n\tp.(i) <- oj;\n\tp.(j) <- oi;\n\tbuild_swaps i (ncyc+1) ((i,j)::ac)\n in\n build_swaps 0 ncycles []\n \nlet () = \n let n = read_int () in\n let p = Array.init n (fun _ -> read_int()-1) in\n let m = read_int () in\n let goal = n-m in (* number of cycles of the goal *)\n\n let mark = Array.make n (-1) in\n\n let rec dfs i c = if mark.(i) < 0 then (\n mark.(i) <- c;\n dfs p.(i) c\n ) in\n\n let rec count_cycles c i = \n if i=n then c \n else if mark.(i) >= 0 then count_cycles c (i+1) else (\n dfs i c;\n count_cycles (c+1) (i+1)\n )\n in\n\n let ncycles = count_cycles 0 0 in\n\n printf \"%d\\n\" (abs (ncycles-goal));\n\n let answer = \n (if ncycles >= goal then merge_cycles else split_cycles) n goal ncycles p mark\n in\n\n List.iter (fun (i,j) -> printf \"%d %d \" (i+1) (j+1)) answer;\n print_newline();\n"}], "negative_code": [], "src_uid": "e7517e32caa1b044ebf1d39276560b47"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\ntype container = {\n cap : int;\n id: int\n};;\n\nlet comp contA contB =\n - (contA.cap - contB.cap);;\n\nlet rec get_best tab1 tab2 size = match (tab1,tab2) with\n | ([],[])\n -> []\n | ([], _) when size < 2\n -> []\n | (_, _) when size = 0\n -> []\n | (first :: tail, _) when size = 1\n -> [first]\n | ([], first :: tail)\n -> first :: get_best [] tail (size - 2)\n | (first :: tail, [])\n -> first :: get_best tail [] (size - 1)\n | (first1 :: [], first2 :: tail2)\n -> if first1.cap >= first2.cap then\n first1 :: get_best [] tab2 (size - 1)\n else\n first2 :: get_best tab1 tail2 (size - 2)\n | (first1 :: second1 :: tail1, first2 :: tail2)\n -> if first1.cap + second1.cap >= first2.cap then\n first1 :: get_best (second1::tail1) tab2 (size - 1)\n else\n first2 :: get_best tab1 tail2 (size - 2);;\n\n(*#trace get_best;;*)\n\nlet rec read_input index left = match left with\n | 0 -> [],[]\n | n ->\n let size = read_int () in\n let cap = read_int () in\n let cont = {cap = cap; id = index} in\n let size1,size2 = read_input (index + 1) (left - 1) in\n if size = 1 then\n (cont :: size1, size2)\n else\n (size1, cont :: size2);;\n\n\n\nlet nbVehi = read_int () in\nlet maxV = read_int () in\nlet unsort1,unsort2 = (read_input 1 nbVehi) in\nlet tab1 = List.sort comp unsort1 in\nlet tab2 = List.sort comp unsort2 in\nlet res = get_best tab1 tab2 maxV in\nbegin\n let maxC = List.fold_left (fun sum cont -> sum + cont.cap) 0 res in\n Printf.printf \"%d\\n\" maxC;\n List.iter (fun cont -> Printf.printf \"%d\\n\" cont.id) res\nend;;", "positive_code": [{"source_code": "let (|>) x f = f x\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int 0 in\n let v = read_int 0 in\n let one = Array.make n (0,0)\n and two = Array.make n (0,0) in\n let rec input i none ntwo =\n if i >= n then\n none,ntwo\n else (\n let t = read_int 0 in\n let c = read_int 0 in\n if t = 1 then (\n one.(none) <- (c,i);\n input (i+1) (none+1) ntwo\n ) else (\n two.(ntwo) <- (c,i);\n input (i+1) none (ntwo+1)\n )\n ) in\n let none,ntwo = input 0 0 0 in\n Array.sort (fun x y -> compare y x) one;\n Array.sort (fun x y -> compare y x) two;\n\n let ans = ref 0\n and ansp = ref 0\n and ansq = ref 0\n and qs = ref 0\n and ps = Array.make (none+1) 0 in\n for i = 0 to none-1 do\n ps.(i+1) <- ps.(i)+fst one.(i)\n done;\n for i = 0 to min (v/2) ntwo do\n let rest = min (v-2*i) none in\n if ps.(rest) + !qs > !ans then (\n ans := ps.(rest) + !qs;\n ansp := rest;\n ansq := i\n );\n if i < ntwo then\n qs := !qs+fst two.(i)\n done;\n\n Printf.printf \"%d\\n\" !ans;\n for i = 0 to !ansp-1 do\n Printf.printf \"%d \" (snd one.(i)+1)\n done;\n for i = 0 to !ansq-1 do\n Printf.printf \"%d \" (snd two.(i)+1)\n done\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\ntype container = {\n cap : int;\n id: int\n};;\n\nlet comp contA contB =\n - (contA.cap - contB.cap);;\n\nlet rec get_best tab1 tab2 size = match (tab1,tab2) with\n | ([],[])\n -> []\n | ([], _) when size < 2\n -> []\n | (_, _) when size = 0\n -> []\n | (first :: tail, _) when size = 1\n -> [first]\n | ([], first :: tail)\n -> first :: get_best [] tail (size - 2)\n | (first :: tail, [])\n -> first :: get_best tail [] (size - 1)\n | (first1 :: second1 :: [], first2 :: tail2) when size > 2\n -> first2 :: get_best tab1 tail2 (size - 2)\n | (first1 :: [], first2 :: tail2)\n -> if first1.cap >= first2.cap then\n first1 :: get_best [] tab2 (size - 1)\n else\n first2 :: get_best tab1 tail2 (size - 2)\n | (first1 :: second1 :: tail1, first2 :: tail2)\n -> if first1.cap + second1.cap >= first2.cap then\n first1 :: second1 :: get_best tail1 tab2 (size - 2)\n else\n first2 :: get_best tab1 tail2 (size - 2);;\n\n(*#trace get_best;;*)\n\nlet rec read_input index left = match left with\n | 0 -> [],[]\n | n ->\n let size = read_int () in\n let cap = read_int () in\n let cont = {cap = cap; id = index} in\n let size1,size2 = read_input (index + 1) (left - 1) in\n if size = 1 then\n (cont :: size1, size2)\n else\n (size1, cont :: size2);;\n\n\n\nlet nbVehi = read_int () in\nlet maxV = read_int () in\nlet unsort1,unsort2 = (read_input 1 nbVehi) in\nlet tab1 = List.sort comp unsort1 in\nlet tab2 = List.sort comp unsort2 in\nlet res = get_best tab1 tab2 maxV in\nbegin\n let maxC = List.fold_left (fun sum cont -> sum + cont.cap) 0 res in\n Printf.printf \"%d\\n\" maxC;\n List.iter (fun cont -> Printf.printf \"%d\\n\" cont.id) res\nend;;"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\ntype container = {\n cap : int;\n id: int\n};;\n\nlet comp contA contB =\n - (contA.cap - contB.cap);;\n\nlet rec get_best tab1 tab2 size = match (tab1,tab2) with\n | ([],[])\n -> []\n | ([], _) when size < 2\n -> []\n | (_, _) when size = 0\n -> []\n | (first :: [], _) when size = 1\n -> [first]\n | ([], first :: tail)\n -> first :: get_best [] tail (size - 2)\n | (first :: tail, [])\n -> first :: get_best tail [] (size - 1)\n | (first1 :: [], first2 :: tail2)\n -> if first1.cap >= first2.cap then\n first1 :: get_best [] tab2 (size - 1)\n else\n first2 :: get_best tab1 tail2 (size - 2)\n | (first1 :: second1 :: tail1, first2 :: tail2)\n -> if first1.cap + second1.cap >= first2.cap then\n first1 :: second1 :: get_best tail1 tab2 (size - 2)\n else\n first2 :: get_best tab1 tail2 (size - 2);;\n\n(*#trace get_best;;*)\n\nlet rec read_input index left = match left with\n | 0 -> [],[]\n | n ->\n let size = read_int () in\n let cap = read_int () in\n let cont = {cap = cap; id = index} in\n let size1,size2 = read_input (index + 1) (left - 1) in\n if size = 1 then\n (cont :: size1, size2)\n else\n (size1, cont :: size2);;\n\n\n\nlet nbVehi = read_int () in\nlet maxV = read_int () in\nlet unsort1,unsort2 = (read_input 1 nbVehi) in\nlet tab1 = List.sort comp unsort1 in\nlet tab2 = List.sort comp unsort2 in\nlet res = get_best tab1 tab2 maxV in\nbegin\n let maxC = List.fold_left (fun sum cont -> sum + cont.cap) 0 res in\n Printf.printf \"%d\\n\" maxC;\n List.iter (fun cont -> Printf.printf \"%d\\n\" cont.id) res\nend;;"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\ntype container = {\n vol : int;\n size: int;\n id: int\n};;\n\nlet comp contA contB =\n - (contA.vol * contB.size - contB.vol * contA.size);;\n\nlet rec get_best tab size = match tab with\n | [] -> []\n | curr_best :: suite ->\n match size with\n | 0 -> []\n | 1 -> \n if curr_best.size == 1 then\n [curr_best]\n else\n get_best suite size\n | n ->\n curr_best :: get_best suite (size - curr_best.size);;\n\nlet rec read_input index left = match left with\n | 0 -> []\n | n ->\n let size = read_int () in\n let cap = read_int () in\n let cont = {\n size = size;\n vol = cap;\n id = index;\n } in\n cont :: read_input (index + 1) (left - 1);;\n\n\nlet nbVehi = read_int () in\nlet maxV = read_int () in\nlet tableau = read_input 1 nbVehi \n |> List.sort comp in\nlet res = get_best tableau maxV in\nbegin\n let maxC = List.fold_left (fun sum cont -> sum + cont.vol) 0 res in\n Printf.printf \"%d\\n\" maxC;\n List.iter (fun cont -> Printf.printf \"%d\\n\" cont.id) res\nend;;"}], "src_uid": "a1f98b06650a5755e784cd6ec6f3b211"} {"source_code": "let calculate_table () =\n let table = Hashtbl.create 1000000 in\n for a = 0 to 500 do\n for b = 0 to 500 do\n let new_value = (a*2020 + b*2021) in\n Hashtbl.add table new_value (a, b)\n done\n done;\n table;;\n\nlet find_opt tbl n =\n try\n Some (Hashtbl.find tbl n)\n with Not_found -> None\n\nlet solution_exists n solutions =\n let maybe_sol = find_opt solutions n in\n match maybe_sol with\n | Some _ -> true\n | None -> false;;\n\nlet cases = read_int () in\nlet solutions = calculate_table () in\nfor i = 1 to cases do\n let test = read_int () in\n if solution_exists test solutions then\n print_endline \"YES\"\n else\n print_endline \"NO\"\ndone", "positive_code": [{"source_code": "module Stdlib = Pervasives\r\nlet std_inp = Stdlib.stdin;;\r\n(* let std_inp = Stdlib.open_in \"input.txt\";; *)\r\nlet std_outp = Stdlib.stdout;;\r\n\r\nlet identity x = x;;\r\n\r\nlet rec repeat ((f, f_in, f_out) as call) = function\r\n| 0 -> ()\r\n| n ->\r\n let _ = f f_in f_out in\r\n repeat call (n - 1);;\r\n\r\nlet flags =\r\n let sum_limit = 1_000_000 in\r\n let flags = Array.make (1 + sum_limit) false in\r\n let safe_get pos =\r\n if pos < 0 then false\r\n else flags.(pos)\r\n in\r\n let rec fill n =\r\n if n > sum_limit then ()\r\n else\r\n let _ = flags.(n) <- ((safe_get (n - 2020)) || (safe_get(n - 2021))) in\r\n fill (n + 1)\r\n in\r\n let _ = flags.(0) <- true in\r\n let _ = fill 1 in\r\n flags;;\r\n\r\nlet run_test inp outp =\r\n let value = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let result = if flags.(value) then \"YES\" else \"NO\" in\r\n let _ = Printf.fprintf outp \"%s\\n\" result in\r\n ();;\r\n\r\nlet (_:unit) =\r\n let inp = std_inp and outp = std_outp in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let _ = repeat (run_test, inp, outp) tests_count in\r\n ();;"}], "negative_code": [], "src_uid": "3ec1b7027f487181dbdfb12f295f11ae"} {"source_code": "let n = read_int () in\n\nlet arr = Array.init n (fun i ->\n\tScanf.scanf \" %d\" (fun i->i)\n) in\n\nlet maxi = ref 0 in\nlet mini = ref 0 in\nlet _ = Array.iteri (fun i r ->\n\tif r <= arr.(!mini) then mini := i;\n\tif r > arr.(!maxi) then maxi := i\n) arr in\nprint_int (!maxi + (n-1- !mini) - (if !maxi > !mini then 1 else 0)) \n\n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet find_min array l = \n let rec loop min position i =\n if i < l \n then\n let current = array.(i) in\n if current <= min\n then\n loop current i (i + 1)\n else\n loop min position (i + 1)\n else\n position\n in loop array.(0) 0 0\n\nlet find_max array l = \n let rec loop max position i =\n if i < l \n then\n let current = array.(i) in\n if current > max\n then\n loop current i (i + 1)\n else\n loop max position (i + 1)\n else\n position\n in loop array.(0) 0 0\n\nlet solve () = \n let l = read () in\n let line = Array.init l (fun x -> read ()) in\n let min_i = find_min line l in\n let max_i = find_max line l in\n if max_i > min_i\n then\n (l - 1 - min_i) + (max_i - 1)\n else\n (l - 1 - min_i) + max_i\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet find_best f array l =\n let rec loop best position i =\n if i < l \n then\n let current = array.(i) in\n if f current best\n then\n loop current i (i + 1)\n else\n loop best position (i + 1)\n else\n position\n in loop array.(0) 0 0\n\nlet find_min = find_best (fun x y -> x <= y)\nlet find_max = find_best (fun x y -> x > y)\n\nlet solve () = \n let l = read () in\n let line = Array.init l (fun x -> read ()) in\n let min_i = find_min line l in\n let max_i = find_max line l in\n if max_i > min_i\n then\n (l - 1 - min_i) + (max_i - 1)\n else\n (l - 1 - min_i) + max_i\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}, {"source_code": "let rec split s i acc =\nbegin\n if i > String.length s \n then List.rev acc\n else \n let first = \n if String.contains_from s i ' ' \n then String.index_from s i ' ' \n else String.length s \n in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc) \nend in \nlet n = int_of_string(read_line ()) and \n vals = split (read_line ()) 0 [] in \nif n == List.length vals\n then \n let maxval = List.fold_right max (List.tl vals) (List.hd vals) and\n minval = List.fold_right min (List.tl vals) (List.hd vals) in\n if (List.nth vals 0) == maxval && (List.nth vals (n-1)) == minval \n then print_int 0 \n else \n let maxpos = ref (n-1) and \n minpos = ref 0 in begin\n List.iteri (fun a b -> if b ==maxval then maxpos := min !maxpos a \n else if b == minval then minpos := max !minpos a\n else ()) vals;\n print_int (!maxpos + n - 1 - !minpos - (if !maxpos > !minpos then 1 else 0))\n end\n else ()\n\n"}, {"source_code": "let ( |> ) x f = f x\nlet () =\n\tlet n = read_int ()\n\tin let a =\n\t\tread_line ()\n\t\t|> Str.split (Str.regexp \"\\ \")\n\t\t|> List.map int_of_string\n\tin let ((max, left_most_pos), (min, right_most_pos)) =\n\t\tlet rec search sublist_of_a pos =\n\t\t\tmatch sublist_of_a with\n\t\t\t\t| [] -> invalid_arg \"\"\n\t\t\t\t| hd :: [] -> ((hd, pos), (hd, pos))\n\t\t\t\t| hd :: tl ->\n\t\t\t\t\t let ((max, left_most_pos), (min, right_most_pos)) = (search tl (pos + 1))\n\t\t\t\t\t in let (new_max, new_left_most_pos) =\n\t\t\t\t\t\t if hd >= max then\n\t\t\t\t\t\t\t (hd, pos)\n\t\t\t\t\t\t else\n\t\t\t\t\t\t\t (max, left_most_pos)\n\t\t\t\t\t in let (new_min, new_right_most_pos) =\n\t\t\t\t\t\t if hd < min then\n\t\t\t\t\t\t\t (hd, pos)\n\t\t\t\t\t\t else\n\t\t\t\t\t\t\t (min, right_most_pos)\n\t\t\t\t\t in ((new_max, new_left_most_pos), (new_min, new_right_most_pos))\n\t\tin search a 0\n\tin begin\n\t\tif left_most_pos > right_most_pos then\n\t\t\t(left_most_pos + (n - right_most_pos - 2))\n\t\telse\n\t\t\t(left_most_pos + (n - right_most_pos - 1))\n\tend |> print_int; print_newline ()\n"}, {"source_code": "(* codeforces 103. 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 n = read_int() in\n let a = Array.make n 0 in\n let () = for i=0 to n-1 do a.(i) <- read_int() done in\n let rec find_max i ac = if i=n then ac else find_max (i+1) (if ac < 0 || a.(i) > a.(ac) then i else ac) in\n let rec find_min i ac = if i=n then ac else find_min (i+1) (if ac < 0 || a.(i) <= a.(ac) then i else ac) in\n let mx = find_max 0 (-1) in\n let mi = find_min 0 (-1) in\n let guess = mx + (n-1-mi) in\n let answer = if mx < mi then guess else guess-1 in\n Printf.printf \"%d\\n\" answer\n"}], "negative_code": [{"source_code": "let rec split s i acc =\nbegin\n if i > String.length s \n then List.rev acc\n else \n let first = \n if String.contains_from s i ' ' \n then String.index_from s i ' ' \n else String.length s \n in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc) \nend in \nlet n = int_of_string(read_line ()) and \n vals = split (read_line ()) 0 [] in \nif n == List.length vals\n then begin\n let maxval = List.fold_right max (List.tl vals) (List.hd vals) and\n minval = List.fold_right min (List.tl vals) (List.hd vals) in\n let maxpos = ref (n-1) and \n minpos = ref 0 in\n List.iteri (fun a b -> if b ==maxval then maxpos := min !maxpos a \n else if b == minval then minpos := max !minpos a\n else ()) vals;\n print_int (!maxpos + n - 1 - !minpos - (if !maxpos > !minpos then 1 else 0))\n end\n else ()\n\n"}, {"source_code": "let ( |> ) x f = f x\nlet () =\n\tlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d\" (fun x -> x)\n\tin let a =\n\t\tread_line ()\n\t\t|> Str.split (Str.regexp \"\\ \")\n\t\t|> List.map int_of_string\n\tin let ((max, left_most_pos), (min, right_most_pos)) =\n\t\tlet rec search sublist_of_a pos =\n\t\t\tmatch sublist_of_a with\n\t\t\t\t| [] -> invalid_arg \"\"\n\t\t\t\t| hd :: [] -> ((hd, pos), (hd, pos))\n\t\t\t\t| hd :: tl ->\n\t\t\t\t\t let ((max, left_most_pos), (min, right_most_pos)) = (search tl (pos + 1))\n\t\t\t\t\t in let (new_max, new_left_most_pos) =\n\t\t\t\t\t\t if hd >= max then\n\t\t\t\t\t\t\t (hd, pos)\n\t\t\t\t\t\t else\n\t\t\t\t\t\t\t (max, left_most_pos)\n\t\t\t\t\t in let (new_min, new_right_most_pos) =\n\t\t\t\t\t\t if hd < min then\n\t\t\t\t\t\t\t (hd, pos)\n\t\t\t\t\t\t else\n\t\t\t\t\t\t\t (min, right_most_pos)\n\t\t\t\t\t in ((new_max, new_left_most_pos), (new_min, new_right_most_pos))\n\t\tin search a 0\n\tin begin\n\t\tif left_most_pos > right_most_pos then\n\t\t\t(left_most_pos + (n - right_most_pos - 2))\n\t\telse\n\t\t\t(left_most_pos + (n - right_most_pos - 1))\n\tend |> Printf.printf \"%d\\n\"\n"}], "src_uid": "ef9ff63d225811868e786e800ce49c92"} {"source_code": "let can x = if 360 mod (180 - x) = 0 then \"YES\\n\" else \"NO\\n\" in\nlet n = read_line () |> int_of_string in\nfor i = 1 to n do\n print_string (read_line () |> int_of_string |> can) \ndone\n", "positive_code": [{"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make n (-1);;\nlet b = Array.make n (-1);;\n\nlet nd=181\nlet c = Array.make nd 0;; \n\nfor i = 3 to 360 do\n if (360 mod i) = 0 then\n c.(180 - 360/i) <- 1\ndone\n\nfor i = 1 to n do\n let deg = Scanf.scanf \"%d \" ( fun x -> x ) in\n if c.(deg) = 0 then print_endline \"NO\" else print_endline \"YES\"\ndone\n"}, {"source_code": "let ok x =\n let an = 180 - x in\n let n = 360 / an\n in an * n = 360 ;;\n\nlet test_num = read_int()\nin\nfor i = 1 to test_num do\n let x = read_int()\n in\n if (ok x) then\n Printf.printf \"YES\\n\"\n else\n Printf.printf \"NO\\n\"\ndone\n"}, {"source_code": "let read () = Pervasives.read_int ()\nlet print string = Pervasives.print_endline string\n\nlet () =\n let n = read () in\n let rec loop i =\n if i < n\n then\n let angle = read () in\n if 360 mod (180 - angle) = 0\n then\n print \"YES\"\n else\n print \"NO\";\n loop (i + 1)\n else\n ()\n in loop 0"}], "negative_code": [{"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make n (-1);;\nlet b = Array.make n (-1);;\n\nlet nd=181\nlet c = Array.make nd 0;; \n\nfor i = 3 to 360 do\n c.(180 - 360/i) <- 1\ndone\n\nfor i = 1 to n do\n let deg = Scanf.scanf \"%d \" ( fun x -> x ) in\n if c.(deg) = 0 then print_endline \"NO\" else print_endline \"YES\"\ndone\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet (a,b) = Scanf.scanf \"%d %d \" ( fun x y -> (x,y))\n\n\nlet aa = ref a in\nlet tt = ref a in\nlet () =\n while ( !aa /b > 0 ) do\n tt := !tt + (!aa)/b; aa := (!aa/b) + (!aa mod b)\n done\nin printf \"%d\\n\" !tt\n\n\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make n (-1);;\nlet b = Array.make n (-1);;\n\nlet nd=181\nlet c = Array.make nd 0;; \n\nfor i = 3 to 360 do\n if (360 mod 5) = 0 then\n c.(180 - 360/i) <- 1\ndone\n\nfor i = 1 to n do\n let deg = Scanf.scanf \"%d \" ( fun x -> x ) in\n if c.(deg) = 0 then print_endline \"NO\" else print_endline \"YES\"\ndone\n"}], "src_uid": "9037f487a426ead347baa803955b2c00"} {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let rec const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n if k>0 then abs (comb \"t\" \"-\" (const k)) else abs (comb \"t\" \"+\" (const (-k)))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"-\" (absdif (k-1)) in\n comb \"2\" \"-\" (abs p1)\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet p1 = (comb (const ((x.(i)+1)/2)) \"*\" (basis i)) in\n\tlet ac = if ac=\"\" then p1 else comb p1 \"+\" ac in\n\tloop (i+1) ac\n in\n loop 0 \"\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n", "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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let rec const k =\n if k < 0 then comb (const 0) \"-\" (const (-k)) else sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb (absdif k) \"+\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis i)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let rec const k =\n if k < 0 then comb (const 0) \"-\" (const (-k)) else sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb (absdif k) \"+\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis i)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}], "negative_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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb \"2\" \"*\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis i)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb (absdif k) \"+\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis (i+1))))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"-\" (absdif (k-1)) in\n let p2 = comb \"2\" \"*\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis v)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb \"2\" \"*\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis v)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb (absdif k) \"+\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis i)))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}, {"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\n let x = Array.make n 0 in\n let y = Array.make n 0 in \n\n for i=0 to n-1 do\n x.(i) <- read_int();\n y.(i) <- read_int();\n x.(i) <- x.(i) + (x.(i) land 1);\n y.(i) <- y.(i) + (y.(i) land 1); \n ignore (read_int())\n done;\n\n let abs f =\n sprintf \"abs(%s)\" f\n in\n\n let comb f op g =\n sprintf \"(%s%s%s)\" f op g\n in\n\n let const k =\n sprintf \"%d\" k\n in\n\n let absdif k =\n abs (comb \"t\" \"-\" (const k))\n in\n\n let basis k =\n let p1 = comb (absdif (k+1)) \"+\" (absdif (k-1)) in\n let p2 = comb \"2\" \"*\" (absdif k) in\n comb p1 \"-\" p2\n in\n\n let build_function n x =\n let rec loop i ac = if i=n then ac else\n\tlet v = x.(i) in\n\tloop (i+1) (comb ac \"+\" (comb (const (v/2)) \"*\" (basis (i+1))))\n in\n loop 0 \"0\"\n in\n\n printf \"%s\\n\" (build_function n x);\n printf \"%s\\n\" (build_function n y); \n"}], "src_uid": "79c337ca7397eac500ca8e6693f83fb6"} {"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 (2 * n) (0, 0, 0) in\n let ll = Array.make n 0 in\n for i = 0 to n - 1 do\n let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(2 * i) <- (l, 0, i);\n\ta.(2 * i + 1) <- (r, 1, i);\n\tll.(i) <- l;\n done;\n Array.sort compare a;\n let res = ref 0 in\n let s = ref [] in\n let tt = ref (-1) in\n for i = 0 to 2 * n - 1 do\n\tlet (t, k, x) = a.(i) in\n\t if k = 0\n\t then ()\n\t else (\n\t if ll.(x) > !tt then (\n\t incr res;\n\t tt := t;\n\t )\n\t )\n done;\n Printf.printf \"%d\\n\" !res\n", "positive_code": [{"source_code": "open Array;;\nopen Str;;\nlet n = read_int () and ans = ref 0;; \nlet par = make n [|0; 0|] and right = ref (-1);;\nfor i = 1 to n do set par (i - 1) (of_list (List.map (int_of_string) (split (regexp \" \") (read_line ())))) done;;\nlet cmp [|a; b|] [|c; d|] = (if b < d then -1 else 1);;\nsort (cmp) par;;\nfor i = 0 to n - 1 do if par.(i).(0) > !right then begin\n\tright := par.(i).(1);\t\t\n\tans := !ans + 1;\nend done;;\nprint_int !ans\n"}], "negative_code": [{"source_code": "open Array;;\nopen Str;;\nlet n = read_int () and ans = ref 0;; \nlet par = make n [|0; 0|] and right = ref (-1);;\nfor i = 1 to n do set par (i - 1) (of_list (List.map (int_of_string) (split (regexp \" \") (read_line ())))) done;;\nlet cmp [|a; b|] [|c; d|] = (if b < d then -1 else 1);;\nsort (cmp) par;;\nfor i = 0 to n - 1 do Printf.printf \"%d %d\\n\" par.(i).(0) par.(i).(1) done;;\nfor i = 0 to n - 1 do if par.(i).(0) > !right then begin\n\tright := par.(i).(1);\t\t\n\tans := !ans + 1;\nend done;;\nprint_int !ans\n"}], "src_uid": "73e8984cceded15027c4ab89c5624a92"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet make_list n =\n let rec loop i list =\n if i < n\n then\n let value = read () in\n loop (i + 1) (value :: list)\n else\n List.rev list\n in loop 0 []\n\nlet counter count max_delay diff =\n if diff <= max_delay\n then\n count + 1\n else\n 1\n\nlet input () = \n let n = read () in\n let delay = read () in\n let seconds = make_list n in\n (delay, seconds)\n\nlet solve (delay, seconds) =\n let rec loop prev rest count =\n match rest with\n | (head :: tail) -> loop head tail (counter count delay (head - prev))\n | [] -> count\n in loop 0 seconds 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "\n\nlet read_nums () = \n let s = read_line () in\n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n nums\n\n;;\n\n\nlet rec get_ans c lst acc prev= \n match lst with\n | hd :: tl -> if (hd - prev <= c) then\n get_ans c tl (acc + 1) hd\n else\n get_ans c tl 1 hd\n | [] -> let () = print_int acc in print_string \"\\n\"\n\n\nlet main () =\n let l = read_nums () in\n match l with\n | [n; c] -> (get_ans c (read_nums ())) 0 0\n | _ -> ()\n;;\n\nmain () ;;\n\n\n\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let c = read_int () in\n let time_arr = Array.init n (fun _ ->\n read_int ()\n )\n in\n let counter = ref 1 in\n for i = 0 to n - 2 do\n if time_arr.(i+1) - time_arr.(i) <= c then\n counter := !counter + 1\n else counter := 1\n done;\n Printf.printf \"%d\" !counter\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet rec calc a i cur n c = if (i = n) then cur\nelse if (a.(i) - a.(i - 1) > c) then calc a (i + 1) 1 n c \nelse calc a (i + 1) (cur + 1) n c;;\n\nlet readInt () = scanf \" %d \" (fun x -> x)\n\nlet a = \nlet answer = \nlet n = readInt () in\nlet c = readInt () in \nlet a = Array.init n (fun y -> readInt ()) in\ncalc a 1 1 n c\nin printf \"%d\\n\" answer;;"}, {"source_code": "open Scanf\nopen Printf\n\nlet rec calc a i cur n c = if (i = n) then cur\nelse if (a.(i) - a.(i - 1) > c) then calc a (i + 1) 1 n c \nelse calc a (i + 1) (cur + 1) n c;;\n\nlet a = \nlet answer = \nlet n = scanf \" %d \" (fun x-> x) in\nlet c = scanf \" %d \" (fun x-> x) in \nlet a = Array.init n (fun y -> scanf \" %d \" (fun x -> x)) in\ncalc a 1 1 n c\nin printf \"%d\\n\" answer;;\n"}], "negative_code": [], "src_uid": "fb58bc3be4a7a78bdc001298d35c6b21"} {"source_code": "let xstr() = Scanf.scanf \"%s \" (fun x -> x)\n\nlet () = \n let s = xstr() and t = xstr() in\n let n = String.length s and m = String.length t in\n let i = ref 0 and j = ref 0 and res = ref 0 in\n while s.[!i] == '0' && !i + 1 < n do\n i := !i + 1;\n done;\n while t.[!j] == '0' && !j + 1 < m do\n j := !j + 1;\n done;\n res := (if n - !i < m - !j then -1 else (\n if n - !i > m - !j then 1 else 0\n ));\n if n - !i = m - !j then (\n res := 0;\n while !i < n && !j < m && !res = 0 do\n res := if s.[!i] < t.[!j] then -1 else (\n if s.[!i] > t.[!j] then 1 else 0\n );\n i := !i + 1;\n j := !j + 1;\n done;\n );\n if !res = 0 then (\n Printf.printf \"=\\n\";\n );\n if !res < 0 then (\n Printf.printf \"<\\n\";\n );\n if !res > 0 then (\n Printf.printf \">\\n\";\n );\n", "positive_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet sprawdz n a = (* czy jest jakis niezerowy *)\n let koniec = ref false in\n for i=0 to n do\n if a.[i] <> '0' then koniec := true\n done;\n !koniec;;\n\nlet rec porownaj ax bx a b =\n if ax = String.length a then '='\n else if a.[ax] = b.[bx] then porownaj (ax+1) (bx+1) a b\n else if a.[ax] < b.[bx] then '<'\n else '>';;\n\nlet check a b =\n let n = String.length a\n and m = String.length b in\n if sprawdz (n-m-1) a then '>'\n else if sprawdz (m-n-1) b then '<'\n else\n let ax = max 0 (n-m)\n and bx = max 0 (m-n) in\n porownaj ax bx a b;;\n\nlet _ = \n let (a,b) = Scanf.scanf \"%s\\n%s\\n\" (fun x y -> x, y) in\n Printf.printf \"%c\\n\" (check a b) ;;\n\n\n"}], "negative_code": [{"source_code": "let xstr() = Scanf.scanf \"%s \" (fun x -> x)\n\nlet () = \n let s = xstr() and t = xstr() in\n let n = String.length s and m = String.length t in\n let i = ref 0 and j = ref 0 and res = ref 0 in\n while s.[!i] == '0' && !i + 1 < n do\n i := !i + 1;\n done;\n while t.[!j] == '0' && !j + 1 < m do\n j := !j + 1;\n done;\n res := (if n - !i < m - !j then -1 else (\n if n - !i < m - !j then 1 else 0\n ));\n if n - !i = m - !j then (\n res := 0;\n while !i < n && !j < m && !res = 0 do\n res := if s.[!i] < t.[!j] then -1 else (\n if s.[!i] > t.[!j] then 1 else 0\n );\n i := !i + 1;\n j := !j + 1;\n done;\n );\n if !res = 0 then (\n Printf.printf \"=\\n\";\n );\n if !res < 0 then (\n Printf.printf \"<\\n\";\n );\n if !res > 0 then (\n Printf.printf \">\\n\";\n );\n"}], "src_uid": "fd63aeefba89bef7d16212a0d9e756cd"} {"source_code": "open Printf\nopen Scanf\n\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 \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let x = long (read_int ()) in\n\n let rec loop i packs distress = if i=n then (packs,distress) else (\n let s = read_string() in\n let q = long (read_int()) in\n match s with\n |\t\"+\" -> loop (i+1) (packs ++ q) distress\n | \"-\" ->\n\tif q > packs then loop (i+1) packs (distress+1)\n\telse loop (i+1) (packs -- q) distress\n | _ -> failwith \"bad input\"\n ) in \n \n let (packs, distress) = loop 0 x 0 in\n\n printf \"%Ld %d\\n\" packs distress\n", "positive_code": [{"source_code": "open Big_int\n\nlet (+.) = add_big_int\n\nlet rec f init dis = function\n | t::q when ge_big_int t zero_big_int -> f (init +. t) dis q\n | t::q -> if lt_big_int (init +. t) zero_big_int\n then f init (dis + 1) q\n else f (init +. t) dis q\n | _ -> (init,dis)\n\nlet _ =\n let (n,init) = Scanf.scanf \"%d %s\" (fun i j -> i,big_int_of_string j) in\n let l = ref [] in\n for i = 1 to n do Scanf.scanf \" %c %d\" (fun c x ->\n l := (big_int_of_int (x * if c = '+' then 1 else -1))::!l);\n done;\n let (a,b) = f init 0 (List.rev !l) in\n Printf.printf \"%s %d\" (string_of_big_int a) b \n"}, {"source_code": "(* Codeforces 686 A Free Ice Cream *)\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);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet x = ref (Int64.of_int 0);;\nlet ndistress = ref 0;;\n\n(* c - + or -, d - nuym of ice cream *)\nlet one_step c d = \n\t(* let _ = begin print_int !x; print_string \"\\n\" end in *)\n\tif c == '+' then \n\t\tbegin\n\t\t\tx := Int64.add !x d\n\t\tend\n\telse\n \t\tif !x < d then\n \t\t\tbegin\n \t\t\t\tndistress := !ndistress + 1\n \t\t\tend\n\t\t\telse \n\t\t\t\tbegin\n\t\t \t\tx := Int64.sub !x d\n\t\t\t\tend;;\n\nlet main() =\n\tlet n = gr() in\n\tlet xx = gr () in\n\tbegin\n\t\tx := Int64.of_int xx;\n\t\tfor i = 1 to n do\n\t\t\tlet c = grc () in\n\t\t\tlet d = Int64.of_int (gr ()) in\n\t\t\tone_step c d\n\t\tdone;\n\t\tprint_string (Int64.to_string !x);\n\t\tprint_string \" \";\t\t\n\t\tprint_int !ndistress;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "let [n; x] = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nlet store = ref (Int64.of_int x)\nlet sad = ref 0\n\nlet step sign amount =\n let open Int64 in\n let amount = of_int amount in\n match sign with\n | '+' ->\n store := Int64.add !store amount\n | '-' ->\n if !store >= amount then\n store := Int64.sub !store amount\n else\n incr sad\n | _ -> assert false\n\nlet () =\n for i = 1 to n do\n Scanf.scanf \"%c %d\\n\" step\n done;\n Printf.printf \"%s %d\\n\" (Int64.to_string !store) !sad\n"}], "negative_code": [{"source_code": "let [n; x] = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nlet store = ref x\nlet sad = ref 0\n\nlet step sign amount =\n match sign with\n | '+' ->\n store := !store + amount\n | '-' ->\n if !store >= amount then\n store := !store - amount\n else\n incr sad\n | _ -> assert false\n\nlet () =\n for i = 1 to n do\n Scanf.scanf \"%c %d\\n\" step\n done;\n Printf.printf \"%d %d\\n\" !store !sad\n"}, {"source_code": "(* Codeforces 686 A Free Ice Cream *)\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);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\n\nlet x = ref 0;;\nlet ndistress = ref 0;;\n\n(* c - + or -, d - nuym of ice cream *)\nlet one_step c d = \n\t(* let _ = begin print_int !x; print_string \"\\n\" end in *)\n\tif c == '+' then \n\t\tbegin\n\t\t\tx := !x + d\n\t\tend\n\telse\n \t\tif !x < d then\n \t\t\tbegin\n \t\t\t\tndistress := !ndistress + 1\n \t\t\tend\n\t\t\telse \n\t\t\t\tbegin\n\t\t \t\tx := !x-d\n\t\t\t\tend;;\n\nlet main() =\n\tlet n = gr() in\n\tlet xx = gr () in\n\tbegin\n\t\tx := xx;\n\t\tfor i = 1 to n do\n\t\t\tlet c = grc () in\n\t\t\tlet d = gr () in\n\t\t\tone_step c d\n\t\tdone;\n\t\tprint_int !x;\n\t\tprint_string \" \";\t\t\n\t\tprint_int !ndistress;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}], "src_uid": "0a9ee8cbfa9888caef39b024563b7dcd"} {"source_code": "(* Little penguin Polo adores strings. But most of all he adores strings of length n.\n\nOne day he wanted to find a string that meets the following conditions:\n\n The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.\n No two neighbouring letters of a string coincide; that is, if we represent a string as s\u2009=\u2009s1s2... sn, then the following inequality holds, si\u2009\u2260\u2009si\u2009+\u20091(1\u2009\u2264\u2009i\u2009<\u2009n).\n Among all strings that meet points 1 and 2, the required string is lexicographically smallest.\n Help him find such string or state that such string doesn't exist.\n\n Input\n A single line contains two positive integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009106,\u20091\u2009\u2264\u2009k\u2009\u2264\u200926) \u2014 the string's length and the number of distinct letters.\n\n string.length = n, string.distinct_letters = k, string.neighbouring_letters = false *)\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n let k = read_int() in\n let s = String.create n in\n\n let answer =\n if n < k then \"-1\"\n else if n=1 then \"a\"\n else if k<2 then \"-1\"\n else (\n for i=0 to n-(k-2)-1 do\n s.[i] <- if i mod 2 = 0 then 'a' else 'b';\n done;\n for i=n-(k-2) to n-1 do\n let j = i-(n-(k-2)) in\n let c = char_of_int ((int_of_char 'c') + j) in\n s.[i] <- c;\n done;\n s\n )\n in\n print_string answer;\n print_newline();\n\n\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_pair () = let a = read_int () in (a , read_int ());;\n\nlet n , k = read_pair ();;\n\nlet ans = String.create n;;\n\nfor i = 0 to (n-1) do\n if i mod 2 = 0 then ans.[i] <- 'a'\n else ans.[i] <- 'b'\ndone;;\n\nif n = 1 && k = 1 then Printf.printf \"a\\n\"\nelse if n != 1 && k = 1 then Printf.printf \"-1\\n\"\nelse if k > n then Printf.printf \"-1\\n\"\nelse begin\n for i = (n-k+2) to (n-1) do ans.[i] <- Char.chr ((Char.code 'c') + i - (n-k+2)) done;\n Printf.printf \"%s\\n\" ans\nend ;;\n \n\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let k = read_int() in\n let s = String.create n in\n\n let answer = \n if n < k then \"-1\" \n else if n=1 then \"a\"\n else if k<2 then \"-1\"\n else (\n for i=0 to n-(k-2)-1 do\n\ts.[i] <- if i mod 2 = 0 then 'a' else 'b';\n done;\n for i=n-(k-2) to n-1 do\n\tlet j = i-(n-(k-2)) in\n\tlet c = char_of_int ((int_of_char 'c') + j) in\n\t s.[i] <- c;\n done;\n s\n )\n in\n print_string answer;\n print_newline();\n"}], "negative_code": [], "src_uid": "2f659be28674a81f58f5c587b6a0f465"} {"source_code": "(* OCaml template *)\n\n(* Utility functions *)\nlet sum = List.fold_left (+) 0;;\n\nlet aux = function\n\t| 'U' -> 'D'\n\t| 'D' -> 'U'\n\t| c -> c\n\n(* Main *)\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\t(* Solve test case here *)\n\tlet n = read_int () in\n\t\tlet s = read_line () in\n\t\t\tprint_endline @@ String.map aux s\ndone\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdin \" %s \" (fun x -> x)\nlet () = \n let cases = read_int () in\n for case = 1 to cases do\n let n = read_int() in\n let s = read_string() in\n for i=0 to n-1 do\n let y = match s.[i] with\n\t| 'L' -> 'L'\n\t| 'R' -> 'R'\n\t| 'U' -> 'D'\n\t| 'D' -> 'U'\n\t| _ -> failwith \"bad input\"\n in\n printf \"%c\" y;\n done;\n print_newline()\n done\n"}], "negative_code": [], "src_uid": "b894e16e8c00f8d97fde4a104466b3ef"} {"source_code": "open Scanf\nopen Printf\n\nlet string_replace s l r o t =\n let f i c =\n if i >= l && i <= r && c = o then\n t\n else\n c\n in\n String.mapi f s\n;;\n\nlet () =\n let (n, m) = bscanf Scanning.stdin \" %d %d\" (fun x y -> (x, y)) in\n let s = bscanf Scanning.stdin \" %s\" (fun x -> x) in\n let rec solve i result =\n if i = m\n then result\n else\n let (l, r, o, t) =\n bscanf Scanning.stdin \" %d %d %c %c\" (fun a b c d -> (a, b, c, d)) in\n let l = l-1 in\n let r = r-1 in\n let result = string_replace result l r o t in\n solve (i+1) result\n in\n printf \"%s\\n\" (solve 0 s);;\n", "positive_code": [{"source_code": "open Scanf\nopen Printf\n\nlet string_replace s l r o t =\n let f i c =\n if i >= l && i <= r && c = o then\n t\n else\n c\n in\n String.mapi f s\n;;\n\nlet () =\n let (n, m) = bscanf Scanning.stdin \" %d %d\" (fun x y -> (x, y)) in\n let s = bscanf Scanning.stdin \" %s\" (fun x -> x) in\n let rec solve i result =\n if i = m\n then result\n else\n let (l, r, o, t) =\n bscanf Scanning.stdin \" %d %d %c %c\" (fun a b c d -> (a, b, c, d)) in\n let ll = l-1 in\n let rr = r-1 in\n let tmp = string_replace result ll rr o t in\n solve (i+1) tmp\n in\n printf \"%s\\n\" (solve 0 s);;\n"}, {"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)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet () = \n let (n,m) = read_pair () in\n let s = read_string() in\n let rec loop i ac = if i=m then ac else (\n let (l,r) = read_pair() in\n let r = r-1 in\n let l = l-1 in\n let c1 = (read_string()).[0] in\n let c2 = (read_string()).[0] in\n let ac = String.init n (fun i -> if i < l || i > r then ac.[i]\n\telse if ac.[i] = c1 then c2 else ac.[i])\n in\n loop (i+1) ac\n )\n in\n\n printf \"%s\\n\" (loop 0 s)\n"}], "negative_code": [{"source_code": "open Scanf\nopen Printf\n\nlet string_replace s l r o t =\n let f i c =\n if i >= l && i <= r && c = o then\n t\n else\n s.[i] in\n String.mapi f s\n;;\n\nlet () =\n let (n, m) = bscanf Scanning.stdin \" %d %d\" (fun x y -> (x, y)) in\n let s = bscanf Scanning.stdin \" %s\" (fun x -> x) in\n let rec solve i result =\n if i = m\n then result\n else\n let (l, r, o, t) =\n bscanf Scanning.stdin \" %d %d %c %c\" (fun a b c d -> (a, b, c, d)) in\n let ll = l-1 in\n let rr = r-1 in\n let tmp = string_replace s ll rr o t in\n solve (i+1) tmp\n in\n printf \"%s\\n\" (solve 0 s);;\n"}], "src_uid": "3f97dc063286a7af4838b7cd1c01df69"} {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) ;;\n\nlet prophesy = read_string () ;;\n\nlet isdigit c = (c >= '0' && c <= '9') ;;\n\nlet months = [|0; 31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31|] ;;\n\nlet parse_date date =\n Scanf.sscanf date \"%d-%d-%d\" (fun d m y -> (d, m, y))\n \nlet valid_date date = \n let rec loop i = \n if i >= 10 then true\n else if (i = 2 || i = 5) && date.[i] = '-' then loop (i + 1)\n else if i != 2 && i != 5 && isdigit date.[i] then loop (i + 1)\n else false\n in if (loop 0) = false then false \n else let (d, m, y) = parse_date date\n in y >= 2013 && y <= 2015 && m > 0 && m <= 12 && d > 0 && d <= months.(m) ;;\n\nlet freq = \n let matrix = Array.make 32 (Array.make_matrix 13 2016 0) in\n for i = 0 to 31 do\n matrix.(i) <- Array.make_matrix 13 2016 0\n done ;\n matrix ;;\n\nlet apocalypse = \n let rec loop i date count =\n if i > (String.length prophesy) - 10 then date\n else \n let cur_date = String.sub prophesy i 10 \n in if valid_date cur_date then let (d, m, y) = parse_date cur_date \n in \n (\n freq.(d).(m).(y) <- freq.(d).(m).(y) + 1 ;\n if freq.(d).(m).(y) > count then \n loop (i + 1) cur_date freq.(d).(m).(y)\n else\n loop (i + 1) date count\n ) \n else loop (i + 1) date count\n in loop 0 \"\" 0 ;;\n\nPrintf.printf \"%s\\n\" apocalypse ;;", "positive_code": [{"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet days = [|31;28;31;30;31;30;31;31;30;31;30;31|]\n\nlet is_digit c = c >= '0' && c <= '9'\n\nlet valid_date s =\n (List.for_all (fun p -> is_digit s.[p]) [0;1;3;4;6;7;8;9]) &&\n (List.for_all (fun p -> s.[p] = '-') [2;5]) &&\n (\n let d = int_of_string (String.sub s 0 2) in\n let m = int_of_string (String.sub s 3 2) in\n let y = int_of_string (String.sub s 6 4) in\n\tm>=1 && m<=12 && d>=1 && d<=days.(m-1) && y>=2013 && y<=2015\n )\n \nlet () = \n let s = read_string () in\n let n = String.length s in\n\n let h = Hashtbl.create 10 in\n\n let increment t = \n let c = try Hashtbl.find h t with Not_found -> 0 in\n Hashtbl.replace h t (c+1)\n in\n \n for i=0 to n-10 do\n let t = String.sub s i 10 in\n\tif valid_date t then increment t\n done;\n\n let m = Hashtbl.fold (fun _ c ac -> max c ac) h 0 in\n\n let t = Hashtbl.fold (fun s c ac -> if c = m then s else ac) h \"\" in\n\n Printf.printf \"%s\\n\" t\n"}], "negative_code": [{"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) ;;\n\nlet prophesy = read_string () ;;\n\nlet isdigit c = (c >= '0' && c <= '9') ;;\n\nlet months = [|0; 31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31|] ;;\n\nlet parse_date date =\n Scanf.sscanf date \"%d-%d-%d\" (fun d m y -> (d, m, y))\n \nlet valid_date date = \n let rec loop i = \n if i >= 10 then true\n else if (i = 2 || i = 5) && date.[i] = '-' then loop (i + 1)\n else if i != 2 && i != 5 && isdigit date.[i] then loop (i + 1)\n else false\n in if (loop 0) = false then false \n else let (d, m, y) = parse_date date\n in y >= 2013 && y <= 2015 && m > 0 && m <= 12 && d > 0 && d <= months.(m) ;;\n\nlet freq = Array.make 32 (Array.make_matrix 13 2016 0) ;;\n\nlet apocalypse = \n let rec loop i date count =\n if i > (String.length prophesy) - 10 then date\n else \n let cur_date = String.sub prophesy i 10 \n in if valid_date cur_date then let (d, m, y) = parse_date cur_date \n in \n (\n freq.(d).(m).(y) <- freq.(d).(m).(y) + 1 ;\n if freq.(d).(m).(y) >= count then \n loop (i + 1) cur_date freq.(d).(m).(y)\n else\n loop (i + 1) date count\n ) \n else loop (i + 1) date count\n in loop 0 \"\" 0 ;;\n\nPrintf.printf \"%s\\n\" apocalypse ;;"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) ;;\n\nlet prophesy = read_string () ;;\n\nlet isdigit c = (c >= '0' && c <= '9') ;;\n\nlet months = [|0; 31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31|] ;;\n\nlet parse_date date =\n Scanf.sscanf date \"%d-%d-%d\" (fun d m y -> (d, m, y))\n \nlet valid_date date = \n let rec loop i = \n if i >= 10 then true\n else if (i = 2 || i = 5) && date.[i] = '-' then loop (i + 1)\n else if i != 2 && i != 5 && isdigit date.[i] then loop (i + 1)\n else false\n in if (loop 0) = false then false \n else let (d, m, y) = parse_date date\n in y >= 2013 && y <= 2015 && m > 0 && m <= 12 && d > 0 && d <= months.(m) ;;\n\nlet freq = Array.make 32 (Array.make_matrix 13 2016 0) ;;\n\nlet apocalypse = \n let rec loop i date count =\n if i > (String.length prophesy) - 10 then date\n else \n let cur_date = String.sub prophesy i 10 \n in if valid_date cur_date then let (d, m, y) = parse_date cur_date \n in \n (\n freq.(d).(m).(y) <- freq.(d).(m).(y) + 1 ;\n if freq.(d).(m).(y) > count then \n loop (i + 1) cur_date freq.(d).(m).(y)\n else\n loop (i + 1) date count\n ) \n else loop (i + 1) date count\n in loop 0 \"\" 0 ;;\n\nPrintf.printf \"%s\\n\" apocalypse ;;"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet days = [|31;28;31;30;31;30;31;31;30;31;31;31|]\n\nlet is_digit c = c >= '0' && c <= '9'\n\nlet valid_date s =\n (List.for_all (fun p -> is_digit s.[p]) [0;1;3;4;6;7;8;9]) &&\n (List.for_all (fun p -> s.[p] = '-') [2;5]) &&\n (\n let d = int_of_string (String.sub s 0 2) in\n let m = int_of_string (String.sub s 3 2) in\n let y = int_of_string (String.sub s 6 4) in\n\tm>=1 && m<=12 && d>=1 && d<=days.(m-1) && y>=2013 && y<=2015\n )\n \nlet () = \n let s = read_string () in\n let n = String.length s in\n\n let h = Hashtbl.create 10 in\n\n let increment t = \n let c = try Hashtbl.find h t with Not_found -> 0 in\n Hashtbl.replace h t (c+1)\n in\n \n for i=0 to n-10 do\n let t = String.sub s i 10 in\n\tif valid_date t then increment t\n done;\n\n let m = Hashtbl.fold (fun _ c ac -> max c ac) h 0 in\n\n let t = Hashtbl.fold (fun s c ac -> if c = m then s else ac) h \"\" in\n\n Printf.printf \"%s\\n\" t\n"}], "src_uid": "dd7fd84f7915ad57b0e21f416e2a3ea0"} {"source_code": "open Scanf;;\nopen String;;\n\ntype cell = RC | NRC;;\n\nlet print_cell t = match t with\n RC -> print_endline \"RC\"\n |NRC -> print_endline \"NRC\"\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet ntostring=[|\"A\";\"B\";\"C\";\"D\";\"E\";\"F\";\"G\";\"H\";\"I\";\"J\";\"K\";\"L\";\"M\";\"N\";\"O\";\"P\";\"Q\";\"R\";\"S\";\"T\";\"U\";\"V\";\"W\";\"X\";\"Y\";\"Z\"|];;\n\nlet myindex s c = try index s c with Not_found -> -100;;\n\nlet is_digit = function\n '0'..'9' -> true\n |_ -> false;;\n\nlet rec digit_index x ind =\n let len = length x in\n match len with\n | 0 -> ind\n | _ -> match get x 0 with\n | '0' .. '9' -> ind\n |_ -> digit_index (sub x 1 (len - 1) ) (ind + 1)\n;;\nlet rec process_RC x = \n let (rown,coln) = get_num x in\n print_string (convert_to_AB coln); print_string (string_of_int rown); print_endline \"\";\nand get_num x = let m = index x 'C' in\n let tmp = (length x) - m -1 in\n let tmp1 = match tmp with\n | x when x <=0 -> 1\n |_ -> int_of_string (sub x (m+1) tmp)\n in\n (int_of_string (sub x 1 (m-1)), tmp1)\nand convert_to_AB x = \n let y = ref x in\n let ss = ref \"\" in\n let () = \n while !y > 0 do\n let tmp = ((!y-1) mod 26) in\n y := (!y - tmp - 1) / 26;\n ss := ntostring.(tmp) ^ !ss\n done in !ss;;\n\nlet rec process_NRC x = \n let (ab,row) = get_content x in\n print_char 'R'; print_string (string_of_int row); print_char 'C';\n print_string(string_of_int (convert_to_int ab)); \n print_endline \"\";\nand get_content x =\n let m = digit_index x 0 in\n let tmp=(length x) -m in\n let tmp2 = match tmp with\n |0 -> 1\n |_ -> int_of_string (sub x m tmp) in\n (sub x 0 m, tmp2)\nand convert_to_int x = \n let k = ref ((length x) - 1) in\n let mul = ref 1 in\n let acc = ref 0 in\n let nA = int_of_char 'A' in\n let () =\n while !k >=0 do\n let f = get x !k in\n let g = (int_of_char f) - nA + 1 in\n acc := !acc + g*(!mul); mul:= !mul* 26; k:=!k-1\n done in !acc\n;;\n\nlet process t s = match t with\n RC -> process_RC s\n |NRC -> process_NRC s\n;;\n\nfor i=1 to n do\n let ms = ref (String.make 32 'A') in\n let () = \n ms := Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) \n in\n let t = match (myindex !ms 'R', myindex !ms 'C') with\n | (-100, _) -> NRC\n | (_,-100) -> NRC\n | (a, b) -> if b - a > 1 && (is_digit (get !ms (a+1))) then RC else NRC\n in (*print_string ! ms; print_string \" : \";*) process t !ms\ndone;; \n\n", "positive_code": [{"source_code": "let (|>) x f = f x\n\nlet is_letter char =\n match char with\n 'A'..'Z' -> true\n | _ -> false\n\nlet is_digit char =\n match char with\n '0'..'9' -> true\n | _ -> false\n\nlet parse_pair s pos =\n let rec parse pred p =\n if p < String.length s && pred (String.get s p)\n then parse pred (p+1)\n else p\n in\n let pos1 = parse is_letter pos in\n let pos2 = parse is_digit pos1 in\n ((String.sub s pos (pos1 - pos), String.sub s pos1 (pos2 - pos1)), pos2)\n\nlet colrow_to_rowcol (col, row) =\n let int_of_letters letters =\n let res = ref 0 in\n String.iter (fun c -> res := !res * 26 + (int_of_char c) - 64) letters;\n !res\n in\n Printf.sprintf \"R%dC%d\" (int_of_string row) (int_of_letters col)\n\nlet rowcol_to_colrow (_, row) (_, col) =\n let rec letters_of_int n acc =\n if n = 0\n then acc\n else letters_of_int ((n-1) / 26) ((String.make 1 (char_of_int (65 + ((n-1) mod 26)))) ^ acc)\n in\n Printf.sprintf \"%s%s\" (letters_of_int (int_of_string col) \"\") row\n\nlet convert s =\n let pair1, pos = parse_pair s 0 in\n if pos = String.length s\n then colrow_to_rowcol pair1\n else let pair2, _ = (parse_pair s pos) in\n rowcol_to_colrow pair1 pair2\n\nlet iterate n =\n for i = 1 to n do\n read_line ()\n |> convert\n |> Printf.printf \"%s\\n\"\n done\n\nlet _= \n read_int ()\n |> iterate\n"}, {"source_code": "let rec split num str =\n match str with\n | \"\" -> []\n | s -> \n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one):: (returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one)::[]\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\nlet rec checkInCHere str =\n match str with\n | \"\" -> false\n | s -> \n if (compare (String.sub s 0 1) \"C\" == 0)\n then true\n else if (Char.code(String.get s 0) > 64) then false\n else checkInCHere (String.sub s 1 (String.length s - 1))\n\nlet checkIsRC str =\n match str with\n | \"\" -> false\n | s ->\n if (compare (String.sub str 0 1) \"R\" == 0) && (Char.code(String.get s 1)<65)\n then checkInCHere (String.sub str 2 (String.length str - 2))\n else false\n\nlet rec reverseList li o =\n match li with \n | [] -> o\n | h :: t -> reverseList t (h :: o)\n\nlet returnConvertedCol k =\n let rec returnIt s =\n if (s > 0) then\n let n = s / 26 in\n let r = s mod 26 in\n (string_of_int r) :: returnIt n\n else [] in\n reverseList (returnIt (int_of_string k)) []\n\nlet returnConvertedRow n =\n let rec returnIt s =\n let k = s mod 26 in\n if (s > 0) then\n if (k == 0) then 'Z' :: (returnIt((s-26)/26))\n else\n (Char.chr (k+64)) :: (returnIt (s/26))\n else\n [] in\n reverseList (returnIt (int_of_string n)) []\n\nlet rec printList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_string h; printList t\n\nlet rec printCharList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_char h; printCharList t\n\nlet changeRCToAlph line =\n let rec newline l row col=\n if (compare (String.sub l 0 1) \"C\") == 0 then\n (row, String.sub l 1 (String.length l -1))\n else\n let newRow = row ^ (String.sub l 0 1) in\n newline (String.sub l 1 (String.length l -1))\n newRow col in\n let (r,c) = newline line \"\" \"\" in\n let rList = returnConvertedRow c in\n printCharList rList; print_string r; print_string \"\\n\"\n\nlet changeStringToAscii n =\n let rec returnStringToNum str num =\n match str with\n | \"\" -> num\n | s ->\n returnStringToNum (String.sub s 1 (String.length str - 1))\n ((Char.code(String.get s 0) - 64) + 26*num) in\n string_of_int (returnStringToNum n 0)\n\n\nlet changeAlphToRC line =\n let rec newline l row =\n if Char.code(String.get l 0) < 65 then\n (row, l)\n else \n newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in\n let (r,c) = newline line \"\" in\n print_char 'R';print_string c;print_char 'C';\n print_string(changeStringToAscii r);print_string\"\\n\"\n\nlet n = read_int()\n\nlet check line =\n if (checkIsRC line) then\n changeRCToAlph(String.sub line 1 (String.length line -1))\n else\n changeAlphToRC line\n\nlet rec strList num =\n if (num > 0) then\n let k = read_line() in\n let _ = check k in\n strList (num-1)\n else\n print_string\"\"\nlet _ = strList n\n"}, {"source_code": "open Printf\nopen Scanf\n\ntype coord = \n | RC of int * int (* row, column *)\n | Concat of string * int (* column, row *)\n\nlet parse: string -> coord =\n fun s ->\n if (Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0) then\n let sep = Str.search_forward (Str.regexp \"C[0-9]+\") s 0 in\n let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in\n let b = int_of_string (Str.string_after s (sep + 1)) in\n RC (a, b) \n else\n let sep = Str.search_forward (Str.regexp \"[0-9]+\") s 0 in\n let a = Str.string_before s sep in\n let b = int_of_string (Str.string_after s sep) in\n Concat (a, b)\n\nlet pp: coord -> string =\n fun c ->\n match c with\n | RC(a, b) -> \"R\" ^ (string_of_int a) ^ \"C\" ^ (string_of_int b)\n | Concat(a, b) -> a ^ (string_of_int b)\n\nlet translate: coord -> coord =\n let char_to_num c = (Char.code c) - (Char.code 'A') + 1in\n let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in\n let num_to_str_system n =\n let rec inner i s =\n let d = i / 26\n and r = i mod 26 in\n if d > 0 then\n if r = 0 then\n if d > 1 then\n inner (d - 1) ((String.make 1 'Z') ^ s)\n else ((String.make 1 'Z') ^ s)\n else\n inner d ((String.make 1 (num_to_char r)) ^ s)\n else\n (String.make 1 (num_to_char r)) ^ s\n in\n inner n \"\"\n in\n let str_to_num_system s =\n let rec inner s = \n if (String.length s > 1) then\n (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))\n else\n (char_to_num s.[String.length s - 1])\n in\n inner s\n in\n fun c ->\n match c with\n | RC(a, b) -> Concat(num_to_str_system b, a)\n | Concat(a, b) -> RC(b, str_to_num_system a)\n\nlet main () =\n let input = input_line stdin in\n let n = sscanf input \"%i\" (fun x -> x) in\n for i = 1 to n do\n let input = input_line stdin in\n let s = sscanf input \"%s\" (fun x -> x) in\n let c = parse s in\n let t = translate c in\n printf \"%s\\n\" (pp t);\n done\n\nlet _ = main ()\n"}, {"source_code": "let (|>) x f = f x\n\nlet rc2xls r c =\n let rec go c acc =\n if c = 0 then\n String.concat \"\" acc\n else\n let t = (c-1) mod 26 in\n go ((c-t-1)/26) (String.make 1 (Char.chr (t+65))::acc)\n in String.concat \"\" [go c []; string_of_int r]\n\nlet foldl f acc s =\n let n = String.length s in\n let rec go i acc =\n if i >= n then\n acc\n else\n go (i+1) (f acc s.[i])\n in go 0 acc\n\nlet xls2rc r c =\n String.concat \"\" [\"R\"; string_of_int c; \"C\"; string_of_int (foldl (fun acc x -> acc*26+(Char.code x-64)) 0 r)]\n\nlet () =\n for i = 1 to read_int () do\n let s = read_line () in\n try\n Scanf.sscanf s \"R%dC%d\" (fun r c ->\n rc2xls r c |> print_endline\n )\n with _ ->\n Scanf.sscanf s \"%[A-Z]%d\" (fun r c ->\n xls2rc r c |> print_endline\n )\n done\n"}, {"source_code": "let n = read_int () ;;\nlet r = Str.regexp \"R[0-9]+C[0-9]+\" ;;\nfor i = 1 to n do\n let coord = read_line () in\n let is_first = Str.string_match r coord 0 in\n if is_first then begin\n let coords = Str.split (Str.regexp \"[A-Z]\") coord in\n let col = int_of_string (List.nth coords 0) in\n let row = int_of_string (List.nth coords 1) in\n let buf1 = Buffer.create 1000 in\n let rec rstring num buf = \n let r = num mod 26 in\n if (num/26) = 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n Buffer.contents buf\n end\n else if r != 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n rstring (num/26) buf\n end\n else if ((num-1)/26) != 0 then begin\n let _ = Buffer.add_char buf 'Z' in\n rstring ((num-1)/26) buf\n end\n else begin\n let _ = Buffer.add_char buf 'Z' in\n Buffer.contents buf\n end in\n\n let rec rev s =\n let sl = String.length s in\n for j=0 to (sl-1)/2 do\n let c = s.[j] in\n s.[j] <- s.[sl-j-1];\n s.[sl-j-1] <- c;\n done;\n s in\n let row_s = rev (rstring (row) (Buffer.create 2)) in\n let _ = Printf.printf \"%s%d\\n\" row_s col in\n\n\n row\n end\n else begin\n let rec row str j runner = \n let fchar = Char.code str.[j] in\n let schar = Char.code str.[j+1] in\n if schar >= 65 then\n let runner = runner + fchar-64 in\n row str (j+1) (runner*26) \n else\n runner + fchar - 64 in\n let rnum = row coord 0 0 in\n let cpos = Str.search_forward (Str.regexp \"[0-9]+\") coord 0 in\n (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in\n *)\n let cstring = Str.matched_string coord in\n let cint = int_of_string cstring in\n let _ = Printf.printf \"R%dC%d\\n\" cint rnum in\n 1\n end\ndone;\n"}, {"source_code": "open Char;;\nopen String;;\n\nlet letters_of_num col =\n let rec letters_of_num' col =\n if col < 26 then Char.escaped (chr (col + code 'A'))\n else (letters_of_num' (col / 26 - 1)) ^ (letters_of_num' (col mod 26)) in\n letters_of_num' (col - 1);;\n\nlet solve_1 row col = letters_of_num (int_of_string col) ^ row;;\n\n\nlet rec pow a = function\n | 0 -> 1\n | 1 -> a\n | n ->\n let b = pow a (n / 2) in\n b * b * (if n mod 2 = 0 then 1 else a);;\n\nlet num_of_letters ls =\n let rec num_of_letters' ls =\n if length ls == 1 then code (get ls 0) - code 'A'\n else\n let hd = sub ls 0 1 in\n let tl = sub ls 1 ((length ls) - 1) in\n (pow 26 (length ls - 1)) * (1 + num_of_letters' hd) + (num_of_letters' tl) in\n num_of_letters' ls + 1;;\n\n\nlet solve_2 row col = \"R\" ^ row ^ \"C\" ^ (string_of_int (num_of_letters col));;\n\n\n\n\nlet solve: string -> string = fun s ->\n let open Str in\n let r_1 = regexp \"^R\\\\([0-9]+\\\\)C\\\\([0-9]+\\\\)$\" in\n let r_2 = regexp \"^\\\\([A-Z]+\\\\)\\\\([0-9]+\\\\)$\" in\n if (string_match r_1 s 0) then (solve_1 (Str.matched_group 1 s) (Str.matched_group 2 s))\n else if string_match r_2 s 0 then solve_2 (Str.matched_group 2 s) (Str.matched_group 1 s)\n else raise (Failure \"Unknown format\");;\n\n\n\nlet rec iter i max =\n if i < max then\n let s = input_line stdin in\n (print_string (solve s); print_newline (); iter (succ i) max)in\niter 0 (int_of_string (input_line stdin));;\n"}, {"source_code": "let get_int () = \nlet n = ref 0 in\nlet c = ref(input_char(stdin)) in\ntry\nwhile !c >= '0' && !c <= '9' do\n n := !n * 10 + (int_of_char !c - int_of_char '0');\n c := input_char(stdin)\ndone;\nn;\nwith End_of_file -> n;;\n\nlet int_of_column_header str =\nlet n = ref 0 in\nlet i = ref 0 in\ntry\nwhile str.[!i] >= 'A' && str.[!i] <= 'Z' do\n n := !n * 26 + (int_of_char str.[!i] - int_of_char 'A' + 1);\n i := !i + 1\ndone;\n(!n,!i);\nwith End_of_file -> (!n,!i);;\n\nlet column_header_of_int n =\n let s = ref \"\" in\n let nref = ref n in\n while !nref > 0 do\n s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;\n nref := (!nref-1)/26;\n done;\n !s;;\n\nlet n = get_int() in\n\nwhile !n > 0 do\n\nlet str = read_line() in\nlet cindex = try String.index str 'C' with Not_found -> -1 in\nlet alt_form = if str.[0] = 'R' && (str.[1] >= '0' && str.[1] <= '9') && (cindex >= 0) then column_header_of_int(int_of_string(String.sub str (cindex + 1) (String.length str - cindex - 1))) ^ (String.sub str 1 (cindex - 1)) else let (n,i) = int_of_column_header str in \"R\" ^ (String.sub str i (String.length str - i)) ^ \"C\" ^ string_of_int n in \nprint_endline(alt_form);\n\nn := !n - 1\n\ndone;;"}, {"source_code": "let rc_format coordinate = \n let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in\n if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then\n\t(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))\n else\n\t(false, -1, -1)\n\nlet excel_format coordinate =\n let rec decode_column c pos =\n\tif coordinate.[pos] < 'A' then\n\t (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)\n\telse\n\t decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)\n in\n decode_column 0 0\n\nlet to_excel_format r c =\n let rec encode_column c = \n\tif c > 0 then\n\t (encode_column ((c - 1) / 26)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + ((c - 1) mod 26))))\n\telse\n\t \"\"\n in\n (encode_column c) ^ (string_of_int r)\n\nlet to_rc_format r c =\n \"R\" ^ (string_of_int r) ^ \"C\" ^ (string_of_int c)\n\nlet () =\n for n = read_int () downto 1 do\n\tlet coordinate = read_line () in\n\tlet (is_rc_format, x, y) = rc_format coordinate in\n\tif is_rc_format then\n\t Printf.printf \"%s\" (to_excel_format x y)\n\telse (\n\t (* Printf.printf \"hooray!!!\"; *)\n\t let (x, y) = excel_format coordinate in\n\t Printf.printf \"%s\" (to_rc_format x y)\n\t);\n\tprint_newline()\n done\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc last_div n =\n if n <= 26\n then (\n if not last_div && ((String.length acc > 0) && ((String.get acc 0) = 'Z')) && (char_at_pos ((n-1) mod 26)) == 'Z'\n then acc\n else if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else\n if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n in aux \"\" false col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "let ia = int_of_char 'A' in\nlet isrc str = \n if str.[0] <> 'R' then failwith \"Wrong\"\n else let p = String.index_from str 2 'C' in (true, int_of_string (String.sub str (p + 1) (String.length str - p - 1)), int_of_string (String.sub str 1 (p - 1)))\nand isan str =\n let rec strip_al ald pos = \n if str.[pos] < 'A' then (ald, pos) else strip_al (26 * ald + (int_of_char str.[pos] - ia + 1)) (pos + 1) \n in\n let (ra, rp) = strip_al 0 0\n in\n (false, ra, int_of_string (String.sub str rp (String.length str - rp)))\nand oprc y x =\n print_char 'R'; print_int x; print_char 'C'; print_int y\nand opan x y =\n let rec px x = if x > 0 then let _ = px ((x - 1) / 26) in print_char (char_of_int ((x - 1) mod 26 + ia)) else () in\n px x; print_int y\nin\nfor lc = (read_int ()) downto 1 do\n let line = read_line () in\n let (is_rc, x, y) = try isrc line with _ -> isan line in\n (if is_rc then opan else oprc) x y; print_newline ()\ndone\n"}, {"source_code": "let read_line_of_strings () =\n read_line () |> Str.split (Str.regexp \" +\")\n\nlet read_line_of f =\n read_line_of_strings () |> List.map f\n\nlet read_line_of_floats () =\n read_line_of float_of_string\n\nlet coordinates_of_string input =\n let rx1 = Str.regexp \"^R\\\\([0-9]+\\\\)C\\\\([0-9]+\\\\)$\" in\n let rx2 = Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([0-9]+\\\\)$\" in\n if Str.string_match rx1 input 0 then\n let row = Str.matched_group 1 input in\n let col = Str.matched_group 2 input in\n `RC (int_of_string row, int_of_string col)\n else if Str.string_match rx2 input 0 then\n let col = Str.matched_group 1 input in\n let row = Str.matched_group 2 input in\n `A1 (int_of_string row, col)\n else\n raise (Invalid_argument input)\n\nlet name_to_int name =\n let len = String.length name in\n let sum = ref 0 in\n let acc = ref 1 in\n for i = len - 1 downto 0 do\n sum := !sum + (Char.code name.[i] - 64) * !acc;\n acc := !acc * 26;\n done;\n !sum\n\nlet to_char k =\n String.make 1 (Char.chr k)\n\nlet int_to_name n =\n let rec iter dividend name =\n if dividend > 0 then\n let modulo = (dividend - 1) mod 26 in\n let next_char = to_char (65 + modulo) in\n iter ((dividend - modulo) / 26) (next_char ^ name)\n else\n name\n in\n iter n \"\"\n\nlet solve = function\n | `RC (row, col) -> Printf.sprintf \"%s%d\" (int_to_name col) row\n | `A1 (row, col) -> Printf.sprintf \"R%dC%d\" row (name_to_int col)\n\nlet convert input =\n solve (coordinates_of_string input)\n\nlet () =\n let [count] = read_line_of int_of_string in\n for i = 1 to count do\n read_line_of coordinates_of_string\n |> List.iter (fun task -> Printf.printf \"%s\\n\" (solve task))\n done;\n"}, {"source_code": "type mode =\n S0\n | S1 of string\n | S2 of string * int\n | S3\n | S4 of int\n | S5 of int\n | S6 of int * int\n\ntype ('a, 'b) either = Left of 'a | Right of 'b\n\nlet _ =\n let n = read_int () in\n let c2s c = String.make 1 c in\n let s2i s =\n let l = String.length s in\n let rec loop i acc =\n if i = l then acc else loop (i + 1) (acc * 26 + int_of_char s.[i] - 64)\n in\n loop 0 0\n in\n let i2s a =\n let rec loop i acc =\n if i = 0 then acc else loop ((i - 1) / 26) (c2s (char_of_int (((i - 1)mod 26) + 65)) ^ acc)\n in\n loop a \"\"\n in\n let conv s =\n let s = s ^ \".\" in\n let rec loop i mode =\n match mode, s.[i] with\n | S0, 'R' -> loop (i + 1) S3\n | S0, k -> loop (i + 1) (S1 (c2s k))\n | S1 a, ('0' .. '9' as k) -> loop (i + 1) (S2 (a, int_of_char k - 48))\n | S1 a, k -> loop (i + 1) (S1 (a ^ c2s k))\n | S2 (a, b), '.' -> Left (a, b)\n | S2 (a, b), ('0' .. '9' as k) -> loop (i + 1) (S2 (a, b * 10 + int_of_char k - 48))\n | S3, ('0' .. '9' as k) -> loop (i + 1) (S4 (int_of_char k - 48))\n | S3, k -> loop (i + 1) (S1 (\"R\" ^ c2s k))\n | S4 a, ('0' .. '9' as k) -> loop (i + 1) (S4 (a * 10 + int_of_char k - 48))\n | S4 a, '.' -> Left (\"R\", a)\n | S4 a, 'C' -> loop (i + 1) (S5 a)\n | S5 a, ('0' .. '9' as k) -> loop (i + 1) (S6 (a, int_of_char k - 48))\n | S6 (a, b), ('0' .. '9' as k) -> loop (i + 1) (S6 (a, b * 10 + int_of_char k - 48))\n | S6 (a, b), '.' -> Right (a, b)\n | _ -> failwith \"Illegal transition\"\n in\n match loop 0 S0 with\n | Left (a, b) -> Printf.sprintf \"R%dC%d\" b (s2i a)\n | Right (a, b) -> Printf.sprintf \"%s%d\" (i2s b) a\n in\n for i = 1 to n do\n let s = read_line () in\n print_endline (conv s)\n done\n"}, {"source_code": "let rec base_26 a = \n if a = 0 then [0]\n else if a < 0 then []\n else (a mod 26) :: (base_26 (a / 26 - 1))\n\nlet inv26 a = \n let n = String.length a in\n let r = ref 0 in\n for i = 0 to (n-1) do \n r := !r * 26 + (Char.code a.[i] - 64)\n done;\n !r\n\nlet rec implode lc = \n match lc with\n |[] -> \"\"\n |c::t -> Printf.sprintf \"%c%s\" c (implode t)\n\nlet convert_nb n = \n let n = int_of_string n in\n let l = List.rev (base_26 (n - 1)) in\n implode (List.map (fun n -> Char.chr (n + 65)) l)\n\nlet () = \n let s = read_line () in \n let n = int_of_string s in\n for i = 0 to (n-1) do \n let s = read_line () in \n if Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0 then begin\n let s = String.sub s 1 (String.length s - 1) in\n let [a;b] = Str.split (Str.regexp \"C\") s in\n Printf.printf \"%s%s\\n\" (convert_nb b) a\n end else begin\n ignore (Str.search_forward (Str.regexp \"[A-Z]+\") s 0);\n let a = Str.matched_string s in\n ignore (Str.search_forward (Str.regexp \"[0-9]+\") s 0);\n let b = Str.matched_string s in\n Printf.printf \"R%sC%i\\n\" b (inv26 a) \n end\n done;\n"}], "negative_code": [{"source_code": "let rec base_26 a = \n if a = 0 then []\n else (a mod 26) :: (base_26 (a / 26))\n\nlet inv26 a = \n let n = String.length a in\n let r = ref 0 in\n for i = 0 to (n-1) do \n r := !r * 26 + (Char.code a.[i] - 64)\n done;\n !r\n\nlet rec implode lc = \n match lc with\n |[] -> \"\"\n |c::t -> Printf.sprintf \"%c%s\" c (implode t)\n\nlet convert_nb n = \n let n = int_of_string n in\n let l = if n = 1 then [0] else (base_26 (n - 1)) in\n let l = List.rev ((List.hd l + 1) :: (List.tl l)) in\n implode (List.map (fun n -> Char.chr (n + 64)) l)\n\nlet () = \n let s = read_line () in \n let n = int_of_string s in\n for i = 0 to (n-1) do \n let s = read_line () in \n if Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0 then begin\n let s = String.sub s 1 (String.length s - 1) in\n let [a;b] = Str.split (Str.regexp \"C\") s in\n Printf.printf \"%s%s\\n\" (convert_nb b) a\n end else begin\n ignore (Str.search_forward (Str.regexp \"[A-Z]+\") s 0);\n let a = Str.matched_string s in\n ignore (Str.search_forward (Str.regexp \"[0-9]+\") s 0);\n let b = Str.matched_string s in\n Printf.printf \"R%sC%i\\n\" b (inv26 a) \n end\n done;\n"}, {"source_code": "let rec base_26 a = \n if a <= 0 then []\n else (a mod 26) :: (base_26 (a / 26 - 1))\n\nlet inv26 a = \n let n = String.length a in\n let r = ref 0 in\n for i = 0 to (n-1) do \n r := !r * 26 + (Char.code a.[i] - 64)\n done;\n !r\n\nlet rec implode lc = \n match lc with\n |[] -> \"\"\n |c::t -> Printf.sprintf \"%c%s\" c (implode t)\n\nlet convert_nb n = \n let n = int_of_string n in\n let l = if n = 1 then [0] else List.rev (base_26 (n - 1)) in\n implode (List.map (fun n -> Char.chr (n + 65)) l)\n\nlet () = \n let s = read_line () in \n let n = int_of_string s in\n for i = 0 to (n-1) do \n let s = read_line () in \n if Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0 then begin\n let s = String.sub s 1 (String.length s - 1) in\n let [a;b] = Str.split (Str.regexp \"C\") s in\n Printf.printf \"%s%s\\n\" (convert_nb b) a\n end else begin\n ignore (Str.search_forward (Str.regexp \"[A-Z]+\") s 0);\n let a = Str.matched_string s in\n ignore (Str.search_forward (Str.regexp \"[0-9]+\") s 0);\n let b = Str.matched_string s in\n Printf.printf \"R%sC%i\\n\" b (inv26 a) \n end\n done;\n"}, {"source_code": "open Printf\nopen Scanf\n\ntype coord = \n | RC of int * int (* row, column *)\n | Concat of string * int (* column, row *)\n\nlet parse: string -> coord =\n fun s ->\n if (Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0) then\n let sep = Str.search_forward (Str.regexp \"C[0-9]+\") s 0 in\n let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in\n let b = int_of_string (Str.string_after s (sep + 1)) in\n RC (a, b) \n else\n let sep = Str.search_forward (Str.regexp \"[0-9]+\") s 0 in\n let a = Str.string_before s sep in\n let b = int_of_string (Str.string_after s sep) in\n Concat (a, b)\n\nlet pp: coord -> string =\n fun c ->\n match c with\n | RC(a, b) -> \"R\" ^ (string_of_int a) ^ \"C\" ^ (string_of_int b)\n | Concat(a, b) -> a ^ (string_of_int b)\n\nlet translate: coord -> coord =\n let char_to_num c = (Char.code c) - (Char.code 'A') + 1in\n let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in\n let num_to_str_system n =\n let rec inner i s =\n let d = i / 26\n and r = i mod 26 in\n if d > 0 then\n if r = 0 then\n inner (d - 1) ((String.make 1 'Z') ^ s)\n else\n inner d ((String.make 1 (num_to_char r)) ^ s)\n else\n (String.make 1 (num_to_char r)) ^ s\n in\n inner n \"\"\n in\n let str_to_num_system s =\n let rec inner s = \n if (String.length s > 1) then\n (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))\n else\n (char_to_num s.[String.length s - 1])\n in\n inner s\n in\n fun c ->\n match c with\n | RC(a, b) -> Concat(num_to_str_system b, a)\n | Concat(a, b) -> RC(b, str_to_num_system a)\n\nlet main () =\n let input = input_line stdin in\n let n = sscanf input \"%i\" (fun x -> x) in\n for i = 1 to n do\n let input = input_line stdin in\n let s = sscanf input \"%s\" (fun x -> x) in\n let c = parse s in\n let t = translate c in\n printf \"%s\\n\" (pp t);\n done\n\nlet _ = main ()\n"}, {"source_code": "open Printf\nopen Scanf\n\ntype coord = \n | RC of int * int (* row, column *)\n | Concat of string * int (* column, row *)\n\nlet parse: string -> coord =\n fun s ->\n if (Str.string_match (Str.regexp \"R[0-9]+C[0-9]+\") s 0) then\n let sep = Str.search_forward (Str.regexp \"C[0-9]+\") s 0 in\n let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in\n let b = int_of_string (Str.string_after s (sep + 1)) in\n RC (a, b) \n else\n let sep = Str.search_forward (Str.regexp \"[0-9]+\") s 0 in\n let a = Str.string_before s sep in\n let b = int_of_string (Str.string_after s sep) in\n Concat (a, b)\n\nlet pp: coord -> string =\n fun c ->\n match c with\n | RC(a, b) -> \"R\" ^ (string_of_int a) ^ \"C\" ^ (string_of_int b)\n | Concat(a, b) -> a ^ (string_of_int b)\n\nlet translate: coord -> coord =\n let char_to_num c = (Char.code c) - (Char.code 'A') + 1in\n let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in\n let num_to_str_system n =\n let rec inner i s =\n let d = i / 26\n and r = i mod 26 in\n if d > 0 then\n inner d ((String.make 1 (num_to_char r)) ^ s)\n else\n (String.make 1 (num_to_char r)) ^ s\n \n in\n inner n \"\"\n in\n let str_to_num_system s =\n let rec inner s = \n if (String.length s > 1) then\n (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))\n else\n (char_to_num s.[String.length s - 1])\n in\n inner s\n in\n fun c ->\n match c with\n | RC(a, b) -> Concat(num_to_str_system b, a)\n | Concat(a, b) -> RC(b, str_to_num_system a)\n\nlet main () =\n let input = input_line stdin in\n let n = sscanf input \"%i\" (fun x -> x) in\n for i = 1 to n do\n let input = input_line stdin in\n let s = sscanf input \"%s\" (fun x -> x) in\n let c = parse s in\n let t = translate c in\n printf \"%s\\n\" (pp t);\n done\n\nlet _ = main ()\n"}, {"source_code": "let n = read_int () ;;\nlet r = Str.regexp \"R[0-9]+C[0-9]+\" ;;\nfor i = 1 to n do\n let coord = read_line () in\n let is_first = Str.string_match r coord 0 in\n if is_first then begin\n let coords = Str.split (Str.regexp \"[A-Z]\") coord in\n let col = int_of_string (List.nth coords 0) in\n let row = int_of_string (List.nth coords 1) in\n let buf1 = Buffer.create 1000 in\n let rec rstring num buf = \n let r = num mod 26 in\n if (num/26) = 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n Buffer.contents buf\n end\n else if r != 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n rstring (num/26) buf\n end\n else if ((num-1)/26) != 0 then begin\n let _ = Buffer.add_char buf 'Z' in\n rstring ((num-1)/26) buf\n end\n else begin\n let _ = Buffer.add_char buf 'Z' in\n Buffer.contents buf\n end in\n\n let rec rev s =\n let sl = String.length s in\n for j=0 to (sl-1)/2 do\n let c = s.[j] in\n s.[j] <- s.[sl-j-1];\n s.[sl-j-1] <- c;\n done;\n s in\n let row_s = rev (rstring (row) (Buffer.create 2)) in\n let _ = Printf.printf \"%s%d\\n\" row_s col in\n\n\n row\n end\n else begin\n let rec row str j = \n let fchar = Char.code str.[j] in\n let schar = Char.code str.[j+1] in\n if schar >= 65 then\n 26*(fchar-64) + (row str (j+1))\n else\n fchar - 64 in\n let rnum = row coord 0 in\n let cpos = Str.search_forward (Str.regexp \"[0-9]+\") coord 0 in\n (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in\n *)\n let cstring = Str.matched_string coord in\n let cint = int_of_string cstring in\n let _ = Printf.printf \"R%dC%d\\n\" cint rnum in\n 1\n end\ndone;\n"}, {"source_code": "let n = read_int () ;;\nlet r = Str.regexp \"R[0-9]+C[0-9]+\" ;;\nfor i = 1 to n do\n let coord = read_line () in\n let is_first = Str.string_match r coord 0 in\n if is_first then begin\n let coords = Str.split (Str.regexp \"[A-Z]\") coord in\n let row = int_of_string (List.nth coords 0) in\n let col = int_of_string (List.nth coords 1) in\n let buf1 = Buffer.create 1000 in\n let rec rstring num buf = \n let r = num mod 26 in\n if (num/26) = 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n Buffer.contents buf\n end\n else if r != 0 then begin\n let _ = Buffer.add_char buf (Char.chr (r+64)) in\n rstring (num/26) buf\n end\n else if ((num-1)/26) != 0 then begin\n let _ = Buffer.add_char buf 'Z' in\n rstring ((num-1)/26) buf\n end\n else begin\n let _ = Buffer.add_char buf 'Z' in\n Buffer.contents buf\n end in\n\n let rec rev s =\n let sl = String.length s in\n for j=0 to (sl-1)/2 do\n let c = s.[j] in\n s.[j] <- s.[sl-j-1];\n s.[sl-j-1] <- c;\n done;\n s in\n let row_s = rev (rstring (row) (Buffer.create 2)) in\n let _ = Printf.printf \"%s%d\\n\" row_s col in\n\n\n row\n end\n else begin\n let rec row str j = \n let fchar = Char.code str.[j] in\n let schar = Char.code str.[j+1] in\n if schar >= 65 then\n 26*(fchar-64) + (row str (j+1))\n else\n fchar - 64 in\n let rnum = row coord 0 in\n let cpos = Str.search_forward (Str.regexp \"[0-9]+\") coord 0 in\n (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in\n *)\n let cstring = Str.matched_string coord in\n let cint = int_of_string cstring in\n let _ = Printf.printf \"R%dC%d\\n\" rnum cint in\n 1\n end\ndone;\n"}, {"source_code": "open Scanf;;\nopen Num;;\nopen Printf;;\nopen String;;\n\nexception No_num;;\nexception Digit;; \n\ntype cell = RC | NRC;;\n\nlet print_cell t = match t with\n RC -> print_endline \"RC\"\n |NRC -> print_endline \"NRC\"\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet myindex s c = try index s c with Not_found -> -100;;\n\nlet ntostring=[|\"A\";\"B\";\"C\";\"D\";\"E\";\"F\";\"G\";\"H\";\"I\";\"J\";\"K\";\"L\";\"M\";\"N\";\"O\";\"P\";\"Q\";\"R\";\"S\";\"T\";\"U\";\"V\";\"W\";\"X\";\"Y\";\"Z\"|];;\n\nlet is_digit = function\n |'1' | '2' |'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' -> true\n |_ -> false;;\n\nlet rec process t s = match t with\n RC -> process_RC s\n |NRC -> process_NRC s\nand process_RC x = \n let (rown,coln) = get_num x in\n print_string (convert_to_AB coln); print_int rown; print_endline \"\";\nand get_num x = let m = index x 'C' in\n\t\t(int_of_string (sub x 1 (m-1)),\n\t\t int_of_string (sub x (m+1) ( (length x) - m -1)))\nand convert_to_AB x = \n let y = ref x in\n let ss = ref \"\" in\n let () = \n while !y > 0 do\n let tmp = ((!y-1) mod 26) in\n y := !y / 26;\n ss := ntostring.(tmp) ^ !ss\n done in !ss\nand process_NRC x = \n let (ab,row) = get_content x in\n print_char 'R'; print_int row; print_char 'C'; print_int (convert_to_int ab);\n print_endline \"\";\nand get_content x = let m = digit_index x in\n\t\t (sub x 0 m, int_of_string (sub x m ((length x)-m)))\nand convert_to_int x = \n let k = ref ((length x) - 1) in\n let mul = ref 1 in\n let acc = ref 0 in\n let nA = int_of_char 'A' in\n let () =\n while !k >=0 do\n let f = get x !k in\n let g = (int_of_char f) - nA + 1 in\n acc := !acc + g*(!mul); mul:= !mul*26; k:=!k-1\n done in !acc\n\nand digit_index x =\n let k = ref 0 in\n try\n let () =\n for i = 0 to ((length x) - 1) \n do\n\tlet f = get x i in\n\tif is_digit f then\n\t raise Digit\n\telse k:=!k+1\n done in !k\n with Digit -> !k\n;;\n\n for i=1 to n do\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) in\n let t = match (myindex s 'R', myindex s 'C') with\n | (-100, _) -> NRC\n | (_,-100) -> NRC\n | (a, b) -> if b - a > 1 then RC else NRC\n in process t s\n done;;\n\n"}, {"source_code": "open Scanf;;\nopen Num;;\nopen Printf;;\nopen String;;\n\nexception No_num;;\nexception Digit;;\n\ntype cell = RC | NRC;;\n\nlet print_cell t = match t with\n RC -> print_endline \"RC\"\n |NRC -> print_endline \"NRC\"\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet myindex s c = try index s c with Not_found -> -100;;\n\nlet ntostring=[|\"A\";\"B\";\"C\";\"D\";\"E\";\"F\";\"G\";\"H\";\"I\";\"J\";\"K\";\"L\";\"M\";\"N\";\"O\";\"P\";\"Q\";\"R\";\"S\";\"T\";\"U\";\"V\";\"W\";\"X\";\"Y\";\"Z\"|];;\n\nlet is_digit = function\n |'1' | '2' |'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' -> true\n |_ -> false;;\n\nlet rec process t s = match t with\n RC -> process_RC s\n |NRC -> process_NRC s\nand process_RC x = \n let (rown,coln) = get_num x in\n print_string (convert_to_AB coln); print_int rown; print_endline \"\";\nand get_num x = let m = index x 'C' in\n\t\t(int_of_string (sub x 1 (m-1)),\n\t\t int_of_string (sub x (m+1) ( (length x) - m -1)))\nand convert_to_AB x = \n let y = ref x in\n let ss = ref \"\" in\n let () = \n while !y > 0 do\n let tmp = ((!y-1) mod 26) in\n y := !y / 26;\n ss := ntostring.(tmp) ^ !ss\n done in !ss\nand process_NRC x = \n let (ab,row) = get_content x in\n print_char 'R'; print_int row; print_char 'C'; print_int (convert_to_int ab);\n print_endline \"\";\nand get_content x = let m = digit_index x in\n\t\t (sub x 0 m, int_of_string (sub x m ((length x)-m)))\nand convert_to_int x = \n let k = ref ((length x) - 1) in\n let mul = ref 1 in\n let acc = ref 0 in\n let nA = int_of_char 'A' in\n let () =\n while !k >=0 do\n let f = get x !k in\n let g = (int_of_char f) - nA + 1 in\n acc := !acc + g*(!mul); mul:= !mul*26; k:=!k-1\n done in !acc\n\nand digit_index x =\n let k = ref 0 in\n try\n let () =\n for i = 0 to ((length x) - 1) \n do\n\tlet f = get x i in\n\tif is_digit f then\n\t raise Digit\n\telse k:=!k+1\n done in !k\n with Digit -> !k\n;;\n\n for i=1 to n do\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) in\n let t = match (myindex s 'R', myindex s 'C') with\n | (-100, _) -> NRC\n | (_,-100) -> NRC\n | (a, b) -> if b - a > 1 then RC else NRC\n in process t s\n done;;\n\n"}, {"source_code": "open Scanf;;\nopen Num;;\nopen Printf;;\nopen String;;\n\nexception No_num;;\nexception Digit;; \n\ntype cell = RC | NRC;;\n\nlet print_cell t = match t with\n RC -> print_endline \"RC\"\n |NRC -> print_endline \"NRC\"\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\n\nlet myindex s c = try index s c with Not_found -> -100;;\n\nlet ntostring=[|\"A\";\"B\";\"C\";\"D\";\"E\";\"F\";\"G\";\"H\";\"I\";\"J\";\"K\";\"L\";\"M\";\"N\";\"O\";\"P\";\"Q\";\"R\";\"S\";\"T\";\"U\";\"V\";\"W\";\"X\";\"Y\";\"Z\"|];;\n\nlet is_digit = function\n |'1' | '2' |'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' -> true\n |_ -> false;;\n\nlet rec process t s = match t with\n RC -> process_RC s\n |NRC -> process_NRC s\nand process_RC x = \n let (rown,coln) = get_num x in\n print_string (convert_to_AB coln); print_int rown; print_endline \"\";\nand get_num x = let m = index x 'C' in\n\t\t(int_of_string (sub x 1 (m-1)),\n\t\t int_of_string (sub x (m+1) ( (length x) - m -1)))\nand convert_to_AB x = \n let y = ref x in\n let ss = ref \"\" in\n let () = \n while !y > 0 do\n let tmp = ((!y-1) mod 26) in\n y := (!y - tmp - 1) / 26;\n ss := ntostring.(tmp) ^ !ss\n done in !ss\nand process_NRC x = \n let (ab,row) = get_content x in\n print_char 'R'; print_int row; print_char 'C'; print_int (convert_to_int ab);\n print_endline \"\";\nand get_content x = let m = digit_index x in\n\t\t (sub x 0 m, int_of_string (sub x m ((length x)-m)))\nand convert_to_int x = \n let k = ref ((length x) - 1) in\n let mul = ref 1 in\n let acc = ref 0 in\n let nA = int_of_char 'A' in\n let () =\n while !k >=0 do\n let f = get x !k in\n let g = (int_of_char f) - nA + 1 in\n acc := !acc + g*(!mul); mul:= !mul*26; k:=!k-1\n done in !acc\n\nand digit_index x =\n let k = ref 0 in\n try\n let () =\n for i = 0 to ((length x) - 1) \n do\n\tlet f = get x i in\n\tif is_digit f then\n\t raise Digit\n\telse k:=!k+1\n done in !k\n with Digit -> !k\n;;\n\n for i=1 to n do\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s \" (fun x -> x) in\n let t = match (myindex s 'R', myindex s 'C') with\n | (-100, _) -> NRC\n | (_,-100) -> NRC\n | (a, b) -> if b - a > 1 then RC else NRC\n in print_string s; print_string \" : \"; process t s\n done;;\n\n"}, {"source_code": "let rec split num str =\n match str with\n | \"\" -> []\n | s -> \n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one):: (returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one)::[]\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\nlet checkIsRC str =\n match str with\n | \"\" -> false\n | s ->\n if (compare (String.sub str 0 1) \"R\" == 0)\n then true\n else false\n\nlet rec reverseList li o =\n match li with \n | [] -> o\n | h :: t -> reverseList t (h :: o)\n\nlet returnConvertedCol k =\n let rec returnIt s =\n if (s > 0) then\n let n = s / 26 in\n let r = s mod 26 in\n (string_of_int r) :: returnIt n\n else [] in\n reverseList (returnIt (int_of_string k)) []\n\nlet returnConvertedRow n =\n let rec returnIt s =\n let k = s mod 10 in\n if (s > 0) then\n (Char.chr (k+64)) :: (returnIt (s/10))\n else\n [] in\n reverseList (returnIt (int_of_string n)) []\n\nlet rec printList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_string h; printList t\n\nlet rec printCharList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_char h; printCharList t\n\nlet changeRCToAlph line =\n let rec newline l row col=\n if (compare (String.sub l 0 1) \"C\") == 0 then\n (row, String.sub l 1 (String.length l -1))\n else\n let newRow = row ^ (String.sub l 0 1) in\n newline (String.sub l 1 (String.length l -1))\n newRow col in\n let (r,c) = newline line \"\" \"\" in\n let rList = returnConvertedRow r in\n let cList = returnConvertedCol c in\n printCharList rList; printList cList; print_string \"\\n\"\n\nlet changeNumToAscii n =\n let num = int_of_string n in\n let rec returnNum k =\n let s = k/10 in\n let r = k mod 10 in\n if (s > 0) then \n r + 26*(returnNum s)\n else\n r in\n string_of_int (returnNum num)\n\n\nlet changeAlphToRC line =\n let rec newline l row =\n if Char.code(String.get l 0) < 65 then\n (row, l)\n else \n let c = (Char.chr(Char.code(String.get l 0)-16)) in\n newline (String.sub l 1 (String.length l -1)) (row^(Char.escaped c)) in\n let (r,c) = newline line \"\" in\n print_char 'R';print_string r;print_char 'C';\n print_string(changeNumToAscii c)\n\nlet n = read_int()\n\nlet check line =\n if (checkIsRC line) then\n changeRCToAlph(String.sub line 1 (String.length line -1))\n else\n changeAlphToRC line\n\nlet rec strList num =\n if (num > 0) then\n let k = read_line() in\n let _ = check k in\n strList (num-1)\n else\n print_string\"\"\nlet _ = strList n\n"}, {"source_code": "let rec split num str =\n match str with\n | \"\" -> []\n | s -> \n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one):: (returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one)::[]\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\nlet rec checkInCHere str =\n match str with\n | \"\" -> false\n | s -> \n if (compare (String.sub str 0 1) \"C\" == 0)\n then true\n else if (int_of_string (String.sub str 0 1)) <= 9 && (int_of_string(String.sub str 0 1)) >= 0 then checkInCHere (String.sub str 1 (String.length str - 1))\n else false\n\nlet checkIsRC str =\n match str with\n | \"\" -> false\n | s ->\n if (compare (String.sub str 0 1) \"R\" == 0)\n then checkInCHere (String.sub str 1 (String.length str - 1))\n else false\n\nlet rec reverseList li o =\n match li with \n | [] -> o\n | h :: t -> reverseList t (h :: o)\n\nlet returnConvertedCol k =\n let rec returnIt s =\n if (s > 0) then\n let n = s / 26 in\n let r = s mod 26 in\n (string_of_int r) :: returnIt n\n else [] in\n reverseList (returnIt (int_of_string k)) []\n\nlet returnConvertedRow n =\n let rec returnIt s =\n let k = s mod 26 in\n if (s > 0) then\n (Char.chr (k+64)) :: (returnIt (s/26))\n else\n [] in\n reverseList (returnIt (int_of_string n)) []\n\nlet rec printList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_string h; printList t\n\nlet rec printCharList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_char h; printCharList t\n\nlet changeRCToAlph line =\n let rec newline l row col=\n if (compare (String.sub l 0 1) \"C\") == 0 then\n (row, String.sub l 1 (String.length l -1))\n else\n let newRow = row ^ (String.sub l 0 1) in\n newline (String.sub l 1 (String.length l -1))\n newRow col in\n let (r,c) = newline line \"\" \"\" in\n let rList = returnConvertedRow c in\n let cList = returnConvertedCol r in\n printCharList rList; printList cList; print_string \"\\n\"\n\nlet changeStringToAscii n =\n let rec returnStringToNum str num =\n match str with\n | \"\" -> num\n | s ->\n returnStringToNum (String.sub s 1 (String.length str - 1))\n ((Char.code(String.get s 0) - 64) + 26*num) in\n string_of_int (returnStringToNum n 0)\n\n\nlet changeAlphToRC line =\n let rec newline l row =\n if Char.code(String.get l 0) < 65 then\n (row, l)\n else \n newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in\n let (r,c) = newline line \"\" in\n print_char 'R';print_string c;print_char 'C';\n print_string(changeStringToAscii r);print_string\"\\n\"\n\nlet n = read_int()\n\nlet check line =\n if (checkIsRC line) then\n changeRCToAlph(String.sub line 1 (String.length line -1))\n else\n changeAlphToRC line\n\nlet rec strList num =\n if (num > 0) then\n let k = read_line() in\n let _ = check k in\n strList (num-1)\n else\n print_string\"\"\nlet _ = strList n\n"}, {"source_code": "let rec split num str =\n match str with\n | \"\" -> []\n | s -> \n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one):: (returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one)::[]\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\nlet checkIsRC str =\n match str with\n | \"\" -> false\n | s ->\n if (compare (String.sub str 0 1) \"R\" == 0)\n then true\n else false\n\nlet rec reverseList li o =\n match li with \n | [] -> o\n | h :: t -> reverseList t (h :: o)\n\nlet returnConvertedCol k =\n let rec returnIt s =\n if (s > 0) then\n let n = s / 26 in\n let r = s mod 26 in\n (string_of_int r) :: returnIt n\n else [] in\n reverseList (returnIt (int_of_string k)) []\n\nlet returnConvertedRow n =\n let rec returnIt s =\n let k = s mod 10 in\n if (s > 0) then\n (Char.chr (k+64)) :: (returnIt (s/10))\n else\n Char.chr(s) :: [] in\n reverseList (returnIt (int_of_string n)) []\n\nlet rec printList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_string h; printList t\n\nlet rec printCharList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_char h; printCharList t\n\nlet changeRCToAlph line =\n let rec newline l row col=\n if (compare (String.sub l 0 1) \"C\") == 0 then\n (row, String.sub l 1 (String.length l -1))\n else\n let newRow = row ^ (String.sub l 0 1) in\n newline (String.sub l 1 (String.length l -1))\n newRow col in\n let (r,c) = newline line \"\" \"\" in\n let rList = returnConvertedRow r in\n let cList = returnConvertedCol c in\n printCharList rList; printList cList; print_string \"\\n\"\n\nlet changeNumToAscii n =\n let num = int_of_string n in\n let rec returnNum k =\n let s = k/10 in\n let r = k mod 10 in\n if (s > 0) then \n r + 26*(returnNum s)\n else\n r in\n string_of_int (returnNum num)\n\n\nlet changeAlphToRC line =\n let rec newline l row =\n if Char.code(String.get l 0) < 65 then\n (row, l)\n else \n let c = (Char.chr(Char.code(String.get l 0)-16)) in\n newline (String.sub l 1 (String.length l -1)) (row^(Char.escaped c)) in\n let (r,c) = newline line \"\" in\n print_char 'R';print_string r;print_char 'C';\n print_string(changeNumToAscii c)\n\nlet n = read_int()\n\nlet check line =\n if (checkIsRC line) then\n changeRCToAlph(String.sub line 1 (String.length line -1))\n else\n changeAlphToRC line\n\nlet rec strList num =\n if (num > 0) then\n let k = read_line() in\n let _ = check k in\n strList (num-1)\n else\n print_string\"\"\nlet _ = strList n\n"}, {"source_code": "let rec split num str =\n match str with\n | \"\" -> []\n | s -> \n let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in\n beg :: (split num rest)\n\nlet rec returnIntList strList one =\n match strList with\n | h :: t -> if (compare h \" \" == 0 || compare h \"\\n\" == 0) then\n (int_of_string one):: (returnIntList t \"\")\n else returnIntList t (one^h)\n | _ -> (int_of_string one)::[]\n\nlet splitToList line =\n let lineList = split 1 line in\n returnIntList lineList \"\"\n\nlet rec checkInCHere str =\n match str with\n | \"\" -> false\n | s -> \n if (compare (String.sub str 0 1) \"C\" == 0)\n then true\n else if (int_of_string (String.sub str 0 1)) <= 9 && (int_of_string(String.sub str 0 1)) >= 0 then checkInCHere (String.sub str 1 (String.length str - 1))\n else false\n\nlet checkIsRC str =\n match str with\n | \"\" -> false\n | s ->\n if (compare (String.sub str 0 1) \"R\" == 0)\n then checkInCHere (String.sub str 2 (String.length str - 2))\n else false\n\nlet rec reverseList li o =\n match li with \n | [] -> o\n | h :: t -> reverseList t (h :: o)\n\nlet returnConvertedCol k =\n let rec returnIt s =\n if (s > 0) then\n let n = s / 26 in\n let r = s mod 26 in\n (string_of_int r) :: returnIt n\n else [] in\n reverseList (returnIt (int_of_string k)) []\n\nlet returnConvertedRow n =\n let rec returnIt s =\n let k = s mod 26 in\n if (s > 0) then\n (Char.chr (k+64)) :: (returnIt (s/26))\n else\n [] in\n reverseList (returnIt (int_of_string n)) []\n\nlet rec printList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_string h; printList t\n\nlet rec printCharList li =\n match li with\n | [] -> print_string \"\"\n | h :: t -> print_char h; printCharList t\n\nlet changeRCToAlph line =\n let rec newline l row col=\n if (compare (String.sub l 0 1) \"C\") == 0 then\n (row, String.sub l 1 (String.length l -1))\n else\n let newRow = row ^ (String.sub l 0 1) in\n newline (String.sub l 1 (String.length l -1))\n newRow col in\n let (r,c) = newline line \"\" \"\" in\n let rList = returnConvertedRow c in\n printCharList rList; print_string r; print_string \"\\n\"\n\nlet changeStringToAscii n =\n let rec returnStringToNum str num =\n match str with\n | \"\" -> num\n | s ->\n returnStringToNum (String.sub s 1 (String.length str - 1))\n ((Char.code(String.get s 0) - 64) + 26*num) in\n string_of_int (returnStringToNum n 0)\n\n\nlet changeAlphToRC line =\n let rec newline l row =\n if Char.code(String.get l 0) < 65 then\n (row, l)\n else \n newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in\n let (r,c) = newline line \"\" in\n print_char 'R';print_string c;print_char 'C';\n print_string(changeStringToAscii r);print_string\"\\n\"\n\nlet n = read_int()\n\nlet check line =\n if (checkIsRC line) then\n changeRCToAlph(String.sub line 1 (String.length line -1))\n else\n changeAlphToRC line\n\nlet rec strList num =\n if (num > 0) then\n let k = read_line() in\n let _ = check k in\n strList (num-1)\n else\n print_string\"\"\nlet _ = strList n\n"}, {"source_code": "let get_int c = \nlet n = ref 0 in\ntry\nwhile !c >= '0' && !c <= '9' do\n n := !n * 10 + (int_of_char !c - int_of_char '0');\n c := input_char(stdin)\ndone;\n(n,c);\nwith End_of_file -> (n,c);;\n\nlet n = fst(get_int(ref '0')) in\nwhile !n > 0 do\n\nlet firstchar = input_char(stdin) in\nlet secondchar = input_char(stdin) in \n\nlet int_of_column_header (fc,sc) =\nlet n = ref 0 in\n(n := !n * 26 + (int_of_char !fc - int_of_char 'A' + 1);\ntry\nwhile !sc >= 'A' && !sc <= 'Z' do\n n := !n * 26 + (int_of_char !sc - int_of_char 'A' + 1);\n sc := input_char(stdin)\ndone;\n(n,sc);\nwith End_of_file -> (n,sc)) in\n\nlet column_header_of_int n =\n let s = ref \"\" in\n let nref = ref n in\n while !nref > 0 do\n s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;\n nref := (!nref-1)/26;\n done;\n !s in\n\nlet row_first c = let row = !(fst(get_int(c))) in let column = !(fst(get_int(ref '0'))) in (row,column) in\n\nlet column_first (fc, sc) = let nc = int_of_column_header(fc,sc) in let column = !(fst(nc)) in let row = !(fst(get_int(snd(nc)))) in (row,column) in\n\nlet rc = if firstchar = 'R' && (secondchar >= '0' && secondchar <= '9') then row_first (ref secondchar) else column_first(ref firstchar, ref secondchar) in\n\nlet alt_format = if firstchar = 'R' && (secondchar >= '0' && secondchar <= '9') then column_header_of_int(snd(rc)) ^ string_of_int(fst(rc))\nelse \"R\" ^ string_of_int(fst(rc)) ^ \"C\" ^ string_of_int(snd(rc)) in\n\nprint_endline(alt_format);\n\nn := !n - 1\n\ndone;;"}, {"source_code": "let get_int c = \nlet n = ref 0 in\ntry\nwhile !c >= '0' && !c <= '9' do\n n := !n * 10 + (int_of_char !c - int_of_char '0');\n c := input_char(stdin)\ndone;\n(n,c);\nwith End_of_file -> (n,c);;\n\nlet n = fst(get_int(ref '0')) in\nwhile !n > 0 do\n\nlet firstchar = input_char(stdin) in\n\nlet int_of_column_header c =\nlet n = ref 0 in\ntry\nwhile !c >= 'A' && !c <= 'Z' do\n n := !n * 26 + (int_of_char !c - int_of_char 'A' + 1);\n c := input_char(stdin)\ndone;\n(n,c);\nwith End_of_file -> (n,c) in\n\nlet column_header_of_int n =\n let s = ref \"\" in\n let nref = ref n in\n while !nref > 0 do\n s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;\n nref := !nref/26;\n done;\n !s in\n\nlet row_first c = let row = !(fst(get_int(c))) in let column = !(fst(get_int(ref '0'))) in (row,column) in\n\nlet column_first c = let nc = int_of_column_header(c) in let column = !(fst(nc)) in let row = !(fst(get_int(snd(nc)))) in (row,column) in\n\nlet rc = if firstchar = 'R' then let c = input_char(stdin) in row_first (ref c) else column_first(ref firstchar) in\n\nlet alt_format = if firstchar = 'R' then column_header_of_int(snd(rc)) ^ string_of_int(fst(rc))\nelse \"R\" ^ string_of_int(fst(rc)) ^ \"C\" ^ string_of_int(snd(rc)) in\n\nprint_endline(alt_format);\n\nn := !n - 1\n\ndone;;"}, {"source_code": "let rc_format coordinate = \n let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in\n if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then\n\t(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))\n else\n\t(false, -1, -1)\n\nlet excel_format coordinate =\n let rec decode_column c pos =\n\tif coordinate.[pos] < 'A' then\n\t (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)\n\telse\n\t decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)\n in\n decode_column 0 0\n\nlet to_excel_format r c =\n let rec encode_column c = \n\tif c > 0 then\n\t (encode_column (c / 26)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + ((c - 1) mod 26))))\n\telse\n\t \"\"\n in\n (encode_column c) ^ (string_of_int r)\n\nlet to_rc_format r c =\n \"R\" ^ (string_of_int r) ^ \"C\" ^ (string_of_int c)\n\nlet () =\n for n = read_int () downto 1 do\n\tlet coordinate = read_line () in\n\tlet (is_rc_format, x, y) = rc_format coordinate in\n\tif is_rc_format then\n\t Printf.printf \"%s\" (to_excel_format x y)\n\telse (\n\t (* Printf.printf \"hooray!!!\"; *)\n\t let (x, y) = excel_format coordinate in\n\t Printf.printf \"%s\" (to_rc_format x y)\n\t);\n\tprint_newline()\n done\n"}, {"source_code": "let rc_format coordinate = \n let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in\n if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then\n\t(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))\n else\n\t(false, -1, -1)\n\nlet excel_format coordinate =\n let rec decode_column c pos =\n\tif coordinate.[pos] < 'A' then\n\t (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)\n\telse\n\t decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)\n in\n decode_column 0 0\n\nlet to_excel_format c r =\n let rec encode_column c = \n\tif c > 0 then\n\t (encode_column (c / 26 - 1)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + (c mod 26))))\n\telse\n\t \"\"\n in\n (encode_column c) ^ (string_of_int r)\n\nlet to_rc_format r c =\n \"R\" ^ (string_of_int r) ^ \"C\" ^ (string_of_int c)\n\nlet () =\n for n = read_int () downto 1 do\n\tlet coordinate = read_line () in\n\tlet (is_rc_format, x, y) = rc_format coordinate in\n\tif is_rc_format then\n\t Printf.printf \"%s\" (to_excel_format (y - 1) x)\n\telse (\n\t (* Printf.printf \"hooray!!!\"; *)\n\t let (x, y) = excel_format coordinate in\n\t Printf.printf \"%s\" (to_rc_format x y)\n\t);\n\tprint_newline()\n done\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc last_div n =\n if n <= 26\n then (\n if not last_div && ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then acc\n else if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else\n if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n in aux \"\" false col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc last_div n =\n if n <= 26\n then (\n if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else\n if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))\n then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n in aux \"\" false col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc last_div n =\n if n <= 26\n then (\n if last_div\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else\n if last_div\n then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)\n in aux \"\" false col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> 0\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 26 -> 'Z' | _ -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t ->\n aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet colum_number_to_string col =\n let rec aux acc n =\n if n <= 26\n then (Char.escaped (char_at_pos n)) ^ acc\n else aux (Char.escaped (char_at_pos (n mod 26)) ^ acc ) (n / 26)\n in aux \"\" col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (colum_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in\n List.rev (loop [] cnt)\n in\n List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc n =\n if n <= 26\n then (\n if (String.length acc > 0) && ((String.get acc 0) = 'Z')\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else\n if (String.length acc > 0) && ((String.get acc 0) = 'Z')\n then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) (n / 26)\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) (n / 26)\n in aux \"\" col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "\ntype numeration =\n | Excel of string * int\n | Coord of int * int\n\nlet string_to_numeration s =\n if Str.string_match (Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))\n else if Str.string_match (Str.regexp \"^R\\\\([1-9][0-9]*\\\\)C\\\\([1-9][0-9]*\\\\)$\") s 0 then\n Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))\n else\n None\n\nlet string_to_list s =\n let rec exp i l =\n if i < 0 then l else exp (i - 1) (s.[i] :: l)\n in exp (String.length s - 1) []\n\nlet pos_in_alphabet = function\n | 'A' -> 1 | 'B' -> 2 | 'C' -> 3 | 'D' -> 4 | 'E' -> 5\n | 'F' -> 6 | 'G' -> 7 | 'H' -> 8 | 'I' -> 9 | 'J' -> 10\n | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15\n | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20\n | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25\n | 'Z' -> 26 | _ -> -1;;\n\nlet char_at_pos = function\n | 1 -> 'A' | 2 -> 'B' | 3 -> 'C' | 4 -> 'D' | 5 -> 'E'\n | 6 -> 'F' | 7 -> 'G' | 8 -> 'H' | 9 -> 'I' | 10 -> 'J'\n | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'\n | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'\n | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'\n | 0 -> 'Z' | x -> ' '\n\nlet string_to_column_number s =\n let rec aux acc cur = function\n | [] -> acc\n | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t\n in aux 0 0 (List.rev (string_to_list s))\n\nlet column_number_to_string col =\n let rec aux acc n =\n if n <= 26\n then (\n if acc = \"Z\"\n then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc\n else (String.make 1 (char_at_pos (n mod 26))) ^ acc\n )\n else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) (n / 26)\n in aux \"\" col\n\nlet numeration_to_string = function\n | Excel (col, row) -> col ^ (string_of_int row)\n | Coord (row, col) -> \"R\" ^ (string_of_int row) ^ \"C\" ^ (string_of_int col)\n\nlet switch_numeration = function\n | Excel (col, row) -> Coord (row, string_to_column_number(col))\n | Coord (row, col) -> Excel (column_number_to_string(col), row)\n\n(*\nlet spreadsheets l =\n l\n |> List.map string_to_numeration\n |> List.filter (function Some(_) -> true | None -> false)\n |> List.map (function Some(x) -> x | x -> assert false)\n |> List.map switch_numeration\n |> List.map numeration_to_string\n*)\n\nlet spreadsheets l =\n l\n |> List.map (fun x ->\n match string_to_numeration (x) with\n | Some(e) -> numeration_to_string (switch_numeration e)\n | None -> assert false)\n\nlet () =\n let num = read_int () in\n let do_parse cnt =\n let rec loop acc = function\n | c when c < 1 -> acc\n | c ->\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s\\n\" (fun x -> x)\n in loop (s::acc) (c-1)\n in List.rev (loop [] cnt)\n in List.iter (Printf.printf \"%s\\n\") (spreadsheets (do_parse num))\n\n"}, {"source_code": "let ia = int_of_char 'A' in\nlet isrc str = \n if str.[0] <> 'R' then failwith \"Wrong\"\n else let p = String.index_from str 2 'C' in (true, int_of_string (String.sub str (p + 1) (String.length str - p - 1)), int_of_string (String.sub str 1 (p - 1)))\nand isan str =\n let rec strip_al ald pos = \n if str.[pos] < 'A' then (ald, pos) else strip_al (26 * ald + (int_of_char str.[pos] - ia + 1)) (pos + 1) \n in\n let (ra, rp) = strip_al 0 0\n in\n (false, ra, int_of_string (String.sub str rp (String.length str - rp)))\nand oprc y x =\n print_char 'R'; print_int x; print_char 'C'; print_int y\nand opan x y =\n let rec px x = if x > 0 then let _ = px (x / 26) in print_char (char_of_int (x mod 26 - 1 + ia)) else () in\n px x; print_int y\nin\nfor lc = (read_int ()) downto 1 do\n let line = read_line () in\n let (is_rc, x, y) = try isrc line with _ -> isan line in\n (if is_rc then opan else oprc) x y; print_newline ()\ndone\n"}, {"source_code": "\nlet read_line_of_strings () =\n read_line () |> Str.split (Str.regexp \" +\")\n\nlet read_line_of f =\n read_line_of_strings () |> List.map f\n\nlet read_line_of_floats () =\n read_line_of float_of_string\n\nlet coordinates_of_string input =\n let rx1 = Str.regexp \"^R\\\\([0-9]+\\\\)C\\\\([0-9]+\\\\)$\" in\n let rx2 = Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([0-9]+\\\\)$\" in\n if Str.string_match rx1 input 0 then\n let row = Str.matched_group 1 input in\n let col = Str.matched_group 2 input in\n `RC (int_of_string row, int_of_string col)\n else if Str.string_match rx2 input 0 then\n let col = Str.matched_group 1 input in\n let row = Str.matched_group 2 input in\n `A1 (int_of_string row, col)\n else\n raise (Invalid_argument input)\n\nlet col_to_int name =\n let len = String.length name in\n let sum = ref 0 in\n let acc = ref 1 in\n for i = len - 1 downto 0 do\n sum := !sum + (Char.code name.[i] - 65) * !acc;\n acc := !acc * 26;\n done;\n !sum\n\nlet int_to_col n =\n let to_digit k = String.make 1 (Char.chr (k + 65)) in\n let rec iter name n =\n if n > 25 then\n let (d, n) = (n mod 26, n / 26) in\n iter (to_digit d ^ name) n\n else\n to_digit n ^ name\n in\n iter \"\" n\n\nlet solve = function\n | `RC (row, col) -> Printf.sprintf \"%s%d\" (int_to_col col) row\n | `A1 (row, col) -> Printf.sprintf \"R%dC%d\" row (col_to_int col)\n\nlet convert input =\n solve (coordinates_of_string input)\n\nlet () =\n let [count] = read_line_of int_of_string in\n for i = 1 to count do\n read_line_of coordinates_of_string\n |> List.iter (fun task -> Printf.printf \"%s\\n\" (solve task))\n done;\n"}, {"source_code": "let read_line_of_strings () =\n read_line () |> Str.split (Str.regexp \" +\")\n\nlet read_line_of f =\n read_line_of_strings () |> List.map f\n\nlet read_line_of_floats () =\n read_line_of float_of_string\n\nlet coordinates_of_string input =\n let rx1 = Str.regexp \"^R\\\\([0-9]+\\\\)C\\\\([0-9]+\\\\)$\" in\n let rx2 = Str.regexp \"^\\\\([A-Z]+\\\\)\\\\([0-9]+\\\\)$\" in\n if Str.string_match rx1 input 0 then\n let row = Str.matched_group 1 input in\n let col = Str.matched_group 2 input in\n `RC (int_of_string row, int_of_string col)\n else if Str.string_match rx2 input 0 then\n let col = Str.matched_group 1 input in\n let row = Str.matched_group 2 input in\n `A1 (int_of_string row, col)\n else\n raise (Invalid_argument input)\n\nlet col_to_int name =\n let len = String.length name in\n let sum = ref 0 in\n let acc = ref 1 in\n for i = len - 1 downto 0 do\n sum := !sum + (Char.code name.[i] - 64) * !acc;\n acc := !acc * 26;\n done;\n !sum\n\nlet int_to_col n =\n let to_digit k = String.make 1 (Char.chr (k + 64)) in\n let rec iter name n =\n if n > 26 then\n let (d, n) = (n mod 26, n / 26) in\n iter (to_digit d ^ name) n\n else\n to_digit n ^ name\n in\n iter \"\" n\n\nlet solve = function\n | `RC (row, col) -> Printf.sprintf \"%s%d\\n\" (int_to_col col) row\n | `A1 (row, col) -> Printf.sprintf \"R%dC%d\\n\" row (col_to_int col)\n\nlet () =\n let [count] = read_line_of int_of_string in\n for i = 1 to count do\n read_line_of coordinates_of_string\n |> List.iter (fun task -> Printf.printf \"%s\\n\" (solve task))\n done;\n"}], "src_uid": "910c0e650d48af22fa51ab05e8123709"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet rec gcd a b =\n\tif b = 0 then a \n\telse gcd b (a mod b)\n\nlet () = \n\tlet n = read_int() in\n\tfor i = 1 to n do\n\t\tlet a = read_int() and b = read_int() in\n\t\tif gcd a b = 1 then printf \"Finite\\n\"\n\t\telse printf \"Infinite\\n\"\n\tdone\n\t\t\n", "positive_code": [{"source_code": "let rec pgcd a b =\n if b = 0 then a\n else if a > b then\n pgcd b a\n else\n let r = b - a in\n pgcd a r\n\n\nlet _ =\n let n = int_of_string (input_line stdin) in\n for i = 1 to n do\n let l = List.map int_of_string @@ Str.split (Str.regexp \" \") (input_line stdin) in\n let (a,b) =\n match l with\n | [a;b] -> (a,b)\n | _ -> assert false\n in\n if pgcd a b <> 1 then\n Format.printf \"Infinite@.\"\n else\n Format.printf \"Finite@.\"\n done\n"}], "negative_code": [], "src_uid": "388450021f2f33177d905879485bb531"} {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let mmod n =\n let r = Int64.rem n mmm in\n if r < 0L\n then r +| mmm\n else r\n in\n let n = getnum () in\n let m = getnum () in\n let fact = Array.make (m + 1) 1 in\n let () =\n for i = 2 to m do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n done;\n in\n let s = Array.make (m + 1) [] in\n let sidx = ref 0 in\n for i = 0 to n - 1 do\n let g = getnum () in\n let a = Array.make (g + 1) 0 in\n\tfor j = 0 to g - 1 do\n\t a.(j) <- getnum ();\n\tdone;\n\ta.(g) <- 10000000;\n\tArray.sort compare a;\n\tlet prev = ref a.(0) in\n\tlet cnt = ref 1 in\n\tlet ht = Hashtbl.create 10 in\n\t for j = 1 to g do\n\t if a.(j) = !prev\n\t then incr cnt\n\t else (\n\t (try\n\t\t let xs = Hashtbl.find ht !cnt in\n\t\t Hashtbl.replace ht !cnt (!prev :: xs)\n\t with\n\t\t | Not_found ->\n\t\t Hashtbl.replace ht !cnt [!prev]\n\t );\n\t prev := a.(j);\n\t cnt := 1;\n\t )\n\t done;\n\t Hashtbl.iter\n\t (fun _cnt xs ->\n\t List.iter\n\t\t (fun x ->\n\t\t (*Printf.printf \"qwe %d %d\\n\" _cnt x;*)\n\t\t s.(x) <- !sidx :: s.(x)\n\t\t ) xs;\n\t incr sidx;\n\t ) ht\n done;\n let ht = Hashtbl.create 10 in\n (*for i = 1 to m do\n\tPrintf.printf \"%d\" i;\n\tList.iter (Printf.printf \" %d\") s.(i);\n\tPrintf.printf \"\\n\"\n\tdone;*)\n for i = 1 to m do\n\t(try\n\t let c = Hashtbl.find ht s.(i) in\n\t Hashtbl.replace ht s.(i) (c + 1)\n\t with\n\t | Not_found ->\n\t Hashtbl.replace ht s.(i) 1\n\t);\n done;\n let res = ref 1L in\n\tHashtbl.iter\n\t (fun _ c ->\n\t res := mmod (!res *| Int64.of_int fact.(c))\n\t ) ht;\n\tPrintf.printf \"%Ld\\n\" !res\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\n\nlet p = 1_000_000_007L\n\nlet ( %% ) x n = let y = Int64.rem x n in if y<0L then Int64.add y n else y\nlet ( ** ) a b = (Int64.mul a b) %% p\nlet ( ++ ) a b = (Int64.add a b) %% p\nlet long x = Int64.of_int x\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet prod i j f = fold i j (fun i a -> (f i) ** a) 1L\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in (* gyms *)\n let m = read_int () in (* pokymon types *)\n let dummy = Hashtbl.create 10 in \n let ht = Array.make n dummy in\n\n for i=0 to n-1 do\n let np = read_int () in\n let h = Hashtbl.create 10 in\n ht.(i) <- h;\n let increment t = \n let c = try Hashtbl.find h t with Not_found -> 0 in\n Hashtbl.replace h t (c+1)\n in\n for j=0 to np-1 do\n let pk = read_int() in\n increment (pk-1);\n done;\n done;\n\n let cl_array = Array.make m 0 in\n\n let classno = ref 1 in (* the next class number to assign *)\n \n for gym = 0 to n-1 do\n (* incorporate the effect of this guy on our class array *)\n let classht = Hashtbl.create 10 in\n Hashtbl.iter (fun pk count ->\n let pair = (cl_array.(pk), count) in\n if not (Hashtbl.mem classht pair) then (\n\tHashtbl.add classht pair !classno;\n\tcl_array.(pk) <- !classno;\n\tclassno := 1 + !classno\n ) else (\n\tcl_array.(pk) <- Hashtbl.find classht pair\n )\n ) ht.(gym);\n done;\n\n let hist = Array.make !classno 0 in\n\n for i=0 to m-1 do\n hist.(cl_array.(i)) <- hist.(cl_array.(i)) + 1\n done;\n\n let fact = Array.make (m+1) 1L in\n\n for i=1 to m do\n fact.(i) <- fact.(i-1) ** (long i)\n done;\n\n let answer = prod 0 (!classno -1) (fun cl -> fact.(hist.(cl))) in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let mmod n =\n let r = Int64.rem n mmm in\n if r < 0L\n then r +| mmm\n else r\n in\n let n = getnum () in\n let m = getnum () in\n let fact = Array.make (m + 1) 1 in\n let () =\n for i = 2 to m do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n done;\n in\n let s = Array.make (m + 1) [] in\n let sidx = ref 0 in\n for i = 0 to n - 1 do\n let g = getnum () in\n let a = Array.make (g + 1) 0 in\n\tfor j = 0 to g - 1 do\n\t a.(j) <- getnum ();\n\tdone;\n\ta.(g) <- 1000000;\n\tArray.sort compare a;\n\tlet prev = ref a.(0) in\n\tlet cnt = ref 1 in\n\tlet ht = Hashtbl.create 10 in\n\t for j = 1 to g do\n\t if a.(j) = !prev\n\t then incr cnt\n\t else (\n\t (try\n\t\t let xs = Hashtbl.find ht !cnt in\n\t\t Hashtbl.replace ht !cnt (!prev :: xs)\n\t with\n\t\t | Not_found ->\n\t\t Hashtbl.replace ht !cnt [!prev]\n\t );\n\t prev := a.(j);\n\t cnt := 1;\n\t )\n\t done;\n\t Hashtbl.iter\n\t (fun _cnt xs ->\n\t List.iter\n\t\t (fun x ->\n\t\t (*Printf.printf \"qwe %d %d\\n\" _cnt x;*)\n\t\t s.(x) <- !sidx :: s.(x)\n\t\t ) xs;\n\t incr sidx;\n\t ) ht\n done;\n let ht = Hashtbl.create 10 in\n (*for i = 1 to m do\n\tPrintf.printf \"%d\" i;\n\tList.iter (Printf.printf \" %d\") s.(i);\n\tPrintf.printf \"\\n\"\n\tdone;*)\n for i = 1 to m do\n\t(try\n\t let c = Hashtbl.find ht s.(i) in\n\t Hashtbl.replace ht s.(i) (c + 1)\n\t with\n\t | Not_found ->\n\t Hashtbl.replace ht s.(i) 1\n\t);\n done;\n let res = ref 1L in\n\tHashtbl.iter\n\t (fun _ c ->\n\t res := mmod (!res *| Int64.of_int fact.(c))\n\t ) ht;\n\tPrintf.printf \"%Ld\\n\" !res\n"}, {"source_code": "let getnum =\n let l = 5120000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let mmod n =\n let r = Int64.rem n mmm in\n if r < 0L\n then r +| mmm\n else r\n in\n let n = getnum () in\n let m = getnum () in\n let fact = Array.make (m + 1) 1 in\n let () =\n for i = 2 to m do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n done;\n in\n let s = Array.make (m + 1) [] in\n let sidx = ref 0 in\n for i = 0 to n - 1 do\n let g = getnum () in\n let a = Array.make (g + 1) 0 in\n\tfor j = 0 to g - 1 do\n\t a.(j) <- getnum ();\n\tdone;\n\ta.(g) <- 1000000;\n\tArray.sort compare a;\n\tlet prev = ref a.(0) in\n\tlet cnt = ref 1 in\n\tlet ht = Hashtbl.create 10 in\n\t for j = 1 to g do\n\t if a.(j) = !prev\n\t then incr cnt\n\t else (\n\t (try\n\t\t let xs = Hashtbl.find ht !cnt in\n\t\t Hashtbl.replace ht !cnt (!prev :: xs)\n\t with\n\t\t | Not_found ->\n\t\t Hashtbl.replace ht !cnt [!prev]\n\t );\n\t prev := a.(j);\n\t cnt := 1;\n\t )\n\t done;\n\t Hashtbl.iter\n\t (fun _cnt xs ->\n\t List.iter\n\t\t (fun x ->\n\t\t (*Printf.printf \"qwe %d %d\\n\" _cnt x;*)\n\t\t s.(x) <- !sidx :: s.(x)\n\t\t ) xs;\n\t incr sidx;\n\t ) ht\n done;\n let ht = Hashtbl.create 10 in\n (*for i = 1 to m do\n\tPrintf.printf \"%d\" i;\n\tList.iter (Printf.printf \" %d\") s.(i);\n\tPrintf.printf \"\\n\"\n\tdone;*)\n for i = 1 to m do\n\t(try\n\t let c = Hashtbl.find ht s.(i) in\n\t Hashtbl.replace ht s.(i) (c + 1)\n\t with\n\t | Not_found ->\n\t Hashtbl.replace ht s.(i) 1\n\t);\n done;\n let res = ref 1L in\n\tHashtbl.iter\n\t (fun _ c ->\n\t res := mmod (!res *| Int64.of_int fact.(c))\n\t ) ht;\n\tPrintf.printf \"%Ld\\n\" !res\n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\nlet _ =\n let mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let mmod n =\n let r = Int64.rem n mmm in\n if r < 0L\n then r +| mmm\n else r\n in\n let n = getnum () in\n let m = getnum () in\n let fact = Array.make (m + 1) 1 in\n let () =\n for i = 2 to m do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n done;\n in\n let s = Array.make (m + 1) [] in\n let sidx = ref 0 in\n for i = 0 to n - 1 do\n let g = getnum () in\n let a = Array.make (g + 1) 0 in\n\tfor j = 0 to g - 1 do\n\t a.(j) <- getnum ();\n\tdone;\n\ta.(g) <- 1000000;\n\tArray.sort compare a;\n\tlet prev = ref a.(0) in\n\tlet cnt = ref 1 in\n\tlet ht = Hashtbl.create 10 in\n\t for j = 1 to g do\n\t if a.(j) = !prev\n\t then incr cnt\n\t else (\n\t (try\n\t\t let xs = Hashtbl.find ht !cnt in\n\t\t Hashtbl.replace ht !cnt (!prev :: xs)\n\t with\n\t\t | Not_found ->\n\t\t Hashtbl.replace ht !cnt [!prev]\n\t );\n\t prev := a.(j);\n\t cnt := 1;\n\t )\n\t done;\n\t Hashtbl.iter\n\t (fun _cnt xs ->\n\t List.iter\n\t\t (fun x ->\n\t\t (*Printf.printf \"qwe %d %d\\n\" _cnt x;*)\n\t\t s.(x) <- !sidx :: s.(x)\n\t\t ) xs;\n\t incr sidx;\n\t ) ht\n done;\n let ht = Hashtbl.create 10 in\n (*for i = 1 to m do\n\tPrintf.printf \"%d\" i;\n\tList.iter (Printf.printf \" %d\") s.(i);\n\tPrintf.printf \"\\n\"\n\tdone;*)\n for i = 1 to m do\n\t(try\n\t let c = Hashtbl.find ht s.(i) in\n\t Hashtbl.replace ht s.(i) (c + 1)\n\t with\n\t | Not_found ->\n\t Hashtbl.replace ht s.(i) 1\n\t);\n done;\n let res = ref 1L in\n\tHashtbl.iter\n\t (fun _ c ->\n\t res := !res *| Int64.of_int fact.(c)\n\t ) ht;\n\tPrintf.printf \"%Ld\\n\" !res\n"}], "src_uid": "cff3074a82bffdd49579a47c7491f972"} {"source_code": "(* \r\n build sequence a0, a1, ... , an\r\n a0 = 0, \r\n 1)ai = a(i-1)+x or 2)ai = a(i-1)-y\r\n ai <= B \r\n \r\n maximise sum\r\n \r\n want all ai to be as close to B as possible\r\n - do 1) up to B then (2) and (1) alternating\r\n\r\n a0, a1, a2, ... , ak, a(k+1), ... , an\r\n\r\n 0, x, 2*x, ... , k*x where k*x <= B, k*x-y, ... , an\r\n\r\n sum = (x+2*x+...+k*x) + floor((n-k)/2)*(k*x-y+k*x) + (k*x-y if n-k is not even)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0, 1, 2, 3, 4, 5 = 5/2(5+1) =15\r\n\r\n \r\n n=7, B=1e8, x=1e8, y=1e8\r\n\r\n 0, 1e8, 0, 1e8, 0, 1e8, 0 = 7\r\n\r\n k = 1e8 / 1e8 = 1 < n\r\n s1 = (1e8*1*2/2)=1e8\r\n s2 = 6*(1e8)/2 = 3*1e8\r\n n-k is even so 4*1e8\r\n\r\n n=4, B=1, x=7, y=3\r\n\r\n 0, -3, 4 -> PROBLEM!\r\n\r\n k = 1 / 7 = 0 \r\n s1 = 0\r\n s2 = (4)*(2*0-3)/2=-6 \r\n\r\n add +x until no longer possible\r\n need to -y until we can +x\r\n add +x \r\n need to -y until we can +x\r\n repeat O(n) complexity\r\n\r\n add +x k1 times\r\n subtract y k2 times\r\n add x\r\n subtract y k2 times\r\n O(1) complexity if we calculate k1 and k2\r\n\r\n k1*x-k2*y + x<=B\r\n (k1+1)*x-B<=k2*y\r\n ((k1+1)*x-B)/y <= k2, since k2 isn't necessarily constant we have to do O(n)\r\n\r\n e.g 0, -3, -6, 1, -2, -5, -8, 0 (goes from 2 to 3)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0 + alternate_sum 100 1 30 1 4\r\n 0 + 1 + alternate_sum ... 2 3\r\n 0 + 1 + 2 + ... 3 2\r\n 0 + 1 + 2 + 3 + ... 4 1\r\n 0 + 1 + 2 + 3 + 4 + ... 5 0\r\n 0 + 1 + 2 + 3 + 4 + 5\r\n\r\n *)\r\n\r\n\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x -> x);;\r\n\r\nlet rec alternate_sum _B x y current = function \r\n | 0 -> current\r\n | n -> \r\n if (current +. x<=_B) then current +. alternate_sum _B x y (current +. x) (n-1)\r\n else current +. alternate_sum _B x y (current -. y) (n-1)\r\n;;\r\n\r\nlet run_case = function\r\n | () -> \r\n let n = read_int () in \r\n let _B = read_float () in \r\n let x = read_float () in \r\n let y = read_float () in\r\n alternate_sum _B x y 0.0 n\r\n;;\r\n\r\n\r\nlet print_big_float_as_int = fun x ->\r\n if (x!='.') then print_char (x)\r\n;;\r\n\r\nlet rec iter_cases = function \r\n | 0 -> 0\r\n | n -> \r\n let sum = run_case () in \r\n (*let _ = String.iter print_big_float_as_int (string_of_float sum) in*)\r\n Printf.printf \"%.0f\" sum;\r\n print_newline ();\r\n iter_cases (n-1)\r\n;;\r\n\r\nlet t = read_int () in \r\niter_cases t ;;", "positive_code": [{"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let n, b, x, y = Scanf.sscanf (input_line stdin) \"%d %d %d %d\" (fun n b x y -> (n,b,x,y)) in\r\n let tot= ref (Int64.zero) in\r\n let curr = ref (Int64.zero) in\r\n for j = 1 to n do\r\n if Int64.add (!tot) (Int64.of_int x) <= Int64.of_int b then \r\n (tot := Int64.add (!tot) (Int64.of_int x) ; curr := Int64.add (!curr) (!tot))\r\n else (tot := Int64.add (!tot) (Int64.of_int (-y)) ; curr := Int64.add (!curr) (!tot)) ; \r\n done;\r\n print_endline (Int64.to_string !curr ) \r\ndone;\r\n;;"}], "negative_code": [{"source_code": "(* \r\n build sequence a0, a1, ... , an\r\n a0 = 0, \r\n 1)ai = a(i-1)+x or 2)ai = a(i-1)-y\r\n ai <= B \r\n \r\n maximise sum\r\n \r\n want all ai to be as close to B as possible\r\n - do 1) up to B then (2) and (1) alternating\r\n \r\n a0, a1, a2, ... , ak, a(k+1), ... , an\r\n \r\n 0, x, 2*x, ... , k*x where k*x <= B, k*x-y, ... , an\r\n \r\n sum = (x+2*x+...+k*x) + floor((n-k)/2)*(k*x-y+k*x) + (k*x-y if n-k is not even)\r\n \r\n n=5, B=100, x=1, y=30\r\n \r\n 0, 1, 2, 3, 4, 5 = 5/2(5+1) =15\r\n \r\n \r\n n=7, B=1e8, x=1e8, y=1e8\r\n \r\n 0, 1e8, 0, 1e8, 0, 1e8, 0 = 7\r\n \r\n k = 1e8 / 1e8 = 1 < n\r\n s1 = (1e8*1*2/2)=1e8\r\n s2 = 6*(1e8)/2 = 3*1e8\r\n n-k is even so 4*1e8\r\n \r\n n=4, B=1, x=7, y=3\r\n \r\n 0, -3, 4 -> PROBLEM!\r\n \r\n k = 1 / 7 = 0 \r\n s1 = 0\r\n s2 = (4)*(2*0-3)/2=-6 \r\n \r\n add +x until no longer possible\r\n need to -y until we can +x\r\n add +x \r\n need to -y until we can +x\r\n repeat O(n) complexity\r\n \r\n add +x k1 times\r\n subtract y k2 times\r\n add x\r\n subtract y k2 times\r\n O(1) complexity if we calculate k1 and k2\r\n \r\n k1*x-k2*y + x<=B\r\n (k1+1)*x-B<=k2*y\r\n ((k1+1)*x-B)/y <= k2, since k2 isn't necessarily constant we have to do O(n)\r\n \r\n e.g 0, -3, -6, 1, -2, -5, -8, 0 (goes from 2 to 3)\r\n \r\n n=5, B=100, x=1, y=30\r\n \r\n 0 + alternate_sum 100 1 30 1 4\r\n 0 + 1 + alternate_sum ... 2 3\r\n 0 + 1 + 2 + ... 3 2\r\n 0 + 1 + 2 + 3 + ... 4 1\r\n 0 + 1 + 2 + 3 + 4 + ... 5 0\r\n 0 + 1 + 2 + 3 + 4 + 5\r\n \r\n *)\r\n \r\n \r\n \r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x -> x);;\r\n \r\nlet rec alternate_sum _B x y current = function \r\n | 0 -> current\r\n | n -> \r\n if (current +. x<=_B) then current +. alternate_sum _B x y (current +. x) (n-1)\r\n else current +. alternate_sum _B x y (current -. y) (n-1)\r\n;;\r\n \r\nlet run_case = function\r\n | () -> \r\n let n = read_int () in \r\n let _B = read_float () in \r\n let x = read_float () in \r\n let y = read_float () in\r\n alternate_sum _B x y 0.0 n\r\n;;\r\n \r\n \r\nlet print_big_float_as_int = fun x ->\r\n if (x!='.') then print_char (x)\r\n;;\r\n\r\nlet rec print_big_float_as_int2 = function\r\n| current_float, current_order ->\r\n if (current_float <= float_of_int max_int) then current_float, current_order\r\n else print_big_float_as_int2 ((current_float/.10.0), (current_order+1))\r\n;;\r\nlet rec print_order = function \r\n | 0 -> ()\r\n | n ->\r\n print_int 0;\r\n print_order (n-1)\r\n;;\r\nlet rec iter_cases = function \r\n | 0 -> 0\r\n | n -> \r\n let sum = run_case () in \r\n (* let _ = String.iter print_big_float_as_int (string_of_float sum) in *)\r\n let float_int, order = print_big_float_as_int2 (sum, 0) in \r\n print_int (int_of_float float_int);\r\n print_order order;\r\n print_newline ();\r\n iter_cases (n-1)\r\n;;\r\n \r\nlet t = read_int () in \r\niter_cases t ;;"}, {"source_code": "(* \r\n build sequence a0, a1, ... , an\r\n a0 = 0, \r\n 1)ai = a(i-1)+x or 2)ai = a(i-1)-y\r\n ai <= B \r\n \r\n maximise sum\r\n \r\n want all ai to be as close to B as possible\r\n - do 1) up to B then (2) and (1) alternating\r\n\r\n a0, a1, a2, ... , ak, a(k+1), ... , an\r\n\r\n 0, x, 2*x, ... , k*x where k*x <= B, k*x-y, ... , an\r\n\r\n sum = (x+2*x+...+k*x) + floor((n-k)/2)*(k*x-y+k*x) + (k*x-y if n-k is not even)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0, 1, 2, 3, 4, 5 = 5/2(5+1) =15\r\n\r\n \r\n n=7, B=1e8, x=1e8, y=1e8\r\n\r\n 0, 1e8, 0, 1e8, 0, 1e8, 0 = 7\r\n\r\n k = 1e8 / 1e8 = 1 < n\r\n s1 = (1e8*1*2/2)=1e8\r\n s2 = 6*(1e8)/2 = 3*1e8\r\n n-k is even so 4*1e8\r\n\r\n n=4, B=1, x=7, y=3\r\n\r\n 0, -3, 4 -> PROBLEM!\r\n\r\n k = 1 / 7 = 0 \r\n s1 = 0\r\n s2 = (4)*(2*0-3)/2=-6 \r\n\r\n add +x until no longer possible\r\n need to -y until we can +x\r\n add +x \r\n need to -y until we can +x\r\n repeat O(n) complexity\r\n\r\n add +x k1 times\r\n subtract y k2 times\r\n add x\r\n subtract y k2 times\r\n O(1) complexity if we calculate k1 and k2\r\n\r\n k1*x-k2*y + x<=B\r\n (k1+1)*x-B<=k2*y\r\n ((k1+1)*x-B)/y <= k2, since k2 isn't necessarily constant we have to do O(n)\r\n\r\n e.g 0, -3, -6, 1, -2, -5, -8, 0 (goes from 2 to 3)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0 + alternate_sum 100 1 30 1 4\r\n 0 + 1 + alternate_sum ... 2 3\r\n 0 + 1 + 2 + ... 3 2\r\n 0 + 1 + 2 + 3 + ... 4 1\r\n 0 + 1 + 2 + 3 + 4 + ... 5 0\r\n 0 + 1 + 2 + 3 + 4 + 5\r\n\r\n *)\r\n\r\n\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x -> x);;\r\n\r\nlet rec alternate_sum _B x y current = function \r\n | 0 -> current\r\n | n -> \r\n if (current +. x<=_B) then current +. alternate_sum _B x y (current +. x) (n-1)\r\n else current +. alternate_sum _B x y (current -. y) (n-1)\r\n;;\r\n\r\nlet run_case = function\r\n | () -> \r\n let n = read_int () in \r\n let _B = read_float () in \r\n let x = read_float () in \r\n let y = read_float () in\r\n alternate_sum _B x y 0.0 n\r\n;;\r\n\r\n\r\nlet print_big_float_as_int = fun x ->\r\n if (x!='.') then print_char (x)\r\n;;\r\n\r\nlet rec iter_cases = function \r\n | 0 -> 0\r\n | n -> \r\n let sum = run_case () in \r\n let _ = String.iter print_big_float_as_int (string_of_float sum) in\r\n print_newline ();\r\n iter_cases (n-1)\r\n;;\r\n\r\nlet t = read_int () in \r\niter_cases t ;;\r\n"}, {"source_code": "(* \r\n build sequence a0, a1, ... , an\r\n a0 = 0, \r\n 1)ai = a(i-1)+x or 2)ai = a(i-1)-y\r\n ai <= B \r\n \r\n maximise sum\r\n \r\n want all ai to be as close to B as possible\r\n - do 1) up to B then (2) and (1) alternating\r\n\r\n a0, a1, a2, ... , ak, a(k+1), ... , an\r\n\r\n 0, x, 2*x, ... , k*x where k*x <= B, k*x-y, ... , an\r\n\r\n sum = (x+2*x+...+k*x) + floor((n-k)/2)*(k*x-y+k*x) + (k*x-y if n-k is not even)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0, 1, 2, 3, 4, 5 = 5/2(5+1) =15\r\n\r\n \r\n n=7, B=1e8, x=1e8, y=1e8\r\n\r\n 0, 1e8, 0, 1e8, 0, 1e8, 0 = 7\r\n\r\n k = 1e8 / 1e8 = 1 < n\r\n s1 = (1e8*1*2/2)=1e8\r\n s2 = 6*(1e8)/2 = 3*1e8\r\n n-k is even so 4*1e8\r\n\r\n n=4, B=1, x=7, y=3\r\n\r\n 0, -3, 4 -> PROBLEM!\r\n\r\n k = 1 / 7 = 0 \r\n s1 = 0\r\n s2 = (4)*(2*0-3)/2=-6 \r\n\r\n add +x until no longer possible\r\n need to -y until we can +x\r\n add +x \r\n need to -y until we can +x\r\n repeat O(n) complexity\r\n\r\n add +x k1 times\r\n subtract y k2 times\r\n add x\r\n subtract y k2 times\r\n O(1) complexity if we calculate k1 and k2\r\n\r\n k1*x-k2*y + x<=B\r\n (k1+1)*x-B<=k2*y\r\n ((k1+1)*x-B)/y <= k2, since k2 isn't necessarily constant we have to do O(n)\r\n\r\n e.g 0, -3, -6, 1, -2, -5, -8, 0 (goes from 2 to 3)\r\n\r\n n=5, B=100, x=1, y=30\r\n\r\n 0 + alternate_sum 100 1 30 1 4\r\n 0 + 1 + alternate_sum ... 2 3\r\n 0 + 1 + 2 + ... 3 2\r\n 0 + 1 + 2 + 3 + ... 4 1\r\n 0 + 1 + 2 + 3 + 4 + ... 5 0\r\n 0 + 1 + 2 + 3 + 4 + 5\r\n\r\n *)\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x -> x);;\r\n\r\nlet rec alternate_sum _B x y current = function \r\n | 0 -> current\r\n | n -> \r\n if (current +. x<=_B) then current +. alternate_sum _B x y (current +. x) (n-1)\r\n else current +. alternate_sum _B x y (current -. y) (n-1)\r\n;;\r\n\r\nlet run_case = function\r\n | () -> \r\n let n = read_int () in \r\n let _B = read_float () in \r\n let x = read_float () in \r\n let y = read_float () in\r\n alternate_sum _B x y 0.0 n\r\n;;\r\n\r\nlet rec iter_cases = function \r\n | 0 -> 0\r\n | n -> \r\n print_float (run_case ());\r\n print_newline ();\r\n iter_cases (n-1)\r\n;;\r\n\r\nlet t = read_int () in \r\niter_cases t ;;\r\n"}], "src_uid": "2c921093abf2c5963f5f0e96cd430456"} {"source_code": "Scanf.(Array.(scanf \" %d %d\" @@ fun x y ->\n let map = make_matrix 1000 1000 false in\n let rooks = make 666 (0,0) in\n init 666 (fun i ->\n scanf \" %d %d\" @@ fun x y ->\n (map.(x).(y) <- true; rooks.(i) <- x,y)\n ) |> ignore;\n let x,y = ref x,ref y in\n let rec move p q =\n if map.(!x+p).(!y+q) then (\n move p 0\n ) else (\n x := !x + p;\n y := !y + q;\n Printf.printf \"%d %d\\n%!\" !x !y;\n let i,u,v = scanf \" %d %d %d\" @@ fun p q r -> p,q,r in\n if i=0 && u=0 && v=0 then exit 0 (* WA *)\n else if i= -1 && u= -1 && v= -1 then exit 0 (* AC *)\n else (\n let pu,pv = rooks.(i-1) in\n map.(pu).(pv) <- false;\n map.( u).( v) <- true;\n rooks.(i-1) <- u,v;\n Printf.eprintf \"%d: %d,%d --> %d %d\\n%!\" i pu pv u v;\n )\n )\n in\n while !x <> 500 || !y <> 500 do\n if !x < 500 then move 1 0\n else if !x > 500 then move (-1) 0\n else if !y < 500 then move 0 1\n else if !y > 500 then move 0 (-1)\n done;\n let tr,tl,bl,br = fold_left (fun (p,q,r,s) (x,y) ->\n match x>500, y>500 with\n (* t/f: right/left, top/bottom *)\n | true, true -> (p+1,q,r,s)\n | false, true -> (p,q+1,r,s)\n | false,false -> (p,q,r+1,s)\n | true,false -> (p,q,r,s+1)\n ) (0,0,0,0) rooks\n in\n Printf.eprintf \"%d; %d; %d; %d\\n%!\" tr tl bl br;\n let mn = fold_left min br [|tr;tl;bl|] in\n ignore @@ init 499 @@ fun _ ->\n if mn=tr then move (-1) (-1)\n else if mn=tl then move 1 (-1)\n else if mn=bl then move 1 1\n else move (-1) 1\n))", "positive_code": [{"source_code": "open Printf\nopen String\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet nrooks = (* 6 *) 666\nlet (maxx,maxy) = (* (9,9) *) (999,999)\nlet (cx,cy) = ((maxx+1)/2, (maxy+1)/2)\n \nlet split_string s = \n let s = trim s in\n \n let n = String.length s in\n let li = fold 0 (n-1) \n (fun i ac -> if s.[i] = ' ' then i::ac else ac) []\n in\n\n let rec chop prev li ac = \n match li with [] -> List.rev ac\n | i::tail -> \n\tchop i tail ((sub s (prev+1) (i-prev-1))::ac)\n in\n \n chop (-1) (List.rev (n::li)) []\n\nlet read_ints () = \n let c = split_string (read_line()) in\n let c = List.map (fun s -> int_of_string s) c in\n Array.of_list c\n\nlet () =\n let rook = Array.make (nrooks+1) (0,0) in\n\n let line1 = read_ints() in\n let (kx, ky) = (line1.(0), line1.(1)) in\n\n for i=1 to nrooks do\n let linei = read_ints() in\n rook.(i) <- (linei.(0), linei.(1));\n done;\n\n let in_check (kx,ky) =\n (* return true if this king is in check *)\n exists 1 nrooks (fun i ->\n let (x,y) = rook.(i) in\n x = kx || y = ky\n ) \n in\n\n let collide (kx,ky) =\n (* return true if the king is on top of a rook *)\n exists 1 nrooks (fun i -> rook.(i) = (kx,ky))\n in\n\n let dirs = [(-1,-1);(-1,0);(-1,1);(0,-1);(0,1);(1,-1);(1,0);(1,1)] in\n\n let rec move_to_goal (kx,ky) (goalx,goaly) = if kx = goalx && ky = goaly then true else (\n (* assume (kx,ky) has already been checked for being in check, or in a collision *)\n(* printf \"move_to_goal (%d,%d) (%d,%d)\\n\" kx ky goalx goaly; *)\n let check_dirs = List.filter (fun (dx,dy) ->\n let (nx,ny) = (kx+dx, ky+dy) in\n nx >= 1 && ny >= 1 && nx<=maxx && ny <= maxy && in_check (nx,ny) && (not (collide (nx,ny)))\n ) dirs in\n\n let (terminal,kx,ky) = \n if check_dirs <> [] then (\n\tlet (dx,dy) = List.hd check_dirs in\n\tlet (kx,ky) = (kx+dx, ky+dy) in\t\n\tprintf \"%d %d\\n\" kx ky;\n\t(true,kx,ky) (* found a winning move *)\n ) else (\n\tlet dx = Pervasives.compare goalx kx in\n\tlet dy = Pervasives.compare goaly ky in\n\tlet (kx,ky) = (kx+dx, ky+dy) in\n\tprintf \"%d %d\\n\" kx ky;\n\t(in_check (kx,ky), kx, ky)\n )\n in\n\n if terminal then false else (\n (* wait for a move from the other guy *)\n let line = read_ints() in\n let (k,x,y) = (line.(0), line.(1), line.(2)) in\n rook.(k) <- (x,y);\n move_to_goal (kx,ky) (goalx,goaly)\n )\n ) in\n\n if move_to_goal (kx,ky) (cx,cy) then (\n let count = Array.make_matrix 2 2 0 in\n for i=1 to nrooks do\n let wx = if fst rook.(i) < cx then 0 else 1 in\n let wy = if snd rook.(i) < cy then 0 else 1 in\n count.(wx).(wy) <- count.(wx).(wy) + 1\n done;\n let (_, i,j) =\n minf 0 1 (fun i ->\n\tminf 0 1 (fun j ->\n\t (count.(i).(j), i, j)\n\t)\n )\n in\n let goalx = [|0;maxx|].(1-i) in\n let goaly = [|0;maxy|].(1-j) in\n\n if move_to_goal (cx,cy) (goalx, goaly) then failwith \"bad\" else ()\n ) else (\n (* the game is already over *)\n )\n"}], "negative_code": [{"source_code": "Scanf.(Array.(scanf \" %d %d\" @@ fun x y ->\n let map = make_matrix 1000 1000 false in\n let rooks = make 666 (0,0) in\n init 666 (fun i ->\n scanf \" %d %d\" @@\n fun x y -> map.(x).(y) <- true;\n rooks.(i) <- x,y) |> ignore;\n let x,y = ref x,ref y in\n let rec move p q =\n if map.(!x+p).(!y+q) then (\n move p 0\n ) else (\n x := !x + p;\n y := !y + q;\n Printf.printf \"%d %d\\n\" !x !y; flush stdout;\n let i,u,v = scanf \" %d %d %d\" @@ fun p q r -> p,q,r in\n if i=0 && u=0 && v=0 then exit 0 (* WA *)\n else if i= -1 && u= -1 && v= -1 then exit 0 (* AC *)\n else (\n let pu,pv = rooks.(i-1) in\n map.(pu).(pv) <- false;\n map.( u).( v) <- true;\n rooks.(i-1) <- u,v;\n Printf.eprintf \"%d: %d,%d --> %d %d\\n\" i pu pv u v; flush stderr\n )\n )\n in\n while !x <> 499 || !y <> 499 do\n if !x < 499 then move 1 0\n else if !x > 499 then move (-1) 0\n else if !y < 499 then move 0 1\n else if !y > 499 then move 0 (-1)\n done;\n let tr,tl,bl,br = fold_left (fun (p,q,r,s) (x,y) ->\n match x>499, y>499 with\n (* t/f: right/left, top/bottom *)\n | true, true -> (p+1,q,r,s)\n | false, true -> (p,q+1,r,s)\n | false,false -> (p,q,r+1,s)\n | true,false -> (p,q,r,s+1)\n ) (0,0,0,0) rooks\n in\n let mn = fold_left min br [|tr;tl;bl|] in\n ignore @@ init 499 @@ fun _ ->\n if mn=tr then move (-1) (-1)\n else if mn=tl then move 1 (-1)\n else if mn=bl then move 1 1\n else move (-1) 1\n))"}, {"source_code": "(* 11:35 *)\nopen Printf\nopen String\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \n \nlet split_string s = \n let s = trim s in\n \n let n = String.length s in\n let li = fold 0 (n-1) \n (fun i ac -> if s.[i] = ' ' then i::ac else ac) []\n in\n\n let rec chop prev li ac = \n match li with [] -> List.rev ac\n | i::tail -> \n\tchop i tail ((sub s (prev+1) (i-prev-1))::ac)\n in\n \n chop (-1) (List.rev (n::li)) []\n\nlet read_ints () = \n let c = split_string (read_line()) in\n let c = List.map (fun s -> int_of_string s) c in\n Array.of_list c\n\nlet () =\n let nrooks = 666 in\n let rook = Array.make (nrooks+1) (0,0) in\n\n let line1 = read_ints() in\n let (kx, ky) = (line1.(0), line1.(1)) in\n\n for i=1 to nrooks do\n let linei = read_ints() in\n rook.(i) <- (linei.(0), linei.(1));\n done;\n\n let in_check (kx,ky) =\n (* return true if this king is in check *)\n exists 1 nrooks (fun i ->\n let (x,y) = rook.(i) in\n x = kx || y = ky\n ) \n in\n\n let collide (kx,ky) =\n (* return true if the king is on top of a rook *)\n exists 1 nrooks (fun i -> rook.(i) = (kx,ky))\n in\n\n let dirs = [(-1,-1);(-1,0);(-1,1);(0,-1);(0,1);(1,-1);(1,0);(1,1)] in\n\n let rec move_to_goal (kx,ky) (goalx,goaly) = if kx = goalx && ky = goaly then true else (\n (* assume (kx,ky) has already been checked for being in check, or in a collision *)\n let check_dirs = List.filter (fun (dx,dy) ->\n let (nx,ny) = (kx+dx, ky+dy) in\n nx >= 1 && ny >= 1 && nx<=999 && ny <= 999 && in_check (nx,ny) && (not (collide (nx,ny)))\n ) dirs in\n\n let terminal = \n if check_dirs <> [] then (\n\tlet (dx,dy) = List.hd check_dirs in\n\tprintf \"%d %d\\n\" (kx+dx) (ky+dy);\n\ttrue (* found a winning move *)\n ) else (\n\tlet dx = Pervasives.compare goalx kx in\n\tlet dy = Pervasives.compare goaly ky in\n\tlet (kx,ky) = (kx+dx, ky+dy) in\n\tprintf \"%d %d\\n\" kx ky;\n\tin_check (kx,ky)\n )\n in\n\n if terminal then false else (\n (* wait for a move from the other guy *)\n let line = read_ints() in\n let (k,x,y) = (line.(0), line.(1), line.(2)) in\n rook.(k) <- (x,y);\n move_to_goal (kx,ky) (goalx,goaly)\n )\n ) in\n\n if move_to_goal (kx,ky) (500,500) then (\n let count = Array.make_matrix 2 2 0 in\n for i=1 to nrooks do\n let wx = if fst rook.(i) < 500 then 0 else 1 in\n let wy = if snd rook.(i) < 500 then 0 else 1 in\n count.(wx).(wy) <- count.(wx).(wy) + 1\n done;\n let (_, i,j) =\n minf 0 1 (fun i ->\n\tminf 0 1 (fun j ->\n\t (count.(i).(j), i, j)\n\t)\n )\n in\n let goalx = [|0;999|].(1-i) in\n let goaly = [|0;999|].(1-j) in\n\n if move_to_goal (500,500) (goalx, goaly) then () else failwith \"bad\"\n ) else (\n (* the game is already over *)\n )\n"}, {"source_code": "(* 11:35 *)\nopen Printf\nopen String\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i) \n \nlet split_string s = \n let s = trim s in\n \n let n = String.length s in\n let li = fold 0 (n-1) \n (fun i ac -> if s.[i] = ' ' then i::ac else ac) []\n in\n\n let rec chop prev li ac = \n match li with [] -> List.rev ac\n | i::tail -> \n\tchop i tail ((sub s (prev+1) (i-prev-1))::ac)\n in\n \n chop (-1) (List.rev (n::li)) []\n\nlet read_ints () = \n let c = split_string (read_line()) in\n let c = List.map (fun s -> int_of_string s) c in\n Array.of_list c\n\nlet () =\n let nrooks = 666 in\n let rook = Array.make (nrooks+1) (0,0) in\n\n let line1 = read_ints() in\n let (kx, ky) = (line1.(0), line1.(1)) in\n\n for i=1 to nrooks do\n let linei = read_ints() in\n rook.(i) <- (linei.(0), linei.(1));\n done;\n\n let in_check (kx,ky) =\n (* return true if this king is in check *)\n exists 1 nrooks (fun i ->\n let (x,y) = rook.(i) in\n x = kx || y = ky\n ) \n in\n\n let collide (kx,ky) =\n (* return true if the king is on top of a rook *)\n exists 1 nrooks (fun i -> rook.(i) = (kx,ky))\n in\n\n let dirs = [(-1,-1);(-1,0);(-1,1);(0,-1);(0,1);(1,-1);(1,0);(1,1)] in\n\n let rec move_to_goal (kx,ky) (goalx,goaly) = if kx = goalx && ky = goaly then true else (\n (* assume (kx,ky) has already been checked for being in check, or in a collision *)\n let check_dirs = List.filter (fun (dx,dy) ->\n let (nx,ny) = (kx+dx, ky+dy) in\n nx >= 0 && ny >= 0 && nx<=999 && ny <= 999 && in_check (nx,ny) && (not (collide (nx,ny)))\n ) dirs in\n\n let terminal = \n if check_dirs <> [] then (\n\tlet (dx,dy) = List.hd check_dirs in\n\tprintf \"%d %d\\n\" (kx+dx) (ky+dy);\n\ttrue (* found a winning move *)\n ) else (\n\tlet dx = Pervasives.compare goalx kx in\n\tlet dy = Pervasives.compare goaly ky in\n\tlet (kx,ky) = (kx+dx, ky+dy) in\n\tprintf \"%d %d\\n\" kx ky;\n\tin_check (kx,ky)\n )\n in\n\n if terminal then false else (\n (* wait for a move from the other guy *)\n let line = read_ints() in\n let (k,x,y) = (line.(0), line.(1), line.(2)) in\n rook.(k) <- (x,y);\n move_to_goal (kx,ky) (goalx,goaly)\n )\n ) in\n\n if move_to_goal (kx,ky) (500,500) then (\n let count = Array.make_matrix 2 2 0 in\n for i=1 to nrooks do\n let wx = if fst rook.(i) < 500 then 0 else 1 in\n let wy = if snd rook.(i) < 500 then 0 else 1 in\n count.(wx).(wy) <- count.(wx).(wy) + 1\n done;\n let (_, i,j) =\n minf 0 1 (fun i ->\n\tminf 0 1 (fun j ->\n\t (count.(i).(j), i, j)\n\t)\n )\n in\n let goalx = [|0;999|].(1-i) in\n let goaly = [|0;999|].(1-j) in\n\n if move_to_goal (500,500) (goalx, goaly) then () else failwith \"bad\"\n ) else (\n (* the game is already over *)\n )\n"}], "src_uid": "3d38584c3bb29e6f84546643b1be8026"} {"source_code": "open Stack\nopen Array\n\ntype node = {\n l : int;\n r : int;\n x : int;\n left : node;\n right : node\n}\n\nlet rec dummy = { l = 0; r = -1; x = -1; left = dummy; right = dummy }\n\nlet build_min a =\n let next l a a' =\n let rec next i i' =\n if i > l - 1 then i'\n else if i = l - 1 then (a'.(i') <- a.(i); i' + 1)\n else\n let left = a.(i) and right = a.(i + 1) in\n a'.(i') <- { l = left.l; r = right.r; x = min left.x right.x; left; right };\n next (i + 2) (i' + 1)\n in\n next\n in\n let rec build l a =\n match l with\n | 0 -> dummy\n | 1 -> a.(0)\n | l ->\n let a' = make (l / 2 + 1) dummy in\n let l' = next l a a' 0 0 in\n build l' a'\n in\n let a = mapi (fun i x -> { l = i; r = i; x; left = dummy; right = dummy}) a in\n build (length a) a\n\nlet many = 10000000\n\nlet find_min root l r =\n let rec find root =\n if root.r < l || root.l > r then many\n else if l <= root.l && root.r <= r then root.x\n else min (find root.left) (find root.right)\n in\n find root\n\nlet search compare return arr =\n let rec search l r =\n if r = l + 1 then Some (match return with `Left -> l | `Right -> r)\n else\n let m = l + (r - l) / 2 in\n match compare arr.(m) with\n | `Eq -> Some m\n | `Lt -> search m r\n | `Gt -> search l m\n in\n let l = 0 and r = length arr - 1 in\n if r < l then None\n else\n let cl = compare arr.(l) and cr = compare arr.(r) in\n if cl = `Gt then (if return = `Right then Some l else None)\n else if cr = `Lt then (if return = `Left then Some r else None)\n else if cl = `Eq then Some l\n else if cr = `Eq then Some r\n else search l r\n\nlet cmp (a : int) b = if a < b then `Lt else if a > b then `Gt else `Eq\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = init n (fun i -> scanf \"%d \" @@ fun x -> x, i) in\n sort compare ns;\n let lrs = ref [] in\n iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = of_list !lrs in\n sort compare lrs;\n let s = Stack.create () in\n iter\n (fun (_, r as lr) ->\n while not (is_empty s) && snd (top s) > r do ignore (pop s) done;\n push lr s)\n lrs;\n let lrs = init (Stack.length s) (fun _ -> pop s) in\n (let l = length lrs in\n for i = 0 to l / 2 - 1 do let t = lrs.(l - i - 1) in lrs.(l - i - 1) <- lrs.(i); lrs.(i) <- t done);\n let search_left l' = search (fun (l, _) -> cmp l l') `Right lrs in\n let search_right r' = search (fun (_, r) -> cmp r r') `Left lrs in\n let root = build_min @@ map (fun (l, r) -> r - l) lrs in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n match search_left (l - 1), search_right (r - 1) with\n | Some l, Some r ->\n Printf.printf \"%d\\n\" (let r = find_min root l r in if r = many then -1 else r)\n | _ -> Printf.printf \"-1\\n\"\n done\n", "positive_code": [{"source_code": "(*[@@@warning \"-30\"]*)\n\ntype node = {\n l : int;\n r : int;\n x : int;\n left : node;\n right : node\n}\n\nlet rec dummy = { l = 0; r = -1; x = -1; left = dummy; right = dummy }\n\nlet build_min a =\n let next l a a' =\n let rec next i i' =\n if i > l - 1 then i'\n else if i = l - 1 then begin a'.(i') <- a.(i); i' + 1 end\n else begin\n let left = a.(i) and right = a.(i + 1) in\n a'.(i') <- { l = left.l; r = right.r; x = min left.x right.x; left; right };\n next (i + 2) (i' + 1)\n end\n in\n next\n in\n let rec build l a =\n match l with\n | 0 -> dummy\n | 1 -> a.(0)\n | l ->\n let a' = Array.make (l / 2 + 1) dummy in\n let l' = next l a a' 0 0 in\n build l' a'\n in\n let a = Array.mapi (fun i x -> { l = i; r = i; x; left = dummy; right = dummy}) a in\n build (Array.length a) a\n\nlet many = 10000000\n\nlet find_min root l r =\n let rec find root =\n if root.r < l || root.l > r then many\n else if l <= root.l && root.r <= r then root.x\n else\n min (find root.left) (find root.right)\n in\n find root\n\ntype cmp = Lt | Gt | Eq\n\ntype return = Left | Right\n\nlet search compare return arr =\n let rec search l r =\n if r = l + 1 then Some (match return with Left -> l | Right -> r)\n else\n let m = l + (r - l) / 2 in\n match compare arr.(m) with\n | Eq -> Some m\n | Lt -> search m r\n | Gt -> search l m\n in\n let l = 0 and r = Array.length arr - 1 in\n if r < l then None\n else\n let cl = compare arr.(l) and cr = compare arr.(r) in\n if cl = Gt then (if return = Right then Some l else None)\n else if cr = Lt then (if return = Left then Some r else None)\n else if cl = Eq then Some l\n else if cr = Eq then Some r\n else search l r\n\nlet cmp (a : int) b = if a < b then Lt else if a > b then Gt else Eq\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = Array.(init n (fun i -> scanf \"%d \" @@ fun x -> x, i)) in\n Array.sort compare ns;\n let lrs = ref [] in\n Array.iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = Array.of_list !lrs in\n Array.sort compare lrs;\n let s = Stack.create () in\n Array.iter\n (fun (_, r as lr) ->\n while not (Stack.is_empty s) && snd (Stack.top s) > r do ignore (Stack.pop s) done;\n Stack.push lr s)\n lrs;\n let lrs = Array.init (Stack.length s) (fun _ -> Stack.pop s) in\n (let l = Array.length lrs in\n for i = 0 to l / 2 - 1 do let t = lrs.(l - i - 1) in lrs.(l - i - 1) <- lrs.(i); lrs.(i) <- t done);\n let search_left l' = search (fun (l, _) -> cmp l l') Right lrs in\n let search_right r' = search (fun (_, r) -> cmp r r') Left lrs in\n let root = build_min @@ Array.map (fun (l, r) -> r - l) lrs in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n match search_left (l - 1), search_right (r - 1) with\n | Some l, Some r ->\n Printf.printf \"%d\\n\" (let r = find_min root l r in if r = many then -1 else r)\n | _ -> Printf.printf \"-1\\n\"\n done\n"}, {"source_code": "open Stack\nopen Array\n\ntype node = {\n l : int;\n r : int;\n x : int;\n left : node;\n right : node\n}\n\nlet rec dummy = { l = 0; r = -1; x = -1; left = dummy; right = dummy }\n\nlet build_min a =\n let next l a a' =\n let rec next i i' =\n if i > l - 1 then i'\n else if i = l - 1 then (a'.(i') <- a.(i); i' + 1)\n else\n let left = a.(i) and right = a.(i + 1) in\n a'.(i') <- { l = left.l; r = right.r; x = min left.x right.x; left; right };\n next (i + 2) (i' + 1)\n in\n next\n in\n let rec build l a =\n match l with\n | 0 -> dummy\n | 1 -> a.(0)\n | l ->\n let a' = make (l / 2 + 1) dummy in\n let l' = next l a a' 0 0 in\n build l' a'\n in\n let a = mapi (fun i x -> { l = i; r = i; x; left = dummy; right = dummy}) a in\n build (length a) a\n\nlet many = 10000000\n\nlet find_min root l r =\n let rec find root =\n if root.r < l || root.l > r then many\n else if l <= root.l && root.r <= r then root.x\n else min (find root.left) (find root.right)\n in\n find root\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = init n (fun i -> scanf \"%d \" @@ fun x -> x, i) in\n sort compare ns;\n let lrs = ref [] in\n iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = of_list !lrs in\n sort compare lrs;\n let s = Stack.create () in\n iter\n (fun (_, r as lr) ->\n while not (is_empty s) && snd (top s) > r do ignore (pop s) done;\n push lr s)\n lrs;\n let lrs = init (Stack.length s) (fun _ -> pop s) in\n let l = length lrs in\n for i = 0 to l / 2 - 1 do let t = lrs.(l - i - 1) in lrs.(l - i - 1) <- lrs.(i); lrs.(i) <- t done;\n let ls, rs = make n ~-1, make n ~-1 in\n ignore @@ fold_left (fun (p, i) (l, _) -> for j = p + 1 to l do ls.(j) <- i done; l, i + 1) (~-1, 0) lrs;\n ignore @@ fold_right (fun (_, r) (p, i) -> for j = r to p - 1 do rs.(j) <- i done; r, i - 1) lrs (n, l - 1);\n let root = build_min @@ map (fun (l, r) -> r - l) lrs in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n let l = ls.(l - 1) and r = rs.(r - 1) in\n if l >= 0 && r >= 0 then Printf.printf \"%d\\n\" (let r = find_min root l r in if r = many then -1 else r)\n else Printf.printf \"-1\\n\"\n done\n"}, {"source_code": "open Stack\nopen Array\n\nlet upd_min a n i (v : int) =\n let rec upd p l r =\n if l <= i && i <= r then begin\n if v < a.(p) then a.(p) <- v;\n if r - l >= 1 then\n let m = l + (r - l) / 2 in\n upd (p lsl 1 + 1) l m;\n upd ((p + 1) lsl 1) (m + 1) r\n end\n in\n upd 0 0 (n - 1)\n\nlet big_n = 10000000\n\nlet find_min a n l r =\n let rec find p l' r' =\n if r' < l || l' > r then big_n\n else if l <= l' && r' <= r then a.(p)\n else if r' - l' >= 1 then\n let m = l' + (r' - l') / 2 in\n min (find (p lsl 1 + 1) l' m) (find ((p + 1) lsl 1) (m + 1) r')\n else big_n\n in\n find 0 0 (n - 1)\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = init n (fun i -> scanf \"%d \" @@ fun x -> x, i) in\n sort compare ns;\n let lrs = ref [] in\n iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = of_list !lrs in\n sort compare lrs;\n let s = Stack.create () in\n iter\n (fun (_, r as lr) ->\n while not (is_empty s) && snd (top s) > r do ignore (pop s) done;\n push lr s)\n lrs;\n let lrs = init (Stack.length s) (fun _ -> pop s) in\n let len = length lrs in\n for i = 0 to len / 2 - 1 do let t = lrs.(len - i - 1) in lrs.(len - i - 1) <- lrs.(i); lrs.(i) <- t done;\n let ls, rs = make n ~-1, make n ~-1 in\n ignore @@ fold_left (fun (p, i) (l, _) -> for j = p + 1 to l do ls.(j) <- i done; l, i + 1) (~-1, 0) lrs;\n ignore @@ fold_right (fun (_, r) (p, i) -> for j = r to p - 1 do rs.(j) <- i done; r, i - 1) lrs (n, len - 1);\n let a = make (n * 3 + 1) big_n in\n iteri (fun i (l, r) -> upd_min a len i (r - l)) lrs;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n let l = ls.(l - 1) and r = rs.(r - 1) in\n if l >= 0 && r >= 0 then Printf.printf \"%d\\n\" (let r = find_min a len l r in if r = big_n then -1 else r)\n else Printf.printf \"-1\\n\"\n done\n"}], "negative_code": [{"source_code": "\ntype sub = {\n mutable bl : node;\n mutable br : node;\n mutable tr : node\n}\nand node =\n | Empty\n | Node of int ref * sub\n\ntype tree = { mutable root : node; size : int }\n\nlet empty = 0, -1, 0, -1\n\nlet split (lmin, lmax, rmin, rmax) =\n let lmid = lmin + (lmax - lmin) / 2 in\n let rmid = rmin + (rmax - rmin) / 2 in\n if lmin < lmax && rmin < rmax then\n (lmin, lmid, rmin, rmid),\n (lmin, lmid, rmid + 1, rmax),\n (lmid + 1, lmax, rmid + 1, rmax)\n else if lmin < lmax then\n (lmin, lmid, rmin, rmax),\n empty,\n (lmid + 1, lmax, rmin, rmax)\n else if rmin < rmax then\n (lmin, lmax, rmin, rmid),\n (lmin, lmax, rmid + 1, rmax),\n empty\n else\n empty, empty, empty\n\nlet add ({ root; size } as t) l r =\n let dist = r - l in\n let rec add (lmin, lmax, rmin, rmax as rect) t =\n if lmin <= l && l <= lmax && rmin <= r && r <= rmax then\n match t with\n | Empty ->\n let r = { bl = Empty; br = Empty; tr = Empty } in\n add' rect r;\n Node (ref dist, r)\n | Node (min, r) as node ->\n add' rect r;\n if dist < !min then min := dist;\n node\n else t\n and add' rect r =\n let bl, br, tr = split rect in\n r.bl <- add bl r.bl;\n r.br <- add br r.br;\n r.tr <- add tr r.tr\n in\n t.root <- add (0, size - 1, 0, size - 1) root\n\nlet none = max_int\n\nlet min { root; size } l r =\n let rec min (lmin, lmax, rmin, rmax as rect) =\n function\n | Empty -> none\n | _ when lmin > lmax || rmin > rmax -> none\n | Node (m, _)\n when l <= lmin && lmax <= r && l <= rmin && rmax <= r -> !m\n | Node _\n when r < lmin || l > lmax || r < rmin || l > rmax -> none\n | Node (_, rct) ->\n let bl, br, tr = split rect in\n let bl = min bl rct.bl and br = min br rct.br and tr = min tr rct.tr in\n let br = if bl < br then bl else br in\n if br < tr then br else tr\n in\n min (0, size - 1, 0, size - 1) root\n\ntype element = { v : int64; i : int }\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let seq = Array.init n (fun i -> scanf \"%Ld \" @@ fun v -> { v; i }) in\n Array.sort\n (fun e1 e2 ->\n let r = Int64.compare e1.v e2.v in\n if r <> 0 then r else compare e1.i e2.i)\n seq;\n let t = { root = Empty; size = n } in\n Array.iteri (fun i v -> if i < n - 1 && v.v = seq.(i + 1).v then add t v.i seq.(i + 1).i) seq;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r -> Printf.printf \"%d\\n\" @@ let m = min t (l - 1) (r - 1) in if m = none then -1 else m\n done\n\n"}, {"source_code": "\ntype sub = {\n mutable bl : node;\n mutable br : node;\n mutable tr : node\n}\nand node =\n | Empty\n | Node of int ref * sub\n\ntype tree = { mutable root : node; size : int }\n\nlet empty = 0, -1, 0, -1\n\nlet split (lmin, lmax, rmin, rmax) =\n let lmid = lmin + (lmax - lmin) / 2 in\n let rmid = rmin + (rmax - rmin) / 2 in\n if lmin < lmax && rmin < rmax then\n (lmin, lmid, rmin, rmid),\n (lmin, lmid, rmid + 1, rmax),\n (lmid + 1, lmax, rmid + 1, rmax)\n else if lmin < lmax then\n (lmin, lmid, rmin, rmax),\n (lmid + 1, lmax, rmin, rmax),\n empty\n else if rmin < rmax then\n (lmin, lmax, rmin, rmid),\n (lmin, lmax, rmid + 1, rmax),\n empty\n else\n empty, empty, empty\n\nlet add ({ root; size } as t) l r =\n let dist = r - l in\n let rec add (lmin, lmax, rmin, rmax as rect) t =\n if lmin <= l && l <= lmax && rmin <= r && r <= rmax then\n match t with\n | Empty ->\n let r = { bl = Empty; br = Empty; tr = Empty } in\n add' rect r;\n Node (ref dist, r)\n | Node (min, r) as node ->\n add' rect r;\n if dist < !min then min := dist;\n node\n else t\n and add' rect r =\n let bl, br, tr = split rect in\n r.bl <- add bl r.bl;\n r.br <- add br r.br;\n r.tr <- add tr r.tr\n in\n t.root <- add (0, size - 1, 0, size - 1) root\n\nlet none = max_int\n\nlet min { root; size } l r =\n let rec min (lmin, lmax, rmin, rmax as rect) =\n function\n | Empty -> none\n | Node (m, _)\n when l <= lmin && lmax <= r && l <= rmin && rmax <= r -> !m\n | Node _\n when r < lmin || l > lmax || r < rmin || l > rmax -> none\n | Node (_, rct) ->\n let bl, br, tr = split rect in\n let bl = min bl rct.bl and br = min br rct.br and tr = min tr rct.tr in\n let br = if bl < br then bl else br in\n if br < tr then br else tr\n in\n min (0, size - 1, 0, size - 1) root\n\ntype element = { v : int; i : int }\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let seq = Array.init n (fun i -> scanf \"%d \" @@ fun v -> { v; i }) in\n Array.sort compare seq;\n let t = { root = Empty; size = n } in\n Array.iteri (fun i v -> if i < n - 1 && v.v = seq.(i + 1).v then add t v.i seq.(i + 1).i) seq;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r -> Printf.printf \"%d\\n\" @@ let m = min t (l - 1) (r - 1) in if m = none then -1 else m\n done\n\n"}, {"source_code": "\ntype sub = {\n mutable bl : node;\n mutable br : node;\n mutable tl : node;\n mutable tr : node\n}\nand node =\n | Empty\n | Node of int * sub\n\ntype tree = { mutable root : node; size : int }\n\nlet split (lmin, lmax, rmin, rmax) =\n let lmid = lmin + (lmax - lmin) / 2 in\n let rmid = rmin + (rmax - rmin) / 2 in\n let empty = 0, -1, 0, -1 in\n if lmin < lmax && rmin < rmax then\n (lmin, lmid, rmin, rmid),\n (lmin, lmid, rmid + 1, rmax),\n (lmid + 1, lmax, rmin, rmid),\n (lmid + 1, lmax, rmid + 1, rmax)\n else if lmin < lmax then\n (lmin, lmid, rmin, rmax),\n empty,\n (lmid + 1, lmax, rmin, rmax),\n empty\n else if rmin < rmax then\n (lmin, lmax, rmin, rmid),\n (lmin, lmax, rmid + 1, rmax),\n empty,\n empty\n else\n empty, empty, empty, empty\n\nlet inside l r (lmin, lmax, rmin, rmax) =\n lmin <= l && l <= lmax && rmin <= r && r <= rmax\n\nlet add ({ root; size } as t) l r =\n let dist = r - l in\n let rec add rect =\n if inside l r rect then\n let add r =\n let bl, br, tl, tr = split rect in\n r.bl <- add bl r.bl;\n r.br <- add br r.br;\n r.tl <- add tl r.tl;\n r.tr <- add tr r.tr\n in\n function\n | Empty ->\n let r = { bl = Empty; br = Empty; tl = Empty; tr = Empty } in\n add r;\n Node (dist, r)\n | Node (min, r) as node ->\n add r;\n if dist < min then Node (dist, r) else node\n else fun x -> x\n in\n t.root <- add (0, size - 1, 0, size - 1) root\n\nlet none = -1\n\nlet min4 x y z k =\n let min x y = if x = none then y else if y = none then x else if x < y then x else y in\n List.fold_left min none [x; y; z; k]\n\nlet min { root; size } l r =\n let rec min (lmin, lmax, rmin, rmax as rect) =\n function\n | Empty -> none\n | Node _\n when not (inside l l rect || inside l r rect || inside r l rect || inside r r rect) -> none\n | Node (m, rct) ->\n if l <= lmin && lmax <= r && l <= rmin && rmax <= r then m\n else\n let bl, br, tl, tr = split rect in\n min4 (min bl rct.bl) (min br rct.br) (min tl rct.tl) (min tr rct.tr)\n in\n min (0, size - 1, 0, size - 1) root\n\ntype element = { v : int; i : int }\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let seq = Array.init n (fun i -> scanf \"%d \" @@ fun v -> { v; i }) in\n Array.sort compare seq;\n let t = { root = Empty; size = n } in\n Array.iteri (fun i v -> if i < n - 1 && v.v = seq.(i + 1).v then add t v.i seq.(i + 1).i) seq;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r -> Printf.printf \"%d\\n\" @@ min t (l - 1) (r - 1)\n done\n\n"}, {"source_code": "type cmp = Le | Gt\n\nlet cmp a b =\n if a <= b then Le\n else Gt\n\ntype node = {\n l : int;\n r : int;\n mutable ll : quadr;\n mutable lr : quadr;\n mutable rl : quadr;\n mutable rr : quadr;\n}\nand quadr = Some of node | None\n\nlet rec merge a b =\n match a, b with\n | None, None -> None\n | Some _, None -> a\n | None, Some _ -> b\n | Some p, Some c ->\n let lp, rp, lc, rc, p, c, r =\n match cmp (abs (p.r - p.l)) (abs (c.r - c.l)) with\n | Le -> p.l, p.l, c.l, c.l, a, b, p\n | Gt -> c.l, c.r, p.l, p.r, b, a, c\n in\n begin match cmp lp lc, cmp rp rc with\n | Le, Le -> r.ll <- merge r.ll c\n | Le, Gt -> r.lr <- merge r.lr c\n | Gt, Le -> r.rl <- merge r.rl c\n | Gt, Gt -> r.rr <- merge r.rr c\n end;\n p\n\nlet add (l, r) t = merge t (Some { l; r; ll = None; lr = None; rl = None; rr = None })\n\nlet rec find t ((l, r) as e) =\n match t with\n | None -> -1\n | Some { l = l'; r = r'; ll; lr; rl; rr } ->\n let try2 a b =\n let a, b = find a e, find b e in\n match cmp 0 a, cmp 0 b, cmp a b with\n | Le, Le, Le -> a\n | Le, Le, Gt -> b\n | Le, Gt, _ -> a\n | Gt, Le, _ -> b\n | Gt, Gt, _ -> -1\n in\n match cmp l l', cmp r' r, cmp l' r, cmp l r' with\n | Le, Le, _, _ -> abs (r' - l')\n | Le, Gt, Le, _ -> try2 lr rr\n | Le, Gt, Gt, _ -> find rr e\n | Gt, Le, _, Le -> try2 ll lr\n | Gt, Le, _, Gt -> find ll e\n | Gt, Gt, _, _ -> find lr e\n\nlet (@@) a b = a b\n\nexception End of quadr\n\nlet () =\n Scanf.scanf \"%d %d\\n\" @@ fun n m ->\n let a = Array.init n (fun i -> Scanf.scanf \" %d\" @@ fun x -> (x, i)) in\n Array.sort (fun (a, i) (a', i') -> let r = compare a a' in if r <> 0 then r else compare i i') a;\n let t = Array.make (n - 1) ((0, 0), n) in\n Array.iteri\n (fun i (c, ci) ->\n if i > 0 then\n let p, pi = a.(i - 1) in\n if p = c then\n t.(i - 1) <- (pi, ci), Random.int n)\n a;\n Array.sort (fun (_, k) (_, k') -> compare k k') t;\n let t = try Array.fold_left (fun t (e, k)-> if k < n then add e t else raise (End t)) None t with End t -> t in\n for i = 1 to m do\n Scanf.scanf \" %d %d\" @@ fun l r -> Printf.printf \"%d\\n\" @@ find t (l - 1, r - 1)\n done\n"}, {"source_code": "\ntype sub = {\n mutable bl : node;\n mutable br : node;\n mutable tr : node\n}\nand node =\n | Empty\n | Node of int ref * sub\n\ntype tree = { mutable root : node; size : int }\n\nlet empty = 0, -1, 0, -1\n\nlet split (lmin, lmax, rmin, rmax) =\n let lmid = lmin + (lmax - lmin) / 2 in\n let rmid = rmin + (rmax - rmin) / 2 in\n if lmin < lmax && rmin < rmax then\n (lmin, lmid, rmin, rmid),\n (lmin, lmid, rmid + 1, rmax),\n (lmid + 1, lmax, rmid + 1, rmax)\n else if lmin < lmax then\n (lmin, lmid, rmin, rmax),\n empty,\n (lmid + 1, lmax, rmin, rmax)\n else if rmin < rmax then\n (lmin, lmax, rmin, rmid),\n (lmin, lmax, rmid + 1, rmax),\n empty\n else\n empty, empty, empty\n\nlet add ({ root; size } as t) l r =\n let dist = r - l in\n let rec add (lmin, lmax, rmin, rmax as rect) t =\n if lmin <= l && l <= lmax && rmin <= r && r <= rmax then\n match t with\n | Empty ->\n let r = { bl = Empty; br = Empty; tr = Empty } in\n add' rect r;\n Node (ref dist, r)\n | Node (min, r) as node ->\n add' rect r;\n if dist < !min then min := dist;\n node\n else t\n and add' rect r =\n let bl, br, tr = split rect in\n r.bl <- add bl r.bl;\n r.br <- add br r.br;\n r.tr <- add tr r.tr\n in\n t.root <- add (0, size - 1, 0, size - 1) root\n\nlet none = max_int\n\nlet min { root; size } l r =\n let rec min (lmin, lmax, rmin, rmax as rect) =\n function\n | Empty -> none\n | Node (m, _)\n when l <= lmin && lmax <= r && l <= rmin && rmax <= r -> !m\n | Node _\n when r < lmin || l > lmax || r < rmin || l > rmax -> none\n | Node (_, rct) ->\n let bl, br, tr = split rect in\n let bl = min bl rct.bl and br = min br rct.br and tr = min tr rct.tr in\n let br = if bl < br then bl else br in\n if br < tr then br else tr\n in\n min (0, size - 1, 0, size - 1) root\n\ntype element = { v : int64; i : int }\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let seq = Array.init n (fun i -> scanf \"%Ld \" @@ fun v -> { v; i }) in\n Array.sort compare seq;\n let t = { root = Empty; size = n } in\n Array.iteri (fun i v -> if i < n - 1 && v.v = seq.(i + 1).v then add t v.i seq.(i + 1).i) seq;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r -> Printf.printf \"%d\\n\" @@ let m = min t (l - 1) (r - 1) in if m = none then -1 else m\n done\n\n"}, {"source_code": "(*[@@@warning \"-30\"]*)\n\ntype node = {\n left : node option;\n mutable right : node option;\n mutable parent : node option;\n l : int;\n r : int;\n olca : olca\n}\nand olca = {\n uf : uf;\n mutable ancestor : node option;\n mutable colored : bool\n}\nand uf = {\n mutable parent : node option;\n mutable rank : int\n}\n\nmodule H = Hashtbl.Make(struct type t = node let equal = (==) let hash n = n.l end)\n\nlet olca () = { uf = { parent = None; rank = 0 }; ancestor = None; colored = false }\n\nlet rec add curr l r =\n match curr with\n | Some curr when curr.r - curr.l < r - l ->\n let olca = olca () in\n begin match curr.right with\n | Some right as left ->\n let node = Some { left; right = None; parent = Some curr; l; r; olca } in\n right.parent <- node;\n curr.right <- node;\n node\n | None ->\n let node = Some { left = None; right = None; parent = Some curr; l; r; olca } in\n curr.right <- node;\n node\n end\n | Some curr ->\n begin match curr.parent with\n | Some _ as p -> add p l r\n | None ->\n let node = Some { left = Some curr; right = None; parent = None; l; r; olca = olca () } in\n curr.parent <- node;\n node\n end\n | None -> Some { left = None; right = None; parent = None; l; r; olca = olca () }\n\nexception Empty_tree\n\nlet of_some = function Some x -> x | None -> raise Empty_tree\n\nlet tarjan_olca queries =\n let init n =\n n.olca.uf.parent <- Some n;\n n.olca.uf.rank <- 0\n in\n let rec find n =\n match n.olca.uf.parent with\n | Some n' when n' == n -> n\n | Some n' ->\n let p = find n' in\n n.olca.uf.parent <- Some p;\n p\n | None -> assert false\n in\n let union u v =\n let u, v = find u, find v in\n if u.olca.uf.rank > v.olca.uf.rank then\n v.olca.uf.parent <- Some u\n else if u.olca.uf.rank < v.olca.uf.rank then\n u.olca.uf.parent <- Some v\n else if u != v then begin\n v.olca.uf.parent <- Some u;\n u.olca.uf.rank <- u.olca.uf.rank + 1\n end\n in\n let rec tarjan u =\n init u;\n u.olca.ancestor <- Some u;\n let recur v =\n tarjan v;\n union u v;\n (find u).olca.ancestor <- Some u\n in\n let handle =\n match u.parent with\n | None -> (function Some v -> recur v | None -> ())\n | Some v' -> function Some v -> if v != v' then recur v | None -> ()\n in\n handle u.left;\n handle u.right;\n u.olca.colored <- true;\n try\n H.iter\n (fun v a ->\n if v.olca.colored then\n let r = of_some (find v).olca.ancestor in\n a := r;\n H.find (H.find queries v) u := r)\n (H.find queries u)\n with\n | Not_found -> ()\n in\n tarjan\n\ntype cmp = Lt | Gt | Eq\n\nlet search compare return arr =\n let rec search l r =\n if r = l + 1 then Some (return (arr.(l), arr.(r)))\n else\n let m = l + (r - l) / 2 in\n match compare arr.(m) with\n | Eq -> Some arr.(m)\n | Lt -> search m r\n | Gt -> search l m\n in\n let l = 0 and r = Array.length arr - 1 in\n if compare arr.(l) = Gt || compare arr.(r) = Lt then None\n else if compare arr.(l) = Eq then Some arr.(l)\n else if compare arr.(r) = Eq then Some arr.(r)\n else search l r\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = Array.init n (fun i -> scanf \"%d \" @@ fun x -> x, i) in\n Array.sort compare ns;\n let lrs = ref [] in\n Array.iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = Array.of_list !lrs in\n Array.sort compare lrs;\n let lrs' = ref [] in\n try\n let root =\n let r =\n of_some @@ Array.fold_left (fun root (l, r) -> let r = add root l r in lrs' := of_some r :: !lrs'; r) None lrs\n in\n let rec root r = match r.parent with None -> r | Some p -> root p in\n root r\n in\n let lrs' = Array.of_list @@ List.rev !lrs' in\n let queries, queries_list = H.create 32, ref [] in\n let add_query u v =\n H.replace\n (try H.find queries u with Not_found -> let h = H.create 16 in H.replace queries u h; h)\n v\n (ref root)\n in\n let add_query l r u v = add_query u v; add_query v u; queries_list := Some (l, r, u, v) :: !queries_list in\n let cmp a b = if a < b then Lt else if b < a then Gt else Eq in\n let search_left l' = search (fun { l; _ } -> cmp l l') snd lrs' in\n let search_right r' = search (fun { r; _ } -> cmp r r') fst lrs' in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n match search_left (l - 1), search_right (r - 1) with\n | Some u, Some v -> add_query (l - 1) (r - 1) u v\n | _ -> queries_list := None :: !queries_list\n done;\n tarjan_olca queries root;\n List.iter Printf.(\n function\n | None -> printf \"-1\\n\"\n | Some (l', r', u, v) ->\n let { l; r; _ } = !H.(find (find queries u) v) in\n if l' <= l && r <= r' then printf \"%d\\n\" (r - l)\n else printf \"-1\\n\")\n (List.rev !queries_list)\n with\n | Empty_tree -> for _ = 1 to m do Printf.printf \"-1\\n\" done\n"}, {"source_code": "(*[@@@warning \"-30\"]*)\n\ntype node = {\n l : int;\n r : int;\n x : int;\n left : node option;\n right : node option\n}\n\nlet build f l =\n let rec next acc =\n function\n | [] -> List.rev acc\n | [x] -> List.rev (x :: acc)\n | x :: y :: xs ->\n next ({ l = x.l; r = y.r; x = f x.x y.x; left = Some x; right = Some y } :: acc) xs\n in\n let next = next [] in\n let rec build =\n function\n | [] -> { l = 0; r = -1; x = -1; left = None; right = None }\n | [root] -> root\n | layer -> build (next layer)\n in\n build @@ List.mapi (fun i x -> { l = i; r = i; x; left = None; right = None}) l\n\nlet find f root l r =\n let rec find root =\n if l <= root.l && root.r <= r then [root.x]\n else if root.r < l || root.l > r then []\n else\n let map = function None -> [] | Some t -> find t in\n let l = map root.left @ map root.right in\n match l with\n | [] -> []\n | _ :: _ -> List.[fold_left f (hd l) (tl l)]\n in\n find root\n\nlet build_min = build min and find_min = find min\n\ntype cmp = Lt | Gt | Eq\n\nlet search compare return arr =\n let rec search l r =\n if r = l + 1 then Some (return (l, r))\n else\n let m = l + (r - l) / 2 in\n match compare arr.(m) with\n | Eq -> Some m\n | Lt -> search m r\n | Gt -> search l m\n in\n let l = 0 and r = Array.length arr - 1 in\n if r < l || compare arr.(l) = Gt || compare arr.(r) = Lt then None\n else if compare arr.(l) = Eq then Some l\n else if compare arr.(r) = Eq then Some r\n else search l r\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let ns = Array.(init n (fun i -> scanf \"%d \" @@ fun x -> x, i)) in\n Array.sort compare ns;\n let lrs = ref [] in\n Array.iteri (fun i (x, j) -> if i < n - 1 && x = fst ns.(i + 1) then lrs := (j, snd ns.(i + 1)) :: !lrs) ns;\n let lrs = Array.of_list !lrs in\n Array.sort compare lrs;\n let s = Stack.create () in\n Array.iter\n (fun (_, r as lr) ->\n while not (Stack.is_empty s) && snd (Stack.top s) > r do ignore (Stack.pop s) done;\n Stack.push lr s)\n lrs;\n let lrs =\n Array.(init (Stack.length s) (fun _ -> Stack.pop s) |>\n to_list |>\n List.rev |>\n of_list)\n in\n let cmp a b = if a < b then Lt else if a > b then Gt else Eq in\n let search_left l' = search (fun (l, _) -> cmp l l') snd lrs in\n let search_right r' = search (fun (_, r) -> cmp r r') fst lrs in\n let root = build_min Array.(to_list @@ map (fun (l, r) -> r - l) lrs) in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun l r ->\n match search_left (l - 1), search_right (r - 1) with\n | Some l, Some r ->\n Printf.printf \"%d\\n\" @@\n begin match find_min root l r with\n | [] -> -1\n | [x] -> x\n | l -> List.(fold_left min (hd l) (tl l))\n end\n | _ -> Printf.printf \"-1\\n\"\n done\n"}], "src_uid": "358da9c353708ba834d0348ba88c2d0c"} {"source_code": "open Printf\nopen Char\nopen Scanf\nmodule LL = Int64\nlet ( !! ) x = LL.to_int x\nlet ( ++ ) x y = LL.add x y\nlet ( -- ) x y = LL.sub x y\nlet ( ** ) x y = LL.mul x y\nlet ( // ) x y = LL.div x y\nlet ( %% ) x y = LL.rem x y\nlet ( >> ) x y = (LL.compare x y) > 0\nlet ( << ) x y = (LL.compare x y) < 0\nlet ( == ) x y = (LL.compare x y) = 0\nlet rd_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet rd_ll _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x)\nlet rd_arr n = Array.init n rd_ll\nlet rd_str _ = bscanf Scanning.stdin \" %s \" (fun x -> x)\nlet rd_mat n m = Array.init n rd_str\n\nlet diag i j n = (i - j + n) mod n\nlet c2i ch = int_of_char ch - int_of_char '0'\nlet solve n mat = \n let s = ref 0 in\n let cnt = Array.init n (fun _ -> 0) in\n for i=0 to n-1 do\n for j=0 to n-1 do\n let d = diag i j n in \n let c = cnt.(d) in \n let x = c2i mat.(i).[j] in\n cnt.(d) <- (c + x);\n s := !s + x;\n done;\n done;\n let best = (Array.fold_right max cnt 0) in\n let offD = !s - best in\n n - best + offD\n\nlet () =\n let t = rd_int () in\n for i=1 to t do\n let n = rd_int () in\n let mat = rd_mat n n in\n printf \"%d\\n\" (solve n mat)\n done;", "positive_code": [{"source_code": "open Printf\r\nopen Char\r\nopen Scanf\r\nmodule LL = Int64\r\nlet ( !! ) x = LL.to_int x\r\nlet ( ++ ) x y = LL.add x y\r\nlet ( -- ) x y = LL.sub x y\r\nlet ( ** ) x y = LL.mul x y\r\nlet ( // ) x y = LL.div x y\r\nlet ( %% ) x y = LL.rem x y\r\nlet ( >> ) x y = (LL.compare x y) > 0\r\nlet ( << ) x y = (LL.compare x y) < 0\r\nlet ( == ) x y = (LL.compare x y) = 0\r\nlet rd_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\r\nlet rd_ll _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x)\r\nlet rd_arr n = Array.init n rd_ll\r\nlet rd_str _ = bscanf Scanning.stdin \" %s \" (fun x -> x)\r\nlet rd_mat n m = Array.init n rd_str\r\n\r\nlet diag i j n = (i - j + n) mod n\r\nlet c2i ch = int_of_char ch - int_of_char '0'\r\nlet solve n mat = \r\n let cnt = Array.init n (fun _ -> 0) in\r\n let rec loop ij sum =\r\n match ij with\r\n | (-1, _) -> sum\r\n | (i, j) -> \r\n let d = diag i j n in\r\n let c = cnt.(d) in\r\n let x = c2i mat.(i).[j] in\r\n let di = if j-1 < 0 then 1 else 0 in\r\n cnt.(d) <- (c + x);\r\n loop (i-di, (j-1+n) mod n) (sum + x)\r\n in\r\n let s = loop (n-1, n-1) 0 in\r\n let onD = (Array.fold_right max cnt 0) in\r\n let offD = s - onD in\r\n n - onD + offD\r\n\r\nlet () =\r\n let t = rd_int () in\r\n for i=1 to t do\r\n let n = rd_int () in\r\n let mat = rd_mat n n in\r\n printf \"%d\\n\" (solve n mat)\r\n done;"}], "negative_code": [], "src_uid": "d174982b64cc9e8d8a0f4b8646f1157c"} {"source_code": "(* OCaml template *)\nopen Printf\nopen Scanf\n\n(* Redefine operators for Int32 *)\n(*\nlet ( + ) = Int32.add;;\nlet ( - ) = Int32.sub;;\nlet ( * ) = Int32.mul;;\nlet ( / ) = Int32.div;;\nlet ( % ) = Int32.rem;;\n*)\n\n(* Redefine operators for Int64 *)\nlet ( + ) = Int64.add;;\nlet ( - ) = Int64.sub;;\nlet ( * ) = Int64.mul;;\nlet ( / ) = Int64.div;;\nlet ( % ) = Int64.rem;;\n\n(* Input *)\nlet read_int32 _ = bscanf Scanning.stdin \"%ld \" @@ fun x -> x;;\nlet read_int64 _ = bscanf Scanning.stdin \"%Ld \" @@ fun x -> x;;\n\n(* Output *)\nlet print_int32 n = printf \"%ld \" n;;\nlet print_int32_endl n = printf \"%ld\\n\" n;;\nlet print_int64 n = printf \"%Ld \" n;;\nlet print_int64_endl n = printf \"%Ld\\n\" n;;\n\n(* Utility functions *)\nlet comp f g x = f @@ g x;;\nlet rec fac n = if n = 0L then 1L else n * fac (n - 1L);;\nlet rec fib n = if n < 2L then n else fib (n - 2L) + fib (n - 1L);;\nlet sum = List.fold_left (+) 0L;;\n\n(* Solve test case *)\nlet solve l r = \n\tif r < 2L * l then\n\t\tr - l\n\telse \n\t\t(r - 1L) / 2L;;\n\n(* Main *)\nlet t = read_int ();;\n\nfor t' = 1 to t do\n\tlet l = read_int64 () in\n\t\tlet r = read_int64 () in\n\t\t\tprint_int64_endl @@ solve l r\ndone\n", "positive_code": [{"source_code": "open Printf\r\nopen Scanf\r\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\r\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\r\n \r\nlet () = \r\n let cases = read_int () in\r\n for case = 1 to cases do\r\n let (a, b) = read_pair () in\r\n let c = b/2+1 in\r\n let result = \r\n if c >= a then b mod c\r\n else b mod a\r\n in\r\n printf \"%d\\n\" result\r\n done"}], "negative_code": [], "src_uid": "c34db7897f051b0de2f49f2696c6ee2f"} {"source_code": "let (+) = Int64.add\nlet ( * ) = Int64.mul\nlet ( - ) = Int64.sub\nlet two = Int64.one + Int64.one\nlet one = Int64.one\nlet zero = Int64.zero\n\nlet solve =\n let n = Scanf.scanf \"%Ld\\n\" (fun n -> n) in\n let readPoints() = Scanf.scanf \"%Ld %Ld\\n\" (fun x y -> (x,y)) in\n let rec readInput i (accX,accY) =\n match i with\n | i when i = n -> (List.rev accX,List.rev accY)\n | i -> let (x,y) = readPoints() in\n readInput (i+one) ((x::accX),(y::accY))\n in\n let rec sumpoints lst sum sqsum i acc =\n match lst with \n | [] -> acc\n | x::xs -> let newval = ((i-one)*(x*x)-two*x*sum+sqsum) in\n sumpoints xs (sum+x) (sqsum+(x*x)) (i+one) (acc+newval)\n in\n let xs,ys = readInput zero ([],[]) in\n Printf.printf \"%Ld\\n\" ((sumpoints xs zero zero one zero)+(sumpoints ys zero zero one zero))\n;;", "positive_code": [{"source_code": "let (+) = Int64.add\nlet ( * ) = Int64.mul\nlet ( - ) = Int64.sub\nlet two = Int64.one + Int64.one\nlet one = Int64.one\nlet zero = Int64.zero\n\nlet solve =\n let n = Scanf.scanf \"%Ld\\n\" (fun n -> n) in\n let readPoints() = Scanf.scanf \"%Ld %Ld\\n\" (fun x y -> (x,y)) in\n let rec readInput i (accX,accY) =\n match i with\n | i when i = n -> (List.rev accX,List.rev accY)\n | i -> let (x,y) = readPoints() in\n readInput (i+one) ((x::accX),(y::accY))\n in\n let rec sumpoints lst sum sqsum i acc =\n match lst with \n | [] -> acc\n | x::xs -> let newval = ((i-one)*(x*x)-(two*x*sum)+sqsum) in\n sumpoints xs (sum+x) (sqsum+(x*x)) (i+one) (acc+newval)\n in\n let xs,ys = readInput zero ([],[]) in\n Printf.printf \"%Ld\\n\" ((sumpoints xs zero zero one zero)+(sumpoints ys zero zero one zero))\n;;\n \n"}], "negative_code": [{"source_code": "let solve =\n let n = Scanf.scanf \"%d\\n\" (fun n -> n) in\n let readPoints() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rec readInput i (accX,accY) =\n match i with\n | i when i = n -> (List.rev accX,List.rev accY)\n | i -> let (x,y) = readPoints() in\n readInput (i+1) ((x::accX),(y::accY))\n in\n let rec sumpoints lst sum sqsum i acc =\n match lst with \n | [] -> acc\n | x::xs -> let newval = ((i-1)*(x*x)-2*x*sum+sqsum) in\n sumpoints xs (sum+x) (sqsum+(x*x)) (i+1) (acc+newval)\n in\n let xs,ys = readInput 0 ([],[]) in\n Printf.printf \"%d\\n\" ((sumpoints xs 0 0 1 0)+(sumpoints ys 0 0 1 0))\n;;"}, {"source_code": "let solve =\n let n = Scanf.scanf \"%d\\n\" (fun n -> n) in\n let readPoints() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rec readInput i (accX,accY) =\n match i with\n | i when i = n -> (List.rev accX,List.rev accY)\n | i -> let (x,y) = readPoints() in\n readInput (i+1) ((x::accX),(y::accY))\n in\n let rec sumpoints lst sum sqsum i acc =\n match lst with \n | [] -> acc\n | x::xs -> let newval = ((i-1)*(x*x)-2*x*sum+sqsum) in\n sumpoints xs (sum+x) (sqsum+(x*x)) (i+1) (acc+newval)\n in\n let xs,ys = readInput 0 ([],[]) in\n let result = (sumpoints xs 0 0 1 0)+(sumpoints ys 0 0 1 0) in\n Printf.printf \"%d\\n\" result\n;;\n"}], "src_uid": "9bd6fea892857d7c94ebce4d4cd46d30"} {"source_code": "let solve a b =\n let rec loop lst1 lst2 cnt =\n match lst1 with\n | [] -> if cnt <= 2 then true else false\n | h :: t ->\n\tif h = List.hd lst2 then loop t (List.tl lst2) cnt\n\telse loop t (List.tl lst2) (cnt+1)\n in\n if List.sort compare a = List.sort compare b && loop a b 0 then \"YES\"\n else \"NO\"\n\nlet _ =\n let a = (Scanf.scanf \" %s\" (Str.split (Str.regexp \"\"))) in\n let b = (Scanf.scanf \" %s\" (Str.split (Str.regexp \"\"))) in\n Printf.printf \"%s\\n\" (solve a b)\n", "positive_code": [{"source_code": "let a = read_line () in\nlet b = read_line () in\nlet x, y = ref [], ref [] in\nlet na = String.length a in\nlet nb = String.length b in\nfor i = 0 to min na nb - 1 do\n if a.[i] <> b.[i] then begin\n x := a.[i] :: !x;\n y := b.[i] :: !y\n end\ndone;\nlet m = List.length !x in\nlet sort = List.sort (fun a b -> Char.code a - Char.code b) in\nprint_endline (if na = nb && m = 2 && sort !x = sort !y\n then \"YES\" else \"NO\")\n"}, {"source_code": "open String;;\nlet diff s a b =\n let l = ref [] in\n for i = 0 to length a - 1 do\n if a.[i] <> b.[i] then\n l := (i) :: (!l)\n done; \n !l;;\n \nlet swap a h k =\n let n = a.[h] in\n a.[h] <- a.[k];\n a.[k] <- n;;\n \nlet ch l a b= match l with\n [] -> false\n |h:: t -> match t with\n [] -> false\n |k :: [] -> swap a h k;a = b\n |t :: k -> false\n;;\nlet main _ =\n let a = Scanf.scanf \"%s\\n\" (fun a -> a) in\n let b = Scanf.scanf \"%s\\n\" (fun a -> a) in\n if length a <> length b\n then print_endline \"NO\"\n else \n let l = diff [] a b in\n if (ch l a b)\n then print_endline \"YES\"\n else print_endline \"NO\"\n;;\nmain ();;"}], "negative_code": [{"source_code": "let solve a b =\n let sorted_a = List.sort compare a in\n let sorted_b = List.sort compare b in\n if sorted_a = sorted_b then \"YES\" else \"NO\"\n\nlet _ =\n let a = (Scanf.scanf \" %s\" (Str.split (Str.regexp \"\"))) in\n let b = (Scanf.scanf \" %s\" (Str.split (Str.regexp \"\"))) in\n Printf.printf \"%s\\n\" (solve a b)\n \n\n \n\n\n"}], "src_uid": "c659bdeda1c1da08cfc7f71367222332"} {"source_code": "let foldli f acc s =\n let n = String.length s in\n let rec go i acc =\n if i >= n then\n acc\n else\n go (i+1) (f i acc s.[i])\n in go 0 acc\n\nlet () =\n let a = read_line () in\n let opt,cnt,_,_ = foldli (fun i (opt,cnt,b,s) c ->\n if c = '(' then\n (opt,cnt,b,i::s)\n else if s = [] then\n (opt,cnt,i,[])\n else\n let s' = List.tl s in\n let opt' = i - (if s' = [] then b else List.hd s') in\n if opt' > opt then\n (opt',1,b,s')\n else if opt' = opt then\n (opt,cnt+1,b,s')\n else\n (opt,cnt,b,s')\n ) (0,1,-1,[]) a in\n Printf.printf \"%d %d\\n\" opt cnt\n", "positive_code": [{"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet solve s =\n let stk = Stack.create () in\n\n let b = ref (-1) in\n let max = ref 0 in\n let max_ct = ref 1 in\n\n for i = 0 to String.length s - 1 do\n try\n match s.[i] with\n | '(' -> Stack.push i stk\n | ')' ->\n let top = Stack.pop stk in\n let len = i - (if Stack.is_empty stk then !b else Stack.top stk) in\n match compare !max len with\n | 1 -> ()\n | 0 -> incr max_ct\n | _ -> max := len; max_ct := 1\n\n with Stack.Empty -> b := i\n done;\n\n (!max, !max_ct)\n\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\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\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet rec rev acc = function\n | '(' :: xs -> rev (')' :: acc) xs\n | ')' :: xs -> rev ('(' :: acc) xs\n | x :: xs -> rev (x :: acc) xs\n | [] -> acc\n\nlet merge (l1, t1) (l2, t2) = \n match (compare l1 l2) with\n | 1 -> (l1, t1)\n | 0 when l1 = 0 -> (0, 1)\n | 0 -> (l1, t1 + t2)\n | _ -> (l2, t2)\n\nlet rec count b ct res = function\n | [] -> if b = 0 then merge res (ct, 1) else res\n | '(' :: xs ->\n count (b + 1) (ct + 1) res xs\n | _ :: xs ->\n if b > 0 then\n count (b - 1) (ct + 1) res xs\n else\n count 0 0 (merge res (ct, 1)) xs\n\nlet solve s =\n let s1 = ')' :: explode s in\n let s2 = rev [] s1 in\n merge (count 0 0 (0, 1) s1) (count 0 0 (0, 1) s2)\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}], "negative_code": [{"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\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\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet rec rev acc = function\n | '(' :: xs -> rev (')' :: acc) xs\n | ')' :: xs -> rev ('(' :: acc) xs\n | x :: xs -> rev (x :: acc) xs\n | [] -> acc\n\nlet merge (l1, t1) (l2, t2) = \n match (compare l1 l2) with\n | 1 -> (l1, t1)\n | 0 when l1 = 0 -> (0, 1)\n | 0 -> (l1, t1 + t2)\n | _ -> (l2, t2)\n\nlet rec count b ct = function\n | [] -> if b = 0 then (ct, 1) else (0, 1)\n | '(' :: xs -> count (b + 1) (ct + 1) xs\n | _ :: xs ->\n if b > 0 then\n count (b - 1) (ct + 1) xs\n else\n merge (count 0 0 xs) (ct, 1)\n\nlet solve s =\n let s1 = ')' :: explode s in\n let s2 = rev [] s1 in\n merge (count 0 0 s1) (count 0 0 s2)\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet srev s1 =\n let s2 = String.copy s1 in\n let len = String.length s1 - 1 in\n for i = 0 to len do\n s2.[i] <- match s1.[len - i] with\n | '(' -> ')'\n | ')' -> '('\n done;\n s2\n\nlet merge (l1, t1) (l2, t2) = \n match (compare l1 l2) with\n | 1 -> (l1, t1)\n | 0 when l1 = 0 -> (0, 1)\n | 0 -> (l1, t1 + t2)\n | -1 -> (l2, t2)\n\nlet count s =\n let rec iter b ct i =\n try\n match s.[i] with\n | '(' -> iter (b + 1) (ct + 1) (i + 1)\n | ')' ->\n if b > 0 then\n iter (b - 1) (ct + 1) (i + 1)\n else\n merge (iter 0 0 (i + 1)) (ct, 1)\n\n with Invalid_argument _ ->\n if b = 0 then (ct, 1) else (0, 1)\n \n in iter 0 0 0\n\nlet solve s =\n let s1 = \")\" ^ s in\n let s2 = srev s1 in\n merge (count s1) (count s2)\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet solve s =\n let stk = Stack.create () in\n\n let b = ref 0 in\n let max = ref 0 in\n let max_ct = ref 1 in\n\n for i = 0 to String.length s - 1 do\n try\n match s.[i] with\n | '(' -> Stack.push i stk\n | ')' ->\n let top = Stack.pop stk in\n let len = if Stack.is_empty stk then i - !b else i - top in\n match compare !max len with\n | 1 -> ()\n | 0 -> incr max_ct\n | _ -> max := len; max_ct := 1\n\n with Stack.Empty -> b := i\n done;\n\n (!max, !max_ct)\n\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" (len+1) count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\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\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet rec rev acc = function\n | '(' :: xs -> rev (')' :: acc) xs\n | ')' :: xs -> rev ('(' :: acc) xs\n | [] -> acc\n\nlet merge (l1, t1) (l2, t2) = \n match (compare l1 l2) with\n | 1 -> (l1, t1)\n | 0 when l1 = 0 -> (0, 1)\n | 0 -> (l1, t1 + t2)\n | -1 -> (l2, t2)\n\nlet rec count b ct = function\n | [] -> if b = 0 then (ct, 1) else (0, 1)\n | '(' :: xs -> count (b + 1) (ct + 1) xs\n | ')' :: xs ->\n if b > 0 then\n count (b - 1) (ct + 1) xs\n else\n merge (count 0 0 xs) (ct, 1)\n\nlet solve s =\n let s1 = ')' :: explode s in\n let s2 = rev [] s1 in\n merge (count 0 0 s1) (count 0 0 s2)\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\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\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet rec rev acc = function\n | '(' :: xs -> rev (')' :: acc) xs\n | ')' :: xs -> rev ('(' :: acc) xs\n | [] -> acc\n\nlet merge (l1, t1) (l2, t2) = \n match (compare l1 l2) with\n | 1 -> (l1, t1)\n | 0 when l1 = 0 -> (0, 1)\n | 0 -> (l1, t1 + t2)\n | -1 -> (l2, t2)\n\nlet rec count b ct = function\n | [] -> if b = 0 then (ct, 1) else (0, 1)\n | '(' :: xs -> count (b + 1) (ct + 1) xs\n | ')' :: xs ->\n if b > 0 then\n count (b - 1) (ct + 1) xs\n else\n merge (count 0 0 xs) (ct, 1)\n\nlet solve s =\n let s1 = explode s in\n let s2 = rev [] s1 in\n merge (count 0 0 s1) (count 0 0 s2)\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}, {"source_code": "\n(* Utils \n --------------------------------------------------------------------------- *)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet solve s =\n let stk = Stack.create () in\n\n let max = ref 0 in\n let max_ct = ref 1 in\n\n for i = 0 to String.length s - 1 do\n try\n match s.[i] with\n | '(' -> Stack.push i stk\n | ')' ->\n let len = i - Stack.pop stk + 1 in\n match compare !max len with\n | 1 -> ()\n | 0 -> incr max_ct\n | _ -> max := len; max_ct := 1\n\n with Stack.Empty -> ()\n done;\n\n (!max, !max_ct)\n\n\nlet _ =\n let (len, count) = solve (read_string ()) in\n Printf.printf \"%d %d\" len count\n"}], "src_uid": "91c3af92731cd7d406674598c0dcbbbc"} {"source_code": "open Char;;\nlet n = read_int () and kol = ref 0 and answer = ref 0;;\nlet a = Array.create n \"\";;\nlet check c x = \nbegin\n\tkol := 0;\n\tfor i = 0 to (String.length x) - 1 do\n\t\tif String.get x i = c then kol := !kol + 1\t\n\tdone; \n\t!kol;\nend;;\nfor i = 0 to n - 1 do let ss = read_line() in Array.set a i ss done;;\nfor i = 1 to 26 do\n\tfor j = 1 to 26 do\n\t\tif i <> j then\n\t\tbegin\n\t\t\tlet ans = ref 0 in\n\t\t\tbegin\n\t\t\t\tfor k = 0 to n - 1 do\n\t\t\t\t\tif (check (chr (i + 96)) a.(k)) + (check (chr (j + 96)) a.(k)) = String.length a.(k) then ans := !ans + String.length a.(k);\n\t\t\t\tdone;\n\t\t\t\tanswer := max !answer !ans;\n\t\t\tend\n\t\tend\n\tdone\ndone;;\nprint_int !answer;;\n\n", "positive_code": [{"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)\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet n2l n = char_of_int ((int_of_char 'a') + n)\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac + (f i))\n \nlet () = \n let n = read_int () in\n let word = Array.init n (fun _ -> read_string()) in\n\n let word_contains_only w c d =\n let n = String.length w in\n forall 0 (n-1) (fun i -> w.[i] = c || w.[i] = d)\n in\n\n \n let answer = maxf 0 25 (fun i ->\n maxf 0 25 (fun j ->\n let c = n2l i in\n let d = n2l j in\n sum 0 (n-1) (fun k ->\n\tif word_contains_only word.(k) c d then String.length word.(k) else 0\n ) 0\n )\n ) in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "d8a93129cb5e7f05a5d6bbeedbd9ef1a"} {"source_code": "module Pset = Set.Make (struct type t = int*int let compare = compare end)\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nlet () = \n let n = read_int() in\n\n let color = [|ref Pset.empty; ref Pset.empty|] in\n\n let () = for i=1 to n do\n let c = read_int() in\n let s = read_int() in\n color.(c) := Pset.add (s,i) (!(color.(c)));\n done in\n\n let step (set0, size0, set1, size1) = \n let i = if size0 = 1 then 0 else if size1 = 1 then 1 else\n ( let (m0,_) = Pset.min_elt set0 in\n\tlet (m1,_) = Pset.min_elt set1 in\n\t if m0 > m1 then 0 else 1\n )\n in\n (* i is the one which stays, 1-i is removed *)\n let (set0, size0, set1, size1) = if i=0 then (set0, size0, set1, size1) else (set1, size1, set0, size0) in\n let (s0,i0) = Pset.min_elt set0 in\n let set0 = Pset.remove (s0,i0) set0 in\n let (s1,i1) = Pset.min_elt set1 in\n let set1 = Pset.remove (s1,i1) set1 in\n \n Printf.printf \"%d %d %d\\n\" i0 i1 s1;\n \n let set0 = Pset.add (s0-s1, i0) set0 in\n\t(set0, size0, set1, size1-1)\n in\n\n let rec loop sets i = if i=n-1 then () else loop (step sets) (i+1) in\n\n loop (!(color.(0)), Pset.cardinal !(color.(0)), !(color.(1)), Pset.cardinal !(color.(1))) 0\n", "positive_code": [{"source_code": "(* Codeforces 260D BlackWhiteTree ??? *)\n\nopen String;;\nopen Array;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet 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 rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet rec readprs idx n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> let c = gr() in\n\t\t\tlet v = gr() in\n\t\t\treadprs (idx +1) (n -1) ((c, v, idx) :: acc);;\n\nlet rec split1 li la lb = match li with\n\t| [] -> (la, lb)\n\t| h :: t ->\n\t\t\tlet (c, _, _) = h in\n\t\t\tmatch c with\n\t\t\t| 0 -> split1 t (h :: la) lb\n\t\t\t| 1 -> split1 t la (h :: lb);;\n\nlet sortfun a b =\n\tlet (ca, va, ia) = a in\n\tlet (cb, vb, ib) = b in\n\t(va - vb);;\n\nlet rec combine_witha lasta lb acc = match lb with\n| [] -> acc\n| hb :: tb ->\n\t\t\t\t\tlet (_, va, ia) = lasta in\n\t\t\t\t\tlet (_, vb, ib) = hb in\n\t\t\t\t\tcombine_witha lasta tb ((ia, ib, vb) :: acc);;\n\nlet rec combine_withb la lastb acc = match la with\n| [] -> acc\n| ha :: ta ->\n\t\t\t\t\tlet (_, va, ia) = ha in\n\t\t\t\t\tlet (_, vb, ib) = lastb in\n\t\t\t\t\tcombine_withb ta lastb ((ia, ib, va) :: acc);;\n\n\nlet rec combine la lb acc = match la with\n\t| [] -> acc\n\t| ha :: [] -> combine_witha ha lb acc\n\t| ha :: ta -> match lb with\n\t\t\t| [] -> acc\n\t\t\t| hb :: [] -> combine_withb la hb acc\n\t\t\t| hb :: tb ->\n\t\t\t\t\tlet (_, va, ia) = ha in\n\t\t\t\t\tlet (_, vb, ib) = hb in\n\t\t\t\t\tif va <= vb then\n\t\t\t\t\t\tcombine ta ((1, (vb - va), ib) :: tb) ((ia, ib, va) :: acc)\n\t\t\t\t\telse\n\t\t\t\t\t\tcombine ((0, (va - vb), ia) :: ta) tb ((ia, ib, vb) :: acc);;\n\nlet rec pricomb co =\n\tlet (ia, ib, w) = co in\n\tbegin\n\t\tprint_int ia; print_string \" \";\n\t\tprint_int ib; print_string \" \";\n\t\tprint_int w;\n\t\tprint_newline()\n\tend;;\n\nlet n = gr();;\n\nlet main () =\n\tlet prs = readprs 1 n [] in\n\tlet (ula, ulb) = split1 prs [] [] in\n\tlet la = List.sort sortfun ula in\n\tlet lb = List.sort sortfun ulb in\n\tlet comb = combine la lb [] in\n\tList.iter pricomb comb;;\n\nmain();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\n\nlet nodes =\n let rec loop i f =\n if i > n then f []\n else let ci = read_int () and si = read_int ()\n in loop (i + 1) (fun l -> f ((i, ci, si) :: l))\n in loop 1 (fun x -> x) ;;\n\nlet white = List.filter (fun (i, c, s) -> c = 0) nodes ;;\nlet black = List.filter (fun (i, c, s) -> c = 1) nodes ;;\n\nlet tree = \n let rec build_tree u cu su w b tree =\n if w = [] && b = [] then tree\n else let (node, color, sum, white, black, edge) = \n let (v, cv, sv), nw, nb, opposite_nodes = \n if cu = 0 then let t = List.tl b in (List.hd b), w, t, t \n else let t = List.tl w in (List.hd w), t, b, t\n in if su > sv || su = sv && opposite_nodes <> [] \n then (u, cu, su - sv, nw, nb, (u, v, sv))\n else (v, cv, sv - su, nw, nb, (u, v, su))\n in build_tree node color sum white black (edge :: tree)\n in let (u, c, s) = List.hd white\n in build_tree u c s (List.tl white) black [] ;;\n \nlet rec print_tree = function\n | [] -> ()\n | (u, v, w) :: t -> Printf.printf \"%d %d %d\\n\" u v w ; print_tree t\nin print_tree tree ;;\n "}], "negative_code": [{"source_code": "(* Codeforces 260D BlackWhiteTree works *)\n\nopen String;;\nopen Array;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet 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 rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet rec readprs idx n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> let c = gr() in\n\t\t\tlet v = gr() in\n\t\t\treadprs (idx +1) (n -1) ((c, v, idx) :: acc);;\n\nlet rec split1 li la lb = match li with\n\t| [] -> (la, lb)\n\t| h :: t ->\n\t\t\tlet (c, _, _) = h in\n\t\t\tmatch c with\n\t\t\t| 0 -> split1 t (h :: la) lb\n\t\t\t| 1 -> split1 t la (h :: lb);;\n\nlet sortfun a b =\n\tlet (ca, va, ia) = a in\n\tlet (cb, vb, ib) = b in\n\t(va - vb);;\n\nlet rec combine la lb acc = match la with\n\t| [] -> acc\n\t| ha :: ta -> match lb with\n\t\t\t| [] -> acc\n\t\t\t| hb :: tb ->\n\t\t\t\t\tlet (_, va, ia) = ha in\n\t\t\t\t\tlet (_, vb, ib) = hb in\n\t\t\t\t\tif va <= vb then\n\t\t\t\t\t\tcombine ta ((1, (vb - va), ib) :: tb) ((ia, ib, va) :: acc)\n\t\t\t\t\telse\n\t\t\t\t\t\tcombine ((0, (va - vb), ia) :: ta) tb ((ia, ib, vb) :: acc);;\n\nlet rec pricomb co =\n\tlet (ia, ib, w) = co in\n\tbegin\n\t\tprint_int ia; print_string \" \";\n\t\tprint_int ib; print_string \" \";\n\t\tprint_int w;\n\t\tprint_newline()\n\tend;;\n\nlet n = gr();;\n\nlet main () =\n\tlet prs = readprs 1 n [] in\n\tlet (ula, ulb) = split1 prs [] [] in\n\tlet la = List.sort sortfun ula in\n\tlet lb = List.sort sortfun ulb in\n\tlet comb = combine la lb [] in\n\tList.iter pricomb comb;;\n\nmain();;\n"}], "src_uid": "b1ece35f190b13a3dfd64ab30c905765"} {"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let a = input_line stdin in \r\n let tab = Array.make 26 (-1) in\r\n let rep = ref true in\r\n for i = 0 to String.length a - 1 do\r\n let lett = a.[i] in\r\n let num = Char.code lett - 97 in\r\n if tab.(num) = -2 then begin rep := false end ;\r\n if !rep && (tab.(num) <> -1) then begin\r\n let last = tab.(num) in\r\n for j = 0 to 25 do\r\n if tab.(j) <> -1 && tab.(j) <> -2 && num<>j && tab.(j) < last then rep := false ;\r\n if tab.(j) = -1 then tab.(j) <- (-2)\r\n done;\r\n end ; tab.(num) <- i ;\r\n \r\n done;\r\n if !rep then print_endline \"YES\" else print_endline \"NO\"\r\ndone;;\r\n ", "positive_code": [{"source_code": "module CharOrd = struct\r\n type t = char\r\n\r\n let compare x y = if x < y then -1 else if x > y then 1 else 0\r\nend\r\n\r\nmodule CharSet = Set.Make (CharOrd)\r\n\r\nlet solve () =\r\n let str = read_line () in\r\n let n = String.length str in\r\n let c = ref CharSet.empty in\r\n let rec find_k i =\r\n if i >= n then n\r\n else if CharSet.exists (fun x -> x == String.get str i) !c then i\r\n else (\r\n c := CharSet.add (String.get str i) !c;\r\n find_k (i + 1))\r\n in\r\n let k = find_k 0 in\r\n let rec is_ok i =\r\n if i >= n then true\r\n else if String.get str i = String.get str (i - k) then is_ok (i + 1)\r\n else false\r\n in\r\n if is_ok k then \"YES\" else \"NO\"\r\n\r\nlet () =\r\n let t = read_int () in\r\n for i = 0 to t - 1 do\r\n print_endline (solve ())\r\n done\r\n"}], "negative_code": [{"source_code": "module CharOrd = struct\r\n type t = char\r\n\r\n let compare x y = if x < y then -1 else if x > y then 1 else 0\r\nend\r\n\r\nmodule CharSet = Set.Make (CharOrd)\r\n\r\nlet solve () =\r\n let str = read_line () in\r\n let n = String.length str in\r\n let c = ref CharSet.empty in\r\n let rec find_k i =\r\n if i >= n then n - 1\r\n else if CharSet.exists (fun x -> x == String.get str i) !c then i\r\n else (\r\n c := CharSet.add (String.get str i) !c;\r\n find_k (i + 1))\r\n in\r\n let k = find_k 0 in\r\n let rec is_ok i =\r\n if i >= n then true\r\n else if String.get str i = String.get str (i - k) then is_ok (i + 1)\r\n else false\r\n in\r\n if is_ok k then \"YES\" else \"NO\"\r\n\r\nlet () =\r\n let t = read_int () in\r\n for i = 0 to t - 1 do\r\n print_endline (solve ())\r\n done\r\n"}, {"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let a = input_line stdin in \r\nlet tab = Array.make 26 (-1) in\r\n let rep = ref true in\r\n for i = 0 to String.length a - 1 do\r\n let lett = a.[i] in\r\n let num = Char.code lett - 97 in\r\n if !rep && (tab.(num) <> -1) then begin\r\n let last = tab.(num) in\r\n for j = 0 to 25 do\r\n if tab.(j) <> -1 && tab.(j) < last then rep := false\r\n done;\r\n \r\n end ; tab.(num) <- i ;\r\n \r\n done;\r\n if !rep then print_endline \"YES\" else print_endline \"NO\"\r\ndone;;\r\n "}], "src_uid": "dd098a17343a02fa5dc0d2d6cea853c7"} {"source_code": "open Printf\nopen Scanf\n\nlet rec gcd a b = if a=0 then b else gcd (b mod a) a\n\nlet ( -- ) (a,b) (c,d) = (a-c,b-d)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let gun = read_pair () in\n let point = Array.init n (fun _ -> (read_pair()) -- gun) in\n\n let h = Hashtbl.create 10 in\n\n let increment t = \n let c = try Hashtbl.find h t with Not_found -> 0 in\n Hashtbl.replace h t (c+1)\n in\n\n for i=0 to n-1 do\n let (x,y) = point.(i) in\n let g = gcd (abs x) (abs y) in\n let (x,y) = (x/g, y/g) in\n let (x,y) = min (x,y) (-x,-y) in\n increment (x,y);\n done;\n\n printf \"%d\\n\" (Hashtbl.length h)\n", "positive_code": [{"source_code": "(* test if points a, b, c are colinear *)\nlet colinear (ax, ay) (bx, by) (cx, cy) =\n (ax - cx) * (by - cy) = (ay - cy) * (bx - cx)\n\nlet () = Scanf.scanf \"%d %d %d\\n\" (fun n x0 y0 ->\n let colinear = colinear (x0, y0) in\n let points = Array.init n (fun _ ->\n Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y)))\n in\n let rays = ref [points.(0)] in\n Array.iter (fun p ->\n (* check each ray to see if it hits this point *)\n let rec aux = function\n | [] -> false\n | q :: ps -> if colinear p q then true else aux ps\n in\n if not (aux !rays) then\n rays := p :: !rays\n ) points;\n Printf.printf \"%d\\n\" (List.length !rays)\n)\n"}], "negative_code": [], "src_uid": "8d2845c33645ac45d4d37f9493b0c380"} {"source_code": "let n = Scanf.scanf \" %d\" (fun x -> x) in\n\nlet rec names n = \n if n == 0 \n then [] \n else Scanf.scanf \" %s\" (fun x -> x::(names (n - 1))) \nin\n\nlet sides names =\n let rec helper names acc =\n match names with\n | [] -> acc\n | hd::tl ->\n match hd with\n | \"Tetrahedron\" -> helper tl (acc + 4)\n | \"Cube\" -> helper tl (acc + 6)\n | \"Octahedron\" -> helper tl (acc + 8)\n | \"Dodecahedron\" -> helper tl (acc + 12)\n | \"Icosahedron\" -> helper tl (acc + 20)\n | _ -> 0\n in helper names 0\nin\n\nPrintf.printf \"%d\\n\" (sides (names n))\n", "positive_code": [{"source_code": "let make_list () = \n let n = Pervasives.read_int () in\n let rec loop i list =\n if i < n\n then\n let shape = Pervasives.read_line () in\n loop (i + 1) (shape :: list)\n else\n list\n in loop 0 []\n\nlet counter count shape =\n match shape with\n | \"Tetrahedron\" -> count + 4\n | \"Cube\" -> count + 6\n | \"Octahedron\" -> count + 8\n | \"Dodecahedron\" -> count + 12\n | \"Icosahedron\" -> count + 20\n\nlet () = \n let shapes = make_list () in\n let count = List.fold_left counter 0 shapes in\n Pervasives.print_int count"}, {"source_code": "let counter shape count =\n match shape with\n | \"Tetrahedron\" -> count + 4\n | \"Cube\" -> count + 6\n | \"Octahedron\" -> count + 8\n | \"Dodecahedron\" -> count + 12\n | \"Icosahedron\" -> count + 20\n\nlet () = \n let n = Pervasives.read_int () in\n let rec loop i count =\n if i < n\n then\n let shape = Pervasives.read_line () in\n loop (i + 1) (counter shape count)\n else\n Pervasives.print_int count\n in loop 0 0"}, {"source_code": "let main () =\n let gr () = Scanf.scanf \"%d\" (fun i -> i) in \n let gs () = Scanf.scanf \"\\n%s\" (fun i -> i) in \n let n = gr () in\n let rec solve cnt ans = \n match cnt with \n | 0 -> ans\n | cnt -> \n let line = gs() in \n let sides = match line with \n | \"Tetrahedron\" -> 4\n | \"Cube\" -> 6\n | \"Octahedron\" -> 8\n | \"Dodecahedron\" -> 12\n | \"Icosahedron\" -> 20\n | somestr -> Printf.printf \"!!!%s\\n\" (somestr); 0\n in \n solve (cnt - 1) (ans + sides)\n in \n Printf.printf \"%d\\n\" (solve n 0);;\nlet _ = main();;\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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n\n let answer = sum 0 (n-1) (fun _ ->\n match read_string() with\n | \"Tetrahedron\" -> 4\n | \"Cube\" -> 6\n | \"Octahedron\" -> 8\n | \"Dodecahedron\" -> 12\n | \"Icosahedron\" -> 20\n | _ -> failwith \"bad input\"\n ) in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "e6689123fefea251555e0e096f58f6d1"} {"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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let a0 = Array.make n 0 in\n let a1 = Array.make n 0 in\n let am0 = Array.make n 0 in\n let am1 = Array.make n 0 in\n let c0 = Array.make m (0, 0) in\n let c1 = Array.make m (0, 0) in\n let cnt0 = ref 0 in\n let cnt1 = ref 0 in\n let t0 = ref 0L in\n let t1 = ref 0L in\n for i = 0 to n - 1 do\n a0.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am0.(i) <-\n\tif i = 0\n\tthen a0.(i)\n\telse min am0.(i - 1) a0.(i);\n done;\n for i = 0 to n - 1 do\n a1.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am1.(i) <-\n\tif i = 0\n\tthen a1.(i)\n\telse min am1.(i - 1) a1.(i);\n done;\n for i = 0 to m - 1 do\n let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif t = 1 then (\n\t c0.(!cnt0) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt0;\n\t) else (\n\t c1.(!cnt1) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt1;\n\t)\n done;\n let cnt0 = !cnt0 in\n let cnt1 = !cnt1 in\n let c0 = Array.sub c0 0 cnt0 in\n let c1 = Array.sub c1 0 cnt1 in\n let res = ref (n + 1) in\n let best0 = ref 0 in\n Array.sort compare c0;\n Array.sort compare c1;\n for i = 0 to min k cnt1 - 1 do\n\tt1 := !t1 +| Int64.of_int (fst c1.(i));\n done;\n for i = 0 to cnt0 do\n\tif k - i <= cnt1 then (\n(*Printf.printf \"asd %d %Ld %Ld\\n\" i !t0 !t1;*)\n\t let l = ref (-1)\n\t and r = ref n in\n\t while !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t let t =\n\t\tInt64.of_int am0.(m) *| !t0 +|\n\t\t Int64.of_int am1.(m) *| !t1\n\t in\n\t\tif t <= s\n\t\tthen r := m\n\t\telse l := m\n\t done;\n(*if n = 34 then Printf.printf \"asd %d %Ld %Ld %d\\n\" i !t0 !t1 (!r + 1);*)\n\t if !res > !r + 1 then (\n\t res := !r + 1;\n\t best0 := i;\n\t )\n\t);\n\tif i < cnt0 then (\n\t t0 := !t0 +| Int64.of_int (fst c0.(i));\n\t);\n\tif k - 1 - i < cnt1 && k - 1 - i >= 0 then (\n\t t1 := !t1 -| Int64.of_int (fst c1.(k - 1 - i));\n\t);\n done;\n if !res > n\n then Printf.printf \"%d\\n\" (-1)\n else (\n\tPrintf.printf \"%d\\n\" !res;\n\tlet d0 = ref 0 in\n\tlet d1 = ref 0 in\n\tlet s' = ref 0L in\n\t for i = 0 to !res - 1 do\n\t if a0.(i) < a0.(!d0)\n\t then d0 := i;\n\t if a1.(i) < a1.(!d1)\n\t then d1 := i;\n\t done;\n\t incr d0;\n\t incr d1;\n\t for i = 0 to !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c0.(i) + 1) !d0;\n\t s' := !s' +| Int64.of_int (fst c0.(i)) *| Int64.of_int a0.(!d0 - 1);\n\t done;\n\t for i = 0 to k - !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c1.(i) + 1) !d1;\n\t s' := !s' +| Int64.of_int (fst c1.(i)) *| Int64.of_int a1.(!d1 - 1);\n\t done;\n\t (*Printf.printf \"qwe %Ld\\n\" !s';*)\n\t assert (!s' <= s);\n )\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet ( ++ ) a b = Int64.add a b\nlet ( ** ) a b = Int64.mul a b\nlet ( -- ) a b = Int64.sub a b\nlet ( // ) a b = Int64.div 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))\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet () = \n let n = read_int() in\n let m = read_int() in\n let k = read_int() in\n let s = long (read_int()) in \n\n let dcost = Array.init n (fun _ -> long (read_int())) in\n let pcost = Array.init n (fun _ -> long (read_int())) in \n\n let rec read_loop i plist dlist = if i=m then (plist,dlist) else\n let t = read_int () in\n let cost = long (read_int ()) in\n if t = 1\n then read_loop (i+1) plist ((cost,i)::dlist)\n else read_loop (i+1) ((cost,i)::plist) dlist\n in\n\n let (plist,dlist) = read_loop 0 [] [] in\n let parray = Array.of_list (List.sort compare plist) in\n let darray = Array.of_list (List.sort compare dlist) in\n\n (*\n let rec firstk i li ac = if i = k then List.rev ac else\n match li with\n\t| [] -> List.rev ac\t \n\t| h::t -> firstk (i+1) t (h::ac)\n in\n \n let plist = firstk 0 plist [] in\n let dlist = firstk 0 dlist [] in \n let dlist = List.rev dlist in\n *)\n \n let nd = min k (Array.length darray) in\n let np = Array.length parray in\n let p_start = k - nd in\n let dsum = sum 0 (nd-1) (fun i -> fst darray.(i)) 0L in\n let psum = sum 0 (p_start-1) (fun i -> fst parray.(i)) 0L in\n \n let is_possible d =\n (* return true if it's possible to get k gadgets in the first d days *)\n (* days are numbered 0, 1, 2, ... n-1. so we're looking at days 0,1,..d-1 *)\n let (best_dollar, dday) = minf 0 (d-1) (fun j -> (dcost.(j), j)) in\n let (best_pound, pday) = minf 0 (d-1) (fun j -> (pcost.(j), j)) in\n\n let rec scan i dsum psum = \n if best_dollar ** dsum ++ best_pound ** psum <= s then i\n else if i >= nd || i + p_start >= np then -1 else\n\tscan (i+1) (dsum -- (fst darray.(nd-1-i))) (psum ++ (fst parray.(p_start+i)))\n in\n\n let goodi = scan 0 dsum psum in\n (goodi >= 0, (dday, pday, goodi))\n in\n\n let rec bsearch lo hi =\n (* lo is impossible, hi is possible *)\n if lo = hi-1 then hi else\n let m = (lo+hi)/2 in\n if fst (is_possible m) then bsearch lo m else bsearch m hi\n in\n\n if not (fst (is_possible n)) then printf \"-1\\n\" else (\n let answer = bsearch 0 n in\n printf \"%d\\n\" answer;\n\n let (_, (dday, pday, goodi)) = is_possible answer in\n\n for j=0 to nd-goodi-1 do\n printf \"%d %d\\n\" (1+ snd darray.(j)) (1+dday)\n done;\n\n for j=0 to p_start+goodi-1 do\n printf \"%d %d\\n\" (1+ snd parray.(j)) (1+pday)\n done\n \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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let a0 = Array.make n 0 in\n let a1 = Array.make n 0 in\n let am0 = Array.make n 0 in\n let am1 = Array.make n 0 in\n let c0 = Array.make m (0, 0) in\n let c1 = Array.make m (0, 0) in\n let cnt0 = ref 0 in\n let cnt1 = ref 0 in\n let t0 = ref 0L in\n let t1 = ref 0L in\n for i = 0 to n - 1 do\n a0.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am0.(i) <-\n\tif i = 0\n\tthen a0.(i)\n\telse min am0.(i - 1) a0.(i);\n done;\n for i = 0 to n - 1 do\n a1.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am1.(i) <-\n\tif i = 0\n\tthen a1.(i)\n\telse min am1.(i - 1) a1.(i);\n done;\n for i = 0 to m - 1 do\n let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif t = 1 then (\n\t c0.(!cnt0) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt0;\n\t) else (\n\t c1.(!cnt1) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t t1 := !t1 +| Int64.of_int (fst c1.(!cnt1));\n\t incr cnt1;\n\t)\n done;\n let cnt0 = !cnt0 in\n let cnt1 = !cnt1 in\n let c0 = Array.sub c0 0 cnt0 in\n let c1 = Array.sub c1 0 cnt1 in\n let res = ref (n + 1) in\n let best0 = ref 0 in\n Array.sort compare c0;\n Array.sort compare c1;\n for i = 0 to cnt0 do\n\tif k - i <= cnt1 then (\n(*Printf.printf \"asd %d %Ld %Ld\\n\" i !t0 !t1;*)\n\t let l = ref (-1)\n\t and r = ref n in\n\t while !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t let t =\n\t\tInt64.of_int am0.(m) *| !t0 +|\n\t\t Int64.of_int am1.(m) *| !t1\n\t in\n\t\tif t <= s\n\t\tthen r := m\n\t\telse l := m\n\t done;\nif n = 34 then Printf.printf \"asd %d %Ld %Ld %d\\n\" i !t0 !t1 (!r + 1);\n\t if !res > !r + 1 then (\n\t res := !r + 1;\n\t best0 := i;\n\t )\n\t);\n\tif i < cnt0 then (\n\t t0 := !t0 +| Int64.of_int (fst c0.(i));\n\t);\n\tif k - 1 - i < cnt1 && k - 1 - i >= 0 then (\n\t t1 := !t1 -| Int64.of_int (fst c1.(k - 1 - i));\n\t);\n done;\n if !res > n\n then Printf.printf \"%d\\n\" (-1)\n else (\n\tPrintf.printf \"%d\\n\" !res;\n\tlet d0 = ref 0 in\n\tlet d1 = ref 0 in\n\tlet s' = ref 0L in\n\t for i = 0 to !res - 1 do\n\t if a0.(i) < a0.(!d0)\n\t then d0 := i;\n\t if a1.(i) < a1.(!d1)\n\t then d1 := i;\n\t done;\n\t incr d0;\n\t incr d1;\n\t for i = 0 to !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c0.(i) + 1) !d0;\n\t s' := !s' +| Int64.of_int (fst c0.(i)) *| Int64.of_int a0.(!d0 - 1);\n\t done;\n\t for i = 0 to k - !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c1.(i) + 1) !d1;\n\t s' := !s' +| Int64.of_int (fst c1.(i)) *| Int64.of_int a1.(!d1 - 1);\n\t done;\n\t (*Printf.printf \"qwe %Ld\\n\" !s';*)\n\t assert (!s' <= s);\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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a0 = Array.make n 0 in\n let a1 = Array.make n 0 in\n let am0 = Array.make n 0 in\n let am1 = Array.make n 0 in\n let c0 = Array.make m (0, 0) in\n let c1 = Array.make m (0, 0) in\n let cnt0 = ref 0 in\n let cnt1 = ref 0 in\n let t0 = ref 0L in\n let t1 = ref 0L in\n for i = 0 to n - 1 do\n a0.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am0.(i) <-\n\tif i = 0\n\tthen a0.(i)\n\telse min am0.(i - 1) a0.(i);\n done;\n for i = 0 to n - 1 do\n a1.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am1.(i) <-\n\tif i = 0\n\tthen a1.(i)\n\telse min am1.(i - 1) a1.(i);\n done;\n for i = 0 to m - 1 do\n let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif t = 1 then (\n\t c0.(!cnt0) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt0;\n\t) else (\n\t c1.(!cnt1) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t t1 := !t1 +| Int64.of_int (fst c1.(!cnt1));\n\t incr cnt1;\n\t)\n done;\n let cnt0 = !cnt0 in\n let cnt1 = !cnt1 in\n let c0 = Array.sub c0 0 cnt0 in\n let c1 = Array.sub c1 0 cnt1 in\n let res = ref (n + 1) in\n let best0 = ref 0 in\n Array.sort compare c0;\n Array.sort compare c1;\n for i = 0 to cnt0 do\n\tif k - i <= cnt1 then (\n(*Printf.printf \"asd %d %Ld %Ld\\n\" i !t0 !t1;*)\n\t let l = ref (-1)\n\t and r = ref n in\n\t while !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t let t =\n\t\tInt64.of_int am0.(m) *| !t0 +|\n\t\t Int64.of_int am1.(m) *| !t1\n\t in\n\t\tif t <= Int64.of_int s\n\t\tthen r := m\n\t\telse l := m\n\t done;\n\t if !res > !r + 1 then (\n\t res := !r + 1;\n\t best0 := i;\n\t )\n\t);\n\tif i < cnt0 then (\n\t t0 := !t0 +| Int64.of_int (fst c0.(i));\n\t);\n\tif k - 1 - i < cnt1 && k - 1 - i >= 0 then (\n\t t1 := !t1 -| Int64.of_int (fst c1.(k - 1 - i));\n\t);\n done;\n if !res > n\n then Printf.printf \"%d\\n\" (-1)\n else (\n\tPrintf.printf \"%d\\n\" !res;\n\tlet d0 = ref 0 in\n\tlet d1 = ref 0 in\n\tlet s' = ref 0L in\n\t for i = 0 to !res - 1 do\n\t if a0.(i) < a0.(!d0)\n\t then d0 := i;\n\t if a1.(i) < a1.(!d1)\n\t then d1 := i;\n\t done;\n\t incr d0;\n\t incr d1;\n\t for i = 0 to !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c0.(i) + 1) !d0;\n\t s' := !s' +| Int64.of_int (fst c0.(i)) *| Int64.of_int a0.(!d0 - 1);\n\t done;\n\t for i = 0 to k - !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c1.(i) + 1) !d1;\n\t s' := !s' +| Int64.of_int (fst c1.(i)) *| Int64.of_int a1.(!d1 - 1);\n\t done;\n\t assert (!s' <= Int64.of_int s);\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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let a0 = Array.make n 0 in\n let a1 = Array.make n 0 in\n let am0 = Array.make n 0 in\n let am1 = Array.make n 0 in\n let c0 = Array.make m (0, 0) in\n let c1 = Array.make m (0, 0) in\n let cnt0 = ref 0 in\n let cnt1 = ref 0 in\n let t0 = ref 0L in\n let t1 = ref 0L in\n for i = 0 to n - 1 do\n a0.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am0.(i) <-\n\tif i = 0\n\tthen a0.(i)\n\telse min am0.(i - 1) a0.(i);\n done;\n for i = 0 to n - 1 do\n a1.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am1.(i) <-\n\tif i = 0\n\tthen a1.(i)\n\telse min am1.(i - 1) a1.(i);\n done;\n for i = 0 to m - 1 do\n let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif t = 1 then (\n\t c0.(!cnt0) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt0;\n\t) else (\n\t c1.(!cnt1) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t if !cnt1 < k\n\t then t1 := !t1 +| Int64.of_int (fst c1.(!cnt1));\n\t incr cnt1;\n\t)\n done;\n let cnt0 = !cnt0 in\n let cnt1 = !cnt1 in\n let c0 = Array.sub c0 0 cnt0 in\n let c1 = Array.sub c1 0 cnt1 in\n let res = ref (n + 1) in\n let best0 = ref 0 in\n Array.sort compare c0;\n Array.sort compare c1;\n for i = 0 to cnt0 do\n\tif k - i <= cnt1 then (\n(*Printf.printf \"asd %d %Ld %Ld\\n\" i !t0 !t1;*)\n\t let l = ref (-1)\n\t and r = ref n in\n\t while !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t let t =\n\t\tInt64.of_int am0.(m) *| !t0 +|\n\t\t Int64.of_int am1.(m) *| !t1\n\t in\n\t\tif t <= s\n\t\tthen r := m\n\t\telse l := m\n\t done;\n(*if n = 34 then Printf.printf \"asd %d %Ld %Ld %d\\n\" i !t0 !t1 (!r + 1);*)\n\t if !res > !r + 1 then (\n\t res := !r + 1;\n\t best0 := i;\n\t )\n\t);\n\tif i < cnt0 then (\n\t t0 := !t0 +| Int64.of_int (fst c0.(i));\n\t);\n\tif k - 1 - i < cnt1 && k - 1 - i >= 0 then (\n\t t1 := !t1 -| Int64.of_int (fst c1.(k - 1 - i));\n\t);\n done;\n if !res > n\n then Printf.printf \"%d\\n\" (-1)\n else (\n\tPrintf.printf \"%d\\n\" !res;\n\tlet d0 = ref 0 in\n\tlet d1 = ref 0 in\n\tlet s' = ref 0L in\n\t for i = 0 to !res - 1 do\n\t if a0.(i) < a0.(!d0)\n\t then d0 := i;\n\t if a1.(i) < a1.(!d1)\n\t then d1 := i;\n\t done;\n\t incr d0;\n\t incr d1;\n\t for i = 0 to !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c0.(i) + 1) !d0;\n\t s' := !s' +| Int64.of_int (fst c0.(i)) *| Int64.of_int a0.(!d0 - 1);\n\t done;\n\t for i = 0 to k - !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c1.(i) + 1) !d1;\n\t s' := !s' +| Int64.of_int (fst c1.(i)) *| Int64.of_int a1.(!d1 - 1);\n\t done;\n\t (*Printf.printf \"qwe %Ld\\n\" !s';*)\n\t assert (!s' <= s);\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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a0 = Array.make n 0 in\n let a1 = Array.make n 0 in\n let am0 = Array.make n 0 in\n let am1 = Array.make n 0 in\n let c0 = Array.make m (0, 0) in\n let c1 = Array.make m (0, 0) in\n let cnt0 = ref 0 in\n let cnt1 = ref 0 in\n let t0 = ref 0L in\n let t1 = ref 0L in\n for i = 0 to n - 1 do\n a0.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am0.(i) <-\n\tif i = 0\n\tthen a0.(i)\n\telse min am0.(i - 1) a0.(i);\n done;\n for i = 0 to n - 1 do\n a1.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n am1.(i) <-\n\tif i = 0\n\tthen a1.(i)\n\telse min am1.(i - 1) a1.(i);\n done;\n for i = 0 to m - 1 do\n let t = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif t = 1 then (\n\t c0.(!cnt0) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t incr cnt0;\n\t) else (\n\t c1.(!cnt1) <- (Scanf.bscanf sb \"%d \" (fun s -> s), i);\n\t t1 := !t1 +| Int64.of_int (fst c1.(!cnt1));\n\t incr cnt1;\n\t)\n done;\n let cnt0 = !cnt0 in\n let cnt1 = !cnt1 in\n let c0 = Array.sub c0 0 cnt0 in\n let c1 = Array.sub c1 0 cnt1 in\n let res = ref (n + 1) in\n let best0 = ref 0 in\n Array.sort compare c0;\n Array.sort compare c1;\n for i = 0 to cnt0 do\n\tif k - i <= cnt1 then (\n\t let l = ref (-1)\n\t and r = ref n in\n\t while !l < !r - 1 do\n\t let m = (!l + !r) / 2 in\n\t let t =\n\t\tInt64.of_int am0.(m) *| !t0 +|\n\t\t Int64.of_int am1.(m) *| !t1\n\t in\n\t\tif t <= Int64.of_int s\n\t\tthen r := m\n\t\telse l := m\n\t done;\n\t if !res > !r + 1 then (\n\t res := !r + 1;\n\t best0 := i;\n\t )\n\t);\n\tif i < cnt0 then (\n\t t0 := !t0 +| Int64.of_int (fst c0.(i));\n\t);\n\tif k - 1 - i < cnt1 && k - 1 - i >= 0 then (\n\t t1 := !t1 -| Int64.of_int (fst c1.(k - 1 - i));\n\t);\n done;\n if !res > n\n then Printf.printf \"%d\\n\" (-1)\n else (\n\tPrintf.printf \"%d\\n\" !res;\n\tlet d0 = ref 0 in\n\tlet d1 = ref 0 in\n\t for i = 0 to !res - 1 do\n\t if a0.(i) < a0.(!d0)\n\t then d0 := i;\n\t if a1.(i) < a1.(!d0)\n\t then d1 := i;\n\t done;\n\t incr d0;\n\t incr d1;\n\t for i = 0 to !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c0.(i) + 1) !d0;\n\t done;\n\t for i = 0 to k - !best0 - 1 do\n\t Printf.printf \"%d %d\\n\" (snd c1.(i) + 1) !d1;\n\t done;\n )\n"}], "src_uid": "045c8f116415f277fb7cf1109488b589"} {"source_code": "let (+|) = Int64.add\nlet (-|) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\n\ntype element = {mutable p : int;\n\t\tmutable rank : int;\n\t\tmutable w : int64}\n\ntype t = element array\n\nlet makeset set x =\n set.(x) <- {p = x; rank = 0; w = 0L}\n\n(*\nlet rec find set x =\n if x <> set.(x).p then set.(x).p <- find set set.(x).p;\n set.(x).p\n*)\nlet rec find set x =\n if x <> set.(x).p\n then find set set.(x).p\n else x\n\nlet link set x y w =\n if set.(x).rank > set.(y).rank then (\n set.(y).p <- x;\n set.(y).w <- w;\n x\n ) else (\n if set.(x).rank = set.(y).rank then set.(y).rank <- set.(y).rank + 1;\n set.(x).p <- y;\n set.(x).w <- w;\n y\n )\n\nlet newsets size =\n let set = Array.make size {p = -1; rank = 0; w = 0L} in\n for i = 0 to size-1 do\n makeset set i\n done;\n set\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make m (0L, 0, 0) in\n for i = 0 to m - 1 do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let w = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tes.(i) <- (w, u - 1, v - 1)\n done;\n let es' = Array.copy es in\n let () = Array.sort compare es in\n let ds = newsets n in\n let c = Array.make n (-1) in\n let t = ref 0L in\n for i = 0 to m - 1 do\n\tlet (w, u, v) = es.(i) in\n\tlet ru = find ds u in\n\tlet rv = find ds v in\n\t if ru <> rv then (\n\t ignore (link ds ru rv w);\n\t t := !t +| w\n\t )\n done;\n for i = 0 to m - 1 do\n\tlet lca =\n\t let (_w, u, v) = es'.(i) in\n\t let u = ref u in\n\t let v = ref v in\n\t while ds.(!u).p <> !u do\n\t c.(!u) <- i;\n\t u := ds.(!u).p\n\t done;\n\t c.(!u) <- i;\n\t while c.(!v) <> i do\n\t v := ds.(!v).p\n\t done;\n\t !v\n\tin\n\tlet (w, u, v) = es'.(i) in\n\tlet ww = ref 0L in\n\tlet u = ref u in\n\tlet v = ref v in\n\t while !u <> lca do\n\t ww := max !ww ds.(!u).w;\n\t u := ds.(!u).p\n\t done;\n\t while !v <> lca do\n\t ww := max !ww ds.(!v).w;\n\t v := ds.(!v).p\n\t done;\n\t let t = !t -| !ww +| w in\n\t Printf.printf \"%Ld\\n\" t\n done;\n", "positive_code": [{"source_code": "(* started 1:10 *)\n\nopen Printf\nopen Scanf\n\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 rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\n let n = read_int() in\n let m = read_int() in\n\n let edges_unsorted = fold 1 m (fun i ac ->\n let u = read_int() -1 in\n let v = read_int() -1 in\n let w = long (read_int()) in\n (w,u,v)::ac) []\n in\n\n let edges_unsorted = List.rev edges_unsorted in\n \n let edges = List.sort compare edges_unsorted in\n\n let uf = Array.make n (-1) in\n let weight = Array.make n 0L in\n\n let rec find i = if uf.(i) < 0 then i else find uf.(i) in\n\n let union i j w =\n (* assume i and j are both canonical elements *)\n let (wi,wj) = (-uf.(i), -uf.(j)) in\n if wi < wj then (\n uf.(j) <- uf.(i) + uf.(j); \n uf.(i) <- j;\n weight.(i) <- w;\n ) else (\n uf.(i) <- uf.(i) + uf.(j); \n uf.(j) <- i;\n weight.(j) <- w; \n )\n in\n\n List.iter (fun (w,u,v) ->\n let (i,j) = (find u, find v) in\n if i <> j then union i j w\n ) edges;\n\n let path = Array.make n (-1) in\n\n let total_cost = sum 0 (n-1) (fun v -> weight.(v)) 0L in\n\n let lca u v i =\n let rec mark u = if u >= 0 then (path.(u) <- i; mark uf.(u)) in\n mark u;\n let rec fmark v = if path.(v) = i then v else fmark uf.(v) in\n fmark v\n in\n\n let rec max_cost_to v l ac = if v = l then ac else\n max_cost_to uf.(v) l (max ac weight.(v))\n in\n \n List.iteri (fun i (w,u,v) ->\n let l = lca u v i in\n let wt = max (max_cost_to u l 0L) (max_cost_to v l 0L) in\n printf \"%Ld\\n\" (total_cost ++ w -- wt)\n ) edges_unsorted;\n"}], "negative_code": [], "src_uid": "bab40fe0052e2322116c084008c43366"} {"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 \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let c = ref 0L in\n for i = 1 to n do\n let k = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tc := !c +| k;\n\tPrintf.printf \"%Ld \" (!c /| m);\n\tc := Int64.rem !c m;\n done;\n Printf.printf \"\\n\"\n", "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 end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * )\n\tlet (+) 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\n\tlet labs p = if p < 0L then -1L*p else p\n\tlet (~|) p = Int64.to_int p\n\tlet (~~|) p = Int64.of_int p\n\n\tlet input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet 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)\n\tlet print_i64_endline n = n |> Int64.to_string |> print_endline\n\t\n\tlet (mod) m n = m - (m/n) * n let (%) = (mod)\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = (m*n) / gcd m n\n\tlet rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_-$1 && !f do match fbod !i with | `Ok -> i := !i +$ 1; | `Ng -> f := false done\n\tlet repi64 from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_-$1 && !f do match fbod ~~| !i with | `Ok -> i := !i +$ 1; | `Ng -> f := false done\nend\n\n\n\nopen MyInt64\nlet () =\n\tlet n,m = get_2_i64 ()\n\tin let a = input_i64_array n\n\tin\n\tArray.fold_left (fun (res,sum,cur) v -> \n\t\tlet w = cur + v\n\t\tin if w >= m then (\n\t\t\tlet q = w / m in let r = w - q * m\n\t\t\tin\n\t\t\t(q::res,sum+q,r)\n\t\t\t(* if sum+q >= n then (\n\t\t\t\tlet q' = n - sum in\n\t\t\t\t(q'::res,n,r)\n\t\t\t) else (\n\t\t\t\t(q::res,sum+q,r)\n\t\t\t) *)\n\t\t) else (0L::res,sum,w)\n\t) ([],0L,0L) a\n\t|> (fun (r,_,_) -> r)\n\t|> List.rev\n\t|> List.iter (printf \"%Ld \")"}], "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 end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * )\n\tlet (+) 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\n\tlet labs p = if p < 0L then -1L*p else p\n\tlet (~|) p = Int64.to_int p\n\tlet (~~|) p = Int64.of_int p\n\n\tlet input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet 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)\n\tlet print_i64_endline n = n |> Int64.to_string |> print_endline\n\t\n\tlet (mod) m n = m - (m/n) * n let (%) = (mod)\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = (m*n) / gcd m n\n\tlet rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_-$1 && !f do match fbod !i with | `Ok -> i := !i +$ 1; | `Ng -> f := false done\n\tlet repi64 from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_-$1 && !f do match fbod ~~| !i with | `Ok -> i := !i +$ 1; | `Ng -> f := false done\nend\n\n\n\nopen MyInt64\nlet () =\n\tlet n,m = get_2_i64 ()\n\tin let a = input_i64_array n\n\tin\n\tArray.fold_left (fun (res,sum,cur) v -> \n\t\tif sum = n then (res,sum,cur)\n\t\telse if sum > n then failwith \"\"\n\t\telse \n\t\tlet w = cur + v\n\t\tin if w >= m then (\n\t\t\tlet q = w / m in let r = w - q * m\n\t\t\tin\n\t\t\tif sum+q >= n then (\n\t\t\t\tlet q' = n - sum in\n\t\t\t\t(q'::res,n,r)\n\t\t\t) else (\n\t\t\t\t(q::res,sum+q,r)\n\t\t\t)\n\t\t) else (0L::res,sum,w)\n\t) ([],0L,0L) a\n\t|> (fun (r,_,_) -> r)\n\t|> List.rev\n\t|> List.iter (printf \"%Ld \")"}], "src_uid": "a2085c2d21b2dbe4cc27a15fa4a1ec4f"} {"source_code": "module A = Array;;\nmodule C = Char;;\nmodule L = List;;\nmodule S = String;;\n\nlet pf = Printf.printf;;\nlet sf = Scanf.scanf;;\nlet ssf = Scanf.sscanf;;\n\nlet (@@) f x = f x;;\nlet (|>) x f = f x;;\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\ntype ('a, 'b) avl_data =\n | Empty\n | Node of int * ('a * 'b) * ('a, 'b) avl_data * ('a, 'b) avl_data\n;;\n\ntype 'a option = Nothing | Just of 'a;;\n\ntype ('a, 'b) avl_tree =\n { set : ('a * 'b) -> unit; value : 'a -> 'b option }\n;;\n\nlet new_avl_tree cmp =\n let tree = ref Empty in\n let err() = raise @@ Error \"AVL-Tree Internal Error.\" in\n let height = function Empty -> 0 | Node (h, _, _, _) -> h in\n let make_node a l r = Node (max (height l) (height r) + 1, a, l, r) in\n let rotate = function\n Empty -> Empty\n | Node (_, a, l, r) ->\n if height l > height r + 1\n then (match l with\n Empty -> err()\n | Node (_, b, ll, lr) ->\n if height ll >= height lr\n then make_node b ll (make_node a lr r)\n else (match lr with\n Empty -> err()\n | Node (_, c, lrl, lrr) ->\n make_node c (make_node b ll lrl) (make_node a lrr r)))\n else if height l + 1 < height r\n then (match r with\n Empty -> err()\n | Node (_, b, rl, rr) ->\n if height rl <= height rr\n then make_node b (make_node a l rl) rr\n else (match rl with\n Empty -> err()\n | Node (_, c, rll, rlr) ->\n make_node c (make_node a l rll) (make_node b rlr rr)))\n else make_node a l r in\n let rec insert (x, y) = function\n Empty -> Node (1, (x, y), Empty, Empty)\n | Node (h, (k, v), l, r) ->\n let t = if cmp x k = 0\n then Node (h, (x, y), l, r)\n else if cmp x k < 0\n then Node (h, (k, v), insert (x, y) l, r)\n else Node (h, (k, v), l, insert (x, y) r) in\n rotate t in\n let rec find x = function\n Empty -> Nothing\n | Node (_, (k, v), l, r) ->\n if cmp x k = 0\n then Just v\n else if cmp x k < 0\n then find x l\n else find x r in\n let this() =\n { set = (fun x -> tree := insert x !tree);\n value = (fun x -> find x !tree) } in\n this();\n;;\n\nlet _ =\n let str = read_line() in\n let (n, m) = ssf str \"%d %d\" (fun x y -> x, y) in\n let avl = new_avl_tree compare in\n for i = 1 to m do\n let s = read_line() in\n let (a, b) = ssf s \"%s %s\" (fun x y -> x, y) in\n let res = if String.length a <= String.length b then a else b in\n avl.set (a, res); avl.set (b, res);\n done;\n let str = read_line() in\n let slist = Str.split (Str.regexp \" \") str in\n let reveal = function Nothing -> \" \" | Just a -> a in\n List.map (fun s -> print_string @@ reveal (avl.value s) ^ \" \") slist\n;;\n", "positive_code": [{"source_code": "module StringMap = Map.Make(String)\n\nlet read_int () = Scanf.scanf \"%d %d \" (fun n m -> (n, m))\nlet read_str () = Scanf.scanf \"%s \" (fun s -> s)\n\nlet get_short str1 str2 = \n if String.length str1 <= String.length str2\n then\n str1\n else\n str2\n\nlet fill_map m =\n let map = StringMap.empty in \n let rec loop i map =\n if i < m\n then\n let key = read_str () in\n let temp = read_str () in\n let value = get_short key temp in\n let map = StringMap.add key value map in\n loop (i + 1) map\n else\n map\n in loop 0 map\n\nlet fill_list n = \n let rec loop i list =\n if i < n\n then\n let temp = read_str () in\n loop (i + 1) (temp :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () =\n let (n, m) = read_int () in\n let words = fill_map m in\n let text = fill_list n in\n (words, text)\n\nlet solve (words, text) =\n let rec loop list acc =\n match list with\n | (head :: tail) -> \n let short = StringMap.find head words in\n loop tail (short :: acc)\n | [] -> List.rev acc\n in loop text []\n\nlet print result = \n (List.iter (Printf.printf \"%s \") result;\n Printf.printf \"\\n\")\n\nlet () = print (solve (input ()))"}, {"source_code": "let () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n let h = Hashtbl.create n in\n for i = 1 to m do\n Scanf.scanf \"%[^ ] %s\\n\" (Hashtbl.add h)\n done;\n let w = Array.init n (fun _ ->\n Scanf.scanf \"%[^ \\n]%_c\" (fun s ->\n let t = Hashtbl.find h s in\n if String.length t < String.length s\n then t else s\n )) in\n print_endline (String.concat \" \" (Array.to_list w))\n)\n"}], "negative_code": [], "src_uid": "edd556d60de89587f1b8daa893538530"} {"source_code": "open List open Str open Int64;;\nlet cmp x y =\n if(nth x 0) < (nth y 0) || (((nth x 0) = (nth y 0)) && ((nth x 1) < (nth y 1)))\n then -1 else 1;;\nlet n = read_int ();;\nlet par = Array.create n [0L;0L] and x_1 :: x_2 :: [] =\n map (of_string) (split (regexp \" \") (read_line ()));;\nfor i = 1 to n do\n let k :: b :: [] = \n map (of_string) (split (regexp \" \") (read_line ())) in\n Array.set par (i - 1) [(add (mul k x_1) b); (add (mul k x_2) b)];\ndone;;\nArray.sort cmp par;;\nfor i = 0 to (Array.length par) - 2 do\n if (nth par.(i + 1) 1) < (nth par.(i) 1) then begin\n print_endline \"YES\";\n exit 0;\nend done;;\nprint_endline \"NO\";;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x) \n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\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 () = \n let n = read_int () in\n let x1 = read_long () in\n let x2 = read_long () in \n\n let k = Array.make n 0L in\n let b = Array.make n 0L in\n\n for i=0 to n-1 do\n k.(i) <- read_long();\n b.(i) <- read_long()\n done;\n\n let y1 = Array.init n (fun i -> (k.(i) ** x1 ++ b.(i), i)) in\n let y2 = Array.init n (fun i -> (k.(i) ** x2 ++ b.(i), i)) in\n\n let y1_init = Array.copy y1 in\n let y2_init = Array.copy y2 in \n \n Array.sort compare y1;\n Array.sort compare y2;\n\n Array.sort (fun (v1,i1) (v2,i2) ->\n if v1 <> v2 then compare v1 v2\n else compare y2_init.(i1) y2_init.(i2)\n ) y1;\n\n Array.sort (fun (v1,i1) (v2,i2) ->\n if v1 <> v2 then compare v1 v2\n else compare y1_init.(i1) y1_init.(i2)\n ) y2;\n\n let answer = forall 0 (n-1) (\n fun i ->\n let (_,i1) = y1.(i) in\n let (_,i2) = y2.(i) in \n i1 = i2\n ) in\n\n if answer then printf \"NO\\n\" else printf \"YES\\n\"\n"}], "negative_code": [{"source_code": "open Array;;\nopen String;;\nopen Str;;\n\n"}, {"source_code": "let cmp x y = if x.(0) < y.(0) then -1 else 1;;\nlet n = read_int ();;\nlet ls = ref (Array.create n [|0;0|]);;\nlet x_1 = ref 0 and x_2 = ref 0;;\nlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\nbegin\n\tx_1 := List.nth ins 0; \n\tx_2 := List.nth ins 1;\nend;;\nfor i = 1 to n do\n\tlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n\tlet k = List.nth ins 0 and b = List.nth ins 1 in\n\tbegin\n\t\tls := Array.append !ls [|[|(!x_1 * k + b);(!x_2 * k + b)|]|];\n\tend;\ndone;\nArray.stable_sort cmp !ls;;\nlet fl = ref 0;;\nfor i = 0 to Array.length !ls - 2 do\n\tif (!ls.(i).(1) > !ls.(i + 1).(1)) then fl := 1;\ndone;;\nif !fl = 0 then print_endline \"NO\" else print_endline \"YES\";;\n\n(*\nfor i = 0 to Array.length !ls - 1 do\n\tprint_int !ls.(i).(0);\n\tprint_string \" \";\n\tprint_int !ls.(i).(1);\n\tprint_endline \"\";\ndone;;*)\n"}, {"source_code": "let cmp x y = if x.(0) < y.(0) then -1 else 1;;\nlet n = read_int ();;\nlet ls = ref (Array.create n [|0;0|]);;\nlet x_1 = ref 0 and x_2 = ref 0;;\nlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\nbegin\n\tx_1 := List.nth ins 0; \n\tx_2 := List.nth ins 1;\nend;;\nfor i = 1 to n do\n\tlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n\tlet k = List.nth ins 0 and b = List.nth ins 1 in\n\tbegin\n Array.set (!ls) (i - 1) [|!x_1 * k + b; !x_2 * k + b|];\n\tend;\ndone;\nArray.stable_sort cmp !ls;;\nlet fl = ref 0;;\nfor i = 0 to Array.length !ls - 2 do\n\tif ((!ls.(i).(1) > !ls.(i + 1).(1))) && (!ls.(i).(0) != !ls.(i + 1).(0)) then fl := 1;\ndone;;\nif !fl = 0 then print_endline \"NO\" else print_endline \"YES\";;\n(*\nfor i = 0 to Array.length !ls - 1 do\n\tprint_int !ls.(i).(0);\n\tprint_string \" \";\n\tprint_int !ls.(i).(1);\n\tprint_endline \"\";\ndone;;*)\n"}, {"source_code": "let cmp x y = if x.(0) < y.(0) then -1 else 1;;\nlet n = read_int ();;\nlet ls = ref (Array.create n [|0;0|]);;\nlet x_1 = ref 0 and x_2 = ref 0;;\nlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\nbegin\n\tx_1 := List.nth ins 0; \n\tx_2 := List.nth ins 1;\nend;;\nfor i = 1 to n do\n\tlet ins = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n\tlet k = List.nth ins 0 and b = List.nth ins 1 in\n\tbegin\n Array.set (!ls) (i - 1) [|!x_1 * k + b; !x_2 * k + b|];\n\tend;\ndone;\nArray.stable_sort cmp !ls;;\nlet fl = ref 0;;\nfor i = 0 to Array.length !ls - 2 do\n\tif (!ls.(i).(1) > !ls.(i + 1).(1)) then fl := 1;\ndone;;\nif !fl = 0 then print_endline \"NO\" else print_endline \"YES\";;\n(*\nfor i = 0 to Array.length !ls - 1 do\n\tprint_int !ls.(i).(0);\n\tprint_string \" \";\n\tprint_int !ls.(i).(1);\n\tprint_endline \"\";\ndone;;*)\n"}], "src_uid": "8b61213e2ce76b938aa68ffd1e4c1429"} {"source_code": "let bs = Scanf.Scanning.stdin\nlet xint() = Scanf.bscanf bs \" %d\" (fun x -> x)\nlet xint32() = Scanf.bscanf bs \" %ld\" (fun x -> x)\nlet xint64() = Scanf.bscanf bs \" %Ld\" (fun x -> x)\nlet xstr() = Scanf.bscanf bs \" %s\" (fun x -> x)\nlet xreal() = Scanf.bscanf bs \" %f\" (fun x -> x)\nlet printf = Printf.printf\n\nlet ( +| ) = Int64.add\nlet ( -| ) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\nlet ( %| ) = Int64.rem\n\nlet () = \n let n = xint() in\n let x1 = xint64() and y1 = xint64() in\n let x2 = xint64() and y2 = xint64() in\n let x = Array.make n 0L and y = Array.make n 0L in\n for i = 0 to n - 1 do\n x.(i) <- xint64();\n y.(i) <- xint64();\n done;\n \n let sqr x = x *| x in\n let max x y =\n if Int64.compare x y > 0 then x\n else y\n in\n let min x y =\n if Int64.compare x y < 0 then x\n else y\n in\n\n let ret = ref 9223372036854775807L in\n for i = -1 to n - 1 do\n let r1 = (if i = -1 then 0L else ((sqr (x.(i) -| x1)) +| (sqr (y.(i) -| y1)))) in\n let r2 = ref 0L in\n for j = 0 to n - 1 do\n let a = (sqr (x.(j) -| x1)) +| (sqr (y.(j) -| y1)) in\n let b = (sqr (x.(j) -| x2)) +| (sqr (y.(j) -| y2)) in\n if Int64.compare a r1 > 0 then (\n r2 := max !r2 b;\n );\n done;\n ret := min !ret (r1 +| !r2);\n done;\n printf \"%Ld\\n\" !ret;", "positive_code": [{"source_code": "let bs = Scanf.Scanning.stdin\nlet xint() = Scanf.bscanf bs \" %d\" (fun x -> x)\nlet xint32() = Scanf.bscanf bs \" %ld\" (fun x -> x)\nlet xint64() = Scanf.bscanf bs \" %Ld\" (fun x -> x)\nlet xstr() = Scanf.bscanf bs \" %s\" (fun x -> x)\nlet xreal() = Scanf.bscanf bs \" %f\" (fun x -> x)\nlet printf = Printf.printf\n\nlet ( +| ) = Int64.add\nlet ( -| ) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\nlet ( %| ) = Int64.rem\n\nlet () = \n let n = xint() in\n let x1 = xint64() and y1 = xint64() in\n let x2 = xint64() and y2 = xint64() in\n let x = Array.make n 0L and y = Array.make n 0L in\n for i = 0 to n - 1 do\n x.(i) <- xint64();\n y.(i) <- xint64();\n done;\n \n let sqr x = x *| x in\n let max x y =\n if Int64.compare x y > 0 then x\n else y\n in\n let min x y =\n if Int64.compare x y < 0 then x\n else y\n in\n\n let ret = ref 9223372036854775807L in\n for i = -1 to n - 1 do\n let r1 = (if i = -1 then 0L else ((sqr (x.(i) -| x1)) +| (sqr (y.(i) -| y1)))) in\n let r2 = ref 0L in\n for j = 0 to n - 1 do\n let a = (sqr (x.(j) -| x1)) +| (sqr (y.(j) -| y1)) in\n let b = (sqr (x.(j) -| x2)) +| (sqr (y.(j) -| y2)) in\n if Int64.compare a r1 > 0 then (\n r2 := max !r2 b;\n );\n done;\n ret := min !ret (r1 +| !r2);\n done;\n printf \"%Ld\\n\" !ret;\n"}, {"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read5 () = Scanf.scanf \"%d %d %d %d %d\\n\" ( fun x y z a b-> x, y, z,a,b);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet (n,x1,y1,x2,y2) = read5 ();;\n\nlet coord = Array.init n ( fun _ -> read2 () );;\n\nlet square a = a *| a;;\n\nlet dis (a,b) (c,d) =\n square ( Int64.of_int(a-c) ) +| ( square ( Int64.of_int(b-d) ) );;\n\nlet licz () =\n Array.sort ( fun a b -> compare ( dis a (x1,y1) ) (dis b (x1,y1) ) ) coord;\n let wynik = ref Int64.max_int in\n for i=0 to n do\n let r1 = if i=0 then Int64.zero else dis coord.(i-1) (x1,y1) in\n let r2 = ref Int64.zero in\n for j=i to (n-1) do\n r2 := max !r2 ( dis coord.(j) (x2,y2) )\n done;\n wynik := min !wynik ( r1 +| !r2 )\n done;\n !wynik;;\n\nlet _ = \n Printf.printf \"%Ld\\n\" ( licz () ) ;;\n\n\n"}], "negative_code": [{"source_code": "let bs = Scanf.Scanning.stdin\nlet xint() = Scanf.bscanf bs \" %d\" (fun x -> x)\nlet xint32() = Scanf.bscanf bs \" %ld\" (fun x -> x)\nlet xint64() = Scanf.bscanf bs \" %Ld\" (fun x -> x)\nlet xstr() = Scanf.bscanf bs \" %s\" (fun x -> x)\nlet xreal() = Scanf.bscanf bs \" %f\" (fun x -> x)\nlet printf = Printf.printf\n\nlet ( +| ) = Int64.add\nlet ( -| ) = Int64.sub\nlet ( *| ) = Int64.mul\nlet ( /| ) = Int64.div\nlet ( %| ) = Int64.rem\n\nlet () = \n let n = xint() in\n let x1 = xint64() and y1 = xint64() in\n let x2 = xint64() and y2 = xint64() in\n let x = Array.make n 0L and y = Array.make n 0L in\n for i = 0 to n - 1 do\n x.(i) <- xint64();\n y.(i) <- xint64();\n done;\n \n let sqr x = x *| x in\n let max x y =\n if Int64.compare x y > 0 then x\n else y\n in\n let min x y =\n if Int64.compare x y < 0 then x\n else y\n in\n\n let ret = ref 9223372036854775807L in\n for i = 0 to n - 1 do\n let r1 = (sqr (x.(i) -| x1)) +| (sqr (y.(i) -| y1)) in\n let r2 = ref 0L in\n for j = 0 to n - 1 do\n let a = (sqr (x.(j) -| x1)) +| (sqr (y.(j) -| y1)) in\n let b = (sqr (x.(j) -| x2)) +| (sqr (y.(j) -| y2)) in\n if Int64.compare a r1 > 0 then (\n r2 := max !r2 b;\n );\n done;\n ret := min !ret (r1 +| !r2);\n done;\n printf \"%Ld\\n\" !ret;"}], "src_uid": "5db9c5673a04256c52f180dbfca2a52f"} {"source_code": "let () = \n let s = read_line() in\n let n = String.length s in\n let b = Array.init n (fun i -> if s.[i]='0' then 0 else 1) in\n\n let rec loop i c = \n if i=n-1 && c=0 then ()\n else if i=n-1 && c>0 then Printf.printf \"%d\" b.(i)\n else if b.(i)=0 && c>0 then (Printf.printf \"0\"; loop (i+1) c) \n else if b.(i)=0 && c=0 then loop (i+1) 1\n else (Printf.printf \"1\"; loop (i+1) c)\n in\n\n loop 0 0;\n print_newline()\n", "positive_code": [{"source_code": "(* Codeforces 257B SlonMagSquare *)\n\nopen String;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet 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 remove_first_zero s = \n\tlet ln = String.length s in\n\tif not (String.contains s '0') then String.sub s 1 (ln-1) \n\telse \n\t\tlet idxz = String.index s '0' in\n\t\tlet a = String.sub s 0 idxz in\n\t\tlet b = String.sub s (idxz+1) (ln-idxz-1) in\n\t\ta ^ b;;\n\nlet main () =\n\tlet s = rdln() in\n\tlet os = remove_first_zero s in\n\tbegin\n\t\tprint_string os;\n\t\tprint_newline()\n\tend;;\n\nmain();;\n"}], "negative_code": [], "src_uid": "133eaf241bb1557ba9a3f59c733d34bf"} {"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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let ne = m-(n-1) in\n let nt = n-1 in\n\n let e = Array.make ne (0,0) in \n let t = Array.make nt (0,0) in\n \n let rec read_loop it ie = if it+ie = m then () else\n let a = (read_int(), it+ie) in\n let b = read_int() in\n if b=1 then (\n t.(it) <- a;\n read_loop (it+1) ie\n ) else (\n e.(ie) <- a;\n read_loop it (ie+1)\n )\n in\n\n read_loop 0 0;\n\n Array.sort compare t;\n Array.sort compare e;\n\n let rec gen_pair_list (i,j) k ac = if k = ne then List.rev ac else\n let ac = (i,j)::ac in\n let next = if i+1 = j then (0,j+1) else (i+1,j) in\n gen_pair_list next (k+1) ac\n in\n\n let pair_array = Array.of_list (gen_pair_list (0,1) 0 []) in\n\n let rec build_answer i ac = if i=ne then Some (List.rev ac) else\n let (ii,jj) = pair_array.(i) in\n let elength = fst e.(i) in\n if elength < fst t.(jj) then None else\n\tlet ac = (ii,jj)::ac in\n\tbuild_answer (i+1) ac\n in\n\n match build_answer 0 [] with\n | None -> printf \"-1\\n\"\n | Some li ->\n let po = Array.make m (0,0) in\n List.iteri (fun i (ii,jj) ->\n\tpo.(snd e.(i)) <- (ii+2, jj+2)\n ) li;\n for i=0 to nt-1 do\n\tpo.(snd t.(i)) <- (1, i+2)\n done;\n for i=0 to m-1 do\n\tprintf \"%d %d\\n\" (fst po.(i)) (snd po.(i))\n done\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n \nlet () =\n let n = read_int () in\n let m = read_int () in\n let a = Array.init m (fun i -> let a = read_int () in let b = read_int () in (a, b, i)) in\n let cmp (x1, y1, _) (x2, y2, _) =\n if x1 = x2 then y2 - y1\n else x1 - x2\n in\n let _ = Array.sort cmp a in\n let ans = Array.make m (0, 0) in\n\n let rec add_extra (extra, extra_cnt) x cur =\n if extra_cnt >= m || x = cur then (extra, extra_cnt)\n else add_extra ((x, cur)::extra, extra_cnt + 1) (x+1) cur\n in\n\n let process_edge (extra, extra_cnt, cur) (a, b, i) =\n if extra_cnt = (-1) then (extra, extra_cnt, cur)\n else if b = 0 then \n begin \n match extra with\n | [] -> (extra, (-1), cur)\n | hd::tl -> ans.(i) <- hd; (tl, extra_cnt-1, cur)\n end\n else \n begin\n ans.(i) <- (0, cur);\n let (extra, extra_cnt) = add_extra (extra, extra_cnt) 1 cur in\n (extra, extra_cnt, cur + 1)\n end\n in\n \n let (_, extra_cnt, _) = Array.fold_left process_edge ([], 0, 1) a in\n if extra_cnt = (-1) then Printf.printf \"-1\\n\"\n else Array.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" (a+1) (b+1)) ans\n"}], "negative_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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n let ne = m-(n-1) in\n let nt = n-1 in\n\n let e = Array.make ne (0,0) in \n let t = Array.make nt (0,0) in\n \n let rec read_loop it ie = if it+ie = m then () else\n let a = (read_int(), it+ie) in\n let b = read_int() in\n if b=1 then (\n t.(it) <- a;\n read_loop (it+1) ie\n ) else (\n e.(ie) <- a;\n read_loop it (ie+1)\n )\n in\n\n read_loop 0 0;\n\n Array.sort compare t;\n Array.sort compare e;\n\n let rec gen_pair_list (i,j) k ac = if k = ne then ac else\n let ac = (i,j)::ac in\n let next = if i+1 = j then (0,j+1) else (i+1,j) in\n gen_pair_list next (k+1) ac\n in\n\n let pair_array = Array.of_list (gen_pair_list (0,1) 0 []) in\n\n let rec build_answer i ac = if i=ne then Some (List.rev ac) else\n let (ii,jj) = pair_array.(i) in\n let elength = fst e.(i) in\n if elength < fst t.(jj) then None else\n\tlet ac = (ii,jj)::ac in\n\tbuild_answer (i+1) ac\n in\n\n match build_answer 0 [] with\n | None -> printf \"-1\\n\"\n | Some li ->\n let po = Array.make m (0,0) in\n List.iteri (fun i (ii,jj) ->\n\tpo.(snd e.(i)) <- (ii+2, jj+2)\n ) li;\n for i=0 to nt-1 do\n\tpo.(snd t.(i)) <- (1, i+2)\n done;\n for i=0 to m-1 do\n\tprintf \"%d %d\\n\" (fst po.(i)) (snd po.(i))\n done\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n \nlet () =\n let n = read_int () in\n let m = read_int () in\n let a = Array.init m (fun i -> let a = read_int () in let b = read_int () in (a, b, i)) in\n let _ = Array.sort (fun (x1, y1, _) (x2, y2, _) -> (x1*2+1-y1) - (x2*2+1-y2)) a in\n let ans = Array.make m (0, 0) in\n\n let rec add_extra (extra, extra_cnt) x cur =\n if extra_cnt >= m || x = cur then (extra, extra_cnt)\n else add_extra ((x, cur)::extra, extra_cnt + 1) (x+1) cur\n in\n\n let process_edge (extra, extra_cnt, cur) (a, b, i) =\n if extra_cnt = (-1) then (extra, extra_cnt, cur)\n else if b = 0 then \n begin \n match extra with\n | [] -> (extra, (-1), cur)\n | hd::tl -> ans.(i) <- hd; (tl, extra_cnt-1, cur)\n end\n else \n begin\n ans.(i) <- (0, cur);\n let (extra, extra_cnt) = add_extra (extra, extra_cnt) 1 cur in\n (extra, extra_cnt, cur + 1)\n end\n in\n \n let (_, extra_cnt, _) = Array.fold_left process_edge ([], 0, 1) a in\n if extra_cnt = (-1) then Printf.printf \"-1\\n\"\n else Array.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" (a+1) (b+1)) ans\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n \nlet () =\n let n = read_int () in\n let m = read_int () in\n let a = Array.init m (fun i -> let a = read_int () in let b = read_int () in (a, b, i)) in\n let cmp (x1, y1, _) (x2, y2, _) =\n if x1 = x2 then y1 - y2\n else x1 - x2\n in\n let _ = Array.sort cmp a in\n let ans = Array.make m (0, 0) in\n\n let rec add_extra (extra, extra_cnt) x cur =\n if extra_cnt >= m || x = cur then (extra, extra_cnt)\n else add_extra ((x, cur)::extra, extra_cnt + 1) (x+1) cur\n in\n\n let process_edge (extra, extra_cnt, cur) (a, b, i) =\n if extra_cnt = (-1) then (extra, extra_cnt, cur)\n else if b = 0 then \n begin \n match extra with\n | [] -> (extra, (-1), cur)\n | hd::tl -> ans.(i) <- hd; (tl, extra_cnt-1, cur)\n end\n else \n begin\n ans.(i) <- (0, cur);\n let (extra, extra_cnt) = add_extra (extra, extra_cnt) 1 cur in\n (extra, extra_cnt, cur + 1)\n end\n in\n \n let (_, extra_cnt, _) = Array.fold_left process_edge ([], 0, 1) a in\n if extra_cnt = (-1) then Printf.printf \"-1\\n\"\n else Array.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" (a+1) (b+1)) ans\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n \nlet () =\n let n = read_int () in\n let m = read_int () in\n let a = Array.init m (fun i -> let a = read_int () in let b = read_int () in (a, b, i)) in\n let _ = Array.sort (fun (x1, _, _) (x2, _, _) -> x1 - x2) a in\n let ans = Array.make m (0, 0) in\n\n let rec add_extra (extra, extra_cnt) x cur =\n if extra_cnt >= m || x = cur then (extra, extra_cnt)\n else add_extra ((x, cur)::extra, extra_cnt + 1) (x+1) cur\n in\n\n let process_edge (extra, extra_cnt, cur) (a, b, i) =\n if extra_cnt = (-1) then (extra, extra_cnt, cur)\n else if b = 0 then \n begin \n match extra with\n | [] -> (extra, (-1), cur)\n | hd::tl -> ans.(i) <- hd; (tl, extra_cnt-1, cur)\n end\n else \n begin\n ans.(i) <- (0, cur);\n let (extra, extra_cnt) = add_extra (extra, extra_cnt) 1 cur in\n (extra, extra_cnt, cur + 1)\n end\n in\n \n let (_, extra_cnt, _) = Array.fold_left process_edge ([], 0, 1) a in\n if extra_cnt = (-1) then Printf.printf \"-1\\n\"\n else Array.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" (a+1) (b+1)) ans\n"}], "src_uid": "1a9968052a363f04380d1177c764717b"} {"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n match Stream.next stdin_stream with\n '-' -> - (ri 0)\n | '+' -> ri 0\n | '0'..'9' as c -> ri ((int_of_char c) - 48)\n | _ -> gi ()\nand ri x =\n match Stream.next stdin_stream with\n '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;\nlet pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) a;;\n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n let n = gi() in\n let a = init n (fun i -> gi()) in\n let b = make (n+1) 0 in\n iter (fun i -> if (i >= 1 && i <= n) then b.(i) <- 1 else ()) a;\n let s = fold_left (+) 0 b in\n Printf.printf \"%d\\n\" (n - s)\n ;;\nmain();;\nflushout ()", "positive_code": [{"source_code": "\nlet getint () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun i->i)\nlet getstr () = Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun s-> s)\nlet getchar () = Scanf.bscanf Scanf.Scanning.stdin \" %c\" (fun i->i)\n\nlet inf = 1000000007\n\n\nlet _ = \n let n = getint () in\n let a = Array.make n 0 in\n for i = 0 to n-1 do\n let x = getint () - 1 in\n if x=0 then a.(x) <- a.(x) + 1;\n done;\n let ans = ref 0 in\n for i = 0 to n-1 do\n if a.(i) = 0 then incr ans\n done;\n Printf.printf \"%d\\n\" !ans\n\n "}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet n = read_int ();;\n\nlet data = Array.init n (fun i -> read_int ());;\n\nArray.sort compare data;;\n\nlet rec solve ac i data = \n if i>=n || data.(i)>n then ac\n else if i = 0 && data.(i) >= 1 && data.(i) <= n then solve (ac+1) (i+1) data\n else if i=0 && (data.(i)<1 || data.(i)>n) then solve ac (i+1) data\n else if data.(i) > n then ac\n else if data.(i) < 1 then solve ac (i+1) data\n else if data.(i) != data.(i-1) then solve (ac+1) (i+1) data\n else solve ac (i+1) data;;\n \nPrintf.printf \"%d\\n\" (n-(solve 0 0 data));;\n"}, {"source_code": "let () =\n\tlet n = read_int() in\n\tlet l = ref [] in\n\t(for i = 1 to n do\n\t\tlet x = Scanf.scanf \" %d\" (fun i->i) in\n\t\tif x >= 1 && x <= n && not (List.mem x !l) then\n\t\t\tl := x::(!l);\n\tdone; print_int (n-(List.length !l)))\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 a = Array.make 5001 0 in\n let b = ref 0 in\n let c = ref 0 in\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(k) <- a.(k) + 1\n done;\n for i = 1 to n do\n if a.(i) = 0\n then incr c\n else if a.(i) > 1\n then b := !b + a.(i) - 1\n done;\n for i = n + 1 to 5000 do\n if a.(i) > 0\n then incr b\n done;\n let res = max !b !c in\n Printf.printf \"%d\\n\" res;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nlet n = read_int()\n\nlet there = Array.make n false\n\nlet () =\n for i=0 to n-1 do\n let k = (read_int()) -1 in\n if k>=0 && k\n let s = Scanf.scanf \"%s\\n\" (fun s -> s) in\n\n (* build a non-overlapping interval set *)\n let t, _ = List.fold_left (fun (acc, pos) hd ->\n match hd with\n | Str.Text s -> (acc, (pos + String.length s))\n | Str.Delim d ->\n let e = pos + String.length d in\n (add (pos, e - 1) acc, e))\n (RangeSet.empty, 1) (Str.full_split (Str.regexp \"\\\\.+\") s) in\n\n (* calculate the answer to the initial query *)\n let ans = ref (RangeSet.fold (fun _ (l, r) acc -> acc + (r - l)) t 0) in\n\n (* a query can have the following possible effects:\n * merge two intervals (or extend an interval)\n * split an interval\n * no effect on intervals *)\n let rec loop t i =\n if i <> m then\n Scanf.scanf \"%d %c\\n\" (fun x c ->\n let t' = match c with\n | '.' ->\n (* if this char is in an interval, no effect *)\n if RangeSet.mem (x, x) t then t else\n\n (* join two intervals *)\n if RangeSet.mem (x-1,x-1) t && RangeSet.mem (x+1, x+1) t then begin\n let l, _ = RangeSet.find (x-1, x-1) t\n and _, r = RangeSet.find (x+1, x+1) t in\n (* calculate new answer *)\n ans := !ans + 2;\n (* create new tree *)\n add (l, r) (RangeSet.remove (x-1, x-1) (RangeSet.remove (x+1, x+1) t))\n end else\n\n (* extend left interval *)\n if RangeSet.mem (x-1, x-1) t then begin\n let l, _ = RangeSet.find (x-1, x-1) t in\n incr ans;\n add (l, x) (RangeSet.remove (x-1, x-1) t)\n end else\n\n (* extend right interval *)\n if RangeSet.mem (x+1, x+1) t then begin\n let _, r = RangeSet.find (x+1, x+1) t in\n incr ans;\n add (x, r) (RangeSet.remove (x+1, x+1) t)\n end else\n\n (* create new interval *)\n add (x, x) t\n | _ ->\n (* if this char is in an interval, split it *)\n if RangeSet.mem (x, x) t then begin\n let l, r = RangeSet.find (x, x) t\n and t = RangeSet.remove (x, x) t in\n (* we take the interval (l, r) to (l,x-1) and (x+1,r)\n * check these new intervals are valid and subtract 1 from ans\n * for each valid new interval *)\n let t =\n if l < x then begin\n decr ans;\n add (l, x-1) t\n end else t\n in\n if r > x then begin\n decr ans;\n add (x+1, r) t\n end else t\n (* otherwise nothing to do *)\n end else t\n in\n Printf.printf \"%d\\n\" !ans;\n loop t' (i + 1))\n in loop t 0)\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d %d\\n\" (fun n m ->\n let s = Scanf.scanf \"%s\\n\" (fun s -> s) in\n (* count number of groups in s *)\n let a = Array.init (n + 2) (fun i -> if i = 0 || i = n + 1 then false else s.[i-1] = '.') in\n\n let rec aux (groups, count) i =\n if i = n then (groups, count)\n else aux (if s.[i] = '.' then\n (groups + (if i = 0 || s.[i - 1] <> '.' then 1 else 0), count + 1)\n else (groups, count))\n (i + 1)\n in\n\n let g, c = aux (0, 0) 0 in\n\n let groups = ref g\n and count = ref c in\n\n for i = 1 to m do\n Scanf.scanf \"%d %c\\n\" (fun x c ->\n (* only do something if we're changing the state *)\n if a.(x) <> (c = '.') then begin\n if c = '.' then begin\n incr count;\n\n (* merge groups *)\n if a.(x - 1) && a.(x + 1)\n then decr groups;\n\n (* create a new group *)\n if not (a.(x - 1) || a.(x + 1))\n then incr groups\n\n (* check whether we merge or split a group *)\n end else begin\n decr count;\n\n (* split a group *)\n if a.(x - 1) && a.(x + 1)\n then incr groups;\n\n (* remove a single point *)\n if not (a.(x - 1) || a.(x + 1))\n then decr groups\n end;\n\n a.(x) <- c = '.'\n end;\n\n Printf.printf \"%d\\n\" (!count - !groups))\n done)\n"}], "negative_code": [], "src_uid": "68883ab115882de5cf77d0848b80b422"} {"source_code": "(* took 1:15 to get this *)\n\n(* Invert the permutation, and call it x. Now the operation is to\n pick an element from the outside and put it somewhere in the\n middle. Make a set that contains i if x.(i) and x.(i+1) are\n inverted. Add 0 and n into the set. Now take the biggest gap\n between neighbors in this set. n minus this is the answer.\n\n This is a lower and upper bound on the number of moves needed.\n It's an upper bound because you can clearly do it by building up\n the longest sorted region (i.e. biggest gap) in that many steps.\n It's a lower bound because for each neighboring pair that are\n inverted we must reach (from one end or the other) one of those\n elements. The answer computed above gives the most efficient way\n to do this.\n*)\n\nopen 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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let p = Array.init n (fun _ -> read_int() -1) in\n let x = Array.make n 0 in\n for i=0 to n-1 do\n x.(p.(i)) <- i\n done;\n \n let rec makel i ac = if i=n then n::ac else\n let ac = if x.(i-1) > x.(i) then (i::ac) else ac in\n makel (i+1) ac\n in\n let lg = Array.of_list (List.rev (makel 1 [0])) in\n let nn = Array.length lg in\n let answer = n - maxf 0 (nn-2) (fun i -> lg.(i+1) - lg.(i)) in\n printf \"%d\\n\" answer\n", "positive_code": [{"source_code": "let n = read_int() and ind = Array.make 100001 0 and ans = ref 1;;\nlet a = Array.of_list (List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line())));;\nfor i = 0 to n - 1 do \n\tif a.(i) == 1 then Array.set ind 1 1 else \n\tbegin\n\t\tArray.set ind a.(i) (ind.(a.(i) - 1) + 1);\n\t\tans := max !ans ind.(a.(i))\nend done;;\nprint_int (n - !ans)\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int ()) in\n let bio = Array.make (n+1) 0 in\n let _ = Array.iter (fun x -> bio.(x) <- bio.(x-1) + 1) a in\n let ans = n - (Array.fold_left max 0 bio) in\n Printf.printf \"%d\\n\" ans\n \n \n"}], "negative_code": [{"source_code": "(*\n#load \"str.cma\";;\n#load \"nums.cma\";;\n*)\nlet n = read_int () and ans = ref 0 and m = ref 99999999999L;;\nlet a = Array.of_list (List.map (Int64.of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nfor i = n - 1 downto 0 do\n\tif Int64.compare a.(i) !m < 0 then m := a.(i);\n\tif Int64.compare a.(i) !m > 0 then ans := !ans + 1;\ndone;;\nprint_int !ans;;\n"}, {"source_code": "let n = read_int () and ans = ref 0 and m = ref 9999999;;\nlet a = Array.of_list (List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nfor i = n - 1 downto 0 do\n\tif a.(i) < !m then m := a.(i);\n\tif a.(i) > !m then ans := !ans + 1;\ndone;;\nprint_int !ans\n"}, {"source_code": "let n = read_int () and ans = ref 0 and m = ref 999999999L;;\nlet a = Array.of_list (List.map (Int64.of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nfor i = n - 1 downto 0 do\n\tif a.(i) < !m then m := a.(i);\n\tif a.(i) > !m then ans := !ans + 1;\ndone;;\nprint_int !ans\n"}], "src_uid": "277948a70c75840445e1826f2b23a897"} {"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet licz x = (x-|Int64.one)/|two_64;;\n\nlet (n,m) = read2 ();;\n\nlet ruch x y = [ (x+1,y); (x-1,y); (x,y+1); (x,y-1) ];;\n\nlet czy_dobry x y tab =\n if x < 0 || x >= n || y < 0 || y >= m then false\n else if tab.(x).(y) = '*' then false\n else true;;\n \n\nlet rec bfs ax ay k tab vis fuf size = \n let kol = Queue.create () in\n Queue.add (ax,ay) kol;\n vis.(ax).(ay) <- true;\n while not (Queue.is_empty kol) do\n let (x,y) = Queue.take kol in\n fuf.(x).(y) <- k;\n match k with\n | (a,b) -> size.(a).(b) <- size.(a).(b) + 1;\n List.iter ( fun (a,b) -> if (czy_dobry a b tab && not vis.(a).(b)) then begin vis.(a).(b) <- true; Queue.add (a,b) kol end ) ( ruch x y )\n done;;\n\nlet wynik x y tab fuf size =\n let ruchy = List.filter ( fun (x,y) -> czy_dobry x y tab ) (ruch x y) in\n List.fold_left (fun a (x,y) -> a + size.(x).(y)) 0\n (\n List.fold_left (fun a (x,y) -> if\n (List.fold_left (fun a b -> if b = fuf.(x).(y) then false else a ) true a )\n then fuf.(x).(y)::a else a ) [] ruchy\n );;\n \n\nlet _ = \n let tab = Array.make_matrix n m '.' \n and vis = Array.make_matrix n m false \n and fuf = Array.make_matrix n m (0,0)\n and size = Array.make_matrix n m 0 in\n for i=0 to (n-1) do\n let s = Scanf.scanf \"%s\\n\" (fun x -> x) in\n for j=0 to (m-1) do\n tab.(i).(j) <- s.[j];\n fuf.(i).(j) <- (i,j)\n done\n done;\n for i =0 to (n-1) do\n for j=0 to (m-1) do\n if czy_dobry i j tab && not vis.(i).(j) then\n bfs i j (i,j) tab vis fuf size\n done\n done;\n for i=0 to (n-1) do\n for j=0 to (m-1) do\n if tab.(i).(j) = '.' then \n Printf.printf \".\"\n else Printf.printf \"%d\" ( ( wynik i j tab fuf size + 1) mod 10 )\n done;\n Printf.printf \"\\n\"\n done;;\n\n\n\n", "positive_code": [{"source_code": "let xstr() = Scanf.scanf \" %s\" (fun x -> x)\nlet xint() = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = xint() and m = xint() in\n let upp = n * m / 2 + 1 in\n let mark = Array.make_matrix n m ~-1 in\n let cnt = Array.make upp 0 in\n let s = Array.make n \"a\" in\n for i = 0 to n - 1 do\n s.(i) <- xstr();\n done;\n let qx = Array.make (n * m) 0 in\n let qy = Array.make (n * m) 0 in\n let dx = Array.make 4 0 and dy = Array.make 4 0 in\n dx.(2) <- 1;\n dx.(3) <- ~-1;\n dy.(0) <- 1;\n dy.(1) <- ~-1;\n let idx = ref 0 in\n let bfs sx sy =\n let h = ref 0 and t = ref 1 in\n qx.(0) <- sx;\n qy.(0) <- sy;\n mark.(sx).(sy) <- !idx;\n while !h < !t do\n let x = qx.(!h) and y = qy.(!h) in\n h := !h + 1;\n for i = 0 to 3 do\n let xx = x + dx.(i) in\n let yy = y + dy.(i) in\n if xx >= 0 && xx < n && yy >= 0 && yy < m then (\n if s.(xx).[yy] = '.' && mark.(xx).(yy) = -1 then (\n mark.(xx).(yy) <- !idx;\n qx.(!t) <- xx;\n qy.(!t) <- yy;\n t := !t + 1;\n )\n )\n done;\n done;\n cnt.(!idx) <- !t;\n in\n\n let gao x y =\n let a = Array.make 4 ~-1 in\n for i = 0 to 3 do\n let xx = x + dx.(i) and yy = y + dy.(i) in\n if xx >= 0 && xx < n && yy >= 0 && yy < m then (\n a.(i) <- mark.(xx).(yy)\n )\n done;\n Array.sort (fun x y -> if x < y then -1 else (if x > y then 1 else 0)) a;\n let sum = ref 1 in\n for i = 0 to 3 do\n if a.(i) != ~-1 then (\n if i = 0 || a.(i) != a.(i - 1) then (\n sum := !sum + cnt.(a.(i))\n )\n )\n done;\n sum := !sum mod 10;\n Char.chr (48 + !sum)\n in\n\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n if s.(i).[j] = '.' && mark.(i).(j) = -1 then (\n bfs i j;\n idx := !idx + 1;\n );\n done;\n done;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n s.(i).[j] <- (if s.(i).[j] = '*' then (gao i j) else '.');\n done;\n Printf.printf \"%s\\n\" s.(i);\n done;\n"}], "negative_code": [{"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet (+|) = Int64.add;;\nlet (-|) = Int64.sub;;\nlet ( *| ) = Int64.mul;;\nlet ( /| ) = Int64.div;;\nlet two_64 = Int64.one +| Int64.one;;\n\nlet licz x = (x-|Int64.one)/|two_64;;\n\nlet (n,m) = read2 ();;\n\nlet ruch x y = [ (x+1,y); (x-1,y); (x,y+1); (x,y-1) ];;\n\nlet czy_dobry x y tab =\n if x < 0 || x >= n || y < 0 || y >= m then false\n else if tab.(x).(y) = '*' then false\n else true;;\n \n\nlet rec dfs x y k tab vis fuf size = \n if not (czy_dobry x y tab) || vis.(x).(y) then ()\n else begin\n vis.(x).(y) <- true;\n fuf.(x).(y) <- k;\n match k with\n | (a,b) -> size.(a).(b) <- size.(a).(b) + 1;\n List.iter ( fun (a,b) -> dfs a b k tab vis fuf size ) ( ruch x y ) end;;\n\nlet wynik x y tab fuf size =\n let ruchy = List.filter ( fun (x,y) -> czy_dobry x y tab ) (ruch x y) in\n List.fold_left (fun a (x,y) -> a + size.(x).(y)) 0\n (\n List.fold_left (fun a (x,y) -> if\n (List.fold_left (fun a b -> if b = fuf.(x).(y) then false else a ) true a )\n then fuf.(x).(y)::a else a ) [] ruchy\n );;\n \n\nlet _ = \n let tab = Array.make_matrix n m '.' \n and vis = Array.make_matrix n m false \n and fuf = Array.make_matrix n m (0,0)\n and size = Array.make_matrix n m 0 in\n for i=0 to (n-1) do\n let s = Scanf.scanf \"%s\\n\" (fun x -> x) in\n for j=0 to (m-1) do\n tab.(i).(j) <- s.[j];\n fuf.(i).(j) <- (i,j)\n done\n done;\n for i =0 to (n-1) do\n for j=0 to (m-1) do\n dfs i j (i,j) tab vis fuf size\n done\n done;\n for i=0 to (n-1) do\n for j=0 to (m-1) do\n if tab.(i).(j) = '.' then \n Printf.printf \".\"\n else Printf.printf \"%d\" ( wynik i j tab fuf size + 1)\n done;\n Printf.printf \"\\n\"\n done;;\n\n\n\n"}], "src_uid": "c91dd34bfa784f55ad3b661e06f84cfb"} {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\n\tlet dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done\nend open MyInt64\n\nlet repm from_ to_ ?(stride=1) m_init fbod =\n\tlet i,f,m = ref ~|from_,ref true,ref m_init in\n\twhile !i <= ~|to_ && !f do\n\t\tmatch fbod !m (~~| !i) with\n\t\t| `Break -> f := false\n\t\t| `Break_m m' -> (f := false; m := m')\n\t\t| `Ok m' -> (i := !i +$ 1; m := m')\n\tdone; !m\n\n\nlet () =\n\tlet n,m,k = get_3_i64 0 in\n\t(\n\t\t(* (0,0),(p,q),(r,s) -> 2S = |ps-qr| \u2208 Z *)\n\t\tif 2L*n*m mod k <> 0L then printf \"NO\\n\"\n\t\telse (\n\t\t\tprintf \"YES\\n0 0\\n\";\n\t\t\tlet x,y = (\n\t\t\t\tlet n,m,k = ref (2L*n),ref m,ref k in\n\t\t\t\twhile !k <> 1L do\n\t\t\t\t\tlet g = gcd !n !k in if g > 1L then (\n\t\t\t\t\t\tn := !n / g;\n\t\t\t\t\t\tk := !k / g);\n\t\t\t\t\tlet g = gcd !m !k in if g > 1L then (\n\t\t\t\t\t\tm := !m / g;\n\t\t\t\t\t\tk := !k / g)\n\t\t\t\tdone; (!n,!m)\n\t\t\t) in\n\t\t\tif x > n && x mod 2L = 0L && y * 2L <= m then (\n\t\t\t\tprintf \"%Ld 0\\n0 %Ld\\n\" (x/2L) (y*2L)\n\t\t\t) else printf \"%Ld 0\\n0 %Ld\\n\" x y\n\t\t)\n\t)", "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 (+$) = (+) 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 repm from_ to_ ?(stride=1) m_init fbod =\n\tlet i,f,m = ref ~|from_,ref true,ref m_init in\n\twhile !i <= ~|to_ && !f do\n\t\tmatch fbod !m (~~| !i) with\n\t\t| `Break -> f := false\n\t\t| `Break_m m' -> (f := false; m := m')\n\t\t| `Ok m' -> (i := !i +$ 1; m := m')\n\tdone; !m\n\n\nlet () =\n\tlet n,m,k = get_3_i64 0 in\n\t(\n\t\t(* (0,0),(p,q),(r,s) -> 2S = |ps-qr| Z *)\n\t\tif 2L*n*m mod k <> 0L then printf \"NO\\n\"\n\t\telse (\n\t\t\tprintf \"YES\\n0 0\\n\";\n\t\t\tlet x,y = (\n\t\t\t\tlet n,m,k = ref (2L*n),ref m,ref k in\n\t\t\t\twhile !k <> 1L do\n\t\t\t\t\tlet g = gcd !n !k in if g > 1L then (\n\t\t\t\t\t\tn := !n / g;\n\t\t\t\t\t\tk := !k / g);\n\t\t\t\t\tlet g = gcd !m !k in if g > 1L then (\n\t\t\t\t\t\tm := !m / g;\n\t\t\t\t\t\tk := !k / g)\n\t\t\t\tdone; (!n,!m)\n\t\t\t) in\n\t\t\tif x > n && x mod 2L = 0L && y * 2L <= m then (\n\t\t\t\tprintf \"%Ld 0\\n0 %Ld\\n\" (x/2L) (y*2L)\n\t\t\t) else printf \"%Ld 0\\n0 %Ld\\n\" x y\n\t\t)\n\t)"}], "negative_code": [], "src_uid": "5c026adda2ae3d7b707d5054bd84db3f"} {"source_code": "open Scanf open Array\nlet (++) = Int64.add\nlet () = scanf \" %d %d %d\" @@ fun n k x ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n let undef = -1L in\n let dp = init (n+1) (fun _ -> make_matrix (x+1) (k+1) undef) in\n dp.(0).(x-1).(k) <- a.(0);\n dp.(0).(x).(k-1) <- 0L;\n let upd i j p v =\n dp.(i).(j).(p) <- max dp.(i).(j).(p) v\n in\n for i=0 to n-2 do\n for j=1 to x do\n for p=1 to k do\n if dp.(i).(j).(p) <> undef then (\n upd (i+1) (j-1) k @@\n dp.(i).(j).(p) ++ a.(i+1);\n upd (i+1) j (p-1) @@\n dp.(i).(j).(p))\n done\n done\n done;\n let mx = ref @@ -1L in\n for i=n-k to n do\n for p=0 to k do\n mx := max !mx dp.(i).(0).(p)\n done\n done;\n Printf.printf \"%Ld\\n\" !mx", "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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let dp = make_matrix (i32 n+$1) (i32 x+$1) @@ undef in\n let update i j v =\n try\n dp.(i).(j) <- max (dp.(i).(j)) v\n with Invalid_argument _ -> ()\n in\n repi 0 (i32 k-$1) (fun k ->\n dp.(k).(i32 x) <- 0L\n );\n repi 0 (i32 n-$1) (fun i ->\n repi 1 (i32 x) (fun j ->\n if dp.(i).(j) <> undef then\n repi 1 (i32 k) (fun k ->\n update (i+$k) (j-$1) @@ dp.(i).(j) + a.(i)\n )\n )\n );\n (* dump_2darr (sprintf \"%4Ld\") dp; *)\n (* let res = ref undef in\n repi 0 (i32 k-$1) (fun k ->\n res := max !res dp.(i32 n-$k).(0)\n );\n if dp.(i32 n).(0) = undef then res := undef;\n if !res = undef then printf \"-1\\n\"\n else printf \"%Ld\\n\" !res *)\n printf \"%Ld\\n\" @@ let res = dp.(i32 n).(0) in if res = undef then -1L else res\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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let n,k,x = i32 n,i32 k,i32 x in\n let dp = make_matrix (n+$1) (x+$1) @@ undef in\n dp.(0).(x) <- 0L;\n repi 1 n (fun i ->\n repi 0 (x-$1) (fun j ->\n repi 1 k (fun k ->\n try\n let v = dp.(i-$k).(j+$1) in\n if v <> undef then\n dp.(i).(j) <- max dp.(i).(j) (v+a.(i-$1))\n with Invalid_argument _ -> ()\n )\n )\n );\n (* dump_2darr (sprintf \"%3Ld\") dp; *)\n let res = ref undef in\n repi (n-$k+$1) n (fun i ->\n res := max !res @@ dp.(i).(0)\n );\n printf \"%Ld\\n\" @@ let v = !res in if v = undef then -1L else v\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\n\nlet () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let dp = make_matrix (i32 n+$1) (i32 x+$1) @@ undef in\n let update i j v =\n try\n dp.(i).(j) <- max (dp.(i).(j)) v\n with Invalid_argument _ -> ()\n in\n repi 0 (i32 k-$1) (fun k ->\n dp.(k).(i32 x) <- 0L\n );\n repi 0 (i32 n-$1) (fun i ->\n repi_rev (i32 x) 1 (fun j ->\n repi 1 (i32 k) (fun k ->\n if dp.(i).(j) <> undef then\n update (i+$k) (j-$1) @@ dp.(i).(j) + a.(i)\n )\n )\n );\n (* dump_2darr (sprintf \"%3Ld\") dp; *)\n let res = ref undef in\n repi 0 (i32 k-$1) (fun k ->\n res := max !res dp.(i32 n-$k).(0)\n );\n if !res = undef then printf \"-1\\n\"\n else printf \"%Ld\\n\" !res\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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let dp = make_matrix (i32 n+$1) (i32 x+$1) @@ undef in\n let update i j v =\n try\n dp.(i).(j) <- max (dp.(i).(j)) v\n with Invalid_argument _ -> ()\n in\n repi 0 (i32 k-$1) (fun k ->\n dp.(k).(i32 x) <- 0L\n );\n repi 0 (i32 n-$1) (fun i ->\n repi 1 (i32 x) (fun j ->\n if dp.(i).(j) <> undef then\n repi 1 (i32 k) (fun k ->\n update (i+$k) (j-$1) @@ dp.(i).(j) + a.(i)\n )\n )\n );\n (* dump_2darr (sprintf \"%10Ld\") dp; *)\n let res = ref undef in\n repi 0 (i32 k-$1) (fun k ->\n res := max !res dp.(i32 n-$k).(0)\n );\n if dp.(i32 n).(0) = undef then res := undef;\n if !res = undef then printf \"-1\\n\"\n else printf \"%Ld\\n\" !res\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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let n,k,x = i32 n,i32 k,i32 x in\n let dp = make_matrix (n+$1) (x+$1) @@ undef in\n repi 0 (k-$1) (fun i ->\n dp.(i).(x) <- 0L\n );\n repi 1 n (fun i ->\n repi 0 (x-$1) (fun j ->\n repi 1 k (fun k ->\n try\n let v = dp.(i-$k).(j+$1) in\n if v <> undef then\n dp.(i).(j) <- max dp.(i).(j) (v+a.(i-$1))\n with Invalid_argument _ -> ()\n )\n )\n );\n (* dump_2darr (sprintf \"%3Ld\") dp; *)\n let res = ref undef in\n repi (n-$k+$1) n (fun i ->\n res := max !res @@ dp.(i).(0)\n );\n printf \"%Ld\\n\" @@ let v = !res in if v = undef then -1L else v\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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let dp = make_matrix (i32 n+$1) (i32 x+$1) @@ undef in\n let update i j v =\n try\n dp.(i).(j) <- max (dp.(i).(j)) v\n with Invalid_argument _ -> ()\n in\n repi 0 (i32 k-$1) (fun k ->\n dp.(k).(i32 x) <- 0L\n );\n repi 0 (i32 n-$1) (fun i ->\n repi 1 (i32 x) (fun j ->\n if dp.(i).(j) <> undef then\n repi 1 (i32 k) (fun k ->\n update (i+$k) (j-$1) @@ dp.(i).(j) + a.(i)\n )\n )\n );\n (* dump_2darr (sprintf \"%10Ld\") dp; *)\n let res = ref undef in\n repib 0 (i32 k-$1) (fun k ->\n let v = dp.(i32 n-$k).(0) in\n if v = undef then (res := undef; `Break)\n else (res := max !res dp.(i32 n-$k).(0); `Ok)\n );\n if !res = undef then printf \"-1\\n\"\n else printf \"%Ld\\n\" !res\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 () =\n let n,k,x = get_3_i64 0 in\n let a = input_i64_array n in\n let undef = -7L in\n let dp = make_matrix (i32 n+$1) (i32 x+$1) @@ undef in\n let update i j v =\n try\n dp.(i).(j) <- max (dp.(i).(j)) v\n with Invalid_argument _ -> ()\n in\n repi 0 (i32 k-$1) (fun k ->\n dp.(k).(i32 x) <- 0L\n );\n repi 0 (i32 n-$1) (fun i ->\n repi 1 (i32 x) (fun j ->\n if dp.(i).(j) <> undef then\n repi 1 (i32 k) (fun k ->\n update (i+$k) (j-$1) @@ dp.(i).(j) + a.(i)\n )\n )\n );\n dump_2darr (sprintf \"%10Ld\") dp;\n let res = ref undef in\n repi 0 (i32 k-$1) (fun k ->\n res := max !res dp.(i32 n-$k).(0)\n );\n if dp.(i32 n).(0) = undef then res := undef;\n if !res = undef then printf \"-1\\n\"\n else printf \"%Ld\\n\" !res\n\n\n\n\n\n\n\n\n"}], "src_uid": "c1d48f546f79b0fd58539a1eb32917dd"} {"source_code": "let n = int_of_string (input_line stdin) ;;\n\nlet a = Array.make n 0 ;;\n\nlet rec aux i =\n Scanf.scanf \"%d \" (fun v -> Array.set a i v); aux (i + 1)\nin try aux 0 with _ -> () ;;\n\nArray.sort compare a ;;\n\nPrintf.printf \"%d\\n\" (Array.get a ((n - 1) / 2)) ;;", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n read_int in\n\n Array.sort compare a;\n\n let k = (n-1)/2 in\n\n printf \"%d\\n\" a.(k)\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n read_int in\n\n Array.sort compare a;\n\n let k = n/2 in\n\n printf \"%d\\n\" a.(k)\n"}], "src_uid": "f93a8bd64a405233342f84542fce314d"} {"source_code": "(* Beautiful Mirrors\n * https://codeforces.com/problemset/problem/1265/E *)\n\nopen Printf\nopen Scanf\n\nlet ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( ** ) = Int64.mul\nlet ( // ) = Int64.div\n\nlet ( %% ) a b = a -- (b ** (a//b))\n\n\nlet md = 998244353L\n\nlet ( *% ) a b = (a ** b) %% md\n\nlet pw a b =\n let a = a %% md in\n let rec iter acc a b =\n if b = 0L then\n acc\n else\n let a' = (a *% a) in\n let b' = b // 2L in\n if Int64.logand b 1L = 1L then\n iter (acc *% a) a' b'\n else\n iter acc a' b' in\n iter 1L a b\n\nlet inv a = pw a (md -- 2L)\n\nlet () =\n let _ = read_int () in\n let i100 = inv 100L in\n let pl = read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map Int64.of_string \n |> List.map (fun p -> p *% i100) in\n let (a, b) = List.fold_right\n (fun p (a, b) -> (p *% a ++ 1L, p *% (b -- 1L) ++ 1L))\n pl (0L, 0L) in\n printf \"%Ld\\n\" (a *% (inv (md ++ 1L -- b)))\n\n\n", "positive_code": [{"source_code": "(* Beautiful Mirrors\n * https://codeforces.com/problemset/problem/1265/E *)\n\nopen Printf\nopen Scanf\n\nlet ( ++ ) = Int64.add\nlet ( -- ) = Int64.sub\nlet ( ** ) = Int64.mul\nlet ( // ) = Int64.div\n\nlet ( %% ) a b = a -- (b ** (a//b))\n\n\nlet md = 998244353L\n\nlet ( *% ) a b = (a ** b) %% md\n\nlet pw a b =\n let a = a %% md in\n let rec iter acc a b =\n if b = 0L then\n acc\n else\n let a' = (a *% a) in\n let b' = b // 2L in\n if Int64.logand b 1L = 1L then\n iter (acc *% a) a' b'\n else\n iter acc a' b' in\n iter 1L a b\n\nlet inv a = pw a (md -- 2L)\n\nlet () =\n let _ = read_int () in\n let pl = read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map Int64.of_string \n |> List.map (fun p -> p *% (inv 100L)) in\n let (a, b) = List.fold_right\n (fun p (a, b) -> (p *% a ++ 1L, p *% (b -- 1L) ++ 1L))\n pl (0L, 0L) in\n printf \"%Ld\\n\" (a *% (inv (md ++ 1L -- b)))\n\n\n"}], "negative_code": [], "src_uid": "43d877e3e1c1fd8ee05dc5e5e3067f93"} {"source_code": "let l = ref []\n\nlet () = \n for i=1 to (read_int ()) do\n l := (Scanf.scanf \" %d %d\\n%d:%d\" (fun x y w z -> x,y,w,z))::!l\n done\n\nlet getReflection n = \n match n with \n | 0 | 1 | 8 -> n\n | 2 -> 5\n | 5 -> 2\n | _ -> -1\n\nlet checkReflection lh lm h m = \n let hd = getReflection (m mod 10)*10 in\n let hu = getReflection (m / 10) in\n let md = getReflection (h mod 10)*10 in\n let mu = getReflection (h / 10) in\n let hr,mr = ((if ((hd <> -1) && (hu <> -1)) then (hd+hu) else -1), (if (md <> -1) && (mu <> -1) then (md+mu) else -1)) in\n if (hr < lh) && (mr < lm) && (hr >= 0) && (mr >= 0)\n then (hr,mr)\n else (-1,-1)\n\nlet checkNextValidReflection lh lm h m = \n let hr,mr = (ref h, ref m) in\n let h,m = (ref h, ref m) in\n let () = \n while (let haux,maux = checkReflection lh lm !h !m in let () = hr := haux in let () = mr := maux in ((!hr = (-1)) && (!mr = (-1)))) do\n if !m < (lm-1)\n then m := !m +1\n else if !h < (lh-1)\n then (h := !h +1; m := 0)\n else (h := 0; m := 0)\n done in\n if !h < 10 \n then (Printf.printf \"0%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n else (Printf.printf \"%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n\n\n\nlet rec testAll l = \n match l with\n | (lh,lm,h,m)::t -> (testAll t; checkNextValidReflection lh lm h m)\n | [] -> ()\n\nlet () = testAll !l", "positive_code": [{"source_code": "(* https://codeforces.com/contest/1493/problem/B *)\n\nlet reverse_digit n =\n match n with\n | 0 -> Some 0\n | 1 -> Some 1\n | 2 -> Some 5\n | 5 -> Some 2\n | 8 -> Some 8\n | 3 | 4 | 6 | 7 | 9 -> None\n\nlet reverse_time_opt [hh; mm] =\n let rec helper_opt e acc =\n match e with\n | [] -> Some acc\n | h::t ->\n match reverse_digit h with\n | Some h2 -> helper_opt t (h2::acc)\n | None -> None in\n let rev_minuts = helper_opt mm [] and\n rev_hours = helper_opt hh [] in\n match rev_minuts, rev_hours with\n | Some m, Some h -> Some [m; h]\n | _ -> None\n\nlet listify time =\n let rec helper i acc num =\n if i = 2\n then acc\n else helper (i+1) ((num mod 10)::acc) (num/10) in\n List.map (helper 0 []) time\n\nlet numberify =\n List.fold_left (fun acc e -> acc * 10 + e) 0\n\nlet add_minut h m =\n let inner_add [hh; mm] =\n let minuts = numberify mm and\n hours = numberify hh in\n if minuts + 1 = m\n then (\n let minuts2 = 0 in\n if hours + 1 = h\n then \n let hours2 = 0 in\n listify [hours2; minuts2]\n else listify [hours+1; minuts2]\n )\n else\n listify [hours; minuts+1] in\n inner_add\n\nlet correct_time h m =\n let inner_correct t =\n match t with\n | None -> false\n | Some [hh; mm] -> \n numberify hh < h && numberify mm < m in\n inner_correct\n\nlet next_time_rev h m time =\n let verify_t = correct_time h m and\n add_m = add_minut h m in\n let rec helper i t =\n if verify_t (reverse_time_opt t)\n then t\n else helper (i+1) (add_m t) in\n helper 0 time\n\nlet print_time [hh; mm] =\n List.iter (Printf.printf \"%d\") hh;\n Printf.printf \":\";\n List.iter (Printf.printf \"%d\") mm\n\nlet input_case () =\n let h::m::_ = \n read_line () \n |> Str.split (Str.regexp \" \") |> List.map int_of_string and\n t = \n read_line () \n |> Str.split (Str.regexp \":\") |> List.map int_of_string |> listify in\n (h, m, t)\n\nlet () =\n let cases = read_int () in\n for i = 1 to cases do\n let (h, m, t) = input_case () in\n next_time_rev h m t\n |> print_time;\n print_newline ()\n done\n"}], "negative_code": [{"source_code": "let l = ref []\n\nlet () = \n for i=1 to (read_int ()) do\n l := (Scanf.scanf \" %d %d\\n%d:%d\" (fun x y w z -> x,y,w,z))::!l\n done\n\nlet getReflection n = \n match n with \n | 0 | 1 | 8 -> n\n | 2 -> 5\n | 5 -> 2\n | _ -> -1\n\nlet checkReflection lh lm h m = \n let hr,mr = (((getReflection (m mod 10)*10) + (getReflection (m / 10))), ((getReflection (h mod 10)*10) + (getReflection (h / 10)))) in\n if (hr < lh) && (mr < lm) && (hr >= 0) && (mr >= 0)\n then (hr,mr)\n else (-1,-1)\n\nlet checkNextValidReflection lh lm h m = \n let hr,mr = (ref h, ref m) in\n let h,m = (ref h, ref m) in\n let () = \n while (let haux,maux = checkReflection lh lm !h !m in let () = hr := haux in let () = mr := maux in ((!hr = (-1)) && (!mr = (-1)))) do\n if !m < (lm-1)\n then m := !m +1\n else if !h < (lh-1)\n then (h := !h +1; m := 0)\n else (h := 0; m := 0)\n done in\n if !h < 10 \n then (Printf.printf \"0%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n else (Printf.printf \"%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n\n\n\nlet rec testAll l = \n match l with\n | (lh,lm,h,m)::t -> (testAll t; checkNextValidReflection lh lm h m)\n | [] -> ()\n\nlet () = testAll !l"}, {"source_code": "let l = ref []\n\nlet () = \n for i=1 to (read_int ()) do\n l := (Scanf.scanf \" %d %d\\n%d:%d\" (fun x y w z -> x,y,w,z))::!l\n done\n\nlet getReflection n = \n match n with \n | 0 | 1 | 8 -> n\n | 2 -> 5\n | 5 -> 2\n | _ -> -1\n\nlet checkReflection lh lm h m = \n let hr,mr = (((getReflection (m mod 10)*10) + (getReflection (m / 10))), ((getReflection (h mod 10)*10) + (getReflection (h / 10)))) in\n if (hr < lh) && (mr < lm) && (hr >= 0) && (mr >= 0)\n then (hr,mr)\n else (-1,-1)\n\nlet checkNextValidReflection lh lm h m = \n let hr,mr = (ref h, ref m) in\n let h,m = (ref h, ref m) in\n let () = \n while (let haux,maux = checkReflection lh lm !h !m in let () = hr := haux in let () = mr := maux in ((!hr = (-1)) && (!mr = (-1)))) do\n if !h >= (lh-1) then h:=0 else h := !h+1;\n if !m >= (lm-1) then m:=0 else m := !m+1;\n done in\n if !h < 10 \n then (Printf.printf \"0%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n else (Printf.printf \"%d:\" !h; if !m < 10 then Printf.printf \"0%d\\n\" !m else Printf.printf \"%d\\n\" !m)\n\n\n\nlet rec testAll l = \n match l with\n | (lh,lm,h,m)::t -> (testAll t; checkNextValidReflection lh lm h m)\n | [] -> ()\n\nlet () = testAll !l"}], "src_uid": "7f28e4dbd199b84bd7885bf7f479cf38"} {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n (*let s = 1000003 in\n let ht = Array.make s 0 in*)\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n (*let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in*)\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet key = (xi, yi) in\n\t(*let key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1*)\n\t try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false*)\n\t\t if Hashtbl.mem ht key\n\t\t then remove := false\n\t ) else (\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false*)\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif n < 100 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (dup, di, dj) =\n let dup = ref false in\n let di = ref 0 in\n let dj = ref 0 in\n let ht = Hashtbl.create n in\n for i = 0 to n - 1 do\n\tif Hashtbl.mem ht a.(i) then (\n\t dup := true;\n\t di := i;\n\t dj := Hashtbl.find ht a.(i)\n\t);\n\tHashtbl.replace ht a.(i) i\n done;\n (!dup, !di, !dj)\n in\n let (_, i, j) =\n if dup\n then (0.0, di, dj)\n else cp2d a\n in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n", "positive_code": [{"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 1000003 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n (*let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in*)\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet key = (xi, yi) in\n\t(*let key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1*)\n\t try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false*)\n\t\t if Hashtbl.mem ht key\n\t\t then remove := false\n\t ) else (\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false*)\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif n < 100 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (dup, di, dj) =\n let dup = ref false in\n let di = ref 0 in\n let dj = ref 0 in\n let ht = Hashtbl.create n in\n for i = 0 to n - 1 do\n\tif Hashtbl.mem ht a.(i) then (\n\t dup := true;\n\t di := i;\n\t dj := Hashtbl.find ht a.(i)\n\t);\n\tHashtbl.replace ht a.(i) i\n done;\n (!dup, !di, !dj)\n in\n let (_, i, j) =\n if dup\n then (0.0, di, dj)\n else cp2d a\n in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}], "negative_code": [{"source_code": "let _ =\nPrintf.printf \"test\\n%!\""}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let ht = Array.make 1000003 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n (*let ht = Hashtbl.create n in*)\n let () =\n for i = 0 to 1000003 - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod 1000003 in\n\tif r < 0\n\tthen r + 1000003\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t(*let key = (xi, yi) in*)\n\tlet key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1\n\t (*try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1*)\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false\n\t\t (*if Hashtbl.mem ht key\n\t\t then remove := false*)\n\t ) else (\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false\n\t\t(*let key = xi * 20000 + yi in\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false*)\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let rec estimate ps =\n let n = Array.length ps in\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t try\n\t let c = Hashtbl.find ht (xi, yi) in\n\t Hashtbl.replace ht (xi, yi) (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht (xi, yi) 1\n done\n in\n let rs = ref [] in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t if Hashtbl.mem ht (xi, yi)\n\t\t then remove := false\n\t ) else (\n\t\tlet c = Hashtbl.find ht (xi, yi) in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove\n\t then rs := ps.(i) :: !rs\n done;\n if !rs = []\n then d\n else estimate (Array.of_list !rs)\n in\n let n = Array.length ps in\n let b = estimate ps in\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tHashtbl.add ht (xi, yi) i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t let rs = Hashtbl.find_all ht (xi, yi) in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let sb = Scanf.Scanning.from_file \"input.txt\" in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) =\n if n < 100000 then\n cp2d a\n else (0.0, 0, 0)\n in\n let fd = open_out \"output.txt\" in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 1000003 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n (*let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in*)\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet key = (xi, yi) in\n\t(*let key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1*)\n\t try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false*)\n\t\t if Hashtbl.mem ht key\n\t\t then remove := false\n\t ) else (\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false*)\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif n < 100000 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 1000003 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n (*let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in*)\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet key = (xi, yi) in\n\t(*let key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1*)\n\t try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false*)\n\t\t if Hashtbl.mem ht key\n\t\t then remove := false\n\t ) else (\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false*)\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m);\nif n < 100 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let ht = Array.make 1000003 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n (*let ht = Hashtbl.create n in*)\n let () =\n for i = 0 to 1000003 - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod 1000003 in\n\tif r < 0\n\tthen r + 1000003\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t(*let key = (xi, yi) in*)\n\tlet key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1\n\t (*try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1*)\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false\n\t\t (*if Hashtbl.mem ht key\n\t\t then remove := false*)\n\t ) else (\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false\n\t\t(*let key = xi * 20000 + yi in\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false*)\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 4000037 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n (*let ht = Hashtbl.create n in*)\n let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t(*let key = (xi, yi) in*)\n\tlet key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1\n\t (*try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1*)\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false\n\t\t (*if Hashtbl.mem ht key\n\t\t then remove := false*)\n\t ) else (\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false\n\t\t(*let key = xi * 20000 + yi in\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false*)\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 4000037 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n (*let ht = Hashtbl.create n in*)\n let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t(*let key = (xi, yi) in*)\n\tlet key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1\n\t (*try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1*)\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false\n\t\t (*if Hashtbl.mem ht key\n\t\t then remove := false*)\n\t ) else (\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false\n\t\t(*let key = xi * 20000 + yi in\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false*)\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif n < 100000 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let ht = Array.make 1000003 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n (*let ht = Hashtbl.create n in*)\n let () =\n for i = 0 to 1000003 - 1 do\n\tht.(i) <- 0\n done\n in\n let hf x y =\n let r = (x * 20000 + y) mod 1000003 in\n\tif r < 0\n\tthen r + 1000003\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\t(*let key = (xi, yi) in*)\n\tlet key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1\n\t (*try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1*)\n done\n in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false\n\t\t (*if Hashtbl.mem ht key\n\t\t then remove := false*)\n\t ) else (\n\t\t(*let key = (xi, yi) in*)\n\t\tlet key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false\n\t\t(*let key = xi * 20000 + yi in\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false*)\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}, {"source_code": "let cp2d ps =\n let sqr x = x *. x in\n let dist (x1, y1) (x2, y2) =\n sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))\n in\n let s = 1000003 in\n let ht = Array.make s 0 in\n let rec estimate ps n rs =\n let idx = Random.int n in\n let d = ref infinity in\n let () =\n for i = 0 to n - 1 do\n\tif i <> idx\n\tthen d := min !d (dist ps.(idx) ps.(i))\n done\n in\n let d = !d in\n let b = d /. 3.0 in\n let ht = Hashtbl.create n in\n (*let () =\n for i = 0 to s - 1 do\n\tht.(i) <- 0\n done\n in*)\n let hf x y =\n let r = (x * 20000 + y) mod s in\n\tif r < 0\n\tthen r + s\n\telse r\n in\n let () =\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet key = (xi, yi) in\n\t(*let key = hf xi yi in\n\t ht.(key) <- ht.(key) + 1*)\n\t try\n\t let c = Hashtbl.find ht key in\n\t Hashtbl.replace ht key (c + 1)\n\t with\n\t | Not_found ->\n\t\tHashtbl.replace ht key 1\n done\n in\n let m = ref 0 in\n for i = 0 to n - 1 do\n\tlet (x, y) = ps.(i) in\n\tlet xi = int_of_float (x /. b) in\n\tlet yi = int_of_float (y /. b) in\n\tlet remove = ref true in\n\t for xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t if not (xd = 0 && yd = 0) then (\n\t\tlet xi = xi + xd in\n\t\tlet yi = yi + yd in\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) > 0\n\t\t then remove := false*)\n\t\t if Hashtbl.mem ht key\n\t\t then remove := false\n\t ) else (\n\t\tlet key = (xi, yi) in\n\t\t(*let key = hf xi yi in\n\t\t if ht.(key) <> 1\n\t\t then remove := false*)\n\t\tlet c = Hashtbl.find ht key in\n\t\t if c <> 1\n\t\t then remove := false\n\t )\n\t done\n\t done;\n\t if not !remove then (\n\t rs.(!m) <- ps.(i);\n\t incr m\n\t )\n done;\n(*if n = 100000 then*)\nif n < 100 && Array.length ps = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f %d\\n%!\" b !m; exit 0);\n if !m = 0\n then d\n else estimate rs !m ps\n in\n let n = Array.length ps in\n let b = estimate (Array.copy ps) n (Array.copy ps) in\nif n = 100000 then\n(Printf.fprintf (open_out \"output.txt\") \"est %f\\n%!\" b; exit 0);\n let ht = Hashtbl.create n in\n let () =\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n (*let key = (xi, yi) in*)\n let key = xi * 20000 + yi in\n\tHashtbl.add ht key i\n done\n in\n let d = ref infinity in\n let di = ref (-1) in\n let dj = ref (-1) in\n for i = 0 to n - 1 do\n let (x, y) = ps.(i) in\n let xi = int_of_float (x /. b) in\n let yi = int_of_float (y /. b) in\n\tfor xd = -1 to 1 do\n\t for yd = -1 to 1 do\n\t let xi = xi + xd in\n\t let yi = yi + yd in\n\t (*let key = (xi, yi) in*)\n\t let key = xi * 20000 + yi in\n\t let rs = Hashtbl.find_all ht key in\n\t List.iter\n\t\t(fun j ->\n\t\t if i <> j then (\n\t\t let dd = dist ps.(i) ps.(j) in\n\t\t if dd < !d then (\n\t\t\t d := dd;\n\t\t\t di := i;\n\t\t\t dj := j;\n\t\t )\n\t\t )\n\t\t) rs\n\t done\n\tdone;\n done;\n (!d, !di, !dj)\n\nlet debug = not true\n\nlet _ =\n Random.init 666666;\n let sb =\n if debug\n then Scanf.Scanning.stdib\n else Scanf.Scanning.from_file \"input.txt\"\n in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n (0.0, 0.0) in\n let b = Array.make n 0 in\n let () =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let (x, y, r) =\n\tif x < 0 && y < 0\n\tthen (-x, -y, 4)\n\telse if x < 0\n\tthen (-x, y, 2)\n\telse if y < 0\n\tthen (x, -y, 3)\n\telse (x, y, 1)\n in\n\ta.(i) <- (float_of_int x, float_of_int y);\n\tb.(i) <- r\n done;\n in\n let rot r =\n match r with\n | 1 -> 4\n | 2 -> 3\n | 3 -> 2\n | 4 -> 1\n | _ -> assert false\n in\n let (_, i, j) = cp2d a in\n let fd =\n if debug\n then stdout\n else open_out \"output.txt\"\n in\n Printf.fprintf fd \"%d %d %d %d\\n\" (i + 1) b.(i) (j + 1) (rot b.(j))\n"}], "src_uid": "41bc5d7e091a92af7160056ca6030588"} {"source_code": "let rec is_pow powered n =\n\t(n = powered) || ((powered mod n = 0) && (is_pow (powered / n) n));;\n\n\nlet f n l =\n\tlet tab = Array.make (n+1) true and compt = ref 0 in\n\t\ttab.(0) <- false;\n\t\ttab.(1) <- false;\n\t\tfor i = 2 to n do\n\t\t\tif tab.(i)\n\t\t\t\tthen \t(incr compt;\n\t\t\t\t\tl := i:: !l;\n\t\t\t\t\tfor j = 2 to (n/i) do\n\t\t\t\t\t\ttab.(i*j) <- false;\n\t\t\t\t\t\tif is_pow (i*j) i\n\t\t\t\t\t\t\tthen (l := (i*j):: !l; incr compt);\n\t\t\t\t\tdone);\n\t\tdone;\n\t\t!compt;;\n\nlet main () =\n\tlet l = ref [] in\n\t\tScanf.scanf \"%d\" (fun i -> Printf.printf \"%d\\n\" (f i l));\n\t\tList.iter (Printf.printf \"%d \") !l;;\n\nmain ();;\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\n\nlet is_prime n =\n let rec go d =\n if d * d > n then true else\n if n mod d = 0 then false else\n go (d+1)\n in\n go 2\n\nlet rec gen_primes n ans =\n if n <= 1 then ans else\n if is_prime n then gen_primes (n-1) (n::ans) else\n gen_primes (n-1) ans\n \nlet () =\n let n = read_int () in\n let rec f p a b = if b > n then a else (f p (b::a) (b*p)) in\n let g a p = f p a p in\n let ans = List.fold_left g [] (gen_primes n []) in\n Printf.printf \"%d\\n\" (List.length ans);\n List.iter (Printf.printf \"%d \") ans;;\n\n"}], "negative_code": [], "src_uid": "7f61b1d0e8294db74d33a6b6696989ad"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\n\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x);;\n\n(*let read_pair () = let a = read_int () in (a , read_int ());;*)\n\nlet read_pair () = Scanf.scanf \" %d %d \" (fun x y -> x , y );;\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\nlet n , t = read_pair ();;\n\nlet data = Array.init (n+1) (fun i -> if i = 0 then Int64.of_int 0 else read_long ());;\n\nlet sum = Array.init 100005 (fun i -> Int64.of_int 0);;\n\nfor i = 1 to n do\n sum.(i) <- sum.(i-1) ++ data.(i)\ndone;;\n\nlet left , right = ( ref 1 , ref n );;\n\nlet binary_search len = \n let isok = ref false in \n for i = 0 to n-len do \n isok := !isok || (sum.(i+len) -- sum.(i) <= Int64.of_int t)\n done;\n !isok;;\n\nwhile !left <= !right do\n let mid = (!left + !right)/2 in \n if binary_search mid then left := mid + 1\n else right := mid - 1\ndone;;\n\nPrintf.printf \"%d\\n\" !right;;\n\n", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int 0 in\n let t = read_int 0 in\n let a = Array.init n read_int in\n\n(*\n let () = for i=1 to n-1 do\n a.(i) <- a.(i-1) + a.(i)\n done in\n (* so now a.(i) = the time needed to read books a.(0)...a.(i) *)\n (* so to read books i to j requires time a.(j) - a.(i-1) *)\n*)\n\n let rec loop i j sum ac = if j=n-1 then ac else\n (* sum = total time of the books from i to j inclusive *)\n (* ac is the biggest number of book found so far that I can read *)\n if sum + a.(j+1) > t \n then loop (i+1) j (sum - a.(i)) ac\n else loop i (j+1) (sum + a.(j+1)) (max ac ((j+1)-i+1))\n in\n\n let answer = loop 0 0 a.(0) (if a.(0) > t then 0 else 1) in\n Printf.printf \"%d\\n\" answer\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\n\nlet read_pair () = Scanf.scanf \" %d %d \" (fun x y -> x , y );;\n\nlet n , t = read_pair ();;\n\nlet data = Array.init (n+1) (fun i -> if i = 0 then 0 else read_int ());;\n\nlet sum = Array.init 100005 (fun i -> 0);;\n\nfor i = 1 to n do\n sum.(i) <- sum.(i-1) + data.(i)\ndone;;\n\nlet left , right = ( ref 1 , ref n );;\n\nlet binary_search len = \n let isok = ref false in \n for i = 0 to n-len do \n isok := !isok || (sum.(i+len) - sum.(i) <= t)\n done;\n !isok;;\n\nwhile !left <= !right do\n let mid = (!left + !right)/2 in \n if binary_search mid then left := mid + 1\n else right := mid - 1\ndone;;\n\nPrintf.printf \"%d\\n\" !right;;\n\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\n\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x);;\n\n(*let read_pair () = let a = read_int () in (a , read_int ());;*)\n\nlet read_pair () = Scanf.scanf \" %d %d \" (fun x y -> x , y );;\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\nlet n , t = read_pair ();;\n\nlet data = Array.init (n+1) (fun i -> if i = 0 then Int64.of_int 0 else read_long ());;\n\nlet sum = Array.init 100005 (fun i -> Int64.of_int 0);;\n\nfor i = 1 to n-1 do\n sum.(i) <- sum.(i-1) ++ data.(i)\ndone;;\n\nlet left , right = ( ref 1 , ref n );;\n\nlet binary_search len = \n let isok = ref true in \n for i = 0 to n-len do \n isok := !isok || (sum.(i+len) -- sum.(i) <= Int64.of_int t)\n done;\n !isok;;\n\nwhile !left <= !right do\n let mid = (!left + !right)/2 in \n if binary_search mid then left := mid + 1\n else right := mid - 1\ndone;;\n\nPrintf.printf \"%d\\n\" !right;;\n\n"}], "src_uid": "ef32a8f37968629673547db574261a9d"} {"source_code": "let () = Scanf.scanf \"%f\\n%f\\n%f\" (fun l p q ->\n Printf.printf \"%f\\n\" (l /. (q /. p +. 1.)))\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet () = \n let l = float_of_int (read_int ()) in\n let p = float_of_int (read_int ()) in\n let q = float_of_int (read_int ()) in\n let res = p *. (l /. (p +. q)) in\n printf \"%f\\n%!\" res\n\n \n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_float () = bscanf Scanning.stdib \" %f \" (fun x -> x)\n\nlet () = \n let l = read_float () in\n let p = read_float () in\n let q = read_float () in\n\n let answer = (p *. l) /. (p +. q) in\n\n printf \"%.5f\\n\" answer\n \n"}], "negative_code": [], "src_uid": "6421a81f85a53a0c8c63fbc32750f77f"} {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\nlet () = \n let add, get, iter =\n let n = read_int () in\n let mk v = Array.make (n + 1) v in\n let p, mcc, mcf, cc = mk ~-1, mk ~-1, mk false, mk 1 in\n let set i c inc =\n let set a v = Array.set a i v in\n let r = cc.(i) in\n if inc then (set mcc c; set mcf false; set cc c)\n else (set mcf true; set cc (succ c));\n r < cc.(i)\n in\n let rec update i =\n let pi, c = p.(i), cc.(i) in\n let set = set pi c in\n let sgn a = if a = 0 then 0 else a / abs a in \n if (match pi, lazy (sgn (c - mcc.(pi)), mcf.(pi)) with\n | -1, _ -> false\n | _, lazy (1, _) -> set true\n | _, lazy (0, false) -> set false\n | _ -> false)\n then update pi\n in\n let k = ref 0 in\n (fun i -> incr k; p.(!k) <- i - 1; update !k), \n (fun () -> mcc.(0)),\n fun f -> for i = 1 to n do f (i < n) done \n in \n iter @@ fun s ->\n Scanf.scanf \" %d\" add;\n print_int (get ());\n print_char (if s then ' ' else '\\n')\n", "positive_code": [{"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\n\nlet (%) f g x = f (g x)\nlet (%>) f g x = g (f x)\n\nmodule Max : sig\n type t\n val mk : int -> t\n val cmp : int -> t -> [`Lt | `Gt | `Eq]\n val int : t -> int\nend = struct\n type t = int\n let mk v = v\n let cmp a =\n function\n | b when a < b -> `Lt\n | b when a = b -> `Eq\n | _ -> `Gt\n let int m = m \nend\n\n\ntype vertex = \n { mutable s : Max.t * bool * int;\n p : vertex option }\n\n\nlet () =\n let vertex p = { s = Max.mk ~-1, false, 1; p } in \n let vertex p = \n let rec update =\n function\n | { p = None } -> () \n | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->\n match Max.cmp c mcc, mcf with\n | `Gt, _ ->\n p.s <- Max.mk c, false, c;\n if pc < c then update p\n | `Eq, false ->\n p.s <- mcc, true, c + 1;\n update p\n | `Eq, true | `Lt, _ -> ()\n in\n let v = vertex p in\n update v;\n v \n in\n let n = read_int () in\n let open Array in\n let vs = make (n + 1) (vertex None) in\n init n (fun _ -> Scanf.scanf \" %d\" @@ fun x -> x - 1)\n |> mapi (fun i pi ->\n vs.(i + 1) <- vertex (Some vs.(pi));\n let mcc, _, _ = vs.(0).s in Max.int mcc)\n |> map string_of_int\n |> to_list\n |> String.concat \" \"\n |> print_endline \n"}, {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\n\nlet (%) f g x = f (g x)\nlet (%>) f g x = g (f x)\n\nmodule List = struct\n include List\n let map f =\n let rec loop acc =\n function\n | [] -> rev acc\n | x :: xs -> loop (f x :: acc) xs\n in\n loop []\n let mapi f =\n map (let c = ref ~-1 in fun e -> incr c; f !c e) \nend\n\nmodule Max : sig\n type t\n val mk : int -> t\n val cmp : int -> t -> [`Lt | `Gt | `Eq]\n val int : t -> int\nend = struct\n type t = int\n let mk v = v\n let cmp a =\n function\n | b when a < b -> `Lt\n | b when a = b -> `Eq\n | _ -> `Gt\n let int m = m \nend\n\n\ntype vertex = \n { mutable s : Max.t * bool * int;\n p : vertex option }\n\n\nlet () =\n let vertex p = { s = Max.mk ~-1, false, 1; p } in \n let vertex p = \n let rec update =\n function\n | { p = None } -> () \n | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->\n match Max.cmp c mcc, mcf with\n | `Gt, _ ->\n p.s <- Max.mk c, false, c;\n if pc < c then update p\n | `Eq, false ->\n p.s <- mcc, true, c + 1;\n update p\n | `Eq, true | `Lt, _ -> ()\n in\n let v = vertex p in\n update v;\n v \n in\n let n = read_int () in\n let vs = Array.make (n + 1) (vertex None) in\n Array.init n (fun _ -> Scanf.scanf \" %d\" @@ fun x -> x - 1)\n |> Array.mapi (fun i pi ->\n vs.(i + 1) <- vertex (Some vs.(pi));\n let { s = mcc, _, _ } = vs.(0) in Max.int mcc)\n |> Array.map string_of_int\n |> Array.to_list\n |> String.concat \" \"\n |> print_endline \n"}, {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\ntype vertex = \n { mutable s : int * bool * int;\n p : vertex option }\n\nlet () =\n let vertex p = { s = -1, false, 1; p } in \n let vertex p = \n let rec update =\n function\n | { p = None } -> () \n | { s = _, _, c; p = Some ({ s = mcc, mcf, pc } as p) } ->\n let sgn a = if a = 0 then 0 else a / abs a in\n match sgn (c - mcc), mcf with\n | 1, _ ->\n p.s <- c, false, c;\n if pc < c then update p\n | 0, false ->\n p.s <- mcc, true, c + 1;\n update p\n | _ -> ()\n in\n let v = vertex p in\n update v;\n v \n in\n let n = read_int () in\n let open Array in\n let vs = make (n + 1) (vertex None) in\n init n (fun _ -> Scanf.scanf \" %d\" @@ fun x -> x - 1)\n |> iteri\n (fun i pi ->\n vs.(i + 1) <- vertex (Some vs.(pi));\n let mcc, _, _ = vs.(0).s in\n print_int mcc;\n if i < n - 1 then print_char ' ');\n print_newline () \n"}, {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\nlet () = \n let add, get, iter =\n let n = read_int () in\n let mk v = Array.make (n + 1) v in\n let p, mcc, cc = mk ~-1, mk ~-1, mk 1 in\n let rec update i =\n let pi, c = p.(i), cc.(i) in\n if (match lazy (c - mcc.(pi), cc.(pi) > mcc.(pi), cc.(pi)) with\n | _ when pi = -1 -> false\n | lazy (d, _, pc) when d > 0 ->\n mcc.(pi) <- c;\n cc.(pi) <- c;\n pc < c\n | lazy (0, false, _) ->\n cc.(pi) <- c + 1;\n true\n | _ -> false)\n then update pi\n in\n let k = ref 0 in\n (fun i -> incr k; p.(!k) <- i - 1; update !k), \n (fun () -> mcc.(0)),\n fun f -> for i = 1 to n do f (i < n) done \n in \n iter @@ fun s ->\n Scanf.scanf \" %d\" add;\n print_int (get ());\n print_char (if s then ' ' else '\\n')\n"}], "negative_code": [{"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\n\nlet (%) f g x = f (g x)\nlet (%>) f g x = g (f x)\n\n\ntype vertex = \n { mutable mcc : int;\n mutable c : int;\n p : vertex option }\n\n\nlet () =\n let n = read_int () in\n let vs = Array.make (n + 1) None in\n let vertex p = \n let rec update =\n let cmp a =\n function\n | b when a < b -> `Lt\n | b when a = b -> `Eq\n | _ -> `Gt\n in\n function\n | { p = None } -> () \n | { c; p = Some p } ->\n match cmp c p.mcc with\n | `Gt -> p.mcc <- c\n | `Eq -> p.c <- p.c + 1; update p\n | `Lt -> ()\n in\n let v = { mcc = -1; c = 0; p } in\n update v;\n v \n in\n let r = { mcc = -1; c = 0; p = None } in\n vs.(0) <- Some r;\n read_line ()\n |> Str.(split (regexp_string \" \"))\n |> List.mapi (fun i ->\n pred % int_of_string\n %> fun pi ->\n vs.(i + 1) <- Some (vertex vs.(pi));\n r.mcc + 1)\n |> List.map string_of_int\n |> String.concat \" \"\n |> print_endline \n"}, {"source_code": "let (|>) x f = f x\nlet (@@) f x = f x\n\ntype vertex = \n { mutable s : (int * bool) * int;\n p : vertex option }\n\nlet () =\n let vertex p = { s = (-1, false), 1; p } in \n let vertex p = \n let rec update =\n function\n | { p = None } -> () \n | { s = _, c; p = Some ({ s = (mcc, mcf), pc } as p) } ->\n if c > mcc then (\n p.s <- (c, false), c;\n if pc < c then update p\n ) else if not mcf then (\n p.s <- (mcc, true), c + 1;\n update p\n )\n in\n let v = vertex p in\n update v;\n v \n in\n let n = read_int () in\n let open Array in\n let vs = make (n + 1) (vertex None) in\n init n (fun _ -> Scanf.scanf \" %d\" @@ fun x -> x - 1)\n |> iteri\n (fun i pi ->\n vs.(i + 1) <- vertex (Some vs.(pi));\n let (mcc, _), _ = vs.(0).s in\n print_int mcc;\n if i < n - 1 then print_char ' ');\n print_newline () \n"}], "src_uid": "dd47f47922a5457f89391beea749242b"} {"source_code": "module Digraph =\nstruct\n type t =\n {mutable nv : int;\n mutable e : int array array;\n mutable degree : int array;\n }\n\n let create n =\n {nv = n;\n e = Array.make n [| |];\n degree = Array.make n 0\n }\n\n let nb_vertex g = g.nv\n\n let iter_succ f g u =\n let vs = g.e.(u) in\n for i = 0 to g.degree.(u) - 1 do\n\tf vs.(i)\n done\n\n let add_edge g u v =\n if u >= g.nv || v >= g.nv then (\n (* TODO *)\n assert false;\n );\n let {e; degree; _} = g in\n if degree.(u) >= Array.length e.(u) then (\n\tlet s = Array.length e.(u) * 2 + 1 in\n\tlet c = e.(u) in\n\tlet c' = Array.make s 0 in\n\t for i = 0 to Array.length c - 1 do\n\t c'.(i) <- c.(i)\n\t done;\n\t e.(u) <- c'\n );\n e.(u).(degree.(u)) <- v;\n degree.(u) <- degree.(u) + 1\n\nend\n\nmodule Dfs =\nstruct\n\n module type G =\n sig\n type t\n\n val nb_vertex : t -> int\n val iter_succ : (int -> unit) -> t -> int -> unit\n end\n\n module Make (G : G) =\n struct\n let do_nothing _ = ()\n\n let iter ?(pre = do_nothing) ?(post = do_nothing) g =\n let n = G.nb_vertex g in\n let used = Array.make n false in\n let rec dfs u =\n\tused.(u) <- true;\n\tpre u;\n\tG.iter_succ\n\t (fun v ->\n\t if not used.(v) then (\n\t dfs v\n\t )\n\t ) g u;\n\tpost u\n in\n\tfor i = 0 to n - 1 do\n\t if not used.(i)\n\t then dfs i\n\tdone\n\n type iterator = G.t * bool array\n\n let start g =\n let n = G.nb_vertex g in\n let used = Array.make n false in\n\t(g, used)\n\n let iter_component ?(pre = do_nothing) ?(post = do_nothing) (g, used) u =\n let rec dfs u =\n\tused.(u) <- true;\n\tpre u;\n\tG.iter_succ\n\t (fun v ->\n\t if not used.(v) then (\n\t dfs v\n\t )\n\t ) g u;\n\tpost u\n in\n\tif not used.(u)\n\tthen dfs u\n\n type prefix_iterator = G.t * bool array * int array\n\n let prefix_start g =\n let n = G.nb_vertex g in\n let used = Array.make n false in\n let stack = Array.make n 0 in\n\t(g, used, stack)\n\n let prefix_component pre (g, used, stack) u =\n if not used.(u) then (\n\tlet pos = ref 0 in\n\tlet rec dfs () =\n\t if !pos > 0 then (\n\t decr pos;\n\t let u = stack.(!pos) in\n\t pre u;\n\t G.iter_succ\n\t (fun v ->\n\t\t if not used.(v) then (\n\t\t stack.(!pos) <- v;\n\t\t incr pos;\n\t\t used.(v) <- true;\n\t\t )\n\t ) g u;\n\t dfs ()\n\t )\n\tin\n\t stack.(!pos) <- u;\n\t incr pos;\n\t used.(u) <- true;\n\t dfs ()\n )\n end\n\nend\n\nmodule DigraphDFS = Dfs.Make(Digraph)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let g = Digraph.create n in\n let gr = Digraph.create n in \n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tDigraph.add_edge g u v;\n\tif f.(v) <> 1\n\tthen Digraph.add_edge gr v u;\n done\n in\n let a = Array.make n false in\n let r = Array.make n false in\n let dfs = DigraphDFS.prefix_start g in\n let dfs2 = DigraphDFS.prefix_start gr in\n for i = 0 to n - 1 do\n if f.(i) = 1\n then DigraphDFS.prefix_component (fun v -> a.(v) <- true) dfs i;\n done;\n for i = 0 to n - 1 do\n if f.(i) = 2\n then DigraphDFS.prefix_component\n\t(fun v -> if a.(v) then r.(v) <- true)\n\tdfs2 i;\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\n", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif f.(v) = 1\n\tthen r.(v) <- true;\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif f.(v) = 1\n\tthen r.(v) <- true;\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n let b = ref r.(u) in\n if f.(u) = 2\n then b := true;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t if f.(v) <> 1\n\t then b := dfs v || !b\n\t ) else b := !b || r.(v)\n done;\n if !b then (\n\tr.(u) <- true;\n );\n !b\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then ignore (dfs i)\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then ignore (dfs i)\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let r = Array.make n 0 in\n let rec dfs u =\n used.(u) <- true;\n let b = ref false in\n if f.(u) = 2\n then b := true;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet v = es.(u).(i) in\n\t if not used.(v) && f.(v) <> 1\n\t then b := !b || dfs v\n done;\n if !b\n then r.(u) <- 1;\n !b\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then ignore (dfs i)\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" r.(i)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n let b = ref false in\n if f.(u) = 2\n then b := true;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t if f.(v) <> 1\n\t then b := dfs v || !b\n\t ) else b := !b || r.(v)\n done;\n if !b\n then r.(u) <- true;\n !b\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then ignore (dfs i)\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n\tif f.(v) = 1\n\tthen r.(v) <- true\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n\tif f.(v) = 1\n\tthen r.(v) <- true\n done;\n in\n if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n\tif f.(v) = 1\n\tthen r.(v) <- true\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n done\n in\n let es = Array.map Array.of_list es in\n let used = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n let b = ref false in\n if f.(u) = 2\n then b := true;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t if f.(v) <> 1\n\t then b := !b || dfs v\n\t ) else b := !b || r.(v)\n done;\n if !b\n then r.(u) <- true;\n !b\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then ignore (dfs i)\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let f = Array.make n (-1) in\n let es = Array.make n [] in\n let esr = Array.make n [] in\n let () =\n for i = 0 to n - 1 do\n f.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n\tes.(u) <- v :: es.(u);\n\tesr.(v) <- u :: esr.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let esr = Array.map Array.of_list esr in\n let used = Array.make n false in\n let a = Array.make n false in\n let r = Array.make n false in\n let rec dfs u =\n used.(u) <- true;\n a.(u) <- true;\n for i = 0 to Array.length es.(u) - 1 do\n let v = es.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs v\n done;\n in\n let rec dfs2 u =\n used.(u) <- true;\n if a.(u)\n then r.(u) <- true;\n for i = 0 to Array.length esr.(u) - 1 do\n let v = esr.(u).(i) in\n\tif not used.(v) && f.(v) <> 1\n\tthen dfs2 v;\n\tif f.(v) = 1\n\tthen r.(v) <- true\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 1\n then dfs i\n done;\n for i = 0 to n - 1 do\n used.(i) <- false\n done;\n if n = 100000 && m = 100000 && f.(0) = 0 && f.(1) = 0 then exit 0;\n for i = 0 to n - 1 do\n if not used.(i) && f.(i) = 2\n then dfs2 i\n done;\n for i = 0 to n - 1 do\n Printf.printf \"%d\\n\" (if r.(i) then 1 else 0)\n done\n"}], "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let n = read_int () in\n let tree = Array.make (n+1) [] in\n\n for i=2 to n do\n let p = read_int() in\n tree.(i) <- p::tree.(i);\n tree.(p) <- i::tree.(p)\n done;\n\n let c = Array.make (n+1) 0 in\n for i=1 to n do c.(i) <- read_int() done;\n\n let rec dfs p u =\n List.fold_left (fun ac v -> if v = p then ac else\n\tlet diff = if c.(u) <> c.(v) then 1 else 0 in\n\tac + diff + (dfs u v)\n ) 0 tree.(u)\n in\n\n printf \"%d\\n\" (1 + dfs 0 1)\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let g = Array.make (n + 1) []\n and visited = Array.make (n + 1) false\n and colors = Array.make (n + 1) 0\n and ans = ref 0 in\n let rec dfs v color =\n if not visited.(v) then begin\n visited.(v) <- true;\n if colors.(v) <> color then incr ans;\n List.iter (fun w -> dfs w colors.(v)) g.(v)\n end in\n for i = 2 to n do\n let a = read_int () in\n g.(i) <- a::g.(i);\n g.(a) <- i::g.(a)\n done;\n for i = 1 to n do\n colors.(i) <- read_int ()\n done;\n dfs 1 0;\n printf \"%d\\n\" !ans"}], "negative_code": [], "src_uid": "b23696f763d90335e8bfb0a5e2094c03"} {"source_code": "let n = read_int();;\n\nlet graf = Array.make_matrix 26 26 false;;\nlet slowa = ref [];;\n\nfor i = 0 to n - 1 do\n slowa := (read_line())::(!slowa)\ndone;;\n\nslowa := List.rev !slowa;;\n\nlet impossibru = ref false;;\n\nlet chti x = (Char.code x) - (Char.code 'a');;\n\nlet porownaj a b =\n let m = min (String.length a) (String.length b)\n and i = ref 0 \n and st = ref false in\n while !i < m && not !st do\n if a.[!i] <> b.[!i] then \n begin\n graf.(chti a.[!i]).(chti b.[!i]) <- true; \n st := true\n end\n else i := !i + 1\n done;\n if !i = m && (String.length a) > (String.length b) then impossibru := true\n\nlet rec gen l = \n let rec genpom a l = \n match l with\n | [] -> ()\n | h::t -> \n porownaj a h;\n genpom a t in\n match l with\n | [] -> ()\n | h::t -> \n genpom h t;\n gen t;;\n\ngen !slowa;;\n\nlet btc x = \n match x with \n | false -> '0'\n | true -> '1';; \n\nlet odw = Array.make 26 (-1);;\nlet gnr = ref 1;;\n\nlet rec dfs v = \n odw.(v) <- 0;\n for i = 0 to 25 do\n if graf.(v).(i) then\n begin\n if odw.(i) = -1 then dfs i\n else if odw.(i) = 0 then impossibru := true\n end\n done;\n odw.(v) <- !gnr;\n gnr := !gnr + 1;;\n\nfor i = 0 to 25 do \n if odw.(i) = -1 then dfs i\ndone;;\n\nif !impossibru then print_string \"Impossible\\n\"\nelse \n let res = String.make 26 ' ' in\n for i = 0 to 25 do \n Bytes.set res (26 - odw.(i)) (Char.chr (Char.code 'a' + i))\n done;\n print_string res \n;;\n", "positive_code": [{"source_code": "type seen = Unseen | Temp | Seen\nexception Cycle\n\n(* non-fatal string indexing *)\nlet nth s n =\n try Some s.[n] with Invalid_argument \"index out of bounds\" -> None\n\n(* array indexing *)\nlet get a c = a.(int_of_char c - int_of_char 'a')\nlet set g d a b t =\n g.(int_of_char a - int_of_char 'a') <- b :: t;\n let (ain, aout) = get d a in\n d.(int_of_char a - int_of_char 'a') <- (ain, aout + 1);\n let (bin, bout) = get d b in\n d.(int_of_char b - int_of_char 'a') <- (bin + 1, bout)\n\n(* group strings by their nth letter *)\nlet group s n =\n let g = List.fold_left (fun a x -> match nth x n with\n | None -> a\n | Some c -> begin\n match a with\n | [] -> [c, [x]]\n | (d, _) :: _ when c <> d -> (c, [x]) :: a\n | (_, xs) :: t -> (c, x :: xs) :: t\n end\n ) [] s in\n List.rev_map (fun (c, xs) -> (c, List.rev xs)) g\n\nlet strcmp order a b =\n let l = min (String.length a) (String.length b) in\n let rec aux i =\n if i >= l then match (nth a i, nth b i) with\n | (None, None) | (Some _, Some _) -> 0\n | (Some _, None) -> 1\n | (None, Some _) -> -1\n else\n let c = compare (get order a.[i]) (get order b.[i]) in\n if c = 0 then aux (i + 1) else c\n in\n aux 0\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n (* list of strings *)\n let strs = Array.to_list (Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun s -> s))) in\n\n (* graph of letter ordering *)\n let gr = Array.make 26 []\n and deg = Array.make 26 (0, 0) in\n let get' = get gr\n and set = set gr deg in\n\n (* recursively process strings *)\n let rec process s n =\n let g = group s n in\n match g with\n | [] -> ()\n | _ ->\n ignore (List.fold_left (fun p (c, xs) ->\n (match p with\n | Some p -> let t = get' p in set p c t\n | None -> ());\n process xs (n + 1);\n Some c) None g)\n in\n process strs 0;\n\n let s = Stack.create ()\n and alphabet = Stack.create ()\n and seen = Array.make 26 Unseen\n and order = Array.make 26 0\n in\n for i = 0 to 25 do Stack.push i s done;\n\n let rec visit i =\n match seen.(i) with\n | Temp -> raise Cycle\n | Seen -> ()\n | Unseen -> begin\n seen.(i) <- Temp;\n List.iter (fun c -> visit (int_of_char c - int_of_char 'a')) gr.(i);\n seen.(i) <- Seen;\n Stack.push (char_of_int (i + int_of_char 'a')) alphabet\n end\n in\n\n (* topologically sort the graph in gr *)\n try\n while not (Stack.is_empty s) do\n visit (Stack.pop s)\n done;\n (* sort strs according to alphabet and\n * check that it doesn't change *)\n let i = ref 0 in\n Stack.iter (fun c -> order.(int_of_char c - int_of_char 'a') <- !i; incr i) (Stack.copy alphabet);\n if List.sort (strcmp order) strs = strs then begin\n Stack.iter print_char alphabet;\n print_char '\\n'\n end else raise Cycle\n with Cycle -> print_endline \"Impossible\"\n)\n"}], "negative_code": [{"source_code": "let n = read_int();;\n\nlet graf = Array.make_matrix 26 26 false;;\nlet slowa = ref [];;\n\nfor i = 0 to n - 1 do\n slowa := (read_line())::(!slowa)\ndone;;\n\nslowa := List.rev !slowa;;\n\nlet impossibru = ref false;;\n\nlet chti x = (Char.code x) - (Char.code 'a');;\n\nlet porownaj a b =\n let m = min (String.length a) (String.length b)\n and i = ref 0 \n and st = ref false in\n while !i < m && not !st do\n if a.[!i] <> b.[!i] then \n begin\n graf.(chti a.[!i]).(chti b.[!i]) <- true; \n st := true\n end\n else i := !i + 1\n done;\n if !i = m then impossibru := true\n\nlet rec gen l = \n let rec genpom a l = \n match l with\n | [] -> ()\n | h::t -> \n porownaj a h;\n genpom a t in\n match l with\n | [] -> ()\n | h::t -> \n genpom h t;\n gen t;;\n\ngen !slowa;;\n\nlet btc x = \n match x with \n | false -> '0'\n | true -> '1';; \n\nlet odw = Array.make 26 (-1);;\nlet gnr = ref 1;;\n\nlet rec dfs v = \n odw.(v) <- 0;\n for i = 0 to 25 do\n if graf.(v).(i) then\n begin\n if odw.(i) = -1 then dfs i\n else if odw.(i) = 0 then impossibru := true\n end\n done;\n odw.(v) <- !gnr;\n gnr := !gnr + 1;;\n\nfor i = 0 to 25 do \n if odw.(i) = -1 then dfs i\ndone;;\n\nif !impossibru then print_string \"Impossible\\n\"\nelse \n let res = String.make 26 ' ' in\n for i = 0 to 25 do \n Bytes.set res (26 - odw.(i)) (Char.chr (Char.code 'a' + i))\n done;\n print_string res \n;;\n"}, {"source_code": "type seen = Unseen | Temp | Seen\nexception Cycle\n\n(* non-fatal string indexing *)\nlet nth s n =\n try Some s.[n] with Invalid_argument \"index out of bounds\" -> None\n\n(* array indexing *)\nlet get a c = a.(int_of_char c - int_of_char 'a')\nlet set g d a b t =\n g.(int_of_char a - int_of_char 'a') <- b :: t;\n let (ain, aout) = get d a in\n d.(int_of_char a - int_of_char 'a') <- (ain, aout + 1);\n let (bin, bout) = get d b in\n d.(int_of_char b - int_of_char 'a') <- (bin + 1, bout)\n\n(* group strings by their nth letter *)\nlet group s n =\n let g = List.fold_left (fun a x -> match nth x n with\n | None -> a\n | Some c -> begin\n match a with\n | [] -> [c, [x]]\n | (d, _) :: _ when c <> d -> (c, [x]) :: a\n | (_, xs) :: t -> (c, x :: xs) :: t\n end\n ) [] s in\n List.rev_map (fun (c, xs) -> (c, List.rev xs)) g\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n (* list of strings *)\n let s = Array.to_list (Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun s -> s))) in\n\n (* graph of letter ordering *)\n let gr = Array.make 26 []\n and deg = Array.make 26 (0, 0) in\n let get = get gr\n and set = set gr deg in\n\n (* recursively process strings *)\n let rec process s n =\n let g = group s n in\n match g with\n | [] -> ()\n | _ ->\n ignore (List.fold_left (fun p (c, xs) ->\n (match p with\n | Some p -> let t = get p in set p c t\n | None -> ());\n process xs (n + 1);\n Some c) None g)\n in\n process s 0;\n\n let s = Stack.create ()\n and alphabet = Stack.create ()\n and seen = Array.make 26 Unseen in\n for i = 0 to 25 do Stack.push i s done;\n\n let rec visit i =\n match seen.(i) with\n | Temp -> raise Cycle\n | Seen -> ()\n | Unseen -> begin\n seen.(i) <- Temp;\n List.iter (fun c -> visit (int_of_char c - int_of_char 'a')) gr.(i);\n seen.(i) <- Seen;\n Stack.push (char_of_int (i + int_of_char 'a')) alphabet\n end\n in\n\n (* topologically sort the graph in gr *)\n try\n while not (Stack.is_empty s) do\n visit (Stack.pop s)\n done;\n Stack.iter print_char alphabet;\n print_char '\\n'\n with Cycle -> print_endline \"Impossible\"\n)\n"}], "src_uid": "12218097cf5c826d83ab11e5b049999f"} {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let n = getnum () in\n let a = Array.make_matrix n n 0 in\n let () =\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let resc = ref 0 in\n let ress = ref 0 in\n let d = 5 in\n let used = Array.make_matrix n n false in\n let stack = Array.make (n * n) (0, 0) in\n let pos = ref 0 in\n let f = 5 in\n let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;\n for i = 0 to n - 1 - d do\n for j = 0 to n - 1 - d do\n\tif not used.(i).(j) then (\n\t let b = ref true in\n\t for i' = 0 to d - 1 do\n\t for j' = 0 to d - 1 do\n\t\tif a.(i + i').(j + j') = 0\n\t\tthen b := false\n\t done\n\t done;\n\t if !b then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t\tif !pos > 0 then (\n\t\t decr pos;\n\t\t let (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t\tif x >= 0 && y >= 0 && x < n && y < n &&\n\t\t\t a.(y).(x) > 0\n\t\t\tthen (\n\t\t\t if not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t )\n\t\t\t) else (\n\t\t\t border := (x, y) :: !border\n\t\t\t)\n\t\t done;\n\t\t dfs ()\n\t\t)\n\t in\n\t\tpos := 0;\n\t\tstack.(!pos) <- (j, i);\n\t\tincr pos;\n\t\tused.(i).(j) <- true;\n\t\tdfs ();\n\t\tlet border = Array.of_list !border in\n\t\tlet l = Array.length border in\n\t\tlet (mx, my) =\n\t\t let mx = ref 0 in\n\t\t let my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t\tmx := !mx + x;\n\t\t\tmy := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t\tin\n\t\tlet d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t )\n\t)\n done\n done;\n Printf.printf \"%d %d\\n\" !resc !ress;\n", "positive_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let n = getnum () in\n let a = Array.make_matrix n n 0 in\n let () =\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let resc = ref 0 in\n let ress = ref 0 in\n let d = 5 in\n let used = Array.make_matrix n n false in\n let stack = Array.make (n * n) (0, 0) in\n let pos = ref 0 in\n for i = 0 to n - 1 - d do\n for j = 0 to n - 1 - d do\n\tif not used.(i).(j) then (\n\t let b = ref true in\n\t for i' = 0 to d - 1 do\n\t for j' = 0 to d - 1 do\n\t\tif a.(i + i').(j + j') = 0\n\t\tthen b := false\n\t done\n\t done;\n\t if !b then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t\tif !pos > 0 then (\n\t\t decr pos;\n\t\t let (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t\tif x >= 0 && y >= 0 && x < n && y < n &&\n\t\t\t a.(y).(x) > 0\n\t\t\tthen (\n\t\t\t if not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t )\n\t\t\t) else (\n\t\t\t border := (x, y) :: !border\n\t\t\t)\n\t\t done;\n\t\t dfs ()\n\t\t)\n\t in\n\t\tpos := 0;\n\t\tstack.(!pos) <- (j, i);\n\t\tincr pos;\n\t\tused.(i).(j) <- true;\n\t\tdfs ();\n\t\tlet border = Array.of_list !border in\n\t\tlet l = Array.length border in\n\t\tlet (mx, my) =\n\t\t let mx = ref 0 in\n\t\t let my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t\tmx := !mx + x;\n\t\t\tmy := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t\tin\n\t\tlet d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr < 1.0\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f %d\\n\" mx my r sr l*)\n\t )\n\t)\n done\n done;\n Printf.printf \"%d %d\\n\" !resc !ress;\n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let n = getnum () in\n let a = Array.make_matrix n n 0 in\n let () =\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let resc = ref 0 in\n let ress = ref 0 in\n let d = 5 in\n let used = Array.make_matrix n n false in\n let stack = Array.make (n * n) (0, 0) in\n let pos = ref 0 in\n for i = 0 to n - 1 - d do\n for j = 0 to n - 1 - d do\n\tif not used.(i).(j) then (\n\t let b = ref true in\n\t for i' = 0 to d - 1 do\n\t for j' = 0 to d - 1 do\n\t\tif a.(i + i').(j + j') = 0\n\t\tthen b := false\n\t done\n\t done;\n\t if !b then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t\tif !pos > 0 then (\n\t\t decr pos;\n\t\t let (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t\tif x >= 0 && y >= 0 && x < n && y < n &&\n\t\t\t a.(y).(x) > 0\n\t\t\tthen (\n\t\t\t if not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t )\n\t\t\t) else (\n\t\t\t border := (x, y) :: !border\n\t\t\t)\n\t\t done;\n\t\t dfs ()\n\t\t)\n\t in\n\t\tpos := 0;\n\t\tstack.(!pos) <- (j, i);\n\t\tincr pos;\n\t\tused.(i).(j) <- true;\n\t\tdfs ();\n\t\tlet border = Array.of_list !border in\n\t\tlet l = Array.length border in\n\t\tlet (mx, my) =\n\t\t let mx = ref 0 in\n\t\t let my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t\tmx := !mx + x;\n\t\t\tmy := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t\tin\n\t\tlet d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr < 1.0\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f %d\\n\" mx my r sr l*)\n\t )\n\t)\n done\n done;\n Printf.printf \"%d %d\\n\" !resc !ress;\n"}], "negative_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let n = getnum () in\n let a = Array.make_matrix n n 0 in\n let () =\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let resc = ref 0 in\n let ress = ref 0 in\n let d = 5 in\n let used = Array.make_matrix n n false in\n let stack = Array.make (n * n) (0, 0) in\n let pos = ref 0 in\n let f = 5 in\n let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;\n for i = 0 to n - 1 - d do\n for j = 0 to n - 1 - d do\n\tif not used.(i).(j) then (\n\t let b = ref true in\n\t for i' = 0 to d - 1 do\n\t for j' = 0 to d - 1 do\n\t\tif a.(i + i').(j + j') = 0\n\t\tthen b := false\n\t done\n\t done;\n\t if !b then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t\tif !pos > 0 then (\n\t\t decr pos;\n\t\t let (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t\tif x >= 0 && y >= 0 && x < n && y < n &&\n\t\t\t a.(y).(x) > 0\n\t\t\tthen (\n\t\t\t if not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t )\n\t\t\t) else (\n\t\t\t border := (x, y) :: !border\n\t\t\t)\n\t\t done;\n\t\t dfs ()\n\t\t)\n\t in\n\t\tpos := 0;\n\t\tstack.(!pos) <- (j, i);\n\t\tincr pos;\n\t\tused.(i).(j) <- true;\n\t\tdfs ();\n\t\tlet border = Array.of_list !border in\n\t\tlet l = Array.length border in\n\t\tlet (mx, my) =\n\t\t let mx = ref 0 in\n\t\t let my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t\tmx := !mx + x;\n\t\t\tmy := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t\tin\n\t\tlet d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr < 1.0\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f %d\\n\" mx my r sr l*)\n\t )\n\t)\n done\n done;\n Printf.printf \"%d %d\\n\" !resc !ress;\n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let n = getnum () in\n let a = Array.make_matrix n n 0 in\n let () =\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let resc = ref 0 in\n let ress = ref 0 in\n let d = 5 in\n let used = Array.make_matrix n n false in\n let stack = Array.make (n * n) (0, 0) in\n let pos = ref 0 in\n let f = 3 in\n let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;\n for i = 0 to n - 1 - d do\n for j = 0 to n - 1 - d do\n\tif not used.(i).(j) then (\n\t let b = ref true in\n\t for i' = 0 to d - 1 do\n\t for j' = 0 to d - 1 do\n\t\tif a.(i + i').(j + j') = 0\n\t\tthen b := false\n\t done\n\t done;\n\t if !b then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t\tif !pos > 0 then (\n\t\t decr pos;\n\t\t let (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t\tif x >= 0 && y >= 0 && x < n && y < n &&\n\t\t\t a.(y).(x) > 0\n\t\t\tthen (\n\t\t\t if not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t )\n\t\t\t) else (\n\t\t\t border := (x, y) :: !border\n\t\t\t)\n\t\t done;\n\t\t dfs ()\n\t\t)\n\t in\n\t\tpos := 0;\n\t\tstack.(!pos) <- (j, i);\n\t\tincr pos;\n\t\tused.(i).(j) <- true;\n\t\tdfs ();\n\t\tlet border = Array.of_list !border in\n\t\tlet l = Array.length border in\n\t\tlet (mx, my) =\n\t\t let mx = ref 0 in\n\t\t let my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t\tmx := !mx + x;\n\t\t\tmy := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t\tin\n\t\tlet d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr < 1.0\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f %d\\n\" mx my r sr l*)\n\t )\n\t)\n done\n done;\n Printf.printf \"%d %d\\n\" !resc !ress;\n"}], "src_uid": "06c7699523a9f8036330857660c0687e"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nmodule Dmap = Map.Make (struct type t = int let compare = compare end)\n\nlet () = \n let (n,m) = read_pair() in\n let k = read_int() in\n\n let rtable = Hashtbl.create 100 in (* represent each of the m+1 rows of length n *)\n let ctable = Hashtbl.create 100 in (* represent each of the n+1 columns of length m *)\n\n let increment map key delta = \n let odelta = try Dmap.find key map with Not_found -> 0 in\n Dmap.add key (odelta+delta) map\n in\n\n let () = \n for i=0 to k-1 do\n let (a,b) = read_pair() in\n let (c,d) = read_pair() in\n let (table, which, lo, hi) = \n\tif a=c then (ctable, a, min b d, max b d)\n\telse (rtable, b, min a c, max a c)\n in\n let map = try Hashtbl.find table which with Not_found -> Dmap.empty in\n let map = increment map lo 1 in\n let map = increment map hi (-1) in\n\tHashtbl.replace table which map\n done\n in\n\n let maplength map dim = \n (* total length of the zero regions of this map, where b is the upper bound of things in it *)\n let rec loop depth ac x map = if Dmap.is_empty map then ac + (dim-x) else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let ac = if depth=0 then ac + (x'-x) else ac in\n let depth = delta + depth in\n\tloop depth ac x' map\n in\n loop 0 0 0 map\n in\n\n let find_move nimber map dim = \n (* returns the position in the given map so that a move from 0 to that position cancels out the nimber *)\n (* we know that it is possible to do this *)\n let rec loop depth need x map = if Dmap.is_empty map then x+need else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let need' = if depth=0 then need - (x'-x) else need in\n let depth = delta + depth in\n\tif need' > 0 then loop depth need' x' map\n\telse x+need\n in\n let pile = maplength map dim in\n let pile' = pile lxor nimber in\n loop 0 (pile - pile') 0 map\n in\n\n let augment_table table dim =\n (* add an extra row or column if the number of untouched rows/colunns is odd *)\n let size = Hashtbl.length table in\n if ((dim-1) - size) mod 2 = 1 then\n\tlet rec find_unused x = if not (Hashtbl.mem table x) then x else find_unused (x+1) in\n\tlet unused = find_unused 1 in\n\t Hashtbl.add table unused Dmap.empty\n in\n\n let () = \n augment_table rtable m;\n augment_table ctable n;\n in\n\n let compute_nimber table dim =\n Hashtbl.fold (fun _ map ac -> (maplength map dim) lxor ac) table 0\n in\n\n let nimber = (compute_nimber rtable n) lxor (compute_nimber ctable m) in\n\n (* Printf.printf \"nimber = %d\\n\" nimber; *)\n\n if nimber = 0 then Printf.printf \"SECOND\\n\" else (\n (* nimber is non-zero so we have to figure out what move to make *)\n (* find a move pile in which to move which has a 1 in the position of the\n\t top 1 bit of the nimber. *)\n let rec compute_top_bit b = if (b lor (b-1)) land nimber = nimber then b else compute_top_bit (2*b) in\n let top_bit = compute_top_bit 1 in\n let find_good_pile table dim =\n\tHashtbl.fold (fun v map ac -> if (top_bit land (maplength map dim)) <> 0 then (v,map) else ac) \n\t table (-1, Dmap.empty)\n in\n\n let (row,rmap) = find_good_pile rtable n in\n let (column,cmap) = find_good_pile ctable m in\n\t(* Printf.printf \"nimber = %d top_bit = %d row = %d column = %d\\n\" nimber top_bit row column; *)\n\n let (sx,sy,ex,ey) = if row >= 0 then (\n\tlet move = find_move nimber rmap n in\n\t (0, row, move, row)\n ) \n else if column >=0 then (\n\tlet move = find_move nimber cmap m in\n\t (column, 0, column, move)\n ) \n else (\n\tPrintf.printf \"Error: can't find move\\n\";\n\t(0,0,0,0)\n )\n in\n\tPrintf.printf \"FIRST\\n\";\n\tPrintf.printf \"%d %d %d %d\\n\" sx sy ex ey\n )\n", "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nmodule Dmap = Map.Make (struct type t = int let compare = compare end)\n\nlet () = \n let (n,m) = read_pair() in\n let k = read_int() in\n\n let rtable = Hashtbl.create 100 in (* represent each of the m+1 rows of length n *)\n let ctable = Hashtbl.create 100 in (* represent each of the n+1 columns of length m *)\n\n let increment map key delta = \n let odelta = try Dmap.find key map with Not_found -> 0 in\n Dmap.add key (odelta+delta) map\n in\n\n let () = \n for i=0 to k-1 do\n let (a,b) = read_pair() in\n let (c,d) = read_pair() in\n let (table, which, lo, hi) = \n\tif a=c then (ctable, a, min b d, max b d)\n\telse (rtable, b, min a c, max a c)\n in\n let map = try Hashtbl.find table which with Not_found -> Dmap.empty in\n let map = increment map lo 1 in\n let map = increment map hi (-1) in\n\tHashtbl.replace table which map\n done\n in\n\n let maplength map dim = \n (* total length of the zero regions of this map, where b is the upper bound of things in it *)\n let rec loop depth ac x map = if Dmap.is_empty map then ac + (dim-x) else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let ac = if depth=0 then ac + (x'-x) else ac in\n let depth = delta + depth in\n\tloop depth ac x' map\n in\n loop 0 0 0 map\n in\n\n let find_move nimber map dim = \n (* returns the position in the given map so that a move from 0 to that position cancels out the nimber *)\n (* we know that it is possible to do this *)\n let rec loop depth need x map = if Dmap.is_empty map then x+need else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let need' = if depth=0 then need - (x'-x) else need in\n let depth = delta + depth in\n\tif need' > 0 then loop depth need' x' map\n\telse x+need\n in\n let pile = maplength map dim in\n let pile' = pile lxor nimber in\n loop 0 (pile - pile') 0 map\n in\n\n let augment_table table dim =\n (* add an extra row or column if the number of untouched rows/colunns is odd *)\n let size = Hashtbl.length table in\n if ((dim-1) - size) mod 2 = 1 then\n\tlet rec find_unused x = if not (Hashtbl.mem table x) then x else find_unused (x+1) in\n\tlet unused = find_unused 1 in\n\t Hashtbl.add table unused Dmap.empty\n in\n\n let () = \n augment_table rtable m;\n augment_table ctable n;\n in\n\n let compute_nimber table dim =\n Hashtbl.fold (fun _ map ac -> (maplength map dim) lxor ac) table 0\n in\n\n let nimber = (compute_nimber rtable n) lxor (compute_nimber ctable m) in\n\n (* Printf.printf \"nimber = %d\\n\" nimber; *)\n\n if nimber = 0 then Printf.printf \"SECOND\\n\" else (\n (* nimber is non-zero so we have to figure out what move to make *)\n (* find a move pile in which to move which has a 1 in the position of the\n\t top 1 bit of the nimber. *)\n let rec compute_top_bit b = if (b lor (b-1)) land nimber = nimber then b else compute_top_bit (2*b) in\n let top_bit = compute_top_bit 1 in\n let find_good_pile table dim =\n\tHashtbl.fold (fun v map ac -> if (top_bit land (maplength map dim)) <> 0 then (v,map) else ac) \n\t table (-1, Dmap.empty)\n in\n\n let (row,rmap) = find_good_pile rtable n in\n let (column,cmap) = find_good_pile ctable m in\n\t(* Printf.printf \"nimber = %d top_bit = %d row = %d column = %d\\n\" nimber top_bit row column; *)\n\n let (sx,sy,ex,ey) = if row >= 0 then (\n\tlet move = find_move nimber rmap n in\n\t (0, row, move, row)\n ) \n else if column >=0 then (\n\tlet move = find_move nimber cmap m in\n\t (column, 0, column, move)\n ) \n else (\n\tPrintf.printf \"Error: can't find move\\n\";\n\t(0,0,0,0)\n )\n in\n\tPrintf.printf \"FIRST\\n\";\n\tPrintf.printf \"%d %d %d %d\\n\" sx sy ex ey\n )\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nmodule Dmap = Map.Make (struct type t = int let compare = compare end)\n\nlet () = \n let (n,m) = read_pair() in\n let k = read_int() in\n let cuts = Array.init k (\n fun _ -> \n let (a,b) = read_pair() in\n let (c,d) = read_pair() in\n\t(a,b,c,d)\n ) in\n\n let rtable = Hashtbl.create 100 in (* represent each of the m+1 rows of length n *)\n let ctable = Hashtbl.create 100 in (* represent each of the n+1 columns of length m *)\n\n let increment map key delta = \n let odelta = try Dmap.find key map with Not_found -> 0 in\n Dmap.add key (odelta+delta) map\n in\n\n let () = \n for i=0 to k-1 do\n let (a,b,c,d) = cuts.(i) in\n let (table, which, lo, hi) = \n\tif a=c then (ctable, a, min b d, max b d)\n\telse (rtable, b, min a c, max a c)\n in\n let map = try Hashtbl.find table which with Not_found -> Dmap.empty in\n let map = increment map lo 1 in\n let map = increment map hi (-1) in\n\tHashtbl.replace table which map\n done\n in\n\n let maplength map dim = \n (* total length of the zero regions of this map, where b is the upper bound of things in it *)\n let rec loop depth ac x map = if Dmap.is_empty map then ac + (dim-x) else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let ac = if depth=0 then ac + (x'-x) else ac in\n let depth = delta + depth in\n\tloop depth ac x' map\n in\n loop 0 0 0 map\n in\n\n let find_move nimber map dim = \n (* returns the position in the given map so that a move from 0 to that position cancels out the nimber *)\n (* we know that it is possible to do this *)\n let rec loop depth need x map = if Dmap.is_empty map then x+need else\n let (x',delta) = Dmap.min_binding map in\n let map = Dmap.remove x' map in\n let need' = if depth=0 then need - (x'-x) else need in\n let depth = delta + depth in\n\tif need' > 0 then loop depth need' x' map\n\telse x+need\n in\n let pile = maplength map dim in\n let pile' = pile lxor nimber in\n loop 0 (pile - pile') 0 map\n in\n\n let augment_table table dim =\n (* add an extra row or column if the number of untouched rows/colunns is odd *)\n let size = Hashtbl.length table in\n if ((dim+1) - size) mod 2 = 1 then\n\tlet rec find_unused x = if not (Hashtbl.mem table x) then x else find_unused (x+1) in\n\tlet unused = find_unused 0 in\n\t Hashtbl.add table unused Dmap.empty\n in\n\n let () = \n augment_table rtable m;\n augment_table ctable n;\n in\n\n let compute_nimber table dim =\n Hashtbl.fold (fun _ map ac -> (maplength map dim) lxor ac) table 0\n in\n\n let nimber = (compute_nimber rtable n) lxor (compute_nimber ctable m) in\n\n (* Printf.printf \"nimber = %d\\n\" nimber; *)\n\n if nimber = 0 then Printf.printf \"SECOND\\n\" else (\n (* nimber is non-zero so we have to figure out what move to make *)\n (* find a move pile in which to move which has a 1 in the position of the\n\t top 1 bit of the nimber. *)\n let rec compute_top_bit b = if (b lor (b-1)) land nimber = nimber then b else compute_top_bit (2*b) in\n let top_bit = compute_top_bit 1 in\n let find_good_pile table dim =\n\tHashtbl.fold (fun v map ac -> if (top_bit land (maplength map dim)) <> 0 then (v,map) else ac) \n\t table (-1, Dmap.empty)\n in\n\n let (row,rmap) = find_good_pile rtable n in\n let (column,cmap) = find_good_pile ctable m in\n\t(* Printf.printf \"nimber = %d top_bit = %d row = %d column = %d\\n\" nimber top_bit row column; *)\n\n let (sx,sy,ex,ey) = if row >= 0 then (\n\tlet move = find_move nimber rmap n in\n\t (0, row, move, row)\n ) \n else if column >=0 then (\n\tlet move = find_move nimber cmap m in\n\t (column, 0, column, move)\n ) \n else (\n\tPrintf.printf \"Error: can't find move\\n\";\n\t(0,0,0,0)\n )\n in\n\tPrintf.printf \"FIRST\\n\";\n\tPrintf.printf \"%d %d %d %d\\n\" sx sy ex ey\n )\n"}], "src_uid": "a7fa7a5ab71690fb3b5301bebc19956b"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let x = x - 1 in\n let a = Array.make n 0 in\n let b = Array.make n (-1) in\n let () =\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- k - 1;\n\tif k > 0\n\tthen b.(k - 1) <- i\n done;\n in\n let used = Array.make n false in\n let c = Array.make n 1 in\n let rec dfs k =\n used.(k) <- true;\n if b.(k) >= 0 then (\n dfs b.(k);\n c.(k) <- c.(b.(k)) + 1;\n )\n in\n let used2 = Array.make n false in\n let bob =\n let c = ref 1 in\n let p = ref x in\n used2.(x) <- true;\n while a.(!p) >= 0 do\n\tincr c;\n\tp := a.(!p);\n\tused2.(!p) <- true;\n done;\n !c\n in\n let () =\n for i = 0 to n - 1 do\n if not used.(i)\n then dfs i\n done;\n in\n let s = ref [] in\n let () =\n for i = 0 to n - 1 do\n if not used2.(i) && a.(i) < 0\n then s := c.(i) :: !s\n done;\n in\n let s = Array.of_list !s in\n let a = Array.make (n + 1) false in\n a.(0) <- true;\n for k = 0 to Array.length s - 1 do\n let k = s.(k) in\n(*Printf.printf \"asd %d\\n\" k;*)\n\tfor i = n downto k do\n\t if a.(i - k)\n\t then a.(i) <- true\n\tdone\n done;\n (*for i = 0 to n - 1 do\n Printf.printf \"c %d %d %d\\n\" i c.(i) x;\n done;*)\n for i = 0 to n do\n if a.(i)\n then Printf.printf \"%d\\n\" (i + bob);\n done\n", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let x = x - 1 in\n let a = Array.make n 0 in\n let b = Array.make n (-1) in\n let () =\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- k - 1;\n\tif k > 0\n\tthen b.(k - 1) <- i\n done;\n in\n let used = Array.make n false in\n let c = Array.make n 1 in\n let rec dfs k =\n used.(k) <- true;\n if b.(k) >= 0 then (\n dfs b.(k);\n c.(k) <- c.(b.(k)) + 1;\n )\n in\n let used2 = Array.make n false in\n let bob =\n let c = ref 1 in\n let p = ref x in\n used2.(x) <- true;\n while a.(!p) >= 0 do\n\tincr c;\n\tp := a.(!p);\n\tused2.(!p) <- true;\n done;\n !c\n in\n let () =\n for i = 0 to n - 1 do\n if not used.(i)\n then dfs i\n done;\n in\n let s = ref [] in\n let () =\n for i = 0 to n - 1 do\n if not used2.(i) && a.(i) < 0\n then s := c.(i) :: !s\n done;\n in\n let s = Array.of_list !s in\n let a = Array.make (n + 1) false in\n a.(0) <- true;\n for k = 0 to Array.length s - 1 do\n let k = s.(k) in\n(*Printf.printf \"asd %d\\n\" k;*)\n\tfor i = n downto k do\n\t if a.(i - k)\n\t then a.(i) <- true\n\tdone\n done;\n (*for i = 0 to n - 1 do\n Printf.printf \"c %d %d %d\\n\" i c.(i) x;\n done;*)\n for i = 0 to n do\n if a.(i)\n then Printf.printf \"%d\\n\" (i + bob);\n done\n"}], "negative_code": [], "src_uid": "5a6b97a2aa27dd2c562f73a7a8f16720"} {"source_code": "let input = open_in \"input.txt\"\nlet output = open_out \"output.txt\"\n\nlet read_int () = Scanf.fscanf input \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\n\nlet a = \n let len = 2 * n \n in let rec loop i f = \n if i > len then f []\n else let ai = read_int () in loop (i + 1) (fun l -> f ((ai, i) :: l))\n in loop 1 (fun x -> x) ;;\n\nlet upper = List.fold_left (fun x (v, i) -> max x v) 0 a ;;\nlet seen = Array.make (upper + 1) 0 ;;\n\nlet pairs = \n let rec loop l a = match l with\n | [] -> a\n | (v, i) :: t ->\n if seen.(v) = 0 then (seen.(v) <- i ; loop t a)\n else let j = seen.(v) in seen.(v) <- 0 ; loop t ((j, i) :: a)\n in loop a [] ;;\n \nlet possible =\n let rec loop i =\n if i > upper then true \n else if seen.(i) <> 0 then false else loop (i + 1)\n in loop 1 ;;\n \nif not possible then Printf.fprintf output \"-1\\n\"\nelse\n let print_pair (a, b) = Printf.fprintf output \"%d %d\\n\" a b \n in let rec loop = function\n | [] -> ()\n | h :: t -> print_pair h ; loop t\n in loop pairs ;;", "positive_code": [{"source_code": "let input = open_in \"input.txt\"\nlet output = open_out \"output.txt\"\n\nlet read_int () = Scanf.fscanf input \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\n\nlet a = \n let len = 2 * n \n in let rec loop i f = \n if i > len then f []\n else let ai = read_int () in loop (i + 1) (fun l -> f ((ai, i) :: l))\n in loop 1 (fun x -> x) ;;\n\nlet seen = Array.make 5001 0 ;;\n\nlet pairs = \n let rec loop l a = match l with\n | [] -> a\n | (v, i) :: t ->\n if seen.(v) = 0 then (seen.(v) <- i ; loop t a)\n else let j = seen.(v) in seen.(v) <- 0 ; loop t ((j, i) :: a)\n in loop a [] ;;\n \nlet possible =\n let rec loop i =\n if i > 5000 then true \n else if seen.(i) <> 0 then false else loop (i + 1)\n in loop 1 ;;\n \nlet print_pair (a, b) = Printf.fprintf output \"%d %d\\n\" a b ;;\n\nif not possible then Printf.fprintf output \"-1\\n\"\nelse \n let rec loop = function\n | [] -> ()\n | h :: t -> print_pair h ; loop t\n in loop pairs ;;"}, {"source_code": "\nlet chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet () = \n let n = read_int() in\n let a = Array.init (2*n) (fun _ -> read_int()) in\n\n let t = Array.make 5001 (-1) in\n\n let rec loop i p = if i=2*n then () else (\n if t.(a.(i)) >= 0 then (\n if p then print_string (Printf.sprintf \"%d %d\\n\" (1+t.(a.(i))) (i+1));\n t.(a.(i)) <- -1;\n loop (i+1) p\n ) else (\n t.(a.(i)) <- i;\n loop (i+1) p\n )\n )\n in\n \n loop 0 false;\n\n if (maxf 0 5000 (fun i-> t.(i))) = -1 then (\n loop 0 true;\n ) else (\n print_string \"-1\\n\"\n )\n"}], "negative_code": [{"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\n\nmodule Iset = Set.Make (struct type t = int let compare = compare end)\n\nlet () = \n let n = read_int() in\n let a = Array.init (2*n) (fun _ -> read_int()) in\n\n let rec loop i p s = if i=2*n then s else (\n if Iset.mem a.(i) s \n then (\n if p then print_string (Printf.sprintf \"%d %d\\n\" a.(i) a.(i));\n loop (i+1) p (Iset.remove a.(i) s)\n )\n else loop (i+1) p (Iset.add a.(i) s)\n )\n in\n let s = loop 0 false Iset.empty in\n\n if Iset.is_empty s then (\n ignore (loop 0 true Iset.empty)\n ) else (\n print_string \"-1\\n\"\n )\n"}], "src_uid": "0352429425782d7fe44818594eb0660c"} {"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 \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let ps = Array.make n (0L, 0L) in\n let _ =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tps.(i) <- (x, y)\n done;\n in\n let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in\n let area3 (x, y) (x1, y1) (x2, y2) =\n x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2\n in\n let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =\n if x1 < x2\n then -1\n else if x1 > x2\n then 1\n else compare y1 y2\n in\n let _ = Array.sort cmp ps in\n (* Convex hull *)\n let p1 = ps.(0)\n and p2 = ps.(n - 1) in\n let up = Array.make n (0L, 0L) in\n let down = Array.make n (0L, 0L) in\n let pos_up = ref 0 in\n let pos_down = ref 0 in\n let hull =\n up.(!pos_up) <- p1;\n incr pos_up;\n down.(!pos_down) <- p1;\n incr pos_down;\n for i = 1 to n - 1 do\n if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (\n\twhile !pos_up >= 2 &&\n\t area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) >= 0L do\n\t decr pos_up\n\tdone;\n\tup.(!pos_up) <- ps.(i);\n\tincr pos_up;\n );\n if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (\n\twhile !pos_down >= 2 &&\n\t area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) <= 0L do\n\t decr pos_down\n\tdone;\n\tdown.(!pos_down) <- ps.(i);\n\tincr pos_down;\n );\n done;\n let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in\n for i = 0 to !pos_up - 1 do\n\thull.(i) <- up.(i)\n done;\n for i = !pos_down - 2 downto 1 do\n\thull.(!pos_down - 2 - i + !pos_up) <- down.(i)\n done;\n hull\n in\n let area3 (x, y) (x1, y1) (x2, y2) =\n let x = float_of_int x\n and y = float_of_int y\n and x1 = float_of_int x1\n and y1 = float_of_int y1\n and x2 = float_of_int x2\n and y2 = float_of_int y2 in\n x *. y1 +. x1 *. y2 +. x2 *. y -. x2 *. y1 -. x1 *. y -. x *. y2\n in\n let hull =\n Array.map (fun (x, y) -> (Int64.to_int x, Int64.to_int y)) hull\n in\n let maxs = ref 0.0 in\n let b = ref (0, 0, 0) in\n (*for i = 0 to Array.length hull - 1 do\n let (x, y) = hull.(i) in\n\tPrintf.eprintf \"asd %Ld %Ld\\n\" x y\n done;*)\n for i = 0 to Array.length hull - 1 do\n let k = ref i in\n\tfor j = i + 2 to Array.length hull - 1 do\n\t let s = ref 0.0 in\n\t let s' = ref 0.0 in\n\t s := abs_float (area3 hull.(i) hull.(j) hull.(!k));\n\t while !k < j - 1 &&\n\t (s' := abs_float (area3 hull.(i) hull.(j) hull.(!k + 1));\n\t !s' >= !s)\n\t do\n\t incr k;\n\t s := !s';\n\t (*Printf.eprintf \"qaz %d %d %d %Ld\\n\" i j !k !s;*)\n\t done;\n\t (*Printf.eprintf \"zxc %d %d %Ld\\n\" i j !s;*)\n\t if !maxs < !s then (\n\t maxs := !s;\n\t b := (i, j, !k);\n\t )\n\tdone;\n done;\n let (i, j, k) = !b in\n let (x1, y1) = hull.(i)\n and (x2, y2) = hull.(j)\n and (x3, y3) = hull.(k) in\n (*Printf.eprintf \"qwe %Ld %Ld\\n\" x1 y1;\n Printf.eprintf \"qwe %Ld %Ld\\n\" x2 y2;\n Printf.eprintf \"qwe %Ld %Ld\\n\" x3 y3;*)\n Printf.printf \"%d %d\\n\" (x2 + x3 - x1) (y2 + y3 - y1);\n Printf.printf \"%d %d\\n\" (x3 + x1 - x2) (y3 + y1 - y2);\n Printf.printf \"%d %d\\n\" (x1 + x2 - x3) (y1 + y2 - y3);\n", "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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n \nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\n\nlet long x = Int64.of_int x\nlet short x = Int64.to_int x\n\nlet cross (x1,y1) (x2,y2) = (x1**y2) -- (y1**x2)\nlet ( --- ) (x1,y1) (x2,y2) = (x1--x2, y1--y2)\nlet ( +++ ) (x1,y1) (x2,y2) = (x1++x2, y1++y2) \n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x) \n\nlet () = \n let n = read_int () in\n let _ = read_long () in (* don't need s *)\n let p = Array.init n (fun _ ->\n let x = read_long() in\n (x, read_long())\n ) in\n\n let area a b c = Int64.abs (cross (b --- a) (c --- a)) in\n\n let rec expand no_change_count ar (a,b,c) =\n if no_change_count = 2 then (a,b,c) else\n let (ar', c') = maxf 0 (n-1) (fun c -> (area p.(a) p.(b) p.(c), c)) in\n if ar' > ar then expand 0 ar' (c',a,b) else expand (no_change_count+1) ar (c,a,b)\n in\n\n let (a,b,c) = expand 0 0L (0,1,2) in\n let (a,b,c) = (p.(a), p.(b), p.(c)) in\n \n let pr (x,y) = printf \"%Ld %Ld\\n\" x y in\n pr (a +++ b --- c);\n pr (b +++ c --- a);\n pr (c +++ a --- b)\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 \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let ps = Array.make n (0L, 0L) in\n let _ =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tps.(i) <- (x, y)\n done;\n in\n let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in\n let area3 (x, y) (x1, y1) (x2, y2) =\n x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2\n in\n let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =\n if x1 < x2\n then -1\n else if x1 > x2\n then 1\n else compare y1 y2\n in\n let _ = Array.sort cmp ps in\n (* Convex hull *)\n let p1 = ps.(0)\n and p2 = ps.(n - 1) in\n let up = Array.make n (0L, 0L) in\n let down = Array.make n (0L, 0L) in\n let pos_up = ref 0 in\n let pos_down = ref 0 in\n let hull =\n up.(!pos_up) <- p1;\n incr pos_up;\n down.(!pos_down) <- p1;\n incr pos_down;\n for i = 1 to n - 1 do\n if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (\n\twhile !pos_up >= 2 &&\n\t area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) >= 0L do\n\t decr pos_up\n\tdone;\n\tup.(!pos_up) <- ps.(i);\n\tincr pos_up;\n );\n if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (\n\twhile !pos_down >= 2 &&\n\t area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) <= 0L do\n\t decr pos_down\n\tdone;\n\tdown.(!pos_down) <- ps.(i);\n\tincr pos_down;\n );\n done;\n let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in\n for i = 0 to !pos_up - 1 do\n\thull.(i) <- up.(i)\n done;\n for i = !pos_down - 2 downto 1 do\n\thull.(!pos_down - 2 - i + !pos_up) <- down.(i)\n done;\n hull\n in\n let maxs = ref 0L in\n let b = ref (0, 0, 0) in\n (*for i = 0 to Array.length hull - 1 do\n let (x, y) = hull.(i) in\n\tPrintf.eprintf \"asd %Ld %Ld\\n\" x y\n done;*)\n for i = 0 to Array.length hull - 1 do\n let k = ref i in\n let s = ref 0L in\n\tfor j = i + 2 to Array.length hull - 1 do\n\t while !k < j - 1 &&\n\t Int64.abs (area3 hull.(i) hull.(j) hull.(!k + 1)) > !s\n\t do\n\t incr k;\n\t s := Int64.abs (area3 hull.(i) hull.(j) hull.(!k));\n\t done;\n\t if !maxs < !s then (\n\t maxs := !s;\n\t b := (i, j, !k);\n\t )\n\tdone;\n done;\n let (i, j, k) = !b in\n let (x1, y1) = hull.(i)\n and (x2, y2) = hull.(j)\n and (x3, y3) = hull.(k) in\n Printf.printf \"%Ld %Ld\\n\" (x2 +| x3 -| x1) (y2 +| y3 -| y1);\n Printf.printf \"%Ld %Ld\\n\" (x3 +| x1 -| x2) (y3 +| y1 -| y2);\n Printf.printf \"%Ld %Ld\\n\" (x1 +| x2 -| x3) (y1 +| y2 -| y3);\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 \"%d \" (fun s -> s) in\n let s = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let ps = Array.make n (0L, 0L) in\n let _ =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n\tps.(i) <- (x, y)\n done;\n in\n let cross x1 y1 x2 y2 = x1 *| y2 -| x2 *| y1 in\n let area3 (x, y) (x1, y1) (x2, y2) =\n x *| y1 +| x1 *| y2 +| x2 *| y -| x2 *| y1 -| x1 *| y -| x *| y2\n in\n let cmp ((x1 : int64), (y1 : int64)) (x2, y2) =\n if x1 < x2\n then -1\n else if x1 > x2\n then 1\n else compare y1 y2\n in\n let _ = Array.sort cmp ps in\n (* Convex hull *)\n let p1 = ps.(0)\n and p2 = ps.(n - 1) in\n let up = Array.make n (0L, 0L) in\n let down = Array.make n (0L, 0L) in\n let pos_up = ref 0 in\n let pos_down = ref 0 in\n let hull =\n up.(!pos_up) <- p1;\n incr pos_up;\n down.(!pos_down) <- p1;\n incr pos_down;\n for i = 1 to n - 1 do\n if i = n - 1 || area3 p1 ps.(i) p2 < 0L then (\n\twhile !pos_up >= 2 &&\n\t area3 up.(!pos_up - 2) up.(!pos_up - 1) ps.(i) > 0L do\n\t decr pos_up\n\tdone;\n\tup.(!pos_up) <- ps.(i);\n\tincr pos_up;\n );\n if i = n - 1 || area3 p1 ps.(i) p2 > 0L then (\n\twhile !pos_down >= 2 &&\n\t area3 down.(!pos_down - 2) down.(!pos_down - 1) ps.(i) < 0L do\n\t decr pos_down\n\tdone;\n\tdown.(!pos_down) <- ps.(i);\n\tincr pos_down;\n );\n done;\n let hull = Array.make (!pos_up + !pos_down - 2) ps.(0) in\n for i = 0 to !pos_up - 1 do\n\thull.(i) <- up.(i)\n done;\n for i = !pos_down - 2 downto 1 do\n\thull.(!pos_down - 2 - i + !pos_up) <- down.(i)\n done;\n hull\n in\n let maxs = ref 0L in\n let b = ref (0, 0, 0) in\n (*for i = 0 to Array.length hull - 1 do\n let (x, y) = hull.(i) in\n\tPrintf.printf \"asd %Ld %Ld\\n\" x y\n done;*)\n for i = 0 to Array.length hull - 1 do\n let k = ref i in\n let s = ref 0L in\n\tfor j = i + 2 to Array.length hull - 1 do\n\t while !k < j - 1 &&\n\t Int64.abs (area3 hull.(i) hull.(j) hull.(!k + 1)) > !s\n\t do\n\t incr k;\n\t s := Int64.abs (area3 hull.(i) hull.(j) hull.(!k));\n\t done;\n\t if !maxs < !s then (\n\t maxs := !s;\n\t b := (i, j, !k);\n\t )\n\tdone;\n done;\n let (i, j, k) = !b in\n let (x1, y1) = hull.(i)\n and (x2, y2) = hull.(j)\n and (x3, y3) = hull.(k) in\n Printf.printf \"%Ld %Ld\\n\" (x2 +| x3 -| x1) (y2 +| y3 -| y1);\n Printf.printf \"%Ld %Ld\\n\" (x3 +| x1 -| x2) (y3 +| y1 -| y2);\n Printf.printf \"%Ld %Ld\\n\" (x1 +| x2 -| x3) (y1 +| y2 -| y3);\n"}], "src_uid": "d7857d3e6b981c313ac16a9b4b0e1b86"} {"source_code": "(* CF odd game prob 276 B *)\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 has1 i s =\n\tif i >= (String.length s) then false\n\telse if s.[i] = '1' then true\n\telse has1 (i+1) s;;\n\nlet can_convert a b = \n\tif (String.length a) <> (String.length b) then false\n\telse \n\t\tlet ha = has1 0 a in\n\t\tlet hb = has1 0 b in\n\t\tha = hb;;\n\nlet main() =\n\tlet sa = rdln() in\n\tlet sb = rdln() in\n\tbegin\n\t\tprint_string (if can_convert sa sb then \"YES\" else \"NO\")\n\tend;;\n\t\t\nmain();;", "positive_code": [{"source_code": "let 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\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\n\nlet () = \n let a = read_line() in\n let b = read_line() in\n let na = String.length a in\n let nb = String.length b in\n let all_zeros s n = forall 0 (n-1) (fun i -> s.[i] = '0') in\n let answer = \n if na != nb then false\n else if all_zeros a na then all_zeros b nb \n else not (all_zeros b nb)\n in\n print_string (if answer then \"YES\\n\" else \"NO\\n\")\n"}], "negative_code": [], "src_uid": "113ae625e67c8ea5ab07be44c3b58a8f"} {"source_code": "let rv f p q = f q p\nlet fi = float_of_int\nlet (++),( ** ),(--),fi64,i64 = Int64.(add,mul,sub,to_float,of_int)\n;;\nScanf.(Array.(scanf \" %d %Ld %Ld\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0L in\n init n (fun left ->\n let left = left + 1 in\n total := !total ++ a.(left-1);\n let add = m -- (i64 n -- i64 left) in\n let limit = (i64 left) ** k in\n let add = min limit add in\n let r =\n if add < 0L then 0.\n else (fi64 (!total ++ add)) /. (fi left) in\n r\n )\n |> fold_left max 0.\n |> Printf.printf \"%.14f\"\n));;", "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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,k) = read_pair () in\n let m = read_int() in\n let a = Array.init n read_int in\n let s = Array.make (n+1) 0.0 in\n\n Array.sort compare a;\n\n for i=1 to n do\n s.(i) <- s.(i-1) +. (float a.(i-1))\n done;\n\n let answer = maxf 0 (min m (n-1)) (fun i ->\n (* i are removed *)\n let kept = s.(n) -. s.(i) in\n let j = float (n-i) in (* number left in the set *)\n let ninc = min (float (m-i)) (j *. (float k)) in\n (kept +. ninc) /. j\n ) in\n\n printf \"%f\\n\" answer\n"}, {"source_code": "let rv f p q = f q p\nlet fi = float_of_int\nlet (++),( ** ),fi64,i64 = Int64.(add,mul,to_float,of_int)\n;;\nScanf.(Array.(scanf \" %d %d %d\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0L in\n init n (fun left ->\n let left = left + 1 in\n total := !total ++ a.(left-1);\n let add = i64 @@ m - (n - left) in\n let limit = (i64 left) ** (i64 k) in\n let add = min limit add in\n let r =\n if add < 0L then 0.\n else (fi64 (!total ++ add)) /. (fi left) in\n (* Printf.printf \"%2d : %2Ld :: %2Ld :: %f\\n\" left add !total r; *)\n r\n )\n |> fold_left max (((fi64 @@ fold_left (++) 0L a)) /. (fi n))\n |> Printf.printf \"%.14f\"\n))"}], "negative_code": [{"source_code": "let rv f p q = f q p\nlet fi = float_of_int;;\nScanf.(Array.(scanf \" %d %d %d\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %d\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0 in\n init n (fun left ->\n let left = left + 1 in\n total := !total + a.(left-1);\n let add = m - (n - left) in\n let limit = left * k in\n let add = min limit add in\n let r =\n if add < 0 then 0.\n else (fi (!total + add)) /. (fi left) in\n (* Printf.printf \"%2d : %2d :: %2d :: %f\\n\" left add !total r; *)\n r\n )\n |> fold_left max 0.\n |> print_float\n))"}, {"source_code": "let rv f p q = f q p\nlet fi = float_of_int\nlet (++),i64f,i64 = Int64.(add,to_float,of_int)\n;;\nScanf.(Array.(scanf \" %d %d %d\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0L in\n init n (fun left ->\n let left = left + 1 in\n total := !total ++ a.(left-1);\n let add = m - (n - left) in\n let limit = left * k in\n let add = i64 @@ min limit add in\n let r =\n if add < 0L then 0.\n else (i64f (!total ++ add)) /. (fi left) in\n (* Printf.printf \"%2d : %2d :: %2d :: %f\\n\" left add !total r; *)\n r\n )\n |> fold_left max 0.\n |> print_float\n));;"}, {"source_code": "let rv f p q = f q p\nlet fi = float_of_int;;\nScanf.(Array.(scanf \" %d %d %d\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %d\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0 in\n init n (fun left ->\n let left = left + 1 in\n total := !total + a.(left-1);\n let add = m - (n - left) in\n let limit = left * k in\n let add = min limit add in\n let r = (fi (!total + add)) /. (fi left) in\n (* Printf.printf \"%2d : %2d :: %2d :: %f\\n\" left add !total r; *)\n r\n )\n |> fold_left max 0.\n |> print_float\n))"}, {"source_code": "let rv f p q = f q p\nlet fi = float_of_int\nlet (++),i64f,i64 = Int64.(add,to_float,of_int)\n;;\nScanf.(Array.(scanf \" %d %d %d\" @@ fun n k m ->\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v) in\n sort (rv compare) a;\n let total = ref 0L in\n init n (fun left ->\n let left = left + 1 in\n total := !total ++ a.(left-1);\n let add = m - (n - left) in\n let limit = left * k in\n let add = i64 @@ min limit add in\n let r =\n if add < 0L then 0.\n else (i64f (!total ++ add)) /. (fi left) in\n (* Printf.printf \"%2d : %2d :: %2d :: %f\\n\" left add !total r; *)\n r\n )\n |> fold_left max ((i64f @@ fold_left (++) 0L a) /. (fi n))\n |> print_float\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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,k) = read_pair () in\n let m = read_int() in\n let a = Array.init n read_int in\n let s = Array.make (n+1) 0.0 in\n\n Array.sort compare a;\n\n for i=1 to n do\n s.(i) <- s.(i-1) +. (float a.(i-1))\n done;\n\n let answer = maxf 0 (min m (n-1)) (fun i ->\n let kept = s.(n) -. s.(i) in\n let j = n-i in (* number left in the set *)\n let ninc = min (m-i) (j * k) in\n (kept +. (float ninc)) /. (float (n-i))\n ) in\n\n printf \"%f\" answer\n"}], "src_uid": "d6e44bd8ac03876cb03be0731f7dda3d"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\n\nlet init (x : int) (f : int -> 'a) : 'a list =\n let rec build k =\n if k = x then []\n else (f k) :: build (k + 1) in\n build 0\n;;\n \nlet run () = \n let n0 = scan_int () in\n let n1 = scan_int () in\n let n2 = scan_int () in\n let lst = \n if (n0 = 0 && n2 = 0) then begin\n let one = 10 :: (init ((n1 - 1) / 2) (fun _x -> 10)) in\n if (n1 mod 2 = 0) then 0 :: one\n else one\n end\n else if n1 = 0 && n2 = 0 then init (n0 + 1) (fun _x -> 0)\n else if (n0 = 0 && n1 = 0) then init (n2 + 1) (fun _x -> 1)\n else begin\n let zer = init (n0+1) (fun _x -> 0) in\n let two = init (n2+1) (fun _x -> 1) in\n if n0 > 0 then\n let one = init ((n1 - 1) / 2) (fun _x -> 10) in\n if n1 mod 2 = 0 then 1 :: (zer @ (one @ two))\n else (zer @ (one @ two))\n else\n let one = init (n1 / 2) (fun _x -> 10) in\n if n1 mod 2 = 1 then 0 :: (one @ two)\n else one @ two\n end in\n List.iter (printf \"%d\") lst;\n print_endline \"\"\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "(* Codeforces 1352 D Alice, Bob and Candies comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\n(* ============= above library below custom ========== *)\n\nlet rec bs_rec i bts n0 n1 n2 = \n\tlet ii = (i + 1) in\n\tif n0 > 0 then\n\t\tlet _ = (Bytes.set bts i '0') in\n\t\tbs_rec ii bts (n0-1) n1 n2\n\telse if n1 > 0 then\n\t\tlet ch = if (n1 mod 2) == 1 then '1' else '0' in\n\t\tlet _ = (Bytes.set bts i ch) in\n\t\tbs_rec ii bts 0 (n1-1) n2\n\telse if n2 > 0 then\n\t\tlet _ = (Bytes.set bts i '1') in\n\t\tbs_rec ii bts 0 0 (n2 - 1)\n\telse\n\t\t();;\t\n\nlet binary_string bts n0 n1 n2 n = \n\tif n0==0 && n1==0 then Bytes.fill bts 0 n '1'\n\telse if n1==0 && n2==0 then Bytes.fill bts 0 n '0'\n\telse\n \tlet _ = if (n1 mod 2) == 0 \n\t\t then \n\t\t\t\tbegin \n\t\t\t\t\tBytes.set bts 0 '1';\n\t\t\t\t\tBytes.set bts 1 '0'\n\t\t\t\tend\n\t\t\telse\n\t\t\t\t(Bytes.set bts 0 '0') in\n \tlet i0,nn1 = if (n1 mod 2) == 0 then 2,(n1 - 1) else 1,n1 in\n\t\tbs_rec i0 bts n0 nn1 n2;;\t\n \nlet do_one () = \n let n0 = gr () in\n let n1 = gr () in\n let n2 = gr () in\n\t\tlet n = n0 + n1 + n2 + 1 in\n\t\tlet bts = Bytes.create n in\n let _ = binary_string bts n0 n1 n2 n in\n\t\tlet bs = Bytes.to_string bts in\n \tPrintf.printf \"%s\\n\" bs;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\n\nlet init (x : int) (f : int -> 'a) : 'a list =\n let rec build k =\n if k = x then []\n else (f k) :: build (k + 1) in\n build 0\n;;\n \nlet run () = \n let n0 = scan_int () in\n let n1 = scan_int () in\n let n2 = scan_int () in\n let lst = \n if (n0 = 0 && n2 = 0) then begin\n let one = 10 :: (init ((n1 - 1) / 2) (fun _x -> 10)) in\n if (n1 mod 2 = 0) then 0 :: one\n else one\n end\n else if n1 = 0 && n2 = 0 then init (n0 + 1) (fun _x -> 0)\n else if (n0 = 0 && n1 = 0) then init (n2 + 1) (fun _x -> 1)\n else begin\n let zer = init (n0+1) (fun _x -> 0) in\n let two = init (n2+1) (fun _x -> 1) in\n if n0 > 0 then\n let one = init ((n1 - 1) / 2) (fun _x -> 10) in\n if n1 mod 2 = 0 then 1 :: (zer @ (one @ two))\n else (zer @ (one @ two))\n else\n let one = init (n1 / 2) (fun _x -> 10) in\n if n1 mod 2 = 0 then 0 :: (one @ two)\n else one @ two\n end in\n List.iter (printf \"%d\") lst;\n print_endline \"\"\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n"}], "src_uid": "4bbb078b66b26d6414e30b0aae845b98"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n for i = 1 to n do\n let l = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let r = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let len = r - l + 1 in\n let s2 = String.copy s in\n\tfor j = l to r do\n\t let p = ((j - l - k) mod len + len) mod len + l in\n\t s.[j] <- s2.[p]\n\tdone;\n done;\n Printf.printf \"%s\\n\" s\n", "positive_code": [{"source_code": "open Array;;\n\nlet string_to_list s =\n let rec explode i l =\n if ( i < 0 ) then l\n else explode (i-1) (s.[i] :: l) \n in explode ( String.length s - 1) [];;\n\n\nlet licz x a b k =\n let y = init ( Array.length x ) (fun i -> x.(i) )\n in\n for i = a-1 to b-1 do\n set y i x.( ( ( (i-a+1-k) mod (b-a+1) ) + (b-a+1) ) mod (b-a+1) + a-1 )\n done;\n y;;\n\nlet case x =\n Scanf.bscanf Scanf.Scanning.stdin \"%d %d %d\\n\" ( licz x );;\n\n\nlet x = Array.of_list ( string_to_list ( read_line() ) );;\n\nlet rec repeat x f y =\n if x > 0 then\n begin\n let z = f y in\n repeat (x-1) f z\n end\n else y;;\n\niter print_char ( repeat ( read_int() ) case x );;\n"}], "negative_code": [], "src_uid": "501b60c4dc465b8a60fd567b208ea1e3"} {"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet a=read_int();;\nlet b=read_int();;\nlet c=read_int();;\nlet tab=Array.make 5 0;;\ntab.(1)<-a;;\ntab.(2)<-b;;\ntab.(3)<-c;;\nlet d=Scanf.scanf \"%d\\n\" (fun x->x);;\ntab.(4)<-d;;\nlet s=Scanf.scanf \"%s\" (fun x->x);;\nlet n=String.length(s);;\nlet nb=ref 0;;\nfor i=0 to n-1 do\n nb:= !nb+tab.(int_of_char(s.[i])-48)\ndone;;\nprint_int !nb;;\n", "positive_code": [{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule H = Hashtbl\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\nlet rec bsearch_min a b test =\n if b - a = 1 then b else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_min a mid test else \n bsearch_min mid b test\nlet rec bsearch_max a b test = \n if b - a = 1 then a else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_max mid b test else \n bsearch_max a mid test\n(* int *)\nlet sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)\nlet sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i) \n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* int, int *)\nlet (++) (a,b) (c,d) = (a+c,b+d)\nlet (--) (a,b) (c,d) = (a-c,b-d)\n(* number theory *)\nlet sieve_under len = (* len > 0 *)\n let sieve = Array.make len true in \n Array.fill sieve 0 (min len 2) false;\n let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in \n for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;\n sieve\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 128 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create (4*1024) in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_int n = printf \"%d\\n\" n\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\n\nlet _ = \n let arr = init 4 (fun i -> read_int()) in\n let str = read_line() in \n \n let len = S.length str in \n let rec run i acc = \n if i = len then acc else \n run (i+1) (acc + arr.(int_of_char str.[i] - 49)) \n in \n printf \"%d\\n\" (run 0 0)"}, {"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 digit_to_int c = \n Pervasives.int_of_char c - Pervasives.int_of_char '0'\n\nlet input () =\n let costs = Scanf.scanf \"%d %d %d %d \" (fun a b c d -> [a; b; c; d]) in\n let moves = Scanf.scanf \"%s\" (fun s -> List.map digit_to_int (str_to_list s)) in\n (costs, moves)\n\nlet solve (costs, moves) =\n List.fold_left (+) 0 (List.map (fun n -> List.nth costs (n - 1)) moves)\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (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 digit_to_int c = \n Pervasives.int_of_char c - Pervasives.int_of_char '0'\n\nlet input () =\n let costs = Scanf.scanf \"%d %d %d %d \" (fun a b c d -> [a; b; c; d]) in\n let moves = Scanf.scanf \"%s\" (fun s -> List.map digit_to_int (str_to_list s)) in\n (costs, moves)\n\nlet solve (costs, moves) =\n let rec loop list i total =\n match list with\n | (head :: tail) -> \n let quantity = List.length (List.filter (fun n -> n = i) moves) in\n let curr_cost = head * quantity in\n loop tail (i + 1) (total + curr_cost)\n | [] -> total\n in loop costs 1 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"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 a = Array.init 4 (fun _ -> read_int()) in\n let s = read_string () in\n\n let n = String.length s in\n\n let t = ref 0 in\n\n for i=0 to n-1 do\n let d = (int_of_char s.[i]) - (int_of_char '1') in\n t := !t + a.(d)\n done;\n\n printf \"%d\\n\" !t\n"}], "negative_code": [], "src_uid": "db9065d975878227a749083f0036a169"} {"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\n\nlet long x = Int64.of_int x\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_long _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x) \nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\n \nlet () =\n let n = read_int() in\n let a = Array.make n 0L in\n let b = Array.make n 0 in\n let c = Array.make n 0 in\n for i=0 to n-1 do\n a.(i) <- read_long ();\n b.(i) <- read_int ();\n c.(i) <- read_int (); \n done;\n\n let tree = Array.make n [] in\n\n for i=1 to n-1 do\n let (u,v) = read_pair() in\n let (u,v) = (u-1,v-1) in\n tree.(u) <- v::tree.(u);\n tree.(v) <- u::tree.(v) \n done;\n\n let rec dfs p u mincost =\n (* return (excess_ones, excess_zeros, cost) for this subtree *)\n let rec loop li ac0 ac1 ac_cost =\n match li with\n\t| [] -> (ac0, ac1, ac_cost)\n\t| v::tail ->\n\t if v = p then loop tail ac0 ac1 ac_cost else\n\t let (v0, v1, v_cost) = dfs u v (min mincost a.(v)) in\n\t loop tail (ac0+v0) (ac1+v1) (ac_cost ++ v_cost)\n in\n let (ac0, ac1, ac_cost) = loop tree.(u) 0 0 0L in\n let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in\n let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in \n let change = min ac0 ac1 in\n let cost = ac_cost ++ 2L ** (long change) ** mincost in\n (ac0 - change, ac1 - change, cost)\n in\n \n let (c0, c1, cost) = dfs (-1) 0 a.(0) in\n printf \"%Ld\\n\" (if c0 + c1 <> 0 then -1L else cost)\n", "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 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\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_long _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x) \nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\n \nlet () =\n let n = read_int() in\n let a = Array.make n 0L in\n let b = Array.make n 0 in\n let c = Array.make n 0 in\n for i=0 to n-1 do\n a.(i) <- read_long ();\n b.(i) <- read_int ();\n c.(i) <- read_int (); \n done;\n\n let tree = Array.make n [] in\n\n for i=1 to n-1 do\n let (u,v) = read_pair() in\n let (u,v) = (u-1,v-1) in\n tree.(u) <- v::tree.(u);\n tree.(v) <- u::tree.(v) \n done;\n\n let ones_there = sum 0 (n-1) (fun i -> b.(i)) in\n let ones_wanted = sum 0 (n-1) (fun i -> c.(i)) in\n if ones_there <> ones_wanted then (\n printf \"-1\\n\"\n ) else (\n\n (*\n let ex = Array.make_matrix 2 n 0 in (*excess 0s and 1s *)\n\n let rec dfs0 p u =\n let rec loop li ac0 ac1 = \n\tmatch li with\n\t | [] -> (ac0, ac1)\n\t | v::tail ->\n\t if v = p then loop tail ac0 ac1 else\n\t let (v0, v1) = dfs0 u v in\n\t loop tail (ac0+v0) (ac1+v1)\n in\n let (ac0, ac1) = loop tree.(u) 0 0 in\n let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in\n let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in \n(* let change = min ac0 ac1 in\n let (ac0, ac1) = (ac0 - change, ac1 - change) in *)\n ex.(0).(u) <- ac0;\n ex.(1).(u) <- ac1;\n (ac0, ac1)\n in\n let _ = dfs (-1) 0 in\n *)\n \n let rec dfs p u mincost =\n (* return (excess_ones, excess_zeros, cost) for this subtree *)\n let rec loop li ac0 ac1 ac_cost =\n\tmatch li with\n\t | [] -> (ac0, ac1, ac_cost)\n\t | v::tail ->\n\t if v = p then loop tail ac0 ac1 ac_cost else\n\t let (v0, v1, v_cost) = dfs u v (min mincost a.(v)) in\n\t loop tail (ac0+v0) (ac1+v1) (ac_cost ++ v_cost)\n in\n let (ac0, ac1, ac_cost) = loop tree.(u) 0 0 0L in\n let ac0 = ac0 + (if b.(u) = 0 && c.(u) = 1 then 1 else 0) in\n let ac1 = ac1 + (if b.(u) = 1 && c.(u) = 0 then 1 else 0) in \n let change = min ac0 ac1 in\n let cost = ac_cost ++ 2L ** (long change) ** mincost in\n (ac0 - change, ac1 - change, cost)\n in\n\n let (_, _, cost) = dfs (-1) 0 a.(0) in\n printf \"%Ld\\n\" cost\n )\n"}], "negative_code": [], "src_uid": "4dce15ff1446b5af2c5b49ee2d30bbb8"} {"source_code": "(* It's a DP algorithm. Keep y_opt.(i) which is the natural place\n where the point y.(i) will land when considering only points 0, 1,\n 2... i.\n \n To compute y_opt.(i) we assume we have already computed the\n previous ones. What we do now is see if y.(i) acting alone would\n be within the window defined by y_opt.(i-1). If it is, we're done\n with y_opt.(i). Say y.(i) is too high to be compatible with\n y_opt.(i-1). Then we glue these two points together by asserting\n y.(i)-y.(i-1)=b. (Analogously, if y.(i) is too low compared to\n y_opt.(i-1) we assert y.(i)-y.(i-1)=a instead.) This pair of\n points has a natural position uninfluenced by anything outside of\n them. If this position is compatible with y_opt.(i-2) then we're\n done, otherwise we add y.(i-2) to the chain and continue. So the\n elements are chained together by a sequence of as and bs,\n intermixed.\n\n We can prove by induction that the solution that this finds is\n optimal. The base case is when y.(i) is within the window allowed\n by y_opt.(i-1). Clearly this is the right answer. Now suppose\n that we have established that in the optimal solution some chain of\n differences relating y.(k),...,y.(i-2), y.(i) must occur. This\n means that when searching for the optimal solution we need only\n consider these values moving in lockstep as specified by the chain.\n Looking at point k-1 if the chain is too low, then the optimal\n solution must also have y.(k-1) in the chain being a below y.(k),\n and if point k-1 is too high then it must be in the chain b below\n y.(i). (The intuition is that of a spring. If you move your\n finger toward a spring and you touch the spring, pushing harder on\n the spring will keep your finger in contact with the spring. The\n spring will not suddenly pull away from your finger as you push\n harder. The (x-y)^2 cost function ensures that this is the correct\n model.)\n\n So the algorithm is O(n^2). It might be possible to work out a\n version of this algorithm that is O(n log n) by keeping the chains\n in a search tree. Then instead of starting from scratch each time\n when adding a new point, it would edit the current chain. It is\n not clear that this can be made to work.\n\n Danny Sleator \n*)\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = Scanf.bscanf Scanf.Scanning.stdib \" %f \" (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.0\nlet sq x = x *. x\nlet (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)\n\nlet quad_min (a,b,c) = -. (b /. (2.0 *. a))\n (* ax^2 + bx + c is our quadratic. Return the value of x that minimizes it *)\n (* a cannot be zero *)\n\nlet () =\n let n = read_int 0 in\n let q0 = read_float 0 in\n let a0 = read_float 0 in\n let b0 = read_float 0 in\n\n let x = Array.init n read_float in\n let y_opt = Array.copy x in\n let chain = Array.make n 0.0 in\n\n let bound h v = max (1.0+.h) (min q0 v) in\n\n let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else\n (* Set the group of points j+1, j+2, ... i all to differ by cumulative h\n the quadratic represented by this group is q. *)\n let yi_nat = bound h (quad_min q) in\n if y_opt.(j) < yi_nat -. h -. b0 then \n\tlet ny = x.(j) +. h +. b0 in\n\t chain.(j) <- b0;\n\t pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else if y_opt.(j) > yi_nat -. h -. a0 then \n\tlet ny = x.(j) +. h +. a0 in\n\t chain.(j) <- a0;\n\t pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else \n\t(yi_nat, j)\n in\n\n for i=1 to n-1 do\n let myq = (1.0, -2.0*.x.(i), sq x.(i)) in\n let (yopt, j) = pull_chain (i-1) 0.0 myq in\n\ty_opt.(i) <- yopt;\n done;\n\n let rec fill_in_y i = if i<0 then () else\n let (_, j) = pull_chain (i-1) 0.0 (1.0, -2.0*.x.(i), sq x.(i)) in\n\tfor k=i-1 downto j+1 do\n\t y_opt.(k) <- y_opt.(k+1) -. chain.(k);\n\tdone;\n\tfill_in_y j\n in\n fill_in_y (n-1);\n \n let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in\n\n\tfor i=0 to n-1 do \n\t Printf.printf \"%.8f \" y_opt.(i);\n\tdone;\n\tprint_newline();\n\tPrintf.printf \"%.8f\\n\" total;\n", "positive_code": [{"source_code": "(* It's a DP algorithm. Keep y_opt.(i) which is the natural place\n where the point y.(i) will land when considering only points 0, 1,\n 2... i.\n \n To compute y_opt.(i) we assume we have already computed the\n previous ones. What we do now is see if y.(i) acting alone would\n be within the window defined by y_opt.(i-1). If it is, we're done\n with y_opt.(i). Say y.(i) is too high to be compatible with\n y_opt.(i-1). Then we glue these two points together by asserting\n y.(i)-y.(i-1)=b. (Analogously, if y.(i) is too low compared to\n y_opt.(i-1) we assert y.(i)-y.(i-1)=a instead.) This pair of\n points has a natural position uninfluenced by anything outside of\n them. If this position is compatible with y_opt.(i-2) then we're\n done, otherwise we add y.(i-2) to the chain and continue. So the\n elements are chained together by a sequence of as and bs,\n intermixed.\n\n We can prove by induction that the solution that this finds is\n optimal. The base case is when y.(i) is within the window allowed\n by y_opt.(i-1). Clearly this is the right answer. Now suppose\n that we have established that in the optimal solution some chain of\n differences relating y.(k),...,y.(i-2), y.(i) must occur. This\n means that when searching for the optimal solution we need only\n consider these values moving in lockstep as specified by the chain.\n Looking at point k-1 if the chain is too low, then the optimal\n solution must also have y.(k-1) in the chain being a below y.(k),\n and if point k-1 is too high then it must be in the chain b below\n y.(i). (The intuition is that of a spring. If you move your\n finger toward a spring and you touch the spring, pushing harder on\n the spring will keep your finger in contact with the spring. The\n spring will not suddenly pull away from your finger as you push\n harder. The (x-y)^2 cost function ensures that this is the correct\n model.)\n\n So the algorithm is O(n^2). It might be possible to work out a\n version of this algorithm that is O(n log n) by keeping the chains\n in a search tree. Then instead of starting from scratch each time\n when adding a new point, it would edit the current chain. It is\n not clear that this can be made to work.\n\n Danny Sleator \n*)\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = Scanf.bscanf Scanf.Scanning.stdib \" %f \" (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.0\nlet sq x = x *. x\nlet (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)\n\nlet quad_min (a,b,c) = -. (b /. (2.0 *. a))\n (* ax^2 + bx + c is our quadratic. Return the value of x that minimizes it *)\n (* a cannot be zero *)\n\nlet () =\n let n = read_int 0 in\n let q0 = read_float 0 in\n let a0 = read_float 0 in\n let b0 = read_float 0 in\n\n let x = Array.init n read_float in\n let y_opt = Array.copy x in\n let chain = Array.make n 0.0 in\n\n let bound h v = max (1.0+.h) (min q0 v) in\n\n let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else\n (* Set the group of points j+1, j+2, ... i all to differ by cumulative h\n the quadratic represented by this group is q. *)\n let yi_nat = bound h (quad_min q) in\n if y_opt.(j) < yi_nat -. h -. b0 then \n\tlet ny = x.(j) +. h +. b0 in\n\t chain.(j) <- b0;\n\t pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else if y_opt.(j) > yi_nat -. h -. a0 then \n\tlet ny = x.(j) +. h +. a0 in\n\t chain.(j) <- a0;\n\t pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else \n\t(yi_nat, j)\n in\n\n for i=1 to n-1 do\n let myq = (1.0, -2.0*.x.(i), sq x.(i)) in\n let (yopt, j) = pull_chain (i-1) 0.0 myq in\n\ty_opt.(i) <- yopt;\n done;\n\n let rec fill_in_y i = if i<0 then () else\n let (_, j) = pull_chain (i-1) 0.0 (1.0, -2.0*.x.(i), sq x.(i)) in\n\tfor k=i-1 downto j+1 do\n\t y_opt.(k) <- y_opt.(k+1) -. chain.(k);\n\tdone;\n\tfill_in_y j\n in\n fill_in_y (n-1);\n \n let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in\n\n\tfor i=0 to n-1 do \n\t Printf.printf \"%.8f \" y_opt.(i);\n\tdone;\n\tPrintf.printf \"%.8f\\n\" total;\n"}, {"source_code": "(* It's a DP algorithm. Keep y_opt.(i) which is the natural place\n where the point y.(i) will land when considering only points 0, 1,\n 2... i.\n \n To compute y_opt.(i) we assume we have already computed the\n previous ones. What we do now is see if y.(i) acting alone would\n be within the window defined by y_opt.(i-1). If it is, we're done\n with y_opt.(i). Say y.(i) is too high to be compatible with\n y_opt.(i-1). Then we glue fix y.(i-1)=y.(i)-b and compute the\n natural position for this pair of points using the sum of their\n potentials. If this is compatible with y_opt.(i-2) then we're\n done, otherwise we add that to the group and continue. The chain\n can consist of a sequence of as and bs, intermixed.\n\n So the algorithm is O(n^2). It could be optimized as follows.\n Remember how far back the block went and continuing from where we\n left off computing y_opt.(i). So if y.(i+1) also is pulling up we\n can continue from where we left off. Can this be turned into an\n O(n) algorithm?\n*)\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = Scanf.bscanf Scanf.Scanning.stdib \" %f \" (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.0\n\nlet sq x = x *. x\n\nlet (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)\n\nlet quad_min (a,b,c) = \n (* ax^2 + bx + c is our quadratic. Return the value of x that minimizes it *)\n (* a cannot be zero *)\n -. (b /. (2.0 *. a))\n\nlet quad_eval (a,b,c) x = a *. (sq x) +. b *. x +. c\n\nlet () =\n let n = read_int 0 in\n let q0 = read_float 0 in\n let a0 = read_float 0 in\n let b0 = read_float 0 in\n\n let x = Array.init n read_float in\n let y_opt = Array.copy x in\n let chain = Array.make n 0.0 in\n let jarray = Array.make n (-1) in\n\n let bound h v = max (1.0+.h) (min q0 v) in\n\n let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else\n (* set the group of points j+1, j+2, ... i all to differ by cumulative h\n the quadratic represented by this group is q. Find its natural position. *)\n let yi_nat = bound h (quad_min q) in\n if y_opt.(j) < yi_nat -. h -. b0 then \n\tlet ny = x.(j) +. h +. b0 in\n\t chain.(j) <- b0;\n\t pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else if y_opt.(j) > yi_nat -. h -. a0 then \n\tlet ny = x.(j) +. h +. a0 in\n\t chain.(j) <- a0;\n\t pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))\n else \n\t(yi_nat, j)\n in\n\n for i=1 to n-1 do\n let myq = (1.0, -2.0*.x.(i), sq x.(i)) in\n let (yopt, j) = pull_chain (i-1) 0.0 myq in\n\ty_opt.(i) <- yopt;\n\tjarray.(i) <- j;\n done;\n\n let rec fill_in_y i = if i<0 then () else\n let myq = (1.0, -2.0*.x.(i), sq x.(i)) in\n let (_, j) = pull_chain (i-1) 0.0 myq in\n let rec loop k = if k<=j then () else\n\tlet delta = chain.(k) in\n\t y_opt.(k) <- y_opt.(k+1) -. delta;\n\t loop (k-1)\n in\n\tloop (i-1);\n\tfill_in_y j\n in\n\n fill_in_y (n-1);\n \n let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in\n\n\tfor i=0 to n-1 do \n\t Printf.printf \"%.8f \" y_opt.(i);\n\tdone;\n\tprint_newline();\n\tPrintf.printf \"%.8f\\n\" total;\n"}], "negative_code": [], "src_uid": "d212e5a9b67c0ced9d85b94ecf0504ae"} {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [1] (a-1)\n\t | x :: [] -> ah (x :: x :: []) a\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [1] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n", "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 n = read_int() in\n let a = read_int() in\n let b = read_int() in\n\n let m = 50000 in\n \n(* i = seen already. current = value of last one seen. sum=sum of all previous*)\n let rec loop i sum current a b print = \n if print then Printf.printf \"%d \" current;\n if current > m then false\n else if i = n then a+b=0\n else (\n if b>0 then loop (i+1) (sum+(2*current)) (2*current) a (b-1) print\n else if a>0 then (\n\tif (current+1 > sum) then loop (i+1) (sum+current) current a b print else loop (i+1) (sum+current+1) (current+1) (a-1) b print\n ) else loop (i+1) (sum+current) current a b print\n )\n in\n if not (loop 1 1 1 a b false) then Printf.printf \"-1\"\n else ignore (loop 1 1 1 a b true);\n print_newline()\n"}], "negative_code": [{"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [1] (a-1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [1] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [2] (a - 1)\n\t | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*)\n\tif lst = [] then\n\t ogo [1] b\n\telse\n\t ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [2] (a - 1)\n\t | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*)\n\tif lst = [] then\n\t ogo [1] b\n\telse\n\t ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [2] a\n\t | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n match b with\n\t0 -> lst\n | _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [1] (a - 1)\n\t | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [1] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"source_code": "let rec print_list lst =\n match lst with\n | [] -> ()\n | h :: [] -> print_int h\n | h :: t -> Printf.printf \"%s \" (string_of_int h); print_list t\nin\nlet make_ah_ogo a b =\n (* Sum of list *)\n let rec lsum lst acc =\n match lst with\n\t[] -> acc\n | h :: tail -> lsum tail (acc + h)\n in\n let rec ogo lst b =\n let cur_sum = lsum lst 0 in\n if lst = [] then\n ogo [1] b\n else\n match b with\n\t 0 -> lst\n\t| _ -> (*Printf.printf \"Cur ogo sum:%d\\n\" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)\n in\n let rec ah lst a =\n match a with\n\t0 -> lst\n | _ -> match lst with\n\t [] -> ah [2] (a - 1)\n\t | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)\n\t | h :: t -> (*Printf.printf \"Incr ah %d\\n\" h;*) ah (h + 1 :: h :: t) (a - 1)\n in\n let logo = ogo [] b in (* Ogo! list *)\n ah logo a (* Ogo! + Ah! list *)\nin\nlet create inp =\n let parse_input x =\n let rx = Str.regexp \"\\\\([0-9]+\\\\) \\\\([0-9]+\\\\) \\\\([0-9]+\\\\)\" in\n if Str.string_match rx x 0 then\n let i ii = int_of_string (Str.matched_group ii x) in\n Some (i 1, i 2, i 3)\n else\n None\n in\n let n, a, b = match parse_input inp with\n None -> raise Not_found\n | Some (x1, x2, x3) -> x1, x2, x3\n in\n (*Printf.printf \"n=%d a=%d b=%d\\n\" n a b;*)\n let result = make_ah_ogo a b in\n let create_remain todo =\n let rec rem list todo =\n match todo with\n\t x when x <= 0 -> list\n\t| _ -> rem (1 :: list) (todo - 1)\n in\n rem [] todo\n in\n let len_remain = n - (List.length result) in\n (*Printf.printf \"Remain to %d length: %d; done %d\\n\" n len_remain (List.length result);*)\n let result = (List.rev result) @ (create_remain len_remain) in\n let len = List.length result in\n if len <= n then\n result\n else begin\n [-1]\n end\nin\nlet init_data = read_line () in\nlet init_list = create init_data in\nlet result_list = init_list in\nprint_list result_list\n"}, {"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 n = read_int() in\n let a = read_int() in\n let b = read_int() in\n\n let m = 50000 in\n \n(* i = seen already. current = value of last one seen *)\n let rec loop i current a b print = \n if print then Printf.printf \"%d \" current;\n if current > m then false\n else if i = n then true \n else (\n if b>0 then loop (i+1) (2*current) a (b-1) print\n else if a>0 then loop (i+1) (current+1) (a-1) b print\n else loop (i+1) current a b print\n )\n in\n if loop 1 1 a b false \n then ignore (loop 1 1 a b true)\n else Printf.printf \"-1\";\n print_newline()\n"}, {"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 n = read_int() in\n let a = read_int() in\n let b = read_int() in\n\n let m = 50000 in\n \n(* i = seen already. current = value of last one seen *)\n let rec loop i current a b print = \n if print then Printf.printf \"%d \" current;\n if current > m then false\n else if i = n then true \n else (\n if b>0 then loop (i+1) (2*current) a (b-1) print\n else if a>0 then loop (i+1) (current+1) (a-1) b print\n else loop (i+1) current a b print\n )\n in\n if a=n-1 || (not (loop 1 1 a b false)) then Printf.printf \"-1\"\n else ignore (loop 1 1 a b true);\n print_newline()\n"}, {"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 n = read_int() in\n let a = read_int() in\n let b = read_int() in\n\n let m = 50000 in\n \n(* i = seen already. current = value of last one seen *)\n let rec loop i current a b print = \n if print then Printf.printf \"%d \" current;\n if current > m then false\n else if i = n then true \n else (\n if a>0 then loop (i+1) (2*current) (a-1) b print\n else if b>0 then loop (i+1) (current+1) a (b-1) print\n else loop (i+1) current a b print\n )\n in\n if loop 1 1 a b false \n then ignore (loop 1 1 a b true)\n else Printf.printf \"-1\";\n print_newline()\n"}, {"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 n = read_int() in\n let a = read_int() in\n let b = read_int() in\n\n let m = 50000 in\n \n(* i = seen already. current = value of last one seen *)\n let rec loop i current a b print = \n if print then Printf.printf \"%d \" current;\n if current > m then false\n else if i = n then true \n else (\n if b>0 then loop (i+1) (2*current) a (b-1) print\n else if a>0 then loop (i+1) (current+1) (a-1) b print\n else loop (i+1) current a b print\n )\n in\n if (a=n-1 && n>1) || (not (loop 1 1 a b false)) then Printf.printf \"-1\"\n else ignore (loop 1 1 a b true);\n print_newline()\n"}], "src_uid": "573995cbae2a7b28ed92d71c48cd9039"} {"source_code": "Scanf.(Array.(scanf \" %d\" @@ fun q ->\n init q (fun _ -> scanf \" %d %s\" @@ fun _ s ->\n Printf.(\n if String.length s = 2 && s.[0] >= s.[1] then printf \"NO\\n\"\n else printf \"YES\\n2\\n%c %s\\n\" s.[0] @@ String.sub s 1 (String.length s - 1)))))", "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_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 q = gi 0 in\n rep 1L q (fun _ ->\n let n = gi 0 in\n let s = scanf \" %s\" @@ id in\n if String.length s = 2 && s.[0] >= s.[1] then (\n printf \"NO\\n\"\n ) else (\n printf \"YES\\n2\\n%c %s\\n\" s.[0] @@ String.sub s 1 (String.length s-$1)\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_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 q = gi 0 in\n rep 1L q (fun _ ->\n let n = gi 0 in\n let s = scanf \" %s\" @@ id in\n let f = ref true in\n String.iter (fun c -> if c <> s.[0] then f := false) s;\n if !f && String.length s = 2 then (\n printf \"NO\\n\"\n ) else (\n printf \"YES\\n2\\n%c %s\\n\" s.[0] @@ String.sub s 1 (String.length s-$1)\n )\n (* let prev = ref 0L in\n let a = ref 0L in\n let ex = make 10 false in\n String.iter (fun c ->\n let p = !a * 10L + i64 (int_of_char c -$ int_of_char '0') in\n if ex.(int_of_char c) then (\n if !prev > p then (\n\n )\n ) else\n if !prev > p then (\n\n )\n ) *)\n )\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "9f87a89c788bd7c7b66e51db9fe47e46"} {"source_code": "let n = read_int ()\n\nlet rec find a b i m = if i>m-2 then -1 else if String.sub a i 2 = b then i else find a b (i+1) m ;;\n\nfor i=1 to n do\n let s = read_line () in\n let z = String.length s in\n let t = find s \"11\" 0 z in\n if t = -1 then print_string \"YES\\n\" else\n if find (String.sub s t (z-t)) \"00\" 0 (z-t) = -1 then print_string \"YES\\n\" else print_string \"NO\\n\"\ndone\n", "positive_code": [{"source_code": "let n = read_int () ;;\r\n\r\nlet translate_to str=\r\nlet len = String.length(str) in\r\nlet rec sup_fun i l=\r\nif i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in\r\nsup_fun (len-1) [];;\r\n\r\nlet rec read_fucking_sheet n =\r\nif n = 0 then [] \r\nelse (translate_to (read_line ()) :: read_fucking_sheet (n-1)) \r\n;;\r\n\r\nlet rec print_yes t =\r\nif t = true then print_string \"YES\"\r\nelse print_string \"NO\"\r\n;;\r\n\r\nlet rec solve l flag =\r\nmatch l with \r\nhd :: hd1 :: tl -> \r\n\tif flag = 1 && hd = 1\r\n\t\tthen (solve (hd1 :: tl) 1)\r\n\telse if flag = 1 && hd = 0 && hd1 = 0\r\n\t\tthen false\r\n\telse if flag = 1 && hd = 0 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n\telse if flag = 0 && hd = 0\r\n\t\tthen (solve (hd1 :: tl) 0)\r\n\telse if flag = 0 && hd = 1 && hd1 = 0\r\n\t\tthen (solve tl 1) || (solve tl 0 )\r\n\telse if flag = 0 && hd = 1 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n else false\r\n|_-> true\r\n;;\r\n\r\nlet rec print_list l =\r\nmatch l with \r\nhd:: tl -> print_int hd ; print_list tl\r\n|_-> print_string \" \" ;; \r\n\r\nlet rec flum l =\r\nmatch l with \r\nhd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string \"\\n\" ; flum tl\r\n|_-> () ;;\r\n\r\n(*print_list (translate_to \"111000\") ;;*)\r\n\r\nflum (List.rev(read_fucking_sheet n))\r\n\r\n(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)\r\n\r\n(*let spisok = [1;1;0;0] ;;\r\n\r\nprint_yes (solve spisok 0) ;;*)"}], "negative_code": [{"source_code": "let n = read_int () ;;\r\n\r\nlet translate_to str=\r\nlet len = String.length(str) in\r\nlet rec sup_fun i l=\r\nif i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in\r\nsup_fun (len-1) [];;\r\n\r\nlet rec read_fucking_sheet n =\r\nif n = 0 then [] \r\nelse (translate_to (read_line ()) :: read_fucking_sheet (n-1)) \r\n;;\r\n\r\nlet rec print_yes t =\r\nif t = true then print_string \"YES\"\r\nelse print_string \"NO\"\r\n;;\r\n\r\nlet rec solve l flag =\r\nmatch l with \r\nhd :: hd1 :: tl -> \r\n\tif flag = 1 && hd = 1\r\n\t\tthen (solve (hd1 :: tl) 1)\r\n\telse if flag = 1 && hd = 0 && hd1 = 0\r\n\t\tthen false\r\n\telse if flag = 1 && hd = 0 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n\telse if flag = 0 && hd = 0\r\n\t\tthen (solve (hd1 :: tl) 0)\r\n\telse if flag = 0 && hd = 1 && hd1 = 0\r\n\t\tthen (solve tl 1) || (solve tl 0 )\r\n\telse if flag = 0 && hd = 1 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n else false\r\n|_-> true\r\n;;\r\n\r\nlet rec print_list l =\r\nmatch l with \r\nhd:: tl -> print_int hd ; print_list tl\r\n|_-> print_string \" \" ;; \r\n\r\nlet rec flum l =\r\nmatch l with \r\nhd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string \"\\n\" ; flum tl\r\n|_-> () ;;\r\n\r\n(*print_list (translate_to \"111000\") ;;*)\r\n\r\nlet rec revers l =\r\nmatch l with \r\nhd::tl -> hd :: (revers tl)\r\n|_-> []\r\n;;\r\n\r\nflum (revers(read_fucking_sheet n))\r\n\r\n(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)\r\n\r\n(*let spisok = [1;1;0;0] ;;\r\n\r\nprint_yes (solve spisok 0) ;;*)\r\n"}, {"source_code": "let n = read_int () ;;\r\n\r\nlet translate_to str=\r\nlet len = String.length(str) in\r\nlet rec sup_fun i l=\r\nif i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in\r\nsup_fun (len-1) [];;\r\n\r\nlet rec read_fucking_sheet n =\r\nif n = 0 then [] \r\nelse (translate_to (read_line ()) :: read_fucking_sheet (n-1)) \r\n;;\r\n\r\nlet rec print_yes t =\r\nif t = true then print_string \"YES\"\r\nelse print_string \"NO\"\r\n;;\r\n\r\nlet rec solve l flag =\r\nmatch l with \r\nhd :: hd1 :: tl -> \r\n\tif flag = 1 && hd = 1\r\n\t\tthen (solve (hd1 :: tl) 1)\r\n\telse if flag = 1 && hd = 0 && hd1 = 0\r\n\t\tthen false\r\n\telse if flag = 1 && hd = 0 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n\telse if flag = 0 && hd = 0\r\n\t\tthen (solve (hd1 :: tl) 0)\r\n\telse if flag = 0 && hd = 1 && hd1 = 0\r\n\t\tthen (solve tl 1) || (solve tl 0 )\r\n\telse if flag = 0 && hd = 1 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n else false\r\n|_-> true\r\n;;\r\n\r\nlet rec print_list l =\r\nmatch l with \r\nhd:: tl -> print_int hd ; print_list tl\r\n|_-> print_string \" \" ;; \r\n\r\nlet rec flum l =\r\nmatch l with \r\nhd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string \"\\n\" ; flum tl\r\n|_-> () ;;\r\n\r\n(*print_list (translate_to \"111000\") ;;*)\r\n\r\nflum (read_fucking_sheet n)\r\n\r\n(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)\r\n\r\n(*let spisok = [1;1;0;0] ;;\r\n\r\nprint_yes (solve spisok 0) ;;*)"}, {"source_code": "let n = read_int () ;;\r\n\r\nlet translate_to str=\r\nlet len = String.length(str) in\r\nlet rec sup_fun i l=\r\nif i = len then [] else (sup_fun (i+1) (int_of_char(str.[i]) :: l)) in\r\nsup_fun 0 [];;\r\n\r\nlet rec read_fucking_sheet n =\r\nif n = 0 then [] \r\nelse (translate_to (read_line ())) \r\n\r\nlet rec print_yes t =\r\nif t = true then print_string \"YES\"\r\nelse print_string \"NO\"\r\n;;\r\n\r\nlet rec solve l flag =\r\nmatch l with \r\nhd :: hd1 :: tl -> \r\n\tif flag = 1 && hd = 1\r\n\t\tthen (solve (hd1 :: tl) flag)\r\n\telse if flag = 1 && hd = 0 && hd1 = 0\r\n\t\tthen false\r\n\telse if flag = 1 && hd = 0 && hd1 = 1\r\n\t\tthen (solve tl flag)\r\n\telse if flag = 0 && hd = 0\r\n\t\tthen (solve (hd1 :: tl) flag)\r\n\telse if flag = 0 && hd = 1 && hd1 = 0\r\n\t\tthen (solve tl 1) || (solve tl flag )\r\n\telse if flag = 0 && hd = 1 && hd1 = 1\r\n\t\tthen (solve tl 1)\r\n else false\r\n|_-> true\r\n;;\r\n\r\nlet rec flum l =\r\nmatch l with \r\nhd :: tl -> print_yes (solve hd 0) ; flum tl\r\n|_-> () ;;\r\n\r\nflum (read_fucking_sheet n)\r\n\r\n(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)\r\n\r\n(*let spisok = [1;0;0;1;1;1;0;0;1] ;;\r\n\r\nprint_yes (solve spisok 0) ;;*)"}], "src_uid": "357dcc8fb7783d878cd2c4ed34eb437e"} {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = let u = read_int 0 in (u,read_int 0)\n\nlet ( ++ ) a b = Int64.add a b\n\nlet () = \n let n = read_int 0 in\n let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in\n let outcome = Array.make_matrix (n+1) 2 0 in\n\n let next_state (x,s) = (* s=0 means the initial state of the process, before \"step 2\" *)\n if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))\n in\n\n let rec fill_table (x,s) = \n if x<1 || x>n then 4\n else if x = 1 then 2+s (* 2 or 3 *)\n else if outcome.(x).(s) = 0 then (\n outcome.(x).(s) <- 5;\n outcome.(x).(s) <- fill_table (next_state (x,s));\n outcome.(x).(s)\n )\n else if outcome.(x).(s) = 5 then (\n outcome.(x).(s) <- 1;\n 1\n )\n else outcome.(x).(s)\n in\n\n let () = for i=2 to n do\n ignore (fill_table (i,0));\n ignore (fill_table (i,1))\n done in\n\n let cycles i = \n let a = outcome.(i+1).(1) in\n let b = outcome.(i+1).(0) in\n a = 1 || a = 2 || (a = 3 && (b = 1 || b = 2 || b = 3))\n in\n\n let yval = Array.make_matrix (n+1) 2 (-1L) in\n\n let rec fill_in_y i (x,s) = \n if x<1 || x>n then 0L\n else if (x,s) = (1,1) then Int64.of_int i\n else if yval.(x).(s) >= 0L then yval.(x).(s)\n else (\n yval.(x).(s) <- (Int64.of_int a.(x)) ++ (fill_in_y i (next_state (x,s)));\n yval.(x).(s)\n )\n in\n\n for i=1 to n-1 do \n if cycles i then print_string (\"-1\\n\") \n else Printf.printf \"%Ld\\n\" ((Int64.of_int i)++(fill_in_y i (i+1,1)))\n done\n", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = let u = read_int 0 in (u,read_int 0)\n\nlet ( ++ ) a b = Int64.add a b\n\nlet () = \n let n = read_int 0 in\n let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in\n let outcome = Array.make_matrix (n+1) 2 0 in\n (* this table has the following meaning:\n 0 unknown\n 1 cyclic\n 2 reaches (1,0)\n 3 reaches (1,1)\n 4 termates\n 5 current search *)\n\n let next_state (x,s) = (* s=0 means the initial state of the process, before \"step 2\" *)\n if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))\n in\n\n let rec fill_table (x,s) = \n if x<1 || x>n then 4\n else if x = 1 then 2+s (* 2 or 3 *)\n else if outcome.(x).(s) = 0 then (\n outcome.(x).(s) <- 5;\n outcome.(x).(s) <- fill_table (next_state (x,s));\n outcome.(x).(s)\n )\n else if outcome.(x).(s) = 5 then (\n outcome.(x).(s) <- 1;\n 1\n )\n else outcome.(x).(s)\n in\n\n let () = for i=2 to n do\n ignore (fill_table (i,0));\n ignore (fill_table (i,1))\n done in\n\n let cycles i = \n let a = outcome.(i+1).(1) in\n let b = outcome.(i+1).(0) in\n a = 1 || a = 2 || (a = 3 && (b = 1 || b = 2 || b = 3))\n in\n\n let yval = Array.make_matrix (n+1) 2 (-1L) in\n\n let rec fill_in_y i (x,s) = \n if x<1 || x>n then 0L\n else if (x,s) = (1,1) then Int64.of_int i\n else if yval.(x).(s) >= 0L then yval.(x).(s)\n else (\n yval.(x).(s) <- (Int64.of_int a.(x)) ++ (fill_in_y i (next_state (x,s)));\n yval.(x).(s)\n )\n in\n\n for i=1 to n-1 do \n if cycles i then print_string (\"-1\\n\") \n else Printf.printf \"%Ld\\n\" ((Int64.of_int i)++(fill_in_y i (i+1,1)))\n done\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair _ = let u = read_int 0 in (u,read_int 0)\n\nlet () = \n let n = read_int 0 in\n let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in\n let outcome = Array.make_matrix (n+1) 2 0 in\n(* this table has the following meaning:\n 0 unknown\n 1 cyclic\n 2 reaches (1,0)\n 3 reaches (1,1)\n 4 termates\n 5 current search *)\n\n let next_state (x,s) = (* s=0 means the initial state of the process, before \"step 2\" *)\n if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))\n in\n\n let rec find_path (x,s) = \n if x<1 || x>n then 4 \n else if x = 1 then 2+s (* 2 or 3 *)\n else if outcome.(x).(s) <> 0 then outcome.(x).(s)\n else (\n outcome.(x).(s) <- 5;\n find_path (next_state(x,s))\n )\n in\n\n let rec label_path (x,s) l =\n if x<1 || x>n then ()\n else if outcome.(x).(s) = 5 then (\n outcome.(x).(s) <- l;\n label_path (next_state(x,s)) l\n )\n in \n\n let fill_table (x,s) = \n let l = find_path(x,s) in\n label_path (x,s) (if l=5 then 1 else l)\n in\n\n let () = for i=1 to n-1 do\n fill_table (i+1,1)\n done in\n\n let cycles i = \n outcome.(i+1).(1) = 1 || outcome.(i+1).(1) = 2\n in\n\n let yval = Array.make_matrix (n+1) 2 (-1) in\n\n let rec testoverflow i = if i=0 then 0 else i+(testoverflow (i-1)) in\n\n\n Printf.printf \"testoverflow 10 = %d\\n\" (testoverflow 1000000);\n\n let rec fill_in_y i (x,s) = \n if x<1 || x>n then 0\n else if (x,s) = (1,1) then i\n else if yval.(x).(s) >= 0 then yval.(x).(s)\n else (\n yval.(x).(s) <- a.(x) + fill_in_y i (next_state (x,s));\n yval.(x).(s)\n )\n in\n\n for i=1 to n-1 do \n if cycles i then print_string (\"-1\\n\") \n else Printf.printf \"%d\\n\" (i+(fill_in_y i (i+1,1)))\n done;\n\n Printf.printf \"testoverflow 10 = %d\\n\" (testoverflow 1000000)\n"}], "src_uid": "369b6390417723799c5c0a19005e78f1"} {"source_code": "(* row : [(row_number,(min_column,max_column));...]\n * col : [(col_number,(min_row,max_row));...]\n * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))] \n * where d = Row-Col || d = Row + Col\n *)\n\nlet solve =\n let n,m = Scanf.scanf \"%d %d\\n\" (fun n m -> (n,m)) in\n let readPos() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rowsHash = Hashtbl.create n in\n let colsHash = Hashtbl.create n in\n let diagsHash = Hashtbl.create n in\n let diagsInvHash = Hashtbl.create n in\n let rec readBoard i acc =\n match i with\n | 0 -> acc\n | i -> let (row,col) = readPos() in\n readBoard (i-1) ((row,col)::acc)\n in\n let rec createRow queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> Hashtbl.add rowsHash row (col,col); createRow xs;\n | Some (minCol,maxCol) -> \n if (col < minCol)\n then\n (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)\n else if (col > maxCol) then\n (Hashtbl.replace rowsHash row (minCol,col); createRow xs)\n else\n createRow xs\n )\n in\n let rec createCol queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> Hashtbl.add colsHash col (row,row); createCol xs;\n | Some (minRow,maxRow) -> \n if (row < minRow)\n then\n (Hashtbl.replace colsHash col (row,maxRow); createCol xs)\n else if (row > maxRow) then\n (Hashtbl.replace colsHash col (minRow,row); createCol xs)\n else\n createCol xs\n )\n in\n let createDiag queens f dHash =\n let rec aux queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> let d = f row col in\n (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with\n | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;\n | Some ((minRow,minCol),(maxRow,maxCol)) -> \n if (row < minRow)\n then \n (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)\n else if (row > maxRow) then\n (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)\n else\n aux xs\n )\n in\n aux queens\n in\n let rec check queens rows cols diag1 diag2 t =\n let checkRow (row,col) =\n match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minCol,maxCol) -> \n if (col > minCol) then\n begin\n if (col < maxCol) then 2 else 1\n end\n else \n if (col < maxCol) then 1 else 0\n in\n let checkCol (row,col) =\n match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minRow,maxRow) -> \n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else \n if (row < maxRow) then 1 else 0\n in\n let checkDiag (row,col) dHash f =\n let d = f row col in\n match (try Some (Hashtbl.find dHash d) with Not_found -> None) with\n | None -> failwith \"if nasa launched sattelites with bugs then\n I am allowed to fuck this up no strings attached!\"\n | Some ((minRow,minCol),(maxRow,maxCol)) ->\n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else\n if (row < maxRow) then 1 else 0\n in\n match queens with\n | [] -> t\n | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) + \n (checkDiag (row,col) diagsHash ( - )) +\n (checkDiag (row,col) diagsInvHash ( + )) \n in\n (match (try Some (List.assoc threats t) with Not_found -> None) with\n | None -> check xs rows cols diag1 diag2 ((threats,1)::t)\n | Some prevThreats -> check xs rows cols diag1 diag2 ((threats,prevThreats + 1)::(List.remove_assoc threats t)))\n in\n let board = readBoard m [] in\n let rows = createRow board in\n let cols = createCol board in\n let diag1 = createDiag board ( - ) diagsHash in\n let diag2 = createDiag board ( + ) diagsInvHash in\n let tSeq = check board rows cols diag1 diag2 [] in\n let print lst =\n let rec aux i =\n match i with \n | 9 -> Printf.printf \"\\n\"\n | i -> \n (match (try Some (List.assoc i lst) with Not_found -> None) with\n | None -> Printf.printf \"0 \"; aux (i+1)\n | Some v -> Printf.printf \"%d \" v; aux (i+1))\n in\n aux 0\n in\n print tSeq\n;;\n", "positive_code": [{"source_code": "(* row : [(row_number,(min_column,max_column));...]\n * col : [(col_number,(min_row,max_row));...]\n * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))] \n * where d = Row-Col || d = Row + Col\n * Implemented with hash tables\n *)\n\nlet solve =\n let n,m = Scanf.scanf \"%d %d\\n\" (fun n m -> (n,m)) in\n let readPos() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rowsHash = Hashtbl.create n in\n let colsHash = Hashtbl.create n in\n let diagsHash = Hashtbl.create n in\n let diagsInvHash = Hashtbl.create n in\n let rec readBoard i acc =\n match i with\n | 0 -> acc\n | i -> let (row,col) = readPos() in\n readBoard (i-1) ((row,col)::acc)\n in\n let rec createRow queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> Hashtbl.add rowsHash row (col,col); createRow xs;\n | Some (minCol,maxCol) -> \n if (col < minCol)\n then\n (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)\n else if (col > maxCol) then\n (Hashtbl.replace rowsHash row (minCol,col); createRow xs)\n else\n createRow xs\n )\n in\n let rec createCol queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> Hashtbl.add colsHash col (row,row); createCol xs;\n | Some (minRow,maxRow) -> \n if (row < minRow)\n then\n (Hashtbl.replace colsHash col (row,maxRow); createCol xs)\n else if (row > maxRow) then\n (Hashtbl.replace colsHash col (minRow,row); createCol xs)\n else\n createCol xs\n )\n in\n let createDiag queens f dHash =\n let rec aux queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> let d = f row col in\n (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with\n | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;\n | Some ((minRow,minCol),(maxRow,maxCol)) -> \n if (row < minRow)\n then \n (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)\n else if (row > maxRow) then\n (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)\n else\n aux xs\n )\n in\n aux queens\n in\n let check queens =\n let rec checkAux queens t =\n let checkRow (row,col) =\n match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minCol,maxCol) -> \n if (col > minCol) then\n begin\n if (col < maxCol) then 2 else 1\n end\n else \n if (col < maxCol) then 1 else 0\n in\n let checkCol (row,col) =\n match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minRow,maxRow) -> \n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else \n if (row < maxRow) then 1 else 0\n in\n let checkDiag (row,col) dHash f =\n let d = f row col in\n match (try Some (Hashtbl.find dHash d) with Not_found -> None) with\n | None -> failwith \"if nasa launched sattelites with bugs then\n I am allowed to fuck this up no strings attached!\"\n | Some ((minRow,minCol),(maxRow,maxCol)) ->\n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else\n if (row < maxRow) then 1 else 0\n in\n match queens with\n | [] -> t\n | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) + \n (checkDiag (row,col) diagsHash ( - )) +\n (checkDiag (row,col) diagsInvHash ( + )) \n in\n (match (try Some (List.assoc threats t) with Not_found -> None) with\n | None -> checkAux xs ((threats,1)::t)\n | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))\n in\n checkAux queens []\n in\n let board = readBoard m [] in\n let _ = createRow board in\n let _ = createCol board in\n let _ = createDiag board ( - ) diagsHash in\n let _ = createDiag board ( + ) diagsInvHash in\n let tSeq = check board in\n let print lst =\n let rec printAux i =\n match i with \n | 9 -> Printf.printf \"\\n\"\n | i -> \n (match (try Some (List.assoc i lst) with Not_found -> None) with\n | None -> Printf.printf \"0 \"; printAux (i+1)\n | Some v -> Printf.printf \"%d \" v; printAux (i+1))\n in\n printAux 0\n in\n print tSeq\n;;\n"}, {"source_code": "(* row : [(row_number,(min_column,max_column));...]\n * col : [(col_number,(min_row,max_row));...]\n * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))] \n * where d = Row-Col || d = Row + Col\n *)\n\nlet solve =\n let n,m = Scanf.scanf \"%d %d\\n\" (fun n m -> (n,m)) in\n let readPos() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rowsHash = Hashtbl.create n in\n let colsHash = Hashtbl.create n in\n let diagsHash = Hashtbl.create n in\n let diagsInvHash = Hashtbl.create n in\n let rec readBoard i acc =\n match i with\n | 0 -> acc\n | i -> let (row,col) = readPos() in\n readBoard (i-1) ((row,col)::acc)\n in\n let rec createRow queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> Hashtbl.add rowsHash row (col,col); createRow xs;\n | Some (minCol,maxCol) -> \n if (col < minCol)\n then\n (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)\n else if (col > maxCol) then\n (Hashtbl.replace rowsHash row (minCol,col); createRow xs)\n else\n createRow xs\n )\n in\n let rec createCol queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> Hashtbl.add colsHash col (row,row); createCol xs;\n | Some (minRow,maxRow) -> \n if (row < minRow)\n then\n (Hashtbl.replace colsHash col (row,maxRow); createCol xs)\n else if (row > maxRow) then\n (Hashtbl.replace colsHash col (minRow,row); createCol xs)\n else\n createCol xs\n )\n in\n let createDiag queens f dHash =\n let rec aux queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> let d = f row col in\n (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with\n | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;\n | Some ((minRow,minCol),(maxRow,maxCol)) -> \n if (row < minRow)\n then \n (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)\n else if (row > maxRow) then\n (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)\n else\n aux xs\n )\n in\n aux queens\n in\n let check queens rows cols diag1 diag2 =\n let rec checkAux queens t =\n let checkRow (row,col) =\n match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minCol,maxCol) -> \n if (col > minCol) then\n begin\n if (col < maxCol) then 2 else 1\n end\n else \n if (col < maxCol) then 1 else 0\n in\n let checkCol (row,col) =\n match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minRow,maxRow) -> \n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else \n if (row < maxRow) then 1 else 0\n in\n let checkDiag (row,col) dHash f =\n let d = f row col in\n match (try Some (Hashtbl.find dHash d) with Not_found -> None) with\n | None -> failwith \"if nasa launched sattelites with bugs then\n I am allowed to fuck this up no strings attached!\"\n | Some ((minRow,minCol),(maxRow,maxCol)) ->\n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else\n if (row < maxRow) then 1 else 0\n in\n match queens with\n | [] -> t\n | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) + \n (checkDiag (row,col) diagsHash ( - )) +\n (checkDiag (row,col) diagsInvHash ( + )) \n in\n (match (try Some (List.assoc threats t) with Not_found -> None) with\n | None -> checkAux xs ((threats,1)::t)\n | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))\n in\n checkAux queens []\n in\n let board = readBoard m [] in\n let rows = createRow board in\n let cols = createCol board in\n let diag1 = createDiag board ( - ) diagsHash in\n let diag2 = createDiag board ( + ) diagsInvHash in\n let tSeq = check board rows cols diag1 diag2 in\n let print lst =\n let rec printAux i =\n match i with \n | 9 -> Printf.printf \"\\n\"\n | i -> \n (match (try Some (List.assoc i lst) with Not_found -> None) with\n | None -> Printf.printf \"0 \"; printAux (i+1)\n | Some v -> Printf.printf \"%d \" v; printAux (i+1))\n in\n printAux 0\n in\n print tSeq\n;;\n"}, {"source_code": "(* row : [(row_number,(min_column,max_column));...]\n * col : [(col_number,(min_row,max_row));...]\n * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))] \n * where d = Row-Col || d = Row + Col\n *)\n\nlet solve =\n let n,m = Scanf.scanf \"%d %d\\n\" (fun n m -> (n,m)) in\n let readPos() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rowsHash = Hashtbl.create n in\n let colsHash = Hashtbl.create n in\n let diagsHash = Hashtbl.create n in\n let diagsInvHash = Hashtbl.create n in\n let rec readBoard i acc =\n match i with\n | 0 -> acc\n | i -> let (row,col) = readPos() in\n readBoard (i-1) ((row,col)::acc)\n in\n let rec createLists queens =\n match queens with\n | [] -> ()\n | (row,col) :: xs -> let createRow () =\n match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> Hashtbl.add rowsHash row (col,col); \n | Some (minCol,maxCol) -> \n if (col < minCol)\n then\n Hashtbl.replace rowsHash row (col,maxCol)\n else if (col > maxCol) then\n Hashtbl.replace rowsHash row (minCol,col)\n else\n ()\n in\n let createCol () =\n match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> Hashtbl.add colsHash col (row,row);\n | Some (minRow,maxRow) -> \n if (row < minRow)\n then\n Hashtbl.replace colsHash col (row,maxRow)\n else if (row > maxRow) then\n Hashtbl.replace colsHash col (minRow,row)\n else\n ()\n in\n let createDiag dHash f =\n let d = f row col in\n match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with\n | None -> Hashtbl.add dHash d ((row,col),(row,col));\n | Some ((minRow,minCol),(maxRow,maxCol)) -> \n if (row < minRow)\n then \n Hashtbl.replace dHash d ((row,col),(maxRow,maxCol))\n else if (row > maxRow) then\n Hashtbl.replace dHash d ((minRow,minCol),(row,col))\n else\n ()\n in\n createRow ();\n createCol ();\n createDiag diagsHash ( - );\n createDiag diagsInvHash ( + );\n createLists xs\n in\n let check queens =\n let rec checkAux queens t =\n let checkRow (row,col) =\n match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minCol,maxCol) -> \n if (col > minCol) then\n begin\n if (col < maxCol) then 2 else 1\n end\n else \n if (col < maxCol) then 1 else 0\n in\n let checkCol (row,col) =\n match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minRow,maxRow) -> \n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else \n if (row < maxRow) then 1 else 0\n in\n let checkDiag (row,col) dHash f =\n let d = f row col in\n match (try Some (Hashtbl.find dHash d) with Not_found -> None) with\n | None -> failwith \"if nasa launched sattelites with bugs then\n I am allowed to fuck this up no strings attached!\"\n | Some ((minRow,minCol),(maxRow,maxCol)) ->\n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else\n if (row < maxRow) then 1 else 0\n in\n match queens with\n | [] -> t\n | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) + \n (checkDiag (row,col) diagsHash ( - )) +\n (checkDiag (row,col) diagsInvHash ( + )) \n in\n (match (try Some (List.assoc threats t) with Not_found -> None) with\n | None -> checkAux xs ((threats,1)::t)\n | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))\n in\n checkAux queens []\n in\n let board = readBoard m [] in\n let _ = createLists board in\n let tSeq = check board in\n let print lst =\n let rec aux i =\n match i with \n | 9 -> Printf.printf \"\\n\"\n | i -> \n (match (try Some (List.assoc i lst) with Not_found -> None) with\n | None -> Printf.printf \"0 \"; aux (i+1)\n | Some v -> Printf.printf \"%d \" v; aux (i+1))\n in\n aux 0\n in\n print tSeq\n;;\n"}, {"source_code": "let read_stuff () =\n let m = Scanf.scanf \" %d %d\" (fun _ a -> a)\n and l = ref [] in\n for i = 1 to m do\n let pair = Scanf.scanf \" %d %d\" (fun a b -> (a, b, 0)) in\n l := pair :: !l;\n done;\n !l\n\nlet postprocess queens =\n let res = Array.create 9 0\n in List.iter (fun (_, _, sz) -> (res.(sz) <- (res.(sz) + 1))) queens; res\n\nlet print_res res =\n Array.iter (fun el -> Printf.printf \"%d \" el) res;\n print_endline \"\"\n\n\n\nlet cmp a b =\n if a == b\n then 0\n else if a > b\n then 1\n else -1\n\n\nlet solve_one queens pred =\n let proc2 q r =\n let (x, y, v) = q in\n if abs(pred q r) == 2 \n then (x, y, v + 1)\n else q\n in let proc = function\n | h :: t -> \n snd (List.fold_left \n (* Sprawdz wszystko oprocz glowy *)\n (fun (last, acc) h -> \n (h, (proc2 h last)::acc))\n (h, [h])\n t)\n | foo -> foo\n and sorted = List.sort pred queens\n in proc (proc (sorted))\n\n\nlet rec solve queens preds = \n match preds with \n | [] -> queens\n | p0 :: ps -> solve (solve_one queens p0) ps\n \nlet oq a b = \n if a == 0 then 2 * b else a\n;;\n\nlet predicates =\n [\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp x1 x2) (cmp y1 y2));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp y1 y2) (cmp x1 x2));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 - y1) (x2 - y2)) (cmp (x1 + y1) (x2 + y2)));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 + y1) (x2 + y2)) (cmp (x1 - y1) (x2 - y2)))\n ]\nin\n print_res (postprocess (solve (read_stuff()) predicates))\n\n\n"}], "negative_code": [{"source_code": "(* row : [(row_number,(min_column,max_column));...]\n * col : [(col_number,(min_row,max_row));...]\n * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))] \n * where d = Row-Col || d = Row + Col\n *)\n\nlet solve =\n let n,m = Scanf.scanf \"%d %d\\n\" (fun n m -> (n,m)) in\n let readPos() = Scanf.scanf \"%d %d\\n\" (fun x y -> (x,y)) in\n let rec readBoard i acc =\n match i with\n | 0 -> List.rev acc\n | i -> let (row,col) = readPos() in\n readBoard (i-1) ((row,col)::acc)\n in\n let rec createRow queens acc =\n match queens with\n | [] -> List.rev acc\n | (row,col) :: xs -> (match (try Some (List.assoc row acc) with Not_found -> None) with\n | None -> createRow xs ((row,(col,col)) :: acc)\n | Some (minCol,maxCol) -> \n if (col < minCol)\n then\n createRow xs ((row,(col,maxCol))::(List.remove_assoc row acc))\n else if (col > maxCol) then\n createRow xs ((row,(minCol,col))::(List.remove_assoc row acc))\n else\n createRow xs acc\n )\n in\n let rec createCol queens acc =\n match queens with\n | [] -> List.rev acc\n | (row,col) :: xs -> (match (try Some (List.assoc col acc) with Not_found -> None) with\n | None -> createCol xs ((col,(row,row)) :: acc) \n | Some (minRow,maxRow) -> \n if (row < minRow)\n then\n createCol xs ((col,(row,maxRow))::(List.remove_assoc col acc))\n else if (row > maxRow) then\n createCol xs ((col,(minRow,row))::(List.remove_assoc col acc))\n else\n createCol xs acc\n )\n in\n let rec createDiag queens acc f =\n match queens with\n | [] -> List.rev acc\n | (row,col) :: xs -> let d = f row col in\n (match (try Some (List.assoc d acc) with Not_found -> None) with\n | None -> createDiag xs ((d,( (row,col), (row,col) )) :: acc) f\n | Some ((minRow,minCol),(maxRow,maxCol)) -> \n if (row < minRow)\n then \n createDiag xs ((d, ((row,col),(maxRow,maxCol))) :: (List.remove_assoc d acc)) f\n else if (row > maxRow) then\n createDiag xs ((d, ((minRow,minCol),(row,col))) :: (List.remove_assoc d acc)) f \n else\n createDiag xs acc f\n )\n in\n let rec check queens rows cols diag1 diag2 t =\n let checkRow (row,col) =\n match (try Some (List.assoc row rows) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minCol,maxCol) -> \n if (col > minCol) then\n begin\n if (col < maxCol) then 2 else 1\n end\n else \n if (col < maxCol) then 1 else 0\n in\n let checkCol (row,col) =\n match (try Some (List.assoc col cols) with Not_found -> None) with\n | None -> failwith \"nothing to see here, move on\"\n | Some (minRow,maxRow) -> \n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else \n if (row < maxRow) then 1 else 0\n in\n let checkDiag (row,col) diag f =\n let d = f row col in\n match (try Some (List.assoc d diag) with Not_found -> None) with\n | None -> failwith \"if nasa launched sattelites with bugs then\n I am allowed to fuck this up no strings attached!\"\n | Some ((minRow,minCol),(maxRow,maxCol)) ->\n if (row > minRow) then\n begin\n if (row < maxRow) then 2 else 1\n end\n else\n if (row < maxRow) then 1 else 0\n in\n match queens with\n | [] -> t\n | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) + \n (checkDiag (row,col) diag1 ( - )) +\n (checkDiag (row,col) diag2 ( + )) \n in\n (match (try Some (List.assoc threats t) with Not_found -> None) with\n | None -> check xs rows cols diag1 diag2 ((threats,1)::t)\n | Some prevThreats -> check xs rows cols diag1 diag2 ((threats,prevThreats + 1)::(List.remove_assoc threats t)))\n in\n let board = readBoard m [] in\n let rows = createRow board [] in\n let cols = createCol board [] in\n let diag1 = createDiag board [] ( - ) in\n let diag2 = createDiag board [] ( + ) in\n let tSeq = check board rows cols diag1 diag2 [] in\n let normalize lst =\n let rec aux lst i acc =\n match i,lst with\n | 9,_ -> List.rev acc\n | i,[] -> aux [] (i+1) ((i,0)::acc)\n | i,((j,v)::t) -> if (i = j) then aux t (i+1) ((j,v) :: acc)\n else\n aux ((j,v)::t) (i+1) ((i,0) :: acc)\n in\n aux lst 0 []\n in\n let tOut = normalize tSeq in\n List.iter (fun (_,v2) -> Printf.printf \"%d \" v2) tOut;\n Printf.printf \"\\n\"\n;;\n"}, {"source_code": "let read_stuff () =\n let m = Scanf.scanf \" %d %d\" (fun _ a -> a)\n and l = ref [] in\n for i = 1 to m do\n let pair = Scanf.scanf \" %d %d\" (fun a b -> (a, b, 0)) in\n l := pair :: !l;\n done;\n !l\n\nlet postprocess queens =\n let res = Array.create 10 0\n in List.iter (fun (_, _, sz) -> (res.(sz) <- (res.(sz) + 1))) queens; res\n\nlet print_res res =\n Array.iter (fun el -> Printf.printf \"%d \" el) res;\n print_endline \"\"\n\n\n\nlet cmp a b =\n if a == b\n then 0\n else if a > b\n then 1\n else -1\n\n\nlet solve_one queens pred =\n let proc2 q r =\n let (x, y, v) = q in\n if abs(pred q r) == 2 \n then (x, y, v + 1)\n else q\n in let proc = function\n | h :: t -> \n snd (List.fold_left \n (* Sprawdz wszystko oprocz glowy *)\n (fun (last, acc) h -> \n (h, (proc2 h last)::acc))\n (h, [h])\n t)\n | foo -> foo\n and sorted = List.sort pred queens\n in proc (proc (sorted))\n\n\nlet rec solve queens preds = \n match preds with \n | [] -> queens\n | p0 :: ps -> solve (solve_one queens p0) ps\n \nlet oq a b = \n if a == 0 then 2 * b else a\n;;\n\nlet predicates =\n [\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp x1 x2) (cmp y1 y2));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp y1 y2) (cmp x1 x2));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 - y1) (x2 - y2)) (cmp (x1 + y1) (x2 + y2)));\n (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 + y1) (x2 + y2)) (cmp (x1 - y1) (x2 - y2)))\n ]\nin\n print_res (postprocess (solve (read_stuff()) predicates))\n\n\n"}], "src_uid": "f19e7f33396d27e1eba2c46b6b5e706a"} {"source_code": "let n = Scanf.scanf \"%d\\n\" (fun x -> x);;\n\nlet tab = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun x -> x));;\n\nlet valide = ref (tab.(0).[0] <> tab.(0).[1]);;\n\nfor i = 0 to n-1 do\nfor j = 0 to n-1 do\n if i = j\n then (if tab.(i).[j] <> tab.(0).[0] then valide := false)\n else if n-j-1 = i\n then (if tab.(i).[j] <> tab.(0).[0] then valide := false)\n else\n if tab.(i).[j] <> tab.(0).[1] then valide := false\ndone;\ndone;\n\nif !valide\n then print_endline \"YES\"\n else print_endline \"NO\"", "positive_code": [{"source_code": "let n=read_int();;\n\nlet tab=Array.make n \" \";;\n\nfor i=0 to n-1 do\n tab.(i)<-read_line()\ndone;;\n\nlet a=tab.(0).[0];;\nlet v=tab.(0).[1];;\nlet b=ref true;;\n\nfor i=0 to n-1 do\n for j=0 to n-1 do\n if (i=j)||(i+j=n-1) then b:= !b&&(tab.(i).[j]=a)\n else b:= !b&&(tab.(i).[j]=v)\n done\ndone;;\n\nif a=v then b:=false;;\n\nif !b then print_string \"YES\" else print_string \"NO\";;"}], "negative_code": [{"source_code": "let n=read_int();;\n\nlet tab=Array.make n \" \";;\n\nfor i=0 to n-1 do\n tab.(i)<-read_line()\ndone;;\n\nlet a=tab.(0).[0];;\nlet v=tab.(0).[1];;\nlet b=ref true;;\n\nfor i=0 to n-1 do\n for j=0 to n-1 do\n if (i=j)||(i+j=n-1) then b:= !b&&(tab.(i).[j]=a)\n else b:= !b&&(tab.(i).[j]=v)\n done\ndone;;\n\nif !b then print_string \"YES\" else print_string \"NO\";;"}, {"source_code": "let n = Scanf.scanf \"%d\\n\" (fun x -> x);;\n\nlet tab = Array.init n (fun _ -> Scanf.scanf \"%s\\n\" (fun x -> x));;\n\nlet valide = ref true;;\n\nfor i = 0 to n-1 do\nfor j = 0 to n-1 do\n if i = j\n then (if tab.(i).[j] <> tab.(0).[0] then valide := false)\n else if n-j-1 = i\n then (if tab.(i).[j] <> tab.(0).[0] then valide := false)\n else\n if tab.(i).[j] <> tab.(0).[1] then valide := false\ndone;\ndone;\n\nif !valide\n then print_endline \"YES\"\n else print_endline \"NO\""}], "src_uid": "02a9081aed29ea92aae13950a6d48325"} {"source_code": "let 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.0\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet construct_a n = \n let nn = n*n in\n let a = Array.make_matrix nn nn 0.0 in\n\n (* the pair of positions (i,j) is mapped into i+j*n of the vector *)\n\n (* the flips in the permutation are for a range [p,q], where p <= q *)\n (* for pair (i,j) and for each flip [p,q] see what happens to (i,j) and\n add this probability to the matrix a *)\n\n let ind i j = i + j*n in\n let fn = float n in\n let pr = 2.0 /. (fn *. (fn +. 1.0)) in\n\n for i=0 to n-1 do\n for j=0 to n-1 do\n if i <> j then (\n\tfor p=0 to n-1 do\n\t for q=p to n-1 do\n\t let map i = if i

q then i else q - (i-p) in\n\t let (i',j') = (map i, map j) in\n\t a.(ind i' j').(ind i j) <- a.(ind i' j').(ind i j) +. pr\n\t done\n\tdone\n )\n done\n done;\n a\n\nlet () = \n let n = read_int () in\n let k = read_int () in\n let perm = Array.init n (fun _ -> read_int()) in\n let nn = n*n in\n\n let ind i j = i + j*n in\n let dot a b = sum 0 (nn-1) (fun i -> a.(i) *. b.(i)) in\n\n let mult a b = \n let c = Array.make nn 0.0 in\n\n for i=0 to nn-1 do\n for j=0 to nn-1 do\n\tc.(i) <- c.(i) +. a.(i).(j) *. b.(j)\n done\n done;\n c\n in\n\n let power a b p =\n let rec loop ac i = if i=p then ac else\n\tloop (mult a ac) (i+1)\n in\n loop b 0\n in\n\n let a = construct_a n in\n\n let b = Array.make nn 0.0 in\n let b' = Array.make nn 0.0 in\n\n for i=0 to n-2 do\n for j=i+1 to n-1 do\n let ii = ind i j in\n if perm.(i) < perm.(j) \n then b.(ii) <- 1.0 \n else b'.(ii) <- 1.0 \n done\n done;\n\n let c = power a b k in\n let c' = power a b' k in\n\n let s = Array.make nn 0.0 in\n let s' = Array.make nn 0.0 in\n\n for i=0 to n-1 do\n for j=0 to n-1 do\n let ii = ind i j in\n if ij then s'.(ii) <- 1.0\n done\n done;\n\n printf \"%12.12f\\n\" ((dot c' s) +. (dot c s'))\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet construct_a n = \n let nn = n*n in\n let a = Array.make_matrix nn nn 0.0 in\n\n (* the pair of positions (i,j) is mapped into i+j*n of the vector *)\n\n (* the flips in the permutation are for a range [p,q], where p <= q *)\n (* for pair (i,j) and for each flip [p,q] see what happens to (i,j) and\n add this probability to the matrix a *)\n\n let ind i j = i + j*n in\n\n let fn = float n in\n let pr = 2.0 /. (fn *. (fn +. 1.0)) in\n\n for i=0 to n-1 do\n for j=0 to n-1 do\n if i <> j then (\n\tfor p=0 to n-1 do\n\t for q=p to n-1 do\n\t let map i = if i

q then i else q - (i-p) in\n\t let (i',j') = (map i, map j) in\n\t a.(ind i' j').(ind i j) <- a.(ind i' j').(ind i j) +. pr\n\t done\n\tdone\n )\n done\n done;\n a\n\nlet () = \n let n = read_int () in\n let k = read_int () in\n let perm = Array.init n (fun _ -> read_int()) in\n \n let nn = n*n in\n\n let mult a b = \n let c = Array.make nn 0.0 in\n\n for i=0 to nn-1 do\n for j=0 to nn-1 do\n\tc.(i) <- c.(i) +. a.(i).(j) *. b.(j)\n done\n done;\n c\n in\n\n let power a b p =\n let rec loop ac i = if i=p then ac else\n\tloop (mult a ac) (i+1)\n in\n loop b 0\n in\n\n let a = construct_a n in\n\n let ind i j = i + j*n in\n let unind ii = (ii - n*(ii/n), ii/n) in\n\n let exp = ref 0.0 in\n\n for i=0 to n-2 do\n for j=i+1 to n-1 do\n let flipprob = ref 0.0 in\n let b = Array.init nn (fun ii-> if ii = ind i j then 1.0 else 0.0) in\n let c = power a b k in\n for ii=0 to nn-1 do\n\tlet (i',j') = unind ii in\n\tif i'<>j' && ((i' (i x) ;;\n\nlet n = read_int () ;;\n\nlet s =\n let rec loop i n f = \n if i > n then f []\n else let si = read_int () in loop (i + 1) n (fun l -> f (si :: l))\n in loop 1 n (fun x -> x) ;;\n\nlet count x = \n let rec loop total = function \n | [] -> total\n | h :: t -> loop (total + if h = x then 1 else 0) t\n in loop 0 ;;\n \nlet one = count 1 s \n and two = count 2 s \n and three = count 3 s \n and four = count 4 s ;;\n\nlet group31 = min one three ;;\nlet group21 = min (two mod 2) (one - group31) ;;\nlet group2 = two / 2 + if group21 = 1 then 0 else (two mod 2) ;;\nlet group1 = ((max 0 (one - group31 - group21 * 2)) + 3) / 4 ;;\n\nlet taxis = four + three + group2 + group21 + group1 ;;\n\nPrintf.printf \"%d\\n\" taxis ;;", "positive_code": [{"source_code": "let _ =\n let main () =\n let n = read_int () in\n let arr = Array.create 5 0 in\n let rec loop i =\n if i > 0 then (\n Scanf.scanf \" %d\" (fun x -> arr.(x) <- arr.(x) + 1);\n loop (i - 1)\n )\n in\n loop n;\n let c = arr.(4) + arr.(3) in\n let _ = arr.(1) <- arr.(1) - min arr.(1) arr.(3) in\n let c = c + (arr.(2) + 1) / 2 in\n let _ = arr.(1) <- arr.(1) - min arr.(1) ((arr.(2) mod 2) * 2) in\n let r = c + (arr.(1) + 3) / 4 in\n Printf.printf \"%d\\n\" r\n in\n main ()\n"}, {"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 numx = Array.make 4 0;;\nlet n = read_int ();;\n for i = 1 to n do\n Scanf.scanf \"%d \" (fun x -> numx.(x-1)<- numx.(x-1)+1)\n done\n\nlet num_cars = ref ( numx.(3) + numx.(1)/2 );;\nlet () = numx.(1) <- numx.(1) mod 2;;\nlet () = if (numx.(0) <= numx.(2) ) then\n begin\n numx.(2) <- numx.(2) - numx.(0);\n num_cars := !num_cars + numx.(0);\n numx.(0) <- 0\n end\n else\n begin\n num_cars := !num_cars + numx.(2);\n numx.(0) <- numx.(0) - numx.(2);\n end\n;;\n\nlet () = if (numx.(0) == 0) then\n num_cars := !num_cars + numx.(2) + numx.(1)\n else\n begin\n if(numx.(1) == 1) then\n begin\n num_cars := !num_cars + 1;\n numx.(0) <- numx.(0) -2\n end;\n if (numx.(0) > 0) then\n num_cars := !num_cars + ( numx.(0) + 3) /4\n end\n;;\nlet ()= print_int !num_cars; print_endline \"\";;\n"}, {"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 ();;\nlet a = Array.init n (fun i -> read_int () );;\nlet numx = Array.make 4 0;;\nlet vote i = numx.(i-1) <- numx.(i-1) + 1;;\nlet () = Array.iter (fun x -> vote x) a;;\n\nlet num_cars = ref ( numx.(3) + numx.(1)/2 );;\n\nlet () = numx.(1) <- numx.(1) mod 2;;\n\nlet () = if (numx.(0) <= numx.(2) ) then\n begin\n numx.(2) <- numx.(2) - numx.(0);\n num_cars := !num_cars + numx.(0);\n numx.(0) <- 0\n end\n else\n begin\n num_cars := !num_cars + numx.(2);\n numx.(0) <- numx.(0) - numx.(2);\n end\n;;\n\nlet () = if (numx.(0) == 0) then\n num_cars := !num_cars + numx.(2) + numx.(1)\n else\n begin\n if(numx.(1) == 1) then\n begin\n num_cars := !num_cars + 1;\n numx.(0) <- numx.(0) -2\n end;\n if (numx.(0) > 0) then\n num_cars := !num_cars + ( numx.(0) + 3) /4\n end\n;;\n\nlet ()= print_int !num_cars; print_endline \"\";;\n"}, {"source_code": "let input () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet rec read list n =\n if n > 0\n then\n let var = Scanf.scanf \"%d \" (fun n -> n) in\n read (var :: list) (n - 1)\n else\n List.rev list\n\nlet separate list s =\n let rec filter list s current_counts =\n if s > 0\n then\n let count = List.length(List.filter (fun int -> int = s) list) in\n filter list (s - 1) (count :: current_counts)\n else\n current_counts\n in filter list s []\n\nlet no_owerflow n = \n if n < 0\n then \n 0\n else\n n\n\nlet taxis list = match (separate list 4) with\n|[ones; twos; threes; fours] -> fours + threes + (twos * 2 + no_owerflow(ones - threes) + 3) / 4\n\nlet solve input = taxis (read [] input)\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))"}, {"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 ();;\nlet a = Array.init n (fun i -> read_int () );;\nlet numx = Array.make 4 0;;\nlet vote i = numx.(i-1) <- numx.(i-1) + 1;;\nlet () = Array.iter (fun x -> vote x) a;;\n\nlet num_cars = ref ( numx.(3) + numx.(1)/2 );;\n\nlet () = numx.(1) <- numx.(1) mod 2;;\n\nlet () = if (numx.(0) <= numx.(2) ) then\n begin\n numx.(2) <- numx.(2) - numx.(0);\n num_cars := !num_cars + numx.(0);\n numx.(0) <- 0\n end\n else\n begin\n num_cars := !num_cars + numx.(2);\n numx.(0) <- numx.(0) - numx.(2);\n numx.(2) <- 0\n end\n;;\n\nlet () = if (numx.(0) == 0) then\n num_cars := !num_cars + numx.(2) + numx.(1)\n else\n begin\n if(numx.(1) == 1) then\n begin\n num_cars := !num_cars + 1;\n numx.(0) <- numx.(0) -2\n end;\n if (numx.(0) > 0) then\n begin\n if (numx.(0) mod 4 == 0) then\n num_cars := !num_cars + numx.(0)/4\n else\n num_cars := !num_cars + numx.(0)/4 + 1\n end\n end\n;;\n\nlet ()= print_int !num_cars; print_endline \"\";;\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve n =\n let data = [|0; 0; 0; 0; 0|] in\n for i = 1 to n do\n match read_int () with\n | 1 when data.(3) > 0 -> data.(3) <- data.(3) - 1; data.(4) <- data.(4) + 1\n | 2 when data.(2) > 0 -> data.(2) <- data.(2) - 1; data.(4) <- data.(4) + 1\n | 3 when data.(1) > 0 -> data.(1) <- data.(1) - 1; data.(4) <- data.(4) + 1\n | i -> data.(i) <- data.(i) + 1\n done;\n\n if data.(2) > 0 && data.(1) > 0 then begin\n data.(2) <- 0;\n data.(4) <- data.(4) + 1;\n if data.(1) > 1\n then data.(1) <- data.(1)-2\n else data.(1) <- 0\n end;\n\n if data.(1) mod 4 = 0\n then data.(4) + data.(3) + data.(2) + data.(1) / 4\n else data.(4) + data.(3) + data.(2) + data.(1) / 4 + 1\n\n\nlet () =\n let n = read_int ()\n in Printf.printf \"%d\\n\" (solve n)\n\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let ones = ones - threes\n in let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if ones mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf\nopen Printf\nlet n = scanf \"%d\\n\" (fun n -> n)\n\nlet (n1,n2,n3,n4) = \n let a = Array.make 10 0 in\n for i=0 to n-1 do \n let i = scanf \"%d \" (fun x -> x) in\n a.(i) <- a.(i) + 1\n done;\n (a.(1),a.(2),a.(3),a.(4))\n\nlet () = (*\n printf \"%d %d %d %d\\n\" n1 n2 n3 n4; *)\n ()\nlet ans = ref n4\nlet n4 = 0\nlet incr2 x = \n ans := !ans +x;\n (*printf \"incr by %d to %d\\n\" x !ans;*)\n ()\nlet info x = (*\n printf \"Evaling %d \\n\" x;*)\n ()\n\nlet () =\n let m = (min n1 n3) in\n incr2 m;\n let n1 = n1 - m in\n let n3 = n3-m in\n let n3 = \n info 3;\n if n3>0 then (incr2 n3; 0) else n3 in\n let n2 = \n info 2;\n incr2 (n2/2);\n n2 mod 2 in\n let (n1,n2) = \n info 2;\n if n2>0 then (incr2 1; (n1-2,0)) else (n1,n2) in\n let () =\n let last = \n if n1>0 then ( (if n1 mod 4 = 0 then 0 else 1) + (n1/4) ) \n else 0\n in\n incr2 last\n in ()\n\nlet () = print_int !ans; print_newline ()\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let nextInt() =\n Scanf.scanf \"%d \" (fun x -> x);;\n\nlet readList n f =\n let rec loop n =\n if n == 0 then\n []\n else\n f() :: loop (n-1)\n in\n List.rev(loop n);;\n\nlet incValue arr x =\n arr.(x) <- arr.(x) + 1;;\n\nlet groupByList l =\n let counts = (Array.make 5 0) in\n let _ = List.map (incValue counts) l in\n counts;;\n\nlet rec fitTaxis counts =\n let sol = ref 0 in\n sol := counts.(4);\n\n let taxi3pack = min counts.(1) counts.(3) in\n sol := !sol + taxi3pack;\n counts.(1) <- counts.(1) - taxi3pack;\n counts.(3) <- counts.(3) - taxi3pack;\n sol := !sol + counts.(3);\n let remainder = counts.(1) + (counts.(2) * 2) in\n if remainder mod 4 == 0 then\n remainder / 4 + !sol\n else\n remainder / 4 + 1 + !sol;;\n\nlet _ =\n let n = read_int() in\n let l = readList n nextInt in\n let counts = groupByList l in\n print_int(fitTaxis counts);\n print_newline()\n"}, {"source_code": "let nextInt() =\n Scanf.scanf \"%d \" (fun x -> x);;\n\nlet readList n f =\n let rec loop n =\n if n == 0 then\n []\n else\n f() :: loop (n-1)\n in\n List.rev(loop n);;\n\nlet incValue arr x =\n arr.(x) <- arr.(x) + 1;;\n\nlet groupByList l =\n let counts = (Array.make 5 0) in\n let _ = List.map (incValue counts) l in\n counts;;\n\nlet fitTaxis counts =\n let sol = ref 0 in\n sol := counts.(4);\n\n let taxi3pack = min counts.(1) counts.(3) in\n sol := !sol + taxi3pack;\n counts.(1) <- counts.(1) - taxi3pack;\n counts.(3) <- counts.(3) - taxi3pack;\n sol := !sol + counts.(3);\n !sol + (counts.(1) + (counts.(2) * 2) + 3) / 4;;\n\nlet _ =\n let n = read_int() in\n let l = readList n nextInt in\n let counts = groupByList l in\n print_int(fitTaxis counts);\n print_newline()\n"}, {"source_code": "open Scanf;;\nopen Printf;;\nopen List;;\n\nlet read_and_count n =\n let rec read n acc =\n match n with\n | 1 -> let y = (scanf \"%d\" (fun x->x) ) in\n acc.(y) <- acc.(y) + 1;\n acc\n | x -> let y = (scanf \"%d \" (fun x->x)) in\n acc.(y) <- acc.(y) + 1;\n read (x-1) acc\n in read n (Array.make 5 0)\n;;\n\n\nlet n = scanf \"%d\\n\" (fun x -> x) in\nlet counters = (read_and_count n) in\nlet sol = ref 0 in\nsol := !sol + counters.(4);\nlet mini = (min counters.(3) counters.(1)) in\nsol := !sol + mini;\ncounters.(3) <- counters.(3) - mini;\ncounters.(1) <- counters.(1) - mini;\nsol := !sol + counters.(3);\nsol := !sol + ( (counters.(2)*2 + counters.(1) + 3) / 4);\nprintf \"%d\\n\" !sol;"}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int();;\nlet tab=Array.make 5 0;;\nfor i=1 to n do\n let k=read_int() in tab.(k)<-tab.(k)+1\ndone;;\nif (tab.(2) mod 2)=0 then (tab.(1)<-max 0 (tab.(1)-tab.(3));tab.(2)<-tab.(2)/2)\nelse (tab.(1)<-max 0 (tab.(1)-tab.(3)-2);tab.(2)<-tab.(2)/2+1);;\nif (tab.(1) mod 4)=0 then tab.(1)<-tab.(1)/4 else tab.(1)<-tab.(1)/4+1;;\nprint_int(tab.(1)+tab.(2)+tab.(3)+tab.(4));;"}, {"source_code": "(* Codeforces 158 B Taxi *)\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 taxi1 n1 = \n let n14 = n1/4 in\n let nn1 = n1 - n14*4 in\n let t1 = if nn1 > 0 then (n14 + 1)\n else n14 in \n (* let _ = Printf.printf \"n1 t1 = %d %d\\n\" n1 t1 in *)\n t1;;\n\nlet taxi2 n1 n2 =\n let n22 = n2/2 in\n let nn2 = n2 - 2 * n22 in\n let nn1 = if nn2 == 0 then n1\n else if n1 > 2 then n1 - 2\n else 0 in\n let t2 = n22 + nn2 + taxi1 nn1 in\n (* let _ = Printf.printf \"n1,n2 = %d %d t2 = %d\\n\" n1 n2 t2 in *)\n t2;;\n\nlet taxi3 n1 n2 n3 =\n let nn1 = if n3 > n1 then 0 else (n1 - n3) in\n n3 + taxi2 nn1 n2;;\n\nlet taxi4 n1 n2 n3 n4 = \n n4 + taxi3 n1 n2 n3;;\n\nlet rec count4 n1 n2 n3 n4 a = match a with\n | [] -> (n1, n2, n3, n4)\n | h :: t ->\n match h with\n | 1 -> count4 (n1 + 1) n2 n3 n4 t\n | 2 -> count4 n1 (n2 + 1) n3 n4 t\n | 3 -> count4 n1 n2 (n3 + 1) n4 t\n | 4 -> count4 n1 n2 n3 (n4 + 1) t\n | _ -> \n let _ = print_string \"bad h in count4\\n\" in \n (-9999,0,0,0);;\n\nlet main() =\n\tlet n = gr () in\n\tlet s = readlist n [] in\n\tlet n1,n2,n3,n4 = count4 0 0 0 0 s in\n (* let _ = Printf.printf \"n1-4 = %d %d %d %d\\n\" n1 n2 n3 n4 in *)\n\tlet taxi = taxi4 n1 n2 n3 n4 in\n\tbegin\n\t\tprint_int taxi;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}], "negative_code": [{"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 ();;\nlet a = Array.init n (fun i -> read_int () );;\nlet numx = Array.make 4 0;;\nlet vote i = numx.(i-1) <- numx.(i-1) + 1;;\nlet () = Array.iter (fun x -> vote x) a;;\n\nlet num_cars = ref ( numx.(3) + numx.(1)/2 + numx.(0)/4 );;\n\nlet remain_2 = numx.(1) mod 2;;\nlet remain_1 = numx.(0) mod 4;;\n\nlet () = if (remain_1 > numx.(2)) then\n num_cars := !num_cars + numx.(2) + (remain_1 - numx.(2) )\n else if (remain_1 == numx.(2)) then\n num_cars := !num_cars + numx.(2) + remain_2\n else\n num_cars := !num_cars + remain_1 + (numx.(2) - remain_1) + remain_2\n;;\n\n\nlet () = (print_int !num_cars; print_endline \"\");;\n\n (* This is the easy way *)\n(*\n let b = Array.to_list cars\n |> List.filter (fun x -> (x>0))\n |> List.length\n;;\n\nlet ()= print_int b; print_endline \"\";;\n *)\n"}, {"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\nlet a = Array.init n (fun i -> read_int () );;\n\nlet () = a |> Array.sort (fun x y -> (if (x < y ) then 1 else -1) );;\n\n\nlet cars = Array.make n 0;; (* Call n empty cars *)\n\n\n exception BreakLoop;;\n for i = 0 to n-1 do\n try\n for j = 0 to n-1 do\n let x = a.(i) + cars.(j) in\n if ( x <= 4 ) then\n begin\n cars.(j) <- x;\n raise BreakLoop\n end\n done\n with BreakLoop -> ()\n\n done;;\n\n let num_cars = ref 0;;\n try\n for i = 0; to n-1 do\n if(cars.(i)>0) then\n num_cars := !num_cars + 1\n else\n raise BreakLoop\n done\n with BreakLoop -> print_int !num_cars; print_endline \"\";;\n\n (* This is the easy way *)\n(*\n let b = Array.to_list cars\n |> List.filter (fun x -> (x>0))\n |> List.length\n;;\n\nlet ()= print_int b; print_endline \"\";;\n *)\n"}, {"source_code": "let _ =\n let main () =\n let n = read_int () in\n let arr = Array.create 5 0 in\n let rec loop i =\n if i > 0 then (\n Scanf.scanf \" %d\" (fun x -> arr.(x) <- arr.(x) + 1);\n loop (i - 1)\n )\n in\n loop n;\n let c = arr.(4) + arr.(3) in\n let _ = arr.(1) <- arr.(1) - min arr.(1) arr.(3) in\n let c = c + (arr.(2) + 1) / 2 in\n let _ = arr.(1) <- arr.(1) - min arr.(1) ((arr.(2) mod 1) * 2) in\n let r = c + (arr.(1) + 3) / 4 in\n Printf.printf \"%d\\n\" r\n in\n main ()\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let ones = ones - threes\n in let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if (ones - threes) mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf;;\n\nlet parse () =\n let rec parseInt acc =\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (d :: acc)\n | exception _ -> acc\n in parseInt [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if ones mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let _ = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse ()\n in taxis numList;;\n\nPrintf.sprintf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if ones - threes mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let ones = ones - threes\n in let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if (ones - threes) mod 4 = 0 then\n needed + 300\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if ones mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}, {"source_code": "open Scanf;;\n\nlet parse n =\n let rec parseInt n acc =\n if n <= 0 then acc\n else\n match bscanf Scanning.stdin \" %d\" (fun x -> x) with\n | d -> parseInt (n - 1) (d :: acc)\n | exception _ -> acc\n in parseInt n [];;\n\nlet taxis numList =\n let ones, twos, threes, fourths = \n List.fold_left ( fun (ones, twos, threes, fourths) x ->\n match x with\n | 1 -> (ones + 1, twos, threes, fourths)\n | 2 -> (ones, twos + 1, threes, fourths)\n | 3 -> (ones, twos, threes + 1, fourths)\n | 4 -> (ones, twos, threes, fourths + 1)\n | _ -> (ones, twos, threes, fourths)\n ) (0, 0, 0, 0) numList\n in let needed = fourths\n in let needed = needed + twos / 2\n in let twos = twos mod 2\n in let needed = needed + threes\n in if ones > threes then\n let needed = needed + ones / 4\n in if twos = 1 then\n if ones mod 4 > 2 then\n needed + 2\n else\n needed + 1\n else\n if (ones - threes) mod 4 = 0 then\n needed\n else\n needed + 1\n else\n needed + twos / 2 + twos mod 2\n\nlet main () = \n let n = bscanf Scanning.stdin \"%d\\n\" (fun x -> x)\n in let numList = parse n\n in taxis numList;;\n\nPrintf.printf \"%d\" (main ());;\n\n\n"}], "src_uid": "371100da1b044ad500ac4e1c09fa8dcb"} {"source_code": "open StdLabels\n\ntype vertex =\n { x : int;\n y : int;\n rot : int;\n }\n\nlet [n; m] = read_line () |> Str.(split (regexp \" \")) |> List.map ~f:int_of_string\nlet s = n * m\n\nlet rotate = function\n | '+' -> '+'\n | '-' -> '|'\n | '|' -> '-'\n | '^' -> '>'\n | '>' -> 'v'\n | 'v' -> '<'\n | '<' -> '^'\n | 'U' -> 'R'\n | 'R' -> 'D'\n | 'D' -> 'L'\n | 'L' -> 'U'\n | '*' -> '*'\n | _ -> failwith \"Unknown block\"\n\nlet maze = Bytes.make (4 * s) ' '\nlet () =\n for y = 0 to n-1 do\n Bytes.blit ~src:(read_line ()) ~src_pos:0 ~dst:maze ~dst_pos:(y * m) ~len:m\n done;\n for i = s to 4 * s - 1 do\n maze.[i] <- rotate maze.[i-s]\n done\n\nlet read_coords () =\n read_line ()\n |> Str.(split (regexp \" \"))\n |> List.map ~f:(fun s -> int_of_string s - 1)\n (* Discovered that (X,Y) are named (Y,X) in problem! *)\n |> fun [y; x] -> y * m + x\n\nlet start = read_coords ()\nlet goal = read_coords ()\n\nlet default d = function\n | Some x -> x\n | None -> d\n\nmodule Int = struct\n type t = int\n let compare = compare\nend\n\nmodule Vertex =\n struct\n type t = vertex\n let compare = compare\n end\n\nmodule PriorityQueue(Priority : Map.OrderedType) =\n struct\n module PriorityMap = Map.Make(Priority)\n\n let create = ref PriorityMap.empty\n\n let add prio elt pq =\n let queue =\n if PriorityMap.mem prio !pq then\n PriorityMap.find prio !pq\n else\n let q = Queue.create () in\n pq := PriorityMap.add prio q !pq;\n q in\n Queue.add elt queue\n\n let pop pq =\n if PriorityMap.is_empty !pq then\n None\n else\n let prio, queue = PriorityMap.min_binding !pq in\n let r = Queue.pop queue in\n if Queue.is_empty queue then\n pq := PriorityMap.remove prio !pq;\n Some r\n end\n\nmodule PriorityVertex =\n struct\n type t = int * Vertex.t\n let compare = compare\n end\n\nmodule VertexSet = Set.Make(Vertex)\n\nmodule VertexQueue = PriorityQueue(Int)\n\nlet astar ?(heuristic = fun v -> 0) ~start ~is_goal =\n let edge_length = 1 in\n let marks = Bytes.make (4*m*n) ' ' in\n let fringe = VertexQueue.create in\n VertexQueue.add (heuristic start) (start, 0) fringe;\n let rec go () =\n match VertexQueue.pop fringe with\n | None -> None\n | Some (v, dist) ->\n if is_goal v then\n Some dist\n else if marks.[v] = '*' then\n go ()\n else\n let dist' = dist + edge_length in\n marks.[v] <- '*';\n let enqueue u =\n if marks.[u] <> '*' then\n VertexQueue.add (dist' + heuristic u) (u, dist') fringe in\n let c = maze.[v] in\n let pl, pu, pr, pd = \"+-DLU\", \"+|vLUR\" in\n let sc = String.contains in\n let xy = v mod s in\n let x = xy mod m and y = xy / m in\n enqueue ((v + s) mod (4 * s));\n if x > 0 && sc pl c && sc pr maze.[v-1] then\n enqueue (v-1);\n if y > 0 && sc pu c && sc pd maze.[v-m] then\n enqueue (v-m);\n if x < m-1 && sc pr c && sc pl maze.[v+1] then\n enqueue (v+1);\n if y < n-1 && sc pd c && sc pu maze.[v+m] then\n enqueue (v+m);\n go () in\n go ()\n\nlet is_goal v = (v - goal) mod s = 0\n\nlet heuristic v =\n let xy = v mod s in\n let dx = xy mod m - goal mod m and dy = xy/m - goal/m in\n abs dx + abs dy\n\nlet () =\n astar ~heuristic ~start ~is_goal\n |> default (-1)\n |> Printf.printf \"%d\\n\"\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n \nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n \nlet () = \n let (n,m) = read_pair () in\n let lab_str = Array.init n (fun _ -> read_string()) in\n let (xt,yt) = read_pair() in\n let (xt,yt) = (xt-1, yt-1) in\n let (xm,ym) = read_pair() in\n let (xm,ym) = (xm-1, ym-1) in\n \n let vt = Array.make_matrix n m 0 in\n\n let visited (i,j,r) = vt.(i).(j) land (1 lsl r) <> 0 in\n let visit (i,j,r) = vt.(i).(j) <- vt.(i).(j) lor (1 lsl r) in\n\n let lab = Array.make_matrix n m [||] in\n \n for i=0 to n-1 do\n for j=0 to m-1 do\n lab.(i).(j) <-\n\tmatch lab_str.(i).[j] with\n\t | '+' -> [|1;1;1;1|]\n\t | '-' -> [|1;0;1;0|]\n\t | '|' -> [|0;1;0;1|]\n\t | '^' -> [|0;1;0;0|]\n\t | '>' -> [|1;0;0;0|]\t \n\t | '<' -> [|0;0;1;0|]\n\t | 'v' -> [|0;0;0;1|]\n\t | 'L' -> [|1;1;0;1|]\n\t | 'R' -> [|0;1;1;1|]\n\t | 'U' -> [|1;0;1;1|]\n\t | 'D' -> [|1;1;1;0|]\n\t | '*' -> [|0;0;0;0|]\n\t | _ -> failwith \"bad input\"\n done\n done;\n\n let out_bounds i j = i < 0 || j < 0 || i > n-1 || j > m-1 in\n \n let neighbors (i,j,r) =\n List.fold_left (fun ac (di,dj,s0) ->\n if lab.(i).(j).((s0+r) mod 4) = 0 then ac\n else if out_bounds (i+di) (j+dj) then ac else\n\tlet s1 = (r + s0 + 2) mod 4 in\n\tif lab.(i+di).(j+dj).(s1) = 0 then ac else (i+di, j+dj, r)::ac\n ) [(i, j, (r+1) mod 4)] [(-1,0,1);(1,0,3);(0,-1,2);(0,1,0)]\n in\n\n let rec bfs nodes level = if nodes = [] then None else (\n let new_nodes = List.fold_left (fun ac x ->\n List.fold_left (fun ac y ->\n\tif visited y then ac else (visit y; y::ac)\n ) ac (neighbors x)\n ) [] nodes in\n if visited (xm,ym,0) || visited (xm,ym,1) || visited (xm,ym,2) || visited (xm,ym,3)\n then Some (level+1) else bfs new_nodes (level+1)\n ) in\n\n visit (xt,yt,0);\n \n let answer =\n if (xm,ym) = (xt,yt) then 0\n else match bfs [(xt,yt,0)] 0 with None -> -1 | Some level -> level\n in\n\n printf \"%d\\n\" answer\n"}, {"source_code": "open StdLabels\n\ntype vertex =\n { x : int;\n y : int;\n rot : int;\n }\n\nlet [n; m] = read_line () |> Str.(split (regexp \" \")) |> List.map ~f:int_of_string\nlet s = n * m\n\nlet rotate = function\n | '+' -> '+'\n | '-' -> '|'\n | '|' -> '-'\n | '^' -> '>'\n | '>' -> 'v'\n | 'v' -> '<'\n | '<' -> '^'\n | 'U' -> 'R'\n | 'R' -> 'D'\n | 'D' -> 'L'\n | 'L' -> 'U'\n | '*' -> '*'\n | _ -> failwith \"Unknown block\"\n\nlet maze = Bytes.make (4 * s) ' '\nlet () =\n for y = 0 to n-1 do\n Bytes.blit ~src:(read_line ()) ~src_pos:0 ~dst:maze ~dst_pos:(y * m) ~len:m\n done;\n for i = s to 4 * s - 1 do\n maze.[i] <- rotate maze.[i-s]\n done\n\nlet read_coords () =\n read_line ()\n |> Str.(split (regexp \" \"))\n |> List.map ~f:(fun s -> int_of_string s - 1)\n (* Discovered that (X,Y) are named (Y,X) in problem! *)\n |> fun [y; x] -> y * m + x\n\nlet start = read_coords ()\nlet goal = read_coords ()\n\nlet default d = function\n | Some x -> x\n | None -> d\n\nmodule Int = struct\n type t = int\n let compare = compare\nend\n\nmodule Vertex =\n struct\n type t = vertex\n let compare = compare\n end\n\nmodule PriorityQueue(Priority : Map.OrderedType) =\n struct\n module PriorityMap = Map.Make(Priority)\n\n let create = ref PriorityMap.empty\n\n let add prio elt pq =\n let queue =\n if PriorityMap.mem prio !pq then\n PriorityMap.find prio !pq\n else\n let q = Queue.create () in\n pq := PriorityMap.add prio q !pq;\n q in\n Queue.add elt queue\n\n let pop pq =\n if PriorityMap.is_empty !pq then\n None\n else\n let prio, queue = PriorityMap.min_binding !pq in\n let r = Queue.pop queue in\n if Queue.is_empty queue then\n pq := PriorityMap.remove prio !pq;\n Some r\n end\n\nmodule Graph =\n struct\n module PriorityVertex =\n struct\n type t = int * Vertex.t\n let compare = compare\n end\n \n module VertexSet = Set.Make(Vertex)\n\n module VertexQueue = PriorityQueue(Int)\n \n let astar ?(heuristic = fun v -> 0) ~edges ~start ~is_goal =\n let edge_length = 1 in\n let marks = Bytes.make (4*m*n) ' ' in\n let fringe = VertexQueue.create in\n VertexQueue.add (heuristic start) (start, 0) fringe;\n let rec go () =\n match VertexQueue.pop fringe with\n | None -> None\n | Some (v, dist) ->\n if is_goal v then\n Some dist\n else if marks.[v] = '*' then\n go ()\n else\n let dist' = dist + edge_length in\n marks.[v] <- '*';\n List.iter\n ~f:(fun u ->\n if marks.[u] <> '*' then\n VertexQueue.add (dist' + heuristic u) (u, dist') fringe)\n (edges v);\n go () in\n go ()\n end\n\n\nlet edges v =\n let c = maze.[v] in\n let pl, pu, pr, pd = \"+-DLU\", \"+|vLUR\" in\n let sc = String.contains in\n let xy = v mod s in\n let x = xy mod m and y = xy / m in\n let r = ref [(v + s) mod (4 * s)] in\n if x > 0 && sc pl c && sc pr maze.[v-1] then\n r := v-1 :: !r;\n if y > 0 && sc pu c && sc pd maze.[v-m] then\n r := v-m :: !r;\n if x < m-1 && sc pr c && sc pl maze.[v+1] then\n r := v+1 :: !r;\n if y < n-1 && sc pd c && sc pu maze.[v+m] then\n r := v+m :: !r;\n !r\n\nlet is_goal v = (v - goal) mod s = 0\n\nlet heuristic v =\n let xy = v mod s in\n let dx = xy mod m - goal mod m and dy = xy/m - goal/m in\n abs dx + abs dy\n\nlet () =\n Graph.astar ~heuristic ~edges ~start ~is_goal\n |> default (-1)\n |> Printf.printf \"%d\\n\"\n"}], "negative_code": [], "src_uid": "fbc119b603ca87787628a3f4b7db8c33"} {"source_code": "let input = open_in \"input.txt\" ;;\nlet output = open_out \"output.txt\" ;;\n\nlet read_int () = Scanf.fscanf input \" %d \" (fun x -> x) ;;\n\nlet n = read_int () ;;\n\nlet olympiads = \n let rec loop i f =\n if i = n then f [] \n else let m = read_int () and d = read_int () and \n p = read_int () and t = read_int ()\n in loop (i + 1) (fun l -> f ((m, d, p, t) :: l))\n in loop 0 (fun x -> x) ;;\n\n(* Create a cumulative array of days since January 1, 2012 for the year 2013 *) \nlet months = [|0; 31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31|]\nlet cumulative_days = Array.make 13 366 ;;\nfor i = 1 to 12 do\n cumulative_days.(i) <- months.(i) + cumulative_days.(i - 1)\ndone ;;\n\nlet start m d t = cumulative_days.(m - 1) + d - t ;;\n\nlet olympiads = \n let compare (m1, d1, p1, t1) (m2, d2, p2, t2) = \n (start m1 d1 t1) - (start m2 d2 t2)\n in List.sort compare olympiads ;;\n\nlet jury_size olympiads = \n let rec loop oly intersection size = match oly with\n | [] -> size\n | (m1, d1, p1, t1) as hd1 :: tl1 ->\n let rec filter l s f = match l with\n | [] -> (s, f [hd1])\n | (m2, d2, p2, t2) as hd2 :: tl2 -> \n if (start m1 d1 t1) > (start m2 d2 1) then filter tl2 s f\n else filter tl2 (s + p2) (fun v -> f (hd2 :: v))\n in let (newsize, newinter) = filter intersection p1 (fun x -> x)\n in loop tl1 newinter (max newsize size)\n in loop olympiads [] 0 ;;\n \nPrintf.fprintf output \"%d\\n\" (jury_size olympiads);;\n ", "positive_code": [{"source_code": "let chan = Scanf.Scanning.from_file \"input.txt\"\nlet read_int () = Scanf.bscanf chan \" %d\" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet h = Array.make 1000 0\nlet offset = 500\n\nlet day_number m d = \n let dpm = [|31;28;31;30;31;30;31;31;30;31;30;31|] in\n let md = sum 0 (m-2) (fun i->dpm.(i)) in\n md + (d-1)\n\nlet () = \n let n = read_int() in\n for i=1 to n do\n let m = read_int() in\n let d = read_int() in\n let p = read_int() in\n let t = read_int() in\n let dn = day_number m d in\n for j=dn-t to dn-1 do\n h.(j+offset) <- h.(j+offset) + p\n done;\n done;\n print_string (Printf.sprintf \"%d\\n\" (maxf 0 999 (fun i-> h.(i))))"}, {"source_code": "let chan = Scanf.Scanning.from_file \"input.txt\"\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet h = Array.make 1000 0\nlet offset = 500\n\nlet day_number m d = \n let dpm = [|31;28;31;30;31;30;31;31;30;31;30;31|] in\n let md = sum 0 (m-2) (fun i->dpm.(i)) in\n md + (d-1)\n\nlet () = \n let n = read_int() in\n for i=1 to n do\n let m = read_int() in\n let d = read_int() in\n let p = read_int() in\n let t = read_int() in\n let dn = day_number m d in\n for j=dn-t to dn-1 do\n h.(j+offset) <- h.(j+offset) + p\n done;\n done;\n print_string (Printf.sprintf \"%d\\n\" (maxf 0 999 (fun i-> h.(i))))"}, {"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet h = Array.make 1000 0\nlet offset = 500\n\nlet day_number m d = \n let dpm = [|31;28;31;30;31;30;31;31;30;31;30;31|] in\n let md = sum 0 (m-2) (fun i->dpm.(i)) in\n md + (d-1)\n\nlet () = \n let n = read_int() in\n for i=1 to n do\n let m = read_int() in\n let d = read_int() in\n let p = read_int() in\n let t = read_int() in\n let dn = day_number m d in\n\tfor j=dn-t to dn-1 do\n\t h.(j+offset) <- h.(j+offset) + p\n\tdone;\n done;\n print_string (Printf.sprintf \"%d\\n\" (maxf 0 999 (fun i-> h.(i))))\n"}], "negative_code": [], "src_uid": "34655e8de9f1020677c5681d9d217d75"} {"source_code": "let change c =\r\n char_of_int (int_of_char 'a' + (1 - ((int_of_char c) - (int_of_char 'a'))))\r\n\r\nlet solve s =\r\n let rec count s i res =\r\n if i < String.length s then \r\n if (s.[i] != s.[i-1]) \r\n then count s (i+1) (res+1)\r\n else count s (i+1) res \r\n else res\r\n in let res = count s 1 0 in\r\n if (res mod 2) == 1\r\n then (String.make 1 (change s.[0])) ^ (String.sub s 1 ((String.length s) - 1))\r\n else s\r\n\r\n\r\n\r\n\r\nlet () =\r\n let tc = Scanf.scanf \" %d\" (fun x -> x) in\r\n let rec loop tc =\r\n match tc with\r\n |0 -> ()\r\n |_ -> Printf.printf \"%s\\n\" (solve (Scanf.scanf \" %s\" (fun x ->x))); loop (tc - 1);\r\n in loop tc\r\n\r\n\r\n", "positive_code": [{"source_code": "let solve s =\n (String.make 1 s.[(String.length s - 1)]) ^ String.sub s 1 (String.length s - 1)\n \nlet () =\n let tc = Scanf.scanf \" %d\" (fun x -> x) in\n (let rec loop tc =\n match tc with\n | 0 -> ()\n | _ -> Printf.printf \"%s\\n\" (solve (Scanf.scanf \" %s\" (fun x ->x))); loop (tc - 1);\n in loop tc)"}], "negative_code": [], "src_uid": "351ffff1dfe1bc1762f062f612463759"} {"source_code": "open Printf\nopen Scanf\nopen String\nopen Array\nopen List\nopen Int64\n\nlet a = make 8 0;;\n\nlet rec read n =\n\tif n=0 then ()\n\telse (let x = scanf \" %d\" (fun y->y)\n\t\tin a.(x) <- a.(x)+1; read (n-1));;\n\nlet rec print s n =\n\tif n=0 then ()\n\telse (printf s; print s (n-1));;\n\nlet ok m =\n\tlet n136 = a.(3) in\n\tlet n124 = a.(4) in\n\tlet n126 = m - n136 - n124 in\n\tif n126 < 0 then false\n\telse if a.(1) <> m then false\n\telse if a.(2) <> n124 + n126 then false\n\telse if a.(6) <> n126 + n136 then false\n\telse\n\t\t(print \"1 2 4\\n\" n124;\n\t\tprint \"1 2 6\\n\" n126;\n\t\tprint \"1 3 6\\n\" n136;\n\t\ttrue);;\n\nlet solve n =\n\tread n;\n\tif not (ok (n/3)) then printf \"-1\"\n\telse ()\nin scanf \"%d\" solve;;", "positive_code": [{"source_code": "let read_int _ = Scanf.scanf \" %d\" (fun x -> x)\nlet read_string _ = Scanf.scanf \" %s\" (fun x -> x)\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 \n let implode l =\n let result = String.create (List.length l) in\n let rec imp i = function\n | [] -> result\n | c :: l -> result.[i] <- c; imp (i + 1) l in\n imp 0 l;;\n \nlet (--) i j = \n let rec aux n acc =\n if n < i then acc else aux (n-1) (n :: acc)\n in aux j []\n \n let () = \n let n = read_int () in\n let arr = Array.init n read_int in\n let count = Array.init 8 (fun _ -> 0) in\n let ok = Array.fold_right (fun x ok ->\n if ok = false || (x = 5 || x = 7) then false\n else begin\n count.(x) <- count.(x) + 1;\n true\n end\n ) arr true\n in\n let bad = ref (ok = false) in\n bad := !bad || (count.(1) <> n / 3);\n bad := !bad || (count.(4) + count.(6) <> n / 3);\n bad := !bad || (count.(2) + count.(3) <> n / 3);\n bad := !bad || (count.(3) > count.(6));\n bad := !bad || (count.(2) <> count.(4) + count.(6) - count.(3));\n if !bad then Printf.printf \"-1\\n\"\n else begin\n let limit = count.(3) in\n for i = 1 to limit do\n Printf.printf \"1 3 6\\n\";\n count.(6) <- count.(6) - 1;\n done;\n for i = 1 to count.(4) do\n Printf.printf \"1 2 4\\n\";\n done;\n for i = 1 to count.(6) do\n Printf.printf \"1 2 6\\n\";\n done;\n end\n"}], "negative_code": [{"source_code": "open String\nopen List\nopen Printf\nopen Scanf\n\n\n"}, {"source_code": "let read_int _ = Scanf.scanf \" %d\" (fun x -> x)\nlet read_string _ = Scanf.scanf \" %s\" (fun x -> x)\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 \n let implode l =\n let result = String.create (List.length l) in\n let rec imp i = function\n | [] -> result\n | c :: l -> result.[i] <- c; imp (i + 1) l in\n imp 0 l;;\n \nlet (--) i j = \n let rec aux n acc =\n if n < i then acc else aux (n-1) (n :: acc)\n in aux j []\n \n let () = \n let n = read_int () in\n let arr = Array.init n read_int in\n let count = Array.init 8 (fun _ -> 0) in\n let ok = Array.fold_right (fun x ok ->\n if ok = false || (x = 5 || x = 7) then false\n else begin\n count.(x) <- count.(x) + 1;\n true\n end\n ) arr true\n in\n let bad = ref (ok = false) in\n bad := !bad || (count.(1) <> n / 3);\n bad := !bad || (count.(4) + count.(6) <> n / 3);\n bad := !bad || (count.(2) + count.(3) <> n / 3);\n bad := !bad || (count.(2) <> count.(4) + count.(6) - count.(3));\n if !bad then Printf.printf \"-1\\n\"\n else begin\n let limit = count.(3) in\n for i = 1 to limit do\n Printf.printf \"1 3 6\\n\";\n count.(6) <- count.(6) - 1;\n done;\n for i = 1 to count.(4) do\n Printf.printf \"1 2 4\\n\";\n done;\n for i = 1 to count.(6) do\n Printf.printf \"1 2 6\\n\";\n done;\n end\n"}], "src_uid": "513234db1bab98c2c2ed6c7030c1ac72"} {"source_code": "let get_tbl n =\n let tbl = Hashtbl.create 100000 in\n let rec loop count =\n if count > n then tbl\n else\n begin\n\tHashtbl.add tbl (Scanf.scanf \" %d\" (fun x -> x)) (Int64.of_int(count));\n\tloop (count+1)\n end\n in\n loop 1\n\nlet rec get_int_list n =\n if n = 0 then []\n else (Scanf.scanf \" %d\" (fun x -> x)) :: get_int_list (n-1)\n\nlet solve tbl len queries =\n let accm_func ans q=\n let nth = Hashtbl.find tbl q in\n ((Int64.add (fst ans) nth),\n (Int64.sub (Int64.add (snd ans) (Int64.of_int(len+1))) nth))\n in\n List.fold_left accm_func (Int64.zero, Int64.zero) queries\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let tbl = get_tbl n in\n let m = Scanf.scanf \" %d\" (fun x -> x) in\n let queries = get_int_list m in\n let ans = solve tbl n queries in\n Printf.printf \"%Ld %Ld\\n\" (fst ans) (snd ans)\n", "positive_code": [{"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let nowhere = -1 in\n let lefts = Array.make n nowhere in\n let rights = Array.make n nowhere in\n for i = 1 to n do\n let a = read \"%d \" (fun x -> x - 1) in\n if lefts.(a) = nowhere then lefts.(a) <- i;\n rights.(a) <- n - i + 1\n done;\n let left = ref (Int64.of_int 0) in\n let right = ref (Int64.of_int 0) in\n let m = read \"%d\\n\" (fun x -> x) in\n for i = 1 to m do\n let q = read \" %d\" (fun x -> x - 1) in\n left := Int64.add !left (Int64.of_int lefts.(q));\n right := Int64.add !right (Int64.of_int rights.(q))\n done;\n Printf.printf \"%Ld %Ld\\n\" !left !right \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "\nlet read format f = Scanf.bscanf Scanf.Scanning.stdib format f\n\nlet () =\n let n = read \"%d\\n\" (fun x -> x) in\n let nowhere = -1 in\n let lefts = Array.make n nowhere in\n let rights = Array.make n nowhere in\n for i = 1 to n do\n let a = read \"%d \" (fun x -> x - 1) in\n if lefts.(a) = nowhere then lefts.(a) <- i;\n rights.(a) <- n - i + 1\n done;\n let left = ref 0 in\n let right = ref 0 in\n let m = read \"%d\\n\" (fun x -> x) in\n for i = 1 to m do\n let q = read \" %d\" (fun x -> x - 1) in\n left := !left + lefts.(q);\n right := !right + rights.(q)\n done;\n Printf.printf \"%d %d\\n\" !left !right \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let get_tbl n =\n let tbl = Hashtbl.create 100000 in\n let rec loop count =\n if count > n then tbl\n else\n begin\n\tHashtbl.add tbl (Scanf.scanf \" %d\" (fun x -> x)) (Int32.of_int(count));\n\tloop (count+1)\n end\n in\n loop 1\n\nlet rec get_int_list n =\n if n = 0 then []\n else (Scanf.scanf \" %d\" (fun x -> x)) :: get_int_list (n-1)\n\nlet solve tbl len queries =\n let accm_func ans q=\n let nth = Hashtbl.find tbl q in\n ((Int32.add (fst ans) nth),\n (Int32.sub (Int32.add (snd ans) (Int32.of_int(len+1))) nth))\n in\n List.fold_left accm_func (Int32.zero, Int32.zero) queries\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let tbl = get_tbl n in\n let m = Scanf.scanf \" %d\" (fun x -> x) in\n let queries = get_int_list m in\n let ans = solve tbl n queries in\n Printf.printf \"%ld %ld\\n\" (fst ans) (snd ans)\n"}, {"source_code": "let get_tbl n =\n let tbl = Hashtbl.create 100000 in\n let rec loop count =\n if count > n then tbl\n else\n begin\n\tHashtbl.add tbl (Scanf.scanf \" %d\" (fun x -> x)) count;\n\tloop (count+1)\n end\n in\n loop 1\n\nlet rec get_int_list n =\n if n = 0 then []\n else (Scanf.scanf \" %d\" (fun x -> x)) :: get_int_list (n-1)\n\nlet solve tbl len queries =\n let accm_func ans q=\n let nth = Hashtbl.find tbl q in\n ((fst ans)+nth, (snd ans)+len-nth+1)\n in\n List.fold_left accm_func (0, 0) queries\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let tbl = get_tbl n in\n let m = Scanf.scanf \" %d\" (fun x -> x) in\n let queries = get_int_list m in\n let ans = solve tbl n queries in\n Printf.printf \"%d %d\\n\" (fst ans) (snd ans)\n"}], "src_uid": "b7aef95015e326307521fd59d4fccb64"} {"source_code": "(* Added sentenials to the left and right end of the list.\n Their (l,r,c) would be (-1,0,0) on the left and\n (n,n+1,0) on the right.\n\n The histogram table keeps characters 0...k. In other\n words an additional character 0 in order to simplify\n the cases in the code.\n*)\n\nmodule Pset = Set.Make (struct type t = int*int*int let compare = compare end)\n(* (l,r+1,character) *)\n\n(* a string s is represented as a set of these triples. For example if\n the string is \"abbbbaacce\" then it is:\n 0123456789\n (-1,0,k) (0,1,a) (1,5,b) (5,7,a) (7,9,c) (9,10,e) (10,11,k)\n\n The histogram is a (k+1) by (k+1) matrix of counts. It's the\n number of times each such transition occurs in the string.\n*)\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 \nlet l2n c = (int_of_char c) - (int_of_char 'a') \n \nlet split2 set e put_tie_left =\n let (a,x,b) = Pset.split e set in\n if not x then (a,b) else\n if put_tie_left then (Pset.add e a, b) else (a, Pset.add e b)\n\nlet pred set e =\n (* e is in the set. Return it's predecessor. It must be there *)\n let (l,_,_) = Pset.split e set in\n Pset.max_elt l\n\nlet succ set e =\n let (_,_,r) = Pset.split e set in\n Pset.min_elt r\n\nlet inc hist i j d =\n hist.(i).(j) <- hist.(i).(j) + d\n \nlet update str n l r c hist =\n (* Update the str (of length n) with a new block of chars c from l\n to r-1. (Note this is different from the problem statement.)\n Return str, the updated version of the string. the histogram is\n updated in place. *)\n\n let first = (* the first one we're going to replace *)\n let (partl, _, _) = Pset.split (l,n+2,0) str in\n Pset.max_elt partl\n in\n\n let last = (* the last one we're going to replace *)\n let (partl, _, _) = Pset.split (r,-2,0) str in \n Pset.max_elt partl\n in\n\n let (left_part,_,_) = Pset.split first str in\n let (_,_,right_part) = Pset.split last str in\n \n let list_of_range str a b =\n let (_,partr) = split2 str a false in\n let (partl,_) = split2 partr b true in\n List.rev (Pset.fold (fun e ac -> e::ac) partl [])\n in\n\n let before_first = pred str first in\n let after_last = succ str last in\n let rem_t = list_of_range str before_first after_last in\n\n let rec rem_scan (l0,r0,c0) li =\n match li with\n | [] -> failwith \"scan called with empty list\"\t\n | (l,r,c)::[] -> inc hist c0 c (-1)\n | (l,r,c)::tail ->\n\tinc hist c0 c (-1);\n\tinc hist c c (-(r-l-1));\n\trem_scan (l,r,c) tail\n in\n\n rem_scan (List.hd rem_t) (List.tl rem_t);\n (* removes all the obsolete transitions *)\n \n let (l0,r0,c0) = first in\n let (l1,r1,c1) = last in\n\n let lphantom = if l0 < l then [(l0,l,c0)] else [] in\n let rphantom = if r1 > r then [(r,r1,c1)] else [] in\n let new_middle = lphantom @ [(l,r,c)] @ rphantom in\n \n let rec add_scan (l0,r0,c0) li =\n match li with\n | [] -> failwith \"scan called with empty list\"\t\n | (l,r,c)::[] -> inc hist c0 c 1\n | (l,r,c)::tail ->\n\tinc hist c0 c 1;\n\tinc hist c c (r-l-1);\n\tadd_scan (l,r,c) tail\n in\n\n add_scan before_first (new_middle @ [after_last]);\n\n let newstr = Pset.union left_part right_part in\n List.fold_left (fun ac e -> Pset.add e ac) newstr new_middle\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let m = read_int () in \n let k = read_int () in\n let s = read_string () in\n\n let rec find_changes s n i ac = if i=n then List.rev (n::ac) else\n if s.[i-1] <> s.[i] then find_changes s n (i+1) (i::ac)\n else find_changes s n (i+1) ac\n in\n\n let changes = Array.of_list (find_changes s n 1 []) in\n(*\n printf \"changes = \";\n for i=0 to -1+ Array.length changes do\n printf \"%d \" changes.(i)\n done;\n print_newline();\n*) \n let str = fold 0 (-2 + Array.length changes) (\n fun i ac -> Pset.add (changes.(i), changes.(i+1), l2n s.[changes.(i)]) ac\n ) (Pset.singleton (0, changes.(0), l2n s.[0])) in\n\n let str = Pset.add (-1,0,k) str in\n let str = Pset.add (n,n+1,k) str in\n\n let hist = Array.make_matrix (k+1) (k+1) 0 in\n for i=0 to n-2 do\n inc hist (l2n s.[i]) (l2n s.[i+1]) 1\n done;\n inc hist k (l2n s.[0]) 1;\n inc hist (l2n s.[n-1]) k 1;\n\n let rec loop i str = if i=m then () else (\n match read_int() with\n\t| 1 ->\n\t let l = -1 + read_int () in\n\t let r = read_int () in\n\t let c = l2n (read_string()).[0] in\n\t let str = update str n l r c hist in\n\t loop (i+1) str\n\t| 2 ->\n\t let p = read_string() in\n\t let p = Array.init k (fun i -> l2n p.[i]) in\n\t let inv = Array.make k 0 in\n\t for i=0 to k-1 do\n\t inv.(p.(i)) <- i\n\t done;\n\t let cycles = sum 0 (k-1) (fun i -> sum 0 (k-1) (fun j ->\n\t if inv.(i) < inv.(j) then 0 else hist.(i).(j)\n\t )) in\n\t printf \"%d\\n\" (cycles+1);\n\t loop (i+1) str\n\t| _ -> failwith \"bad input\"\n ) in\n \n loop 0 str\n", "positive_code": [{"source_code": "module Pset = Set.Make (struct type t = int*int*int let compare = compare end)\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 \nlet l2n c = (int_of_char c) - (int_of_char 'a') \n \nlet split2 set e put_tie_left =\n let (a,x,b) = Pset.split e set in\n if not x then (a,b) else\n if put_tie_left then (Pset.add e a, b) else (a, Pset.add e b)\n\nlet pred set e =\n let (l,_,_) = Pset.split e set in\n Pset.max_elt l\n\nlet succ set e =\n let (_,_,r) = Pset.split e set in\n Pset.min_elt r\n\nlet inc h i j d =\n h.(i).(j) <- h.(i).(j) + d\n \nlet update str n l r c hist =\n let first = (* the first one we're going to replace *)\n let (partl, _, _) = Pset.split (l,n+2,0) str in\n Pset.max_elt partl\n in\n\n let last = (* the last one we're going to replace *)\n let (partl, _, _) = Pset.split (r,-2,0) str in \n Pset.max_elt partl\n in\n\n let (left_part,_,_) = Pset.split first str in\n let (_,_,right_part) = Pset.split last str in\n \n let list_of_range str a b =\n let (_,partr) = split2 str a false in\n let (partl,_) = split2 partr b true in\n List.rev (Pset.fold (fun e ac -> e::ac) partl [])\n in\n\n let before_first = pred str first in\n let after_last = succ str last in\n let rem_t = list_of_range str before_first after_last in\n\n let rec rem_scan (l0,r0,c0) li =\n match li with\n | [] -> failwith \"scan called with empty list\"\t\n | (l,r,c)::[] -> inc hist c0 c (-1)\n | (l,r,c)::tail ->\n\tinc hist c0 c (-1);\n\tinc hist c c (-(r-l-1));\n\trem_scan (l,r,c) tail\n in\n\n rem_scan (List.hd rem_t) (List.tl rem_t);\n \n let (l0,r0,c0) = first in\n let (l1,r1,c1) = last in\n\n let lphantom = if l0 < l then [(l0,l,c0)] else [] in\n let rphantom = if r1 > r then [(r,r1,c1)] else [] in\n let new_middle = lphantom @ [(l,r,c)] @ rphantom in\n \n let rec add_scan (l0,r0,c0) li =\n match li with\n | [] -> failwith \"scan called with empty list\"\t\n | (l,r,c)::[] -> inc hist c0 c 1\n | (l,r,c)::tail ->\n\tinc hist c0 c 1;\n\tinc hist c c (r-l-1);\n\tadd_scan (l,r,c) tail\n in\n\n add_scan before_first (new_middle @ [after_last]);\n\n let newstr = Pset.union left_part right_part in\n List.fold_left (fun ac e -> Pset.add e ac) newstr new_middle\n\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_conv_str () =\n let s = bscanf Scanning.stdib \" %s \" (fun x -> x) in\n Array.init (String.length s) (fun i -> l2n s.[i])\n \nlet () =\n let n = read_int () in\n let m = read_int () in \n let k = read_int () in\n let s = read_conv_str () in\n\n let str = Pset.singleton (-1,0,k) in\n let str = Pset.add (n,n+1,k) str in\n\n let str = fold 0 (n-1) (\n fun i ac -> Pset.add (i, i+1, s.(i)) ac\n ) str in\n\n let hist = Array.make_matrix (k+1) (k+1) 0 in\n for i=0 to n-2 do\n inc hist s.(i) s.(i+1) 1\n done;\n\n ignore (fold 0 (m-1) (fun _ str ->\n match read_int() with\n | 1 ->\n\tlet l = -1 + read_int () in\n\tlet r = read_int () in\n\tlet c = (read_conv_str()).(0) in\n\tupdate str n l r c hist\n | 2 ->\n\tlet p = read_conv_str() in\n\tlet cycles = sum 0 (k-1) (fun i -> sum 0 i (fun j -> hist.(p.(i)).(p.(j)))) in\n\tprintf \"%d\\n\" (cycles+1);\n\tstr\n | _ -> failwith \"bad input\"\n ) str)\n"}], "negative_code": [], "src_uid": "ed56526ea39d477bcc549c8ff11ed3e2"} {"source_code": "\nlet rec watch curr skip watched lst =\n let is_skippable curr skip range =\n match (curr, skip, range) with\n c, s, [l; r;] when c + s <= l -> true\n | _ -> false\n in\n match lst with\n [] -> watched\n | _ ->\n let next = List.hd lst in\n let right = List.nth next 1\n in\n if is_skippable curr skip next then\n watch (curr + skip) skip watched lst\n else\n let minutes = right - curr + 1\n in\n watch (right + 1) skip (watched + minutes) (List.tl lst)\n;;\n\nlet words s = Str.split (Str.regexp \" \") s;; \n\nlet rec make_ranges lines =\n let rec inner lines rv =\n let range s = List.map int_of_string (words s) in\n match lines with\n [] -> rv\n | (l::ls) -> inner ls (List.append rv [range l])\n in\n inner lines []\n;;\n\nlet rec read_lines n =\n let rec inner m rv =\n match m with\n 0 -> rv\n | k -> inner (k - 1) (List.append rv [read_line ()])\n in\n inner n []\n;;\n\nlet () =\n let nk_line = read_line () in\n let [nline; skip] = List.map int_of_string (words nk_line) in\n let scenes = make_ranges (read_lines nline) in\n Printf.printf \"%d\\n\" (watch 1 skip 0 scenes)\n;;\n \n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d %d\\n\" (fun n x ->\n let rec aux a t i =\n if i = n then a\n else begin\n let l, r = Scanf.scanf \"%d %d\\n\" (fun l r -> (l, r)) in\n let b = (l - t) mod x in\n let a = a + b + r - l + 1 in\n aux a (succ r) (succ i)\n end\n in\n Printf.printf \"%d\\n\" (aux 0 1 0)\n)\n"}, {"source_code": "module A = Array;;\nmodule C = Char;;\nmodule L = List;;\nmodule S = String;;\n\nlet pf = Printf.printf;;\nlet sf = Scanf.scanf;;\nlet ssf = Scanf.sscanf;;\n\nlet (|>) x f = f x;;\nlet (@@) f x = f x;;\nlet id x = x;;\nlet id2 x y = (x, y);;\nlet id3 x y z = (x, y, z);;\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\nlet _ =\n let (n, x) = sf \"%d %d\\n\" id2 in\n let now = ref 0 in\n let res = ref 0 in\n for i = 1 to n do\n let (l, r) = sf \"%d %d\\n\" id2 in\n res := !res + (r - !now) - (l - !now - 1) / x * x;\n now := r\n done;\n pf \"%d\\n\" !res\n;;\n"}], "negative_code": [], "src_uid": "ac33b73da5aaf2139b348a9c237f93a4"} {"source_code": "\n(* Utils\n --------------------------------------------------------------------------- *)\n\nlet read_int () =\n Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet read_string () =\n Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet ( |> ) x f = f x\n\n\n(* Solution \n --------------------------------------------------------------------------- *)\n\nlet _ =\n let s1 = read_line () in\n let s2 = read_line () in\n \n let c47 = ref 0 in\n let c74 = ref 0 in\n\n for i = 0 to String.length s1 - 1 do\n match (s1.[i], s2.[i]) with\n | '4', '7' -> incr c47\n | '7', '4' -> incr c74\n | _ -> ()\n done;\n\n Printf.printf \"%d\" (max !c47 !c74)\n", "positive_code": [{"source_code": "(* codeforces 104. 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 a = read_string() in\n let b = read_string() in\n let n = String.length a in\n let rec count i a47 a74 = if i=n then (a47,a74) else \n match (a.[i],b.[i]) with\n | ('4','7') -> count (i+1) (a47+1) a74\n | ('7','4') -> count (i+1) a47 (a74+1)\n | _ -> count (i+1) a47 a74\n in\n let (c47,c74) = count 0 0 0 in\n Printf.printf \"%d\\n\" (max c47 c74)\n"}], "negative_code": [], "src_uid": "2d1609b434262d30f6bd030d41a71bd5"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\nlet read_point () = Scanf.scanf \" %d %d\" (fun x y -> float x, float y)\n\nlet n = read_int ()\nlet p = read_point ()\nlet first = read_point ()\nlet prev = ref (0., 0.)\nlet () = prev := first\nlet minimum = ref infinity\nlet maximum = ref 0.\nlet pi = 3.14159265\n\nlet on_segment (x1, y1) (x, y) (x2, y2) =\n (x -. x1) *. (x -. x2) <= 0. && (y -. y1) *. (y -. y2) <= 0.\n\nlet min_and_max p1 p2 =\n let d (x, y) = sqrt ((fst p -. x)**2. +. (snd p -. y)**2.) in\n let rzut_p (x1, y1) (x2, y2) =\n let skal (x1, y1) (x2, y2) (x3, y3) =\n (x2 -. x1) *. (x3 -. x1) +. (y2 -. y1) *. (y3 -. y1)\n in\n let s = skal (x1, y1) p (x2, y2) /. skal (x1, y1) (x2, y2) (x2, y2) in\n ((x1 +. (x2 -. x1) *. s), (y1 +. (y2 -. y1) *. s))\n in\n let rzut = rzut_p p1 p2 in\n let min = if on_segment p1 rzut p2 then d rzut else min (d p1) (d p2) in\n (min, max (d p1) (d p2) )\n\nlet print_point (x, y) =\n print_float x;\n print_string \" \";\n print_float y;\n print_newline()\n\nlet add cur =\n let mini, maxi = min_and_max !prev cur in\n (if mini < !minimum then minimum := mini else ());\n (if maxi > !maximum then maximum := maxi else ());\n prev := cur\n;;\n\nlet () =\n for i = 1 to n - 1 do\n let cur = read_point () in\n add cur\n done;\n add first\n\nlet () =\n (pi *. !maximum ** 2. -. pi *. !minimum ** 2.) |> print_float;\n print_newline ()\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %f %f \" (fun x y -> (x,y))\n\nlet long x = Int64.of_int x\n\nlet cross (x1,y1) (x2,y2) = (x1*.y2) -. (y1*.x2)\nlet ( -- ) (x1,y1) (x2,y2) = (x1-.x2, y1-.y2)\nlet len (x,y) = sqrt(x*.x +. y*.y)\nlet dot (x1,y1) (x2,y2) = x1*.x2 +. y1*.y2\nlet mul c (x,y) = (c*.x, c*.y)\nlet sq x = x *. x\n \nlet dist p q r = (* the distance from point r to the line from point p to point q *)\n let a = q -- p in\n let b = r -- p in\n let an = mul (1.0 /. (len a)) a in\n let v = mul (dot an b) an in\n if len v <= len a && (dot v a) >= 0.0 then len (b -- v) else 1e15\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i) \nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet pi = 2.0 *. asin 1.0\n \nlet dist2 (a,b) (c,d) =\n let x = a-.c in\n let y = b-.d in\n ((x*.x) +. (y*.y))\n\n \nlet () = \n let n = read_int () in\n let p = read_pair () in\n let poly = Array.init n (fun _ -> read_pair()) in\n\n let inner = minf 0 (n-1) (fun i->\n min (dist2 p poly.(i)) (sq (dist poly.(i) poly.((i+1) mod n) p))\n ) in\n let outer = maxf 0 (n-1) (fun i-> dist2 p poly.(i)) in\n\n printf \"%.8f\\n\" (pi *. (outer -. inner))\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i) \nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet pi = 2.0 *. asin 1.0\n \nlet dist (a,b) (c,d) =\n let x = float (a-c) in\n let y = float (b-d) in\n sqrt ((x*.x) +. (y*.y))\n \nlet () = \n let n = read_int () in\n let p = read_pair () in\n let poly = Array.init n (fun _ -> read_pair()) in\n\n let inner = minf 0 (n-1) (fun i-> dist p poly.(i)) in\n let outer = maxf 0 (n-1) (fun i-> dist p poly.(i)) in\n\n printf \"%.8f\\n\" (pi *. (outer *. outer -. inner *. inner))\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i) \nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet pi = 2.0 *. asin 1.0\n \nlet dist (a,b) (c,d) =\n let x = float (a-c) in\n let y = float (b-d) in\n sqrt ((x*.x) +. (y*.y))\n \nlet () = \n let n = read_int () in\n let p = read_pair () in\n let poly = Array.init n (fun _ -> read_pair()) in\n\n let inner = minf 0 (n-1) (fun i-> dist p poly.(i)) in\n let outer = maxf 0 (n-1) (fun i-> dist p poly.(i)) in\n\n printf \"%.8f\\n\" (pi *. (outer -. inner) *. (outer +. inner))\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\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 rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i) \nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet pi = 2.0 *. asin 1.0\n \nlet dist2 (a,b) (c,d) =\n let x = long (a-c) in\n let y = long (b-d) in\n ((x**x) ++ (y**y))\n \nlet () = \n let n = read_int () in\n let p = read_pair () in\n let poly = Array.init n (fun _ -> read_pair()) in\n\n let inner = minf 0 (n-1) (fun i-> dist2 p poly.(i)) in\n let outer = maxf 0 (n-1) (fun i-> dist2 p poly.(i)) in\n\n printf \"%.8f\\n\" (pi *. Int64.to_float (outer -- inner))\n"}], "src_uid": "1d547a38250c7780ddcf10674417d5ff"} {"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 0L in\n let () =\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- Int64.of_int k\n done\n in\n let res = ref 0L in\n for i = 0 to n - 2 do\n let p = ref 1 in\n\twhile !p * 2 + i < n do\n\t p := !p * 2;\n\tdone;\n\tres := Int64.add !res a.(i);\n\ta.(i + !p) <- Int64.add a.(i + !p) a.(i);\n\ta.(i) <- 0L;\n\tPrintf.printf \"%Ld\\n\" !res;\n done\n", "positive_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 0L in\n let () =\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- Int64.of_int k\n done\n in\n let res = ref 0L in\n for i = 0 to n - 2 do\n let p = ref 1 in\n\twhile !p * 2 + i < n do\n\t p := !p * 2;\n\tdone;\n\tres := Int64.add !res a.(i);\n\ta.(i + !p) <- Int64.add a.(i + !p) a.(i);\n\ta.(i) <- 0L;\n\tPrintf.printf \"%Ld\\n\" !res;\n done\n"}, {"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 0L in\n let () =\n for i = 0 to n - 1 do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- Int64.of_int k\n done\n in\n let res = ref 0L in\n for i = 0 to n - 2 do\n let p = ref 1 in\n\twhile !p * 2 + i < n do\n\t p := !p * 2;\n\tdone;\n\tres := Int64.add !res a.(i);\n\ta.(i + !p) <- Int64.add a.(i + !p) a.(i);\n\ta.(i) <- 0L;\n\tPrintf.printf \"%Ld\\n\" !res;\n done\n"}], "negative_code": [], "src_uid": "c7e49c643dd8738f273c0d24e56c505f"} {"source_code": "\nlet 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\nlet n,l,a = Scanf.sscanf (read_line ()) \"%i %i %i\" (fun n l a -> n,l,a) in\nlet num = ref 0 in\nlet time = ref 0 in\nfor i = 0 to n-1 do\n let ti, li = Scanf.sscanf (read_line()) \"%i %i\" (fun ti li -> ti,li) in\n num := !num + ((ti - !time)/a);\n time := ti + li;\ndone;\nprint_int (!num + ((l - !time)/a))\n", "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 (+$) = (+) 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(* module Imos = struct\n\tlet make n = Array.make (i32 n +$ 2) 0L\n\tlet add_destructive_closed l r a =\n\t\ttry\n\t\ta.(l+$1) <- a.(l+$1) + 1L;\n\t\ta.(r+$2) <- a.(r+$2) - 1L\n\t\twith Invalid_argument _ -> ()\n\tlet add_destructive_1orig_closed l r a =\n\t\ta.(l) <- a.(l) + 1L;\n\t\ta.(r+$1) <- a.(r+$1) - 1L\n\tlet cumulate_destructive a = for i=1 to Array.length a -$ 2 do\n\t\ta.(i) <- a.(i) + a.(i-$1)\n\tdone\nend *)\n\nlet () =\n\tlet n,l,a = get_3_i64 9 in\n\tlet b = Array.init (i32 n) (fun _ -> get_2_i64 0)\n\tin\n\tlet p = ref 0L in\n\tlet c = ref 0L in\n\tArray.iter (fun (t,l) ->\n\t\t(* printf \"%Ld %Ld %Ld %Ld\\n\" !p t l !c; *)\n\t\tlet d = t - !p in c += (d / a);\n\t\tp := t + l\n\t) b;\n\tprintf \"%Ld\\n\" (!c + (l- !p)/a)"}], "negative_code": [], "src_uid": "00acb3b54975820989a788b9389c7c0b"} {"source_code": "\nlet () =\n let (@@) f x = f x in\n let (%) f g x = f @@ g x in\n let (|>) x f = f x in\n let open List in\n let open Num in\n let split = Str.split @@ Str.regexp_string \" \" in\n read_line () |> split |> map int_of_string |> fun n_k ->\n let n = hd n_k and k = hd @@ tl n_k in\n read_line () |> split |> map int_of_string |> mapi (fun i a -> i + 1, a) |> fun ratings ->\n let rec loop rev_result acc i n = function\n | (_, ai) as r :: rs when acc -/ (Int ai) */ (Int n -/ Int i) */ (Int i -/ Int 1) \n loop (r :: rev_result) acc i (n - 1) rs\n | (_, ai) :: rs -> loop rev_result (acc +/ (Int ai) */ (Int i -/ Int 1)) (i + 1) n rs\n | [] -> rev rev_result\n in\n loop [] (Int 0) 1 n ratings |> map (string_of_int % fst) |> iter print_endline\n", "positive_code": [{"source_code": "\nlet () =\n let (@@) f x = f x in\n let (%) f g x = f @@ g x in\n let (|>) x f = f x in\n let open List in\n let open Num in\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n k ->\n Array.init n (fun i -> scanf \"%d \" @@ fun a -> i + 1, a) |> Array.to_list |> fun ratings ->\n let rec loop rev_result acc i n = function\n | (_, ai) as r :: rs when acc -/ (Int ai) */ (Int n -/ Int i) */ (Int i -/ Int 1) \n loop (r :: rev_result) acc i (n - 1) rs\n | (_, ai) :: rs -> loop rev_result (acc +/ (Int ai) */ (Int i -/ Int 1)) (i + 1) n rs\n | [] -> rev rev_result\n in\n loop [] (Int 0) 1 n ratings |> map (string_of_int % fst) |> iter print_endline\n"}], "negative_code": [{"source_code": "\nlet () =\n let (@@) f x = f x in\n let (%) f g x = f @@ g x in\n let (|>) x f = f x in\n let (|*>) (a, b) f = f a b in\n let open List in\n let split = Str.split @@ Str.regexp_string \" \" in\n read_line () |> split |> map int_of_string |> fun n_k ->\n let n = hd n_k and k = hd @@ tl n_k in\n read_line () |> split |> map int_of_string |> mapi (fun i a -> i + 1, a) |> fun ratings ->\n let d ratings (i, ai) =\n (0, ratings) |*> fold_left (fun s (j, aj) -> s + if j < i then aj * (j - 1) - (n - i) * ai else 0)\n in\n let extract_next ratings =\n let rec loop rev_head = function\n | r :: rs when d ratings r < k -> (r, rev_append rev_head rs)\n | r :: rs -> loop (r :: rev_head) rs\n | [] -> raise Not_found\n in\n loop [] ratings\n in\n let rec loop rev_result rs =\n try let r, rs = extract_next rs in loop (r :: rev_result) rs\n with Not_found -> rev rev_result\n in\n loop [] ratings |> map (string_of_int % fst) |> iter print_endline\n"}, {"source_code": "\nlet () =\n let (@@) f x = f x in\n let (%) f g x = f @@ g x in\n let (|>) x f = f x in\n let (|*>) (a, b) f = f a b in\n let open List in\n let open Int64 in\n let split = Str.split @@ Str.regexp_string \" \" in\n read_line () |> split |> map int_of_string |> fun n_k ->\n let n = hd n_k and k = hd @@ tl n_k in\n read_line () |> split |> map int_of_string |> mapi (fun i a -> i + 1, a) |> fun ratings ->\n let d ratings (i, ai) =\n (0L, ratings) |*> fold_left (fun s (j, aj) ->\n add s @@\n if j < i then sub (mul (of_int aj) (sub (of_int j) 1L)) @@ mul (sub (of_int n) @@ of_int i) (of_int ai)\n else 0L)\n in\n let extract_next ratings =\n let rec loop rev_head = function\n | r :: rs when d ratings r < (of_int k) -> (r, rev_append rev_head rs)\n | r :: rs -> loop (r :: rev_head) rs\n | [] -> raise Not_found\n in\n loop [] ratings\n in\n let rec loop rev_result rs =\n try let r, rs = extract_next rs in loop (r :: rev_result) rs\n with Not_found -> rev rev_result\n in\n loop [] ratings |> map (string_of_int % fst) |> iter print_endline\n"}], "src_uid": "7237361e3c2a9b1524d6410283839d48"} {"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet v=read_int();;\nlet tab=Array.make (n+1) 0;;\nlet vec=Array.make (n+1) 0;;\nlet mat=Array.make 3001 0;;\nfor i=1 to n do\n let x=read_int() and y=read_int() in (tab.(i)<-x;mat.(x)<-mat.(x)+y)\ndone;;\nlet r=ref 0;;\nlet nb=ref 0;;\nfor i=1 to 3000 do\n nb:= !nb+min (!r) v;\n let vv=v-min (!r) v in\n nb:= !nb+min vv mat.(i);\n r:= mat.(i)-min vv mat.(i)\ndone;;\nprint_int (!nb+min !r v);;", "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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nlet nn = 3001\nlet () = \n let n = read_int () in\n let v = read_int () in\n let fruit = Array.make (nn+1) 0 in\n for i=0 to n-1 do\n let a = read_int() in\n let b = read_int() in\n fruit.(a) <- fruit.(a) + b\n done;\n\n let ( ++ ) a b = Int64.add a b in\n\n let count = ref 0L in\n\n for t=1 to nn do \n let prev = fruit.(t-1) in\n let take_prev = min v prev in\n count := !count ++ (Int64.of_int take_prev);\n fruit.(t-1) <- fruit.(t-1) - take_prev;\n let v = v - take_prev in\n let current = fruit.(t) in\n let take_current = min v current in\n count := !count ++ (Int64.of_int take_current);\n fruit.(t) <- fruit.(t) - take_current;\n done;\n\n printf \"%Ld\\n\" !count\n"}], "negative_code": [], "src_uid": "848ead2b878f9fd8547e1d442e2f85ff"} {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nexception Found of int\n\nlet _ =\n let n = 100000 in\n let prime = Array.make (n + 1) true in\n let d = Array.make (n + 1) 0 in\n let p = Array.make 10000 0 in\n let pk = ref 0 in\n let _ =\n for i = 2 to n do\n if prime.(i) then (\n\tp.(!pk) <- i;\n\td.(i) <- !pk;\n\tincr pk;\n\tlet j = ref (2 * i) in\n while !j <= n do\n\t let jj = !j in\n prime.(jj) <- false;\n\t d.(jj) <- !pk - 1;\n j := jj + i\n done\n )\n done;\n in\n let pk = !pk - 1 in\n let n = getnum () in\n let m = getnum () in\n let a = Array.make (n + 1) false in\n let h = Array.init 10000 (fun _ -> Hashtbl.create 1) in\n for i = 1 to m do\n let q = getnum () in\n let k = getnum () in\n\tmatch q with\n\t | -5 -> (* + *)\n\t if a.(k)\n\t then Printf.printf \"Already on\\n\"\n\t else (\n\t\ttry\n\t\t (let r = ref k in\n\t\t while !r > 1 do\n\t\t let pn = d.(!r) in\n\t\t let p = p.(pn) in\n\t\t\t while !r mod p = 0 do\n\t\t\t r := !r / p\n\t\t\t done;\n\t\t\t let ht = h.(pn) in\n\t\t\t if Hashtbl.length ht <> 0 then (\n\t\t\t Hashtbl.iter (fun c () -> raise (Found c)) ht\n\t\t\t )\n\t\t done);\n\t\t a.(k) <- true;\n\t\t (let r = ref k in\n\t\t while !r > 1 do\n\t\t let pn = d.(!r) in\n\t\t let p = p.(pn) in\n\t\t\t while !r mod p = 0 do\n\t\t\t r := !r / p\n\t\t\t done;\n\t\t\t let ht = h.(pn) in\n\t\t\t Hashtbl.replace ht k ()\n\t\t done);\n\t\t Printf.printf \"Success\\n\"\n\t\twith\n\t\t | Found c ->\n\t\t Printf.printf \"Conflict with %d\\n\" c\n\t )\n\t | 0 -> (* - *)\n\t if not a.(k)\n\t then Printf.printf \"Already off\\n\"\n\t else (\n\t\ta.(k) <- false;\n\t\t(let r = ref k in\n\t\t while !r > 1 do\n\t\t let pn = d.(!r) in\n\t\t let p = p.(pn) in\n\t\t while !r mod p = 0 do\n\t\t\t r := !r / p\n\t\t done;\n\t\t let ht = h.(pn) in\n\t\t\t Hashtbl.remove ht k\n\t\t done);\n\t\tPrintf.printf \"Success\\n\"\n\t )\n\t | _ -> assert false\n done;\n", "positive_code": [{"source_code": "let main () =\n let n, m = Scanf.sscanf (read_line ()) \"%d %d\" (fun n m -> n, m) in\n let arr = Array.create (n + 1) [] in\n for i = 2 to n do\n if arr.(i) = [] then (\n let rec loop j =\n if j <= n then (\n arr.(j) <- i :: arr.(j);\n loop (j + i)\n )\n in\n loop i\n )\n done;\n\n let col = Array.create (n + 1) false in\n let prim = Array.create (n + 1) 0 in\n \n let rec loop i =\n if i > 0 then (\n let (c, r) = Scanf.sscanf (read_line ()) \"%c %d\" (fun c r -> c, r) in\n if c = '+' then (\n if col.(r) then\n print_endline \"Already on\"\n else\n let k = List.fold_left (fun acc v -> if prim.(v) > 0 then prim.(v) else acc) 0 arr.(r) in\n if k > 0 then Printf.printf \"Conflict with %d\\n\" k else (\n print_endline \"Success\";\n col.(r) <- true;\n List.iter (fun v -> prim.(v) <- r) arr.(r)\n )\n ) else (\n if not col.(r) then print_endline \"Already off\" else\n let _ = print_endline \"Success\" in\n let _ = col.(r) <- false in\n List.iter (fun v -> prim.(v) <- 0) arr.(r)\n );\n loop (i - 1)\n )\n in\n loop m\n;;\nmain()\n"}], "negative_code": [{"source_code": "let rec gcd a b = if b = 0 then a else gcd b (a mod b)\n\nlet main () =\n let n, m = Scanf.sscanf (read_line ()) \"%d %d\" (fun n m -> n, m) in\n let col = Array.create (n + 1) false in\n let check col p =\n let rec loop i =\n if i * i > n then None else\n if col.(i) && gcd p i > 1 then Some i else loop (i + 1)\n in\n loop 2\n in\n for i = 1 to m do\n let (c, r) = Scanf.sscanf (read_line ()) \"%c %d\" (fun c r -> c, r) in\n if c = '+' then (\n if col.(r) then print_endline \"Already on\" else\n match check col r with\n | None -> print_endline \"Success\"; col.(r) <- true\n | Some k -> Printf.printf \"Conflict with %d\\n\" k\n ) else\n if col.(r) = false then print_endline \"Already off\" else\n let _ = col.(r) <- false in\n print_endline \"Success\"\n done\n;;\nmain()\n"}, {"source_code": "let rec gcd a b = if b = 0 then a else gcd b (a mod b)\n\nlet main () =\n let n, m = Scanf.sscanf (read_line ()) \"%d %d\" (fun n m -> n, m) in\n let col = Array.create (n + 1) false in\n let check col p =\n let rec loop i =\n if i * i > n then None else\n if col.(i) && gcd p i > 1 then Some i else loop (i + 1)\n in\n loop 1\n in\n for i = 1 to m do\n let (c, r) = Scanf.sscanf (read_line ()) \"%c %d\" (fun c r -> c, r) in\n if c = '+' then (\n if col.(r) then print_endline \"Already on\" else\n match check col r with\n | None -> print_endline \"Success\"; col.(r) <- true\n | Some k -> Printf.printf \"Conflict with %d\\n\" k\n ) else\n if col.(r) = false then print_endline \"Already off\" else\n let _ = col.(r) <- false in\n print_endline \"Success\"\n done\n;;\nmain()\n"}], "src_uid": "6cec3662101b419fb734b7d6664fdecd"} {"source_code": "open Printf open Scanf\nmodule Int64 = struct \n\tinclude Int64\n\t(* int *)\n\tlet (+$) = (+)\n\tlet (-$) = (-)\n\tlet (/$) = (/)\n\tlet ( *$) = ( * )\n\t(* int64 *)\n\tlet (+) p q = Int64.add p q\n\tlet (-) p q = Int64.sub p q\n\tlet ( * ) p q = Int64.mul p q\n\tlet (/) p q = Int64.div p q\n\n\tlet labs p = if p < 0L then -1L*p else p\n\t(* let (~|) p = Int64.of_int p *)\n\tlet (~|) p = Int64.to_int p\n\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *=) r v= r := !r * v\n\tlet (/=) r v = r := !r / v\n\n\tlet input_i64_array n = \n\t\tArray.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 () = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 () = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 () = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet print_i64_endline n =\n\t\tn |> Int64.to_string |> print_endline\nend open Int64\n\nlet () =\n let n,d = get_2_i64 ()\n in let ar = input_i64_array n\n in\n let res = ref 0L\n in\n for i=0 to ~|n-$1 do\n let lef = ar.(i) - d in\n if (i>=1 && labs (lef - ar.(i-$1)) >= d) || i=0 then (\n (* printf \"%Ld\\n\" lef; *)\n res+=1L;\n );\n let rig = ar.(i) + d in\n if i= ~|n-$1 ||\n (i<= ~|n-$2 && labs (rig - ar.(i+$1)) >= d && ar.(i+$1)-ar.(i)<>2L*d)\n then (\n (* printf \"%Ld\\n\" rig; *)\n res+=1L\n );\n done;\n !res |> print_i64_endline\n\n\n\n", "positive_code": [{"source_code": "open Int64\n\nlet 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\nlet n,d = Scanf.sscanf (read_line ()) \"%s %s\" (fun n d -> of_string n,of_string d) in\nlet hotel = read_line () |> split_on_char ' ' |> List.map of_string in\nsnd (List.fold_left (fun (old_x, tmp) x ->\n if sub x old_x > mul 2L d then (x, add tmp 2L)\n else if sub x old_x = mul 2L d then (x, add tmp 1L)\n else (x, tmp)) (List.hd hotel, 2L) (List.tl hotel))\n|> to_string\n|> print_endline\n"}, {"source_code": "(* Codeforces 1004 A Sonya and Hotels *)\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;; *)\n\t\tlet 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\n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec hotel_cnt d cnt l = match l with\n\t| [] -> cnt\n\t| h :: [] -> cnt+1\n\t| h :: nh :: tl ->\n\t\tlet nl = nh :: tl in\n\t\tlet mtwo = Int64.of_int 2 in\n\t\tlet nhh = Int64.sub nh (Int64.mul mtwo d) in\n\t\tlet icomp = Int64.compare h nhh in\n\t\tlet ncnt = \n\t\t\tif icomp == 0 then cnt + 1\n\t\t\telse if icomp < 0 then cnt + 2\n\t\t\telse cnt in\n\t\t(* let _ = Printf.printf \"h,nhh,cnt,ncnt= %Ld %Ld %d %d\\n\" h nhh cnt ncnt in *)\n\t\thotel_cnt d ncnt nl;;\n\nlet rec to_i_64 l = match l with\n| [] -> []\n| h :: tl ->\n\tlet ih = Int64.of_int h in\n\tih :: to_i_64 tl;;\n\nlet main() =\n\tlet n = gr () in\n\tlet d = Int64.of_int (gr ()) in\n\tlet a = readlist n [] in\n\tlet ra = List.rev a in\n\tlet iaa = to_i_64 ra in\n\tlet cnt = hotel_cnt d 1 iaa in\t\n\tbegin\n\t\tprint_int cnt;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}], "negative_code": [{"source_code": "(* Codeforces 1004 A Sonya and Hotels *)\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;; *)\n\t\tlet 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\n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec hotel_cnt d cnt l = match l with\n\t| [] -> cnt\n\t| h :: [] -> cnt+1\n\t| h :: nh :: tl ->\n\t\tlet nl = nh :: tl in\n\t\tlet mtwo = Int64.of_int 2 in\n\t\tlet nhh = Int64.sub nh (Int64.mul mtwo d) in\n\t\tlet icomp = Int64.compare h nhh in\n\t\tlet ncnt = \n\t\t\tif icomp == 0 then cnt + 1\n\t\t\telse if icomp < 0 then cnt + 2\n\t\t\telse cnt in\n\t\tlet _ = Printf.printf \"h,nhh,cnt,ncnt= %Ld %Ld %d %d\\n\" h nhh cnt ncnt in\n\t\thotel_cnt d ncnt nl;;\n\nlet rec to_i_64 l = match l with\n| [] -> []\n| h :: tl ->\n\tlet ih = Int64.of_int h in\n\tih :: to_i_64 tl;;\n\nlet main() =\n\tlet n = gr () in\n\tlet d = Int64.of_int (gr ()) in\n\tlet a = readlist n [] in\n\tlet ra = List.rev a in\n\tlet iaa = to_i_64 ra in\n\tlet cnt = hotel_cnt d 1 iaa in\t\n\tbegin\n\t\tprint_int cnt;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "(* Codeforces 1004 A Sonya and Hotels *)\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;; *)\n\t\tlet 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\n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec hotel_cnt d cnt l = match l with\n\t| [] -> cnt\n\t| h :: [] -> cnt+1\n\t| h :: nh :: tl ->\n\t\tlet nl = nh :: tl in\n\t\tlet ncnt = \n\t\t\tif h == nh - 2 * d then cnt + 1\n\t\t\telse if h < nh - 2 * d then cnt + 2\n\t\t\telse cnt in\n\t\t(*let _ = Printf.printf \"h,n,cnt,ncnt= %d %d %d %d\\n\" h nh cnt ncnt in*)\n\t\thotel_cnt d ncnt nl;;\n\nlet main() =\n\tlet n = gr () in\n\tlet d = gr () in\n\tlet a = readlist n [] in\n\tlet ra = List.rev a in\n\tlet cnt = hotel_cnt d 1 ra in\t\n\tbegin\n\t\tprint_int cnt;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;"}, {"source_code": "open Printf open Scanf\nmodule Int64 = struct \n\tinclude Int64\n\t(* int *)\n\tlet (+$) = (+)\n\tlet (-$) = (-)\n\tlet (/$) = (/)\n\tlet ( *$) = ( * )\n\t(* int64 *)\n\tlet (+) p q = Int64.add p q\n\tlet (-) p q = Int64.sub p q\n\tlet ( * ) p q = Int64.mul p q\n\tlet (/) p q = Int64.div p q\n\n\tlet labs p = if p < 0L then -1L*p else p\n\t(* let (~|) p = Int64.of_int p *)\n\tlet (~|) p = Int64.to_int p\n\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *=) r v= r := !r * v\n\tlet (/=) r v = r := !r / v\n\n\tlet input_i64_array n = \n\t\tArray.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 () = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 () = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 () = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet print_i64_endline n =\n\t\tn |> Int64.to_string |> print_endline\nend open Int64\n\nlet () =\n let n,d = get_2_i64 ()\n in let ar = input_i64_array n\n in\n let res = ref 0L\n in\n for i=0 to ~|n-$1 do\n let lef = ar.(i) - d in if i>=1 && lef>ar.(i-$1) then res+=1L;\n let rig = ar.(i) + d in if i<= ~|n-$2 && rig2L*d then res+=1L;\n done;\n !res |> print_i64_endline"}, {"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,d) in\nlet hotel = read_line () |> split_on_char ' ' |> List.map int_of_string in\nprint_int @@ snd (List.fold_left (fun (old_x, tmp) x ->\n if x - old_x > 2 * d then (x,tmp + 2)\n else if x - old_x = 2 * d then (x, tmp+1)\n else (x, tmp)) (List.hd hotel, 2) (List.tl hotel));\nprint_newline ();\n"}], "src_uid": "5babbb7c5f6b494992ffa921c8e19294"} {"source_code": "(* Codeforces 1005 A Tanya and Stairways *)\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\n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec to_tania acc last l = match l with\n\t| [] -> last :: acc\n\t| h :: t -> match h with\n\t\t\t| 1 -> \n\t\t\t\tlet lacc = if last == 0 then acc else last :: acc in\n\t\t\t\tto_tania lacc 1 t\n\t\t\t| _ -> to_tania acc h t;;\n\nlet main() =\n\tlet n = gr () in\n\tlet ra = readlist n [] in\n\tlet a = List.rev ra in\n\tlet ro = to_tania [] 0 a in\n\tlet o = List.rev ro in\n\tlet lno = List.length o in\n\tbegin\n\t\tprint_int lno;\n\t\tprint_string \"\\n\";\n\t\tprintlisti o;\n\t\tprint_string \"\\n\"\n\tend;;\n\nmain();;", "positive_code": [{"source_code": "open Scanf\nopen Printf\n\nlet n = scanf \"%d\" (fun n -> n)\n\nlet l = Array.to_list (Array.init n (fun i -> scanf \" %d\" (fun i -> i)))\n\nlet rec process_l l out =\n match l with\n | [] -> l, out\n | h::t ->\n if h > out then\n process_l t h\n else\n l, out\n\nlet rec process l out out_st =\n match l with\n | [] -> out, out_st\n | _ ->\n let l', st = process_l l 0 in\n process l' (out + 1) (st::out_st)\n\nlet () =\n let out, out_st = process l 0 [] in\n printf \"%d\\n\" out;\n List.iter (fun i -> printf \"%d \" i) (List.rev out_st);\n ()\n"}, {"source_code": "open Printf\nlet input_int_array n =\n\tArray.init n (fun _ -> Scanf.scanf \" %d\" (fun v -> v))\n\nlet get_int () = Scanf.scanf \" %d\" (fun v -> v)\nlet get_2_ints () = Scanf.scanf \" %d %d\" (fun u v -> u,v)\nlet get_3_ints () = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w)\nlet get_4_ints () = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x)\nlet get_5_ints () = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n\nlet print_int_endline n = n |> string_of_int |> print_endline\n\nlet () =\n let n = get_int ()\n in let ar = input_int_array n\n in\n let l = Array.fold_left (fun (c,l) v ->\n if v=c+1 then (v,l)\n else if v=1 then (v,c::l)\n else failwith \"\"\n ) (0,[]) ar\n |> (fun (last,l) -> last::l)\n |> List.rev\n in\n print_endline @@ (List.length l |> string_of_int);\n l |> List.iter (printf \"%d \");\n print_newline ()"}], "negative_code": [], "src_uid": "0ee86e75ff7a47a711c9eb41b34ad1a5"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) ;;\n\nlet a = read_int () and b = read_int () and n = read_int () ;;\n\nlet result = \n let rec loop d = \n if d >= 10 then -1\n else if (a * 10 + d) mod b = 0 then (a * 10 + d)\n else loop (d + 1)\n in loop 0 ;;\n \nPrintf.printf \"%d\" result ;;\n\nif result <> -1 then \n for i = 1 to n - 1 do\n Printf.printf \"0\"\n done ;;\n\nPrintf.printf \"\\n\" ;;", "positive_code": [{"source_code": "(* Codeforces 246C KonkursKrasoti written *)\n\nopen String;;\nopen Hashtbl;;\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\nlet 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 rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet debug = false;;\n\nlet a = gr();;\nlet b = gr();;\nlet n = gr();;\nlet ch = Array.make n 0;;\n\nlet rec nextchar ao c idx ca =\n\tif idx >= n then 0\n\telse if c > 9 then -1\n\telse if ((10 * ao + c) mod b) != 0 then nextchar ao (c +1) idx ca\n\telse\n\t\tlet oo = 0 in\n\t\tbegin\n\t\t\tca.(idx) <- c;\n\t\t\tnextchar oo 0 (idx +1) ca\n\t\tend;;\n\nlet prichars a ca n =\n\tbegin\n\t\tprint_int a;\n\t\tfor i = 1 to n do\n\t\t\tprint_int ca.(i -1)\n\t\tdone;\n\t\tprint_newline()\n\tend;;\n\nlet main () =\n\tlet ret = nextchar a 0 0 ch in\n\tif ret < 0 then begin print_int (-1); print_newline() end\n\telse prichars a ch n;;\n\nmain();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let a = read_int() in \n let b = read_int() in\n let n = read_int() in\n let rec f d = if d = 10 then (-1) else if (10*a+d) mod b = 0 then d else f (d+1) in\n let d = f 0 in\n if d = -1 then Printf.printf \"-1\\n\"\n else (\n Printf.printf \"%d%d\" a d; \n for i = 1 to n-1 do Printf.printf \"0\" done;\n print_newline()\n )"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let a = read_int() in\n let b = read_int() in\n let n = read_int() in\n\n let rec first d = if d=10 then -1 else if (10*a+d) mod b = 0 then d else first (d+1) in\n\n let d = first 0 in\n if d = -1 then (\n Printf.printf \"-1\\n\"\n ) else (\n Printf.printf \"%d%d\" a d;\n for i=1 to n-1 do Printf.printf \"0\" done;\n print_newline()\n )\n"}], "negative_code": [], "src_uid": "206eb67987088843ef42923b0c3939d4"} {"source_code": "let _ = read_int () in\nlet str = read_line () in\n\nlet trans c = match c with\n| 'A' -> 1\n| 'D' -> -1\n| _ -> 0 in\n\nlet rec count_ad s i l =\n if i >= l then 0\n else (count_ad s (i+1) l) + trans s.[i] in\n\nlet get_output c =\n if c = 0 then \"Friendship\"\n else if c > 0 then \"Anton\"\n else \"Danik\" in\n\nprint_endline (get_output (count_ad str 0 (String.length str)))", "positive_code": [{"source_code": "let a_count = ref 0 and\n d_count = ref 0 and\n n = int_of_string (read_line ()) and\n s = read_line () in\nfor i = 0 to n - 1 do\n begin\n a_count := !a_count + (if s.[i] = 'A' then 1 else 0);\n d_count := !d_count + (if s.[i] = 'D' then 1 else 0);\n end\ndone;\nprint_string ( if a_count = d_count then \"Friendship\"\n else if a_count > d_count then \"Anton\"\n else \"Danik\"\n)\n"}, {"source_code": "let () =\n Scanf.scanf \"%d \" @@ fun n ->\n let anton = ref 0 in\n let danik = ref 0 in\n Scanf.scanf \"%s \" @@ String.iter (function 'A' -> incr anton | 'D' -> incr danik | _ -> failwith \"\");\n if !anton = !danik then\n print_endline \"Friendship\"\n else if !anton > !danik then\n print_endline \"Anton\"\n else\n print_endline \"Danik\"\n"}, {"source_code": "let char_count s len c =\n let rec cc i sum =\n if i = len then\n sum\n else\n let n = if s.[i] = c then 1 else 0 in\n cc (i + 1) (sum + n)\n in cc 0 0\n\nlet n = read_int () ;;\nlet s = read_line () ;;\nlet a = char_count s n 'A'\nand d = char_count s n 'D'\nin\nif a = d then\n print_string \"Friendship\\n\"\nelse if a > d then\n print_string \"Anton\\n\"\nelse\n print_string \"Danik\\n\"\n;;\n"}, {"source_code": "let input () = \n let total = Scanf.scanf \"%d \" (fun n -> n) in\n let rec read list n =\n if n > 0\n then\n let var = Scanf.scanf \"%c\" (fun c -> c) in\n read (var :: list) (n - 1)\n else\n List.rev list\n in read [] total\n\nlet solve list =\n let anton_wins = List.length (List.filter (fun c -> c = 'A') list) in\n let danik_wins = List.length (List.filter (fun c -> c = 'D') list) in\n if anton_wins = danik_wins\n then\n \"Friendship\"\n else \n if anton_wins > danik_wins \n then\n \"Anton\"\n else\n \"Danik\"\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (input ()))\n"}], "negative_code": [], "src_uid": "0de32a7ccb08538a8d88239245cef50b"} {"source_code": "open Printf\nlet read_string () = Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun x -> x)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\nlet read_long_int () = Scanf.bscanf Scanf.Scanning.stdin \" %Ld\" (fun x -> x)\nlet (+) x y = Int64.add x y\n\nlet () = \n let n = read_int() in\n let s = read_string() in\n let tab = Array.make n 0L in\n let h = ref 0L and a = ref 0L and r = ref 0L and d = ref 0L in\n\n for i = 0 to n - 1 do\n tab.(i) <- read_long_int()\n done;\n\n for i = 0 to n - 1 do\n if s.[i] = 'h' then h := !h + tab.(i)\n else if s.[i] = 'a' then a := min !h (!a + tab.(i))\n else if s.[i] = 'r' then r := min !a (!r + tab.(i))\n else if s.[i] = 'd' then d := min !r (!d + tab.(i))\n done;\n\n printf \"%Ld\\n\" !d\n\n\n", "positive_code": [{"source_code": "let max_i64,(++) = Int64.(shift_left 1L 60,add);;\nScanf.(Array.(\n scanf \" %d %s\" @@ fun n s ->\n let t = \"hard\" in\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v)\n in\n let dp = make_matrix (n+2) 5 max_i64 in\n let update i j v =\n dp.(i).(j) <- min dp.(i).(j) v\n in\n dp.(0).(0) <- 0L;\n for i=1 to n do\n for j=0 to 3 do\n if s.[i-1] = t.[j] then (\n update i (j+1) @@ dp.(i-1).(j);\n update i j @@ dp.(i-1).(j) ++ a.(i-1)\n ) else (\n update i j @@ dp.(i-1).(j)\n )\n done\n done;\n (* for i=0 to n do\n for j=0 to 4 do\n Printf.printf \"%Ld \" dp.(i).(j)\n done;\n print_newline ()\n done; *)\n Printf.printf \"%Ld\" @@\n List.fold_left min max_i64 @@\n List.tl @@ List.rev @@ to_list dp.(n)\n))"}], "negative_code": [{"source_code": "open Printf\nlet read_string () = Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun x -> x)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let s = read_string() in\n let tab = Array.make n 0 in\n let h = ref 0 and a = ref 0 and r = ref 0 and d = ref 0 in\n\n for i = 0 to n - 1 do\n tab.(i) <- read_int()\n done;\n\n for i = n - 1 downto 0 do\n if s.[i] = 'd' then d := !d + tab.(i)\n else if s.[i] = 'r' && !d <> 0 then r := !r + tab.(i)\n else if s.[i] = 'a' && !r <> 0 then a := !a + tab.(i)\n else if s.[i] = 'h' && !a <> 0 then h := !h + tab.(i)\n done;\n\n if !h = 0 then printf \"0\\n\"\n else printf \"%d\\n\" (min (min !h !a) (min !r !d))\n\n\n"}, {"source_code": "open Printf\nlet read_string () = Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun x -> x)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\nlet read_long_int () = Scanf.bscanf Scanf.Scanning.stdin \" %Ld\" (fun x -> x)\nlet (+) x y = Int64.add x y\n\nlet () = \n let n = read_int() in\n let s = read_string() in\n let tab = Array.make n 0L in\n let h = ref 0L and a = ref 0L and r = ref 0L and d = ref 0L in\n\n for i = 0 to n - 1 do\n tab.(i) <- read_long_int()\n done;\n\n for i = n - 1 downto 0 do\n if s.[i] = 'd' then d := !d + tab.(i)\n else if s.[i] = 'r' && !d <> 0L then r := !r + tab.(i)\n else if s.[i] = 'a' && !r <> 0L then a := !a + tab.(i)\n else if s.[i] = 'h' && !a <> 0L then h := !h + tab.(i)\n done;\n\n if !h = 0L then printf \"0\\n\"\n else printf \"%Ld\\n\" (min (min !h !a) (min !r !d))\n\n\n"}, {"source_code": "let max_i64,(++) = Int64.(max_int,add);;\nScanf.(Array.(\n scanf \" %d %s\" @@ fun n s ->\n let t = \"hard\" in\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v)\n in\n let dp = make_matrix (n+2) 5 max_i64 in\n let update i j v =\n dp.(i).(j) <- min dp.(i).(j) v\n in\n dp.(0).(0) <- 0L;\n for i=1 to n do\n for j=0 to 3 do\n if s.[i-1] = t.[j] then (\n update i (j+1) @@ dp.(i-1).(j);\n update i j @@ dp.(i-1).(j) ++ a.(i-1)\n ) else (\n update i j @@ dp.(i-1).(j)\n )\n done\n done;\n (* for i=0 to n do\n for j=0 to 4 do\n Printf.printf \"%Ld \" dp.(i).(j)\n done;\n print_newline ()\n done; *)\n Printf.printf \"%Ld\" @@ fold_left min max_i64 dp.(n)\n))"}, {"source_code": "let max_i64,(++) = Int64.(shift_left 1L 60,add);;\nScanf.(Array.(\n scanf \" %d %s\" @@ fun n s ->\n let t = \"hard\" in\n let a = init n (fun _ -> scanf \" %Ld\" @@ fun v -> v)\n in\n let dp = make_matrix (n+2) 5 max_i64 in\n let update i j v =\n if v>=0L then dp.(i).(j) <- min dp.(i).(j) v\n in\n dp.(0).(0) <- 0L;\n for i=1 to n do\n for j=0 to 3 do\n if s.[i-1] = t.[j] then (\n update i (j+1) @@ dp.(i-1).(j);\n update i j @@ dp.(i-1).(j) ++ a.(i-1)\n ) else (\n update i j @@ dp.(i-1).(j)\n )\n done\n done;\n (* for i=0 to n do\n for j=0 to 4 do\n Printf.printf \"%Ld \" dp.(i).(j)\n done;\n print_newline ()\n done; *)\n Printf.printf \"%Ld\" @@ fold_left min max_i64 dp.(n)\n));;"}], "src_uid": "8cc22dc6e81bb49b64136e5ff7eb8caf"} {"source_code": "let read_ints () =\n let str = read_line () in\n List.map (fun x -> int_of_string x) (Str.split (Str.regexp \" +\") str)\n;;\n\nlet rec count (num : int list) (modi : int) (ind : int)=\n match num with\n |[] -> 0\n |h :: t -> if ((ind mod 2) <> modi && h mod 2 = modi) then 1 + count t modi (ind + 1) else count t modi (ind + 1)\n;;\n\nlet rec main (t : int) =\n if t = 0 then\n ()\n else\n (\n let siz = read_int () in\n let a = read_ints () in\n let one_zero = count a 0 0 in\n let zero_one = count a 1 0 in\n if (one_zero <> zero_one) then print_endline \"-1\" else print_endline (string_of_int one_zero);\n main (t - 1)\n )\n;;\nlet t = read_int() in\nmain t\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let t = read_int () in\n for i = 1 to t do\n let n = read_int () in \n let (a, b) = \n let rec loop a b = function\n | 0 -> (a, b)\n | m -> \n let x = read_int () in\n if not ((x mod 2) = ((n-m) mod 2)) then\n if ((n-m) mod 2) = 0 then \n loop (a+1) b (m-1) \n else \n loop a (b+1) (m-1)\n else \n loop a b (m-1)\n in loop 0 0 n\n in\n if not (a = b) then Printf.printf \"-1\\n\" else Printf.printf \"%d\\n\" a\n done\n"}], "negative_code": [], "src_uid": "942123e43a83d5a4cea95a6781064e28"} {"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\n\nlet () = \n let n = read_int() in\n let c = Array.init n (fun i -> read_int()) in\n let () = Array.sort compare c in\n \n let rec loop i j ac =\n if i=n then ac else\n if j >= n-1 || c.(j+1) > 2*c.(i) then \n\tloop (i+1) j (max (j-i+1) ac)\n else loop i (j+1) ac\n in\n \n let a = loop 0 0 0 in\n print_string (Printf.sprintf \"%d\\n\" (n-a))\n", "positive_code": [{"source_code": "let chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\n\nlet () = \n let n = read_int() in\n let c = Array.init n (fun i -> read_int()) in\n let () = Array.sort compare c in\n \n let rec loop i j ac = if i=n then ac else\n if j >= n-1 || c.(j+1) > 2*c.(i) then loop (i+1) j (max (j-i+1) ac)\n else loop i (j+1) ac\n in\n \n let a = loop 0 0 0 in\n print_string (Printf.sprintf \"%d\\n\" (n-a))\n"}], "negative_code": [{"source_code": "open Scanf;;\nopen Array;;\nopen Printf;;\n\n(*print_endline \"begin\";;\n *)\n\nlet file_in = \"input.txt\";;\nlet file_out = \"output.txt\";;\n\nlet ic = open_in file_in;;\nlet n = Scanf.bscanf (Scanf.Scanning.from_channel ic) \"%d \" (fun x -> x);;\nlet a = Array.make n 0;;\n\n(*print_endline \"xx\";;\n *)\nlet () = \n for i = 0 to n-1 do\n let x = Scanf.bscanf (Scanf.Scanning.from_channel ic) \"%d \" (fun x -> x) in\n a.(i) <- x\n done in\n Array.sort (fun x y -> y - x) a\n;;\n\n(*Array.iter (fun x -> print_int x; print_endline \"\") a;;\n *)\n\nclose_in ic;;\n\nlet my_min x y = if x < y then x else y;;\n\nexception Found;;\n\nlet nrow = \n let row = ref 0 in\n let i = ref (n - 1) in\n try \n while (!i >=0) do\n if a.(0) <= (2*a.(!i)) then raise Found;\n row := !row + 1;\n i:=!i-1\n done; !row+1\n with Found -> !row+1;;\n\nlet ncol = \n let col = ref 0 in\n let i = ref 0 in\n try \n while (!i < n) do\n if 2*a.(n-1) >= a.(!i) then raise Found;\n col := !col + 1;\n i:=!i+1\n done; !col+1\n with Found -> !col+1;;\n\nlet biggest = max_int;;\nlet b = Array.make_matrix nrow ncol 0;;\n(*Initialize the matrix*)\nlet () = \n for i = ncol-1 downto 1 do\n b.(nrow-1).(i) <- biggest\n done;\n for i = nrow-1 downto 1 do\n b.(i).(ncol-1) <- biggest\n done\n;;\n\nlet () = \n b.(nrow-1).(0) <- nrow - 1;\n b.(0).(ncol-1) <- ncol -1\n;; \n\nlet my_min x y z = min (min x y) (min y z);;\n\n (*\nfor i = ncol-2 downto 0 do\n for j = nrow -2 downto 0 do\n let x = b.(j+1).(i) in\n let y = b.(j).(i+1) in\n let z = if a.(nrow - 1 - j) > 2*a.(n-1 - (ncol-1 - i)) then biggest else (ncol-1-i)+(nrow-1-j)\n in\n b.(j).(i) <- (my_min x y z)\n done\ndone; let oc = open_out file_out in\n if b.(0).(0) = biggest then \n\tPrintf.fprintf oc \"%d\\n\" 1 \n else\n\tPrintf.fprintf oc \"%d\\n\" b.(0).(0);;\n *)\n\nlet ncold = ncol -1 in\nlet nrowd = nrow -1 in\nlet rec find_b00 i j =\n match i,j with\n (0, ncold) -> nrowd \n |(x, ncold) when x>0 -> biggest \n |(nrowd, 0) -> ncold\n |(nrowd, x) when x>0 -> nrowd\n |_ -> \n begin\n let x = find_b00 (j+1) (i) in\n let y = find_b00 (j) (i+1) in\n let z = if a.(nrow - 1 - j) > 2*a.(n-1 - (ncol-1 - i)) then biggest else (ncol-1-i)+(nrow-1-j)\n in\n my_min x y z\n end\n in let rslt = find_b00 0 0 in\n let oc = open_out file_out in\n Printf.fprintf oc \"%d\\n\" rslt;;\n \n"}, {"source_code": "open Scanf;;\nopen Array;;\nopen Printf;;\n\n(* This version uses binary search and rec\n *)\n\nlet file_in = \"input.txt\";;\nlet file_out = \"output.txt\";;\n\nlet ic = open_in file_in;;\nlet oc = open_out file_out;;\n\nlet n = Scanf.bscanf (Scanf.Scanning.from_channel ic) \"%d \" (fun x -> x);;\nlet a = Array.make n 0;;\n\nlet () = \n for i = 0 to n-1 do\n let x = Scanf.bscanf (Scanf.Scanning.from_channel ic) \"%d \" (fun x -> x) in\n a.(i) <- x\n done in\n Array.sort (fun x y -> y - x) a\n;; (*array a is from large to small*)\n\n(*\nArray.iter (fun x -> print_int x; print_string \" \") a;;\nprint_endline \"\\n-------\";;\n *)\n\nclose_in ic;;\n\nlet my_min x y z = min (min x y ) (min y z )\n\nexception Found;;\n\nlet rec b1search x ii jj =\n let mid = (ii+jj)/2 in\n if mid = ii then ii\n else\n if x > 2*a.(mid) then b1search x (mid+1) jj\n else b1search x ii mid\n;; \n\n \n \nlet rec b2search x ii jj =\nlet mid = (ii+jj)/2 in\nif mid = ii then ii\nelse\n if 2*x < a.(mid) then b2search x (mid+1) jj\n else b2search x ii mid\n;;\n\n(*let y = b1search 8 0 5 in\nprint_int y;;\n *)\n\nlet rec solve i j =\n if i >= j then 0\n else if\n a.(i) <= 2*a.(j) \n then i+(n-1-j)\n else\n begin\n let x = j-(b1search a.(i) i j) in (*b1search search for small value*)\n let y = (b2search a.(j) i j)-i in (*b2 search searchh for large value*)\n let z = 2 + (solve (i+1) (j-1)) in\n my_min x y z;\n end\n;;\n\nlet rslt = solve 0 (n-1) \n in\n Printf.fprintf oc \"%d\\n\" rslt\n;;\n"}, {"source_code": "(*amazing: this version uses the technique of two pointers*)\n\nlet chan = Scanf.Scanning.from_channel (open_in \"input.txt\")\nlet read_int () = Scanf.bscanf chan \" %d \" (fun x -> x)\n\nlet ochan = open_out \"output.txt\"\nlet print_string s = Printf.fprintf ochan \"%s\" s\n\nlet () = \n let n = read_int() in\n let c = Array.init n (fun i -> read_int()) in\n let () = Array.sort compare c in\n \n let rec loop i j ac =\n if i=j then ac else\n if c.(j) <= 2*c.(i) then \n\tloop (i+1) j (max (j-i+1) ac)\n else loop i (j-1) ac\n in\n \n let a = loop 0 (n-1) 0 in\n print_string (Printf.sprintf \"%d\\n\" (n-a))\n"}], "src_uid": "80cf3ea119fd398e8f003d22a76895a7"} {"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 read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let adj = Array.init n (fun _ -> read_string()) in\n let a = Array.init n (fun _ -> read_int()) in\n\n let set = Array.make n false in\n let count = Array.make n 0 in\n\n let compute_count () =\n Array.fill count 0 n 0;\n for i=0 to n-1 do\n if set.(i) then\n\tfor j=0 to n-1 do\n\t if adj.(i).[j] = '1' then count.(j) <- count.(j) + 1\n\tdone\n done\n in\n\n let rec find_correct_item i = if i=n then -1 else\n if a.(i) = count.(i) then i else find_correct_item (i+1)\n in\n\n let rec loop () =\n compute_count ();\n let k = find_correct_item 0 in\n if k >= 0 then (\n set.(k) <- true;\n loop ()\n )\n in\n\n loop ();\n\n let c = sum 0 (n-1) (fun i -> if set.(i) then 1 else 0) in\n\n printf \"%d\\n\" c;\n\n for i=0 to n-1 do\n if set.(i) then printf \"%d \" (i+1)\n done;\n\n print_newline();\n", "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\nlet read_int() = bscanf Scanning.stdib \" %d \" (fun x->x)\nlet read_string() = bscanf Scanning.stdib \" %s \" (fun x->x)\nlet () =\n let n = read_int() in\n let adj = Array.init n (fun _-> read_string()) in\n let a = Array.init n (fun _-> read_int()) in\n (* set.(i) = true means excluse i from party*)\n let set = Array.make n false in\n let count = Array.make n 0 in\n \n (* compute each person get how many msgs*)\n let compute() =\n\tArray.fill count 0 n 0;\n\tfor i=0 to n-1 do\n\t if set.(i) then \n\t\tfor j=0 to n-1 do\n\t\t if adj.(i).[j]='1' then count.(j)<-count.(j)+1\n\t\tdone\n\tdone\n in\n \n let rec find_bad_person i =\n\tif i>=n then i\n\telse\n\t if a.(i)=count.(i) then i else find_bad_person (i+1)\n in\n \n let rec loop() =\n\tcompute();\n\tlet i = find_bad_person 0 in\n\tif i if set.(i) then 1 else 0) in\n printf \"%d\\n\" c;\n \n for i=0 to n-1 do\n\tif set.(i) then printf \"%d \" (i+1)\n done;\n print_newline();\n \n"}], "negative_code": [{"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)\nlet () = \n let n = read_int () in\n let _ = Array.init n (fun _ -> read_string()) in\n let a = Array.init n (fun _ -> read_int()) in\n\n if a.(0) = 0 then (\n printf \"1\\n\";\n printf \"1\\n\"\n ) else (\n printf \"0\\n\";\n printf \"\\n\";\n )\n"}, {"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)\nlet () = \n let n = read_int () in\n let _ = Array.init n (fun _ -> read_string()) in\n let a = Array.init n (fun _ -> read_int()) in\n\n if a.(0) = 0 then (\n printf \"1\\n\";\n printf \"1\\n\"\n ) else (\n printf \"0\\n\"\n )\n"}], "src_uid": "794b0ac038e4e32f35f754e9278424d3"} {"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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\n\nmodule ModCalc = struct\n let md = 1000000007L\n (* let md = 998244353L *)\n let validate v =\n (v + (labs(v) / md + 1L) * md) mod md\n let _add_mod md u v = u mod md + v mod md |> validate\n let _sub_mod md u v = u mod md - v mod md |> validate\n let _mul_mod md u v = u mod md * v mod md |> validate\n (* let rec pw u v =\n if v=0L then 1L\n else if v=1L then u mod md\n else let p = pw u (v/2L) in\n if v mod 2L = 0L then _mul_mod md p p\n else _mul_mod md (_mul_mod md p p) u *)\n let rec pow_mod n k = (* to be tested *)\n let rec f a n = function\n | 0L -> a mod md\n | 1L -> _mul_mod md a n\n | k when k mod 2L = 0L -> f a (_mul_mod md n n) (k/2L)\n | k -> f (_mul_mod md a n) n (k-1L)\n in f 1L n k\n let _inv md v = pow_mod v (md-2L) (* md must be prime; otherwise use extended Euclidean algorithm *)\n let _div_mod md u v =\n _mul_mod md u (_inv md v)\n let (+%) u v = _add_mod md u v\n let (-%) u v = _sub_mod md u v\n let ( *%) u v = _mul_mod md u v\n let (/%) u v = _div_mod md u v\n let rec pow x n = if n = 0L then 1L\n else if n mod 2L = 1L then x *% pow x (n-1L)\n else let w = pow x (n/2L) in w *% w\n let fact_simple n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\n type fact = Fact of int64 array * int64 array\n let fact_make n =\n let m = i32 n in\n let fact,invf = Array.make m 0L,Array.make m 0L in\n fact.(0) <- 1L;\n for i=1 to m-$1 do fact.(i) <- fact.(i-$1) *% (i64 i); done;\n invf.(m-$1) <- pow fact.(m-$1) (md-2L);\n for i=m-$2 downto 0 do invf.(i) <- invf.(i+$1) *% (i64 i + 1L); done; Fact (fact,invf)\n let fact_get i (Fact (fact,_)) = fact.(i)\n (* let fact_inv_get i (Fact (_,invf)) = invf.(i) (* not tested yet *) *)\n let ncr n r (Fact (fact,invf)) = fact.(n) *% invf.(r) *% invf.(n-$r)\nend open ModCalc\nlet tp k = pow 2L k\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = tp one - 1L in\n let sum_zero = sum_one * (tp zero - 1L) in\n printf \"%Ld\\n\" (sum_one +% sum_zero)\n )\n\n\n\n\n\n\n\n\n", "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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\n\nmodule ModCalc = struct\n let md = 1000000007L\n (* let md = 998244353L *)\n let validate v =\n (v + (labs(v) / md + 1L) * md) mod md\n let _add_mod md u v = u mod md + v mod md |> validate\n let _sub_mod md u v = u mod md - v mod md |> validate\n let _mul_mod md u v = u mod md * v mod md |> validate\n let rec pw u v =\n if v=0L then 1L\n else if v=1L then u mod md\n else let p = pw u (v/2L) in\n if v mod 2L = 0L then _mul_mod md p p\n else _mul_mod md (_mul_mod md p p) u\n let _inv md v = pw v (md-2L) (* md must be prime; otherwise use extended Euclidean algorithm *)\n let _div_mod md u v =\n _mul_mod md u (_inv md v)\n let (+%) u v = _add_mod md u v\n let (-%) u v = _sub_mod md u v\n let ( *%) u v = _mul_mod md u v\n let (/%) u v = _div_mod md u v\n let rec pow x n = if n = 0L then 1L\n else if n mod 2L = 1L then x *% pow x (n-1L)\n else let w = pow x (n/2L) in w *% w\n let fact_simple n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\n type fact = Fact of int64 array * int64 array\n let fact_make n =\n let m = i32 n in\n let fact,invf = Array.make m 0L,Array.make m 0L in\n fact.(0) <- 1L;\n for i=1 to m-$1 do fact.(i) <- fact.(i-$1) *% (i64 i); done;\n invf.(m-$1) <- pow fact.(m-$1) (md-2L);\n for i=m-$2 downto 0 do invf.(i) <- invf.(i+$1) *% (i64 i + 1L); done; Fact (fact,invf)\n let fact_get i (Fact (fact,_)) = fact.(i)\n (* let fact_inv_get i (Fact (_,invf)) = invf.(i) (* not tested yet *) *)\n let ncr n r (Fact (fact,invf)) = fact.(n) *% invf.(r) *% invf.(n-$r)\nend open ModCalc\n\nlet tp i =\n let i = ref i in\n let x = ref 2L in\n let r = ref 1L in\n while !i > 0L do\n if !i mod 2L = 1L then (\n r := !r *% !x;\n );\n x := !x *% !x;\n i /= 2L;\n done; !r\n\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n (* printf \"%Ld %Ld\\n\" one zero; *)\n let sum_one = tp one - 1L in\n (* printf \"%Ld\\n\" sum_one; *)\n let sum_zero = sum_one * (tp zero - 1L) in\n (* printf \"%Ld\\n\" sum_zero; *)\n printf \"%Ld\\n\" (sum_one +% sum_zero)\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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\n\nlet md = 1000000007L\nlet ( *$ ) p q = ((p mod md) * (q mod md)) mod md\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*$n) (k/2L)\n in f 1L n k\n\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = pow 2L one - 1L in\n let sum_zero = sum_one * (pow 2L zero - 1L) in\n printf \"%Ld\\n\" @@ (sum_one + sum_zero) mod md\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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\nmodule ModCalc_test = struct\n let md = 1000000007L\n (* let md = 998244353L *)\n (* be careful of negative int *)\n let (+%) p q = ((p mod md) + (q mod md)) mod md\n let (-%) p q = ((p mod md) - (q mod md)) mod md\n let ( *% ) p q = ((p mod md) * (q mod md)) mod md\n let rec pow_mod n k = (* to be tested *)\n let rec f a n = function\n | 0L -> a mod md\n | 1L -> a *% n\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 let inv v = pow_mod v (md-2L) (* md must be prime; otherwise use extended Euclidean algorithm *)\n let (/%) p q = p *% (inv q)\n let fact_simple n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\n type fact = Fact of int64 array * int64 array\n let fact_make n =\n let m = i32 n in\n let fact,invf = Array.make m 0L,Array.make m 0L in\n fact.(0) <- 1L;\n for i=1 to m-$1 do fact.(i) <- fact.(i-$1) *% (i64 i); done;\n invf.(m-$1) <- pow_mod fact.(m-$1) (md-2L);\n for i=m-$2 downto 0 do invf.(i) <- invf.(i+$1) *% (i64 i + 1L); done; Fact (fact,invf)\n let fact_get i (Fact (fact,_)) = fact.(i)\n let ncr n r (Fact (fact,invf)) = fact.(n) *% invf.(r) *% invf.(n-$r)\nend\nopen ModCalc_test\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = pow_mod 2L one - 1L in\n let sum_zero = sum_one * (pow_mod 2L zero - 1L) in\n printf \"%Ld\\n\" @@ sum_one +% sum_zero\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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\n\nlet md = 1000000007L\nlet ( +$ ) p q = ((p mod md) + (q mod md)) mod md\nlet ( *$ ) p q = ((p mod md) * (q mod md)) mod md\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*$n) (k/2L)\n in f 1L n k\n\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = pow 2L one - 1L in\n let sum_zero = sum_one * (pow 2L zero - 1L) in\n printf \"%Ld\\n\" @@ sum_one +$ sum_zero\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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\nmodule ModCalc_test = struct\n let md = 1000000007L\n (* let md = 998244353L *)\n (* be careful of negative int *)\n let (+%) p q = ((p mod md) + (q mod md)) mod md\n let (-%) p q = ((p mod md) - (q mod md)) mod md\n let ( *% ) p q = ((p mod md) * (q mod md)) mod md\n let rec pow_mod n k = (* to be tested *)\n let rec f a n = function\n | 0L -> a mod md\n | 1L -> a *% n\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 (* let inv v = pow_mod v (md-2L) (* md must be prime; otherwise use extended Euclidean algorithm *)\n let (/%) p q = p *% (inv q)\n let fact_simple n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\n type fact = Fact of int64 array * int64 array\n let fact_make n =\n let m = i32 n in\n let fact,invf = Array.make m 0L,Array.make m 0L in\n fact.(0) <- 1L;\n for i=1 to m-$1 do fact.(i) <- fact.(i-$1) *% (i64 i); done;\n invf.(m-$1) <- pow_mod fact.(m-$1) (md-2L);\n for i=m-$2 downto 0 do invf.(i) <- invf.(i+$1) *% (i64 i + 1L); done; Fact (fact,invf)\n let fact_get i (Fact (fact,_)) = fact.(i)\n let ncr n r (Fact (fact,invf)) = fact.(n) *% invf.(r) *% invf.(n-$r) *)\nend\nopen ModCalc_test\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = pow_mod 2L one - 1L in\n let sum_zero = sum_one * (pow_mod 2L zero - 1L) in\n printf \"%Ld\\n\" @@ sum_one +% sum_zero\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\n\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\n\nlet md = 1000000007L\nlet pow n k =\n let rec f a n = function\n | 0L -> a\n | 1L -> (n*a) mod md\n | k when k mod 2L = 0L -> f a (n*n) (k/2L) mod md\n | k -> f (a*n) (n*n) (k/2L) mod md\n in f 1L n k\n\nlet () =\n let n,q = get_2_i64 0 in\n let a =\n let s = scanf \" %s\"@@id in\n let a = make (String.length s) 0L in\n String.iteri (fun i c -> a.(i) <- i64 @@ (int_of_char c) -$ (int_of_char '0')) s;\n a in\n let ones = CumulSumArray.make a in\n rep 1L q (fun _ ->\n let l,r = get_2_i64 0 in\n let one = CumulSumArray.sum_1orig (i32 l) (i32 r) ones in\n let zero = r - l + 1L - one in\n let sum_one = pow 2L one - 1L in\n let sum_zero = sum_one * (pow 2L zero - 1L) in\n printf \"%Ld\\n\" @@ (sum_one + sum_zero) mod md\n )\n\n\n\n\n\n\n\n\n"}], "src_uid": "88961744a28d7c890264a39a0a798708"} {"source_code": "let sum_vec (x1,y1,z1) (x2,y2,z2) =\n\t(x1+x2, y1+y2, z1+z2)\n;;\n\nlet read_vec _ = Scanf.scanf \"%d %d %d\\n\" (fun x y z -> (x,y,z));;\n\nlet () =\n\tlet n = read_int () in\n\tlet forces = Array.init n read_vec in\n\tlet f = Array.fold_left sum_vec (0,0,0) forces in\n\t\tprint_string (if f = (0,0,0) then \"YES\" else \"NO\")\n;;\n", "positive_code": [{"source_code": "let solve n =\n let rec loop n x y z =\n if n <= 0\n then\n if x == 0 && y == 0 && z == 0\n then \"YES\"\n else \"NO\"\n else Scanf.scanf \"%d %d %d\\n\" (fun a b c -> loop (n-1) (x+a) (y+b) (z+c))\n in\n loop n 0 0 0\n\nlet _ =\n Printf.printf \"%s\\n\" (Scanf.scanf \"%d\\n\" solve)\n \n"}, {"source_code": "\n(* Codeforces 69A *)\n\ntype coordinate = { x: int; y: int; z: int }\n\nlet zero = { x = 0; y = 0; z = 0 }\n \nlet make_coordinate x y z = { x = x; y = y; z = z }\n\nlet add a b =\n { x = a.x + b.x; y = a.y + b.y; z = a.z + b.z }\n\nlet rec solve accu = function\n | 0 -> if accu = zero then \"YES\" else \"NO\"\n | n ->\n let c =\n Scanf.scanf \"%d %d %d\\n\" (fun x y z -> make_coordinate x y z) in\n solve (add accu c) (n-1)\n\nlet _ =\n let n = read_int() in\n print_endline (solve zero n)\n\n \n\n \n"}, {"source_code": "let list_init n f =\n let rec read_vectors n vectors = \n if n > 0\n then\n let coordinates = f() in\n read_vectors (n - 1) (coordinates :: vectors)\n else\n List.rev vectors\n in read_vectors n []\n\nlet vectors n = list_init n (fun i -> Scanf.scanf \"%d %d %d \" (fun s0 s1 s2 -> [s0; s1; s2]))\n\nlet input () = \n let number_of_vectors = Scanf.scanf \"%d \" (fun n -> n) in\n vectors number_of_vectors\n\nlet add_vectors [x; y; z] [xs; ys; zs] = [x + xs; y + ys; z + zs]\n\nlet get_sum list = List.fold_left(fun a b -> add_vectors a b) [0; 0; 0] list\n\nlet solve input = \n if get_sum input = [0; 0; 0]\n then\n \"YES\"\n else\n \"NO\"\n\nlet print result = Printf.printf \"%s\\n\" result\n\nlet () = print (solve (input()))"}], "negative_code": [], "src_uid": "8ea24f3339b2ec67a769243dc68a47b2"} {"source_code": "let main = \n let (s,n) = Scanf.scanf \"%d %d\" (fun s n -> (s,n)) in\n let rec read_all acc n =\n if n = 0 then acc\n else Scanf.scanf \" %d %d\" (fun x y -> read_all ((x,y)::acc) (n-1)) in\n let dragons = read_all [] n in\n let sorted = List.sort compare dragons in\n let rec walk s dragons = \n match dragons with \n | [] -> \"YES\"\n | ((x,y) :: t) -> \n\tif s > x then walk (s+y) t\n else \"NO\" in\n Printf.printf \"%s\\n\" (walk s sorted)\n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d %d \" (fun n m -> (n, m)) \n\nlet input () = \n let (hero_power, total) = read () in\n let rec loop dragons i =\n if i < total\n then\n let dragon = read () in\n loop (dragon :: dragons) (i + 1)\n else\n (hero_power, dragons)\n in loop [] 0\n\nlet fight hero_power (dragon_power, reward) =\n if hero_power > dragon_power\n then\n `victory (hero_power + reward)\n else\n `defeat\n\nlet tuple_compare (power_1, reward_1) (power_2, reward_2) =\n Pervasives.compare power_1 power_2\n\nlet solve (hero_power, dragons) =\n let dragons = List.sort (tuple_compare) dragons in \n let rec loop power list =\n match list with\n | (dragon :: tail) -> \n (match fight power dragon with\n | `victory (upd_power) -> loop upd_power tail\n | `defeat -> \"NO\")\n | [] -> \"YES\"\n in loop hero_power dragons\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (input ()))"}], "negative_code": [{"source_code": "let main = \n let (s,n) = Scanf.scanf \"%d %d\" (fun s n -> (s,n)) in\n let rec read_all acc n =\n if n = 0 then acc\n else Scanf.scanf \" %d %d\" (fun x y -> read_all ((x,y)::acc) (n-1)) in\n let dragons = read_all [] n in\n let pcompare (_,y1) (_,y2) = - (compare y1 y2) in\n let sorted = List.sort pcompare dragons in\n let rec walk s dragons = \n match dragons with \n | [] -> \"YES\"\n | ((x,y) :: t) -> \n\tif s > x then walk (s+y) t\n else \"NO\" in\n Printf.printf \"%s\\n\" (walk s sorted)\n"}], "src_uid": "98f5b6aac08f48f95b2a8ce0738de657"} {"source_code": "(** https://codeforces.com/contest/1472/problem/B *)\n\nlet get_candies () =\n let tbl = Array.make 2 0 in\n let candy_list =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string in\n List.iter\n (fun candy -> tbl.(candy-1) <- tbl.(candy-1) + 1)\n candy_list;\n tbl\n\nlet fair_share tbl_candies =\n if tbl_candies.(1) mod 2 = 0\n then tbl_candies.(0) mod 2 = 0\n else tbl_candies.(0) - 2 >= 0 && (tbl_candies.(0) - 2) mod 2 = 0\n\nlet solve_n nb_cases =\n let rec helper i =\n if i > 0\n then (\n let _ = read_line () in\n let tbl_candies = get_candies () in\n (if fair_share tbl_candies then \"YES\" else \"NO\")\n |> print_endline;\n helper (i-1)\n ) in\n helper nb_cases\n\nlet () =\n let nb_cases = read_int () in\n solve_n nb_cases\n", "positive_code": [{"source_code": "(* #load \"str.cma\" *)\r\nmodule Stdlib = Pervasives;;\r\n(* let std_inp = Stdlib.open_in \"input.txt\";; *)\r\nlet std_inp = Stdlib.stdin;;\r\nlet std_outp = Stdlib.stdout;;\r\n\r\nlet identity x = x;;\r\n\r\nlet recogn (ones, twos) item =\r\n if item == 1 then (ones + 1, twos)\r\n else (ones, twos + 1);;\r\n\r\nlet rec solve (ones, twos) n =\r\nif n > twos / 2 then false\r\nelse\r\n let ones_debt = (twos - n * 2) * 2 in\r\n (* let _ = Printf.printf \"Debt: %d\\n\" ones_debt in *)\r\n if ones >= ones_debt && (ones - ones_debt) mod 2 == 0 then true\r\n else solve (ones, twos) (n + 1);;\r\n\r\nlet solution inp outp =\r\n let _ = input_line inp in\r\n let (ones, twos)=\r\n input_line inp\r\n |> Str.split @@ Str.regexp \" \"\r\n |> List.map int_of_string\r\n |> List.fold_left recogn (0, 0)\r\n in\r\n (* let _ = Printf.printf \"Ones: %d; Twos: %d\\n\" ones twos in *)\r\n let result = solve (ones, twos) 0 in\r\n let _ =\r\n if result then Printf.printf \"YES\\n\"\r\n else Printf.printf \"NO\\n\"\r\n in\r\n ();;\r\n\r\nlet rec run_test = function\r\n| (0, _, _) -> ()\r\n| (t, inp, outp) ->\r\n let _ = solution inp outp in\r\n run_test (t - 1, inp, outp);;\r\n\r\nlet (_:unit) =\r\n let inp = std_inp and outp = std_outp in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let _ = run_test (tests_count, inp, outp) in\r\n ();;"}], "negative_code": [{"source_code": "(* #load \"str.cma\" *)\r\nmodule Stdlib = Pervasives;;\r\n(* let std_inp = Stdlib.open_in \"input.txt\";; *)\r\nlet std_inp = Stdlib.stdin;;\r\nlet std_outp = Stdlib.stdout;;\r\n\r\nlet identity x = x;;\r\n\r\nlet recogn (ones, twos) item =\r\n if item == 1 then (ones + 1, twos)\r\n else (ones, twos + 1);;\r\n\r\nlet rec solve (ones, twos) n =\r\nif n > twos then false\r\nelse\r\n let ones_debt = (twos - n) * 2 in\r\n (* let _ = Printf.printf \"Debt: %d\\n\" ones_debt in *)\r\n if ones > ones_debt && (ones - ones_debt) mod 2 == 0 then true\r\n else solve (ones, twos) (n + 1);;\r\n\r\nlet solution inp outp =\r\n let _ = input_line inp in\r\n let (ones, twos)=\r\n input_line inp\r\n |> Str.split @@ Str.regexp \" \"\r\n |> List.map int_of_string\r\n |> List.fold_left recogn (0, 0)\r\n in\r\n (* let _ = Printf.printf \"Ones: %d; Twos: %d\\n\" ones twos in *)\r\n let result = solve (ones, twos) 0 in\r\n let _ =\r\n if result then Printf.printf \"YES\\n\"\r\n else Printf.printf \"NO\\n\"\r\n in\r\n ();;\r\n\r\nlet rec run_test = function\r\n| (0, _, _) -> ()\r\n| (t, inp, outp) ->\r\n let _ = solution inp outp in\r\n run_test (t - 1, inp, outp);;\r\n\r\nlet (_:unit) =\r\n let inp = std_inp and outp = std_outp in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let _ = run_test (tests_count, inp, outp) in\r\n ();;"}], "src_uid": "1d9d34dca11a787d6e2345494680e717"} {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de brul\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 600 downto 300 do\n\t\tif (tab.(i) = 1) || (tab.(i) = 3)\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\tthen incr compte\n\t\t\t\t\t\n\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure + 1 to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 601 0 in\n\tfor i=1 to m do\n\t\ttab.(300 + Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\nfinal ();;\n", "positive_code": [{"source_code": "exception Not_possible\nlet () =\n Scanf.scanf \"%d %d %d\\n\" (fun m t r ->\n (* array of ghost times *)\n let g = Array.init m (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* queue of candles *)\n let q = Queue.create () in\n (* number of candles *)\n let c = ref r in\n (* maximum timeslot at which a candle was lit *)\n let m = ref (g.(0) - 1) in\n (* light r candles before the first ghost *)\n for i = g.(0) - r to g.(0) - 1 do\n Queue.add i q\n done;\n try\n Array.iter (fun w ->\n (* remove stale candles *)\n while not (Queue.is_empty q) && Queue.peek q + t < w do\n ignore (Queue.take q)\n done;\n let l = Queue.length q in\n (* add more candles if necessary *)\n for i = w - r + l to w - 1 do\n if i <= !m then\n raise Not_possible\n else begin\n Queue.add i q;\n incr c;\n m := i\n end\n done\n ) g;\n Printf.printf \"%d\\n\" !c\n with Not_possible -> print_endline \"-1\"\n )\n"}], "negative_code": [{"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de pos\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 820 downto 400 do\n\t\tif tab.(i) mod 3 = 1\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\t\tthen incr compte\n\t\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure + 1 to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 821 0 in\n\tfor i=1 to m do\n\t\ttab.(400 + Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\t\nfinal ();;\n"}, {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de pos\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 620 downto 300 do\n\t\tif tab.(i) mod 3 = 1\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\t\tthen incr compte\n\t\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure + 1 to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 621 0 in\n\tfor i=1 to m do\n\t\ttab.(300 + Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\t\nfinal ();;\n"}, {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de pos\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 620 downto 300 do\n\t\tif tab.(i) mod 3 = 1\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\t\tthen incr compte\n\t\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure + 1 to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 621 0 in\n\tfor i=1 to m do\n\t\ttab.(Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\t\nfinal ();;\n"}, {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de pos\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 820 downto 400 do\n\t\tif (tab.(i) = 1) || (tab.(i) = 3)\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\tthen incr compte\n\t\t\t\t\t\n\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 821 0 in\n\tfor i=1 to m do\n\t\ttab.(400 + Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n(*\nfinal ();;\n*)\n\nlet test l dure besoin =\n\tlet tab = Array.make 821 0 in\n\t\tList.iter (fun i -> tab.(400 + i) <- 1) l;\n\t\tf tab dure besoin;;\n\n(test [10] 8 3 = 3,\ntest [5;8] 10 1 = 1,\ntest [10] 1 3 = -1);;\n"}, {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de pos\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 620 downto 300 do\n\t\tif tab.(i) mod 3 = 1\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\t\tfor j= i - dure + 1 to i do\n\t\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\t\tthen incr compte\n\t\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure + 1 to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 3)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 621 0 in\n\tfor i=1 to m do\n\t\ttab.(Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\t\nfinal ();;\n"}, {"source_code": "(* 0 = rien; 1= fantome ; 2 = bougie finie de brul\u00e9e ; bougie et fantome *)\n\nlet f tab dure besoin =\n\tlet bug = ref false in\n\tfor i= 600 downto 300 do\n\t\tif (tab.(i) = 1) || (tab.(i) = 3)\n\t\t\tthen begin\n\t\t\t\tlet compte = ref 0 in\n\t\t\t\tfor j= i - dure to i do\n\t\t\t\t\tif tab.(j) > 1\n\t\t\t\t\t\tthen incr compte\n\t\t\t\t\t\n\t\t\t\tdone;\n\t\t\t\tlet manque = ref (besoin - !compte) in\n\t\t\t\tfor j = i - dure to i do\n\t\t\t\t\tif (!manque > 0) && (tab.(j) < 2)\n\t\t\t\t\t\tthen (decr manque; tab.(j) <- tab.(j) + 2);\n\t\t\t\tdone;\n\t\t\t\tif !manque > 0 then bug := true;\n\t\t\t end\n\tdone;\n\tif !bug\n\t\tthen -1\n\t\telse (let compte = ref 0 in\n\t\t\tfor i = 0 to Array.length tab - 1 do\n\t\t\t\tif tab.(i) > 1 then incr compte;\n\t\t\tdone; !compte);;\nlet final () =\n\tlet (m,t,r) = Scanf.scanf \"%d %d %d \" (fun i j k -> (i,j,k)) in\n\tlet tab = Array.make 601 0 in\n\tfor i=1 to m do\n\t\ttab.(300 + Scanf.scanf \"%d \" (fun i -> i)) <- 1;\n\tdone;\n\tPrintf.printf \"%d \" (f tab t r);;\n\nfinal ();;\n"}, {"source_code": "exception Not_possible\nlet () =\n Scanf.scanf \"%d %d %d\\n\" (fun m t r ->\n (* array of ghost times *)\n let g = Array.init m (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* queue of candles *)\n let q = Queue.create () in\n (* number of candles *)\n let c = ref r in\n (* maximum timeslot at which a candle was lit *)\n let m = ref (g.(0) - 1) in\n (* light r candles before the first ghost *)\n for i = g.(0) - r - 1 to g.(0) - 1 do\n Queue.add i q\n done;\n try\n Array.iter (fun w ->\n (* remove stale candles *)\n while not (Queue.is_empty q) && Queue.peek q + t < w do\n ignore (Queue.take q)\n done;\n let l = Queue.length q in\n (* add more candles if necessary *)\n for i = w - r + l - 1 to w - 1 do\n if i <= !m then\n raise Not_possible\n else begin\n Queue.add i q;\n incr c;\n m := i\n end\n done\n ) g;\n Printf.printf \"%d\\n\" !c\n with Not_possible -> print_endline \"-1\"\n )\n"}], "src_uid": "03772bac6ed5bfe75bc0ad4d2eab56fd"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\n\nmodule PSet = struct\n type 'k set =\n | Empty\n | Node of 'k set * 'k * 'k set * int\n\n type 'k t =\n {\n cmp : 'k -> 'k -> int;\n set : 'k set;\n }\n\n let height = function\n | Node (_, _, _, h) -> h\n | Empty -> 0\n\n let make l k r = Node (l, k, r, max (height l) (height r) + 1)\n\n let bal l k r =\n let hl = height l in\n let hr = height r in\n if hl > hr + 2 then\n match l with\n | Node (ll, lk, lr, _) ->\n if height ll >= height lr then make ll lk (make lr k r)\n else\n (match lr with\n | Node (lrl, lrk, lrr, _) ->\n make (make ll lk lrl) lrk (make lrr k r)\n | Empty -> assert false)\n | Empty -> assert false\n else if hr > hl + 2 then\n match r with\n | Node (rl, rk, rr, _) ->\n if height rr >= height rl then make (make l k rl) rk rr\n else\n (match rl with\n | Node (rll, rlk, rlr, _) ->\n make (make l k rll) rlk (make rlr rk rr)\n | Empty -> assert false)\n | Empty -> assert false\n else Node (l, k, r, max hl hr + 1)\n\n let rec min_elt = function\n | Node (Empty, k, _, _) -> k\n | Node (l, _, _, _) -> min_elt l\n | Empty -> raise Not_found\n\n let rec remove_min_elt = function\n | Node (Empty, _, r, _) -> r\n | Node (l, k, r, _) -> bal (remove_min_elt l) k r\n | Empty -> invalid_arg \"PSet.remove_min_elt\"\n\n let merge t1 t2 =\n match t1, t2 with\n | Empty, _ -> t2\n | _, Empty -> t1\n | _ ->\n let k = min_elt t2 in\n bal t1 k (remove_min_elt t2)\n\n let create cmp = { cmp = cmp; set = Empty }\n let empty = { cmp = compare; set = Empty }\n\n let is_empty x = \n x.set = Empty\n\n let rec add_one cmp x = function\n | Node (l, k, r, h) ->\n let c = cmp x k in\n if c = 0 then Node (l, x, r, h)\n else if c < 0 then\n let nl = add_one cmp x l in\n bal nl k r\n else\n let nr = add_one cmp x r in\n bal l k nr\n | Empty -> Node (Empty, x, Empty, 1)\n\n let add x { cmp = cmp; set = set } =\n { cmp = cmp; set = add_one cmp x set }\n\n let rec join cmp l v r =\n match (l, r) with\n (Empty, _) -> add_one cmp v r\n | (_, Empty) -> add_one cmp v l\n | (Node(ll, lv, lr, lh), Node(rl, rv, rr, rh)) ->\n if lh > rh + 2 then bal ll lv (join cmp lr v r) else\n if rh > lh + 2 then bal (join cmp l v rl) rv rr else\n make l v r\n\n let split x { cmp = cmp; set = set } =\n let rec loop x = function\n Empty ->\n (Empty, false, Empty)\n | Node (l, v, r, _) ->\n let c = cmp x v in\n if c = 0 then (l, true, r)\n else if c < 0 then\n let (ll, pres, rl) = loop x l in (ll, pres, join cmp rl v r)\n else\n let (lr, pres, rr) = loop x r in (join cmp l v lr, pres, rr)\n in\n let setl, pres, setr = loop x set in\n { cmp = cmp; set = setl }, pres, { cmp = cmp; set = setr }\n\n let remove x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n if c = 0 then merge l r else\n if c < 0 then bal (loop l) k r else bal l k (loop r)\n | Empty -> Empty in\n { cmp = cmp; set = loop set }\n\n let mem x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n c = 0 || loop (if c < 0 then l else r)\n | Empty -> false in\n loop set\n\n let exists = mem\n\n let iter f { set = set } =\n let rec loop = function\n | Empty -> ()\n | Node (l, k, r, _) -> loop l; f k; loop r in\n loop set\n\n let fold f { cmp = cmp; set = set } acc =\n let rec loop acc = function\n | Empty -> acc\n | Node (l, k, r, _) ->\n loop (f k (loop acc l)) r in\n loop acc set\n\n let elements { set = set } = \n let rec loop acc = function\n Empty -> acc\n | Node(l, k, r, _) -> loop (k :: loop acc r) l in\n loop [] set\nend;;\n\nmodule type GRAPH_LABELS = \n sig \n type label\n end;;\n\n(* Typ modu\u0142u implementuj\u0105cego grafy o wierzcho\u0142kach numerowanych od 0 do n-1. *)\nmodule type GRAPH = \n sig \n (* Etykiety kraw\u0119dzi. *)\n type label\n\n (* Typ graf\u00f3w o wierzcho\u0142kach typu 'a. *)\n type graph\n \n (* Pusty graf. *)\n val init : int -> graph\n\n (* Rozmiar grafu *)\n val size : graph -> int\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_directed_edge : graph -> int -> int -> label -> unit\n\n (* Dodanie kraw\u0119dzi nieskierowanej (dwukierunkowej) \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_edge : graph -> int -> int -> label -> unit\n\n (* Lista incydencji danego wierzcho\u0142ka. *)\n val neighbours : graph -> int -> (int*label) list\n end;;\n\nmodule Graph = functor (L : GRAPH_LABELS) -> \n(struct\n (* Etykiety kraw\u0119dzi. *)\n type label = L.label\n \n (* Typ graf\u00f3w - tablica list s\u0105siedztwa. *)\n type graph = {n : int; e : (int*label) list array}\n \n (* Pusty graf. *)\n let init s = {n = s; e = Array.make s []}\n\n (* Rozmiar grafu. *)\n let size g = g.n\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n let insert_directed_edge g x y l = \n assert ((x<>y) && (x >= 0) && (x < size g) && (y >= 0) && (y < size g));\n g.e.(x) <- (y,l)::g.e.(x)\n \n (* Dodanie kraw\u0119dzi \u0142\u0105cz\u0105cej dwa (istniej\u0105ce) wierzcho\u0142ki. *)\n let insert_edge g x y l =\n insert_directed_edge g x y l;\n insert_directed_edge g y x l\n \n (* Lista incydencji danego wierzcho\u0142ka. *)\n let neighbours g x =\n g.e.(x)\nend : GRAPH with type label = L.label);;\n\nmodule IntLabel = \n struct\n type label = int\n end;;\n\nmodule G = Graph(IntLabel);;\n\nopen G;;\nopen PSet;;\nlet n = scan_int() and m = scan_int() and k = scan_int();;\nlet g = G.init n;;\n\nlet zbior = ref empty;;\n\nfor i = 1 to m do\n let a = scan_int() - 1 and b = scan_int() - 1 and c = scan_int() in\n (*dbg a; pnl(); dbg b; pnl(); pnl(); *)\n G.insert_edge g a b c;\ndone;;\n\nfor i = 1 to k do\n let a = scan_int() - 1 and b = scan_int() in\n zbior := add (Int64.of_int(b), 1, a) !zbior;\ndone;; \n\nzbior := add (Int64.zero, 0, 0) !zbior;;\nlet dis = Array.make n Int64.max_int;;\n\nlet przydatne = ref 0;;\n\nwhile is_empty !zbior = false do\n let (odl, czy, u) = min_elt (!zbior).set in\n zbior := {cmp = (!zbior).cmp; set = remove_min_elt (!zbior).set};\n if odl < dis.(u) then begin\n (* dbg (Int64.to_int odl); psp(); dbg czy; psp(); dbg u; pnl(); *)\n dis.(u) <- odl;\n if czy = 1 then incr przydatne;\n List.iter (fun (v, w) ->\n let waga = Int64.add odl (Int64.of_int(w)) in\n if waga < dis.(v) then begin\n zbior := add (waga, 0, v) !zbior;\n end;\n ) (neighbours g u);\n end;\ndone;;\n\nprint_int (k - !przydatne);;\n", "positive_code": [{"source_code": "(* codeforces 103. Danny Sleator *)\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nmodule Pset = Set.Make (struct type t = int64*int let compare = compare end)\n\nlet long x = Int64.of_int x\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\n\nlet n = read_int ()\nlet m = read_int ()\nlet k = read_int ()\nlet ne = m + k\n\nlet ss = Array.make (2*ne) 0\nlet ff = Array.make (2*ne) 0\nlet ww = Array.make (2*ne) 0L\nlet first = Array.make n (-1)\nlet next = Array.make (2*ne) 0\nlet reg_edge = Array.make (2*ne) false\nlet parent_edge = Array.make n (-1)\nlet start = 0\n\nlet () = \n for i=0 to m-1 do\n let vi = read_int() -1 in\n let ui = read_int() -1 in\n let xi = long (read_int()) in\n ss.(i) <- vi;\n ff.(i+ne) <- vi;\n ff.(i) <- ui;\n ss.(i+ne) <- ui;\n ww.(i) <- xi;\n ww.(i+ne) <- xi;\n reg_edge.(i) <- true;\n reg_edge.(i+ne) <- true;\n done;\n\n for i=m to ne-1 do\n let vi = read_int() -1 in\n let ui = start in\n let xi = long (read_int()) in\n ss.(i) <- vi;\n ff.(i+ne) <- vi;\n ff.(i) <- ui;\n ss.(i+ne) <- ui;\n ww.(i) <- xi;\n ww.(i+ne) <- xi;\n done;\n\n for i=0 to 2*ne-1 do\n next.(i) <- first.(ss.(i));\n first.(ss.(i)) <- i;\n done\n\nlet inf = 1_000_000_000_000_000_000L\nlet dist = Array.make n inf\nlet () = dist.(start) <- 0L\n\nlet rec dijkstra s = if Pset.is_empty s then () else \n let (d, v) = Pset.min_elt s in\n let s = Pset.remove (d, v) s in\n let rec loop e s = if e = -1 then s else\n let w = ff.(e) in\n (* processing edge v,w *)\n if dist.(w) = inf then (\n\tdist.(w) <- dist.(v) ++ ww.(e);\n\tparent_edge.(w) <- e;\n\tloop (next.(e)) (Pset.add (dist.(w), w) s)\n ) else if dist.(v) ++ ww.(e) < dist.(w) then (\n\tlet s = Pset.remove (dist.(w), w) s in\n\tdist.(w) <- dist.(v) ++ ww.(e);\n\tparent_edge.(w) <- e;\n\tloop (next.(e)) (Pset.add (dist.(w), w) s)\n ) else if dist.(v) ++ ww.(e) = dist.(w) && reg_edge.(e) then (\n\tparent_edge.(w) <- e;\n\tloop (next.(e)) s\n ) else (\n\tloop (next.(e)) s\n )\n in\n dijkstra (loop first.(v) s)\n\nlet () = dijkstra (Pset.singleton (0L,start))\n\nlet ecount = ref 0\n\nlet () =\n for i=1 to n-1 do\n if parent_edge.(i) < 0 then failwith \"graph not connected\";\n if not (reg_edge.(parent_edge.(i))) then ecount := !ecount + 1\n done;\n\n Printf.printf \"%d\\n\" (k - !ecount)\n"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\n\nmodule PSet = struct\n type 'k set =\n | Empty\n | Node of 'k set * 'k * 'k set * int\n\n type 'k t =\n {\n cmp : 'k -> 'k -> int;\n set : 'k set;\n }\n\n let height = function\n | Node (_, _, _, h) -> h\n | Empty -> 0\n\n let make l k r = Node (l, k, r, max (height l) (height r) + 1)\n\n let bal l k r =\n let hl = height l in\n let hr = height r in\n if hl > hr + 2 then\n match l with\n | Node (ll, lk, lr, _) ->\n if height ll >= height lr then make ll lk (make lr k r)\n else\n (match lr with\n | Node (lrl, lrk, lrr, _) ->\n make (make ll lk lrl) lrk (make lrr k r)\n | Empty -> assert false)\n | Empty -> assert false\n else if hr > hl + 2 then\n match r with\n | Node (rl, rk, rr, _) ->\n if height rr >= height rl then make (make l k rl) rk rr\n else\n (match rl with\n | Node (rll, rlk, rlr, _) ->\n make (make l k rll) rlk (make rlr rk rr)\n | Empty -> assert false)\n | Empty -> assert false\n else Node (l, k, r, max hl hr + 1)\n\n let rec min_elt = function\n | Node (Empty, k, _, _) -> k\n | Node (l, _, _, _) -> min_elt l\n | Empty -> raise Not_found\n\n let rec remove_min_elt = function\n | Node (Empty, _, r, _) -> r\n | Node (l, k, r, _) -> bal (remove_min_elt l) k r\n | Empty -> invalid_arg \"PSet.remove_min_elt\"\n\n let merge t1 t2 =\n match t1, t2 with\n | Empty, _ -> t2\n | _, Empty -> t1\n | _ ->\n let k = min_elt t2 in\n bal t1 k (remove_min_elt t2)\n\n let create cmp = { cmp = cmp; set = Empty }\n let empty = { cmp = compare; set = Empty }\n\n let is_empty x = \n x.set = Empty\n\n let rec add_one cmp x = function\n | Node (l, k, r, h) ->\n let c = cmp x k in\n if c = 0 then Node (l, x, r, h)\n else if c < 0 then\n let nl = add_one cmp x l in\n bal nl k r\n else\n let nr = add_one cmp x r in\n bal l k nr\n | Empty -> Node (Empty, x, Empty, 1)\n\n let add x { cmp = cmp; set = set } =\n { cmp = cmp; set = add_one cmp x set }\n\n let rec join cmp l v r =\n match (l, r) with\n (Empty, _) -> add_one cmp v r\n | (_, Empty) -> add_one cmp v l\n | (Node(ll, lv, lr, lh), Node(rl, rv, rr, rh)) ->\n if lh > rh + 2 then bal ll lv (join cmp lr v r) else\n if rh > lh + 2 then bal (join cmp l v rl) rv rr else\n make l v r\n\n let split x { cmp = cmp; set = set } =\n let rec loop x = function\n Empty ->\n (Empty, false, Empty)\n | Node (l, v, r, _) ->\n let c = cmp x v in\n if c = 0 then (l, true, r)\n else if c < 0 then\n let (ll, pres, rl) = loop x l in (ll, pres, join cmp rl v r)\n else\n let (lr, pres, rr) = loop x r in (join cmp l v lr, pres, rr)\n in\n let setl, pres, setr = loop x set in\n { cmp = cmp; set = setl }, pres, { cmp = cmp; set = setr }\n\n let remove x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n if c = 0 then merge l r else\n if c < 0 then bal (loop l) k r else bal l k (loop r)\n | Empty -> Empty in\n { cmp = cmp; set = loop set }\n\n let mem x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n c = 0 || loop (if c < 0 then l else r)\n | Empty -> false in\n loop set\n\n let exists = mem\n\n let iter f { set = set } =\n let rec loop = function\n | Empty -> ()\n | Node (l, k, r, _) -> loop l; f k; loop r in\n loop set\n\n let fold f { cmp = cmp; set = set } acc =\n let rec loop acc = function\n | Empty -> acc\n | Node (l, k, r, _) ->\n loop (f k (loop acc l)) r in\n loop acc set\n\n let elements { set = set } = \n let rec loop acc = function\n Empty -> acc\n | Node(l, k, r, _) -> loop (k :: loop acc r) l in\n loop [] set\nend;;\n\nmodule type GRAPH_LABELS = \n sig \n type label\n end;;\n\n(* Typ modu\u0142u implementuj\u0105cego grafy o wierzcho\u0142kach numerowanych od 0 do n-1. *)\nmodule type GRAPH = \n sig \n (* Etykiety kraw\u0119dzi. *)\n type label\n\n (* Typ graf\u00f3w o wierzcho\u0142kach typu 'a. *)\n type graph\n \n (* Pusty graf. *)\n val init : int -> graph\n\n (* Rozmiar grafu *)\n val size : graph -> int\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_directed_edge : graph -> int -> int -> label -> unit\n\n (* Dodanie kraw\u0119dzi nieskierowanej (dwukierunkowej) \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_edge : graph -> int -> int -> label -> unit\n\n (* Lista incydencji danego wierzcho\u0142ka. *)\n val neighbours : graph -> int -> (int*label) list\n end;;\n\nmodule Graph = functor (L : GRAPH_LABELS) -> \n(struct\n (* Etykiety kraw\u0119dzi. *)\n type label = L.label\n \n (* Typ graf\u00f3w - tablica list s\u0105siedztwa. *)\n type graph = {n : int; e : (int*label) list array}\n \n (* Pusty graf. *)\n let init s = {n = s; e = Array.make s []}\n\n (* Rozmiar grafu. *)\n let size g = g.n\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n let insert_directed_edge g x y l = \n assert ((x<>y) && (x >= 0) && (x < size g) && (y >= 0) && (y < size g));\n g.e.(x) <- (y,l)::g.e.(x)\n \n (* Dodanie kraw\u0119dzi \u0142\u0105cz\u0105cej dwa (istniej\u0105ce) wierzcho\u0142ki. *)\n let insert_edge g x y l =\n insert_directed_edge g x y l;\n insert_directed_edge g y x l\n \n (* Lista incydencji danego wierzcho\u0142ka. *)\n let neighbours g x =\n g.e.(x)\nend : GRAPH with type label = L.label);;\n\nmodule IntLabel = \n struct\n type label = int\n end;;\n\nmodule G = Graph(IntLabel);;\n\nopen G;;\nopen PSet;;\nlet n = scan_int() and m = scan_int() and k = scan_int();;\nlet g = G.init n;;\n\nlet zbior = ref empty;;\n\nfor i = 1 to m do\n let a = scan_int() - 1 and b = scan_int() - 1 and c = scan_int() in\n (*dbg a; pnl(); dbg b; pnl(); pnl(); *)\n G.insert_edge g a b c;\ndone;;\n\nfor i = 1 to k do\n let a = scan_int() - 1 and b = scan_int() in\n zbior := add (Int64.of_int(b), 1, a) !zbior;\ndone;; \n\nzbior := add (Int64.zero, 0, 0) !zbior;;\nlet dis = Array.make n Int64.max_int;;\n\nlet przydatne = ref 0;;\n\nwhile is_empty !zbior = false do\n let (odl, czy, u) = min_elt (!zbior).set in\n zbior := {cmp = (!zbior).cmp; set = remove_min_elt (!zbior).set};\n if odl < dis.(u) then begin\n dis.(u) <- odl;\n if czy = 1 then incr przydatne;\n List.iter (fun (v, w) ->\n let waga = Int64.add odl (Int64.of_int(w)) in\n if waga < dis.(v) then begin\n dis.(v) <- waga;\n zbior := add (waga, 0, v) !zbior;\n end;\n ) (neighbours g u);\n end;\ndone;;\n\nprint_int (k - !przydatne);;\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 \" \";; let pnl () = print_newline ();;\nlet b2i x = if x == true then 1 else 0;;\nlet dbg x = print_int(x); pnl();;\n\n\nmodule PSet = struct\n type 'k set =\n | Empty\n | Node of 'k set * 'k * 'k set * int\n\n type 'k t =\n {\n cmp : 'k -> 'k -> int;\n set : 'k set;\n }\n\n let height = function\n | Node (_, _, _, h) -> h\n | Empty -> 0\n\n let make l k r = Node (l, k, r, max (height l) (height r) + 1)\n\n let bal l k r =\n let hl = height l in\n let hr = height r in\n if hl > hr + 2 then\n match l with\n | Node (ll, lk, lr, _) ->\n if height ll >= height lr then make ll lk (make lr k r)\n else\n (match lr with\n | Node (lrl, lrk, lrr, _) ->\n make (make ll lk lrl) lrk (make lrr k r)\n | Empty -> assert false)\n | Empty -> assert false\n else if hr > hl + 2 then\n match r with\n | Node (rl, rk, rr, _) ->\n if height rr >= height rl then make (make l k rl) rk rr\n else\n (match rl with\n | Node (rll, rlk, rlr, _) ->\n make (make l k rll) rlk (make rlr rk rr)\n | Empty -> assert false)\n | Empty -> assert false\n else Node (l, k, r, max hl hr + 1)\n\n let rec min_elt = function\n | Node (Empty, k, _, _) -> k\n | Node (l, _, _, _) -> min_elt l\n | Empty -> raise Not_found\n\n let rec remove_min_elt = function\n | Node (Empty, _, r, _) -> r\n | Node (l, k, r, _) -> bal (remove_min_elt l) k r\n | Empty -> invalid_arg \"PSet.remove_min_elt\"\n\n let merge t1 t2 =\n match t1, t2 with\n | Empty, _ -> t2\n | _, Empty -> t1\n | _ ->\n let k = min_elt t2 in\n bal t1 k (remove_min_elt t2)\n\n let create cmp = { cmp = cmp; set = Empty }\n let empty = { cmp = compare; set = Empty }\n\n let is_empty x = \n x.set = Empty\n\n let rec add_one cmp x = function\n | Node (l, k, r, h) ->\n let c = cmp x k in\n if c = 0 then Node (l, x, r, h)\n else if c < 0 then\n let nl = add_one cmp x l in\n bal nl k r\n else\n let nr = add_one cmp x r in\n bal l k nr\n | Empty -> Node (Empty, x, Empty, 1)\n\n let add x { cmp = cmp; set = set } =\n { cmp = cmp; set = add_one cmp x set }\n\n let rec join cmp l v r =\n match (l, r) with\n (Empty, _) -> add_one cmp v r\n | (_, Empty) -> add_one cmp v l\n | (Node(ll, lv, lr, lh), Node(rl, rv, rr, rh)) ->\n if lh > rh + 2 then bal ll lv (join cmp lr v r) else\n if rh > lh + 2 then bal (join cmp l v rl) rv rr else\n make l v r\n\n let split x { cmp = cmp; set = set } =\n let rec loop x = function\n Empty ->\n (Empty, false, Empty)\n | Node (l, v, r, _) ->\n let c = cmp x v in\n if c = 0 then (l, true, r)\n else if c < 0 then\n let (ll, pres, rl) = loop x l in (ll, pres, join cmp rl v r)\n else\n let (lr, pres, rr) = loop x r in (join cmp l v lr, pres, rr)\n in\n let setl, pres, setr = loop x set in\n { cmp = cmp; set = setl }, pres, { cmp = cmp; set = setr }\n\n let remove x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n if c = 0 then merge l r else\n if c < 0 then bal (loop l) k r else bal l k (loop r)\n | Empty -> Empty in\n { cmp = cmp; set = loop set }\n\n let mem x { cmp = cmp; set = set } =\n let rec loop = function\n | Node (l, k, r, _) ->\n let c = cmp x k in\n c = 0 || loop (if c < 0 then l else r)\n | Empty -> false in\n loop set\n\n let exists = mem\n\n let iter f { set = set } =\n let rec loop = function\n | Empty -> ()\n | Node (l, k, r, _) -> loop l; f k; loop r in\n loop set\n\n let fold f { cmp = cmp; set = set } acc =\n let rec loop acc = function\n | Empty -> acc\n | Node (l, k, r, _) ->\n loop (f k (loop acc l)) r in\n loop acc set\n\n let elements { set = set } = \n let rec loop acc = function\n Empty -> acc\n | Node(l, k, r, _) -> loop (k :: loop acc r) l in\n loop [] set\nend;;\n\nmodule type GRAPH_LABELS = \n sig \n type label\n end;;\n\n(* Typ modu\u0142u implementuj\u0105cego grafy o wierzcho\u0142kach numerowanych od 0 do n-1. *)\nmodule type GRAPH = \n sig \n (* Etykiety kraw\u0119dzi. *)\n type label\n\n (* Typ graf\u00f3w o wierzcho\u0142kach typu 'a. *)\n type graph\n \n (* Pusty graf. *)\n val init : int -> graph\n\n (* Rozmiar grafu *)\n val size : graph -> int\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_directed_edge : graph -> int -> int -> label -> unit\n\n (* Dodanie kraw\u0119dzi nieskierowanej (dwukierunkowej) \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n val insert_edge : graph -> int -> int -> label -> unit\n\n (* Lista incydencji danego wierzcho\u0142ka. *)\n val neighbours : graph -> int -> (int*label) list\n end;;\n\nmodule Graph = functor (L : GRAPH_LABELS) -> \n(struct\n (* Etykiety kraw\u0119dzi. *)\n type label = L.label\n \n (* Typ graf\u00f3w - tablica list s\u0105siedztwa. *)\n type graph = {n : int; e : (int*label) list array}\n \n (* Pusty graf. *)\n let init s = {n = s; e = Array.make s []}\n\n (* Rozmiar grafu. *)\n let size g = g.n\n \n (* Dodanie kraw\u0119dzi skierowanej \u0142\u0105cz\u0105cej dwa wierzcho\u0142ki. *)\n let insert_directed_edge g x y l = \n assert ((x<>y) && (x >= 0) && (x < size g) && (y >= 0) && (y < size g));\n g.e.(x) <- (y,l)::g.e.(x)\n \n (* Dodanie kraw\u0119dzi \u0142\u0105cz\u0105cej dwa (istniej\u0105ce) wierzcho\u0142ki. *)\n let insert_edge g x y l =\n insert_directed_edge g x y l;\n insert_directed_edge g y x l\n \n (* Lista incydencji danego wierzcho\u0142ka. *)\n let neighbours g x =\n g.e.(x)\nend : GRAPH with type label = L.label);;\n\nmodule IntLabel = \n struct\n type label = int\n end;;\n\nmodule G = Graph(IntLabel);;\n\nopen G;;\nopen PSet;;\nlet n = scan_int() and m = scan_int() and k = scan_int();;\nlet g = G.init n;;\n\nlet zbior = ref empty;;\n\nfor i = 1 to m do\n let a = scan_int() - 1 and b = scan_int() - 1 and c = scan_int() in\n (*dbg a; pnl(); dbg b; pnl(); pnl(); *)\n G.insert_edge g a b c;\ndone;;\n\nfor i = 1 to k do\n let a = scan_int() - 1 and b = scan_int() in\n zbior := add (Int64.of_int(b), 1, a) !zbior;\ndone;; \n\nzbior := add (Int64.zero, 0, 0) !zbior;;\nlet dis = Array.make n Int64.max_int;;\n\nlet przydatne = ref 0;;\n\nwhile is_empty !zbior = false do\n let (odl, czy, u) = min_elt (!zbior).set in\n zbior := {cmp = (!zbior).cmp; set = remove_min_elt (!zbior).set};\n if odl < dis.(u) then begin\n dis.(u) <- odl;\n if czy = 1 then incr przydatne;\n List.iter (fun (v, w) ->\n let waga = Int64.add odl (Int64.of_int(w)) in\n if waga < dis.(v) then begin\n zbior := remove (dis.(v), 0, v) !zbior;\n zbior := remove (dis.(v), 1, v) !zbior;\n dis.(v) <- waga;\n zbior := add (waga, 0, v) !zbior;\n end;\n ) (neighbours g u);\n end;\ndone;;\n\nprint_int (k - !przydatne);;\n"}], "src_uid": "03d6b61be6ca0ac9dd8259458f41da59"} {"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 mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let l = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = 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 m = l /| (Int64.of_int n) in\n let n' = Int64.to_int (Int64.rem l (Int64.of_int n)) in\n let a' = Array.sub a 0 n' in\n let b = Array.copy a in\n let () = Array.sort compare b in\n let b' = Array.copy a' in\n let () = Array.sort compare b' in\n let bs a x =\n let l = ref (-1) in\n let r = ref (Array.length a) in\n while !l < !r - 1 do\n\tlet m = (!l + !r) lsr 1 in\n\t if a.(m) <= x\n\t then l := m\n\t else r := m\n done;\n !r\n in\n let d = Array.make_matrix n (k + 1) 1 in\n (*let cc = Array.init n (fun i -> bs b a.(i)) in*)\n let _ =\n for j = 1 to k do\n let p = ref 0 in\n\tfor i = 0 to n - 1 do\n\t while !p < n && b.(!p) <= b.(i) do\n\t incr p;\n\t done;\n\t d.(i).(j) <-\n\t if i = 0\n\t then d.(!p - 1).(j - 1)\n\t else \n\t Int32.to_int\n\t\t(Int32.rem\n\t\t (Int32.add\n\t\t (Int32.of_int d.(i - 1).(j))\n\t\t (Int32.of_int d.(!p - 1).(j - 1)))\n\t\t (Int32.of_int mm));\n\t (*Printf.printf \"zxc %d %d %d\\n\" i j d.(i).(j)*)\n\tdone\n done;\n in\n let res = ref 0L in\n for i = 0 to n' - 1 do\n let c = bs b a.(i) in\n\t(*Printf.printf \"asd %d %d %d\\n\" i a.(i) c;*)\n\tfor kk = 1 to k do\n\t let k = kk - 1 in\n\t if Int64.of_int k <= m then (\n\t res :=\n\t\tInt64.rem\n\t\t (!res +|\n\t\t (*Int64.of_int bmk.(k) *| *)\n\t\t\t Int64.of_int d.(c - 1).(k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\t )\n\tdone;\n done;\n for kk = 1 to k do\n let k = kk in\n\tif Int64.of_int k <= m then (\n\t res :=\n\t Int64.rem\n\t (!res +|\n\t\t Int64.rem (m -| Int64.of_int (k - 1)) mmm *|\n\t\t Int64.of_int d.(n - 1).(k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\t)\n done;\n Printf.printf \"%Ld\\n\" !res\n", "positive_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x)\n\nlet m = 1_000_000_007\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( ** ) a b = Int64.mul a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet ll a = Int64.of_int a\n\nlet add a b = Int64.to_int (((ll a) ++ (ll b)) %% (ll m))\n\nlet () =\n let n = read_int () in\n let l = Int64.of_string (read_string ()) in\n let k = read_int () in\n let a = Array.init n (fun _ -> read_int ()) in\n let sorted = Array.init n (fun i -> (a.(i), i)) in\n Array.sort (fun a b -> (fst a) - (fst b)) sorted;\n\n let f = Array.make_matrix (k+1) n 0 in\n for j = 0 to n-1 do\n f.(1).(j) <- 1\n done;\n \n for i = 2 to k do\n let sum = ref 0 in\n let l = ref 0 in\n while !l < n do\n let r = ref !l in\n while !r < n && (fst sorted.(!r)) = (fst sorted.(!l)) do\n sum := add !sum f.(i-1).(snd sorted.(!r));\n r := !r + 1\n done;\n while !l < !r do\n f.(i).(snd sorted.(!l)) <- !sum;\n l := !l + 1\n done;\n done;\n done;\n\n let ans = ref 0 in\n for i = 1 to k do\n for j = 0 to n-1 do\n let len = ((ll (i-1)) ** (ll n)) ++ (ll (j+1)) in\n let ways = (l -- len ++ (ll n)) // (ll n) %% (ll m) in\n let llf = ll f.(i).(j) in\n let total = (ways ** llf) %% (ll m) in\n if len <= l then ans := add !ans (Int64.to_int total)\n done;\n done;\n \n Printf.printf \"%d\\n\" !ans\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 mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let l = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = 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 inv = Array.make 1000001 1 in\n let _ =\n for i = 2 to 1000000 do\n inv.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (mmm -| Int64.rem (Int64.of_int (mm / i) *| Int64.of_int inv.(mm mod i)) mmm)\n\t mmm);\n done\n in\n let fact = Array.make (n + k + 2) 1 in\n let ifact = Array.make (n + k + 2) 1 in\n let () =\n for i = 2 to n + k + 1 do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n ifact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int ifact.(i - 1) *| Int64.of_int inv.(i)) mmm);\n done;\n in\n let binom n k =\n Int64.to_int\n (Int64.rem\n\t (Int64.rem (Int64.of_int fact.(n) *| Int64.of_int ifact.(n - k)) mmm *|\n\t Int64.of_int ifact.(k)) mmm)\n in\n (*let binomial = Array.make_matrix (n + k + 1) (k + 1) 0 in\n let _ =\n binomial.(0).(0) <- 1;\n for i = 1 to n + k do\n binomial.(i).(0) <- 1;\n for j = 1 to k do\n\tbinomial.(i).(j) <-\n\t (Int32.to_int\n\t (Int32.rem\n\t\t(Int32.add\n\t\t (Int32.of_int binomial.(i - 1).(j - 1))\n\t\t (Int32.of_int binomial.(i - 1).(j)))\n\t\t(Int32.of_int mm)))\n done\n done\n in*)\n let m = l /| (Int64.of_int n) in\n let bmk = Array.make (k + 1) 1 in\n let _ =\n let m = Int64.rem m mmm in\n for i = 1 to k do\n\tbmk.(i) <-\n\t Int64.to_int\n\t (Int64.rem\n\t (Int64.rem\n\t\t(Int64.of_int bmk.(i - 1) *| (m -| Int64.of_int (i - 1))) mmm *|\n\t\t Int64.of_int inv.(i))\n\t mmm);\n\t(*Printf.printf \"qwe %Ld %d %d %d\\n\" m i bmk.(i) inv.(i)*)\n done;\n in\n let n' = Int64.to_int (Int64.rem l (Int64.of_int n)) in\n let a' = Array.sub a 0 n' in\n let b = Array.copy a in\n let () = Array.sort compare b in\n let b' = Array.copy a' in\n let () = Array.sort compare b' in\n let bs a x =\n let l = ref (-1) in\n let r = ref (Array.length a) in\n while !l < !r - 1 do\n\tlet m = (!l + !r) lsr 1 in\n\t if a.(m) <= x\n\t then l := m\n\t else r := m\n done;\n !r\n in\n let res = ref 0L in\n for i = 0 to n' - 1 do\n let c = bs b a.(i) in\n\t(*Printf.printf \"asd %d %d %d\\n\" i a.(i) c;*)\n\tfor kk = 1 to k do\n\t let k = kk - 1 in\n\t res :=\n\t Int64.rem\n\t\t(!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t\t Int64.of_int (binom (c + k - 1) k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\tdone;\n done;\n for kk = 1 to k do\n let k = kk in\n\tres :=\n\t Int64.rem\n\t (!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t Int64.of_int (binom (n + k - 1) k)) mmm;\n\t(*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n done;\n Printf.printf \"%Ld\\n\" !res\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 mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let l = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = 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 inv = Array.make 1000001 1 in\n let _ =\n for i = 2 to 1000000 do\n inv.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (mmm -| Int64.rem (Int64.of_int (mm / i) *| Int64.of_int inv.(mm mod i)) mmm)\n\t mmm);\n done\n in\n let m = l /| (Int64.of_int n) in\n let bmk = Array.make (k + 1) 1 in\n let _ =\n let m = Int64.rem m mmm in\n for i = 1 to k do\n\tbmk.(i) <-\n\t Int64.to_int\n\t (Int64.rem\n\t (Int64.rem\n\t\t(Int64.of_int bmk.(i - 1) *| (m -| Int64.of_int (i - 1))) mmm *|\n\t\t Int64.of_int inv.(i))\n\t mmm);\n\t(*Printf.printf \"qwe %Ld %d %d %d\\n\" m i bmk.(i) inv.(i)*)\n done;\n in\n let n' = Int64.to_int (Int64.rem l (Int64.of_int n)) in\n let a' = Array.sub a 0 n' in\n let b = Array.copy a in\n let () = Array.sort compare b in\n let b' = Array.copy a' in\n let () = Array.sort compare b' in\n let bs a x =\n let l = ref (-1) in\n let r = ref (Array.length a) in\n while !l < !r - 1 do\n\tlet m = (!l + !r) lsr 1 in\n\t if a.(m) <= x\n\t then l := m\n\t else r := m\n done;\n !r\n in\n let d = Array.make_matrix n (k + 1) 1 in\n (*let cc = Array.init n (fun i -> bs b a.(i)) in*)\n let _ =\n for j = 1 to k do\n let p = ref 0 in\n\tfor i = 0 to n - 1 do\n\t while !p < n && b.(!p) <= b.(i) do\n\t incr p;\n\t done;\n\t d.(i).(j) <-\n\t if i = 0\n\t then d.(!p - 1).(j - 1)\n\t else \n\t Int32.to_int\n\t\t(Int32.rem\n\t\t (Int32.add\n\t\t (Int32.of_int d.(i - 1).(j))\n\t\t (Int32.of_int d.(!p - 1).(j - 1)))\n\t\t (Int32.of_int mm));\n\t (*Printf.printf \"zxc %d %d %d\\n\" i j d.(i).(j)*)\n\tdone\n done;\n in\n let res = ref 0L in\n for i = 0 to n' - 1 do\n let c = bs b a.(i) in\n\t(*Printf.printf \"asd %d %d %d\\n\" i a.(i) c;*)\n\tfor kk = 1 to k do\n\t let k = kk - 1 in\n\t if Int64.of_int k <= m then (\n\t res :=\n\t\tInt64.rem\n\t\t (!res +|\n\t\t (*Int64.of_int bmk.(k) *| *)\n\t\t\t Int64.of_int d.(c - 1).(k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\t )\n\tdone;\n done;\n for kk = 1 to k do\n let k = kk in\n\tif Int64.of_int k <= m then (\n\t res :=\n\t Int64.rem\n\t (!res +|\n\t\t (m -| Int64.of_int (k - 1)) *|\n\t\t Int64.of_int d.(n - 1).(k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\t)\n done;\n Printf.printf \"%Ld\\n\" !res\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 mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let l = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = 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 inv = Array.make 1000001 1 in\n let _ =\n for i = 2 to 1000000 do\n inv.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (mmm -| Int64.rem (Int64.of_int (mm / i) *| Int64.of_int inv.(mm mod i)) mmm)\n\t mmm);\n done\n in\n let fact = Array.make (n + k + 2) 1 in\n let ifact = Array.make (n + k + 2) 1 in\n let () =\n for i = 2 to n + k + 1 do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n ifact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int ifact.(i - 1) *| Int64.of_int inv.(i)) mmm);\n done;\n in\n let binom n k =\n Int64.to_int\n (Int64.rem\n\t (Int64.rem (Int64.of_int fact.(n) *| Int64.of_int ifact.(n - k)) mmm *|\n\t Int64.of_int ifact.(k)) mmm)\n in\n (*let binomial = Array.make_matrix (n + k + 1) (k + 1) 0 in\n let _ =\n binomial.(0).(0) <- 1;\n for i = 1 to n + k do\n binomial.(i).(0) <- 1;\n for j = 1 to k do\n\tbinomial.(i).(j) <-\n\t (Int32.to_int\n\t (Int32.rem\n\t\t(Int32.add\n\t\t (Int32.of_int binomial.(i - 1).(j - 1))\n\t\t (Int32.of_int binomial.(i - 1).(j)))\n\t\t(Int32.of_int mm)))\n done\n done\n in*)\n let m = l /| (Int64.of_int n) in\n let bmk = Array.make (k + 1) 1 in\n let _ =\n let m = Int64.rem m mmm in\n for i = 1 to k do\n\tbmk.(i) <-\n\t Int64.to_int\n\t (Int64.rem\n\t (Int64.rem\n\t\t(Int64.of_int bmk.(i - 1) *| (m -| Int64.of_int (i - 1))) mmm *|\n\t\t Int64.of_int inv.(i))\n\t mmm);\n\t(*Printf.printf \"qwe %Ld %d %d %d\\n\" m i bmk.(i) inv.(i)*)\n done;\n in\n let n' = Int64.to_int (Int64.rem l (Int64.of_int n)) in\n let a' = Array.sub a 0 n' in\n let b = Array.copy a in\n let () = Array.sort compare b in\n let b' = Array.copy a' in\n let () = Array.sort compare b' in\n let bs a x =\n let l = ref (-1) in\n let r = ref (Array.length a) in\n while !l < !r - 1 do\n\tlet m = (!l + !r) lsr 1 in\n\t if a.(m) <= x\n\t then l := m\n\t else r := m\n done;\n !r\n in\n let d = Array.make_matrix n (k + 1) 1 in\n (*let cc = Array.init n (fun i -> bs b a.(i)) in*)\n let _ =\n d.(0).(0) <- 1;\n for j = 1 to k do\n let p = ref 0 in\n\tfor i = 0 to n - 1 do\n\t while !p < n && b.(!p) <= b.(i) do\n\t incr p;\n\t done;\n\t d.(i).(j) <-\n\t if i = 0\n\t then d.(!p - 1).(j - 1)\n\t else \n\t Int32.to_int\n\t\t(Int32.rem\n\t\t (Int32.add\n\t\t (Int32.of_int d.(i - 1).(j))\n\t\t (Int32.of_int d.(!p - 1).(j - 1)))\n\t\t (Int32.of_int mm));\n\t (*Printf.printf \"zxc %d %d %d\\n\" i j d.(i).(j)*)\n\tdone\n done;\n in\n let res = ref 0L in\n for i = 0 to n' - 1 do\n let c = bs b a.(i) in\n\t(*Printf.printf \"asd %d %d %d\\n\" i a.(i) c;*)\n\tfor kk = 1 to k do\n\t let k = kk - 1 in\n\t res :=\n\t Int64.rem\n\t\t(!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t\t Int64.of_int d.(c - 1).(k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\tdone;\n done;\n for kk = 1 to k do\n let k = kk in\n\tres :=\n\t Int64.rem\n\t (!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t Int64.of_int d.(n - 1).(k)) mmm;\n\t(*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n done;\n Printf.printf \"%Ld\\n\" !res\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 mm = 1000000007 in\n let mmm = Int64.of_int mm in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let l = Scanf.bscanf sb \"%Ld \" (fun s -> s) in\n let k = 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 inv = Array.make 1000001 1 in\n let _ =\n for i = 2 to 1000000 do\n inv.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (mmm -| Int64.rem (Int64.of_int (mm / i) *| Int64.of_int inv.(mm mod i)) mmm)\n\t mmm);\n done\n in\n let fact = Array.make (n + k + 2) 1 in\n let ifact = Array.make (n + k + 2) 1 in\n let () =\n for i = 2 to n + k + 1 do\n fact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int fact.(i - 1) *| Int64.of_int i) mmm);\n ifact.(i) <-\n\tInt64.to_int\n\t(Int64.rem\n\t (Int64.of_int ifact.(i - 1) *| Int64.of_int inv.(i)) mmm);\n done;\n in\n let binom n k =\n Int64.to_int\n (Int64.rem\n\t (Int64.rem (Int64.of_int fact.(n) *| Int64.of_int ifact.(n - k)) mmm *|\n\t Int64.of_int ifact.(k)) mmm)\n in\n (*let binomial = Array.make_matrix (n + k + 1) (k + 1) 0 in\n let _ =\n binomial.(0).(0) <- 1;\n for i = 1 to n + k do\n binomial.(i).(0) <- 1;\n for j = 1 to k do\n\tbinomial.(i).(j) <-\n\t (Int32.to_int\n\t (Int32.rem\n\t\t(Int32.add\n\t\t (Int32.of_int binomial.(i - 1).(j - 1))\n\t\t (Int32.of_int binomial.(i - 1).(j)))\n\t\t(Int32.of_int mm)))\n done\n done\n in*)\n let m = l /| (Int64.of_int n) in\n let bmk = Array.make (k + 1) 1 in\n let _ =\n let m = Int64.rem m mmm in\n for i = 1 to k do\n\tbmk.(i) <-\n\t Int64.to_int\n\t (Int64.rem\n\t (Int64.rem\n\t\t(Int64.of_int bmk.(i - 1) *| (m -| Int64.of_int (i - 1))) mmm *|\n\t\t Int64.of_int inv.(i))\n\t mmm);\n\t(*Printf.printf \"qwe %Ld %d %d %d\\n\" m i bmk.(i) inv.(i)*)\n done;\n in\n let n' = Int64.to_int (Int64.rem l (Int64.of_int n)) in\n let a' = Array.sub a 0 n' in\n let b = Array.copy a in\n let () = Array.sort compare b in\n let b' = Array.copy a' in\n let () = Array.sort compare b' in\n let bs a x =\n let l = ref (-1) in\n let r = ref (Array.length a) in\n while !l < !r - 1 do\n\tlet m = (!l + !r) lsr 1 in\n\t if a.(m) <= x\n\t then l := m\n\t else r := m\n done;\n !r\n in\n let d = Array.make_matrix n (k + 1) 1 in\n (*let cc = Array.init n (fun i -> bs b a.(i)) in*)\n let _ =\n d.(0).(0) <- 1;\n for j = 1 to k do\n let p = ref 0 in\n\tfor i = 0 to n - 1 do\n\t while !p < n && b.(!p) <= b.(i) do\n\t incr p;\n\t done;\n\t d.(i).(j) <-\n\t if i = 0\n\t then d.(!p - 1).(j - 1)\n\t else \n\t Int32.to_int\n\t\t(Int32.rem\n\t\t (Int32.add\n\t\t (Int32.of_int d.(i - 1).(j))\n\t\t (Int32.of_int d.(!p - 1).(j - 1)))\n\t\t (Int32.of_int mm));\n\t (*Printf.printf \"zxc %d %d %d\\n\" i j d.(i).(j)*)\n\tdone\n done;\n in\n let res = ref 0L in\n for i = 0 to n' - 1 do\n let c = bs b a.(i) in\n\t(*Printf.printf \"asd %d %d %d\\n\" i a.(i) c;*)\n\tfor kk = 1 to k do\n\t let k = kk - 1 in\n\t res :=\n\t Int64.rem\n\t\t(!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t\t Int64.of_int (binom (c + k - 1) k)) mmm;\n\t (*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n\tdone;\n done;\n for kk = 1 to k do\n let k = kk in\n\tres :=\n\t Int64.rem\n\t (!res +|\n\t\t Int64.of_int bmk.(k) *|\n\t\t Int64.of_int d.(n - 1).(k)) mmm;\n\t(*Printf.printf \"qwe %d %Ld %d\\n\" k !res bmk.(k)*)\n done;\n Printf.printf \"%Ld\\n\" !res\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x)\n\nlet m = 1_000_000_007\n\nlet ( ++ ) a b = Int64.add a b\nlet ( -- ) a b = Int64.sub a b\nlet ( ** ) a b = Int64.mul a b\nlet ( // ) a b = Int64.div a b\nlet ( %% ) a b = Int64.rem a b\n\nlet ll a = Int64.of_int a\n \nlet () =\n let n = read_int () in\n let l = Int64.of_string (read_string ()) in\n let k = read_int () in\n let a = Array.init n (fun _ -> read_int ()) in\n let sorted = Array.init n (fun i -> (a.(i), i)) in\n Array.sort (fun a b -> (fst a) - (fst b)) sorted;\n\n let f = Array.make_matrix (k+1) n 0 in\n for j = 0 to n-1 do\n f.(1).(j) <- 1\n done;\n \n for i = 2 to k do\n let sum = ref 0 in\n let l = ref 0 in\n while !l < n do\n let r = ref !l in\n while !r < n && (fst sorted.(!r)) = (fst sorted.(!l)) do\n sum := (!sum + f.(i-1).(snd sorted.(!r))) mod m;\n r := !r + 1\n done;\n while !l < !r do\n f.(i).(snd sorted.(!l)) <- !sum;\n l := !l + 1\n done;\n done;\n done;\n\n let ans = ref 0 in\n for i = 1 to k do\n for j = 0 to n-1 do\n let len = ((ll (i-1)) ** (ll n)) ++ (ll (j+1)) in\n let ways = (l -- len ++ (ll n)) // (ll n) %% (ll m) in\n let llf = ll f.(i).(j) in\n let total = (ways ** llf) %% (ll m) in\n if len <= l then ans := (!ans + (Int64.to_int total)) mod m\n done;\n done;\n \n Printf.printf \"%d\\n\" !ans\n;;\n"}], "src_uid": "917fb578760e11155227921a7347e58b"} {"source_code": "(* Codeforces 246B *)\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i)\nlet rec readline n li = match n with\n\t| 0 -> li\n\t| _ -> readline (n-1) (gr () :: li);;\n\nlet rec sum l = match l with\n\t| [] -> 0\n\t| h :: t -> h + (sum t);;\n\nlet main () =\n\tlet n = gr () in\n\tlet ll = readline n [] in\n\tlet sm = sum ll in\n\tlet ret = if (sm mod n) = 0 then n else n -1 in\n\t(* print_string \"sm: \"; *)\n\t(* print_int sm; *)\n\t(* print_string \" ret: \"; *)\n\tprint_int ret;;\n\nmain();;\n", "positive_code": [{"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 n = read_int() in\n let a = Array.init n (fun i -> read_int()) in\n let s = sum 0 (n-1) (fun i -> a.(i)) in\n let a = if s mod n = 0 then n else (n-1) in\n Printf.printf \"%d\\n\" a\n"}], "negative_code": [{"source_code": "(* Codeforces 246B *)\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i)\nlet rec readline n li = match n with\n\t| 0 -> li\n\t| _ -> readline (n-1) (gr () :: li);;\n\nlet rec sum l = match l with\n\t| [] -> 0\n\t| h :: t -> h + (sum t);;\n\nlet main () =\n\tlet n = gr () in\n\tlet ll = readline n [] in\n\tlet sm = sum ll in\n\tlet ret = if (sm mod n) = 0 then n else n -1 in\n\tprint_string \"sm: \";\n\tprint_int sm;\n\tprint_string \" ret: \";\n\tprint_int ret;;\n\nmain();;\n"}, {"source_code": "(* Codeforces 246B *)\n\nlet gr () = Scanf.scanf \" %d\" (fun i -> i)\nlet readline n li = match n with\n\t| 0 -> li\n\t| _ -> gr () :: li;;\n\nlet rec sum l = match l with\n\t| [] -> 0\n\t| h :: t -> h + (sum t);;\n\nlet main () =\n\tlet n = gr () in\n\tlet ll = readline n [] in\n\tlet sm = sum ll in\n\tlet ret = if (sm mod n) = 0 then n else n -1 in\n\tprint_int ret;;\n\nmain();;\n"}], "src_uid": "71cead8cf45126902c518c9ce6e5e186"} {"source_code": "(* equivalent to 1061C's solution with n,m are maximized *)\nlet divisors n =\n let rec f0 i a =\n if i*i > n then a\n else if i*i = n && n mod i = 0 then i::a\n else if n mod i = 0 then f0 (i+1) (i::(n/i)::a)\n else f0 (i+1) a\n in f0 1 []\nlet (++) u v = Int64.rem (Int64.add u v) 1000000007L\nexternal id : 'a -> 'a = \"%identity\"\nlet n = Scanf.scanf \" %d\" @@ id\nlet a = Array.init n (fun _ -> Scanf.scanf \" %d\" @@ id)\nlet dp = Array.make 1000007 0L\nlet () =\n Array.iter (fun v ->\n divisors v\n |> List.sort (fun u v -> compare v u)\n |> List.iter (fun d ->\n if d=1 then dp.(1) <- dp.(1) ++ 1L\n else dp.(d) <- dp.(d) ++ dp.(d-1)\n )\n ) a;\n Printf.printf \"%Ld\\n\" @@ Array.fold_left (++) 0L dp\n\n\n", "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(* let divisors v =\n let rec f0 i a =\n if i*i > v then a\n else if i*i = v && v mod i = 0L then i::a\n else if v mod i = 0L then f0 (i+1L) (i::(v/i)::a)\n else f0 (i+1L) a in f0 1L [] *)\nlet divisors n =\n let rec f0 i a =\n if i*$i > n then a\n else if i*$i = n && n %$ i = 0 then i::a\n else if n %$ i = 0 then f0 (i+$1) (i::(n/$i)::a)\n else f0 (i+$1) a\n in f0 1 []\nlet n = get_i64 0\nlet a = input_i64_array n\nlet dp = make 1000007 0L\nlet (++) u v = (u+v) mod 1000000007L\nlet () =\n iter (fun v ->\n i32 v\n |> divisors\n |> List.sort (fun u v -> compare v u)\n |> List.iter (fun d ->\n if d=1 then dp.(1) <- dp.(1) ++ 1L\n else dp.(d) <- dp.(d) ++ dp.(d-$1)\n )\n ) a;\n printf \"%Ld\\n\" @@ fold_left (++) 0L dp\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "587ac3b470aaacaa024a0c6dde134b7c"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet n = scan_int ();;\nlet a = Array.make n 0;;\nfor i = 0 to (n - 1) do\n a.(i) <- (scan_int ());\ndone\n\nlet k = ref 0;;\nfor i = 1 to (n - 2) do\n if a.(i - 1) = 1 && a.(i) = 0 && a.(i + 1) = 1 then\n begin\n a.(i + 1) <- 0;\n incr k;\n end;\ndone;;\nprint_int !k;;\nprint_endline \"\";;", "positive_code": [{"source_code": "(* Problem 2 of round 521*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n - 1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\n(*test\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\" ) a\n*)\nlet () = \n let t = ref 0 in\n for i = 1 to n-2 do\n if a.(i)==0 then\n begin\n if a.(i-1)==1 && a.(i+1)==1 then\n begin\n a.(i+1) <- 0;\n incr t\n end\n end\n done;\n print_int !t; print_endline \"\"\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 () =\n let n = get_i64 0 in\n let a = input_i64_array n in\n let r = ref 0L in\n rep 1L (n-2L) (fun i ->\n let i = i32 i in\n if a.(i-$1)=1L && a.(i)=0L && a.(i+$1)=1L then (\n r += 1L;\n a.(i+$1) <- 0L;\n )\n );\n printf \"%Ld\\n\" !r\n\n\n\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "ea62b6f68d25fb17aba8932af8377db0"} {"source_code": "let is_right_neighbor a b = (fst a) > (fst b) && (snd a) = (snd b)\nlet is_left_neighbor a b = (fst a) < (fst b) && (snd a) = (snd b)\nlet is_lower_neighbor a b = (fst a) = (fst b) && (snd a) < (snd b)\nlet is_upper_neighbor a b = (fst a) = (fst b) && (snd a) > (snd b)\n\nlet is_supercentral_point p points =\n List.exists (is_right_neighbor p) points &&\n List.exists (is_left_neighbor p) points &&\n List.exists (is_lower_neighbor p) points &&\n List.exists (is_upper_neighbor p) points\n\nlet solve points =\n let count accum p =\n if is_supercentral_point p points then accum+1\n else accum\n in\n List.fold_left count 0 points\n\nlet rec read_n_tuples n lst =\n if n = 0 then lst\n else read_n_tuples (n-1) ((Scanf.scanf \" %d %d\" (fun x y -> (x, y))) :: lst)\n \nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let points = read_n_tuples n [] in\n Printf.printf \"%d\\n\" (solve points)\n \n", "positive_code": [{"source_code": "let _ =\n let main () =\n let n = read_int () in\n let arr = Array.init n (fun i -> Scanf.sscanf (read_line ()) \"%d %d\" (fun x y -> x, y)) in\n let bits = Array.create n 0 in\n Array.iteri (fun i (x, y) ->\n Array.iteri (fun j (a, b) ->\n if a > x && y = b then bits.(j) <- bits.(j) lor 1; \n if a < x && y = b then bits.(j) <- bits.(j) lor 2; \n if a = x && y < b then bits.(j) <- bits.(j) lor 4; \n if a = x && y > b then bits.(j) <- bits.(j) lor 8; \n ) arr\n ) arr;\n Printf.printf \"%d\\n\" (Array.fold_left (fun acc k -> acc + k / 15) 0 bits)\n in\n main ()\n"}, {"source_code": "open Array;;\n(* Common part*)\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\n(* Programme *)\nlet f x y = match x, y with (x,y,_), (x1,y1,_) -> if x=x1 then y-y1 else x-x1\nlet f1 x y = match x, y with (x,y,_), (x1,y1,_) -> if y=y1 then x-x1 else y-y1\n\nlet y arr n i = if i>=n then function _-> ()\n else function (x,y,z) ->\n match arr.(i+1)\n with (x1,y1,z1) when x1=x -> arr.(i)<-(x,y,z+1); arr.(i+1) <- (x1,y1,z1+1)\n | _ -> ()\n\nlet y1 arr n i = if i>=n then function _-> ()\n else function (x,y,z) ->\n match arr.(i+1)\n with (x1,y1,z1) when y=y1 -> arr.(i)<-(x,y,z+1); arr.(i+1) <- (x1,y1,z1+1)\n | _ -> ()\n\nlet main () =\n let n = readIntLn () in\n let arr = init n (function _ -> let a= readInStr () in (a, readIntLn (), 0) ) in\n fast_sort f arr;\n iteri (n-1|>y arr) arr;\n fast_sort f1 arr;\n iteri (n-1|>y1 arr) arr;\n fold_left (fun acc-> function (_,_,z) -> if z = 4 then (acc+1) else acc ) 0 arr |> print_int;\n ;;\nmain()"}], "negative_code": [{"source_code": "open Array;;\n(* Common part*)\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\n(* Programme *)\nlet f x y = match x, y with (x,y,z), (x1,y1,z1) -> if x=x1 then y-y1 else x-x1\n\nlet y arr n i = if i>=n then function _-> ()\n else function (x,y,z) ->\n match arr.(i+1)\n with (x1,y1,z1) when x1=x -> arr.(i)<-(x,y,z+1); arr.(i+1) <- (x1,y1,z1+1)\n | _ -> ()\n\nlet main () =\n let n = readIntLn () in\n let arr = init n (function _ -> let a= readInStr () in (a, readIntLn (), 0) ) in\n fast_sort f arr;\n iteri (n-1|>y arr) arr;\n fast_sort (flip f) arr;\n iteri (n-1|>y arr) arr;\n fold_left (fun acc-> function (_,_,z) -> if z = 4 then (acc+1) else acc ) 0 arr |> print_int;\n ;;\nmain()\n"}], "src_uid": "594e64eef7acd055d59f37710edda201"} {"source_code": "open Str;;\nopen Array;;\nopen String;;\n\nlet split sep =\n\tlet re = Str.regexp sep in\n\tStr.split re\n;;\n\nlet rec range a b =\n\tif a = b then [] else a :: range (a+1) b\n;;\n\nlet (!!) ls n =\n\tList.nth ls n\n;;\n\nlet main =\n\tlet len = read_int()\n\tand nums = Array.map float_of_string (Array.of_list (split \" \" (read_line()))) in\n\tlet sum = Array.fold_left (+.) 0. nums in\n\tlet ln = ref 0 in\n\tlet indexes = Array.mapi (fun i x ->\n\t\tif (sum -. x) /. (float_of_int (len-1)) = x then begin\n\t\t\tincr ln;\n\t\t\ti + 1\n\t\tend else\n\t\t\t0\n\t) nums in\n\tlet _ = print_int (!ln) in\n\tlet _ = print_string \"\\n\" in\n\tArray.iter (fun i ->\n\t\tif i > 0 then\n\t\t\tlet _ = print_int i in\n\t\t\tprint_string \" \"\n\t) indexes\n;;\n", "positive_code": [{"source_code": "let rec input_seq n lst =\n if n <= 1 then (Scanf.scanf \"%d\\n\" (fun x -> x)) :: lst\n else input_seq (n - 1) ((Scanf.scanf \"%d \" (fun x -> x)) :: lst)\n\nlet input_seq n = List.rev (input_seq n [])\n \nlet solve n =\n let seq = input_seq n in\n let sum = List.fold_left (+) 0 seq in\n let rec loop lst accm cnt = match lst with \n | [] -> accm\n | first :: rest\n\t-> if first * n == sum then loop rest (cnt::accm) (cnt+1)\n\t else loop rest accm (cnt+1)\n in\n loop seq [] 1\n\nlet rec print_int_list = function\n | [] -> Printf.printf \"\\n\"\n | lst :: [] -> Printf.printf \"%d\\n\" lst\n | first :: rest ->\n begin\n Printf.printf \"%d \" first;\n print_int_list rest\n end\n \nlet _ =\n let ans = Scanf.scanf \"%d\\n\" solve in\n Printf.printf \"%d\\n\" (List.length ans);\n if List.length ans != 0 then print_int_list (List.rev ans)\n \n"}], "negative_code": [{"source_code": "open Str;;\nopen Array;;\nopen String;;\n\nlet split sep =\n\tlet re = Str.regexp sep in\n\tStr.split re\n;;\n\nlet rec range a b =\n\tif a = b then [] else a :: range (a+1) b\n;;\n\nlet (!!) ls n =\n\tList.nth ls n\n;;\n\nlet main =\n\tlet len = read_int()\n\tand nums = Array.map float_of_string (Array.of_list (split \" \" (read_line()))) in\n\tlet sum = Array.fold_left (+.) 0. nums in\n\tlet indexes = List.filter (fun i ->\n\t\t(sum -. nums.(i)) /. (float_of_int (len-1)) = nums.(i)\n\t) (range 0 len) in\n\tlet _ = print_int (List.length indexes) in\n\tlet _ = print_string \"\\n\" in\n\tprint_string (String.concat \" \" (List.map (fun x ->string_of_int (x+1)) indexes))\n;;\n"}, {"source_code": "open Str;;\nopen List;;\n\nlet split sep =\n\tlet re = Str.regexp sep in\n\tStr.split re\n;;\n\nlet rec range a b =\n\tif a = b then [] else a :: range (a+1) b\n;;\n\nlet (!!) ls n =\n\tList.nth ls n\n;;\n\nlet main =\n\tlet len = read_int()\n\tand nums = List.map float_of_string (split \" \" (read_line())) in\n\tlet sum = List.fold_left (+.) 0. nums in\n\tlet avg = sum /. (float_of_int len) in\n\tlet indexes = List.filter (fun i ->\n\t\t(sum -. (List.nth nums i)) /. (float_of_int (len-1)) = List.nth nums i\n\t) (range 0 len) in\n\tlet _ = print_int (List.length indexes) in\n\tlet _ = print_string \"\\n\" in\n\tList.iter (fun i -> print_int (i+1); print_string \" \") indexes\n;;\n"}, {"source_code": "open Str;;\nopen List;;\n\nlet split sep =\n\tlet re = Str.regexp sep in\n\tStr.split re\n;;\n\nlet rec range a b =\n\tif a = b then [] else a :: range (a+1) b\n;;\n\nlet (!!) ls n =\n\tList.nth ls n\n;;\n\nlet main =\n\tlet len = read_int()\n\tand nums = List.map int_of_string (split \" \" (read_line())) in\n\tlet sum = List.fold_left (+) 0 nums in\n\tlet avg = sum / len in\n\tlet indexes = List.filter (fun i ->\n\t\tavg = List.nth nums i\n\t) (range 0 len) in\n\tlet _ = print_int (List.length indexes) in\n\tlet _ = print_string \"\\n\" in\n\tList.iter (fun i -> print_int (i+1); print_string \" \") indexes\n;;\n"}, {"source_code": "open Str;;\nopen List;;\nopen String;;\n\nlet split sep =\n\tlet re = Str.regexp sep in\n\tStr.split re\n;;\n\nlet rec range a b =\n\tif a = b then [] else a :: range (a+1) b\n;;\n\nlet (!!) ls n =\n\tList.nth ls n\n;;\n\nlet main =\n\tlet len = read_int()\n\tand nums = List.map float_of_string (split \" \" (read_line())) in\n\tlet sum = List.fold_left (+.) 0. nums in\n\tlet avg = sum /. (float_of_int len) in\n\tlet indexes = List.filter (fun i ->\n\t\t(sum -. (List.nth nums i)) /. (float_of_int (len-1)) = List.nth nums i\n\t) (range 0 len) in\n\tlet _ = print_int (List.length indexes) in\n\tlet _ = print_string \"\\n\" in\n\tprint_string (String.concat \" \" (List.map (fun x ->string_of_int (x+1)) indexes))\n;;\n"}, {"source_code": "let rec input_seq n lst =\n if n <= 1 then (Scanf.scanf \"%d\\n\" (fun x -> x)) :: lst\n else input_seq (n - 1) ((Scanf.scanf \"%d \" (fun x -> x)) :: lst)\n\nlet input_seq n = List.rev (input_seq n [])\n \nlet solve n =\n let seq = input_seq n in\n let sum = List.fold_left (+) 0 seq in\n let rec loop lst accm cnt = match lst with \n | [] -> accm\n | first :: rest\n\t-> if (sum-first) / (n - 1) == first then loop rest (cnt::accm) (cnt+1)\n\t else loop rest accm (cnt+1)\n in\n loop seq [] 1\n\nlet rec print_int_list = function\n | [] -> Printf.printf \"\\n\"\n | lst :: [] -> Printf.printf \"%d\\n\" lst\n | first :: rest ->\n begin\n Printf.printf \"%d \" first;\n print_int_list rest\n end\n \nlet _ =\n let ans = Scanf.scanf \"%d\\n\" solve in\n Printf.printf \"%d\\n\" (List.length ans);\n if List.length ans != 0 then print_int_list (List.rev ans)\n \n"}, {"source_code": "let rec input_seq n lst =\n if n <= 1 then (Scanf.scanf \"%d\\n\" (fun x -> x)) :: lst\n else input_seq (n - 1) ((Scanf.scanf \"%d \" (fun x -> x)) :: lst)\n\nlet input_seq n = List.rev (input_seq n [])\n \nlet solve n =\n let seq = input_seq n in\n let sum = List.fold_left (+) 0 seq in\n let rec loop lst accm cnt = match lst with \n | [] -> accm\n | first :: rest\n\t-> if (sum-first) / (n - 1) == first then loop rest (cnt::accm) (cnt+1)\n\t else loop rest accm (cnt+1)\n in\n loop seq [] 1\n\nlet rec print_int_list = function\n | [] -> Printf.printf \"\\n\"\n | lst :: [] -> Printf.printf \"%d\\n\" lst\n | first :: rest ->\n begin\n Printf.printf \"%d \" first;\n print_int_list rest\n end\n \nlet _ =\n let ans = Scanf.scanf \"%d\\n\" solve in\n Printf.printf \"%d\\n\" (List.length ans);\n print_int_list (List.rev ans)\n \n"}], "src_uid": "1a22bc82ddf6b3dfbf270bc5e3294c28"} {"source_code": "let n = int_of_string (input_line stdin) ;;\n\nlet sum a b c = a + b + c ;;\n\nlet rec solve i count =\n if i == 0 then count\n else let input = Scanf.bscanf Scanf.Scanning.stdin \"%d %d %d\\n\" sum in\n if input > 1 then solve (i - 1) (count + 1)\n else solve (i - 1) count ;;\n\nPrintf.printf \"%d\\n\" (solve n 0) ;;", "positive_code": [{"source_code": "let number_of_problems = Scanf.scanf \"%d \" (fun n -> n)\n\nlet if_certain d = match d with\n |0 -> false\n |_-> true\n\nlet remove_uncertainity l = List.filter(if_certain) l\n\nlet rec getting_statuses n k = \n if n > 0\n then\n let status = Scanf.scanf \"%d %d %d \" (fun s0 s1 s2 -> [s0; s1; s2]) in\n if (List.length (remove_uncertainity status)) >= 2\n then \n getting_statuses(n - 1) (k + 1)\n else\n getting_statuses(n - 1) k\n else\n Printf.printf (\"%d\\n\") k\n\nlet () = getting_statuses number_of_problems 0"}, {"source_code": "let input () = let number_of_problems = Scanf.scanf \"%d \" (fun n -> n) in\n let rec getting_statuses n = \n if n > 0\n then\n let status = Scanf.scanf \"%d %d %d \" (fun s0 s1 s2 -> [s0; s1; s2]) in\n let rest = getting_statuses (n - 1) in\n (status :: rest)\n else\n []\n in getting_statuses number_of_problems\n\nlet if_certain d = match d with\n |0 -> false\n |_-> true\n\nlet count f l = List.length (List.filter f l)\n\nlet solve : int list list -> int = count (fun l -> count if_certain l >= 2)\n\nlet print k = Printf.printf \"%d\\n\" k\n\nlet () = print (solve (input ()))\n"}, {"source_code": "let rec loop n = \n if n == 0 then\n 0\n else\n let score = Scanf.scanf \"%d %d %d\\n\" (fun x y z -> if x+y+z >= 2 then 1 else 0) in\n score + loop (n-1);;\n\nlet _ =\n let n = read_int() in\n print_int(loop n) in\n print_newline()\n"}, {"source_code": "let n=Scanf.scanf \"%d\" (fun a->a);;\nlet ans= ref 0;;\nfor i=1 to n do\n ans:=!ans+(Scanf.scanf \" %d %d %d\" (fun a b c->if a+b+c>=2 then 1 else 0)) \ndone;;\nprint_int(!ans)\n"}, {"source_code": "let n=Scanf.scanf \"%d\" (fun a->a);;\nlet ans= ref 0;;\nfor i=1 to n do\n let (a,b,c)=(Scanf.scanf \" %d %d %d\" (fun a b c->(a,b,c))) in\n if a+b+c>=2 then ans:=!ans+1\ndone;;\nprint_int(!ans)\n"}, {"source_code": "\nlet check lst = 2 <= List.fold_left (+) 0 lst\n;;\n\nlet solve llst = List.length (List.filter check llst)\n;;\n\nlet make_nums n =\n let arr = Array.init n (fun _ -> Scanf.scanf \"%d %d %d \"\n (fun n m k -> [n; m; k;]))\n in\n Array.to_list arr\n;;\n\nlet () =\n let nums = Scanf.scanf \"%d \"\n (fun n -> make_nums n)\n in\n Printf.printf \"%d\\n\" (solve nums)\n;;\n \n"}, {"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\nlet a = Array.init n (fun i -> (read_int3 () ));;\n\nlet vote = function\n | (0,0,0) -> 0\n | (1,0,0) -> 0\n | (0,1,0) -> 0\n | (0,0,1) -> 0\n | (_,_,_) -> 1\n;;\n\nlet b = Array.map (fun x -> vote x) a\n |> Array.fold_left (+) 0\n in print_int b; print_endline \"\"\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve n =\n let rec check_opinions acc = function\n | 0 -> acc\n | n -> let o1 = read_int ()\n and o2 = read_int ()\n and o3 = read_int () in\n if o1 + o2 + o3 > 1\n then check_opinions (acc + 1) (n - 1)\n else check_opinions acc (n - 1)\n in check_opinions 0 n\n\nlet () =\n let n = read_int () in\n Printf.printf \"%d\\n\" (solve n)\n"}, {"source_code": "open Scanf\n\nlet rec solve n =\n if n = 0 then 0\n else\n begin\n scanf \"%d %d %d\\n\" (fun x y z ->\n\tlet rest = solve (n - 1) in\n\tif (x = 0 && y = 0 || x = 0 && z = 0 || y = 0 && z = 0) then rest\n\telse 1 + rest)\n end\n \nlet _ =\n Printf.printf \"%d\\n\" (scanf \"%d\\n\" solve)\n"}, {"source_code": "let read_one () = Scanf.scanf \" %d\" (fun x -> x)\nlet read_two () = Scanf.scanf \" %d %d\" (fun x y -> (x,y)) \nlet read_three () = Scanf.scanf \" %d %d %d\" (fun x y z -> (x,y,z))\n\nlet read_many n =\n let rec helper i acc =\n if i >= n then List.rev acc\n else Scanf.scanf \" %d\" (fun n -> helper (i+1) (n::acc)) in\n helper 0 []\n\nlet list_iteri f lst = List.fold_left (fun j b -> f j b; j+1) 0 lst\n\nlet main =\n let t = Scanf.scanf \"%d\" (fun t -> t) in\n let sum = ref 0 in\n for case = 1 to t do\n let (a,b,c) = read_three() in\n sum := !sum + if a+b+c >= 2 then 1 else 0;\n done;\n Printf.printf \"%d\\n\" !sum\n"}, {"source_code": "let pf = Printf.printf;;\nlet sf = Scanf.scanf;;\n\nlet (|>) x f = f x;;\nlet (@@) f x = f x;;\nlet read0() = sf \"%d \" (fun x -> x)\nlet read1() = sf \"%d\\n\" (fun x -> x)\nlet read2() = sf \"%d %d\\n\" (fun x y -> x, y)\nlet read3() = sf \"%d %d %d\\n\" (fun x y z -> x, y, z)\n\nexception Error of string\n\nlet inf = 1000000000;;\nlet eps = 1e-11;;\n\nlet _ =\n let n = read1() in\n let res = ref 0 in\n for i = 1 to n do\n let (x, y, z) = read3() in\n if x + y + z >= 2 then res := !res + 1\n done;\n pf \"%d\\n\" !res\n;;\n"}, {"source_code": "let read_int () = \n Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x)\n\nlet rec solve n = \n if n == 0 then 0\n else if read_int () + read_int () + read_int () > 1 then 1 + solve (n - 1)\n else 0 + solve (n - 1)\n \nlet () =\n Printf.printf \"%d\" (solve (read_int ()))\n"}, {"source_code": "open Printf\n\nlet read_ints() =\n\tArray.map (int_of_string) (Array.of_list (Str.split (Str.regexp \" +\") (read_line())))\n\nlet sum xs = Array.fold_left (+) 0 xs\n\n\nlet main = \n let n = read_int() in\n let answer = ref 0 in\n for i = 1 to n do\n let xs = read_ints() in\n if (sum xs) >= 2 then\n answer := !answer + 1;\n done;\n printf \"%d\\n\" !answer;;\n"}, {"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\n\nlet rec loop n a =\n if n <= 0 then a\n else\n let (x,y,z) = read3() in\n loop (n-1) ( if x+y+z >= 2 then (a+1) else a );;\n\nlet _ = \n let n = read1() in\n Printf.printf \"%d\\n\" ( loop n 0 );;\n\n"}], "negative_code": [{"source_code": "let number_of_problems = Scanf.scanf \"%d \" (fun n -> n)\n\nlet if_certain d = match d with\n |0 -> false\n |_-> true\n\nlet remove_uncertainity l = List.filter(if_certain) l\n\nlet rec getting_statuses n k = \n if n > 0\n then\n let status = Scanf.scanf \"%d %d %d \" (fun s0 s1 s2 -> [s0; s1; s2]) in\n if (List.length (remove_uncertainity status)) >= 2\n then \n getting_statuses(n - 1) (k + 1)\n else\n ()\n else\n Printf.printf (\"%d\\n\") k\n\nlet () = getting_statuses number_of_problems 0"}, {"source_code": "open Scanf\n\nlet rec solve n =\n if n = 0 then 0\n else\n begin\n scanf \"%d %d %d\\n\" (fun x y z ->\n\tlet rest = solve (n - 1) in\n\tif x = 0 && y = 0 && z = 0 then rest\n\telse 1 + rest)\n end\n \nlet _ =\n Printf.printf \"%d\\n\" (scanf \"%d\\n\" solve)\n"}, {"source_code": "let read_int = \n Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x)\n\nlet rec solve n = \n if n == 0 then 0\n else if read_int + read_int + read_int > 1 then 1 + solve (n - 1)\n else 0 + solve (n - 1)\n \nlet () =\n Printf.printf \"%d\" (solve read_int)\n"}], "src_uid": "3542adc74a41ccfd72008faf983ffab5"} {"source_code": "let input () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet print_looper n a = \n let rec loop i =\n if i < n\n then\n (Printf.printf \"%d \" a;\n loop (i + 1))\n else\n ()\n in loop 0\n\nlet wrapper (n, a, b) =\n Printf.printf \"%d\\n\" n;\n print_looper a 2;\n print_looper b 3;\n Printf.printf \"\\n\"\n\nlet solve n = \n let total = n / 2 in\n let modulo = n mod 2 in\n if modulo = 1\n then\n (total, total - 1, 1)\n else\n (total, total, 0)\n\nlet () = wrapper (solve (input ()))", "positive_code": [{"source_code": "let main () =\n let n = read_int () in\n let k = n / 2 in\n print_int k; print_newline ();\n for i = 1 to k-1 do\n print_string \"2 \"\n done;\n print_int (n - 2 * (k-1))\n\n\nlet () = main ()\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec print2 k = if k = 0 then () else let () = print2(k-1) in printf \"%d \" 2\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x) in\nlet () = \n let n = read_int() in\n let () = printf \"%d\\n\" (n/2) in\n if n mod 2 = 0 then \n print2 (n/2)\n else let () = print2 (n/2-1) in printf \"%d\" 3 in\n()"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\n\n(* int -> int list\n create_range(n) = [2,..., k-1] len = k-2\n *)\nlet rec create_range k = if k <= 2 then [] else\n List.append (create_range (k-1)) [k-1] in\n\n(* int -> bool\n true iff n is a prime\n *)\nlet isPrime n = if n < 2 then false else \n if n == 2 then true else\n let divisible k = if (n mod k) = 0 then true else false in\n let range = create_range n in\n not (List.exists divisible range) in\n\n(* int -> int list\n length(res) = n-1 and res[i] = answer for i+2 *)\n\nlet rec produce_table n range primes = if n = 2 then [1] else \n let res_table = produce_table (n-1) primes range in\n let fold_help prime res = if n-prime < 2 then res else\n let index = n-prime-2 in \n let pot = List.nth res_table index in \n if pot > res then pot else res in\n let new_val = 1 + List.fold_right fold_help primes 0 in\n List.append res_table [new_val] in\n\n(* int -> int list\n returns a list of primes\n *)\n\nlet rec produce_primes n res_table range primes = if n = 2 then [2] else\n let help a = let fst = List.nth res_table (a-2) in\n let snd = List.nth res_table (n-2) in\n if snd = fst + 1 then true else false in\n let fold_help a b = if n-a > 2 && help (n-a) then \n [a] else b in\n let index = List.fold_right fold_help primes [] in\n match index with\n [prime] -> prime::(produce_primes (n-prime) res_table range primes)\n | _ -> [n] in\n\n\n\n(* processing input *)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x) in\nlet () = \n let n = read_int() in\n let range = create_range(n) in\n let primes = List.filter isPrime range in\n let res_table = produce_table n range primes in\n let answer = produce_primes n res_table range primes in\n let len = List.length answer in\n let () = printf \"%d\\n\" len in\n let helpero a = printf \"%d \" a in\n List.iter helpero answer in\n()\n\n"}], "src_uid": "98fd00d3c83d4b3f0511d8afa6fdb27b"} {"source_code": "let (+) = Int64.add\nlet (--) = Int64.sub\nlet (/) = Int64.div\nlet ( * ) = Int64.mul\n\nlet () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let a = Array.make n Int64.zero in\n let res = ref Int64.zero in\n let ones = ref Int64.zero in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%Ld \" (fun x -> x) in\n let m2 = m / 2L in\n let x = min (m / 2L) !ones in\n res := !res + x;\n ones := !ones -- x;\n let m = m -- x * 2L in\n a.(i) <- m;\n let m3 = m / 3L in\n res := !res + m3;\n ones := !ones + m -- m3 * 3L;\n done;\n Printf.printf \"%Ld\" !res\n;;\n", "positive_code": [{"source_code": "let (+) = Int64.add\nlet (--) = Int64.sub\nlet (/) = Int64.div\nlet ( * ) = Int64.mul\n\nlet () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let a = Array.make n Int64.zero in\n let res = ref Int64.zero in\n let ones = ref Int64.zero in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%Ld \" (fun x -> x) in\n let m2 = m / (Int64.of_int 2) in\n let x = min (m / (Int64.of_int 2)) !ones in\n res := !res + x;\n ones := !ones -- x;\n let m = m -- x * Int64.of_int 2 in\n a.(i) <- m;\n let m3 = m / (Int64.of_int 3) in\n res := !res + m3;\n ones := !ones + m -- m3 * (Int64.of_int 3);\n done;\n Printf.printf \"%Ld\" !res\n;;\n"}], "negative_code": [{"source_code": "let () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let a = Array.make n 0 in\n let res = ref 0 in\n let ones = ref 0 in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%d \" (fun x -> x) in\n let m2 = m / 2 in\n let x = min (m / 2) !ones in\n res := !res + x;\n ones := !ones - x;\n let m = m - x * 2 in\n let m3 = m / 3 in\n res := !res + m3;\n ones := !ones + m - m3 * 3;\n done;\n Printf.printf \"%d\" !res\n;;\n"}, {"source_code": "let () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let res = ref 0 in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%d \" (fun x -> x/3) in\n res := !res + m\n done;\n Printf.printf \"%d\" !res\n;;\n"}, {"source_code": "let () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let a = Array.make n 0 in\n let res = ref 0 in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%d \" (fun x -> x) in\n let m3 = m / 3 in\n res := !res + m3;\n a.(i) <- m - m3 * 3;\n done;\n let ones = ref 0 in\n Array.iter (function\n | 2 when !ones > 0 -> decr ones; incr res;\n | 2 -> incr ones; incr ones;\n | 1 -> incr ones;\n | _ -> ()\n ) a;\n Printf.printf \"%d\" !res\n;;\n"}, {"source_code": "let () =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let a = Array.make n 0 in\n let res = ref 0 in\n for i = 0 to n-1 do\n let m = Scanf.scanf \"%d \" (fun x -> x) in\n let m3 = m / 3 in\n res := !res + m3;\n a.(i) <- m - m3;\n done;\n let ones = ref 0 in\n Array.iter (function\n | 2 when !ones > 0 -> decr ones; incr res;\n | 2 -> incr ones; incr ones;\n | 1 -> incr ones;\n | _ -> ()\n ) a;\n Printf.printf \"%d\" !res\n;;\n"}], "src_uid": "a8f3e94845cb15a483ce8f774779efac"} {"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\nmodule IMap = Map.Make (Int64)\nlet count a = (* (value,count) *)\n Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a\nlet () =\n let n = get_i64 0 in\n let a = input_i64_array n in\n let mp = count a in\n let sum = fold_left (+) 0L a in\n let ans = ref [] in\n iteri (fun i v ->\n let rest = sum - v in\n if rest mod 2L = 0L then\n try\n let c = IMap.find (rest/2L) mp in\n if v = rest/2L then (\n if c >= 2L then ans := (i+$1) :: !ans\n ) else if c >= 1L then ans := (i+$1) :: !ans\n with Not_found -> ()\n ) a;\n printf \"%Ld\\n\" @@ llen !ans;\n print_list string_of_int !ans\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "(* Problem 2 of round 521*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nopen Num;;\nlet n1 = num_of_int 1;;\n\nlet total = ref (num_of_int 0)\nlet () =\n Array.iter (fun x-> H.add t (num_of_int x) (num_of_int 0)) a;\n Array.iter (fun x-> H.replace t (num_of_int x) (n1+/(H.find t (num_of_int x)))) a;\n Array.iter (fun x -> total := !total +/ (num_of_int x)) a;;\n\n(*\nprint_int !total; print_endline \"\"\nlet () =\n H.iter (fun k v -> Printf.printf \"%d %d\\n\" k v) t\n*)\n\nlet my_find x =\n try H.find t x\n with Not_found -> num_of_int 0\n\nlet n0 = num_of_int 0;;\n\nlet is_good x =\n let r = !total -/ x in\n let m = int_of_num (mod_num r (num_of_int 2)) in\n match m with\n 1 -> false\n | _ -> begin\n let r1 = r // (num_of_int 2) in\n let rslt = int_of_num (my_find r1) in\n match rslt with\n 0 -> false\n | 1 -> begin\n if eq_num r1 x then\n false\n else\n true\n end\n | _ -> true\n end\n\nlet s = H.create n;;\n\nlet () =\n Array.iteri (fun i x -> if (is_good (num_of_int x)) then\n begin H.add s (num_of_int (i + 1) ) n0 end\n ) a\n;;\n\n\nlet () = \n print_int (H.length s); print_endline \"\";\n H.iter (fun k v -> Printf.printf \"%d \" (int_of_num k)) s\n"}], "negative_code": [{"source_code": "(* Problem 2 of round 521*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nopen Num;;\nlet n1 = num_of_int 1;;\n\nlet total = ref (num_of_int 0)\nlet () =\n Array.iter (fun x-> H.add t (num_of_int x) (num_of_int 0)) a;\n Array.iter (fun x-> H.replace t (num_of_int x) (n1+/(H.find t (num_of_int x)))) a;\n Array.iter (fun x -> total := !total +/ (num_of_int x)) a;;\n\n(*\nprint_int !total; print_endline \"\"\nlet () =\n H.iter (fun k v -> Printf.printf \"%d %d\\n\" k v) t\n*)\n\nlet my_find x =\n try H.find t x\n with Not_found -> num_of_int 0\n\nlet n0 = num_of_int 0;;\n\nlet is_good x =\n let r = !total -/ x in\n let m = int_of_num (mod_num r (num_of_int 2)) in\n match m with\n 1 -> false\n | _ -> begin\n let r1 = r // (num_of_int 2) in\n let rslt = int_of_num (my_find r1) in\n match rslt with\n 0 -> false\n | 1 -> begin\n if r1 == x then\n false\n else\n true\n end\n | _ -> true\n end\n\nlet s = H.create n;;\n\nlet () =\n Array.iteri (fun i x -> if (is_good (num_of_int x)) then\n begin H.add s (num_of_int (i + 1) ) n0 end\n ) a\n;;\n\n\nlet () = \n print_int (H.length s); print_endline \"\";\n H.iter (fun k v -> Printf.printf \"%d \" (int_of_num k)) s\n"}, {"source_code": "(* Problem 2 of round 521*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet total = ref 0\nlet () =\n Array.iter (fun x-> H.add t x 0) a;\n Array.iter (fun x-> H.replace t x (1+(H.find t x))) a;\n Array.iter (fun x -> total := !total + x) a;;\n\n(*\nprint_int !total; print_endline \"\"\nlet () =\n H.iter (fun k v -> Printf.printf \"%d %d\\n\" k v) t\n*)\n\nlet my_find x =\n try H.find t x\n with Not_found -> 0\n\nlet is_good x =\n let r = !total -x in\n match r mod 2 with\n 1 -> false\n | _ -> begin\n let r1 = r / 2 in\n let rslt = my_find r1 in\n match rslt with\n 0 -> false\n | 1 -> begin\n if r1 == x then\n false\n else\n true\n end\n | _ -> true\n end\n\nlet s = H.create n;;\n\nlet () =\n Array.iteri (fun i x -> if (is_good x) then\n begin H.add s (i+1) 0 end\n ) a\n;;\n\nlet () = \n print_int (H.length s); print_endline \"\";\n H.iter (fun k v -> Printf.printf \"%d \" k) s\n"}, {"source_code": "(* Problem 2 of round 521*)\nopen Scanf;;\nopen String;;\nopen Num;;\n\n(*These are some utility functions*)\nmodule U = struct\n let mprint z =\n print_endline (Num.string_of_num z);;\n\n let read_one format =\n let n = Scanf.scanf format (fun x -> x) in\n n;;\n\n let read_one_number () =\n let n = read_one \"%d \" in\n n\n\n let read_array n a =\n for i = 0 to n-1 do\n let n = read_one_number () in\n a.(i) <- n\n done\n\nend\n\n(*The solutions*)\n\nlet n = U.read_one_number ()\nlet a = Array.make n 0\nlet () = U.read_array n a\n\nmodule H = Hashtbl\nlet t = H.create n\n\n(*\nlet () =\n Array.iter (fun x-> print_int x; print_endline \"\") a\n*)\n\nlet total = ref 0\nlet () =\n Array.iter (fun x-> H.add t x 0) a;\n Array.iter (fun x-> H.replace t x (1+(H.find t x))) a;\n Array.iter (fun x -> total := !total + x) a;;\n\n(*\nprint_int !total; print_endline \"\"\nlet () =\n H.iter (fun k v -> Printf.printf \"%d %d\\n\" k v) t\n*)\n\nlet my_find x =\n try H.find t x\n with Not_found -> 0\n\nlet is_good x =\n let r = !total -x in\n match r mod 2 with\n 1 -> false\n | _ -> begin\n let r1 = r / 2 in\n let rslt = my_find r1 in\n match rslt with\n 0 -> false\n | 1 -> begin\n if r1 == x then\n false\n else\n true\n end\n | _ -> true\n end\n\nlet s = H.create n;;\n\nlet () =\n Array.iteri (fun i x -> if (is_good x) then\n begin H.add s (i+1) 0 end\n ) a\n;;\n\n\nlet () = \n print_int (H.length s); print_endline \"\";\n H.iter (fun k v -> Printf.printf \"%d \" k) s\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\nmodule CumulSumArray = struct\n let make a =\n let ln = Array.length a\n in let a1 = Array.make (ln+$1) 0L in for i=1 to ln do a1.(i) <- a1.(i-$1) + a.(i-$1) done; a1\n let sum l r a = (* 0-origin,closed *)\n if l>r then 0L else (a.(r+$1) - a.(l))\n let sum_1orig l r a = sum (l-$1) (r-$1) a\nend\nlet () =\n let n = get_i64 0 in\n let a = input_i64_array n in\n let b = init (i32 n) (fun i -> a.(i)) in\n sort compare b;\n (* let c = CumulSumArray.make a in *)\n let s = fold_left (+) 0L a in\n let r = ref [] in\n repi 0 (i32 n-$1) (fun i ->\n (* let rest = CumulSumArray.sum i 0 in *)\n let rest = s - a.(i) in\n let j = lower_bound b (rest/2L) in\n (* printf \"%Ld, %Ld\\n\" rest j; *)\n if 0L<=j && j x)\n\nlet () =\n let n = read_int () and k = read_int () in\n let a = Array.init n read_int\n and h = Array.make 200001 0\n and min_elem = ref 200001\n and max_elem = ref 0\n and cnt = ref 0\n and cur = ref 0\n and ans = ref 0 in\n Array.iter (fun x ->\n min_elem := min !min_elem x;\n max_elem := max !max_elem x;\n h.(x) <- h.(x) + 1\n ) a;\n for i = !max_elem downto !min_elem + 1 do\n cnt := !cnt + h.(i);\n cur := !cur + !cnt;\n if !cur > k then begin\n incr ans;\n cur := !cnt\n end\n done;\n if max_elem <> min_elem then incr ans;\n printf \"%d\\n\" !ans", "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\nmodule Imos = struct\n\tlet make n = Array.make (i32 n +$ 2) 0L\n\tlet add_destructive_closed l r a =\n\t\ta.(l+$1) <- a.(l+$1) + 1L;\n\t\ta.(r+$2) <- a.(r+$2) - 1L\n\tlet add_destructive_1orig_closed l r a =\n\t\ta.(l) <- a.(l) + 1L;\n\t\ta.(r+$1) <- a.(r+$1) - 1L\n\tlet cumulate_destructive a = for i=1 to Array.length a -$ 2 do\n\t\ta.(i) <- a.(i) + a.(i-$1)\n\tdone\nend\n\n(* let a = Array.make 200000 0L *)\nlet a = Imos.make 2000010L\nlet () =\n\tlet n,k = get_2_i64 0 in\n\tlet mi,mx = ref Int64.max_int,ref 0L in\n\trep 1L n (fun _ ->\n\t\tlet h = get_i64 0 in\n\t\tmi := min h !mi;\n\t\tmx := max h !mx;\n\t\tImos.add_destructive_1orig_closed 1 (i32 h) a;\n\t\t`Ok\n\t);\n\tImos.cumulate_destructive a;\n\tlet i = ref !mx in\n\tlet s = ref 0L in\n\tlet c = ref 0L in\n\twhile !i > !mi do\n\t\t(* printf \"%2Ld >= %2Ld: %Ld, %Ld :: %Ld\\n\" !i !mi !s a.(i32 !i) !c; *)\n\t\ts += a.(i32 !i);\n\t\tif !s > k then (\n\t\t\tc += 1L;\n\t\t\ts := a.(i32 !i)\n\t\t);\n\t\ti -= 1L;\n\tdone;\n\tif !s > 0L then (\n\t\tc += 1L;\n\t);\n\t(* printf \"%Ld %Ld\\n\" !s !c; *)\n\t!c |> printf \"%Ld\\n\";\n\t(* printf \"[%Ld %Ld]: %Ld\\n\" !mi !mx !c; *)\n\n\n\n\n\n\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() and k = scan_int();;\nlet h = Array.make n 0 ;;\n\nfor i = 0 to n - 1 do\n h.(i) <- scan_int();\ndone;;\n\nArray.sort compare h;;\n\nlet ans = ref 0 and magazyn = ref 0;;\n\nfor i = n - 1 downto 1 do\n let lewy = h.(i - 1) in\n let linia = n - i in\n let odejm = (k - !magazyn) / linia in\n let roz = h.(i) - lewy in\n if odejm <= roz && roz <> 0 then begin\n let wys = k / linia in\n let ile = (roz - if(!magazyn > 0) then odejm else 0) / wys in\n (*print_int(i); psp(); print_int(ile); psp(); print_int(!magazyn); print_newline();*)\n ans := !ans + ile + b2i(!magazyn <> 0);\n magazyn := ((roz - odejm) mod wys) * linia;\n end\n else magazyn := !magazyn + linia * roz;\n (*print_int(!magazyn); print_newline(); *)\ndone;;\n\nprint_int (!ans + b2i(!magazyn <> 0));;\n\n(*\n3 3\n1 2 3\n*)"}], "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\nmodule Imos = struct\n\tlet make n = Array.make (i32 n +$ 2) 0L\n\tlet add_destructive_closed l r a =\n\t\ta.(l+$1) <- a.(l+$1) + 1L;\n\t\ta.(r+$2) <- a.(r+$2) - 1L\n\tlet add_destructive_1orig_closed l r a =\n\t\ta.(l) <- a.(l) + 1L;\n\t\ta.(r+$1) <- a.(r+$1) - 1L\n\tlet cumulate_destructive a = for i=1 to Array.length a -$ 2 do\n\t\ta.(i) <- a.(i) + a.(i-$1)\n\tdone\nend\n\n(* let a = Array.make 200000 0L *)\nlet a = Imos.make 2000010L\nlet () =\n\tlet n,k = get_2_i64 0 in\n\tlet mi,mx = ref Int64.max_int,ref 0L in\n\trep 1L n (fun _ ->\n\t\tlet h = get_i64 0 in\n\t\tmi := min h !mi;\n\t\tmx := max h !mx;\n\t\tImos.add_destructive_1orig_closed 1 (i32 h) a;\n\t\t`Ok\n\t);\n\tImos.cumulate_destructive a;\n\tlet i = ref !mx in\n\tlet s = ref 0L in\n\tlet c = ref 0L in\n\twhile !i >= !mi do\n\t\t(* printf \"%Ld >= %Ld: %Ld, %Ld :: %Ld\\n\" !i !mi !s a.(i32 !i) !c; *)\n\t\ts += a.(i32 !i);\n\t\tif !s > k then (\n\t\t\tc += 1L;\n\t\t\ts := a.(i32 !i)\n\t\t);\n\t\ti -= 1L;\n\tdone;\n\t!c |> printf \"%Ld\\n\";\n\t(* printf \"[%Ld %Ld]: %Ld\\n\" !mi !mx !c; *)\n\n\n\n\n\n\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() and k = scan_int();;\nlet h = Array.make n 0 ;;\n\nfor i = 0 to n - 1 do\n h.(i) <- scan_int();\ndone;;\n\nArray.sort compare h;;\n\nlet ans = ref 0 and magazyn = ref 0;;\n\nfor i = n - 1 downto 1 do\n let lewy = h.(i - 1) in\n let linia = n - i in\n let odejm = (k - !magazyn) / linia in\n let roz = h.(i) - lewy in\n if odejm <= roz && roz <> 0 then begin\n let wys = k / linia in\n let ile = (roz - odejm) / wys in\n (* print_int(ile); psp(); print_int(!magazyn); print_newline(); *)\n ans := !ans + ile + b2i(!magazyn <> 0);\n magazyn := ((roz - odejm) mod wys) * linia;\n end\n else magazyn := !magazyn + linia * roz;\n (*print_int(!magazyn); print_newline(); *)\ndone;;\n\nprint_int (!ans + b2i(!magazyn <> 0));;"}], "src_uid": "676729309dfbdf4c9d9d7c457a129608"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let rf () = float (read_int()) in\n let y1 = rf() in\n let y2 = rf() in\n let yw = rf() in\n let xb = rf() in\n let yb = rf() in\n let r = rf() in\n\n let yb' = (yw-.r) +. (yw-.r-.yb) in\n (* reflected ball y coordinate *)\n\n let sq x = x*.x in\n\n let a = xb in\n let yh = r +. y1 in\n let b = yb' -. yh in\n let c = sqrt ((sq a) +. (sq b)) in\n let h = (c/.a) *. r in\n let yt = yh +. h in\n if yt >= y2 then Printf.printf \"-1\\n\"\n else (\n (* we aim at position yh *)\n let d = xb in\n let c = yb' -. yh in\n let b = yb' -. (yw -. r) in\n let a = (d/.c) *. b in\n let xw1 = xb -. a in\n\n(*\tif yb -. r >= y1 then Printf.printf \"%.10f\\n\" xw1 *)\n\tif true then Printf.printf \"%.10f\\n\" xw1\n\telse (\n\t let c = sqrt ((sq xb) +. (sq (y1 -. yb))) in\n\t let alpha = asin (r/.c) in\n\t let beta = asin ((y1 -. yb)/.c) in\n\t let phi = alpha +. beta in\n\t let xw2 = xb -. ((yw -. r -. yb) /. (tan phi)) in\n\t if xw2 > xw1 then Printf.printf \"-1\\n\" else Printf.printf \"%.10f\\n\" xw1\n\t)\n )\n\n\n", "positive_code": [{"source_code": "(* Codeforces 248C Football Robot Electronic *)\n\nopen Big_int;;\nopen List;;\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 main () =\n\tlet y1 = grf() in\n\tlet y2 = grf() in\n\tlet yw = grf() in\n\tlet xb = grf() in\n\tlet yb = grf() in\n\tlet r = grf() in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"y1,y2,yw,xb,yb,r=\";\n \t\tprint_float y1; print_string \" \";\n \t\tprint_float y2; print_string \" \";\n \t\tprint_float yw; print_string \" \";\n \t\tprint_float xb; print_string \" \";\n \t\tprint_float yb; print_string \" \";\n \t\tprint_float r; print_string \" done print input\\n\"\n\t\tend;\n\tlet targ = (y2 +. y1) *. 0.5 in\n\tlet dy2 = yw -. r -. yb in \n\tlet dy1 = yw -. r -. r -. y1 in\n\tlet dy = dy1 +. dy2 in\n\tlet al = atan (xb /. dy) in\n\tlet xw = xb *. dy1 /. dy in \n\tlet halfg = y2 -. y1 -. r in\n\tlet rr = halfg *. (sin al) in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"targ dy2 dy1 dy al xw halfg rr =\";\n \t\tprint_float targ; print_string \" \";\n \t\tprint_float dy2; print_string \" \";\n \t\tprint_float dy1; print_string \" \";\n \t\tprint_float dy; print_string \" \";\n \t\tprint_float al; print_string \" \";\n \t\tprint_float xw; print_string \" \";\n \t\tprint_float halfg; print_string \" \";\n \t\tprint_float rr; print_string \" done print vars\\n\"\n\t\tend;\n\tlet retv = \n\t\t(if rr < r then -1.0\n\t\t else if rr > r *. 1.01 then xw -. 0.0001\n\t\t else xw)\n\t\tin\n\tprint_float retv\n\tend end;; \t\n\t\nmain();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let rf () = float (read_int()) in\n let y1 = rf() in\n let y2 = rf() in\n let yw = rf() in\n let xb = rf() in\n let yb = rf() in\n let r = rf() in\n\n let yb' = (yw-.r) +. (yw-.r-.yb) in\n (* reflected ball y coordinate *)\n\n let sq x = x*.x in\n\n let a = xb in\n let yh = r +. y1 in\n let b = yb' -. yh in\n let c = sqrt ((sq a) +. (sq b)) in\n let h = (c/.a) *. r in\n let yt = yh +. h in\n if yt >= y2 then Printf.printf \"-1\\n\"\n else (\n (* we aim at position yh *)\n let d = xb in\n let c = yb' -. yh in\n let b = yb' -. (yw -. r) in\n let a = (d/.c) *. b in\n let xw1 = xb -. a in\n\n\tif yb -. r >= y1 then Printf.printf \"%.10f\\n\" xw1\n\telse (\n\t let c = sqrt ((sq xb) +. (sq (y1 -. yb))) in\n\t let alpha = asin (r/.c) in\n\t let beta = asin ((y1 -. yb)/.c) in\n\t let phi = alpha +. beta in\n\t let xw2 = xb -. ((yw -. r -. yb) /. (tan phi)) in\n\t if xw2 > xw1 then Printf.printf \"-1\\n\" else Printf.printf \"%.10f\\n\" xw1\n\t)\n )\n\n\n"}], "negative_code": [{"source_code": "(* Codeforces 248C Football Robot Electronic *)\n\nopen Big_int;;\nopen List;;\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 main () =\n\tlet y1 = grf() in\n\tlet y2 = grf() in\n\tlet yw = grf() in\n\tlet xb = grf() in\n\tlet yb = grf() in\n\tlet r = grf() in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"y1,y2,yw,xb,yb,r=\";\n \t\tprint_float y1; print_string \" \";\n \t\tprint_float y2; print_string \" \";\n \t\tprint_float yw; print_string \" \";\n \t\tprint_float xb; print_string \" \";\n \t\tprint_float yb; print_string \" \";\n \t\tprint_float r; print_string \" done print input\\n\"\n\t\tend;\n\tlet targ = (y2 +. y1) *. 0.5 in\n\tlet dy2 = yw -. r -. yb in \n\tlet dy1 = yw -. r -. r -. y1 in\n\tlet dy = dy1 +. dy2 in\n\tlet al = atan (xb /. dy) in\n\tlet xw = xb *. dy1 /. dy in \n\tlet halfg = y2 -. y1 -. r in\n\tlet rr = halfg *. (sin al) in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"targ dy2 dy1 dy al xw halfg rr =\";\n \t\tprint_float targ; print_string \" \";\n \t\tprint_float dy2; print_string \" \";\n \t\tprint_float dy1; print_string \" \";\n \t\tprint_float dy; print_string \" \";\n \t\tprint_float al; print_string \" \";\n \t\tprint_float xw; print_string \" \";\n \t\tprint_float halfg; print_string \" \";\n \t\tprint_float rr; print_string \" done print vars\\n\"\n\t\tend;\n\tlet retv = \n\t\t(if rr < r then -1.0\n\t\t else if rr > r *. 1.01 then xw +. 0.0001\n\t\t else xw)\n\t\tin\n\tprint_float retv\n\tend end;; \t\n\t\nmain();;\n"}, {"source_code": "(* Codeforces 248C Football Robot Electronic *)\n\nopen Big_int;;\nopen List;;\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 main () =\n\tlet y1 = grf() in\n\tlet y2 = grf() in\n\tlet yw = grf() in\n\tlet xb = grf() in\n\tlet yb = grf() in\n\tlet r = grf() in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"y1,y2,yw,xb,yb,r=\";\n \t\tprint_float y1; print_string \" \";\n \t\tprint_float y2; print_string \" \";\n \t\tprint_float yw; print_string \" \";\n \t\tprint_float xb; print_string \" \";\n \t\tprint_float yb; print_string \" \";\n \t\tprint_float r; print_string \" done print input\\n\"\n\t\tend;\n\tlet targ = (y2 +. y1) *. 0.5 in\n\tlet dy2 = yw -. r -. yb in \n\tlet dy1 = yw -. r -. targ in\n\tlet dy = dy1 +. dy2 in\n\tlet al = atan (xb /. dy) in\n\tlet xw = xb *. dy1 /. dy in \n\tlet halfg = (y2 -. y1) *. 0.5 in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"targ dy2 dy1 dy al xw halfg =\";\n \t\tprint_float targ; print_string \" \";\n \t\tprint_float dy2; print_string \" \";\n \t\tprint_float dy1; print_string \" \";\n \t\tprint_float dy; print_string \" \";\n \t\tprint_float al; print_string \" \";\n \t\tprint_float xw; print_string \" \";\n \t\tprint_float halfg; print_string \" done print vars\\n\"\n\t\tend;\n\tlet retv = \n\t\t(if halfg *. (sin al) < r then -1.0\n\t\t else xw)\n\t\tin\n\tprint_float retv\n\tend end;; \t\n\t\nmain();;\n"}, {"source_code": "(* Codeforces 248C Football Robot Electronic *)\n\nopen Big_int;;\nopen List;;\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 main () =\n\tlet y1 = grf() in\n\tlet y2 = grf() in\n\tlet yw = grf() in\n\tlet xb = grf() in\n\tlet yb = grf() in\n\tlet r = grf() in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"y1,y2,yw,xb,yb,r=\";\n \t\tprint_float y1; print_string \" \";\n \t\tprint_float y2; print_string \" \";\n \t\tprint_float yw; print_string \" \";\n \t\tprint_float xb; print_string \" \";\n \t\tprint_float yb; print_string \" \";\n \t\tprint_float r; print_string \" done print input\\n\"\n\t\tend;\n\tlet targ = (y2 +. y1) *. 0.5 in\n\tlet dy2 = yw -. r -. yb in \n\tlet dy1 = yw -. r -. r -. y1 in\n\tlet dy = dy1 +. dy2 in\n\tlet al = atan (xb /. dy) in\n\tlet xw = xb *. dy1 /. dy in \n\tlet halfg = y2 -. y1 -. r in\n\tlet rr = halfg *. (sin al) in\n\tbegin\n\t\tif debug then begin\n \t\tprint_string \"targ dy2 dy1 dy al xw halfg rr =\";\n \t\tprint_float targ; print_string \" \";\n \t\tprint_float dy2; print_string \" \";\n \t\tprint_float dy1; print_string \" \";\n \t\tprint_float dy; print_string \" \";\n \t\tprint_float al; print_string \" \";\n \t\tprint_float xw; print_string \" \";\n \t\tprint_float halfg; print_string \" \";\n \t\tprint_float rr; print_string \" done print vars\\n\"\n\t\tend;\n\tlet retv = \n\t\t(if rr < r then -1.0\n\t\t else xw)\n\t\tin\n\tprint_float retv\n\tend end;; \t\n\t\nmain();;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let rf () = float (read_int()) in\n let y1 = rf() in\n let y2 = rf() in\n let yw = rf() in\n let xb = rf() in\n let yb = rf() in\n let r = rf() in\n\n let yb = (yw-.r) +. (yw-.r-.yb) in\n (* reflected ball y coordinate *)\n\n let a = xb in\n let b = yb -. y1 in\n let c = sqrt (a*.a +. b*.b) in\n let h = (c/.a) *. r in\n let yh = r +. y1 in\n let yt = yh +. h in\n\n if yt >= y2 then Printf.printf \"-1\\n\"\n else (\n (* we aim at position yh *)\n let d = xb in\n let c = yb -. yh in\n let b = yb -. (yw -. r) in\n let a = (d/.c) *. b in\n let xw = xb -. a in\n\tPrintf.printf \"%.10f\\n\" xw\n )\n"}], "src_uid": "92c2f3599d221f2b1b695227c5739e84"} {"source_code": "let main() =\n let s = Scanf.scanf \" %s\" (fun i -> i) in\n let n = String.length s in\n let k = Scanf.scanf \" %d\" (fun i -> i) in\n let a = Array.make_matrix n n 0 in\n for l = 2 to n do\n for i = 0 to n-l do\n let j = i + l - 1 in\n a.(i).(j) <- (if l == 2 then 0 else a.(i+1).(j-1)) + (if s.[i] == s.[j] then 0 else 1);\n done;\n done;\n let b = Array.make_matrix (k+1) (n+1) (2*n) in let p = Array.make_matrix (k+1) (n+1) (-1) in\n b.(0).(0) <- 0;\n for l = 1 to k do\n let br = b.(l-1) in let bn = b.(l) in\n for i = 0 to (n-1) do\n let x = br.(i) in let y = a.(i) in\n for j = (i+1) to n do\n let v = x + y.(j-1) in\n if bn.(j) > v then (bn.(j) <- v; p.(l).(j) <- i) else ();\n done;\n done;\n done;\n let d = Array.init k (fun i -> b.(i+1).(n), i+1) in\n let best_v, best_k = Array.fold_left (fun b x -> if (fst b) < (fst x) then b else x) (2*n, -1) d in\n let rec h i j =\n if i < j then (s.[j] <- s.[i]; h (i+1) (j-1)) else ()\n in\n let g i j =\n h i j;\n String.sub s i (j - i + 1)\n in\n let rec ans k j l =\n if k = 0 then l else (let i = p.(k).(j) in ans (k-1) i ((g i (j-1))::l))\n in\n Printf.printf \"%d\\n%s\\n\" best_v (String.concat \"+\" (ans best_k n []))\n ;;\nmain()", "positive_code": [{"source_code": "\nlet getint () = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun i->i)\nlet getstr () = Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun s-> s)\nlet getchar () = Scanf.bscanf Scanf.Scanning.stdin \" %c\" (fun i->i)\nlet inf = 1000000007\n\nlet s = getstr ()\nlet n = String.length s\nlet k = getint ()\nlet cost = Array.make_matrix n n 0\nlet dp = Array.make_matrix (n+1) (k+1) inf\nlet tb = Array.make_matrix (n+1) (k+1) 0\n\n\n \nlet calc_cost () =\n for i = 0 to n-1 do\n for j = i to n-1 do\n let i' = ref i and j' = ref j in\n while !i' <= !j' do\n if s.[!i'] <> s.[!j'] then cost.(i).(j) <- cost.(i).(j) + 1;\n incr i'; decr j'\n done\n done\n done\n\n\nlet minimize () = \n for j = 0 to k do\n dp.(0).(j) <- 0\n done;\n for i = 1 to n do\n for j = 1 to k do\n for m = 0 to i-1 do\n if dp.(i).(j) > dp.(m).(j-1) + cost.(m).(i-1) \n then \n begin\n dp.(i).(j) <- dp.(m).(j-1) + cost.(m).(i-1); \n tb.(i).(j) <- m \n end\n done\n done\n done\n\n\nlet trace_back () = \n let len = ref n and k' = ref k and l = ref [] in\n while !len <> 0 do\n l := (!len - tb.(!len).(!k')) :: !l;\n len := tb.(!len).(!k');\n decr k'\n done;\n let last = ref 0 in\n List.iter\n (\n fun len -> \n let i = ref !last and j = ref (!last + len - 1) in\n while !i <= !j do\n if s.[!i] <> s.[!j] then s.[!i] <- s.[!j];\n incr i; decr j\n done;\n for i = !last to !last+ len - 1 do\n print_char s.[i];\n done;\n last := !last + len;\n if !last <> n then print_char '+'\n else print_char '\\n';\n )\n !l \n\nlet _ = \n calc_cost ();\n minimize ();\n print_int dp.(n).(k); print_newline ();\n trace_back ()\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x);;\n\nlet str = read_string ();;\nlet k = read_int ();;\nlet n = String.length str;;\n\nlet dp = Array.create_matrix 505 505 10000000;;\nlet cnt = Array.create_matrix 505 505 0;;\nlet mark = Array.create_matrix 505 505 0;;\n\nlet _ = for i = 0 to (n-1) do\n for j = (i+1) to (n-1) do\n for t1 = i to ((j+i)/2) do\n if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1\n done\n done\n done;;\n\nlet _ = for i = 0 to (n-1) do\n dp.(i).(1) <- cnt.(0).(i);\n mark.(i).(1) <- -1\n done;;\n\nlet _ = for i = 0 to (n-1) do\n for j = 2 to (min (i+1) k) do\n for t = 0 to (i-1) do\n if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then\n begin\n dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);\n mark.(i).(j) <- t\n end\n done\n done\n done;;\n\nlet ans = ref 10000000;; \nlet len = ref (-1);;\nlet p = ref 0;;\n\nlet _ = for i = 1 to k do\n if dp.(n-1).(i) < !ans then \n begin\n ans := dp.(n-1).(i);\n len := i;\n p := mark.(n-1).(i)\n end\n done;;\n\nlet rec solve2 str i j = \n if i>=j then str\n else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end\n else solve2 str (i+1) (j-1);;\n\nlet rec solve str len s t = \n if len = 1 then solve2 (String.sub str s (t-s+1)) 0 (t-s)\n else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1) ^ \"+\" ^ solve2 (String.sub str s (t-s+1)) 0 (t-s);; \n \nif n = 1 then Printf.printf \"0\\n%s\\n\" str\nelse Printf.printf \"%d\\n%s\\n\" (!ans) (solve str (!len) (!p+1) (n-1));;\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x);;\n\nlet str = read_string ();;\nlet k = read_int ();;\nlet n = String.length str;;\n\nlet dp = Array.create_matrix 505 505 10000000;;\nlet cnt = Array.create_matrix 505 505 0;;\nlet mark = Array.create_matrix 505 505 0;;\n\nlet _ = for i = 0 to (n-1) do\n for j = (i+1) to (n-1) do\n for t1 = i to ((j+i)/2) do\n if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1\n done\n done\n done;;\n\nlet _ = for i = 0 to (n-1) do\n dp.(i).(1) <- cnt.(0).(i);\n mark.(i).(1) <- -1\n done;;\n\nlet _ = for i = 0 to (n-1) do\n for j = 2 to (min (i+1) k) do\n for t = 0 to (i-1) do\n if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then\n begin\n dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);\n mark.(i).(j) <- t\n end\n done\n done\n done;;\n\nlet ans = ref 10000000;; \nlet len = ref (-1);;\nlet p = ref 0;;\n\nlet _ = for i = 1 to k do\n if dp.(n-1).(i) < !ans then \n begin\n ans := dp.(n-1).(i);\n len := i;\n p := mark.(n-1).(i)\n end\n done;;\n\nlet rec solve2 str i j = \n if i>=j then str\n else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end\n else solve2 str (i+1) (j-1);;\n\nlet rec solve str len s t str_ans = \n if len = 0 then str_ans\n else if len = 1 then solve \"\" 0 0 0 (solve2 (String.sub str s (t-s+1)) 0 (t-s) ^ str_ans )\n else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1) (\"+\" ^ solve2 (String.sub str s (t-s+1)) 0 (t-s) ^ str_ans) ;; \n \nif n = 1 then Printf.printf \"0\\n%s\\n\" str\nelse let str_ans = (solve str (!len) (!p+1) (n-1) \"\") in Printf.printf \"%d\\n%s\\n\" (!ans) str_ans;;\n"}, {"source_code": "let s = input_line stdin;;\nlet n = String.length s;;\nlet k = read_int ();;\nlet f = Array.make_matrix n n 0;;\nfor i = n - 1 downto 0 do\n for j = i to n - 1 do\n if i == j then begin\n f.(i).(j) <- 0\n end else if i + 1 == j then begin\n f.(i).(j) <- if s.[i] != s.[j] then 1 else 0;\n end else begin\n f.(i).(j) <- f.(i + 1).(j - 1) + if s.[i] != s.[j] then 1 else 0;\n end;\n done\ndone;;\nlet g = Array.make_matrix (n + 1) (n + 1) 12345;;\nlet p = Array.make_matrix (n + 1) (n + 1) 12345;;\ng.(0).(0) <- 0;;\nfor i = 0 to n - 1 do\n for j = 0 to i do\n for l = i + 1 to n do\n let cur = g.(i).(j) + f.(i).(l - 1) in\n if g.(l).(j + 1) > cur then begin\n g.(l).(j + 1) <- cur;\n p.(l).(j + 1) <- i;\n end\n done;\n done\ndone;;\nlet h = Array.make n \"\";;\nlet u = ref 0;;\nlet v = ref n;;\nfor j = 0 to k do\n if g.(n).(!u) > g.(n).(j) then begin u := j end\ndone;;\nPrintf.printf \"%d\\n\" g.(n).(!u);; \nlet w = ref 0;;\nfor j = 0 to !u - 1 do\n let c = String.sub s p.(!v).(!u - j) (!v - p.(!v).(!u - j)) in\n let t = String.length c in\n let x = ref 0 in\n let y = ref (t - 1) in begin\n while !x < !y do\n c.[!y] <- c.[!x];\n x := !x + 1;\n y := !y - 1;\n done;\n h.(j) <- c;\n v := p.(!v).(!u - j);\n end;\ndone;;\nfor j = !u - 1 downto 0 do\n Printf.printf \"%s%s\" h.(j) (if j == 0 then \"\\n\" else \"+\");\ndone;;\n"}, {"source_code": "let main() =\n let s = Scanf.scanf \" %s\" (fun i -> i) in\n let n = String.length s in\n let k = Scanf.scanf \" %d\" (fun i -> i) in\n let a = Array.make_matrix n n 0 in\n let rec d1 l =\n let rec d2 i =\n let j = i + l - 1 in\n if j < n then (a.(i).(j) <- (if l == 2 then 0 else a.(i+1).(j-1)) + (if s.[i] == s.[j] then 0 else 1); d2 (i+1)) else ()\n in\n d2 0;\n if l < n then d1 (l+1) else ()\n in\n d1 2;\n let b = Array.make_matrix (k+1) (n+1) (2*n) in\n let p = Array.make_matrix (k+1) (n+1) (-1) in\n b.(0).(0) <- 0;\n let rec f1 l =\n let br = b.(l-1) in let bn = b.(l) in\n let rec f2 i =\n let x = br.(i) in let y = a.(i) in\n let rec f3 j =\n let v = x + y.(j-1) in\n if bn.(j) > v then (bn.(j) <- v; p.(l).(j) <- i) else ();\n if j < n then f3 (j+1) else ()\n in\n f3 (i+1);\n if i < (n-1) then f2 (i+1) else ()\n in\n f2 0;\n if l < k then f1 (l+1) else ();\n in\n f1 1;\n let d = Array.init k (fun i -> b.(i+1).(n), i+1) in\n let best_v, best_k = Array.fold_left (fun b x -> if (fst b) < (fst x) then b else x) (2*n, -1) d in\n let rec h i j =\n if i < j then (s.[j] <- s.[i]; h (i+1) (j-1)) else ()\n in\n let g i j =\n h i j;\n String.sub s i (j - i + 1)\n in\n let rec ans k j l =\n if k = 0 then l else (let i = p.(k).(j) in ans (k-1) i ((g i (j-1))::l))\n in\n Printf.printf \"%d\\n%s\\n\" best_v (String.concat \"+\" (ans best_k n []))\n ;;\nmain()"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = String.length s in\n let c = Array.make_matrix n n 0 in\n let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tlet d = ref 0 in\n\t for k = 0 to (j - i + 1) / 2 - 1 do\n\t if s.[i + k] <> s.[j - k]\n\t then incr d;\n\t done;\n\t c.(i).(j) <- !d\n done\n done\n in\n (*let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tPrintf.printf \"%d \" c.(i).(j)\n done;\n Printf.printf \"\\n\"\n done\n in*)\n (*let min (x : int) y = if x < y then x else y in*)\n let a = Array.make_matrix (k + 1) (n + 1) 10000 in\n let d = Array.make_matrix (k + 1) (n + 1) 10000 in\n a.(0).(0) <- 0;\n for i = 1 to k do\n a.(i).(0) <- 0;\n for j = 1 to n do\n\tfor r = 0 to j - 1 do\n\t if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (\n\t a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);\n\t d.(i).(j) <- r;\n\t )\n\tdone\n done\n done;\n (*let _ =\n for i = 0 to k do\n\tfor j = 0 to n do\n\t Printf.printf \"%d(%d) \" a.(i).(j) d.(i).(j)\n\tdone;\n\tPrintf.printf \"\\n\"\n done\n in*)\n let palindromize s =\n let n = String.length s in\n\tfor i = 0 to n / 2 - 1 do\n\t if s.[i] <> s.[n - i - 1]\n\t then s.[i] <- s.[n - i - 1]\n\tdone\n in\n let res = a.(k).(n) in\n let ss = ref [] in\n let _ =\n let i = ref n in\n\tfor j = k downto 1 do\n\t if !i > 0 then (\n\t let r = d.(j).(!i) in\n\t ss := String.sub s r (!i - r) :: !ss;\n\t i := r;\n\t )\n\tdone\n in\n assert (!ss <> []);\n Printf.printf \"%d\\n\" res;\n let f = ref true in\n\tList.iter\n\t (fun s ->\n\t if not !f\n\t then Printf.printf \"+\";\n\t f := false;\n\t assert (s <> \"\");\n\t palindromize s;\n\t Printf.printf \"%s\" s\n\t ) !ss;\n\tPrintf.printf \"\\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 inf = 1_000_000\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\n\nlet argmin i j f = \n fold i j (\n fun k (index,v) -> let m = (f k) in if m= 0 then c.(i).(p) else \n let cc = \n\tif p=1 then dist.(0).(i) else\n\t let (j,opt) = argmin 0 i (fun j -> (cost (j-1) (p-1)) + dist.(j).(i)) in\n\t bj.(i).(p) <- j;\n\t opt\n in\n\tc.(i).(p) <- cc;\n\tcc\n\nlet make_palindrome i j = (* return a palindrome of s.[i...j] *)\n let l = j-i+1 in\n let r = String.sub s i l in\n for k=0 to l/2-1 do\n r.[k] <- r.[l-1-k]\n done;\n r\n\nlet rec build_soln i p ac =\n if i<0 || p<1 then ac else\n let j = bj.(i).(p) in\n build_soln (j-1) (p-1) ((make_palindrome j i)::ac)\n\nlet () = \n Printf.printf \"%d\\n\" (cost (n-1) k);\n Printf.printf \"%s\\n\" (String.concat \"+\" (build_soln (n-1) k []));\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x);;\n\nlet str = read_string ();;\nlet k = read_int ();;\nlet n = String.length str;;\n\nlet dp = Array.create_matrix 505 505 10000000;;\nlet cnt = Array.create_matrix 505 505 0;;\nlet mark = Array.create_matrix 505 505 0;;\n\nlet _ = for i = 0 to (n-1) do\n for j = (i+1) to (n-1) do\n for t1 = i to ((j+i)/2) do\n if str.[t1]!=str.[j-t1+i] then cnt.(i).(j) <- cnt.(i).(j) + 1\n else ()\n done\n done\n done;;\n\nlet _ = for i = 0 to (n-1) do\n begin\n dp.(i).(1) <- cnt.(0).(i);\n mark.(i).(1) <- -1\n end\n done;;\n\nlet _ = for i = 0 to (n-1) do\n for j = 2 to (min (i+1) k) do\n for t = 0 to (i-1) do\n if dp.(t).(j-1) + cnt.(t+1).(i) < dp.(i).(j) then\n dp.(i).(j) <- dp.(t).(j-1) + cnt.(t+1).(i);\n mark.(i).(j) <- t\n done\n done\n done;;\n\nlet ans = ref 10000000;; \nlet len = ref (-1);;\nlet p = ref 0;;\n\nlet _ = for i = 1 to k do\n if dp.(n-1).(i) < !ans then \n ans := dp.(n-1).(i);\n len := i;\n p := mark.(n-1).(i)\n done;;\n\nlet rec solve2 str i j = \n if i>=j then str\n else if str.[i]!=str.[j] then begin str.[i] <- str.[j]; solve2 str (i+1) (j-1) end\n else solve2 str (i+1) (j-1);;\n\nlet rec solve str len s t = \n if len = 1 then solve2 (String.sub str s (t-s+1)) s t\n else solve (String.sub str 0 s) (len-1) (mark.(s-1).(len-1)+1) (s-1) ^ \"+\" ^ solve2 (String.sub str s (t-s+1)) s t;; \n \nif n = 1 then Printf.printf \"0\\n%s\\n\" str\nelse Printf.printf \"%d\\n%s\\n\" (!ans) (solve str (!len) (!p+1) (n-1));;\n"}, {"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n match Stream.next stdin_stream with\n '-' -> - (ri 0)\n | '+' -> ri 0\n | '0'..'9' as c -> ri ((int_of_char c) - 48)\n | _ -> gi ()\nand ri x =\n match Stream.next stdin_stream with\n '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;\nlet pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) a;;\n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n let s = Scanf.scanf \"%s\" (fun i -> i) in\n let mk = Scanf.scanf \" %d\" (fun i -> i) in\n let l = String.length s in\n let a = make_matrix l l (-1, 0) in\n let b = make_matrix (mk+1) (l+1) 10000 in\n let c = make_matrix (mk+1) (l+1) (-1) in\n let rec f i j = \n if (j-i) <= 1 then (0,0)\n else (if (fst a.(i).(j)) >= 0 then a.(i).(j)\n else \n (\n let (u,_) = f (i+1) (j-1) in\n let r = if s.[i] == s.[j] then (u, 0) else (u + 1, 1) in\n a.(i).(j) <- r;\n r \n )\n ) \n in\n let rec g i j = \n if (j-i) <= 1 then ()\n else ((match snd (f i j) with\n 1 -> s.[i] <- s.[j]\n | _ -> () \n ); g (i+1) (j-1))\n in \n b.(mk).(0) <- 0; \n for k = (mk - 1) downto 0 do\n for i = 0 to (l - 1) do\n let w = b.(k+1).(i) in\n for j = (i+1) to l do \n let v = w + (fst (f i (j-1))) in\n if v < b.(k).(j) then ( b.(k).(j) <- v; c.(k).(j) <- i )\n else ()\n done\n done\n done;\n let rec h j k a =\n if k == mk then a\n else (\n let i = c.(k).(j) in\n g i (j-1);\n let ss = String.sub s i (j - i) in\n h i (k+1) (ss::a)\n )\n in\n let y = h l 0 [] in\n Printf.printf \"%d\\n%s\\n\" (b.(0).(l)) (String.concat \"+\" y)\n ;;\nmain();;\nflushout ()"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = String.length s in\n let c = Array.make_matrix n n 0 in\n let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tlet d = ref 0 in\n\t for k = 0 to (j - i + 1) / 2 - 1 do\n\t if s.[i + k] <> s.[j - k]\n\t then incr d;\n\t done;\n\t c.(i).(j) <- !d\n done\n done\n in\n (*let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tPrintf.printf \"%d \" c.(i).(j)\n done;\n Printf.printf \"\\n\"\n done\n in*)\n (*let min (x : int) y = if x < y then x else y in*)\n let a = Array.make_matrix (k + 1) (n + 1) 10000 in\n let d = Array.make_matrix (k + 1) (n + 1) 10000 in\n a.(0).(0) <- 0;\n for i = 1 to k do\n a.(i).(0) <- 0;\n for j = 0 to n do\n\tfor r = 0 to j - 1 do\n\t if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (\n\t a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);\n\t d.(i).(j) <- r;\n\t )\n\tdone\n done\n done;\n (*let _ =\n for i = 0 to k do\n\tfor j = 0 to n do\n\t Printf.printf \"%d \" a.(i).(j)\n\tdone;\n\tPrintf.printf \"\\n\"\n done\n in*)\n let palindromize s =\n let n = String.length s in\n\tfor i = 0 to n / 2 do\n\t if s.[i] <> s.[n - i - 1]\n\t then s.[i] <- s.[n - i - 1]\n\tdone\n in\n let res = a.(k).(n) in\n let ss = ref [] in\n let _ =\n let i = ref n in\n\tfor j = k downto 1 do\n\t if !i > 0 then (\n\t let r = d.(k).(!i) in\n\t ss := String.sub s r (!i - r) :: !ss;\n\t i := r;\n\t )\n\tdone\n in\n Printf.printf \"%d\\n\" res;\n let f = ref true in\n\tList.iter\n\t (fun s ->\n\t if not !f\n\t then Printf.printf \"+\";\n\t f := false;\n\t palindromize s;\n\t Printf.printf \"%s\" s\n\t ) !ss;\n\tPrintf.printf \"\\n\"\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = String.length s in\n let c = Array.make_matrix n n 0 in\n let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tlet d = ref 0 in\n\t for k = 0 to (j - i + 1) / 2 - 1 do\n\t if s.[i + k] <> s.[j - k]\n\t then incr d;\n\t done;\n\t c.(i).(j) <- !d\n done\n done\n in\n (*let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tPrintf.printf \"%d \" c.(i).(j)\n done;\n Printf.printf \"\\n\"\n done\n in*)\n (*let min (x : int) y = if x < y then x else y in*)\n let a = Array.make_matrix (k + 1) (n + 1) 10000 in\n let d = Array.make_matrix (k + 1) (n + 1) 10000 in\n a.(0).(0) <- 0;\n for i = 1 to k do\n a.(i).(0) <- 0;\n for j = 1 to n do\n\tfor r = 0 to j - 1 do\n\t if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (\n\t a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);\n\t d.(i).(j) <- r;\n\t )\n\tdone\n done\n done;\n (*let _ =\n for i = 0 to k do\n\tfor j = 0 to n do\n\t Printf.printf \"%d \" a.(i).(j)\n\tdone;\n\tPrintf.printf \"\\n\"\n done\n in*)\n let palindromize s =\n let n = String.length s in\n\tfor i = 0 to n / 2 - 1 do\n\t if s.[i] <> s.[n - i - 1]\n\t then s.[i] <- s.[n - i - 1]\n\tdone\n in\n let res = a.(k).(n) in\n let ss = ref [] in\n let _ =\n let i = ref n in\n\tfor j = k downto 1 do\n\t if !i > 0 then (\n\t let r = d.(k).(!i) in\n\t ss := String.sub s r (!i - r) :: !ss;\n\t i := r;\n\t )\n\tdone\n in\n assert (!ss <> []);\n Printf.printf \"%d\\n\" res;\n let f = ref true in\n\tList.iter\n\t (fun s ->\n\t if not !f\n\t then Printf.printf \"+\";\n\t f := false;\n\t assert (s <> \"\");\n\t palindromize s;\n\t Printf.printf \"%s\" s\n\t ) !ss;\n\tPrintf.printf \"\\n\"\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = String.length s in\n let c = Array.make_matrix n n 0 in\n let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tlet d = ref 0 in\n\t for k = 0 to (j - i + 1) / 2 - 1 do\n\t if s.[i + k] <> s.[j - k]\n\t then incr d;\n\t done;\n\t c.(i).(j) <- !d\n done\n done\n in\n (*let _ =\n for i = 0 to n - 1 do\n for j = i to n - 1 do\n\tPrintf.printf \"%d \" c.(i).(j)\n done;\n Printf.printf \"\\n\"\n done\n in*)\n (*let min (x : int) y = if x < y then x else y in*)\n let a = Array.make_matrix (k + 1) (n + 1) 10000 in\n let d = Array.make_matrix (k + 1) (n + 1) 10000 in\n a.(0).(0) <- 0;\n for i = 1 to k do\n a.(i).(0) <- 0;\n for j = 1 to n do\n\tfor r = 0 to j - 1 do\n\t if a.(i).(j) > a.(i - 1).(r) + c.(r).(j - 1) then (\n\t a.(i).(j) <- a.(i - 1).(r) + c.(r).(j - 1);\n\t d.(i).(j) <- r;\n\t )\n\tdone\n done\n done;\n (*let _ =\n for i = 0 to k do\n\tfor j = 0 to n do\n\t Printf.printf \"%d \" a.(i).(j)\n\tdone;\n\tPrintf.printf \"\\n\"\n done\n in*)\n let palindromize s =\n let n = String.length s in\n\tfor i = 0 to n / 2 do\n\t if s.[i] <> s.[n - i - 1]\n\t then s.[i] <- s.[n - i - 1]\n\tdone\n in\n let res = a.(k).(n) in\n let ss = ref [] in\n let _ =\n let i = ref n in\n\tfor j = k downto 1 do\n\t if !i > 0 then (\n\t let r = d.(k).(!i) in\n\t ss := String.sub s r (!i - r) :: !ss;\n\t i := r;\n\t )\n\tdone\n in\n assert (!ss <> []);\n Printf.printf \"%d\\n\" res;\n let f = ref true in\n\tList.iter\n\t (fun s ->\n\t if not !f\n\t then Printf.printf \"+\";\n\t f := false;\n\t assert (s <> \"\");\n\t palindromize s;\n\t Printf.printf \"%s\" s\n\t ) !ss;\n\tPrintf.printf \"\\n\"\n"}], "src_uid": "c1de33ee9bb05db090c4d23ec9994f72"} {"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 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 t = gi 0 in\n rep 1L t (fun _ ->\n let l,r = g2 0 in\n (* let f,u,v = ref true,ref l,ref r in\n while !f do\n while !f do\n if !v mod !u = 0L then (\n f := false;\n printf \"%Ld %Ld\\n\" !u !v\n );\n v -= 1L\n done;\n u += 1L;\n done; *)\n (* let f,u = ref true,ref l in\n while !f do\n done *)\n (* if l*2L > r then (\n\n ) *)\n printf \"%Ld %Ld\\n\" l (l*2L);\n )\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "Scanf.(Array.(\n let t = scanf \" %d\" @@ fun v -> v in\n init t (fun _ ->\n let l = scanf \" %d %d\" @@ fun p _ -> p in\n Printf.printf \"%d %d\\n\" l (l*2))))"}], "negative_code": [], "src_uid": "a9cd97046e27d799c894d8514e90a377"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix n n 0 in\n let c = Array.make n 0 in\n let tot = ref true in\n let m = ref 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tif i <> j && c.(i) < k && a.(i).(j) = 0 then (\n\t c.(i) <- c.(i) + 1;\n\t incr m;\n\t a.(i).(j) <- 1;\n\t a.(j).(i) <- -1;\n\t)\n done\n done;\n for i = 0 to n - 1 do\n if c.(i) < k\n then tot := false;\n done;\n if not !tot\n then Printf.printf \"-1\\n\"\n else (\n Printf.printf \"%d\\n\" (n * k);\n for i = 0 to n - 1 do\n\tfor j = 0 to n - 1 do\n\t if a.(i).(j) = 1\n\t then Printf.printf \"%d %d\\n\" (i + 1) (j + 1);\n\tdone\n done;\n )\n", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and k=read_int();;\nlet m=n*(n-1)/2;;\nlet nb=k*n;;\nlet mat=Array.make_matrix (n+1) (n+1) 0;;\nlet b=ref true\n\nlet rec win r i j=\nif r=0 then ()\nelse if i=j then win r i (j+1)\nelse if j>n then b:=false\nelse \n begin\n if mat.(i).(j)=0 then (mat.(i).(j)<-1;mat.(j).(i)<-(-1);win (r-1) i (j+1))\n else win r i (j+1)\n end;;\n\nif nb>m then b:=false;;\n\nfor i=1 to n do\n win k i 1\ndone;;\n\nif !b=false then print_int(-1) else\nbegin\nprint_int nb;\nprint_newline();\nfor i=1 to n do\n for j=1 to n do\n if mat.(i).(j)=1 then Printf.printf \"%d %d\\n\" i j\n done\ndone\nend;;\n"}], "negative_code": [], "src_uid": "14570079152bbf6c439bfceef9816f7e"} {"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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let n = read_int() in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n let l = (n-2)/2 in\n let v = n-2-l in\n\n printf \"%d\\n\" (minf 0 v (fun i -> x.(i+n-v-1) - x.(i)))\n", "positive_code": [{"source_code": "\nopen Str\n\nlet n = int_of_string @@ read_line () ;;\nlet xs = List.sort compare \n ( List.map int_of_string ( (split @@ regexp \" \") (read_line()) ) );;\n\n\nlet maxInIntv len = \n let rec miii l r c = match r with\n | [] -> 0\n | rx::rt -> if rx - List.hd l <= len \n then max c ( miii l rt (c+1) )\n else miii (List.tl l) r (c-1)\n in miii xs xs 1\nin\nlet rec optlen lmin lmax =\n if lmin = lmax then lmin\n else\n let mid = lmin/2 + lmax/2 in\n if (maxInIntv mid) > n/2\n then optlen lmin mid\n else optlen (mid+1) lmax\nin\nprint_int @@ optlen 1 1_000_000_000\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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let n = read_int() in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n let l = (n-2)/2 in\n let v = n-2-l in\n\n printf \"%d\\n\" (minf 0 v (fun i -> x.(i+n-v-1) - x.(i)))\n"}], "negative_code": [{"source_code": "\nopen Str\n\nlet n = int_of_string @@ read_line () ;;\nlet xs = List.map int_of_string ( (split @@ regexp \" \") (read_line()) ) ;;\n\nprint_int (List.nth xs (n-1) );;\n\n(* let maxInIntv len = \n let rec miii (l as lx::lt) r c = match r with\n | [] -> 0\n | rx::rt -> if rx - lx <= len \n then max c ( miii l rt (c+1) )\n else miii lt r (c-1)\n in miii xs xs 1\nin\nlet rec minlen lmin lmax =\n if lmin = lmax then lmin\n else\n let mid = lmin/2 + lmax/2 *)"}], "src_uid": "8aaabe089d2512b76e5de938bac5c3bf"} {"source_code": "let t = read_int() in\n\nfor i = 1 to t do\n let n=read_int() in\n let s=read_line() in\n let co = ref 0 in\n for j = 0 to (n-1) do\n if s.[j] = 'Q' then\n co := !co + 1\n else\n co := max (!co - 1) 0\n done;\n if !co > 0 then\n print_string(\"No\\n\")\n else\n print_string(\"Yes\\n\");\ndone", "positive_code": [{"source_code": "let t = read_int() in\r\n \r\nfor i = 1 to t do\r\n let n=read_int() in\r\n let s=read_line() in\r\n let co = ref 0 in\r\n for j = 0 to (n-1) do\r\n if s.[j] = 'Q' then\r\n co := !co + 1\r\n else\r\n co := max (!co - 1) 0\r\n done;\r\n if !co > 0 then\r\n print_string(\"No\\n\")\r\n else\r\n print_string(\"Yes\\n\");\r\ndone"}], "negative_code": [{"source_code": "let t = read_int() in\n\nfor i = 1 to t do\n let n=read_int() in\n let s=read_line() in\n let co = ref 0 in\n for j = 0 to (n-1) do\n if s.[j] = 'Q' then\n co := !co + 1\n else\n co := !co - 1\n done;\n if !co > 0 then\n print_string(\"No\\n\")\n else\n print_string(\"Yes\\n\");\ndone"}], "src_uid": "c5389b39312ce95936eebdd83f510e40"} {"source_code": "let rec str_to_list (str : string) (index : int) =\n if index = String.length str then\n []\n else\n (String.get str index) :: str_to_list str (index + 1)\n;;\n\nlet rec main (t : int) =\n if t = 0 then\n ()\n else\n (let str = read_line () in\n let str_list = str_to_list str 0 in\n let num_ones = List.fold_left (fun acc x -> if x = '1' then acc + 1 else acc) 0 str_list in\n let num_zeros = (String.length str) - num_ones in\n if (min num_ones num_zeros) mod 2 = 0 then\n print_endline \"NET\"\n else\n print_endline \"DA\"\n ;\n main (t-1)\n );;\n\nlet t = read_int () in\nmain t\n", "positive_code": [{"source_code": "(* Codeforces 1373 B. 01 Game train *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec countz cnt idx s = \n\tif idx == (String.length s) then cnt\n\telse\n\t\tlet ncnt = if s.[idx]=='0' then (cnt + 1) else cnt in\n\t\tcountz ncnt (idx + 1) s;;\n\nlet game s = \n let nz = countz 0 0 s in\n\t\tlet no = (String.length s) - nz in\n\t\tlet minzo = if nz < no then nz else no in\n\t\t(* let _ = Printf.printf \"minzo = %d\\n\" minzo in *)\n\t\tlet alice_win = (minzo mod 2) == 1 in\n\t\talice_win;;\n \nlet do_one () = \n let s = rdln() in\n let ans = game s in\n\t\tlet sans = if ans then \"DA\" else \"NET\" in\n Printf.printf \"%s\\n\" sans;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet st = rdln () in\n\tlet t = int_of_string st in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [], "src_uid": "046900001c7326fc8d890a22fa7267c9"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let cnt = ref 0 in\n for i = 1 to n do\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tif k = 0\n\tthen incr cnt\n done;\n if (n > 1 && !cnt = 1) || (n = 1 && !cnt = 0)\n then Printf.printf \"YES\\n\"\n else Printf.printf \"NO\\n\"\n", "positive_code": [{"source_code": "\nlet read_nums () = \n let s = read_line () in\n let n = int_of_string s in\n let s = read_line () in \n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n (n, nums) \n\n;;\n\n\n\nlet rec sum nums acc = match nums with\n | [] -> acc\n | hd :: tl -> sum tl (acc + hd)\n \n;;\n\nlet get_ans () = \n \n let (n, nums) = read_nums () in\n let x = sum nums 0 in\n if (n = 1 && x = 1) then\n true\n else if (n > 1 && (n-1) = x) then\n true\n else\n false \n;;\n\n\nlet r = get_ans () in\nif r then\n print_string \"YES\\n\"\nelse\n print_string \"NO\\n\"\n \n\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n let s = Array.fold_left (+) 0 a in\n print_endline (if (n = 1 && s = 1) || (n > 1 && s = n - 1) then \"YES\" else \"NO\"))\n"}], "negative_code": [{"source_code": "\nlet read_nums () = \n let s = read_line () in\n let n = int_of_string s in\n let s = read_line () in \n let nums = List.map int_of_string (Str.split (Str.regexp \" \") s) in\n (n, nums) \n\n;;\n\n\n\nlet rec sum nums acc = match nums with\n | [] -> acc\n | hd :: tl -> sum tl (acc + hd)\n \n\nlet get_ans () = \n \n let (n, nums) = read_nums () in\n let x = sum nums 0 in\n (n = 1 && x = 1) || ((n-1) = x)\n \n;;\n\n\nlet r = get_ans () in\nif r then\n print_string \"YES\\n\"\nelse\n print_string \"NO\\n\"\n \n\n"}], "src_uid": "7db0b870177e7d7b01da083e21ba35f5"} {"source_code": "let _ =\n let mm = 1000000000 in\n let mmm = 1000000000l in\n let mmmm = 1000000000L in\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let add x y =\n let r =\n Int32.to_int\n\t(Int32.rem\n\t (Int32.add\n\t (Int32.of_int x)\n\t (Int32.of_int y))\n\t mmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let mul x y =\n let r =\n Int64.to_int\n\t(Int64.rem\n\t (Int64.mul\n\t (Int64.of_int x)\n\t (Int64.of_int y))\n\t mmmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let o = 131072 * 2 in\n (*let o = 16 in*)\n let fib = Array.make (o + 1) 0 in\n let _ =\n fib.(1) <- 1;\n for i = 2 to o do\n fib.(i) <- add fib.(i - 1) fib.(i - 2)\n done\n in\n let d = Array.make (o + 1) 0 in\n let shift ofs v v' =\n let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) v') in\n (*Printf.printf \"shift %d %d %d %d -> %d\\n\" ofs v v' fib.(ofs + 1) res;*)\n res\n in\n let a = Array.make (2 * o) 0 in\n let a' = Array.make (2 * o) 0 in\n let rec update i x l r k =\n if l = r then (\n a.(k) <- x;\n a'.(k) <- 0;\n ) else (\n let m = (l + r) / 2 in\n\tif i <= m\n\tthen update i x l m (2 * k + 1)\n\telse update i x (m + 1) r (2 * k + 2);\n\tlet a1 = a.(2 * k + 1) in\n\tlet a2 = a.(2 * k + 2) in\n\tlet a1' = a'.(2 * k + 1) in\n\tlet a2' = a'.(2 * k + 2) in\n\t a.(k) <- add a1 (shift (m - l + 1) a2 a2');\n\t a'.(k) <- add a1' (shift (m - l + 0) a2 a2');\n )\n in\n let rec rmq x y l r k =\n if x <= l && r <= y\n then (\n shift (l - x) a.(k) a'.(k)\n ) else (\n let m = (l + r) / 2 in\n\tif m < x\n\tthen rmq x y (m + 1) r (2 * k + 2)\n\telse if m >= y\n\tthen rmq x y l m (2 * k + 1)\n\telse\n\t let a1 = rmq x y l m (2 * k + 1)\n\t and a2 = rmq x y (m + 1) r (2 * k + 2) in\n\t add a1 a2\n )\n in\n let () =\n for i = 1 to n do\n d.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n update i d.(i) 1 o 0\n done;\n in\n for k = 1 to m do\n(*for j = 0 to Array.length a - 1 do\n Printf.printf \"%d \" a.(j);\ndone;\nPrintf.printf \"\\n\";*)\n let op = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tmatch op with\n\t | 1 ->\n\t let i = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t\td.(i) <- v;\n\t\tupdate i v 1 o 0;\n\t | 2 ->\n\t let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let res = rmq l r 1 o 0 in\n\t\tPrintf.printf \"%d\\n\" res;\n\t | _ -> assert false\n done\n", "positive_code": [{"source_code": "let _ =\n let mm = 1000000000 in\n let mmm = 1000000000l in\n let mmmm = 1000000000L in\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let add x y =\n let r =\n Int32.to_int\n\t(Int32.rem\n\t (Int32.add\n\t (Int32.of_int x)\n\t (Int32.of_int y))\n\t mmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let mul x y =\n let r =\n Int64.to_int\n\t(Int64.rem\n\t (Int64.mul\n\t (Int64.of_int x)\n\t (Int64.of_int y))\n\t mmmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let o = 131072 * 2 in\n (*let o = 16 in*)\n let fib = Array.make (o + 1) 0 in\n let _ =\n fib.(1) <- 1;\n for i = 2 to o do\n fib.(i) <- add fib.(i - 1) fib.(i - 2)\n done\n in\n let d = Array.make (o + 1) 0 in\n let shift pos ofs v =\n let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (add v (-d.(pos)))) in\n (*Printf.printf \"shift %d %d %d %d %d -> %d\\n\" pos ofs v d.(pos) fib.(ofs + 1) res;*)\n res\n in\n let a = Array.make (2 * o) 0 in\n let rec update i x l r k =\n if l = r then (\n a.(k) <- x;\n ) else (\n let m = (l + r) / 2 in\n\tif i <= m\n\tthen update i x l m (2 * k + 1)\n\telse update i x (m + 1) r (2 * k + 2);\n\tlet a1 = a.(2 * k + 1) in\n\tlet a2 = a.(2 * k + 2) in\n\t a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);\n )\n in\n let rec rmq x y l r k =\n if x <= l && r <= y\n then (\n a.(k)\n ) else (\n let m = (l + r) / 2 in\n\tif m < x\n\tthen rmq x y (m + 1) r (2 * k + 2)\n\telse if m >= y\n\tthen rmq x y l m (2 * k + 1)\n\telse\n\t let a1 = rmq x y l m (2 * k + 1)\n\t and a2 = rmq x y (m + 1) r (2 * k + 2) in\n\t add a1 (shift (m + 1) (m - x + 1) a2)\n )\n in\n let () =\n for i = 1 to n do\n d.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n update i d.(i) 1 o 0\n done;\n in\n for k = 1 to m do\n(*for j = 0 to Array.length a - 1 do\n Printf.printf \"%d \" a.(j);\ndone;\nPrintf.printf \"\\n\";*)\n let op = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tmatch op with\n\t | 1 ->\n\t let i = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t\td.(i) <- v;\n\t | 2 ->\n\t let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let res = ref 0 in\n\t\tfor i = l to r do\n\t\t res := add !res (mul fib.(i - l + 1) d.(i))\n\t\tdone;\n\t\tPrintf.printf \"%d\\n\" !res;\n\t | _ -> assert false\n done\n"}], "negative_code": [{"source_code": "let _ =\n let mm = 1000000000 in\n let mmm = 1000000000l in\n let mmmm = 1000000000L in\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let add x y =\n let r =\n Int32.to_int\n\t(Int32.rem\n\t (Int32.add\n\t (Int32.of_int x)\n\t (Int32.of_int y))\n\t mmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let mul x y =\n let r =\n Int64.to_int\n\t(Int64.rem\n\t (Int64.mul\n\t (Int64.of_int x)\n\t (Int64.of_int y))\n\t mmmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let o = 131072 * 2 in\n (*let o = 8 in*)\n let fib = Array.make (o + 1) 0 in\n let _ =\n fib.(1) <- 1;\n for i = 2 to o do\n fib.(i) <- add fib.(i - 1) fib.(i - 2)\n done\n in\n let d = Array.make (o + 1) 0 in\n let shift pos ofs v =\n let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (add v (-d.(pos)))) in\n (*Printf.printf \"shift %d %d %d %d %d -> %d\\n\" pos ofs v d.(pos) fib.(ofs + 1) res;*)\n res\n in\n let a = Array.make (2 * o) 0 in\n let rec update i x l r k =\n if l = r then (\n a.(k) <- x;\n ) else (\n let m = (l + r) / 2 in\n\tif i <= m\n\tthen update i x l m (2 * k + 1)\n\telse update i x (m + 1) r (2 * k + 2);\n\tlet a1 = a.(2 * k + 1) in\n\tlet a2 = a.(2 * k + 2) in\n\t a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);\n )\n in\n let rec rmq x y l r k =\n if x <= l && r <= y\n then (\n a.(k)\n ) else (\n let m = (l + r) / 2 in\n\tif m < x\n\tthen rmq x y (m + 1) r (2 * k + 2)\n\telse if m >= y\n\tthen rmq x y l m (2 * k + 1)\n\telse\n\t let a1 = rmq x y l m (2 * k + 1)\n\t and a2 = rmq x y (m + 1) r (2 * k + 2) in\n\t add a1 (shift (m + 1) (m - x + 1) a2)\n )\n in\n let () =\n for i = 1 to n do\n d.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n update i d.(i) 1 o 0\n done;\n in\n for k = 1 to m do\n(*for j = 0 to Array.length a - 1 do\n Printf.printf \"%d \" a.(j);\ndone;\nPrintf.printf \"\\n\";*)\n let op = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tmatch op with\n\t | 1 ->\n\t let i = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t\td.(i) <- v;\n\t\tupdate i v 1 o 0;\n\t | 2 ->\n\t let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let res = rmq l r 1 o 0 in\n\t\tPrintf.printf \"%d\\n\" res;\n\t | _ -> assert false\n done\n"}, {"source_code": "let _ =\n let mm = 1000000000 in\n let mmm = 1000000000l in\n let mmmm = 1000000000L in\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let add x y =\n let r =\n Int32.to_int\n\t(Int32.rem\n\t (Int32.add\n\t (Int32.of_int x)\n\t (Int32.of_int y))\n\t mmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let mul x y =\n let r =\n Int64.to_int\n\t(Int64.rem\n\t (Int64.mul\n\t (Int64.of_int x)\n\t (Int64.of_int y))\n\t mmmm)\n in\n if r < 0\n then r + mm\n else r\n in\n let o = 131072 * 2 in\n (*let o = 8 in*)\n let fib = Array.make (o + 1) 0 in\n let _ =\n fib.(1) <- 1;\n for i = 2 to o do\n fib.(i) <- add fib.(i - 1) fib.(i - 2)\n done\n in\n let d = Array.make (o + 1) 0 in\n let shift pos ofs v =\n let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (v - d.(pos))) in\n (*Printf.printf \"shift %d %d %d %d %d -> %d\\n\" pos ofs v d.(pos) fib.(ofs + 1) res;*)\n res\n in\n let a = Array.make (2 * o) 0 in\n let rec update i x l r k =\n if l = r then (\n a.(k) <- x;\n ) else (\n let m = (l + r) / 2 in\n\tif i <= m\n\tthen update i x l m (2 * k + 1)\n\telse update i x (m + 1) r (2 * k + 2);\n\tlet a1 = a.(2 * k + 1) in\n\tlet a2 = a.(2 * k + 2) in\n\t a.(k) <- add a1 (shift (m + 1) (m - l + 1) a2);\n )\n in\n let rec rmq x y l r k =\n if x <= l && r <= y\n then (\n a.(k)\n ) else (\n let m = (l + r) / 2 in\n\tif m < x\n\tthen rmq x y (m + 1) r (2 * k + 2)\n\telse if m >= y\n\tthen rmq x y l m (2 * k + 1)\n\telse\n\t let a1 = rmq x y l m (2 * k + 1)\n\t and a2 = rmq x y (m + 1) r (2 * k + 2) in\n\t add a1 (shift (m + 1) (m - x + 1) a2)\n )\n in\n let () =\n for i = 1 to n do\n d.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n update i d.(i) 1 o 0\n done;\n in\n for k = 1 to m do\n(*for j = 0 to Array.length a - 1 do\n Printf.printf \"%d \" a.(j);\ndone;\nPrintf.printf \"\\n\";*)\n let op = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tmatch op with\n\t | 1 ->\n\t let i = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t\td.(i) <- v;\n\t\tupdate i v 1 o 0;\n\t | 2 ->\n\t let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let res = rmq l r 1 o 0 in\n\t\tPrintf.printf \"%d\\n\" res;\n\t | _ -> assert false\n done\n"}, {"source_code": "let _ =\n let mm = 1000000000 in\n let mmm = 1000000000l in\n let mmmm = 1000000000L in\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let add x y =\n Int32.to_int\n (Int32.rem\n\t (Int32.add\n\t (Int32.of_int x)\n\t (Int32.of_int y))\n\t mmm)\n in\n let mul x y =\n Int64.to_int\n (Int64.rem\n\t (Int64.mul\n\t (Int64.of_int x)\n\t (Int64.of_int y))\n\t mmmm)\n in\n let o = 131072 * 2 in\n (*let o = 8 in*)\n let fib = Array.make (o + 1) 0 in\n let _ =\n fib.(1) <- 1;\n for i = 2 to o do\n fib.(i) <- add fib.(i - 1) fib.(i - 2)\n done\n in\n let d = Array.make (o + 1) 0 in\n let shift pos ofs v =\n let res = add (mul fib.(ofs + 1) v) (mul fib.(ofs) (v - d.(pos))) in\n (*Printf.printf \"shift %d %d %d %d %d -> %d\\n\" pos ofs v d.(pos) fib.(ofs + 1) res;*)\n res\n in\n let a = Array.make (2 * o) 0 in\n let rec update i x l r k =\n if l = r then (\n a.(k) <- x;\n ) else (\n let m = (l + r) / 2 in\n\tif i <= m\n\tthen update i x l m (2 * k + 1)\n\telse update i x (m + 1) r (2 * k + 2);\n\tlet a1 = a.(2 * k + 1) in\n\tlet a2 = a.(2 * k + 2) in\n\t a.(k) <- a1 + shift (m + 1) (m - l + 1) a2;\n )\n in\n let rec rmq x y l r k =\n if x <= l && r <= y\n then (\n a.(k)\n ) else (\n let m = (l + r) / 2 in\n\tif m < x\n\tthen rmq x y (m + 1) r (2 * k + 2)\n\telse if m >= y\n\tthen rmq x y l m (2 * k + 1)\n\telse\n\t let a1 = rmq x y l m (2 * k + 1)\n\t and a2 = rmq x y (m + 1) r (2 * k + 2) in\n\t a1 + shift (m + 1) (m - x + 1) a2\n )\n in\n let () =\n for i = 1 to n do\n d.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s);\n update i d.(i) 1 o 0\n done;\n in\n for k = 1 to m do\n(*for j = 0 to Array.length a - 1 do\n Printf.printf \"%d \" a.(j);\ndone;\nPrintf.printf \"\\n\";*)\n let op = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\tmatch op with\n\t | 1 ->\n\t let i = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let v = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t\td.(i) <- v;\n\t\tupdate i v 1 o 0;\n\t | 2 ->\n\t let l = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let r = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let res = rmq l r 1 o 0 in\n\t\tPrintf.printf \"%d\\n\" res;\n\t | _ -> assert false\n done\n"}], "src_uid": "165467dd842b47bc2d932b04e85ae8d7"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\n\r\nlet rec read_log_lengths = function\r\n | 0 -> []\r\n | n -> (read_int ())::(read_log_lengths (n-1))\r\n;;\r\n\r\nlet rec get_num_moves = function\r\n | 0 -> 0\r\n | n -> \r\n let log_length=read_int () in\r\n log_length-1 + get_num_moves (n-1)\r\n;;\r\n\r\n(* Moves | Length 0 | 1, 1 | 2, 2 | 3, 3 | 4 *)\r\nlet calculate_test_case = function\r\n | num_moves ->\r\n if (num_moves mod 2 == 0) then \"maomao90\"\r\n else \"errorgorn\"\r\n\r\n;;\r\n\r\nlet rec iterate_through_cases = function\r\n | 0 -> 0\r\n | n -> \r\n let num_logs = read_int () in\r\n let num_moves = get_num_moves num_logs in\r\n print_string (calculate_test_case num_moves);\r\n print_newline ();\r\n iterate_through_cases (n-1)\r\n;;\r\n\r\nlet num_cases = read_int () in\r\niterate_through_cases num_cases;;", "positive_code": [{"source_code": "let parse len str = let rep = Array.make len (-1) in\r\n let temp = ref \"\" in\r\n let j = ref 0 in\r\n for i = 0 to String.length str -1 do\r\n if str.[i] = ' ' then \r\n (rep.(!j) <- (int_of_string !temp) ; incr j ; temp:=\"\" ) \r\n else \r\n (temp:= !temp ^ (String.make 1 str.[i]))\r\n done; rep.(!j) <- (int_of_string !temp) ;rep\r\n;; \r\n\r\nlet n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let len = int_of_string (input_line stdin) in\r\n let str = (input_line stdin) in\r\n let tab = parse len str in\r\n let rep = ref 0 in\r\n for j = 0 to len -1 do\r\n rep := !rep + tab.(j) -1\r\n done;\r\n if !rep mod 2 = 1 then \r\n print_endline \"errorgorn\"\r\n else \r\n print_endline \"maomao90\"\r\ndone;;"}], "negative_code": [], "src_uid": "fc75935b149cf9f4f2ddb9e2ac01d1c2"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\n\r\nlet rec max_int_from_input max = function\r\n | 0 -> max\r\n | n -> \r\n let new_in = read_int () in \r\n if (max < new_in) then max_int_from_input new_in (n-1)\r\n else max_int_from_input max (n-1)\r\n;;\r\n\r\nlet rec run_test_case = function\r\n | 0 -> 0\r\n | n ->\r\n let num_alice = read_int () in\r\n let max_alice = max_int_from_input 0 num_alice in\r\n let num_bob = read_int () in\r\n let max_bob = max_int_from_input 0 num_bob in\r\n if (max_alice > max_bob) then begin\r\n print_string \"Alice\\n\";\r\n print_string \"Alice\\n\";\r\n run_test_case (n-1)\r\n end\r\n else if (max_alice == max_bob) then begin\r\n print_string \"Alice\\n\";\r\n print_string \"Bob\\n\";\r\n run_test_case (n-1)\r\n end\r\n else begin\r\n print_string \"Bob\\n\";\r\n print_string \"Bob\\n\";\r\n run_test_case (n-1)\r\n end\r\n;;\r\n\r\nlet num_cases = read_int () in\r\nrun_test_case num_cases;;", "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 maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () =\n\n let cases = read_int()in\n for case = 1 to cases do\n let n = read_int() in\n let a = Array.init n read_int in\n let m = read_int() in\n let b = Array.init m read_int in\n let maxa = maxf 0 (n-1) (fun i -> a.(i)) in\n let maxb = maxf 0 (m-1) (fun i -> b.(i)) in\n printf \"%s\\n\" (if maxa >= maxb then \"Alice\" else \"Bob\");\n printf \"%s\\n\" (if maxb >= maxa then \"Bob\" else \"Alice\"); \n done\n"}], "negative_code": [], "src_uid": "581c89736e549300c566e4700b741906"} {"source_code": "open Scanf;;\nopen Printf;;\n\nlet rec head n ls =\n match (n, ls) with\n (0, _) -> []\n | (n, []) -> failwith \"\"\n | (n, x::xs) -> x :: (head (n - 1) xs)\n\nlet n, k = scanf \"%d %d \" (fun x y -> x, y);;\nlet arr = Array.make (2 * n + 1) 0;;\n\nfor i = 0 to 2 * n do\n arr.(i) <- (scanf \"%d \" (fun x -> x))\ndone;;\n\nlet main () = \n let rec loop i res =\n if i >= 2 * n then res\n else if arr.(i - 1) + 1 < arr.(i) && arr.(i) > arr.(i + 1) + 1 then\n loop (i + 2) (i :: res)\n else loop (i + 2) res in\n let res = head k (loop 1 []) in\n List.iter (fun i -> arr.(i) <- (arr.(i) - 1)) res;;\n\nmain ();;\n\nfor i = 0 to 2 * n do\n printf \"%d \" arr.(i)\ndone;;\nprintf \"\\n\"\n", "positive_code": [{"source_code": "let _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let k = ref (Scanf.scanf \" %d\" (fun x -> x)) in\n let a = Array.create (2*n+1) 0 in\n for i = 0 to 2 * n do\n a.(i) <- Scanf.scanf \" %d\" (fun x -> x)\n done;\n for i = 0 to n - 1 do\n let j = 2*i+1 in\n if !k > 0 && a.(j) > a.(j-1) + 1 && a.(j) > a.(j+1) + 1 then begin\n k := !k - 1;\n a.(j) <- a.(j) - 1\n end\n done;\n print_string (String.concat \" \" (List.map string_of_int (Array.to_list a)))\n;;\n"}], "negative_code": [{"source_code": "open Scanf;;\nopen Printf;;\n\nlet rec head n ls =\n match (n, ls) with\n (0, _) -> []\n | (n, []) -> failwith \"\"\n | (n, x::xs) -> x :: (head (n - 1) xs)\n\nlet n, k = scanf \"%d %d \" (fun x y -> x, y);;\nlet arr = Array.make (2 * n + 1) 0;;\n\nfor i = 0 to 2 * n do\n arr.(i) <- (scanf \"%d \" (fun x -> x))\ndone;;\n\nlet main () = \n let rec loop i res =\n if i >= 2 * n then res\n else if arr.(i - 1) + 1 < arr.(i) && arr.(i) > arr.(i - 1) + 1 then\n loop (i + 2) (i :: res)\n else loop (i + 2) res in\n let res = head k (loop 1 []) in\n List.iter (fun i -> arr.(i) <- (arr.(i) - 1)) res;;\n\nmain ();;\n\nfor i = 0 to 2 * n do\n printf \"%d \" arr.(i)\ndone;;\nprintf \"\\n\"\n"}], "src_uid": "1adb4675dc88208f8a05a2db49bb44cb"} {"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet () =\n let t = read_int () in\n\n for _ = 1 to t do\n let n = read_int () in\n let k = read_int () in\n let a = read_array read_int n in\n let ans = ref 0 in\n for i = 0 to k - 1 do\n if (a.(i) > k) then ans := !ans + 1;\n done;\n pf \"%d\\n\" !ans;\n done", "positive_code": [{"source_code": "let get_num () =\n let rec f acc =\n try\n let c = input_byte stdin in\n if int_of_char '0' <= c && c <= int_of_char '9' then\n f ((acc * 10) + c - int_of_char '0')\n else if acc > 0 then Some acc\n else None\n with End_of_file -> if acc > 0 then Some acc else None\n in\n f 0\n\nlet solve_case () =\n match (get_num (), get_num ()) with\n | Some n, Some k ->\n let rec f i ans =\n let i = i + 1 in\n if i > n then print_int ans\n else\n match get_num () with\n | Some p ->\n let ans = if i <= k && p > k then ans + 1 else ans in\n f i ans\n | _ -> exit 1\n in\n f 0 0\n | _ -> ()\n\nlet () =\n match get_num () with\n | Some t ->\n let rec f i =\n if i = 0 then ()\n else\n let () = solve_case () in\n let () = print_newline () in\n f (i - 1)\n in\n f t\n | _ -> exit 1\n"}], "negative_code": [], "src_uid": "10927dcb59007fc3a31fdb6b5d13846f"} {"source_code": "(* Codeforces 248C Football Robot Electronic *)\n\nopen Big_int;;\nopen List;;\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;;\n\nlet rec readlist n acc = match n with\n\t| 0 -> List.rev acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\n\nlet rec sumab a b l = \n\tif a>1 then (sumab (a-1) (b-1) (List.tl l))\n\telse if b>1 then ((List.hd l) + (sumab 0 (b-1) (List.tl l)))\n\telse 0;;\n\nlet debug = false;;\n\nlet main () =\n\tlet n = gr() in\n\tlet d = readlist (n-1) [] in\n\tlet a = gr() in\n\tlet b = gr() in\n\tlet sab = sumab a b d in\n\tbegin\n\t\t(* printlisti d; *)\n\t\t(* print_string \"\\n now result\\n\"; *)\n\t print_int sab\n\tend;;\n\nmain();;\n", "positive_code": [{"source_code": "open Scanf;;\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x);;\nlet aa = Array.make (n-1) 0;;\n\nfor i = 0 to n - 2 do\n let x = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun y->y) in\n aa.(i) <- x\ndone\n;;\n\nlet (a,b) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d \" (fun x y->(x,y) );;\nif b <= a then\n begin\n print_int 0; print_endline \"\";\n end\nelse\n let rslt=ref 0 in\n let () = \n for j = (a-1) to (b-2) do\n rslt := !rslt + aa.(j)\n done in print_int !rslt; print_endline \"\"\n;;\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "69850c2af99d60711bcff5870575e15e"} {"source_code": "Array.(Scanf.scanf \" %s %s\" @@ fun s t ->\n let f s =\n init (String.length s) (fun i -> s.[i])\n |> map (function\n | 'a' | 'i' | 'u' | 'e' | 'o' -> 1\n | _ -> 0) in\n print_endline @@ if f s = f t then \"Yes\" else \"No\")", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_str _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let s = read_str() in\n let t = read_str() in\n\n let isvowel c =\n c='a' || c='e' || c='i' || c='o' || c='u' \n in\n \n let f s =\n let n = String.length s in\n Array.init n (fun i -> isvowel s.[i])\n in\n\n if (f s) = (f t) then printf \"Yes\\n\" else printf \"No\\n\""}, {"source_code": "let is_vowel c = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';;\n\nlet rec is_transformable a b i j na nb = na == nb && (if i < na && j < nb then (is_vowel (String.get a i)) == (is_vowel (String.get b j)) && (is_transformable a b (i + 1) (j + 1) na nb) else true);;\n\nlet a = read_line() in\nlet b = read_line() in\nprint_string (if is_transformable a b 0 0 (String.length a) (String.length b) then \"Yes\" else \"No\");;\n"}], "negative_code": [{"source_code": "let is_vowel c = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';;\n\nlet is_transformable a b i j na nb = na == nb && i < na && j < nb && (is_vowel (String.get a i)) == (is_vowel (String.get b j));;\n\nlet a = read_line() in\nlet b = read_line() in\nprint_string (if is_transformable a b 0 0 (String.length a) (String.length b) then \"Yes\" else \"No\");;\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n\nlet read_str _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let s = read_str() in\n let t = read_str() in\n\n let isvowel c =\n c='a' || c='e' || c='i' || c='o' || c='u' \n in\n \n let f s =\n let n = String.length s in\n Array.init n (fun i -> isvowel s.[i])\n in\n\n let alldiff s t =\n let n = String.length s in\n let m = String.length t in\n m = n && (forall 0 (n-1) (fun i -> s.[i] <> t.[i]))\n in\n\n if (f s) = (f t) && (alldiff s t) then printf \"Yes\\n\" else printf \"No\\n\"\n"}], "src_uid": "2b346d5a578031de4d19edb4f8f2626c"} {"source_code": "\n(* --- *)\nexception UnwrapNone\n\nlet unwrap v = match v with Some x -> x | _ -> raise UnwrapNone\n\n(* -- *)\nmodule RandomizedSet = struct\n type ('a, 'b) t =\n { hash: ('b, int) Hashtbl.t\n ; arr: 'a option array\n ; mutable size: int\n ; cap: int }\n\n let create cap =\n {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}\n\n let is_empty set = set.size = 0\n\n let is_full set = set.size = set.cap\n\n let insert set v =\n let {hash; arr; cap} = set in\n match (Hashtbl.mem hash v, is_full set) with\n | true, _ | _, true -> false\n | _ ->\n arr.(set.size) <- Some v ;\n Hashtbl.replace hash v set.size ;\n set.size <- set.size + 1 ;\n true\n\n let remove set v =\n let {hash; arr; cap} = set in\n if Hashtbl.mem hash v then (\n let i = Hashtbl.find hash v in\n let another = arr.(set.size - 1) in\n if i <> set.size - 1 then (\n arr.(i) <- another ;\n Hashtbl.replace hash (unwrap another) i ) ;\n set.size <- set.size - 1 ;\n Hashtbl.remove hash v ;\n true )\n else false\n\n let get_random set =\n if is_empty set then None else set.arr.(Random.int set.size)\nend\n\n(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nexception InputError of string\n\nlet read_into_int_list () =\n read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string\n\n(* --- *)\nlet do_case () =\n match read_into_int_list () with\n | [vertices_count; edges_count] ->\n let degs = Array.make (vertices_count + 1) 0 in\n let adj =\n Array.init (vertices_count + 1) (fun _ ->\n RandomizedSet.create vertices_count )\n in\n (* read in edges *)\n for i = 1 to edges_count do\n match read_into_int_list () with\n | [one; another] ->\n degs.(one) <- degs.(one) + 1 ;\n degs.(another) <- degs.(another) + 1 ;\n RandomizedSet.insert adj.(one) (one, another) ;\n RandomizedSet.insert adj.(another) (one, another)\n | _ -> raise @@ InputError \"unexpected edge input\"\n done ;\n (* connect all odd vertices with an additional one *)\n let addv_i = 0 in\n let even_count = ref 0 in\n for i = 1 to vertices_count do\n if degs.(i) mod 2 <> 0 then (\n let e = (i, addv_i) in\n RandomizedSet.insert adj.(i) e ;\n RandomizedSet.insert adj.(addv_i) e ;\n () )\n else even_count := !even_count + 1\n done ;\n Printf.printf \"%d\\n\" !even_count ;\n (* dfs *)\n let rec dfs v =\n while not @@ RandomizedSet.is_empty adj.(v) do\n match RandomizedSet.get_random adj.(v) with\n | Some ((one, another) as e) ->\n let next = if one = v then another else one in\n RandomizedSet.remove adj.(v) e ;\n RandomizedSet.remove adj.(next) e ;\n if next <> addv_i && v <> addv_i then\n Printf.printf \"%d %d\\n\" v next ;\n dfs next\n | None -> ()\n done\n in\n for i = 0 to vertices_count do\n dfs i\n done\n | _ -> raise @@ InputError \"unexpected vertice_count and edges_count input\"\n\n(* --- *)\nlet test_case_count = read_line () |> int_of_string\n\n;;\nfor i = 1 to test_case_count do\n do_case ()\ndone\n", "positive_code": [{"source_code": "\nlet zip xs ys =\n let rec h accu xs' ys' =\n match (xs', ys') with\n | [], _ | _, [] -> accu\n | x :: xr, y :: yr -> h ((x, y) :: accu) xr yr\n in\n h [] xs ys\n\n(* --- *)\nexception UnwrapNone\n\nlet unwrap v = match v with Some x -> x | _ -> raise UnwrapNone\n\n(* -- *)\nmodule RandomizedSet = struct\n type ('a, 'b) t =\n { hash: ('b, int) Hashtbl.t\n ; arr: 'a option array\n ; mutable size: int\n ; cap: int }\n\n let create cap =\n {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}\n\n let is_empty set = set.size = 0\n\n let is_full set = set.size = set.cap\n\n let insert set v =\n let {hash; arr; cap} = set in\n match (Hashtbl.mem hash v, is_full set) with\n | true, _ -> false\n | _, true -> false\n | _ ->\n arr.(set.size) <- Some v ;\n Hashtbl.replace hash v set.size ;\n set.size <- set.size + 1 ;\n true\n\n let remove set v =\n let {hash; arr; cap} = set in\n if Hashtbl.mem hash v then (\n let i = Hashtbl.find hash v in\n let another = arr.(set.size - 1) in\n if i <> set.size - 1 then (\n arr.(i) <- another ;\n Hashtbl.replace hash (unwrap another) i ) ;\n set.size <- set.size - 1 ;\n Hashtbl.remove hash v ;\n true )\n else false\n\n let get_next set = if is_empty set then None else set.arr.(0)\nend\n\n(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nexception InputError of string\n\nlet read_into_int_list () =\n read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string\n\n(* --- *)\ntype 'a edge = {from: 'a; to': 'a}\n\nlet identify {from; to'} =\n let f' = string_of_int from and t' = string_of_int to' in\n if from < to' then f' ^ \"-\" ^ t' else t' ^ \"-\" ^ f'\n\n(* --- *)\n\nlet do_case () =\n match read_into_int_list () with\n | [vertices_count; edges_count] ->\n let degs = Array.make (vertices_count + 1) 0 in\n let adj =\n Array.init (vertices_count + 1) (fun _ ->\n RandomizedSet.create vertices_count )\n in\n (* read in edges *)\n for i = 1 to edges_count do\n match read_into_int_list () with\n | [from; to'] ->\n degs.(from) <- degs.(from) + 1 ;\n degs.(to') <- degs.(to') + 1 ;\n RandomizedSet.insert adj.(from) {from; to'} ;\n RandomizedSet.insert adj.(to') {from; to'}\n | _ -> raise @@ InputError \"unexpected edge input\"\n done ;\n (* connect all odd vertices with an additional one *)\n let addv_i = 0 in\n let even_count = ref 0 in\n for i = 1 to vertices_count do\n if degs.(i) mod 2 <> 0 then (\n let e = {from= i; to'= addv_i} in\n RandomizedSet.insert adj.(i) e ;\n RandomizedSet.insert adj.(addv_i) e ;\n () )\n else even_count := !even_count + 1\n done ;\n Printf.printf \"%d\\n\" !even_count ;\n (* dfs *)\n let passed_vertices = ref [] in\n (* used to indicate that one vertex has been found in one component *)\n let is_vertex_visited = Array.make (vertices_count + 1) false in\n let rec dfs v =\n while not @@ RandomizedSet.is_empty adj.(v) do\n match RandomizedSet.get_next adj.(v) with\n | Some e ->\n let next = if e.from = v then e.to' else e.from in\n RandomizedSet.remove adj.(v) e ;\n RandomizedSet.remove adj.(next) e ;\n dfs next\n | None -> ()\n done ;\n is_vertex_visited.(v) <- true ;\n passed_vertices := v :: !passed_vertices\n in\n for i = 0 to vertices_count do\n if not is_vertex_visited.(i) then (\n (* reset passed_vertices when entering a new component *)\n passed_vertices := [] ;\n dfs i ;\n (* get path from passed_vertices within current component *)\n List.fold_left\n (fun es ((a, b) as e) ->\n if a = addv_i || b = addv_i then es else e :: es )\n []\n @@ zip !passed_vertices @@ List.tl !passed_vertices\n |> List.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" a b) )\n done\n | _ -> raise @@ InputError \"unexpected vertice_count and edges_count input\"\n\n(* --- *)\nlet test_case_count = read_line () |> int_of_string\n\n;;\nfor i = 1 to test_case_count do\n do_case () ;\ndone\n"}, {"source_code": "let zip xs ys =\n let rec h accu xs' ys' =\n match (xs', ys') with\n | [], _ | _, [] -> accu\n | x :: xr, y :: yr -> h ((x, y) :: accu) xr yr\n in\n h [] xs ys\n\n(* --- *)\nexception UnwrapNone\n\nlet unwrap v = match v with Some x -> x | _ -> raise UnwrapNone\n\n(* -- *)\nmodule RandomizedSet = struct\n type ('a, 'b) t =\n { hash: ('b, int) Hashtbl.t\n ; arr: 'a option array\n ; mutable size: int\n ; cap: int }\n\n let create cap =\n {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}\n\n let is_empty set = set.size = 0\n\n let is_full set = set.size = set.cap\n\n let insert set v =\n let {hash; arr; cap} = set in\n match (Hashtbl.mem hash v, is_full set) with\n | true, _ -> false\n | _, true -> false\n | _ ->\n arr.(set.size) <- Some v ;\n Hashtbl.replace hash v set.size ;\n set.size <- set.size + 1 ;\n true\n\n let remove set v =\n let {hash; arr; cap} = set in\n if Hashtbl.mem hash v then (\n let i = Hashtbl.find hash v in\n let another = arr.(set.size - 1) in\n if i <> set.size - 1 then (\n arr.(i) <- another ;\n Hashtbl.replace hash (unwrap another) i ) ;\n set.size <- set.size - 1 ;\n Hashtbl.remove hash v ;\n true )\n else false\n\n let get_next set = if is_empty set then None else set.arr.(0)\nend\n\n(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nexception InputError of string\n\nlet read_into_int_list () =\n read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string\n\n(* --- *)\ntype 'a edge = {from: 'a; to': 'a}\n\n(* --- *)\nlet do_case () =\n match read_into_int_list () with\n | [vertices_count; edges_count] ->\n let degs = Array.make (vertices_count + 1) 0 in\n let adj =\n Array.init (vertices_count + 1) (fun _ ->\n RandomizedSet.create vertices_count )\n in\n (* read in edges *)\n for i = 1 to edges_count do\n match read_into_int_list () with\n | [from; to'] ->\n degs.(from) <- degs.(from) + 1 ;\n degs.(to') <- degs.(to') + 1 ;\n RandomizedSet.insert adj.(from) {from; to'} ;\n RandomizedSet.insert adj.(to') {from; to'}\n | _ -> raise @@ InputError \"unexpected edge input\"\n done ;\n (* connect all odd vertices with an additional one *)\n let addv_i = 0 in\n let even_count = ref 0 in\n for i = 1 to vertices_count do\n if degs.(i) mod 2 <> 0 then (\n let e = {from= i; to'= addv_i} in\n RandomizedSet.insert adj.(i) e ;\n RandomizedSet.insert adj.(addv_i) e ;\n () )\n else even_count := !even_count + 1\n done ;\n Printf.printf \"%d\\n\" !even_count ;\n (* dfs *)\n let rec dfs v =\n while not @@ RandomizedSet.is_empty adj.(v) do\n match RandomizedSet.get_next adj.(v) with\n | Some e ->\n let next = if e.from = v then e.to' else e.from in\n RandomizedSet.remove adj.(v) e ;\n RandomizedSet.remove adj.(next) e ;\n if next <> addv_i && v <> addv_i then\n Printf.printf \"%d %d\\n\" v next ;\n dfs next\n | None -> ()\n done\n in\n for i = 0 to vertices_count do\n dfs i\n done\n | _ -> raise @@ InputError \"unexpected vertice_count and edges_count input\"\n\n(* --- *)\nlet test_case_count = read_line () |> int_of_string\n\n;;\nfor i = 1 to test_case_count do\n do_case ()\ndone\n"}, {"source_code": "(* --- *)\nexception UnwrapNone\n\nlet unwrap v = match v with Some x -> x | _ -> raise UnwrapNone\n\n(* -- *)\nmodule RandomizedSet = struct\n type ('a, 'b) t =\n { hash: ('b, int) Hashtbl.t\n ; arr: 'a option array\n ; mutable size: int\n ; cap: int }\n\n let create cap =\n {hash= Hashtbl.create cap; arr= Array.make cap None; size= 0; cap}\n\n let is_empty set = set.size = 0\n\n let is_full set = set.size = set.cap\n\n let insert set v =\n let {hash; arr; cap} = set in\n match (Hashtbl.mem hash v, is_full set) with\n | true, _ | _, true -> false\n | _ ->\n arr.(set.size) <- Some v ;\n Hashtbl.replace hash v set.size ;\n set.size <- set.size + 1 ;\n true\n\n let remove set v =\n let {hash; arr; cap} = set in\n if Hashtbl.mem hash v then (\n let i = Hashtbl.find hash v in\n let another = arr.(set.size - 1) in\n if i <> set.size - 1 then (\n arr.(i) <- another ;\n Hashtbl.replace hash (unwrap another) i ) ;\n set.size <- set.size - 1 ;\n Hashtbl.remove hash v ;\n true )\n else false\n\n let get_next set = if is_empty set then None else set.arr.(0)\nend\n\n(* --- *)\nlet concat_chars cs = String.concat \"\" (List.map (String.make 1) cs)\n\nlet explode str =\n let exploded = ref [] in\n for i = String.length str - 1 downto 0 do\n exploded := str.[i] :: !exploded\n done ;\n !exploded\n\nlet split_on_char c str =\n let exploded = explode str in\n let cs', pending' =\n List.fold_right\n (fun x (ls, pending) ->\n match (x = c, pending) with\n | false, _ -> (ls, x :: pending)\n | true, [] -> (ls, pending)\n | true, _ -> (pending :: ls, []) )\n exploded ([], [])\n in\n List.map concat_chars (if pending' = [] then cs' else pending' :: cs')\n\n(* --- *)\nexception InputError of string\n\nlet read_into_int_list () =\n read_line () |> String.trim |> split_on_char ' ' |> List.map int_of_string\n\n(* --- *)\nlet do_case () =\n match read_into_int_list () with\n | [vertices_count; edges_count] ->\n let degs = Array.make (vertices_count + 1) 0 in\n let adj =\n Array.init (vertices_count + 1) (fun _ ->\n RandomizedSet.create vertices_count )\n in\n (* read in edges *)\n for i = 1 to edges_count do\n match read_into_int_list () with\n | [one; another] ->\n degs.(one) <- degs.(one) + 1 ;\n degs.(another) <- degs.(another) + 1 ;\n RandomizedSet.insert adj.(one) (one, another) ;\n RandomizedSet.insert adj.(another) (one, another)\n | _ -> raise @@ InputError \"unexpected edge input\"\n done ;\n (* connect all odd vertices with an additional one *)\n let addv_i = 0 in\n let even_count = ref 0 in\n for i = 1 to vertices_count do\n if degs.(i) mod 2 <> 0 then (\n let e = (i, addv_i) in\n RandomizedSet.insert adj.(i) e ;\n RandomizedSet.insert adj.(addv_i) e ;\n () )\n else even_count := !even_count + 1\n done ;\n Printf.printf \"%d\\n\" !even_count ;\n (* dfs *)\n let rec dfs v =\n while not @@ RandomizedSet.is_empty adj.(v) do\n match RandomizedSet.get_next adj.(v) with\n | Some ((one, another) as e) ->\n let next = if one = v then another else one in\n RandomizedSet.remove adj.(v) e ;\n RandomizedSet.remove adj.(next) e ;\n if next <> addv_i && v <> addv_i then\n Printf.printf \"%d %d\\n\" v next ;\n dfs next\n | None -> ()\n done\n in\n for i = 0 to vertices_count do\n dfs i\n done\n | _ -> raise @@ InputError \"unexpected vertice_count and edges_count input\"\n\n(* --- *)\nlet test_case_count = read_line () |> int_of_string\n\n;;\nfor i = 1 to test_case_count do\n do_case ()\ndone\n"}], "negative_code": [], "src_uid": "4f2c2d67c1a84bf449959b06789bb3a7"} {"source_code": "open Scanf\nopen Printf\n\nlet s = scanf \"%s\" (fun n -> n)\n\nlet s' = scanf \" %s\" (fun n -> n)\n\nlet compare s s' =\n let rec loop i i' =\n if i = -1 || i' = -1 then\n i, i'\n else if s.[i] = s'.[i'] then\n loop (i-1) (i'-1)\n else\n i, i'\n in loop (String.length s - 1) (String.length s' - 1)\n\nlet process s s' =\n let i, i' = compare s s' in\n i + i' + 2\n\nlet () =\n let out = process s s' in\n printf \"%d\\n\" out;\n ()\n", "positive_code": [{"source_code": "open Printf\n\nlet char_list_of_string str = \n let rec f0 i a =\n if i<0 then a else f0 (i-1) (str.[i]::a)\n in f0 (String.length str - 1) []\n\nlet print_int_endline n = n |> string_of_int |> print_endline\n\nlet () =\n let rec f0 (lu,lv) = match lu,lv with\n | [],[] -> 0\n | [],rest | rest,[] -> List.length rest\n | p::tlu,q::tlv ->\n if p=q then f0 (tlu,tlv)\n else (List.length tlu + List.length tlv + 2)\n in\n Scanf.scanf \" %s %s\" (fun u v ->\n List.rev @@ char_list_of_string u,\n List.rev @@ char_list_of_string v)\n |> f0 |> printf \"%d\\n\"\n"}], "negative_code": [], "src_uid": "59d926bca19a6dcfe3eb3e3dc03fffd6"} {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\tInt64.to_int(Int64.rem (Int64.add (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n\nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\nlet init_binomial n 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 sum b.(i-1).(j-1) b.(i-1).(j)\n done done;\n b\n;;\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\nlet bb = init_binomial n n in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\ns.(1) <- n - k;\ns.(2) <- 1;\n\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 then begin \t\t\n\t\t\tif s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));\t\t\n\t\t\ts.(4) <- s.(0);\n\t\tend;\n\t\t\n\t\ts.(3) <- 1; \n\t\t\n\t\ts.(2) <- pdt (s.(2)) (bb.(s.(1)).(s.(0)));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\nPrintf.printf \"%d\\n\" s.(2)", "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.rem (Int64.mul a b) mval)\nlet ( ++ ) a b = (Int64.rem (Int64.add a b) mval)\n(* let ( -- ) a b = Int64.sub a b\n let ( // ) 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) 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 init_powers n = \n let p = Array.make (n+1) 1L in\n for i=1 to n do\n p.(i) <- p.(i-1) ++ p.(i-1)\n done;\n p\n\nlet () =\n let n = read_int() in\n let m = read_int() in\n let on = Array.make (m+2) 0 in\n let () = for i=1 to m do\n on.(i) <- read_int();\n done in\n\n let () = on.(m+1) <- n+1 in\n\n let () = Array.sort compare on in\n\n let bi = init_binomial n n in\n let po = init_powers n in\n\n let rec find_gaps i stop ac = if i=stop then ac else\n (* consider gap from on.(i-1) to on.(i) *)\n if on.(i-1) + 1 = on.(i) then find_gaps (i+1) stop ac else\n find_gaps (i+1) stop ((on.(i) - on.(i-1) - 1) :: ac)\n in\n\n let gaps = find_gaps 1 (m+2) [] in\n let gaps = Array.of_list gaps in\n let g = Array.length gaps in\n\n let rec bloop i s ac = if i=g then ac else\n let s = s+gaps.(i) in\n let ac = ac ** bi.(s).(gaps.(i)) in\n bloop (i+1) s ac\n in\n\n let mix_count = bloop 0 0 1L in\n\n let pgaps = find_gaps 2 (m+1) [] in\n\n let rec ploop gl ac = match gl with [] -> ac\n | g::gl -> ploop gl (po.(g-1) ** ac)\n in\n let pow_count = ploop pgaps 1L in\n\n Printf.printf \"%Ld\\n\" (pow_count ** mix_count);\n"}], "negative_code": [{"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\n\ns.(1) <- n - k;\ns.(2) <- 1;\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);\n\t\tif (s.(0) > 0) then begin s.(3) <- 1; s.(4) <- s.(0); end;\n\t\ts.(2) <- pdt (s.(2)) (comb s.(1) s.(0));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\n\nPrintf.printf \"%d\\n\" s.(2)\n\n(*\n(pdt (pow k (k-1)) (pow (n-k) (n-k)))\n*)"}, {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\ns.(1) <- n - k;\ns.(2) <- 1;\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 && s.(4) > 0 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);\t\t\n\t\ts.(3) <- 1; s.(4) <- s.(0);\t\t\t\t\t\t\t\t\t\n\t\ts.(2) <- pdt (s.(2)) (comb s.(1) s.(0));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\nPrintf.printf \"%d\\n\" s.(2)\n\n(*\n(pdt (pow k (k-1)) (pow (n-k) (n-k)))\n*)"}, {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n) <- 1;\n\n\ns.(1) <- n - k;\ns.(2) <- 1;\n\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 then s.(2) <- pdt (s.(2)) ((pow 2 s.(4)) - 1);\n\t\ts.(3) <- 1; \n\t\ts.(4) <- s.(0);\n\t\ts.(2) <- pdt (s.(2)) (comb s.(1) s.(0));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\n\nPrintf.printf \"%d\\n\" s.(2)\n\n(*\n(pdt (pow k (k-1)) (pow (n-k) (n-k)))\n*)"}, {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\ns.(1) <- n - k;\ns.(2) <- 1;\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif (s.(3) = 1) && (s.(4) > 0) then begin \n\t\t\ts.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));\t\t\n\t\t\ts.(4) <- s.(0);\n\t\tend;\n\t\t\n\t\ts.(3) <- 1; \n\t\t\n\t\ts.(2) <- pdt (s.(2)) (comb s.(1) s.(0));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\nPrintf.printf \"%d\\n\" s.(2)\n\n(*\n(pdt (pow k (k-1)) (pow (n-k) (n-k)))\n*)"}, {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n\nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\nlet init_binomial n 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 sum b.(i-1).(j-1) b.(i-1).(j)\n done done;\n b\n;;\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\nlet bb = init_binomial n n in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\ns.(1) <- n - k;\ns.(2) <- 1;\n\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 then begin \t\t\n\t\t\tif s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));\t\t\n\t\t\ts.(4) <- s.(0);\n\t\tend;\n\t\t\n\t\ts.(3) <- 1; \n\t\t\n\t\ts.(2) <- pdt (s.(2)) (bb.(s.(1)).(s.(0)));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\nPrintf.printf \"%d\\n\" s.(2)"}, {"source_code": "open Int64\n\nlet read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet mmod = 1000000007\n\nlet sum a b =\n\t(a + b) mod mmod\n;;\n\nlet pdt a b =\n\tInt64.to_int(Int64.rem (Int64.mul (Int64.of_int a) (Int64.of_int b)) (Int64.of_int mmod))\n;;\n \nlet rec pow a n =\n\tif n=0 then 1 else\n\tlet b = pow a (n/2) in\n\tif (n mod 2) = 0 then pdt b b else pdt a (pdt b b)\n ;;\n \n let rec comb n m =\n\tif m = 0 or n = m then 1\n\telse sum (comb(n-1) (m-1)) (comb(n-1) m)\n;;\n\n\nlet n = read_int 0 in\nlet k = read_int 0 in\nlet a = Array.init k read_int in\nlet b = Array.make (n+2) 0 in\nlet s = Array.make 5 0 in\n\nfor i = 0 to k-1 do\t\n\tb.(a.(i)) <- 1\ndone;\n\nb.(n+1) <- 1;\ns.(1) <- n - k;\ns.(2) <- 1;\n\nfor i = 1 to n+1 do\n\tif b.(i) = 0 then s.(0) <- s.(0) + 1\n\telse begin\t\t\t\n\t\tif s.(3) = 1 && s.(4) > 0 then s.(2) <- pdt (s.(2)) (pow 2 (s.(4) - 1));\t\t\n\t\ts.(3) <- 1; s.(4) <- s.(0);\t\t\t\t\t\t\t\t\t\n\t\ts.(2) <- pdt (s.(2)) (comb s.(1) s.(0));\n\t\ts.(1) <- s.(1) - s.(0);\n\t\ts.(0) <- 0;\n\tend;\ndone;\n\n\nPrintf.printf \"%d\\n\" s.(2)\n\n(*\n(pdt (pow k (k-1)) (pow (n-k) (n-k)))\n*)"}], "src_uid": "14da0cdf2939c796704ec548f49efb87"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n printf \"%d\\n\" n\n done\n", "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet show_int n = Printf.printf \"%d\\n\" n;;\n\nlet t = scan_int ();;\nfor x = 1 to t do\n\tlet n = scan_int () in\n\tshow_int n\ndone;;\n"}], "negative_code": [], "src_uid": "740c05c036b646d8fb6b391af115d7f0"} {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \n\nlet s = String.lowercase (read_string ())\nlet n = String.length s\n\nlet start = n\n\nlet leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)\n\nlet is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false\n\n(* we've processed chars 0,1,2...i-1, and have the height and best for that *)\nlet rec fill_leftmost i height best = if i=n then (height,best) else\n if is_vowel s.[i] then (\n leftmost.(height-1) <- min leftmost.(height-1) (i+1);\n fill_leftmost (i+1) (height-1) (max best (i+1-leftmost.(height-1)))\n ) else (\n leftmost.(height+1) <- min leftmost.(height+1) i;\n leftmost.(height+2) <- min leftmost.(height+2) (i+1);\n fill_leftmost (i+1) (height+2) (max best (i+1-leftmost.(height+2)))\n )\n\nlet (height,best) = fill_leftmost 0 start 0\n\nlet rec complete h b = if h<0 then b else\n complete (h-1) (max b (n - leftmost.(h)))\n\nlet best = complete height best\n\nlet cvowel i = if is_vowel s.[i] then 1 else 0\n\n(* vow for the range i....i+best-1, count for the previous one *)\nlet rec count_strings i count vow =\n let count = count + (if vow<=2*(best-vow) then 1 else 0) in\n if i+best-1 = n-1 then count else\n let vow = vow - (cvowel i) + (cvowel (i+best)) in\n count_strings (i+1) count vow\n\nlet rec count_vow i count = \n if i=best then count else count_vow (i+1) (count + (cvowel i))\n\nlet () = \n if best = 0\n then Printf.printf \"No solution\\n\"\n else Printf.printf \"%d %d\\n\" best (count_strings 0 0 (count_vow 0 0))\n", "positive_code": [{"source_code": "\n\nlet getint () = Scanf.scanf \" %d\" (fun i->i)\nlet getstr () = Scanf.bscanf Scanf.Scanning.stdin \"%s\" (fun s -> s)\nlet getval c= \n match c with\n | 'a' | 'e' | 'i' | 'o' | 'u' -> -1\n | _ -> 2\n\nlet _ =\n let s = String.lowercase (getstr ()) in\n let n = String.length s in\n let mn = ref 0 in\n let res = ref ~-1 in\n let mxSub = Array.make 200200 0 in\n let prefix = Array.make 200200 0 in\n let getsum i j = prefix.(j) - (if i=0 then 0 else prefix.(i-1)) in\n for i = 0 to n-1 do\n prefix.(i) <- getval s.[i] + (if i=0 then 0 else prefix.(i-1));\n done;\n for i = 0 to n-1 do\n mxSub.(i) <- prefix.(i) - !mn;\n mn := min !mn prefix.(i);\n let lo = ref 0 and hi = ref i and ans = ref ~-1 in\n while !lo <= !hi do\n let mid = (!lo + !hi) / 2 in\n let right = getsum mid i\n and left = max 0 (if mid=0 then 0 else mxSub.(mid-1)) in\n if left+right>=0 then (ans:= mid; hi := mid-1)\n else lo := mid+1\n done;\n if !ans <> -1 then res := max !res (i - !ans + 1)\n done;\n if !res= -1 then Printf.printf \"No solution\\n\"\n else\n begin\n let cnt = ref 0 in\n for i = 0 to n - !res do\n if getsum i (i + !res - 1) >=0 \n then cnt := !cnt + 1\n done;\n Printf.printf \"%d %d\\n\" !res !cnt\n end"}, {"source_code": "\n\nlet getint () = Scanf.scanf \" %d\" (fun i->i)\nlet getstr () = Scanf.bscanf Scanf.Scanning.stdin \"%s\" (fun s -> s)\nlet getval c= \n\tmatch c with\n\t\t| 'a' | 'e' | 'i' | 'o' | 'u' -> -1\n\t\t| _ -> 2\n\nlet _ =\n let s = String.lowercase (getstr ()) in\n let n = String.length s in\n let mn = ref 0 in\n let res = ref ~-1 in\n let mxSub = Array.make 200200 0 in\n let prefix = Array.make 200200 0 in\n let getsum i j = prefix.(j) - (if i=0 then 0 else prefix.(i-1)) in\n \tfor i = 0 to n-1 do\n \t\tprefix.(i) <- getval s.[i] + (if i=0 then 0 else prefix.(i-1));\n \tdone;\n \tfor i = 0 to n-1 do\n \t\tmxSub.(i) <- prefix.(i) - !mn;\n \t\tmn := min !mn prefix.(i);\n \t\tlet lo = ref 0 and hi = ref i and ans = ref ~-1 in\n \t\t\twhile !lo <= !hi do\n \t\t\t\tlet mid = (!lo + !hi) / 2 in\n\t \t\t\t\tlet right = getsum mid i\n\t \t\t\t\tand left = max 0 (if mid=0 then 0 else mxSub.(mid-1)) in\n\t \t\t\t\t\tif left+right>=0 then (ans:= mid; hi := mid-1)\n\t \t\t\t\t\telse lo := mid+1\n \t\t\tdone;\n \t\t\tif !ans <> -1 then res := max !res (i - !ans + 1)\n \tdone;\n \tif !res= -1 then Printf.printf \"No solution\\n\"\n \telse\n \t\tbegin\n \t\t\tlet cnt = ref 0 in\n\t \t\t\tfor i = 0 to n - !res do\n\t \t\t\t\tif getsum i (i + !res - 1) >=0 \n\t \t\t\t\tthen cnt := !cnt + 1\n\t \t\t\tdone;\n\t \t\t\tPrintf.printf \"%d %d\\n\" !res !cnt\n \t\tend"}, {"source_code": "let main() =\n let f = function\n 'a' | 'e' | 'i' | 'o' | 'u' -> -1\n | _ -> 2\n in\n let s = Scanf.scanf \"%s\" String.lowercase in\n let n = String.length s in\n let a = Array.init n (fun i -> (f s.[i])) in\n let b = Array.create (n+1) 0 in\n Array.iteri (fun i x -> b.(i+1) <- b.(i) + x) a;\n let c = Array.mapi (fun i x -> x, i) b in\n Array.stable_sort (fun x y -> compare (fst x) (fst y)) c;\n let rec g k j maxl tot =\n if k < 0 then maxl, tot\n else\n let i = snd c.(k) in\n if i > j then g (k-1) i maxl tot\n else (\n let l = j - i in\n if l < maxl then g (k-1) j maxl tot\n else g (k-1) j l (if l == maxl then (tot+1) else 1)\n )\n in\n let r,v = g n 0 0 0 in\n if r > 0 then Printf.printf \"%d %d\\n\" r v else Printf.printf \"No solution\\n\"\n ;;\nmain()"}, {"source_code": "let min (x : int) y = if x < y then x else y\n\nlet fr n = n + (n land (-n))\nlet fl n = n land (n - 1)\n\nlet fenwick_new n =\n Array.make (n + 1) 1000000000\n\nlet fenwick_modify ft n x =\n let i = ref n in\n while !i < Array.length ft do\n ft.(!i) <- min ft.(!i) x;\n i := fr !i;\n done\n\nlet fenwick_min ft n =\n let i = ref n in\n let res = ref 1000000000 in\n while !i > 0 do\n res := min !res ft.(!i);\n i := fl !i;\n done;\n !res\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 ft = fenwick_new 800000 in\n let sum = ref 300000 in\n let res = ref (-1) in\n let a = Array.make (n + 1) !sum in\n fenwick_modify ft !sum 0;\n for i = 0 to n - 1 do\n let c = s.[i] in\n\t(match c with\n\t | 'a' | 'e' | 'i' | 'o' | 'u'\n\t | 'A' | 'E' | 'I' | 'O' | 'U' ->\n\t decr sum;\n\t | _ ->\n\t sum := !sum + 2\n\t);\n\tlet l = fenwick_min ft !sum in\n\t (*Printf.printf \"asd %d %d %d\\n\" i !sum l;*)\n\t if l < 1000000000 && i + 1 - l > !res then (\n\t res := i + 1 - l\n\t );\n\t fenwick_modify ft !sum (i + 1);\n\t a.(i + 1) <- !sum\n done;\n if !res < 0\n then Printf.printf \"No solution\\n\"\n else (\n let c = ref 0 in\n\tfor i = !res to n do\n\t if a.(i) - a.(i - !res) >= 0\n\t then incr c\n\tdone;\n\tPrintf.printf \"%d %d\\n\" !res !c;\n )\n"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \n\nlet s = String.lowercase (read_string ())\nlet n = String.length s\n\nlet start = n\n\nlet leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)\n\nlet is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false\n\n(* we've processed chars 0,1,2...i-1, and have the height and best for that *)\nlet rec fill_leftmost i height bc = if i=n then bc else\n let best_count (b,c) nb = if nb < b then (b,c) else if nb = b then (b,c+1) else (nb, 1) in\n if is_vowel s.[i] then (\n leftmost.(height-1) <- min leftmost.(height-1) (i+1);\n fill_leftmost (i+1) (height-1) (best_count bc (i+1-leftmost.(height-1)))\n ) else (\n leftmost.(height+1) <- min leftmost.(height+1) i;\n leftmost.(height+2) <- min leftmost.(height+2) (i+1);\n fill_leftmost (i+1) (height+2) (best_count bc (i+1-leftmost.(height+2)))\n )\n\nlet (best,count) = fill_leftmost 0 start (0,1)\n\nlet () = \n if best = 0\n then Printf.printf \"No solution\\n\"\n else Printf.printf \"%d %d\\n\" best count\n"}], "negative_code": [{"source_code": "let main() =\n let f = function\n 'a' | 'e' | 'i' | 'o' | 'u' | 'y' -> -1\n | _ -> 2\n in\n let s = Scanf.scanf \"%s\" String.lowercase in\n let n = String.length s in\n let a = Array.init n (fun i -> (f s.[i])) in\n let b = Array.create (n+1) 0 in\n Array.iteri (fun i x -> b.(i+1) <- b.(i) + x) a;\n let c = Array.mapi (fun i x -> x, i) b in\n Array.stable_sort (fun x y -> compare (fst x) (fst y)) c;\n let rec g k j maxl tot =\n if k < 0 then maxl, tot\n else\n let i = snd c.(k) in\n if i > j then g (k-1) i maxl tot\n else (\n let l = j - i in\n if l < maxl then g (k-1) j maxl tot\n else g (k-1) j l (if l == maxl then (tot+1) else 1)\n )\n in\n let r,v = g n 0 0 0 in\n if r > 0 then Printf.printf \"%d %d\\n\" r v else Printf.printf \"No solution\\n\"\n ;;\nmain()"}, {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \n\nlet s = String.lowercase (read_string ())\nlet n = String.length s\n\nlet start = n\n\nlet leftmost = Array.init (3*n+1) (fun i -> if i>=start then 0 else max_int/2)\n\nlet is_vowel c = match c with 'a' | 'e' | 'i' | 'o' | 'u' -> true | _ -> false\n\n(* we've processed chars 0,1,2...i-1, and have the height and best for that *)\nlet rec fill_leftmost i height best = if i=n then (height,best) else\n if is_vowel s.[i] then (\n leftmost.(height-1) <- min leftmost.(height-1) (i+1);\n fill_leftmost (i+1) (height-1) (max best (i+1-leftmost.(height-1)))\n ) else (\n leftmost.(height+1) <- min leftmost.(height+1) i;\n leftmost.(height+2) <- min leftmost.(height+2) (i+1);\n fill_leftmost (i+1) (height+2) (max best (i+1-leftmost.(height+2)))\n )\n\nlet (height,best) = fill_leftmost 0 start 0\n\nlet rec complete h b = if h<0 then b else\n complete (h-1) (max b (n - leftmost.(h)))\n\nlet best = complete height best\n\nlet cvowel i = if is_vowel s.[i] then 1 else 0\n\n(* vow for the range i....i+best-1, count for the previous one *)\nlet rec count_strings i count vow =\n let count = count + (if vow<=2*(best-vow) then 1 else 0) in\n if i+best-1 = n-1 then count else\n let vow = vow - (cvowel i) + (cvowel (i+best)) in\n count_strings (i+1) count vow\n\nlet rec count_vow i count = \n if i=best then count else count_vow (i+1) (count + (cvowel i))\n\n;;\n\nPrintf.printf \"%d %d\\n\" best (count_strings 0 0 (count_vow 0 0))\n"}], "src_uid": "763aa950a9a8e5c975a6028e014de20f"} {"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 for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1\n done;\n let u = Array.make n false in\n let cs = ref [] in\n let _ =\n for i = 0 to n - 1 do\n\tif not u.(i) then (\n\t let pos = ref i in\n\t let c = ref [] in\n\t while not u.(!pos) do\n\t u.(!pos) <- true;\n\t c := !pos :: !c;\n\t pos := a.(!pos);\n\t done;\n\t let c = Array.of_list (List.rev !c) in\n\t cs := (Array.length c, c) :: !cs\n\t)\n done;\n in\n let cs = Array.of_list !cs in\n let res = Array.make n 0 in\n let skip = ref false in\n Array.sort compare cs;\n for i = 0 to Array.length cs - 1 do\n\tif not !skip then (\n\tlet (k, p) = cs.(i) in\n(*Printf.printf \"qwe %d\\n\" k;*)\n\t if k mod 2 <> 0 then (\n\t for j = 0 to k - 1 do\n\t res.(p.(j)) <- p.((j + k / 2 + 1) mod k)\n\t done;\n\t ) else (\n\t if i + 1 < Array.length cs && fst (cs.(i + 1)) = k then (\n\t let (_, p') = cs.(i + 1) in\n\t\tfor j = 0 to k - 1 do\n(*Printf.printf \"asd %d %d %d %d\\n\" i k p.(j) p'.(j);*)\n\t\t res.(p.(j)) <- p'.(j);\n\t\t res.(p'.(j)) <- p.((j + 1) mod k)\n\t\tdone;\n\t\tskip := true;\n\t ) else (\n\t Printf.printf \"-1\\n\";\n\t exit 0;\n\t )\n\t )\n\t) else skip := false\n done;\n for i = 0 to n - 1 do\n\tPrintf.printf \"%d \" (res.(i) + 1);\n done;\n Printf.printf \"\\n\"\n", "positive_code": [{"source_code": "open Scanf\nopen Printf\n\nlet length = Array.length\nlet print_array l = Array.iter (fun a -> printf \"%d \" (a+1)) l\nlet print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l\nlet square p =\n let n = Array.length p in\n Array.init n (fun a -> p.(p.(a)))\n\nlet read_int _ = scanf \" %d\" (fun x -> x)\nlet read_perm _ = scanf \" %d\" (fun x -> (x-1))\nlet read_array num =\n Array.init num read_perm\n\nlet add x l =\n l := (x :: !l)\n\ntype permutation = int array\n\nlet split_cycles ar =\n let n = Array.length ar in\n let visited = Array.make n false\n and out = ref [] in\n for i = 0 to n-1 do\n if not visited.(i) then\n begin\n let per = ref [] and x = ref i in\n while not visited.(!x) do\n add (!x) per;\n visited.(!x) <- true;\n x := ar.(!x)\n done;\n let x = Array.of_list (List.rev !per)\n in add x out\n end\n done;\n Array.of_list !out\n\nlet cmp a b =\n Array.length a - Array.length b\n\nlet root_odd ar =\n let n = Array.length ar in\n let m = (n+1)/2 in\n assert (n mod 2 = 1);\n Array.init n (fun x -> if x mod 2 = 0 then ar.(x/2) else ar.(m + x/2))\n\nlet root_even a b =\n assert (Array.length a = Array.length b);\n assert (Array.length a mod 2 = 0);\n let n = Array.length a in\n Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))\n\nlet get_answer ar = (* assume sorted *)\n let n = Array.length ar\n and i = ref 0\n and out = ref []\n and error = ref false in\n while !i < n do\n let l = Array.length ar.(!i) in\n if l mod 2 = 0 then\n begin\n if !i = n - 1 then (incr i; error := true)\n else if Array.length ar.(!i + 1) <> l then (i := n; error := true)\n else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)\n end\n else\n begin\n add (root_odd ar.(!i)) out;\n incr i\n end\n done;\n if !error then [||]\n else Array.of_list !out\n\nlet convert n ar =\n let out = Array.make n 0\n and k = Array.length ar in\n for i = 0 to k - 1 do\n let a = ar.(i) in\n let l = Array.length a in\n for j = 0 to l - 1 do\n if j = l - 1 then out.(a.(j)) <- a.(0)\n else out.(a.(j)) <- a.(j+1)\n done\n done;\n out\n\n\nlet n = read_int ()\nlet ar = read_array n\nlet cycles = split_cycles ar\nlet () = Array.sort cmp cycles\n(*let () = print_array2 cycles; print_endline \"====================\"*)\nlet ans = get_answer cycles\nlet () =\n if ans = [||] then printf \"-1\\n\"\n else\n let out = convert n ans in\n print_array out (*; print_string \"\\nSquare:\\n\"; print_array (square out) *)\n"}], "negative_code": [{"source_code": "open Scanf\nopen Printf\n\nlet length = Array.length\nlet print_array l = Array.iter (fun a -> printf \"%d \" a) l\nlet print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l\nlet square p =\n let n = Array.length p in\n Array.init n (fun a -> p.(p.(a)-1))\n\nlet read_int _ = scanf \" %d\" (fun x -> x)\nlet read_array num =\n Array.init num read_int\n\nlet add x l =\n l := (x :: !l)\n\ntype permutation = int array\n\nlet split_cycles ar =\n let n = Array.length ar in\n let visited = Array.make n false\n and out = ref [] in\n for i = 0 to n-1 do\n if not visited.(i) then\n let per = ref [] and x = ref i in\n while not visited.(!x) do\n add (!x + 1) per;\n visited.(!x) <- true;\n x := ar.(!x) - 1\n done;\n let x = Array.of_list (List.rev !per)\n in add x out\n done;\n Array.of_list !out\n\nlet cmp a b =\n Array.length a - Array.length b\n\nlet root_odd ar =\n let n = Array.length ar in\n assert (n mod 2 = 1);\n Array.init n (fun a -> ar.(2*a mod n))\n\nlet root_even a b =\n assert (Array.length a = Array.length b);\n assert (Array.length a mod 2 = 0);\n let n = Array.length a in\n Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))\n\nlet get_answer ar = (* assume sorted *)\n let n = Array.length ar\n and i = ref 0\n and out = ref []\n and error = ref false in\n while !i < n do\n let l = Array.length ar.(!i) in\n if l mod 2 = 0 then\n begin\n if !i = n - 1 then (incr i; error := true)\n else if Array.length ar.(!i + 1) <> l then (i := n; error := true)\n else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)\n end\n else\n begin\n add (root_odd ar.(!i)) out;\n incr i\n end\n done;\n if !error then [||]\n else Array.of_list !out\n\nlet convert n ar =\n let out = Array.make n 0\n and k = Array.length ar in\n for i = 0 to k - 1 do\n let a = ar.(i) in\n let l = Array.length a in\n for j = 0 to l - 1 do\n if j = l - 1 then out.(a.(j)-1) <- a.(0)\n else out.(a.(j)-1) <- a.(j+1)\n done\n done;\n out\n\n\nlet n = read_int ()\nlet ar = read_array n\nlet cycles = split_cycles ar\nlet () = Array.sort cmp cycles\n(*let () = print_array2 cycles; print_endline \"====================\"*)\nlet ans = get_answer cycles\nlet () =\n if ans = [||] then printf \"-1\\n\"\n else\n let out = convert n ans in\n print_array out (*; print_string \"\\nSquare:\\n\"; print_array (square out) *)\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet length = Array.length\nlet print_array l = Array.iter (fun a -> printf \"%d \" a) l\nlet print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l\n\nlet read_int _ = scanf \" %d\" (fun x -> x)\nlet read_array num =\n Array.init num read_int\n\nlet add x l =\n l := (x :: !l)\n\ntype permutation = int array\n\nlet split_cycles ar =\n let n = Array.length ar in\n let visited = Array.make n false\n and out = ref [] in\n for i = 0 to n-1 do\n if not visited.(i) then\n let per = ref [] and x = ref i in\n while not visited.(!x) do\n add (!x + 1) per;\n visited.(!x) <- true;\n x := ar.(!x) - 1\n done;\n let x = Array.of_list !per\n in add x out\n done;\n Array.of_list !out\n\nlet cmp a b =\n Array.length a - Array.length b\n\nlet root_odd ar =\n let n = Array.length ar in\n assert (n mod 2 = 1);\n Array.init n (fun a -> ar.(2*a mod n))\n\nlet root_even a b =\n assert (Array.length a = Array.length b);\n assert (Array.length a mod 2 = 0);\n let n = Array.length a in\n Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))\n\nlet get_answer ar = (* assume sorted *)\n let n = Array.length ar\n and i = ref 0\n and out = ref []\n and error = ref false in\n while !i < n do\n let l = Array.length ar.(!i) in\n if l mod 2 = 0 then\n begin\n if !i = n - 1 then (incr i; error := true)\n else if Array.length ar.(!i + 1) <> l then (i := n; error := true)\n else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)\n end\n else\n begin\n add (root_odd ar.(!i)) out;\n incr i\n end\n done;\n if !error then [||]\n else Array.of_list !out\n\nlet convert n ar =\n let out = Array.make n 0\n and k = Array.length ar in\n for i = 0 to k - 1 do\n let a = ar.(i) in\n let l = Array.length a in\n for j = 0 to l - 1 do\n if j = l - 1 then out.(a.(j)-1) <- a.(0)\n else out.(a.(j)-1) <- a.(j+1)\n done\n done;\n out\n\n\nlet n = read_int ()\nlet ar = read_array n\nlet cycles = split_cycles ar\nlet _ = Array.sort cmp cycles\nlet ans = get_answer cycles\nlet () =\n if ans = [||] then printf \"-1\\n\"\n else\n let out = convert n ans in\n print_array out\n"}], "src_uid": "f52a4f8c4d84733a8e78a5825b63bdbc"} {"source_code": "module type ExtremumType =\nsig\n type t\n val extremum : t -> t -> bool\nend\n\nmodule type RMQ =\nsig\n type t\n type elt\n val of_array : elt array -> t\n val rmq : t -> int -> int -> int\nend\n\nmodule type RMQMake =\nsig\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t\nend\n\nmodule RMQST =\nstruct\n module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t =\n struct\n type elt = Ext.t\n type t = {a : elt array;\n\t m : int array array}\n let ext = Ext.extremum\n let of_array a =\n let n = Array.length a in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= n do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k in\n\tlet m = Array.make_matrix k n 0 in\n\t for i = 0 to n - 1 do\n\t m.(0).(i) <- i;\n\t done;\n\t for j = 1 to k - 1 do\n\t for i = 0 to n - (1 lsl j) do\n\t let i2 = i + (1 lsl (j - 1)) in\n\t\tm.(j).(i) <-\n\t\t if ext a.(m.(j - 1).(i)) a.(m.(j - 1).(i2))\n\t\t then m.(j - 1).(i)\n\t\t else m.(j - 1).(i2)\n\t done\n\t done;\n\t {a = a;\n\t m = m}\n let rmq data x y =\n let a = data.a\n and m = data.m in\n let l = y - x + 1 in\n let k = ref 0\n and d = ref 1 in\n\twhile !d <= l do\n\t d := 2 * !d;\n\t incr k\n\tdone;\n\tlet k = !k - 1 in\n\tlet i2 = y - (1 lsl k) + 1 in\n\t if ext a.(m.(k).(x)) a.(m.(k).(i2))\n\t then m.(k).(x)\n\t else m.(k).(i2)\n end\nend\n\nmodule RMQSTmin =\n RMQST.Make(\n struct\n type t = int\n let extremum (x : t) (y : t) = x < y\n end\n )\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let is_bridge = ref false in\n\tes.(u) <- (v, is_bridge) :: es.(u);\n\tes.(v) <- (u, is_bridge) :: es.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Array.make k 0 in\n let l = Array.make k 0 in\n let () =\n for i = 0 to k - 1 do\n s.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n l.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n done\n in\n let min (x : int) y = if x < y then x else y in\n let used = Array.make n false in\n let t = ref 0 in\n let e = Array.make n 0 in\n let up = Array.make n 0 in\n let rec dfs u prev =\n used.(u) <- true;\n e.(u) <- !t;\n up.(u) <- !t;\n incr t;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif v <> prev then (\n\t if not used.(v) then (\n\t dfs v u;\n\t up.(u) <- min up.(u) up.(v);\n\t if up.(v) > e.(u) then (\n\t is_bridge := true;\n\t (*Printf.printf \"bridge %d %d\\n\" u v*)\n\t )\n\t ) else (\n\t up.(u) <- min up.(u) e.(v);\n\t )\n\t)\n done;\n in\n let stack = Array.make (2 * n) (fun _ -> ()) in\n let stack_pos = ref 0 in\n let rec execute () =\n if !stack_pos > 0 then (\n decr stack_pos;\n let f = stack.(!stack_pos) in\n\tf ();\n\texecute ()\n )\n in\n let rec dfs u prev =\n used.(u) <- true;\n e.(u) <- !t;\n up.(u) <- !t;\n incr t;\n let rec aux i =\n if i < Array.length es.(u) then (\n\tstack.(!stack_pos) <- (fun () -> aux (i + 1));\n\tincr stack_pos;\n\tlet (v, is_bridge) = es.(u).(i) in\n\t if v <> prev then (\n\t if not used.(v) then (\n\t let f () =\n\t\tup.(u) <- min up.(u) up.(v);\n\t\tif up.(v) > e.(u) then (\n\t\t is_bridge := true;\n\t\t (*Printf.printf \"bridge %d %d\\n\" u v*)\n\t\t)\n\t in\n\t\tstack.(!stack_pos) <- f;\n\t\tincr stack_pos;\n\t\tstack.(!stack_pos) <- (fun () -> dfs v u);\n\t\tincr stack_pos;\n\t ) else (\n\t up.(u) <- min up.(u) e.(v);\n\t )\n\t );\n )\n in\n aux 0\n in\n let color = Array.make n (-1) in\n let c = ref 0 in\n let rec dfs2 u =\n used.(u) <- true;\n color.(u) <- !c;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif not used.(v) && not !is_bridge then (\n\t dfs2 v\n\t)\n done\n in\n let rec dfs2 u =\n used.(u) <- true;\n color.(u) <- !c;\n let rec aux i =\n if i < Array.length es.(u) then (\n\tstack.(!stack_pos) <- (fun () -> aux (i + 1));\n\tincr stack_pos;\n\tlet (v, is_bridge) = es.(u).(i) in\n\t if not used.(v) && not !is_bridge then (\n\t stack.(!stack_pos) <- (fun () -> dfs2 v);\n\t incr stack_pos;\n\t )\n )\n in\n aux 0\n in\n for i = 0 to n - 1 do\n if not used.(i) then (\n\tstack_pos := 0;\n\tdfs i (-1);\n\texecute ()\n )\n done;\n for j = 0 to n - 1 do\n used.(j) <- false\n done;\n for i = 0 to n - 1 do\n if not used.(i) then (\n\tstack_pos := 0;\n\tdfs2 i;\n\texecute ();\n\tincr c\n )\n done;\n let c = !c in\n let es2 = Array.make c [] in\n let () =\n for i = 0 to n - 1 do\n\tfor j = 0 to Array.length es.(i) - 1 do\n\t let (v, is_bridge) = es.(i).(j) in\n\t if !is_bridge then (\n\t let u = color.(i)\n\t and v = color.(v) in\n\t\tes2.(u) <- v :: es2.(u);\n\t\tes2.(v) <- u :: es2.(v);\n\t )\n\tdone\n done\n in\n let es = Array.map Array.of_list es2 in\n let used = Array.make c false in\n let d = Array.make (2 * c) 0 in\n let de = Array.make (2 * c) 0 in\n let g1 = Array.make c 0 in\n let g2 = Array.make c 0 in\n let pos = ref 0 in\n let rec dfs3 u depth =\n used.(u) <- true;\n g1.(u) <- !pos;\n d.(!pos) <- depth;\n de.(!pos) <- u;\n incr pos;\n for i = 0 to Array.length es.(u) - 1 do\n\tlet v = es.(u).(i) in\n\t if not used.(v) then (\n\t dfs3 v (depth + 1);\n\t g2.(u) <- !pos;\n\t d.(!pos) <- depth;\n\t de.(!pos) <- u;\n\t incr pos;\n\t )\n done\n in\n let rec dfs3 u depth =\n used.(u) <- true;\n g1.(u) <- !pos;\n d.(!pos) <- depth;\n de.(!pos) <- u;\n incr pos;\n let rec aux i =\n\tif i < Array.length es.(u) then (\n\t stack.(!stack_pos) <- (fun () -> aux (i + 1));\n\t incr stack_pos;\n\t let v = es.(u).(i) in\n\t if not used.(v) then (\n\t let f () =\n\t\tg2.(u) <- !pos;\n\t\td.(!pos) <- depth;\n\t\tde.(!pos) <- u;\n\t\tincr pos;\n\t in\n\t\tstack.(!stack_pos) <- f;\n\t\tincr stack_pos;\n\t\tstack.(!stack_pos) <- (fun () -> dfs3 v (depth + 1));\n\t\tincr stack_pos;\n\t )\n\t)\n in\n\taux 0\n in\n stack_pos := 0;\n dfs3 0 0;\n execute ();\n let rmq = RMQSTmin.of_array d in\n\tfor i = 0 to k - 1 do\n\t let u = color.(s.(i))\n\t and v = color.(l.(i)) in\n\t let w =\n\t if g1.(u) < g1.(v)\n\t then RMQSTmin.rmq rmq g1.(u) g1.(v)\n\t else RMQSTmin.rmq rmq g1.(v) g1.(u)\n\t in\n\t let depth = d.(w) in\n\t let res = d.(g1.(u)) - depth + d.(g1.(v)) - depth in\n\t Printf.printf \"%d\\n\" res;\n\tdone\n", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let is_bridge = ref false in\n\tes.(u) <- (v, is_bridge) :: es.(u);\n\tes.(v) <- (u, is_bridge) :: es.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Array.make k 0 in\n let l = Array.make k 0 in\n let () =\n for i = 0 to k - 1 do\n s.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n l.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n done\n in\n let min (x : int) y = if x < y then x else y in\n let used = Array.make n false in\n let t = ref 0 in\n let e = Array.make n 0 in\n let up = Array.make n 0 in\n let rec dfs u prev =\n used.(u) <- true;\n e.(u) <- !t;\n up.(u) <- !t;\n incr t;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif v <> prev then (\n\t if not used.(v) then (\n\t dfs v u;\n\t up.(u) <- min up.(u) up.(v);\n\t if up.(v) > e.(u) then (\n\t is_bridge := true;\n\t (*Printf.printf \"bridge %d %d\\n\" u v*)\n\t )\n\t ) else (\n\t up.(u) <- min up.(u) e.(v);\n\t )\n\t)\n done;\n in\n let res = ref 0 in\n let rec dfs2 u dest dist =\n used.(u) <- true;\n if u = dest then (\n res := dist\n );\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif not used.(v) then (\n\t let dist =\n\t if !is_bridge\n\t then dist + 1\n\t else dist\n\t in\n\t dfs2 v dest dist;\n\t)\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i)\n then dfs i (-1)\n done;\n for i = 0 to k - 1 do\n for j = 0 to n - 1 do\n\tused.(j) <- false\n done;\n dfs2 s.(i) l.(i) 0;\n Printf.printf \"%d\\n\" !res;\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let es = Array.make n [] in\n let () =\n for i = 1 to m do\n let u = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let v = Scanf.bscanf sb \"%d \" (fun s -> s) - 1 in\n let is_bridge = ref false in\n\tes.(u) <- (v, is_bridge) :: es.(u);\n\tes.(v) <- (u, is_bridge) :: es.(v);\n done\n in\n let es = Array.map Array.of_list es in\n let k = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let s = Array.make k 0 in\n let l = Array.make k 0 in\n let () =\n for i = 0 to k - 1 do\n s.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n l.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s) - 1;\n done\n in\n let min (x : int) y = if x < y then x else y in\n let used = Array.make n false in\n let t = ref 0 in\n let e = Array.make n 0 in\n let up = Array.make n 0 in\n let rec dfs u prev =\n used.(u) <- true;\n e.(u) <- !t;\n up.(u) <- !t;\n incr t;\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif v <> prev then (\n\t if not used.(v) then (\n\t dfs v u;\n\t up.(u) <- min up.(u) up.(v);\n\t if up.(v) > e.(u) then (\n\t is_bridge := true;\n\t (*Printf.printf \"bridge %d %d\\n\" u v*)\n\t )\n\t ) else (\n\t up.(u) <- min up.(u) e.(v);\n\t )\n\t)\n done;\n in\n let res = ref 0 in\n let rec dfs2 u dest dist =\n used.(u) <- true;\n if u = dest then (\n res := dist\n );\n for i = 0 to Array.length es.(u) - 1 do\n let (v, is_bridge) = es.(u).(i) in\n\tif not used.(v) then (\n\t let dist =\n\t if !is_bridge\n\t then dist + 1\n\t else dist\n\t in\n\t dfs2 v dest dist;\n\t)\n done;\n in\n for i = 0 to n - 1 do\n if not used.(i)\n then dfs i (-1)\n done;\n for i = 0 to k - 1 do\n for j = 0 to n - 1 do\n\tused.(j) <- false\n done;\n dfs2 s.(i) l.(i) 0;\n Printf.printf \"%d\\n\" !res;\n done\n"}], "negative_code": [], "src_uid": "184314d3aa83d48b71a95ae4b48de457"} {"source_code": "open List\nlet read_int _ = Scanf.scanf \" %d\" (fun x -> x);;\n\nlet min x y = if x < y then x else y;; \n\nlet rec read_list l n = \n if n = 0 then l \n else let x = read_int() and y = read_int() in \n read_list (l @ [(x, y)]) (n-1);;\n\nlet rec answer l r n = match (l, r) with\n | ([], []) -> n\n | ((x, y) :: l, []) -> n + y \n | ([], (x, y)::l) -> n + y \n | ((x1, y1) :: l', (x2, y2) :: r') -> answer l' r' (n + y1 + y2);;\n\nlet mysort (x1, y1) (x2, y2) = x1 - x2;;\n\nlet () = \n let n = read_int () in\n let xa = read_list [] n in \n let left = filter (fun (x, y) -> (x < 0)) xa and right = filter (fun (x, y) -> (x > 0)) xa in\n let left = sort mysort left and right = sort mysort right in\n let ans = answer (rev left) right 0 in\n Printf.printf \"%d\\n\" ans \n;;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let d = Array.init n (fun _ -> read_pair()) in\n\n let rec make_lists l r i = if i=n then (l,r) else\n let (x,a) = d.(i) in\n if x < 0 then make_lists ((-x,a)::l) r (i+1)\n else make_lists l ((x,a)::r) (i+1)\n in\n\n let (l,r) = make_lists [] [] 0 in\n\n let l = List.sort compare l in\n let r = List.sort compare r in\n\n let (nl, nr) = (List.length l, List.length r) in\n\n let (l,r) = if nl < nr then (r,l) else (l,r) in\n let (nl,nr) = (max nl nr, min nl nr) in\n\n let sum_r = List.fold_left (fun t (_,a) -> t+a) 0 r in\n\n let (sum_l,_) = List.fold_left (fun (t,i) (_,a) -> if (i>=nr+1) then (t,i+1) else (t+a,i+1)) (0,0) l in\n\n printf \"%d\\n\" (sum_l + sum_r)\n"}], "negative_code": [], "src_uid": "bf573af345509b2364ada6e613b6f998"} {"source_code": "let solve n s =\n let elts = n/2 + 1 in\n s/elts;;\n\n\nlet divide s =\n let l = String.length s in\n let rec aux i =\n if s.[i] = ' ' then i else aux (i+1) in\n let space = aux 0 in\n let a = String.sub s 0 space and b = String.sub s (space+1) (l-space-1) in\n (int_of_string a, int_of_string b);;\n \n \n\nlet read_test i =\n let test = read_line () in divide test;;\n \n\nlet t = read_int ();;\n\n\n\nlet process x =\n let (n, s) = read_test () in print_int(solve n s); print_newline ();;\n\n\nlet rec execute i =\n if i < t then\n begin\n process i; execute (i+1)\n end;;\n\nlet () = execute 0;;\n", "positive_code": [{"source_code": "let w = read_int () in\r\nlet rec aux z = (if z > 0 then\r\n (\r\n let y = read_line () in\r\n let len = String.length y in\r\n let resolution y =\r\n let rec breaker = (function\r\n (a,b) when y.[b] = ' ' -> (int_of_string(String.sub y 0 b), int_of_string(String.sub y (b+1) (len-(b+1))))\r\n |(a,b) -> breaker(a,b+1)) in\r\n let a = breaker (y,0) in let (x,y) = a in\r\n print_int (match x with\r\n 1 -> y\r\n |x when x mod 2 = 0 -> y/(x-((x-1)/2))\r\n |x -> y/(x-(x/2))); print_newline ()\r\n in \r\n (resolution y; aux(z-1) )\r\n )) in aux (w);;"}], "negative_code": [], "src_uid": "0a05b11307fbb2536f868acf4e81c1e2"} {"source_code": "let _ =\n let n = Scanf.scanf \"%d\" (fun i -> i) in\n let tab = Array.init n (fun _ -> Scanf.scanf \" %d\" (fun j -> j)) in\n let perm i j =\n let z = tab.(i) in\n tab.(i) <- tab.(j);\n tab.(j) <- z\n in\n let a = ref (-1) in\n while !a < n-1 do\n if !a < 0\n then incr a\n else if tab.(!a) > tab.(1 + !a)\n then begin\n perm !a (1 + !a);\n Printf.printf \"%d %d\\n\" (1 + !a) (2 + !a);\n decr a\n end\n else incr a;\n done\n", "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 a = Array.init n (fun _ -> read_int()) in\n\n for i=1 to n-1 do\n for j=i downto 1 do\n if a.(j-1) > a.(j) then (\n\tprintf \"%d %d\\n\" (j) (j+1);\n\tlet (x,y) = (a.(j-1), a.(j)) in\n\ta.(j-1) <- y;\n\ta.(j) <- x\n )\n done\n done\n"}, {"source_code": "let n = read_int ()\nlet a = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string |> Array.of_list\n\nlet () =\n for i = 0 to n - 2 do\n let min = ref i in\n for j = i + 1 to n - 1 do\n if a.(j) < a.(!min) then\n min := j\n done;\n\n for j = !min - 1 downto i do\n Printf.printf \"%d %d\\n\" (j+1) (j+2);\n let tmp = a.(j) in\n a.(j) <- a.(j+1);\n a.(j+1) <- tmp\n done\n done\n"}], "negative_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 a = Array.init n (fun _ -> read_int()) in\n\n for i=0 to n-2 do\n for j=i to n-2 do\n if a.(j) > a.(j+1) then (\n\tprintf \"%d %d\\n\" (j+1) (j+2);\n\tlet (x,y) = (a.(j), a.(j+1)) in\n\ta.(j) <- y;\n\ta.(j+1) <- x\n )\n done\n done\n\n"}], "src_uid": "233c2806db31916609421fbd126133d0"} {"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet max_n = 200000\n\nmodule SegTree = struct\n type t = int64 array\n\n let init n = A.make (2 * n) I.zero\n\n let add t i x =\n let v = ref i in\n let n = A.length t in\n while !v < n do\n t.(!v) <- I.add t.(!v) x;\n v := !v lor (!v + 1);\n done\n\n let pref_sum t i =\n let r = ref i in\n let res = ref I.zero in\n while !r >= 0 do\n res := I.add !res t.(!r);\n r := (!r land (!r + 1)) - 1;\n done;\n !res\n\n let sum t l r = I.sub (pref_sum t r) (pref_sum t (l - 1))\nend\n\nmodule L_ = struct\n let filter_map f =\n let rec aux accu = function\n | [] -> L.rev accu\n | x :: l ->\n match f x with\n | None -> aux accu l\n | Some v -> aux (v :: accu) l\n in\n aux []\nend\n\ntype query = {\n l: int;\n q_index: int;\n}\n\nlet find_first_div n =\n let i = ref 2 in\n let found = ref (-1) in\n while !i * !i <= n && !found = -1 do\n if (n mod !i = 0) then found := !i;\n i := !i + 1;\n done;\n if (!found = -1) then n\n else !found\n\nlet () =\n let q = read_int () in\n let original_queries: (int * int) array = Array.make q (0, 0) in\n let ans = Array.make q I.zero in\n let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in\n for i = 0 to q - 1 do\n let l = read_int () in\n let r = read_int () in\n original_queries.(i) <- (l, r);\n events.(r) <- {l; q_index = i;} :: events.(r);\n done;\n\n let (divisors: int list array) = Array.make (max_n + 1) [] in\n let pw2 = Array.make (max_n + 1) 0 in\n divisors.(1) <- [1];\n\n let inc_tree = SegTree.init max_n in\n for k = 2 to max_n do\n let fd = find_first_div k in\n let divs_prev = divisors.(k / fd) in\n divisors.(k) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);\n if (k mod 2 = 0) then pw2.(k) <- pw2.(k / 2) + 1;\n\n let divs = divisors.(k) in\n let divs_num = L.length divs in\n L.iteri (fun idx i ->\n if (i <> k) then\n SegTree.add inc_tree i @@ I.of_int @@ divs_num - idx - 2;\n ) divs;\n let p = pw2.(k) in\n\n let new_divs =\n A.of_list @@\n L.tl @@\n L.fast_sort (fun x y -> -compare x y) @@\n divs @ L_.filter_map (fun d ->\n if (d * 2 < k && pw2.(d) == p) then Some (d * 2)\n else None\n ) divs in\n let sj_p = ref 0 and ptr_j = ref (-1) in\n A.iteri (fun idx i ->\n while (!ptr_j <> -1 && new_divs.(!ptr_j) + i <= k) do\n let cd = new_divs.(!ptr_j) in\n if (pw2.(cd) = p + 1) then sj_p := !sj_p - 1;\n ptr_j := !ptr_j - 1\n done;\n\n if (pw2.(i) = p + 1) then\n SegTree.add inc_tree i @@ I.of_int @@ !ptr_j + 1\n else\n SegTree.add inc_tree i @@ I.of_int !sj_p;\n\n while (!ptr_j + 1 <= idx && new_divs.(!ptr_j + 1) + i > k) do\n let cd = new_divs.(!ptr_j + 1) in\n if (pw2.(cd) = p + 1) then sj_p := !sj_p + 1;\n ptr_j := !ptr_j + 1\n done;\n ) new_divs;\n\n L.iter (fun q ->\n ans.(q.q_index) <- SegTree.sum inc_tree q.l k;\n ) events.(k)\n done;\n\n for i = 0 to q - 1 do\n let n = snd original_queries.(i) - fst original_queries.(i) + 1 in\n let real_ans =\n I.(sub\n (div\n (mul (mul (of_int n) (of_int @@ n - 1)) (of_int @@ n - 2))\n (of_int 6))\n ans.(i)) in\n pf \"%Ld\\n\" real_ans;\n done;", "positive_code": [{"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet max_n = 200000\n\nmodule SegTree = struct\n type t = int64 array\n\n let init n = A.make n I.zero\n\n let add t i x =\n let v = ref i in\n let n = A.length t in\n while !v < n do\n t.(!v) <- I.add t.(!v) x;\n v := !v lor (!v + 1);\n done\n\n let pref_sum t i =\n let r = ref i in\n let res = ref I.zero in\n while !r >= 0 do\n res := I.add !res t.(!r);\n r := (!r land (!r + 1)) - 1;\n done;\n !res\n\n let sum t l r = I.sub (pref_sum t r) (pref_sum t (l - 1))\nend\n\nmodule L_ = struct\n let filter_map f =\n let rec aux accu = function\n | [] -> L.rev accu\n | x :: l ->\n match f x with\n | None -> aux accu l\n | Some v -> aux (v :: accu) l\n in\n aux []\nend\n\ntype query = {\n l: int;\n q_index: int;\n}\n\nlet find_first_div n =\n let i = ref 2 in\n let found = ref (-1) in\n while !i * !i <= n && !found = -1 do\n if (n mod !i = 0) then found := !i;\n i := !i + 1;\n done;\n if (!found = -1) then n\n else !found\n\nlet () =\n let q = read_int () in\n let original_queries: (int * int) array = Array.make q (0, 0) in\n let ans = Array.make q I.zero in\n let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in\n for i = 0 to q - 1 do\n let l = read_int () in\n let r = read_int () in\n original_queries.(i) <- (l, r);\n events.(r) <- {l; q_index = i;} :: events.(r);\n done;\n\n let (divisors: int list array) = Array.make (max_n + 1) [] in\n let pw2 = Array.make (max_n + 1) 0 in\n divisors.(1) <- [1];\n\n let inc_tree = SegTree.init (max_n + 1) in\n for k = 2 to max_n do\n let fd = find_first_div k in\n let divs_prev = divisors.(k / fd) in\n divisors.(k) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);\n if (k mod 2 = 0) then pw2.(k) <- pw2.(k / 2) + 1;\n\n let divs = divisors.(k) in\n let divs_num = L.length divs in\n L.iteri (fun idx i ->\n if (i <> k) then\n SegTree.add inc_tree i @@ I.of_int @@ divs_num - idx - 2;\n ) divs;\n let p = pw2.(k) in\n\n let new_divs =\n A.of_list @@\n L.tl @@\n L.fast_sort (fun x y -> -compare x y) @@\n divs @ L_.filter_map (fun d ->\n if (d * 2 < k && pw2.(d) == p) then Some (d * 2)\n else None\n ) divs in\n let sj_p = ref 0 and ptr_j = ref (-1) in\n A.iteri (fun idx i ->\n while (!ptr_j <> -1 && new_divs.(!ptr_j) + i <= k) do\n let cd = new_divs.(!ptr_j) in\n if (pw2.(cd) = p + 1) then sj_p := !sj_p - 1;\n ptr_j := !ptr_j - 1\n done;\n\n if (pw2.(i) = p + 1) then\n SegTree.add inc_tree i @@ I.of_int @@ !ptr_j + 1\n else\n SegTree.add inc_tree i @@ I.of_int !sj_p;\n\n while (!ptr_j + 1 <= idx && new_divs.(!ptr_j + 1) + i > k) do\n let cd = new_divs.(!ptr_j + 1) in\n if (pw2.(cd) = p + 1) then sj_p := !sj_p + 1;\n ptr_j := !ptr_j + 1\n done;\n ) new_divs;\n\n L.iter (fun q ->\n ans.(q.q_index) <- SegTree.sum inc_tree q.l k;\n ) events.(k)\n done;\n\n for i = 0 to q - 1 do\n let n = snd original_queries.(i) - fst original_queries.(i) + 1 in\n let real_ans =\n I.(sub\n (div\n (mul (mul (of_int n) (of_int @@ n - 1)) (of_int @@ n - 2))\n (of_int 6))\n ans.(i)) in\n pf \"%Ld\\n\" real_ans;\n done;"}], "negative_code": [{"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet max_n = 200000\n\nmodule SegTree = struct\n let init = ()\n let add _i (_x: int64) = ()\n\n let sum _l _r: int64 = I.zero\n\nend\n\ntype query = {\n l: int;\n q_index: int;\n}\n\nlet find_first_div n =\n let i = ref 2 in\n let found = ref (-1) in\n while !i * !i <= n && !found = -1 do\n if (n mod !i = 0) then found := !i;\n i := !i + 1;\n done;\n if (!found = -1) then n\n else !found\n\nlet () =\n (* let q = read_int () in\n let original_queries: (int * int) array = Array.make q (0, 0) in\n let ans = Array.make q I.zero in\n let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in\n for i = 0 to q - 1 do\n let l = read_int () in\n let r = read_int () in\n original_queries.(i) <- (l, r);\n events.(r) <- {l; q_index = i;} :: events.(r);\n done; *)\n\n let (divisors: int list array) = Array.make (max_n + 1) [] in\n let pw2 = Array.make (max_n + 1) 0 in\n divisors.(1) <- [1];\n\n for i = 2 to max_n do\n let fd = find_first_div i in\n let divs_prev = divisors.(i / fd) in\n divisors.(i) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);\n if (i mod 2 = 0) then pw2.(i) <- pw2.(i / 2) + 1;\n done;\n\n"}, {"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet max_n = 200000\n\nmodule SegTree = struct\n let init = ()\n let add _i (_x: int64) = ()\n\n let sum _l _r: int64 = I.zero\n\nend\n\ntype query = {\n l: int;\n q_index: int;\n}\n\nlet find_first_div n =\n let i = ref 2 in\n let found = ref (-1) in\n while !i * !i <= n && !found = -1 do\n if (n mod !i = 0) then found := !i;\n i := !i + 1;\n done;\n if (!found = -1) then n\n else !found\n\nlet () =\n (* let q = read_int () in\n let original_queries: (int * int) array = Array.make q (0, 0) in\n let (events: query list array) = Array.init max_n (fun _ -> []) in\n for i = 0 to q - 1 do\n let l = read_int () in\n let r = read_int () in\n original_queries.(i) <- (l, r);\n events.(r) <- {l; q_index = i;} :: events.(r);\n done; *)\n\n let (divisors: int list array) = Array.make (max_n + 1) [] in\n let pw2 = Array.make (max_n + 1) 0 in\n divisors.(0) <- [1];\n\n for i = 2 to max_n do\n let fd = find_first_div i in\n let divs_prev = divisors.(i / fd) in\n divisors.(i) <- List.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);\n if (i mod 2 = 0) then pw2.(i) <- pw2.(i / 2) + 1;\n done;\n\n"}], "src_uid": "6a3043daecdb0442f4878ee08a8b70ba"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n\nopen Printf\nopen Array\n\nlet rec exists f a =\n fold_right f a false\n;;\nlet run () =\n let n = scan_int () in\n let k1 = scan_int () in\n let k2 = scan_int () in\n let a = init k1 (fun _x -> scan_int ()) in\n let _b = init k2 (fun _x -> scan_int ()) in\n if exists (fun x y -> x = n or y) a then\n printf \"YES\\n\"\n else printf \"NO\\n\"\n;;\n\nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)\n \nlet () =\n\n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let (k1,k2) = read_pair() in\n let cards1 = Array.init k1 read_int in\n let _ = Array.init k2 read_int in\n if exists 0 (k1-1) (fun i -> cards1.(i) = n) then printf \"YES\\n\" else printf \"NO\\n\"\n done\n"}], "negative_code": [], "src_uid": "3ef23f114be223255bd10131b2375b86"} {"source_code": "let f (mx,cur) next =\n let nx = if next then cur+1 else 0 in\n (max mx nx, nx)\nin let rec g q x =\n if q = 0 then x else g (q - 1) (f x (String.contains (Scanf.scanf \" %s\" (fun x->x)) '0'))\nin print_int @@ fst @@ Scanf.scanf \"%_d %d\" (fun d -> g d (0,0))\n", "positive_code": [{"source_code": "let () =\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [n; d] ->\n let cur = ref 0 in\n let r = ref 0 in\n for i = 1 to d do\n let present = read_line () |> Str.(split (regexp \"\")) |> List.map int_of_string in\n if List.exists (fun x -> x == 0) present then (\n incr cur;\n if !cur > !r then\n r := !cur\n ) else\n cur := 0\n done;\n Printf.printf \"%d\\n\" !r\n | _ -> assert false\n"}, {"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 let d = read_int () in\n\n let all = String.make n '1' in\n\n let win_all = Array.init d (fun i ->\n read_string() <> all\n ) in\n\n let rec scan i len max_len = if i=d then max_len else\n let opt1 = if win_all.(i) then len+1 else 0 in\n scan (i+1) opt1 (max opt1 max_len)\n in\n\n let answer = scan 0 0 0 in\n\n printf \"%d\\n\" answer\n \n"}], "negative_code": [], "src_uid": "a6ee741df426fd2d06fdfda4ca369397"} {"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 newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 1e-12 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L && (\n let a = !x in\n let b = d -. a in\n abs_float ((a +. b) -. (a *. b))>10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6 ||\n abs_float ((a *. b) -. d) > 10e-6\n ) then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n if (\n abs_float ((a +. b) -. (a *. b)) > 10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6 ||\n abs_float ((a *. b) -. d) > 10e-6\n ) then printf \"N\\n\"\n else printf \"Y %.16f %.16f\\n\" (max a b) (min a b);\n (* printf \" %.12f %.12f\\n\" (a+.b) (a*.b); *)\n )\n )\n\n\n\n\n\n\n\n\n", "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 bsf ng ok f = let d = if ng < ok then 1. else -1. in\n let rec f0 c ng ok =\n if abs_float (ok -. ng) <= 10e-12 || c < 0L then ok\n else let mid = ng +. (ok -. ng) /. 2. in\n if f mid then f0 (c-1L) ng mid else f0 (c-1L) mid ok\n in f0 100000L ng ok\nlet ok a b d =\n abs_float ((a +. b) -. (a *. b)) > 10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n if d = 0. then (\n printf \"Y 0.000000000000 0.000000000000\\n\"\n ) else (\n let b = bsf 0. (d /. 2.) (fun b ->\n let a = d -. b in\n if a *. b > d then true else false\n ) in\n let a = d -. b in\n if abs_float (a *. b -. d) > 10e-6 || ok a b d then (\n printf \"N\\n\"\n ) else (\n printf \"Y %.14f %.14f\\n\" a b\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\n\nlet newton start ?(count=100000L) ?(eps=1e-13) f f' =\n let g v = v -. f v /. f' v in\n let rec lp a = function\n | 0L -> a\n | c ->\n let b = g a in\n if abs_float (b -. a) <= eps then a\n else lp b (c-1L)\n in lp start count\n\nlet ok a b d =\n abs_float ((a +. b) -. (a *. b)) <= 10e-6 &&\n abs_float ((a +. b) -. d) <= 10e-6 &&\n abs_float ((a *. b) -. d) <= 10e-6\n\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n if d = 0. then\n printf \"Y 0.0000000000000000 0.0000000000000000\\n\"\n else\n let a = newton 0.\n (fun v -> v*.v -. d*.v +. d)\n (fun v -> 2.*.v -. d) in\n let b = d -. a in\n if ok a b d then\n printf \"Y %.16f %.16f\\n\" a b\n else printf \"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\n\nlet newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 10e-12 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L && (\n let a = !x in\n let b = d -. a in\n abs_float ((a +. b) -. (a *. b))>10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6\n ) then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n if (\n abs_float ((a +. b) -. (a *. b)) > 10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6\n ) then printf \"N\\n\"\n else printf \"Y %.16f %.16f\\n\" (max a b) (min a b);\n (* printf \" %.12f %.12f\\n\" (a+.b) (a*.b); *)\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 newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 10e-8 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n printf \"Y %.12f %.12f\\n\" (max a b) (min a b);\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 newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 10e-9 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L && (\n let a = !x in\n let b = d -. a in\n abs_float ((a +. b) -. (a *. b))>10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6\n ) then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n if (\n abs_float ((a +. b) -. (a *. b)) > 10e-6 ||\n abs_float ((a +. b) -. d) > 10e-6\n ) then printf \"N\\n\"\n else printf \"Y %.16f %.16f\\n\" (max a b) (min a b);\n (* printf \" %.12f %.12f\\n\" (a+.b) (a*.b); *)\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 newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 10e-8 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n printf \"Y %.12f %.12f\\n\" a b;\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 newton d =\n let x = ref 0. in\n let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in\n let b = ref @@ f !x in\n let c = ref 10000L in\n while !c > 0L && abs_float (!b -. !x) > 10e-9 do\n c -= 1L;\n x := !b;\n b := f !x;\n done;\n (* printf \"%f %f : %f\\n\" !x (d -. !x) !b; *)\n if !c = 0L && (\n abs_float ((!x+. !b) -. (!x*. !b))>10e-6 ||\n abs_float ((!x+. !b) -. d) > 10e-6\n ) then None else Some !x\nlet () =\n let t = get_i64 0 in\n rep 1L t (fun _ ->\n let d = scanf \" %f\" @@ id in\n match newton d with\n | None -> printf \"N\\n\"\n | Some a -> (\n let b = d -. a in\n printf \"Y %.12f %.12f\\n\" (max a b) (min a b);\n (* printf \" %.12f %.12f\\n\" (a+.b) (a*.b); *)\n )\n )\n\n\n\n\n\n\n\n\n"}], "src_uid": "6f5d41346419901c830233b3bf5c9e65"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let z = ref 0 in\n let o = ref 0 in\n let q = ref 0 in\n let z2 = ref 0 in\n let o2 = ref 0 in\n let q2 = ref 0 in\n for i = 0 to n - 3 do\n match s.[i] with\n\t| '0' -> incr z\n\t| '1' -> incr o\n\t| '?' -> incr q\n\t| _ -> assert false\n done;\n for i = n - 2 to n - 1 do\n match s.[i] with\n\t| '0' -> incr z2\n\t| '1' -> incr o2\n\t| '?' -> incr q2\n\t| _ -> assert false\n done;\n let ht = Hashtbl.create 4 in\n let solve' s =\n let s = ref s in\n let d = ref 1 in\n\twhile String.length !s > 2 do\n\t (*Printf.printf \"asd %s %d\\n\" !s !d;*)\n\t (try\n\t let i = String.index !s (Char.chr (!d + Char.code '0')) in\n\t s := String.sub !s 0 i ^\n\t\t String.sub !s (i + 1) (String.length !s - i - 1);\n\t with\n\t | Not_found ->\n\t\t s := String.sub !s 1 (String.length !s - 1)\n\t );\n\t d := 1 - !d;\n\tdone;\n\tHashtbl.replace ht !s ()\n in\n let solve _s z o q z2 o2 tail =\n (*for d = 0 to q do\n\tlet z = z + d\n\tand o = o + (q - d) in*)\n\t (*Printf.printf \"asd zoq %d %d %d\\n\" z o q;*)\n\t if n mod 2 = 0 then (\n\t if z + q >= o + 4\n\t then solve' (\"0000\" ^ tail);\n\t if z < o + q + 4 && z + q >= o + 2\n\t then solve' (\"00\" ^ tail);\n\t if o + q >= z + 4\n\t then solve' (\"1111\" ^ tail);\n\t if o < z + q + 4 && o + q >= z + 2\n\t then solve' (\"11\" ^ tail);\n\t if z <= o + q && o <= z + q\n\t then Hashtbl.replace ht tail ();\n\t ) else (\n\t if z + q >= o + 5\n\t then solve' (\"00000\" ^ tail);\n\t if z <= o + q + 5 && z + q >= o + 3\n\t then solve' (\"000\" ^ tail);\n\t if o + q >= z + 5\n\t then solve' (\"11111\" ^ tail);\n\t if o < z + q + 5 && o + q >= z + 3\n\t then solve' (\"111\" ^ tail);\n\t if z <= o + q + 1 && o + 1 <= z + q\n\t then solve' (\"0\" ^ tail);\n\t if z + 1 <= o + q && o <= z + 1 + q\n\t then solve' (\"1\" ^ tail);\n\t )\n (*done*)\n in\n (match s.[n - 2], s.[n - 1] with\n\t | '?', '?' ->\n\t solve s !z !o !q 2 0 \"00\";\n\t solve s !z !o !q 1 1 \"01\";\n\t solve s !z !o !q 1 1 \"10\";\n\t solve s !z !o !q 0 2 \"11\";\n\t | '?', _ ->\n\t solve s !z !o !q (!z2 + 1) !o2 (\"0\" ^ String.make 1 s.[n - 1]);\n\t solve s !z !o !q !z2 (!o2 + 1) (\"1\" ^ String.make 1 s.[n - 1]);\n\t | _, '?' ->\n\t solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ \"0\");\n\t solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ \"1\");\n\t | _ ->\n\t solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);\n );\n if Hashtbl.mem ht \"00\" then Printf.printf \"00\\n\";\n if Hashtbl.mem ht \"01\" then Printf.printf \"01\\n\";\n if Hashtbl.mem ht \"10\" then Printf.printf \"10\\n\";\n if Hashtbl.mem ht \"11\" then Printf.printf \"11\\n\";\n", "positive_code": [{"source_code": " let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let z = ref 0 in\n let o = ref 0 in\n let q = ref 0 in\n let z2 = ref 0 in\n let o2 = ref 0 in\n let q2 = ref 0 in\n for i = 0 to n - 3 do\n match s.[i] with\n | '0' -> incr z\n | '1' -> incr o\n | '?' -> incr q\n | _ -> assert false\n done;\n for i = n - 2 to n - 1 do\n match s.[i] with\n | '0' -> incr z2\n | '1' -> incr o2\n | '?' -> incr q2\n | _ -> assert false\n done;\n let ht = Hashtbl.create 4 in\n let solve' s =\n let s = ref s in\n let d = ref 1 in\n while String.length !s > 2 do\n (*Printf.printf \"asd %s\\n\" !s;*)\n (try\n let i = String.index !s (Char.chr (!d + Char.code '0')) in\n s := String.sub !s 0 i ^\n String.sub !s (i + 1) (String.length !s - i - 1);\n with\n | Not_found ->\n s := String.sub !s 1 (String.length !s - 1)\n );\n d := 1 - !d;\n done;\n Hashtbl.replace ht !s ()\n in\n let solve _s z o q z2 o2 tail =\n for d = 0 to q do\n let z = z + d\n and o = o + (q - d) in\n (*Printf.printf \"asd zoq %d %d %d\\n\" z o q;*)\n if n mod 2 = 0 then (\n if z >= o + 4\n then solve' (\"0000\" ^ tail)\n else if o >= z + 4\n then solve' (\"1111\" ^ tail)\n else if z >= o + 2\n then solve' (\"00\" ^ tail)\n else if o >= z + 2\n then solve' (\"11\" ^ tail)\n else if z = o\n then Hashtbl.replace ht tail ()\n else assert false\n ) else (\n if z >= o + 5\n then solve' (\"00000\" ^ tail)\n else if o >= z + 5\n then solve' (\"11111\" ^ tail)\n else if z >= o + 3\n then solve' (\"000\" ^ tail)\n else if o >= z + 3\n then solve' (\"111\" ^ tail)\n else if z = o + 1\n then solve' (\"0\" ^ tail)\n else if z + 1 = o\n then solve' (\"1\" ^ tail)\n else assert false\n )\n done\n in\n (match s.[n - 2], s.[n - 1] with\n | '?', '?' ->\n solve s !z !o !q 2 0 \"00\";\n solve s !z !o !q 1 1 \"01\";\n solve s !z !o !q 1 1 \"10\";\n solve s !z !o !q 0 2 \"11\";\n | '?', _ ->\n solve s !z !o !q (!z2 + 1) !o2 (\"0\" ^ String.make 1 s.[n - 1]);\n solve s !z !o !q !z2 (!o2 + 1) (\"1\" ^ String.make 1 s.[n - 1]);\n | _, '?' ->\n solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ \"0\");\n solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ \"1\");\n | _ ->\n solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);\n );\n if Hashtbl.mem ht \"00\" then Printf.printf \"00\\n\";\n if Hashtbl.mem ht \"01\" then Printf.printf \"01\\n\";\n if Hashtbl.mem ht \"10\" then Printf.printf \"10\\n\";\n if Hashtbl.mem ht \"11\" then Printf.printf \"11\\n\";"}], "negative_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let z = ref 0 in\n let o = ref 0 in\n let q = ref 0 in\n let z2 = ref 0 in\n let o2 = ref 0 in\n let q2 = ref 0 in\n for i = 0 to n - 3 do\n match s.[i] with\n\t| '0' -> incr z\n\t| '1' -> incr o\n\t| '?' -> incr q\n\t| _ -> assert false\n done;\n for i = n - 2 to n - 1 do\n match s.[i] with\n\t| '0' -> incr z2\n\t| '1' -> incr o2\n\t| '?' -> incr q2\n\t| _ -> assert false\n done;\n let ht = Hashtbl.create 4 in\n let solve' s =\n let s = ref s in\n let d = ref 1 in\n\twhile String.length !s > 2 do\n\t (*Printf.printf \"asd %s\\n\" !s;*)\n\t (try\n\t let i = String.index !s (Char.chr (!d + Char.code '0')) in\n\t s := String.sub !s 0 i ^\n\t\t String.sub !s (i + 1) (String.length !s - i - 1);\n\t with\n\t | Not_found ->\n\t\t s := String.sub !s 1 (String.length !s - 1)\n\t );\n\t d := 1 - !d;\n\tdone;\n\tHashtbl.replace ht !s ()\n in\n let solve _s z o q z2 o2 tail =\n (*for d = 0 to q do\n\tlet z = z + d\n\tand o = o + (q - d) in*)\n\t (*Printf.printf \"asd zoq %d %d %d\\n\" z o q;*)\n\t if n mod 2 = 0 then (\n\t if z + q >= o + 4\n\t then solve' (\"0000\" ^ tail);\n\t if o + q >= z + 4\n\t then solve' (\"1111\" ^ tail);\n\t if z + q >= o + 2\n\t then solve' (\"00\" ^ tail);\n\t if o + q >= z + 2\n\t then solve' (\"11\" ^ tail);\n\t if 0 <= o - z + q && o - z <= q\n\t then Hashtbl.replace ht tail ();\n\t ) else (\n\t if z + q >= o + 5\n\t then solve' (\"00000\" ^ tail);\n\t if o + q >= z + 5\n\t then solve' (\"11111\" ^ tail);\n\t if z + q >= o + 3\n\t then solve' (\"000\" ^ tail);\n\t if o + q >= z + 3\n\t then solve' (\"111\" ^ tail);\n\t if 0 <= o - z + q + 1 && o - z + 1 <= q\n\t then solve' (\"0\" ^ tail);\n\t if 0 <= o - z + q - 1 && o - z - 1 <= q\n\t then solve' (\"1\" ^ tail);\n\t )\n (*done*)\n in\n (match s.[n - 2], s.[n - 1] with\n\t | '?', '?' ->\n\t solve s !z !o !q 2 0 \"00\";\n\t solve s !z !o !q 1 1 \"01\";\n\t solve s !z !o !q 1 1 \"10\";\n\t solve s !z !o !q 0 2 \"11\";\n\t | '?', _ ->\n\t solve s !z !o !q (!z2 + 1) !o2 (\"0\" ^ String.make 1 s.[n - 1]);\n\t solve s !z !o !q !z2 (!o2 + 1) (\"1\" ^ String.make 1 s.[n - 1]);\n\t | _, '?' ->\n\t solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ \"0\");\n\t solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ \"1\");\n\t | _ ->\n\t solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);\n );\n if Hashtbl.mem ht \"00\" then Printf.printf \"00\\n\";\n if Hashtbl.mem ht \"01\" then Printf.printf \"01\\n\";\n if Hashtbl.mem ht \"10\" then Printf.printf \"10\\n\";\n if Hashtbl.mem ht \"11\" then Printf.printf \"11\\n\";\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let z = ref 0 in\n let o = ref 0 in\n let q = ref 0 in\n let z2 = ref 0 in\n let o2 = ref 0 in\n let q2 = ref 0 in\n for i = 0 to n - 3 do\n match s.[i] with\n\t| '0' -> incr z\n\t| '1' -> incr o\n\t| '?' -> incr q\n\t| _ -> assert false\n done;\n for i = n - 2 to n - 1 do\n match s.[i] with\n\t| '0' -> incr z2\n\t| '1' -> incr o2\n\t| '?' -> incr q2\n\t| _ -> assert false\n done;\n let ht = Hashtbl.create 4 in\n let solve' s =\n let s = ref s in\n let d = ref 1 in\n\twhile String.length !s > 2 do\n\t (*Printf.printf \"asd %s %d\\n\" !s !d;*)\n\t (try\n\t let i = String.index !s (Char.chr (!d + Char.code '0')) in\n\t s := String.sub !s 0 i ^\n\t\t String.sub !s (i + 1) (String.length !s - i - 1);\n\t with\n\t | Not_found ->\n\t\t s := String.sub !s 1 (String.length !s - 1)\n\t );\n\t d := 1 - !d;\n\tdone;\n\tHashtbl.replace ht !s ()\n in\n let solve _s z o q z2 o2 tail =\n (*for d = 0 to q do\n\tlet z = z + d\n\tand o = o + (q - d) in*)\n\t (*Printf.printf \"asd zoq %d %d %d\\n\" z o q;*)\n\t if n mod 2 = 0 then (\n\t if z + q >= o + 4\n\t then solve' (\"0000\" ^ tail)\n\t else if z + q >= o + 2\n\t then solve' (\"00\" ^ tail);\n\t if o + q >= z + 4\n\t then solve' (\"1111\" ^ tail)\n\t else if o + q >= z + 2\n\t then solve' (\"11\" ^ tail);\n\t if z <= o + q && o <= z + q\n\t then Hashtbl.replace ht tail ();\n\t ) else (\n\t if z + q >= o + 5\n\t then solve' (\"00000\" ^ tail)\n\t else if z + q >= o + 3\n\t then solve' (\"000\" ^ tail);\n\t if o + q >= z + 5\n\t then solve' (\"11111\" ^ tail)\n\t else if o + q >= z + 3\n\t then solve' (\"111\" ^ tail);\n\t if z <= o + q + 1 && o + 1 <= z + q\n\t then solve' (\"0\" ^ tail);\n\t if z + 1 <= o + q && o <= z + 1 + q\n\t then solve' (\"1\" ^ tail);\n\t )\n (*done*)\n in\n (match s.[n - 2], s.[n - 1] with\n\t | '?', '?' ->\n\t solve s !z !o !q 2 0 \"00\";\n\t solve s !z !o !q 1 1 \"01\";\n\t solve s !z !o !q 1 1 \"10\";\n\t solve s !z !o !q 0 2 \"11\";\n\t | '?', _ ->\n\t solve s !z !o !q (!z2 + 1) !o2 (\"0\" ^ String.make 1 s.[n - 1]);\n\t solve s !z !o !q !z2 (!o2 + 1) (\"1\" ^ String.make 1 s.[n - 1]);\n\t | _, '?' ->\n\t solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ \"0\");\n\t solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ \"1\");\n\t | _ ->\n\t solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);\n );\n if Hashtbl.mem ht \"00\" then Printf.printf \"00\\n\";\n if Hashtbl.mem ht \"01\" then Printf.printf \"01\\n\";\n if Hashtbl.mem ht \"10\" then Printf.printf \"10\\n\";\n if Hashtbl.mem ht \"11\" then Printf.printf \"11\\n\";\n"}], "src_uid": "f03f1613292cacc36abbd3a3a25cbf86"} {"source_code": "open Printf\nopen Num\n\nlet n = Scanf.scanf \"%d \" (fun x -> x)\n\nlet my_hash = Hashtbl.create 1234567\n\nlet my_hash2 = Hashtbl.create 1234567\n\nlet () =\n for i = 0 to n-1 do\n let j = Scanf.scanf \"%d \" (fun x -> x) in\n Hashtbl.add my_hash j i\n done\n\nlet () =\n for i = 0 to n-2 do\n let j = Scanf.scanf \"%d \" (fun x -> x) in\n Hashtbl.add my_hash2 j i;\n Hashtbl.remove my_hash j\n done\n\nlet () = Hashtbl.iter (fun x y -> printf \"%d\\n\" x) my_hash\n\nlet () =\n for i = 0 to n-3 do\n let j = Scanf.scanf \"%d \" (fun x -> x) in\n Hashtbl.remove my_hash2 j;\n done\n\nlet () = Hashtbl.iter (fun x y -> printf \"%d\\n\" x) my_hash2\n\n \n \n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet get_list l =\n let rec loop i list =\n if i > 0\n then\n let var = read () in\n loop (i - 1) (var :: list)\n else\n List.sort (Pervasives.compare) list\n in loop l []\n\nlet subtract_lists first second = \n let rec subtract l1 l2 =\n match l1, l2 with \n | [], _ -> []\n | _, [] -> l1\n | hd :: tl, hhd :: ttl when hd = hhd -> subtract tl ttl\n | hd :: tl, _ -> hd :: (subtract tl l2) \n in subtract first second\n\nlet solve () = \n let n = read () in\n let first = get_list n in\n let second = get_list (n - 1) in\n let third = get_list (n - 2) in\n let bug_one = subtract_lists first second in\n let bug_two = subtract_lists second third in\n match bug_one, bug_two with\n | hd :: tl, hhd :: ttl -> (hd, hhd)\n | _ -> failwith \"Empty list\"\n\nlet print (a, b) = Printf.printf \"%d\\n%d\\n\" a b\nlet () = print (solve ())\n"}, {"source_code": "let _ = read_line () in\nlet ints _ = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string |> List.sort compare in\nlet rec diff x y = \n match (x ,y) with\n | ([e],[]) -> e\n | ((c :: cs), (d :: ds)) when c != d -> c\n | ((a :: ax), (b :: bx)) when a = b -> diff ax bx\n | _ -> failwith \"error\" in\n\nlet first = ints () and\n second = ints () and\n third = ints () in\nPrintf.printf \"%d\\n%d\" (diff first second) (diff second third)\n"}, {"source_code": "let next_int() =\n Scanf.scanf \"%d \" (fun x->x);;\n\nlet read_list n f =\n let rec loop idx =\n if idx == n then\n []\n else\n f()::loop (idx+1) in\n loop 0;;\n \nlet findDiff l1 l2 =\n let rec loop l1 l2 =\n match l1, l2 with\n | h1::t1, h2::t2 ->\n if h1 == h2 then\n loop t1 t2\n else\n h1\n | h1::t1, [] -> h1\n | _, _ -> 0 in\n loop (List.sort compare l1) (List.sort compare l2);;\n\nlet _ =\n let n = read_int() in\n let l1 = read_list n next_int in\n let l2 = read_list (n-1) next_int in\n let l3 = read_list (n-2) next_int in\n print_int(findDiff l1 l2);\n print_newline();\n print_int(findDiff l2 l3);\n print_newline();;\n"}, {"source_code": "let rec prem_dif = function\n\t|[a],[]\t\t-> a\n\t|t::q,t'::q'\t-> if t=t'\n\t\t\t\tthen prem_dif (q,q')\n\t\t\t\telse t;;\n\nlet main () =\n\tlet n = Scanf.scanf \"%d \" (fun i -> i) and prem = ref []\n\tand sec = ref [] and tro = ref [] in\n\t\tfor i = 1 to n do\n\t\t\tprem := (Scanf.scanf \"%d \" (fun j -> j))::!prem;\n\t\tdone;\n\t\tfor i = 1 to n-1 do\n\t\t\tsec := (Scanf.scanf \"%d \" (fun j -> j))::!sec;\n\t\tdone;\n\t\tfor i = 1 to n-2 do\n\t\t\ttro := (Scanf.scanf \"%d \" (fun j -> j))::!tro;\n\t\tdone;\n\t\tprem := List.sort compare !prem;\n\t\tsec := List.sort compare !sec;\n\t\ttro := List.sort compare !tro;\n\t\tPrintf.printf \"%d\\n%d\" (prem_dif (!prem,!sec)) (prem_dif (!sec,!tro));;\n\nmain ();;\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet increment h t d = \n let c = try Hashtbl.find h t with Not_found -> 0 in\n if c+d = 0 then Hashtbl.remove h t else Hashtbl.replace h t (c+d)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let b = Array.init (n-1) (fun _ -> read_int()) in\n let c = Array.init (n-2) (fun _ -> read_int()) in\n\n let ha = Hashtbl.create 1000 in\n\n for i=0 to n-1 do\n increment ha a.(i) 1\n done;\n\n for i=0 to n-2 do\n increment ha b.(i) (-1)\n done;\n\n if Hashtbl.length ha <> 1 then failwith \"input wrong 1\";\n let e1 = ref (-1) in\n Hashtbl.iter (fun k v -> e1 := k) ha;\n\n let hb = Hashtbl.create 1000 in\n\n for i=0 to n-2 do\n increment hb b.(i) 1\n done;\n\n for i=0 to n-3 do\n increment hb c.(i) (-1)\n done;\n\n if Hashtbl.length hb <> 1 then failwith \"input wrong 2\";\n let e2 = ref (-1) in\n Hashtbl.iter (fun k v -> e2 := k) hb;\n\n printf \"%d\\n%d\\n\" !e1 !e2\n"}], "negative_code": [{"source_code": "let rec prem_dif = function\n\t|[a],[]\t\t-> a\n\t|t::q,t'::q'\t-> if t=t'\n\t\t\t\tthen prem_dif (q,q')\n\t\t\t\telse t;;\n\nlet main () =\n\tlet n = Scanf.scanf \"%d \" (fun i -> i) and prem = ref []\n\tand sec = ref [] and tro = ref [] in\n\t\tfor i = 1 to n do\n\t\t\tprem := (Scanf.scanf \"%d \" (fun j -> j))::!prem;\n\t\tdone;\n\t\tfor i = 1 to n-1 do\n\t\t\tsec := (Scanf.scanf \"%d \" (fun j -> j))::!sec;\n\t\tdone;\n\t\tfor i = 1 to n-2 do\n\t\t\ttro := (Scanf.scanf \"%d \" (fun j -> j))::!tro;\n\t\tdone;\n\t\tPrintf.printf \"%d\\n%d\" (prem_dif (!prem,!sec)) (prem_dif (!sec,!tro));;\n\nmain ();;\n"}], "src_uid": "1985566215ea5a7f22ef729bac7205ed"} {"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 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\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\nlet sq x = x ** x\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string _ = bscanf Scanning.stdib \" %s \" (fun x -> x)\nlet () = \n let n = read_int () in\n let c1 = long (read_int ()) in\n let c2 = long (read_int ()) in\n let s = read_string() in\n let m = sum 0 (n-1) (fun i -> if s.[i] = '0' then 0 else 1) in (* number of adults *)\n\n let answer = minf 1 m (fun g -> (* g = number of groups *)\n let x1 = n/g in\n let x2 = x1 + 1 in\n let n2 = n - (g * x1) in\n let n1 = g - n2 in\n let (g,n1,n2,x1,x2) = (long g, long n1, long n2, long x1, long x2) in\n c1 ** g ++ c2 ** (n1 ** (sq (x1--1L)) ++ n2 ** (sq (x2 -- 1L)))\n ) in\n\n printf \"%Ld\\n\" answer\n", "positive_code": [{"source_code": "open Printf;;\nopen String;;\n\nlet ( +| ) a b = Int64.add a b;;\nlet ( -| ) a b = Int64.sub a b;;\nlet ( *| ) a b = Int64.mul a b;;\nlet ( /| ) a b = Int64.div a b;;\n\nlet inp = Str.split (Str.regexp \" \") (read_line());;\nlet n = int_of_string (List.nth inp 0);;\nlet c1 = Int64.of_string (List.nth inp 1);;\nlet c2 = Int64.of_string (List.nth inp 2);;\nlet s = read_line();;\n\nlet rec count_one idx =\n if idx = n then 0\n else (if (String.get s idx) = '1' then 1 else 0) + (count_one (idx + 1));;\n \nlet adults = count_one 0;;\n\nlet calc_single x = c1 +| (c2 *| ((x -| 1L) *| (x -| 1L)));;\n \nlet calc_total x = \n let nn = Int64.of_int n in\n let r = Int64.rem nn x in\n (r *| calc_single((nn /| x) +| 1L)) +|\n ((x -| r) *| calc_single(nn /| x));;\n \n\nlet rec process i ans = \n if i > adults then printf \"%Ld\\n\" ans else\n let newcost = calc_total (Int64.of_int i) in\n process (i + 1) (if ans > newcost then newcost else ans);;\n \nlet _ = process 1 Int64.max_int;;"}], "negative_code": [{"source_code": "open Printf;;\nopen String;;\n \nlet inp = Str.split (Str.regexp \" \") (read_line());;\nlet n = int_of_string (List.nth inp 0);;\nlet c1 = Int64.of_string (List.nth inp 1);;\nlet c2 = Int64.of_string (List.nth inp 2);;\nlet s = read_line();;\n\nlet rec can_group len idx adult =\n let slen = (String.length s) in\n if idx = slen then true\n else if (idx mod len) = 0 && (not adult) then false\n else can_group len (idx + 1) (((String.get s idx) = '1')\n || ((idx mod len) > 0 && adult));;\n\nlet rec process i ans = \n if i > n then printf \"%Ld\\n\" ans else\n let newcost = \n if (n mod i) = 0 && (can_group i 0 true) then\n let scost = Int64.add c1 (Int64.mul c2 (Int64.mul (Int64.of_int (i - 1)) (Int64.of_int (i - 1)))) in\n Int64.mul scost (Int64.div (Int64.of_int n) (Int64.of_int i))\n else Int64.max_int in\n process (i + 1) (if ans > newcost then newcost else ans);;\n \nlet _ = process 1 Int64.max_int;;"}, {"source_code": "open Printf;;\nopen String;;\n \nlet inp = Str.split (Str.regexp \" \") (read_line());;\nlet n = int_of_string (List.nth inp 0);;\nlet c1 = Int64.of_string (List.nth inp 1);;\nlet c2 = Int64.of_string (List.nth inp 2);;\nlet s = read_line();;\n\nlet rec can_group len idx adult =\n let slen = (String.length s) in\n if idx = slen then true\n else if (idx mod len) = 0 && (not adult) then false\n else can_group len (idx + 1) (((String.get s idx) = '1')\n || ((idx mod len) > 0 && adult));;\n\nlet rec process i ans = \n if i > n then printf \"%Ld\\n\" ans else\n let newcost = \n if (n mod i) = 0 && (can_group i 0 true) then\n let scost = Int64.add c1 (Int64.mul c2 (Int64.mul (Int64.of_int (i - 1)) (Int64.of_int (i - 1)))) in\n Int64.mul scost (Int64.div (Int64.of_int n) (Int64.of_int i))\n else 1000000000000000000L in\n process (i + 1) (if ans > newcost then newcost else ans);;\n \nlet _ = process 1 1000000000000000000L;;"}], "src_uid": "78d013b01497053b8e321fe7b6ce3760"} {"source_code": "open Printf\r\nopen Scanf\r\n\r\nlet ( ** ) a b = Int64.mul a b\r\nlet ( ++ ) a b = Int64.add a b\r\nlet ( -- ) a b = Int64.sub a b\r\nlet ( // ) a b = Int64.div a b\r\nlet ( %% ) a b = Int64.rem a b\r\n\r\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\r\nlet sum i j f = fold i j (fun i a -> (f i) + a) 0\r\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\r\n\r\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\r\nlet read_string _ = bscanf Scanning.stdin \" %s \" (fun x -> x) \r\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\r\nlet read_tup _ = bscanf Scanning.stdin \" %d %d %d \" (fun x y z -> (x,y,z))\r\n\r\n\r\n\r\nlet rec inp (n : int) = \r\n if (n == 0) \r\n then []\r\n else\r\n let i = read_int () in\r\n let j = read_int () in\r\n let x = read_int () in\r\n \r\n (i - 1, j - 1, x) :: inp (n - 1)\r\n\r\n\r\nlet rec solve (n : int) (m : int) arr = \r\n if (m == 0) \r\n then Array.make n 0\r\n else\r\n let prev = solve n (m / 2) arr in\r\n let z = Array.make n 0 in\r\n let res = Array.make n 0 in\r\n let adj = Array.make n [] in\r\n let rec process aa = \r\n match aa with\r\n [] -> ()\r\n | (i, j, x) :: xs ->\r\n let () = (\r\n if ((x land m) == 0)\r\n then\r\n (* let () = printf \"A %d %d %d %d \\n\" i j x m in *)\r\n let () = Array.set z i 1 in\r\n Array.set z j 1\r\n else\r\n (* let () = printf \"B %d %d %d %d \\n\" i j x m in *)\r\n if (i == j)\r\n then Array.set res i m\r\n else\r\n (\r\n let oldi = Array.get adj i in\r\n let () = Array.set adj i (j :: oldi) in\r\n let oldj = Array.get adj j in\r\n let () = Array.set adj j (i :: oldj) in\r\n ()\r\n )\r\n ) in\r\n process xs\r\n in\r\n let () = process arr in\r\n \r\n let () = \r\n for i = 0 to (n - 1) do\r\n let rec uu aa = \r\n (\r\n match aa with\r\n [] -> ()\r\n | x :: xs -> \r\n let () = (\r\n if ((Array.get z x) == 1)\r\n then Array.set res i m\r\n else ()\r\n ) in\r\n uu xs \r\n )\r\n in\r\n let rec vv aa = \r\n (\r\n match aa with\r\n [] -> ()\r\n | x :: xs -> \r\n let () = Array.set res x m in\r\n (* let () = printf \"%d %d %d \\n\" m i x in *)\r\n vv xs \r\n )\r\n in\r\n let () = uu (Array.get adj i) in\r\n (\r\n if ((Array.get res i) == 0)\r\n then\r\n (* let () = Array.set z i 1 in *)\r\n vv (Array.get adj i)\r\n else \r\n ()\r\n )\r\n done\r\n in\r\n \r\n let () = \r\n for i = 0 to (n - 1) do\r\n Array.set res i ((Array.get res i) + (Array.get prev i))\r\n done\r\n in\r\n res\r\n\r\nlet () = \r\n let t = read_int () in\r\n \r\n for i = 1 to t do\r\n let n = read_int () in\r\n let a = n / 2 in\r\n let b = n / 3 in\r\n \tprintf \"%d\\n\" (n + a + a + b + b)\r\n done\r\n \r\n", "positive_code": [{"source_code": "let rec loop (t : int) =\r\n if t = 0 then\r\n ()\r\n else\r\n let n = read_int () in\r\n let () = print_endline (string_of_int (n + 2*(n / 2) + 2*(n/3))) in\r\n loop (t-1)\r\n;;\r\n\r\nlet t = read_int () in loop t;;\r\n"}, {"source_code": "(* This is an OCaml editor.\r\n Enter your program here and send it to the toplevel using the \"Eval code\"\r\n button or [Ctrl-e]. *)\r\n\r\nlet i = read_int() in\r\nlet rec loop x= \r\n if x=0 then () else \r\n (let j = read_int() in print_int (j+ (j/2)*2 + (j/3)*2);print_newline() ; loop (x-1) )\r\n \r\nin loop i"}], "negative_code": [], "src_uid": "a6b6d9ff2ac5c367c00a64a387cc9e36"} {"source_code": "\n(* [@@@warning \"-30\"] *)\n\ntype vertex = {\n mutable adjacent : vertex array;\n mutable parent : vertex;\n mutable depth : int;\n mutable t_entr : int;\n mutable t_exit : int;\n mutable sigma_d : int64;\n mutable sigma'_d : int64;\n mutable count : int64;\n uf : uf;\n mutable ancestor : vertex;\n mutable colored : bool;\n}\nand uf = {\n mutable parent : vertex;\n mutable rank : int;\n}\n\nmodule H = Hashtbl.Make(struct type t = vertex let equal = (==) let hash v = v.t_entr end)\n\nlet none = -1\n\nlet dummy () =\n let rec v = {\n adjacent = [| |];\n parent = v;\n depth = none;\n t_entr = none;\n t_exit = none;\n sigma_d = 0L;\n sigma'_d = 0L;\n count = 0L;\n uf = { parent = v; rank = 0 };\n ancestor = v;\n colored = false\n }\n in\n v\n\nlet (+~), (-~), zero = Int64.(add, sub, zero)\n\nlet dfs1 root =\n let rec dfs d t p curr =\n curr.t_entr <- t;\n curr.depth <- d;\n curr.parent <- p;\n curr.count <- curr.count +~ 1L;\n let t =\n Array.fold_left\n (fun t v ->\n if v != p then begin\n let t = dfs (d + 1) (t + 1) curr v in\n curr.sigma_d <- curr.sigma_d +~ v.sigma_d +~ v.count;\n curr.count <- curr.count +~ v.count;\n t\n end else t)\n t\n curr.adjacent\n in\n curr.t_exit <- t;\n t\n in\n ignore @@ dfs 0 0 root root\n\nlet dfs2 root =\n let rec dfs curr =\n let p = curr.parent in\n curr.sigma'_d <-\n if p != curr then\n (if p.parent != p then p.sigma'_d +~ root.count -~ p.count else 0L) +~\n p.sigma_d -~ curr.sigma_d -~ curr.count\n else\n 0L;\n Array.iter (fun v -> if v != p then dfs v) curr.adjacent\n in\n dfs root\n\nlet tarjan_olca queries =\n let init v =\n v.uf.parent <- v;\n v.uf.rank <- 0\n in\n let rec find v =\n if v.uf.parent == v then\n v\n else\n let p = find v.uf.parent in\n v.uf.parent <- p;\n p\n in\n let union u v =\n let u, v = find u, find v in\n if u.uf.rank > v.uf.rank then\n v.uf.parent <- u\n else if u.uf.rank < v.uf.rank then\n u.uf.parent <- v\n else if u != v then begin\n v.uf.parent <- u;\n u.uf.rank <- u.uf.rank + 1\n end\n in\n let rec tarjan u =\n init u;\n u.ancestor <- u;\n Array.iter\n (fun v ->\n if v != u.parent then begin\n tarjan v;\n union u v;\n (find u).ancestor <- u\n end)\n u.adjacent;\n u.colored <- true;\n try\n H.iter\n (fun v a ->\n if v.colored then\n let r = (find v).ancestor in\n a := r;\n H.find (H.find queries v) u := r)\n (H.find queries u)\n with\n | Not_found -> ()\n in\n tarjan\n\ntype data = { low : vertex; sub : vertex }\n\ntype path_kind = I of data | V\n\nlet search queries u v =\n let search u v =\n let rec search l r =\n if l = r then u.adjacent.(l)\n else\n let m = l + (r - l) / 2 in\n let m = if u.adjacent.(m) == u.parent then m + 1 else m in\n if u.adjacent.(m).t_entr > v.t_entr then search l (m - 1)\n else if u.adjacent.(m).t_exit < v.t_exit then search (m + 1) r\n else u.adjacent.(m)\n in\n search 0 (Array.length u.adjacent - 1)\n in\n let kind =\n if u.t_entr <= v.t_entr && u.t_exit >= v.t_exit then I { low = v; sub = search u v }\n else if v.t_entr <= u.t_entr && v.t_exit >= u.t_exit then I { low = u; sub = search v u }\n else V\n in\n kind, u.depth + v.depth - 2 * (!H.(find (find queries u) v)).depth\n\nlet solve queries root u v =\n let fl, (+), (/) = Int64.to_float, (+.), (/.) in\n match search queries u v with\n | V, n ->\n float_of_int n + 1. + fl u.sigma_d / fl u.count + fl v.sigma_d / fl v.count\n | I { low; sub } , n ->\n float_of_int n + 1. + fl low.sigma_d / fl low.count + fl sub.sigma'_d / fl (root.count -~ sub.count)\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let vertices = Array.init n (fun _ -> dummy ()) in\n let root = vertices.(0) in\n let edges = Array.make n [] in\n let add a i e = a.(i) <- e :: a.(i) in\n for _ = 1 to n - 1 do\n scanf \"%d %d\\n\" @@ fun a b ->\n add edges (a - 1) vertices.(b - 1);\n add edges (b - 1) vertices.(a - 1)\n done;\n Array.iteri (fun i v -> v.adjacent <- Array.of_list edges.(i)) vertices;\n dfs1 root;\n dfs2 root;\n let queries, queries_list = H.create 32, ref [] in\n let add_query u v =\n H.replace\n (try H.find queries u with Not_found -> let h = H.create 16 in H.replace queries u h; h)\n v\n (ref root)\n in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun u v ->\n let u, v = vertices.(u - 1), vertices.(v - 1) in\n add_query u v ;\n add_query v u;\n queries_list := (u, v) :: !queries_list\n done;\n tarjan_olca queries vertices.(0);\n List.(iter (fun (u, v) -> Printf.printf \"%.7f\\n\" @@ solve queries root u v) @@ rev !queries_list)\n", "positive_code": [{"source_code": "\nmodule H = Hashtbl.Make(struct type t = int let equal = ((=) : int -> int -> _) let hash x = x end)\n\ntype tree = {\n verts : int array;\n edges : int array array;\n parent : int array;\n depth : int array;\n t_entr : int array;\n t_exit : int array;\n sigma_d : int64 array;\n sigma'_d : int64 array;\n count : int64 array;\n\n uf_parent : int array;\n uf_rank : int array;\n ancestor : int array;\n colored : bool array;\n queries : int ref H.t H.t;\n}\n\nlet (+~), (-~), zero, none = Int64.(add, sub, zero, -1)\n\nlet incr a i n = a.(i) <- a.(i) +~ n\n\nlet dfs1 { verts; edges; parent; depth; t_entr; t_exit; sigma_d; count } =\n let rec dfs d t p curr =\n verts.(t) <- curr;\n t_entr.(curr) <- t;\n depth.(curr) <- d;\n parent.(curr) <- p;\n incr count curr 1L;\n let t =\n Array.fold_left\n (fun t v ->\n if v <> p then begin\n let t = dfs (d + 1) (t + 1) curr v in\n incr sigma_d curr @@ sigma_d.(v) +~ count.(v);\n incr count curr @@ count.(v);\n t\n end else t)\n t\n edges.(curr)\n in\n t_exit.(curr) <- t;\n t\n in\n ignore @@ dfs 0 0 none 0\n\nlet dfs2 { edges; parent; sigma'_d; sigma_d; count } =\n let rec dfs curr =\n let p = parent.(curr) in\n sigma'_d.(curr) <-\n if p <> none then\n (if parent.(p) <> none then sigma'_d.(p) +~ count.(0) -~ count.(p) else 0L) +~\n sigma_d.(p) -~ sigma_d.(curr) -~ count.(curr)\n else\n 0L;\n Array.iter (fun v -> if v <> p then dfs v) edges.(curr)\n in\n dfs 0\n\nlet tarjan_olca { edges; parent; uf_parent; uf_rank; ancestor; colored; queries } =\n let init v =\n uf_parent.(v) <- v;\n uf_rank.(v) <- 0\n in\n let rec find v =\n if uf_parent.(v) == v then\n v\n else\n let p = find uf_parent.(v) in\n uf_parent.(v) <- p;\n p\n in\n let union u v =\n let u, v = find u, find v in\n if uf_rank.(u) > uf_rank.(v) then\n uf_parent.(v) <- u\n else if uf_rank.(u) < uf_rank.(v) then\n uf_parent.(u) <- v\n else if u <> v then begin\n uf_parent.(v) <- u;\n uf_rank.(u) <- uf_rank.(u) + 1\n end\n in\n let rec tarjan u =\n init u;\n ancestor.(u) <- u;\n Array.iter\n (fun v ->\n if v <> parent.(u) then begin\n tarjan v;\n union u v;\n ancestor.(find u) <- u\n end)\n edges.(u);\n colored.(u) <- true;\n try\n H.iter\n (fun v a ->\n if colored.(v) then\n let r = ancestor.(find v) in\n a := r;\n H.find (H.find queries v) u := r)\n (H.find queries u)\n with\n | Not_found -> ()\n in\n tarjan 0\n\ntype data = { low : int; sub : int }\n\ntype path_kind = I of data | V\n\nlet search { verts; edges; parent; t_entr; t_exit; depth; queries } u v =\n let search u v =\n let rec search l r =\n if l = r then edges.(u).(l)\n else\n let m = l + (r - l) / 2 in\n let m = if edges.(u).(m) = parent.(u) then m + 1 else m in\n if t_entr.(edges.(u).(m)) > t_entr.(v) then search l (m - 1)\n else if t_exit.(edges.(u).(m)) < t_exit.(v) then search (m + 1) r\n else edges.(u).(m)\n in\n search 0 (Array.length edges.(u) - 1)\n in\n let kind =\n if t_entr.(u) <= t_entr.(v) && t_exit.(u) >= t_exit.(v) then I { low = v; sub = search u v }\n else if t_entr.(v) <= t_entr.(u) && t_exit.(v) >= t_exit.(u) then I { low = u; sub = search v u }\n else V\n in\n kind, depth.(u) + depth.(v) - 2 * depth.(!H.(find (find queries u) v))\n\nlet solve ({ sigma_d; sigma'_d; count } as t) u v =\n let fl, (+), (/) = Int64.to_float, (+.), (/.) in\n match search t u v with\n | V, n ->\n float_of_int n + 1. + fl sigma_d.(u) / fl count.(u) + fl sigma_d.(v) / fl count.(v)\n | I { low; sub } , n ->\n float_of_int n + 1. + fl sigma_d.(low) / fl count.(low) + fl sigma'_d.(sub) / fl (count.(0) -~ count.(sub))\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let edges = Array.make n [] in\n let add a i e = a.(i) <- e :: a.(i) in\n for _ = 1 to n - 1 do\n scanf \"%d %d\\n\" @@ fun a b ->\n add edges (a - 1) (b - 1);\n add edges (b - 1) (a - 1)\n done;\n let t =\n Array.{\n verts = make n none;\n edges = init n (fun i -> Array.of_list edges.(i));\n parent = make n none;\n depth = make n none;\n t_entr = make n none;\n t_exit = make n none;\n sigma_d = make n zero;\n sigma'_d = make n zero;\n count = make n zero;\n\n uf_parent = make n none;\n uf_rank = make n none;\n ancestor = make n none;\n colored = make n false;\n queries = H.create 32;\n }\n in\n dfs1 t;\n dfs2 t;\n let queries = ref [] in\n let add_query u v =\n H.replace\n (try H.find t.queries u with Not_found -> let h = H.create 16 in H.replace t.queries u h; h)\n v\n (ref none)\n in\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun u v ->\n add_query (u - 1) (v - 1);\n add_query (v - 1) (u - 1);\n queries := (u - 1, v - 1) :: !queries\n done;\n tarjan_olca t;\n List.(iter (fun (u, v) -> Printf.printf \"%.7f\\n\" @@ solve t u v) @@ rev !queries)\n"}, {"source_code": " (* keywords: dynamic programming, tree DP, union find, tarjan LCA *)\n (* see also ~/Sync/contest-work/NCPC-2014/particle/ *)\n\nlet order (a,b) = (min a b, max a b)\n\nlet ( ** ) a b = Int64.mul a b\nlet ( ++ ) a b = Int64.add a b\nlet long x = Int64.of_int x\nlet float = Int64.to_float\n\nopen Printf\nopen Scanf\n\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,m) = read_pair () in\n\n let tree = Array.make n [] in\n \n for i=1 to n-1 do\n let (a,b) = read_pair () in\n let (a,b) = (a-1,b-1) in\n tree.(a) <- b::tree.(a);\n tree.(b) <- a::tree.(b); \n done;\n\n let qgraph = Array.make n [] in\n let query = Array.make m (0,0) in\n \n for i=0 to m-1 do\n let (a,b) = read_pair () in\n let (a,b) = (a-1,b-1) in\n query.(i) <- (a,b);\n qgraph.(a) <- b::qgraph.(a);\n qgraph.(b) <- a::qgraph.(b); \n done;\n\n (* ------------------ union find ------------------- *)\n let uf = Array.make n (-1) in\n\n let rec find i = if uf.(i) < 0 then i else \n let r = find uf.(i) in\n uf.(i) <- r;\n r\n in\n \n let union i j =\n (* assume i and j are both canonical elements *)\n (* true union by rank (not size) *)\n let (wi,wj) = (-uf.(i), -uf.(j)) in\n let (wi,wj,i,j) = if wi < wj then (wi,wj,i,j) else (wj,wi,j,i) in\n uf.(j) <- - ((if wi=wj then 1 else 0) + wj);\n uf.(i) <- j;\n in\n (* ---------------- end union find ------------------ *)\n\n\n (* pure version\n (* ------------------ off-line LCA ------------------- *)\n let lca = Hashtbl.create 100 in\n let mark = Array.make n false in\n let ancestor = Array.make n 0 in\n \n let rec tarjan p u =\n List.iter (fun v -> if v <> p then (\n tarjan u v;\n union (find u) (find v);\n ancestor.(find u) <- u\n )) tree.(u);\n \n mark.(u) <- true;\n \n List.iter (fun v ->\n if mark.(v) then Hashtbl.replace lca (order (u,v)) ancestor.(find v)\n ) qgraph.(u)\n in\n tarjan (-1) 0;\n\n (* Hashtbl.iter (fun (u,v) a -> printf \"LCA(%d,%d) = %d\\n\" (u+1) (v+1) (a+1)) lca; *)\n (* ---------------- end off-line LCA ------------------ *) *)\n\n (* ------------------ customized off-line LCA ------------------- *)\n let nbr = Hashtbl.create 100 in\n let dist = Hashtbl.create 100 in \n let mark = Array.make n false in\n let on_stack = Array.make n false in \n let ancestor = Array.make n 0 in\n let current_child = Array.make n 0 in\n let parent = Array.make n 0 in\n let depth = Array.make n 0 in\n \n let rec tarjan p u d =\n parent.(u) <- p;\n depth.(u) <- d;\n on_stack.(u) <- true;\n List.iter (fun v -> if v <> p then (\n current_child.(u) <- v;\n tarjan u v (d+1);\n union (find u) (find v);\n ancestor.(find u) <- u\n )) tree.(u);\n\n on_stack.(u) <- false;\n mark.(u) <- true;\n \n List.iter (fun v ->\n if mark.(v) then (\n\tlet lca = ancestor.(find v) in\n\tlet distance = depth.(v) + depth.(u) - 2*depth.(lca) in\n\tHashtbl.add dist (order (u,v)) distance;\n\tif u <> lca then Hashtbl.add nbr (u,v) p;\n\tif v <> lca then Hashtbl.add nbr (v,u) parent.(v)\n ) else (\n\tif on_stack.(v) then Hashtbl.add nbr (v,u) current_child.(v)\n )\n ) qgraph.(u)\n in\n tarjan (-1) 0 0;\n (* --------------------------------------------------------------- *)\n\n (* now count paths *)\n\n let info = Hashtbl.create 100 in\n\n let rec dfs p u =\n try Hashtbl.find info (p,u) with Not_found ->\n let answer =\n\tList.fold_left (fun (ac_len, ac_n) v ->\n\t if v = p then (ac_len, ac_n) else\n\t let (pathlen, nnodes) = dfs u v in\n\t (ac_len ++ pathlen ++ nnodes, ac_n ++ nnodes)\n\t) (0L, 1L) tree.(u)\n in\n Hashtbl.add info (p,u) answer;\n answer\n in\n\n for i=0 to m-1 do\n let (u,v) = query.(i) in\n let nu = Hashtbl.find nbr (u,v) in\n let nv = Hashtbl.find nbr (v,u) in\n let (len_u, n_u) = dfs nu u in\n let (len_v, n_v) = dfs nv v in\n let ave_len_u = (float len_u) /. (float n_u) in\n let ave_len_v = (float len_v) /. (float n_v) in\n let path_dist = float (long (Hashtbl.find dist (order (u,v)))) in\n printf \"%.8f\\n\" (1.0 +. ave_len_u +. ave_len_v +. path_dist)\n done;\n"}], "negative_code": [{"source_code": "\ntype tree = {\n verts : int array;\n edges : int array array;\n parent : int array;\n depth : int array;\n t_entr : int array;\n t_exit : int array;\n sigma_d : int64 array;\n sigma'_d : int64 array;\n count : int64 array\n}\n\nlet (+~), (-~), zero, none = Int64.(add, sub, zero, -1)\n\nlet incr a i n = a.(i) <- a.(i) +~ n\n\nlet dfs1 { verts; edges; parent; depth; t_entr; t_exit; sigma_d; count } =\n let rec dfs d t p curr =\n verts.(t) <- curr;\n t_entr.(curr) <- t;\n depth.(curr) <- d;\n parent.(curr) <- p;\n incr count curr 1L;\n let t =\n Array.fold_left\n (fun t v ->\n if v <> p then begin\n let t = dfs (d + 1) (t + 1) curr v in\n incr sigma_d curr @@ sigma_d.(v) +~ count.(v);\n incr count curr @@ count.(v);\n t\n end else t)\n t\n edges.(curr)\n in\n t_exit.(curr) <- t;\n t\n in\n ignore @@ dfs 0 0 none 0\n\nlet dfs2 { edges; parent; sigma'_d; sigma_d; count } =\n let rec dfs curr =\n let p = parent.(curr) in\n sigma'_d.(curr) <-\n if p <> none then\n (if parent.(p) <> none then sigma'_d.(p) +~ count.(0) -~ count.(p) else 0L) +~\n sigma_d.(p) -~ sigma_d.(curr) -~ count.(curr)\n else\n 0L;\n Array.iter (fun v -> if v <> p then dfs v) edges.(curr)\n in\n dfs 0\n\ntype data = { low : int; sub : int }\n\ntype path_kind = I of data | V\n\nlet search { verts; edges; t_entr; t_exit; depth } u v =\n let search u v =\n let rec search l r =\n if l = r then edges.(u).(l)\n else\n let m = l + (r - l) / 2 in\n if t_entr.(edges.(u).(m)) > t_entr.(v) then search l (m - 1)\n else if t_exit.(edges.(u).(m)) < t_exit.(u) then search (m + 1) r\n else edges.(u).(m)\n in\n search 0 (Array.length edges.(u) - 1)\n in\n let kind =\n if t_entr.(u) <= t_entr.(v) && t_exit.(u) >= t_exit.(v) then I { low = v; sub = search u v }\n else if t_entr.(v) <= t_entr.(u) && t_exit.(v) >= t_exit.(u) then I { low = u; sub = search v u }\n else V\n in\n let rec search l r =\n if l = r then verts.(l)\n else\n let m = l + (r - l + 1) / 2 in\n (*Printf.eprintf \"m=%d(%d) t_entr.(m)=%d t_exit.(m)=%d t_entr.(u)=%d t_entr.(v)=%d\\n\"\n m verts.(m) t_entr.(verts.(m)) t_exit.(verts.(m)) t_entr.(u) t_entr.(v);*)\n if t_entr.(verts.(m)) > min t_entr.(u) t_entr.(v) ||\n t_exit.(verts.(m)) < max t_exit.(u) t_exit.(v)\n then search l (m - 1)\n else search m r\n in\n (*Printf.eprintf \"For u=%d v=%d search gave %d\\n\" u v (search 0 (Array.length verts - 1));*)\n kind, depth.(u) + depth.(v) - 2 * depth.(search 0 (Array.length verts - 1))\n\nlet solve ({ sigma_d; sigma'_d; count } as t) u v =\n let fl, (+), (/) = Int64.to_float, (+.), (/.) in\n match search t u v with\n | V, n ->\n float_of_int n + 1. + fl sigma_d.(u) / fl count.(u) + fl sigma_d.(v) / fl count.(v)\n | I { low; sub } , n ->\n (*Printf.eprintf \"u=%d v=%d n=%d s=%d l=%d fp=%f num=%f den=%f\\n\"\n u v n sub low\n (float_of_int n + 1. + fl sigma_d.(low) / fl count.(low))\n (fl sigma'_d.(sub))\n (fl (count.(0) -~ count.(sub)));*)\n float_of_int n + 1. + fl sigma_d.(low) / fl count.(low) + fl sigma'_d.(sub) / fl (count.(0) -~ count.(sub))\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let edges = Array.make n [] in\n let add a i e = a.(i) <- e :: a.(i) in\n for _ = 1 to n - 1 do\n scanf \"%d %d\\n\" @@ fun a b ->\n add edges (a - 1) (b - 1);\n add edges (b - 1) (a - 1)\n done;\n let t =\n Array.{\n verts = make n none;\n edges = init n (fun i -> Array.of_list edges.(i));\n parent = make n none;\n depth = make n none;\n t_entr = make n none;\n t_exit = make n none;\n sigma_d = make n zero;\n sigma'_d = make n zero;\n count = make n zero\n }\n in\n dfs1 t;\n dfs2 t;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun u v -> Printf.printf \"%.7f\\n\" @@ solve t (u - 1) (v - 1)\n done\n"}, {"source_code": "\ntype tree = {\n verts : int array;\n edges : int array array;\n parent : int array;\n depth : int array;\n t_entr : int array;\n t_exit : int array;\n sigma_d : int64 array;\n sigma'_d : int64 array;\n count : int64 array\n}\n\nlet (+~), (-~), zero, none = Int64.(add, sub, zero, -1)\n\nlet incr a i n = a.(i) <- a.(i) +~ n\n\nlet dfs1 { verts; edges; parent; depth; t_entr; t_exit; sigma_d; count } =\n let rec dfs d t p curr =\n verts.(t) <- curr;\n t_entr.(curr) <- t;\n depth.(curr) <- d;\n parent.(curr) <- p;\n incr count curr 1L;\n let t =\n Array.fold_left\n (fun t v ->\n if v <> p then begin\n let t = dfs (d + 1) (t + 1) curr v in\n incr sigma_d curr @@ sigma_d.(v) +~ count.(v);\n incr count curr @@ count.(v);\n t\n end else t)\n t\n edges.(curr)\n in\n t_exit.(curr) <- t;\n t\n in\n ignore @@ dfs 0 0 none 0\n\nlet dfs2 { edges; parent; sigma'_d; sigma_d; count } =\n let rec dfs curr =\n let p = parent.(curr) in\n sigma'_d.(curr) <-\n if p <> none then\n (if parent.(p) <> none then sigma'_d.(p) +~ count.(0) -~ count.(p) else 0L) +~\n sigma_d.(p) -~ sigma_d.(curr) -~ count.(curr)\n else\n 0L;\n Array.iter (fun v -> if v <> p then dfs v) edges.(curr)\n in\n dfs 0\n\ntype data = { low : int; sub : int }\n\ntype path_kind = I of data | V\n\nlet search { verts; edges; parent; t_entr; t_exit; depth } u v =\n let search u v =\n let rec search l r =\n if l = r then edges.(u).(l)\n else\n let m = l + (r - l) / 2 in\n let m = if edges.(u).(m) = parent.(u) then m + 1 else m in\n if t_entr.(edges.(u).(m)) > t_entr.(v) then search l (m - 1)\n else if t_exit.(edges.(u).(m)) < t_exit.(v) then search (m + 1) r\n else edges.(u).(m)\n in\n search 0 (Array.length edges.(u) - 1)\n in\n let kind =\n if t_entr.(u) <= t_entr.(v) && t_exit.(u) >= t_exit.(v) then I { low = v; sub = search u v }\n else if t_entr.(v) <= t_entr.(u) && t_exit.(v) >= t_exit.(u) then I { low = u; sub = search v u }\n else V\n in\n let rec search best l r =\n (*Printf.eprintf \"best=%d l=%d r=%d\\n\" best l r;*)\n if l > r then verts.(best)\n else\n let m = l + (r - l + 1) / 2 in\n (*Printf.eprintf \"m=%d(%d) t_entr.(m)=%d t_exit.(m)=%d t_entr.(u)=%d t_entr.(v)=%d\\n\"\n m verts.(m) t_entr.(verts.(m)) t_exit.(verts.(m)) t_entr.(u) t_entr.(v);*)\n if t_entr.(verts.(m)) > min t_entr.(u) t_entr.(v) then search best l (m - 1)\n else if t_exit.(verts.(m)) < max t_exit.(u) t_exit.(v) then search best (m + 1) r\n else if m = r then verts.(m)\n else search m m r\n in\n (*Printf.eprintf \"For u=%d v=%d search gave %d\\n\" u v (search 0 0 (Array.length verts - 1));*)\n kind, depth.(u) + depth.(v) - 2 * depth.(search 0 0 (Array.length verts - 1))\n\nlet solve ({ sigma_d; sigma'_d; count } as t) u v =\n let fl, (+), (/) = Int64.to_float, (+.), (/.) in\n match search t u v with\n | V, n ->\n float_of_int n + 1. + fl sigma_d.(u) / fl count.(u) + fl sigma_d.(v) / fl count.(v)\n | I { low; sub } , n ->\n (*Printf.eprintf \"sub=%d\" sub;*)\n (*Printf.eprintf \"u=%d v=%d n=%d s=%d l=%d fp=%f num=%f den=%f\\n\"\n u v n sub low\n (float_of_int n + 1. + fl sigma_d.(low) / fl count.(low))\n (fl sigma'_d.(sub))\n (fl (count.(0) -~ count.(sub)));*)\n float_of_int n + 1. + fl sigma_d.(low) / fl count.(low) + fl sigma'_d.(sub) / fl (count.(0) -~ count.(sub))\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let edges = Array.make n [] in\n let add a i e = a.(i) <- e :: a.(i) in\n for _ = 1 to n - 1 do\n scanf \"%d %d\\n\" @@ fun a b ->\n add edges (a - 1) (b - 1);\n add edges (b - 1) (a - 1)\n done;\n let t =\n Array.{\n verts = make n none;\n edges = init n (fun i -> Array.of_list edges.(i));\n parent = make n none;\n depth = make n none;\n t_entr = make n none;\n t_exit = make n none;\n sigma_d = make n zero;\n sigma'_d = make n zero;\n count = make n zero\n }\n in\n dfs1 t;\n dfs2 t;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun u v -> Printf.printf \"%.7f\\n\" @@ solve t (u - 1) (v - 1)\n done\n"}, {"source_code": "\ntype tree = {\n verts : int array;\n edges : int array array;\n parent : int array;\n depth : int array;\n t_entr : int array;\n t_exit : int array;\n sigma_d : int64 array;\n sigma'_d : int64 array;\n count : int64 array\n}\n\nlet (+~), (-~), zero, none = Int64.(add, sub, zero, -1)\n\nlet incr a i n = a.(i) <- a.(i) +~ n\n\nlet dfs1 { verts; edges; parent; depth; t_entr; t_exit; sigma_d; count } =\n let rec dfs d t p curr =\n verts.(t) <- curr;\n t_entr.(curr) <- t;\n depth.(curr) <- d;\n parent.(curr) <- p;\n incr count curr 1L;\n let t =\n Array.fold_left\n (fun t v ->\n if v <> p then begin\n let t = dfs (d + 1) (t + 1) curr v in\n incr sigma_d curr @@ sigma_d.(v) +~ count.(v);\n incr count curr @@ count.(v);\n t\n end else t)\n t\n edges.(curr)\n in\n t_exit.(curr) <- t;\n t\n in\n ignore @@ dfs 0 0 none 0\n\nlet dfs2 { edges; parent; sigma'_d; sigma_d; count } =\n let rec dfs curr =\n let p = parent.(curr) in\n sigma'_d.(curr) <-\n if p <> none then\n (if parent.(p) <> none then sigma'_d.(p) +~ count.(0) -~ count.(p) else 0L) +~\n sigma_d.(p) -~ sigma_d.(curr) -~ count.(curr)\n else\n 0L;\n Array.iter (fun v -> if v <> p then dfs v) edges.(curr)\n in\n dfs 0\n\ntype data = { low : int; sub : int }\n\ntype path_kind = I of data | V\n\nlet search { verts; edges; t_entr; t_exit; depth } u v =\n let search u v =\n let rec search l r =\n if l = r then edges.(u).(l)\n else\n let m = l + (r - l) / 2 in\n if t_entr.(edges.(u).(m)) > t_entr.(v) then search l (m - 1)\n else if t_exit.(edges.(u).(m)) < t_exit.(u) then search (m + 1) r\n else edges.(u).(m)\n in\n search 0 (Array.length edges.(u) - 1)\n in\n let kind =\n if t_entr.(u) <= t_entr.(v) && t_exit.(u) >= t_exit.(v) then I { low = v; sub = search u v }\n else if t_entr.(v) <= t_entr.(u) && t_exit.(v) >= t_exit.(u) then I { low = u; sub = search v u }\n else V\n in\n let rec search best l r =\n (*Printf.eprintf \"best=%d l=%d r=%d\\n\" best l r;*)\n if l > r then verts.(best)\n else\n let m = l + (r - l + 1) / 2 in\n (*Printf.eprintf \"m=%d(%d) t_entr.(m)=%d t_exit.(m)=%d t_entr.(u)=%d t_entr.(v)=%d\\n\"\n m verts.(m) t_entr.(verts.(m)) t_exit.(verts.(m)) t_entr.(u) t_entr.(v);*)\n if t_entr.(verts.(m)) > min t_entr.(u) t_entr.(v) then search best l (m - 1)\n else if t_exit.(verts.(m)) < max t_exit.(u) t_exit.(v) then search best (m + 1) r\n else if m = r then verts.(m)\n else search m m r\n in\n (*Printf.eprintf \"For u=%d v=%d search gave %d\\n\" u v (search 0 0 (Array.length verts - 1));*)\n kind, depth.(u) + depth.(v) - 2 * depth.(search 0 0 (Array.length verts - 1))\n\nlet solve ({ sigma_d; sigma'_d; count } as t) u v =\n let fl, (+), (/) = Int64.to_float, (+.), (/.) in\n match search t u v with\n | V, n ->\n float_of_int n + 1. + fl sigma_d.(u) / fl count.(u) + fl sigma_d.(v) / fl count.(v)\n | I { low; sub } , n ->\n (*Printf.eprintf \"u=%d v=%d n=%d s=%d l=%d fp=%f num=%f den=%f\\n\"\n u v n sub low\n (float_of_int n + 1. + fl sigma_d.(low) / fl count.(low))\n (fl sigma'_d.(sub))\n (fl (count.(0) -~ count.(sub)));*)\n float_of_int n + 1. + fl sigma_d.(low) / fl count.(low) + fl sigma'_d.(sub) / fl (count.(0) -~ count.(sub))\n\nlet () =\n let open Scanf in\n scanf \"%d %d\\n\" @@ fun n m ->\n let edges = Array.make n [] in\n let add a i e = a.(i) <- e :: a.(i) in\n for _ = 1 to n - 1 do\n scanf \"%d %d\\n\" @@ fun a b ->\n add edges (a - 1) (b - 1);\n add edges (b - 1) (a - 1)\n done;\n let t =\n Array.{\n verts = make n none;\n edges = init n (fun i -> Array.of_list edges.(i));\n parent = make n none;\n depth = make n none;\n t_entr = make n none;\n t_exit = make n none;\n sigma_d = make n zero;\n sigma'_d = make n zero;\n count = make n zero\n }\n in\n dfs1 t;\n dfs2 t;\n for _ = 1 to m do\n scanf \"%d %d\\n\" @@ fun u v -> Printf.printf \"%.7f\\n\" @@ solve t (u - 1) (v - 1)\n done\n"}], "src_uid": "2c1a2f8b91dd40e39763b5bedd8ad01a"} {"source_code": "open Scanf;;\nopen Num;;\nopen Printf;;\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x);;\n\nlet imatch = Array.create n (num_of_int 0);;\nlet kmatch = ref (Num.num_of_int 0);;\n\nfor i = 0 to n-1 do\n let ni = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x) in\n imatch.(i) <- num_of_int ni; kmatch := (num_of_int ni) +/ !kmatch\ndone\n;;\n\n(*Remove the average*)\nlet av = div_num !kmatch (num_of_int n) in\nfor i = 0 to n - 1 do\n imatch.(i) <- imatch.(i) -/ av\ndone\n;;\n\n(*Array.iter (fun x -> print_int x; print_endline \"\") imatch;;*)\n\nlet sum_over i j =\n let total = ref (num_of_int 0) in\n for k = i to j do\n total := !total +/ imatch.(k)\n done; total\n;;\n\nlet rec direct_cal nl nr rslt = \n if nl = nr then\n rslt +/ !(sum_over nl nr)\n else\n let mid = (nl + nr) / 2 in\n let a = !(sum_over nl mid) in\n imatch.(mid) <- imatch.(mid) -/ a;\n imatch.(mid+1)<-imatch.(mid+1) +/ a;\n rslt +/ (abs_num a) +/ (direct_cal nl mid (num_of_int 0)) +/\n (direct_cal (mid + 1) nr (num_of_int 0)) \n;;\n\nlet rslt = direct_cal 0 (n-1) (num_of_int 0) in\nprint_endline (string_of_num \n (abs_num rslt) );;\n\n(* earlier dubug\nprintf \"%d %d\\n\" n !kmatch\n*)\n", "positive_code": [{"source_code": "(**D. The Child and Sequence*)\n\nopen Scanf;;\nopen Num;;\nopen Printf;;\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x);;\n\nlet imatch = Array.create n (num_of_int 0);;\nlet kmatch = ref (Num.num_of_int 0);;\n\nfor i = 0 to n-1 do\n let ni = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x) in\n imatch.(i) <- num_of_int ni; kmatch := (num_of_int ni) +/ !kmatch\ndone\n;;\n\n(*Remove the average*)\nlet av = div_num !kmatch (num_of_int n) in\nfor i = 0 to n - 1 do\n imatch.(i) <- imatch.(i) -/ av\ndone\n;;\n\n(*Array.iter (fun x -> print_int x; print_endline \"\") imatch;;*)\n\nlet sum_over i j =\n let total = ref (num_of_int 0) in\n for k = i to j do\n total := !total +/ imatch.(k)\n done; total\n;;\n\nlet rec direct_cal nl nr rslt = \n if nl = nr then\n rslt +/ !(sum_over nl nr)\n else\n let mid = (nl + nr) / 2 in\n let a = !(sum_over nl mid) in\n imatch.(mid) <- imatch.(mid) -/ a;\n imatch.(mid+1)<-imatch.(mid+1) +/ a;\n rslt +/ (abs_num a) +/ (direct_cal nl mid (num_of_int 0)) +/\n (direct_cal (mid + 1) nr (num_of_int 0)) \n;;\n\nlet rslt = direct_cal 0 (n-1) (num_of_int 0) in\nprint_endline (string_of_num \n (abs_num rslt) );;\n\n(* earlier dubug\nprintf \"%d %d\\n\" n !kmatch\n*)\n"}], "negative_code": [], "src_uid": "41ae8b0dee3b0f4e91bd06e4a0635492"} {"source_code": "open String\n \nlet read_ints() = Array.map (int_of_string) (Array.of_list (Str.split (Str.regexp \" +\") (read_line())));;\nlet n = read_int();;\n\nfor i = 0 to (n - 1) do \n let size = read_int() and \n arr = read_ints() and \n cnt = ref 0 in (\n for j = 0 to (size - 1) do \n if arr.(j) mod 2 = 0\n then cnt := !cnt + 1\n done;\n print_int (min (size - !cnt) !cnt)\n );\n print_newline ()\ndone\n", "positive_code": [{"source_code": "(* 2x-1+2y-1=2(x+y-1)\r\no + o = e, o+e=o\r\nwe either need all odd \r\nor all even\r\n\r\ne.g if we have odd anywhere in sequence,\r\nthe next number must be odd or it must be end of seq,\r\nif it end of seq , the numbers before must be odd\r\n*)\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x->x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x->x);;\r\n\r\nlet rec read_seq = function\r\n| 0 -> 0\r\n| n ->\r\n let item = read_int () in\r\n if (item mod 2 ==0) then 1 + read_seq (n-1)\r\n else read_seq (n-1)\r\n;;\r\n \r\nlet run_case = function\r\n| () -> \r\n let n = read_int () in\r\n let even_count = read_seq n in\r\n if (even_count<=n-even_count) then even_count\r\n else n-even_count\r\n;;\r\n\r\nlet rec iter_cases = function\r\n| 0 -> 0\r\n| n -> \r\n print_int (run_case ());\r\n print_newline ();\r\n iter_cases (n-1)\r\n;;\r\n\r\nlet t= read_int () in \r\niter_cases t;;"}], "negative_code": [{"source_code": "open String\nopen Printf \n \nlet read_ints() = Array.map (int_of_string) (Array.of_list (Str.split (Str.regexp \" +\") (read_line())));;\nlet n = read_int();;\n\nfor i = 0 to (n - 1) do \n let size = read_int() and \n arr = read_ints() and \n cnt = ref 0 in (\n for j = 0 to (size - 1) do \n if arr.(j) mod 2 = 0\n then cnt := !cnt + 1\n done;\n print_int (min (size - !cnt) !cnt)\n )\ndone\n"}, {"source_code": "(* 2x-1+2y-1=2(x+y-1)\r\no + o = e, o+e=o\r\nwe either need all odd \r\nor all even\r\n\r\ne.g if we have odd anywhere in sequence,\r\nthe next number must be odd or it must be end of seq,\r\nif it end of seq , the numbers before must be odd\r\n*)\r\n\r\nlet read_int () = Scanf.scanf \" %d\" (fun x->x);;\r\nlet read_float () = Scanf.scanf \" %f\" (fun x->x);;\r\n\r\nlet rec read_seq = function\r\n| 0 -> 0\r\n| n ->\r\n let item = read_int () in\r\n if (item mod 2 ==0) then 1 + read_seq (n-1)\r\n else read_seq (n-1)\r\n;;\r\n \r\nlet run_case = function\r\n| () -> \r\n let n = read_int () in\r\n let even_count = read_seq n in\r\n if (even_count<=n-even_count) then even_count\r\n else n-even_count\r\n;;\r\n\r\nlet rec iter_cases = function\r\n| 0 -> 0\r\n| n -> \r\n print_int (run_case ());\r\n iter_cases (n-1)\r\n;;\r\n\r\nlet t= read_int () in \r\niter_cases t;;"}], "src_uid": "4b33db3950303b8993812cb265fa9819"} {"source_code": "let split_words = Str.split (Str.regexp \" \")\n\nexception Break\n\nlet primes =\n let array = Array.make 1_000_001 true in\n array.(0) <- false;\n array.(1) <- false;\n begin try\n for i = 2 to Array.length array do\n if array.(i)\n then (\n if i * i >= Array.length array\n then (raise Break);\n for j = i to (Array.length array - 1) / i do\n array.(i * j) <- false\n done)\n done\n with\n | _ -> ()\n end;\n array\n;;\n\nlet is_prime n = primes.(Int64.to_int n)\n\nlet is_t_prime n =\n let sq = Int64.of_float (sqrt (Int64.to_float n)) in\n Int64.mul sq sq = n && is_prime sq\n;;\n\nlet () =\n ignore (input_line stdin);\n input_line stdin\n |> split_words\n |> List.map Int64.of_string\n |> List.iter (fun number ->\n if is_t_prime number\n then (print_endline \"YES\")\n else (print_endline \"NO\"))\n;;\n", "positive_code": [{"source_code": "let sieve () =\n let nums = Array.make 1000001 true in\n nums.(0) <- false;\n nums.(1) <- false;\n for i = 2 to 1000000 do\n if nums.(i) then\n let rec walk j = \n\tif j > 1000000 then ()\n\telse begin\n\t nums.(j) <- false;\n\t walk (j + i) \n\tend in\n walk (i+i)\n done;\n nums\n\nlet main = \n let primes = sieve () in\n let n = Scanf.scanf \"%d\" (fun n -> n) in\n for i = 1 to n do\n let f = Scanf.scanf \" %f\" (fun f -> f) in\n let (ff, fi) = modf (sqrt f) in\n if ff > 0.000001 then \n Printf.printf \"NO\\n\"\n else \n Printf.printf \"%s\\n\" (if primes.(int_of_float fi) then \"YES\" else \"NO\")\n done;\n \n \n"}, {"source_code": "module I64 = struct\nlet ( / ) = Int64.div\nlet ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( mod ) = Int64.rem\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\nend\n\nlet is_prime =\n let n = 1000000 in\n let a = Array.make (n + 1) true in\n let rec loop i =\n if i * i <= n\n then\n ((if a.(i)\n then\n let rec looper j =\n if j > n\n then\n ()\n else\n (Array.set a j false;\n looper (j + i))\n in looper (i * i)\n else\n ());\n loop (i + 1))\n else\n ()\n in loop 2;\n Array.set a 0 false;\n Array.set a 1 false;\n\n fun i -> a.(i)\n\nlet find_sqrt n =\n let open I64 in\n let r = Pervasives.sqrt (Int64.to_float n) in\n let rec loop (+) (<) approx =\n if approx * approx < n\n then\n loop (+) (<) (approx + one)\n else\n approx\n in \n let r = loop (-) (>) (loop (+) (<) (Int64.of_float r)) in\n if r * r = n\n then\n Some (Int64.to_int r)\n else\n None\n\nlet is_tprime n =\n match (find_sqrt n) with\n | Some r -> is_prime r\n | None -> false\n\nlet () = \n let length = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop i =\n if i < length\n then\n let number = Scanf.scanf \"%Ld \" (fun n -> n) in\n (if is_tprime number\n then\n Printf.printf \"YES\\n\"\n else\n Printf.printf \"NO\\n\");\n loop (i + 1)\n else\n ()\n in loop 0"}], "negative_code": [{"source_code": "module I64 = struct\nlet ( / ) = Int64.div\nlet ( * ) = Int64.mul\nlet ( + ) = Int64.add\nlet ( - ) = Int64.sub\nlet ( mod ) = Int64.rem\nlet zero = Int64.zero\nlet one = Int64.one\nlet two = Int64.of_int 2\nend\n\nlet is_prime =\n let n = 1000000 in\n let a = Array.make (n + 1) true in\n let rec loop i =\n if i * i <= n\n then\n if a.(i)\n then\n let rec looper j =\n if j > n\n then\n ()\n else\n (Array.set a j false;\n looper (j + i))\n in looper (i * i)\n else\n ()\n in loop 2;\n Array.set a 0 false;\n Array.set a 1 false;\n\n fun i -> a.(i)\n\nlet find_sqrt n =\n let open I64 in\n let r = Pervasives.sqrt (Int64.to_float n) in\n let rec loop (+) (<) approx =\n if approx * approx < n\n then\n loop (+) (<) (approx + one)\n else\n approx\n in \n let r = loop (-) (>) (loop (+) (<) (Int64.of_float r)) in\n if r * r = n\n then\n Some (Int64.to_int r)\n else\n None\n\nlet is_tprime n =\n match (find_sqrt n) with\n | Some r -> is_prime r\n | None -> false\n\nlet () = \n let length = Scanf.scanf \"%d \" (fun n -> n) in\n let rec loop i =\n if i < length\n then\n let number = Scanf.scanf \"%Ld \" (fun n -> n) in\n (if is_tprime number\n then\n Printf.printf \"YES\\n\"\n else\n Printf.printf \"NO\\n\");\n loop (i + 1)\n else\n ()\n in loop 0 "}], "src_uid": "6cebf9af5cfbb949f22e8b336bf07044"} {"source_code": "let trim (line: string) =\n\t(* trim leading white space *)\n\tlet line = Str.replace_first (Str.regexp \"^[ \\t\\n\\r]+\") \"\" line in\n\t(* trim trailing white space *)\n\tlet line = Str.replace_first (Str.regexp \"[ \\t\\n\\r]+$\") \"\" line in\n\tline\n;;\n\n\nlet ints_of_string (line: string) = \n\tArray.of_list (List.map int_of_string (Str.split (Str.regexp \" \") (trim line)))\n;;\n\nlet solve (a: int array) =\n\tlet n = Array.length a in\n\tlet b = Array.create (1+n) 0 in\n\tb.(1) <- a.(0);\n\tfor i=2 to n do\n\t\tb.(i) <- b.(i-1) + a.(i-1)\n\tdone;\n\tlet sum i j = b.(j) - b.(i-1) in\n\t(*Printf.printf \"n = %d\\n\" n;\n\tfor i=0 to n do\n\t\tPrintf.printf \"%d \" b.(i)\n\tdone;\n*)\n\tlet best = ref 0 in\n\tfor i=1 to n do\n\t\tfor j=i to n do\n\t\t\tlet tmp = \n\t\t\t\tb.(i-1) + \n\t\t\t\t(j-i+1) - (b.(j) - b.(i-1)) +\n\t\t\t\tb.(n)-b.(j)\n\t\t\tin\n\t\t\tif tmp > !best then\n\t\t\t\tbest := !best + 1\n\t\tdone;\n\tdone;\n\tPrintf.printf \"%d\\n\" !best\n;;\n\n\n\nlet _ = \n\tlet n = int_of_string (read_line()) in\n\tfor i=n to n+n-1 do\n\t\tPrintf.printf \"%d \" i\n\tdone;\n\t\n\n\n\n\t\n", "positive_code": [{"source_code": "(* Codeforces contest 327B - hungry seq *)\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 n = gr();; (* number of test data *)\n\nlet printseq n =\n\tfor i = n +5 to n + 4 + n do\n\t\t( print_int i; print_string \" \" )\n\tdone;;\n\nlet main() =\n\tprintseq n;;\n\nmain();;\n"}], "negative_code": [], "src_uid": "c047040426e736e9085395ed9666135f"} {"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 slen = String.length\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 prefix s t =\n String.(sub s 0 (length t)) = t\n (* let f = ref true in\n repi 0 (String.length t-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if s.[j] <> t.[j] then f:=false\n ); !f *)\nlet suffix s t =\n String.(sub s ((length s -$ 1) -$ (length t -$ 1)) (length t)) = t\n (* let f = ref true in\n let d = String.length t-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if s.[String.length s-$1-$d+$j] <> t.[j] then f:=false\n ); !f *)\nlet () =\n let n = gi 0 in let n = i32 n in let m = 2*$n-$2 in\n let a = init m (fun _ -> scanf \" %s\" @@ id) in\n let len = make n [] in\n let unz = make n [] in\n iteri (fun i v ->\n len.(slen v) <- v :: len.(slen v);\n unz.(slen v) <- i :: unz.(slen v)\n ) a;\n let res = make m '_' in\n let p0,q0 = match len.(n-$1) with [p;q] -> p,q | _ -> fail 0 in\n let gen_str p q =\n p ^ (String.make 1 q.[n-$2])\n in\n let solve str =\n (* printf \"%s::\\n\" str; *)\n let f = ref true in\n repi_rev (n-$1) 1 (fun i ->\n let p,q = match len.(i) with [p;q] -> p,q | _ -> fail 0 in\n let u,v = match unz.(i) with [p;q] -> p,q | _ -> fail 0 in\n (* printf \" %s:%d; %s:%d\\n\" p u q v; *)\n if prefix str p && suffix str q then (\n res.(u) <- 'P';\n res.(v) <- 'S';\n ) else if suffix str p && prefix str q then (\n res.(u) <- 'S';\n res.(v) <- 'P';\n ) else f := false\n );\n if !f then (\n iter print_char res; exit 0\n )\n in\n solve (gen_str p0 q0);\n solve (gen_str q0 p0);\n\n\n\n\n\n\n\n\n\n\n", "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 slen = String.length\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 prefix s t =\n let f = ref true in\n repi 0 (String.length t-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if s.[j] <> t.[j] then f:=false\n ); !f\nlet suffix s t =\n let f = ref true in\n let d = String.length t-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if s.[String.length s-$1-$d+$j] <> t.[j] then f:=false\n ); !f\nlet () =\n let n = gi 0 in let n = i32 n in let m = 2*$n-$2 in\n let a = init m (fun _ -> scanf \" %s\" @@ id) in\n let len = make n [] in\n let unz = make n [] in\n iteri (fun i v ->\n len.(slen v) <- v :: len.(slen v);\n unz.(slen v) <- i :: unz.(slen v)\n ) a;\n let res = make m '_' in\n let p0,q0 = match len.(n-$1) with [p;q] -> p,q | _ -> fail 0 in\n let gen_str p q =\n p ^ (String.make 1 q.[n-$2])\n in\n let solve str =\n (* printf \"%s::\\n\" str; *)\n let f = ref true in\n repi_rev (n-$1) 1 (fun i ->\n let p,q = match len.(i) with [p;q] -> p,q | _ -> fail 0 in\n let u,v = match unz.(i) with [p;q] -> p,q | _ -> fail 0 in\n (* printf \" %s:%d; %s:%d\\n\" p u q v; *)\n if prefix str p && suffix str q then (\n res.(u) <- 'P';\n res.(v) <- 'S';\n ) else if suffix str p && prefix str q then (\n res.(u) <- 'S';\n res.(v) <- 'P';\n ) else f := false\n );\n if !f then (\n iter print_char res; exit 0\n )\n in\n solve (gen_str p0 q0);\n solve (gen_str q0 p0);\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i)) in\n sort (fun u v -> -compare (String.length u) (String.length v)) aa;\n let str = aa.(0) ^ (String.make 1 aa.(1).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(0).[i] <> aa.(1).[i-$1] then ff := false\n );\n let res = make (i32 @@ 2L*n-2L) '_' in\n (* print_endline str; *)\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n exit 0\n )\n );\n (* let str = (String.make 1 a.(0).[0]) ^ a.(1) in *)\n let str = aa.(1) ^ (String.make 1 aa.(0).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(1).[i] <> aa.(0).[i-$1] then ff := false\n );\n (* print_endline str; *)\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n exit 0\n )\n );\n raise Not_found\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 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 prefix s t =\n let f = ref true in\n repi 0 (String.length t-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if s.[j] <> t.[j] then f:=false\n ); !f\nlet suffix s t =\n let f = ref true in\n let d = String.length t-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if s.[String.length s-$1-$d+$j] <> t.[j] then f:=false\n ); !f\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i),i) in\n sort (fun (u,i) (v,j) -> -compare (String.length u) (String.length v)) aa;\n let m = i32 @@ 2L*n -2L in\n (* print_array (fun (c,i) -> sprintf \"%s#%d\" c i) aa; *)\n let zip = make m 0 in\n let unzip = make (m) 0 in\n iteri (fun i (_,j) -> zip.(i) <- j; unzip.(j) <- i) aa;\n let a0,a1 = fst aa.(0),fst aa.(1) in\n let arr0 = a in\n let a = map (fun (v,i) -> v) aa in\n let res = make (i32 @@ 2L*n-2L) ('_',0) in\n (* print_array id a; *)\n\n\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n rep 0L (i64 m/2L-1L) (fun i ->\n let i = i32 @@ i * 2L in\n let u,v = a.(i),a.(i+$1) in\n (* printf \" %s %s\\n\" u v; *)\n let p,q,r,s = prefix str u,prefix str v,suffix str u,suffix str v in\n if p && s then (\n res.(i) <- ('P',i);\n res.(i+$1) <- ('S',i+$1);\n ) else if q && r then (\n res.(i) <- ('S',i);\n res.(i+$1) <- ('P',i+$1);\n ) else ff := false\n );\n if !ff then (\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n exit 0;\n );\n let a0,a1 = a1,a0 in\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n rep 0L (i64 m/2L) (fun i ->\n let i = i32 i in\n let u,v = a.(i),a.(i+$1) in\n let p,q,r,s = prefix str u,prefix str v,suffix str u,suffix str v in\n if p && s then (\n res.(i) <- ('P',i);\n res.(i+$1) <- ('S',i+$1);\n ) else if q && r then (\n res.(i) <- ('S',i);\n res.(i+$1) <- ('P',i+$1);\n ) else ff := false\n );\n if !ff then (\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n exit 0;\n );\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i),i) in\n sort (fun (u,i) (v,j) -> -compare (String.length u) (String.length v)) aa;\n let m = i32 @@ 2L*n -2L in\n let zip = make m 0 in\n let unz = make (m) 0 in\n iteri (fun i (_,j) -> zip.(i) <- j; unz.(j) <- i) aa;\n let a0,a1 = fst aa.(0),fst aa.(1) in\n let arr0 = a in\n let a = map (fun (v,i) -> v) aa in\n let ffff = ref false in\n let res = make (i32 @@ 2L*n-2L) '_' in\n\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n let s,p = ref (i32 n-$1),ref (i32 n-$1) in\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !p > 0 && !f then (\n res.(i) <- 'P'; p:=!p-$1\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'; s := !s -$ 1\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n print_newline ();\n (* exit 0 *)\n ffff := true;\n )\n );\n if not !ffff then (\n (* let str = (String.make 1 a.(0).[0]) ^ a.(1) in *)\n let str = a1 ^ (String.make 1 a0.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a1.[i] <> a0.[i-$1] then ff := false\n );\n (* print_endline str; *)\n let s,p = ref (i32 n-$1),ref (i32 n-$1) in\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !p>0 && !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n (* exit 0 *)\n ffff := true;\n )\n );\n );\n (* raise Not_found *)\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 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 prefix s t =\n let f = ref true in\n repi 0 (String.length t-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if s.[j] <> t.[j] then f:=false\n ); !f\nlet suffix s t =\n let f = ref true in\n let d = String.length t-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if s.[String.length s-$1-$d+$j] <> t.[j] then f:=false\n ); !f\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i),i) in\n sort (fun (u,i) (v,j) -> -compare (String.length u) (String.length v)) aa;\n let m = i32 @@ 2L*n -2L in\n (* print_array (fun (c,i) -> sprintf \"%s#%d\" c i) aa; *)\n let zip = make m 0 in\n let unzip = make (m) 0 in\n iteri (fun i (_,j) -> zip.(i) <- j; unzip.(j) <- i) aa;\n let a0,a1 = fst aa.(0),fst aa.(1) in\n let arr0 = a in\n let a = map (fun (v,i) -> v) aa in\n let res = make (i32 @@ 2L*n-2L) ('_',0) in\n (* print_array id a; *)\n\n\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n let ns,np = ref (i32 n-$1),ref (i32 n-$1) in\n rep 0L (i64 m/2L-1L) (fun i ->\n let i = i32 @@ i * 2L in\n let u,v = a.(i),a.(i+$1) in\n (* printf \" %s %s\\n\" u v; *)\n let p,q,r,s = prefix str u,prefix str v,suffix str u,suffix str v in\n (* if not p && r && q then (\n\n ) else if p && not q && then (\n\n ) else if not r && s then (\n\n ) else if r && not s then (\n\n ) else () *)\n if p && s then (\n res.(i) <- ('P',i);\n res.(i+$1) <- ('S',i+$1);\n ) else if q && r then (\n res.(i) <- ('S',i);\n res.(i+$1) <- ('P',i+$1);\n ) else ff := false\n );\n if !ff then (\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n exit 0;\n );\n let a0,a1 = a1,a0 in\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n let ns,np = ref (i32 n-$1),ref (i32 n-$1) in\n rep 0L (i64 m/2L) (fun i ->\n let i = i32 i in\n let u,v = a.(i),a.(i+$1) in\n let p,q,r,s = prefix str u,prefix str v,suffix str u,suffix str v in\n (* if not p && r && q then (\n\n ) else if p && not q && then (\n\n ) else if not r && s then (\n\n ) else if r && not s then (\n\n ) else () *)\n if p && s then (\n res.(i) <- ('P',i);\n res.(i+$1) <- ('S',i+$1);\n ) else if q && r then (\n res.(i) <- ('S',i);\n res.(i+$1) <- ('P',i+$1);\n ) else ff := false\n );\n if !ff then (\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n exit 0;\n );\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i),i) in\n sort (fun (u,i) (v,j) -> -compare (String.length u) (String.length v)) aa;\n let m = i32 @@ 2L*n -2L in\n (* print_array (fun (c,i) -> sprintf \"%s#%d\" c i) aa; *)\n let zip = make m 0 in\n let unz = make (m) 0 in\n iteri (fun i (_,j) -> zip.(i) <- j; unz.(j) <- i) aa;\n let a0,a1 = fst aa.(0),fst aa.(1) in\n let arr0 = a in\n let a = map (fun (v,i) -> v) aa in\n let ffff = ref false in\n let res = make (i32 @@ 2L*n-2L) ('_',0) in\n\n let str = a0 ^ (String.make 1 a1.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a0.[i] <> a1.[i-$1] then ff := false\n );\n (* print_endline str; *)\n let s,p = ref (i32 n-$1),ref (i32 n-$1) in\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !p > 0 && !f then (\n res.(i) <- ('P',i); p:=!p-$1\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- ('S',i); s := !s -$ 1\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n print_newline ();\n (* exit 0 *)\n ffff := true;\n )\n );\n if not !ffff then (\n (* let str = (String.make 1 a.(0).[0]) ^ a.(1) in *)\n let str = a1 ^ (String.make 1 a0.[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if a1.[i] <> a0.[i-$1] then ff := false\n );\n (* print_endline str; *)\n\n let s,p = ref (i32 n-$1),ref (i32 n-$1) in\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !p > 0 && !f then (\n res.(i) <- ('P',i); p:=!p-$1\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- ('S',i); s := !s -$ 1\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n let ress = make m 'x' in\n iter (fun (c,i) -> ress.(zip.(i)) <- c) res;\n iter (fun c -> printf \"%c\" c) ress;\n print_newline ();\n (* exit 0 *)\n ffff := true;\n )\n );\n );\n (* raise Not_found *)\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i)) in\n sort (fun u v -> -compare (String.length u) (String.length v)) aa;\n let str = aa.(0) ^ (String.make 1 aa.(1).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(0).[i] <> aa.(1).[i-$1] then ff := false\n );\n let res = make (i32 @@ 2L*n-2L) '_' in\n print_endline str;\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n exit 0\n )\n );\n (* let str = (String.make 1 a.(0).[0]) ^ a.(1) in *)\n let str = aa.(1) ^ (String.make 1 aa.(0).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(1).[i] <> aa.(0).[i-$1] then ff := false\n );\n print_endline str;\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n exit 0\n )\n );\n raise Not_found\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 Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n let a = init (i32 @@ 2L*n-2L) (fun _ -> scanf \" %s\" @@ id) in\n let aa = init (i32 @@ 2L*n-2L) (fun i -> a.(i)) in\n sort (fun u v -> -compare (String.length u) (String.length v)) aa;\n let str = aa.(0) ^ (String.make 1 aa.(1).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(0).[i] <> aa.(1).[i-$1] then ff := false\n );\n let res = make (i32 @@ 2L*n-2L) '_' in\n (* print_endline str; *)\n let ffff = ref false in\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n print_newline ();\n (* exit 0 *)\n ffff := true;\n )\n );\n if not !ffff then (\n (* let str = (String.make 1 a.(0).[0]) ^ a.(1) in *)\n let str = aa.(1) ^ (String.make 1 aa.(0).[i32 n-$2]) in\n let ff = ref true in\n repi 1 (i32 n-$2) (fun i ->\n if aa.(1).[i] <> aa.(0).[i-$1] then ff := false\n );\n (* print_endline str; *)\n if !ff then (\n repi 0 (i32 @@ 2L*n-3L) (fun i ->\n let f = ref true in\n (* P *)\n (* printf \" %d\\n\" i; *)\n repi 0 (String.length a.(i)-$1) (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[j] a.(i).[j] (str.[j] = a.(i).[j]); *)\n if str.[j] <> a.(i).[j] then f:=false\n );\n if !f then (\n res.(i) <- 'P'\n ) else (\n let f = ref true in\n let d = String.length a.(i)-$1 in\n repi 0 d (fun j ->\n (* printf \" %d %d :: %c %c --> %b\\n\" i j str.[i32 n-$d+$j-$1] a.(i).[j] (str.[i32 n-$d+$j-$1] = a.(i).[j]); *)\n if str.[i32 n-$d+$j-$1] <> a.(i).[j] then f:=false\n );\n (* printf \" -> %b\\n\" !f; *)\n if !f then (\n res.(i) <- 'S'\n ) else ff := false\n )\n );\n if !ff then (\n (* print_array (String.make 1) res; *)\n iter (fun c -> printf \"%c\" c) res;\n (* exit 0 *)\n ffff := true;\n )\n );\n );\n (* raise Not_found *)\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "ddbde202d00b928a858e9f4ff461e88c"} {"source_code": "\r\n(*LMAOOOOOOOOOO*)\r\n\r\nclass ['a] vector =\r\n object (self)\r\n val mutable a = ([||] : 'a array) \r\n val mutable size = 0\r\n method check = \r\n if size = Array.length a then\r\n a <- Array.append a a \r\n method pop = \r\n if size = 0 then false\r\n else \r\n let () = size <- size - 1 in\r\n true\r\n method push x =\r\n if Array.length a = 0 then\r\n let () = a <- Array.make 1 x in\r\n size <- 1\r\n else\r\n let () = self#check in\r\n let () = a.(size) <- x in \r\n size <- size + 1 \r\n method size =\r\n size\r\n method get i =\r\n a.(i)\r\n method con (other : 'a vector) = \r\n for i = 0 to other#size do\r\n self#push (other#get i)\r\n done\r\n method sub l r = \r\n let ans = (new vector : 'a vector) in \r\n let () = \r\n for i = l to r do \r\n ans#push (self#get i)\r\n done in \r\n ans\r\n method from_string s = \r\n for i = 0 to String.length s - 1 do\r\n self#push s.[i]\r\n done\r\n method eq (other : 'a vector) = \r\n if self#size <> other#size then false\r\n else \r\n let pos = ref true in\r\n let () = \r\n for i = 0 to self#size - 1 do\r\n if (self#get i) <> (other#get i) then pos := false\r\n done in\r\n !pos\r\n method string =\r\n String.init self#size (fun i -> self#get i) \r\n end;;\r\n\r\nlet readInt() = Scanf.scanf \" %d\" (fun i -> i);; \r\nlet readLine() = input_line stdin;;\r\nlet print_number x = print_string ((string_of_int x) ^ \" \");;\r\nlet print_char c = print_string (Char.escaped c);;\r\nlet print_array a = \r\n let () = \r\n for i = 0 to Array.length a - 1 do\r\n print_number a.(i)\r\n done in\r\n print_string \"\\n\";;\r\nlet f c = int_of_char(c) - int_of_char('a');;\r\nlet build s1 order = \r\n let ans = new vector in\r\n let () = \r\n let banned = Array.make 26 false in\r\n for i = 0 to Array.length order - 1 do\r\n let j = ref 0 in\r\n let quit_loop = ref false in\r\n let () = \r\n while not !quit_loop do\r\n let () = \r\n if ans#size = 500000 then quit_loop := true\r\n else if !j = s1#size then quit_loop := true\r\n else if not banned.(f (s1#get !j)) then\r\n ans#push (s1#get !j) in\r\n j := !j + 1\r\n done in\r\n banned.(order.(i)) <- true\r\n done in\r\n ans;;\r\n\r\nlet check s1 s2 order = \r\n (build s1 order)#eq s2;;\r\n \r\n(*let a = new vector in\r\n let b = new vector in\r\n let () = a#from_string \"abacaba\" in\r\n let () = b#from_string \"abacabaaacaac\" in\r\n (build a [|1; 0; 2|])#string;;*)\r\n\r\nlet da x = ()\r\nlet reverse a n = Array.init (n+1) (fun i -> a.(n - i));;\r\nlet t = readLine() in \r\nfor i = 1 to int_of_string t do\r\n let inp = readLine() in\r\n let s = new vector in\r\n let () = (s#from_string inp) in\r\n let ptr = ref (-1) in\r\n let seen = Array.make 26 0 in\r\n let rev_order = Array.make 26 0 in\r\n let freq = Array.make 26 0 in\r\n let possible = ref true in\r\n let sum = ref 0 in\r\n let () = \r\n for j = 0 to s#size - 1 do\r\n let rj = s#size - 1 - j in\r\n let c = f (s#get rj) in\r\n let () = \r\n freq.(c) <- freq.(c) + 1 in\r\n if seen.(c) = 0 then \r\n let () = seen.(c) <- 1 in\r\n let () = ptr := !ptr + 1 in\r\n rev_order.(!ptr) <- c\r\n done in\r\n let order = reverse rev_order !ptr in \r\n let () = \r\n for j = 0 to Array.length order - 1 do\r\n let c = order.(j) in\r\n let () = \r\n if freq.(c) mod (j+1) <> 0 then\r\n possible := false\r\n else\r\n freq.(c) <- freq.(c) / (j+1) in\r\n sum := !sum + freq.(c)\r\n done in\r\n let sb = s#sub 0 (!sum - 1) in\r\n let ord = String.init (Array.length order) (fun i -> char_of_int (order.(i) + int_of_char('a'))) in\r\n if (check sb s order) then\r\n print_string (sb#string ^ \" \" ^ ord ^ \"\\n\")\r\n else\r\n print_string \"-1\\n\"\r\ndone;;", "positive_code": [{"source_code": "\r\n(*LMAOOOOOOOOOO'*)\r\n\r\nclass ['a] vector =\r\n object (self)\r\n val mutable a = ([||] : 'a array) \r\n val mutable size = 0\r\n method check = \r\n if size = Array.length a then\r\n a <- Array.append a a \r\n method pop = \r\n if size = 0 then false\r\n else \r\n let () = size <- size - 1 in\r\n true\r\n method push x =\r\n if Array.length a = 0 then\r\n let () = a <- Array.make 1 x in\r\n size <- 1\r\n else\r\n let () = self#check in\r\n let () = a.(size) <- x in \r\n size <- size + 1 \r\n method size =\r\n size\r\n method get i =\r\n a.(i)\r\n method con (other : 'a vector) = \r\n for i = 0 to other#size do\r\n self#push (other#get i)\r\n done\r\n method sub l r = \r\n let ans = (new vector : 'a vector) in \r\n let () = \r\n for i = l to r do \r\n ans#push (self#get i)\r\n done in \r\n ans\r\n method from_string s = \r\n for i = 0 to String.length s - 1 do\r\n self#push s.[i]\r\n done\r\n method eq (other : 'a vector) = \r\n if self#size <> other#size then false\r\n else \r\n let pos = ref true in\r\n let () = \r\n for i = 0 to self#size - 1 do\r\n if (self#get i) <> (other#get i) then pos := false\r\n done in\r\n !pos\r\n method string =\r\n String.init self#size (fun i -> self#get i) \r\n end;;\r\n\r\nlet readInt() = Scanf.scanf \" %d\" (fun i -> i);; \r\nlet readLine() = input_line stdin;;\r\nlet print_number x = print_string ((string_of_int x) ^ \" \");;\r\nlet print_char c = print_string (Char.escaped c);;\r\nlet print_array a = \r\n let () = \r\n for i = 0 to Array.length a - 1 do\r\n print_number a.(i)\r\n done in\r\n print_string \"\\n\";;\r\nlet f c = int_of_char(c) - int_of_char('a');;\r\nlet build s1 order = \r\n let ans = new vector in\r\n let () = \r\n let banned = Array.make 26 false in\r\n for i = 0 to Array.length order - 1 do\r\n let j = ref 0 in\r\n let quit_loop = ref false in\r\n let () = \r\n while not !quit_loop do\r\n let () = \r\n if ans#size = 500000 then quit_loop := true\r\n else if !j = s1#size then quit_loop := true\r\n else if not banned.(f (s1#get !j)) then\r\n ans#push (s1#get !j) in\r\n j := !j + 1\r\n done in\r\n banned.(order.(i)) <- true\r\n done in\r\n ans;;\r\n\r\nlet check s1 s2 order = \r\n (build s1 order)#eq s2;;\r\n \r\n(*let a = new vector in\r\n let b = new vector in\r\n let () = a#from_string \"abacaba\" in\r\n let () = b#from_string \"abacabaaacaac\" in\r\n (build a [|1; 0; 2|])#string;;*)\r\n\r\nlet da x = ()\r\nlet reverse a n = Array.init (n+1) (fun i -> a.(n - i));;\r\nlet t = readLine() in \r\nfor i = 1 to int_of_string t do\r\n let inp = readLine() in\r\n let s = new vector in\r\n let () = (s#from_string inp) in\r\n let ptr = ref (-1) in\r\n let seen = Array.make 26 0 in\r\n let rev_order = Array.make 26 0 in\r\n let freq = Array.make 26 0 in\r\n let possible = ref true in\r\n let sum = ref 0 in\r\n let () = \r\n for j = 0 to s#size - 1 do\r\n let rj = s#size - 1 - j in\r\n let c = f (s#get rj) in\r\n let () = \r\n freq.(c) <- freq.(c) + 1 in\r\n if seen.(c) = 0 then \r\n let () = seen.(c) <- 1 in\r\n let () = ptr := !ptr + 1 in\r\n rev_order.(!ptr) <- c\r\n done in\r\n let order = reverse rev_order !ptr in \r\n let () = \r\n for j = 0 to Array.length order - 1 do\r\n let c = order.(j) in\r\n let () = \r\n if freq.(c) mod (j+1) <> 0 then\r\n possible := false\r\n else\r\n freq.(c) <- freq.(c) / (j+1) in\r\n sum := !sum + freq.(c)\r\n done in\r\n let sb = s#sub 0 (!sum - 1) in\r\n let ord = String.init (Array.length order) (fun i -> char_of_int (order.(i) + int_of_char('a'))) in\r\n if (check sb s order) then\r\n print_string (sb#string ^ \" \" ^ ord ^ \"\\n\")\r\n else\r\n print_string \"-1\\n\"\r\ndone;;"}], "negative_code": [], "src_uid": "8705adec1bea1f898db1ca533e15d5c3"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet make_list () = \n let n = read () in\n let rec loop i list =\n if i < n\n then\n let temp = read () in\n loop (i + 1) (temp :: list)\n else\n List.sort (Pervasives.compare) list\n in loop 0 []\n\nlet input () = \n let boys = make_list () in\n let girls = make_list () in\n (boys, girls)\n\nlet pair boy girl =\n if boy = girl || boy = girl + 1 || boy = girl - 1\n then\n `Paired\n else\n if boy <= girl - 2\n then\n `Next_boy\n else\n `Next_girl\n\nlet solve (boys, girls) =\n let rec loop l ll count = \n match (l, ll) with\n | (hd :: tl), (hhd :: ttl) -> \n (match (pair hd hhd) with\n | `Paired -> loop tl ttl (count + 1)\n | `Next_boy -> loop tl ll count\n | `Next_girl -> loop l ttl count)\n | _, [] -> count\n | [], _ -> count\n | [], [] -> count\n in loop boys girls 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet make_list () = \n let n = read () in\n let rec loop i list =\n if i < n\n then\n let temp = read () in\n loop (i + 1) (temp :: list)\n else\n List.sort (Pervasives.compare) list\n in loop 0 []\n\nlet input () = \n let boys = make_list () in\n let girls = make_list () in\n (boys, girls)\n\nlet pair boy girl =\n if boy = girl || boy = girl + 1 || boy = girl - 1\n then\n `Paired\n else\n if boy <= girl - 2\n then\n `Next_boy\n else\n `Next_girl\n\nlet solve (boys, girls) =\n let rec loop l ll count = \n match (l, ll) with\n | (hd :: tl), (hhd :: ttl) -> \n (match (pair hd hhd) with\n | `Paired -> loop tl ttl (count + 1)\n | `Next_boy -> loop tl ll count\n | `Next_girl -> loop l ttl count)\n | _, _ -> count\n in loop boys girls 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}], "negative_code": [], "src_uid": "62766ef9a0751cbe7987020144de7512"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = 8 in\n let a = Array.make n (0, 0) in\n let _ =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- (x, y)\n done\n in\n let is_right (x, y) (x1, y1) (x2, y2) =\n (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) = 0\n in\n let is_rect p1 p2 p3 p4 =\n is_right p1 p2 p4 &&\n is_right p2 p1 p3 &&\n is_right p3 p2 p4\n in\n let sqr x = x * x in\n let dist2 (x1, y1) (x2, y2) =\n sqr (x1 - x2) + sqr (y1 - y2)\n in\n let is_square p1 p2 p3 p4 =\n is_rect p1 p2 p3 p4 &&\n dist2 p1 p2 = dist2 p2 p3\n in\n let b = Array.make n 0 in\n let u = Array.make n false in\n let rec bf k =\n if k >= 0 then (\n for i = 0 to n - 1 do\n\tif not u.(i) then (\n\t u.(i) <- true;\n\t b.(k) <- i;\n\t bf (k - 1);\n\t u.(i) <- false;\n\t)\n done\n ) else (\n if is_square a.(b.(0)) a.(b.(1)) a.(b.(2)) a.(b.(3)) &&\n\tis_rect a.(b.(4)) a.(b.(5)) a.(b.(6)) a.(b.(7))\n then (\n\tPrintf.printf \"YES\\n\";\n\tfor i = 0 to 3 do\n\t Printf.printf \"%d \" (b.(i) + 1)\n\tdone;\n\tPrintf.printf \"\\n\";\n\tfor i = 4 to 7 do\n\t Printf.printf \"%d \" (b.(i) + 1)\n\tdone;\n\tPrintf.printf \"\\n\";\n\texit 0\n )\n )\n in\n bf (n - 1);\n Printf.printf \"NO\\n\"\n", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = 8 in\n let a = Array.make n (0, 0) in\n let _ =\n for i = 0 to n - 1 do\n let x = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let y = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\ta.(i) <- (x, y)\n done\n in\n let is_right (x, y) (x1, y1) (x2, y2) =\n (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) = 0\n in\n let is_rect p1 p2 p3 p4 =\n is_right p1 p2 p4 &&\n is_right p2 p1 p3 &&\n is_right p3 p2 p4\n in\n let sqr x = x * x in\n let dist2 (x1, y1) (x2, y2) =\n sqr (x1 - x2) + sqr (y1 - y2)\n in\n let is_square p1 p2 p3 p4 =\n is_rect p1 p2 p3 p4 &&\n dist2 p1 p2 = dist2 p2 p3\n in\n let b = Array.make n 0 in\n let u = Array.make n false in\n let rec bf k =\n if k >= 0 then (\n for i = 0 to n - 1 do\n\tif not u.(i) then (\n\t u.(i) <- true;\n\t b.(k) <- i;\n\t bf (k - 1);\n\t u.(i) <- false;\n\t)\n done\n ) else (\n if is_square a.(b.(0)) a.(b.(1)) a.(b.(2)) a.(b.(3)) &&\n\tis_rect a.(b.(4)) a.(b.(5)) a.(b.(6)) a.(b.(7))\n then (\n\tPrintf.printf \"YES\\n\";\n\tfor i = 0 to 3 do\n\t Printf.printf \"%d \" (b.(i) + 1)\n\tdone;\n\tPrintf.printf \"\\n\";\n\tfor i = 4 to 7 do\n\t Printf.printf \"%d \" (b.(i) + 1)\n\tdone;\n\tPrintf.printf \"\\n\";\n\texit 0\n )\n )\n in\n bf (n - 1);\n Printf.printf \"NO\\n\"\n"}], "negative_code": [], "src_uid": "a36fb51b1ebb3552308e578477bdce8f"} {"source_code": "let yolo hasht x =\n\ttry\n\t\tHashtbl.find hasht x\n\twith _ -> 0\n\nlet _ =\n\tlet hasht = Hashtbl.create 0 in\n\tlet s = Scanf.scanf \"%s\" (fun s -> s) in\n\t\tfor i = 0 to String.length s - 1 do\n\t\t\tlet x = s.[i] in\n\t\t\tlet a = yolo hasht x in\n\t\t\t\tHashtbl.add hasht x (a+1)\n\t\tdone;\n\tlet bleu = List.fold_left min max_int\n\t\t(List.map (yolo hasht) ['B';'l';'b';'s';'r'])\n\tin\n\tlet rouge = min bleu ((yolo hasht 'u') / 2) in\n\tlet vert = min rouge ((yolo hasht 'a') / 2) in\n\t\tprint_int vert", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let a = Array.make 256 0 in\n let _ =\n for i = 0 to String.length s - 1 do\n let c = Char.code s.[i] in\n\ta.(c) <- a.(c) + 1\n done;\n in\n let r = a.(Char.code 'B') in\n let r = min r (a.(Char.code 'u') / 2) in\n let r = min r a.(Char.code 'l') in\n let r = min r a.(Char.code 'b') in\n let r = min r (a.(Char.code 'a') / 2) in\n let r = min r a.(Char.code 's') in\n let r = min r a.(Char.code 'r') in\n Printf.printf \"%d\\n\" r\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_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 count c = sum 0 (n-1) (fun i -> if s.[i] = c then 1 else 0) in\n let nB = count 'B' in\n let ns = count 's' in\n let nl = count 'l' in\n let nu = count 'u' in\n let nr = count 'r' in\n let na = count 'a' in\n let nb = count 'b' in \n\n let answer = min nB (min (nu/2) (min nl (min nb (min (na/2) (min ns nr))))) in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "9c429fd7598ea75acce09805a15092d0"} {"source_code": "let input () = let number_of_coins = Scanf.scanf \"%d \" (fun n -> n) in\n (*List.init number_of_coins (fun _ -> Scanf.scanf \"%d \" (fun n -> n))\n *)\n let rec read list n =\n if n > 0\n then\n let var = Scanf.scanf \"%d \" (fun n -> n) in\n read (var :: list) (n - 1)\n else\n list\n in read [] number_of_coins\n\nlet sort list = List.rev(List.sort(Pervasives.compare) list)\n\nlet get_total list = List.fold_left(fun a b -> a + b) 0 list\n\nlet more_than_half total = (total / 2) + 1\n\nlet get_big_coins list amount =\n let rec loop list amount count = \n if amount > 0\n then \n match list with\n |(a :: tail) -> loop tail (amount - a) (count + 1)\n |[] -> failwith \"No money. Now cry\"\n else\n count\n in loop list amount 0\n\nlet solve input = get_big_coins (sort input)(more_than_half(get_total input))\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "open Array;;\nlet main () =\n let a = ref 0\n in let summ = ref 0\n in let n = read_int ()\n in let f n = \n let tmp = Scanf.scanf \"%d \" (fun x->x) in \n summ := !summ + tmp; tmp\n in let ar = init n f\n in fast_sort (-) ar;\n for i = n-1 downto 0 do\n if !a > !summ then( print_int (n-1-i);exit 0)\n else( a:= !a + ar.(i); summ:= !summ - ar.(i); ())\n done;\n print_int n\n;;\nmain()"}, {"source_code": "\nlet sum seq = List.fold_left (+) 0 seq;;\n\nlet coins lst = \n let rec inner llst num get rest =\n if rest < get then\n num\n else\n let curr = List.hd llst\n in\n inner (List.tl llst) (num + 1) (get + curr) (rest - curr)\n in\n inner lst 0 0 (sum lst);;\n\nlet () =\n let arr = Scanf.scanf \"%d \"\n (fun n -> Array.init\n n\n (fun _ -> Scanf.scanf \"%d \" (fun m -> m))) in\n let _ = Array.fast_sort compare arr\n in\n Printf.printf \"%d\\n\" (coins (List.rev (Array.to_list arr)));;\n \n"}, {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make n (-1);;\n\nfor i = 0 to n-1 do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n a.(i)<-j;\ndone\n\nlet sum = Array.fold_left (fun x y -> x + y ) 0 a\n\nlet () = Array.sort (fun x y -> y - x) a\n\n(*\nlet () = printf \"%d \\n\" sum\nlet () = Array.iter (fun x -> printf \"%d \" x) a\n*)\n\nlet rec loop s i =\n let s' = s+a.(i) in\n if s' > (sum - s') || i >= n then\n printf \"%d\\n\" (i+1)\n else\n loop s' (i+1)\nin loop 0 0\n\n"}], "negative_code": [{"source_code": "open Array;;\nlet main () =\n let a = ref 0\n in let summ = ref 0\n in let n = read_int ()\n in let f n = \n let tmp = Scanf.scanf \"%d \" (fun x->x) in \n summ := !summ + tmp; tmp\n in let ar = init n f\n in fast_sort (-) ar;\n for i = n-1 downto 0 do\n if !a > !summ then( print_int (i-1);exit 0)\n else( a:= !a + ar.(i); summ:= !summ - ar.(i); ())\n done;\n print_int n\n;;\nmain()"}, {"source_code": "\nlet sum seq = List.fold_left (+) 0 seq;;\n\nlet coins lst = \n let rec inner llst num get rest =\n if rest < get then\n num\n else\n let curr = List.hd llst\n in\n inner (List.tl llst) (num + 1) (get + curr) (rest - curr)\n in\n inner lst 0 0 (sum lst);;\n\nlet () =\n let arr = Scanf.scanf \"%d \"\n (fun n -> Array.init\n n\n (fun _ -> Scanf.scanf \"%d \" (fun m -> m))) in\n let _ = Array.fast_sort compare arr\n in\n Printf.printf \"%d\\n\" (coins (Array.to_list arr));;\n \n"}], "src_uid": "ee535e202b7662dbaa91e869c8c6cee1"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n\n let overlap (a,b) (c,d) = max a c <= min b d in\n\n let possible n m startwith = (* n zeros, m ones *)\n let bal n m = \n let zlo = n in\n let zhi = n in\n let olo = (m+1)/2 in\n let ohi = m in\n n>=0 && m>=0 && overlap (zlo,zhi) (olo,ohi)\n in\n if bal n m then true else\n if startwith = 0 then bal (n-1) m\n else bal n (m-1) || bal n (m-2)\n in\n\n let mcount = [|1;2|]in\n\n if not (possible n m 0 || possible n m 1) then printf \"-1\\n\" else (\n\n let rec loop current maxremain n m =\n if m=0 && n=0 then () \n else if n=0 then (printf \"1\"; loop 1 (maxremain-1) n (m-1))\n else if m=0 then (printf \"0\"; loop 0 (maxremain-1) (n-1) m)\n else (\n\tif maxremain = 0 then (\n\t let current = 1-current in\n\t loop current mcount.(current) n m\n\t) else (\n\t let nc = if possible n m current then current else 1-current in\n\t printf \"%d\" nc;\n\t let n = if nc = 0 then n-1 else n in\n\t let m = if nc = 1 then m-1 else m in\n\t let maxremain = if nc=current then maxremain-1 else mcount.(nc)-1 in\n\t loop nc maxremain n m\n\t)\n )\n in\n \n let current = if possible n m 1 then 1 else 0 in\n printf \"%d\" current;\n let n = if current = 0 then n-1 else n in\n let m = if current = 1 then m-1 else m in\n loop current (mcount.(current) - 1) n m;\n printf \"\\n\"\n \n )\n\n", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and m=read_int();;\n\nlet rec print_list a b=\nif b>a+1 then (if b=2 then print_int 11 else (print_int 110;print_list (a-1) (b-2)))\nelse if a>b then (print_int 0;print_list (a-1) b)\nelse if (a=b)&&(a<>0) then (print_int 10;print_list (a-1) (b-1))\nelse if a+1=b then (if b=1 then print_int 1 else (print_int 10;print_list (a-1) (b-1)));;\n\nif n>m+1 then print_int (-1)\nelse if (m/2)+(m mod 2)>n+1 then print_int (-1)\nelse print_list n m;;\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let m = read_int () in\n\n let overlap (a,b) (c,d) = max a c <= min b d in\n\n let possible n m startwith = (* n zeros, m ones *)\n let bal n m = \n let zlo = (n+1)/2 in\n let zhi = n in\n let olo = (m+1)/2 in\n let ohi = m in\n n>=0 && m>=0 && overlap (zlo,zhi) (olo,ohi)\n in\n if bal n m then true else\n if startwith = 0 then bal (n-1) m || bal (n-2) m\n else bal n (m-1) || bal n (m-2)\n in\n\n let mcount = [|2;2|]in\n\n if not (possible n m 0 || possible n m 1) then printf \"-1\\n\" else (\n\n let rec loop current maxremain n m =\n if m=0 && n=0 then () \n else if n=0 then (printf \"1\"; loop 1 (maxremain-1) n (m-1))\n else if m=0 then (printf \"0\"; loop 0 (maxremain-1) (n-1) m)\n else (\n\tif maxremain = 0 then (\n\t let current = 1-current in\n\t loop current mcount.(current) n m\n\t) else (\n\t let nc = if possible n m current then current else 1-current in\n\t printf \"%d\" nc;\n\t let n = if nc = 0 then n-1 else n in\n\t let m = if nc = 1 then m-1 else m in\n\t let maxremain = if nc=current then maxremain-1 else mcount.(nc)-1 in\n\t loop nc maxremain n m\n\t)\n )\n in\n \n let current = if possible n m 1 then 1 else 0 in\n printf \"%d\" current;\n let n = if current = 0 then n-1 else n in\n let m = if current = 1 then m-1 else m in\n loop current (mcount.(current) - 1) n m;\n printf \"\\n\"\n \n )\n\n"}], "src_uid": "854c561539596722b1dbc8f99cbdca78"} {"source_code": "open Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n\ntype result =\n | YES of (char * char * char * char) list\n | NO\n\nlet print_result (r:result) =\n match r with\n | NO -> print_string \"NO\"\n | YES l ->\n match l with\n | [] -> print_string \"NO\"\n | l ->\n print_string \"YES\\n\";\n let rec print result_l =\n match result_l with\n | [] -> print_string \"\"\n | (a,b,c,d)::tl ->\n Printf.printf \"%c%c|%c%c\\n\" a b c d;\n print tl\n in print l\n\nlet find_and_replace_seats row_arr =\n let row_l = Array.to_list row_arr in\n let rec helper acc row_l =\n match row_l with\n | [] -> NO\n | (a,b,c,d)::tl ->\n if a = 'O' && b = 'O' then YES (List.rev (List.rev tl @ [('+','+',c,d)] @ acc))\n else if c = 'O' && d = 'O' then YES (List.rev (List.rev tl @ [(a,b,'+','+')] @ acc))\n else helper ((a,b,c,d)::acc) tl\n in helper [] row_l\n\nlet () =\n let n = read_int () in\n let row_arr = Array.init n (fun _ ->\n let input = read_string () in\n let a = input.[0] in\n let b = input.[1] in\n let c = input.[3] in\n let d = input.[4] in\n (a,b,c,d)\n )\n in\n find_and_replace_seats row_arr\n |> print_result\n", "positive_code": [{"source_code": "let list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n \nlet mod_first list f =\n let rec loop prev list =\n match list with\n | [] -> None\n | (hd :: tl) -> \n match (f hd) with\n | None -> loop (hd :: prev) tl\n | Some hd' -> Some (List.rev_append (hd' :: prev) tl)\n in loop [] list\n\nlet read_input () =\n let n = Scanf.scanf \"%d \" (fun n -> n) in \n let read_row () = Scanf.scanf \"%c%c%c%c%c \" (fun a b c d e -> ((a, b) :: (d, e) :: [])) in\n let bus = list_init n (fun _ -> read_row ()) in\n bus\n\nlet seat bus = mod_first bus (fun row -> mod_first row (fun pair ->\n if pair = ('O', 'O')\n then\n Some ('+', '+')\n else\n None))\n\nlet print_row row =\n match row with\n | [a, b; c, d] -> Printf.printf \"%c%c|%c%c\\n\" a b c d\n | _ -> failwith \"Invalid bus\"\n \nlet print_bus bus = \n match bus with\n | Some bus -> \n Printf.printf \"YES\\n\";\n List.iter print_row bus\n | _ -> Printf.printf \"NO\\n\"\n\nlet () = print_bus (seat (read_input ()))"}, {"source_code": "let list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n \nlet mod_first list f =\n let rec loop prev list =\n match list with\n | [] -> None\n | (hd :: tl) -> \n match (f hd) with\n | None -> loop (hd :: prev) tl\n | Some hd' -> Some (List.rev_append (hd' :: prev) tl)\n in loop [] list \n\nlet read_input () =\n let n = Scanf.scanf \"%d \" (fun n -> n) in \n let read_row () = Scanf.scanf \"%c%c%c%c%c \" (fun a b c d e -> ((a, b) :: (d, e) :: [])) in\n let bus = list_init n (fun _ -> read_row ()) in\n bus\n\nlet seat bus = mod_first bus (fun row -> mod_first row (fun pair ->\n if pair = ('O', 'O')\n then\n Some ('+', '+')\n else\n None))\n\nlet print_char char =\n Printf.printf \"%c\" char\n\nlet print_str str = \n Printf.printf \"%s\\n\" str\n\nlet print_side (a, b) =\n Printf.printf \"%c%c\" a b\n\nlet print_row row =\n match row with\n | [left; right] -> \n print_side left; \n print_char '|';\n print_side right; \n print_char '\\n'\n | _ -> failwith \"Invalid bus\"\n \nlet print_bus bus = \n match bus with\n | Some bus -> \n print_str \"YES\";\n List.iter print_row bus\n | _ -> print_str \"NO\"\n\nlet () = print_bus (seat (read_input ()))\n"}, {"source_code": "let read_int () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_char () = Scanf.scanf \"%c \" (fun c -> c)\nlet print option = \n match option with\n | Some array -> Printf.printf \"YES\\n\";\n Array.iter (fun row -> \n Array.iter (Printf.printf \"%c\") row;\n Printf.printf \"\\n\") array\n | None -> Printf.printf \"NO\\n\"\n \nlet input () = \n let n = read_int () in \n let all_rows = Array.init n (fun _ -> Array.init 5 (fun _ -> read_char ())) in\n (all_rows, n)\n\nlet modify row =\n let rec loop i = \n if i < 5\n then\n let char = row.(i) in\n let prev = row.(i - 1) in\n if char = 'O' && char = prev\n then\n (Array.set row i '+';\n Array.set row (i - 1) '+';\n true)\n else\n loop (i + 1)\n else\n false\n in loop 1\n\nlet solve (all_rows, n) =\n let rec loop i = \n if i < n\n then\n let row = all_rows.(i) in\n if modify row\n then\n Some all_rows\n else\n loop (i + 1)\n else\n None\n in loop 0\n\nlet () = print (solve (input ()))"}], "negative_code": [], "src_uid": "e77787168e1c87b653ce1f762888ac57"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x) in\nlet n = read_int() in\n let f = read_int() in \n let mmin = ref f and mmax = ref f in\n let count = ref 0 in\n for i = 1 to n-1 do\n let next = read_int() in\n if next > !mmax then begin\n mmax := next;\n incr count;\n end else if next < !mmin then begin\n mmin := next;\n incr count;\n end;\n done;\n print_int !count;\n print_newline();;", "positive_code": [{"source_code": "let rdint =\n let l = ref 0 in\n let i = ref 0 in\n let s = String.create 65536 in\n let refill () =\n let n = input stdin s 0 65536 in\n i := 0;\n l := n in\n refill ();\n\n fun () ->\n let rec loop2 j k t f =\n let fin j t f =\n let _ = i := j in\n t * f in\n\n if j = k then (\n let _ = refill () in\n if !l > 0 then loop2 !i !l t f else fin j t f\n ) else if s.[j] >= '0' && s.[j] <= '9' then\n loop2 (j + 1) k (t * 10 + Char.code s.[j] - 48) f\n else fin j t f in\n\n let rec loop1 j k =\n if j = k then (\n let _ = refill () in\n if !l > 0 then loop1 !i !l else 0\n ) else if s.[j] = '-' then loop2 (j + 1) k 0 (-1)\n else if s.[j] >= '0' && s.[j] <= '9' then loop2 (j + 1) k (Char.code s.[j] - 48) 1\n else loop1 (j + 1) k in\n loop1 !i !l\n\nlet main () =\n let rec loop i min0 max0 acc =\n if i = 0 then Printf.printf \"%d\\n\" acc else\n let k = rdint () in\n let acc = if k < min0 || k > max0 then acc + 1 else acc in\n loop (i - 1) (min min0 k) (max max0 k) acc\n in\n let n = rdint() in\n let s = rdint() in\n loop (n - 1) s s 0\n;;\nmain ()\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet solve () =\n let n = read () in\n let first = read () in\n let rec loop i count max min =\n if i < n\n then\n let score = read () in\n if score < min\n then\n loop (i + 1) (count + 1) max score\n else\n if score > max\n then\n loop (i + 1) (count + 1) score min\n else\n loop (i + 1) count max min\n else\n count\n in loop 1 0 first first\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ()) "}], "negative_code": [], "src_uid": "a61b96d4913b419f5715a53916c1ae93"} {"source_code": "(*\n2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n4\n9\n25\n49\n\n*)\n\nlet _ =\n let tab =\n[|\n3;\n5;\n7;\n11;\n13;\n17;\n19;\n23;\n29;\n31;\n37;\n41;\n43;\n47;\n4;\n9;\n25;\n49\n|] in\n let cpt = ref (Printf.printf \"2\\n\"; flush stdout; Scanf.scanf \"%s\" (fun i -> if i = \"yes\" then 1 else 0)) in\n Array.iter (fun i -> Printf.printf \"%d\\n\" i; flush stdout; Scanf.scanf \" %s\" (fun i -> if i = \"yes\" then incr cpt)) tab;\n if !cpt < 2\n then Printf.printf \"prime\"\n else Printf.printf \"composite\";\n flush stdout\n", "positive_code": [{"source_code": "open Printf\nopen String\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 primes_small = [2; 3; 5; 7]\nlet primes_big = [11; 13; 17; 19; 23; 29; 31; 37; 41; 43; 47]\nlet squares = [4; 9; 25; 49]\n\nlet () = \n\n let try_a_d d =\n printf \"%d\\n%!\" d;\n let s = read_line() in\n match s with \"yes\" -> true | \"no\" -> false | _ -> failwith \"bad input\"\n in\n\n let countlist li = List.fold_left (\n fun ac e -> if try_a_d e then ac+1 else ac\n ) 0 li in\n\n\n let nsmall = countlist primes_small in\n let nbig = countlist primes_big in\n let nsquares = countlist squares in\n \n if nsmall = 0 then printf \"prime\\n\"\n else if nsmall >= 2 || nsquares > 0 then printf \"composite\\n\"\n else if nbig = 0 then printf \"prime\\n\"\n else printf \"composite\\n\"\n"}], "negative_code": [{"source_code": "open Printf\nopen String\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 primes_small = [2; 3; 5; 7]\nlet primes_big = [11; 13; 17; 19; 23; 29; 31; 37; 41; 43; 47]\nlet squares = [4; 9; 25; 49]\n\nlet () = \n\n let try_a_d d =\n printf \"%d\\n%!\" d;\n let s = read_line() in\n match s with \"yes\" -> true | \"no\" -> false | _ -> failwith \"bad input\"\n in\n\n let countlist li = List.fold_left (\n fun ac e -> if try_a_d e then 1 else 0\n ) 0 li in\n\n\n let nsmall = countlist primes_small in\n let nbig = countlist primes_big in\n let nsquares = countlist squares in\n \n if nsmall = 0 then printf \"prime\\n\"\n else if nsmall >= 2 || nsquares > 0 then printf \"composite\\n\"\n else if nbig = 0 then printf \"prime\\n\"\n else printf \"composite\\n\"\n"}], "src_uid": "8cf479fd47050ba96d21f3d8eb43c8f0"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 0 in\n\n\tlet tab = Array.make (n + 1) 100000 in\n\n\tfor i = 0 to n - 1 do \n\t\ttab.(i) <- read_int ()\n\tdone;\n\n\tfor i = 1 to n - 1 do \n\t\tif tab.(i) + tab.(i - 1) < m then begin\n\t\t\twyn := !wyn + abs(m - (tab.(i) + tab.(i - 1)));\n\t\t\ttab.(i) <- m - tab.(i - 1);\n\t\tend;\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;\n\n\tfor i = 0 to n - 1 do \n\t\tprintf \"%d \" tab.(i)\n\tdone;", "positive_code": [{"source_code": "open Printf\n\nlet (n1,k1) = Scanf.scanf \"%d %d \" (fun x y -> (x,y) )\n\nlet rec readi n a =\n match n with\n | 0 -> (List.rev a)\n | _ -> let x = Scanf.scanf \"%d \" (fun x -> x) in\n readi (n-1) (x::a)\n\nlet l = readi n1 []\n\n(*\nlet () =\n List.iter (fun x -> printf \"%d \" x) l;\n print_endline \"\"\n *)\n\nlet rec f a al ll = \n match ll with\n |[] -> (a, List.rev al)\n |x1::[] -> (a,List.rev (x1::al))\n |x1::(x2::tl) -> \n if x1+x2 printf \"%d \" x) al\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let k = read () in \n let arr = Array.append (Array.make 1 k) (Array.init n (fun n -> read ())) in\n (n, k, arr)\n\nlet solve (n, k, arr) =\n let rec loop sum i = \n if i < n + 1\n then \n let a = arr.(i - 1) in\n let b = arr.(i) in\n if a + b < k \n then\n (arr.(i) <- k - a;\n let new_sum = sum + (k - a - b) in\n loop new_sum (i + 1))\n else\n loop sum (i + 1)\n else\n (sum, Array.sub arr 1 n)\n in loop 0 1\n\nlet print (sum, array) = \n Printf.printf \"%d\\n\" sum;\n Array.iter (Printf.printf \"%d \") array;\n Printf.printf \"\\n\"\n\nlet () = print (solve (input ()))\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 0 in\n\n\tlet tab = Array.make (n + 1) 100000 in\n\n\tfor i = 0 to n - 1 do \n\t\ttab.(i) <- read_int ()\n\tdone;\n\n\tfor i = 1 to n - 1 do \n\t\tif tab.(i) + tab.(i - 1) < m then\n\t\t\twyn := !wyn + abs(tab.(i) - tab.(i - 1));\n\t\ttab.(i) <- m - tab.(i - 1);\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;\n\t\n\tfor i = 0 to n - 1 do \n\t\tprintf \"%d \" tab.(i)\n\tdone;"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n\tlet n = read_int ()\n\tand m = read_int () \n\tand wyn = ref 0 in\n\n\tlet tab = Array.make (n + 1) 100000 in\n\n\tfor i = 0 to n - 1 do \n\t\ttab.(i) <- read_int ()\n\tdone;\n\n\tfor i = 1 to n - 1 do \n\t\tif tab.(i) + tab.(i - 1) < m then\n\t\t\twyn := !wyn + abs(m - (tab.(i) + tab.(i - 1)));\n\t\ttab.(i) <- m - tab.(i - 1);\n\tdone;\n\n\tprintf \"%d\\n\" !wyn;\n\n\tfor i = 0 to n - 1 do \n\t\tprintf \"%d \" tab.(i)\n\tdone;"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let k = read () in \n let arr = Array.append (Array.make 1 k) (Array.init n (fun n -> read ())) in\n (n, k, arr)\n\nlet solve (n, k, arr) =\n let rec loop sum i = \n if i < n + 1\n then \n let a = arr.(i - 1) in\n let b = arr.(i) in\n if a + b < k \n then\n (arr.(i) <- k - a;\n let new_sum = sum + (k - a) in\n loop new_sum (i + 1))\n else\n loop sum (i + 1)\n else\n (sum, Array.sub arr 1 n)\n in loop 0 1\n\nlet print (sum, array) = \n Printf.printf \"%d\\n\" sum;\n Array.iter (Printf.printf \"%d \") array;\n Printf.printf \"\\n\"\n\nlet () = print (solve (input ()))\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let k = read () in \n let arr = Array.append (Array.make 1 k) (Array.init n (fun n -> read ())) in\n (n, k, arr)\n\nlet solve (n, k, arr) =\n let rec loop i = \n if i < n + 1\n then \n let a = arr.(i - 1) in\n let b = arr.(i) in\n if a + b < k \n then\n (arr.(i) <- k - a;\n loop (i + 1))\n else\n loop (i + 1)\n else\n Array.sub arr 1 n \n in loop 1\n\nlet print array = Array.iter (Printf.printf \"%d \") array;\n Printf.printf \"\\n\"\n\nlet () = print (solve (input ()))"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let k = read () in \n let arr = Array.append (Array.make 1 k) (Array.init n (fun n -> read ())) in\n (n, k, arr)\n\nlet solve (n, k, arr) =\n let rec loop sum i = \n if i < n + 1\n then \n let a = arr.(i - 1) in\n let b = arr.(i) in\n if a + b < k \n then\n (arr.(i) <- k - a - b;\n let new_sum = sum + (k - a) in\n loop new_sum (i + 1))\n else\n loop sum (i + 1)\n else\n (sum, Array.sub arr 1 n)\n in loop 0 1\n\nlet print (sum, array) = \n Printf.printf \"%d\\n\" sum;\n Array.iter (Printf.printf \"%d \") array;\n Printf.printf \"\\n\"\n\nlet () = print (solve (input ()))\n"}], "src_uid": "1956e31a9694b4fd7690f1a75028b9a1"} {"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let str = (input_line stdin) in\r\n let rep = ref true in \r\n if str.[0] = 'B' || str.[String.length str -1] = 'A' then rep := false \r\n else begin\r\n let tot = ref 0 in\r\n for j = 0 to String.length str -1 do\r\n if str.[j] = 'B' then incr tot else decr tot ;\r\n if !tot > 0 then rep := false\r\n done;\r\n end;\r\n if !rep then print_endline \"YES\" else print_endline \"NO\";\r\ndone;;", "positive_code": [{"source_code": "let read_word () = Scanf.scanf \" %s\" (fun x -> x);;\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\n\r\nlet rec create_char_list input input_length = function\r\n | 0 -> []\r\n | n -> (String.get input (input_length-n))::(create_char_list input input_length (n-1))\r\n;;\r\n\r\ntype acceptable_char = A | B | AB ;;\r\n\r\nlet rec run_case a_count = function\r\n | A, [x] -> false\r\n | _, [x] -> if (x=='B') then true else false\r\n | A, x::xs -> \r\n if (x=='A') then run_case (a_count+1) (AB, xs) \r\n else false\r\n | B, x::xs -> \r\n if (x=='B') then run_case (a_count-1) (A, xs) \r\n else false\r\n | AB, x::xs -> \r\n if (x=='B' && a_count==1) then run_case 0 (A, xs) \r\n else if (x=='B') then run_case (a_count-1) (AB, xs)\r\n else run_case (a_count+1) (AB, xs)\r\n;;\r\n\r\nlet rec run_cases = function\r\n | 0 -> 0\r\n | n -> \r\n let str_case = read_word () in \r\n let lst_case = create_char_list str_case (String.length str_case) (String.length str_case) in\r\n if (run_case 0 (A, lst_case)) then begin\r\n print_string \"YES\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n else begin\r\n print_string \"NO\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n;;\r\n\r\nlet num_cases = read_int () in\r\nrun_cases num_cases;;\r\n"}], "negative_code": [{"source_code": "let read_word () = Scanf.scanf \" %s\" (fun x -> x);;\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\n\r\nlet rec create_char_list input input_length = function\r\n | 0 -> []\r\n | n -> (String.get input (input_length-n))::(create_char_list input input_length (n-1))\r\n;;\r\n\r\ntype acceptable_char = A | B | AB ;;\r\n\r\nlet rec run_case = function\r\n | A, [x] -> false\r\n | _, [x] -> if (x=='B') then true else false\r\n | A, x::xs -> if (x=='A') then run_case (AB, xs) else false\r\n | B, x::xs -> if (x=='B') then run_case (A, xs) else false\r\n | AB, x::xs -> run_case (AB, xs)\r\n;;\r\n\r\nlet rec run_cases = function\r\n | 0 -> 0\r\n | n -> \r\n let str_case = read_word () in \r\n let lst_case = create_char_list str_case (String.length str_case) (String.length str_case) in\r\n if (run_case (A, lst_case)) then begin\r\n print_string \"YES\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n else begin\r\n print_string \"NO\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n;;\r\n\r\nlet num_cases = read_int () in\r\nrun_cases num_cases;;\r\n"}, {"source_code": "let read_word () = Scanf.scanf \" %s\" (fun x -> x);;\r\nlet read_int () = Scanf.scanf \" %d\" (fun x -> x);;\r\n\r\nlet rec create_char_list input input_length = function\r\n | 0 -> []\r\n | n -> (String.get input (input_length-n))::(create_char_list input input_length (n-1))\r\n;;\r\n\r\ntype acceptable_char = A | B | AB ;;\r\n\r\nlet rec run_case = function\r\n | A, [x] -> false\r\n | _, [x] -> if (x=='B') then true else false\r\n | A, x::xs -> if (x=='A') then run_case (AB, xs) else false\r\n | B, x::xs -> if (x=='B') then run_case (A, xs) else false\r\n | AB, x::xs -> if (x=='B') then run_case (A, xs) else run_case (AB, xs)\r\n;;\r\n\r\nlet rec run_cases = function\r\n | 0 -> 0\r\n | n -> \r\n let str_case = read_word () in \r\n let lst_case = create_char_list str_case (String.length str_case) (String.length str_case) in\r\n if (run_case (A, lst_case)) then begin\r\n print_string \"YES\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n else begin\r\n print_string \"NO\";\r\n print_newline ();\r\n run_cases (n-1)\r\n end\r\n;;\r\n\r\nlet num_cases = read_int () in\r\nrun_cases num_cases;;\r\n\r\n"}, {"source_code": "let n = int_of_string (input_line stdin) in\r\nfor i = 0 to n-1 do\r\n let str = (input_line stdin) in\r\n let rep = ref true in \r\n if str.[0] = 'B' || str.[String.length str -1] = 'A' then rep := false \r\n else begin\r\n for j = 0 to String.length str -2 do\r\n if str.[j] = 'B' && str.[j+1] = 'B' then rep := false\r\n done;\r\n end;\r\n if !rep then print_endline \"YES\" else print_endline \"NO\";\r\ndone;;"}], "src_uid": "0b9be2f076cfa13cdc76c489bf1ea416"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet rec pow n = if n=0 then 1 else \n let m = n/2 in\n let p = pow m in\n (if m+m=n then 1 else 10)*p*p mod 210\n\nlet () = \n let n = read_int() in\n if n<=2 then print_string \"-1\\n\"\n else if n=3 then print_string \"210\\n\"\n else \n let x = pow (n-1) in\n let y = 210-x in\n\tprint_string \"1\";\n\tfor i=2 to n-3 do\n\t print_string \"0\"\n\tdone;\n\tPrintf.printf \"%03d\\n\" y\n\t\n\t\n", "positive_code": [{"source_code": "(* Codeforces 248B PaperWork done *)\n\nopen Big_int;;\nopen List;;\n\n(* you can use either gr or rdln but not both *)\nlet gr () = Scanf.scanf \" %d\" (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 sp = [2; 3; 5; 7];;\n\nlet cvo o p = (o * 10) mod p;;\n\n(* remainders 10^n from dividing by 2 3 5 7 *)\nlet rec ostat n p o = match n with \n| 0 -> o\n| _ -> ostat (n-1) p (cvo o p);; \n\nlet checkonep o p k = ((o + k) mod p) = 0;;\n\nlet rec checklp lo lp k = match lo with \n| [] -> true\n| h :: t -> (checkonep h (List.hd lp) k) && (checklp t (List.tl lp) k);;\n\nlet rec findfirst lo lp k = \n\tif checklp lo lp k then k\n\telse findfirst lo lp (k+1);;\n\t\nlet rec pow10 n = match n with\n| 0 -> Big_int.unit_big_int\n| _ ->\n\tif n < 10 then Big_int.mult_int_big_int 10 (pow10 (n-1))\n\telse \n\t\tlet a = n/2 in\n\t\tlet b = n - 2*a in\n\t\tlet pa = pow10 a in\n\t\tlet pb = pow10 b in\n\t\tBig_int.mult_big_int pa (Big_int.mult_big_int pa pb);;\n\nlet main () =\n\tlet n = gr() in\n\tlet lo = List.map (fun p -> ostat (n-1) p 1) sp in\n\tlet k = findfirst lo sp 1 in\n\tif n < 3 then print_string \"-1\"\n\telse begin\n\t\t(* print_string \"lo = \"; *)\n\t\t(* printlisti lo; *)\n\t\t(* print_string (\"\\nk = \" ^ (string_of_int k) ^ \"\\n\"); *)\n\t\tlet pown = pow10 (n-1) in\n\t\tlet ret = Big_int.add_int_big_int k pown in\n\t\tprint_string (Big_int.string_of_big_int ret)\n\tend;;\n\nmain();;\n"}], "negative_code": [], "src_uid": "386345016773a06b9e190a55cc3717fa"} {"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n\n let rec remove d x = if x mod d = 0 then remove d (x/d) else x in\n\n for i=0 to n-1 do\n a.(i) <- remove 3 (remove 2 a.(i))\n done;\n\n if forall 1 (n-1) (fun i -> a.(0) = a.(i)) then printf \"Yes\\n\" else printf \"No\\n\"\n\n \n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet id x = x\n\nlet rec gen_norm k x = if x mod k = 0 then gen_norm k (x / k) else x\nlet norm x = gen_norm 2 (gen_norm 3 x)\n\nlet () =\n let n = scanf \" %d\" id in\n let a = scanf \" %d\" norm in\n let rec check = function\n | 0 -> true\n | n -> (scanf \" %d\" norm = a) && check (n - 1) in\n printf \"%s\\n\" (if check (n - 1) then \"Yes\" else \"No\")\n"}, {"source_code": "open Printf\nopen Scanf\n\n(* returns true iff f t = true for all i <= t <= j *)\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\n\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 let rec remove d x = if x mod d = 0 then remove d (x/d) else x in\n\n for i=0 to n-1 do\n a.(i) <- remove 3 (remove 2 a.(i))\n\n done;\n\n if forall 1 (n-1) (fun i -> (a.(0) = a.(i))) \n then printf \"Yes\\n\" else printf \"No\\n\""}, {"source_code": "module IntMap = Map.Make(struct type t = int let compare = compare end)\n\n(* factorise : int -> (int * int) list *)\nlet reachable n =\n let rec aux d n =\n if n = 1 then true else\n if d > 3 then false else\n if n mod d = 0 then aux d (n / d) else aux (d + 1) n\n in\n aux 2 n\n\nlet rec gcd n m =\n if m = 0 then n else gcd m (n mod m)\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* calculate lcm *)\n let g = Array.fold_left (fun a b -> gcd a b)\n a.(0) (Array.sub a 1 (Array.length a - 1))\n in\n let ap = Array.map (fun n -> reachable (n / g)) a in\n print_endline (if List.for_all (fun x -> x) (Array.to_list ap) then \"Yes\" else \"No\"))\n"}], "negative_code": [], "src_uid": "2bb893703cbffe9aeaa0bed02f42a05c"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let total = (read ()) - 1 in\n let destination = (read ()) - 1 in\n let portals = Array.init total (fun n -> read ()) in\n (total, destination, portals)\n\nlet solve (total, destination, portals) = \n let rec loop i =\n if i < total\n then\n let portal_in = portals.(i) in\n let portal_out = portal_in + i in\n if portal_out < destination\n then\n loop (portal_out) \n else\n if portal_out = destination\n then\n \"YES\"\n else\n \"NO\"\n else\n failwith \"Corrupted input\"\n in loop 0\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d %d\\n\" (fun n t ->\n let p = Array.init (n - 1) (fun _ ->\n Scanf.scanf \"%d%_c\" (fun x -> x))\n in\n let rec f i =\n if i > t then false\n else if i = t then true\n else f (i + p.(i - 1))\n in\n print_endline (if f 1 then \"YES\" else \"NO\")\n)\n"}, {"source_code": "\nlet words line = Str.split (Str.regexp \" \") line;;\n\nlet transport curr arr = curr + arr.(curr - 1);;\n\nlet rec step arr start goal =\n if start = goal then\n \"YES\"\n else if goal < start then\n \"NO\"\n else\n step arr (transport start arr) goal\n;;\n\nlet () =\n let nk = words (read_line ()) in\n let goal = int_of_string (List.nth nk 1) in\n let line = words (read_line ()) in\n let arr = Array.of_list (List.map int_of_string line)\n in\n Printf.printf \"%s\\n\"\n (step arr 1 goal)\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 t = read_int () in\n let a = Array.init n (fun i -> if i=0 then 0 else read_int()) in\n \n let rec scan c =\n if c = t then true else if c = n then false else scan (c + a.(c))\n in\n\n if scan 1 then printf \"YES\\n\" else printf \"NO\\n\"\n"}], "negative_code": [{"source_code": "let input () = Scanf.scanf \"%d %d \" (fun n m -> (n, m))\n\nlet solve (n, m) =\n let rec loop i =\n if i < n\n then\n let portal_in = Scanf.scanf \"%d \" (fun p -> p) in\n let portal_out = portal_in + i in\n if portal_out < m\n then\n loop (i + 1) \n else\n if portal_out = m\n then\n \"YES\"\n else\n \"NO\"\n else\n failwith \"Corrupted input\"\n in loop 1\n\nlet print result = Printf.printf \"%s\\n\" result\nlet () = print (solve (input ()))"}], "src_uid": "9ee3d548f93390db0fc2f72500d9eeb0"} {"source_code": "input_line stdin\n\nlet eval a b =\n if a + b == 0 then 0 else 1 ;;\n\n let rec solve acc =\n let i = Scanf.scanf \"%d %d \" eval in\n try solve (acc + i) with _ -> acc + i ;;\n\nlet ans = solve 0 ;;\n\nPrintf.printf \"%d\\n\" ans ;;", "positive_code": [{"source_code": "let [n; m]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) and ans = ref 0;;\nfor i= 1 to n do\n\tlet s = List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n\t\tfor j= 1 to m do \n\t\t\tif (List.nth s (2 * j - 1) = 1) || (List.nth s (2 * j - 2) = 1) then \n\t\t\t\tans:= !ans + 1;\n\t\tdone\ndone;;\nprint_int !ans\n"}, {"source_code": "let read_int() = Scanf.scanf \"%d \" (fun x->x) ;;\nlet rec f = function 0 -> 0 | c -> ( read_int() lor read_int() ) + f (c-1) in print_int @@ f ( read_int() * read_int() )"}, {"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 m = read_int () in\n\n let awake a b = if a+b > 0 then 1 else 0 in\n let answer = sum 1 n (fun i ->\n sum 1 m (fun j ->\n let a = read_int() in\n let b = read_int() in\n awake a b\n )\n ) in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [], "src_uid": "5b9aed235094de7de36247a3b2a34e0f"} {"source_code": "open Array;;\nopen String;;\nlet (|>) x f = f x\nlet identity = fun x -> x\n \nlet flip f y x = f x y\n \nlet readStrLn _ = \n try Some (Scanf.scanf \"%s\\n\" identity)\n with _ -> None\nlet readIntLn _ = Scanf.scanf \"%d\\n\" identity\n \nlet foldCont f a cont = \n let rec fold' a = match cont () with\n None -> a\n | Some x -> fold' (f a x)\n in fold' a\n \nlet _ = readIntLn ()\nlet temp = Scanf.scanf \"%s\\n\" identity\nlet len = length temp;;\nlet f a b = \n let rec f' i = match b.[i] with\n c when c = temp.[i] -> f' (i+1)\n | _ -> temp.[i] <- ' '; i\n in f' 0;;\n(*let main () = *)\nif len = 1 then (print_int 0)\nelse ( len |> flip (foldCont f) readStrLn |> print_int; ());;", "positive_code": [{"source_code": "let solve codes =\n let rec loop length =\n let num = String.get (List.hd codes) length in\n if List.for_all (fun str -> (String.get str length) = num) codes\n then loop (length+1)\n else length\n in\n loop 0\n\nlet rec input_strings n =\n if n <= 0 then []\n else (Scanf.scanf \" %s\" (fun x -> x)) :: (input_strings (n-1))\n\nlet _ =\n let codes = Scanf.scanf \" %d\" input_strings in\n Printf.printf \"%d\\n\" (solve codes)\n \n"}], "negative_code": [{"source_code": "open Array;;\nopen String;;\nlet (|>) x f = f x\nlet identity = fun x -> x\n \nlet flip f y x = f x y\n \nlet readStrLn _ = \n try Some (Scanf.scanf \"%s\\n\" identity)\n with _ -> None\nlet readIntLn _ = Scanf.scanf \"%d\\n\" identity\n \nlet foldCont f a cont = \n let rec fold' a = match cont () with\n None -> a\n | Some x -> fold' (f a x)\n in fold' a\n \nlet _ = readIntLn ()\nlet temp = Scanf.scanf \"%s\\n\" identity\nlet len = length temp ;;\nlet f a b = \n let rec f' i = match b.[i] with\n c when c = temp.[i] -> f' (i+1)\n | _ -> i\n in f' 0;;\n(*let main () = *)\nif len = 1 then (print_int 0)\nelse ( len |> flip (foldCont f) readStrLn |> print_int; ());;"}], "src_uid": "081b35620952bd32ce6d8ddc756e5c9d"} {"source_code": "\nlet int_of_hex c = match c with\n| '0' .. '9' -> int_of_char c - int_of_char '0'\n| 'A' .. 'F' -> int_of_char c - int_of_char 'A' + 10\n| _ -> failwith \"\"\nlet rec fix f x = f (fix f) x\nlet gcd = fix (fun f m n ->\n if n=0 then m else f n (m mod n))\n;;\nScanf.(Array.(scanf \" %d\" @@ fun n ->\n let mat = make_matrix n n 0 in\n init n (fun i -> scanf \" %s\" @@ fun s ->\n String.iteri (fun j c ->\n let ih = int_of_hex c in\n mat.(i).(4*j) <- ih land 8 / 8;\n mat.(i).(4*j+1) <- ih land 4 / 4;\n mat.(i).(4*j+2) <- ih land 2 / 2;\n mat.(i).(4*j+3) <- ih land 1;\n ) s\n ) |> ignore;\n let visited = make_matrix n n false in\n let g = ref n in\n let fy y x pt = fix (fun f y ->\n if y>=n || visited.(y).(x) || mat.(y).(x) <> pt then y-1 else f (y+1)) y in\n for i=0 to n-1 do\n for j=0 to n-1 do\n if visited.(i).(j) then ()\n else (\n let pat = mat.(i).(j) in\n let bottom = fy i j pat in\n let finalize x =\n for ii=i to bottom do\n for jj=j to x-1 do\n visited.(ii).(jj) <- true\n done\n done;\n in\n let p,q = fix (fun f (p,q) x ->\n if x>=n then (\n finalize x; (p,q)\n ) else\n let b1 = fy i x pat in\n if b1 <> bottom then (\n finalize x; (p,q)\n ) else f (p,q+1) (x+1)\n ) (bottom+1,1) (j+1) in\n g := gcd !g @@ gcd p q;\n (* Printf.printf \"%2d %2d :: %2d %2d\\n\" i j p q;\n iter (fun b ->\n iter (fun f -> Printf.printf @@ if f then \"t \" else \"_ \") b; print_newline ()\n ) visited *)\n )\n done;\n done;\n print_int @@ !g\n))", "positive_code": [{"source_code": "let int_of_hex c = match c with\n| '0' .. '9' -> int_of_char c - int_of_char '0'\n| 'A' .. 'F' -> int_of_char c - int_of_char 'A' + 10\n| _ -> failwith \"\"\nlet rv f p q = f q p\nlet divisors n = (* O(sqrt n) *)\n let rec f0 i a =\n if i*i > n then a\n else if i*i = n && n mod i = 0 then i::a\n else if n mod i = 0 then f0 (i+1) (i::(n/i)::a)\n else f0 (i+1) a in f0 1 []\n;;\nScanf.(Array.(scanf \" %d\" @@ fun n ->\n let mat = make_matrix n n 0 in\n init n (fun i -> scanf \" %s\" @@ fun s ->\n String.iteri (fun j c ->\n let ih = int_of_hex c in\n mat.(i).(4*j) <- ih land 8 / 8;\n mat.(i).(4*j+1) <- ih land 4 / 4;\n mat.(i).(4*j+2) <- ih land 2 / 2;\n mat.(i).(4*j+3) <- ih land 1;\n ) s\n ) |> ignore;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%d \" v\n ) a; print_newline ()\n ) mat; *)\n let cml = make_matrix (n+1) (n+1) 0 in\n iteri (fun i a ->\n iteri (fun j _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j) + mat.(i).(j)\n ) a\n ) mat;\n iteri (fun j a ->\n iteri (fun i _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j+1) + cml.(i).(j+1)\n ) a\n ) mat;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%2d \" v\n ) a; print_newline ()\n ) cml; *)\n let get d y x =\n let y,x = y+1,x+1 in\n cml.(y+d-1).(x+d-1) - cml.(y+d-1).(x-1) - cml.(y-1).(x+d-1) + cml.(y-1).(x-1)\n in\n divisors n\n |> List.sort (rv compare)\n |> List.iter (fun d ->\n if d=1 then (\n print_int 1; exit 0;\n );\n let f = ref true in\n init (n/d) (fun y ->\n init (n/d) (fun x ->\n let w = get d (y*d) (x*d) in\n if w=d*d || w=0 then ()\n else f := false\n ) |> ignore\n ) |> ignore;\n if !f then (\n print_int d; exit 0\n )\n )\n));;"}], "negative_code": [{"source_code": "\nlet int_of_hex c = match c with\n| '0' .. '9' -> int_of_char c - int_of_char '0'\n| 'A' .. 'F' -> int_of_char c - int_of_char 'A' + 10\n| _ -> failwith \"\"\nlet divisors n = (* O(sqrt n) *)\n let rec f0 i a =\n if i*i > n then a\n else if i*i = n && n mod i = 0 then i::a\n else if n mod i = 0 then f0 (i+1) (i::(n/i)::a)\n else f0 (i+1) a in f0 1 []\nlet binary_search ng ok f = let d = if ng < ok then 1 else -1 in\n let rec f0 ng ok =\n if abs (ok - ng) <= 1 then ok\n else let mid = ng + (ok - ng) / 2 in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-d) (ok+d)\n;;\nScanf.(Array.(scanf \" %d\" @@ fun n ->\n let mat = make_matrix n n 0 in\n init n (fun i -> scanf \" %s\" @@ fun s ->\n String.iteri (fun j c ->\n let ih = int_of_hex c in\n mat.(i).(4*j) <- ih land 8 / 8;\n mat.(i).(4*j+1) <- ih land 4 / 4;\n mat.(i).(4*j+2) <- ih land 2 / 2;\n mat.(i).(4*j+3) <- ih land 1;\n ) s\n ) |> ignore;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%d \" v\n ) a; print_newline ()\n ) mat; *)\n let cml = make_matrix (n+1) (n+1) 0 in\n iteri (fun i a ->\n iteri (fun j _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j) + mat.(i).(j)\n ) a\n ) mat;\n iteri (fun j a ->\n iteri (fun i _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j+1) + cml.(i).(j+1)\n ) a\n ) mat;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%2d \" v\n ) a; print_newline ()\n ) cml; *)\n let get d y x =\n cml.(y+d).(x+d) - cml.(y+d).(x) - cml.(y).(x+d) + cml.(y).(x)\n in\n let divs = divisors n |> List.sort compare |> of_list in\n (* iter (Printf.printf \"%2d; \") divs; print_newline (); *)\n print_int @@ divs.(\n binary_search (length divs-1) 0 (fun i ->\n let d = divs.(i) in\n let f = ref true in\n (* Printf.printf \"%d:\\n\" d; *)\n init (n/d) (fun y ->\n init (n/d) (fun x ->\n let w = get d (y*d) (x*d) in\n (* Printf.printf \" %2d,%2d :: %2d\\n\" (y*d) (x*d) w; *)\n if w=d*d || w=0 then ()\n else f := false\n ) |> ignore\n ) |> ignore; !f\n ))\n));;"}, {"source_code": "let int_of_hex c = match c with\n| '0' .. '9' -> int_of_char c - int_of_char '0'\n| 'A' .. 'F' -> int_of_char c - int_of_char 'A' + 10\n| _ -> failwith \"\"\nlet divisors n = (* O(sqrt n) *)\n let rec f0 i a =\n if i*i > n then a\n else if i*i = n && n mod i = 0 then i::a\n else if n mod i = 0 then f0 (i+1) (i::(n/i)::a)\n else f0 (i+1) a in f0 1 []\nlet binary_search ng ok f = let d = if ng < ok then 1 else -1 in\n let rec f0 ng ok =\n if abs (ok - ng) <= 1 then ok\n else let mid = ng + (ok - ng) / 2 in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-d) (ok+d)\n;;\nScanf.(Array.(scanf \" %d\" @@ fun n ->\n let mat = make_matrix n n 0 in\n init n (fun i -> scanf \" %s\" @@ fun s ->\n String.iteri (fun j c ->\n let ih = int_of_hex c in\n mat.(i).(4*j) <- ih land 8 / 8;\n mat.(i).(4*j+1) <- ih land 4 / 4;\n mat.(i).(4*j+2) <- ih land 2 / 2;\n mat.(i).(4*j+3) <- ih land 1;\n ) s\n ) |> ignore;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%d \" v\n ) a; print_newline ()\n ) mat; *)\n let cml = make_matrix (n+1) (n+1) 0 in\n iteri (fun i a ->\n iteri (fun j _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j) + mat.(i).(j)\n ) a\n ) mat;\n iteri (fun j a ->\n iteri (fun i _ ->\n cml.(i+1).(j+1) <- cml.(i+1).(j+1) + cml.(i).(j+1)\n ) a\n ) mat;\n (* iter (fun a ->\n iter (fun v ->\n Printf.printf \"%2d \" v\n ) a; print_newline ()\n ) cml; *)\n let get d y x =\n cml.(y+d).(x+d) - cml.(y+d).(x) - cml.(y).(x+d) + cml.(y).(x)\n in\n let divs = divisors n |> List.sort compare |> of_list in\n print_int @@ divs.(\n binary_search (length divs-1) 0 (fun i ->\n let d = divs.(i) in\n let f = ref true in\n init (n/d) (fun y ->\n init (n/d) (fun x ->\n let w = get d y x in\n if w=d*d || w=0 then ()\n else f := false\n ) |> ignore\n ) |> ignore; !f\n ))\n))"}, {"source_code": "let int_of_hex c = match c with\n| '0' .. '9' -> int_of_char c - int_of_char '0'\n| 'A' .. 'F' -> int_of_char c - int_of_char 'A' + 10\n| _ -> failwith \"\"\nlet rec fix f x = f (fix f) x\nlet gcd = fix (fun f m n ->\n if n=0 then m else f n (m mod n))\n;;\nScanf.(Array.(scanf \" %d\" @@ fun n ->\n let mat = make_matrix n n 0 in\n init n (fun i -> scanf \" %s\" @@ fun s ->\n String.iteri (fun j c ->\n let ih = int_of_hex c in\n mat.(i).(4*j) <- ih land 8 / 8;\n mat.(i).(4*j+1) <- ih land 4 / 4;\n mat.(i).(4*j+2) <- ih land 2 / 2;\n mat.(i).(4*j+3) <- ih land 1;\n ) s\n ) |> ignore;\n let visited = make_matrix n n false in\n let g = ref n in\n let rec visit y x c =\n if y >= n || x >= n || visited.(y).(x) || mat.(y).(x) <> c then 0,0\n else (\n visited.(y).(x) <- true;\n let p,q = visit (y+1) x c in\n let r,s = visit y (x+1) c in\n p+r+1,q+s+1\n )\n in\n for i=0 to n-1 do\n for j=0 to n-1 do\n if visited.(i).(j) then ()\n else (\n let p,q = visit i j mat.(i).(j) in\n g := gcd !g @@ gcd p q;\n )\n done;\n done;\n print_int @@ !g\n))"}], "src_uid": "31d95251cd79d889ff9f0a624ef31394"} {"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\n(* kmp algorithm. *)\n(* memo.(i) will store the length of the longest prefix of s\n that matches the tail of s1...si *)\nlet kmptable s n = \n let memo = Array.make n 0 in\n for i=1 to (n-1) do\n let rec loop j = \n\tif s.[i] = s.[j] then j+1 else if j=0 then 0 else loop memo.(j-1)\n in memo.(i) <- loop memo.(i-1)\n done;\n memo\n\n(*\n(* returns table.\n table.(i) will store the length of the longest prefix of ms\n that matches the tail of ts0...tsi *)\nlet tailtable ts n ms m = \n let memo = kmptable ms m in\n let table = Array.make n 0 in\n table.(0) <- if ts.[0] = ms.[0] then 1 else 0;\n for i=1 to (n-1) do\n let rec loop j = \n\tif ts.[i] = ms.[j] then j+1 else if j=0 then 0 else loop memo.(j-1)\n in\n\ttable.(i) <- loop (if table.(i-1) < m then table.(i-1) else memo.(m-1))\n done;\n table\n*)\n\nlet solve child n pattern =\n let m = String.length pattern in\n let memo = kmptable pattern m in\n\n let run_kmp s j =\n let n = String.length s in\n let rec outer_loop i count j = if i=n then (j, count) else\n let rec loop j = \n\tif s.[i] = pattern.[j] then j+1 else if j=0 then 0 else loop memo.(j-1)\n in\n let j = loop j in\n let count = if j=m then count+1 else count in\n let j = if j=m then memo.(j-1) else j in\n\touter_loop (i+1) count j\n in\n outer_loop 0 0 j\n in\n \n let rec dfs v j ac = \n(* Printf.printf \"at node %d (j=%d, ac=%d)\\n\" v j ac; *)\n List.fold_left (\n fun ac (w,s) ->\n(*\tPrintf.printf \" edge: (%d, %d) = \\\"%s\\\"\\n\" v w s; *)\n\tlet (j', count) = run_kmp s j in\n\t dfs w j' (ac + count)\n ) ac child.(v)\n in\n dfs 0 0 0\n\nlet () =\n let n = read_int() in\n let child = Array.make n [] in\n for i=1 to n-1 do\n let p = read_int() -1 in\n let s = read_string() in\n\tchild.(p) <- (i,s)::child.(p);\n done;\n\n let pattern = read_string() in\n\n Printf.printf \"%d\\n\" (solve child n pattern)\n", "positive_code": [{"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\n(* kmp algorithm. *)\n(* memo.(i) will store the length of the longest prefix of s\n that matches the tail of s1...si *)\nlet kmptable s n = \n let memo = Array.make n 0 in\n for i=1 to (n-1) do\n let rec loop j = \n\tif s.[i] = s.[j] then j+1 else if j=0 then 0 else loop memo.(j-1)\n in memo.(i) <- loop memo.(i-1)\n done;\n memo\n\n(*\n(* returns table.\n table.(i) will store the length of the longest prefix of ms\n that matches the tail of ts0...tsi *)\nlet tailtable ts n ms m = \n let memo = kmptable ms m in\n let table = Array.make n 0 in\n table.(0) <- if ts.[0] = ms.[0] then 1 else 0;\n for i=1 to (n-1) do\n let rec loop j = \n\tif ts.[i] = ms.[j] then j+1 else if j=0 then 0 else loop memo.(j-1)\n in\n\ttable.(i) <- loop (if table.(i-1) < m then table.(i-1) else memo.(m-1))\n done;\n table\n*)\n\nlet l2n c = (int_of_char c) - (int_of_char 'a')\nlet n2l n = char_of_int ((int_of_char 'a') + n)\n\nlet solve child n pattern =\n let m = String.length pattern in\n let memo = kmptable pattern m in\n let jupdate_array = Array.make_matrix m 26 (-1) in\n\n let rec jupdate c x j = \n if jupdate_array.(j).(x) >= 0 then jupdate_array.(j).(x) else\n let j' = if c = pattern.[j] then j+1 else if j=0 then 0 else jupdate c x memo.(j-1) in\n\tjupdate_array.(j).(x) <- j';\n\tj'\n in\n\n let run_kmp s j =\n let n = String.length s in\n let rec loop i count j = if i=n then (j, count) else\n let j = jupdate s.[i] (l2n s.[i]) j in\n let count = if j=m then count+1 else count in\n let j = if j=m then memo.(j-1) else j in\n\tloop (i+1) count j\n in\n loop 0 0 j\n in\n \n let rec dfs v j ac = \n(* Printf.printf \"at node %d (j=%d, ac=%d)\\n\" v j ac; *)\n List.fold_left (\n fun ac (w,s) ->\n(*\tPrintf.printf \" edge: (%d, %d) = \\\"%s\\\"\\n\" v w s; *)\n\tlet (j', count) = run_kmp s j in\n\t dfs w j' (ac + count)\n ) ac child.(v)\n in\n dfs 0 0 0\n\nlet () =\n let n = read_int() in\n let child = Array.make n [] in\n for i=1 to n-1 do\n let p = read_int() -1 in\n let s = read_string() in\n\tchild.(p) <- (i,s)::child.(p);\n done;\n\n let pattern = read_string() in\n\n Printf.printf \"%d\\n\" (solve child n pattern)\n"}], "negative_code": [], "src_uid": "2e08077d0b49c52586266ddcc12edcb5"} {"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 inc = Array.make n 0 in\n let id = Array.make n 0 in\n \n for i=0 to n-1 do\n inc.(i) <- if read_string() = \"-\" then -1 else 1;\n id.(i) <- read_int()\n done;\n\n let rogue = ref [] in\n\n let h = Hashtbl.create 10 in\n\n for i=0 to n-1 do\n if not (Hashtbl.mem h id.(i)) then (\n Hashtbl.replace h id.(i) true;\n if inc.(i) = -1 then rogue := id.(i) :: !rogue\n )\n done;\n\n let rec make_events ac i = if i=n then List.rev ac else\n make_events (id.(i) :: ac) (i+1)\n in\n\n let events = (!rogue) @ (make_events [] 0) in\n\n let h = Hashtbl.create 10 in\n \n let rec scan ev maxsize =\n match ev with [] -> maxsize\n | id::tail ->\n\tif Hashtbl.mem h id then (\n\t Hashtbl.remove h id;\n\t scan tail maxsize\n\t) else (\n\t Hashtbl.replace h id true;\n\t scan tail (max maxsize (Hashtbl.length h))\n\t)\n in\n\n let answer = scan events 0 in\n\n printf \"%d\\n\" answer;\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.make 1_000_000 false in\n let cur = ref 0 and best = ref 0 in\n for i = 1 to n do\n Scanf.scanf \"%c %d\\n\" (fun c x ->\n if c = '-' && not a.(x - 1)\n then incr best\n else begin\n a.(x - 1) <- c = '+';\n if a.(x - 1) then begin\n incr cur;\n best := max !best !cur\n end else decr cur\n end)\n done;\n\n Printf.printf \"%d\\n\" !best)\n"}], "negative_code": [], "src_uid": "6cfd3b0a403212ec68bac1667bce9ef1"} {"source_code": "module A = Array\nmodule L = List\nmodule I = Int64\n\nlet pf = Printf.printf\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\nlet read_array read n = A.init n (fun _ -> read ())\n\nlet () =\n let t = read_int () in\n\n for _ = 1 to t do\n let n = read_int () in\n let a = read_array read_int n in\n let pos = A.make (n + 1) (-1) in\n A.iteri (fun i x -> pos.(x) <- i) a;\n\n let i = ref (n - 2) in\n while !i >= 0 && a.(!i) <= a.(!i + 1) do i := !i - 1 done;\n let decr_pos = !i + 1 in\n if (decr_pos = 0) then\n pf \"0\\n\"\n else begin\n let diff = Array.make (n + 1) false in\n let cnt = ref 0 in\n let mx = ref 0 in\n i := 0;\n while !i < n do\n mx := max !mx pos.(a.(!i));\n if (not diff.(a.(!i))) then cnt := !cnt + 1;\n diff.(a.(!i)) <- true;\n if !i = !mx && !mx + 1 >= decr_pos then begin\n pf \"%d\\n\" !cnt;\n i := n;\n end;\n i := !i + 1;\n done\n end\n done", "positive_code": [{"source_code": "let get_num () =\n let rec f acc =\n try\n let c = input_byte stdin in\n if int_of_char '0' <= c && c <= int_of_char '9' then\n f ((acc * 10) + c - int_of_char '0')\n else if acc > 0 then Some acc\n else None\n with End_of_file -> if acc > 0 then Some acc else None\n in\n f 0\n\nmodule Int_Set = Set.Make (struct\n type t = int\n\n let compare = compare\nend)\n\nlet solve_case () =\n match get_num () with\n | Some n ->\n let rec f i set pending prev =\n if i = n then set\n else\n let i = i + 1 in\n match get_num () with\n | Some a ->\n let a = if Int_Set.mem a set then 0 else a in\n if a < prev then\n let set = Int_Set.union set pending in\n f i set (Int_Set.singleton a) a\n else f i set (Int_Set.add a pending) a\n | _ -> exit 1\n in\n let s = f 0 Int_Set.empty Int_Set.empty 0 in\n let s = Int_Set.remove 0 s in\n let fold_f a x = x + 1 in\n let ans = Int_Set.fold fold_f s 0 in\n print_int ans\n | _ -> exit 1\n\nlet () =\n match get_num () with\n | Some t ->\n let rec f i =\n if i = 0 then ()\n else\n let () = solve_case () in\n let () = print_newline () in\n f (i - 1)\n in\n f t\n | _ -> exit 1\n"}], "negative_code": [], "src_uid": "68e830551c1580bb5aff40d7848d968d"} {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\nlet maxw = 1000100 in\nlet fr = Array.init (maxw+10) (fun _ -> 0) in\n\nlet rec read_loop i = \n\tif i < n then\n\tbegin\n\t\tlet w = (Scanf.scanf \"%d%_c\" (fun x -> x)) in Array.set fr w (succ (Array.get fr w));\n\t\tread_loop (i+1)\n\tend\nin read_loop 0;\n\nlet rec solve_loop i rem needed_steps = \n\tif i <= maxw then\n\t\tlet total = rem + fr.(i) in\n\t\tsolve_loop (i+1) (total/2) (needed_steps + (total mod 2))\n\telse \n\t\tPrintf.printf \"%d\\n\" needed_steps\nin solve_loop 0 0 0);;\n\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\nlet maxw = 1000100 in\nlet fr = Array.init (maxw+10) (fun _ -> 0) in\n\nlet rec read_loop i = \n\tif i < n then\n\tbegin\n\t\tlet w = (Scanf.scanf \"%d%_c\" (fun x -> x)) in fr.(w) <- succ fr.(w);\n\t\tread_loop (i+1)\n\tend\nin read_loop 0;\n\nlet rec solve_loop i rem needed_steps = \n\tif i <= maxw then\n\t\tlet total = rem + fr.(i) in\n\t\tsolve_loop (i+1) (total/2) (needed_steps + (total mod 2))\n\telse \n\t\tPrintf.printf \"%d\\n\" needed_steps\nin solve_loop 0 0 0);;\n\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let m = 1000030 in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n Array.sort compare a;\n let b = Array.make m false in\n for i = 0 to n - 1 do\n\tlet pos = ref a.(i) in\n\t while b.(!pos) do\n\t b.(!pos) <- false;\n\t incr pos;\n\t done;\n\t b.(!pos) <- true\n done;\n let res = ref 0 in\n\tfor i = 0 to m - 1 do\n\t if b.(i)\n\t then incr res\n\tdone;\n\tPrintf.printf \"%d\\n\" !res\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet () =\n let m = 1_000_100 in\n let a = Array.make m 0 in\n let n = read_int() in\n for i = 1 to n do\n let x = read_int() in\n a.(x) <- a.(x) + 1\n done;\n let rec go i carry acc =\n if i = m then acc\n else go (i+1) ((carry + a.(i)) / 2) (acc + ((carry + a.(i)) mod 2))\n in\n Printf.printf \"%d\\n\" (go 0 0 0);;\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let w = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n let s = Array.make 2_000_000 false in\n let on = ref 0 in\n\n let rec insert a =\n if s.(a) then begin\n s.(a) <- false;\n decr on;\n insert (a + 1)\n end else begin\n s.(a) <- true;\n incr on\n end\n in\n\n for i = 0 to n - 1 do\n insert w.(i)\n done;\n\n Printf.printf \"%d\\n\" !on)\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 for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n let b = Array.make n 0 in\n let pos = ref 0 in\n b.(0) <- a.(0);\n for i = 1 to n - 1 do\n\tincr pos;\n\tb.(!pos) <- a.(i);\n\twhile !pos > 0 && b.(!pos) = b.(!pos - 1) do\n\t decr pos;\n\t b.(!pos) <- b.(!pos) + 1\n\tdone;\n done;\n Printf.printf \"%d\\n\" (!pos + 1)\n"}, {"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 for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%d \" (fun s -> s)\n done;\n Array.sort compare a;\n let b = Array.make n 0 in\n let pos = ref 0 in\n b.(0) <- a.(0);\n for i = 1 to n - 1 do\n\tincr pos;\n\tb.(!pos) <- a.(i);\n\twhile !pos > 0 && b.(!pos) = b.(!pos - 1) do\n\t decr pos;\n\t b.(!pos) <- b.(!pos) + 1\n\tdone;\n done;\n Printf.printf \"%d\\n\" (!pos + 1)\n"}], "src_uid": "089eea1841ef10064647e61094c374fd"} {"source_code": "\nlet input_int =\n Scanf.scanf \"%d \" (fun x -> x)\n;;\n\nlet input_string =\n Scanf.scanf \"%s \" (fun x -> x)\n;;\n\nlet solve moves member_count =\n let rec solve_aux i ret =\n if i < String.length moves then begin\n if i >= 3 && moves.[i-1] == moves.[i-2]\n && moves.[i-2] == moves.[i-3] then\n solve_aux (i+member_count) (ret+1)\n else\n solve_aux (i+member_count) ret\n end else ret\n in solve_aux 0 0\n;;\n\nlet member_count = input_int in\nlet moves = input_string in\nPrintf.printf \"%d\\n\" (solve moves member_count);\n\n", "positive_code": [{"source_code": "(* betaveros's polyglot adventure *)\n\nlet people = int_of_string (read_line ());;\nlet moves = read_line ();;\n\nlet canDrink s i = s.[i-1] == s.[i-2] && s.[i-2] == s.[i-3];;\n\nlet rec addDrinkCount s n i accum =\n\tif i >= String.length s then accum\n\telse addDrinkCount s n (i + n) (\n\t\taccum + if canDrink s i then 1 else 0);;\n\nlet solution = addDrinkCount moves people people 0 in\n\tprint_endline (string_of_int solution);;\n"}], "negative_code": [{"source_code": "\nlet input_int =\n Scanf.scanf \"%d \" (fun x -> x)\n;;\n\nlet input_string =\n Scanf.scanf \"%s \" (fun x -> x)\n;;\n\nlet solve moves member_count =\n let rec solve_aux i ret =\n if i < String.length moves then begin\n if i >= 3 && moves.[i-1] == moves.[i-2]\n && moves.[i-2] == moves.[i-3] then\n solve_aux (i+1) (ret+1)\n else\n solve_aux (i+1) ret\n end else ret\n in solve_aux 0 0\n;;\n\nlet member_count = input_int in\nlet moves = input_string in\nPrintf.printf \"%d\\n\" (solve moves member_count);\n\n"}], "src_uid": "5606799ab5345bb9501fa6535e5abef9"} {"source_code": "let read_ints () =\n let str = read_line () in\n List.map (fun x -> int_of_string x) (Str.split (Str.regexp \" +\") str)\n;;\n\nlet rec main (t : int) =\n if t = 0 then\n ()\n else\n let [a;b;c] = read_ints () in\n (if a < c then print_int 1\n else print_int (-1);\n print_string \" \";\n let a2 = Int64.of_int a in\n let b2 = Int64.of_int b in\n let c2 = Int64.of_int c in\n if (Int64.mul a2 b2) > c2 then\n print_int b\n else\n print_int (-1);\n print_endline \"\";\n main (t-1))\n\n;;\n\nlet n = read_int () in\nmain n\n", "positive_code": [{"source_code": "(* Codeforces 1373 A Donut Shops train *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet shops a b c = \n let n1 = if a < c then Int64.one else Int64.minus_one in\n\t\tlet n2 = if c < (Int64.mul b a) then b else Int64.minus_one in\n\t\t(n1, n2);;\n \nlet do_one () = \n let a = grl () in\n let b = grl () in\n let c = grl () in\n let n1,n2 = shops a b c in\n Printf.printf \"%Ld %Ld\\n\" n1 n2;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [{"source_code": "(* Codeforces 1373 A Donut Shops train *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet shops a b c = \n let n1 = if a < c then 1 else -1 in\n\t\tlet n2 = if c < (b * a) then b else -1 in\n\t\t(n1, n2);;\n \nlet do_one () = \n let a = gr () in\n let b = gr () in\n let c = gr () in\n let n1,n2 = shops a b c in\n Printf.printf \"%d %d\\n\" n1 n2;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "src_uid": "002801f26568a1b3524d8754207d32c1"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n \nlet () = \n let n = read_int () in\n let pair = Array.make (2*n) 0 in\n let pair_index = Array.make n 0 in\n for i=0 to n-1 do\n let (a,b) = read_pair() in\n let (a,b) = (a-1,b-1) in\n pair.(a) <- b;\n pair.(b) <- a;\n pair_index.(i) <- a\n done;\n\n let color = Array.make (2*n) 0 in\n\n let rec dfs1 v = if color.(v) = 0 then (\n color.(v) <- 1;\n dfs2 pair.(v)\n )\n and dfs2 v = \n color.(v) <- 2;\n dfs1 (v lxor 1)\n in\n\n for v=0 to 2*n-1 do dfs1 v done;\n \n for i=0 to n-1 do\n let a = pair_index.(i) in\n printf \"%d %d\\n\" color.(a) color.(pair.(a))\n done\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n \nlet () = \n let n = read_int () in\n let pair = Array.make (2*n) 0 in\n let pair_index = Array.make n 0 in\n for i=0 to n-1 do\n let (a,b) = read_pair() in\n let (a,b) = (a-1,b-1) in\n pair.(a) <- b;\n pair.(b) <- a;\n pair_index.(i) <- a\n done;\n\n let color = Array.make (2*n) (-1) in\n\n let rec dfs0 v = if color.(v) < 0 then (\n color.(v) <- 0;\n dfs1 pair.(v)\n )\n and dfs1 v = \n color.(v) <- 1;\n dfs0 (v lxor 1)\n in\n\n for v=0 to 2*n-1 do dfs0 v done;\n\n for i=0 to n-1 do\n let a = pair_index.(i) in\n printf \"%d %d\\n\" (1+color.(a)) (1+color.(pair.(a)))\n done\n"}, {"source_code": "let n = read_int () in\nlet nn = 2 * n in\nlet io2chair = Array.make nn 0 and chair2io = Array.make nn 0 in\nfor i = 0 to nn - 1 do\n let chair = Scanf.scanf \"%d \" (fun x -> x - 1) in\n io2chair.(i) <- chair ; chair2io.(chair) <- i\ndone;\nlet out = Array.make nn 0 in\nlet rec fill_cycle i =\n if out.(i) == 0 then (\n out.(i) <- 1;\n let neighbor = chair2io.(io2chair.(i) lxor 1) in\n out.(neighbor) <- 2;\n fill_cycle (neighbor lxor 1)\n ) in\nfor i = 0 to nn - 1 do\n fill_cycle i\ndone;\nArray.iter (Printf.printf \"%d \") out\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n \nlet () = \n let n = read_int () in\n let pair = Array.make (2*n) 0 in\n let pair_index = Array.make n 0 in\n for i=0 to n-1 do\n let (a,b) = read_pair() in\n let (a,b) = (a-1,b-1) in\n pair.(a) <- b;\n pair.(b) <- a;\n pair_index.(i) <- a\n done;\n\n let color = Array.make (2*n) (-1) in\n\n let rec dfs0 v = if color.(v) < 0 then (\n color.(v) <- 0;\n dfs1 pair.(v)\n )\n and dfs1 v = \n color.(v) <- 1;\n dfs0 (v lxor 1)\n in\n\n let rec dfs_loop v =\n if v < 2*n then if color.(v) < 0 then dfs0 v else dfs_loop (v+1)\n in\n\n dfs_loop 0;\n\n for i=0 to n-1 do\n let a = pair_index.(i) in\n printf \"%d %d\\n\" (1+color.(a)) (1+color.(pair.(a)))\n done\n"}], "src_uid": "49a78893ea2849aa59647846b4eaba7c"} {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet g = [\"don't even\"; \"are you serious?\" ; \"worse\"; \"terrible\"; \"go die in a hole\"; \"no way\"]\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if List.mem s g then\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n else\n incr i\n done\n", "positive_code": [{"source_code": "\nmodule StringSet = Set.Make(String)\n\ntype cat =\n | Normal\n | Grumpy\n\nlet cats = [\n Normal, StringSet.of_list [\n \"great!\";\n \"don't think so\";\n \"nod bad\";\n \"don't touch me\";\n \"cool\"\n ]\n ; Grumpy, StringSet.of_list [\n \"don't even\";\n \"are you serious?\";\n \"go die in a hole\";\n \"no way\";\n \"worse\";\n \"terrible\"\n ]\n]\n\nlet cats_re = [\n Normal, List.map Str.regexp [\n \"cool\";\n \"great\";\n ]\n ; Grumpy, List.map Str.regexp [\n \"die\";\n \"away\";\n \"even\";\n ]\n]\n\nlet find_opt (f: 'a -> bool) (l: 'a list): 'a option =\n try Some (List.find f l) with\n | Not_found -> None\n\nlet determine_heuristic (a: string): cat option =\n (* didn't realize that a simple string find is so hard ... *)\n let str_exist p s =\n try Str.search_forward p s 0; true with\n | Not_found -> false\n in\n match find_opt (fun (_, res) -> List.exists (fun re -> str_exist re a) res) cats_re with\n | None -> None\n | Some (c, _) -> Some c\n\nlet rec determine (i: int): cat =\n if i >= 10\n then Grumpy\n else begin\n i |> string_of_int |> print_endline;\n let reaction = read_line () in\n (* OCaml 4.02.1 has no List.find_opt ... *)\n if reaction = \"no\"\n then i + 1 |> determine\n else\n let found = List.find_all (fun (_, res) -> StringSet.mem reaction res) cats in\n match found with\n | (c, _) :: _ -> c\n | [] -> match determine_heuristic reaction with\n | Some c -> c\n | None -> i + 1 |> determine\n end\n\nlet () =\n (match determine 0 with\n | Normal -> \"normal\"\n | Grumpy -> \"grumpy\") |> print_endline"}], "negative_code": [{"source_code": "let str = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet _ =\n for i = 0 to 9\n do\n Format.printf \"%d@.\" i;\n flush_all ();\n str := read_line ()::!str\n done;\n if result !str then\n Format.printf \"normal@.\"\n else\n Format.printf \"grumpy@.\"\n"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if s = \"don't think so\" then\n ignore(1/0)\n else if s = \"don't touch me!\" then\n ignore(1/0)\n else if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}, {"source_code": "let str = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet _ =\n for i = 0 to 9\n do\n Format.printf \"%d@.\" i;\n flush_all ();\n str := read_line ()::!str\n done;\n if result !str then\n Format.printf \"grumpy@.\"\n else\n Format.printf \"grumpy@.\"\n"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if s = \"don't think so\" then\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n else if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}, {"source_code": "let str = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n Str.string_match (Str.regexp cool) s 0\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet _ =\n for i = 0 to 9\n do\n Format.printf \"%d@.\" i;\n flush_all ();\n str := read_line ()::!str\n done;\n if result !str then\n Format.printf \"normal@.\"\n else\n Format.printf \"grumpy@.\"\n"}, {"source_code": "let str = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet _ =\n for i = 0 to 9\n do\n Format.printf \"%d@.\" i;\n flush_all ();\n str := read_line ()::!str\n done;\n if result !str then\n Format.printf \"normal@.\"\n else\n Format.printf \"normal@.\"\n"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if s = \"don't touch me!\" then\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n else if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}, {"source_code": "\nmodule StringSet = Set.Make(String)\n\ntype cat =\n | Normal\n | Grumpy\n\nlet cats = [\n Normal, StringSet.of_list [\n \"great!\";\n \"don't think so\";\n \"nod bad\";\n \"don't touch me\";\n \"cool\"\n ]\n ; Grumpy, StringSet.of_list [\n \"don't even\";\n \"are you serious?\";\n \"go die in a hole\";\n \"no way\";\n \"worse\";\n \"terrible\"\n ]\n]\n\nlet rec determine (i: int): cat =\n if i >= 10\n then Grumpy\n else begin\n i |> string_of_int |> print_endline;\n let reaction = read_line () in\n (* OCaml 4.02.1 has no List.find_opt ... *)\n let found = List.find_all (fun (_, res) -> StringSet.mem reaction res) cats in\n match found with\n | (c, _) :: _ -> c\n | [] -> i + 1 |> determine\n end\n\nlet () =\n (match determine 0 with\n | Normal -> \"normal\"\n | Grumpy -> \"grumpy\") |> print_endline"}, {"source_code": "\nmodule StringSet = Set.Make(String)\n\ntype cat =\n | Normal\n | Grumpy\n\nlet cats = [\n Normal, StringSet.of_list [\n \"great!\";\n \"don't think so\";\n \"nod bad\";\n \"don't touch me\";\n \"cool\"\n ]\n ; Grumpy, StringSet.of_list [\n \"don't even\";\n \"are you serious?\";\n \"go die in a hole\";\n \"no way\";\n \"worse\";\n \"terrible\"\n ]\n]\n\nlet rec determine (i: int): cat =\n i |> string_of_int |> print_endline;\n let reaction = read_line () in\n (* OCaml 4.02.1 has no List.find_opt ... *)\n let found = List.find_all (fun (_, res) -> StringSet.mem reaction res) cats in\n match found with\n | (c, _) :: _ -> c\n | [] -> i + 1 |> determine\n\nlet () =\n (match determine 0 with\n | Normal -> \"normal\"\n | Grumpy -> \"grumpy\") |> print_endline"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n ignore(1/0);\n if s = \"don't think so\" then\n ignore(1/0)\n else if s = \"don't touch me!\" then\n ignore(1/0)\n else if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}, {"source_code": "let str: string list ref = ref []\n\nlet cool = \"cool\"\n\nlet mem s =\n s = cool\n\nlet result l =\n List.exists (fun s -> mem s) l\n\nlet n = [\"cool\";\"not bad\";\"great\";\"don't think so\"; \"don't touch me!\";]\n\nlet _ =\n let i = ref 0 in\n while !i < 10\n do\n Format.printf \"%d@.\" !i;\n let s = read_line () in\n flush_all ();\n if s = \"don't think so\" then\n while true do () done\n else if s = \"don't touch me!\" then\n while true do () done\n else if List.mem s n then\n begin\n Format.printf \"normal@.\";\n exit 0\n end\n else if s = \"no\" then\n incr i\n else\n begin\n Format.printf \"grumpy@.\";\n exit 0\n end\n done\n"}], "src_uid": "465eae7567d12a40a05e0f258d963838"} {"source_code": "let n = read_int ()\nlet a = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nmodule IntMap = Map.Make(struct type t = int let compare = compare end)\n\ntype node =\n { level : int;\n up : int option;\n }\n\nlet add_node map value =\n let lefts, _, rights = IntMap.split value map in\n let up, {level} = match IntMap.is_empty lefts, IntMap.is_empty rights with\n | true, true -> value, {level = 0; up = None}\n | false, true -> IntMap.max_binding lefts\n | true, false -> IntMap.min_binding rights\n | false, false ->\n let value_left, left = IntMap.max_binding lefts in\n let value_right, right = IntMap.min_binding rights in\n if left.level > right.level\n then value_left, left\n else value_right, right in\n IntMap.add value { level = level + 1; up = Some up; } map\n\nlet node_map = List.fold_left add_node IntMap.empty a\n\nlet () =\n List.tl a\n |> List.iter (fun x -> let {up = Some y} = IntMap.find x node_map in\n Printf.printf \"%d \" y);\n print_newline ()\n", "positive_code": [{"source_code": "let n = read_int ()\nlet a = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nmodule IntMap = Map.Make(struct type t = int let compare = compare end)\n\ntype node =\n { value : int;\n level : int;\n up : int option;\n left : int option;\n right : int option;\n }\n\nlet new_node value =\n { value;\n left = None;\n right = None;\n level = 0;\n up = None }\n\nlet add_node map value =\n let lefts, _, rights = IntMap.split value map in\n let node = new_node value in\n let attached_left () =\n let _, left = (IntMap.max_binding lefts) in\n map\n |> IntMap.add value { node with left = Some left.value;\n level = left.level + 1;\n up = Some left.value; }\n |> IntMap.add left.value { left with right = Some node.value } in\n let attached_right () =\n let _, right = (IntMap.min_binding rights) in\n map\n |> IntMap.add value { node with right = Some right.value;\n level = right.level + 1;\n up = Some right.value; }\n |> IntMap.add right.value { right with left = Some node.value } in\n match IntMap.is_empty lefts, IntMap.is_empty rights with\n | true, true -> IntMap.singleton value node\n | false, true -> attached_left ()\n | true, false -> attached_right ()\n | false, false ->\n let _, left = (IntMap.max_binding lefts) in\n let _, right = (IntMap.min_binding rights) in\n if right.level > left.level then attached_right() else attached_left()\n\nlet node_map = List.fold_left add_node IntMap.empty a\n\nlet () =\n List.tl a\n |> List.iter (fun x -> let {up = Some y} = IntMap.find x node_map in\n Printf.printf \"%d \" y);\n print_newline ()\n"}, {"source_code": "let n = read_int ()\nlet a = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nmodule IntMap = Map.Make(struct type t = int let compare = compare end)\n\ntype node =\n { level : int;\n up : int;\n }\n\nlet add_node map value =\n let lefts, _, rights = IntMap.split value map in\n let up, {level} = match IntMap.is_empty lefts, IntMap.is_empty rights with\n | true, true -> value, {level = 0; up = value}\n | false, true -> IntMap.max_binding lefts\n | true, false -> IntMap.min_binding rights\n | false, false ->\n let value_left, left = IntMap.max_binding lefts in\n let value_right, right = IntMap.min_binding rights in\n if left.level > right.level\n then value_left, left\n else value_right, right in\n IntMap.add value { level = level + 1; up; } map\n\nlet node_map = List.fold_left add_node IntMap.empty a\n\nlet () =\n List.tl a\n |> List.iter (fun x -> let {up} = IntMap.find x node_map in\n Printf.printf \"%d \" up);\n print_newline ()\n"}, {"source_code": "(* 2:35 *)\nopen Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let seq = Array.init n (fun i -> read_int()) in\n let perm = Array.init n (fun i -> i) in\n\n Array.sort (fun i j -> compare seq.(i) seq.(j)) perm;\n let nseq = Array.make n 0 in\n for i=0 to n-1 do\n nseq.(perm.(i)) <- i\n done;\n\n let next = Array.make n 0 in\n let prev = Array.make n 0 in\n\n for i=0 to n-1 do\n prev.(i) <- i-1;\n next.(i) <- if i = n-1 then -1 else i+1\n done;\n\n let answer = Array.make n 0 in\n\n for i = n-1 downto 1 do\n let togo = nseq.(i) in\n let get k = if k<0 then -1 else perm.(k) in\n answer.(perm.(togo)) <- max (get next.(togo)) (get prev.(togo));\n (* now delete togo from the doubly linked list *)\n let (pj, nj) = (prev.(togo), next.(togo)) in\n if pj >= 0 then next.(pj) <- nj;\n if nj >= 0 then prev.(nj) <- pj;\n done;\n\n for i=1 to n-1 do\n printf \"%d \" seq.(answer.(i))\n done;\n print_newline()\n"}], "negative_code": [{"source_code": "let n = read_int ()\nlet a = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string\n\nmodule IntMap = Map.Make(struct type t = int let compare = compare end)\n\ntype node =\n { level : int;\n up : int option;\n }\n\nlet add_node map value =\n let lefts, _, rights = IntMap.split value map in\n let up, {level} = match IntMap.is_empty lefts, IntMap.is_empty rights with\n | true, true -> value, {level = 0; up = None}\n | false, true -> IntMap.max_binding lefts\n | true, false -> IntMap.min_binding rights\n | false, false ->\n let value_left, left = IntMap.max_binding lefts in\n let value_right, right = IntMap.min_binding rights in\n if right.level > left.level\n then value_left, left\n else value_right, right in\n IntMap.add value { level = level + 1; up = Some up; } map\n\nlet node_map = List.fold_left add_node IntMap.empty a\n\nlet () =\n List.tl a\n |> List.iter (fun x -> let {up = Some y} = IntMap.find x node_map in\n Printf.printf \"%d \" y);\n print_newline ()\n"}], "src_uid": "d2d21871c068e04469047e959dcf0d09"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let s = Array.init n read_int\n and cnt = Array.make 101 0\n and nice = ref 0\n and swap = ref false in\n for i = 0 to n - 1 do\n cnt.(s.(i)) <- cnt.(s.(i)) + 1;\n if cnt.(s.(i)) = 1 then incr nice\n else if cnt.(s.(i)) = 2 then decr nice\n else if cnt.(s.(i)) = 3 then swap := true\n done;\n if !nice mod 2 = 1 && !swap = false then printf \"NO\\n\"\n else begin\n printf \"YES\\n\";\n let move = ref (!nice / 2) in\n if !nice mod 2 = 0 then swap := false;\n for i = 0 to n - 1 do\n if cnt.(s.(i)) = 1 then\n if !move > 0 then begin\n printf \"B\";\n decr move\n end\n else printf \"A\"\n else if cnt.(s.(i)) >= 3 then\n if !swap then begin\n printf \"B\";\n swap := false\n end\n else printf \"A\"\n else printf \"A\"\n done\n end", "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 (+$) = (+) 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\nend open MyInt64\nlet llen l = i64 @@ List.length l\n\nmodule ISet = Set.Make (Int64)\nmodule IMap = Map.Make (Int64)\nlet () =\n\tlet n = get_i64 0 in\n\tlet a = input_i64_array n in\n\tlet f,z = ref false,ref (-1L) in\n\tlet o,n = Array.fold_left (fun (o,n) v ->\n\t\tif IMap.exists (fun u _ -> u = v) n then (\n\t\t\tlet p = (IMap.find v n) + 1L in\n\t\t\t(* printf \" %Ld\\n\" p; *)\n\t\t\tif p >= 3L then (\n\t\t\t\tf := true;z := v\n\t\t\t); (o,IMap.add v p n)\n\t\t) else if ISet.exists ((=) v) o then (ISet.remove v o,\n\t\t\tIMap.add v 2L n\n\t\t) else (ISet.add v o,n) \n\t) (ISet.empty,IMap.empty) a\n\tin\n\t(* printf \"%Ld\\n\" !z; *)\n\tlet w,x = ISet.elements o |> llen, IMap.bindings n |> llen in\n\t(* printf \"%Ld %Ld\\n\" w x; *)\n\tif w mod 2L = 1L && not !f then (\n\t\tprintf \"NO\\n\"\n\t) else if w mod 2L = 0L then (\n\t\tprintf \"YES\\n\";\n\t\tArray.fold_left (fun m v ->\n\t\t\tif IMap.exists (fun u _ -> u = v) n then (printf \"A\"; m)\n\t\t\telse (printf (if m then \"A\" else \"B\"); (not m))\n\t\t) true a\n\t\t|> ignore;\n\t) else (\n\t\tprintf \"YES\\n\";\n\t\tArray.fold_left (fun (m,q) v ->\n\t\t\tif IMap.exists (fun u _ -> u = v) n then (\n\t\t\t\t(* if q then (printf \"B\";(m,false))\n\t\t\t\telse (printf \"A\"; (m,q)) *)\n\t\t\t\t(* printf \"%Ld %Ld\\n\" v !z; *)\n\t\t\t\tif v = !z then (\n\t\t\t\t\tprintf \"B\"; z := -1L; (m,q);\n\t\t\t\t) else (\n\t\t\t\t\tprintf \"A\"; (m,q)\n\t\t\t\t)\n\t\t\t) else (printf (if m then \"A\" else \"B\"); (not m,q))\n\t\t) (true,true) a\n\t\t|> ignore;\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 (+$) = (+) 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\nend open MyInt64\nlet llen l = i64 @@ List.length l\n\nmodule ISet = Set.Make (Int64)\nmodule IMap = Map.Make (Int64)\nlet () =\n\tlet n = get_i64 0 in\n\tlet a = input_i64_array n in\n\tlet f,z = ref false,ref (-1L) in\n\tlet o,n = Array.fold_left (fun (o,n) v ->\n\t\tif IMap.exists (fun u _ -> u = v) n then (\n\t\t\tlet p = (IMap.find v n) + 1L in\n\t\t\tprintf \" %Ld\\n\" p;\n\t\t\tif p >= 3L then (\n\t\t\t\tf := true;z := v\n\t\t\t); (o,IMap.add v p n)\n\t\t) else if ISet.exists ((=) v) o then (ISet.remove v o,\n\t\t\tIMap.add v 2L n\n\t\t) else (ISet.add v o,n) \n\t) (ISet.empty,IMap.empty) a\n\tin\n\t(* printf \"%Ld\\n\" !z; *)\n\tlet w,x = ISet.elements o |> llen, IMap.bindings n |> llen in\n\t(* printf \"%Ld %Ld\\n\" w x; *)\n\tif w mod 2L = 1L && not !f then (\n\t\tprintf \"NO\\n\"\n\t) else if w mod 2L = 0L then (\n\t\tprintf \"YES\\n\";\n\t\tArray.fold_left (fun m v ->\n\t\t\tif IMap.exists (fun u _ -> u = v) n then (printf \"A\"; m)\n\t\t\telse (printf (if m then \"A\" else \"B\"); (not m))\n\t\t) true a\n\t\t|> ignore;\n\t) else (\n\t\tprintf \"YES\\n\";\n\t\tArray.fold_left (fun (m,q) v ->\n\t\t\tif IMap.exists (fun u _ -> u = v) n then (\n\t\t\t\t(* if q then (printf \"B\";(m,false))\n\t\t\t\telse (printf \"A\"; (m,q)) *)\n\t\t\t\t(* printf \"%Ld %Ld\\n\" v !z; *)\n\t\t\t\tif v = !z then (\n\t\t\t\t\tprintf \"B\"; z := -1L; (m,q);\n\t\t\t\t) else (\n\t\t\t\t\tprintf \"A\"; (m,q)\n\t\t\t\t)\n\t\t\t) else (printf (if m then \"A\" else \"B\"); (not m,q))\n\t\t) (true,true) a\n\t\t|> ignore;\n\t)"}, {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\nend open MyInt64\nlet llen l = i64 @@ List.length l\n\nmodule ISet = Set.Make (Int64)\nlet () =\n\tlet n = get_i64 0 in\n\tlet a = input_i64_array n in\n\tlet o,n = Array.fold_left (fun (o,n) v ->\n\t\tif ISet.exists ((=) v) n then (o,n)\n\t\telse if ISet.exists ((=) v) o then (ISet.remove v o, ISet.add v n)\n\t\telse (ISet.add v o,n) \n\t) (ISet.empty,ISet.empty) a\n\tin\n\tif (ISet.elements o |> llen) mod 2L = 1L then (\n\t\tprintf \"NO\\n\"\n\t) else (\n\t\tprintf \"YES\\n\";\n\t\tArray.fold_left (fun m v ->\n\t\t\tif ISet.exists ((=) v) n then (printf \"A\"; m)\n\t\t\telse (printf (if m then \"A\" else \"B\"); (not m))\n\t\t) true a\n\t\t|> ignore;\n\t)"}], "src_uid": "d126ef6b94e9ab55624cf7f2a96c7ed1"} {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\n\tlet dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done\nend open MyInt64\n\nlet n = get_i64 0\nlet nn = \n\tlet r = ref 1L in\n\twhile !r*2L <= n do\n\t\tr *= 2L\n\tdone; !r\nlet f v =\n\tlet r = ref 1L in\n\twhile !r*v <= n do r *= v\n\tdone; !r\nlet () =\n\tif n = 1L then printf \"1\\n\"\n\telse if n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L (!p-1L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tprintf \"%Ld\\n\" ((n / !v) * !v);\n\t\t\t(* print_endline \"\";\n\t\t\tprintf \"%Ld\\n\" nn;\n\t\t\tprintf \"%Ld %Ld %Ld\\n\" ((n/2L)*2L) (f !v) ((n / !v) * !v); *)\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;", "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\nexception Found;;\n\nlet last_big l a =\n let tmp = ref 0 in\n try\n for i = l-1 downto 0 do\n if a.(i) then (tmp := i + 1; raise Found)\n done;\n !tmp\n with Found -> !tmp\n;;\n\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet b = Array.make n true in\nlet div = ref 1 in\nlet continue = ref 0 in\nlet last = ref n in\nwhile !continue != n do\n for j = 1 to n do\n if b.(j-1) && j mod (2 * !div) != 0 then begin\n if j = !last && !continue = n - 2 then begin\n Printf.printf \"%i \" !div;\n incr continue;\n Printf.printf \"%i \" !last;\n end else Printf.printf \"%i \" !div;\n incr continue;\n b.(j-1) <- false;\n if j = !last then last := last_big !last b\n end\n done;\n div := 2 * !div;\ndone;\nprint_newline ()\n"}], "negative_code": [{"source_code": "\nlet 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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet b = Array.make n true in\nlet div = ref 1 in\nlet continue = ref 0 in\nwhile !continue != n do\n for j = 1 to n do\n if b.(j-1) && j mod (2 * !div) != 0 then begin\n b.(j-1) <- false;\n incr continue;\n Printf.printf \"%i \" (if n = 3 && !continue = n then n else !div);\n end\n done;\n div := 2 * !div;\ndone;\nprint_newline ()\n"}, {"source_code": "\nlet 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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet b = Array.make n true in\nlet div = ref 1 in\nlet continue = ref true in\nwhile !continue do\n continue := false;\n for j = 1 to n do\n if b.(j-1) then continue := true;\n if b.(j-1) && j mod (2 * !div) != 0 then begin\n b.(j-1) <- false;\n print_int !div;\n end\n done;\n div := 2 * !div;\ndone;\nprint_newline ()\n"}, {"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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet b = Array.make n true in\nlet div = ref 1 in\nlet continue = ref 0 in\nwhile !continue != n do\n for j = 1 to n do\n if b.(j-1) && j mod (2 * !div) != 0 then begin\n b.(j-1) <- false;\n if j = n && !continue = n - 2 then begin\n Printf.printf \"%i \" !div;\n incr continue;\n Printf.printf \"%i \" n;\n end else Printf.printf \"%i \" !div;\n incr continue;\n end\n done;\n div := 2 * !div;\ndone;\nprint_newline ()\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 (+$) = (+) 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 n = get_i64 0\nlet () =\n\tif n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L (!p-1L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tprintf \"%Ld\\n\" n;\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;\n\n\n(* \nlet n = get_i64 0\nlet mx = i32 n +$ 24\n\nlet prime = Array.make (mx) true\nlet preprocess _ =\n\tprime.(0) <- false;\n\tprime.(1) <- false;\n\trepi 2 mx (fun u ->\n\t\tif prime.(u) then (\n\t\t\trepi (u*$2) mx (fun v ->\n\t\t\t\tprime.(v) <- false;\n\t\t\t\t`Ok\n\t\t\t)\n\t\t);\n\t\t`Ok\n\t)\n\t\nlet () =\n *)\n\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 (+$) = (+) 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 n = get_i64 0\nlet () =\n\tif n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L (!p-1L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tprintf \"%Ld\\n\" ((n/2L)*2L);\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;"}, {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\n\tlet dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done\nend open MyInt64\n\nlet n = get_i64 0\nlet nn = \n\tlet r = ref 1L in\n\twhile !r*2L <= n do\n\t\tr *= 2L\n\tdone; !r\nlet () =\n\tif n = 1L then printf \"1\\n\"\n\telse if n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L (!p-1L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tprintf \"%Ld\\n\" nn;\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;"}, {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\n\tlet dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done\nend open MyInt64\n\nlet n = get_i64 0\nlet () =\n\tif n = 1L then printf \"1\\n\"\n\telse if n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L (!p-1L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tprintf \"%Ld\\n\" ((n/2L)*2L);\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;\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 (+$) = (+) 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 n = get_i64 0\nlet () =\n\tif n = 2L then printf \"1 2\\n\"\n\telse if n = 3L then printf \"1 1 3\\n\"\n\telse\n\tlet p,v = ref n,ref 1L in\n\twhile !p > 0L do\n\t\tif !p >= 4L then (\n\t\t\trep 1L (!p - !p / 2L) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L !p (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L;\n\t\t)\n\t\t(* let c = !p - !p / 2L in\n\t\tif c >= 2L then (\n\t\t\trep 1L (c) (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tv *= 2L;\n\t\t\tp /= 2L;\n\t\t) else (\n\t\t\trep 1L c (fun _ -> printf \"%Ld \" !v; `Ok);\n\t\t\tp := 0L\n\t\t) *)\n\tdone;"}], "src_uid": "cadff0864835854f4f1e0234f2fd3edf"} {"source_code": "let () = Scanf.scanf \"%s\\n\" (fun s ->\n (* characters that can be the middle of a string *)\n let mid = ['A'; 'H'; 'I'; 'M'; 'O'; 'o'; 'T'; 'U'; 'V'; 'v'; 'W'; 'w'; 'X'; 'x'; 'Y']\n (* mirrored pairs *)\n and pairs = ['b', 'd'; 'd', 'b'; 'p', 'q'; 'q', 'p'] in\n\n let n = String.length s in\n\n print_endline (\n if (n mod 2 = 0 || List.mem s.[n / 2] mid) &&\n Array.fold_left (&&) true (Array.init (n / 2) (fun i ->\n (s.[i] = s.[n - i - 1] && List.mem s.[i] mid) ||\n (List.mem_assoc s.[i] pairs && List.assoc s.[i] pairs = s.[n - i - 1])))\n then \"TAK\" else \"NIE\"))\n", "positive_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let res = ref true in\n let sym =\n function\n | 'A' -> 'A'\n | 'b' -> 'd'\n | 'd' -> 'b'\n | 'H' -> 'H'\n | 'I' -> 'I'\n | 'M' -> 'M'\n | 'O' -> 'O'\n | 'o' -> 'o'\n | 'T' -> 'T'\n | 'U' -> 'U'\n | 'V' -> 'V'\n | 'v' -> 'v'\n | 'W' -> 'W'\n | 'w' -> 'w'\n | 'X' -> 'X'\n | 'x' -> 'x'\n | 'Y' -> 'Y'\n | 'p' -> 'q'\n | 'q' -> 'p'\n | _ -> '\\000'\n in\n for i = 0 to (n - 1) / 2 do\n if s.[i] <> sym s.[n - i - 1]\n then res := false\n done;\n if !res\n then Printf.printf \"TAK\\n\"\n else Printf.printf \"NIE\\n\"\n"}], "negative_code": [{"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let res = ref true in\n let sym =\n function\n | 'A' -> 'A'\n | 'b' -> 'd'\n | 'd' -> 'b'\n | 'H' -> 'H'\n | 'I' -> 'I'\n | 'M' -> 'M'\n | 'O' -> 'O'\n | 'o' -> 'o'\n | 'T' -> 'T'\n | 'U' -> 'U'\n | 'V' -> 'V'\n | 'v' -> 'v'\n | 'W' -> 'W'\n | 'w' -> 'w'\n | 'X' -> 'X'\n | 'x' -> 'x'\n | 'Y' -> 'Y'\n | _ -> '\\000'\n in\n for i = 0 to (n - 1) / 2 do\n if s.[i] <> sym s.[n - i - 1]\n then res := false\n done;\n if !res\n then Printf.printf \"TAK\\n\"\n else Printf.printf \"NIE\\n\"\n"}], "src_uid": "bec2349631158b7dbfedcaededf65cc2"} {"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\tlet dump_list f ls = string_of_list f ls |> print_endline\n\tlet dump_array f a = string_of_array f a |> print_endline\nend open Lib\n\nopen I64_infix\nlet undef = -77L\nlet () =\n\tlet tbl = Hashtbl.create ~random:true 10014 in\n\trep 0L 3L (fun t ->\n\t\trep 0L 3L (fun a ->\n\t\t\trep 0L 3L (fun b ->\n\t\t\t\tlet ls = ref (-1L) in\n\t\t\t\trep 0L 3L (fun tt ->\n\t\t\t\t\tif a = t lor tt && b = t land tt then ls := tt\n\t\t\t\t);\n\t\t\t\tif !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls\n\t\t\t\telse Hashtbl.add tbl (t,a,b) undef\n\t\t\t)\n\t\t)\n\t);\n\tlet n = get_i64 0 in\n\tlet a = input_i64_array (n-1L) in\n\tlet b = input_i64_array (n-1L) in\n\tlet t = Array.make (i32 n) 0L in\n\trep 0L 3L (fun t0 ->\n\t\tt.(0) <- t0;\n\t\tlet f = ref true in\n\t\trepf 1L (n-1L) (fun i ->\n\t\t\tlet i = i32 i in\n\t\t\tlet v = Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1))\n\t\t\tin if v = undef then (f := false; `Break)\n\t\t\telse (t.(i) <- v; `Ok)\n\t\t);\n\t\tif !f then (\n\t\t\tprintf \"YES\\n\";\n\t\t\tdump_array Int64.to_string t; exit 0\n\t\t)\n\t);\n\tprintf \"NO\\n\";\n", "positive_code": [{"source_code": "open Printf open Scanf\nmodule Lib = struct\n\tlet i32,i64,ist = Int64.(to_int,of_int,to_string)\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n\tlet labs = Int64.abs\n\tlet (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *= ) r v = r := !r * v\n\tlet (/=) r v = r := !r / v\n\tlet (%=) r v = r := !r % v\n\t(* math *)\n\tlet ceildiv p q = (p+q-1L) / q\n\tlet rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n\tlet lcm m n = m / gcd m n * n \n\tmodule I64_infix = struct\n\t\tlet (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n\t\t\tlet open Int64 in\n\t\t\t(logand),(logor),(logxor),lognot,\n\t\t\t(fun u v -> shift_left u (i32 v)),\n\t\t\t(fun u v -> shift_right u (i32 v)),\n\t\t\t(fun u v -> shift_right_logical u (i32 v))\n\tend\n\t(* io *)\n\tlet input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet 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\t(* utils *)\n\tlet alen a = i64 @@ Array.length a\n\tlet llen l = i64 @@ List.length l\n\tlet string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n\tlet string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n\tlet 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\tlet string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\t(* imperative *)\n\tlet rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done\n\tlet repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done\n\tlet repm f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + 1L done; !m\n\tlet repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done\n\tlet repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do\n\t\tmatch fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done\n\tlet repim f t m0 fbod =\n\t\tlet i,c,m = ref f,ref true,ref m0 in\n\t\twhile !i<=t && !c do match fbod !m !i with\n\t\t| `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ 1 done; !m\n\t(* debug *)\n\tlet dump_list f ls = string_of_list f ls |> print_endline\n\tlet dump_array f a = string_of_array f a |> print_endline\nend open Lib\n\nopen I64_infix\nlet () =\n\tlet tbl = Hashtbl.create ~random:true 10014 in\n\trep 0L 3L (fun t ->\n\t\trep 0L 3L (fun a ->\n\t\t\trep 0L 3L (fun b ->\n\t\t\t\tlet ls = ref (-1L) in\n\t\t\t\trep 0L 3L (fun tt ->\n\t\t\t\t\tif a = t lor tt && b = t land tt then ls := tt\n\t\t\t\t);\n\t\t\t\tif !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls\n\t\t\t\t\n\t\t\t)\n\t\t)\n\t);\n\tlet n = get_i64 0 in\n\tlet a = input_i64_array (n-1L) in\n\tlet b = input_i64_array (n-1L) in\n\tlet t = Array.make (i32 n) 0L in\n\trep 0L 3L (fun t0 ->\n\t\tt.(0) <- t0;\n\t\tlet f = ref true in\n\t\trepf 1L (n-1L) (fun i ->\n\t\t\tlet i = i32 i in\n\t\t\ttry\n\t\t\t\tt.(i) <- Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1));\n\t\t\t\t`Ok\n\t\t\twith | Not_found -> (\n\t\t\t\tf := false; `Break\n\t\t\t)\n\t\t);\n\t\tif !f then (\n\t\t\tprintf \"YES\\n\";\n\t\t\tdump_array Int64.to_string t; exit 0\n\t\t)\n\t);\n\tprintf \"NO\\n\";\n"}, {"source_code": "let rec read_int_seq n stream = \n\tif n = 1 then Scanf.bscanf stream \"%i\" (fun x -> [x]) \n\telse Scanf.bscanf stream \"%i \" (fun x -> x::(read_int_seq (n - 1) stream))\n;;\n\nlet rec into_bits nums = \n\tmatch nums with\n\t| h::t -> (h / 2, h mod 2)::(into_bits t)\n\t| [] -> []\n;;\n\nlet append_to_option head tail =\n\tmatch tail with\n\t| Some t -> Some (head::t)\n\t| None -> None\n;;\n\nlet either f g =\n\tmatch f () with\n\t| Some a -> Some a\n\t| None -> match g () with\n\t\t| Some a -> Some a\n\t\t| None -> None\n;;\n\nlet unwrap op =\n\tmatch op with\n\t| Some a -> a\n\t| None -> failwith \"no value in option\"\n;;\n\nlet contradict_barrier want_to_place hint x =\n\tmatch hint with\n\t| Some a when a = want_to_place -> x\n\t| None -> x\n\t| _ -> None\n;;\n\nlet rec solve nums_a nums_b current_hint_l current_hint_r =\n\tlet infer_l a_bit b_bit a_tail b_tail =\n\t\tlet infer_r l_res next_hint_l =\n\t\t\tmatch (snd a_bit, snd b_bit, current_hint_r) with\n\t\t\t| (0, 0, _) -> contradict_barrier 0 current_hint_r (append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0)))\n\t\t\t| (1, 1, _) -> contradict_barrier 1 current_hint_r (append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1)))\n\t\t\t| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))\n\t\t\t| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))\n\t\t\t| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))\n\t\t\t| (0, 1, _) -> None\n\t\t\t| _ -> failwith \"corrupt data\"\n\t\tin\n\t\tmatch (fst a_bit, fst b_bit, current_hint_l) with\n\t\t| (0, 0, _) -> contradict_barrier 0 current_hint_l (infer_r 0 (Some 0))\n\t\t| (1, 1, _) -> contradict_barrier 1 current_hint_l (infer_r 1 (Some 1))\n\t\t| (1, 0, Some 0) -> infer_r 0 (Some 1)\n\t\t| (1, 0, Some 1) -> infer_r 1 (Some 0)\n\t\t| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))\n\t\t| (0, 1, _) -> None\n\t\t| _ -> failwith \"corrupt data\"\n\tin \n\tmatch (nums_a, nums_b) with\n\t| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2\n\t| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]\n;;\n\nlet n = read_int();;\nlet input_len = n - 1;;\nlet nums_a = read_line();;\nlet nums_b = read_line();;\nlet nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;\nlet nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;\nlet nums_a = into_bits nums_a;;\nlet nums_b = into_bits nums_b;;\n\nlet solution = solve nums_a nums_b None None;;\nmatch solution with\n\t| Some solution -> (Printf.printf \"YES\\n\"; List.iter (fun (x, y) -> Printf.printf \"%i \" (2*x + y)) solution)\n\t| None -> Printf.printf \"NO\\n\"\n;;"}], "negative_code": [{"source_code": "let rec read_int_seq n stream = \n\tif n = 1 then Scanf.bscanf stream \"%i\" (fun x -> [x]) \n\telse Scanf.bscanf stream \"%i \" (fun x -> x::(read_int_seq (n - 1) stream))\n;;\n\nlet rec into_bits nums = \n\tmatch nums with\n\t| h::t -> (h / 2, h mod 2)::(into_bits t)\n\t| [] -> []\n;;\n\nlet append_to_option head tail =\n\tmatch tail with\n\t| Some t -> Some (head::t)\n\t| None -> None\n;;\n\nlet either f g =\n\tmatch f () with\n\t| Some a -> Some a\n\t| None -> match g () with\n\t\t| Some a -> Some a\n\t\t| None -> None\n;;\n\nlet unwrap op =\n\tmatch op with\n\t| Some a -> a\n\t| None -> failwith \"no value in option\"\n;;\n\nlet rec solve nums_a nums_b current_hint_l current_hint_r =\n\tlet infer_l a_bit b_bit a_tail b_tail =\n\t\tlet infer_r l_res next_hint_l =\n\t\t\tmatch (snd a_bit, snd b_bit, current_hint_r) with\n\t\t\t| (0, 0, _) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0))\n\t\t\t| (1, 1, _) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1))\n\t\t\t| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))\n\t\t\t| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))\n\t\t\t| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))\n\t\t\t| (0, 1, _) -> None\n\t\t\t| _ -> failwith \"corrupt data\"\n\t\tin\n\t\tmatch (fst a_bit, fst b_bit, current_hint_l) with\n\t\t| (0, 0, _) -> infer_r 0 (Some 0)\n\t\t| (1, 1, _) -> infer_r 1 (Some 1)\n\t\t| (1, 0, Some 0) -> infer_r 0 (Some 1)\n\t\t| (1, 0, Some 1) -> infer_r 1 (Some 0)\n\t\t| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))\n\t\t| (0, 1, _) -> None\n\t\t| _ -> failwith \"corrupt data\"\n\tin \n\tmatch (nums_a, nums_b) with\n\t| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2\n\t| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]\n;;\n\nlet n = read_int();;\nlet input_len = n - 1;;\nlet nums_a = read_line();;\nlet nums_b = read_line();;\nlet nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;\nlet nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;\nlet nums_a = into_bits nums_a;;\nlet nums_b = into_bits nums_b;;\n\nlet solution = solve nums_a nums_b None None;;\nmatch solution with\n\t| Some solution -> (Printf.printf \"YES\\n\"; List.iter (fun (x, y) -> Printf.printf \"%i \" (2*x + y)) solution)\n\t| None -> Printf.printf \"NO\\n\"\n;;"}], "src_uid": "ac21483a33e7bcb031b1f8f62e39d60f"} {"source_code": "let n = read_int () in\nlet g = ref 1 in\nlet l = ref '2' in\nfor i = 1 to n do\n match read_line () with\n \"01\" -> if !l = '0' then g := !g + 1; l := '1'\n | \"10\" -> if !l = '1' then g := !g + 1; l := '0'\ndone ;\nprint_int !g ; print_newline () ;;\n", "positive_code": [{"source_code": "let solve () = \n let n = Pervasives.read_int () in\n let rec loop i last count = \n if i <= n\n then\n let current = Pervasives.read_line () in\n if String.compare current last = 0\n then\n loop (i + 1) last count\n else\n loop (i + 1) current (count + 1)\n else\n count\n in loop 2 (Pervasives.read_line ()) 1\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}, {"source_code": "let n = int_of_string (read_line ()) in\nlet g = Array.init n (fun i -> int_of_string (read_line ())) |> Array.to_list in\nprint_int (List.fold_left (fun (b,c) a -> (a, c + if a != b then 1 else 0)) (List.hd g, 1) (List.tl g) |> snd)\n\n"}], "negative_code": [], "src_uid": "6c52df7ea24671102e4c0eee19dc6bba"} {"source_code": "type state =\n | Start\n | Word of Buffer.t\n | Mark\n\nlet _ =\n let s = input_line stdin in\n let s = s ^ \" \" in\n let n = String.length s in\n let state = ref Start in\n for i = 0 to n - 1 do\n let c = s.[i] in\n\tmatch c with\n\t | 'a'..'z' -> (\n\t match !state with\n\t\t| Start ->\n\t\t let b = Buffer.create 10 in\n\t\t Buffer.add_char b c;\n\t\t state := Word b\n\t\t| Word b ->\n\t\t Buffer.add_char b c\n\t\t| Mark ->\n\t\t output_char stdout ' ';\n\t\t let b = Buffer.create 10 in\n\t\t Buffer.add_char b c;\n\t\t state := Word b\n\t )\n\t | '.' | ',' | '!' | '?' -> (\n\t match !state with\n\t\t| Start ->\n\t\t output_char stdout c;\n\t\t state := Mark\n\t\t| Word b ->\n\t\t output_string stdout (Buffer.contents b);\n\t\t output_char stdout c;\n\t\t state := Mark;\n\t\t| Mark ->\n\t\t output_char stdout c;\n\t )\n\t | ' ' -> (\n\t match !state with\n\t\t| Start -> ()\n\t\t| Word b ->\n\t\t output_string stdout (Buffer.contents b);\n\t\t state := Mark\n\t\t| Mark -> ()\n\t )\n\t | _ -> assert false\n done\n", "positive_code": [{"source_code": "type state =\n | Start\n | Word of Buffer.t\n | Mark\n\nlet _ =\n let s = input_line stdin in\n let s = s ^ \" \" in\n let n = String.length s in\n let state = ref Start in\n for i = 0 to n - 1 do\n let c = s.[i] in\n\tmatch c with\n\t | 'a'..'z' -> (\n\t match !state with\n\t\t| Start ->\n\t\t let b = Buffer.create 10 in\n\t\t Buffer.add_char b c;\n\t\t state := Word b\n\t\t| Word b ->\n\t\t Buffer.add_char b c\n\t\t| Mark ->\n\t\t output_char stdout ' ';\n\t\t let b = Buffer.create 10 in\n\t\t Buffer.add_char b c;\n\t\t state := Word b\n\t )\n\t | '.' | ',' | '!' | '?' -> (\n\t match !state with\n\t\t| Start ->\n\t\t output_char stdout c;\n\t\t state := Mark\n\t\t| Word b ->\n\t\t output_string stdout (Buffer.contents b);\n\t\t output_char stdout c;\n\t\t state := Mark;\n\t\t| Mark ->\n\t\t output_char stdout c;\n\t )\n\t | ' ' -> (\n\t match !state with\n\t\t| Start -> ()\n\t\t| Word b ->\n\t\t output_string stdout (Buffer.contents b);\n\t\t state := Mark\n\t\t| Mark -> ()\n\t )\n\t | _ -> assert false\n done\n"}], "negative_code": [], "src_uid": "8c26daa1eed2078af3b32737da0a0f84"} {"source_code": "let id x = x\n\nlet div_of_rating rating =\n let ns =\n match rating with\n | r when r <= 1399 -> \"4\"\n | r when r <= 1599 -> \"3\"\n | r when r <= 1899 -> \"2\"\n | _ -> \"1\"\n in\n \"Division \" ^ ns\n\nlet solve () =\n let t = Scanf.scanf \"%d\\n\" id in\n let () =\n for i = 1 to t do\n let r = Scanf.scanf \"%d\\n\" (fun x -> x) in\n print_endline (div_of_rating r)\n done\n in\n ()\n\nlet main = solve ()\n", "positive_code": [{"source_code": "let getInt () = Scanf.scanf \" %d\" (fun i -> i);;\r\nlet f((x: int)) = \r\nif x >= 1900 then 1\r\nelse if x >= 1600 then 2\r\nelse if x >= 1400 then 3\r\nelse 4;;\r\n\r\nlet main() = \r\n let t = getInt() in\r\n for i = 1 to t do \r\n let x = getInt() in print_endline(\"Division \" ^ string_of_int(f(x)))\r\n done;;\r\n\r\nmain();;\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "020c7b64688736ecc5e97d17df2c2605"} {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let read _ = Scanf.scanf \"%d%_c\" (fun x -> x) in\n\n let a1 = Array.init (n - 1) read\n and a2 = Array.init (n - 1) read\n and b = Array.init n read in\n\n (* calculate cumulative sum of a1\n * and reverse cumulative sum of a2 *)\n let s1 = Array.of_list (List.rev (Array.fold_left (fun (hd::_ as acc) x -> (x + hd) :: acc) [0] a1))\n and s2 = Array.of_list (Array.fold_right (fun x (hd::_ as acc) -> (x + hd) :: acc) a2 [0]) in\n\n let best = ref (-1) in\n\n (* first crossing *)\n for i = 0 to n - 2 do\n (* second crossing *)\n for j = i + 1 to n - 1 do\n let sum = s1.(i) + s2.(j) + s1.(j) + s2.(i) + b.(i) + b.(j) in\n if !best = (-1) || sum < !best\n then best := sum\n done\n done;\n\n Printf.printf \"%d\\n\" !best)\n", "positive_code": [{"source_code": "let a = ref [] in\nlet b = ref [] in\nlet c = ref [] in\nlet n = read_int () in\n\t(let l = Scanf.Scanning.from_string (read_line ()) in\n\tfor j = 1 to n-1 do\n\t\ttry let k = Scanf.bscanf l \"%d \" (fun x -> x) in a := k::(!a) with _ -> \n\t\tlet k = Scanf.bscanf l \"%d\" (fun x -> x) in a := k::(!a)\n\tdone);\n\t(let l = Scanf.Scanning.from_string (read_line ()) in\n\tfor j = 1 to n-1 do\n\t\ttry let k = Scanf.bscanf l \"%d \" (fun x -> x) in b := k::(!b) with _ ->\n\t\tlet k = Scanf.bscanf l \"%d\" (fun x -> x) in b := k::(!b)\n\tdone);\n\t(let l = Scanf.Scanning.from_string (read_line ()) in\n\tfor j = 1 to n do\n\t\ttry let k = Scanf.bscanf l \"%d \" (fun x -> x) in c := k::(!c) with _ ->\n\t\tlet k = Scanf.bscanf l \"%d\" (fun x -> x) in c := k::(!c)\n\tdone);\n\nlet al = List.rev (!a) in\nlet bl = List.rev (!b) in\nlet cl = List.rev (!c) in\n\nlet rec trav i where st =\n\tmatch where with\n\t\ttrue ->\n\t\t\tlet k2 = trav i false (2::st) in\n\t\t\tif i = n-1 then ((fst k2) + List.nth cl i, snd k2)\n\t\t\telse\n\t\t\t\tlet k1 = trav (i+1) true (0::st) in\n\t\t\t\tlet i2 = List.nth cl i in\t\n\t\t\t\tlet t = min (fst k1 + List.nth al i) (fst k2 + i2) in\n\t\t\t\tif t = (i2 + fst k2) then (t, snd k2) \n\t\t\t\telse (t, snd k1)\n\t\t| false -> \n\t\t\tif i = n-1 then (0, st)\n\t\t\telse let k2 = trav (i+1) false (1::st) in\n\t\t\t(fst k2 + (List.nth bl i), snd k2)\n\tin\t\t\t\nlet (stv, stl) = trav 0 true [] in\nlet st = List.rev stl in\n\nlet rec trav2 i where ed w =\n\tmatch where with\n\t\tfalse ->\n\t\t\tlet k2 = trav2 i true (2::ed) 2 in\n\t\t\tif i = 0 then ((fst k2) + List.nth cl i, snd k2)\n\t\t\telse\n\t\t\t\tlet k1 = trav2 (i-1) false (1::ed) 1 in\n\t\t\t\tlet i2 = List.nth cl i in\t\n\t\t\t\tlet t = min (fst k1 + List.nth bl (i-1)) (fst k2 + i2) in\n\t\t\t\tif t = (i2 + fst k2) then (t, snd k2) \n\t\t\t\telse (t, snd k1)\n\t\t| true -> \n\t\t\tif i = 0 then\n\t\t\t\t(let bb = ed <> st in\n\t\t\t\tif bb then (0, ed) else (99999999, ed))\n\t\t\telse let k2 = trav2 (i-1) true (0::ed) 0 in\n\t\t\t(fst k2 + (List.nth al (i-1)), snd k2)\n\tin\nlet (edv, edl) = trav2 (n-1) false [] 2 in\n\nprint_int (stv + edv);;\n"}, {"source_code": "let n= read_int () and ans = ref max_int;;\nlet a= Array.append\n\t[|( Array.of_list (List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()))))|]\n [|( Array.of_list (List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()))))|];;\nlet b= Array.of_list (List.map(int_of_string) (Str.split (Str.regexp \" \") (read_line ())));;\nlet f1= Array.create n 0 and f2= Array.create n 0;;\nfor i= 1 to n - 1 do Array.set f1 i (f1.(i - 1) + a.(1).(i - 1)) done;;\nfor i= n - 2 downto 0 do Array.set f2 i (f2.(i + 1) + a.(0).(i)) done;;\nfor i= 0 to n - 1 do for j= 0 to n - 1 do if i <> j then\n\tans:= min !ans (f1.(i) + b.(i) + f2.(i) + f2.(j) + f1.(j) + b.(j))\ndone done;;\nprint_int !ans;;\n"}], "negative_code": [], "src_uid": "e3e0625914fdc08950601248b1278f7d"} {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 4 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n", "positive_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 4 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h &&\n\t\t\t (x' - x) * (x' - x) + (y' - y) * (y' - y) <= d * d\n\t\t\t then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && float_of_int !s *. 6.5 < float_of_int !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 4 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}], "negative_code": [{"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 4 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 4 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && float_of_int !s *. 3.5 < float_of_int !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\tlet mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 3 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 3 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\tlet mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 3 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 3 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\tlet mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)\n\t in\n\t let ps = ref [] in\n\t let d = 5 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 3 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w false in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif not used.(i).(j) then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif not used.(y).(x) then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- true;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- true;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 6 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if a.(y').(x') <> 0\n\t\t\t then incr s;\n\t\t\t if a.(y').(x') <> 0 && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let sqr x = x *. x in\n let h = getnum () in\n let w = getnum () in\n let a = Array.make_matrix h w 0 in\n let () =\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\ta.(i).(j) <- getnum ()\n done\n done\n in\n let cand = Array.make_matrix h w false in\n let res = ref 0 in\n let rays = ref [] in\n let used = Array.make_matrix h w 0 in\n let stack = Array.make (h * w) (0, 0) in\n let pos = ref 0 in\n let idx = ref 0 in\n (*let a' = Array.make_matrix n n 0 in\n for i = 0 to n - 1 do\n for j = 0 to n - 1 do\n\tlet b = ref 0 in\n\t for i' = -f to f do\n\t for j' = -f to f do\n\t let x = j + j'\n\t and y = i + i' in\n\t\tif x >= 0 && y >= 0 && x < n && y < n\n\t\tthen b := !b + a.(y).(x)\n\t done\n\t done;\n\t if float_of_int !b > float_of_int ((2 * f + 1) * (2 * f + 1)) *. 0.4\n\t then a'.(i).(j) <- 1\n done\n done;\n for i = 0 to n - 1 do\n a.(i) <- a'.(i)\n done;*)\n for i = 0 to h - 1 do\n for j = 0 to w - 1 do\n\tif used.(i).(j) = 0 then (\n\t if a.(i).(j) <> 0 then (\n\t let d = [| (1, 0); (0, 1); (-1, 0); (0, -1) |] in\n\t let border = ref [] in\n\t let mx = ref 0 in\n\t let my = ref 0 in\n\t let cnt = ref 0 in\n\t let rec dfs () =\n\t if !pos > 0 then (\n\t\tdecr pos;\n\t\tlet (x, y) = stack.(!pos) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t incr cnt;\n\t\t for i = 0 to 3 do\n\t\t let (dx, dy) = d.(i) in\n\t\t let x = x + dx\n\t\t and y = y + dy in\n\t\t if x >= 0 && y >= 0 && x < w && y < h &&\n\t\t\ta.(y).(x) > 0\n\t\t then (\n\t\t\tif used.(y).(x) = 0 then (\n\t\t\t stack.(!pos) <- (x, y);\n\t\t\t incr pos;\n\t\t\t used.(y).(x) <- !idx;\n\t\t\t)\n\t\t ) else (\n\t\t\tborder := (x, y) :: !border\n\t\t )\n\t\t done;\n\t\t dfs ()\n\t )\n\t in\n\t incr idx;\n\t pos := 0;\n\t stack.(!pos) <- (j, i);\n\t incr pos;\n\t used.(i).(j) <- !idx;\n\t dfs ();\n\t let border = Array.of_list !border in\n\t let l = Array.length border in\n\t let (mx, my) =\n\t\t(*let mx = ref 0 in\n\t\tlet my = ref 0 in\n\t\t for i = 0 to l - 1 do\n\t\t let (x, y) = border.(i) in\n\t\t mx := !mx + x;\n\t\t my := !my + y;\n\t\t done;\n\t\t (float_of_int !mx /. float_of_int l,\n\t\t float_of_int !my /. float_of_int l)*)\n\t\t(float_of_int !mx /. float_of_int !cnt,\n\t\t float_of_int !my /. float_of_int !cnt)\n\t in\n\t let ps = ref [] in\n\t let d = 6 in\n\t let () =\n\t\tArray.iter\n\t\t (fun (x, y) ->\n\t\t let b = ref true in\n\t\t let dist = \n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t in\n\t\t let s = ref 0 in\n\t\t let t = ref 0 in\n\t\t for y' = y - d to y + d do\n\t\t\t for x' = x - d to x + d do\n\t\t\t incr t;\n\t\t\t if x' >= 0 && y' >= 0 && x' < w && y' < h then (\n\t\t\t let dist' = \n\t\t\t let x = float_of_int x'\n\t\t\t and y = float_of_int y' in\n\t\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t\t in\n\t\t\t if cand.(y').(x')\n\t\t\t then b := false;\n\t\t\t if used.(y').(x') = !idx\n\t\t\t then incr s;\n\t\t\t if used.(y').(x') = !idx && dist' > dist\n\t\t\t then b := false;\n\t\t\t )\n\t\t\t done\n\t\t done;\n\t\t if !b && !s * 4 < !t then (\n\t\t\t cand.(y).(x) <- true;\n\t\t\t ps := (x, y) :: !ps;\n\t\t\t (*Printf.printf \"asd %d %d %d %d\\n\" x y !s !t;*)\n\t\t )\n\t\t ) border\n\t in\n\t\trays := (List.length !ps) :: !rays;\n\t\tincr res;\n\t\t(*let d =\n\t\t Array.map\n\t\t (fun (x, y) ->\n\t\t let x = float_of_int x\n\t\t and y = float_of_int y in\n\t\t\t sqrt (sqr (x -. mx) +. sqr (y -. my))\n\t\t ) border\n\t\tin\n\t\tlet r =\n\t\t let r = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t r := !r +. d.(i)\n\t\t done;\n\t\t !r /. float_of_int l\n\t\tin\n\t\tlet sr =\n\t\t let sr = ref 0.0 in\n\t\t for i = 0 to l - 1 do\n\t\t sr := !sr +. sqr (d.(i) -. r)\n\t\t done;\n\t\t !sr /. float_of_int l\n\t\tin\n\t\t if sr /. r < 0.03\n\t\t then incr resc\n\t\t else incr ress;\n\t\t (*Printf.printf \"asd %f %f %f %f\\t%f %d\\n\"\n\t\t mx my r sr (sr /. r) l*)\n\t\t*)\n\t )\n\t)\n done\n done;\n let rays = List.sort compare !rays in\n Printf.printf \"%d\\n\" !res;\n List.iter (Printf.printf \"%d \") rays;\n Printf.printf \"\\n\"\n\n \n"}], "src_uid": "71f9a86f8af6a99ba010d5c55f74d63a"} {"source_code": "let () =\n let n = read_int () in\n let h = Hashtbl.create n in\n for i = 1 to n do\n let s = read_line () in\n let x = try Hashtbl.find h s with _ -> 0 in\n Hashtbl.replace h s (x+1);\n if x = 0 then\n print_endline \"OK\"\n else\n Printf.printf \"%s%d\\n\" s x\n done\n", "positive_code": [{"source_code": "let n = read_int ();; let users = Hashtbl.create 1000;; for i = 1 to n do let name = read_line () in if Hashtbl.mem users name then begin let _ = print_endline (name ^ (string_of_int (Hashtbl.find users name +1)) ^ \"\\n\") in Hashtbl.replace users name (Hashtbl.find users name+1) end else begin let _ = print_string \"OK\\n\" in Hashtbl.add users name 0 end done; "}, {"source_code": "open Printf\nopen String\n\nmodule type DICTIONARY =\nsig\n type key = string\n type 'a dict\n exception NotFound\n\n val make : unit -> 'a dict\n val insert : 'a dict -> key -> 'a -> 'a dict\n val lookup : 'a dict -> key -> 'a\n val map : ('a -> 'b) -> 'a dict -> 'b dict\nend\n\n(* implemented with association list *)\nmodule AssocList : DICTIONARY =\nstruct\n type key = string\n type 'a dict = (key * 'a) list\n exception NotFound\n \n let make () : 'a dict = []\n let insert (d : 'a dict) (k : key) (x : 'a) : 'a dict = (k, x) :: d\n let rec lookup (d : 'a dict) (k : key) : 'a =\n match d with\n | [] -> raise NotFound\n | (k', x) :: rest ->\n if k = k' then x\n else lookup rest k\n let map (f : 'a -> 'b) (d : 'a dict) =\n List.map (fun (k, a) -> (k, f a)) d\nend\n\n(* implemented with higher-order function *)\nmodule FunctionDict : DICTIONARY =\nstruct\n type key = string\n type 'a dict = string -> 'a\n exception NotFound\n \n let make () = fun _ -> raise NotFound\n let lookup (d : 'a dict) (key : string) : 'a = d key\n let insert (d : 'a dict) (k : key) (x : 'a) : 'a dict = \n fun k' -> if k = k' then x else d k'\n let map (f : 'a -> 'b) (d : 'a dict) = fun k -> f (d k)\nend \n\n(* a better association list verion *)\nmodule SortedAssocList : DICTIONARY =\nstruct\n type key = string\n type 'a dict = (key * 'a) list\n exception NotFound\n \n let make() : 'a dict = []\n let rec insert (d : 'a dict) (k : key) (x : 'a) : 'a dict =\n match d with\n | [] -> (k, x) :: []\n | (k', x') :: rest ->\n match String.compare k k' with\n 1 -> (k', x') :: (insert rest k x)\n | 0 -> (k, x) :: rest\n | -1 -> (k, x) :: (k', x') :: rest\n | _ -> failwith \"Impossible\"\n\n let rec lookup (d : 'a dict) (k : key) : 'a =\n match d with\n [] -> raise NotFound\n | (k', x) :: rest ->\n match String.compare k k' with\n 0 -> x\n | -1 -> raise NotFound\n | 1 -> lookup rest k\n | _ -> failwith \"Impossible\"\n\n let map (f : 'a -> 'b) (d : 'a dict) =\n List.map (fun (k,a) -> (k, f a)) d\nend\n\n(* implemented with binary tree, logn loopup *)\nmodule AssocTree : DICTIONARY =\nstruct\n type key = string\n type 'a dict = Empty | Node of key * 'a * 'a dict * 'a dict\n exception NotFound\n\n\n let make() : 'a dict = Empty\n\n let rec insert (d : 'a dict) (k : key) (x : 'a) : 'a dict =\n match d with\n Empty -> Node (k, x, Empty, Empty)\n | Node (k', x', l, r) ->\n match String.compare k k' with\n 0 -> Node(k, x, l, r)\n | -1 -> Node(k', x', insert l k x, r)\n | 1 -> Node(k', x', l, insert r k x)\n | _ -> failwith \"Impossible\"\n\n let rec lookup (d : 'a dict) (k : key) : 'a =\n match d with\n Empty -> raise NotFound\n | Node(k', x, l, r) ->\n match String.compare k k' with\n 0 -> x\n | -1 -> lookup l k\n | 1 -> lookup r k\n | _ -> failwith \"Impossible\"\n\n let rec map (f : 'a -> 'b) (d : 'a dict) =\n match d with\n Empty -> Empty\n | Node (k, x, l, r) -> Node (k, f x, map f l, map f r)\nend\n\nlet tree = AssocTree.make ()\n \nlet n = Scanf.scanf \"%d \" (fun x -> x)\n\nlet myprint s i =\n let t = s^(string_of_int i) in\n printf \"%s\\n\" t\n\nlet rec loop tr ii =\n if ii = 0 then\n ()\n else\n begin\n let open AssocTree in\n let s = Scanf.scanf \"%s \" (fun x -> x) in\n try\n let x = lookup tr s in\n myprint s (x+1); loop (insert tr s (x+1)) (ii-1) \n with\n NotFound -> printf \"OK\\n\"; loop (insert tr s 0) (ii-1)\n end \n \n let () = loop tree n\n \n"}, {"source_code": "let solve n =\n let tbl = Hashtbl.create 100000 in\n for i = 1 to n do\n let query = Scanf.scanf \" %s\" (fun x -> x) in\n if Hashtbl.mem tbl query\n then\n begin\n\tlet v = Hashtbl.find tbl query in\n\tHashtbl.add tbl query (v+1);\t\n\tPrintf.printf \"%s%d\\n\" query v;\n end\n else\n begin\n\tHashtbl.add tbl query 1;\n\tPrintf.printf \"OK\\n\";\n end\n done\n\nlet _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n solve n\n \n\n"}, {"source_code": "let acceptable = \"OK\\n\"\n\nlet processName name table =\n if Hashtbl.mem table name\n then let currFreeNum = Hashtbl.find table name in\n begin\n Hashtbl.replace table name (currFreeNum + 1);\n Printf.sprintf \"%s%d\\n\" name currFreeNum\n end\n else \n begin\n Hashtbl.add table name 1;\n acceptable\n end\n\nlet () =\n let numNames = Scanf.sscanf (read_line ()) \"%d\" (fun x -> x) in\n let table = Hashtbl.create numNames in\n for i = 1 to numNames do\n let currName = read_line () in\n print_string (processName currName table)\n done\n"}, {"source_code": "let num = read_int () in\n let hbl = Hashtbl.create (num / 8) in\n for tot = 1 to num do\n let uc = read_line () in\n let i = try Hashtbl.find hbl uc with Not_found -> 0 in\n if i <> 0 then (print_string uc; print_int i; print_newline ()) else (print_endline \"OK\");\n Hashtbl.replace hbl uc (i + 1)\n done\n \n "}, {"source_code": "open Hashtbl;;\n\nlet regs = read_int ();;\n\nlet users = Hashtbl.create 0;;\n\nfor i = 1 to regs do\n\tlet name = read_line () in\n\tif Hashtbl.mem users name then begin\n\t\tlet x = Hashtbl.find users name + 1 in\n\t\tlet _ = print_string (name ^ (string_of_int x) ^ \"\\n\") in\n\t\tHashtbl.replace users name x\n\t\t\n\tend else begin\n\t\tHashtbl.add users name 0;\n\t\tprint_string \"OK\\n\"\n\tend\ndone;\n"}], "negative_code": [], "src_uid": "24098df9c12d9704391949c9ff529c98"} {"source_code": "(* Petya and Construction Set\n * https://codeforces.com/contest/1214/problem/E *)\n\nlet ans =\n let n = read_int() in\n let ds = read_line()\n |> Str.split_delim (Str.regexp \" \")\n |> List.map int_of_string in\n let prs = Array.make n (0, 0) in\n List.iteri (fun i k -> prs.(i) <- (k, i)) ds;\n Array.fast_sort (fun x y -> - (compare x y)) prs;\n let par = Array.make (n * 2 + 1) 0 in\n let lst = Array.make (n * 2) 0 in\n Array.iteri (fun i (_,k) -> lst.(i) <- 2 * k + 1) prs;\n let cur = ref n in\n let rec iter i cur =\n if i = n then cur\n else\n let (d, k) = prs.(i) in\n let ncur =\n if d + i = cur then\n (lst.(cur) <- 2*k+2;\n cur + 1)\n else (par.(2*k+2) <- lst.(d + i - 1);\n cur) in\n iter (i+1) ncur in\n let cur = iter 0 n in\n (* Array.iteri (fun i (d,k) ->\n * if d + i = !cur then\n * (lst.(!cur) <- 2*k+2;\n * cur := !cur + 1)\n * else\n * par.(2*k+2) <- lst.(d + i - 1)\n * ) prs; *)\n for i = 1 to cur - 1 do\n par.(lst.(i)) <- lst.(i-1)\n done;\n Array.iteri\n (fun i j -> if j = 0 then () else Printf.printf \"%d %d\\n\" i j) par\n", "positive_code": [{"source_code": "(* let iteri_if action cond seq =\n * let rec go i seq = \n * match seq with\n * | Seq.Nil -> ()\n * | Seq.Cons (x, rest) -> (if cond i x then action i x else ()) ; go (i + 1) (rest ())\n * in go 0 seq *)\n\nlet arr_iteri_if action cond arr =\n let rec go i =\n match i with\n | k when k = Array.length arr -> ()\n | _ -> (if cond i arr.(i) then action i arr.(i) else ()) ; go (i + 1) \n in go 0\n\nlet ans =\n let n = read_int() in\n let s = read_line() in\n let words = Str.split_delim (Str.regexp \" \") s in\n let ds = List.map int_of_string words in\n let prs = Array.make n (0, 0) in\n List.iteri (fun i k -> prs.(i) <- (k, i)) ds;\n Array.fast_sort (fun x y -> - (compare x y)) prs;\n let par = Array.make (n * 2 + 1) 0 in\n let lst = Array.make (n * 2) 0 in\n Array.iteri (fun i (_,k) -> lst.(i) <- 2 * k + 1) prs;\n let cur = ref n in\n Array.iteri (fun i (d,k) ->\n if d + i = !cur then\n (lst.(!cur) <- 2*k+2;\n cur := !cur + 1)\n else\n par.(2*k+2) <- lst.(d + i - 1)\n ) prs;\n for i = 1 to !cur-1 do\n par.(lst.(i)) <- lst.(i-1)\n done;\n arr_iteri_if (fun i j -> Printf.printf \"%d %d\\n\" i j)\n (fun i j -> j <> 0) par\n"}, {"source_code": "let ans =\n let n = read_int() in\n let s = read_line() in\n let words = Str.split_delim (Str.regexp \" \") s in\n let ds = List.map int_of_string words in\n let prs = Array.make n (0, 0) in\n List.iteri (fun i k -> prs.(i) <- (k, i)) ds;\n Array.fast_sort (fun x y -> - (compare x y)) prs;\n let par = Array.make (n * 2 + 1) 0 in\n let lst = Array.make (n * 2) 0 in\n Array.iteri (fun i (_,k) -> lst.(i) <- 2 * k + 1) prs;\n let cur = ref n in\n for i = 0 to n-1 do\n let (d, k) = prs.(i) in\n if d + i = !cur then\n (lst.(!cur) <- 2*k+2;\n cur := !cur + 1)\n else\n par.(2*k+2) <- lst.(d + i - 1)\n done;\n for i = 1 to !cur-1 do\n par.(lst.(i)) <- lst.(i-1)\n done;\n for i = 1 to n * 2 do\n if par.(i) = 0 then\n ()\n else\n Printf.printf \"%d %d\\n\" i par.(i)\n done \n"}, {"source_code": "let iteri_if action cond lst =\n let rec go i lst = \n match lst with\n | [] -> ()\n | x :: rest -> (if cond i x then action i x else ()) ; go (i + 1) rest\n in go 0 lst\n\nlet ans =\n let n = read_int() in\n let s = read_line() in\n let words = Str.split_delim (Str.regexp \" \") s in\n let ds = List.map int_of_string words in\n let prs = Array.make n (0, 0) in\n List.iteri (fun i k -> prs.(i) <- (k, i)) ds;\n Array.fast_sort (fun x y -> - (compare x y)) prs;\n let par = Array.make (n * 2 + 1) 0 in\n let lst = Array.make (n * 2) 0 in\n Array.iteri (fun i (_,k) -> lst.(i) <- 2 * k + 1) prs;\n let cur = ref n in\n Array.iteri (fun i (d,k) ->\n if d + i = !cur then\n (lst.(!cur) <- 2*k+2;\n cur := !cur + 1)\n else\n par.(2*k+2) <- lst.(d + i - 1)\n ) prs;\n for i = 1 to !cur-1 do\n par.(lst.(i)) <- lst.(i-1)\n done;\n iteri_if (fun i j -> Printf.printf \"%d %d\\n\" i j)\n (fun i j -> j <> 0) (Array.to_list par)\n"}], "negative_code": [{"source_code": "(* Petya and Construction Set\n * https://codeforces.com/contest/1214/problem/E *)\n\nlet ans =\n let n = read_int() in\n let ds = read_line()\n |> Str.split_delim (Str.regexp \" \")\n |> List.map int_of_string in\n let prs = Array.make n (0, 0) in\n List.iteri (fun i k -> prs.(i) <- (k, i)) ds;\n Array.fast_sort (fun x y -> - (compare x y)) prs;\n let par = Array.make (n * 2 + 1) 0 in\n let lst = Array.make (n * 2) 0 in\n Array.iteri (fun i (_,k) -> lst.(i) <- 2 * k + 1) prs;\n let cur = ref n in\n let rec iter i cur =\n if i = n then ()\n else\n let (d, k) = prs.(i) in\n let ncur = \n if d + i = cur then\n (lst.(cur) <- 2*k+2;\n cur + 1)\n else (par.(2*k+2) <- lst.(d + i - 1);\n cur) in\n iter (i+1) ncur in\n iter 0 n;\n (* Array.iteri (fun i (d,k) ->\n * if d + i = !cur then\n * (lst.(!cur) <- 2*k+2;\n * cur := !cur + 1)\n * else\n * par.(2*k+2) <- lst.(d + i - 1)\n * ) prs; *)\n for i = 1 to !cur-1 do\n par.(lst.(i)) <- lst.(i-1)\n done;\n Array.iteri\n (fun i j -> if j = 0 then () else Printf.printf \"%d %d\\n\" i j) par\n"}, {"source_code": "(* #load \"str.cma\" *)\n\nlet () =\n let n = read_int() in\n let s = read_line() in\n let words = Str.split_delim (Str.regexp \" \") s in\n let ds = List.map int_of_string words in\n print_int (List.fold_left (+) 0 ds)\n"}], "src_uid": "61bb5f2b315eddf2e658e3f54d8f43b8"} {"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 \"\" in\n let _ =\n for i = 0 to n - 1 do\n a.(i) <- Scanf.bscanf sb \"%s \" (fun s -> s)\n done;\n in\n let k = String.length a.(0) in\n let res = String.make k 'x' in\n for i = 0 to k - 1 do\n let c = ref '?' in\n\tfor j = 0 to n - 1 do\n\t if !c = '?' && a.(j).[i] <> '?' then (\n\t c := a.(j).[i];\n\t res.[i] <- !c;\n\t ) else if !c <> '?' && a.(j).[i] <> '?' && a.(j).[i] <> !c then (\n\t res.[i] <- '?'\n\t )\n\tdone\n done;\n Printf.printf \"%s\\n\" res;\n", "positive_code": [{"source_code": "let n=read_int();;\nlet tab=Array.make (n+1) \"\";;\nfor i=1 to n do\n tab.(i)<-read_line()\ndone;;\nlet m=String.length(tab.(1));;\nlet vec=Array.make m ' ';;\nfor j=0 to m-1 do\n vec.(j)<-tab.(1).[j]\ndone;;\nfor i=2 to n do\n for j=0 to m-1 do\n if vec.(j)='?' then vec.(j)<-tab.(i).[j]\n else if tab.(i).[j]='?' then ()\n else if tab.(i).[j]<>vec.(j) then vec.(j)<-'!'\n done\ndone;;\n\nlet sol=tab.(1);;\nfor j=0 to m-1 do\n if vec.(j)='?' then sol.[j]<-'a'\n else if vec.(j)='!' then sol.[j]<-'?'\n else sol.[j]<-vec.(j)\ndone;;\nprint_string sol;;\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet read_int () = scanf \" %d \" (fun x -> x) in\nlet read_string () = scanf \" %s \" (fun x -> x) in\n\nlet n = read_int () in\nlet a = Array.init n (fun x -> (read_string ())) in\nlet m = String.length a.(0) in\n\nlet res = String.make m 'A' in\n\nlet upd i c =\n if c <> '?' then\n if res.[i] = 'A' || res.[i] = c then\n res.[i] <- c\n else\n res.[i] <- '?' in\n\nArray.iter (String.iteri upd) a;\nprintf \"%s\\n\" (String.lowercase res);;\n\n\n"}], "negative_code": [], "src_uid": "a51d2e6e321d7db67687a594a2b85e47"} {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_pair () = let a = read_int () in (a , read_int ());;\n\nmodule Pair_set = struct\n type t = int*int\n let compare = compare\nend;;\n\nmodule Mytest = Set.Make (Pair_set);;\n\nlet n = read_int ();;\n\nlet data = Array.init n (fun i -> read_pair ());;\nArray.sort compare data;;\n\nlet ans = ref 0 and _end = ref (-1) in \n for i = 0 to (n-1) do\n let first , second = data.(i) in\n if second < !_end then ans := !ans + 1\n else _end := second\n done;\n Printf.printf \"%d\\n\" !ans;;\n\n\n", "positive_code": [{"source_code": "(*************** Ocaml stdio functions **********************)\nlet stdin_stream = Stream.of_channel stdin;;\nlet stdout_buffer = Buffer.create 65536;;\nlet rec gi() =\n match Stream.next stdin_stream with\n '-' -> - (ri 0)\n | '+' -> ri 0\n | '0'..'9' as c -> ri ((int_of_char c) - 48)\n | _ -> gi ()\nand ri x =\n match Stream.next stdin_stream with\n '0'..'9' as c -> ri (((int_of_char c) - 48) + (x * 10))\n | _ -> x\n;;\nlet flushout () = Buffer.output_buffer stdout stdout_buffer; Buffer.reset stdout_buffer;;\nlet putchar c =\n if (Buffer.length stdout_buffer) >= 65536 then flushout() else ();\n Buffer.add_char stdout_buffer c;;\nlet rec ppi i = if i < 10 then putchar (char_of_int (48 + i)) else (ppi (i / 10); putchar (char_of_int (48 + (i mod 10)))) ;;\nlet pi i = if i >= 0 then ppi i else (putchar ('-'); ppi (-i));;\nlet pa a = let n = Array.length a in Array.iteri (fun i j -> pi j; putchar (if i == (n-1) then '\\n' else ' ')) a;;\n(*************** Ocaml solution ******************************)\nopen Array\nlet main() =\n let n = gi() in\n let a = init n (fun i -> let ai = gi () in let bi = gi () in (ai, bi)) in\n let cmp a b = compare (fst a) (fst b) in\n stable_sort cmp a;\n let mx = ref 0 in\n let s = ref 0 in\n for i = 0 to (n-1) do\n let b = snd a.(i) in\n s := (!s) + (if b > (!mx) then 0 else 1);\n mx := max (!mx) b\n done;\n Printf.printf \"%d\\n\" (!s)\n ;;\nmain();;\nflushout ()"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nmodule Pset = Set.Make (struct type t = int*int let compare = compare end)\n\nlet n = read_int()\n\nlet p = Array.make n (0,0)\n\nlet contained (a,b) s = \n let (l,_,_) = Pset.split (a,b) s in\n if Pset.is_empty l then false else\n let (ai,bi) = Pset.max_elt l in b < bi\n\nlet () =\n for i=0 to n-1 do\n let a = read_int() in\n let b = read_int() in\n p.(i) <- (a,b)\n done;\n Array.sort (fun (a,b) (c,d) -> compare (d-c) (b-a)) p;\n\n let s = ref Pset.empty in\n let count = ref 0 in\n for i=0 to n-1 do\n if not (contained p.(i) !s) then s := Pset.add p.(i) !s\n else count := !count + 1;\n done;\n \n Printf.printf \"%d\\n\" !count\n"}, {"source_code": "let getnum =\n let l = 512000 in\n let buf = String.make l ' ' in\n let s = ref 0 in\n let pos = ref 0 in\n let getc () =\n if !pos >= !s then (\n let new_s = input stdin buf 0 l in\n\t(*if new_s = 0 then raise End_of_file;*)\n\ts := new_s;\n\tif new_s = 0 then (\n\t buf.[0] <- '\\000';\n\t s := 1;\n\t);\n\tpos := 0;\n );\n let c = buf.[!pos] in\n incr pos;\n c\n in\n let aux () =\n let n = ref 0 in\n let k = ref 1 in\n if !s - !pos < 50 then (\n\tlet c = ref (getc ()) in\n\t while !c <= ' ' do\n\t c := getc ()\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := getc ();\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := getc ()\n\t done;\n\t !n * !k\n ) else (\n\tlet c = ref (buf.[!pos]) in\n\t incr pos;\n\t while !c <= ' ' do\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t if !c = '-' then (\n\t k := -1;\n\t c := buf.[!pos];\n\t incr pos;\n\t );\n\t while !c > ' ' do\n\t n := !n * 10 + (Char.code !c - Char.code '0');\n\t c := buf.[!pos];\n\t incr pos;\n\t done;\n\t !n * !k\n )\n in\n aux\n\nlet _ =\n let n = getnum () in\n let c = Array.make n (0, 0) in\n for i = 0 to n - 1 do\n let a = getnum () in\n let b = getnum () in\n\tc.(i) <- (a, b)\n done;\n Array.sort compare c;\n let latest = ref 0 in\n let res = ref 0 in\n for i = 0 to n - 1 do\n\tlet (_a, b) = c.(i) in\n\t if b < !latest\n\t then incr res;\n\t latest := max !latest b\n done;\n output_string stdout (string_of_int !res);\n output_char stdout '\\n';\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\n\nlet read_pair () = let a = read_int () in (a , read_int ());;\n\nlet n = read_int ();;\n\nlet events = Array.init (2*n) (fun i -> (read_int (),if i land 1 = 0 then 0 else 1));;\n\nlet compare x y = let a , b = x in let c , d = y in if a = c then 0 else if a > c then 1 else -1;;\n\nArray.sort compare events;;\n\nlet ans = ref 0;;\n\nlet () = \n let cnt = ref 0 in\n for i = 0 to (2*n-1) do\n let first , second = events.(i) in \n if second = 1 then begin\n cnt := !cnt - 1;\n if !cnt > 0 then ans := !ans + 1\n else () end\n else cnt := !cnt + 1\n done;;\n\nPrintf.printf \"%d\\n\" !ans;;\n \n"}], "src_uid": "dfb1479ffa17489095b6bf1921758f7e"} {"source_code": "let rec gcd x y =\n if y == 0 then\n x\n else\n gcd y (x mod y)\n\nlet () =\n match read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string with\n | [n; k] ->\n let c = read_line () |> Str.(split (regexp \" \")) |> List.map int_of_string in\n print_endline (\n if List.(fold_left gcd k (map (fun ci -> k / gcd k ci) c)) == 1 then\n \"Yes\"\n else\n \"No\"\n )\n | _ -> assert false\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet factor n = (* factor n into a list of prime powers *)\n let rec loop n p pow ac =\n let ac' = if pow>1 then (pow::ac) else ac in\n if n=1 then ac'\n else if n mod p = 0 then loop (n/p) p (pow*p) ac\n else loop n (p+1) 1 ac'\n in\n List.rev (loop n 2 1 [])\n \nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f) \n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let k = read_int () in\n let c = Array.init n (fun _ -> read_int()) in\n\n let factors = factor k in\n\n let answer = List.exists (fun p ->\n forall 0 (n-1) (fun i -> c.(i) mod p <> 0)\n ) factors in\n \n if answer then printf \"No\\n\" else printf \"Yes\\n\"\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n \nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f) \n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let k = read_int () in\n let c = Array.init n (fun _ -> read_int()) in\n\n let factors = List.sort_uniq compare (factor k) in\n\n let answer = List.exists (fun p ->\n forall 0 (n-1) (fun i -> c.(i) mod p <> 0)\n ) factors in\n \n if answer then printf \"No\\n\" else printf \"Yes\\n\"\n"}], "src_uid": "e72fa6f8a31c34fd3ca0ce3a3873ff50"} {"source_code": "type el = {\n i : int; (* node index *)\n mutable d : int; (* node degree *)\n mutable s : int; (* xor sum of neighbours *)\n}\n\nmodule H : sig\n type t\n val make : int -> t\n val add : t -> el -> unit\n val dec : t -> int -> unit\n val is_empty : t -> bool\n val pop : t -> el\n val get : t -> int -> el * int\nend = struct\n type t = {\n mutable len : int;\n arr : el array;\n rev : int array;\n }\n\n let is_empty h = h.len = 0\n\n let make n = {\n len = 0;\n arr = Array.make n { i = -1; d = 0; s = 0 };\n rev = Array.make n 0;\n }\n\n let get h i =\n let j = h.rev.(i) in\n (h.arr.(j), j)\n\n let swap h i j =\n let e = h.arr.(i)\n and f = h.arr.(j) in\n h.arr.(i) <- f;\n h.arr.(j) <- e;\n h.rev.(e.i) <- j;\n h.rev.(f.i) <- i\n\n let rec dec h i =\n if i = 0 then ()\n else begin\n (* get parent *)\n let p = (i - 1) / 2 in\n (* if the child has smaller degree than parent *)\n if h.arr.(p).d > h.arr.(i).d then begin\n swap h i p;\n dec h p\n end\n end\n\n let rec inc h i =\n let l = 2 * i + 1\n and r = 2 * i + 2 in\n\n (* no children *)\n if l >= h.len then ()\n\n (* only left child *)\n else if r >= h.len then begin\n if h.arr.(i).d > h.arr.(l).d then begin\n swap h i l;\n inc h l\n end\n end\n\n (* both children *)\n else begin\n if h.arr.(i).d > h.arr.(l).d then\n (* right child is smallest *)\n if h.arr.(l).d > h.arr.(r).d then begin\n swap h i r;\n inc h r\n (* left child is smallest *)\n end else begin\n swap h i l;\n inc h l\n end\n (* right child is smaller *)\n else if h.arr.(i).d > h.arr.(r).d then begin\n swap h i r;\n inc h r\n end\n end\n\n let add h e =\n (* insert the element at the end of the heap *)\n h.arr.(h.len) <- e;\n h.rev.(e.i) <- h.len;\n\n (* bubble up to enforce the heap constraint *)\n dec h h.len;\n h.len <- h.len + 1\n\n let pop h =\n let e = h.arr.(0) in\n h.len <- h.len - 1;\n\n (* move the last element to the top *)\n swap h 0 h.len;\n\n (* bubble down *)\n inc h 0;\n\n (* return the element *)\n e\nend\n\nlet () = Scanf.scanf \"%d\\n\" (fun n ->\n let nodes = H.make n in\n let edges = ref [] in\n\n (* read nodes and populate the heap *)\n for i = 0 to n - 1 do\n let d, s = Scanf.scanf \"%d %d\\n\" (fun d s -> (d, s)) in\n let el = { i; d; s } in\n H.add nodes el\n done;\n\n while not (H.is_empty nodes) do\n let e = H.pop nodes in\n match e.d with\n | 0 -> () (* isolated node; no edges *)\n\n | 1 -> (* leaf node, add edge to list *)\n edges := (e.i, e.s) :: !edges;\n let f, j = H.get nodes e.s in\n f.s <- f.s lxor e.i;\n f.d <- f.d - 1;\n H.dec nodes j;\n\n | _ -> failwith \"Cycle detected\"\n done;\n\n Printf.printf \"%d\\n\" (List.length !edges);\n List.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" a b) !edges\n)\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let s = Stack.create () in\n let e = ref [] in\n let a = Array.init n (fun i ->\n let d, x = Scanf.scanf \"%d %d\\n\" (fun d s -> (d, s)) in\n if d = 1 then Stack.push i s;\n (d, x)\n ) in\n while not (Stack.is_empty s) do\n let i = Stack.pop s in\n let d', j = a.(i) in\n if d' = 1 then begin\n e := (i, j) :: !e;\n let d, x = a.(j) in\n a.(j) <- (d - 1, x lxor i);\n if d = 2 then Stack.push j s\n end\n done;\n Printf.printf \"%d\\n\" (List.length !e);\n List.iter (fun (a, b) -> Printf.printf \"%d %d\\n\" a b) !e\n)\n"}], "negative_code": [], "src_uid": "14ad30e33bf8cad492e665b0a486008e"} {"source_code": "open Printf\r\nopen Scanf\r\n\r\n\r\nlet solve_one = (\r\n)\r\n\r\nlet remove_last s = (String.sub s 0 ((String.length s) - 1))\r\n\r\nlet find_div7 s = \r\n let rec find_div7_try k =\r\n if k == 10 then 0\r\n else if ((s * 10 + k) mod 7) == 0 then (s * 10 + k)\r\n else find_div7_try (k + 1) in\r\n find_div7_try 0\r\n\r\nlet rec solve t =\r\n if t > 0 then (\r\n let s = read_line() in\r\n let v = int_of_string s in\r\n (\r\n if v mod 7 == 0 then v\r\n else find_div7 (int_of_string (remove_last s))\r\n )\r\n |> string_of_int\r\n |> print_endline;\r\n solve (t - 1)\r\n )\r\n else ()\r\n\r\nlet () = \r\n let t = int_of_string (read_line()) in\r\n solve t\r\n", "positive_code": [{"source_code": "Scanf.scanf \"%d\" (fun t ->\n for i = 1 to t do\n Printf.printf \"%d\\n\" (\n Scanf.scanf \" %d\" (fun n ->\n if n mod 7 = 0 then n else\n let n2 = n / 10 * 10 in\n let rec loop i =\n if (n2 + i) mod 7 = 0 then n2 + i else loop (i + 1)\n in\n loop 0\n )\n )\n done\n)\n"}], "negative_code": [{"source_code": "open Printf\r\nopen Scanf\r\n\r\n\r\nlet solve_one = (\r\n)\r\n\r\nlet remove_last s = (String.sub s 0 ((String.length s) - 1))\r\n\r\nlet find_div7 s = \r\n let rec find_div7_try k =\r\n if k == 10 then 0\r\n else if ((s * 10 + k) mod 7) == 0 then (s * 10 + k)\r\n else find_div7_try (k + 1) in\r\n find_div7_try 0\r\n\r\nlet rec solve t =\r\n if t > 0 then (\r\n let s = read_line() in\r\n print_endline (string_of_int (find_div7 (int_of_string (remove_last s))));\r\n solve (t - 1)\r\n )\r\n else ()\r\n\r\nlet () = \r\n let t = int_of_string (read_line()) in\r\n solve t\r\n"}], "src_uid": "128372d890f632494e59e81287abd85a"} {"source_code": "let ( ** ) 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(* http://www.cs.cmu.edu/~quake/robust.html *)\n\nlet sq x = x ** x\n\nlet det ((a,b,c),(d,e,f),(g,h,i)) = \n a**(e**i -- f**h) -- b**(d**i -- f**g) ++ c**(d**h -- e**g)\n\n(* This returns 0 if the four points are on the same circle.\n It returns >0 if going around the circle in the direction\n a --> b --> c then d is on the side of the circle pointed\n to by my left hand. It returns >0 otherwise. It's a fourth\n degree function in the given coordinates. *)\n\nlet incircle (ax,ay) (bx,by) (cx,cy) (dx,dy) = \n let row ax dx ay dy = \n let a = ax -- dx in\n let b = ay -- dy in\n (a, b, (sq a) ++ (sq b))\n in\n det (row ax dx ay dy, row bx dx by dy, row cx dx cy dy)\n\nlet (---) (x1,y1) (x2,y2) = (x1--x2, y1--y2);;\nlet (+++) (x1,y1) (x2,y2) = (x1++x2, y1++y2);;\nlet cross (x1,y1) (x2,y2) = (x1**y2) -- (y1**x2);;\nlet dot (x1,y1) (x2,y2) = (x1**x2) ++ (y1**y2);;\n\n(* radius of a circle given three points from\n http://en.wikipedia.org/wiki/Circumscribed_circle *)\n\nlet length (x,y) = \n let (x,y) = (Int64.to_float x, Int64.to_float y) in\n sqrt (x*.x +. y*.y)\n\nlet radius a b c = \n let a = a --- c in\n let b = b --- c in\n (length a) *. (length b) *. (length (a --- b)) /. \n (2.0 *. (abs_float (Int64.to_float (cross a b))))\n\n(* this returns >0 if c on the left side of a-->b, <0 if on the right, and 0 if on. *)\nlet leftside a b c = cross (a---c) (b---c)\n\n\n(* The following function takes a list of points as input, and returns true\n if it's smooth, that is, if none of the angles as we walk around the points\n subsumes more than half of the circle *)\nlet smooth_set a = \n let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init) in\n let sum i j f = fold i j (fun i a -> (f i) +. a) 0.0 in\n let float_of_array a n =\n Array.init n (fun i -> let (xi, yi) = a.(i) in (Int64.to_float xi, Int64.to_float yi))\n in\n\n let a = Array.of_list a in\n let n = Array.length a in\n let af = float_of_array a n in\n let cx = (sum 0 (n-1) (fun i -> fst af.(i))) /. (float n) in\n let cy = (sum 0 (n-1) (fun i -> snd af.(i))) /. (float n) in\n let ang = Array.init n (fun i -> (atan2 ((fst af.(i) -. cx)) ((snd af.(i)) -. cy), i)) in\n let () = Array.sort compare ang in\n\n let rec loop i = i=n || (\n let j1 = snd ang.(i) in\n let j2 = snd (ang.((i+1) mod n)) in\n let j3 = snd (ang.((i+2) mod n)) in\n let v1 = a.(j3) --- a.(j1) in\n let v2 = a.(j2) --- a.(j3) in\n dot v1 v2 < 0L && loop (i+1)\n ) in\n loop 0\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x)\nlet read_pair _ = let u = read_long() in (u, read_long())\n\nlet print_smooth_set s = \n Printf.printf \"smooth set: \";\n List.iter (fun (x,y) -> Printf.printf \"(%Ld,%Ld) \" x y) s;\n print_newline()\n\nlet () = \n let n = read_int() in\n let c = Array.init n read_pair in\n \n let bestr = ref (-1.0) in\n \n for i=0 to n-1 do\n for j=0 to n-1 do\n\tif i <> j then (\n\t let prev = ref (-1) in\n\t for k=0 to n-1 do\n\t if k <> i && k <> j && (leftside c.(i) c.(j) c.(k) > 0L) then (\n\t\tif !prev = -1 || (incircle c.(i) c.(j) c.(!prev) c.(k)) > 0L then prev := k\n\t )\n\t done;\n\t if !prev >0 then (\n\t let bad = ref false in\n\t let onlist = ref [] in\n\t\tfor k=0 to n-1 do\n\t\t let cval = incircle c.(i) c.(j) c.(!prev) c.(k) in\n\t\t if cval = 0L then onlist := c.(k) :: !onlist\n\t\t else if cval > 0L then bad := true\n\t\tdone;\n\t\tif (not !bad) && (smooth_set !onlist) then (\n(*\t\t print_smooth_set !onlist; *)\n\t\t let r = radius c.(i) c.(j) c.(!prev) in\n\t\t bestr := max r !bestr\n\t\t)\n\t )\n\t)\n done\n done;\n \n if !bestr < 0.0 then Printf.printf \"-1\\n\" else Printf.printf \"%.6f\\n\" !bestr\n", "positive_code": [{"source_code": "(* O(n^2) Delaunay triangulation algorithm *)\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(* http://www.cs.cmu.edu/~quake/robust.html *)\n\n(* This returns 0 if the four points are on the same circle.\n It returns >0 if going around the circle in the direction\n a --> b --> c then d is on the side of the circle pointed\n to by my left hand. It returns >0 otherwise. It's a fourth\n degree function in the given coordinates. *)\n\nlet (---) (x1,y1) (x2,y2) = (x1--x2, y1--y2);;\nlet (+++) (x1,y1) (x2,y2) = (x1++x2, y1++y2);;\nlet cross (x1,y1) (x2,y2) = (x1**y2) -- (y1**x2);;\nlet dot (x1,y1) (x2,y2) = (x1**x2) ++ (y1**y2);;\nlet sq x = x ** x\nlet length (x,y) = \n let (x,y) = (Int64.to_float x, Int64.to_float y) in\n sqrt (x*.x +. y*.y)\n\nlet incircle (ax,ay) (bx,by) (cx,cy) (dx,dy) = \n let det ((a,b,c),(d,e,f),(g,h,i)) = \n a**(e**i -- f**h) -- b**(d**i -- f**g) ++ c**(d**h -- e**g)\n in\n\n let row ax dx ay dy = \n let a = ax -- dx in\n let b = ay -- dy in\n (a, b, (sq a) ++ (sq b))\n in\n det (row ax dx ay dy, row bx dx by dy, row cx dx cy dy)\n\n(* radius of a circle given three points from\n http://en.wikipedia.org/wiki/Circumscribed_circle *)\n\nlet radius a b c = \n let a = a --- c in\n let b = b --- c in\n (length a) *. (length b) *. (length (a --- b)) /. \n (2.0 *. (abs_float (Int64.to_float (cross a b))))\n\n(* this returns >0 if c on the left side of a-->b, <0 if on the right, and 0 if on. *)\nlet leftside a b c = cross (a---c) (b---c)\n\nmodule Pset = Set.Make (struct type t = int*int let compare = compare end)\n\n(* takes as input an array of p of n points, and computes\n the Delaunay triangulation of them *)\nlet delaunay p n = \n\n let len2 (px,py) (qx,qy) = (sq (px--qx)) ++ (sq (py--qy)) in\n\n let rec closest (i,j) (bi,bj) dist = \n if j=n then (bi,bj) else\n let d = len2 p.(i) p.(j) in\n let next = if i+1j vector\n with the normalized j-->k vector, and sort it in decreasing order. *)\n let v = Array.make (nv-2) (0.0, 0) in\n let rec loadv k li = match li with [] -> () | h::li ->\n let a = p.(j) --- p.(i) in\n let b = p.(h) --- p.(j) in\n let dp = (Int64.to_float (dot a b)) /. (length b) in\n\tv.(k) <- (dp, h);\n\tloadv (k+1) li\n in\n loadv 0 face;\n Array.sort (fun a b -> compare b a) v;\n Array.init nv (fun k -> if k=0 then i else if k=1 then j else snd v.(k-2))\n in\n\n let rec loop (completed,todo) ac =\n match todo with \n | [] -> ac\n | (i,j)::todo ->\n\t if Pset.mem (i,j) completed then loop (completed,todo) ac else\n\t let rec findface ac k = if k=n then ac else \n\t if k = i || k = j || (leftside p.(i) p.(j) p.(k) <= 0L) then findface ac (k+1) else \n\t\tif ac = [] then findface [k] (k+1) else \n\t\t let ic = incircle p.(i) p.(j) p.(List.hd ac) p.(k) in\n\t\t if ic > 0L then findface [k] (k+1)\n\t\t else if ic = 0L then findface (k::ac) (k+1)\n\t\t else findface ac (k+1)\n\t in\n\t let face = findface [] 0 in\n\n\t if face = [] then loop (Pset.add (i,j) completed, todo) ac (* convex hull edge *)\n\t else (\n\t\tlet nv = 2 + (List.length face) in\n\t\tlet v = order_face i j face nv in\n\t\tlet rec process_face k (s,t) = if k = nv then (s,t) else\n\t\t let l = (k+1) mod nv in\n\t\t let s = Pset.add (v.(k), v.(l)) s in\n\t\t let t = (v.(l), v.(k)) :: t in\n\t\t process_face (k+1) (s,t)\n\t\tin\n\t\t loop (process_face 0 (completed,todo)) (v::ac)\n\t )\n in \n loop (Pset.empty, [(bi,bj); (bj,bi)]) []\n\n(*----------------------------------------------------------------------*)\n\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x)\nlet read_pair _ = let u = read_long() in (u, read_long())\n\nlet () = \n let n = read_int() in\n let p = Array.init n read_pair in\n\n (* The following function takes an array of indices on a circle as input,\n and returns true if it's smooth, that is, if the polygon strictly \n contains the center. *)\n let smooth_set a n = \n let rec loop i = i=n || (\n let j1 = a.(i) in\n let j2 = a.((i+1) mod n) in\n let j3 = a.((i+2) mod n) in\n let v1 = p.(j3) --- p.(j1) in\n let v2 = p.(j2) --- p.(j3) in\n\tdot v1 v2 < 0L && loop (i+1)\n ) in\n loop 0\n in\n\n let rec loop bestr f = match f with [] -> bestr\n | a::f -> \n\tlet nv = Array.length a in\n\tlet bestr = if smooth_set a nv then \n\t max bestr (radius p.(a.(0)) p.(a.(1)) p.(a.(2))) else bestr\n\tin\n\t loop bestr f\n in\n let bestr = loop (-1.0) (delaunay p n) in\n if bestr < 0.0 then Printf.printf \"-1\\n\" else Printf.printf \"%.6f\\n\" bestr\n"}], "negative_code": [], "src_uid": "8b1129d61855e558e4153e9c07427ffd"} {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\n\nlet rec show_int_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_int x; print_string \" \"; show_int_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet calc x =\n let m = Int64.of_int m in\n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in\n aux (Int64.zero) (Int64.of_int x)\n\nlet get_dvsr () = \n let up = iof (sqrt (foi d)) in\n let rec aux n acc = \n\tif n > up then acc\n\telse \n\t if d mod n = 0 then \n\t\tif n * n <> d then aux (n + 1) (n :: (d/n) :: acc)\n\t\telse aux (n + 1) (n :: acc)\n\t else \n\t\taux (n + 1) acc\n in\n aux 1 []\n\nlet () =\n List.filter (fun x -> x mod 2 = 1) (get_dvsr () )\n\t|> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero\n\t|> Printf.printf \"%Ld\"\n\t\n\n\n \n", "positive_code": [{"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\n\nlet rec show_int_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_int x; print_string \" \"; show_int_list xs\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 rec gcd x y = \n if y = 0 then x else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet calc x =\n let m = Int64.of_int m in\n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in\n aux (Int64.zero) (Int64.of_int x)\n\nlet get_dvsr () = \n let up = iof (sqrt (foi d)) in\n let rec aux n acc = \n\tif n > up then acc\n\telse \n\t if d mod n = 0 then \n\t\tif n * n <> d then aux (n + 1) (n :: (d/n) :: acc)\n\t\telse aux (n + 1) (n :: acc)\n\t else \n\t\taux (n + 1) acc\n in\n aux 1 []\n\nlet () =\n List.filter (fun x -> x mod 2 = 1) (get_dvsr () )\n\t|> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero\n\t|> Printf.printf \"%Ld\"\n\t\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\n\nlet rec show_int_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_int x; print_string \" \"; show_int_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x =\n let m = Int64.of_int m in\n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in\n aux (Int64.zero) (Int64.of_int x)\n\nlet get_dvsr () = \n let up = iof (sqrt (foi d)) in\n let rec aux n acc = \n\tif n > up then acc\n\telse \n\t if d mod n = 0 then \n\t\tif n * n <> d then aux (n + 1) (n :: (d/n) :: acc)\n\t\telse aux (n + 1) (n :: acc)\n\t else \n\t\taux (n + 1) acc\n in\n aux 1 []\n\nlet () =\n Printf.printf \"%Ld\" ( \n\tList.filter (fun x -> x mod 2 = 1) (get_dvsr () )\n\t\t\t\t\t\t |> List.map calc\n\t\t\t\t\t\t |> List.fold_left (fun x y -> Int64.add x y) Int64.zero) \n\t\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\n\nlet rec show_int_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_int x; print_string \" \"; show_int_list xs\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 rec gcd x y = \n if y = 0 then x else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet calc x =\n let m = Int64.of_int m in\n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (Int64.add acc (Int64.sub m x)) (Int64.add x x) in\n aux (Int64.zero) (Int64.of_int x)\n\nlet get_dvsr () = \n let up = iof (sqrt (foi d)) in\n let rec aux n acc = \n\tif n > up then acc\n\telse \n\t if d mod n = 0 then \n\t\tif n * n <> d then aux (n + 1) (n :: (d/n) :: acc)\n\t\telse aux (n + 1) (n :: acc)\n\t else \n\t\taux (n + 1) acc\n in\n aux 1 []\n\nlet () =\n Printf.printf \"%Ld\" ( \n\tList.filter (fun x -> x mod 2 = 1) (get_dvsr () )\n\t\t\t\t\t\t |> List.fold_left (fun acc y -> Int64.add acc (calc y)) Int64.zero)\n\t\n\n\n \n"}], "negative_code": [{"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = Int64.of_int (min m 800000000) in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (Int64.add acc (Int64.sub mm x)) (Int64.add x x) in\n aux (Int64.zero) (Int64.of_int x)\n\n\nlet () =\n Printf.printf \"%Ld\" (List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (fun x y -> Int64.add x y) Int64.zero) \n\t\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 500000011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc +. foi (mm - x)) (2 * x) in\n aux 0. x\n\n\nlet () =\n Printf.printf \"%.0f\" (List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+.) 0.) \n\t\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 1000011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc + mm - x) (2 * x) in\n aux 0 x\n\n\nlet () =\n List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+) 0 \n\t|> print_int\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 10011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc + mm - x) (2 * x) in\n aux 0 x\n\n\nlet () =\n List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+) 0 \n\t|> print_int\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 100000011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc + mm - x) (2 * x) in\n aux 0 x\n\n\nlet () =\n List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+) 0 \n\t|> print_int\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 500000011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc + mm - x) (2 * x) in\n aux 0 x\n\n\nlet () =\n List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+) 0 \n\t|> print_int\n\n\n \n"}, {"source_code": "let ( |> ) x f = f x\nlet ( <| ) f x = f x\n\nlet foi = float_of_int\nlet iof = int_of_float\n\nlet next_int () = Scanf.scanf \"%d%c\" (fun x _ -> x)\nlet next_flt () = Scanf.scanf \"%f%c\" (fun x _ -> x)\n\nlet seq n = \n let rec aux n acc = \n\tif n = 0 then acc\n\telse aux (n-1) (n :: acc) in\n aux n []\n\nlet rec show_flt_list x = \n match x with\n\t [] -> print_newline ()\n\t| x::xs -> print_float x; print_string \" \"; show_flt_list xs\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 rec gcd x y = \n if x mod y = 0 then y else gcd y (x mod y)\n;;\n\nlet n = next_int () \nlet m = next_int () \n\n(* let () = \n print_newline(); print_int n; print_newline (); print_int m; print_newline()\n*)\n\nlet a = loop n (fun _ -> (next_int()) - 1) []\nlet d = List.fold_left gcd (List.hd a) a\n\nlet chk y = \n let rec aux acc x = \n\tif x >= m then acc\n\telse aux (acc + m - x) (2 * x) in\n aux 0 y\n\nlet calc x = \n let mm = min m 100011 in\n let rec aux acc x = \n\tif x >= mm then acc\n\telse aux (acc + mm - x) (2 * x) in\n aux 0 x\n\n\nlet () =\n List.filter (fun x -> x mod 2 = 1 && d mod x = 0) (seq d)\n\t|> List.map calc \n\t|> List.fold_left (+) 0 \n\t|> print_int\n\n\n \n"}], "src_uid": "189a8a9a6e99ed52bda9a5773bf2621b"} {"source_code": "open Printf\nopen Scanf\n\nlet () = \n let n = read_int() in\n let arrv : bool array = Array.create n false in\n let arrh : bool array = Array.create n false in\n for i = 1 to n*n do\n let h, v = scanf \"%d %d\\n\" (fun x y -> x, y) in\n if not (arrh.(h-1) || arrv.(v-1)) then begin\n arrh.(h-1) <- true;\n arrv.(v-1) <- true;\n printf \"%d \" i\n end;\n printf \"\\n%!\"\ndone\n", "positive_code": [{"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let h = Array.make n false\n and v = Array.make n false in\n for i = 1 to n*n do\n Scanf.scanf \"%d %d\\n\" (fun x y ->\n if not (h.(x - 1) || v.(y - 1)) then begin\n h.(x - 1) <- true;\n v.(y - 1) <- true;\n Printf.printf \"%d \" i\n end)\n done)\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet () = \n let n = read_int () in\n let vert : bool array = Array.create n false in\n let horz : bool array = Array.create n false in\n for i = 1 to n * n do\n let h, v = scanf \"%d %d\\n\" (fun x y -> x - 1, y - 1) in\n if not (horz.(h) || vert.(v)) then begin\n horz.(h) <- true;\n vert.(v) <- true;\n printf \"%d \" i\n end;\n printf \"\\n%!\"\n done\n\n \n"}], "negative_code": [], "src_uid": "c611808e636d9307e6df9ee0e706310b"} {"source_code": "let solve n ds =\n let beauty = List.fold_left ( + ) 0 ds in\n let rec loop best index i = function\n | [] -> index\n | d :: ds ->\n let b = abs (beauty - 2 * d) in\n if b > best then\n loop b i (i - 1) ds\n else\n loop best index (i - 1) ds\n in loop (abs beauty) 0 n ds\n\nlet () =\n Scanf.scanf \"%d \" @@ fun n ->\n let ds =\n let rec loop acc = function\n | 0 -> acc\n | n ->\n let d = Scanf.scanf \"%d %d\\n\" @@ ( - ) in\n loop (d :: acc) (n - 1)\n in loop [] n in\n solve n ds |> string_of_int |> print_endline\n", "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 rec loop\n neg_max neg_max_index neg_sum\n pos_max pos_max_index pos_sum i =\n if i > n then\n begin\n if (pos_max - neg_sum) > (pos_sum - neg_max) then pos_max_index\n else neg_max_index\n end\n else\n begin\n let l = read_int () and r = read_int () in\n let diff = l - r in\n if diff < 0 then\n begin\n if (diff < neg_max) then\n loop\n diff i (neg_sum + diff)\n pos_max pos_max_index pos_sum\n (i + 1)\n else\n loop\n neg_max neg_max_index (neg_sum + diff)\n pos_max pos_max_index pos_sum (i + 1)\n end\n else if diff > 0 then\n begin\n if (diff > pos_max) then\n loop\n neg_max neg_max_index neg_sum\n diff i (pos_sum + diff) (i + 1)\n else\n loop\n neg_max neg_max_index neg_sum\n pos_max pos_max_index (pos_sum + diff)\n (i + 1)\n end\n else\n loop\n neg_max neg_max_index neg_sum\n pos_max pos_max_index pos_sum (i + 1)\n end\n in\n loop 0 0 0 0 0 0 1 |> Printf.printf \"%d\"\n"}], "negative_code": [], "src_uid": "2be73aa00a13be5274cf840ecd3befcb"} {"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)\nlet read_pair () = let u = read_int () in (u, read_int ())\n\nlet () =\n let (n, m) = read_pair () in\n let board = Array.init n (fun _ -> read_string ()) in\n\n let count = ref 0 in\n\n let is_face l = \n let l = List.sort compare l in \n l = ['a'; 'c'; 'e'; 'f']\n in \n\n for i=0 to n-2 do\n for j = 0 to m-2 do\n if is_face [board.(i).[j]; board.(i+1).[j]; board.(i).[j+1]; board.(i+1).[j+1] ]\n then count := !count + 1\n done\n done;\n\n printf \"%d\\n\" !count", "positive_code": [{"source_code": "(* iterate all 2x2 square *)\nopen Scanf\nopen Printf\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 let m = read_int() in\n let img = Array.init n (fun _-> read_string()) in\n let ci c = int_of_char c in\n let face = 1 lsl (ci 'f') + 1 lsl (ci 'a') + 1 lsl (ci 'c') + 1 lsl (ci 'e') in\n let is_face a b c d = 1 lsl (ci a) + 1 lsl (ci b) + 1 lsl (ci c) + 1 lsl (ci d) == face in \n let count = ref 0 in\n for i=0 to n-2 do\n\tfor j=0 to m-2 do\n\t if is_face img.(i).[j] img.(i).[j+1] img.(i+1).[j] img.(i+1).[j+1] then\n\t\tcount := !count + 1\n\tdone\n done;\n\tprintf \"%d\\n\" !count\n\t \n\n \n"}, {"source_code": "let ok mat =\n\tlet compt = ref 0 in\n\tfor i=0 to Array.length mat - 2 do\n\tfor j=0 to String.length (mat.(0)) - 2 do\n\t\tif List.sort compare [(mat.(i)).[j];(mat.(i+1)).[j];(mat.(i)).[j+1];(mat.(i+1)).[j+1]] = ['a';'c';'e';'f']\n\t\t\tthen incr compt;\n\tdone;\n\tdone;\n\t!compt\n\nlet () =\n\tlet n = Scanf.scanf \"%d %d \" (fun i _ -> i) in\n\tlet tab = Array.init n (fun i -> Scanf.scanf \" %s\" (fun j -> j)) in\n\t\tPrintf.printf \"%d\" (ok tab)\n"}, {"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)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let (n,m) = read_pair () in\n let board = Array.init n (fun _ -> read_string()) in\n\n let count = ref 0 in\n\n let is_face l =\n let l = List.sort compare l in\n l = ['a';'c';'e';'f']\n in\n\n for i=0 to n-2 do\n for j=0 to m-2 do\n if is_face [board.(i).[j]; board.(i+1).[j]; board.(i).[j+1]; board.(i+1).[j+1] ]\n then count := !count + 1\n done\n done;\n\n printf \"%d\\n\" !count\n"}], "negative_code": [], "src_uid": "742e4e6ca047da5f5ebe5d854d6a2024"} {"source_code": "open Int64;;\r\nopen Array;;\r\nlet da x = ();;\r\nlet is_digit c = \r\n if (int_of_char c) >= (int_of_char '0') \r\n then if (int_of_char c) <= (int_of_char '9') then true\r\n else false\r\n else false;;\r\nlet digit c = (int_of_char c) - (int_of_char '0');;\r\nlet digitInt64 c = of_int(digit c);;\r\nlet readLine() = input_line stdin;;\r\nlet print_number x = print_string (to_string x ^ \" \");;\r\nlet print_char c = print_string (Char.escaped c);;\r\nlet readChar() = \r\n let s = Bytes.create 1 in\r\n let () = da (input stdin s 0 1) in \r\n Bytes.get s 0;;\r\nlet readLong() =\r\n let number = ref 0L in\r\n let () = \r\n let quit_loop = ref false in\r\n while not !quit_loop do\r\n let c = readChar() in\r\n if is_digit c then \r\n number := add (mul !number 10L) (digitInt64 c)\r\n else\r\n quit_loop := true\r\n done in \r\n !number;;\r\n \r\n \r\n \r\nlet merge a b =\r\n let n = length a in\r\n let m = length b in\r\n let ret = make (n+m) 0L in\r\n let i = ref 0 in\r\n let j = ref 0 in\r\n let who = ref false in\r\n let ptr = ref 0 in\r\n while !ptr < (n+m) do\r\n let () = \r\n if !i < n then \r\n if !j < m then who := a.(!i) < b.(!j) \r\n else who := true\r\n else who := false in\r\n let () = \r\n if !who = true then ret.(!ptr) <- a.(!i)\r\n else ret.(!ptr) <- b.(!j) in\r\n let () = \r\n if !who = true then i := !i + 1\r\n else j := !j + 1 in\r\n ptr := !ptr + 1\r\n done; \r\n ret;; \r\nlet rec merge_sort a = \r\n if (length a) = 1 then a\r\n else \r\n let l = init ((length a + 1) / 2) (fun i -> a.(i)) in\r\n let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in\r\n merge (merge_sort l) (merge_sort r);;\r\nlet n = readLong() in\r\nlet k = ref (readLong()) in\r\nlet x = readLong() in\r\nlet a = Array.init (to_int n) (fun i -> readLong()) in\r\nif n = 1L then print_number n \r\nelse\r\n let sorted = merge_sort a in\r\n let cost = make (to_int n-1) 0L in\r\n let () = \r\n for i = 1 to (length a - 1) do\r\n let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in\r\n if cost.(i-1) < 0L then cost.(i-1) <- 0L\r\n done in\r\n let sorted_cost = merge_sort cost in\r\n let answer = ref 1L in\r\n let () = \r\n for i = 0 to (length cost - 1) do\r\n if !k >= sorted_cost.(i) then\r\n k := Int64.sub !k sorted_cost.(i)\r\n else\r\n answer := Int64.add !answer 1L\r\n done in\r\n print_number !answer;;", "positive_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x)\r\nlet scan_lint () = Scanf.scanf \" %Ld\" (fun x -> x)\r\nlet n = scan_int()\r\nlet k = ref (scan_lint())\r\nlet x = scan_lint()\r\n\r\nlet () =\r\n let a = Array.make n 0L in\r\n for i = 0 to n - 1 do\r\n a.(i) <- scan_lint()\r\n done;\r\n Array.sort compare a;\r\n let d = Array.make (n - 1) 0L in\r\n for i = 0 to n - 2 do\r\n d.(i) <- Int64.sub a.(i + 1) a.(i)\r\n done;\r\n Array.sort compare d;\r\n let ans = ref n in\r\n for i = 0 to Array.length d - 1 do\r\n if d.(i) <= x then\r\n ans := !ans - 1\r\n else if !k > 0L then\r\n let di = Int64.sub d.(i) 1L in\r\n let c = Int64.div di x in\r\n let ok = !k >= c in\r\n if ok then k := (Int64.sub !k c);\r\n if ok then ans := !ans - 1;\r\n done;\r\n Printf.printf \"%d\\n\" !ans;;"}, {"source_code": "open Int64;;\r\nopen Array;;\r\nlet merge a b =\r\n let n = length a in\r\n let m = length b in\r\n let ret = make (n+m) 0L in\r\n let i = ref 0 in\r\n let j = ref 0 in\r\n let who = ref false in\r\n let ptr = ref 0 in\r\n while !ptr < (n+m) do\r\n let () = \r\n if !i < n then \r\n if !j < m then who := a.(!i) < b.(!j) \r\n else who := true\r\n else who := false in\r\n let () = \r\n if !who = true then ret.(!ptr) <- a.(!i)\r\n else ret.(!ptr) <- b.(!j) in\r\n let () = \r\n if !who = true then i := !i + 1\r\n else j := !j + 1 in\r\n ptr := !ptr + 1\r\n done; \r\n ret;; \r\nlet rec merge_sort a = \r\n if (length a) = 1 then a\r\n else \r\n let l = init ((length a + 1) / 2) (fun i -> a.(i)) in\r\n let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in\r\n merge (merge_sort l) (merge_sort r);;\r\nlet readLong () = Scanf.scanf \" %Ld\" (fun i -> i);;\r\nlet print_number x = print_string (to_string x);;\r\nlet n = readLong() in\r\nlet k = ref (readLong()) in\r\nlet x = readLong() in\r\nlet a = Array.init (to_int n) (fun i -> readLong()) in\r\nif n = 1L then print_number n \r\nelse\r\n let sorted = merge_sort a in\r\n let cost = make (to_int n-1) 0L in\r\n let () = \r\n for i = 1 to (length a - 1) do\r\n let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in\r\n if cost.(i-1) < 0L then cost.(i-1) <- 0L\r\n done in\r\n let sorted_cost = merge_sort cost in\r\n let answer = ref 1L in\r\n let () = \r\n for i = 0 to (length cost - 1) do\r\n if !k >= sorted_cost.(i) then\r\n k := Int64.sub !k sorted_cost.(i)\r\n else\r\n answer := Int64.add !answer 1L\r\n done in\r\n print_number !answer;;"}], "negative_code": [{"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x)\r\nlet scan_lint () = Scanf.scanf \" %Ld\" (fun x -> x)\r\nlet n = scan_int()\r\nlet k = ref (scan_lint())\r\nlet x = scan_lint()\r\n\r\nlet () =\r\n let a = Array.make n 0L in\r\n for i = 0 to n - 1 do\r\n a.(i) <- scan_lint()\r\n done;\r\n let b = List.sort compare (Array.to_list a) in\r\n let d = Array.make (n - 1) 0L in\r\n for i = 1 to n - 2 do\r\n d.(i) <- Int64.sub (List.nth b i) (List.nth b (i - 1))\r\n done;\r\n let d = List.sort compare (Array.to_list d) in\r\n let ans = ref n in\r\n for i = 0 to List.length d - 1 do\r\n if (List.nth d i) <= x then\r\n ans := !ans - 1\r\n else if !k > 0L then\r\n let di = Int64.sub (List.nth d i) 1L in\r\n let c = Int64.div di x in\r\n let ok = !k >= c in\r\n if ok then k := (Int64.sub !k c);\r\n if ok then ans := !ans - 1;\r\n done;\r\n Printf.printf \"%d\\n\" !ans;;"}, {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x)\r\nlet scan_lint () = Scanf.scanf \" %Ld\" (fun x -> x)\r\nlet rec init n =\r\n if n = 0 then []\r\n else scan_lint() :: (init (n - 1))\r\nlet rec cal_diff l pos =\r\n if pos = List.length l then []\r\n else if pos = 0 then\r\n cal_diff l (pos + 1)\r\n else Int64.sub (List.nth l pos) (List.nth l (pos - 1)) :: cal_diff l (pos + 1)\r\nlet get_diff l = let sl = List.fast_sort compare l in List.sort compare (cal_diff sl 0)\r\nlet n = scan_int()\r\nlet k = ref (scan_lint())\r\nlet x = scan_lint()\r\nlet d = get_diff (init n)\r\n\r\nlet () =\r\n let ans = ref n in\r\n for i = 0 to List.length d - 1 do\r\n if (List.nth d i) <= x then\r\n ans := !ans - 1\r\n else\r\n let c = Int64.div (List.nth d i) x in\r\n let ok = !k >= c in\r\n if ok then k := (Int64.sub !k c);\r\n if ok then ans := !ans - 1;\r\n done;\r\n Printf.printf \"%d\\n\" !ans;;"}, {"source_code": "\r\nopen Int64;;\r\nopen Array;;\r\nlet size = 1000;;\r\nlet s = Bytes.create size;;\r\nlet pos = ref 0;;\r\nlet ptr = ref 0;;\r\nlet read cnt = \r\n if !pos + cnt < size then\r\n let () = pos := !pos + (input stdin s !pos cnt) in\r\n true\r\n else\r\n false;;\r\nlet restart() =\r\n let () = \r\n for i = 1 to !pos - !ptr do\r\n Bytes.set s (i - 1) (Bytes.get s (i + !ptr)) \r\n done in\r\n let () = \r\n pos := !pos - !ptr in\r\n ptr := 0;;\r\nlet da x = ();;\r\nlet is_digit c = \r\n if (int_of_char c) >= (int_of_char '0') \r\n then if (int_of_char c) <= (int_of_char '9') then true\r\n else false\r\n else false;;\r\nlet digit c = (int_of_char c) - (int_of_char '0');;\r\nlet digitInt64 c = of_int(digit c);;\r\nlet readLine() = input_line stdin;;\r\nlet print_number x = print_string (to_string x ^ \" \");;\r\nlet print_char c = print_string (Char.escaped c);;\r\nlet check_reader() = \r\n let () = \r\n if !pos < size then da (read (size - !pos - 1)) in\r\n if !ptr >= 980 then restart();;\r\nlet skip() = \r\n let () = check_reader() in\r\n let quit_loop = ref false in\r\n while not !quit_loop do\r\n let c = Bytes.get s !ptr in\r\n let () = \r\n if is_digit c then quit_loop := true\r\n else ptr := !ptr + 1 in check_reader()\r\n done;;\r\nlet readLong() =\r\n let () = skip() in\r\n let quit_loop = ref false in \r\n let number = ref 0L in\r\n let () = \r\n while not !quit_loop do\r\n let c = Bytes.get s !ptr in\r\n if is_digit c then \r\n let () = number := add (mul !number 10L) (digitInt64 c) in\r\n ptr := !ptr + 1\r\n else\r\n quit_loop := true\r\n done in\r\n !number;;\r\nlet merge a b =\r\n let n = length a in\r\n let m = length b in\r\n let ret = make (n+m) 0L in\r\n let i = ref 0 in\r\n let j = ref 0 in\r\n let who = ref false in\r\n let ptr = ref 0 in\r\n while !ptr < (n+m) do\r\n let () = \r\n if !i < n then \r\n if !j < m then who := a.(!i) < b.(!j) \r\n else who := true\r\n else who := false in\r\n let () = \r\n if !who = true then ret.(!ptr) <- a.(!i)\r\n else ret.(!ptr) <- b.(!j) in\r\n let () = \r\n if !who = true then i := !i + 1\r\n else j := !j + 1 in\r\n ptr := !ptr + 1\r\n done; \r\n ret;; \r\nlet rec merge_sort a = \r\n if (length a) = 1 then a\r\n else \r\n let l = init ((length a + 1) / 2) (fun i -> a.(i)) in\r\n let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in\r\n merge (merge_sort l) (merge_sort r);;\r\nlet n = readLong() in\r\nlet k = ref (readLong()) in\r\nlet x = readLong() in\r\nlet a = Array.init (to_int n) (fun i -> readLong()) in\r\nif n = 1L then print_number n \r\nelse\r\n let sorted = merge_sort a in\r\n let cost = make (to_int n-1) 0L in\r\n let () = \r\n for i = 1 to (length a - 1) do\r\n let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in\r\n if cost.(i-1) < 0L then cost.(i-1) <- 0L\r\n done in\r\n let sorted_cost = merge_sort cost in\r\n let answer = ref 1L in\r\n let () = \r\n for i = 0 to (length cost - 1) do\r\n if !k >= sorted_cost.(i) then\r\n k := Int64.sub !k sorted_cost.(i)\r\n else\r\n answer := Int64.add !answer 1L\r\n done in\r\n print_number !answer;;"}, {"source_code": "\r\nopen Int64;;\r\nopen Array;;\r\nlet size = 1000;;\r\nlet s = Bytes.create size;;\r\nlet pos = ref 0;;\r\nlet ptr = ref 0;;\r\nlet read cnt = \r\n if !pos + cnt < size then\r\n let nums = (input stdin s !pos cnt) in\r\n let () = pos := !pos + nums in\r\n true\r\n else\r\n false;;\r\nlet restart() =\r\n let () = \r\n for i = 1 to !pos - !ptr do\r\n Bytes.set s (i - 1) (Bytes.get s (i + !ptr)) \r\n done in\r\n let () = \r\n pos := !pos - !ptr in\r\n ptr := 0;;\r\nlet da x = ();;\r\nlet is_digit c = \r\n if (int_of_char c) >= (int_of_char '0') \r\n then if (int_of_char c) <= (int_of_char '9') then true\r\n else false\r\n else false;;\r\nlet digit c = (int_of_char c) - (int_of_char '0');;\r\nlet digitInt64 c = of_int(digit c);;\r\nlet readLine() = input_line stdin;;\r\nlet print_number x = print_string (to_string x ^ \" \");;\r\nlet print_char c = print_string (Char.escaped c);;\r\nlet check_reader() = \r\n let () = \r\n if !pos < size then da (read (size - !pos - 1)) in\r\n if !ptr >= 980 then restart();;\r\nlet skip() = \r\n let quit_loop = ref false in\r\n while not !quit_loop do\r\n let c = Bytes.get s !ptr in\r\n if is_digit c then quit_loop := true\r\n else ptr := !ptr + 1\r\n done;;\r\nlet readInt() = \r\n let () = check_reader() in\r\n let () = skip() in\r\n let quit_loop = ref false in \r\n let number = ref 0 in\r\n let () = \r\n while not !quit_loop do\r\n let c = Bytes.get s !ptr in\r\n if is_digit c then \r\n let () = number := !number * 10 + (digit c) in\r\n ptr := !ptr + 1\r\n else\r\n quit_loop := true\r\n done in\r\n !number;;\r\nlet readLong() =\r\n let () = check_reader() in\r\n let () = skip() in\r\n let quit_loop = ref false in \r\n let number = ref 0L in\r\n let () = \r\n while not !quit_loop do\r\n let c = Bytes.get s !ptr in\r\n if is_digit c then \r\n let () = number := add (mul !number 10L) (digitInt64 c) in\r\n ptr := !ptr + 1\r\n else\r\n quit_loop := true\r\n done in\r\n !number;;\r\nlet merge a b =\r\n let n = length a in\r\n let m = length b in\r\n let ret = make (n+m) 0L in\r\n let i = ref 0 in\r\n let j = ref 0 in\r\n let who = ref false in\r\n let ptr = ref 0 in\r\n while !ptr < (n+m) do\r\n let () = \r\n if !i < n then \r\n if !j < m then who := a.(!i) < b.(!j) \r\n else who := true\r\n else who := false in\r\n let () = \r\n if !who = true then ret.(!ptr) <- a.(!i)\r\n else ret.(!ptr) <- b.(!j) in\r\n let () = \r\n if !who = true then i := !i + 1\r\n else j := !j + 1 in\r\n ptr := !ptr + 1\r\n done; \r\n ret;; \r\nlet rec merge_sort a = \r\n if (length a) = 1 then a\r\n else \r\n let l = init ((length a + 1) / 2) (fun i -> a.(i)) in\r\n let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in\r\n merge (merge_sort l) (merge_sort r);;\r\nlet n = readLong() in\r\nlet k = ref (readLong()) in\r\nlet x = readLong() in\r\nlet a = Array.init (to_int n) (fun i -> readLong()) in\r\nif n = 1L then print_number n \r\nelse\r\n let sorted = merge_sort a in\r\n let cost = make (to_int n-1) 0L in\r\n let () = \r\n for i = 1 to (length a - 1) do\r\n let () = cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x) in\r\n if cost.(i-1) < 0L then cost.(i-1) <- 0L\r\n done in\r\n let sorted_cost = merge_sort cost in\r\n let answer = ref 1L in\r\n let () = \r\n for i = 0 to (length cost - 1) do\r\n if !k >= sorted_cost.(i) then\r\n k := Int64.sub !k sorted_cost.(i)\r\n else\r\n answer := Int64.add !answer 1L\r\n done in\r\n print_number !answer;;"}, {"source_code": "open Int64;;\r\nopen Array;;\r\nlet merge a b =\r\n let n = length a in\r\n let m = length b in\r\n let ret = make (n+m) 0L in\r\n let i = ref 0 in\r\n let j = ref 0 in\r\n let who = ref false in\r\n let ptr = ref 0 in\r\n while !ptr < (n+m) do\r\n let () = \r\n if !i < n then \r\n if !j < m then who := a.(!i) < b.(!j) \r\n else who := true\r\n else who := false in\r\n let () = \r\n if !who = true then ret.(!ptr) <- a.(!i)\r\n else ret.(!ptr) <- b.(!j) in\r\n let () = \r\n if !who = true then i := !i + 1\r\n else j := !j + 1 in\r\n ptr := !ptr + 1\r\n done; \r\n ret;; \r\nlet rec merge_sort a = \r\n if (length a) = 1 then a\r\n else \r\n let l = init ((length a + 1) / 2) (fun i -> a.(i)) in\r\n let r = init ((length a) / 2) (fun i -> a.(i + (length a + 1) / 2)) in\r\n merge (merge_sort l) (merge_sort r);;\r\nlet readLong () = Scanf.scanf \" %Ld\" (fun i -> i);;\r\nlet print_number x = print_string (to_string x);;\r\nlet n = readLong();;\r\nlet k = ref (readLong());;\r\nlet x = readLong();;\r\nlet a = Array.init (to_int n) (fun i -> readLong())\r\nlet sorted = merge_sort a;;\r\nlet cost = make (to_int n-1) 0L;; \r\nfor i = 1 to (length a - 1) do\r\n cost.(i-1) <- (Int64.div(Int64.sub(Int64.sub sorted.(i) sorted.(i-1)) 1L) x)\r\ndone;;\r\nlet sorted_cost = merge_sort cost;;\r\nlet answer = ref 1L;;\r\nfor i = 0 to (length cost - 1) do\r\n if !k >= sorted_cost.(i) then\r\n k := Int64.sub !k sorted_cost.(i)\r\n else\r\n answer := Int64.add !answer 1L\r\ndone;;\r\nprint_number !answer;;"}], "src_uid": "c6c07ef23cf2def9f99cbfb6076c9810"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\n\nlet () = \n let (n,k) = read_pair() in\n let best = ref 0 in\n for i=0 to n-1 do\n let (f,t) = read_pair() in\n let score = if t > k then f - (t-k) else f in\n\tif score > !best || i=0 then best := score\n done;\n Printf.printf \"%d\\n\" !best\n", "positive_code": [{"source_code": "open 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 n = gr();;\nlet k = gr();;\nlet optv = ref (- 1001000000);;\n\nlet main() = \n\tbegin\n\t\tfor i = 1 to n do\n\t\t\t\tlet f = gr () in\n\t\t\t\tlet t = gr () in\n\t\t\t\tlet v = if t > k then f - (t-k) else f in\n\t\t\t\tif v > !optv then\n\t\t\t\t\toptv := v\n\t\tdone;\n\t\tprint_int !optv; print_newline ()\n\tend;;\n\nmain();;"}], "negative_code": [], "src_uid": "1bb5b64657e16fb518d49d3c799d4823"} {"source_code": "let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib \" %Ld\" (fun x -> x)\nlet read_str _ = Scanf.bscanf Scanf.Scanning.stdib \" %s\" (fun x -> x)\nlet (|>) x f = f x\nlet flip f x y = f y x\n\nopen Int64\n\nlet ( ++ ) = add\nlet ( -- ) = sub\nlet ( ** ) = mul\nlet ( // ) = div\nlet ( %% ) = rem\n\nlet phi x =\n let rec go acc x i =\n if i**i > x then\n acc, x\n else if x%%i = 0L then\n let rec go2 x =\n if x%%i <> 0L then\n x\n else\n go2 (x//i)\n in\n go (acc--acc//i) (go2 x) (i++1L)\n else\n go acc x (i++1L)\n in\n let r,x = go x x 2L in\n if x > 1L then\n r--r//x\n else\n r\n\nlet f a p =\n let rec go acc i =\n if i >= String.length a then\n acc\n else\n let acc' = (acc**10L ++ (int_of_char a.[i] - 48 |> of_int)) %%p in\n go acc' (i+1)\n in\n go 0L 0\n\nlet powmod a n p =\n let rec go r a n =\n if n = 0L then\n r\n else if logand n 1L <> 0L then\n go (r**a%%p) (a**a%%p) (n//2L)\n else\n go r (a**a%%p) (n//2L)\n in\n go 1L a n\n\nlet () =\n let bb = read_str 0 in\n let nn = read_str 0 in\n let c = read_int64 0 in\n let phi_c = phi c in\n\n let b = f bb c in\n let n = if String.length nn >= 10 then\n f nn phi_c ++ phi_c\n else\n let n = of_string nn in\n if n--1L >= phi_c then\n n%%phi_c++phi_c\n else\n n\n in\n powmod b (n--1L) c ** (b++c--1L) %% c\n |> (fun x -> if x = 0L then c else x)\n |> Printf.printf \"%Ld\\n\"\n", "positive_code": [{"source_code": "let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib \" %Ld\" (fun x -> x)\nlet read_str _ = Scanf.bscanf Scanf.Scanning.stdib \" %s\" (fun x -> x)\nlet (|>) x f = f x\nlet flip f x y = f y x\n\nopen Int64\n\nlet ( ++ ) = add\nlet ( -- ) = sub\nlet ( ** ) = mul\nlet ( // ) = div\nlet ( %% ) = rem\n\nlet phi x =\n let rec go acc x i =\n if i**i > x then\n acc, x\n else if x%%i = 0L then\n let rec go2 x =\n if x%%i <> 0L then\n x\n else\n go2 (x//i)\n in\n go (acc--acc//i) (go2 x) (i++1L)\n else\n go acc x (i++1L)\n in\n let r,x = go x x 2L in\n if x > 1L then\n r--r//x\n else\n r\n\nlet f a p =\n let rec go acc i =\n if i >= String.length a then\n acc\n else\n let acc' = (acc**10L ++ (int_of_char a.[i] - 48 |> of_int)) %%p in\n go acc' (i+1)\n in\n go 0L 0\n\nlet powmod a n p =\n let rec go r a n =\n if n = 0L then\n r\n else if logand n 1L <> 0L then\n go (r**a%%p) (a**a%%p) (n//2L)\n else\n go r (a**a%%p) (n//2L)\n in\n go 1L a n\n\nlet () =\n let bb = read_str 0 in\n let nn = read_str 0 in\n let c = read_int64 0 in\n let phi_c = phi c in\n\n let b = f bb c in\n let n = if String.length nn >= 10 then\n f nn phi_c ++ phi_c\n else\n let n = of_string nn in\n if n--1L >= phi_c then\n n%%phi_c++phi_c\n else\n n\n in\n powmod b (n--1L) c ** (b++c--1L) %% c\n |> (fun x -> if x = 0L then c else x)\n |> Printf.printf \"%Ld\\n\""}], "negative_code": [{"source_code": "let read_int64 _ = Scanf.bscanf Scanf.Scanning.stdib \" %Ld\" (fun x -> x)\nlet read_str _ = Scanf.bscanf Scanf.Scanning.stdib \" %s\" (fun x -> x)\nlet (|>) x f = f x\nlet flip f x y = f y x\n\nopen Int64\n\nlet ( ++ ) = add\nlet ( -- ) = sub\nlet ( ** ) = mul\nlet ( // ) = div\nlet ( %% ) = rem\n\nlet phi x =\n let rec go acc x i =\n if i**i > x then\n acc, x\n else if x%%i = 0L then\n let rec go2 x =\n if x%%i <> 0L then\n x\n else\n go2 (x//i)\n in\n go (acc--acc//i) (go2 x) (i++1L)\n else\n go acc x (i++1L)\n in\n let r,x = go x x 2L in\n if x > 1L then\n r--r//x\n else\n r\n\nlet f a p =\n let rec go acc i =\n if i >= String.length a then\n acc\n else\n let acc' = (acc**10L ++ (int_of_char a.[i] - 48 |> of_int)) %%p in\n go acc' (i+1)\n in\n go 0L 0\n\nlet powmod a n p =\n let rec go r a n =\n if n = 0L then\n r\n else if logand n 1L <> 0L then\n go (r**a%%p) (a**a%%p) (n//2L)\n else\n go r (a**a%%p) (n//2L)\n in\n go 1L a n\n\nlet () =\n let bb = read_str 0 in\n let nn = read_str 0 in\n let c = read_int64 0 in\n let phi_c = phi c in\n\n let b = f bb c in\n let b1 = b++c--1L in\n let n = f nn phi_c in\n let n1 = n++phi_c--1L in\n powmod b n1 c ** b1 %% c\n |> (fun x -> if x = 0L then c else x)\n |> Printf.printf \"%Ld\\n\"\n"}], "src_uid": "566adc43d2d6df257c26c5f5495a5745"} {"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.0\n\nlet comp x = 1.0 -. x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float () = bscanf Scanning.stdib \" %f \" (fun x -> x) \n\nlet () = \n let n = read_int () in\n let h = read_int () in\n let pl = read_float () in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n\n let pr = comp pl in\n\n let topple_left = Array.make n 0 in\n (* topple_left.(i) is the furthest one to the left that topples\n as a result of toppling i to the left *)\n let topple_right = Array.make n (n-1) in\n\n for i=1 to n-1 do\n topple_left.(i) <- if x.(i) - x.(i-1) < h then topple_left.(i-1) else i;\n let j = n-1-i in\n topple_right.(j) <- if x.(j+1) - x.(j) < h then topple_right.(j+1) else j; \n done;\n\n let p = Array.make_matrix n (4*n) 0.0 in\n (* p.(i).(j).(lfalldir).(rfalldir) is the probability of the situation\n where the upright trees are [i,j] and the one to the left of this\n fell in direction lfalldir (0=left, 1=right) and the one to the\n right fell in rfalldir. *)\n\n let int = Array.make ((n+1)*4) 0.0 in\n (* represents the interval (numbered starting from 0 on the left)\n Stores the probability for each of the four ways the interval\n can be resolved. Actually, for short intervals only the \n resolution (0,1) i.e. (left, right) is used *)\n \n let inc i j ldir rdir x =\n if i <= j then\n let ind = 4*j + 2*ldir + rdir in\n p.(i).(ind) <- x +. p.(i).(ind)\n in\n\n let incx i ldir rdir x =\n let ind = 4*i + 2*ldir + rdir in\n int.(ind) <- x +. int.(ind)\n in\n\n let geti i ldir rdir = int.(4*i + 2*ldir + rdir) in\n let getp i j ldir rdir = p.(i).(4*j + 2*ldir + rdir) in \n\n inc 0 (n-1) 0 1 1.0;\n\n for d=n-1 downto 0 do\n for i=0 to n-1-d do\n let j = i+d in\n for ldir = 0 to 1 do\n\tfor rdir = 0 to 1 do\n\t let pstate = getp i j ldir rdir in\n\t let xl = pstate *. 0.5 *. pl in\n\t let xr = pstate *. 0.5 *. pr in\n\t (* i falls to the left *)\n\t inc (i+1) j 0 rdir xl;\n\t incx i ldir 0 xl;\n\t if i=j then incx (j+1) 0 rdir xl;\n\t (* j falls to the right *)\n\t inc i (j-1) ldir 1 xr;\n\t incx (j+1) 1 rdir xr;\n\t if i=j then incx i ldir 1 xr;\n\t (* i falls to the right *)\n\t inc (topple_right.(i)+1) j 1 rdir xr;\n\t incx i ldir 1 xr;\n\t if topple_right.(i) >= j then incx (j+1) 1 rdir xr;\n\t (* j falls to the left *)\n\t inc i (topple_left.(j)-1) ldir 0 xl;\n\t incx (j+1) 0 rdir xl;\n\t if topple_left.(j) <= i then incx i ldir 0 xl;\t \n\tdone\n done\n done\n done;\n\n let evaluate_gap i =\n let d = if i=0 || i=n then h else x.(i) - x.(i-1) in\n if d < h then\n (comp (geti i 0 1)) *. (float d)\n else\n (geti i 1 0) *. (float (min d (2*h))) +. ((geti i 0 0) +. (geti i 1 1)) *. (float h)\n in\n\n printf \"%1.9f\\n\" (sum 0 n evaluate_gap)\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac +. (f i))\nlet comp x = 1.0 -. x\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float () = bscanf Scanning.stdib \" %f \" (fun x -> x) \n\nlet () = \n let n = read_int () in\n let h = read_int () in\n let pl = read_float () in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n\n let pr = comp pl in\n\n let topple_left = Array.make n 0 in\n let topple_right = Array.make n (n-1) in\n\n for i=1 to n-1 do\n topple_left.(i) <- if x.(i) - x.(i-1) < h then topple_left.(i-1) else i;\n let j = n-1-i in\n topple_right.(j) <- if x.(j+1) - x.(j) < h then topple_right.(j+1) else j; \n done;\n\n let p = Array.make_matrix n (4*n) 0.0 in\n let int = Array.make ((n+1)*4) 0.0 in\n let inc i j ldir rdir x =\n if i <= j then\n let ind = 4*j + 2*ldir + rdir in\n p.(i).(ind) <- x +. p.(i).(ind)\n in\n\n let incx i ldir rdir x =\n let ind = 4*i + 2*ldir + rdir in\n int.(ind) <- x +. int.(ind)\n in\n\n let geti i ldir rdir = int.(4*i + 2*ldir + rdir) in\n let getp i j ldir rdir = p.(i).(4*j + 2*ldir + rdir) in \n\n inc 0 (n-1) 0 1 1.0;\n\n for i=0 to n-1 do\n for j=n-1 downto i do\n for ldir = 0 to 1 do\n for rdir = 0 to 1 do\n let pstate = getp i j ldir rdir in\n let xl = pstate *. 0.5 *. pl in\n let xr = pstate *. 0.5 *. pr in\n inc (i+1) j 0 rdir xl;\n incx i ldir 0 xl;\n if i=j then incx (j+1) 0 rdir xl;\n inc i (j-1) ldir 1 xr;\n incx (j+1) 1 rdir xr;\n if i=j then incx i ldir 1 xr;\n inc (topple_right.(i)+1) j 1 rdir xr;\n incx i ldir 1 xr;\n if topple_right.(i) >= j then incx (j+1) 1 rdir xr;\n inc i (topple_left.(j)-1) ldir 0 xl;\n incx (j+1) 0 rdir xl;\n if topple_left.(j) <= i then incx i ldir 0 xl; \n done\n done\n done\n done;\n\n let evaluate_gap i =\n let d = if i=0 || i=n then h else x.(i) - x.(i-1) in\n if d < h then\n (comp (geti i 0 1)) *. (float d)\n else\n (geti i 1 0) *. (float (min d (2*h))) +. ((geti i 0 0) +. (geti i 1 1)) *. (float h)\n in\n\n printf \"%1.9f\\n\" (sum 0 n evaluate_gap 0.0)"}, {"source_code": "open Printf\nopen Scanf\n\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac +. (f i))\nlet comp x = 1.0 -. x\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float () = bscanf Scanning.stdib \" %f \" (fun x -> x) \n\nlet () = \n let n = read_int () in\n let h = read_int () in\n let pl = read_float () in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n\n let pr = comp pl in\n\n let topple_left = Array.make n 0 in\n let topple_right = Array.make n (n-1) in\n\n for i=1 to n-1 do\n topple_left.(i) <- if x.(i) - x.(i-1) < h then topple_left.(i-1) else i;\n let j = n-1-i in\n topple_right.(j) <- if x.(j+1) - x.(j) < h then topple_right.(j+1) else j; \n done;\n\n let p = Array.make_matrix n (4*n) 0.0 in\n let int = Array.make ((n+1)*4) 0.0 in\n let inc i j ldir rdir x =\n if i <= j then\n let ind = 4*j + 2*ldir + rdir in\n p.(i).(ind) <- x +. p.(i).(ind)\n in\n\n let incx i ldir rdir x =\n let ind = 4*i + 2*ldir + rdir in\n int.(ind) <- x +. int.(ind)\n in\n\n let geti i ldir rdir = int.(4*i + 2*ldir + rdir) in\n let getp i j ldir rdir = p.(i).(4*j + 2*ldir + rdir) in \n\n inc 0 (n-1) 0 1 1.0;\n\n for i=0 to n-1 do\n for j=n-1 downto i do\n for ldir = 0 to 1 do\n\tfor rdir = 0 to 1 do\n\t let pstate = getp i j ldir rdir in\n\t let xl = pstate *. 0.5 *. pl in\n\t let xr = pstate *. 0.5 *. pr in\n\t inc (i+1) j 0 rdir xl;\n\t incx i ldir 0 xl;\n\t if i=j then incx (j+1) 0 rdir xl;\n\t inc i (j-1) ldir 1 xr;\n\t incx (j+1) 1 rdir xr;\n\t if i=j then incx i ldir 1 xr;\n\t inc (topple_right.(i)+1) j 1 rdir xr;\n\t incx i ldir 1 xr;\n\t if topple_right.(i) >= j then incx (j+1) 1 rdir xr;\n\t inc i (topple_left.(j)-1) ldir 0 xl;\n\t incx (j+1) 0 rdir xl;\n\t if topple_left.(j) <= i then incx i ldir 0 xl;\t \n\tdone\n done\n done\n done;\n\n let evaluate_gap i =\n let d = if i=0 || i=n then h else x.(i) - x.(i-1) in\n if d < h then\n (comp (geti i 0 1)) *. (float d)\n else\n (geti i 1 0) *. (float (min d (2*h))) +. ((geti i 0 0) +. (geti i 1 1)) *. (float h)\n in\n\n printf \"%1.9f\\n\" (sum 0 n evaluate_gap 0.0)\n"}], "negative_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.0\n\nlet comp x = 1.0 -. x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float () = bscanf Scanning.stdib \" %f \" (fun x -> x) \n\nlet () = \n let n = read_int () in\n let h = read_int () in\n let pr = read_float () in\n let x = Array.init n (fun _ -> read_int()) in\n Array.sort compare x;\n\n let g = Array.make_matrix (n+1) (n+1) (-1.0) in\n (* g.(a).(b) is the probability that an interval with\n a trees on the left and b trees on the right survives. *)\n\n let pl = comp pr in\n \n g.(0).(1) <- pr;\n g.(1).(0) <- pl;\n g.(0).(0) <- 1.0;\n \n let rec compg a b =\n if g.(a).(b) >= 0.0 then g.(a).(b) else\n let answer = match (a,b) with\n\t| (0,_) -> 0.5 *. (pr *. (compg 0 (b-1)) +. pr)\n\t| (_,0) -> 0.5 *. (pl *. (compg (a-1) 0) +. pl)\n\t| (_,_) -> 0.5 *. (pl *. (compg (a-1) b) +. pr *. (compg a (b-1)))\n in\n g.(a).(b) <- answer;\n answer\n in\n\n let rec find_blocks i j ac = if j=n-1 then (i,j)::ac else\n (* i....j is an initial part of a block *)\n if x.(j+1) < h + x.(j)\n then find_blocks i (j+1) ac\n else find_blocks (j+1) (j+1) ((i,j)::ac)\n in\n\n let block = Array.of_list (List.rev (find_blocks 0 0 [])) in\n let nb = Array.length block in\n\n (*\n for i=0 to nb-1 do\n printf \"block: (%d,%d) \" (fst block.(i)) (snd block.(i))\n done;\n print_newline();\n\n for a=0 to n do\n for b=0 to n-a do\n printf \"g.(%d).(%d) = %f\\n\" a b (compg a b)\n done\n done;\n *)\n let e_internal_coverage (i,j) =\n sum (i+1) j (fun k ->\n let len = float (x.(k) - x.(k-1)) in\n len *. (comp (compg (k-i) (j+1-k)))\n )\n in\n\n let e_total_coverage =\n sum 0 (nb-1) (fun k -> e_internal_coverage block.(k))\n in\n\n let e_boundary_coverage =\n sum 1 (nb-1) (fun k ->\n let (i,j) = block.(k) in\n let (i',j') = block.(k-1) in\n let lp = comp (compg 0 (j-i+1)) in\n let rp = comp (compg (j'-i'+1) 0) in\n lp *. rp *. (float (min (x.(i) - x.(j')) (2*h))) +.\n\t(comp lp) *. rp *. (float h) +.\n\tlp *. (comp rp) *. (float h)\n )\n in\n\n let e_ends =\n let (i,j) = block.(0) in\n let e_left_end = (comp (compg 0 (j-i+1))) *. (float h) in\n let (i,j) = block.(nb-1) in \n let e_right_end = (comp (compg (j-i+1) 0)) *. (float h) in\n e_left_end +. e_right_end\n in\n\n let answer = e_total_coverage +. e_boundary_coverage +. e_ends in\n\n printf \"%1.9f\\n\" answer\n"}], "src_uid": "c08d8313fccb1f5fa291bb4945747843"} {"source_code": "open String\nopen Printf\nopen Scanf\nlet solve : (string -> int * int) = function\n | str when (not (contains str 'L')) -> (index str 'R' + 1, rindex str 'R' + 2)\n | str when (not (contains str 'R')) -> (rindex str 'L' + 1, index str 'L')\n | str -> (index str 'R' + 1, rindex str 'R' + 1);;\nlet (s,t) = scanf \"%d %s\" (fun _ -> solve);;\nPrintf.printf \"%d %d\\n\" s t\n", "positive_code": [{"source_code": "open String\nopen Printf\nopen Scanf\nlet solve : (string -> int * int) = function\n | str when not (contains str 'L') -> index str 'R' + 1, rindex str 'R' + 2\n | str when not (contains str 'R') -> rindex str 'L' + 1, index str 'L'\n | str -> index str 'R' + 1, rindex str 'R' + 1;;\nlet s,t = scanf \"%d %s\" (fun _ -> solve);;\nprintf \"%d %d\\n\" s t\n"}], "negative_code": [], "src_uid": "3053cba2426ebd113fcd70a9b026dad0"} {"source_code": "let ( ++ ) = Int64.add\nlet ( %% ) = Int64.rem\nlet zero = Int64.zero\nlet two = Int64.of_int 2\n\nlet read () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_l () = Scanf.scanf \"%Ld \" (fun n -> n)\nlet print int = Printf.printf \"%Ld\\n\" int\n\nlet input () = \n let n = read () in\n let rec loop i even odd =\n if i < n\n then\n let int = read_l () in\n if int %% two = zero\n then\n loop (i + 1) (int :: even) odd\n else\n loop (i + 1) even (int :: odd)\n else\n (even, odd)\n in loop 0 [] []\n\nlet get_sum list =\n let l = List.length list in\n if l <= 1\n then\n zero\n else\n if l mod 2 = 0\n then\n List.fold_left (fun acc n -> acc ++ n) zero list\n else\n List.fold_left (fun acc n -> acc ++ n) zero (List.tl list) \n\nlet solve (even, odd)=\n let odd_sorted = List.sort (Pervasives.compare) odd in\n let sum_even = List.fold_left (fun acc n -> acc ++ n) zero even in\n let sum_odd = get_sum odd_sorted in\n sum_even ++ sum_odd\n\nlet () = print (solve (input ()))", "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\nlet long x = Int64.of_int x\n\nlet rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)\nlet rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))\nlet minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n \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 _ -> long(read_int())) in\n\n let total = sum 0 (n-1) (fun i -> a.(i)) 0L in\n\n let inf = Int64.max_int in\n\n let is_odd x = x%% 2L = 1L in\n \n let min_odd = minf 0 (n-1) (fun i -> if is_odd a.(i) then a.(i) else inf) in\n\n let answer = if not (is_odd total) then total else total -- min_odd in\n\n printf \"%Ld\\n\" answer\n"}], "negative_code": [], "src_uid": "adb66b7b22d70bb37cb625d531d8865f"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let n = String.length s in\n let a = Array.make n 0 in\n let pos = ref 0 in\n let push x =\n a.(!pos) <- x;\n incr pos\n in\n let res = ref 0 in\n let pop x =\n if !pos <= 0 then (\n Printf.printf \"Impossible\\n\";\n exit 0;\n );\n if a.(!pos - 1) <> x\n then incr res;\n decr pos;\n in\n for i = 0 to n - 1 do\n let c = s.[i] in\n\tmatch c with\n\t | '(' -> push 0\n\t | '{' -> push 1\n\t | '<' -> push 2\n\t | '[' -> push 3\n\t | ')' -> pop 0\n\t | '}' -> pop 1\n\t | '>' -> pop 2\n\t | ']' -> pop 3\n\t | _ -> assert false\n done;\n if !pos <> 0\n then Printf.printf \"Impossible\\n\"\n else Printf.printf \"%d\\n\" !res\n", "positive_code": [{"source_code": "open Printf\n\nlet rec over a b f k =\n if a >= b then k\n else over (a + 1) b f (f a k)\n\nlet group = function\n | '[' | ']' -> 0\n | '(' | ')' -> 1\n | '<' | '>' -> 2\n | '{' | '}' -> 3\n | _ -> assert false\n\nlet () =\n let s = input_line stdin in\n let x =\n over 0 (String.length s) (fun i x ->\n match s.[i], x with\n | _, None ->\n None\n | ('[' | '<' | '(' | '{'), Some (n, q) ->\n Some (n, group s.[i] :: q)\n | r, Some (n, []) -> \n None\n | r, Some (n, t :: ts) when group r = t ->\n Some (n, ts)\n | r, Some (n, t :: ts) when group r <> t ->\n Some ((n + 1), ts)\n | _ -> assert false\n ) (Some (0, []))\n in\n match x with\n | None -> printf \"Impossible\\n\"\n | Some (_, _ :: _) -> printf \"Impossible\\n\"\n | Some (n, []) -> printf \"%d\\n\" n\n"}], "negative_code": [], "src_uid": "4147fef7a151c52e92c010915b12c06b"} {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x)\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\nlet () =\n let n = read_int() in\n let k = read_long() in\n let a = Array.init n (fun _ -> read_long()) in\n\n let () = Array.sort compare a in\n\n let h = Hashtbl.create 100 in\n\n let () = \n for i=0 to n-1 do\n Hashtbl.add h a.(i) false\n done in\n\n let rec mark_chain x i = \n if Hashtbl.mem h x then (\n if Hashtbl.find h x then 0 else (\n\tHashtbl.replace h x true;\n\tmark_chain (x ** k) (i+1)\n )\n ) else i\n in\n \n let count = ref 0 in\n \n for i=0 to n-1 do\n let c = mark_chain a.(i) 0 in\n\tcount := !count + ((c+1)/2)\n done;\n\n if k=1L then Printf.printf \"%d\\n\" n\n else Printf.printf \"%d\\n\" !count\n", "positive_code": [{"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 () and k = scan_int();;\nlet a = Array.make n 0;;\n\nfor i = 0 to n - 1 do a.(i) <- scan_int() done;\nArray.sort compare a;\n\nlet cnt = ref 0 and q = Queue.create() in\nfor i = n - 1 downto 0 do\n while(not (Queue.is_empty q) && Queue.top q > a.(i)) do Queue.pop q; done;\n if(not (Queue.is_empty q) && Queue.top q = a.(i)) then incr cnt\n else if(a.(i) mod k = 0) then Queue.push (a.(i) / k) q;\ndone;\n\nprint_int(n - !cnt);\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\nlet read_long () = Scanf.bscanf Scanf.Scanning.stdib \" %Ld \" (fun x -> x)\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\nlet () =\n let n = read_int() in\n let k = read_long() in\n let a = Array.init n (fun _ -> read_long()) in\n\n let () = Array.sort compare a in\n\n let h = Hashtbl.create 100 in\n\n let () = \n for i=0 to n-1 do\n Hashtbl.add h a.(i) false\n done in\n\n let rec mark_chain x i = \n if Hashtbl.mem h x then (\n if Hashtbl.find h x then 0 else (\n\tHashtbl.replace h x true;\n\tmark_chain (x ** k) (i+1)\n )\n ) else i\n in\n \n let count = ref 0 in\n \n for i=0 to n-1 do\n let c = mark_chain a.(i) 0 in\n\tcount := !count + ((c+1)/2)\n done;\n\n Printf.printf \"%d\\n\" !count\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 () and k = scan_int();;\nlet a = Array.make n 0;;\n\nfor i = 0 to n - 1 do a.(i) <- scan_int() done;\nArray.sort compare a;\n\nlet cnt = ref 0 and q = Queue.create() in\nfor i = n - 1 downto 0 do\n while(not (Queue.is_empty q) && Queue.top q > a.(i)) do Queue.pop q; done;\n if(not (Queue.is_empty q) && Queue.top q = a.(i)) then incr cnt; \n if(a.(i) mod k = 0) then Queue.push (a.(i) / k) q;\ndone;\n\nprint_int(n - !cnt);\n"}], "src_uid": "4ea1de740aa131cae632c612e1d582ed"} {"source_code": "(* module IntSet = Set.Make(\n struct\n let compare = Pervasives.compare\n type t = int\n end) *)\n\nmodule CharSet = Set.Make(Char)\n\nlet add s b = \n if String.length b == 0 then s\n else CharSet.add (String.get b 0) s\n\nlet x = \n let line = Str.split (Str.regexp \"[{},] *\") (read_line ()) in\n let s = List.fold_left add CharSet.empty line in\n print_int (CharSet.cardinal s);\n print_newline;", "positive_code": [{"source_code": "let get_list () =\n let letters = Pervasives.read_line () in \n let l = String.length letters in\n let rec loop i list =\n if i < 1 \n then \n list \n else \n loop (i - 3) (letters.[i] :: list)\n in loop (l - 2) []\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.length (get_uniques (List.sort (Pervasives.compare) (get_list ())))\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())"}], "negative_code": [{"source_code": "let get_list () =\n let letters = Pervasives.read_line () in \n let l = String.length letters in\n let rec loop i list =\n if i < 1 \n then \n list \n else \n loop (i - 3) (letters.[i] :: list)\n in loop (l - 2) []\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.length (get_uniques (get_list ()))\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())"}], "src_uid": "1cbbffd1941ed83b5f04e1ee33c77f61"} {"source_code": "let kikou tab =\n let red_even = ref 0\n and blu_even = ref 0\n and red_odd = ref 0\n and blu_odd = ref 0\n in\n for i = 0 to String.length tab - 1 do\n incr @@ match tab.[i] , i mod 2 with\n | 'b', 0 -> blu_even\n | 'b', 1 -> blu_odd\n | 'r', 0 -> red_even\n | 'r', 1 -> red_odd\n done;\n !red_even, !blu_even, !red_odd, !blu_odd\n\nlet solve tab =\n let n = String.length tab in\n let (re,be,ro,bo) = kikou tab in\n let a = min re bo in\n let (re',be',ro',bo') = (re-a,be+a,ro+a,bo-a) in\n a + (((n+1)/2) - be') + ((n/2) - ro')\n\nlet olol =\n String.map (fun x -> if x = 'b' then 'r' else 'b')\n\nlet _ =\n let w = Scanf.scanf \"%d %s\" (fun _ w -> w) in\n Printf.printf \"%d\" (min (solve w) (solve (olol w)))\n", "positive_code": [{"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 let s = read_string () in\n\n let comp c = match c with 'r' -> 'b' | 'b' -> 'r' | _ -> failwith \"bad input\" in\n\n let solve c =\n (* c is the goal color of position 0 *)\n let rec loop i c rtob btor =\n if i=n then (rtob, btor) else\n\tlet rtob = rtob + (if s.[i] = 'r' && c = 'b' then 1 else 0) in\n\tlet btor = btor + (if s.[i] = 'b' && c = 'r' then 1 else 0) in\n\tloop (i+1) (comp c) rtob btor\n in\n let (rtob, btor) = loop 0 c 0 0 in\n let swaps = min rtob btor in\n (rtob + btor) - swaps\n in\n\n let answer = min (solve 'r') (solve 'b') in\n\n printf \"%d\\n\" answer\n"}], "negative_code": [{"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 let s = read_string () in\n\n let comp c = match c with 'r' -> 'b' | 'b' -> 'r' | _ -> failwith \"bad input\" in\n \n let rec color i c ac =\n (* position i is already correctly colored c *)\n (* continue coloring from i+1 to the end *)\n if i = n-1 then ac else (\n if s.[i+1] = comp c then color (i+1) (comp c) ac\n else if i+2 < n && s.[i+2] <> s.[i+1] then color (i+2) c (ac+1)\n else color (i+1) (comp c) (ac+1)\n )\n in\n\n let answer = min (color (-1) 'r' 0) (color (-1) 'b' 0) in\n\n printf \"%d\\n\" answer\n"}], "src_uid": "3adc75a180d89077aa90bbe3d8546e4d"} {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and x=read_int();;\nlet s=ref 0;;\nfor i=1 to n do\n s:= !s+read_int()\ndone;;\nif !s<0 then s:= 0- !s;;\ns:= !s+x-1;;\nprint_int ( !s/x);;", "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_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let x = read_int() in\n let input = Array.init n (fun _ -> read_int()) in\n let s = sum 0 (n-1) (fun i -> input.(i)) in\n\n (* want the minimum number of cards such that their sum when\n combined with s is zero. *)\n\n let s = abs s in\n let k = s/x in\n let k = if k*x = s then k else k+1 in\n printf \"%d\\n\" k\n"}, {"source_code": "let k = int_of_string (List.nth (Str.split (Str.regexp_string \" \") (read_line ())) 1);;\nlet s = List.map int_of_string (Str.split (Str.regexp_string \" \") (read_line ()));;\nlet sum = abs (List.fold_left ( + ) 0 s);;\nprint_newline (print_int ((fun x -> if x * k < sum then (x + 1) else x) (sum / k)));;\n"}], "negative_code": [{"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and x=read_int();;\nlet s=ref 0;;\nfor i=1 to n do\n s:= !s+read_int()\ndone;;\nif !s<0 then s:= 0- !s;;\nprint_int ( !s/x);;"}, {"source_code": "let k = int_of_string (List.nth (Str.split (Str.regexp_string \" \") (read_line ())) 1);;\nlet s = List.map int_of_string (Str.split (Str.regexp_string \" \") (read_line ()));;\nlet sum = abs (List.fold_left ( + ) 0 s);;\nprint_newline (print_int ((fun x -> if x * k < sum then x + 1 else x) (sum mod k)));;\n"}], "src_uid": "066906ee58af5163636dac9334619ea7"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n (*let s = \"gerald.agapov1991@gmail.com\" in\n let s = \"x@x.x@x.x_e_@r1.com\" in*)\n let n = String.length s in\n let c = ref 0 in\n let c2 = ref 0 in\n let a = Array.make n 0 in\n let b = Array.make n 0 in\n let res = ref 0L in\n for i = 0 to n - 1 do\n match s.[i] with\n\t| '@' ->\n\t a.(i) <- !c;\n\t c := 0;\n\t| '.' -> c := 0;\n\t| 'a'..'z' -> incr c;\n\t| '0'..'9' -> ()\n\t| '_' -> ()\n\t| _ -> assert false\n done;\n c := 0;\n for i = n - 1 downto 0 do\n match s.[i] with\n\t| '@' ->\n\t if !c2 <> 0 && s.[i + 1] <> '.'\n\t then b.(i) <- !c2;\n\t c2 := 0;\n\t c := 0;\n\t| '.' ->\n\t c2 := !c;\n\t c := 0;\n\t| 'a'..'z' ->\n\t incr c;\n\t| '0'..'9' ->\n\t c := 0;\n\t| '_' ->\n\t c := 0;\n\t c2 := 0;\n\t| _ -> assert false\n done;\n for i = 0 to n - 1 do\n if s.[i] = '@'\n then res := Int64.add !res (Int64.mul (Int64.of_int a.(i))\n\t\t\t\t (Int64.of_int b.(i)))\n done;\n Printf.printf \"%Ld\\n\" !res;\n a, b\n", "positive_code": [{"source_code": "let s=read_line();;\nlet n=String.length(s)-1;;\n\nlet isvalid c=\nif (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;\n\nlet isletter c=\nif (c>='a')&&(c<='z') then true else false;;\n\nlet sol=ref Int64.zero;;\n\nlet rec faire i deb etape=\nif i>n then ()\nelse if etape=\"debut\" then\n begin\n if s.[i]='@' then \n begin\n if deb<>0 then faire (i+1) deb \"arobase1\"\n else faire (i+1) 0 \"debut\"\n end\n else if s.[i]='.' then faire (i+1) 0 \"debut\"\n else if (isletter s.[i]) then faire (i+1) (deb+1) \"debut\"\n else faire (i+1) deb \"debut\"\n end\nelse if etape=\"arobase1\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\" else faire (i+1) 0 \"debut\"\n end\nelse if etape=\"arobase2\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\"\n else if s.[i]='.' then faire (i+1) deb \"point\"\n else faire (i-1) 0 \"retour_arobase\"\n end\nelse if etape=\"point\" then\n begin\n if (isletter s.[i]) then (sol:= Int64.add (!sol) (Int64.of_int deb);faire (i+1) deb \"point\")\n else faire (i-1) 0 \"retour_point\"\n end\nelse if etape=\"retour_point\" then\n begin\n if s.[i]='.' then faire (i+1) 0 \"debut\"\n else faire (i-1) 0 \"retour_point\"\n end\nelse if s.[i]='@' then faire (i+1) 0 \"debut\"\nelse faire (i-1) 0 \"retour_arobase\";;\n\nfaire 0 0 \"debut\";;\n \nprint_string( Int64.to_string(!sol));;"}], "negative_code": [{"source_code": "let s=read_line();;\nlet n=String.length(s)-1;;\n\nlet isvalid c=\nif (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;\n\nlet isletter c=\nif (c>='a')&&(c<='z') then true else false;;\n\nlet sol=ref 0;;\n\nlet rec faire i deb etape=\nif i>n then ()\nelse if etape=\"debut\" then\n begin\n if s.[i]='@' then \n begin\n if deb<>0 then faire (i+1) deb \"arobase1\"\n else faire (i+1) 0 \"debut\"\n end\n else if s.[i]='.' then faire (i+1) 0 \"debut\"\n else if (isletter s.[i]) then faire (i+1) (deb+1) \"debut\"\n else faire (i+1) deb \"debut\"\n end\nelse if etape=\"arobase1\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\" else faire (i+1) 0 \"debut\"\n end\nelse if etape=\"arobase2\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\"\n else if s.[i]='.' then faire (i+1) deb \"point\"\n else faire (i-1) 0 \"retour_arobase\"\n end\nelse if etape=\"point\" then\n begin\n if (isletter s.[i]) then (sol:= !sol+deb;faire (i+1) deb \"point\")\n else faire (i-1) 0 \"retour_point\"\n end\nelse if etape=\"retour_point\" then\n begin\n if s.[i]='.' then faire (i+1) 0 \"debut\"\n else faire (i-1) 0 \"retour_point\"\n end\nelse if s.[i]='@' then faire (i+1) 0 \"debut\"\nelse faire (i-1) 0 \"retour_arobase\";;\n\nfaire 0 0 \"debut\";;\n \nprint_int( !sol);;\n \n\n"}, {"source_code": "let s=read_line();;\nlet n=String.length(s)-1;;\n\nlet isvalid c=\nif (c<>'.')&&(c<>'@')&&(c<>'_') then true else false;;\n\nlet isletter c=\nif (c>='a')&&(c<='z') then true else false;;\n\nlet sol=ref 0;;\n\nlet rec faire i deb etape=\nif i>n then ()\nelse if etape=\"debut\" then\n begin\n if s.[i]='@' then \n begin\n if deb<>0 then faire (i+2) deb \"arobase1\"\n else faire (i+1) 0 \"debut\"\n end\n else if s.[i]='.' then faire (i+1) 0 \"debut\"\n else if (isletter s.[i]) then faire (i+1) (deb+1) \"debut\"\n else faire (i+1) deb \"debut\"\n end\nelse if etape=\"arobase1\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\" else faire (i+1) 0 \"debut\"\n end\nelse if etape=\"arobase2\" then\n begin\n if (isvalid s.[i]) then faire (i+1) deb \"arobase2\"\n else if s.[i]='.' then faire (i+2) deb \"point\"\n else faire (i-1) 0 \"retour_arobase\"\n end\nelse if etape=\"point\" then\n begin\n if (isletter s.[i]) then (sol:= !sol+deb;faire (i+1) deb \"point\")\n else faire (i-1) 0 \"retour_point\"\n end\nelse if etape=\"retour_point\" then\n begin\n if s.[i]='.' then faire (i+1) 0 \"debut\"\n else faire (i-1) 0 \"retour_point\"\n end\nelse if s.[i]='@' then faire (i+1) 0 \"debut\"\nelse faire (i-1) 0 \"retour_arobase\";;\n\nfaire 0 0 \"debut\";;\n \nprint_int( !sol);;"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n (*let s = \"gerald.agapov1991@gmail.com\" in\n let s = \"x@x.x@x.x_e_@r1.com\" in*)\n let n = String.length s in\n let c = ref 0 in\n let c2 = ref 0 in\n let st = ref 0 in\n let a = Array.make n 0 in\n let b = Array.make n 0 in\n let res = ref 0L in\n for i = 0 to n - 1 do\n match s.[i] with\n\t| '@' ->\n\t a.(i) <- !c;\n\t c := 0;\n\t| '.' -> c := 0;\n\t| 'a'..'z' -> incr c;\n\t| '0'..'9' -> ()\n\t| '_' -> ()\n\t| _ -> assert false\n done;\n c := 0;\n for i = n - 1 downto 0 do\n match s.[i] with\n\t| '@' ->\n\t b.(i) <- !c2;\n\t c2 := 0;\n\t c := 0;\n\t| '.' ->\n\t c2 := !c;\n\t c := 0;\n\t| 'a'..'z' ->\n\t incr c;\n\t| '0'..'9' ->\n\t c := 0;\n\t| '_' ->\n\t c := 0;\n\t c2 := 0;\n\t| _ -> assert false\n done;\n for i = 0 to n - 1 do\n if s.[i] = '@'\n then res := Int64.add !res (Int64.mul (Int64.of_int a.(i))\n\t\t\t\t (Int64.of_int b.(i)))\n done;\n Printf.printf \"%Ld\\n\" !res;\n a, b\n"}], "src_uid": "08924ff11b857559a44c1637761b508a"} {"source_code": "let n = read_int ()\r\n;;\r\nlet read_pair _ = Scanf.bscanf Scanf.Scanning.stdin \" %d %d \" (fun x y -> (x,y))\r\n;;\r\n\r\nfor i = 1 to n do\r\n let (a,b) = read_pair () in\r\n Printf.printf \"%d\\n\" (a*b)\r\ndone", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_pair _ = bscanf Scanning.stdin \" %d %d \" (fun x y -> (x,y))\nlet () = \n let cases = read_int () in\n for case = 1 to cases do\n let (a,b) = read_pair () in\n printf \"%d\\n\" (a*b)\n done\n"}], "negative_code": [], "src_uid": "806dcdab8364f5169334e172a192598a"} {"source_code": "let r_long () = Int64.of_int (Scanf.scanf \" %d\" (fun x -> x)) in\nlet r_int () = Scanf.scanf \" %d\" (fun x -> x) in\n\nlet rec max_diff maxi = function\n| 0 -> 0L\n| nbNombres -> \n let nombre = r_long () in\n let nouvMax = max nombre maxi in\n max (Int64.sub maxi nombre) (max_diff nouvMax (nbNombres - 1))\nin\n\nlet rec log = function\n| 0L -> 0\n| n -> 1 + log (Int64.div n 2L)\nin\n\nlet nbTests = r_int () in\nfor iTest = 1 to nbTests do\n let nbNombres = r_int () in\n let diff = max_diff (r_long ()) (nbNombres - 1) in\n print_int (log diff);\n print_newline ()\ndone;", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec topbit d = if d lsr 1 = 0 then 0 else 1 + topbit (d lsr 1)\n\nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let a = Array.init n read_int in\n let rec loop i mb = if i=n-1 then mb else (\n if a.(i) <= a.(i+1) then loop (i+1) mb\n else (\n\tlet d = a.(i) - a.(i+1) in\n\ta.(i+1) <- a.(i);\n\tlet mb = max mb (1 + topbit d) in\n\tloop (i+1) mb\n )\n )\n in\n printf \"%d\\n\" (if n = 1 then 0 else loop 0 0)\n done\n"}], "negative_code": [{"source_code": "let r_int () = Scanf.scanf \" %d\" (fun x -> x) in\n\nlet rec max_diff maxi = function\n| 0 -> 0\n| nbNombres -> \n let nombre = r_int () in\n let nouvMax = max nombre maxi in\n max (maxi - nombre) (max_diff nouvMax (nbNombres - 1))\nin\n\nlet rec log = function\n| 0 -> 0\n| n -> 1 + log (n / 2)\nin\n\nlet nbTests = r_int () in\nfor iTest = 1 to nbTests do\n let nbNombres = r_int () in\n let diff = max_diff (r_int ()) (nbNombres - 1) in\n print_int (log diff);\n print_newline ()\ndone;"}], "src_uid": "bfc2e7de37db4a0a74cdd55f2124424a"} {"source_code": "\nmodule StringSet = Set.Make(String)\n\nmodule StringMap = Map.Make(String)\n\nlet all_colors = (StringSet.of_list [\n \"purple\"; \"green\"; \"blue\"; \"orange\"; \"red\"; \"yellow\"\n ])\n\nlet gem_of_color = ref StringMap.empty\n \nlet () =\n List.iter\n (fun (k, v) -> gem_of_color := StringMap.add k v !gem_of_color)\n [\n (\"purple\", \"Power\");\n (\"green\", \"Time\");\n (\"blue\", \"Space\");\n (\"orange\", \"Soul\");\n (\"red\", \"Reality\");\n (\"yellow\", \"Mind\");\n ];\n let m = Scanf.scanf \"%d\" (fun i -> i) in\n let colors = ref all_colors in\n for i = 1 to m do\n let s = Scanf.scanf \" %s\" (fun i -> i) in\n colors := StringSet.remove s !colors\n done;\n Printf.printf \"%d\\n\" (StringSet.cardinal !colors);\n StringSet.iter (fun s ->\n Printf.printf \"%s\\n\" (StringMap.find s !gem_of_color)) !colors\n", "positive_code": [{"source_code": "let gems =\n [(\"purple\", \"Power\");\n (\"green\", \"Time\");\n (\"blue\", \"Space\");\n (\"orange\", \"Soul\");\n (\"red\", \"Reality\");\n (\"yellow\", \"Mind\")]\n\nlet () =\n let n = int_of_string (input_line stdin) in\n let pr = ref [] in\n for i = 0 to n - 1 do\n pr := (input_line stdin) :: !pr\n done;\n let present = !pr in\n let p (gem_colour, gem_name) = not (List.mem gem_colour present) in\n let f (gem_colour, gem_name) = gem_name in\n let toprint = List.map f (List.filter p gems) in\n print_endline (string_of_int (List.length toprint));\n ignore (List.map print_endline toprint)"}], "negative_code": [], "src_uid": "7eff98fbcf4e4a3284e2d2f98351fe4a"} {"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 long x = Int64.of_int x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let a = read_int() in\n let b = read_int() in\n let c = read_int() in\n let d = read_int() in\n\n let det = (long a) ** (long d) -- (long b) ** (long c) in\n if det = 0L then printf \"0.0\\n\" else\n\n let (a,b,c,d) = (float a, float b, float c, float d) in\n let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in\n let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in\n \n let lohi a b e =\n let x1 = (a -. e) *. (b -. e) in\n let x2 = (a +. e) *. (b -. e) in\n let x3 = (a -. e) *. (b +. e) in\n let x4 = (a +. e) *. (b +. e) in\n let hi = max (max x1 x2) (max x3 x4) in\n let lo = min (min x1 x2) (min x3 x4) in\n (lo,hi)\n in\n \n let intervals_intersect (lo1, hi1) (lo2, hi2) =\n if hi1 < lo2 then false\n else if hi2 < lo1 then false\n else true\n in\n \n let test e =\n intervals_intersect (lohi a d e) (lohi b c e)\n in\n \n let rec bsearch x y =\n let m = (x +. y) /. 2.0 in\n if abs_float (x -. y) < (1e-13) *. m then m\n else if test m then bsearch x m else bsearch m y\n in\n \n let answer = bsearch 0.0 1.0 in\n \n printf \"%.10f\\n\" (answer *. big)\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let a = float (read_int()) in\n let b = float (read_int()) in\n let c = float (read_int()) in\n let d = float (read_int()) in\n\n let lohi a b e =\n let x1 = (a -. e) *. (b -. e) in\n let x2 = (a +. e) *. (b -. e) in\n let x3 = (a -. e) *. (b +. e) in\n let x4 = (a +. e) *. (b +. e) in\n let hi = max (max x1 x2) (max x3 x4) in\n let lo = min (min x1 x2) (min x3 x4) in\n (lo,hi)\n in\n \n let intervals_intersect (lo1, hi1) (lo2, hi2) =\n if hi1 < lo2 then false\n else if hi2 < lo1 then false\n else true\n in\n \n let test e =\n intervals_intersect (lohi a d e) (lohi b c e)\n in\n \n let rec bsearch x y n =\n let m = (x +. y) /. 2.0 in\n if n=0 then m\n else if test m then bsearch x m (n-1) else bsearch m y (n-1)\n in\n \n printf \"%.10f\\n\" (bsearch 0.0 1e10 200)\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let a = float (read_int()) in\n let b = float (read_int()) in\n let c = float (read_int()) in\n let d = float (read_int()) in\n\n let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in\n\n let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in\n\n let lohi a b e =\n let x1 = (a -. e) *. (b -. e) in\n let x2 = (a +. e) *. (b -. e) in\n let x3 = (a -. e) *. (b +. e) in\n let x4 = (a +. e) *. (b +. e) in\n let hi = max (max x1 x2) (max x3 x4) in\n let lo = min (min x1 x2) (min x3 x4) in\n (lo,hi)\n in\n\n let intervals_intersect (lo1, hi1) (lo2, hi2) =\n if hi1 < lo2 then false\n else if hi2 < lo1 then false\n else true\n in\n \n let test e =\n intervals_intersect (lohi a d e) (lohi b c e)\n in\n\n let rec bsearch x y =\n let m = (x +. y) /. 2.0 in\n if abs_float (x -. y) < 1e-15 then m\n else if test m then bsearch x m else bsearch m y\n in\n\n let answer = bsearch 0.0 1.0 in\n\n printf \"%.9f\\n\" (answer *. big)\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 long x = Int64.of_int x\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet () =\n let a = read_int() in\n let b = read_int() in\n let c = read_int() in\n let d = read_int() in\n\n let det = (long a) ** (long d) -- (long b) ** (long c) in\n if det = 0L then printf \"0.0\\n\" else\n\n let (a,b,c,d) = (float a, float b, float c, float d) in\n let big = (max (max (abs_float a) (abs_float b)) (max (abs_float c) (abs_float d))) in\n let (a,b,c,d) = if (big = 0.0) then (a,b,c,d) else (a/.big, b/.big, c/.big, d/.big) in\n \n let lohi a b e =\n let x1 = (a -. e) *. (b -. e) in\n let x2 = (a +. e) *. (b -. e) in\n let x3 = (a -. e) *. (b +. e) in\n let x4 = (a +. e) *. (b +. e) in\n let hi = max (max x1 x2) (max x3 x4) in\n let lo = min (min x1 x2) (min x3 x4) in\n (lo,hi)\n in\n \n let intervals_intersect (lo1, hi1) (lo2, hi2) =\n if hi1 < lo2 then false\n else if hi2 < lo1 then false\n else true\n in\n \n let test e =\n intervals_intersect (lohi a d e) (lohi b c e)\n in\n \n let rec bsearch x y =\n let m = (x +. y) /. 2.0 in\n if abs_float (x -. y) < 1e-13 then m\n else if test m then bsearch x m else bsearch m y\n in\n \n let answer = bsearch 0.0 1.0 in\n \n printf \"%.9f\\n\" (answer *. big)\n"}], "src_uid": "b779946fe86b1a2a4449bc85ff887367"} {"source_code": "let read1 () = Scanf.scanf \"%d\\n\" ( fun x -> x );;\nlet read2 () = Scanf.scanf \"%d %d\\n\" ( fun x y -> x, y );;\nlet read3 () = Scanf.scanf \"%d %d %d\\n\" ( fun x y z -> x, y, z);;\nlet read x = (if x = 0 then Scanf.scanf \"%d\\n\" else Scanf.scanf \"%d \") ( fun x -> x );;\n\nlet (+$) x y =\n if x > max_int - y then max_int\n else x + y;;\n\nlet rec ( *$ ) x y =\n if y = 0 then 0 else\n if y mod 2 = 1 then x *$ (y-1) +$ x\n else let a = x *$ (y/2) in a +$ a;;\n\nlet rec loop n tab =\n if n >= 0 then\n let x = read n in\n tab.(x) <- true;\n loop (n-1) tab\n else ();;\n\nlet _ = \n let (n, m) = read2 () in\n let tab = Array.make (m+1) false in\n tab.(0) <- true;\n for i=1 to n do\n let k = Scanf.scanf \"%d \" ( fun x -> x ) in\n loop (k-1) tab\n done;\n Printf.printf \"%s\\n\" (Array.fold_left ( fun a x -> if not x then \"NO\" else a ) \"YES\" tab);;\n\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet () = \n let (n,m) = read_pair () in\n let mark = Array.make m false in\n for i=0 to n-1 do\n let x = read_int () in\n for j=0 to x-1 do\n let y = -1 + read_int() in\n mark.(y) <- true;\n done\n done;\n\n if forall 0 (m-1) (fun i -> mark.(i)) then printf \"YES\\n\" else printf \"NO\\n\"\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet rec forall i j f = (i>j) || ((f i) && forall (i+1) j f)\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet () = \n let (n,m) = read_pair () in\n let mark = Array.make m false in\n for i=0 to n-1 do\n let x = read_int () in\n for j=0 to x-1 do\n let y = -1 + read_int() in\n mark.(y) <- true;\n done\n done;\n\n if forall 0 (n-1) (fun i -> mark.(i)) then printf \"YES\\n\" else printf \"NO\\n\"\n"}], "src_uid": "9438ce92e10e846dd3ab7c61a1a2e3af"} {"source_code": "open Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0L)))\nlet md = 998244353L\nlet hoge p q r s =\n\tlet m p q = Int64.rem q p in\n\tp |> m md |> Int64.add q |> m md |> Int64.add r |> m md |> Int64.add s |> m md\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1L;\n\tdp.(1).(3).(0).(1) <- 1L;\n\tdp.(1).(3).(1).(0) <- 1L;\n\tdp.(1).(2).(1).(1) <- 1L;\n\tfor i=2 to n do\n\t\tfor j=2 to i*2+1 do\n\t\t\tdp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0);\n\t\tdone;\n\tdone;\n\tprintf \"%Ld\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\n\t)\n\n", "positive_code": [{"source_code": "open Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0L)))\nlet md = 998244353L\nlet hoge p q r s =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m |> Int64.add r |> m |> Int64.add s |> m\nlet (@~) a (i,j,k,l) =\n\ta.(i).(j).(k).(l)\nlet (<@~) a (i,j,k,l,v) = a.(i).(j).(k).(l) <- v\nlet (+%) p q =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m\nlet rep f t fbod = for i=f to t do fbod i done\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1L;\n\tdp.(1).(3).(0).(1) <- 1L;\n\tdp.(1).(3).(1).(0) <- 1L;\n\tdp.(1).(2).(1).(1) <- 1L;\n\t(* for i=2 to n do\n\t\tfor j=2 to i*2+1 do *)\n\trep 2 n (fun i ->\n\t\trep 2 (i*2+1) (fun j ->\n\t\t\tdp<@~(i,j,0,0,(\n\t\t\t\thoge\n\t\t\t\t\t(dp@~(i-1,j,0,0))\n\t\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t\t(dp@~(i-1,j-1,1,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,1,(\n\t\t\t\thoge\n\t\t\t\t\t(dp@~(i-1,j,1,1))\n\t\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t\t(dp@~(i-1,j-1,0,0))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,0,(\n\t\t\t\thoge\n\t\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t\t(dp@~(i-1,j-1,1,1))\n\t\t\t\t\t(dp@~(i-1,j-1,0,0))\n\t\t\t\t\t(dp@~(i-1,j-2,0,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,0,1,(\n\t\t\t\thoge\n\t\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t\t(dp@~(i-1,j-1,1,1))\n\t\t\t\t\t(dp@~(i-1,j-1,0,0))\n\t\t\t\t\t(dp@~(i-1,j-2,1,0))\n\t\t\t));\n\t\t\t(* dp<@~(i,j,0,0,(\n\t\t\t\t(dp@~(i-1,j,0,0))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,1,(\n\t\t\t\t(dp@~(i-1,j,1,1))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,0,(\n\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,0,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,0,1,(\n\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,1,0))\n\t\t\t)); *)\n\t\t\t(* dp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0); *)\n\t\t(* done;\n\tdone; *)\n\t));\n\tprintf \"%Ld\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\n\t)\n\n"}, {"source_code": "open Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0L)))\nlet md = 998244353L\nlet hoge p q r s =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m |> Int64.add r |> m |> Int64.add s |> m\nlet (@~) a (i,j,k,l) =\n\ta.(i).(j).(k).(l)\nlet (<@~) a (i,j,k,l,v) = a.(i).(j).(k).(l) <- v\nlet (+%) p q =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m\nlet rep f t fbod = for i=f to t do fbod i done\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1L;\n\tdp.(1).(3).(0).(1) <- 1L;\n\tdp.(1).(3).(1).(0) <- 1L;\n\tdp.(1).(2).(1).(1) <- 1L;\n\t(* for i=2 to n do\n\t\tfor j=2 to i*2+1 do *)\n\trep 2 n (fun i ->\n\t\trep 2 (i*2+1) (fun j ->\n\t\t\tdp<@~(i,j,0,0,(\n\t\t\t\t(dp@~(i-1,j,0,0))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,1,(\n\t\t\t\t(dp@~(i-1,j,1,1))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,0,(\n\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,0,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,0,1,(\n\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,1,0))\n\t\t\t));\n\t\t\t(* dp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0); *)\n\t\t(* done;\n\tdone; *)\n\t));\n\tprintf \"%Ld\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\n\t)\n\n"}, {"source_code": "(* infix abuse harms? *)\n\nopen Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0L)))\nlet md = 998244353L\nlet hoge p q r s =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m |> Int64.add r |> m |> Int64.add s |> m\nlet (@~) a (i,j,k,l) = a.(i).(j).(k).(l)\nlet (<@~) a (i,j,k,l,v) = a.(i).(j).(k).(l) <- v\nlet (+%) p q =\n\tlet m q = Int64.rem q md in\n\tp |> m |> Int64.add q |> m\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1L;\n\tdp.(1).(3).(0).(1) <- 1L;\n\tdp.(1).(3).(1).(0) <- 1L;\n\tdp.(1).(2).(1).(1) <- 1L;\n\tfor i=2 to n do\n\t\tfor j=2 to i*2+1 do\n\t\t\tdp<@~(i,j,0,0,(\n\t\t\t\t(dp@~(i-1,j,0,0))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,1,(\n\t\t\t\t(dp@~(i-1,j,1,1))\n\t\t\t\t+% (dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t));\n\t\t\tdp<@~(i,j,1,0,(\n\t\t\t\t(dp@~(i-1,j,1,0))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,0,1))\n\t\t\t));\n\t\t\tdp<@~(i,j,0,1,(\n\t\t\t\t(dp@~(i-1,j,0,1))\n\t\t\t\t+% (dp@~(i-1,j-1,1,1))\n\t\t\t\t+% (dp@~(i-1,j-1,0,0))\n\t\t\t\t+% (dp@~(i-1,j-2,1,0))\n\t\t\t));\n\t\t\t(*\n\t\t\tdp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0); *)\n\t\tdone;\n\tdone;\n\tprintf \"%Ld\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\n\t)\n\n"}], "negative_code": [{"source_code": "open Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0)))\nlet md = 998244353\nlet hoge p q r s =\n\tlet m p q = q mod p in\n\tp |> (+) q |> m md |> (+) r |> m md |> (+) s |> m md\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1;\n\tdp.(1).(3).(0).(1) <- 1;\n\tdp.(1).(3).(1).(0) <- 1;\n\tdp.(1).(2).(1).(1) <- 1;\n\tfor i=2 to n do\n\t\tfor j=2 to i*2+1 do\n\t\t\tdp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0);\n\t\tdone;\n\tdone;\n\tprintf \"%d\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\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 (+$) = (+) 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\nend open MyInt64\n\nmodule ModCalc = struct\n\t(* let md = 1000000007L *)\n\tlet md = 998244353L\n\tlet validate v =\n\t\t(v + (labs(v) / md + 1L) * md) mod md\n\tlet _add_mod md u v = u mod md + v mod md |> validate\n\tlet _sub_mod md u v = u mod md - v mod md |> validate\n\tlet _mul_mod md u v = u mod md * v mod md |> validate\n\tlet rec pw u v =\n\t\tif v=0L then 1L\n\t\telse if v=1L then u mod md\n\t\telse let p = pw u (v/2L) in\n\t\t\tif v mod 2L = 0L then _mul_mod md p p\n\t\t\telse _mul_mod md (_mul_mod md p p) u\n\tlet _inv md v = pw v (md-2L)\n\tlet _div_mod md u v = \n\t\t_mul_mod md u (_inv md v)\n\n\tlet (+%) u v = _add_mod md u v\n\tlet (-%) u v = _sub_mod md u v\n\tlet ( *%) u v = _mul_mod md u v\n\tlet (/%) u v = _div_mod md u v\n\tlet rec pow x n = if n = 0L then 1L\n\t\telse if n mod 2L = 1L then x *% pow x (n-1L)\n\t\telse let w = pow x (n/2L) in w *% w\n\tlet fact n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\nend open ModCalc\n\n\nlet make_3darray p q r d = Array.init (~|p) (fun _ -> Array.make_matrix (~|q) (~|r) d)\nlet make_4darray p q r s d = Array.init (~|p) (fun _ -> make_3darray q r s d)\nlet (@~) a (i,j,k,l) = try a.(~|i).(~|j).(~|k).(~|l) with | Invalid_argument _ -> 0L\nlet (<@~) a (i,j,k,l,v) = a.(~|i).(~|j).(~|k).(~|l) <- v\nlet dp = make_4darray 1024L 2048L 2L 2L 0L\n\nlet () =\n\tlet n,k = get_2_i64 0 in\n\tdp.(1).(1).(0).(0) <- 1L;\n\tdp.(1).(2).(0).(1) <- 1L;\n\tdp.(1).(2).(1).(0) <- 1L;\n\tdp.(1).(1).(1).(1) <- 1L;\n\trep 2L n (fun i ->\n\t\trep 1L (i*2L+2L) (fun j ->\n\t\t\tdp<@~(i,j,0L,0L,(\n\t\t\t\t(dp@~(i-1L,j,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,1L,1L))\n\t\t\t));\n\t\t\tdp<@~(i,j,1L,1L,(\n\t\t\t\t(dp@~(i-1L,j,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,0L,0L))\n\t\t\t));\n\t\t\tdp<@~(i,j,1L,0L,(\n\t\t\t\t(dp@~(i-1L,j,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,0L,1L))\n\t\t\t));\n\t\t\tdp<@~(i,j,0L,1L,(\n\t\t\t\t(dp@~(i-1L,j,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,1L,0L))\n\t\t\t));\n\t\t\t`Ok\n\t\t);\n\t\t`Ok\n\t);\n\tprintf \"%Ld\\n\" (\n\t\t(dp@~(n,k,0L,0L))\n\t\t+% (dp@~(n,k,0L,1L))\n\t\t+% (dp@~(n,k,1L,0L))\n\t\t+% (dp@~(n,k,1L,1L))\n\t)"}, {"source_code": "open Printf open Scanf\nmodule MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end\nmodule MyInt64 = struct\n\tlet (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=\" \") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls \"\" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n\tlet (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v\n\tlet ceildiv m n = (m+n-1L) / n\n\tlet abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf \" %s\" (fun v -> v)\n\tlet i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a\nend open MyInt64\n\nmodule ModCalc = struct\n\t(* let md = 1000000007L *)\n\tlet md = 998244353L\n\tlet validate v =\n\t\t(v + (labs(v) / md + 1L) * md) mod md\n\tlet _add_mod md u v = u mod md + v mod md |> validate\n\tlet _sub_mod md u v = u mod md - v mod md |> validate\n\tlet _mul_mod md u v = u mod md * v mod md |> validate\n\tlet rec pw u v =\n\t\tif v=0L then 1L\n\t\telse if v=1L then u mod md\n\t\telse let p = pw u (v/2L) in\n\t\t\tif v mod 2L = 0L then _mul_mod md p p\n\t\t\telse _mul_mod md (_mul_mod md p p) u\n\tlet _inv md v = pw v (md-2L)\n\tlet _div_mod md u v = \n\t\t_mul_mod md u (_inv md v)\n\n\tlet (+%) u v = _add_mod md u v\n\tlet (-%) u v = _sub_mod md u v\n\tlet ( *%) u v = _mul_mod md u v\n\tlet (/%) u v = _div_mod md u v\n\tlet rec pow x n = if n = 0L then 1L\n\t\telse if n mod 2L = 1L then x *% pow x (n-1L)\n\t\telse let w = pow x (n/2L) in w *% w\n\tlet fact n = let rec f0 n v = if n = 0L then v else f0 (n-1L) (n*%v) in f0 n 1L\nend open ModCalc\n\n\nlet make_3darray p q r d = Array.init (~|p) (fun _ -> Array.make_matrix (~|q) (~|r) d)\nlet make_4darray p q r s d = Array.init (~|p) (fun _ -> make_3darray q r s d)\nlet (@~) a (i,j,k,l) = try a.(~|i).(~|j).(~|k).(~|l) with | Invalid_argument _ -> 0L\nlet (<@~) a (i,j,k,l,v) = a.(~|i).(~|j).(~|k).(~|l) <- v\nlet dp = make_4darray 1024L 2048L 2L 2L 0L\n\nlet () =\n\tlet n,k = get_2_i64 0 in\n\tdp.(1).(1).(0).(0) <- 1L;\n\tdp.(1).(2).(0).(1) <- 1L;\n\tdp.(1).(2).(1).(0) <- 1L;\n\tdp.(1).(1).(1).(1) <- 1L;\n\trep 2L n (fun i ->\n\t\trep 1L (i*2L+2L) (fun j ->\n\t\t\tdp<@~(i,j,0L,0L,(\n\t\t\t\t(dp@~(i-1L,j,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,1L))\n\t\t\t));\n\t\t\tdp<@~(i,j,1L,1L,(\n\t\t\t\t(dp@~(i-1L,j,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,0L))\n\t\t\t));\n\t\t\tdp<@~(i,j,1L,0L,(\n\t\t\t\t(dp@~(i-1L,j,1L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,0L,1L))\n\t\t\t));\n\t\t\tdp<@~(i,j,0L,1L,(\n\t\t\t\t(dp@~(i-1L,j,0L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,1L,1L))\n\t\t\t\t+% (dp@~(i-1L,j-1L,0L,0L))\n\t\t\t\t+% (dp@~(i-1L,j-2L,1L,0L))\n\t\t\t));\n\t\t\t`Ok\n\t\t);\n\t\t`Ok\n\t);\n\tprintf \"%Ld\\n\" (\n\t\t(dp@~(n,k,0L,0L))\n\t\t+% (dp@~(n,k,0L,1L))\n\t\t+% (dp@~(n,k,1L,0L))\n\t\t+% (dp@~(n,k,1L,1L))\n\t)"}, {"source_code": "open Printf open Scanf\n\nlet dp = Array.init 1024 (fun _ ->\n\tArray.init 2048 (fun _ -> \n\t\tArray.init 2 (fun _ ->\n\t\t\tArray.make 2 0)))\nlet md = 998244353\nlet hoge p q r s =\n\tlet m p q = q mod p in\n\tp |> m md |> (+) q |> m md |> (+) r |> m md |> (+) s |> m md\nlet () =\n\tlet n,k = scanf \" %d %d\" (fun u v -> u,v) in\n\tdp.(1).(2).(0).(0) <- 1;\n\tdp.(1).(3).(0).(1) <- 1;\n\tdp.(1).(3).(1).(0) <- 1;\n\tdp.(1).(2).(1).(1) <- 1;\n\tfor i=2 to n do\n\t\tfor j=2 to i*2+1 do\n\t\t\tdp.(i).(j).(0).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(0)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1);\n\t\t\tdp.(i).(j).(1).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(1)\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0);\n\t\t\tdp.(i).(j).(1).(0) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(1).(0)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(0).(1);\n\t\t\tdp.(i).(j).(0).(1) <-\n\t\t\t\thoge\n\t\t\t\t\tdp.(i-1).(j).(0).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(1).(1)\n\t\t\t\t\tdp.(i-1).(j-1).(0).(0)\n\t\t\t\t\tdp.(i-1).(j-2).(1).(0);\n\t\tdone;\n\tdone;\n\tprintf \"%d\" (\n\t\thoge\n\t\t\tdp.(n).(k+1).(0).(0)\n\t\t\tdp.(n).(k+1).(0).(1)\n\t\t\tdp.(n).(k+1).(1).(0)\n\t\t\tdp.(n).(k+1).(1).(1)\n\t)\n\n"}], "src_uid": "7e6a2329633ee283e3327413114901d1"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x);;\nlet scan_string () = Scanf.scanf \" %s\" (fun x -> x);;\nlet psp () = print_string \" \";;\nlet b2i x = if x == true then 1 else 0;;\n\nopen Int64;;\nlet t = scan_int();;\n\nlet f s a b c =\n let c1 = mul a c in\n let ile = div s c1 in\n add (mul ile (add a b)) (div (sub s (mul ile c1)) c);;\n\nfor i = 0 to t - 1 do\n let a = Int64.of_int(scan_int()) and \n b = Int64.of_int(scan_int()) and\n c = Int64.of_int(scan_int()) and\n d = Int64.of_int(scan_int()) in\n print_string(Int64.to_string(f a b c d)); print_newline();\ndone;;", "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 () =\n\tlet t = get_i64 0 in\n\trep 1L t (fun _ ->\n\t\tlet s,a,b,c = get_4_i64 0 in\n\t\tlet buy = s / c in\n\t\tlet d = buy / a in\n\t\t(d*(a+b) + (buy - d*a)) |> printf \"%Ld\\n\";\n\t\t(* printf \"%Ld %Ld\\n\" buy d; *)\n\t\t`Ok\n\t)\t\n\n"}], "negative_code": [], "src_uid": "ec8060260a6c7f4ff3e6afc9fd248afc"} {"source_code": "(* Codeforces 252B RazborCode 255B *)\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 rec cntxy s idx cntx cnty =\n\tif idx >= (length s) then (cntx, cnty)\n\telse begin\n\t\tlet c = s.[idx] in\n\t\tlet id1 = idx +1 in\n\t\tif c = 'x' then\n\t\t\tcntxy s id1 (cntx + 1) cnty\n\t\telse cntxy s id1 cntx (cnty + 1)\n\tend;;\n\nlet rec reppri s n = match n with\n\t| 0 -> ()\n\t| _ -> begin\n\t\t\t\tprint_string s;\n\t\t\t\treppri s (n -1)\n\t\t\tend;;\n\nlet main () =\n\tlet s = rdln() in\n\tlet (cx, cy) = cntxy s 0 0 0 in\n\tbegin\n\t\t(* print_string \" cx,cy = \"; print_int cx; print_string \" \"; print_int *)\n\t\t(* cy; *)\n\t\tif cx < cy then reppri \"y\" (cy - cx) \n\t\t\telse reppri \"x\" (cx - cy);\n\t\tprint_newline()\n\tend;;\n\nmain();;\n", "positive_code": [{"source_code": "let read_string () = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x) \n\nlet explode s = \n let rec exp i l = \n if i < 0 then l else exp (i - 1) (s.[i] :: l) \n in exp (String.length s - 1) [] ;;\n \nlet s = explode (read_string ()) ;;\n\nlet count s =\n let rec loop (x, y) = function\n | [] -> (x, y)\n | h :: t -> \n if h = 'x' then loop (x + 1, y) t \n else loop (x, y + 1) t\n in loop (0, 0) s ;;\n\nlet result = \n let (x, y) = count s in \n if x > y then String.make (x - y) 'x'\n else String.make (y - x) 'y' ;;\n\nPrintf.printf \"%s\\n\" result ;;"}, {"source_code": "let () = \n let s = read_line() in\n let c = Array.make 2 0 in\n for i = 0 to (String.length s)-1 do\n let w = if s.[i] = 'x' then 0 else 1 in\n\tc.(w) <- c.(w) + 1\n done;\n\n let b = if c.(0) > c.(1) then 'x' else 'y' in\n let n = abs (c.(0) - c.(1)) in\n for i=0 to n-1 do\n\tprint_char b\n done;\n print_newline()\n"}], "negative_code": [], "src_uid": "528459e7624f90372cb2c3a915529a23"} {"source_code": "(* #load \"str.cma\" *)\r\nmodule Stdlib = Pervasives;;\r\n(* let std_inp = Stdlib.open_in \"input.txt\";; *)\r\nlet std_inp = Stdlib.stdin;;\r\nlet std_outp = Stdlib.stdout;;\r\n\r\nlet identity x = x;;\r\nlet tup3 x1 x2 x3 = (x1, x2, x3);;\r\n\r\nlet rec slices n =\r\n if n mod 2 == 0 then 1 + slices (n / 2)\r\n else 0;;\r\n\r\nlet rec pow base = function\r\n| 0 -> 1\r\n| n -> base * (pow base (n - 1));;\r\n\r\nlet solution inp outp =\r\n let (w, h, n) = let line = input_line inp in Scanf.sscanf line \"%d %d %d\" tup3 in\r\n let w_count = slices w and h_count = slices h in\r\n (* let _ = Printf.printf \"W: %d; H: %d; N: %d\\n\" w h n in *)\r\n (* let _ = Printf.printf \"WC: %d; HC: %d\\n\" w_count h_count in *)\r\n let _ =\r\n if (pow 2 w_count) * (pow 2 h_count) >= n then Printf.printf \"YES\\n\"\r\n else Printf.printf \"NO\\n\"\r\n in\r\n ();;\r\nlet rec run_test = function\r\n| (0, _, _) -> ()\r\n| (t, inp, outp) ->\r\n let _ = solution inp outp in\r\n run_test (t - 1, inp, outp);;\r\n\r\nlet (_:unit) =\r\n let inp = std_inp and outp = std_outp in\r\n let tests_count = let line = input_line inp in Scanf.sscanf line \"%d\" identity in\r\n let _ = run_test (tests_count, inp, outp) in\r\n ();;", "positive_code": [{"source_code": "(** https://codeforces.com/problemset/problem/1472/A *)\n\nlet max_friends width height =\n let rec helper num i =\n if num land 1 = 1\n then i\n else helper (num lsr 1) (i+1) in\n let cut_width = helper width 0 and\n cut_height = helper height 0 in\n let rec pow2 i res =\n if i = 0\n then res\n else pow2 (i-1) (res lsl 1) in\n pow2 (cut_width+cut_height) 1\n \nlet solve_n nb_cases =\n let rec helper i =\n if i > 0\n then (\n let [width; height; friends] =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string in\n (if max_friends width height >= friends then \"YES\" else \"NO\")\n |> print_endline;\n helper (i-1)\n ) in\n helper nb_cases\n\nlet () =\n let nb_cases = read_int () in\n solve_n nb_cases\n"}], "negative_code": [], "src_uid": "a8201326dda46542b23dc4e528d413eb"} {"source_code": "let k = List.nth (read_line () |> Str.split (Str.regexp \" +\") ) 1 |> int_of_string and\n ys = read_line() |> Str.split (Str.regexp \" +\") |> List.map int_of_string in\n \n ys |> List.map (fun x -> x + k) |> List.filter (fun x -> x <=5) |> List.length |> fun x -> x / 3 |> print_int \n", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet k=read_int();;\nlet nb=ref 0;;\nfor i=1 to n-1 do\n let x=read_int() in\n if x<=5-k then incr nb\ndone;;\nlet a=Scanf.scanf \"%d\" (fun x->x) in if a<=5-k then incr nb;;\nprint_int( (!nb)/3);;"}, {"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\n(* int *)\nlet intsqrt n = \n if n < 0 then raise (Invalid_argument \"sqrt of negative int\") else \n let rec bs a b = begin \n if b - a = 1 then a else \n let mid = (a+b)/2 in \n if mid*mid <= n then bs mid b else bs a mid\n end in \n bs 0 (1 lsl 31)\n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* tuple *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let len = read_int() in \n let k = read_int() in \n let arr = init len (fun i -> read_int() ) in \n sort compare arr;\n let rec upper_bound a b =\n if b - a = 1 then b else \n let mid = (a+b)/2 in \n if arr.(mid) <= 5-k then upper_bound mid b else upper_bound a mid \n in \n printf \"%d\\n\" ((upper_bound (-1) len)/3)"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet input () = \n let n = read () in\n let k = read () in\n let rec loop i list =\n if i < n\n then\n let temp = read () in\n loop (i + 1) (temp :: list)\n else\n (k, list)\n in loop 0 []\n\nlet solve (k, list) = \n let qualified = List.filter (fun m -> m + k <= 5) list in\n List.length qualified / 3\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 k=read_int();;\nlet nb=ref 0;;\nfor i=1 to n-1 do\n let x=read_int() in\n if x<=5-k then incr nb\ndone;;\nlet a=Scanf.scanf \"%d\" (fun x->x) in if a<=5-k then incr nb;;\nprint_int( (!nb)/3);;"}], "negative_code": [], "src_uid": "fbde1e2ee02055592ff72fb04366812b"} {"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 k = read_int () in\n let a = read_int () in\n let m = read_int () in\n let x = Array.init m (fun _ -> -1 + read_int()) in\n\n let feasible i =\n (* returns true iff bob's moves 0...i are feasible. *)\n let mark = Array.make n false in\n for j=0 to i do\n mark.(x.(j)) <- true\n done;\n\n let place_one_block j =\n (* return the place to start the next block, or -1 if \n\t can't place any block *)\n let rec pl j placed =\n\tif placed = a then j+1\n\telse if j>=n then -1\n\telse if mark.(j) then pl (j+1) 0\n\telse pl (j+1) (placed+1)\n in\n pl j 0\n in\n \n let rec fill j b_placed =\n if b_placed = k then true else\n\tlet j' = place_one_block j in\n\tif j' < 0 then false else fill j' (b_placed+1)\n in\n\n fill 0 0\n in\n\n let rec bsearch lo hi =\n (* lo < hi and lo is possible, hi is impossible *)\n if lo+1 = hi then hi else\n let m = (lo + hi) / 2 in\n if feasible m then bsearch m hi else bsearch lo m\n in\n\n let answer =\n if feasible (m-1) then -1 else 1 + bsearch (-1) (m-1)\n in\n\n printf \"%d\\n\" answer;\n", "positive_code": [{"source_code": "module RangeMap = Map.Make(\n struct\n type t = int * int\n let compare (l1, r1) (l2, r2) =\n if r1 < l2 then -1\n else if r2 < l1 then 1\n else 0\n end)\n\nlet add elt s = RangeMap.add elt elt s\n\n(* n - size of playing field\n * k - number of ships\n * a - width of ship \n * m - number of moves *)\nlet () = Scanf.scanf \"%d %d %d\\n%d\\n\" (fun n k a m ->\n (* count number of ships that can fit in a k-wide space *)\n let count k = (k + 1) / (a + 1) in\n\n (* we want to maintain a bunch of intervals over which\n * it's possible for ships to fit *)\n let t = RangeMap.singleton (1, n) (1, n) in\n\n let rem = ref (count n) in\n\n let rec loop t i =\n if i <> m then\n let t' = Scanf.scanf \"%d%_c\" (fun x ->\n if RangeMap.mem (x, x) t\n then begin\n let l, r = RangeMap.find (x, x) t in\n rem := !rem - (count (r - l + 1)) + (count (x - l)) + (count (r - x));\n add (l, x - 1) (add (x + 1, r) (RangeMap.remove (x, x) t))\n end else t)\n in\n if !rem < k\n then Printf.printf \"%d\\n\" (i + 1)\n else loop t' (i + 1)\n in\n loop t 0;\n \n if !rem >= k then Printf.printf \"-1\\n\")\n"}], "negative_code": [], "src_uid": "e83c40f6d08b949900e5ae93b1d6f2c3"} {"source_code": "open List\nopen Printf\nopen Scanf\n\nlet inf= 1070000000;;\n\nlet rec getlist n =\n\tif n=0 then []\n\telse scanf \" %d\" (fun x->x)::getlist (n-1);;\n\nlet min a b = if ax)\nin let a = getlist n\nin let ans = min_ a\nin printf \"%d\\n\"\n\t(if for_all (fun x -> x mod ans = 0) a\n\t\tthen ans\n\t\telse (-1));;\n\n", "positive_code": [{"source_code": "open List\nopen Printf\nopen Scanf\n\nlet inf= 1070000000;;\n\nlet rec getlist n =\n\tif n=0 then []\n\telse scanf \" %d\" (fun x->x)::getlist (n-1);;\n\nlet min a b = if ax)\nin let a = getlist n\nin let ans = min_ a\nin printf \"%d\\n\"\n\t(if for_all (fun x -> x mod ans = 0) a\n\t\tthen ans\n\t\telse -1);;\n"}], "negative_code": [], "src_uid": "b0ffab0bf169f8278af48fe2d58dcd2d"} {"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\n(* int *)\nlet intsqrt n = \n if n < 0 then raise (Invalid_argument \"sqrt of negative int\") else \n let rec bs a b = begin \n if b - a = 1 then a else \n let mid = (a+b)/2 in \n if mid*mid <= n then bs mid b else bs a mid\n end in \n bs 0 (1 lsl 31)\n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* tuple *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let len = read_int() in \n let ch = make len 0 in \n let ca = make len 0 in\n\n for i = 0 to len-1 do \n ch.(i) <- read_int();\n ca.(i) <- read_int();\n done; \n\n sort compare ch;\n\n let rec run i = \n if i = len then () else begin \n let rec lower_bound a b = \n if b - a = 1 then b else \n let mid = (a+b)/2 in \n if ch.(mid) >= ca.(i) then lower_bound a mid else lower_bound mid b \n in \n let rec upper_bound a b =\n if b - a = 1 then b else \n let mid = (a+b)/2 in \n if ch.(mid) <= ca.(i) then upper_bound mid b else upper_bound a mid \n in \n let n = upper_bound (-1) len - lower_bound (-1) len in \n printf \"%d %d\\n\" (len-1+n) (len-1-n);\n run (i+1)\n end\n in \n run 0", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet home=Array.make (n+1) 0;;\nlet away=Array.make (n+1) 0;;\nlet color=Array.make 100001 0;;\nlet color2=Array.make 100001 0;;\nfor i=1 to n-1 do\n let x=read_int() and y=read_int() in\n home.(i)<-x;\n away.(i)<-y;\n color.(x)<-color.(x)+1;\n color2.(y)<-color2.(y)+1\ndone;;\nlet x=read_int() and y=Scanf.scanf \"%d\" (fun x->x) in\n begin\n home.(n)<-x;\n away.(n)<-y;\n color.(x)<-color.(x)+1;\n color2.(y)<-color2.(y)+1\n end;;\nfor i=1 to n do\n Printf.printf \"%d \" (n-1+color.(away.(i)));\n Printf.printf \"%d\\n\" (n-1-color.(away.(i)))\ndone;;\n"}], "negative_code": [{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\n(* int *)\nlet intsqrt n = \n if n < 0 then raise (Invalid_argument \"sqrt of negative int\") else \n let rec bs a b = begin \n if b - a = 1 then a else \n let mid = (a+b)/2 in \n if mid*mid <= n then bs mid b else bs a mid\n end in \n bs 0 (1 lsl 31)\n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* tuple *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create 1_000_000 in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let len = read_int() in \n let ch = make len 0 in \n let ca = make len 0 in\n\n for i = 0 to len-1 do \n ch.(i) <- read_int();\n ca.(i) <- read_int();\n done; \n\n sort compare ch;\n\n let rec run i = \n if i = len then () else begin \n let rec lower_bound a b = \n if b - a = 1 then b else \n let mid = (a+b)/2 in \n if ch.(mid) >= ca.(i) then lower_bound a mid else lower_bound mid b \n in \n let rec upper_bound a b =\n if b - a = 1 then b else \n let mid = (a+b)/2 in \n if ch.(mid) <= ca.(i) then upper_bound mid b else upper_bound a mid \n in \n let n = upper_bound 0 len - lower_bound (-1) len in \n printf \"%d %d\\n\" (len-1+n) (len-1-n);\n run (i+1)\n end\n in \n run 0"}], "src_uid": "7899a22cee29bb96d671f6188f246c21"} {"source_code": "let id x = x\n\nmodule S = struct\n open String\n\n let split_on_char sep s =\n let r = ref [] in\n let j = ref (String.length s) in\n for i = length s - 1 downto 0 do\n if unsafe_get s i = sep then begin\n r := sub s (i + 1) (!j - i - 1) :: !r;\n j := i\n end\n done;\n sub s 0 !j :: !r\nend\n\nlet alternating xs =\n let (result, _) =\n List.fold_left\n (fun prevResult curr ->\n match prevResult with\n | (false, _) -> (false, Some curr)\n | (true, Some x) -> (x <> curr, Some curr)\n | (true, None) -> (true, Some curr))\n (true, None)\n xs\n in\n result\n\nlet eq xs =\n let (result, _) =\n List.fold_left\n (fun prevResult curr ->\n match prevResult with\n | (false, _) -> (false, Some curr)\n | (true, Some x) -> (x = curr, Some curr)\n | (true, None) -> (true, Some curr))\n (true, None)\n xs\n in\n result\n\nlet solve () =\n let _ = Scanf.scanf \"%d\\n\" id in\n let xs =\n Scanf.scanf \"%s@\\n\" (fun x -> x)\n |> S.split_on_char ' '\n |> List.filter (fun x -> x <> \"\")\n |> List.map int_of_string\n |> List.map (fun x -> x mod 2)\n in\n if eq xs || alternating xs then\n print_endline \"YES\"\n else\n print_endline \"NO\"\n\nlet () =\n let t = Scanf.scanf \"%d\\n\" id in\n for i = 1 to t do\n solve ()\n done\n", "positive_code": [{"source_code": "let getInt () = Scanf.scanf \" %d\" (fun i -> i);;\r\n\r\nlet getList(n): int list = \r\n let rec getList2 ((n: int), (acc: int list)) = match n with\r\n\t | 0 -> List.rev acc\r\n\t | _ -> getList2 (n-1, getInt() :: acc)\r\n in getList2(n, [])\r\nlet rec f((arr: int list), (curr: int)) = \r\n match arr with\r\n | [] -> true\r\n | v1::(v2 :: xs) -> if (v1 mod 2) = curr then f(xs, curr) else false\r\n | v1::[] -> if (v1 mod 2) = curr then true else false;;\r\n\r\nlet main() = \r\n let t = getInt() in\r\n for i = 1 to t do \r\n let n = getInt() in let (arr: int list) = getList(n)\r\n in let a = (f(arr, 0) || f(arr, 1)) in let b = (f(List.tl(arr),0) || f(List.tl(arr), 1)) in \r\n if (a && b) then print_endline(\"YES\")\r\n else print_endline(\"NO\")\r\n done;;\r\n\r\nlet x = f([2;2;2;2], 0);;\r\nmain();;\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "fbb4e1cf1cad47481c6690ce54b27a1e"} {"source_code": "let (--) = Int64.sub\nlet zero = Int64.zero\n\nlet read_int () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_int64 () = Scanf.scanf \"%Ld \" (fun n -> n)\nlet print (min, max) = Printf.printf \"%Ld %Ld\\n\" min max\n\nlet make_array () = \n let n = read_int () in\n let array = Array.make n zero in\n let rec loop i array = \n if i < n\n then\n let city = read_int64 () in\n let () = Array.set array i city in\n loop (i + 1) array\n else\n (n, array)\n in loop 0 array\n\nlet get_first_last (n, array) =\n let first = array.(0) in\n let last = array.(n - 1) in\n (first, last) \n \nlet get_min_max (first, last) (n, array) i curr = \n if i = 0\n then\n let min = array.(i + 1) -- curr in\n let max = last -- curr in\n print (min, max)\n else\n if i = n - 1\n then\n let min = curr -- array.(i - 1) in\n let max = curr -- first in\n print (min, max)\n else\n let min = Pervasives.min (curr -- array.(i - 1)) (array.(i + 1) -- curr) in\n let max = Pervasives.max (curr -- first) (last -- curr) in\n print (min, max)\n\nlet () = \n let (n, cities) = make_array () in\n let (first, last) = get_first_last (n, cities) in\n Array.iteri (get_min_max (first, last) (n, cities)) cities", "positive_code": [{"source_code": "let (--) = Int64.sub\nlet zero = Int64.zero\n\nlet read_int () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_int64 () = Scanf.scanf \"%Ld \" (fun n -> n)\nlet print (min, max) = Printf.printf \"%Ld %Ld\\n\" min max\n\nlet make_array () = \n let n = read_int () in\n let array = Array.make n zero in\n let rec loop i array = \n if i < n\n then\n let city = read_int64 () in\n let () = Array.set array i city in\n loop (i + 1) array\n else\n (n, array)\n in loop 0 array\n\nlet get_min_max (n, array) i curr =\n let min =\n if i = 0\n then\n array.(i + 1) -- curr\n else\n if i = n - 1\n then\n curr -- array.(i - 1)\n else\n Pervasives.min (curr -- array.(i - 1)) (array.(i + 1) -- curr)\n in\n let max = Pervasives.max (curr -- array.(0)) (array.(n - 1) -- curr) in\n print (min, max)\n\nlet () = \n let (n, cities) = make_array () in\n Array.iteri (get_min_max (n, cities)) cities"}, {"source_code": "let read_int () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_int64 () = Scanf.scanf \"%Ld \" (fun n -> n)\n\nlet make_array () = \n let n = read_int () in\n let array = Array.make n Int64.zero in\n let rec loop i array = \n if i < n\n then\n let city = read_int64 () in\n let () = Array.set array i city in\n loop (i + 1) array\n else\n (n, array)\n in loop 0 array\n\nlet get_min_max (n, array) =\n let first = array.(0) in\n let last = array.(n - 1) in\n let rec loop i list =\n if i < n\n then\n let curr = array.(i) in\n let min_max =\n if i = 0\n then\n let min = Int64.sub array.(i + 1) curr in\n let max = Int64.sub last curr in\n (min, max)\n else\n if i = n - 1\n then\n let min = Int64.sub curr array.(i - 1) in\n let max = Int64.sub curr first in\n (min, max)\n else\n let min = Pervasives.min (Int64.sub curr array.(i - 1)) (Int64.sub array.(i + 1) curr) in\n let max = Pervasives.max (Int64.sub curr first) (Int64.sub last curr) in\n (min, max)\n in loop (i + 1) (min_max :: list)\n else\n List.rev list\n in loop 0 []\n\nlet print list = List.iter (fun (min, max) -> Printf.printf \"%Ld %Ld\\n\" min max) list\n\nlet () = print (get_min_max (make_array ()))"}, {"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.stdib \" %d \" (fun x -> x)\nlet () = \n let n = read_int () in\n let x = Array.init n (fun _ -> long (read_int())) in\n\n Array.sort compare x;\n\n let inf = 1_000_000_000_000L in\n let closest i =\n let li = [] in\n let li = if i=0 then li else (x.(i) -- x.(i-1))::li in\n let li = if i=n-1 then li else (x.(i+1) -- x.(i))::li in\n List.fold_left (fun ac x -> min ac x) inf li\n in\n\n let farthest i =\n let li = [x.(n-1) -- x.(i); x.(i) -- x.(0)] in\n List.fold_left (fun ac x -> max ac x) 0L li\n in\n\n for i=0 to n-1 do\n printf \"%Ld %Ld\\n\" (closest i) (farthest i)\n done;\n"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%Ld%_c\" (fun x -> x)) in\n let (--) = Int64.sub in\n Array.iteri (fun i x ->\n let mn, mx =\n if i = 0\n then (a.(1) -- x, a.(n - 1) -- x)\n else if i = n - 1\n then (x -- a.(i - 1), x -- a.(0))\n else (min (x -- a.(i - 1)) (a.(i + 1) -- x),\n max (x -- a.(0)) (a.(n - 1) -- x))\n in Printf.printf \"%Ld %Ld\\n\" mn mx) a)\n"}], "negative_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet make_array () = \n let n = read () in\n let array = Array.make n 0 in\n let rec loop i array = \n if i < n\n then\n let city = read () in\n let () = Array.set array i city in\n loop (i + 1) array\n else\n (n, array)\n in loop 0 array\n\nlet get_min_max (n, array) =\n let first = array.(0) in\n let last = array.(n - 1) in\n let rec loop i list =\n if i < n\n then\n let curr = array.(i) in\n let min_max =\n if i = 0\n then\n let min = array.(i + 1) - curr in\n let max = last - curr in\n (min, max)\n else\n if i = n - 1\n then\n let min = curr - array.(i - 1) in\n let max = curr - first in\n (min, max)\n else\n let min = Pervasives.min (curr - array.(i - 1)) (array.(i + 1) - curr) in\n let max = Pervasives.max (curr - first) (last - curr) in\n (min, max)\n in loop (i + 1) (min_max :: list)\n else\n List.rev list\n in loop 0 []\n\nlet print list = List.iter (fun (min, max) -> Printf.printf \"%d %d\\n\" min max) list\n\nlet () = print (get_min_max (make_array ()))"}, {"source_code": "let () = Scanf.scanf \"%d\\n\" (fun n ->\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n Array.iteri (fun i x ->\n let mn, mx =\n if i = 0\n then (a.(1) - x, a.(n - 1) - x)\n else if i = n - 1\n then (x - a.(i - 1), x - a.(0))\n else (min (x - a.(i - 1)) (a.(i + 1) - x),\n max (x - a.(0)) (a.(n - 1) - x))\n in Printf.printf \"%d %d\\n\" mn mx) a)\n"}], "src_uid": "55383f13c8d097408b0ccf5653c4563d"} {"source_code": "module NodeSet = Set.Make (struct \n type t = int * bool\n let compare x y = compare x y\nend)\n\nlet rec bfs que nodes level visited n k =\n if NodeSet.is_empty que then\n false\n else if NodeSet.max_elt que >= (n,false) then\n true\n else if level > n then\n false\n else\n let nque,visited = NodeSet.fold (fun (x,b) (nque,visited) ->\n if NodeSet.mem (x,b) visited then\n nque,visited\n else\n let visited = NodeSet.add (x,b) visited in\n let next = [(x+1,b);(x-1,b);(x+k,not b)] in\n List.fold_left (fun e (x,b) -> \n if x > level && (NodeSet.mem (x,b) nodes|| x > n) then\n (* let () = print_endline (\"(\"^string_of_int x^\",\"\n ^string_of_bool b^\",\"\n ^string_of_int level^\")\")in\n *) NodeSet.add (x,b) e\n else\n e) nque next,visited) que (NodeSet.empty,visited) in\n bfs nque nodes (level+1) visited n k\n\nlet solve s1 s2 n k =\n let nodes = ref NodeSet.empty in\n let i = ref 0 in\n let () = String.iter (function\n | '-' -> nodes := NodeSet.add (!i,false) !nodes; i := !i+1;\n | _ -> i := !i+1) s1 in\n let () = i := 0 in\n let () = String.iter (function\n | '-' -> nodes := NodeSet.add (!i,true) !nodes; i := !i+1;\n | _ -> i := !i+1) s2 in\n bfs (NodeSet.singleton (0,false)) !nodes 0 NodeSet.empty (n-1) k\n \nlet main () =\n let rval = Scanf.bscanf Scanf.Scanning.stdib \"%d %d\\n%s\\n%s\\n\" \n (fun n k s1 s2 -> solve s1 s2 n k) in\n if rval then\n print_endline \"YES\"\n else\n print_endline \"NO\"\n\nlet _ = main ()", "positive_code": [{"source_code": "exception Found\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let kk = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let sl = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let sr = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let s = [| sl; sr |] in\n let used = Array.make_matrix 2 n false in\n (*let d = Array.make_matrix 2 n (-1) in*)\n let q1 = Array.make (n * 2) (0, 0) in\n let l1 = ref 0 in\n let q2 = Array.make (n * 2) (0, 0) in\n let l2 = ref 0 in\n let rec bfs_step k q1 l1 q2 l2 =\n l2 := 0;\n for i = 0 to !l1 - 1 do\n let (x, y) = q1.(i) in\n\tif y - 1 > k && s.(x).[y - 1] <> 'X' then (\n\t if not used.(x).(y - 1) then (\n\t used.(x).(y - 1) <- true;\n\t q2.(!l2) <- (x, y - 1);\n\t incr l2\n\t );\n\t);\n\tif y + 1 >= n\n\tthen raise Found;\n\tif s.(x).[y + 1] <> 'X' then (\n\t if not used.(x).(y + 1) then (\n\t used.(x).(y + 1) <- true;\n\t q2.(!l2) <- (x, y + 1);\n\t incr l2\n\t );\n\t);\n\tif y + kk >= n\n\tthen raise Found;\n\tif s.(1 - x).[y + kk] <> 'X' then (\n\t if not used.(1 - x).(y + kk) then (\n\t used.(1 - x).(y + kk) <- true;\n\t q2.(!l2) <- (1 - x, y + kk);\n\t incr l2\n\t );\n\t);\n done;\n if !l2 > 0\n then bfs_step (k + 1) q2 l2 q1 l1\n in\n used.(0).(0) <- true;\n l1 := 0;\n l2 := 0;\n q1.(!l1) <- (0, 0);\n incr l1;\n try\n bfs_step 0 q1 l1 q2 l2;\n Printf.printf \"NO\\n\"\n with\n | Found ->\n\t Printf.printf \"YES\\n\"\n"}, {"source_code": "\nmodule NodeSet = Set.Make (struct \n type t = int * bool\n let compare x y = compare x y\nend)\n\nlet rec bfs que nodes level visited n k =\n if NodeSet.is_empty que then\n false\n else if NodeSet.max_elt que >= (n,false) then\n true\n else if level > n then\n false\n else\n let nque,visited = NodeSet.fold (fun (x,b) (nque,visited) ->\n if NodeSet.mem (x,b) visited then\n nque,visited\n else\n let visited = NodeSet.add (x,b) visited in\n let next = [(x+1,b);(x-1,b);(x+k,not b)] in\n List.fold_left (fun e (x,b) -> \n if x > level && (NodeSet.mem (x,b) nodes|| x > n) then\n (* let () = print_endline (\"(\"^string_of_int x^\",\"\n ^string_of_bool b^\",\"\n ^string_of_int level^\")\")in\n *) NodeSet.add (x,b) e\n else\n e) nque next,visited) que (NodeSet.empty,visited) in\n bfs nque nodes (level+1) visited n k\n\nlet solve s1 s2 n k =\n let nodes = ref NodeSet.empty in\n let i = ref 0 in\n let () = String.iter (function\n | '-' -> nodes := NodeSet.add (!i,false) !nodes; i := !i+1;\n | _ -> i := !i+1) s1 in\n let () = i := 0 in\n let () = String.iter (function\n | '-' -> nodes := NodeSet.add (!i,true) !nodes; i := !i+1;\n | _ -> i := !i+1) s2 in\n bfs (NodeSet.singleton (0,false)) !nodes 0 NodeSet.empty (n-1) k\n \nlet main () =\n let rval = Scanf.bscanf Scanf.Scanning.stdib \"%d %d\\n%s\\n%s\\n\" \n (fun n k s1 s2 -> solve s1 s2 n k) in\n if rval then\n print_endline \"YES\"\n else\n print_endline \"NO\"\n\nlet _ = main ()\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_char _ = bscanf Scanning.stdib \" %c \" (fun x -> x)\n\nlet () =\n let n = read_int () and k = read_int () in\n let a = Array.make_matrix n 2 ' ' in\n for i = 0 to n - 1 do\n a.(i).(0) <- read_char ()\n done;\n for i = 0 to n - 1 do\n a.(i).(1) <- read_char ()\n done;\n let bfs start =\n let visited = Array.make_matrix n 2 false\n and time = Array.make_matrix n 2 0\n and q = Queue.create ()\n and ans = ref false in\n visited.(fst start).(snd start) <- true;\n Queue.push start q;\n while not (Queue.is_empty q) do\n let (v, side) = Queue.pop q in\n if time.(v).(side) <= v then begin\n if v + k >= n then ans := true;\n let go i j =\n 0 <= i && i <= n - 1 && a.(i).(j) <> 'X' && not visited.(i).(j) in\n if go (v - 1) side then begin\n visited.(v- 1).(side) <- true;\n time.(v - 1).(side) <- time.(v).(side) + 1;\n Queue.push ((v - 1), side) q\n end;\n if go (v + 1) side then begin\n visited.(v + 1).(side) <- true;\n time.(v + 1).(side) <- time.(v).(side) + 1;\n Queue.push ((v + 1), side) q\n end;\n if go (v + k) ((side + 1) mod 2) then begin\n visited.(v + k).((side + 1) mod 2) <- true;\n time.(v + k).((side + 1) mod 2) <- time.(v).(side) + 1;\n Queue.push ((v + k), ((side + 1) mod 2)) q\n end;\n end\n done;\n !ans in\n if bfs (0, 0) then printf \"YES\\n\"\n else printf \"NO\""}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_char _ = bscanf Scanning.stdib \" %c \" (fun x -> x)\n\nlet () =\n let n = read_int () and k = read_int () in\n let a = Array.make_matrix n 2 ' ' in\n for i = 0 to n - 1 do\n a.(i).(0) <- read_char ()\n done;\n for i = 0 to n - 1 do\n a.(i).(1) <- read_char ()\n done;\n let bfs start =\n let queue = Array.make (2 * n) (0, 0) and front = ref 0 and back = ref 0 in\n let push w =\n queue.(!back) <- w;\n back := !back + 1 in\n let pop () =\n let x = queue.(!front) in\n front := !front + 1;\n x in\n let visited = Array.make_matrix n 2 false\n and time = Array.make_matrix n 2 0 in\n let ans = ref false in\n visited.(fst start).(snd start) <- true;\n push start;\n while not (!back = !front) do\n let (v, side) = pop () in\n if time.(v).(side) <= v then begin\n if v + k >= n then ans := true;\n let go i j =\n 0 <= i && i <= n - 1 && a.(i).(j) <> 'X' && not visited.(i).(j) in\n if go (v - 1) side then begin\n visited.(v - 1).(side) <- true;\n time.(v - 1).(side) <- time.(v).(side) + 1;\n push ((v - 1), side)\n end;\n if go (v + 1) side then begin\n visited.(v + 1).(side) <- true;\n time.(v + 1).(side) <- time.(v).(side) + 1;\n push ((v + 1), side)\n end;\n if go (v + k) ((side + 1) mod 2) then begin\n visited.(v + k).((side + 1) mod 2) <- true;\n time.(v + k).((side + 1) mod 2) <- time.(v).(side) + 1;\n push ((v + k), ((side + 1) mod 2))\n end;\n end\n done;\n !ans in\n if bfs (0, 0) then printf \"YES\\n\"\n else printf \"NO\""}], "negative_code": [], "src_uid": "e95bde11483e05751ee7da91a6b4ede1"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n let s = 1_000_000 in\n let n = read_int () in\n\n let comp x = s+1-x in\n let usedx = Array.make (s+1) false in\n \n for i=0 to n-1 do\n usedx.(read_int ()) <- true;\n done;\n\n printf \"%d\\n\" n;\n\n let count = ref 0 in\n\n for i=1 to s do\n if (not usedx.(i)) && usedx.(comp i) then (\n usedx.(i) <- true;\n printf \"%s%d\" (if !count=0 then \"\" else \" \") i;\n count := !count+1\n )\n done;\n\n let pairs = (n - !count)/2 in\n \n let rec loop y j = if j=0 then () else\n if not usedx.(y) then (\n\tprintf \"%s%d %d\" (if !count=0 then \"\" else \" \") y (comp y);\n\tcount := !count + 2;\n\tloop (y+1) (j-1)\n ) else loop (y+1) j\n in\n\n loop 1 pairs;\n print_newline()\n \n \n\n\n \n \n\n", "positive_code": [{"source_code": "\nopen Printf\nopen Scanf\n\nlet (@@) f x = f x;;\nlet (@.) f g x = f (g x);;\n\nlet read_int () = scanf \" %d\" (fun x -> x);;\n\nlet n = read_int();;\n\nlet a = Array.make 1000000 false;;\nmodule IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;\n\nlet () = \n for i = 0 to n-1 do\n a.(read_int() - 1) <- true;\n done;\n;;\n\nlet rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =\n if i = 500000 then (count, set)\n else if a.(i) then\n if a.(1000000-i-1) then f (i+1) (count+1) set\n else f (i+1) count @@ IntSet.add (1000000-i) set\n else\n if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set\n else f (i+1) count set\n;;\n\nlet (count, set) = f 0 0 IntSet.empty;;\n\nlet rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t = \n if i = 500000 then (count, set)\n else if count = 0 then (0, set)\n else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i) set\n else g (i+1) count set\n;;\n\nlet (count, set) = g 0 count set;;\n\nprintf \"%d\\n\" @@ IntSet.cardinal set;\nIntSet.iter (fun x -> printf \"%d \" x) set;\nprint_newline();"}], "negative_code": [{"source_code": "\nopen Printf\nopen Scanf\n\nlet (@@) f x = f x;;\nlet (@.) f g x = f (g x);;\n\nlet read_int () = scanf \" %d\" (fun x -> x);;\n\nlet n = read_int();;\n\nlet a = Array.make 1000000 false;;\nmodule IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;\n\nlet () = \n for i = 0 to n-1 do\n a.(read_int() - 1) <- true;\n done;\n;;\n\nlet rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =\n if i = 500000 then (count, set)\n else if a.(i) then\n if a.(1000000-i-1) then f (i+1) (count+1) set\n else f (i+1) count @@ IntSet.add (1000000-i) set\n else\n if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set\n else f (i+1) count set\n;;\n\nlet (count, set) = f 0 0 IntSet.empty;;\n\nlet rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t = \n if i = 500000 then (count, set)\n else if count = 0 then (0, set)\n else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i-1) set\n else g (i+1) count set\n;;\n\nlet (count, set) = g 0 count set;;\n\nIntSet.iter (fun x -> printf \"%d \" x) set;\nprint_newline();"}, {"source_code": "\nopen Printf\nopen Scanf\n\nlet (@@) f x = f x;;\nlet (@.) f g x = f (g x);;\n\nlet read_int () = scanf \" %d\" (fun x -> x);;\n\nlet n = read_int();;\n\nlet a = Array.make 1000000 false;;\nmodule IntSet = Set.Make(struct type t = int;; let compare = Pervasives.compare;; end);;\n\nlet () = \n for i = 0 to n-1 do\n a.(read_int() - 1) <- true;\n done;\n;;\n\nlet rec f (i : int) (count : int) (set : IntSet.t) : int * IntSet.t =\n if i = 500000 then (count, set)\n else if a.(i) then\n if a.(1000000-i-1) then f (i+1) (count+1) set\n else f (i+1) count @@ IntSet.add (1000000-i) set\n else\n if a.(1000000-i-1) then f (i+1) count @@ IntSet.add (i+1) set\n else f (i+1) count set\n;;\n\nlet (count, set) = f 0 0 IntSet.empty;;\n\nlet rec g (i : int) (count : int) (set : IntSet.t) : int * IntSet.t = \n if i = 500000 then (count, set)\n else if count = 0 then (0, set)\n else if (not a.(i)) && (not a.(1000000-i-1)) then g (i+1) (count-1) @@ IntSet.add (i+1) @@ IntSet.add (1000000-i-1) set\n else g (i+1) count set\n;;\n\nlet (count, set) = g 0 count set;;\n\nprintf \"%d\\n\" @@ IntSet.cardinal set;\nIntSet.iter (fun x -> printf \"%d \" x) set;\nprint_newline();"}], "src_uid": "4143caa25fcc2f4d400d169f9697be01"} {"source_code": "open Printf\n\nlet order a b =\n if a < b then (a, b) else (b, a)\n\nlet () =\n let n = int_of_string @@ input_line stdin in\n if n mod 2 = 0 then\n printf \"4 %d\\n\" (n - 4)\n else\n let (a, b) = order 9 (n - 9) in\n printf \"%d %d\\n\" a b \n", "positive_code": [{"source_code": "let input () = Scanf.scanf \"%d\" (fun n -> n)\n\nlet solve int = \n let rec loop n =\n if n < int / 2\n then\n let div = 2 * n in\n let rest = int - div in\n if rest mod 2 = 0\n then\n (div, rest)\n else\n if rest mod 3 = 0\n then\n (div, rest)\n else\n loop (n + 1)\n else\n failwith \"Bad number\"\n in loop 2\n\nlet print (a, b) = Printf.printf \"%d %d\\n\" a b\n\nlet () = print (solve (input ()))"}], "negative_code": [], "src_uid": "3ea971165088fae130d866180c6c868b"} {"source_code": "open Printf\nopen Scanf\n\nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n\nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n g.(u) <- ((v, w) :: g.(u));\n g.(v) <- ((u, w) :: g.(v))\n done;\n\n let edges = Array.make n (0L, 0) in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n edges.(new_vert) <- (cost, add)\n )\n in\n\n List.iter (fun (new_vert, cost) -> upd_cnt new_vert cost) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let sum = ref 0L in\n\n let rec calc_set ind =\n if ind = n then SS.empty\n else (\n let set_now = calc_set (ind + 1) in\n let (cost, cnt) = edges.(ind) in\n let mult = Int64.mul cost (Int64.of_int cnt) in\n sum := Int64.add !sum mult;\n let mult = Int64.mul (div2 cost) (Int64.of_int cnt) in\n SS.add (mult, ind) set_now\n )\n in\n\n let answer = ref 0 in\n \n let set = Array.make 1 (calc_set 0) in\n\n while !sum > s do\n answer := !answer + 1;\n let (del_value, del_id) = SS.max_elt set.(0) in\n let new_set = SS.remove (del_value, del_id) set.(0) in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n edges.(del_id) <- (Int64.div cost_edge 2L, cnt_edge);\n let cost_edge = Int64.div cost_edge 2L in\n let new_cost_edge = div2 cost_edge in\n let new_set = SS.add (Int64.mul new_cost_edge (Int64.of_int cnt_edge), del_id) new_set in\n sum := Int64.add !sum (Int64.mul (Int64.of_int (-1)) del_value);\n set.(0) <- new_set\n done;\n \n printf \"%d\\n\" !answer\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done", "positive_code": [{"source_code": "open Printf\nopen Scanf\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n \nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n \nlet solve() =\n let t = Sys.time() in\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n \n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n let c = 1 in\n g.(u) <- ((v, w, c) :: g.(u));\n g.(v) <- ((u, w, c) :: g.(v))\n done;\n \n let list_1 = ref [] in\n let list_2 = ref [] in\n let sum = ref 0L in\n \n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n \n let upd_cnt new_vert cost t =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n \n let mult = Int64.mul cost (Int64.of_int add) in\n sum := Int64.add !sum mult;\n let c = ref cost in\n while !c > 0L do\n let mult = Int64.mul (div2 !c) (Int64.of_int add) in\n if t = 1 then (\n list_1 := mult :: !list_1\n ) \n else (\n list_2 := mult :: !list_2\n );\n c := Int64.div !c 2L\n done \n )\n in\n \n List.iter (fun (new_vert, cost, t) -> upd_cnt new_vert cost t) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n \n let answer = ref 0 in\n \n list_1 := List.sort compare !list_1;\n list_2 := List.sort compare !list_2;\n list_1 := List.rev !list_1;\n list_2 := List.rev !list_2;\n \n while !sum > s do\n if t -. Sys.time() > 2.5 then (\n sum := 0L\n )\n else (\n if List.length !list_2 = 0 then (\n sum := Int64.sub !sum (List.hd !list_1);\n list_1 := List.tl !list_1\n ) else if List.length !list_1 = 0 then (\n sum := Int64.sub !sum (List.hd !list_2);\n list_2 := List.tl !list_2;\n answer := !answer + 1\n ) else (\n let cost_1 = List.hd !list_1 in\n let cost_2 = List.hd !list_2 in\n if cost_1 >= cost_2 || !sum <= (Int64.add s cost_1) then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n let cost_3 = if List.length !list_1 > 1 then List.hd (List.tl !list_1) else 0L in\n if (Int64.add cost_1 cost_3) >= cost_2 then (\n list_1 := List.tl !list_1;\n sum := Int64.sub !sum cost_1\n ) else (\n list_2 := List.tl !list_2;\n sum := Int64.sub !sum cost_2;\n answer := !answer + 1\n )\n )\n )\n );\n \n answer := !answer + 1\n done;\n \n printf \"%d\\n\" !answer\n;;\n \nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nmodule Pair = struct \n type t = int64 * int \n let compare = compare\nend\n\nmodule SS = Set.Make(Pair)\n \nlet read_int _ = bscanf Scanning.stdin \"%d \" (fun x -> x)\nlet read_lint _ = bscanf Scanning.stdin \"%Ld \" (fun x -> x)\n\nlet div2 a =\n Int64.div (Int64.add a 1L) 2L\n;;\n\nlet solve() =\n let n = read_int() in\n let s = read_lint() in\n let g = Array.make n [] in\n\n for i = 0 to n - 2 do\n let u = read_int() - 1 in\n let v = read_int() - 1 in\n let w = read_lint() in\n g.(u) <- ((v, w) :: g.(u));\n g.(v) <- ((u, w) :: g.(v))\n done;\n\n let edges = Array.make n (0L, 0) in\n\n let rec dfs vert parent =\n let cnt_leaves = ref (if List.length g.(vert) = 1 then 1 else 0) in\n\n let upd_cnt new_vert cost =\n if new_vert = parent then ()\n else (\n let add = dfs new_vert vert in\n cnt_leaves := !cnt_leaves + add;\n edges.(new_vert) <- (cost, add)\n )\n in\n\n List.iter (fun (new_vert, cost) -> upd_cnt new_vert cost) g.(vert);\n \n !cnt_leaves\n in\n \n dfs 0 0;\n\n let sum = ref 0L in\n\n let rec calc_set ind =\n if ind = n then SS.empty\n else (\n let set_now = calc_set (ind + 1) in\n let (cost, cnt) = edges.(ind) in\n let mult = Int64.mul cost (Int64.of_int cnt) in\n sum := Int64.add !sum mult;\n let mult = Int64.mul (div2 cost) (Int64.of_int cnt) in\n SS.add (mult, ind) set_now\n )\n in\n\n if n = 100000 then printf \"not runtime\"\n else (\n let rec greed priority_set now_cost = \n if now_cost <= s then 0\n else (\n let (del_value, del_id) = SS.max_elt priority_set in\n let new_set = SS.remove (del_value, del_id) priority_set in\n let (cost_edge, cnt_edge) = edges.(del_id) in\n edges.(del_id) <- (Int64.div cost_edge 2L, cnt_edge);\n let cost_edge = Int64.div cost_edge 2L in\n let new_cost_edge = div2 cost_edge in\n let new_set = SS.add (Int64.mul new_cost_edge (Int64.of_int cnt_edge), del_id) new_set in\n 1 + (greed new_set (Int64.add now_cost (Int64.mul (Int64.of_int (-1)) del_value)))\n )\n in\n\n let set = calc_set 0 in\n \n printf \"%d\\n\" (greed set !sum)\n )\n;;\n\nlet () = \n let cases = read_int() in\n for case = 1 to cases do\n solve()\n done"}], "src_uid": "9cd7f058d4671b12b67babd38293a3fc"} {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x)\nlet read_string () = Scanf.scanf \" %s \" (fun x -> x)\nlet read_list read_func size =\n let rec aux lst rf sz =\n if sz = 0 then lst\n else aux (rf () :: lst) rf (sz - 1)\n in\n aux [] read_func size\n (*List.rev (aux [] read_func size)*)\nlet is_even num = num land 1 = 0\nlet is_odd num = num land 1 = 1\n\nlet () =\n let n = read_int () in\n let m = read_int () in\n let wordlist = read_list read_string (n + m) in\n (*List.iter (Printf.printf \"%s d\\n\") wordlist*)\n let uniqsorted = List.sort_uniq compare wordlist in\n let uslen = List.length uniqsorted in\n let isodd = if is_odd uslen then 1 else 0 in\n if isodd + n > m then print_string \"YES\\n\" else print_string \"NO\\n\"\n\n", "positive_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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let ht = Hashtbl.create 10 in\n let c = ref 0 in\n for i = 1 to n do\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tHashtbl.replace ht s ()\n done;\n for i = 1 to m do\n let s = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tif Hashtbl.mem ht s\n\tthen incr c;\n done;\n if !c mod 2 = 0 && n > m || !c mod 2 = 1 && n >= m\n then Printf.printf \"YES\\n\"\n else Printf.printf \"NO\\n\"\n"}], "negative_code": [], "src_uid": "4b352854008a9378551db60b76d33cfa"} {"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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x) \nlet () = \n let n = read_int () in\n let s = Array.init n (fun i -> read_int()) in\n\n let maxs = 100_000 in\n \n let pcount = Array.make maxs 0 in\n\n for i=0 to n-1 do\n let lf = factor s.(i) in\n let lf = List.sort_uniq compare lf in\n List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;\n done;\n\n let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in\n\n printf \"%d\\n\" (max answer 1)\n", "positive_code": [{"source_code": "let _ =\n let n2 = 100000 in\n let prime = Array.make (n2 + 1) true in\n let p = Array.make (n2 + 1) 0 in\n let pd = Array.init (n2 + 1) (fun i -> i) in\n let pk = ref 0 in\n let () =\n for i = 2 to n2 do\n if prime.(i) then (\n\tp.(!pk) <- i;\n\tincr pk;\n\tpd.(i) <- i;\n\tlet j = ref (2 * i) in\n while !j <= n2 do\n\t let jj = !j in\n prime.(jj) <- false;\n\t pd.(jj) <- i;\n j := jj + i\n done\n )\n done;\n prime.(1) <- false;\n in\n let pk = !pk - 1 in\n let fp = Array.make 20 0 in\n let fd = Array.make 20 0 in\n let ff = Array.make 20 0 in\n let factor x =\n let r = ref 0 in\n let x = ref x in\n while !x > 1 && not (pd.(!x) = !x) do\n\tlet pr = pd.(!x) in\n\t let d = ref 0 in\n\t ff.(!r) <- 1;\n\t while !x mod pr = 0 do\n\t incr d;\n\t x := !x / pr;\n\t ff.(!r) <- ff.(!r) * pr;\n\t done;\n\t fp.(!r) <- pr;\n\t fd.(!r) <- !d;\n\t incr r;\n done;\n if !x > 1 then (\n\tfp.(!r) <- !x;\n\tfd.(!r) <- 1;\n\tff.(!r) <- !x;\n\tincr r;\n );\n !r\n in\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 c = Array.make (n2 + 1) 0 in\n let _ =\n for i = 0 to n - 1 do\n let t = factor a.(i) in\n\tfor j = 0 to t - 1 do\n\t c.(fp.(j)) <- c.(fp.(j)) + 1\n\tdone;\n done;\n in\n let res = ref 1 in\n for i = 0 to n2 do\n res := max !res c.(i)\n done;\n Printf.printf \"%d\\n\" !res\n"}], "negative_code": [{"source_code": "let _ =\n let n2 = 100000 in\n let prime = Array.make (n2 + 1) true in\n let p = Array.make (n2 + 1) 0 in\n let pd = Array.init (n2 + 1) (fun i -> i) in\n let pk = ref 0 in\n let () =\n for i = 2 to n2 do\n if prime.(i) then (\n\tp.(!pk) <- i;\n\tincr pk;\n\tpd.(i) <- i;\n\tlet j = ref (2 * i) in\n while !j <= n2 do\n\t let jj = !j in\n prime.(jj) <- false;\n\t pd.(jj) <- i;\n j := jj + i\n done\n )\n done;\n prime.(1) <- false;\n in\n let pk = !pk - 1 in\n let fp = Array.make 20 0 in\n let fd = Array.make 20 0 in\n let ff = Array.make 20 0 in\n let factor x =\n let r = ref 0 in\n let x = ref x in\n while !x > 1 && not (pd.(!x) = !x) do\n\tlet pr = pd.(!x) in\n\t let d = ref 0 in\n\t ff.(!r) <- 1;\n\t while !x mod pr = 0 do\n\t incr d;\n\t x := !x / pr;\n\t ff.(!r) <- ff.(!r) * pr;\n\t done;\n\t fp.(!r) <- pr;\n\t fd.(!r) <- !d;\n\t incr r;\n done;\n if !x > 1 then (\n\tfp.(!r) <- !x;\n\tfd.(!r) <- 1;\n\tff.(!r) <- !x;\n\tincr r;\n );\n !r\n in\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 c = Array.make (n2 + 1) 0 in\n let _ =\n for i = 0 to n - 1 do\n let t = factor a.(i) in\n\tfor j = 0 to t - 1 do\n\t c.(fp.(j)) <- c.(fp.(j)) + 1\n\tdone;\n done;\n in\n let res = ref 0 in\n for i = 0 to n2 do\n res := max !res c.(i)\n done;\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x) \nlet () = \n let n = read_int () in\n let s = Array.init n (fun i -> read_int()) in\n\n let maxs = 100_000 in\n \n let pcount = Array.make maxs 0 in\n\n for i=0 to n-1 do\n let lf = factor s.(i) in\n let lf = List.sort_uniq compare lf in\n List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;\n done;\n\n let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in\n\n printf \"%d\\n\" (min answer 1)\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\nlet maxf i j f = fold (i+1) j (fun k a -> max (f k) a) (f i)\n\nlet factor n = \n let rec loop n p ac = \n if n=1 then ac\n else if p*p > n then (n::ac)\n else if n mod p = 0 then loop (n/p) p (p::ac)\n else loop n (p+1) ac\n in\n List.rev (loop n 2 [])\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x) \nlet () = \n let n = read_int () in\n let s = Array.init n (fun i -> read_int()) in\n\n let maxs = 100_000 in\n \n let pcount = Array.make maxs 0 in\n\n for i=0 to n-1 do\n let lf = factor s.(i) in\n let lf = List.sort_uniq compare lf in\n List.iter (fun f -> pcount.(f) <- pcount.(f) + 1) lf;\n done;\n\n let answer = maxf 0 (maxs-1) (fun i -> pcount.(i)) in\n\n printf \"%d\\n\" answer\n"}], "src_uid": "eea7860e6bbbe5f399b9123ebd663e3e"} {"source_code": "let _ = read_line () |> int_of_string and\n ts = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in \nlet ones = List.mapi (fun i a -> if a = 1 then i + 1 else 0) ts and\n twos = List.mapi (fun i a -> if a = 2 then i + 1 else 0) ts and\n threes = List.mapi (fun i a -> if a = 3 then i + 1 else 0) ts in\nlet rec map3 a b c acc = \n match (a,b,c) with\n | ([], _, _) -> acc \n | (_, [], _) -> acc \n | (_, _, []) -> acc \n | ((0::ax), (b::bx), (c::cx)) -> map3 ax (b::bx) (c::cx) acc\n | ((a::ax), (0::bx), (c::cx)) -> map3 (a::ax) bx (c::cx) acc\n | ((a::ax), (b::bx), (0::cx)) -> map3 (a::ax) (b::bx) cx acc\n | ((a::ax), (b::bx), (c::cx)) -> map3 ax bx cx ([a;b;c]::acc) in\nlet print_list ls = \nbegin\nList.length ls |> Printf.printf \"%d\\n\";\nList.iter (fun l -> Printf.printf \"%d %d %d\\n\" (List.nth l 0) (List.nth l 1) (List.nth l 2)) ls\nend in\nmap3 ones twos threes [] |> print_list\n \n\n", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet divide () = \n let n = read () in\n let rec loop i one two three =\n if i <= n\n then\n match read () with\n | 1 -> loop (i + 1) (i :: one) two three\n | 2 -> loop (i + 1) one (i :: two) three\n | 3 -> loop (i + 1) one two (i :: three)\n else\n (one, two, three)\n in loop 1 [] [] []\n\nlet combine (one, two, three) = \n let rec loop one two three list =\n match one, two, three with\n | (coder :: one), (mather :: two), (boxer :: three) -> \n loop one two three ((coder :: mather :: boxer :: []) :: list)\n | _ -> list\n in loop one two three []\n\nlet solve () = \n let teams = combine (divide ()) in\n let total = List.length teams in\n (total, teams)\n\nlet print (n, teams) = \n Printf.printf \"%d\\n\" n;\n List.iter (fun [a; b; c] -> Printf.printf \"%d %d %d\\n\" a b c) teams\n\nlet () = print (solve())"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet divide () = \n let n = read () in\n let rec loop i one two three =\n if i <= n\n then\n match read () with\n | 1 -> loop (i + 1) (i :: one) two three\n | 2 -> loop (i + 1) one (i :: two) three\n | 3 -> loop (i + 1) one two (i :: three)\n else\n (one, two, three)\n in loop 1 [] [] []\n\nlet combine (one, two, three) = \n let rec loop one two three list =\n match one, two, three with\n | (coder :: one), (mather :: two), (boxer :: three) -> \n loop one two three ((coder :: mather :: boxer :: []) :: list)\n | _ -> list\n in loop one two three []\n\nlet solve () = \n let teams = combine (divide ()) in\n let total = List.length teams in\n (total, teams)\n\nlet print (n, teams) = \n Printf.printf \"%d\\n\" n;\n let rec loop list =\n match list with\n | ((coder :: mather :: boxer :: []) :: list) -> \n Printf.printf \"%d %d %d\\n\" coder mather boxer;\n loop list\n | _ -> ()\n in loop teams\n \nlet () = print (solve())\n"}], "negative_code": [{"source_code": "let _ = read_line () |> int_of_string and\n ts = read_line () |> Str.split (Str.regexp \" +\") |> List.map int_of_string in \nlet ones = List.mapi (fun i a -> if a = 1 then i + 1 else 0) ts and\n twos = List.mapi (fun i a -> if a = 2 then i + 1 else 0) ts and\n threes = List.mapi (fun i a -> if a = 3 then i + 1 else 0) ts in\nlet rec map3 a b c acc = \n match (a,b,c) with\n | ([], _, _) -> acc \n | (_, [], _) -> acc \n | (_, _, []) -> acc \n | ((0::ax), (b::bx), (c::cx)) -> map3 ax (b::bx) (c::cx) acc\n | ((a::ax), (0::bx), (c::cx)) -> map3 (a::ax) bx (c::cx) acc\n | ((a::ax), (b::bx), (0::cx)) -> map3 (a::ax) (b::bx) cx acc\n | ((a::ax), (b::bx), (c::cx)) -> map3 ax bx cx ([a;b;c]::acc) in\nlet print_list = List.iter (fun l -> Printf.printf \"%d %d %d\\n\" (List.nth l 0) (List.nth l 1) (List.nth l 2))\nin map3 ones twos threes [] |> print_list\n \n\n"}], "src_uid": "c014861f27edf35990cc065399697b10"} {"source_code": "\nlet compute (s: string): bool =\n let l = String.length s in\n let rec f (i: int): bool =\n if i >= (l / 2) then true\n else\n let diff = abs (Char.code (String.get s i) - Char.code (String.get s (l - i - 1))) in\n let ret = diff = 2 || diff = 0 in\n ret && f (i + 1)\n in\n f 0\n\nlet _ =\n let t = Scanf.scanf \" %d\" (fun i -> i) in\n for i = 1 to t do\n let (n, s) = Scanf.scanf \" %d %s\" (fun i j -> (i, j)) in\n (if compute s then \"YES\" else \"NO\") |> print_endline\n done\n", "positive_code": [{"source_code": "let palindromalbe str n =\n let rec check i j =\n if i > j then true\n else \n let ch1 = int_of_char (String.get str i) in \n let ch2 = int_of_char (String.get str j) in\n match abs (ch1 - ch2) with\n | 0 | 2 -> check (i + 1) (j - 1)\n | _ -> false\n in\n check 0 (n - 1)\n\nlet () =\nlet t = read_int () in\nfor _ = 1 to t do \n let n = read_int () in\n let str = read_line () in \n print_endline (if palindromalbe str n then \"YES\" else \"NO\")\ndone"}, {"source_code": "\nlet same a b =\n let a = Char.code a in\n let b = Char.code b in\n let diff = abs (a - b) in\n (diff == 0) || (diff == 2) ;; \n\nlet solve () =\n let n = read_int() in\n let s = read_line() in\n\n let rec check str l r =\n if l > r then\n true\n else if same (String.get str l) (String.get str r) then\n true && (check str (l+1) (r-1))\n else false in\n \n let res = check s 0 (n - 1) in\n if res == true then\n print_string \"YES\"\n else\n print_string \"NO\" ;\n print_newline () ;;\n \nlet t = read_int () in\nfor i = 1 to t do \n solve ()\ndone\n"}], "negative_code": [], "src_uid": "cc4cdcd162a83189c7b31a68412f3fe7"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () =\n let n = read () in\n let rec loop i sum max =\n if i < n\n then\n let balance = read () in\n if balance > max\n then\n loop (i + 1) (sum + balance) balance\n else\n loop (i + 1) (sum + balance) max\n else\n print (n * max - sum)\n in loop 0 0 0", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print result = Printf.printf \"%d\\n\" result\n\nlet input () =\n let n = read () in\n let rec loop list i max =\n if i < n\n then\n let balance = read () in\n if balance > max\n then\n loop (balance :: list) (i + 1) balance\n else\n loop (balance :: list) (i + 1) max\n else\n (list, max)\n in loop [] 0 0\n\nlet solve (list, max) =\n let rec loop sum rest =\n match rest with\n | hd :: tl -> loop (sum + (max - hd)) tl\n | [] -> sum\n in loop 0 list\n\nlet () = print (solve (input ()))"}, {"source_code": "let n = read_int () ;;\nlet a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) ;;\nlet m = Array.fold_left max 0 a ;;\nlet d = Array.map ((-) m) a ;;\nlet s = Array.fold_left (+) 0 d ;;\n\nPrintf.printf \"%d\\n\" s\n"}, {"source_code": "let maximum = List.fold_left max 0 in\nlet _ = read_line () in\nlet ns = read_line () |> (Str.regexp \" +\" |> Str.split) |> List.map int_of_string in\nlet s = maximum ns |> Array.make (List.length ns) |> Array.to_list |> List.map2 (fun a b -> b - a ) ns |> List.fold_left (+) 0 in\nprint_int s\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let lst = \n let rec loop a = function\n | 0 -> a\n | m -> loop ([read_int ()] @ a) (m - 1)\n in loop [] n\n in\n let max =\n let rec loop a = function\n | [] -> a\n | hd :: tl -> if hd > a then loop hd tl else loop a tl\n in loop 0 lst\n in\n let ans = List.fold_left (fun a b -> a + (abs (b - max))) 0 lst in\n Printf.printf \"%d\\n\" ans\n"}, {"source_code": "let rec accumulate_burles n ax m_ax =\n\tmatch n with\n\t|0 -> (ax, m_ax)\n\t|_ -> \n\t\tlet v = ref 0 in \n\t\tbegin \n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %i\" ( fun x -> v := x; );\n\t\t\taccumulate_burles (n-1) (ax + !v) (max m_ax !v)\n\t\tend\n\nlet read_and_solve total_count =\n\tlet (sum, max_val) = (accumulate_burles total_count 0 0) in\n\tlet diff = max_val * total_count - sum in\n\tPrintf.printf \"%i\\n\" diff\n;;\n\t\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %i \" read_and_solve\n;;\n\nread_input ()\n"}, {"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 res = ref 0 in\n let m = ref a.(0) in\n for i = 0 to n - 1 do\n m := max !m a.(i);\n done;\n for i = 0 to n - 1 do\n res := !res + !m - a.(i)\n done;\n Printf.printf \"%d\\n\" !res\n"}], "negative_code": [{"source_code": "let maximum = List.fold_left max 0 in\nlet _ = read_line () in\nlet ns = read_line () |> (Str.regexp \" *\" |> Str.split) |> List.map int_of_string in\nlet s = maximum ns |> Array.make (List.length ns) |> Array.to_list |> List.map2 (fun a b -> b - a ) ns |> List.fold_left (+) 0 in\nprint_int s\n"}], "src_uid": "a5d3c9ea1c9affb0359d81dae4ecd7c8"} {"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.logxor a b\n \nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_long _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x) \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) 0L\nlet xsum i j f = fold i j (fun i a -> (f i) ^ a) 0L\n \nlet () =\n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let ar = Array.init n read_long in\n let x = xsum 0 (n-1) (fun i -> ar.(i)) in\n let s = sum 0 (n-1) (fun i -> ar.(i)) in\n let xs = x ++ s in\n printf \"2\\n\";\n printf \"%Ld %Ld\\n\" x xs\n done", "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.logxor a b\n \nlet read_int _ = bscanf Scanning.stdin \" %d \" (fun x -> x)\nlet read_long _ = bscanf Scanning.stdin \" %Ld \" (fun x -> x) \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) 0L\nlet xsum i j f = fold i j (fun i a -> (f i) ^ a) 0L\n \nlet () =\n let cases = read_int() in\n for case = 1 to cases do\n let n = read_int() in\n let ar = Array.init n read_long in\n let b = xsum 0 (n-1) (fun i -> ar.(i)) in\n let a = sum 0 (n-1) (fun i -> ar.(i)) in\n let x = b in\n let a' = x ++ a in\n let y = a' in\n printf \"2\\n\";\n printf \"%Ld %Ld\\n\" x y\n done\n"}], "negative_code": [], "src_uid": "cced3c3d3f1a63e81e36c94fc2ce9379"} {"source_code": "let n=ref 0;;\nlet m=ref 0;;\nlet pos s=\nlet i=ref 0 in\nwhile s.[ !i]<>':' do\n incr i\ndone;\nincr i;\n!i;;\nlet b=ref true;;\nfor j=1 to 100 do\n if !b then \n begin\n let s = try read_line() with _ -> \"\" in\n if s=\"\" then b:=false\n else if s.[0]='+' then incr n\n else if s.[0]='-' then decr n\n else let i=pos s in m:= !m+String.length(String.sub s i (String.length( s)-i))* !n;\n end\ndone;;\nprint_int !m;;", "positive_code": [{"source_code": "module StrSet = Set.Make(String)\n\nlet rec f h ans =\n try\n let a = read_line () in\n let l = String.length a in\n if a.[0] = '+' then\n f (StrSet.add (String.sub a 1 (l-1)) h) ans\n else if a.[0] = '-' then\n f (StrSet.remove (String.sub a 1 (l-1)) h) ans\n else\n f h (ans+(StrSet.cardinal h*(l-1-String.index a ':')))\n with End_of_file ->\n ans\n\nlet () =\n Printf.printf \"%d\\n\" (f StrSet.empty 0)\n"}], "negative_code": [], "src_uid": "d7fe15a027750c004e4f50175e1e20d2"} {"source_code": "open Printf open Scanf\nmodule MyInt64 = struct \n\t(* include Int64 *)\n\t(* int *)\n\tlet (+$) = (+)\n\tlet (-$) = (-)\n\tlet (/$) = (/)\n\tlet ( *$) = ( * )\n\t(* int64 *)\n\tlet (+) p q = Int64.add p q\n\tlet (-) p q = Int64.sub p q\n\tlet ( * ) p q = Int64.mul p q\n\tlet (/) p q = Int64.div p q\n\n\tlet labs p = if p < 0L then -1L*p else p\n\t(* let (~|) p = Int64.of_int p *)\n\tlet (~|) p = Int64.to_int p\n\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *=) r v= r := !r * v\n\tlet (/=) r v = r := !r / v\n\n\tlet input_i64_array n = \n\t\tArray.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 () = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 () = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 () = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet print_i64_endline n =\n\t\tn |> Int64.to_string |> print_endline\n\tlet ($) = (~|)\nend open MyInt64\n\nlet () =\n let n = get_i64 ()\n\tin let ar = input_i64_array n\n\tin let mx = 100020\n\tin let undef = -1\n\tin let n_occur = Array.make mx undef\n\tin let n_occur_rev = Array.make mx undef\n\tin let k_occur = Array.make ~|n 0L\n\tin \n\tlet ns = ref [] in\n\tArray.iteri (fun i v ->\n\t\tlet v = ~|v in\n\t\tif n_occur.(v) = undef then (\n\t\t\tn_occur.(v) <- i;\n\t\t\tns := v::!ns\n\t\t);\n\t) ar;\n\tlet ns = List.map (fun v -> \n\t\tn_occur.(v)\n\t) !ns in\n\tlet k0 = ref 0L in \n\tArray.iteri (fun i v ->\n\t\tlet v = ~|v in let i = ~|n-$1-$i in\n\t\tif n_occur_rev.(v) = undef then (\n\t\t\tn_occur_rev.(v) <- i;\n\t\t\tk0 += 1L;\n\t\t);\n\t\tif (i-$1 >= 0) then k_occur.(i-$1) <- !k0;\n\t) (ar |> Array.to_list |> List.rev |> Array.of_list);\n\t(* Array.iteri (fun i v ->\n\t\tprintf \"%d: %Ld\\n\" i k_occur.(i);\n\t) ar; *)\n\tlet ans = ref 0L in\n\tList.iter (fun v -> \n\t\t(* printf \"ans += k_occur.(%d) = %Ld\\n\" v k_occur.(v); *)\n\t\tans += k_occur.(v);\n\t) ns;\n\t!ans |> print_i64_endline", "positive_code": [{"source_code": "open Int64\n\nlet 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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in\nlet count = ref zero in\nlet rseen = Array.make 500000 zero in\nfor i = n - 1 downto 0 do\n if rseen.(number.(i)) = zero then count := succ !count;\n rseen.(number.(i)) <- succ rseen.(number.(i));\ndone;\nlet result = ref zero in\nlet seen = Array.make 500000 false in\nfor i = 0 to n - 2 do\n rseen.(number.(i)) <- pred rseen.(number.(i));\n if rseen.(number.(i)) = zero then count := pred !count;\n if not seen.(number.(i)) then result := add !result !count;\n seen.(number.(i)) <- true;\ndone;\nprint_endline @@ to_string !result;\n"}, {"source_code": "open Int64\n\nlet 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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in\nlet count = ref 0L in\nlet rseen = Array.make 500000 0L in\nfor i = n - 1 downto 0 do\n if rseen.(number.(i)) = 0L then count := succ !count;\n rseen.(number.(i)) <- succ rseen.(number.(i));\ndone;\nlet result = ref 0L in\nlet seen = Array.make 500000 false in\nfor i = 0 to n - 2 do\n rseen.(number.(i)) <- pred rseen.(number.(i));\n if rseen.(number.(i)) = 0L then count := pred !count;\n if not seen.(number.(i)) then result := add !result !count;\n seen.(number.(i)) <- true;\ndone;\nprint_endline @@ to_string !result;\n"}], "negative_code": [{"source_code": "open Int32\n\nlet 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\nlet n = Scanf.sscanf (read_line ()) \"%i\" (fun n -> n) in\nlet number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in\nlet count = ref zero in\nlet rseen = Array.make 500000 zero in\nfor i = n - 1 downto 0 do\n if rseen.(number.(i)) = zero then count := succ !count;\n rseen.(number.(i)) <- succ rseen.(number.(i));\ndone;\nlet result = ref zero in\nlet seen = Array.make 500000 false in\nfor i = 0 to n - 2 do\n rseen.(number.(i)) <- pred rseen.(number.(i));\n if rseen.(number.(i)) = zero then count := pred !count;\n if not seen.(number.(i)) then result := add !result !count;\n seen.(number.(i)) <- true;\ndone;\nprint_endline @@ to_string !result;\n"}, {"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) in\nlet number = read_line () |> split_on_char ' ' |> List.map int_of_string |> Array.of_list in\nlet count = ref 0 in\nlet rseen = Array.make 500000 0 in\nfor i = n - 1 downto 0 do\n if rseen.(number.(i)) = 0 then incr count;\n rseen.(number.(i)) <- rseen.(number.(i)) + 1;\ndone;\nlet result = ref 0 in\nlet seen = Array.make 500000 false in\nfor i = 0 to n - 2 do\n rseen.(number.(i)) <- rseen.(number.(i)) - 1;\n if rseen.(number.(i)) = 0 then decr count;\n if not seen.(number.(i)) then result := !result + !count;\n seen.(number.(i)) <- true;\ndone;\nprint_int !result;\nprint_newline ();\n"}], "src_uid": "4671380d70876044e0ec7a9cab5e25ae"} {"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, m)) in\nfor i = 1 to m do\n ignore (read_line ());\ndone;\nfor i = 1 to n do\n print_int (i mod 2);\ndone;\nprint_newline ();\n", "positive_code": [{"source_code": "open Printf open Scanf\nmodule MyInt64 = struct \n\t(* include Int64 *)\n\t(* int *)\n\tlet (+$) = (+)\n\tlet (-$) = (-)\n\tlet (/$) = (/)\n\tlet ( *$) = ( * )\n\t(* int64 *)\n\tlet (+) p q = Int64.add p q\n\tlet (-) p q = Int64.sub p q\n\tlet ( * ) p q = Int64.mul p q\n\tlet (/) p q = Int64.div p q\n\n\tlet labs p = if p < 0L then -1L*p else p\n\t(* let (~|) p = Int64.of_int p *)\n\tlet (~|) p = Int64.to_int p\n\n\tlet (+=) r v = r := !r + v\n\tlet (-=) r v = r := !r - v\n\tlet ( *=) r v= r := !r * v\n\tlet (/=) r v = r := !r / v\n\n\tlet input_i64_array n = \n\t\tArray.init (~| n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v))\n\tlet get_i64 () = Scanf.scanf \" %Ld\" (fun v -> v)\n\tlet get_2_i64 () = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v)\n\tlet get_3_i64 () = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w)\n\tlet get_4_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x)\n\tlet get_5_i64 () = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y)\n\tlet print_i64_endline n =\n\t\tn |> Int64.to_string |> print_endline\nend open MyInt64\n\nlet () =\n let n,m = get_2_i64 ()\n in let ar = Array.make (~|m) (0L,0L)\n in\n for i=0 to ~|m-$1 do\n let u,v = get_2_i64 ()\n in ar.(i) <- u,v\n done;\n let res = Array.make ~|n 0 in\n Array.iteri (fun i _ -> print_int @@ if i mod 2 = 0 then 1 else 0) res;\n print_newline ()\n\n\n"}], "negative_code": [], "src_uid": "cac8ca5565e06021a44bb4388b5913a5"} {"source_code": "open Printf open Scanf\nmodule Lib = struct\n let i32,i64,ist = Int64.(to_int,of_int,to_string)\n let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)\n let labs = Int64.abs\n let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)\n let (+=) r v = r := !r + v\n let (-=) r v = r := !r - v\n let ( *= ) r v = r := !r * v\n let (/=) r v = r := !r / v\n let (%=) r v = r := !r % v\n let max_i64_lim,min_i64_lim = Int64.(max_int,min_int)\n let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L\n (* math *)\n let ceildiv p q = (p+q-1L) / q\n let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)\n let lcm m n = m / gcd m n * n\n module Int64_infix = struct\n let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =\n let open Int64 in\n (logand),(logor),(logxor),lognot,\n (fun u v -> shift_left u (i32 v)),\n (fun u v -> shift_right u (i32 v)),\n (fun u v -> shift_right_logical u (i32 v))\n end\n let pow n k =\n let rec f a n = function\n | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)\n in f 1L n k\n (* input *)\n let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf \" %Ld\" (fun v -> v)) let iia = input_i64_array\n let get_i64 _ = Scanf.scanf \" %Ld\" (fun v -> v) let gi = get_i64\n let get_2_i64 _ = Scanf.scanf \" %Ld %Ld\" (fun u v -> u,v) let g2 = get_2_i64\n let get_3_i64 _ = Scanf.scanf \" %Ld %Ld %Ld\" (fun u v w -> u,v,w) let g3 = get_3_i64\n let get_4_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld\" (fun u v w x -> u,v,w,x) let g4 = get_4_i64\n let get_5_i64 _ = Scanf.scanf \" %Ld %Ld %Ld %Ld %Ld\" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64\n let i32_get_int _ = Scanf.scanf \" %d\" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf \" %d %d\" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf \" %d %d %d\" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf \" %d %d %d %d\" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf \" %d %d %d %d %d\" (fun u v w x y -> u,v,w,x,y)\n (* utils *)\n external id : 'a -> 'a = \"%identity\"\n let ( *< ) f g x = f (g x)\n let ( *> ) f g x = g (f x)\n let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)\n let alen a = i64 @@ Array.length a\n let llen l = i64 @@ List.length l\n let slen s = String.length s\n let string_of_list ?(separator=\" \") f ls = ls |> List.map f |> String.concat separator\n let string_of_array ?(separator=\" \") f a = a |> Array.to_list |> string_of_list ~separator f\n let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []\n let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) \"\" ls\n let fail _ = failwith \"fail\"\n let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]\n let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev\n let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten\n let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a\n let binary_search ng ok f = let d = if ng < ok then 1L else -1L in\n let rec f0 ng ok =\n if labs (ok - ng) <= 1L then ok\n else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok\n in f0 (ng-1L*d) (ok+1L*d)\n let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)\n let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) > v)\n let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)\n let rec fix f x = f (fix f) x\n let fix_memo ?(size=10000) f x =\n let tb = Hashtbl.create ~random:true size in\n let rec f0 x =\n try Hashtbl.find tb x with\n | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)\n in f0 x\n (* imperative *)\n let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done\n let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done\n let repm f t ?(stride=1L) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m\n let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done\n let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do\n match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done\n let repim f t ?(stride=1) m0 fbod =\n let i,c,m = ref f,ref true,ref m0 in\n while !i<=t && !c do match fbod !m !i with\n | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m\n let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v\n let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v\n let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v\n let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v\n let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v\n (* output *)\n let print_list_mle f ls = string_of_list f ls |> print_endline\n let print_array_mle f a = string_of_array f a |> print_endline\n let print_list f ls = ls |> List.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n let print_array f a = a |> Array.iter (fun v -> printf \"%s \" @@ f v); print_newline ()\n (* debug *)\n let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)\n let dump_i64_list ls = print_list ist ls\n let dump_i64_array a = print_array ist a\nend open Lib open Array\n\nlet () =\n let n = gi 0 in\n rep 1L n (fun _ ->\n let k,x = g2 0 in\n printf \"%Ld\\n\" @@ x + 9L * (k - 1L)\n )\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "let (++),( ** ),(--) = Int64.(add,mul,sub);;\nScanf.(Array.(scanf \" %d\" @@ fun q ->\n init q (fun _ -> scanf \" %Ld %Ld\" @@ fun k x ->\n Printf.printf \"%Ld\\n\" @@ x ++ 9L ** (k--1L))))"}], "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 n = gi 0 in\n rep 1L n (fun _ ->\n let k,x = g2 0 in\n printf \"%Ld\" @@ x + 9L * (k - 1L)\n )\n\n\n\n\n\n\n\n\n"}], "src_uid": "891fabbb6ee8a4969b6f413120f672a8"} {"source_code": "\n\nlet read_pair = fun a b -> (a, b) in\n\nlet (n, m) = Scanf.scanf \"%d %d\\n\" read_pair and ans = ref 99999999 in\nfor i = 1 to m do\n let (tmp1, tmp2) = Scanf.scanf \"%d %d\\n\" read_pair in\n ans := min (!ans) (tmp2 - tmp1 + 1)\ndone;\nprint_int !ans;\nprint_newline ();\nfor i = 0 to n - 1 do\n print_int (i mod !ans);\n print_string \" \"\ndone;;\n\n\n \n\n", "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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n \nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet () = \n let (n,m) = read_pair () in\n\n let len = minf 0 (m-1) (fun _ ->\n let (l,r) = read_pair() in\n r-l+1\n ) in\n\n printf \"%d\\n\" len;\n\n for i=0 to n-1 do\n printf \"%d \" (i mod len)\n done;\n\n print_newline()\n"}, {"source_code": "let () =\n Scanf.scanf \"%d %d \" @@ fun n m ->\n let mex = ref n in\n for i = 1 to m do\n Scanf.scanf \"%d %d \" @@ fun l r ->\n mex := min !mex (r - l + 1)\n done;\n Printf.printf \"%d\\n\" !mex;\n for i = 0 to n - 2 do\n Printf.printf \"%d \" (i mod !mex)\n done;\n Printf.printf \"%d\\n\" ((n - 1) mod !mex)\n"}], "negative_code": [], "src_uid": "317891277a5393758bd3c8f606769070"} {"source_code": "let read_int () = Scanf.scanf \"%d \" (fun n -> n)\nlet read_char () = Scanf.scanf \"%c \" (fun c -> c)\n\nlet solve () = \n let n = read_int () in\n let rec loop i zeros ones = \n if i < n\n then\n let number = read_char () in\n if number = '0'\n then\n loop (i + 1) (zeros + 1) ones\n else\n loop (i + 1) zeros (ones + 1) \n else\n Pervasives.abs (zeros - ones)\n in loop 0 0 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve ())", "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 () = \n let n = Pervasives.read_int () in\n let list = str_to_list (Pervasives.read_line ()) in\n (list, n)\n\nlet solve (list, n) = \n let zeros = List.length (List.filter (fun c -> c = '0') list) in\n let ones = n - zeros in\n let result = Pervasives.abs (zeros - ones) in\n result\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let rec count s c i =\n if i = String.length s\n then 0\n else (if s.[i]=c then 1 else 0) + count s c (i+1)\n\nin let n = read_int()\nin let s = read_line()\nin let reml = n - 2 * min (count s '0' 0) (count s '1' 0)\nin print_int(reml)\n"}], "negative_code": [], "src_uid": "fa7a44fd24fa0a8910cb7cc0aa4f2155"} {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make (n+1) 0\n\nfor i = 1 to n do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n a.(i)<-j\ndone\n\nlet rslt = Array.fold_left (fun x y -> if x > y then x else y ) (-1000) a\nin printf \"%d\\n\" rslt\n\n", "positive_code": [{"source_code": "let pf = Printf.printf ;;\nlet epf = Printf.eprintf ;;\nlet sf = Scanf.scanf ;;\n\nlet (|>) x f = f x ;;\nlet (@@) f x = f x ;;\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 sf \"%d \" (fun n ->\n let arr = Array.init n ~f:(fun i -> sf \"%d \" (fun i -> i)) in\n pf \"%d\\n\" @@ Array.fold_left ~init:0 arr ~f:max)\n;;\n"}], "negative_code": [{"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet a = Array.make (n+1) 0\n\nfor i = 1 to n do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n a.(i)<-j\ndone\n\nlet cnt = ref 0\n\nfor i = 1 to n do\n let m = a.(i) - a.(i-1) in\n cnt := m + !cnt\ndone\n\nlet () = printf \"%d\\n\" !cnt\n\n"}], "src_uid": "d03ad531630cbecc43f8da53b02d842e"} {"source_code": "let fraction n d =\n let str = (string_of_int n) ^ \"/\" ^ (string_of_int d) in\n Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))\n\nlet solve p q =\n if List.length p > List.length q\n then if (List.hd p) * (List.hd q) >= 0 then \"Infinity\"\n else \"-Infinity\"\n else if List.length p < List.length q then \"0/1\"\n else fraction (List.hd p) (List.hd q)\n\nlet id x = x\n \nlet rec input_polynomial dim =\n if dim < 0 then []\n else (Scanf.scanf \" %d\" id) :: input_polynomial (dim - 1)\n \nlet _ =\n let n = Scanf.scanf \" %d\" id in\n let m = Scanf.scanf \" %d\" id in\n let p = List.rev (input_polynomial n) in\n let q = List.rev (input_polynomial m) in\n Printf.printf \"%s\\n\" (solve p q)\n", "positive_code": [{"source_code": "let sb = Scanf.Scanning.stdib;;\n\nlet fraction n d =\n let str = (string_of_int n) ^ \"/\" ^ (string_of_int d) in\n Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))\n\nlet solve p q =\n if List.length p > List.length q\n then if (List.hd p) * (List.hd q) >= 0 then \"Infinity\"\n else \"-Infinity\"\n else if List.length p < List.length q then \"0/1\"\n else fraction (List.hd p) (List.hd q)\n\nlet id x = x\n \nlet rec input_polynomial dim =\n if dim < 0 then []\n else (Scanf.bscanf sb \" %d\" id) :: input_polynomial (dim - 1)\n \nlet _ =\n let n = Scanf.bscanf sb \" %d\" id in\n let m = Scanf.bscanf sb \" %d\" id in\n let p = List.rev (input_polynomial n) in\n let q = List.rev (input_polynomial m) in\n Printf.printf \"%s\\n\" (solve p q)\n"}, {"source_code": "let rec gcd a b =\n if b == 0 then a else gcd b (a mod b)\n;;\n\nlet next_int: unit -> int = fun _ ->\n Scanf.scanf \" %d\" (fun x -> x)\n;;\n\nlet next_polynomial n =\n let ret = next_int () in\n for i = 1 to n do\n next_int ()\n done;\n ret\n;;\n\nlet rec print_gcd a b =\n let g = gcd (abs a) (abs b) in\n if b < 0\n then print_gcd (-a) (-b)\n else Printf.printf \"%d/%d\" (a / g) (b / g)\n;;\n\nlet _ =\n let n = next_int () in\n let m = next_int () in\n let a = next_polynomial n in\n let b = next_polynomial m in\n if n < m then print_string \"0/1\"\n else if n = m then print_gcd a b\n else print_string ((if a * b > 0 then \"\" else \"-\") ^ \"Infinity\")\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\nlet rec gcd x y =\n if y = 0 then x\n else gcd y (x mod y)\n\n(* entry point *)\nlet n = int ()\nlet m = int ()\n\nlet a = n_int (n+1) ()\nlet b = n_int (m+1) ()\n\nlet () =\n if n > m then\n Printf.printf \"%s\\n\" (if (L.hd a) * (L.hd b) > 0 then \"Infinity\" else \"-Infinity\")\n else if n < m then\n Printf.printf \"%s\\n\" \"0/1\" \n else \n let a = (L.hd a) in\n let b = (L.hd b) in\n let g = gcd a b in\n let a = a / g in\n let b = b / g in\n if a > 0 && b < 0 then\n Printf.printf \"%d/%d\" (-a) (-b)\n else\n Printf.printf \"%d/%d\" a b\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "let rec gcd x y =\n if y == 0 then x else gcd y (x mod y)\n \nlet solve n m p q =\n let a = List.hd p in\n let b = List.hd q in\n if n > m then if a * b >= 0 then \"Infinity\" else \"-Infinity\"\n else if n < m then \"0/1\"\n else\n let gcd = gcd a b in\n let a = a / gcd in\n let b = b / gcd in\n if a > 0 && b < 0\n then (string_of_int (- a)) ^ \"/\" ^ (string_of_int (- b))\n else (string_of_int a) ^ \"/\" ^ (string_of_int b)\n \n\nlet id x = x\n \nlet rec input_polynomial dim =\n if dim < 0 then []\n else (Scanf.scanf \" %d\" id) :: input_polynomial (dim - 1)\n \nlet _ =\n let n = Scanf.scanf \" %d\" id in\n let m = Scanf.scanf \" %d\" id in\n let p = List.rev (input_polynomial n) in\n let q = List.rev (input_polynomial m) in\n Printf.printf \"%s\\n\" (solve n m p q)\n"}], "negative_code": [{"source_code": "let rec gcd x y =\n if y == 0 then x else gcd y (x mod y)\n \nlet solve n m p q =\n let a = List.hd p in\n let b = List.hd q in\n if n > m then if a * b >= 0 then \"Infinity\" else \"-Infinity\"\n else if n < m then \"0/1\"\n else\n let gcd = gcd a b in\n let a = a / gcd in\n let b = b / gcd in\n (string_of_int a) ^ \"/\" ^ (string_of_int b)\n\nlet id x = x\n \nlet rec input_polynomial dim =\n if dim < 0 then []\n else (Scanf.scanf \" %d\" id) :: input_polynomial (dim - 1)\n \nlet _ =\n let n = Scanf.scanf \" %d\" id in\n let m = Scanf.scanf \" %d\" id in\n let p = List.rev (input_polynomial n) in\n let q = List.rev (input_polynomial m) in\n Printf.printf \"%s\\n\" (solve n m p q)\n"}, {"source_code": "let sb = Scanf.Scanning.stdib;;\n\nlet fraction n d =\n let str = (string_of_int n) ^ \"/\" ^ (string_of_int d) in\n Ratio.string_of_ratio (Num.ratio_of_num (Num.num_of_string str))\n\nlet solve p q =\n if List.length p > List.length q\n then if (List.hd p) > 0 then \"Infinity\"\n else \"-Infinity\"\n else if List.length p < List.length q then \"0/1\"\n else fraction (List.hd p) (List.hd q)\n\nlet id x = x\n \nlet rec input_polynomial dim =\n if dim < 0 then []\n else (Scanf.bscanf sb \" %d\" id) :: input_polynomial (dim - 1)\n \nlet _ =\n let n = Scanf.bscanf sb \" %d\" id in\n let m = Scanf.bscanf sb \" %d\" id in\n let p = List.rev (input_polynomial n) in\n let q = List.rev (input_polynomial m) in\n Printf.printf \"%s\\n\" (solve p q)\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\nlet rec gcd x y =\n if y = 0 then x\n else gcd y (x mod y)\n\n(* entry point *)\nlet n = int ()\nlet m = int ()\n\nlet a = n_int (n+1) ()\nlet b = n_int (m+1) ()\n\nlet () =\n if n > m then\n Printf.printf \"%s\\n\" (if (L.hd a > 0) then \"Infinity\" else \"-Infinity\")\n else if n < m then\n Printf.printf \"%s\\n\" \"0/1\" \n else \n let a = (L.hd a) in\n let b = (L.hd b) in\n let g = gcd a b in\n let a = a / g in\n let b = b / g in\n if a > 0 && b < 0 then\n Printf.printf \"%d/%d\" (-a) (-b)\n else\n Printf.printf \"%d/%d\" a b\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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\nlet rec gcd x y =\n if y = 0 then x\n else gcd y (x mod y)\n\n(* entry point *)\nlet n = int ()\nlet m = int ()\n\nlet a = n_int (n+1) ()\nlet b = n_int (m+1) ()\n\nlet () =\n if n > m then\n Printf.printf \"%s\\n\" (if (L.hd a > 0) then \"Infinity\" else \"-Infinity\")\n else if n < m then\n Printf.printf \"%s\\n\" \"0/1\" \n else \n let a = (L.hd a) in\n let b = (L.hd b) in\n let g = gcd a b in\n Printf.printf \"%d/%d\" (a / g) (b / g)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "37cf6edce77238db53d9658bc92b2cab"} {"source_code": "open Printf\nopen Scanf\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\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 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)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x) \nlet () = \n let n = read_int () in\n let k = read_long () in\n let a = Array.init n (fun _ -> read_long()) in\n let b = Array.init n (fun _ -> read_long()) in\n\n let can_bake m =\n let mp = sum 0 (n-1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in\n mp <= k\n in\n\n let rec bsearch lo hi =\n (* lo can be made, hi cannot *)\n if lo++1L = hi then lo else\n let m = (lo ++ hi) // 2L in\n if can_bake m then bsearch m hi else bsearch lo m\n in\n\n let rec findhi hi = if can_bake hi then findhi (2L ** hi) else hi in\n\n printf \"%Ld\\n\" (bsearch 0L (findhi 1L))\n \n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x);;\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x);;\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\nlet ( ^^ ) a b = Int64.shift_left a b\nlet rec sum (i : int) (j : int) f (ac : int64) =\n if i > j then\n ac\n else\n sum (i + 1) j f (ac ++ (f i));;\n\nlet () =\n try\n while true do\n let n = read_int () in\n let k = read_long () in\n let a = Array.init n (fun _ -> read_long()) in\n let b = Array.init n (fun _ -> read_long()) in\n\n let possible m =\n let x = sum 0 (n - 1) (fun i -> min 4000000000L (max 0L ((m ** a.(i)) -- b.(i)))) 0L in\n x <= k\n in\n\n let rec binary_search small large =\n if (small ++ 1L) < large then\n let (mid : int64) = (small ++ large) // 2L in\n if possible mid then binary_search mid large else binary_search small mid\n else\n small\n in\n \n printf \"%Ld\\n\" (binary_search 0L 2000000001L)\n done\n with End_of_file -> ()\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x);;\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x);;\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\nlet ( ^^ ) a b = Int64.shift_left a b\nlet rec sum (i : int) (j : int) f (ac : int64) =\n if i > j then\n ac\n else\n sum (i + 1) j f (ac ++ (f i));;\n\nlet () =\n try\n while true do\n let n = read_int () in\n let k = read_long () in\n let a = Array.init n (fun _ -> read_long()) in\n let b = Array.init n (fun _ -> read_long()) in\n\n let possible m =\n let x = sum 0 (n - 1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in\n x <= k\n in\n\n let rec binary_search small large =\n if (small ++ 1L) < large then\n let mid = (small ++ large) // 2L in\n if possible mid then binary_search mid large else binary_search small mid\n else\n small\n in\n\n printf \"%Ld\\n\" (binary_search 0L 1000000001L)\n done\n with End_of_file -> ()\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x);;\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x);;\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\nlet ( ^^ ) a b = Int64.shift_left a b\nlet rec sum (i : int) (j : int) f (ac : int64) =\n if i > j then\n ac\n else\n sum (i + 1) j f (ac ++ (f i));;\n\nlet () =\n try\n while true do\n let n = read_int () in\n let k = read_long () in\n let a = Array.init n (fun _ -> read_long()) in\n let b = Array.init n (fun _ -> read_long()) in\n\n let possible m =\n let x = sum 0 (n - 1) (fun i -> max 0L (m ** a.(i) -- b.(i))) 0L in\n x <= k\n in\n\n let rec binary_search small large =\n if (small ++ 1L) < large then\n let mid = (small ++ large) // 2L in\n if possible mid then binary_search mid large else binary_search small mid\n else\n small\n in\n \n printf \"%Ld\\n\" (binary_search 0L 2000000001L)\n done\n with End_of_file -> ()\n"}], "src_uid": "ab1b4487899609ac0f882e1b1713d162"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print int = Printf.printf \"%d\\n\" int\n\nlet binary_search arr n value =\n let result =\n (let rec search low high =\n if high = low || high - low = 1\n then\n low\n else\n let mid = (low + high) / 2 in\n if arr.(mid - 1) > value \n then\n search low mid\n else\n search mid high\n in search 0 (n + 1))\n in \n print result\n\nlet input () =\n let n = read () in\n let price = Array.init n (fun n -> read ()) in\n let m = read () in\n let cash = Array.init m (fun n -> read ()) in\n (n, price, cash)\n\nlet solve (n, price, cash) =\n (Array.fast_sort Pervasives.compare price;\n Array.iter (binary_search price n) cash)\n\nlet () = solve (input ())", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print int = Printf.printf \"%d\\n\" int\n\nlet make_array n = \n let arr = Array.make n 0 in\n let rec loop i =\n if i < n\n then\n (let int = read () in\n Array.set arr i int;\n loop (i + 1))\n else\n arr\n in loop 0\n\nlet binary_search arr n value =\n let result =\n (let rec search low high =\n if high = low || high - low = 1\n then\n low\n else\n let mid = (low + high) / 2 in\n if arr.(mid - 1) > value \n then\n search low mid\n else\n search mid high\n in search 0 (n + 1))\n in \n print result\n\nlet input () =\n let n = read () in\n let price = make_array n in\n let m = read () in\n let cash = make_array m in\n (n, price, cash)\n\nlet solve (n, price, cash) =\n (Array.fast_sort Pervasives.compare price;\n Array.iter (binary_search price n) cash)\n\nlet () = 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 x = Array.init n (fun _ -> read_int()) in \n let q = read_int () in\n let m = Array.init q (fun _ -> read_int()) in\n\n Array.sort compare x;\n\n let find_index m =\n (* return the index of the biggest shop whose cost is <= m *)\n (* -1 if there is no such one *)\n let rec bsearch lo hi =\n (* x.(lo) <= m x.(hi) > m *)\n if lo + 1 = hi then lo else\n\tlet mid = (lo+hi)/2 in\n\tif x.(mid) <= m then bsearch mid hi else bsearch lo mid\n in\n if x.(n-1) <= m then n-1\n else if x.(0) > m then -1\n else bsearch 0 (n-1)\n in\n\n for j=0 to q-1 do\n let i = find_index m.(j) in\n printf \"%d\\n\" (i+1)\n done\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\nlet print int = Printf.printf \"%d\\n\" int\n\nlet make_array n = \n let arr = Array.make n 0 in\n let rec loop i =\n if i < n\n then\n (let int = read () in\n Array.set arr i int;\n loop (i + 1))\n else\n arr\n in loop 0\n\nlet binary_search arr n value =\n let result = \n (let rec search low high contender =\n assert (high >= low);\n if high = low\n then\n if arr.(low) <= value \n then\n low\n else\n contender\n else \n let mid = (low + high) / 2 in\n if arr.(mid) > value \n then\n if mid = low\n then\n contender\n else\n search low (mid - 1) contender\n else\n search (mid + 1) high mid\n\n in search 0 (n - 1) (-1))\n in\n print (result + 1)\n\nlet input () =\n let n = read () in\n let price = make_array n in\n let m = read () in\n let cash = make_array m in\n (n, price, cash)\n\nlet solve (n, price, cash) =\n (Array.fast_sort Pervasives.compare price;\n Array.iter (binary_search price n) cash)\n\nlet () = solve (input ())"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet count_smaller ele shop_arr n =\n let print n = Printf.printf \"%d\\n\" n in\n if ele < shop_arr.(0) then print 0\n else if ele >= shop_arr.(n-1) then print n\n else\n let rec bsearch low high =\n if low + 1 = high then print high\n else\n let mid = (low + high) / 2 in\n if ele < shop_arr.(mid) then bsearch low mid\n else if ele >= shop_arr.(mid) then bsearch mid high\n in bsearch 0 (n - 1)\n\n\nlet () =\n let n = read_int () in\n let shop_arr = Array.init n (fun _ ->\n read_int ();\n )\n in\n let q = read_int () in\n let coin_arr = Array.init q (fun _ ->\n read_int ();\n )\n in\n Array.sort compare shop_arr;\n Array.iter (fun x -> count_smaller x shop_arr n) coin_arr\n"}], "negative_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x)\n\nlet count_smaller ele shop_arr n =\n let print n = Printf.printf \"%d\\n\" n in\n if ele < shop_arr.(0) then print 0\n else if ele >= shop_arr.(n-1) then print n\n else\n let rec bsearch low high =\n if low + 1 = high then print high\n else\n let mid = (low + high) / 2 in\n if ele < shop_arr.(mid) then bsearch low mid\n else if ele > shop_arr.(mid) then bsearch mid high\n else print (mid + 1)\n in bsearch 0 (n - 1)\n\n\nlet () =\n let n = read_int () in\n let shop_arr = Array.init n (fun _ ->\n read_int ();\n )\n in\n let q = read_int () in\n let coin_arr = Array.init q (fun _ ->\n read_int ();\n )\n in\n Array.sort compare shop_arr;\n Array.iter (fun x -> count_smaller x shop_arr n) coin_arr\n"}], "src_uid": "80a03e6d513f4051175cd5cd1dea33b4"} {"source_code": "let scan_int () = Scanf.scanf \" %d\" (fun x -> x) ;;\n \nopen Printf\n\nlet init (x : int) (f : int -> 'a) : 'a list =\n let rec build k =\n if k = x then []\n else (f k) :: build (k + 1) in\n build 0\n;;\n \nlet run () = \n let open Int64 in\n let n = scan_int () |> of_int in\n let k = scan_int () |> of_int in\n let check x =\n sub x (div x n) >= k in\n let rec f lo hi ans =\n if lo > hi then ans\n else begin\n let md = div (add lo hi) 2L in\n ifprintf stdout \"%Ld %Ld %Ld %B\\n\" lo hi md (check md);\n if check md then f lo (sub md 1L) md\n else f (add md 1L) hi ans\n end in\n printf \"%Ld\\n\" (f 1L 3000000000L max_int)\n;;\n \nlet () =\n let t = scan_int () in\n for i = 1 to t do\n run ()\n done\n;;\n", "positive_code": [{"source_code": "(* Codeforces 1352 C K-th Not Divisible by n comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec kth_not_div n k = \n\tlet n1 = Int64.pred n in\n\tlet o = Int64.rem k n1 in\n\tlet d = Int64.div k n1 in\n\tlet oo = if (Int64.compare o Int64.zero) == 0 then Int64.minus_one else o in\n\tlet ret = Int64.add (Int64.mul n d) oo in\n\tret;;\t\n \nlet do_one () = \n let n = grl () in\n let k = grl () in\n\t\tlet kth = kth_not_div n k in \n \tPrintf.printf \"%Ld\\n\" kth;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "negative_code": [{"source_code": "(* Codeforces 1352 C K-th Not Divisible by n comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec kth_not_div n k = \n\tlet o = k mod (n - 1) in\n\tlet d = k / (n - 1) in\n\tlet ret = (n * d) + (if o==0 then (-1) else o) in\n\t(* let _ = Printf.printf \"n,k,o,d,ret = %d %d %d %d %d\\n\" n k o d ret in *)\n\tret;;\t\n \nlet do_one () = \n let n = gr () in\n let k = gr () in\n\t\tlet kth = kth_not_div n k in \n \tPrintf.printf \"%d\\n\" kth;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}, {"source_code": "(* Codeforces 1352 C K-th Not Divisible by n comp *)\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 \n(* reading reversed list *)\nlet rec readlist n acc = match n with\n\t| 0 -> acc\n\t| _ -> readlist (n -1) (gr() :: acc);;\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\n\nlet rec kth_not_div n k = \n\tlet o = k mod (n - 1) in\n\tlet d = k / (n - 1) in\n\tlet ret = (n * d) + (if o==0 then (-1) else o) in\n\t(* let _ = Printf.printf \"n,k,o,d,ret = %d %d %d %d %d\\n\" n k o d ret in *)\n\tret;;\t\n \nlet do_one () = \n let n = gr () in\n let k = gr () in\n\t\tlet kth = kth_not_div n k in \n \tPrintf.printf \"%d\\n\" kth;;\n \nlet do_all t = \n for i = 1 to t do\n do_one ()\n done;;\n \nlet main() =\n\tlet t = gr () in\n\tdo_all t;;\n \nmain();;"}], "src_uid": "7d6f76e24fe9a352beea820ab56f03b6"} {"source_code": "let dist a b =\n\tmin (10+b-a) (min (abs (10+a-b)) (abs (a-b)))\n\nlet _ =\n\t\n\tlet (n,ini,fin) = Scanf.scanf \"%d %s %s\" (fun i j k -> (i,j,k))\n\tand res = ref 0 and f mot i = int_of_char (mot.[i]) in\n\t\tfor i=0 to n-1 do\n\t\t\tres := !res + dist (f ini i) (f fin i);\n\t\tdone;\n\tPrintf.printf \"%d\\n\" (!res)\n", "positive_code": [{"source_code": "let input () = \n let n = Scanf.scanf \"%d \" (fun n -> n) in\n let start = Array.init n (fun i -> Scanf.scanf \"%c \" (fun i -> i)) in\n let goal = Array.init n (fun i -> Scanf.scanf \"%c \" (fun i -> i)) in\n (n, start, goal)\n\nlet solve (n, start, goal) = \n let rec loop i count =\n if i < n\n then\n let s = Pervasives.int_of_char (start.(i)) in\n let g = Pervasives.int_of_char (goal.(i)) in\n let min = Pervasives.min s g in\n let max = Pervasives.max s g in\n let try_one = max - min in\n let try_two = min + 10 - max in\n let r = Pervasives.min try_one try_two in\n loop (i + 1) (count + r)\n else\n count\n in loop 0 0\n\nlet print result = Printf.printf \"%d\\n\" result\nlet () = print (solve (input ()))"}, {"source_code": "let split x = x |> Str.split (Str.regexp \"\") |> List.map int_of_string and\n minimum = List.fold_left min 10 and\n sum = List.fold_left (+) 0 in \nlet _ = read_line () and\n fromComb = read_line () |> split and\n toComb = read_line () |> split\nin\nList.map2 (fun x y -> List.map abs [x-y; y-x; 10+x-y; 10+y-x] |> minimum) fromComb toComb |> sum |> print_int\n"}, {"source_code": "let ( |> ) x f = f x;;\n\nlet n = read_int();;\nlet a = read_line();;\nlet b = read_line();;\nlet rec solve index =\n if index >= String.length a || index >= String.length b then\n 0\n else (\n let d = int_of_char a.[index] - (int_of_char b.[index]) |> abs in\n let dis = min d (10 - d) in\n dis + (solve (index + 1))\n );;\nsolve 0 |> print_int;;\n "}], "negative_code": [], "src_uid": "5adb1cf0529c3d6c93c107cf72fa5e0b"} {"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\n\ntype road_graph = (int * bool) list array\ntype dep_graph = int list array\ntype tout_comp = int -> int\n\nlet (%) f g x = f @@ g x\n\nlet () =\n let make_dfs g =\n let marked, mark =\n let marked = Array.(make (length g) false) in\n (fun v -> marked.(v)),\n (fun v -> marked.(v) <- true)\n in\n fun fout v ->\n let rec dfs v =\n if not (marked v) then begin\n mark v;\n List.iter dfs g.(v);\n fout v\n end\n in\n dfs v\n in\n let add_edge g a b = g.(a) <- b :: g.(a) in\n let transpose g =\n let g' = Array.(make (length g) []) in\n ArrayLabels.iteri g ~f:(fun a -> List.iter @@ fun b -> add_edge g' b a);\n g'\n in\n let condensation (g : dep_graph) : tout_comp =\n let n = Array.length g in\n let add, iter, get_tout =\n let order = Array.make n ~-1 in\n let index = Array.copy order in\n let size = ref 0 in\n (fun v -> incr size; order.(!size - 1) <- v; index.(v) <- !size -1),\n (fun f -> Array.iter f order),\n (fun v -> index.(v))\n in\n let dfs = make_dfs g in\n for i = 0 to n - 1 do dfs add i done;\n let set_parent, get_parent =\n let parent = Array.(make (length g) ~-1) in\n (fun p v -> parent.(v) <- p),\n (fun v -> parent.(v))\n in\n let dfs = make_dfs @@ transpose g in\n iter (fun i -> dfs (set_parent i) i);\n get_tout % get_parent\n in\n let opposite n i = n / 2 - (i - n / 2) - 1 in\n let _2sat (g : dep_graph) =\n let n = Array.length g in\n let toc = condensation g in\n try\n Some (Array.init (n / 2) (fun v ->\n let tocv = toc v and toc'v = toc @@ opposite n v in\n if tocv <> toc'v then tocv > toc'v\n else raise Not_found))\n with Not_found -> None\n in\n let dep_graph_of_road_graph (g : road_graph) : dep_graph =\n let n = Array.length g * 2 in\n let (!!) = opposite n in\n let add_disj, get =\n let g = Array.make n [] in\n (fun (a, b) -> add_edge g (!! a) b; add_edge g (!! b) a),\n (fun () -> g)\n in\n let add_disjs = List.iter add_disj in\n ArrayLabels.iteri g ~f:(fun i ->\n List.iter @@ fun (j, asphalted) ->\n add_disjs @@ (* literals correspond to enevenness of switches *)\n if asphalted then [(i, !! j); (j, !!i)] else [(i, j); (!!i, !!j)]);\n get ()\n in\n let solution = function\n | None -> \"Impossible\"\n | Some a ->\n let to_switch, _ =\n ArrayLabels.fold_left a\n ~init:([], 1)\n ~f:(fun (acc, i) even -> (if not even then i :: acc else acc), i + 1)\n in\n List.(Printf.sprintf \"%d\\n%s\"\n (length to_switch)\n (String.concat \" \" @@ map string_of_int @@ rev to_switch))\n in\n let input () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let add_road, get =\n let g = Array.make n [] in\n (fun a b asphalted -> add_edge g a (b, asphalted); add_edge g b (a, asphalted)),\n (fun () -> g)\n in\n for i = 1 to m do\n ignore i; (* to get rid of unused variable warning *)\n Scanf.scanf \" %d %d %d\" @@ fun a b asphalted ->\n add_road (a - 1) (b - 1) (asphalted = 1)\n done;\n get ()\n in\n input ()\n |> dep_graph_of_road_graph\n |> _2sat\n |> solution\n |> Printf.printf \"%s\\n\"\n", "positive_code": [{"source_code": "let () =\n Scanf.scanf \"%d %d\" (fun n m ->\n let g = Array.make n [] in\n for i = 1 to m do\n Scanf.scanf \" %d %d %d\" (fun a b c ->\n let a = a - 1 and b = b - 1 in\n g.(a) <- (b, c) :: g.(a); g.(b) <- (a, c) :: g.(b))\n done;\n let cc = Array.make n 2 in\n let rec dfs c v = match cc.(v) with\n | 2 -> cc.(v) <- c; List.iter (fun (v, c') -> dfs (1 land (lnot (c lxor c'))) v) g.(v)\n | c' when c = c' -> ()\n | _ -> raise Not_found\n in\n try\n Array.iteri (fun v _ -> try dfs 1 v with Not_found -> dfs 0 v) g;\n let l, _ = Array.fold_left (fun (acc, i) c -> (if c = 1 then string_of_int i :: acc else acc), i + 1) ([], 1) cc in\n Printf.printf \"%d\\n%s\\n\" (List.length l) (String.concat \" \" l)\n with Not_found -> Printf.printf \"Impossible\\n\")"}, {"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\nlet (%) f g x = f @@ g x\n\nlet () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let g = Array.make (n + n * n) [] in\n let add_edges = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a); g.(b) <- a :: g.(b) in\n let idx a b = n + n * (min a b) + (max a b) in\n for i = 1 to m do\n ignore i;\n Scanf.scanf \" %d %d %d\" @@ fun a b even ->\n let a = a - 1 and b = b - 1 in\n add_edges @@ if even = 1 then [(a, idx a b); (idx a b, b)] else [(a, b)]\n done;\n let colors = Array.make (n + n * n) None in\n let rec dfs c v = match colors.(v) with\n | Some c' when c <> c' -> raise Not_found\n | Some _ -> ()\n | None -> colors.(v) <- Some c; List.iter (dfs @@ not c) g.(v)\n in\n let get o = match o with Some c -> c | None -> assert false in\n try\n ArrayLabels.iteri colors ~f:(fun v c -> if c = None then dfs false v);\n List.(\n Array.sub colors 0 n |> Array.to_list\n |> mapi (fun i b -> i, b) |> filter (get % snd) |> map (string_of_int % succ % fst) |> fun l ->\n Printf.printf \"%d\\n%s\\n\" (length l) @@ String.concat \" \" l)\n with Not_found -> Printf.printf \"Impossible\\n\""}, {"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\n\nlet (%) f g x = f @@ g x\n\nmodule Option = struct\n let get = function\n | Some x -> x\n | None -> assert false\nend\n\nlet () =\n let dsf n = object(self)\n val parent = Array.init n (fun x -> x)\n val rank = Array.make n 1\n method get v =\n if v = parent.(v) then v\n else begin\n parent.(v) <- self#get parent.(v);\n parent.(v)\n end\n method merge a b =\n let a, b = (fun a b -> max a b, min a b) (self#get a) (self#get b) in\n if a <> b then begin\n parent.(b) <- a;\n if rank.(a) = rank.(b) then rank.(a) <- rank.(a) + 1\n end\n end in\n let bicolor g =\n let n = Array.length g in\n let colors = Array.make n None in\n let rec dfs color v =\n match colors.(v) with\n | Some c when c <> color -> raise Not_found\n | Some _ -> ()\n | None ->\n colors.(v) <- Some color;\n List.iter (dfs @@ not color) g.(v)\n in\n try\n for v = 0 to n - 1 do\n if colors.(v) = None then dfs false v\n done;\n Some (Array.map Option.get colors)\n with Not_found -> None\n in\n let add_edges g = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a) in\n let condense g : int list array * (int -> int) =\n let n = Array.length g in\n let dsf = dsf n in\n let iter_g f = ArrayLabels.iteri g ~f:(fun a -> List.iter @@ f a) in\n iter_g (fun a (b, asphalted) -> if asphalted then dsf#merge a b);\n let index = Array.make n None in\n let size = ref 0 in\n for i = 0 to n - 1 do\n let root = dsf#get i in\n begin match index.(root) with\n | Some _ -> ()\n | None -> incr size; index.(root) <- Some (!size - 1)\n end;\n index.(i) <- index.(root)\n done;\n let g' = Array.make n [] in\n let get v = Option.get index.(v) in\n iter_g (fun a (b, asphalted) ->\n let a, b = get a, get b in\n if not asphalted then add_edges g' [a, b; b, a]);\n g', get\n in\n let solve g : (int -> bool) option =\n let g', get = condense g in\n match bicolor g' with\n | Some colors -> Some (Array.get colors % get)\n | None -> None\n in\n let output n switched =\n let answer = ref [] in\n for i = 0 to n - 1 do\n if switched i then answer := (i + 1) :: !answer\n done;\n List.(Printf.sprintf \"%d\\n%s\"\n (length !answer)\n (String.concat \" \" @@ map string_of_int @@ rev !answer))\n in\n let input () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let g = Array.make n [] in\n let add_road a b asphalted = add_edges g [a, (b, asphalted); b, (a, asphalted)] in\n for i = 1 to m do\n ignore i; (* to get rid of unused variable warning *)\n Scanf.scanf \" %d %d %d\" @@ fun a b asphalted ->\n add_road (a - 1) (b - 1) (asphalted = 1)\n done;\n g\n in\n input ()\n |> fun g ->\n Printf.printf \"%s\\n\" @@\n match solve g with\n | None -> \"Impossible\"\n | Some f -> output (Array.length g) f"}, {"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\nlet (%) f g x = f @@ g x\n\nlet () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let g = Array.make n [] in\n let add_edge a b c = g.(a) <- (b, c) :: g.(a); g.(b) <- (a, c) :: g.(b) in\n for i = 1 to m do\n ignore i;\n Scanf.scanf \" %d %d %d\" @@ fun a b c ->\n add_edge (a - 1) (b - 1) c\n done;\n let colors = Array.make n ~-1 in\n let rec dfs c v = match colors.(v) with\n | -1 -> colors.(v) <- c; List.iter (fun (v, c') -> dfs (1 land (lnot @@ c lxor c')) v) g.(v)\n | c' when c = c' -> ()\n | _ -> raise Not_found\n in\n try\n Array.iteri (fun v _ -> try dfs 1 v with Not_found -> dfs 0 v) colors;\n Array.fold_left (fun (acc, i) c -> (if c = 1 then (string_of_int i) :: acc else acc), i + 1) ([], 1) colors\n |> fun (l, _) ->\n Printf.printf \"%d\\n%s\\n\" (List.length l) @@ String.concat \" \" l\n with Not_found -> Printf.printf \"Impossible\\n\""}, {"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\n\ntype road_graph = (int * bool) list array\ntype dep_graph = int list array\ntype tout_comp = int -> int\n\nlet (%) f g x = f @@ g x\n\nlet () =\n let make_dfs g =\n let marked, mark =\n let marked = Array.(make (length g) false) in\n Array.get marked,\n (fun v -> marked.(v) <- true)\n in\n fun fout v ->\n let rec dfs v =\n if not (marked v) then begin\n mark v;\n List.iter dfs g.(v);\n fout v\n end\n in\n dfs v\n in\n let add_edge g a b = g.(a) <- b :: g.(a) in\n let transpose g =\n let g' = Array.(make (length g) []) in\n ArrayLabels.iteri g ~f:(fun a -> List.iter @@ fun b -> add_edge g' b a);\n g'\n in\n let condensation g : tout_comp =\n let n = Array.length g in\n let add, iter, get_tout =\n let order = Array.make n ~-1 in\n let index = Array.copy order in\n let size = ref 0 in\n (fun v -> incr size; order.(!size - 1) <- v; index.(v) <- !size -1),\n (fun f -> Array.iter f order),\n Array.get index\n in\n let set_parent, get_parent =\n let parent = Array.(make (length g) ~-1) in\n (fun p v -> parent.(v) <- p),\n Array.get parent\n in\n let dfs = make_dfs g in\n for i = 0 to n - 1 do dfs add i done;\n let dfs = make_dfs @@ transpose g in\n iter (fun i -> dfs (set_parent i) i);\n get_tout % get_parent\n in\n let opposite n i = n / 2 - (i - n / 2) - 1 in\n let _2sat (g : dep_graph) =\n let n = Array.length g in\n let toc = condensation g in\n try\n Some (Array.init (n / 2) (fun v ->\n let tocv = toc v and tocv' = toc @@ opposite n v in\n if tocv <> tocv' then tocv > tocv'\n else raise Not_found))\n with Not_found -> None\n in\n let dep_graph_of_road_graph (g : road_graph) : dep_graph =\n let n = Array.length g * 2 in\n let (!!) = opposite n in\n let add_disj, get =\n let g = Array.make n [] in\n (fun (a, b) -> add_edge g (!! a) b; add_edge g (!! b) a),\n (fun () -> g)\n in\n let add_disjs = List.iter add_disj in\n ArrayLabels.iteri g ~f:(fun i ->\n List.iter @@ fun (j, asphalted) ->\n add_disjs @@ (* literals correspond to enevenness of switches *)\n if asphalted then [(i, !!j); (j, !!i)] else [(i, j); (!!i, !!j)]);\n get ()\n in\n let solution = function\n | None -> \"Impossible\"\n | Some a ->\n let to_switch, _ =\n ArrayLabels.fold_left a\n ~init:([], 1)\n ~f:(fun (acc, i) even -> (if not even then i :: acc else acc), i + 1)\n in\n List.(Printf.sprintf \"%d\\n%s\"\n (length to_switch)\n (String.concat \" \" @@ map string_of_int @@ rev to_switch))\n in\n let input () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let add_road, get =\n let g = Array.make n [] in\n (fun a b asphalted -> add_edge g a (b, asphalted); add_edge g b (a, asphalted)),\n (fun () -> g)\n in\n for i = 1 to m do\n ignore i; (* to get rid of unused variable warning *)\n Scanf.scanf \" %d %d %d\" @@ fun a b asphalted ->\n add_road (a - 1) (b - 1) (asphalted = 1)\n done;\n get ()\n in\n input ()\n |> dep_graph_of_road_graph\n |> _2sat\n |> solution\n |> Printf.printf \"%s\\n\"\n"}], "negative_code": [{"source_code": "let (@@) f x = f x\nlet (|>) x f = f x\nlet (%) f g x = f @@ g x\n\nlet () =\n Scanf.scanf \"%d %d\" @@ fun n m ->\n let g = Array.make (n + n * n) [] in\n let add_edges = List.iter @@ fun (a, b) -> g.(a) <- b :: g.(a); g.(b) <- a :: g.(b) in\n let idx a b = n + n * (min a b) + (max a b) in\n for i = 1 to m do\n ignore i;\n Scanf.scanf \" %d %d %d\" @@ fun a b even ->\n let a = a - 1 and b = b - 1 in\n add_edges @@ if even = 1 then [(a, idx a b); (idx a b, b)] else [(a, b)]\n done;\n let colors = Array.make (n + n * n) None in\n let rec dfs c v = match colors.(v) with\n | Some c' when c <> c' -> raise Not_found\n | Some _ -> ()\n | None -> colors.(v) <- Some c; List.iter (dfs @@ not c) g.(v)\n in\n let get o = match o with Some c -> c | None -> assert false in\n try\n ArrayLabels.iteri colors ~f:(fun v c -> if c = None then dfs false v);\n List.(\n Array.sub colors 0 n |> Array.to_list\n |> mapi (fun i b -> i, b) |> filter (get % snd) |> map (string_of_int % fst) |> fun l ->\n Printf.printf \"%d\\n%s\\n\" (length l) @@ String.concat \" \" l)\n with Not_found -> Printf.printf \"Impossible\\n\""}], "src_uid": "1598bd5d75abd3645d49604e0dc10765"} {"source_code": "let rec pass k = function\n | 0 -> 1\n | x -> (x + pass k (x - 1)) mod k;;\nlet k = read_int ();;\nfor i = 1 to k - 1 do\n print_int ((fun x -> if x == 0 then k else x) (pass k i));\n print_string \" \"\ndone;;\nprint_newline ();;\n", "positive_code": [{"source_code": "let n = Scanf.scanf \"%d\" abs;;\n\nlet m = ref 0;;\n\nfor i = 1 to n-1 do (\n\tm := ((!m + i) mod n);\n\tprint_int (!m + 1);\n\tif i <> n-1 then print_string \" \";\n) done\n"}], "negative_code": [], "src_uid": "7170c40405cf7a5e0f2bd15e4c7d189d"} {"source_code": "open Int64 open Str;;\nlet aset = Array.set;;\nlet [n; m]= List.map (int_of_string) (split (regexp \" \") (read_line ()));;\nlet mx= Array.make (n + 1) \"\" and x= ref 0L and y = ref 0L;;\nlet ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;\nlet pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;\nfor i= 0 to n-1 do Array.set mx i (read_line ()) done;;\nfor i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin\n if j <> m-1 then if String.get mx.(i) (j+1) = '.' then aset ma.(i) j 1L;\n if i <> n-1 then if String.get mx.(i+1) j = '.' then aset mb.(i) j 1L;\nend done done;;\nfor i= 1 to n do for j= 1 to m do \n aset pma.(i) j (sub (add (add pma.(i-1).(j) pma.(i).(j-1)) ma.(i-1).(j-1)) pma.(i-1).(j-1));\t\n aset pmb.(i) j (sub (add (add pmb.(i-1).(j) pmb.(i).(j-1)) mb.(i-1).(j-1)) pmb.(i-1).(j-1));\t\ndone done;;\nlet q= read_int ();;\nfor i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (split (regexp \" \") (read_line ())) in begin\n x := sub (add pma.(y2).(x2-1) pma.(y1-1).(x1-1)) (add pma.(y2).(x1-1) pma.(y1-1).(x2-1));\n if !x < 0L then x:= 0L;\n y := sub (add pmb.(y2-1).(x2) pmb.(y1-1).(x1-1)) (add pmb.(y2-1).(x1-1) pmb.(y1-1).(x2));\n if !y < 0L then y:= 0L;\n print_endline (to_string (add !x !y))\nend done;;\n", "positive_code": [{"source_code": "(*#load \"str.cma\";;*)\nopen Printf;;\nlet [n; m]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet mx= Array.make (n + 1) \"\";;\nlet ma= Array.make_matrix (n * 2) (m * 2) 0 and mb= Array.make_matrix (n * 2) (m * 2) 0;;\nlet pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0 and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0;;\nfor i= 0 to n - 1 do Array.set mx i (read_line ()) done;;\nfor i= 0 to n - 1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then\nbegin\n\tif j <> m - 1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1;\n\tif i <> n - 1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1;\nend done done;;\nfor i= 1 to n do for j= 1 to m do \n\tArray.set pma.(i) j (ma.(i - 1).(j - 1) + pma.(i).(j - 1) + pma.(i - 1).(j) - pma.(i-1).(j-1));\t\n\tArray.set pmb.(i) j (mb.(i - 1).(j - 1) + pmb.(i).(j - 1) + pmb.(i - 1).(j) - pmb.(i-1).(j-1));\t\ndone done;;\nlet q= read_int ();;\nfor i= 1 to q do\n let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n begin\n\t\tprint_int \n\t\t\t\t((max 0 (pma.(y2).(x2 - 1) - pma.(y2).(x1 - 1) - pma.(y1 - 1).(x2 - 1) + pma.(y1 - 1).(x1 - 1))) + \n\t\t\t\t(max 0 (pmb.(y2 - 1).(x2) - pmb.(y2 - 1).(x1 - 1) - pmb.(y1 - 1).(x2) + pmb.(y1 - 1).(x1 - 1))));\n\t\tprint_endline \"\"\n\tend\ndone;;\n"}, {"source_code": "open Int64;;\nlet [n; m]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet mx= Array.make (n + 1) \"\" and x= ref 0L and y = ref 0L;;\nlet ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;\nlet pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;\nfor i= 0 to n-1 do Array.set mx i (read_line ()) done;;\nfor i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin\n\tif j <> m-1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1L;\n\tif i <> n-1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1L;\nend done done;;\nfor i= 1 to n do for j= 1 to m do \n Array.set pma.(i) j\t(sub (add (add ma.(i - 1).(j - 1) pma.(i).(j - 1)) pma.(i - 1).(j)) pma.(i-1).(j-1));\t\n\tArray.set pmb.(i) j (sub (add (add mb.(i - 1).(j - 1) pmb.(i).(j - 1)) pmb.(i - 1).(j)) pmb.(i-1).(j-1));\t\ndone done;;\nlet q= read_int ();;\nfor i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in begin\n\tx := sub (add pma.(y2).(x2 - 1) pma.(y1 - 1).(x1 - 1)) (add pma.(y2).(x1 - 1) pma.(y1 - 1).(x2 - 1));\n\tif !x < 0L then x := 0L;\n\ty := sub (add pmb.(y2 - 1).(x2) pmb.(y1 - 1).(x1 - 1)) (add pmb.(y2 - 1).(x1 - 1) pmb.(y1 - 1).(x2));\n\tif !y < 0L then y := 0L;\n\tprint_endline (to_string (add !x !y))\nend done;;\n"}, {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\nlet read_string () = bscanf Scanning.stdib \" %s \" (fun x -> x)\n \nlet () = \n let h = read_int () in\n let w = read_int () in\n let grid = Array.init h (fun _ -> read_string()) in\n let q = read_int () in\n let query = Array.init q (fun _ ->\n let a = read_pair() in\n let b = read_pair() in\n (a,b)\n ) in\n\n let geth i j =\n if i<0 || j<0 then '#' else grid.(i).[j]\n in\n\n let getv i j =\n if i<0 || j<0 then '#' else grid.(j).[i]\n in\n\n let getcount count i j = if i<0 || j<0 then 0 else count.(i).(j) in\n \n let make_count h w get =\n let c = Array.make_matrix h w 0 in\n for i=0 to h-1 do\n for j=0 to w-1 do\n\tlet here = if (get i j) = '.' && (get i (j-1)) = '.' then 1 else 0 in\n\tc.(i).(j) <- here + (getcount c (i-1) j) + (getcount c i (j-2)) - (getcount c (i-1) (j-2));\n done\n done;\n c\n in\n\n let counth = make_count h w geth in\n let countv = make_count w h getv in\n\n for k = 0 to q-1 do\n let ((r1,c1),(r2,c2)) = query.(k) in\n let ((r1,c1),(r2,c2)) = ((r1-2,c1-2),(r2-1,c2-1)) in\n\n let heven =\n let c2 = c2 - (c2 land 1) in\n let c1 = c1 + (c1 land 1) in\n (getcount counth r2 c2)\n - (getcount counth r1 c2) - (getcount counth r2 c1)\n + (getcount counth r1 c1)\n in\n\n let hodd =\n let c2 = c2 - (1 - (c2 land 1)) in\n let c1 = c1 + (1 - (c1 land 1)) in\n (getcount counth r2 c2)\n - (getcount counth r1 c2) - (getcount counth r2 c1)\n + (getcount counth r1 c1)\n in\n\n let veven =\n let r2 = r2 - (r2 land 1) in\n let r1 = r1 + (r1 land 1) in\n (getcount countv c2 r2)\n - (getcount countv c1 r2) - (getcount countv c2 r1)\n + (getcount countv c1 r1)\n in\n\n let vodd =\n let r2 = r2 - (1 - (r2 land 1)) in\n let r1 = r1 + (1 - (r1 land 1)) in\n (getcount countv c2 r2)\n - (getcount countv c1 r2) - (getcount countv c2 r1)\n + (getcount countv c1 r1)\n in\n\n printf \"%d\\n\" (heven + hodd + veven + vodd)\n done\n"}], "negative_code": [{"source_code": "open Printf;;\nlet [n; m]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ()));;\nlet mx= Array.make (n + 1) \"\";;\nlet ma= Array.make_matrix (n * 2) (m * 2) 0 and mb= Array.make_matrix (n * 2) (m * 2) 0;;\nlet pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0 and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0;;\nfor i= 0 to n - 1 do Array.set mx i (read_line ()) done;;\nfor i= 0 to n - 1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then\nbegin\n\tif j <> m - 1 then if String.get mx.(i) (j + 1) = '.' then Array.set ma.(i) j 1;\n\tif i <> n - 1 then if String.get mx.(i + 1) j = '.' then Array.set mb.(i) j 1;\nend done done;;\nfor i= 1 to n do for j= 1 to m do \n\tArray.set pma.(i) j (ma.(i - 1).(j - 1) + pma.(i).(j - 1) + pma.(i - 1).(j) - pma.(i-1).(j-1));\t\n\tArray.set pmb.(i) j (mb.(i - 1).(j - 1) + pmb.(i).(j - 1) + pmb.(i - 1).(j) - pmb.(i-1).(j-1));\t\ndone done;;\nlet q= read_int ();;\nfor i= 1 to q do\n let [y1; x1; y2; x2]= List.map (int_of_string) (Str.split (Str.regexp \" \") (read_line ())) in\n begin\n\t\tif y2 <> 1 && x2 <> 1 then \n\t\t\tprint_int \n\t\t\t\t\t((max 0 (pma.(y2).(x2 - 1) - pma.(y2).(x1 - 1) - pma.(y1 - 1).(x2 - 1) + pma.(y1 - 1).(x1 - 1))) + \n\t\t\t\t\t(max 0 (pmb.(y2 - 1).(x2) - pmb.(y2 - 1).(x1 - 1) - pmb.(y1 - 1).(x2) + pmb.(y1 - 1).(x1 - 1))))\n\t\telse if y2 = 1 && x2 <> 1 then \n\t\t\tprint_int \n\t\t\t\t\t(max 0 (pma.(y2 - 1).(x2) - pma.(y2 - 1).(x1 - 1) - pma.(y1 - 1).(x2) + pma.(y1 - 1).(x1 - 1)))\n\t\telse if x2 = 1 && y2 <> 1 then\n\t\t\tprint_int \n\t\t\t\t\t(max 0 (pmb.(y2).(x2 - 1) - pmb.(y2).(x1 - 1) - pmb.(y1 - 1).(x2 - 1) + pmb.(y1 - 1).(x1 - 1)))\n\t\telse print_int 0;\n\t\tprint_endline \"\"\n\tend\ndone;;\n"}, {"source_code": "open Int64 open Str;;\nlet aset = Array.set;;\nlet [n; m]= List.map (int_of_string) (split (regexp \" \") (read_line ()));;\nlet mx= Array.make (n + 1) \"\" and x= ref 0L and y = ref 0L;;\nlet ma= Array.make_matrix (n * 2) (m * 2) 0L and mb= Array.make_matrix (n * 2) (m * 2) 0L;;\nlet pma= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L and pmb= Array.make_matrix (n * 2 + 1) (m * 2 + 1) 0L;;\nfor i= 0 to n-1 do Array.set mx i (read_line ()) done;;\nfor i= 0 to n-1 do for j= 0 to m - 1 do if String.get mx.(i) j = '.' then begin\n if j <> m-1 then if String.get mx.(i) (j+1) = '.' then aset ma.(i) j 1L;\n if i <> n-1 then if String.get mx.(i+1) j = '.' then aset mb.(i) j 1L;\nend done done;;\nfor i= 1 to n do for j= 1 to m do \n aset pma.(i) j (sub (add (add ma.(i-1).(j) pma.(i).(j-1)) pma.(i-1).(j-1)) pma.(i-1).(j-1));\t\n aset pmb.(i) j (sub (add (add mb.(i-1).(j-1) pmb.(i).(j-1)) pmb.(i-1).(j)) pmb.(i-1).(j-1));\t\ndone done;;\nlet q= read_int ();;\nfor i= 1 to q do let [y1; x1; y2; x2]= List.map (int_of_string) (split (regexp \" \") (read_line ())) in begin\n x := sub (add pma.(y2).(x2-1) pma.(y1-1).(x1-1)) (add pma.(y2).(x1-1) pma.(y1-1).(x2-1));\n if !x < 0L then x:= 0L;\n y := sub (add pmb.(y2-1).(x2) pmb.(y1-1).(x1-1)) (add pmb.(y2-1).(x1-1) pmb.(y1-1).(x2));\n if !y < 0L then y:= 0L;\n print_endline (to_string (add !x !y))\nend done;;\n"}], "src_uid": "d9fdf0827940883069bead0d00b3da53"} {"source_code": "#load \"str.cma\";;\n\nlet rec get_input () =\n let n = int_of_string (read_line ()) and\n\t ls = Str.split (Str.regexp \"[ \\t]+\") (read_line ()) in\n (n, Array.mapi (fun idx x -> (idx, x))\n\t(Array.of_list (List.map int_of_string ls)));;\n\nlet print_int' n =\n begin\n\tprint_int (n + 1);\n\tprint_string \"\\n\";\n end;;\n\nlet solve n sls =\n if n == 1 then print_int' (fst sls.(0))\n else\n\tbegin\n\t Array.fast_sort (fun (idxx, x) (idxy, y) -> x - y) sls;\n\t (* Array.iter (fun (x, y) -> print_int y) sls;*)\n\t if snd (sls.(0)) == snd (sls.(1)) then\n\t\tprint_string \"Still Rozdil\\n\"\n\t else\n\t\tprint_int' (fst (sls.(0)))\n\tend;;\n\nlet (n, ls) = get_input () in\nsolve n ls;;\n\n \n", "positive_code": [{"source_code": "let _ =\n let n = Scanf.scanf \" %d\" (fun x -> x) in\n let a = Array.make n 0 in\n for i = 0 to n - 1 do\n Scanf.scanf \" %d\" (fun x -> a.(i) <- x)\n done;\n let k = ref 0 in\n let m = ref a.(0) in\n for i = 1 to n - 1 do\n if a.(i) < !m then (m := a.(i); k := i)\n else if a.(i) = !m then k := -1\n done;\n if !k = -1\n then print_string \"Still Rozdil\"\n else print_int (!k + 1)\n;;\n"}], "negative_code": [{"source_code": "#load \"str.cma\";;\n\nlet rec get_input () =\n let n = read_line () and\n\t ls = Str.split (Str.regexp \"[ \\t]\") (read_line ()) in\n (n, List.map int_of_string ls);;\n\nlet solve n ls =\n let rec iter l cur flag =\n\tmatch l with \n\t\t[] -> if flag then -1 else cur\n\t | (x::xs) ->\n\t\tif x == cur then \n\t\t iter xs x true\n\t\telse if x < cur then\n\t\t iter xs x false\n\t\telse\n\t\t iter xs cur flag\n in iter ls 1000000001 false;;\n\nlet (n, ls) = get_input () in\nbegin\n (*\n List.iter (fun x -> print_int x; print_string\" \") ls;\n print_string \"\\n\";\n *)\n if solve n ls == -1 then\n\tprint_string \"Still Rozdil\"\n else print_int (solve n ls); print_string \"\\n\";\nend\n"}], "src_uid": "ce68f1171d9972a1b40b0450a05aa9cd"} {"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 minf i j f = fold (i+1) j (fun k a -> min (f k) a) (f i)\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let v = read_int () in\n let s = Array.make n [||] in\n for i=0 to n-1 do\n let k = read_int () in\n s.(i) <- Array.init k (fun i-> read_int())\n done;\n\n let rec loop i ac = if i=n then ac else\n let m = minf 0 ((Array.length s.(i)) -1) (fun j -> s.(i).(j)) in\n if m < v then loop (i+1) (i::ac) else loop (i+1) ac\n in\n\n let ans = loop 0 [] in\n let ans = List.sort compare ans in\n\n printf \"%d\\n\" (List.length ans);\n\n List.iter (fun i -> printf \"%d \" (i+1)) ans;\n\n print_newline();\n\n", "positive_code": [{"source_code": "let read_int()=Scanf.scanf \"%d \" (fun x->x);;\nlet n=read_int();;\nlet v=read_int();;\nlet tab=Array.make (n+1) 0;;\nlet vec=Array.make (n+1) false;;\nlet nb=ref 0;;\nfor i=1 to n do\n let x=read_int() in \n for j=1 to x do\n let a=read_int() in\n if a i) in \n let n = gr () in\n let ph flag = \n match flag with \n | 0 -> \"I hate\"\n | 1 -> \"I love\"\n in \n let rec f cnt flag = \n match cnt with \n | 1 -> ph flag\n | cnt -> String.concat \" that \" [ph flag; f (cnt - 1) (1 - flag)] \n in\n Printf.printf \"%s it\\n\" (f n 0)\n ;;\nlet _ = main();;\n", "positive_code": [{"source_code": "let input () = Scanf.scanf \"%d\" (fun n -> n)\n\nlet solve input = \n let rec loop i =\n if i <= input\n then\n ((if i mod 2 <> 0\n then\n Printf.printf \"I hate \"\n else\n Printf.printf \"I love \");\n (if i <> input\n then\n Printf.printf \"that \"\n else\n Printf.printf \"it\\n\");\n loop (i + 1))\n else\n ()\n in loop 1\n\nlet () = solve (input ())"}, {"source_code": "let rec get_result n p = \n if n > 1 then\n if p = 1 then\n \"I hate that \" ^ get_result (n-1) (1-p)\n else\n \"I love that \" ^ get_result (n-1) (1-p)\n else\n if p = 1 then\n \"I hate it\\n\"\n else\n \"I love it\\n\"\n\n;;\n\nlet () =\nlet n = read_int () in \nlet () = print_string (get_result n 1) in ();;\n\n"}, {"source_code": "let rec f t b x =\n if t = x then \n if (b = 1) then Printf.printf \"I hate it\\n\"\n else Printf.printf \"I love it\\n\"\n else\n (if (b = 1) then Printf.printf \"I hate that \"\n else Printf.printf \"I love that \";\n f (t + 1) (1 - b) x)\n;;\nlet _ =\n let x = read_int() in\n f 1 1 x\n;;\n"}, {"source_code": "let text_gen n =\n let rec helper k acc =\n if k == n \n then acc ^ \" it\"\n else \n if k mod 2 == 0 \n then helper (k+1) (acc ^ \" that I hate\")\n else helper (k+1) (acc ^ \" that I love\")\n in helper 1 \"I hate\"\nin\n \nlet n = read_int() in\nPrintf.printf \"%s\\n\" (text_gen 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\n for i = 1 to n do\n if i=1 then printf \"I hate \"\n else if i land 1 = 1 then printf \"that I hate \"\n else printf \"that I love \"\n done;\n\n printf \"it\\n\"\n"}], "negative_code": [{"source_code": "let input () = Scanf.scanf \"%d\" (fun n -> n)\n\nlet solve input = \n let rec loop i =\n if i <= input\n then\n ((if i mod 2 <> 0\n then\n Printf.printf \"I hate \"\n else\n Printf.printf \"I love \");\n (if i <> input\n then\n Printf.printf \"that \"\n else\n Printf.printf \"it.\\n\");\n loop (i + 1))\n else\n ()\n in loop 1\n\nlet () = solve (input ())"}], "src_uid": "7f2441cfb32d105607e63020bed0e145"} {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let rec loop cnt_ev cnt_od lst_ev lst_od = function\n | 0 -> if cnt_ev = 1 then lst_ev else lst_od\n | c -> (\n let num = read_int () in\n if num mod 2 = 0 then\n loop (cnt_ev+1) cnt_od c lst_od (c - 1)\n else\n loop cnt_ev (cnt_od+1) lst_ev c (c - 1)\n ) in\n Printf.printf \"%d\\n\" (n - (loop 0 0 0 0 n) + 1)\n", "positive_code": [{"source_code": "let () =\n let n = Scanf.scanf \"%d \" (fun a -> a) in\n let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf \"%d \" (fun a -> a)) in\n\n let o_l = List.mapi (fun i x -> if x mod 2 <> 0 then i+1 else -1) a_lst\n |> List.filter (fun x -> x <> -1)\n in\n let e_l = List.mapi (fun i x -> if x mod 2 = 0 then i+1 else -1) a_lst\n |> List.filter (fun x -> x <> -1)\n in\n\n if List.length o_l = 1 then\n Printf.printf \"%d\\n\" @@ List.hd o_l\n else\n Printf.printf \"%d\\n\" @@ List.hd e_l\n"}, {"source_code": "let rec split s i acc =\nbegin\n if i > String.length s \n then List.rev acc\n else \n let first = \n if String.contains_from s i ' ' \n then String.index_from s i ' ' \n else String.length s \n in split s (first+1) (int_of_string (String.init (first-i) (fun x -> String.get s (i+x))) :: acc) \nend in \nlet rec find n xs =\n match xs with\n | (1::0::0::_) | (0::1::1::_) -> n+0\n | (0::1::0::_) | (1::0::1::_) -> n+1\n | (0::0::1::_) | (1::1::0::_) -> n+2\n | bs -> find (n+1) (List.tl bs)\nin\nlet _ = int_of_string (read_line ()) in\nlet xs = split (read_line ()) 0 [] in\nprint_int (xs |> List.map (fun x -> x mod 2 ) |> find 1 )\n"}, {"source_code": "let index_of_list elm lst =\n let rec loop lst index =\n match lst with\n | [] -> -1\n | h :: t ->\n\tif h = elm then index\n\telse loop t (index+1)\n in\n loop lst 0\n\t\nlet solve lst =\n let evens = List.filter (fun x -> x mod 2 = 0) lst in\n if List.length evens = 1 then (index_of_list (List.hd evens) lst)+1\n else\n let odds = List.filter (fun x -> x mod 2 = 1) lst in\n (index_of_list (List.hd odds) lst)+1\n\nlet rec some_int n =\n if 0 >= n then [] else (Scanf.scanf \" %d\" (fun x -> x)) :: some_int (n - 1)\n \nlet _ =\n let lst = Scanf.scanf \" %d\" some_int in\n Printf.printf \"%d\\n\" (solve (List.rev lst))\n"}, {"source_code": "let id x = x in\nlet (@.) f g = fun x -> f @@ g x in\nlet scan_int () = Scanf.scanf \" %d\" id in\nlet rec read_n_ints n = let i = scan_int () in\n if n = 1 then [i]\n else [i] @ (read_n_ints @@ n-1) in\n\nlet rec find_first_index p l = match l with\n | [] -> 0\n | hd :: tl when p hd -> 0\n | _ :: tl -> 1 + (find_first_index p tl) in\n\nlet n = scan_int () in\nlet l = read_n_ints n in\nlet is_even x = x mod 2 = 0 in\nlet n_even = l |> List.filter is_even |> List.length in\nlet index = if n_even = 1 then find_first_index is_even l\n else find_first_index (not @. is_even) l in\nPrintf.printf \"%d\\n\" @@ 1 + index"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet find_rare_parity array = \n let rec loop i odds evens =\n if i < 3\n then\n if array.(i) mod 2 > 0\n then\n loop (i + 1) (odds + 1) evens\n else\n loop (i + 1) odds (evens + 1)\n else\n if odds > evens\n then\n 0\n else\n 1\n in loop 0 0 0\n\nlet get_index parity array l =\n let rec loop i = \n if i < l\n then\n if array.(i) mod 2 = parity\n then\n i + 1\n else\n loop (i + 1)\n else\n failwith \"Corrupted input\"\n in loop 0\n\nlet solve () = \n let l = read () in\n let numbers = Array.init l (fun x -> read ()) in\n get_index (find_rare_parity numbers) numbers l\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet find_rare_parity array = \n let rec loop i odds evens =\n if i < 3\n then\n if array.(i) mod 2 > 0\n then\n loop (i + 1) (odds + 1) evens\n else\n loop (i + 1) odds (evens + 1)\n else\n if odds > evens\n then\n `even\n else\n `odd\n in loop 0 0 0\n\nlet get_index parity array l =\n let rec loop i = \n if i < l\n then\n if parity = `odd \n then\n if array.(i) mod 2 > 0\n then\n i + 1\n else\n loop (i + 1)\n else\n if array.(i) mod 2 = 0\n then\n i + 1\n else\n loop (i + 1)\n else\n failwith \"Corrupted input\"\n in loop 0\n\nlet solve () = \n let l = read () in\n let numbers = Array.init l (fun x -> read ()) in\n get_index (find_rare_parity numbers) numbers l\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet find_rare_parity array = \n let rec loop i odds evens =\n if i < 3\n then\n if array.(i) mod 2 > 0\n then\n loop (i + 1) (odds + 1) evens\n else\n loop (i + 1) odds (evens + 1)\n else\n if odds > evens\n then\n `even\n else\n `odd\n in loop 0 0 0\n\nlet get_odd_index array l =\n let rec loop i = \n if i < l\n then\n if array.(i) mod 2 > 0\n then\n i + 1\n else\n loop (i + 1)\n else\n failwith \"No odd numbers\"\n in loop 0\n\nlet get_even_index array l =\n let rec loop i = \n if i < l\n then\n if array.(i) mod 2 = 0\n then\n i + 1\n else\n loop (i + 1)\n else\n failwith \"No even numbers\"\n in loop 0\n\nlet solve () = \n let l = read () in\n let numbers = Array.init l (fun x -> read ()) in\n if find_rare_parity numbers = `odd\n then \n get_odd_index numbers l\n else\n get_even_index numbers l\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve ())"}], "negative_code": [{"source_code": "let index_of_list elm lst =\n let rec loop lst index =\n match lst with\n | [] -> -1\n | h :: t ->\n\tif h = elm then index\n\telse loop t (index+1)\n in\n loop lst 0\n\t\nlet solve lst =\n let evens = List.filter (fun x -> x mod 2 = 0) lst in\n if List.length evens = 1 then (index_of_list (List.hd evens) lst)+1\n else\n let odds = List.filter (fun x -> x mod 2 = 1) lst in\n (index_of_list (List.hd odds) lst)+1\n\nlet rec some_int n =\n if 0 >= n then [] else (Scanf.scanf \" %d\" (fun x -> x)) :: some_int (n - 1)\n \nlet _ =\n let lst = Scanf.scanf \" %d\" some_int in\n Printf.printf \"%d\\n\" (solve lst)\n"}], "src_uid": "dd84c2c3c429501208649ffaf5d91cee"} {"source_code": "let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> Int64.of_int x);;\r\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x);;\r\nlet read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;\r\nlet comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;; \r\nlet min x y = if Int64.compare x y < 0 then x else y\r\nlet max x y = if Int64.compare x y > 0 then x else y\r\nlet empty_read x = read_int64 ();;\r\n\r\nlet n = read_int ();;\r\nlet a = Array.init n empty_read;;\r\nlet b = Array.init n empty_read;;\r\nlet c = (Array.init n (fun i ->\r\n if Int64.compare a.(i) b.(i) <= 0\r\n then (a.(i), b.(i), 0)\r\n else (b.(i), a.(i), 1)));;\r\nlet _ = Array.sort (fun (x, y, z) (u, v, w) ->\r\n if Int64.compare x u != 0\r\n then Int64.compare x u\r\n else\r\n if Int64.compare y v != 0\r\n then Int64.compare y v\r\n else compare z w) c;;\r\nlet mx = Array.make 2 Int64.zero;;\r\nlet ans = Array.fold_left Int64.add Int64.zero (\r\n Array.map (fun (a, b, c) -> Int64.sub b a) c);;\r\n \r\nlet diff = ref Int64.zero;;\r\nfor i = 0 to n - 1 do\r\n match c.(i) with (a, b, x) ->\r\n diff := max !diff (Int64.sub (min b mx.(1 - x)) a);\r\n mx.(x) <- max mx.(x) b\r\ndone;;\r\n\r\nPrintf.printf \"%s\\n\" (Int64.to_string (Int64.sub ans (Int64.mul 2L !diff)));;", "positive_code": [{"source_code": "let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> Int64.of_int x);;\r\nlet read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x);;\r\nlet read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;\r\nlet comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;; \r\n\r\nlet min x y = if Int64.compare x y < 0 then x else y\r\n\r\nlet max x y = if Int64.compare x y > 0 then x else y\r\n\r\nlet empty_read x = read_int64 ();;\r\n\r\nlet n = read_int ();;\r\nlet a = Array.init n empty_read;;\r\nlet b = Array.init n empty_read;;\r\nlet c = (Array.init n (fun i ->\r\n if Int64.compare a.(i) b.(i) <= 0\r\n then (a.(i), b.(i), 0)\r\n else (b.(i), a.(i), 1)));;\r\n\r\nlet _ = Array.stable_sort (fun (x, y, z) (u, v, w) ->\r\n if Int64.compare x u != 0\r\n then Int64.compare x u\r\n else\r\n if Int64.compare y v != 0\r\n then Int64.compare y v\r\n else compare z w) c;;\r\n\r\nlet mx = Array.make 2 Int64.zero;;\r\n\r\nlet ans = Array.fold_left Int64.add Int64.zero (\r\n Array.map (fun (a, b, c) -> Int64.sub b a) c);;\r\n\r\nlet diff = ref Int64.zero;;\r\n\r\nfor i = 0 to n - 1 do\r\n match c.(i) with (a, b, x) ->\r\n diff := max !diff (Int64.sub (min b mx.(1 - x)) a);\r\n mx.(x) <- max mx.(x) b\r\ndone;;\r\n\r\nPrintf.printf \"%s\\n\" (Int64.to_string (Int64.sub ans (Int64.mul 2L !diff)))\r\n\r\n"}], "negative_code": [], "src_uid": "f995d575f86eee139c710cb0fe955682"} {"source_code": "let input () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet if_max max ppl_inside =\n if ppl_inside > max\n then\n ppl_inside\n else\n max \n\nlet rec at_trainstop ppl_inside max n =\n if n > 0\n then\n let new_ppl = Scanf.scanf \"%d %d \" (fun a b -> (-a + b)) in\n at_trainstop (ppl_inside + new_ppl) (if_max max (ppl_inside + new_ppl)) (n - 1)\n else\n max\n\nlet solve input = at_trainstop 0 0 input\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet nn = n + 10\n\nlet a = Array.make nn (-1);;\nlet b = Array.make nn (-1);;\nlet c = Array.make nn (-1);; (*The number of people on tram after each stop*)\n\nfor i = 1 to n do\n let (ai,bi) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d \" ( fun x y -> (x,y) ) in\n a.(i) <- ai; b.(i) <- bi\ndone\n;;\n\nlet () = c.(0) <- 0;;\n\nfor i = 1 to n do\n c.(i) <- (c.(i-1) + b.(i-1) - a.(i-1))\ndone\n;;\n\nlet z = Array.fold_left (fun x y -> if x > y then x else y ) (-1) c\nin print_int z; print_endline \"\"\n"}, {"source_code": "let solve n stops =\n let rec loop stops passenger max_capacity = match stops with\n [] -> max_capacity\n | first :: rest ->\n loop rest (passenger+(snd first)-(fst first)) (max passenger max_capacity)\n in\n loop stops 0 0;;\n\nlet rec get_stops n stops=\n if n <= 0\n then stops\n else get_stops (n-1) (Scanf.scanf \"%d %d\\n\" (fun x y -> (x, y)) :: stops)\n\nlet get_stops n = List.rev (get_stops n [])\n\nlet _ =\n let n = Scanf.scanf \"%d\\n\" (fun x -> x) in\n let stops = get_stops n in\n Printf.printf \"%d\\n\" (solve n stops)\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet solve n =\n let rec find_max n max sum = match n with\n | 0 -> max\n | n -> let a = read_int ()\n and b = read_int () in\n let new_sum = sum - a + b in\n if max > new_sum\n then find_max (n - 1) max new_sum\n else find_max (n - 1) new_sum new_sum\n in find_max n 0 0\n\nlet () =\n let n = read_int ()\n in Printf.printf \"%d\\n\" (solve 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 _ =\n let n = sf \"%d\\n\" (fun x -> x) in\n let a = ref 0 in\n let b = ref 0 in\n let res = ref 0 in\n for i = 1 to n do\n let (x, y) = sf \"%d %d\\n\" (fun x y -> x, y) in\n a := !a + x;\n b := !b + y;\n res := max !res (!b - !a)\n done;\n pf \"%d\\n\" !res\n;;\n"}, {"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x)\n\nlet max a b = \n if a < b then b\n else a\n\nlet () =\n let n = ref (read_int ()) in\n let ans = ref 0 in\n let count_now = ref 0 in\n for i = 1 to !n do\n count_now := !count_now + read_int () - read_int ();\n ans := max !ans !count_now;\n done;\n Printf.printf \"%d\" !ans;\n"}, {"source_code": "let read_list () = \n let n = read_int() \n and l = ref [] in\n for i = 1 to n do\n let pair = Scanf.scanf \" %d %d\" (fun a b -> (a, b)) in\n l := pair :: !l;\n done;\n !l\n\nlet solve l =\n fst (List.fold_left\n (fun (mx, ac) (hm, hp) -> let na = (ac + hp - hm) in (max mx na, na))\n (0, 0)\n (List.rev l))\n\nlet print_res = \n print_int \n\nlet main =\n let l = read_list () in\n print_res (solve l)\n \n\n \n"}, {"source_code": "let _ =\n let main () =\n let n = Scanf.sscanf (read_line ()) \"%d\" (fun n -> n) in\n let rec loop i cur m =\n if i = 0 then Printf.printf \"%d\\n\" m else\n let (a, b) = Scanf.sscanf (read_line ()) \"%d %d\" (fun a b -> a, b) in\n let cur = cur - a + b in\n let m = max cur m in\n loop (i - 1) cur m\n in\n loop n 0 0\n in\n main ()\n"}, {"source_code": "let input () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet rec at_trainstop ppl_inside current_max n =\n if n > 0\n then\n let new_ppl = Scanf.scanf \"%d %d \" (fun a b -> (-a + b)) in\n at_trainstop (ppl_inside + new_ppl) (Pervasives.max current_max (ppl_inside + new_ppl)) (n - 1)\n else\n current_max\n\nlet solve input = at_trainstop 0 0 input\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))"}, {"source_code": "let rec tram n l m o i =\n\tif n = 0 then m\n\telse Scanf.scanf \"%d %d\\n\" (fun oo ii -> \n\t\ttram (n-1) (l-o+i) (max (l-o+i) m) oo ii\n\t)\n;;\n\nlet () =\n\tlet n = read_int () in\n\tprint_int (tram n 0 0 0 0)\n;;\n"}, {"source_code": "let read_int() = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x)\nlet printf = Printf.printf\n\nlet max a b = if (a > b) then a else b\n\nlet () = \n\tlet n = read_int() in \n\tlet a = Array.make (n + 1) 0 in \n\tlet b = Array.make (n + 1) 0 in \n\tlet sum = ref 0 in \n\tlet mx = ref 0 in \n\t\tfor i = 1 to n do \n\t\t\ta.(i) <- read_int();\n\t\t\tb.(i) <- read_int();\n\t\t\tsum := !sum - a.(i) + b.(i); \n\t\t\tmx := max !mx !sum;\n\t\tdone;\n\t\tprintf \"%d\\n\" (!mx) "}, {"source_code": "let read_int()=Scanf.scanf \" %d\" (fun x->x);;\nlet n=read_int() and r=ref 0 and s=ref 0;;\nfor i=1 to n do\n let x=read_int() and y=read_int() in\n r:= !r+y-x;\n s:=max !s !r\ndone;;\nPrintf.printf \"%d\" !s;;"}], "negative_code": [{"source_code": "let rec tram n m o i =\n\tif n = 0 then m\n\telse let oo, ii = Scanf.scanf \"%d %d\\n\" (fun o i -> (o, i)) \n\t\tin tram (n-1) (max (m-o+i) m) oo ii\n;;\n\nlet () =\n\tlet n = read_int () in\n\tprint_int (tram n 0 0 0)\n;;\n"}, {"source_code": "let read_int() = Scanf.bscanf Scanf.Scanning.stdin \" %d \" (fun x -> x)\nlet printf = Printf.printf\n\nlet max a b = if (a > b) then a else b\n\nlet () = \n\tlet n = read_int() in \n\tlet a = Array.make (n + 1) 0 in \n\tlet b = Array.make (n + 1) 0 in \n\tlet sum = ref 0 in \n\tlet mx = ref 0 in \n\t\tfor i = 1 to n do \n\t\t\ta.(i) <- read_int();\n\t\t\tb.(i) <- read_int();\n\t\t\tsum := !sum + a.(i) - b.(i); \n\t\t\tmx := max !mx !sum;\n\t\tdone;\n\t\tprintf \"%d\\n\" (!mx) "}, {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\nlet nn = n + 10\n\nlet a = Array.make nn (-1);;\nlet b = Array.make nn (-1);;\nlet c = Array.make nn (-1);; (*The number of people on tram after each stop*)\n\nfor i = 1 to n do\n let (ai,bi) = Scanf.bscanf Scanf.Scanning.stdin \"%d %d \" ( fun x y -> (x,y) ) in\n a.(i) <- ai; b.(i) <- bi\ndone\n;;\n\nlet () = c.(0) <- 0;;\n\nfor i = 1 to n-1 do\n c.(i) <- (c.(i-1) + b.(i-1) - a.(i-1))\ndone\n;;\n\nlet z = Array.fold_left (fun x y -> if x > y then x else y ) (-1) c\nin print_int z; print_endline \"\"\n"}, {"source_code": "let read_list () = \n let n = read_int() \n and l = ref [] in\n for i = 1 to n do\n let pair = Scanf.scanf \" %d %d\" (fun a b -> (a, b)) in\n l := pair :: !l;\n done;\n !l\n\nlet solve l =\n List.fold_left \n (fun ac (hp, hm) -> max ac (ac - hp + hm))\n 0\n l\n\nlet print_res = \n print_int \n\nlet main =\n let l = read_list () in\n print_res (solve l)\n \n\n \n"}], "src_uid": "74b90fe9458b147568ac9bd09f219aab"} {"source_code": "Scanf.(Array.(\n let n = scanf \" %d\" @@ fun v -> v in\n let l,r,zero = make 500010 0, make 500010 0, ref 0 in\n init n (fun _ ->\n let s = scanf \" %s\" @@ fun v -> v in\n let s = init (String.length s) (fun i -> s.[i]) in\n let post,pre = fold_left (fun (sum,pre) -> function\n | '(' -> (sum+1,pre)\n | ')' -> if sum=0 then (0,pre+1) else (sum-1,pre)\n | _ -> failwith \"\"\n ) (0,0) s in\n if post>0 && pre>0 then ()\n else if post>0 then (\n r.(post) <- r.(post) + 1\n ) else if pre>0 then (\n l.(pre) <- l.(pre) + 1\n ) else (\n zero := !zero + 1\n )\n ) |> ignore;\n fold_left (fun (sum,i) v ->\n let u = r.(i) in (sum + min u v,i+1)\n ) (!zero/2,0) l\n |> fst |> print_int\n))", "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_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 calc s =\n let cnt,pre,post = ref 0L,ref 0L,ref 0L in\n String.iteri (fun i c ->\n if c = '(' then cnt += 1L\n else (\n cnt -= 1L;\n if !cnt < 0L then (\n pre := max (!pre) (-1L*(!cnt));\n )\n )\n ) s;\n cnt := !pre;\n String.iteri (fun i c ->\n if c = '(' then cnt += 1L\n else (\n cnt -= 1L;\n )\n ) s;\n post := !cnt;\n if !cnt>0L && !pre>0L then (\n `None\n ) else if !pre>0L then (\n `Pre !pre\n ) else if !post>0L then (\n `Post !cnt\n ) else (\n `Zero\n )\nlet () =\n let n = gi 0 in\n let pos,neg,zero = make 600010 0L,make 600010 0L,ref 0L in\n repi 1 (i32 n) (fun i ->\n let s = scanf \" %s\" @@ id in\n let v = calc s in\n match v with\n | `None -> ()\n | `Pre v ->\n neg.(i32 v) <- neg.(i32 v) + 1L\n | `Post v ->\n pos.(i32 v) <- pos.(i32 v) + 1L\n | `Zero -> zero += 1L\n );\n let r = ref 0L in\n iteri (fun i v ->\n let w = neg.(i) in\n r += min v w\n ) pos;\n r += !zero/2L;\n printf \"%Ld\\n\" !r\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 calc s =\n let r = ref [] in\n let lv = ref 0L in\n String.iteri (fun i c ->\n if c = '(' then (\n r := i :: !r;\n lv += 1L;\n ) else (\n match !r with\n | i::tl -> (\n r := tl;\n lv -= 1L\n );\n | [] -> lv -= 1L;\n )\n ) s; !lv\nlet () =\n let n = gi 0 in\n let pos,neg,zero = make 100010 0L,make 100010 0L,ref 0L in\n repi 1 (i32 n) (fun i ->\n let s = scanf \" %s\" @@ id in\n let v = calc s in\n (* printf \"%Ld\\n\" v; *)\n if v > 0L then (\n pos.(i32 v) <- pos.(i32 v) + 1L\n ) else if v < 0L then (\n neg.(-i32 v) <- neg.(-i32 v) + 1L\n ) else zero += 1L\n );\n let r = ref 0L in\n iteri (fun i v ->\n let w = neg.(i) in\n r += min v w\n ) pos;\n r += !zero/2L;\n printf \"%Ld\\n\" !r\n\n\n\n\n\n\n\n\n"}], "src_uid": "2cfb08b2269dbf5417c1758def4c035f"} {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet make_array () = \n let n = read () in\n let array = Array.make n (0, 0) in\n let rec loop i array prev = \n if i < n\n then\n let quantity = read () in\n let min = prev + 1 in\n let max = prev + quantity in\n let () = Array.set array i (min, max) in\n loop (i + 1) array max\n else\n (n, array)\n in loop 0 array 0\n\n\nlet make_list () = \n let n = read () in\n let rec loop i list =\n if i < n\n then\n let value = read () in\n loop (i + 1) (value :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () =\n let piles = make_array () in\n let worms = make_list () in\n (piles, worms)\n\nlet classify (min, max) value =\n if value >= min && value <= max\n then\n `Inside\n else\n if value < min\n then\n `To_the_left\n else\n `To_the_right\n\nlet rec binary_search array value low high = \n let mid = (low + high) / 2 in\n match classify array.(mid) value with\n | `To_the_right -> binary_search array value (mid + 1) high \n | `To_the_left -> binary_search array value low (mid - 1)\n | `Inside -> mid + 1\n\nlet wrapper (n, array) value = \n let result = binary_search array value 0 n in\n Printf.printf \"%d\\n\" result\n \nlet solve (piles, worms) = \n List.iter (wrapper piles) worms \n\nlet () =\n solve (input ())", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\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 \" %d \" (fun x -> x)\nlet read_long () = bscanf Scanning.stdib \" %Ld \" (fun x -> x)\n\nlet () = \n let n = read_int() in\n let a = Array.init n (fun _ -> read_long()) in\n let m = read_int() in\n let q = Array.init m (fun _ -> read_long()) in\n\n let ends = Array.make n 0L in\n ends.(0) <- a.(0);\n \n for i=1 to n-1 do\n ends.(i) <- ends.(i-1) ++ a.(i)\n done;\n\n let find i = \n let rec bsearch lo hi = \n (* must be in lo, lo+1....hi-1 *)\n if lo+1 = hi then lo else\n\tlet m = (lo+hi)/2 in\n\tif i > ends.(m-1) then bsearch m hi else bsearch lo m\n in\n \n bsearch 0 n\n in\n \n for i=0 to m-1 do\n printf \"%d\\n\" (1 + find q.(i))\n done;\n"}], "negative_code": [], "src_uid": "10f4fc5cc2fcec02ebfb7f34d83debac"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make h (-1) in\n let ht = Hashtbl.create h in\n let res = ref 0 in\n for i = 0 to n - 1 do\n let op = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tmatch op with\n\t | \"+\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let j = ref hash in\n\t\twhile a.(!j) >= 0 do\n\t\t j := (!j + m) mod h;\n\t\t incr res;\n\t\tdone;\n\t\tHashtbl.replace ht id !j;\n\t\ta.(!j) <- id;\n\t | \"-\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Hashtbl.find ht id in\n\t\tHashtbl.remove ht id;\n\t\ta.(hash) <- -1;\n\t | _ -> assert false\n done;\n Printf.printf \"%d\\n\" !res;\n", "positive_code": [{"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet g2d n = n land (-n)\n\nlet fenwick_new n =\n Array.make n 0\n\nlet fenwick_modify ft n x =\n let i = ref (n + 1) in\n while !i <= Array.length ft do\n ft.(!i - 1) <- ft.(!i - 1) + x;\n i := !i + g2d !i;\n done\n\nlet fenwick_count ft n =\n let i = ref (n + 1) in\n let res = ref 0 in\n while !i > 0 do\n res := !res + ft.(!i - 1);\n i := !i - g2d !i;\n done;\n !res\n\nlet fenwick_count2 ft m n =\n fenwick_count ft n - fenwick_count ft (m - 1)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make h (-1) in\n let b = Array.make (2 * h) (-1) in\n let c = Array.make h (-1) in\n let g = gcd m h in\n let () =\n let pos = ref 0 in\n for i = 0 to h - 1 do\n\tif c.(i) < 0 then (\n\t let k = ref i in\n\t for j = 0 to h / g - 1 do\n\t c.(!k) <- !pos;\n\t b.(!pos) <- !k;\n\t b.(!pos + h / g) <- !k;\n\t incr pos;\n\t k := (!k + m) mod h;\n\t done;\n\t pos := !pos + h / g;\n\t)\n done\n in\n let ft = fenwick_new (2 * h) in\n let ht = Hashtbl.create h in\n let res = ref 0L in\n for i = 0 to n - 1 do\n let op = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tmatch op with\n\t | \"+\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let l = ref (c.(hash) - 1) in\n\t let r = ref (c.(hash) + h / g) in\n\t\twhile !l < !r - 1 do\n\t\t let m = (!l + !r) / 2 in\n(*Printf.printf \"step %d %d %d %d\\n\" !l !r m (fenwick_count2 ft c.(hash) m);*)\n\t\t if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)\n\t\t then r := m\n\t\t else l := m\n\t\tdone;\n\t\tres := Int64.add !res (Int64.of_int (!r - c.(hash)));\n\t\tlet hash = b.(!r) in\n(*Printf.printf \"add %d %d %d %d\\n\" id hash !l !r;*)\n\t\t(*while a.(!j) >= 0 do\n\t\t j := (!j + m) mod h;\n\t\t incr res;\n\t\tdone;*)\n\t\t Hashtbl.replace ht id hash;\n\t\t a.(hash) <- id;\n\t\t fenwick_modify ft c.(hash) 1;\n\t\t fenwick_modify ft (c.(hash) + h / g) 1;\n\t | \"-\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Hashtbl.find ht id in\n\t\tHashtbl.remove ht id;\n\t\ta.(hash) <- -1;\n\t\tfenwick_modify ft c.(hash) (-1);\n\t\tfenwick_modify ft (c.(hash) + h / g) (-1);\n\t | _ -> assert false\n done;\n Printf.printf \"%Ld\\n\" !res;\n"}, {"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet g2d n = n land (-n)\n\nlet fenwick_new n =\n Array.make n 0\n\nlet fenwick_modify ft n x =\n let i = ref (n + 1) in\n while !i <= Array.length ft do\n ft.(!i - 1) <- ft.(!i - 1) + x;\n i := !i + g2d !i;\n done\n\nlet fenwick_count ft n =\n let i = ref (n + 1) in\n let res = ref 0 in\n while !i > 0 do\n res := !res + ft.(!i - 1);\n i := !i - g2d !i;\n done;\n !res\n\nlet fenwick_count2 ft m n =\n fenwick_count ft n - fenwick_count ft (m - 1)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make h (-1) in\n let b = Array.make (2 * h) (-1) in\n let c = Array.make h (-1) in\n let g = gcd m h in\n let () =\n let pos = ref 0 in\n for i = 0 to h - 1 do\n\tif c.(i) < 0 then (\n\t let k = ref i in\n\t for j = 0 to h / g - 1 do\n\t c.(!k) <- !pos;\n\t b.(!pos) <- !k;\n\t b.(!pos + h / g) <- !k;\n\t incr pos;\n\t k := (!k + m) mod h;\n\t done;\n\t pos := !pos + h / g;\n\t)\n done\n in\n let ft = fenwick_new (2 * h) in\n let ht = Hashtbl.create h in\n let res = ref 0L in\n for i = 0 to n - 1 do\n let op = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tmatch op with\n\t | \"+\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let l = ref (c.(hash) - 1) in\n\t let r = ref (c.(hash) + h / g) in\n\t\twhile !l < !r - 1 do\n\t\t let m = (!l + !r) / 2 in\n(*Printf.printf \"step %d %d %d %d\\n\" !l !r m (fenwick_count2 ft c.(hash) m);*)\n\t\t if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)\n\t\t then r := m\n\t\t else l := m\n\t\tdone;\n\t\tres := Int64.add !res (Int64.of_int (!r - c.(hash)));\n\t\tlet hash = b.(!r) in\n(*Printf.printf \"add %d %d %d %d\\n\" id hash !l !r;*)\n\t\t(*while a.(!j) >= 0 do\n\t\t j := (!j + m) mod h;\n\t\t incr res;\n\t\tdone;*)\n\t\t Hashtbl.replace ht id hash;\n\t\t a.(hash) <- id;\n\t\t fenwick_modify ft c.(hash) 1;\n\t\t fenwick_modify ft (c.(hash) + h / g) 1;\n\t | \"-\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Hashtbl.find ht id in\n\t\tHashtbl.remove ht id;\n\t\ta.(hash) <- -1;\n\t\tfenwick_modify ft c.(hash) (-1);\n\t\tfenwick_modify ft (c.(hash) + h / g) (-1);\n\t | _ -> assert false\n done;\n Printf.printf \"%Ld\\n\" !res;\n"}], "negative_code": [{"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet g2d n = n land (-n)\n\nlet fenwick_new n =\n Array.make n 0\n\nlet fenwick_modify ft n x =\n let i = ref (n + 1) in\n while !i <= Array.length ft do\n ft.(!i - 1) <- ft.(!i - 1) + x;\n i := !i + g2d !i;\n done\n\nlet fenwick_count ft n =\n let i = ref (n + 1) in\n let res = ref 0 in\n while !i > 0 do\n res := !res + ft.(!i - 1);\n i := !i - g2d !i;\n done;\n !res\n\nlet fenwick_count2 ft m n =\n fenwick_count ft n - fenwick_count ft (m - 1)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make h (-1) in\n let b = Array.make (2 * h) (-1) in\n let c = Array.make h (-1) in\n let g = gcd m h in\n let () =\n let pos = ref 0 in\n for i = 0 to h - 1 do\n\tif c.(i) < 0 then (\n\t for j = 0 to h / g - 1 do\n\t c.((i + j * m) mod h) <- !pos;\n\t b.(!pos) <- (i + j * m) mod h;\n\t b.(!pos + h / g) <- (i + j * m) mod h;\n\t incr pos\n\t done;\n\t pos := !pos + h / g;\n\t)\n done\n in\n let ft = fenwick_new (2 * h) in\n let ht = Hashtbl.create h in\n let res = ref 0 in\n for i = 0 to n - 1 do\n let op = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tmatch op with\n\t | \"+\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let l = ref (c.(hash) - 1) in\n\t let r = ref (c.(hash) + h / g) in\n\t\twhile !l < !r - 1 do\n\t\t let m = (!l + !r) / 2 in\n(*Printf.printf \"step %d %d %d %d\\n\" !l !r m (fenwick_count2 ft c.(hash) m);*)\n\t\t if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)\n\t\t then r := m\n\t\t else l := m\n\t\tdone;\n\t\tres := !res + !r - c.(hash);\n\t\tlet hash = b.(!r) in\n(*Printf.printf \"add %d %d %d %d\\n\" id hash !l !r;*)\n\t\t(*while a.(!j) >= 0 do\n\t\t j := (!j + m) mod h;\n\t\t incr res;\n\t\tdone;*)\n\t\t Hashtbl.replace ht id hash;\n\t\t a.(hash) <- id;\n\t\t fenwick_modify ft c.(hash) 1;\n\t\t fenwick_modify ft (c.(hash) + h / g) 1;\n\t | \"-\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Hashtbl.find ht id in\n\t\tHashtbl.remove ht id;\n\t\ta.(hash) <- -1;\n\t\tfenwick_modify ft c.(hash) (-1);\n\t\tfenwick_modify ft (c.(hash) + h / g) (-1);\n\t | _ -> assert false\n done;\n Printf.printf \"%d\\n\" !res;\n"}, {"source_code": "let rec gcd a b =\n if b = 0\n then a\n else gcd b (a mod b)\n\nlet g2d n = n land (-n)\n\nlet fenwick_new n =\n Array.make n 0\n\nlet fenwick_modify ft n x =\n let i = ref (n + 1) in\n while !i <= Array.length ft do\n ft.(!i - 1) <- ft.(!i - 1) + x;\n i := !i + g2d !i;\n done\n\nlet fenwick_count ft n =\n let i = ref (n + 1) in\n let res = ref 0 in\n while !i > 0 do\n res := !res + ft.(!i - 1);\n i := !i - g2d !i;\n done;\n !res\n\nlet fenwick_count2 ft m n =\n fenwick_count ft n - fenwick_count ft (m - 1)\n\nlet _ =\n let sb = Scanf.Scanning.stdib in\n let h = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make h (-1) in\n let b = Array.make (2 * h) (-1) in\n let c = Array.make h (-1) in\n let g = gcd m h in\n let () =\n let pos = ref 0 in\n for i = 0 to h - 1 do\n\tif c.(i) < 0 then (\n\t for j = 0 to h / g - 1 do\n\t c.((i + j * m) mod h) <- !pos;\n\t b.(!pos) <- (i + j * m) mod h;\n\t b.(!pos + h / g) <- (i + j * m) mod h;\n\t incr pos\n\t done;\n\t pos := !pos + h / g;\n\t)\n done\n in\n let ft = fenwick_new (2 * h) in\n let ht = Hashtbl.create h in\n let res = ref 0 in\n for i = 0 to n - 1 do\n let op = Scanf.bscanf sb \"%s \" (fun s -> s) in\n\tmatch op with\n\t | \"+\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let l = ref (c.(hash) - 1) in\n\t let r = ref (c.(hash) + h / g) in\n\t\twhile !l < !r - 1 do\n\t\t let m = (!l + !r) / 2 in\n(*Printf.printf \"step %d %d %d %d\\n\" !l !r m (fenwick_count2 ft c.(hash) m);*)\n\t\t if fenwick_count2 ft c.(hash) m < m + 1 - c.(hash)\n\t\t then r := m\n\t\t else l := m\n\t\tdone;\n\t\tres := !res + !r - c.(hash);\n\t\tlet hash = b.(!r) in\n(*Printf.printf \"add %d %d %d %d\\n\" id hash !l !r;*)\n\t\t(*while a.(!j) >= 0 do\n\t\t j := (!j + m) mod h;\n\t\t incr res;\n\t\tdone;*)\n\t\t Hashtbl.replace ht id hash;\n\t\t a.(hash) <- id;\n\t\t fenwick_modify ft !r 1;\n\t\t fenwick_modify ft (!r + h / g) 1;\n\t | \"-\" ->\n\t let id = Scanf.bscanf sb \"%d \" (fun s -> s) in\n\t let hash = Hashtbl.find ht id in\n\t\tHashtbl.remove ht id;\n\t\ta.(hash) <- -1;\n\t\tfenwick_modify ft c.(hash) (-1);\n\t\tfenwick_modify ft (c.(hash) + h / g) (-1);\n\t | _ -> assert false\n done;\n Printf.printf \"%d\\n\" !res;\n"}], "src_uid": "7bf9c0e67312a7768ae89c42edb4a2de"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand m = read_int () in\n\n\tlet tab = Array.make n 0\n\tand uzyte = Array.make 100007 false \n\tand dp = Array.make (n + 1) 0 in\n\n\tfor i = 0 to n - 1 do\n\t\ttab.(i) <- read_int ()\n\tdone;\n\n\tfor i = n - 1 downto 0 do \n\t\tif uzyte.(tab.(i)) = false then\n\t\t\tdp.(i) <- dp.(i + 1) + 1\n\t\telse\n\t\t\tdp.(i) <- dp.(i + 1);\n\n\t\tuzyte.(tab.(i)) <- true;\n\tdone;\n\n\tfor i = 1 to m do\n\t\tlet a = read_int () in\n\t\tprintf \"%d\\n\" dp.(a - 1);\n\tdone;", "positive_code": [{"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () = \n let n = read () in\n let m = read () in\n let arr = Array.init n (fun n -> read ()) in\n let list = list_init m (fun n -> read ()) in\n (n, arr, list)\n\nlet count_duplicates n arr = \n let seen = Array.make 100001 0 in\n let dup_count = Array.make n 0 in \n let rec loop i count = \n if i >= 0\n then\n let a = arr.(i) in\n if seen.(a) = 0\n then\n (seen.(a) <- 1;\n dup_count.(i) <- count;\n loop (i - 1) count)\n else\n (dup_count.(i) <- count + 1;\n loop (i - 1) (count + 1))\n else\n dup_count\n in loop (n - 1) 0\n\nlet count_uniques arr i n list = \n let a = n - i - arr.(i) in\n (a :: list)\n\nlet solve (n, arr, list) = \n let dups = count_duplicates n arr in\n let rec loop rest uniqs = \n match rest with\n | (i :: tl) -> loop tl (count_uniques dups (i - 1) n uniqs)\n | [] -> List.rev uniqs\n in loop list []\n\nlet print list = List.iter (Printf.printf \"%d\\n\") list\n\nlet () = print (solve (input ()))\n"}, {"source_code": "let read () = Scanf.scanf \"%d \" (fun n -> n)\n\nlet list_init n f =\n let rec loop i list = \n if i < n\n then\n let element = f(i) in\n loop (i + 1) (element :: list)\n else\n List.rev list\n in loop 0 []\n\nlet input () = \n let n = read () in\n let m = read () in\n let arr = Array.init n (fun n -> read ()) in\n let list = list_init m (fun n -> read ()) in\n (n, arr, list)\n\nlet count_uniqs n arr = \n let seen = Array.make 100001 0 in\n let uniq_count = Array.make n 0 in \n let rec loop i count = \n if i >= 0\n then\n let a = arr.(i) in\n if seen.(a) = 0\n then\n (seen.(a) <- 1;\n uniq_count.(i) <- count + 1;\n loop (i - 1) (count + 1))\n else\n (uniq_count.(i) <- count;\n loop (i - 1) count)\n else\n uniq_count\n in loop (n - 1) 0\n\nlet solve (n, arr, list) = \n let uniqs = count_uniqs n arr in\n List.map (fun i -> uniqs.(i - 1)) list\n\nlet print list = List.iter (Printf.printf \"%d\\n\") list\n\nlet () = print (solve (input ()))\n"}, {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n\tlet n = read_int ()\n\tand m = read_int () in\n\tlet a = Array.init n read_int in\n\n\tlet vis = Array.make 100001 false\n\tand suf = Array.make (n + 1) 0 in\n\n\tfor i = n - 1 downto 0 do\n\t\tlet x = a.(i) in\n\t\tsuf.(i) <- suf.(i + 1);\n\t\tif not vis.(x) then suf.(i) <- suf.(i) + 1;\n\t\tvis.(x) <- true\n\tdone;\n\tfor i = 1 to m do\n\t\tlet l = read_int () in\n\t\tprintf \"%d\\n\" suf.(l - 1)\n\tdone"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x) in\n\nlet n = read_int() and m = read_int() in\nlet a = Array.init n (fun _ -> read_int()) in\nlet e = Array.init 100001 (fun _ -> false) in\nlet b = Array.make n 0 in\n\nb.(n-1) <- 1;\ne.(a.(n-1)) <- true;\n\nfor i = n-2 downto 0 do\n b.(i) <- b.(i+1);\n if not e.(a.(i)) then\n begin\n e.(a.(i)) <- true;\n b.(i) <- b.(i) + 1;\n end\ndone;\n\nfor i = 1 to m do\n let l = read_int() in\n Printf.printf \"%d\\n\" b.(l-1);\ndone;"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\\n\" x;;\n\nlet () =\n let n = read_int() in\n let m = read_int() in\n let a = Array.init n read_int in\n let dp = Array.make n 0 in\n let check = Array.make 100000 0 in\n check.(a.(n-1) - 1) <- 1;\n dp.(n-1) <- 1; \n let rec loop = function \n | k -> (if check.(a.(k)-1) = 0 \n then\n (check.(a.(k)-1) <- 1;\n dp.(k) <- dp.(k+1) + 1)\n else \n dp.(k) <- dp.(k+1));\n if k > 0 then loop (k-1);\n in\n let rec loop2 = function\n | k when k = m -> ()\n | k -> let t = read_int 0 in \n print_int dp.(t-1); loop2 (k+1) in \n if n > 1 then loop (n-2);\n loop2 0;;\n"}], "negative_code": [], "src_uid": "1e156dfc65ef88f19ca1833f75192259"} {"source_code": "open Array;;\n \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 a = readInStr () in\n let b = readIntLn () in\n let h = init n (fun i -> readInStr()) in\n fast_sort(-)h;\n h.(b) - h.(b-1) |> print_int\n ;;\nmain()", "positive_code": [{"source_code": "open Array;;\n \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 a = readInStr () in\n let b = readIntLn () in\n let h = init n (fun i -> readInStr()) in\n fast_sort(-)h;\n if b <= n-1\n then h.(b) - h.(b-1) |> print_int\n else print_int 1\n ;;\nmain()"}], "negative_code": [], "src_uid": "d3c8c1e32dcf4286bef19e9f2b79c8bd"} {"source_code": "let xint _ = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () = \n let n = xint () in\n let sum = ref 0 in\n for i = 1 to n do\n let x1 = xint () in\n let y1 = xint () in\n let x2 = xint () in\n let y2 = xint () in\n sum := !sum + (x2 - x1 + 1) * (y2 - y1 + 1);\n done;\n print_int !sum\n", "positive_code": [{"source_code": "let () =\n\tlet n = Scanf.scanf \"%d\" (fun i -> i) and res = ref 0 in\n\t\tfor i=1 to n do\n\t\t\tScanf.scanf \" %d %d %d %d\" (fun i j k l -> res := !res + (k-i+1)*(l-j+1));\n\t\tdone;\n\tPrintf.printf \"%d\" !res\n"}], "negative_code": [], "src_uid": "ca5c44093b1ab7c01970d83b5f49d0c6"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int () = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_pair () = let u = read_int() in (u,read_int())\nlet () = \n let n = read_int () in\n let tree = Array.make n [] in\n \n for i=0 to n-2 do \n let u = (read_int()) -1 in\n let v = (read_int()) -1 in\n tree.(u) <- v::tree.(u);\n tree.(v) <- u::tree.(v);\n done;\n\n let init = Array.init n (fun _ -> read_int()) in\n \n for i=0 to n-1 do\n let b = read_int () in\n init.(i) <- init.(i) lxor b\n done;\n\n let parent = Array.make n (-1) in\n\n let rec dfs u p = \n List.iter (fun v -> \n if v <> p then (\n\tparent.(v) <- u;\n\tdfs v u\n )\n ) tree.(u)\n in\n\n dfs 0 (-1);\n\n let rec loop i ac = if i=n then ac else\n let condadd bit = if bit=0 then ac else i::ac in\n if parent.(i) < 0 || parent.(parent.(i)) < 0 then loop (i+1) (condadd init.(i))\n else loop (i+1) (condadd (init.(i) lxor init.(parent.(parent.(i)))))\n in\n\n let li = loop 0 [] in\n printf \"%d\\n\" (List.length li);\n List.iter (fun i -> printf \"%d\\n\" (i+1)) (loop 0 [])\n", "positive_code": [{"source_code": "(* compiled on 64-bit system with ocamlopt -pp camlp4o $file *)\n\nopen Printf\nopen Scanf\nopen Array\n\nmodule S = String\nmodule Q = Queue\nmodule T = Stack\nmodule H = Hashtbl\nmodule L = List\n\n(* misc *)\nlet neg_compare x y = - compare x y\nlet min3 a b c = min a (min b c)\nlet mid3 a b c = if a < b then max a (min b c) else max b (min a c) \nlet max3 a b c = max a (max b c)\nlet min4 a b c d = min (min a b) (min c d)\nlet max4 a b c d = max (max a b) (max c d)\nlet itb a = a <> 0\nlet bti b = if b then 1 else 0\nlet rec bsearch_min a b test =\n if b - a = 1 then b else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_min a mid test else \n bsearch_min mid b test\nlet rec bsearch_max a b test = \n if b - a = 1 then a else \n let mid = (a-b)/2 + b in \n if test mid then bsearch_max mid b test else \n bsearch_max a mid test\n(* int *)\nlet sqrt_floor n = bsearch_max 0 (1 lsl 31) (fun i -> i*i <= n)\nlet sqrt_ceil n = bsearch_min (-1) (1 lsl 31) (fun i -> n <= i*i) \n(* float *)\nlet round f = truncate (f +. 0.5)\nlet inv_float f = 1. /. f\n(* functional *)\nlet id x = x\nlet const x _ = x\nlet (|>) x f = f x\nlet (^>) x f = f x\nlet (@@) a b = a b \nlet on g f a b = g (f a) (f b)\nlet rec fix f = f (fun x -> fix f x)\nlet ift cond a = if cond then a\nlet ifte cond a b = if cond then a else b\nlet rec for_ i len c f = if i = len then c else for_ (i+1) len (f i c) f\n(* predicate *)\nlet is_odd x = x land 1 = 1\nlet is_even x = x land 1 = 0\n(* option *)\nlet is_none = function | Some _ -> false | None -> true\nlet is_some = function | Some _ -> true | None -> false\nlet default x = function Some y -> y | None -> x\n(* ref *)\nlet (+=) a b = a := !a + b\nlet (-=) a b = a := !a - b \nlet ( *= ) a b = a := !a * b\nlet assign_min x y = x := min !x y \nlet assign_max x y = x := max !x y\n(* array *) \nlet set_min x i v = x.(i) <- min x.(i) v \nlet set_max x i v = x.(i) <- max x.(i) v \nlet swap arr i j = let t = arr.(i) in arr.(i) <- arr.(j); arr.(j) <- t \n(* int, int *)\nlet (+:) (a,b) (c,d) = (a+c,b+d)\nlet (-:) (a,b) (c,d) = (a-c,b-d)\n(* number theory *)\nlet sieve_under len = (* len > 0 *)\n let sieve = Array.make len true in \n Array.fill sieve 0 (min len 2) false;\n let rec erase i k = if i >= len then () else (sieve.(i) <- false; erase (i+k) k) in \n for i = 2 to sqrt_floor len do if sieve.(i) then erase (2*i) i done;\n sieve\n(* Arithmetic *)\nlet negate x = -x\nlet rec factorial n = if n = 0 then 1 else n * factorial (n-1)\nlet rec gcd a b = if b = 0 then a else gcd b (a mod b)\nlet rec extgcd a b = \n if b = 0 then 1,0,a else\n let x,y,g = extgcd b (a mod b) in \n y,x-(a/b)*y,g\nlet rec pow x n = if n = 0 then 1 else\n let n' = n/2 in\n let p = pow x n' in\n if is_odd n then x*p*p else p*p\nlet rec modpow m x n = \n if n = 0 then 1 else \n let n' = n/2 in\n let p = modpow m x n' in \n if is_even n then (p*p mod m) else\n (x*(p*p mod m) mod m) \nlet modinv m i = let _,x,_ = extgcd m i in x\n(* IO *)\nlet is_digit c =\n let i = int_of_char c in\n 48 <= i && i < 58\nlet is_space c = c = ' ' || c = '\\n' || c = '\\t' || c = '\\r' \nlet read_char () = try input_char stdin with End_of_file -> '\\000'\nlet rec read_letter () = \n let c = read_char() in \n if is_space c then read_letter() else c \nlet read_int () = \n let digit c = int_of_char c - 48 in\n let rec read n = \n let c = read_char() in \n if is_digit c then read (10*n + (digit c)) else \n n \n in\n let rec run c = \n if is_digit c then read (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -read (digit c) else run c \n end else \n if c = '\\000' then 0 else \n run (read_char())\n in \n run (read_char())\nlet read_float () = \n let digit c = float (int_of_char c - 48) in\n let rec read_decimial m f = \n let c = read_char () in \n if is_digit c then read_decimial (m /. 10.) (f +. m *. digit c) else f\n in \n let rec read_integral n = \n let c = read_char () in \n if is_digit c then read_integral (10. *. n +. digit c) else \n if c = '.' then n +. read_decimial 0.1 0.0 else \n n \n in \n let rec run c = begin \n if is_digit c then read_integral (digit c) else \n if c = '-' then begin \n let c = read_char() in \n if is_digit c then -. read_integral (digit c) else \n run c \n end else \n if c = '.' then read_decimial 0.1 0.0 else \n if c = '\\000' then 0.0 else \n run (read_char())\n end in \n run (read_char())\nlet read_word () = \n let open Buffer in \n let buf = create 128 in \n let rec read c = \n if is_space c || c = '\\000' then contents buf else begin \n add_char buf c; \n read (read_char())\n end \n in\n let rec run c = \n if is_space c then run (read_char()) else \n if c = '\\000' then \"\" else \n read c \n in \n run (read_char())\nlet read_line () = \n let open Buffer in \n let buf = create (4*1024) in \n let rec run c = \n if c = '\\n' || c = '\\000' then contents buf else begin \n add_char buf c;\n run (read_char())\n end \n in\n run (read_char()) \nlet newline () = print_newline()\nlet print_tuple s (x,y) = printf s x y \nlet print_array s arr = Array.iter (printf s) arr; print_newline()\nlet print_matrix s mat = Array.iter (print_array s) mat\nlet print_list s lis = List.iter (printf s) lis; print_newline()\n;;\n\nlet _ = \n let len = read_int() in \n let graph = make len [] in \n for i = 0 to len-2 do \n let a = read_int() - 1 in\n let b = read_int() - 1 in \n graph.(a) <- b :: graph.(a);\n graph.(b) <- a :: graph.(b)\n done;\n let ini = init len (fun i -> read_int() ) in \n let goal = init len (fun i -> read_int() ) in \n\n let cnt = ref [] in \n let rec dfs lv odd even p i = \n let curr = if is_odd lv then (ini.(i) lxor odd) else (ini.(i) lxor even) in \n if curr <> goal.(i) then begin \n cnt := i :: !cnt;\n let odd = if is_odd lv then odd lxor 1 else odd in \n let even = if is_even lv then even lxor 1 else even in \n L.iter (fun j -> if j <> p then dfs (lv+1) odd even i j) graph.(i) \n end else \n L.iter (fun j -> if j <> p then dfs (lv+1) odd even i j) graph.(i) \n in \n dfs 0 0 0 (-1) 0;\n printf \"%d\\n\" (L.length !cnt);\n L.iter (fun i -> printf \"%d\\n\" (i+1)) !cnt\n"}], "negative_code": [], "src_uid": "f3a27e4dc3085712608ecf844e663dfd"} {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nmodule DisJoint: sig\n\n type 'a t\n val create : 'a -> 'a t\n val get : 'a t -> 'a\n val set : 'a t -> 'a -> unit\n val same : 'a t -> 'a t -> bool\n val union : 'a t -> 'a t -> unit\n\nend = struct\n\n type 'a root = {\n mutable value: 'a;\n mutable rank: int;\n }\n\n type 'a t = { mutable parent : 'a parent; }\n and 'a parent =\n | Parent of 'a t\n | Root of 'a root\n\n let create v =\n { parent = Root { value = v; rank = 0; }; }\n\n let compress t =\n let rec loop t ac =\n match t.parent with\n | Root _ ->\n let p = Parent t in\n List.iter (fun t -> t.parent <- p) ac;\n | Parent t' -> loop t' (t :: ac)\n in loop t []\n\n let find t =\n compress t;\n match t.parent with\n | Root r -> (t, r)\n | Parent t ->\n match t.parent with\n | Root r -> (t, r)\n | Parent _ -> assert false\n\n let root t =\n snd (find t)\n\n let get t =\n (root t).value\n\n let set t v =\n (root t).value <- v\n\n let same t1 t2 =\n (root t1) == (root t2)\n\n let union t1 t2 =\n let (t1, r1) = find t1 in\n let (t2, r2) = find t2 in\n if r1 == r2 then ()\n else\n if r1.rank < r2.rank then\n t1.parent <- Parent t2\n else\n (t2.parent <- Parent t1;\n if r1.rank = r2.rank then\n r1.rank <- r1.rank + 1)\n\nend\n\n\nlet (n, input) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet _ =\n let ct = ref 0 in\n let u = Array.init (n + 1) (fun i -> DisJoint.create i) in\n input |> Array.iter (fun (a, b) ->\n if not (DisJoint.same u.(a) u.(b)) then\n DisJoint.union u.(a) u.(b)\n else\n u |> Array.map (fun b -> if DisJoint.same u.(a) b then 1 else 0)\n |> Array.fold_left (+) 0\n |> (fun c -> if c mod 2 = 1 then incr ct));\n\n printf \"%d\"\n (if (n - !ct) mod 2 = 0 then !ct else !ct + 1)\n", "positive_code": [{"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nlet (n, arr) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet ct = ref 0\n\nlet rec merge (a, b, len) = function\n | [] -> []\n | (a2, b2, len2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n if (len + len2) mod 2 = 1 then\n (incr ct; xs)\n else\n xs\n else\n if a2 = a then (b, b2, len + len2) :: xs else\n if a2 = b then (a, b2, len + len2) :: xs else\n if b2 = a then (a2, b, len + len2) :: xs else\n if b2 = b then (a, a2, len + len2) :: xs else\n (a2, b2, len2) :: merge (a, b, len) xs\n\nlet rec process = function\n | [] -> printf \"%d\" (if (n + !ct) mod 2 = 0 then !ct else !ct + 1)\n | x :: xs -> process (merge x xs)\n\nlet _ = process\n (arr |> Array.to_list\n |> List.map (fun (a, b) -> (a, b, 1)))\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nlet (n, arr) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet ct = ref 0\n\nlet rec merge (a, b, len) = function\n | [] -> []\n | (a2, b2, len2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n if (len + len2) mod 2 = 1 then\n (incr ct; xs)\n else\n xs\n else\n if a2 = a then (b, b2, len + len2) :: xs else\n if a2 = b then (a, b2, len + len2) :: xs else\n if b2 = a then (a2, b, len + len2) :: xs else\n if b2 = b then (a, a2, len + len2) :: xs else\n (a2, b2, len2) :: merge (a, b, len) xs\n\nlet rec process = function\n | [] -> printf \"%d\" (match (n mod 2, !ct mod 2) with\n | (0, 0) -> !ct\n | (0, 1) -> !ct + 1\n | (1, 0) -> !ct + 1\n | (1, 1) -> !ct)\n | x :: xs -> process (merge x xs)\n\nlet _ = process\n (arr |> Array.to_list\n |> List.map (fun (a, b) -> (a, b, 1)))\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nmodule DisJoint: sig\n\n type 'a t\n val create : 'a -> 'a t\n val get : 'a t -> 'a\n val set : 'a t -> 'a -> unit\n val same : 'a t -> 'a t -> bool\n val union : 'a t -> 'a t -> unit\n\nend = struct\n\n type 'a root = {\n mutable value: 'a;\n mutable rank: int;\n }\n\n type 'a t = { mutable parent : 'a parent; }\n and 'a parent =\n | Parent of 'a t\n | Root of 'a root\n\n let create v =\n { parent = Root { value = v; rank = 0; }; }\n\n let compress t =\n let rec loop t ac =\n match t.parent with\n | Root _ ->\n let p = Parent t in\n List.iter (fun t -> t.parent <- p) ac;\n | Parent t' -> loop t' (t :: ac)\n in loop t []\n\n let find t =\n compress t;\n match t.parent with\n | Root r -> (t, r)\n | Parent t ->\n match t.parent with\n | Root r -> (t, r)\n | Parent _ -> assert false\n\n let root t =\n snd (find t)\n\n let get t =\n (root t).value\n\n let set t v =\n (root t).value <- v\n\n let same t1 t2 =\n (root t1) == (root t2)\n\n let union t1 t2 =\n let (t1, r1) = find t1 in\n let (t2, r2) = find t2 in\n if r1 == r2 then ()\n else\n if r1.rank < r2.rank then\n t1.parent <- Parent t2\n else\n (t2.parent <- Parent t1;\n if r1.rank = r2.rank then\n r1.rank <- r1.rank + 1)\n\nend\n\n\nlet (n, input) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet _ =\n let ct = ref 0 in\n let u = Array.init (n + 1) (fun i -> DisJoint.create i) in\n input |> Array.iter (fun (a, b) ->\n if DisJoint.same u.(a) u.(b) then\n (let c = u |> Array.map (fun b -> if DisJoint.same u.(a) b then 1 else 0)\n |> Array.fold_left (+) 0 in\n if c mod 2 = 1 then incr ct)\n else\n DisJoint.union u.(a) u.(b));\n\n printf \"%d\"\n (if (n - !ct) mod 2 = 0 then !ct else !ct + 1)\n"}], "negative_code": [{"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nlet (n, arr) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet ct = ref 0\n\nlet rec merge (a, b, len) = function\n | [] -> []\n | (a2, b2, len2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n if (len + len2) mod 2 = 1 then\n (incr ct; xs)\n else\n xs\n else\n if a2 = a then (b, b2, len + len2) :: xs else\n if a2 = b then (a, b2, len + len2) :: xs else\n if b2 = a then (a2, b, len + len2) :: xs else\n if b2 = b then (a, a2, len + len2) :: xs else\n (a2, b2, len2) :: merge (a, b, len) xs\n\nlet rec process = function\n | [] -> printf \"%d\" (if n mod 2 = 1 && !ct mod 2 = 0 then !ct + 1 else !ct)\n | x :: xs -> process (merge x xs)\n\nlet _ = process\n (arr |> Array.to_list\n |> List.map (fun (a, b) -> (a, b, 1)))\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nmodule DisJoint: sig\n\n type 'a t\n val create : 'a -> 'a t\n val get : 'a t -> 'a\n val set : 'a t -> 'a -> unit\n val same : 'a t -> 'a t -> bool\n val union : 'a t -> 'a t -> unit\n\nend = struct\n\n type 'a root = {\n mutable value: 'a;\n mutable rank: int;\n }\n\n type 'a t = { mutable parent : 'a parent; }\n and 'a parent =\n | Parent of 'a t\n | Root of 'a root\n\n let create v =\n { parent = Root { value = v; rank = 0; }; }\n\n let compress t =\n let rec loop t ac =\n match t.parent with\n | Root _ ->\n let p = Parent t in\n List.iter (fun t -> t.parent <- p) ac;\n | Parent t' -> loop t' (t :: ac)\n in loop t []\n\n let find t =\n compress t;\n match t.parent with\n | Root r -> (t, r)\n | Parent t ->\n match t.parent with\n | Root r -> (t, r)\n | Parent _ -> assert false\n\n let root t =\n snd (find t)\n\n let get t =\n (root t).value\n\n let set t v =\n (root t).value <- v\n\n let same t1 t2 =\n (root t1) == (root t2)\n\n let union t1 t2 =\n let (t1, r1) = find t1 in\n let (t2, r2) = find t2 in\n if r1 == r2 then ()\n else\n if r1.rank < r2.rank then\n t1.parent <- Parent t2\n else\n (t2.parent <- Parent t1;\n if r1.rank = r2.rank then\n r1.rank <- r1.rank + 1)\n\nend\n\n\nlet (n, input) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet _ =\n let ct = ref 0 in\n let u = Array.init (n + 1) (fun i -> DisJoint.create i) in\n input |> Array.iter (fun (a, b) ->\n if DisJoint.same u.(a) u.(b) then incr ct else\n DisJoint.union u.(a) u.(b));\n\n printf \"%d\"\n (if (n - !ct) mod 2 = 0 then !ct else !ct + 1)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (n, arr) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet ct = ref 0\n\nlet rec merge (a, b) = function\n | [] -> []\n | (a2, b2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n (incr ct; xs)\n else\n if a2 = a then (b, b2) :: xs else\n if a2 = b then (a, b2) :: xs else\n if b2 = a then (a2, b) :: xs else\n if b2 = b then (a, a2) :: xs else\n (a2, b2) :: merge (a, b) xs\n\nlet rec process = function\n | [] -> printf \"%d\" (if n mod 2 = 1 && !ct mod 2 = 0 then !ct + 1 else !ct)\n | x :: xs -> process (merge x xs)\n\nlet _ = process (Array.to_list arr)\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet (|>) f x = x f\n\n\nlet (n, arr) =\n bscanf Scanning.stdib \"%d %d \" (fun n m ->\n (n, Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b)))))\n\nlet ct = ref 0\n\nlet rec merge (a, b, len) = function\n | [] -> []\n | (a2, b2, len2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n if (len + len2) mod 2 = 1 then\n (incr ct; xs)\n else\n xs\n else\n if a2 = a then (b, b2, len + len2) :: xs else\n if a2 = b then (a, b2, len + len2) :: xs else\n if b2 = a then (a2, b, len + len2) :: xs else\n if b2 = b then (a, a2, len + len2) :: xs else\n (a2, b2, len2) :: merge (a, b, len) xs\n\nlet rec process = function\n | [] -> printf \"%d\" (if n mod 2 = 1 && !ct mod 2 = 0 then !ct + 1 else !ct)\n | x :: xs -> process (merge x xs)\n\nlet _ = process\n (arr |> Array.to_list\n |> List.map (fun (a, b) -> (a, b, 0)))\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\nopen Scanf\nopen Printf\n\n\nlet ct = ref 0\n\nlet rec merge (a, b) = function\n | [] -> []\n | (a2, b2) :: xs ->\n if (a2 = a && b2 = b) || (a2 = b && b2 = a) then\n (incr ct; xs)\n else\n if a2 = a then (b, b2) :: xs else\n if a2 = b then (a, b2) :: xs else\n if b2 = a then (a2, b) :: xs else\n if b2 = b then (a, a2) :: xs else\n (a2, b2) :: merge (a, b) xs\n\nlet rec process = function\n | [] -> printf \"%d\" !ct\n | x :: xs -> process (merge x xs)\n\nlet _ = process\n (Array.to_list\n (bscanf Scanning.stdib \"%d %d \" (fun n m ->\n Array.init m (fun _ ->\n bscanf Scanning.stdib \"%d %d \" (fun a b -> (a, b))))))\n"}], "src_uid": "a0e55bfbdeb3dc550e1f86b9fa7cb06d"} {"source_code": "let list_init n f =\n let rec read n list = \n if n > 0\n then\n let var = f() in\n read (n - 1) (var :: list)\n else\n List.rev list\n in read n []\n\nlet income n = list_init n (fun i -> Scanf.scanf \"%d \" (fun k -> k))\n\nlet input () = \n let days = Scanf.scanf \"%d \" (fun n -> n) in\n income days\n\nlet max a b =\n if a > b\n then\n a\n else\n b\n\nlet find_max list = \n let rec loop list prev count max_seen =\n match list with\n |(head :: tail) -> \n if prev <= head \n then\n let new_count = count + 1 in\n loop tail head new_count (max new_count max_seen)\n else\n loop tail head 1 max_seen\n |[] -> max_seen\n\n in loop list 0 0 0\n\nlet solve list = find_max list\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (solve (input ()))", "positive_code": [{"source_code": "let list_init n f =\n let rec read n list = \n if n > 0\n then\n let var = f() in\n read (n - 1) (var :: list)\n else\n List.rev list\n in read n []\n\nlet income n = list_init n (fun i -> Scanf.scanf \"%d \" (fun k -> k))\n\nlet input () = \n let days = Scanf.scanf \"%d \" (fun n -> n) in\n income days\n\nlet find_max list = \n let rec loop list prev count max_seen =\n match list with\n |(head :: tail) -> \n if prev <= head \n then\n let new_count = count + 1 in\n loop tail head new_count (Pervasives.max new_count max_seen)\n else\n loop tail head 1 max_seen\n |[] -> max_seen\n\n in loop list 0 0 0\n\nlet print result = Printf.printf \"%d\\n\" result\n\nlet () = print (find_max (input ()))"}, {"source_code": "let read_int () = Scanf.scanf \" %d\" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let ans = ref 0 in\n let rec loop acc prev = function\n | 0 -> ()\n | num -> (\n let curr = read_int () in\n if curr >= prev then\n (ans := max !ans (acc + 1);\n loop (acc + 1) curr (num - 1))\n else\n loop 1 curr (num - 1)\n ) in\n loop 0 0 n;\n Printf.printf \"%d\\n\" !ans\n"}, {"source_code": "open Big_int;;\n\nlet rec biggest aux = function\n\t|[a]\t-> aux\n\t| a::b::q -> if compare_big_int a b > -1\n\t\t\tthen biggest (aux + 1) (b::q)\n\t\t\telse max aux (biggest 1 (b::q));;\n\nlet main () =\n\tlet l = ref [] and n = Scanf.scanf \"%d\" (fun i -> i) in\n\t\tfor i=1 to n do\n\t\t\tl := (Scanf.scanf \" %s\" big_int_of_string)::!l;\n\t\tdone;\n\tPrintf.printf \"%d\" (biggest 1 !l);;\n\nmain ();; \n"}, {"source_code": "open Printf\nopen String\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x) ;;\n\nlet a = Array.make n (-1);;\n\nfor i = 0 to n-1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\n a.(i) <- jj\ndone\n\nlet c = Array.make n 1;; (* This is the array counting the number of increasing sequence *)\n\nlet d = ref 1;;\n\n for i = 1 to n-1 do\n begin\n if( a.(i) >= a.(i-1) ) then\n c.(i) <- c.(i-1) + 1;\n if( !d < c.(i) ) then d := c.(i)\n end\n done;;\n\nlet () = print_int !d; print_endline \"\";;\n"}, {"source_code": "let read_int () = Scanf.scanf \" %d \" (fun x -> x);;\nlet () =\n let n = read_int () in\n let a = Array.init n (fun _ -> read_int()) in\n let rec go i prev cnt best =\n if i = n then max cnt best else\n if a.(i) >= prev then go (i+1) a.(i) (cnt+1) best else\n go (i+1) a.(i) 1 (max cnt best)\n in\n Printf.printf \"%d\\n\" (go 0 0 0 0);;\n\n"}, {"source_code": "let n = int_of_string (input_line stdin);;\nlet first = Scanf.scanf \"%d \" (fun v -> v);;\n\nlet rec solve num_remaining last acc best =\n if num_remaining == 0 then (max acc best) else\n let v = Scanf.scanf \"%d \" (fun v -> v) in\n if v >= last then solve (num_remaining - 1) v (acc + 1) best\n else solve (num_remaining - 1) v 1 (max acc best);;\n\nlet ans = solve (n - 1) first 1 0 in\nPrintf.printf \"%d\\n\" ans;"}, {"source_code": "open Printf\nopen List\nopen Pervasives\n\nlet 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(* 2 2 1 3 4 1 *)\nlet rec longest_non_decr_seq seq last count longest = \n match seq with \n | [] -> longest\n | hd::tl -> \n if last > hd then longest_non_decr_seq tl hd 1 (if count > longest then\n count else longest)\n else longest_non_decr_seq tl hd (count + 1) (if (count + 1) > longest then\n (count + 1 ) else longest)\n\nlet get_list_size () = \n int_of_string (read_line ())\n\nlet get_input_list () = \n let in_line = read_line() in\n List.map int_of_string (split_on_char ' ' in_line)\n\nlet () = \n let expected_len = get_list_size () in \n let list = get_input_list () in\n assert (expected_len = List.length list);\n match list with\n | [] -> printf \"0\\n\"\n | hd::_ -> printf \"%d\\n\" (longest_non_decr_seq list hd 0 0)\n \n"}], "negative_code": [{"source_code": "open Printf\nopen Pervasives"}, {"source_code": "open Pervasives\nopen Printf\n\nlet () = printf \"%d\\n\" 3"}, {"source_code": "open Printf\nopen List\nopen Pervasives\n\nlet 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\nlet rec longest_non_decr_seq seq last count longest = \n match seq with \n | [] -> longest\n | hd::tl -> \n if last > hd then longest_non_decr_seq tl hd 0 (if count > longest then\n count else longest)\n else longest_non_decr_seq tl hd (count + 1) (if (count + 1) > longest then\n (count + 1 ) else longest)\n\nlet get_list_size () = \n int_of_string (read_line ())\n\nlet get_input_list () = \n let in_line = read_line() in\n List.map int_of_string (split_on_char ' ' in_line)\n\nlet () = \n let expected_len = get_list_size () in \n let list = get_input_list () in\n assert (expected_len = List.length list);\n printf \"%d\\n\" ((longest_non_decr_seq list 2 0 0) + 1)\n"}, {"source_code": "open Printf\nopen String\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x) ;;\n\nlet a = Array.make n (-1);;\n\nfor i = 0 to n-1 do\n let jj = Scanf.bscanf Scanf.Scanning.stdin \"%d \" (fun x -> x) in\n a.(i) <- jj\ndone\n\nlet c = Array.make n 1;; (* This is the array counting the number of increasing sequence *)\n\nlet d = ref 0;;\n\n for i = 1 to n-1 do\n begin\n if( a.(i) >= a.(i-1) ) then\n c.(i) <- c.(i-1) + 1;\n if( !d < c.(i) ) then d := c.(i)\n end\n done;;\n\nlet () = print_int !d; print_endline \"\";;\n"}], "src_uid": "1312b680d43febdc7898ffb0753a9950"} {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let ans = ref (-1) in\n for i = 1 to n-1 do\n for j = i to n-1 do\n (* representation of a_{i-1}-1 *)\n let p = a.(i-1)-1 |> ref\n and c = ref 1\n and w = ref a.(j) in\n for k = i to j do\n let t = !p / a.(k) in\n c := !c + t;\n w := !w + a.(k) * t;\n p := !p mod a.(k)\n done;\n\n p := !w;\n for k = 0 to n-1 do\n c := !c - !p / a.(k);\n p := !p mod a.(k)\n done;\n if !c < 0 && (!ans < 0 || !w < !ans) then\n ans := !w;\n done\n done;\n Printf.printf \"%d\\n\" !ans\n", "positive_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let ans = ref (-1) in\n for i = 1 to n-1 do\n for j = i to n-1 do\n (* representation of a_{i-1}-1 *)\n let p = a.(i-1)-1 |> ref\n and c = ref 1\n and w = ref a.(j) in\n for k = i to j do\n let t = !p / a.(k) in\n c := !c + t;\n w := !w + a.(k) * t;\n p := !p mod a.(k)\n done;\n\n p := !w;\n for k = 0 to n-1 do\n c := !c - !p / a.(k);\n p := !p mod a.(k)\n done;\n if !c < 0 && (!ans < 0 || !w < !ans) then\n ans := !w;\n done\n done;\n Printf.printf \"%d\\n\" !ans\n"}], "negative_code": [{"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let ans = ref (-1) in\n for i = 1 to n-1 do\n for j = i to n-1 do\n let p = a.(i-1)-1 |> ref\n and c = ref 1\n and w = ref a.(j) in\n for k = i to j do\n let t = !p / a.(k) in\n c := !c + t;\n w := !w + a.(k) * t;\n p := !p mod a.(k)\n done;\n if !p = 0 then (\n p := !w;\n for k = 0 to n-1 do\n c := !c - !p / a.(k);\n p := !p mod a.(k)\n done\n );\n if !c < 0 && (!ans < 0 || !w < !ans) then\n ans := !w;\n done\n done;\n Printf.printf \"%d\\n\" !ans\n"}, {"source_code": "let read_int _ = Scanf.bscanf Scanf.Scanning.stdib \" %d\" (fun x -> x)\nlet (|>) x f = f x\n\nlet () =\n let n = read_int 0 in\n let a = Array.init n read_int in\n let ans = ref (-1) in\n for i = 1 to n-1 do\n for j = i to n-1 do\n let p = a.(i-1)-1 |> ref\n and c = ref 0\n and w = ref a.(j) in\n for k = i to j do\n let t = !p / a.(k) in\n c := !c + t;\n w := !w + a.(k) * t;\n p := !p mod a.(k)\n done;\n if !p = 0 then (\n p := !w;\n for k = 0 to n-1 do\n c := !c - !p / a.(k);\n p := !p mod a.(k)\n done\n );\n if !c < 0 && (!ans < 0 || !w < !ans) then\n ans := !w;\n done\n done;\n Printf.printf \"%d\\n\" !ans\n"}], "src_uid": "c592778fe180234ab007f113f2440393"} {"source_code": "(*********************************************************************************)\n\ntype disk = {\n\ta : int; (* inner radius *)\n\tb : int; (* outer radius *)\n\th : int64; (* dist height *)\n};;\n\n(*********************************************************************************)\n\t\nlet read_disks n =\n\tlet arr = Array.make n {a=0; b=0; h=Int64.zero} in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %d %d %Ld \" (fun a b h -> arr.(k) <- {a=a; b=b; h=h};);\n\t\tdone;\n\t\tarr;\n\tend\n;;\n\n(*********************************************************************************)\n\nlet lower_bound arr n x less =\n\tlet l = ref 0 in\n\tlet r = ref n in\n\tbegin\n\t\twhile !l < !r do\n\t\t\tlet mid = !l + (!r - !l) / 2 in\n\t\t\tif (less arr.(mid) x) then\n\t\t\t\tbegin\n\t\t\t\t\tl := mid + 1;\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tbegin\n\t\t\t\t\tr := mid;\n\t\t\t\tend\n\t\tdone;\n\t\t!r\n\tend\n;;\n\n(*********************************************************************************)\nlet upper_bound arr n x less =\n\tlet l = ref 0 in\n\tlet r = ref n in\n\tbegin\n\t\twhile !l < !r do\n\t\t\tlet mid = !l + (!r - !l) / 2 in\n\t\t\tif (less x arr.(mid)) then\n\t\t\t\tbegin\n\t\t\t\t\tr := mid;\n\t\t\t\tend\n\t\t\telse (* a[mid] <= x *)\n\t\t\t\tbegin\n\t\t\t\t\tl := mid + 1;\n\t\t\t\tend\n\t\tdone;\n\t\t!r\n\tend\n;;\n\n(*********************************************************************************)\n\nlet find_highest_tower arr =\n\t(* precondition: arr is sorted by increasing disk.b *)\n\tlet n = Array.length arr in\n\tlet tw = Array.make n 0 in\n\t(* \n\t\tTowers are arranged according to increase of width and decrease of height.\n\t\tIn essence tower with a smaller width can precede a tower with a greater width only if it is higher.\n\t*)\n\tlet th = Array.make n Int64.zero in \n\tlet m = ref 0 in (* amount of towers to lookup *)\n\tbegin\n\tfor k = 0 to n - 1 do\n\t\tlet d = arr.(k) in\n\t\tlet j = upper_bound tw !m d.a (<) in (* find the tower with width > outer radius of the disk, or return the end of tower list *)\n\t\tlet t = if j < !m then (Int64.add th.(j) d.h) else d.h in\n\t\tlet mm = lower_bound th j t (>) in (* find first tower which is not taller than the new one *)\n\t\tbegin\n\t\t\tm := mm + 1; (* no point to search beyond the widest tower *)\n\t\t\ttw.(mm) <- d.b;\n\t\t\tth.(mm) <- t;\n\t\t\t(*Printf.printf \"j=%d, m=%d, w=%d, h=%Ld\\n\" j !m d.b t;*)\n\t\tend\n\tdone;\n\tth.( 0 )\n\tend\n;;\n\n(*********************************************************************************)\n\nlet cmp_disks d1 d2 =\n\tif d1.b < d2.b then -1\n\telse if d2.b < d1.b then 1\n\telse compare d1.a d2.a\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n\tlet a = read_disks n in\n\tbegin\n\t\tArray.sort cmp_disks a;\n\t\tPrintf.printf \"%Ld\\n\" (find_highest_tower a);\n\tend\n;;\n\n(*********************************************************************************)\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n;;\n\n(*********************************************************************************)\n\nread_input ()\n", "positive_code": [{"source_code": "(*********************************************************************************)\n\ntype disk = {\n\ta : int; (* inner radius *)\n\tb : int; (* outer radius *)\n\th : int64; (* dist height *)\n};;\n\n(*********************************************************************************)\n\t\nlet read_disks n =\n\tlet arr = Array.make n {a=0; b=0; h=Int64.zero} in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %d %d %Ld \" (fun a b h -> arr.(k) <- {a=a; b=b; h=h};);\n\t\tdone;\n\t\tarr;\n\tend\n;;\n\n(*********************************************************************************)\n\nlet find_highest_tower arr =\n\t(* precondition: arr is sorted by increasing disk.b *)\n\tlet n = Array.length arr in\n\tlet s = Array.make n arr.(0) in\n\tlet m = ref 1 in\n\tlet t = ref arr.(0).h in (* highest possible tower containing disk k-1 *)\n\tlet tt = ref !t in (* highest possible tower built from disks from 0 to (k-1) *)\n\tbegin\n\tfor k = 1 to n - 1 do\n\t\tlet d = arr.(k) in\n\t\tbegin\n\t\twhile (!m > 0) && (d.b <= s.(!m - 1).a) do\n\t\t\tbegin\n\t\t\tm := !m - 1;\n\t\t\tt := Int64.sub !t s.(!m).h;\n\t\t\tend\n\t\tdone;\n\t\ts.(!m) <- d;\n\t\tm := !m + 1;\n\t\tt := Int64.add !t d.h;\n\t\ttt := max !tt !t;\n\t\tend\n\tdone;\n\t!tt;\n\tend\n;;\n\n(*********************************************************************************)\n\nlet cmp_disks_desc d1 d2 =\n\tif ( d1.b == d2.b ) then compare d2.a d1.a\n\telse compare d2.b d1.b\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n\tlet a = read_disks n in\n\tbegin\n\t\tArray.sort cmp_disks_desc a;\n\t\tPrintf.printf \"%Ld\\n\" (find_highest_tower a);\n\tend\n;;\n\n(*********************************************************************************)\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n;;\n\n(*********************************************************************************)\n\nread_input ()\n"}], "negative_code": [{"source_code": "(*********************************************************************************)\n\ntype disk = {\n\ta : int; (* inner radius *)\n\tb : int; (* outer radius *)\n\th : int; (* dist height *)\n\tmutable t : int; (* height of tallest tower containing this disk *)\n};;\n\n(*********************************************************************************)\n\nlet print_disks a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tlet d = a.(k) in\n\t\tPrintf.printf \"a=%d; b=%d; h=%d; t=%d;\\n\" d.a d.b d.h d.t;\n\tdone;\n\t(*print_newline ();*)\n;;\n\n(*********************************************************************************)\n\nlet create_disk va vb vh = { a=va; b=vb; h=vh; t=vh };;\n\n(*********************************************************************************)\n\t\nlet read_disks n =\n\tlet arr = Array.make n (create_disk 0 0 0) in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %d %d %d \" (fun a b h -> arr.(k) <- (create_disk a b h););\n\t\tdone;\n\t\tarr;\n\tend\n;;\n\n(*********************************************************************************)\n\nlet find_highest_tower arr =\n\t(* precondition: arr is sorted by increasing disk.b *)\n\tlet n = Array.length arr in\n\tlet tt = ref 0 in (* height of the tallest tower *)\n\tbegin\n\t\tfor k = 0 to n - 1 do (* Invariant k: tt contains height of the tallest tower from arr[0] to arr[k-1] *)\n\t\t\tlet d = arr.(k) in\n\t\t\tlet t = ref 0 in (* height of the tallest tower involving disk d.(k) *)\n\t\t\tbegin\n\t\t\t\t(*\t\n\t\t\t\t*\tWe need to check only the towers ending with the disk of outer radius <= d.b \n\t\t\t\t*\tbecause the towers ending with wider disks cannot be placed on top of disk d.\n\t\t\t\t*\tAll these good towers are to the left of k-th disk because by precondition our array is sorted by disk.b\n\t\t\t\t*\n\t\t\t\t*\tInvariant j: \n\t\t\t\t*\t------------\n\t\t\t\t*\tt is the height of the tallest tower such that it contains some (possibly all or none) \n\t\t\t\t*\tproperly arranged disks in the range (j..k)\n\t\t\t\t*)\n\t\t\t\tfor j=(k-1) downto 0 do \n\t\t\t\t\tlet dd = arr.(j) in\n\t\t\t\t\t(*\n\t\t\t\t\t*\tOnly disks with outer radius greater than arr[k].b can be put on top of k-th disk\n\t\t\t\t\t*)\n\t\t\t\t\tt := if dd.b > d.a then max !t dd.t else !t;\n\t\t\t\tdone;\n\t\t\t\td.t <- (!t + d.h);\n\t\t\t\t(*\n\t\t\t\t\tThe tallest tower from 0-th to k-th is either:\n\t\t\t\t\t1. The tallest one among those containing the k-th disk\n\t\t\t\t\t2. The tallest one among those which do not contain k-th disk\n\t\t\t\t*)\n\t\t\t\ttt := max !tt d.t;\n\t\t\tend\n\t\tdone;\n\n\t\t!tt\n\tend\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n\tlet a = read_disks n in\n\tbegin\n\t\tArray.sort (fun d1 d2 -> compare d1.b d2.b) a;\n\t\tPrintf.printf \"%d\\n\" (find_highest_tower a);\n\tend\n;;\n\n(*********************************************************************************)\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n;;\n\n(*********************************************************************************)\n\nread_input ()\n"}, {"source_code": "(*********************************************************************************)\n\ntype disk = {\n\ta : int; (* inner radius *)\n\tb : int; (* outer radius *)\n\th : int; (* dist height *)\n\tmutable t : int; (* height of tallest tower containing this disk *)\n};;\n\n(*********************************************************************************)\n\nlet print_disks a =\n\tlet n = Array.length a in\n\tfor k = 0 to n - 1 do\n\t\tlet d = a.(k) in\n\t\tPrintf.printf \"a=%d; b=%d; h=%d; t=%d;\\n\" d.a d.b d.h d.t;\n\tdone;\n\t(*print_newline ();*)\n;;\n\n(*********************************************************************************)\n\nlet create_disk va vb vh = { a=va; b=vb; h=vh; t=vh };;\n\n(*********************************************************************************)\n\t\nlet read_disks n =\n\tlet arr = Array.make n (create_disk 0 0 0) in\n\tbegin\n\t\tfor k=0 to (n - 1) do\n\t\t\tScanf.bscanf Scanf.Scanning.stdin \" %d %d %d \" (fun a b h -> arr.(k) <- (create_disk a b h););\n\t\tdone;\n\t\tarr;\n\tend\n;;\n\n(*********************************************************************************)\n\nlet find_highest_tower arr =\n\t(* precondition: arr is sorted by increasing disk.b *)\n\tlet n = Array.length arr in\n\tlet tt = ref 0 in (* height of the tallest tower *)\n\tbegin\n\t\tfor k = 0 to n - 1 do (* Invariant k: tt contains height of the tallest tower from arr[0] to arr[k-1] *)\n\t\t\tlet d = arr.(k) in\n\t\t\tlet t = ref 0 in (* height of the tallest tower involving disk d.(k) *)\n\t\t\tbegin\n\t\t\t\t(*\t\n\t\t\t\t*\tWe need to check only the towers ending with the disk of outer radius <= d.b \n\t\t\t\t*\tbecause the towers ending with wider disks cannot be placed on top of disk d.\n\t\t\t\t*\tAll these good towers are to the left of k-th disk because by precondition our array is sorted by disk.b\n\t\t\t\t*\n\t\t\t\t*\tInvariant j: \n\t\t\t\t*\t------------\n\t\t\t\t*\tt is the height of the tallest tower such that it contains some (possibly all or none) \n\t\t\t\t*\tproperly arranged disks in the range (j..k)\n\t\t\t\t*)\n\t\t\t\tfor j=(k-1) downto 0 do \n\t\t\t\t\tlet dd = arr.(j) in\n\t\t\t\t\t(*\n\t\t\t\t\t*\tOnly disks with outer radius greater than arr[k].b can be put on top of k-th disk\n\t\t\t\t\t*)\n\t\t\t\t\tt := if dd.b > d.a then max !t dd.t else !t;\n\t\t\t\tdone;\n\t\t\t\td.t <- (!t + d.h);\n\t\t\t\t(*\n\t\t\t\t\tThe tallest tower from 0-th to k-th is either:\n\t\t\t\t\t1. The tallest one among those containing the k-th disk\n\t\t\t\t\t2. The tallest one among those which do not contain k-th disk\n\t\t\t\t*)\n\t\t\t\ttt := max !tt d.t;\n\t\t\tend\n\t\tdone;\n\n\t\t!tt\n\tend\n;;\n\n(*********************************************************************************)\n\nlet cmp_disks d1 d2 =\n\tif d1.b < d2.b then -1\n\telse if d2.b < d1.b then 1\n\telse compare d1.a d2.a\n;;\n\n(*********************************************************************************)\n\nlet read_and_process n =\n\tlet a = read_disks n in\n\tbegin\n\t\tArray.sort cmp_disks a;\n\t\tPrintf.printf \"%d\\n\" (find_highest_tower a);\n\tend\n;;\n\n(*********************************************************************************)\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %d \" read_and_process\n;;\n\n(*********************************************************************************)\n\nread_input ()\n"}], "src_uid": "8d0f569359f655f3685c68fb364114a9"} {"source_code": "let input () =\n Scanf.bscanf Scanf.Scanning.stdin \" %s\" (fun x -> x)\n\nlet eat () =\n let s = input ()\n in let len = String.length s\n in if len > 10 then\n Printf.printf \"%c%d%c\\n\" (String.get s 0) (len - 2) (String.get s (len - 1))\n else\n Printf.printf \"%s\\n\" s\n\nlet main () =\n let n = Scanf.bscanf Scanf.Scanning.stdin \" %d\" (fun x -> x)\n in let rec int x =\n if x = 0 then ()\n else (eat (); int (x - 1))\n in int n\n\n;;\nmain ();;\n", "positive_code": [{"source_code": "let next_int ()= \n\tScanf.scanf \" %d\" (function i -> i);;\n\t\nlet next_string ()= \n\tScanf.scanf \" %s\" (function i -> i);;\n\nlet string_of_char c = \n\tString.make 1 c\n;;\n\t\nlet n = next_int();;\n\nlet rec read n =\n\tif n = 0 then [] \n\telse next_string() :: (read (n - 1))\n;;\n\nlet data = read n;;\n\nlet change s = \n\tlet len = String.length s in\n\tif len <= 10 then s\n\telse string_of_char (String.get s 0) ^ (string_of_int (len - 2)) ^ string_of_char (String.get s (len - 1))\n;;\n\nlet ans = List.map change data;;\n\nList.map (function x -> print_endline x) (List.rev ans);;"}, {"source_code": "let n=read_int();;\nfor i=1 to n do\n let str=read_line() in \n let va=String.length(str) in\n if va<=10 then print_endline(str) else print_endline((String.make 1 str.[0])^(string_of_int (va-2))^(String.make 1 str.[va-1]));\ndone;;\n"}, {"source_code": "\nlet abbr s =\n let len = String.length s in\n let head = String.sub s 0 1 in\n let last = String.sub s (len - 1) 1\n in\n if 10 < len then\n head ^ (string_of_int (len - 2)) ^ last\n else\n s\n;;\n\nlet make_list n =\n Array.to_list (Array.init n (fun _ -> read_line ()))\n;;\n\n(* solve :: bytes list -> bytes *)\nlet solve xs =\n String.concat \"\\n\" (List.map abbr xs)\n;;\n\nlet () =\n Printf.printf \"%s\\n\"\n (solve (make_list (read_int ())))\n;;\n"}, {"source_code": "let rec read_lines n =\n match n with\n | 0 -> []\n | _ -> (read_line ()) :: read_lines (n - 1)\n\nlet () =\n let num = read_int() in\n read_lines num\n |> List.rev\n |> List.iter (fun str ->\n let len = String.length str in\n if len <= 10\n then\n Printf.printf \"%s\\n\" str\n else\n Printf.printf \"%c%d%c\\n\" str.[0] (len - 2) str.[len - 1]\n )\n;;\n"}, {"source_code": "open Scanf\nopen Num\nopen Printf\nopen String\n\nlet n = Scanf.bscanf Scanf.Scanning.stdin \"%d \" ( fun x -> x)\n\nfor i = 1 to n do\n let s = Scanf.bscanf Scanf.Scanning.stdin \"%s \" ( fun x -> x) in\n let l = length s in \n if ( l <= 10) then\n print_endline s\n else\n let s1 = String.make 1 (String.get s 0) in\n let se = String.make 1 (String.get s ( l - 1)) in\n let num = string_of_int ( l - 2 ) in \n print_endline (s1 ^ num ^ se)\ndone\n"}, {"source_code": "let abbrev word =\n let len = (String.length word) in\n if len < 11 then word\n else (String.make 1 (String.get word 0))\n ^ (string_of_int (len-2)) \n ^ (String.make 1 (String.get word (len-1)))\n\nlet main () =\n let gr () = Scanf.scanf \" %d\\n\" (fun i -> i) in\n let n = gr () in\n for i = 1 to n do\n let grr () = Scanf.scanf \"%s\\n\" (fun i -> i) in\n let word = grr () in\n Printf.printf \"%s\\n\" (abbrev word)\n done\n;;\n\nlet _ = main();;\n"}, {"source_code": "let len word = String.length word;;\nlet first word = String.make 1 (String.get word 0);;\nlet last word = String.make 1 (String.get word ((len word) - 1));;\nlet abbr word = (first word) ^ (string_of_int ((len word) - 2)) ^ (last word);;\nlet solve word = if len word > 10 then abbr word else word;;\n\nlet rec read_and_solve n = if n > 0 then (\n Scanf.scanf \"%s\\n\" (fun s -> print_string ((solve s) ^ \"\\n\"));\n read_and_solve (n - 1);\n) else ();;\n\nlet () = Scanf.scanf \"%d\\n\" read_and_solve;;"}, {"source_code": "open Printf\nopen Scanf\n\nlet id x = x\n\nlet abbreviate s =\n let n = String.length s in\n if n > 10 then sprintf \"%c%d%c\" s.[0] (n - 2) s.[n-1] else s\n\nlet () =\n let n = scanf \" %d\" id in\n for i = 1 to n do begin\n let s = scanf \" %s\" id in\n let t = abbreviate s in\n printf \"%s\\n\" t\n end done\n"}, {"source_code": "let trans = function\n | s when (String.length s) <= 10 -> s\n | s -> let head = String.get s 0\n and len = String.length s in\n let tail = String.get s (len - 1)\n in\n Printf.sprintf \"%c%d%c\" head (len - 2) tail;;\n\nlet case_num = read_int ();;\nfor i = 1 to case_num do\n let s = read_line ()\n in Printf.printf \"%s\\n\" (trans s)\ndone ;;\n"}, {"source_code": "open Printf\n\nlet compress word = \n let l = String.length word in\n if l > 10 then\n sprintf \"%c%d%c\" (word.[0]) (l - 2) (word.[l - 1])\n else\n word\n\nlet main =\n let n = read_int() in\n for i = 1 to n do\n let word = read_line() in\n printf \"%s\\n\" (compress word)\n done"}, {"source_code": "let read_string() = Scanf.bscanf Scanf.Scanning.stdib \" %s \" (fun x -> x)\n\nlet () =\n let n = read_int() in\n for i=1 to n do\n let s = read_string() in\n let l = String.length s in\n if l > 10 then Printf.printf \"%c%d%c\\n\" s.[0] (l - 2) s.[l - 1]\n else print_endline s\n done"}, {"source_code": "let _ =\n let main () =\n let n = read_int () in\n for i = 1 to n do\n let s = read_line () in\n let l = String.length s in\n if l > 10 then (\n Printf.printf \"%c%d%c\\n\" s.[0] (l - 2) s.[l - 1]\n ) else print_endline s\n done\n in\n main ()\n"}, {"source_code": "let number_of_words = Scanf.scanf \"%d \" (fun n -> n)\n\nlet abbreviate w = \n let l = String.length w in\n let first_char = String.make 1 (String.get w 0) in\n let last_char = String.make 1 (String.get w (l - 1)) in\n if l > 10\n then first_char ^ Pervasives.string_of_int (l - 2) ^ last_char\n else w\n\nlet rec reading_words n = \n if n > 0\n then \n let word = Scanf.scanf \"%s \" (fun word -> word) in\n Printf.printf \"%s\\n\" (abbreviate word);\n reading_words (n - 1)\n else \n ()\n\nlet () = reading_words number_of_words\n\n"}, {"source_code": "let number_of_words = Scanf.scanf \"%d \" (fun n -> n)\n\nlet abbreviate w = \n let l = String.length w in\n let first_char = String.make 1 (String.get w 0) in\n let last_char = String.make 1 (String.get w (l - 1)) in\n if l > 10\n then first_char ^ string_of_int (l - 2) ^ last_char\n else w\n\nlet rec reading_words n = \n if n > 0\n then \n let word = Scanf.scanf \"%s \" (fun word -> word) in\n Printf.printf \"%s\\n\" (abbreviate word);\n reading_words (n - 1)\n else \n ()\n\nlet () = reading_words number_of_words\n\n"}, {"source_code": "(* Code Forces : Way Too Long Words *)\n\nopen Scanf\nopen Printf\n\nlet i = scanf \" %d\" (fun i -> i)\n\nlet l_w =\n let rec loop i out =\n if i = 0 then\n out\n else\n loop (i-1) ((scanf \" %s\" (fun w -> w))::out)\n in loop i []\n\nlet () =\n let l_w' =\n List.rev_map\n (fun w ->\n let len = String.length w in\n if len > 10 then\n let b = String.sub w 0 1 in\n let e = String.sub w (len - 1) 1 in\n let slen = string_of_int (len-2) in\n b ^ slen ^ e\n else\n w)\n l_w\n in\n List.iter (fun w -> printf \"%s\\n\" w) l_w'\n"}, {"source_code": "let () =\n let n=read_int () in\n for i=1 to n do\n let s=read_line () in\n let len=String.length s in\n if len > 10 then\n print_endline ((String.sub s 0 1) ^ (string_of_int(len - 2)) ^ (String.sub s (len - 1) 1))\n else\n print_endline s\n done\n"}, {"source_code": "for i=1to read_int()do let s,c=read_line(),print_char in let l=String.length s in if l>10then(c s.[0];print_int(l-2);c s.[l-1])else print_string s; c '\\n' done\n"}, {"source_code": "let short s =\n\tlet len = String.length s in\n\tif len > 10 then\n\t\t(String.sub s 0 1) ^ (string_of_int (len-2)) ^ (String.sub s (len-1) 1)\n\telse\n\t\ts\n;;\n\nlet () =\n\tlet n = read_int() in\n\tfor i = 1 to n do print_string (short (read_line()) ^ \"\\n\") done\n;;\n"}, {"source_code": "let readList n f =\n let rec loop n =\n if n == 0 then\n []\n else\n f() :: loop (n-1)\n in\n List.rev(loop n);;\n\nlet solve() =\n let str = read_line() in\n let len = String.length str in\n if (len) <= 10 then\n Printf.printf \"%s\\n\" str\n else\n Printf.printf \"%c%d%c\\n\" (str.[0]) (len-2) (str.[len-1]);;\n\nlet n = read_int() in\nreadList n solve\n"}, {"source_code": "let process s len = \n String.sub s 0 1 ^ string_of_int (len-2) ^ String.sub s (len-1) 1\n\nlet rec solve n = \n match n with \n | 0 -> ()\n | n -> \n let s = read_line () in\n let f s = \n let len = String.length s in\n match s with \n | s when len <= 10 -> print_string (s ^ \"\\n\")\n | s -> print_string ((process s len) ^ \"\\n\")\n in let top n = \n f s; \n solve (n-1) in top n\n \nlet n = read_int() in\n solve n\n"}, {"source_code": "let n=read_int();;\nfor i=1 to n do\n let s=read_line() in\n if String.length(s)<=10 then print_endline(s)\n else print_endline((String.sub s 0 1)^string_of_int(String.length(s)-2)^(String.sub s (String.length(s)-1) 1))\ndone;;"}, {"source_code": "\nlet () =\n let n = read_int () in\n for i = 1 to n do\n let str = read_line () in\n let len = String.length str in\n if len>10 then\n Printf.printf \"%c%d%c\\n\" (String.get str 0) (len-2) (String.get str (len-1))\n else\n Printf.printf \"%s\\n\" str\n done;;\n"}], "negative_code": [{"source_code": "let _ =\n let main () =\n let n = read_int () in\n for i = 1 to n do\n let s = read_line () in\n let l = String.length s in\n if l >= 10 then (\n Printf.printf \"%c%d%c\\n\" s.[0] (l - 2) s.[l - 1]\n ) else print_endline s\n done\n in\n main ()\n"}, {"source_code": "let input () =\n Scanf.bscanf Scanf.Scanning.stdin \"%s\" (fun x -> x)\n\nlet main () =\n let s = input ()\n in let len = String.length s\n in if len > 10 then\n Printf.printf \"%c%d%c\" (String.get s 0) (len - 2) (String.get s (len - 1))\n else\n Printf.printf \"%s\" s\n;;\n\nmain ();;\n"}, {"source_code": "let n=read_int();;\nfor i=1 to n do\n let s=read_line() in\n if String.length(s)<10 then print_endline(s)\n else print_endline((String.sub s 0 1)^string_of_int(String.length(s)-2)^(String.sub s (String.length(s)-1) 1))\ndone;;"}, {"source_code": "let rec read_lines n =\n match n with\n | 0 -> []\n | _ -> (read_line ()) :: read_lines (n - 1)\n\nlet () =\n let num = read_int() in\n read_lines num\n |> List.rev\n |> List.iter (fun str ->\n let len = String.length str in\n if len <= num\n then\n Printf.printf \"%s\\n\" str\n else\n Printf.printf \"%c%d%c\\n\" str.[0] (len - 2) str.[len - 1]\n )\n;;\n"}, {"source_code": "let rec read_lines n =\n match n with\n | 0 -> []\n | _ -> (read_line ()) :: read_lines (n - 1)\n\nlet () =\n let num = read_int() in\n read_lines num\n |> List.iter (fun str ->\n let len = String.length str in\n if len <= num\n then\n Printf.printf \"%s\\n\" str\n else\n Printf.printf \"%c%d%c\\n\" str.[0] (len - 2) str.[len - 1]\n )\n;;\n"}, {"source_code": "let abbrev word =\n let len = (String.length word) in\n if len < 10 then word\n else (String.make 1 (String.get word 0))\n ^ (string_of_int (len-2)) \n ^ (String.make 1 (String.get word (len-1)))\n\nlet main () =\n let gr () = Scanf.scanf \" %d\\n\" (fun i -> i) in\n let n = gr () in\n for i = 1 to n do\n let grr () = Scanf.scanf \"%s\\n\" (fun i -> i) in\n let word = grr () in\n Printf.printf \"%s\\n\" (abbrev word)\n done\n;;\n\nlet _ = main();;\n"}], "src_uid": "6639d6c53951f8c1a8324fb24ef68f7a"} {"source_code": "let find x t = let rep = ref 0 in\r\n for i = 0 to Array.length t -1 do\r\n if t.(i) = x then rep:=i ;\r\n done ;\r\n !rep ;;\r\n\r\nlet inverse s n1 n2 = let rep = ref \"\" in\r\n let pile = Stack.create () in\r\n for i = 0 to Array.length s -1 do \r\n let popo = if i = Array.length s -1 then \"\" else \" \" in\r\n if in2 then (rep := (!rep)^(string_of_int s.(i)^popo))\r\n else (\r\n if i = n2 then (Stack.push s.(i) pile ; for j = n1 to n2 -1 do rep := (!rep)^(string_of_int (Stack.pop pile))^\" \";done; rep:=(!rep)^(string_of_int (Stack.pop pile))^popo) \r\n else (Stack.push s.(i) pile ) )\r\n done ; !rep ;;\r\n\r\nlet to_t s len = let t = Array.make len 0 in\r\n let temp = ref \"\" in\r\n let inc = ref 0 in\r\n for i = 0 to String.length s -1 do\r\n if s.[i] = ' ' then (t.(!inc)<- int_of_string (!temp); incr inc ; temp:= \"\" )else \r\n temp := !temp^(String.make 1 (s.[i])) done ; t.(!inc)<- int_of_string (!temp); t;;\r\n\r\nlet n = int_of_string(input_line stdin) in\r\n\r\nfor i = 0 to n-1 do \r\n let len = int_of_string(input_line stdin) in\r\n let str = (input_line stdin) in \r\n let t = to_t str len in\r\n let finito = ref false in\r\n let interest = ref (-1,-1) in\r\n for j = 0 to Array.length t -1 do\r\n if not(!finito) && (t.(j))<>j+1 then\r\n (interest := (j,find (j+1) t) ; \r\n finito := true)\r\n done ; \r\n let rety = if !interest <> (-1,-1) then \r\n (let a,b = !interest in inverse t a b ) \r\n else str in\r\n print_endline rety\r\ndone;\r\n;;", "positive_code": [{"source_code": "(* Codeforces 1638 A Reverse train *)\r\n \r\n(* you can use either gr or rdln but not both *)\r\nlet gr () = Scanf.scanf \" %d\" (fun i -> i);;\r\nlet grf () = Scanf.scanf \" %f\" (fun i -> i);;\r\nlet grl () = Scanf.scanf \" %Ld\" (fun i -> i);;\r\nlet rdln() = input_line stdin;;\r\n(* let spli s = Str.split (Str.regexp \" \") s;; *)\r\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\r\nlet printarri ai = Array.iter (fun i -> (print_int i; print_string \" \")) ai;;\r\nlet debug = false;;\r\n \r\n(* reading list *)\r\nlet rec readlist n acc = match n with\r\n\t| 0 -> List.rev acc\r\n\t| _ -> readlist (n -1) (gr() :: acc);;\r\nlet printlisti li = List.iter (fun i -> (print_int i; print_string \" \")) li;;\r\nlet printlists ls = List.iter (fun s -> (print_string s; print_string \" \")) ls;;\r\nlet list_to_s li = String.concat \" \" (List.map string_of_int li);;\r\n\r\n\r\nlet rec extract_smallest_start i first l = match l with\r\n | [] -> (i, [])\r\n | h :: t ->\r\n if h == i then extract_smallest_start (i+1) (h :: first) t\r\n else \r\n (i, l);;\r\n\r\nlet rec get_until_a a part l = match l with\r\n | [] -> (part, l)\r\n | h :: t -> \r\n if h == a then (a :: part, t)\r\n else get_until_a a (h :: part) t;;\r\n\r\nlet rec generater n = if n==0 then [] else n :: generater (n-1);;\r\nlet generate n = List.rev (generater n);;\r\n\r\nlet do_one () = \r\n let n = gr () in\r\n let p = readlist n [] in\r\n let nfirst, pl = extract_smallest_start 1 [] p in\r\n (*let _ = Printf.printf \"nfirst = %d\\n\" nfirst in\r\n let _ = Printf.printf \"pl: %s\\n\" (list_to_s pl) in*)\r\n let pend = if List.length pl == 0 then [] \r\n else \r\n ( let revpart, pla = get_until_a nfirst [] pl in\r\n (List.append revpart pla)) in\r\n let lret = List.append (generate (nfirst-1)) pend in\r\n (printlisti lret; print_string \"\\n\");;\r\n \r\nlet do_all () = \r\n let t = gr () in\r\n for i = 1 to t do\r\n do_one ()\r\n done;;\r\n \r\nlet main() =\r\n\tdo_all ();;\r\n \r\nmain();;"}], "negative_code": [{"source_code": "let find x s = let rep = ref 0 in\r\n for i = 0 to String.length s -1 do\r\n if s.[i] = (string_of_int(x)).[0] then rep:=i ;\r\n done ;\r\n !rep ;;\r\n\r\nlet inverse s n1 n2 = let rep = ref \"\" in\r\n let pile = Stack.create () in\r\n for i = 0 to String.length s -1 do \r\n if in2 then (rep := (!rep)^(String.make 1 (s.[i])))\r\n else (\r\n if i = n2 then (Stack.push (String.make 1 (s.[i])) pile ; for j = n1 to n2 do rep := (!rep)^(Stack.pop pile);done;) \r\n else (\r\n (String.make 1 (s.[i])) ; Stack.push (String.make 1 (s.[i])) pile ))\r\n done ; !rep ;;\r\n\r\n\r\nlet n = int_of_string(input_line stdin) in\r\n\r\nfor i = 0 to n-1 do \r\n let len = int_of_string(input_line stdin) in\r\n let str = (input_line stdin) in \r\n let finito = ref false in\r\n let interest = ref (-1,-1) in\r\n for j = 0 to String.length str -1 do\r\n if str.[j] <> ' ' && not(!finito) && str.[j]<>(string_of_int (j/2 +1)).[0] then\r\n (prerr_endline (string_of_int j);\r\n interest := (j,find (j/2 +1) str) ; \r\n finito := true)\r\n done ; \r\n let rety = if !interest <> (-1,-1) then \r\n (let a,b = !interest in inverse str a b ) \r\n else str in\r\n print_endline rety\r\ndone;\r\n;;"}], "src_uid": "a57823a7ca0f67a07f94175ab59d33de"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let n = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let m = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let a = Array.make_matrix n m (-1) in\n let b = Array.make_matrix n m (-1) in\n let res = ref 0 in\n let pred = ref 10 in\n let rec bf x y k =\n (*Printf.printf \"asd %d %d %d\\n\" x y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n let x = ref x in\n let y = ref y in\n while !x < n && a.(!x).(!y) >= 0 do\n\tincr x\n done;\n (*Printf.printf \"qwe %d %d %d\\n\" !x !y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n if !x = n then (\n\tif !y < m - 1 then (\n\t x := 0;\n\t incr y;\n\t bf !x !y k;\n\t) else (\n\t if !res < k then (\n\t res := k;\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t\tb.(i).(j) <- a.(i).(j)\n\t done\n\t done;\n\t if !res >= !pred then raise Not_found\n\t )\n\t)\n ) else (\n\tlet x = !x\n\tand y = !y in\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 2).(y + 1) <- -1;\n\t );\n\t if 1 <= x && x <= n - 2 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 2) < 0 &&\n\t a.(x - 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t a.(x - 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t a.(x - 1).(y + 2) <- -1;\n\t );\n\t if 2 <= x && x <= n - 1 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x - 1).(y + 1) < 0 &&\n\t a.(x - 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x - 1).(y + 1) <- k;\n\t a.(x - 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x - 1).(y + 1) <- -1;\n\t a.(x - 2).(y + 1) <- -1;\n\t );\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x + 1).(y) < 0 &&\n\t a.(x + 2).(y) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x + 1).(y) <- k;\n\t a.(x + 2).(y) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x + 1).(y) <- -1;\n\t a.(x + 2).(y) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t );\n\t bf (x + 1) y k;\n )\n in\n (match n, m with\n | 9, 9 -> pred := 13\n | 8, 9 -> pred := 12\n | 9, 8 -> pred := 12\n | 8, 8 -> pred := 10\n | 7, 9 -> pred := 10\n | 9, 7 -> pred := 10\n | 7, 8 -> pred := 9\n | 8, 7 -> pred := 9\n | _ -> ()\n );\n (try bf 0 0 0 with Not_found -> ());\n Printf.printf \"%d\\n\" !res;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tlet v = b.(i).(j) in\n\tlet c =\n\t if v < 0\n\t then '.'\n\t else Char.chr (Char.code 'A' + v)\n\tin\n\t Printf.printf \"%c\" c\n done;\n Printf.printf \"\\n\"\n done\n", "positive_code": [{"source_code": "let read_int () = Scanf.bscanf Scanf.Scanning.stdib \" %d \" (fun x -> x) \n\nlet n = read_int()\nlet m = read_int()\n\nlet (h,w) = (n+1,m+1)\n\nlet wall = -2\nlet hole = -1\nlet empty = 0\n\nlet a = Array.make (h*w) wall\nlet () = \n for i=0 to n-1 do for j=0 to m-1 do\n a.(w*i+j) <- empty\n done done\n\nlet p = Array.make 4 [||]\nlet () = \n p.(0) <- [|w;w+1;w+2;2*w|];\n p.(1) <- [|1;2;w+1;2*w+1|];\n p.(2) <- [|w-2;w-1;w;2*w|];\n p.(3) <- [|w;2*w-1;2*w;2*w+1|]\n\nlet rec backtrack i blanks = (* i is the first empty space, blanks is the # of blanks left *)\n if i=h*w then true else if a.(i) != empty then backtrack (i+1) blanks else \n let rec trypiece q = if q=4 then (\n if blanks=0 then false else (\n\ta.(i) <- hole;\n\tif backtrack (i+1) (blanks-1) then true else (\n\t a.(i) <- empty;\n\t false\n\t)\n )\n ) else (\n let rec fit j = if j=4 then true else a.(i+p.(q).(j)) = 0 && (fit (j+1)) in\n let rec fill j x = if j=4 then a.(i) <- x else (\n\ta.(i+p.(q).(j)) <- x;\n\tfill (j+1) x\n )\n in\n\tif not (fit 0) then trypiece (q+1) else (\n\t fill 0 (i+1);\n\t if backtrack (i+1) blanks then true else (\n\t fill 0 empty;\n\t trypiece (q+1)\n\t )\n\t)\n )\n in\n trypiece 0\n\nlet rec tryblanks b = if backtrack 0 b then b else tryblanks (b+5)\n\nlet () = \n let blanks = tryblanks (n*m mod 5) in\n let lab = Array.make (h*w) (-1) in\n let rec labels i c = if i=h*w then () else (\n if a.(i)=hole || a.(i)=wall || lab.(a.(i)) >= 0 then labels (i+1) c else (\n lab.(a.(i)) <- c;\n labels (i+1) (c+1)\n )\n )\n in\n Printf.printf \"%d\\n\" (((n*m)-blanks)/5);\n labels 0 0;\n for i=0 to n-1 do \n for j=0 to m-1 do\n\tlet c = if a.(w*i+j) = hole then '.' else char_of_int ((int_of_char 'A') + lab.(a.(w*i+j))) in\n\t print_char c\n done;\n print_newline ()\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = min n m\n and m = max n m in\n let a = Array.make_matrix n m (-1) in\n let b = Array.make_matrix n m (-1) in\n let res = ref 0 in\n let pred = ref 10 in\n let rec bf x y k =\n (*Printf.printf \"asd %d %d %d\\n\" x y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n let x = ref x in\n let y = ref y in\n while !x < n && a.(!x).(!y) >= 0 do\n\tincr x\n done;\n (*Printf.printf \"qwe %d %d %d\\n\" !x !y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n if !x = n then (\n\tif !y < m - 1 then (\n\t x := 0;\n\t incr y;\n\t bf !x !y k;\n\t) else (\n\t if !res < k then (\n\t res := k;\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t\tb.(i).(j) <- a.(i).(j)\n\t done\n\t done;\n\t if !res >= !pred then raise Not_found\n\t )\n\t)\n ) else (\n\tlet x = !x\n\tand y = !y in\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 2).(y + 1) <- -1;\n\t );\n\t if 1 <= x && x <= n - 2 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 2) < 0 &&\n\t a.(x - 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t a.(x - 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t a.(x - 1).(y + 2) <- -1;\n\t );\n\t if 2 <= x && x <= n - 1 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x - 1).(y + 1) < 0 &&\n\t a.(x - 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x - 1).(y + 1) <- k;\n\t a.(x - 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x - 1).(y + 1) <- -1;\n\t a.(x - 2).(y + 1) <- -1;\n\t );\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x + 1).(y) < 0 &&\n\t a.(x + 2).(y) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x + 1).(y) <- k;\n\t a.(x + 2).(y) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x + 1).(y) <- -1;\n\t a.(x + 2).(y) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t );\n\t bf (x + 1) y k;\n )\n in\n (match n, m with\n | 9, 9 -> pred := 13\n | 8, 9 -> pred := 12\n | 8, 8 -> pred := 10\n | 7, 9 -> pred := 10\n | 7, 8 -> pred := 9\n | _ -> ()\n );\n (try bf 0 0 0 with Not_found -> ());\n Printf.printf \"%d\\n\" !res;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tlet v = b.(i).(j) in\n\tlet c =\n\t if v < 0\n\t then '.'\n\t else Char.chr (Char.code 'A' + v)\n\tin\n\t Printf.printf \"%c\" c\n done;\n Printf.printf \"\\n\"\n done\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 = Scanf.bscanf sb \"%d \" (fun s -> s) in\n let n = min n m\n and m = max n m in\n let a = Array.make_matrix n m (-1) in\n let b = Array.make_matrix n m (-1) in\n let res = ref 0 in\n let pred = ref 10 in\n let rec bf x y k =\n (*Printf.printf \"asd %d %d %d\\n\" x y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n let x = ref x in\n let y = ref y in\n while !x < n && a.(!x).(!y) >= 0 do\n\tincr x\n done;\n (*Printf.printf \"qwe %d %d %d\\n\" !x !y k;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tPrintf.printf \"%d \" a.(i).(j)\n done;\n Printf.printf \"\\n\"\n done;*)\n if !x = n then (\n\tif !y < m - 1 then (\n\t x := 0;\n\t incr y;\n\t bf !x !y k;\n\t) else (\n\t if !res < k then (\n\t res := k;\n\t for i = 0 to n - 1 do\n\t for j = 0 to m - 1 do\n\t\tb.(i).(j) <- a.(i).(j)\n\t done\n\t done;\n\t if !res >= !pred then raise Not_found\n\t )\n\t)\n ) else (\n\tlet x = !x\n\tand y = !y in\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 2).(y + 1) <- -1;\n\t );\n\t if 1 <= x && x <= n - 2 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x + 1).(y + 2) < 0 &&\n\t a.(x - 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t a.(x - 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t a.(x - 1).(y + 2) <- -1;\n\t );\n\t if 2 <= x && x <= n - 1 && y <= m - 3 &&\n\t a.(x).(y + 1) < 0 &&\n\t a.(x).(y + 2) < 0 &&\n\t a.(x - 1).(y + 1) < 0 &&\n\t a.(x - 2).(y + 1) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x).(y + 1) <- k;\n\t a.(x).(y + 2) <- k;\n\t a.(x - 1).(y + 1) <- k;\n\t a.(x - 2).(y + 1) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x).(y + 1) <- -1;\n\t a.(x).(y + 2) <- -1;\n\t a.(x - 1).(y + 1) <- -1;\n\t a.(x - 2).(y + 1) <- -1;\n\t );\n\t if x <= n - 3 && y <= m - 3 &&\n\t a.(x + 1).(y) < 0 &&\n\t a.(x + 2).(y) < 0 &&\n\t a.(x + 1).(y + 1) < 0 &&\n\t a.(x + 1).(y + 2) < 0\n\t then (\n\t a.(x).(y) <- k;\n\t a.(x + 1).(y) <- k;\n\t a.(x + 2).(y) <- k;\n\t a.(x + 1).(y + 1) <- k;\n\t a.(x + 1).(y + 2) <- k;\n\t bf x y (k + 1);\n\t a.(x).(y) <- -1;\n\t a.(x + 1).(y) <- -1;\n\t a.(x + 2).(y) <- -1;\n\t a.(x + 1).(y + 1) <- -1;\n\t a.(x + 1).(y + 2) <- -1;\n\t );\n\t bf (x + 1) y k;\n )\n in\n (match n, m with\n | 9, 9 -> pred := 13\n | 8, 9 -> pred := 12\n | 7, 9 -> pred := 10\n | 7, 8 -> pred := 9\n | _ -> ()\n );\n (try bf 0 0 0 with Not_found -> ());\n Printf.printf \"%d\\n\" !res;\n for i = 0 to n - 1 do\n for j = 0 to m - 1 do\n\tlet v = b.(i).(j) in\n\tlet c =\n\t if v < 0\n\t then '.'\n\t else Char.chr (Char.code 'A' + v)\n\tin\n\t Printf.printf \"%c\" c\n done;\n Printf.printf \"\\n\"\n done\n"}], "src_uid": "f29eba31c20246686b8427b7aeadd184"} {"source_code": "(* 2n+1, 1 then second player wins \r\nsince 1st moves 2a-1, 2nd moves 2(n-a)+1, leaving 1,1 for first.\r\n\r\n2n,1 then first player wins since first moves 2n-1\r\nwhich leaves second with 1,1\r\n\r\n2n,2m then 2x+1,2m so second player wins.\r\n2n+1,2m then first moves 2m-1 leaving 2n+1,1 and that means\r\nfirst player wins as second player must go first in this grid type.\r\n\r\n2n+1,2m+1 then first player moves 2a-1 in either direction so\r\nsecond should move in that direction s.t 1,2m+1 or 2n+1,1 which means they win as the player that \r\nneeds to go seconds in the config wins.\r\n*)\r\n\r\nlet read_long () = Scanf.scanf \" %Ld\" (fun l-> l);;\r\nlet read_int () = Scanf.scanf \" %d\" (fun x-> x);;\r\nlet run_case = function\r\n| () ->\r\n let n = read_long () in\r\n let m = read_long () in\r\n let nrem = Int64.sub n (Int64.mul (Int64.div n 2L) 2L) in\r\n let mrem = Int64.sub m (Int64.mul (Int64.div m 2L) 2L) in\r\n if ((nrem=0L)&&(mrem=0L)) then print_string \"Tonya\"\r\n else if ((nrem=0L)||(mrem=0L)) then print_string \"Burenka\"\r\n else print_string \"Tonya\"\r\n;;\r\n\r\nlet rec iter_cases = function\r\n| 0->()\r\n| t -> run_case (); print_newline (); iter_cases (t-1)\r\n;;\r\n\r\nlet t=read_int () in iter_cases t;;\r\n", "positive_code": [{"source_code": "\nlet sf = Scanf.scanf\nlet read_int () = sf \" %d\" (fun x -> x)\n\nlet () =\n let t = read_int () in\n for _ = 1 to t do\n let n = read_int () in\n let m = read_int () in\n if (n + m) mod 2 = 0 then\n Printf.printf \"Tonya\\n\"\n else\n Printf.printf \"Burenka\\n\"\n done;"}], "negative_code": [], "src_uid": "13611e428c24b94023811063bbbfa077"} {"source_code": "let read_array n = let a = Array.make n 0 in\n for i = 0 to (n - 1) do\n Scanf.scanf \" %d\" (fun x -> a.(i) <- x)\n done;\n a\n\nlet best_time pos spd =\n let n = Array.length pos in\n let max_x = float_of_int (Array.fold_left max min_int pos) in\n let min_v = float_of_int (Array.fold_left min max_int spd) in\n let merge (a, b) (c, d) = (max a c, min b d) in\n let feasible_time t =\n let range = ref (neg_infinity, infinity) in\n for i = 0 to (n-1) do\n let (x, dx) = (float_of_int pos.(i), float_of_int spd.(i) *. t) in\n range := merge !range (x -. dx, x +. dx)\n done;\n let (a, b) = !range in a <= b\n in\n let rec find lo hi it =\n if (hi -. lo) < epsilon_float || it >= 64\n then lo\n else\n let m = lo +. (hi -. lo) /. 2. in\n if feasible_time m\n then find lo m (it + 1)\n else find (m +. epsilon_float) hi (it + 1)\n in\n find 0.0 (max_x /. min_v) 0\n\nlet () =\n let n = Scanf.scanf \"%d\" (fun x -> x) in\n let pos = read_array n in\n let spd = read_array n in\n Printf.printf \"%10.12f\\n\" (best_time pos spd)\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = bscanf Scanning.stdib \" %f \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let x = Array.init n read_float in\n let v = Array.init n read_float in\n\n let intersect (lo1,hi1) (lo2,hi2) = (max lo1 lo2, min hi1 hi2) in\n let no_overlap (lo,hi) = lo > hi in\n\n let overlap_interval t =\n (* given time t, if they overlap return Some (lo,hi) else None *)\n let rec loop oldinterval i =\n if i=n then Some oldinterval else\n\tlet my_hi = x.(i) +. t *. v.(i) in\n\tlet my_lo = x.(i) -. t *. v.(i) in\n\tlet newinterval = if i=0 then (my_lo,my_hi) else intersect (my_lo,my_hi) oldinterval in\n\tif no_overlap newinterval then None else loop newinterval (i+1)\n in\n loop (0.0, 0.0) 0\n in\n\n let rec bsearch lo_t hi_t count = (* hi has overlap, lo has no overlap *)\n if count = 50 then hi_t else\n let m = (lo_t +. hi_t) /. 2.0 in\n match overlap_interval m with\n\t| None -> bsearch m hi_t (count+1)\n\t| Some _ -> bsearch lo_t m (count+1)\n in\n\n let rec find_hi t = match overlap_interval t with None -> find_hi (2.0 *. t) | Some _ -> t in\n\n let answer = match overlap_interval 0.0 with Some _ -> 0.0\n | None -> bsearch 0.0 (find_hi 1.0) 0\n in\n\n printf \"%.10f\\n\" answer\n"}], "negative_code": [{"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_float _ = bscanf Scanning.stdib \" %f \" (fun x -> x)\n \nlet () = \n let n = read_int () in\n let x = Array.init n read_float in\n let v = Array.init n read_float in\n\n let intersect (lo1,hi1) (lo2,hi2) = (max lo1 lo2, min hi1 hi2) in\n let no_overlap (lo,hi) = lo > hi in\n\n let overlap_interval t =\n (* given time t, if they overlap return Some (lo,hi) else None *)\n let rec loop oldinterval i =\n if i=n then Some oldinterval else\n\tlet my_hi = x.(i) +. t *. v.(i) in\n\tlet my_lo = x.(i) -. t *. v.(i) in\n\tlet newinterval = if i=0 then (my_lo,my_hi) else intersect (my_lo,my_hi) oldinterval in\n\tif no_overlap newinterval then None else loop newinterval (i+1)\n in\n loop (0.0, 0.0) 0\n in\n\n let rec bsearch lo_t hi_t count = (* hi has overlap, lo has no overlap *)\n if count = 50 then hi_t else\n let m = (lo_t +. hi_t) /. 2.0 in\n match overlap_interval m with\n\t| None -> bsearch m hi_t (count+1)\n\t| Some _ -> bsearch lo_t m (count+1)\n in\n\n let rec find_hi t = match overlap_interval t with None -> find_hi (2.0 *. t) | Some _ -> t in\n\n let answer = match overlap_interval 0.0 with Some (lo,hi) -> lo | None ->\n bsearch 0.0 (find_hi 1.0) 0\n in\n\n printf \"%.10f\\n\" answer\n"}], "src_uid": "f13f27a131b9315ebbb8688e2f43ddde"} {"source_code": "let rd_int = (fun () -> Scanf.scanf \" %d\" (fun n -> n)) in\nlet pri i = print_string ((string_of_int i) ^ \" \") in\nlet n = rd_int () in\nlet rec make_list n = \n if n == 0 then \n [] \n else \n let num = rd_int () in\n num :: make_list (n - 1) \nin\nlet a = make_list n in \nlet rec pr_list k l rl = \n if k >= n then\n ()\n else \n \n match l with\n | [] -> ()\n | hd :: tl -> \n match rl with\n | [] -> ()\n | hdr :: tlr ->\n let _ = pri hdr in \n let _ = pr_list (k + 2) tlr tl in\n if k + 1 == n then () else pri hd\nin\npr_list 0 a (List.rev a);;\n", "positive_code": [{"source_code": "let () =\n let n = read_int () in\n (* values *)\n let a = Array.init n (fun _ -> Scanf.scanf \"%d%_c\" (fun x -> x)) in\n (* permutation *)\n let p = Array.init n (fun i ->\n if i mod 2 = (if n mod 2 = 0 && i >= n / 2 then 1 else 0)\n then a.(n - i - 1)\n else a.(i)) in\n (* output *)\n print_endline (String.concat \" \" (Array.to_list (Array.map string_of_int p)))\n"}, {"source_code": "let print_array a = \n for k = 0 to (Array.length a) - 1 do\n print_int a.(k);\n print_char ' ';\n done;\n\n print_newline (); \n;;\n\nlet rearrange_blocks a = \n let n = Array.length a in\n let n_2 = n / 2 in\n let n_4 = (n_2 + 1) / 2 in\n for j = 0 to (n_4 - 1) do\n let k = j * 2 in\n let tmp = a.(k) in\n begin\n a.( k ) <- a.( n - k - 1 );\n a.( n - k - 1 ) <- tmp;\n end \n done;\n print_array a;\n;;\n\nlet rec read_block a k = \n if k < (Array.length a) then\n Scanf.bscanf Scanf.Scanning.stdin \"%i \" (add_block a k)\n else\n rearrange_blocks a\nand add_block a k v = \n begin\n a.(k) <- v;\n read_block a (k + 1)\n end \n;;\n\nlet read_blocks n = \n let blocks = Array.make n 0 in\n read_block blocks 0\n;;\n \nread_blocks (read_int ());;\n"}], "negative_code": [], "src_uid": "7d2f22fc06d4f0b8ff8be6c6862046e7"} {"source_code": "(* Feeding Chicken\n * https://codeforces.com/contest/1254/problem/A *)\n\n(* I shouldn't need explicitly named record fields. But I wanted to\n * practice the notation. *)\ntype cell = {coords: int * int; has_rice: bool}\ntype assignment = {coords: int * int; chicken: int}\n\n(* Converts a board into a list of cells, in snake order. *)\nlet cells_of_board n m (board: string array) =\n let next (i, j) = match (i mod 2, j) with\n | (0, k) when k = m - 1 -> (i + 1, j)\n | (0, _) -> (i, j + 1)\n | (_, 0) -> (i + 1, j)\n | _ -> (i, j - 1) in\n let rec iter i j acc =\n if i >= n then\n acc\n else\n let (ni, nj) = next (i, j) in\n iter ni nj ({coords = (i, j); has_rice = String.get board.(i) j = 'R'} :: acc)\n in iter 0 0 []\n\n(* Converts a bunch of chicken assignments to an array of 'bytes' arrays representing\n * the result. *)\nlet result_of_assns n m (assns : assignment list) =\n let chicken_labels =\n \"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\" in\n (* The following didn't work! It created n references to the same array.\n It's like doing \"arr = [[0] * m] * n\" in Python.\n let res = Array.make n (Bytes.make m '0') in *)\n let res = Array.init n (fun _ -> Bytes.make m '0') in\n (* Ugh, imperative updates... but this is probably more efficient. *)\n let rec iter ls = match ls with\n | [] -> ()\n | {coords=(i, j); chicken = c} :: lss ->\n (Bytes.set res.(i) j (String.get chicken_labels c);\n iter lss)\n in (iter assns; res)\n\n(* Takes a 'board' (2D array showing where the rice is) and\n * converts it to a board of chicken assignments. *)\nlet solve n m chicks (board: string array) =\n let cells = cells_of_board n m board in\n (* There's probably a function to do this in one go. *)\n let rice_total = List.fold_left\n (fun acc cl -> if cl.has_rice then acc + 1 else acc)\n 0 cells\n in\n (* The amount of rice each chicken should have. *)\n let amt = rice_total / chicks in\n (* These are hungry chickens! They will eat amt+1 rice. *)\n let hungry = rice_total - amt * chicks in\n (* Iterate through cells and assign them chickens in order.\n * Assign the hungry chickens first, then the rest. *)\n let rec iter cls prev_chick k acc =\n match cls with\n | [] -> acc\n | {coords=crd; has_rice=hr} :: clss ->\n let mx = if prev_chick < hungry then amt + 1 else amt in\n let nk' = if hr then k + 1 else k in\n let (cur_chick, nk) = if nk' > mx then\n (prev_chick + 1, 1)\n else\n (prev_chick, nk') in\n iter clss cur_chick nk ({coords=crd; chicken=cur_chick} :: acc)\n in result_of_assns n m (iter cells 0 0 [])\n\nlet rec rep n f = if n = 0 then () else (f (); rep (n-1) f)\n\nlet main () =\n let tt = read_int () in\n rep tt (fun () ->\n (* Scanf.scanf caused Codeforces to give a runtime error for some reason *)\n let [n; m; k] =\n read_line ()\n |> Str.split (Str.regexp \" \")\n |> List.map int_of_string in\n let board = Array.init n (fun _ -> read_line ()) in\n Array.iter (fun s -> (print_bytes s; print_newline ())) (solve n m k board)\n )\n\nlet _ = main ()\n", "positive_code": [{"source_code": "(* Feeding Chicken\n * https://codeforces.com/contest/1254/problem/A *)\n\n(* I shouldn't need explicitly named record fields. But I wanted to\n * practice the notation. *)\ntype cell = {coords: int * int; has_rice: bool}\ntype assignment = {coords: int * int; chicken: int}\n\n(* Converts a board into a list of cells, in snake order. *)\nlet cells_of_board n m (board: string array) =\n let next (i, j) = match (i mod 2, j) with\n | (0, k) when k = m - 1 -> (i + 1, j)\n | (0, _) -> (i, j + 1)\n | (_, 0) -> (i + 1, j)\n | _ -> (i, j - 1) in\n let rec iter i j acc =\n if i >= n then\n acc\n else\n let (ni, nj) = next (i, j) in\n iter ni nj ({coords = (i, j); has_rice = String.get board.(i) j = 'R'} :: acc)\n in iter 0 0 []\n\n(* Converts a bunch of chicken assignments to an array of 'bytes' arrays representing\n * the result. *)\nlet result_of_assns n m (assns : assignment list) =\n let chicken_labels =\n \"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\" in\n (* The following didn't work! It created n references to the same array.\n It's like doing \"arr = [[0] * m] * n\" in Python.\n let res = Array.make n (Bytes.make m '0') in *)\n let res = Array.init n (fun _ -> Bytes.make m '0') in\n (* Ugh, imperative updates... but this is probably more efficient. *)\n let rec iter ls = match ls with\n | [] -> ()\n | {coords=(i, j); chicken = c} :: lss ->\n (Bytes.set res.(i) j (String.get chicken_labels c);\n iter lss)\n in (iter assns; res)\n\n(* Takes a 'board' (2D array showing where the rice is) and\n * converts it to a board of chicken assignments. *)\nlet solve n m chicks (board: string array) =\n let cells = cells_of_board n m board in\n (* There's probably a function to do this in one go. *)\n let rice_total = List.fold_left\n (fun acc cl -> if cl.has_rice then acc + 1 else acc)\n 0 cells\n in\n (* The amount of rice each chicken should have. *)\n let amt = rice_total / chicks in\n (* These are hungry chickens! They will eat amt+1 rice. *)\n let hungry = rice_total - amt * chicks in\n (* Iterate through cells and assign them chickens in order.\n * Assign the hungry chickens first, then the rest. *)\n let rec iter cls prev_chick k acc =\n match cls with\n | [] -> acc\n | {coords=crd; has_rice=hr} :: clss ->\n let mx = if prev_chick < hungry then amt + 1 else amt in\n let nk' = if hr then k + 1 else k in\n let (cur_chick, nk) = if nk' > mx then\n (prev_chick + 1, 1)\n else\n (prev_chick, nk') in\n iter clss cur_chick nk ({coords=crd; chicken=cur_chick} :: acc)\n in result_of_assns n m (iter cells 0 0 [])\n\nlet rec rep n f = if n = 0 then () else (f (); rep (n-1) f)\n\nlet main () =\n let tt = read_int () in\n rep tt (fun () ->\n (* Scanf.scanf caused Codeforces to give a runtime error for some reason *)\n let (n, m, k) = Scanf.sscanf (read_line ()) \"%d %d %d\" (fun x y z -> (x, y, z)) in\n let board = Array.init n (fun _ -> read_line ()) in\n Array.iter (fun s -> (print_bytes s; print_newline ())) (solve n m k board)\n )\n\nlet _ = main ()\n"}], "negative_code": [{"source_code": "print_string \"asdf\""}, {"source_code": "(* Feeding Chicken\n * https://codeforces.com/contest/1254/problem/A *)\n\n(* I shouldn't need explicitly named record fields. But I wanted to\n * practice the notation. *)\ntype cell = {coords: int * int; has_rice: bool}\ntype assignment = {coords: int * int; chicken: int}\n\n(* Converts a board into a list of cells, in snake order. *)\nlet cells_of_board n m (board: string array) =\n let next (i, j) = match (i mod 2, j) with\n | (0, k) when k = m - 1 -> (i + 1, j)\n | (0, _) -> (i, j + 1)\n | (_, 0) -> (i + 1, j)\n | _ -> (i, j - 1) in\n let rec iter i j acc =\n if i >= n then\n acc\n else\n let (ni, nj) = next (i, j) in\n iter ni nj ({coords = (i, j); has_rice = String.get board.(i) j = 'R'} :: acc)\n in iter 0 0 []\n\n(* Converts a bunch of chicken assignments to an array of 'bytes' arrays representing\n * the result. *)\nlet result_of_assns n m (assns : assignment list) =\n let chicken_labels =\n \"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKKLZXCVBNM\" in\n (* The following didn't work! It created n references to the same array.\n It's like doing \"arr = [[0] * m] * n\" in Python.\n let res = Array.make n (Bytes.make m '0') in *)\n let res = Array.init n (fun _ -> Bytes.make m '0') in\n (* Ugh, imperative updates... but this is probably more efficient. *)\n let rec iter ls = match ls with\n | [] -> ()\n | {coords=(i, j); chicken = c} :: lss ->\n (Bytes.set res.(i) j (String.get chicken_labels c);\n iter lss)\n in (iter assns; res)\n\n(* Takes a 'board' (2D array showing where the rice is) and\n * converts it to a board of chicken assignments. *)\nlet solve n m chicks (board: string array) =\n let cells = cells_of_board n m board in\n (* There's probably a function to do this in one go. *)\n let rice_total = List.fold_left\n (fun acc cl -> if cl.has_rice then acc + 1 else acc)\n 0 cells\n in\n (* The amount of rice each chicken should have. *)\n let amt = rice_total / chicks in\n (* These are hungry chickens! They will eat amt+1 rice. *)\n let hungry = rice_total - amt * chicks in\n (* Iterate through cells and assign them chickens in order.\n * Assign the hungry chickens first, then the rest. *)\n let rec iter cls prev_chick k acc =\n match cls with\n | [] -> acc\n | {coords=crd; has_rice=hr} :: clss ->\n let mx = if prev_chick < hungry then amt + 1 else amt in\n let nk' = if hr then k + 1 else k in\n let (cur_chick, nk) = if nk' > mx then\n (prev_chick + 1, 1)\n else\n (prev_chick, nk') in\n iter clss cur_chick nk ({coords=crd; chicken=cur_chick} :: acc)\n in result_of_assns n m (iter cells 0 0 [])\n\nlet rec rep n f = if n = 0 then () else (f (); rep (n-1) f)\n\nlet main () =\n let tt = read_int () in\n rep tt (fun () ->\n (* Scanf.scanf caused Codeforces to give a runtime error for some reason *)\n let (n, m, k) = Scanf.sscanf (read_line ()) \"%d %d %d\" (fun x y z -> (x, y, z)) in\n let board = Array.init n (fun _ -> read_line ()) in\n Array.iter (fun s -> (print_bytes s; print_newline ())) (solve n m k board)\n )\n\nlet _ = main ()\n"}, {"source_code": "(* Feeding Chicken\n * https://codeforces.com/contest/1254/problem/A *)\n\n(* I shouldn't need explicitly named record fields. But I wanted to\n * practice the notation. *)\ntype cell = {coords: int * int; has_rice: bool}\ntype assignment = {coords: int * int; chicken: int}\n\n(* Converts a board into a list of cells, in snake order. *)\nlet cells_of_board n m (board: string array) =\n let next (i, j) = match (i mod 2, j) with\n | (0, k) when k = m - 1 -> (i + 1, j)\n | (0, _) -> (i, j + 1)\n | (_, 0) -> (i + 1, j)\n | _ -> (i, j - 1) in\n let rec iter i j acc =\n if i >= n then\n acc\n else\n let (ni, nj) = next (i, j) in\n iter ni nj ({coords = (i, j); has_rice = String.get board.(i) j = 'R'} :: acc)\n in iter 0 0 []\n\n(* Converts a bunch of chicken assignments to an array of 'bytes' arrays representing\n * the result. *)\nlet result_of_assns n m (assns : assignment list) =\n let chicken_labels =\n \"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKKLZXCVBNM\" in\n (* The following didn't work! It created n references to the same array.\n It's like doing \"arr = [[0] * m] * n\" in Python.\n let res = Array.make n (Bytes.make m '0') in *)\n let res = Array.init n (fun _ -> Bytes.make m '0') in\n (* Ugh, imperative updates... but this is probably more efficient. *)\n let rec iter ls = match ls with\n | [] -> ()\n | {coords=(i, j); chicken = c} :: lss ->\n (Bytes.set res.(i) j (String.get chicken_labels c);\n iter lss)\n in (iter assns; res)\n\n(* Takes a 'board' (2D array showing where the rice is) and\n * converts it to a board of chicken assignments. *)\nlet solve n m chicks (board: string array) =\n let cells = cells_of_board n m board in\n (* There's probably a function to do this in one go. *)\n let rice_total = List.fold_left\n (fun acc cl -> if cl.has_rice then acc + 1 else acc)\n 0 cells\n in\n (* The amount of rice each chicken should have. *)\n let amt = rice_total / chicks in\n (* These are hungry chickens! They will eat amt+1 rice. *)\n let hungry = rice_total - amt * chicks in\n (* Iterate through cells and assign them chickens in order.\n * Assign the hungry chickens first, then the rest. *)\n let rec iter cls prev_chick k acc =\n match cls with\n | [] -> acc\n | {coords=crd; has_rice=hr} :: clss ->\n let mx = if prev_chick < hungry then amt + 1 else amt in\n let nk' = if hr then k + 1 else k in\n let (cur_chick, nk) = if nk' > mx then\n (prev_chick + 1, 1)\n else\n (prev_chick, nk') in\n iter clss cur_chick nk ({coords=crd; chicken=cur_chick} :: acc)\n in result_of_assns n m (iter cells 0 0 [])\n\nlet rec rep n f = if n = 0 then () else (f (); rep (n-1) f)\n\nlet main () =\n print_string \"asdf\"\n\nlet _ = main ()\n"}], "src_uid": "dc0acf5347fba3c211ebaca7c9475bf5"} {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let a = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let c2i c = Char.code c - Char.code 'a' in\n let n = String.length a\n and m = String.length b in\n let inf = 1000000000 in\n let prev = Array.make_matrix 26 n 0 in\n let next = Array.make_matrix 26 n 0 in\n let p = Array.make 26 inf in\n let p' = Array.make 26 (-1) in\n let _ =\n for i = 0 to n - 1 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t prev.(j).(i) <- p'.(j)\n\tdone;\n\tp'.(c) <- i;\n done;\n for i = n - 1 downto 0 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t next.(j).(i) <- p.(j)\n\tdone;\n\tp.(c) <- i;\n done;\n in\n let d = Array.make m (-1) in\n let pos = ref p.(c2i b.[0]) in\n let _ =\n d.(0) <- !pos;\n for i = 1 to m - 1 do\n if !pos < inf then (\n\tlet c = c2i b.[i] in\n\t pos := next.(c).(!pos);\n );\n d.(i) <- !pos;\n done;\n in\n let d' = Array.make m (-1) in\n let _ =\n pos := p'.(c2i b.[m - 1]);\n d'.(m - 1) <- !pos;\n for i = m - 2 downto 0 do\n if !pos >= 0 then (\n\tlet c = c2i b.[i] in\n\t pos := prev.(c).(!pos);\n );\n d'.(i) <- !pos;\n done;\n in\n (*for i = 0 to m - 1 do\n Printf.printf \"asd %d %d\\n\" d.(i) d'.(i)\n done;*)\n let bl = ref (-1) in\n let br = ref m in\n let r = ref 0 in\n while !r < m && d'.(!r) < 0 do\n incr r;\n done;\n if !br - !bl > !r - (-1) then (\n br := !r;\n bl := -1;\n );\n for l = 0 to m - 1 do\n while !r < m && (!r <= l || d'.(!r) <= d.(l)) do\n\tincr r;\n done;\n if d.(l) < inf && !br - !bl > !r - l then (\n\tbr := !r;\n\tbl := l;\n )\n done;\n (*Printf.printf \"qwe %d %d\\n\" !bl !br;*)\n let res = String.sub b 0 (!bl + 1) ^ String.sub b !br (m - !br) in\n if res = \"\"\n then Printf.printf \"-\\n\"\n else Printf.printf \"%s\\n\" res\n", "positive_code": [{"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make (ns+1) 0 in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tbegin\n\t\t(*\n\t\tInvariant: \n\t\t\t1. forall j' < js, arr[j'] is amount of matches between strings p and s[0..j'-1]\n\t\t\t2. kp - amount of matches between strings p[0..kp-1] and s[0..js-1] \n\t\tBase case: 1,2. vacuous truth\n\t\tTermination: js == ns, array range of indices j=[0..ns-1] contains amount of matches between p and corresponding substrings s[0..j-1]\n\t\t\t\tkp - maximal amount of matches between s[0..ns-1] (i.e. the whole string s) and p\n\t\t*)\n\t\twhile !js < ns do\n\n\t\t\tarr.(!js) <- !kp; (* now arr[!js] contains amount of matches between p and s[0..js-1] *)\n\n\t\t\tif (!kp < np) && (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\tend;\n\n\t\t\tjs := !js + 1;\n\n\t\tdone;\n\n\t\t(* the last value just duplicates amount if matches between the whole strings p and s *)\n\t\tarr.(!js) <- !kp;\n\n\t\tarr\n\tend\n;;\n\nlet right_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make (ns+1) 0 in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\n\t\t(*\n\t\tInvariant: \n\t\t\t1. forall j' > js, arr[j'] is amount of matches between strings p and s[j'..ns-1]\n\t\t\t2. kp - position of the last match (if any) in string p or np otherwise. \n\t\tBase case: 1,2. vacuous truth\n\t\tTermination: js == 0, array range of indices j=[1..ns-1] contains amount of matches between p and corresponding substrings s[j..ns-1]\n\t\t\t\t\tarr[ns] contains 0 as there is no matches beyond string length\n\t\t\t\tkp - maximal amount of matches between s[1..ns-1] and p\n\t\t*)\n\t\twhile !js > 0 do\n\n\t\t\tarr.(!js) <- (np - !kp);\n\n\t\t\tif (!kp > 0) && (String.get p (!kp-1) ) == (String.get s (!js-1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\n\t\t\tjs := !js - 1;\n\n\t\tdone;\n\n\t\t(* amount of matches between the whole strings p and s *)\n\t\tarr.(!js) <- (np - !kp);\n\n\t\tarr;\n\tend\n;;\n\nlet process_strings s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet l = left_arrangements s p in\n\tlet r = right_arrangements s p in\n\tlet best_ks = ref 0 in\n\tlet best_sum = ref 0 in\n\tbegin\n\t\tfor ks = 0 to ns do\n\t\t\tlet sum = l.(ks) + r.(ks) in\n\t\t\tif sum > !best_sum then\n\t\t\t\tbegin\n\t\t\t\t\tbest_sum := sum;\n\t\t\t\t\tbest_ks := ks;\n\t\t\t\tend;\n\t\tdone;\n\n\t\tlet res = if !best_sum <= np \n\t\t\t\tthen (String.sub p 0 l.(!best_ks)) ^ (String.sub p (np - r.(!best_ks)) r.(!best_ks))\n\t\t\t\telse p in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_subsequence_lengths a b =\n\n\tlet n = String.length a in\n\tlet m = String.length b in\n\tlet l = Array.make (n+1) 0 in\n\tlet j = ref 0 in\n\tbegin\n\n\tl.(0) <- !j;\n\n\tfor k=0 to (n-1) do\n\n\t\tif (!j < m) && ((String.get a k) == (String.get b !j)) then\n\t\t\tbegin\n\t\t\tj := !j + 1;\n\t\t\tend;\n\n\t\tl.(k+1) <- !j; (* now l[!js] contains amount of matches between b and a[0..js-1] *)\n\n\tdone;\n\n\tl\n\tend\n;;\n\nlet right_subsequence_lengths a b =\n\tlet n = String.length a in\n\tlet m = String.length b in\n\tlet r = Array.make (n+1) 0 in\n\tlet j = ref m in\n\tbegin\n\n\tr.(n) <- (m - !j);\n\n\tfor k = (n-1) downto 0 do\n\n\t\tif (!j > 0) && ((String.get a k ) == (String.get b (!j-1))) then\n\t\t\tbegin\n\t\t\tj := !j - 1;\n\t\t\tend;\n\n\t\tr.(k) <- (m - !j);\n\n\tdone;\n\n\tr;\n\tend\n;;\n\nlet longest_subsequence a b =\n\tlet n = String.length a in\n\tlet m = String.length b in\n\tlet l = left_subsequence_lengths a b in\n\tlet r = right_subsequence_lengths a b in\n\tlet s_best = ref (l.(0) + r.(0)) in\n\tlet k_best = ref 0 in\n\tbegin\n\tfor k = 1 to n do\n\t\tlet s = l.(k) + r.(k) in\n\t\tif s > !s_best then\n\t\t\tbegin\n\t\t\ts_best := s;\n\t\t\tk_best := k;\n\t\t\tend;\n\tdone;\n\n\tif !s_best >= m\n\t\tthen b\n\t\telse (String.sub b 0 l.(!k_best)) ^ (String.sub b (m - r.(!k_best)) r.(!k_best))\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" (fun a b -> print_result (longest_subsequence a b))\n;;\n\nread_input ()\n"}], "negative_code": [{"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\nlet left_mismatch s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tlet jl = ref 0 in (* index in s after last match with p *)\n\tbegin\n\t\twhile (!kp < np) && (!js < ns) \n\t\tdo\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\t\tjl := !js + 1;\n\t\t\tend;\n\t\t\tjs := !js + 1;\n\t\tdone; (* for k : (p_b..p_e) *)\n\t\t(!kp, !jl)\n\tend\n;;\n\nlet right_mismatch s p s_b p_b =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\t\twhile (!kp > p_b) && (!js > s_b) \n\t\tdo\n\t\t\tif (String.get p (!kp - 1) ) == (String.get s (!js - 1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\t\t\tjs := !js - 1;\n\t\tdone; (* for k : (p_b..p_e) *)\n\t\t!kp\n\tend\n;;\n\nlet process_strings s p =\n\tbegin\n\t\tlet m = String.length p in\n\t\tlet (lp, ls) = left_mismatch s p in\n\t\tlet rp = right_mismatch s p ls lp in\n\t\tlet nr = m - rp in\n\t\tlet res = (String.sub p 0 lp) ^ (String.sub p rp nr) in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tbegin\n\t\twhile (!kp < np) && (!js < ns) do\n\n\t\t\tarr.(!js) <- !kp;\n\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\tend;\n\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\twhile !js < ns do\n\t\t\tarr.(!js) <- np;\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\tarr\n\tend\n;;\n\nlet right_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\t\twhile (!kp > 0) && (!js > 0) do\n\n\t\t\tif (String.get p (!kp-1) ) == (String.get s (!js-1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\n\t\t\tjs := !js - 1;\n\n\t\t\tarr.(!js) <- (np - !kp);\n\t\tdone;\n\n\t\twhile (!js > 0) do\n\t\t\tjs := !js - 1;\n\t\t\tarr.(!js) <- np;\n\t\tdone;\n\n\t\tarr;\n\tend\n;;\n\nlet process_strings s p =\n\tlet n = String.length s in\n\tlet m = String.length p in\n\tlet l = left_arrangements s p in\n\tlet r = right_arrangements s p in\n\tlet best_k = ref 0 in\n\tlet best_sum = ref 0 in\n\tbegin\n\t\tfor k = 0 to (n-1) do\n\t\t\tlet sum = l.(k) + r.(k) in\n\t\t\tif sum > !best_sum then\n\t\t\t\tbegin\n\t\t\t\t\tbest_sum := sum;\n\t\t\t\t\tbest_k := k;\n\t\t\t\tend;\n\t\tdone;\n\n\t\tlet res = if !best_sum <= m\n\t\t\t\tthen (String.sub p 0 l.(!best_k)) ^ (String.sub p (m - r.(!best_k)) r.(!best_k))\n\t\t\t\telse p in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tbegin\n\t\twhile (!kp < np) && (!js < ns) do\n\n\t\t\tarr.(!js) <- !kp;\n\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\tend;\n\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\twhile !js < ns do\n\t\t\tarr.(!js) <- np;\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\tarr\n\tend\n;;\n\nlet right_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\t\twhile (!kp > 0) && (!js > 0) do\n\n\t\t\tif (String.get p (!kp-1) ) == (String.get s (!js-1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\n\t\t\tjs := !js - 1;\n\n\t\t\tarr.(!js) <- (np - !kp);\n\t\tdone;\n\n\t\twhile (!js > 0) do\n\t\t\tarr.(!js) <- np;\n\t\t\tjs := !js - 1;\n\t\tdone;\n\n\t\tarr;\n\tend\n;;\n\nlet process_strings s p =\n\tlet n = String.length s in\n\tlet m = String.length p in\n\tlet l = left_arrangements s p in\n\tlet r = right_arrangements s p in\n\tlet best_k = ref 0 in\n\tlet best_sum = ref 0 in\n\tbegin\n\t\tfor k = 0 to (n-1) do\n\t\t\tlet sum = l.(k) + r.(k) in\n\t\t\tif sum > !best_sum then\n\t\t\t\tbegin\n\t\t\t\t\tbest_sum := sum;\n\t\t\t\t\tbest_k := k;\n\t\t\t\tend;\n\t\tdone;\n\n\t\tlet res = (String.sub p 0 l.(!best_k)) ^ (String.sub p (m - r.(!best_k)) r.(!best_k)) in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tbegin\n\t\twhile (!kp < np) && (!js < ns) do\n\n\t\t\tarr.(!js) <- !kp;\n\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\tend;\n\n\t\t\tjs := !js + 1;\n\n\t\tdone;\n\n\t\tarr\n\tend\n;;\n\nlet right_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\t\twhile (!kp > 0) && (!js > 0) do\n\n\t\t\tif (String.get p (!kp-1) ) == (String.get s (!js-1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\n\t\t\tjs := !js - 1;\n\n\t\t\tarr.(!js) <- (np - !kp);\n\n\t\tdone;\n\n\t\tarr;\n\tend\n;;\n\nlet process_strings s p =\n\tlet n = String.length s in\n\tlet m = String.length p in\n\tlet l = left_arrangements s p in\n\tlet r = right_arrangements s p in\n\tlet best_k = ref 0 in\n\tlet best_sum = ref 0 in\n\tbegin\n\t\tfor k = 0 to (n-1) do\n\t\t\tlet sum = l.(k) + r.(k) in\n\t\t\tif sum > !best_sum then\n\t\t\t\tbegin\n\t\t\t\t\tbest_sum := sum;\n\t\t\t\t\tbest_k := k;\n\t\t\t\tend;\n\t\tdone;\n\n\t\tlet res = (String.sub p 0 l.(!best_k)) ^ (String.sub p (m - r.(!best_k)) r.(!best_k)) in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\n\nlet left_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tbegin\n\t\twhile (!kp < np) && (!js < ns) do\n\n\t\t\tarr.(!js) <- !kp;\n\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\tend;\n\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\twhile !js < ns do\n\t\t\tarr.(!js) <- np;\n\t\t\tjs := !js + 1;\n\t\tdone;\n\n\t\tarr\n\tend\n;;\n\nlet right_arrangements s p =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet arr = Array.make ns 0 in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tbegin\n\t\twhile (!kp > 0) && (!js > 0) do\n\n\t\t\tif (String.get p (!kp-1) ) == (String.get s (!js-1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\tend;\n\n\t\t\tjs := !js - 1;\n\n\t\t\tarr.(!js) <- (np - !kp);\n\t\tdone;\n\n\t\twhile (!js > 0) do\n\t\t\tjs := !js - 1;\n\t\t\tarr.(!js) <- np;\n\t\tdone;\n\n\t\tarr;\n\tend\n;;\n\nlet process_strings s p =\n\tlet n = String.length s in\n\tlet m = String.length p in\n\tlet l = left_arrangements s p in\n\tlet r = right_arrangements s p in\n\tlet best_k = ref 0 in\n\tlet best_sum = ref 0 in\n\tbegin\n\t\tfor k = 0 to (n-1) do\n\t\t\tlet sum = l.(k) + r.(k) in\n\t\t\tif sum > !best_sum then\n\t\t\t\tbegin\n\t\t\t\t\tbest_sum := sum;\n\t\t\t\t\tbest_k := k;\n\t\t\t\tend;\n\t\tdone;\n\n\t\tlet res = (String.sub p 0 l.(!best_k)) ^ (String.sub p (m - r.(!best_k)) r.(!best_k)) in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let print_result s = \n\tmatch s with\n\t| \"\" ->\n\t\tPrintf.printf \"-\\n\";\n\t| _ ->\n\t\tPrintf.printf \"%s\\n\" s;\n;;\n\nlet left_mismatch s p s_e p_e =\n\tlet kp = ref 0 in\n\tlet js = ref 0 in\n\tlet jl = ref 0 in (* index in s after last match with p *)\n\tbegin\n\t\twhile (!kp < p_e) && (!js < s_e) \n\t\tdo\n\t\t\tif (String.get p !kp) == (String.get s !js) then\n\t\t\tbegin\n\t\t\t\tkp := !kp + 1;\n\t\t\t\tjl := !js + 1;\n\t\t\tend;\n\t\t\tjs := !js + 1;\n\t\tdone; (* for k : (p_b..p_e) *)\n\t\t(!kp, !jl)\n\tend\n;;\n\nlet right_mismatch s p s_b p_b =\n\tlet ns = String.length s in\n\tlet np = String.length p in\n\tlet kp = ref np in\n\tlet js = ref ns in\n\tlet jl = ref ns in\n\tbegin\n\t\twhile (!kp > p_b) && (!js > s_b) \n\t\tdo\n\t\t\tif (String.get p (!kp - 1) ) == (String.get s (!js - 1) ) then\n\t\t\tbegin\n\t\t\t\tkp := !kp - 1;\n\t\t\t\tjl := !js - 1;\n\t\t\tend;\n\t\t\tjs := !js - 1;\n\t\tdone; (* for k : (p_b..p_e) *)\n\t\t(!kp, !jl)\n\tend\n;;\n\nlet process_strings s p =\n\tbegin\n\t\tlet n = String.length s in\n\t\tlet m = String.length p in\n\t\tlet (lp1, ls1) = left_mismatch s p n m in\n\t\tlet (rp1, _) = right_mismatch s p ls1 lp1 in\n\t\tlet (rp2, rs2) = right_mismatch s p 0 0 in\n\t\tlet (lp2, _) = left_mismatch s p rs2 rp2 in\n\t\tlet nr1 = m - rp1 in\n\t\tlet nr2 = m - rp2 in\n\t\tlet n1 = lp1 + nr1 in\n\t\tlet n2 = lp2 + nr2 in\n\t\tlet res = if (n1 > n2) \n\t\t\tthen (String.sub p 0 lp1) ^ (String.sub p rp1 nr1)\n\t\t\telse (String.sub p 0 lp2) ^ (String.sub p rp2 nr2) in\n\t\tprint_result res;\n\tend\n;;\n\nlet read_input () = \n\tScanf.bscanf Scanf.Scanning.stdin \" %s %s \" process_strings\n;;\n\nread_input ()\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let a = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let c2i c = Char.code c - Char.code 'a' in\n let n = String.length a\n and m = String.length b in\n let inf = 1000000000 in\n let prev = Array.make_matrix 26 n 0 in\n let next = Array.make_matrix 26 n 0 in\n let p = Array.make 26 inf in\n let p' = Array.make 26 (-1) in\n let _ =\n for i = 0 to n - 1 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t prev.(j).(i) <- p'.(j)\n\tdone;\n\tp'.(c) <- i;\n done;\n for i = n - 1 downto 0 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t next.(j).(i) <- p.(j)\n\tdone;\n\tp.(c) <- i;\n done;\n in\n let d = Array.make m (-1) in\n let pos = ref p.(c2i b.[0]) in\n let _ =\n d.(0) <- !pos;\n for i = 1 to m - 1 do\n if !pos < inf then (\n\tlet c = c2i b.[i] in\n\t pos := next.(c).(!pos);\n );\n d.(i) <- !pos;\n done;\n in\n let d' = Array.make m (-1) in\n let _ =\n pos := p'.(c2i b.[m - 1]);\n d'.(m - 1) <- !pos;\n for i = m - 2 downto 0 do\n if !pos >= 0 then (\n\tlet c = c2i b.[i] in\n\t pos := prev.(c).(!pos);\n );\n d'.(i) <- !pos;\n done;\n in\n for i = 0 to m - 1 do\n Printf.printf \"asd %d %d\\n\" d.(i) d'.(i)\n done;\n let bl = ref (-1) in\n let br = ref m in\n let r = ref 0 in\n (*while !r < m && d'.(!r) < 0 do\n incr r;\n done;*)\n if !br - !bl > !r - (-1) then (\n br := !r;\n bl := -1;\n );\n for l = 0 to m - 1 do\n while !r < m && (!r <= l || d'.(!r) <= d.(l)) do\n\tincr r;\n done;\n if d.(l) < inf && !br - !bl > !r - l then (\n\tbr := !r;\n\tbl := l;\n )\n done;\n (*Printf.printf \"qwe %d %d\\n\" !bl !br;*)\n let res = String.sub b 0 (!bl + 1) ^ String.sub b !br (m - !br) in\n if res = \"\"\n then Printf.printf \"-\\n\"\n else Printf.printf \"%s\\n\" res\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let a = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let c2i c = Char.code c - Char.code 'a' in\n let n = String.length a\n and m = String.length b in\n let inf = 1000000000 in\n let prev = Array.make_matrix 26 n 0 in\n let next = Array.make_matrix 26 n 0 in\n let p = Array.make 26 inf in\n let p' = Array.make 26 (-1) in\n let _ =\n for i = 0 to n - 1 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t prev.(j).(i) <- p'.(j)\n\tdone;\n\tp'.(c) <- i;\n done;\n for i = n - 1 downto 0 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t next.(j).(i) <- p.(j)\n\tdone;\n\tp.(c) <- i;\n done;\n in\n let d = Array.make m (-1) in\n let pos = ref p.(c2i b.[0]) in\n let _ =\n d.(0) <- !pos;\n for i = 1 to m - 1 do\n if !pos < inf then (\n\tlet c = c2i b.[i] in\n\t pos := next.(c).(!pos);\n );\n d.(i) <- !pos;\n done;\n in\n let d' = Array.make m (-1) in\n let _ =\n pos := p'.(c2i b.[m - 1]);\n d'.(m - 1) <- !pos;\n for i = m - 2 downto 0 do\n if !pos >= 0 then (\n\tlet c = c2i b.[i] in\n\t pos := prev.(c).(!pos);\n );\n d'.(i) <- !pos;\n done;\n in\n (*for i = 0 to m - 1 do\n Printf.printf \"asd %d %d\\n\" d.(i) d'.(i)\n done;*)\n let bl = ref (-1) in\n let br = ref m in\n let r = ref 0 in\n for l = 0 to m - 1 do\n while !r < m && d'.(!r) <= d.(l) do\n\tincr r;\n done;\n if d.(l) < inf && !br - !bl > !r - l then (\n\tbr := !r;\n\tbl := l;\n )\n done;\n (*Printf.printf \"qwe %d %d\\n\" !bl !br;*)\n let res = String.sub b 0 (!bl + 1) ^ String.sub b !br (m - !br) in\n if res = \"\"\n then Printf.printf \"-\\n\"\n else Printf.printf \"%s\\n\" res\n"}, {"source_code": "let _ =\n let sb = Scanf.Scanning.stdib in\n let a = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let b = Scanf.bscanf sb \"%s \" (fun s -> s) in\n let c2i c = Char.code c - Char.code 'a' in\n let n = String.length a\n and m = String.length b in\n let inf = 1000000000 in\n let prev = Array.make_matrix 26 n 0 in\n let next = Array.make_matrix 26 n 0 in\n let p = Array.make 26 inf in\n let p' = Array.make 26 (-1) in\n let _ =\n for i = 0 to n - 1 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t prev.(j).(i) <- p'.(j)\n\tdone;\n\tp'.(c) <- i;\n done;\n for i = n - 1 downto 0 do\n let c = c2i a.[i] in\n\tfor j = 0 to 25 do\n\t next.(j).(i) <- p.(j)\n\tdone;\n\tp.(c) <- i;\n done;\n in\n let d = Array.make m (-1) in\n let pos = ref p.(c2i b.[0]) in\n let _ =\n d.(0) <- !pos;\n for i = 1 to m - 1 do\n if !pos < inf then (\n\tlet c = c2i b.[i] in\n\t pos := next.(c).(!pos);\n );\n d.(i) <- !pos;\n done;\n in\n let d' = Array.make m (-1) in\n let _ =\n pos := p'.(c2i b.[m - 1]);\n d'.(m - 1) <- !pos;\n for i = m - 2 downto 0 do\n if !pos >= 0 then (\n\tlet c = c2i b.[i] in\n\t pos := prev.(c).(!pos);\n );\n d'.(i) <- !pos;\n done;\n in\n (*for i = 0 to m - 1 do\n Printf.printf \"asd %d %d\\n\" d.(i) d'.(i)\n done;*)\n let bl = ref (-1) in\n let br = ref m in\n let r = ref 0 in\n for l = 0 to m - 1 do\n while !r < m && d'.(!r) <= d.(l) do\n\tincr r;\n done;\n if d.(l) < m && !br - !bl > !r - l then (\n\tbr := !r;\n\tbl := l;\n )\n done;\n (*Printf.printf \"asd %d %d\\n\" !bl !br;*)\n let res = String.sub b 0 (!bl + 1) ^ String.sub b !br (m - !br) in\n if res = \"\"\n then Printf.printf \"-\\n\"\n else Printf.printf \"%s\\n\" res\n"}], "src_uid": "89aef6720eac7376ce0a657d46c3c5b7"} {"source_code": "type state = Unseen | One | Both\n\nlet () =\n let n = Scanf.scanf \"%d\" (fun x -> x) in\n let pairs = Array.make (n + 1) Unseen in\n let on_table = ref 0 in\n let m = ref 0 in\n for i = 1 to 2*n do\n let k = Scanf.scanf \" %d\" (fun x -> x) in\n match pairs.(k) with\n | Unseen -> begin\n pairs.(k) <- One;\n incr on_table;\n m := max !m !on_table\n end\n | One -> begin\n pairs.(k) <- Both;\n decr on_table\n end\n | Both -> ()\n done;\n Printf.printf \"%d\\n\" !m\n", "positive_code": [{"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 x = Array.init (2*n) read_int in\n\n let out = Array.make (2*n) false in\n\n let rec loop i nout maxout = if i=2*n then maxout else (\n let sock = x.(i)-1 in\n if out.(sock) then (\n out.(sock) <- false;\n loop (i+1) (nout-1) maxout\n ) else (\n out.(sock) <- true;\n loop (i+1) (nout+1) (max maxout (nout+1))\n )\n ) in\n\n printf \"%d\\n\" (loop 0 0 0)\n"}], "negative_code": [{"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 x = Array.init n read_int in\n\n let out = Array.make n false in\n\n let rec loop i nout maxout = if i=n then maxout else (\n let sock = x.(i)-1 in\n if out.(sock) then (\n out.(sock) <- false;\n loop (i+1) (nout-1) maxout\n ) else (\n out.(sock) <- true;\n loop (i+1) (nout+1) (max maxout (nout+1))\n )\n ) in\n\n printf \"%d\\n\" (loop 0 0 0)\n"}], "src_uid": "7f98c9258f3e127a782041c421d6317b"} {"source_code": "open Scanf;;\nscanf \"%d %d\\n\" (fun n m ->\n let mat=Array.make_matrix n m 0 in\n let set i j x= mat.(i).(j) <- x in\n for i=0 to n-1 do\n for j=0 to m-2 do\n scanf \"%d \" (set i j) \n done;\n scanf \"%d\\n\" (set i (m-1))\n done;\n let all_N' = List.fold_left (fun f x->f&&x>0) true in\n let rec r_to_list x j=\n if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in\n let rec c_to_list y i=\n if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in\n let test_r r=r_to_list r 0 |> all_N' in\n let test_c c=c_to_list c 0 |> all_N' in\n let do_r r=\n for j=0 to m-1 do\n mat.(r).(j)<-mat.(r).(j)-1\n done; \"row \"^(string_of_int (r+1)) in\n let do_c c=\n for i=0 to n-1 do\n mat.(i).(c)<-mat.(i).(c)-1\n done; \"col \"^(string_of_int (c+1)) in\n let solve() = \n let rec solve_r r acc=match test_r r with\n | true -> solve_r r (do_r r ::acc)\n | false -> if r=n-1 then acc else solve_r (r+1) acc in\n let rec solve_c c acc=match test_c c with\n | true -> solve_c c (do_c c ::acc)\n | false -> if c=m-1 then acc else solve_c (c+1) acc in\n if n>m then solve_r 0 [] @ solve_c 0 [] else solve_c 0 [] @ solve_r 0 [] in\n let flag_N'=ref false in\n let test_N'() = \n for i=0 to n-1 do\n for j=0 to m-1 do\n if mat.(i).(j)>0 then flag_N':=true\n done\n done in\n let write l=\n let rec print_list =function\n | [] -> ()\n | h :: t -> print_endline h;print_list t in\n print_int (List.length l);\n print_newline();\n print_list l in\n let ans=solve() in\n test_N'();\n if !flag_N' then print_endline \"-1\" else write ans\n)", "positive_code": [{"source_code": "open Scanf;;\nscanf \"%d %d\" (fun n m ->\n let mat=Array.make_matrix n m 0 in\n for i=0 to n-1 do\n for j=0 to m-1 do\n scanf \" %d\" (fun x->mat.(i).(j) <- x)\n done;\n done;\n let all_N' =List.for_all (fun x->x>0) in \n let rec r_to_list x j=\n if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in\n let rec c_to_list y i=\n if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in\n let test_r r=r_to_list r 0 |> all_N' and test_c c=c_to_list c 0 |> all_N' in\n let dec i j = mat.(i).(j)<-mat.(i).(j)-1 in\n let do_r r=\n for j=0 to m-1 do\n dec r j\n done; \"row \"^(string_of_int (r+1))\n and do_c c=\n for i=0 to n-1 do\n dec i c\n done; \"col \"^(string_of_int (c+1)) in\n let solve() = \n let rec solve_r r acc=match test_r r with\n | true -> solve_r r (do_r r ::acc)\n | false -> if r=n-1 then acc else solve_r (r+1) acc\n and solve_c c acc=match test_c c with\n | true -> solve_c c (do_c c ::acc)\n | false -> if c=m-1 then acc else solve_c (c+1) acc in\n if n0 then flag_N':=true\n done\n done in\n let write l=\n let rec print_list =function\n | [] -> ()\n | h :: t -> print_endline h;print_list t in\n print_int (List.length l);\n print_newline();\n print_list l in\n let ans=solve() in\n test_N'();\n if !flag_N' then print_endline \"-1\" else write ans\n)"}], "negative_code": [{"source_code": "open Scanf;;\nscanf \"%d %d\\n\" (fun n m ->\n let mat=Array.make_matrix n m 0 in\n let set i j x= mat.(i).(j) <- x in\n for i=0 to n-1 do\n for j=0 to m-2 do\n scanf \"%d \" (set i j) \n done;\n scanf \"%d\\n\" (set i (m-1))\n done;\n let has_N' = List.fold_left (fun f x->f&&x>0) true in\n let rec r_to_list x j=\n if j=m-1 then [] else mat.(x).(j) :: r_to_list x (j+1) in\n let rec c_to_list y i=\n if i=n-1 then [] else mat.(i).(y) :: c_to_list y (i+1) in\n let test_r r=r_to_list r 0 |> has_N' in\n let test_c c=c_to_list c 0 |> has_N' in\n let do_r r=\n for j=0 to m-1 do\n mat.(r).(j)<-mat.(r).(j)-1\n done; \"row \"^(string_of_int (r+1)) in\n let do_c c=\n for i=0 to n-1 do\n mat.(i).(c)<-mat.(i).(c)-1\n done; \"col \"^(string_of_int (c+1)) in\n let do_point_rf r c =match test_r r, test_c c with\n | true ,_ -> do_r r\n | _ , true -> do_c c\n | _ ->raise Not_found in\n let do_point_cf r c =match test_r r, test_c c with\n | _ , true -> do_c c\n | true ,_ -> do_r r\n | _ ->raise Not_found in\n let do_point r c = if r (-1,-1)\n |r,c when c=m-1 -> (r+1,0)\n |r,c -> (r,c+1) in\n let test_point r c = mat.(r).(c)>0 in\n let solve() = \n let rec solve_inn r c acc=match test_point r c with\n | true -> solve_inn r c (do_point r c ::acc)\n | false -> \n match next (r,c) with\n | -1,-1 ->acc\n | nr,nc ->solve_inn nr nc acc in solve_inn 0 0 [] in\n let write l=\n let rec print_list =function\n | [] -> ()\n | h :: t -> print_endline h;print_list t in\n print_int (List.length l);\n print_newline();\n print_list l in\n try write (solve()) with\n Not_found -> print_endline \"-1\"\n)"}, {"source_code": "open Scanf;;\nscanf \"%d %d\\n\" (fun n m ->\n let mat=Array.make_matrix n m 0 in\n let set i j x= mat.(i).(j) <- x in\n for i=0 to n-1 do\n for j=0 to m-2 do\n scanf \"%d \" (set i j) \n done;\n scanf \"%d\\n\" (set i (m-1))\n done;\n let all_N' = List.fold_left (fun f x->f&&x>0) true in\n let rec r_to_list x j=\n if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in\n let rec c_to_list y i=\n if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in\n let test_r r=r_to_list r 0 |> all_N' in\n let test_c c=c_to_list c 0 |> all_N' in\n let do_r r=\n for j=0 to m-1 do\n mat.(r).(j)<-mat.(r).(j)-1\n done; \"row \"^(string_of_int (r+1)) in\n let do_c c=\n for i=0 to n-1 do\n mat.(i).(c)<-mat.(i).(c)-1\n done; \"col \"^(string_of_int (c+1)) in\n let solve() = \n let rec solve_r r acc=match test_r r with\n | true -> solve_r r (do_r r ::acc)\n | false -> if r=n-1 then acc else solve_r (r+1) acc in\n let rec solve_c c acc=match test_c c with\n | true -> solve_c c (do_c c ::acc)\n | false -> if c=m-1 then acc else solve_c (c+1) acc in\n if n0 then flag_N':=true\n done\n done in\n let write l=\n let rec print_list =function\n | [] -> ()\n | h :: t -> print_endline h;print_list t in\n print_int (List.length l);\n print_newline();\n print_list l in\n let ans=solve() in\n test_N'();\n if !flag_N' then print_endline \"-1\" else write ans\n)"}, {"source_code": "open Scanf;;\nscanf \"%d %d\\n\" (fun n m ->\n let mat=Array.make_matrix n m 0 in\n let set i j x= mat.(i).(j) <- x in\n for i=0 to n-1 do\n for j=0 to m-2 do\n scanf \"%d \" (set i j) \n done;\n scanf \"%d\\n\" (set i (m-1))\n done;\n let has_N' = List.fold_left (fun f x->f&&x>0) true in\n let rec r_to_list x j=\n if j=m-1 then [] else mat.(x).(j) :: r_to_list x (j+1) in\n let rec c_to_list y i=\n if i=n-1 then [] else mat.(i).(y) :: c_to_list y (i+1) in\n let test_r r=r_to_list r 0 |> has_N' in\n let test_c c=c_to_list c 0 |> has_N' in\n let do_r r=\n for j=0 to m-1 do\n mat.(r).(j)<-mat.(r).(j)-1\n done; \"row \"^(string_of_int (r+1)) in\n let do_c c=\n for i=0 to n-1 do\n mat.(i).(c)<-mat.(i).(c)-1\n done; \"col \"^(string_of_int (c+1)) in\n let do_point r c =match test_r r, test_c c with\n | true ,_ -> do_r r\n | _ , true -> do_c c\n | _ ->raise Not_found in\n let next =function\n |r,c when r=n-1 && c=m-1 -> (-1,-1)\n |r,c when c=m-1 -> (r+1,0)\n |r,c -> (r,c+1) in\n let test_point r c = mat.(r).(c)>0 in\n let solve() = \n let rec solve_inn r c acc=match test_point r c with\n | true -> solve_inn r c (do_point r c ::acc)\n | false -> \n match next (r,c) with\n | -1,-1 ->acc\n | nr,nc ->solve_inn nr nc acc in solve_inn 0 0 [] in\n let write l=\n let rec print_list =function\n | [] -> ()\n | h :: t -> print_endline h;print_list t in\n print_int (List.length l);\n print_newline();\n print_list l in\n try write (solve()) with\n Not_found -> print_endline \"-1\"\n)"}], "src_uid": "b19ab2db46484f0c9b49cf261502bf64"} {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\ntype 'a employee = 'a * 'a list (*int is employee's immediate manager; int list are her subordinates*)\n\nlet a = Array.make (n+1) (0,[]);;\n\nlet manager (z:int employee) =\n match z with\n | (i,_) -> i\n\nlet subo (z:int employee) = \n match z with\n | (_,il) -> il\n\nlet adds (t:int employee) x = \n match t with\n (_,z) -> x::z\n\nfor i = 1 to n do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n if j = -1 then\n begin\n let il = subo a.(i) in\n let i2 = adds a.(0) i in\n a.(i) <- (manager a.(i),il); a.(0) <- (manager a.(0),i2)\n end\n else\n begin\n a.(i) <- (j,subo a.(i)); a.(j) <- (manager a.(j), adds a.(j) i)\n end\ndone\n\n(*\nlet printe (z:int employee) =\n match z with \n | (i,il) -> printf \"%d \" i; List.iter (fun x -> printf \"%d \" x) il\n\nlet () = printe a.(11)\n\nlet () = print_endline \"\"\n*)\n\nlet rec height (z:int employee) =\n match z with\n |(_,[]) -> 1\n |(_,il) -> \n List.fold_right (fun x y -> max x y) \n ( List.map (fun i -> 1 + (height a.(i))) il) (-1)\nin\nlet m = height a.(0) in\nprintf \"%d\\n\" (m-1)\n\n\n", "positive_code": [{"source_code": "type tree = Leaf of int\n | Node of tree list\n\nlet rec makeList numList num =\n match numList with\n | h :: t -> (num, h) :: (makeList t (num+1))\n | _ -> []\n\nlet rec findOrigin numList =\n match numList with\n | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)\n else findOrigin t\n | _ -> []\n\nlet rec findNum numList num = \n match numList with\n | (h, n) :: t -> if (n == num) then h :: (findNum t num)\n else findNum t num\n | _ -> []\n\n\nlet makeTree numList =\n let originList = findOrigin numList in\n let rec makeList nList =\n match nList with\n | h :: t ->\n let newList = findNum numList h in\n Node(Leaf(h) :: makeList newList) :: (makeList t)\n | _ -> [] in\n makeList originList\n\nlet nodeCount tree =\n let rec node tree count =\n match tree with\n | Node(h::t) :: tail ->\n let c = node (h::t) (count+1) in\n c @ (node tail count)\n | Leaf(h) :: t ->\n node t count\n | _ -> count ::[] in\n let countList = node tree 1 in\n let rec maxCount cList max =\n match cList with\n | h :: t -> if (max > h) then maxCount t max\n else maxCount t h\n | _ -> max in\n maxCount countList 1\n\nlet printLeaf leaf =\n match leaf with\n | Leaf(h) -> let _ = print_string (\"Leaf \") in\n let _ = print_int h in\n print_string \" \"\n | _ -> print_string \" \"\n\nlet rec printNode node =\n match node with\n | Node(h :: t) :: tail -> let _ = print_string (\"[Node \") in\n let _ = printLeaf h in\n let _ = printNode t in\n let _ = print_string \"] \" in\n printNode tail\n | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in\n printNode tail\n | _ -> print_string \" \"\n\nlet num = read_int()\n\nlet rec inputList num =\n if (num != 0) then \n let k = read_int() in\n k :: (inputList (num-1))\n else\n []\nlet numList = makeList (inputList num) 1\nlet k = makeTree numList\n(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1\n\nlet k = makeTree numList\n\nlet _ = printNode k\n\nlet _ = print_string\"\\n\\n\"\n*)\nlet _ = print_int((nodeCount k)-1)\n\n\n"}], "negative_code": [{"source_code": "type tree = Leaf of int\n | Node of tree list\n\nlet rec makeList numList num =\n match numList with\n | h :: t -> (num, h) :: (makeList t (num+1))\n | _ -> []\n\nlet rec findOrigin numList =\n match numList with\n | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)\n else findOrigin t\n | _ -> []\n\nlet rec findNum numList num = \n match numList with\n | (h, n) :: t -> if (n == num) then h :: (findNum t num)\n else findNum t num\n | _ -> []\n\n\nlet makeTree numList =\n let originList = findOrigin numList in\n let rec makeList nList =\n match nList with\n | h :: t ->\n let newList = findNum numList h in\n Node(Leaf(h) :: makeList newList) :: (makeList t)\n | _ -> [] in\n makeList originList\n\nlet nodeCount tree =\n let rec node tree count =\n match tree with\n | Node(h::t) :: tail ->\n let c = node (h::t) (count+1) in\n c @ (node tail count)\n | Leaf(h) :: t ->\n node t count\n | _ -> count ::[] in\n let countList = node tree 1 in\n let rec maxCount cList max =\n match cList with\n | h :: t -> if (max > h) then maxCount t max\n else maxCount t h\n | _ -> max in\n let rec printList m =\n match m with\n | h :: t -> let _ = print_int h in\n let _ = print_string \" \" in\n printList t\n | _ -> print_string \" \\n\\n\" in\n let _ = printList countList in\n maxCount countList 1\n\nlet printLeaf leaf =\n match leaf with\n | Leaf(h) -> let _ = print_string (\"Leaf \") in\n let _ = print_int h in\n print_string \" \"\n | _ -> print_string \" \"\n\nlet rec printNode node =\n match node with\n | Node(h :: t) :: tail -> let _ = print_string (\"[Node \") in\n let _ = printLeaf h in\n let _ = printNode t in\n let _ = print_string \"] \" in\n printNode tail\n | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in\n printNode tail\n | _ -> print_string \" \"\n\nlet num = read_int()\n\nlet rec inputList num =\n if (num != 0) then \n let k = read_int() in\n k :: (inputList (num-1))\n else\n []\nlet numList = makeList (inputList num) 1\nlet k = makeTree numList\n(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1\n\nlet k = makeTree numList\n\nlet _ = printNode k\n\nlet _ = print_string\"\\n\\n\"\n*)\nlet _ = print_int((nodeCount k)-1)\n\n\n"}, {"source_code": "type tree = Leaf of int\n | Node of tree list\n\nlet rec makeList numList num =\n match numList with\n | h :: t -> (num, h) :: (makeList t (num+1))\n | _ -> []\n\nlet rec findOrigin numList =\n match numList with\n | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)\n else findOrigin t\n | _ -> []\n\nlet rec findNum numList num = \n match numList with\n | (h, n) :: t -> if (n == num) then h :: (findNum t num)\n else findNum t num\n | _ -> []\n\n\nlet makeTree numList =\n let originList = findOrigin numList in\n let rec makeList nList =\n match nList with\n | h :: t ->\n let newList = findNum numList h in\n Node(Leaf(h) :: makeList newList) :: (makeList t)\n | _ -> [] in\n makeList originList\n\nlet nodeCount tree =\n let rec node tree count =\n match tree with\n | Node(h::t) :: tail ->\n let c = node t count in\n c @ (node t (count+1))\n | _ -> count ::[] in\n let countList = node tree 1 in\n let rec maxCount cList max =\n match cList with\n | h :: t -> if (max > h) then maxCount t max\n else maxCount t h\n | _ -> max in\n maxCount countList 1\n\nlet printLeaf leaf =\n match leaf with\n | Leaf(h) -> let _ = print_string (\"Leaf \") in\n let _ = print_int h in\n print_string \" \"\n | _ -> print_string \" \"\n\nlet rec printNode node =\n match node with\n | Node(h :: t) :: tail -> let _ = print_string (\"[Node \") in\n let _ = printLeaf h in\n let _ = printNode t in\n let _ = print_string \"] \" in\n printNode tail\n | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in\n printNode tail\n | _ -> print_string \" \"\n\nlet num = read_int()\n\nlet rec inputList num =\n if (num != 0) then \n let k = read_int() in\n k :: (inputList (num-1))\n else\n []\nlet numList = makeList (inputList num) 1\nlet k = makeTree numList\n\n(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1\n\nlet k = makeTree numList\n\nlet _ = printNode k\n\nlet _ = print_string\"\\n\\n\"\n*)\nlet _ = print_int((nodeCount k)-1)\n\n\n"}, {"source_code": "open Scanf\nopen Printf\n\nlet n = Scanf.scanf \"%d \" ( fun x -> x )\n\ntype 'a employee = 'a * 'a list (*int is employee's immediate manager; int list are her subordinates*)\n\nlet a = Array.make (n+1) (0,[]);;\n\nlet manager (z:int employee) =\n match z with\n | (i,_) -> i\n\nlet subo (z:int employee) = \n match z with\n | (_,il) -> il\n\nlet adds (t:int employee) x = \n match t with\n (_,z) -> x::z\n\nfor i = 1 to n do\n let j = Scanf.scanf \"%d \" ( fun x -> x ) in\n if j = -1 then\n begin\n let il = subo a.(i) in\n let i2 = adds a.(0) i in\n a.(i) <- (0,il); a.(0) <- (0,i2)\n end\n else\n begin\n a.(i) <- (j,[]); a.(j) <- (manager a.(j), adds a.(j) i)\n end\ndone\n\n(*\nlet printe (z:int employee) =\n match z with \n | (i,il) -> printf \"%d \" i; List.iter (fun x -> printf \"%d \" x) il\n\nlet () = printe a.(0)\n*)\n\nlet rec height (z:int employee) =\n match z with\n |(_,[]) -> 1\n |(_,il) -> \n List.fold_right (fun x y -> max x y) \n ( List.map (fun i -> 1 + (height a.(i))) il) (-1)\nin\nlet m = height a.(0) in\nprintf \"%d\\n\" (m-1)\n\n\n"}], "src_uid": "8d911f79dde31f2c6f62e73b925e6996"} {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype sgn = POS | NEG;;\nlet mul x y = match (x, y) with\n\t| (POS, x) -> x\n\t| (NEG, POS) -> NEG\n\t| (NEG, NEG) -> POS\n;;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (sgn * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (POS, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (NEG, (a, b)))\n\t| a::b::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (POS, (a, b)))::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (NEG, (a, b)))::l)\n\t\telse (\n\t\t\tlet c::l = l in\n\t\t\tlet z = xy c in\n\t\t\tif (r (plus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((plus x z), (POS, (a, c)))::b::l)\n\t\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((minus x z), (NEG, (a, c)))::b::l)\n\t\t\telse if (r (plus y z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((plus y z), (POS, (b, c)))::a::l)\n\t\t\telse if (r (minus y z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((minus y z), (NEG, (b, c)))::a::l)\n\t\t\telse\n\t\t\t\tfailwith \"lochas\"\n\t\t)\n\t)\n;;\nlet ret = Array.make n NEG;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2\n;;\nfind POS (fix (read 0));;\nArray.iter (fun x -> match x with POS -> puts \"1 \" | NEG -> puts \"-1 \") ret;;", "positive_code": [{"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (int * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (1, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (-1, (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (1, (a, b)))::c::l)\n\t\telse if (r (plus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x z), (1, (a, c)))::b::l)\n\t\telse if (r (plus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus y z), (1, (b, c)))::a::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (-1, (a, b)))::c::l)\n\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x z), (-1, (a, c)))::b::l)\n\t\telse if (r (minus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus y z), (-1, (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 0;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2\n;;\nlet c = fix (read 0);;\nlet (x, y) = xy c;;\nfind 1 c;;\nArray.iter (fun x -> if x = 1 then puts \"1 \" else puts \"-1 \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nopen Printf\nopen Scanf\nlet scan_int() = bscanf Scanning.stdib \" %d \" (fun x -> x);;\nlet print_int x = printf \"%d\" x;;\nlet puts s = printf s;;\nlet n = scanf \"%d\" (fun x -> x);;\ntype sgn = POS | NEG;;\nlet mul x y = match (x, y) with\n\t| (POS, x) -> x\n\t| (NEG, POS) -> NEG\n\t| (NEG, NEG) -> POS\n;;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (sgn * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (POS, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (NEG, (a, b)))\n\t| a::b::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (POS, (a, b)))::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (NEG, (a, b)))::l)\n\t\telse (\n\t\t\tlet c::l = l in\n\t\t\tlet z = xy c in\n\t\t\tif (r (plus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((plus x z), (POS, (a, c)))::b::l)\n\t\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((minus x z), (NEG, (a, c)))::b::l)\n\t\t\telse \n\t\t\t\tfix ((\n\t\t\t\t\tif (r (plus y z)) <= 1000000000000L then \n\t\t\t\t\t\tCombine((plus y z), (POS, (b, c)))\n\t\t\t\t\telse\n\t\t\t\t\t\tCombine((minus y z), (NEG, (b, c)))\n\t\t\t\t)::a::l)\n\t\t)\n\t)\n;;\nlet ret = Array.make n NEG;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2\n;;\nfind POS (fix (read 0));;\nArray.iter (fun x -> match x with POS -> puts \"1 \" | NEG -> puts \"-1 \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse if ryzm = rmin then\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 0;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2\n;;\nlet rec check l = match l with\n\t| Leaf((x,y), i) -> puts \"(\";print_int y;puts \")\";\n\t| Combine((x, y), ((w1, w2), (l1, l2)))-> \n\tputs \"(\";\n\tcheck l1;\n\tputs (if(w2==1) then \"+\" else \"-\");\n\tcheck l2;\n\tputs \")\";\n;;\nlet c = fix (read 0);;\nif r (xy c) > (Int64.mul 1500000L 1500000L)\n\tthen failwith \"Oh shit\";;\nlet (x, y) = xy c;;\n(*Printf.printf \"%d %d\\n\" x y;;\nputs \"\\n\";\ncheck c;;*)\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype sgn = POS | NEG;;\nlet mul x y = match (x, y) with\n\t| (POS, x) -> x\n\t| (NEG, POS) -> NEG\n\t| (NEG, NEG) -> POS\n;;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (sgn * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (POS, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (NEG, (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (POS, (a, b)))::c::l)\n\t\telse if (r (plus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x z), (POS, (a, c)))::b::l)\n\t\telse if (r (plus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus y z), (POS, (b, c)))::a::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (NEG, (a, b)))::c::l)\n\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x z), (NEG, (a, c)))::b::l)\n\t\telse if (r (minus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus y z), (NEG, (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n NEG;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2\n;;\nlet c = fix (read 0);;\nlet (x, y) = xy c;;\nfind POS c;;\nArray.iter (fun x -> match x with POS -> puts \"1 \" | NEG -> puts \"-1 \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype sgn = POS | NEG;;\nlet mul x y = match (x, y) with\n\t| (POS, x) -> x\n\t| (NEG, POS) -> NEG\n\t| (NEG, NEG) -> POS\n;;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (sgn * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (POS, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (NEG, (a, b)))\n\t| a::b::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (POS, (a, b)))::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (NEG, (a, b)))::l)\n\t\telse (\n\t\t\tlet c::l = l in\n\t\t\tlet z = xy c in\n\t\t\tif (r (plus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((plus x z), (POS, (a, c)))::b::l)\n\t\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\t\tfix (Combine((minus x z), (NEG, (a, c)))::b::l)\n\t\t\telse \n\t\t\t\tfix ((\n\t\t\t\t\tif (r (plus y z)) <= 1000000000000L then \n\t\t\t\t\t\tCombine((plus y z), (POS, (b, c)))\n\t\t\t\t\telse\n\t\t\t\t\t\tCombine((minus y z), (NEG, (b, c)))\n\t\t\t\t)::a::l)\n\t\t)\n\t)\n;;\nlet ret = Array.make n NEG;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2\n;;\nfind POS (fix (read 0));;\nArray.iter (fun x -> match x with POS -> puts \"1 \" | NEG -> puts \"-1 \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (int * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (1, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (-1, (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tif (r (plus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x y), (1, (a, b)))::c::l)\n\t\telse if (r (plus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus x z), (1, (a, c)))::b::l)\n\t\telse if (r (plus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((plus y z), (1, (b, c)))::a::l)\n\t\telse if (r (minus x y)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x y), (-1, (a, b)))::c::l)\n\t\telse if (r (minus x z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus x z), (-1, (a, c)))::b::l)\n\t\telse if (r (minus y z)) <= 1000000000000L then\n\t\t\tfix (Combine((minus y z), (-1, (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 0;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2\n;;\nlet c = fix (read 0);;\nlet (x, y) = xy c;;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = Scanf.scanf \"%d\" (fun x -> x);;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * (int * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tlet x = scan_int() in\n\t\tlet y = scan_int() in\n\t\tLeaf((x, y), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), (1, (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), (-1, (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), (1, (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), (1, (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), (1, (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), (-1, (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), (-1, (a, c)))::b::l)\n\t\telse if ryzm = rmin then\n\t\t\tfix (Combine((minus y z), (-1, (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 0;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2\n;;\nlet c = fix (read 0);;\nlet (x, y) = xy c;;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}], "negative_code": [{"source_code": "(*input\n8\n1000000 0\n0 1000000\n1000000 0\n0 1000000\n1000000 0\n0 1000000\n1000000 0\n0 1000000\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a < c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [Leaf(x, y)] -> Leaf(x, y)\n\t| [Combine(x, y)] -> Combine(x, y)\n\t| a::b::[] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2 \n;;\nlet c = fix (read 0);;\nif r (xy c) > (Int64.mul 1500000L 1500000L)\n\tthen failwith \"Oh shit\";;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = x * x + y * y;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list minimum\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a < c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [Leaf(x, y)] -> Leaf(x, y)\n\t| [Combine(x, y)] -> Combine(x, y)\n\t| a::b::[] -> \n\t\tif (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2 \n;;\nfind 1 (fix (read 0));;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a < c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [Leaf(x, y)] -> Leaf(x, y)\n\t| [Combine(x, y)] -> Combine(x, y)\n\t| a::b::[] -> \n\t\tif (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2 \n;;\nlet c = fix (read 0);;\nlet (x, y) = xy c;;\nPrintf.eprintf \"%d %d\\n\" x y;;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n29\n-613226 -227707\n792237 219301\n-751961 -552208\n-735407 -381381\n650764 -404462\n413131 907455\n-262161 -747347\n-428939 470614\n664354 659984\n-290291 1532\n92915 -821135\n-30613 -930254\n260114 958879\n463417 -576361\n-262253 400445\n-789867 129047\n47749 -851008\n-584972 -453671\n-737269 -24930\n807411 -34487\n-213137 347345\n848053 -522014\n460897 -28204\n-466335 -264003\n293691 -180751\n808540 -399397\n-221574 869266\n253114 264291\n25466 377868\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse if ryzm = rmin then\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2\n;;\nlet shuffle d =\n let nd = List.map (fun c -> (Random.bits (), c)) d in\n let sond = List.sort compare nd in\n List.map snd sond\nlet c = fix (shuffle (read 0));;\nif r (xy c) > (Int64.mul 1500000L 1500000L)\n\tthen failwith \"Oh shit\";;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n29\n-613226 -227707\n792237 219301\n-751961 -552208\n-735407 -381381\n650764 -404462\n413131 907455\n-262161 -747347\n-428939 470614\n664354 659984\n-290291 1532\n92915 -821135\n-30613 -930254\n260114 958879\n463417 -576361\n-262253 400445\n-789867 129047\n47749 -851008\n-584972 -453671\n-737269 -24930\n807411 -34487\n-213137 347345\n848053 -522014\n460897 -28204\n-466335 -264003\n293691 -180751\n808540 -399397\n-221574 869266\n253114 264291\n25466 377868\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a <= c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [a] -> a\n\t| [a; b] -> \n\t\tif ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse if ryzm = rmin then\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t\telse\n\t\t\tfailwith \"lochas\"\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2\n;;\nlet c = fix (read 0);;\nif r (xy c) > (Int64.mul 1500000L 1500000L)\n\tthen failwith \"Oh shit\";;\nfind 1 c;;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}, {"source_code": "(*input\n8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n*)\nlet scan_int() = Scanf.scanf \" %d\" (fun x -> x);;\nlet print_int x = Printf.printf \"%d\" x;;\nlet puts s = Printf.printf s;;\nlet n = scan_int();;\ntype vect = \n\t| Leaf of (int * int) * int \n\t| Combine of (int * int) * ((int * int) * (vect * vect))\n;;\nlet xy l = match l with\n\t| Leaf((x, y), _) -> (x, y)\n\t| Combine((x, y), _) -> (x, y)\n;;\nlet plus (a, b) (x, y) = (a + x, b + y);;\nlet minus (a, b) (x, y) = (a - x, b - y);;\nlet rec read i = \n\tif i >= n then \n\t\t[]\n\telse \n\t\tLeaf((scan_int(), scan_int()), i)::(read (i + 1));;\nlet r (x, y) = \n\tlet a = Int64.of_int x in\n\tlet b = Int64.of_int y in\n\tInt64.add (Int64.mul a a) (Int64.mul b b)\n;;\nlet rec min l = match l with\n\t| [] -> failwith \"empty list minimum\"\n\t| [x] -> x\n\t| a::b -> let c = (min b) in if a < c then a else c\n;;\nlet rec fix l = match l with\n\t| [] -> Leaf((-1, -1), -1)\n\t| [Leaf(x, y)] -> Leaf(x, y)\n\t| [Combine(x, y)] -> Combine(x, y)\n\t| a::b::[] -> \n\t\tif (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then\n\t\t\tCombine((plus (xy a) (xy b)), ((1, 1), (a, b)))\n\t\telse \n\t\t\tCombine((minus (xy a) (xy b)), ((1, -1), (a, b)))\n\t| a::b::c::l -> (\n\t\tlet x = xy a in\n\t\tlet y = xy b in\n\t\tlet z = xy c in\n\t\tlet rxyp = r (plus x y) in\n\t\tlet rxzp = r (plus x z) in\n\t\tlet ryzp = r (plus y z) in\n\t\tlet rxym = r (minus x y) in\n\t\tlet rxzm = r (minus x z) in\n\t\tlet ryzm = r (minus y z) in\n\t\tlet rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in\n\t\tif rxyp = rmin then\n\t\t\tfix (Combine((plus x y), ((1, 1), (a, b)))::c::l)\n\t\telse if rxzp = rmin then\n\t\t\tfix (Combine((plus x z), ((1, 1), (a, c)))::b::l)\n\t\telse if ryzp = rmin then\n\t\t\tfix (Combine((plus y z), ((1, 1), (b, c)))::a::l)\n\t\telse if rxym = rmin then\n\t\t\tfix (Combine((minus x y), ((1, -1), (a, b)))::c::l)\n\t\telse if rxzm = rmin then\n\t\t\tfix (Combine((minus x z), ((1, -1), (a, c)))::b::l)\n\t\telse\n\t\t\tfix (Combine((minus y z), ((1, -1), (b, c)))::a::l)\n\t)\n;;\nlet ret = Array.make n 1;;\nlet rec find w l = match l with\n\t| Leaf(_, i) -> (ret.(i) <- w)\n\t| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2 \n;;\nfind 1 (fix (read 0));;\nArray.iter (fun x -> print_int x;puts \" \") ret;;"}], "src_uid": "a37a92db3626b46c7af79e3eb991983a"} {"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () = \n\tlet n = read_int ()\n\tand suma = ref 0\n\tand mini = ref 10007 \n\tand maxi = ref (-10007) in\n\n\tfor i = 1 to n do \n\t\tlet a = read_int () in\n\t\tif a > 0 then begin\n\t\t\tsuma := !suma + a;\n\t\t\tif a mod 2 = 1 then\n\t\t\t\tmini := min !mini a\n\t\tend else if abs (a mod 2) = 1 then\n\t\t\tmaxi := max !maxi a;\n\tdone;\n\n\tif !suma mod 2 = 1 then\n\t\tprintf \"%d\\n\" !suma\n\telse\n\t\tprintf \"%d\\n\" (max (!suma - !mini) (!suma + !maxi))\n\n", "positive_code": [{"source_code": "open Printf\nopen Scanf\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\n\nlet () =\n let n = read_int () in\n let a = Array.init n read_int in\n let sum = Array.fold_left (fun acc x -> if x > 0 then acc + x else acc) 0 a in\n let max_neg = Array.fold_left (fun acc x -> if x < 0 && abs x mod 2 = 1 then max acc x else acc) (-1000000000) a in\n let min_pos = Array.fold_left (fun acc x -> if x > 0 && abs x mod 2 = 1 then min acc x else acc) (1000000000) a in\n let ans =\n if sum mod 2 = 1 then sum\n else max (sum - min_pos) (sum + max_neg) in\n printf \"%d\\n\" ans"}], "negative_code": [], "src_uid": "76dd49c5545770a1dfbb2da4140199c1"} {"source_code": "open Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_2 _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet graph_cyclic edge_list =\n let map = Hashtbl.create 5 in\n let vn = ref 0 in\n let set_map u =\n if not (Hashtbl.mem map u) then (\n Hashtbl.add map u !vn;\n vn := !vn+1\n )\n in\n let get_map u = Hashtbl.find map u in\n List.iter (fun (u,v) -> set_map u; set_map v) edge_list;\n\n let parent = Array.make !vn (-1) in\n let rec find i = if parent.(i) < 0 then i else (\n parent.(i) <- find (parent.(i));\n parent.(i)\n ) in\n let union u v = parent.(u) <- v in\n\n let rec find_cycle li =\n match li with\n |\t[] -> false\n | (u,v)::tail ->\n\tlet cu = find (get_map u) in\n\tlet cv = find (get_map v) in\n\tif cu = cv then true else (\n\t union cu cv;\n\t find_cycle tail\n\t)\n in\n find_cycle edge_list\n \nlet () = \n let (n,m) = read_2 () in\n\n let v1 = Array.make m 0 in\n let v2 = Array.make m 0 in\n let w = Array.make m 0 in \n\n for i=0 to m-1 do\n v1.(i) <- read_int() -1;\n v2.(i) <- read_int() -1;\n w.(i) <- read_int(); \n done;\n\n let q = read_int() in\n let query = Array.make q ([],[[]]) in\n\n for i=0 to q-1 do\n let k = read_int() in\n let rec loop j ac = if j=k then ac else loop (j+1) ((read_int()-1) :: ac) in\n let qlist = loop 0 [] in\n\n let h = Hashtbl.create 5 in\n List.iter (fun e ->\n let li = try Hashtbl.find h w.(e) with Not_found -> [] in\n Hashtbl.replace h w.(e) (e :: li)\n ) qlist;\n \n query.(i) <- (qlist, Hashtbl.fold (fun _ v ac -> v::ac) h [])\n (* it's a list of lists of edges of the same weight *)\n done;\n\n let parent = Array.make n (-1) in\n let size = Array.make n 1 in\n let edge_no = Array.make n (-1) in\n\n let union a b edge =\n (* assume a and b are canonoical elements *)\n let (a,b) = if size.(a) <= size.(b) then (a,b) else (b,a) in\n parent.(a) <- b;\n size.(b) <- size.(b) + size.(a);\n edge_no.(a) <- edge\n in\n let rec find i = if parent.(i) < 0 then i else find parent.(i) in\n\n let perm = Array.init m (fun i -> i) in\n\n Array.sort (fun a b -> compare w.(a) w.(b)) perm;\n\n for i=0 to m-1 do\n let i = perm.(i) in\n let (a,b) = (find v1.(i), find v2.(i)) in\n if a<>b then union a b i\n done;\n\n for i=0 to q-1 do\n let (qlist, qlistlist) = query.(i) in\n (* first determine if the queries form a cycle *)\n let graph = List.map (fun e -> (v1.(e), v2.(e))) qlist in\n if graph_cyclic graph then printf \"NO\\n\" else (\n let edge_set_valid es =\n\tlet rec find_canon j ew =\n\t if parent.(j) >= 0 && w.(edge_no.(j)) < ew then find_canon parent.(j) ew\n\t else j\n\tin\n\n\tlet graph = List.map (fun e -> (find_canon v1.(e) w.(e), find_canon v2.(e) w.(e))) es in\n\tnot (graph_cyclic graph)\n in\n\n if List.for_all edge_set_valid qlistlist then printf \"YES\\n\" else printf \"NO\\n\"\n )\n done\n", "positive_code": [{"source_code": "(* keywords: union-find, MST\n Really nice problem involving understainding the MST algorithm, and\n how to use the union/find data structure without path compression.\n*)\n\nopen Printf\nopen Scanf\n\nlet read_int _ = bscanf Scanning.stdib \" %d \" (fun x -> x)\nlet read_2 _ = bscanf Scanning.stdib \" %d %d \" (fun x y -> (x,y))\n\nlet graph_cyclic edge_list =\n let map = Hashtbl.create 5 in\n let vn = ref 0 in\n let set_map u =\n if not (Hashtbl.mem map u) then (\n Hashtbl.add map u !vn;\n vn := !vn+1\n )\n in\n let get_map u = Hashtbl.find map u in\n List.iter (fun (u,v) -> set_map u; set_map v) edge_list;\n\n let parent = Array.make !vn (-1) in\n let rec find i = if parent.(i) < 0 then i else (\n parent.(i) <- find (parent.(i));\n parent.(i)\n ) in\n let union u v = parent.(u) <- v in\n\n let rec find_cycle li =\n match li with\n |\t[] -> false\n | (u,v)::tail ->\n\tlet cu = find (get_map u) in\n\tlet cv = find (get_map v) in\n\tif cu = cv then true else (\n\t union cu cv;\n\t find_cycle tail\n\t)\n in\n find_cycle edge_list\n \nlet () = \n let (n,m) = read_2 () in\n\n let v1 = Array.make m 0 in\n let v2 = Array.make m 0 in\n let w = Array.make m 0 in \n\n for i=0 to m-1 do\n v1.(i) <- read_int() -1;\n v2.(i) <- read_int() -1;\n w.(i) <- read_int(); \n done;\n\n let q = read_int() in\n let query = Array.make q [] in\n\n for i=0 to q-1 do\n let k = read_int() in\n let rec loop j ac = if j=k then ac else loop (j+1) ((read_int()-1) :: ac) in\n query.(i) <- loop 0 []\n done;\n\n let parent = Array.make n (-1) in\n let size = Array.make n 1 in\n let edge_no = Array.make n (-1) in\n\n let union a b edge =\n (* assume a and b are canonoical elements *)\n let (a,b) = if size.(a) <= size.(b) then (a,b) else (b,a) in\n parent.(a) <- b;\n size.(b) <- size.(b) + size.(a);\n edge_no.(a) <- edge\n in\n let rec find i = if parent.(i) < 0 then i else find parent.(i) in\n\n let perm = Array.init m (fun i -> i) in\n\n Array.sort (fun a b -> compare w.(a) w.(b)) perm;\n\n for i=0 to m-1 do\n let i = perm.(i) in\n let (a,b) = (find v1.(i), find v2.(i)) in\n if a<>b then union a b i\n done;\n\n for i=0 to q-1 do\n (* first determine if the queries form a cycle *)\n let graph = List.map (fun e -> (v1.(e), v2.(e))) query.(i) in\n if graph_cyclic graph then printf \"NO\\n\" else (\n let rec find_canon j ew =\n\tif parent.(j) >= 0 && w.(edge_no.(j)) < ew then find_canon parent.(j) ew\n\telse j\n in\n \n let graph = List.map (fun e -> (find_canon v1.(e) w.(e), find_canon v2.(e) w.(e))) query.(i) in\n if graph_cyclic graph then printf \"NO\\n\" else printf \"YES\\n\"\n )\n done\n"}], "negative_code": [], "src_uid": "21a1aada3570f42093c7ed4e06f0766d"}