'use strict'

const input = require("fs").readFileSync("/dev/stdin", "utf8");
const lines = input.split('\n').filter(Boolean);

const N = lines[0];
// 小さい順
let numbers = lines[1].split(' ').filter(s => s !== '').map(Number).sort((a, b) => a - b);

// でかいの - ちいさいの
// const max = (nums) => Math.max.apply(nums);
// const min = (nums) => Math.min.apply(nums);

const result = [];

while (numbers.length > 1) {
  var min = numbers[0]; numbers.shift();
  var max = numbers[numbers.length - 1]; numbers.pop();
  result.push(`${max} ${min}`);
  numbers.push(max - min);
  // todofix
  numbers.sort((a, b) => a - b);
  numbers = numbers;
}

const last = numbers[0];

console.log(`${last}\n${result.join('\n')}`);

// const negatives = numbers.filter(n => n < 0);
// const positives = numbers.filter(n => n >= 0);
// if (negatives.length > positives.length)