M = gets.chop.to_i
nums = gets.chop.split.map(&:to_i)

nums.sort

max_num = nums.pop

process = []
while !nums.empty? && nums[0] <= 0
  num = nums.shift
  process << "#{max_num} #{num}"
  max_num -= num
end

while nums.size > 1
  a = nums.pop
  b = nums.pop
  process << "#{a} #{b}"
  c = a - b
  idx = nums.bsearch { |x| x >= c }
  idx = nums.size if idx.nil?
  nums.insert(idx, c)
end

process << "#{max_num} #{nums[0]}"
puts max_num - nums[0]
puts process.join("\n")

