output_description: Print the maximum possible sum of the absolute differences between the
  adjacent elements after arranging the given integers in a row in any order you
  like.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1
      :
      A_N
attempt: def getInt():
      return int(input())
  
  
  def getIntList():
      return [int(x) for x in input().split()]
  
  
  def zeros(n):
      return [0] * n
  
  
  INF = 10**18
  
  
  class Debug:
      def __init__(self):
          self.debug = True
  
      def off(self):
          self.debug = False
  
      def dmp(self, x, cmt=""):
          if self.debug:
              if cmt != "":
                  w = cmt + ": " + str(x)
              else:
                  w = str(x)
              print(w)
          return x
  
  
  def prob():
      d = Debug()
      d.off()
      N = getInt()
      A = zeros(N)
      for i in range(N):
          A[i] = getInt()
      d.dmp((N, A), "N,A")
      A.sort()
      a = zeros(N)
      a[0] = A[N // 2]
      k = 1
      if a[0] - A[0] >= A[-1] - a[0]:
          from0 = True
      else:
          from0 = False
      for i in range(N // 2):
          d.dmp((k), "k")
          if from0:
              a[k] = A[i]
              if i * 2 + 1 < N:
                  a[k + 1] = A[-i - 1]
          else:
              a[k] = A[-i - 1]
              if i * 2 + 1 < N - 1:
                  a[k + 1] = A[i]
          k += 2
      if N % 2 == 0:
          a[-1] = A[N // 2 + 1]
      d.dmp((a), "a")
      dif = 0
      for i in range(N - 1):
          dif += abs(a[i] - a[i + 1])
      print(dif)
  
  
  ans = prob()
  
problem_description: Statement
  
  You are given N integers; the i-th of them is A_i. Find the maximum possible
  sum of the absolute differences between the adjacent elements after arranging
  these integers in a row in any order you like.
samples: [{"input": "5\n    6\n    8\n    1\n    2\n    3", "output": "21\n    \n\nWhen the integers are arranged as 3,8,1,6,2, the sum of the absolute\ndifferences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6\n- 2| = 21. This is the maximum possible sum.\n\n* * *"}, {"input": "6\n    3\n    1\n    4\n    1\n    5\n    9", "output": "25\n    \n\n* * *"}, {"input": "3\n    5\n    5\n    1", "output": "8"}]