Scanf.scanf "%d" (fun n ->
    let xyp = Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun x y p -> x, y, p)) in

    let vp = Array.init n (fun i ->
        let me, _, p = xyp.(i) in
        Array.init (1 lsl n) (fun bit ->
            let rec loop j acc =
                if j = n then acc * p else
                    if bit land (1 lsl j) = 0 then loop (j + 1) acc else
                        let k, _, _ = xyp.(j) in
                        let acc = min acc (abs (k - me)) in
                        loop (j + 1) acc
            in
            loop 0 (abs me)
        )
    ) in
    let hp = Array.init n (fun i ->
        let _, me, p = xyp.(i) in
        Array.init (1 lsl n) (fun bit ->
            let rec loop j acc =
                if j = n then acc * p else
                    if bit land (1 lsl j) = 0 then loop (j + 1) acc else
                        let _, k, _ = xyp.(j) in
                        let acc = min acc (abs (k - me)) in
                        loop (j + 1) acc
            in
            loop 0 (abs me)
        )
    ) in

    let best = Array.make (n + 1) max_int in
    let calc h v =
        let rec loop i acc =
            if i = n then acc else
                loop (i + 1) (acc + min vp.(i).(v) hp.(i).(h))
        in
        loop 0 0
    in

    let rec loop i c hbit vbit =
        best.(c) <- min best.(c) (calc hbit vbit);
        if i < n then (
            loop (i + 1) c       hbit                 vbit;
            loop (i + 1) (c + 1) (hbit lor (1 lsl i)) vbit;
            loop (i + 1) (c + 1) hbit                 (vbit lor (1 lsl i));
        )
    in
    loop 0 0 0 0;

    Array.iter (Printf.printf "%d\n") best;
)