let stream_fold f init st = let result = ref init in Stream.iter (fun x -> result := f !result x) st; !result let stream_to_rev_list st = stream_fold (fun result elem -> elem :: result) [] st let () = let st = Stream.from (fun i -> if i >= 3 then None else let c = (65 + i) |> char_of_int and h = read_line () |> int_of_string in Some(c, h) ) in st |> stream_to_rev_list |> List.sort (fun (c1, h1) (c2, h2) -> compare h2 h1) |> List.iter (fun (c, h) -> print_endline (String.make 1 c))