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: #coding:utf-8
  import copy
  N = int(input())
  A_list = []
  for i in range(N):
      A_list.append(int(input()) )
  
  def calculate_x(list):
      len_list = len(list)
      sum = 0
      for i in range(len_list-1):
          sum = sum + abs(list[i]-list[i+1])
      return sum
  
  A_list = sorted(A_list)
  
  if N % 2 ==0: #even
      answer_list = []
      A_min_list = A_list[:int(N/2)-1]
      A_max_list = A_list[-int(N/2)+1:]
      for max, min in zip(A_max_list, A_min_list):
          answer_list.append(max)
          answer_list.append(min)
      answer_list.append(A_list[int(N/2)]) #min of max_list
      answer_list.insert(0,A_list[int(N/2)-1]) #max of min_list
      tmp = calculate_x(answer_list)
      print(tmp)
  
  else: #odd
      if N >=5:
      answer_list = []
      A_min_list = A_list[:int((N-1)/2)-1] #0,1
      A_max_list = A_list[-int((N-1)/2)+1:] #5,6
      x1 = A_list[int((N-1)/2)-1] #2
      x2 = A_list[int((N-1)/2)]#3
      x3 = A_list[int((N-1)/2)+1]#4
      for max, min in zip(A_max_list, A_min_list):
          answer_list.append(max)
          answer_list.append(min)
  
      answer_list2 = copy.deepcopy(answer_list)
      max = 0
      answer_list2.append(x1)
      answer_list2.insert(0,x2)
      answer_list2.insert(0,x3)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
      answer_list2 = copy.deepcopy(answer_list)
      answer_list2.append(x1)
      answer_list2.insert(0,x3)
      answer_list2.insert(0,x2)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
      answer_list2 = copy.deepcopy(answer_list)
      answer_list2.append(x2)
      answer_list2.insert(0,x1)
      answer_list2.insert(0,x3)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
      answer_list2 = copy.deepcopy(answer_list)
      answer_list2.append(x2)
      answer_list2.insert(0,x3)
      answer_list2.insert(0,x1)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
      answer_list2 = copy.deepcopy(answer_list)
      answer_list2.append(x3)
      answer_list2.insert(0,x1)
      answer_list2.insert(0,x2)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
      answer_list2 = copy.deepcopy(answer_list)
      answer_list2.append(x3)
      answer_list2.insert(0,x2)
      answer_list2.insert(0,x1)
      tmp = calculate_x(answer_list2)
      if tmp > max:
          max = tmp
  
  
  
      answer_list3 = []
      A_min_list = A_list[:int((N-1)/2)-1] #0,1
      A_max_list = A_list[-int((N-1)/2)+1:] #5,6
      x1 = A_list[int((N-1)/2)-1] #2
      x2 = A_list[int((N-1)/2)]#3
      x3 = A_list[int((N-1)/2)+1]#4
      for max, min in zip(A_max_list, A_min_list):
          answer_list3.append(min)
          answer_list3.append(max)
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x1)
      answer_list4.insert(0,x2)
      answer_list4.insert(0,x3)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x1)
      answer_list4.insert(0,x3)
      answer_list4.insert(0,x2)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x2)
      answer_list4.insert(0,x1)
      answer_list4.insert(0,x3)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x2)
      answer_list4.insert(0,x3)
      answer_list4.insert(0,x1)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x3)
      answer_list4.insert(0,x1)
      answer_list4.insert(0,x2)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
  
      answer_list4 = copy.deepcopy(answer_list3)
      answer_list4.append(x3)
      answer_list4.insert(0,x2)
      answer_list4.insert(0,x1)
      tmp = calculate_x(answer_list4)
      if tmp > max:
          max = tmp
      print(max)
  
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"}]