n=int(input())
a=list(map(int,input().split()))
a.sort()
A=[a[0]]
x=0
sum=sum(a)
sumL=-9999999999
if n==2:
  print(max(a)-min(a))
  print(max(a),min(a))
else:
  for i in range(1,n):
    A.append(A[i-1]+a[i])
  for i in range(1,n):
    if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
  print(sumL)
  L1=a[0:x]
  L2=a[x:n]

  if x!=1:
    print(L2[0],L1[0])
    z=L2[0]-L1[0]
    for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
  else:
    z=L2[0]

  if x!=n-1:
    print(L1[x-1],L2[1])
    y=L1[x-1]-L2[1]
    for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
  else:
    y=L1[len(L1)-1]

  print(z,y) n=int(input()) n int(input()) int input() input a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a.sort() a.sort a sort A=[a[0]] A [a[0]] a[0] a 0 x=0 x 0 sum=sum(a) sum sum(a) sum a sumL=-9999999999 sumL -9999999999 if n==2:
  print(max(a)-min(a))
  print(max(a),min(a))
else:
  for i in range(1,n):
    A.append(A[i-1]+a[i])
  for i in range(1,n):
    if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
  print(sumL)
  L1=a[0:x]
  L2=a[x:n]

  if x!=1:
    print(L2[0],L1[0])
    z=L2[0]-L1[0]
    for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
  else:
    z=L2[0]

  if x!=n-1:
    print(L1[x-1],L2[1])
    y=L1[x-1]-L2[1]
    for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
  else:
    y=L1[len(L1)-1]

  print(z,y) n==2 n 2 print(max(a)-min(a)) print max(a)-min(a) max(a) max a min(a) min a print(max(a),min(a)) print max(a) max a min(a) min a for i in range(1,n):
    A.append(A[i-1]+a[i])
   i range(1,n) range 1 n A.append(A[i-1]+a[i]) A.append A append A[i-1]+a[i] A[i-1] A i-1 i 1 a[i] a i for i in range(1,n):
    if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
   i range(1,n) range 1 n if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
   sumL<-A[i-1]+sum-A[i-1] sumL -A[i-1]+sum-A[i-1] -A[i-1]+sum -A[i-1] A[i-1] A i-1 i 1 sum A[i-1] A i-1 i 1 sumL=-A[i-1]+sum-A[i-1] sumL -A[i-1]+sum-A[i-1] -A[i-1]+sum -A[i-1] A[i-1] A i-1 i 1 sum A[i-1] A i-1 i 1 x=i x i print(sumL) print sumL L1=a[0:x] L1 a[0:x] a 0:x 0 x L2=a[x:n] L2 a[x:n] a x:n x n if x!=1:
    print(L2[0],L1[0])
    z=L2[0]-L1[0]
    for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
  else:
    z=L2[0]

   x!=1 x 1 print(L2[0],L1[0]) print L2[0] L2 0 L1[0] L1 0 z=L2[0]-L1[0] z L2[0]-L1[0] L2[0] L2 0 L1[0] L1 0 for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
   i range(1,x-1) range 1 x-1 x 1 print(z,L1[i]) print z L1[i] L1 i z=z-L1[i] z z-L1[i] z L1[i] L1 i z=L2[0] z L2[0] L2 0 if x!=n-1:
    print(L1[x-1],L2[1])
    y=L1[x-1]-L2[1]
    for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
  else:
    y=L1[len(L1)-1]

   x!=n-1 x n-1 n 1 print(L1[x-1],L2[1]) print L1[x-1] L1 x-1 x 1 L2[1] L2 1 y=L1[x-1]-L2[1] y L1[x-1]-L2[1] L1[x-1] L1 x-1 x 1 L2[1] L2 1 for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
   i range(2,len(L2)) range 2 len(L2) len L2 print(y,L2[i]) print y L2[i] L2 i y=y-L2[i] y y-L2[i] y L2[i] L2 i y=L1[len(L1)-1] y L1[len(L1)-1] L1 len(L1)-1 len(L1) len L1 1 print(z,y) print z y y=L1[x-1]-L2[1] L1[x-1]-L2[1] y z=L2[0] L2[0] z sumL=-9999999999 -9999999999 sumL n=int(input()) int(input()) n y=y-L2[i] y-L2[i] y L1=a[0:x] a[0:x] L1 L2=a[x:n] a[x:n] L2 y=L1[len(L1)-1] L1[len(L1)-1] y a=list(map(int,input().split())) list(map(int,input().split())) a x=0 0 x z=L2[0]-L1[0] L2[0]-L1[0] z sumL=-A[i-1]+sum-A[i-1] -A[i-1]+sum-A[i-1] sumL sum=sum(a) sum(a) sum A=[a[0]] [a[0]] A x=i i x z=z-L1[i] z-L1[i] z
n=int(input())
a=list(map(int,input().split()))
a.sort()
A=[a[0]]
x=0
sum=sum(a)
sumL=-9999999999
if n==2:
  print(max(a)-min(a))
  print(max(a),min(a))
else:
  for i in range(1,n):
    A.append(A[i-1]+a[i])
  for i in range(1,n):
    if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
  print(sumL)
  L1=a[0:x]
  L2=a[x:n]

  if x!=1:
    print(L2[0],L1[0])
    z=L2[0]-L1[0]
    for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
  else:
    z=L2[0]

  if x!=n-1:
    print(L1[x-1],L2[1])
    y=L1[x-1]-L2[1]
    for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
  else:
    y=L1[len(L1)-1]

  print(z,y)