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

logs = []

while(arr.count != 1)
  arr.sort!
  min = arr.shift
  max = arr.pop

  if arr.count % 2 == 0
    arr.push(max - min)
    logs.push([max, min])
  else
    arr.push(min - max)
    logs.push([min, max])
  end
end

puts arr.first
logs.each { |log| puts "#{log[0]} #{log[1]}"}