n=gets.to_i
a=[]
b=[]
n.times{a<<gets.to_i}
a.sort!
if a.size%2==0
  count=0
  while a.size!=0
    if count%2==0
      b.insert 0,a[0]
      a.delete_at 0
      b.insert -1,a[-1]
      a.delete_at -1
    else
      b.insert -1,a[0]
      a.delete_at 0
      b.insert 0,a[-1]
      a.delete_at -1
    end
    count+=1
  end
else
  count=0
  b.insert 0,a[0]
  a.delete_at 0
  while a.size!=0
    b.insert -1*(count+1),a[0]
    a.delete_at 0
    b.insert  count,a[0]
    a.delete_at 0
    count+=1
  end
end
puts b.join " "
ans=0
(n-1).times{|i|
  ans+=(b[i+1]-b[i]).abs
}
puts ans
