Scanf.scanf "%d" (fun k -> let module M = Map.Make (struct type t = int let compare = compare end) in let calc i map = let rec loop b i j map = if i + j > 30 then map else let map = M.add (b lsl j) (i, j) map in loop b i (j + 1) map in let base = i * (i - 1) / 2 in loop base i 0 map in let rec loop i map = if i = 31 then map else loop (i + 1) (calc i map) in let map = loop 2 (M.singleton 0 (1, 0)) in let a, b = M.find k map in Printf.printf "%d\n" (a + b); let _ = Array.init (a + b) (fun i -> if i < b then Printf.printf "0 " else Printf.printf "1 ") in print_newline () )