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 _ in range(n)]
  
  if n == 2:
      print(abs(a[0] - a[1]))
  elif n == 3:
      print(
          max(
              abs(a[0] - a[1]) + abs(a[0] - a[2]),
              abs(a[1] - a[2]) + abs(a[1] - a[0]),
              abs(a[2] - a[1]) + abs(a[2] - a[0]),
          )
      )
  else:
      b = sorted(a)
      ans = [0] * n
      if n % 2 == 0:
          for i in range(2, n - 1, 2):
              ans[i] = b[(i // 2) - 1]
              # print(i, ans[i])
          for i in range(1, n - 1, 2):
              ans[i] = b[-1 - ((i - 1) // 2)]
              # print(i, ans[i])
          ans[0] = b[n // 2 - 1]
          ans[n - 1] = b[n // 2]
      else:
          ans[0] = b[n // 2]
          if b[n // 2 + 1] + b[n // 2 - 1] >= 2 * b[n // 2]:
              for i in range(2, n - 1, 2):
                  ans[i] = b[(i // 2) - 1]
              for i in range(1, n - 1, 2):
                  ans[i] = b[-1 - ((i - 1) // 2)]
  
              ans[n - 1] = b[n // 2 - 1]
              # ans[n-2] = b[n // 2 + 1]
          else:
              for i in range(1, n - 1, 2):
                  ans[i] = b[((i - 1) // 2)]
              for i in range(2, n - 1, 2):
                  ans[i] = b[-1 - ((i - 2) // 2)]
  
              ans[n - 1] = b[n // 2 + 1]
              # ans[n-2] = b[n // 2 - 1]
  
      # print(ans)
      print(sum([abs(ans[i] - ans[i + 1]) for i in range(n - 1)]))
  
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"}]