Scanf.scanf "%d" (fun n -> let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in Array.sort (fun (a1, b1) (a2, b2) -> compare (a2 * b1) (a1 * b2)) ab; Array.iter (fun (a, b) -> Printf.printf "%d %d\n" a b) ab )