Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;

    let rec loop i mx mi =
        if i = n - 1 then mx - mi else
            if a.(i) >= 0 then loop (i + 1) mx (mi - a.(i))
                          else loop (i + 1) (mx - a.(i)) mi
    in
    Printf.printf "%d\n" @@ loop 1 a.(n - 1) a.(0);

    let rec loop i mx mi =
        if i = n - 1 then Printf.printf "%d %d\n" mx mi else
            if a.(i) >= 0 then (Printf.printf "%d %d\n" mi a.(i); loop (i + 1) mx (mi - a.(i)))
                          else (Printf.printf "%d %d\n" mx a.(i); loop (i + 1) (mx - a.(i)) mi)
    in
    loop 1 a.(n - 1) a.(0)
)