def sum(a)
    sum = 0
    a.each { |i| sum += i }
    sum
end

N = gets.to_i
a = gets.split.map(&:to_i)

a.sort!

puts sum(a.slice(1,N)) - a[0]

if N>=3
(N-2).times do
    puts "#{a[0]} #{a[-1]}"
    a[0] -= a[-1]
    a.pop
    a.sort!
end
puts "#{a[-1]} #{a[0]}"
else
    puts "#{a[-1]} #{a[0]}"
end