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: import sys
  
  stdin = sys.stdin
  
  sys.setrecursionlimit(10**5)
  
  
  def li():
      return map(int, stdin.readline().split())
  
  
  def li_():
      return map(lambda x: int(x) - 1, stdin.readline().split())
  
  
  def lf():
      return map(float, stdin.readline().split())
  
  
  def ls():
      return stdin.readline().split()
  
  
  def ns():
      return stdin.readline().rstrip()
  
  
  def lc():
      return list(ns())
  
  
  def ni():
      return int(stdin.readline())
  
  
  def nf():
      return float(stdin.readline())
  
  
  from collections import deque
  
  n = ni()
  a = []
  for _ in range(n):
      a.append(ni())
  
  mx_cent = [ai for ai in a]
  mn_cent = [ai for ai in a]
  
  a.sort()
  a = deque(a)
  
  mx_cent = deque([ai for ai in a])
  mn_cent = deque([ai for ai in a])
  
  
  bmx = deque([mx_cent.pop()])
  bmn = deque([mn_cent.popleft()])
  
  cnt = 0
  
  
  while len(mx_cent) > 1:
      lf = 0
      rt = 0
      if cnt % 2 == 0:
          lf = mx_cent.popleft()
          rt = mx_cent.popleft()
      else:
          lf = mx_cent.pop()
          rt = mx_cent.pop()
  
      bmx.appendleft(lf)
      bmx.append(rt)
  
      if cnt % 2 == 0:
          lf = mn_cent.pop()
          rt = mn_cent.pop()
      else:
          lf = mn_cent.popleft()
          rt = mn_cent.popleft()
  
      bmn.appendleft(lf)
      bmn.append(rt)
  
      cnt += 1
  
  
  if len(mx_cent) == 1:
      last = mx_cent.pop()
      if abs(bmx[0] - last) > abs(bmx[-1] - last):
          bmx.appendleft(last)
      else:
          bmx.append(last)
  
      last = mn_cent.pop()
      if abs(bmn[0] - last) > abs(bmn[-1] - last):
          bmn.appendleft(last)
      else:
          bmn.append(last)
  
  diffmx, diffmn = 0, 0
  for i in range(n - 1):
      diffmx += abs(bmx[i + 1] - bmx[i])
      diffmn += abs(bmn[i + 1] - bmn[i])
  
  print(max(diffmx, diffmn))
  
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"}]