import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.container.rbtree;

alias T = Tuple!(long, long);
alias Tree = RedBlackTree!(long, "a < b", true);

void main() {
  int n;
  readf (" %d", &n);
  auto a = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  a.sort ();
  T[] r;
  auto t = new Tree (a.map! (to!long));
  foreach (iters; 2 .. n) {
    long x = t.front;
    t.removeFront ();
    long z = t.back;
    t.removeBack ();
    long y = t.back;
    t.removeBack;
    if (false) {
      r ~= tuple (z, x); 
      t.insert (y);
      t.insert (z - x);
    } else {
      r ~= tuple (x, y);
      t.insert (z);
      t.insert (x - y);
    }
  }
  long x = t.front;
  long y = t.back;
  r ~= tuple (y, x);
  writeln (y - x);
  foreach (p; r) {
    writeln (p[0], ' ', p[1]);
  }
}
