-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad (forM_)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let ys = U.scanl' (\(!m,!n) x -> (maximum [x - m, x - n, m - x, n - x], minimum [x - m, x - n, m - x, n - x])) (U.head xs, U.head xs) (U.tail xs)
      (r, _) = U.last ys
  print r
  let loop 0 acc !y = acc
      loop i acc y
        | y == x - m = loop (i - 1) ((x, m) : acc) m
        | y == m - x = loop (i - 1) ((m, x) : acc) m
        | y == x - n = loop (i - 1) ((x, n) : acc) n
        | y == n - x = loop (i - 1) ((n, x) : acc) n
        | otherwise = error $ "invalid input " ++ show (y,x,m,n)
        where x = xs U.! i
              (m,n) = ys U.! (i - 1)
  forM_ (loop (n - 1) [] r) $ \(x,y) -> do
    putStrLn $ concat [show x, " ", show y]
