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: from math import ceil
  from itertools import permutations
  
  
  def main():
      length = int(input())
      numbers = [int(input()) for _ in range(length)]
      numbers.sort()
      number_pair = []
      for i in range(ceil(length / 2) - 1):
          number_pair.append([numbers[i], numbers[-i - 1]])
      number_pair.sort(key=lambda x: x[1])
      side = [numbers[length // 2]]
      if length % 2 == 0:
          side.append(numbers[length // 2 - 1])
      else:
          side.append(-1)
      answer = 0
      if 2 < length:
          for left_side, right_side in permutations(side):
              large_first = 0
              small_first = 0
              for i in range(len(number_pair)):
                  if i == 0 and left_side != -1:
                      large_first += abs(left_side - number_pair[i][1])
                      small_first += abs(left_side - number_pair[i][0])
                  elif i == len(number_pair) - 1 and right_side != -1:
                      large_first += abs(right_side - number_pair[i][0])
                      small_first += abs(right_side - number_pair[i][1])
                  if 0 < i:
                      large_first += abs(number_pair[i][1] - number_pair[i - 1][0])
                      small_first += abs(number_pair[i][0] - number_pair[i - 1][1])
                  large_first += abs(number_pair[i][0] - number_pair[i][1])
                  small_first += abs(number_pair[i][0] - number_pair[i][1])
              answer = max(answer, large_first, small_first)
      else:
          answer = abs(numbers[0] - numbers[1])
      print(answer)
  
  
  if __name__ == "__main__":
      main()
  
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"}]