N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)[0..N]

min = A.min
max = A.max

puts (if min > 0
  A.reduce(&:+) - min*2
elsif max < 0
  max*2 - A.reduce(&:+)
else
  A.reduce{ |sum, value| sum.abs + value.abs }
end)

(N-1).times do
  positives = A.select{ |v| v > 0 }
  a, b = begin
    if positives.size > 1
      [ A.min, positives.min ]
    else
      [ A.max,  A.min ]
    end
  end
  A.delete_at(A.index(a))
  A.delete_at(A.index(b))
  A.push(a - b)
  puts [a, b].join(" ")
end