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: N = int(input())
  A = [int(input()) for i in range(N)]
  A.sort()
  l = []
  if len(A) % 2 == 0:
      A_s = A[: int(len(A) / 2)]
      A_l = A[int(len(A) / 2) :]
      l.append(A_s[-1])
      l.append(A_l[0])
      for i in range(1, int(len(A) / 2) + 1):
          if i % 2 == 1:
              l.insert(i, A_l[-i])
              l.insert(-i - 1, A_s[i - 1])
          elif i % 2 == 0:
              l.insert(i, A_s[i - 1])
              l.insert(-i - 1, A_l[-i])
  elif len(A) % 2 == 1:
      A_s = A[: int(len(A) / 2)]
      A_l = A[int(len(A) / 2) + 1 :]
      A_m = A[int(len(A) / 2)]
      d = abs(A_m - A_s[-1]) - abs(A_m - A_l[0])
      if d >= 0:
          l.append(A_m)
          l.append(A_l[0])
          for i in range(1, int(len(A_s) / 2) + 1):
              if i % 2 == 1:
                  l.insert(i, A_s[i - 1])
                  l.insert(-i - 1, A_s[i])
              elif i % 2 == 0:
                  l.insert(i, A_l[-i + 1])
                  l.insert(-i - 1, A_l[-i])
          l.insert(int(len(A_s) / 2) + 1, A_l[1])
      else:
          l.append(A_s[-1])
          l.append(A_m)
          for i in range(1, int(len(A_l) / 2) + 1):
              if i % 2 == 1:
                  l.insert(i, A_l[-i + 1])
                  l.insert(-i - 1, A_l[-i])
              elif i % 2 == 0:
                  l.insert(i, A_s[i - 1])
                  l.insert(-i - 1, A_s[i])
          l.insert(int(len(A_l) / 2) + 1, A_s[-2])
  l_d = [abs(l[i] - l[i + 1]) for i in range(len(l) - 1)]
  print(sum(l_d))
  
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"}]