let N = Int(readLine()!)!
var A = readLine()!.characters.split(" ").map{Int(String($0))!}
for i in (1..<N).reverse() {
  A.sortInPlace()
  let x: Int!
  let y: Int!
  if i%2 > 0 {
    x = A.last!
    y = A.first!
    A[A.endIndex.predecessor()] -= A[A.startIndex]
    A.removeFirst()
  } else {
    x = A.first!
    y = A.last!
    A[A.startIndex] -= A[A.endIndex.predecessor()]
    A.removeLast()
  }
  print("\(x) \(y)")
}
print(A.first!)