(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ps = Array.make_matrix 2 n 0
let pc = Array.make 2 0
let ms = Array.make_matrix 2 2 0
let mis = Array.make_matrix 2 2 0
let ds = Array.make_matrix 2 n false
let xys = ref []
let _ =
  let f i a =
    let j = if a < 0 then 1 else 0 in
    ps.(j).(pc.(j)) <- a; pc.(j) <- pc.(j) + 1;
    if a < ms.(j).(0) then (ms.(j).(0) <- a; mis.(j).(0) <- i);
    if a > ms.(j).(1) then (ms.(j).(1) <- a; mis.(j).(1) <- i) in
  Array.iteri f a_s;
  let i, j, k, l = if pc.(0) = 0 then 0, 1, 1, 0 else if pc.(1) = 0 then 1, 0, 0, 1 else -1, -1, -1, -1 in
  if i <> -1 then
    let x, y = ps.(j).(mis.(j).(k)), ps.(j).(mis.(j).(l)) in
    xys := (x, y) :: !xys;
    ds.(j).(mis.(j).(k)) <- true;
    ds.(j).(mis.(j).(l)) <- true;
    ps.(i).(0) <- x - y;
    pc.(i) <- 1
  else ();
  let g (i0, j0) =
    for i = i0 to pc.(1 - j0) - 1 do
      if not ds.(1 - j0).(i) then
        let x, y = ps.(j0).(0), ps.(1 - j0).(i) in
        xys := (x, y) :: !xys;
        ps.(j0).(0) <- x - y;
        ds.(1 - j0).(i) <- true;
    done in
  List.iter g [1, 1; 0, 0];
  Printf.printf "%d\n" ps.(0).(0);
  List.rev !xys |> List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y)