import Control.Monad
import Data.List

-- (idx val is_plus)
pm_list :: [Int] -> [(Int, Int, Bool)]
pm_list ls =
  let n = length ls
   in let (m, p) =
            splitAt (div n 2) $
            sortBy (\(_, v) -> \(_, w) -> compare v w) $ zip [1 ..] ls
       in let m_ = map (\(i, v) -> (i, v, False)) m
           in let p_ = map (\(i, v) -> (i, v, True)) p
               in sortBy (\(i, _, _) -> \(j, _, _) -> compare i j) (m_ ++ p_)

max_val :: [(Int, Int, Bool)] -> Int
max_val =
  sum .
  map
    (\(_, v, b) ->
       if b
         then v
         else (-v))

construct_op :: [(Int, Int, Bool)] -> [(Int, Int)]
construct_op ls =
  let tot = max_val ls
   in fun tot ls
  where
    fun tot (_:[]) = []
    fun tot ((idx, val, pos):rest) =
      if pos
        then (val, val - tot) : (fun (tot - val) rest)
        else (tot + val, val) : (fun (tot + val) rest)

solver :: [Int] -> (Int, [(Int, Int)])
solver ls =
  let pm = pm_list ls
   in (max_val pm, reverse $ construct_op pm)

main :: IO ()
main = do
  _ <- getLine
  dat <- (map read . words) <$> getLine
  let (v, ls) = solver dat
  print v
  forM_ ls (\(x, y) -> putStrLn $ show x ++ " " ++ show y)