output_description: If the length of S is 2, print S as is; if the length is 3, print S after
  reversing it.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
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
      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 a string S of length 2 or 3 consisting of lowercase English
  letters. If the length of the string is 2, print it as is; if the length is 3,
  print the string after reversing it.
samples: [{"input": "abc", "output": "cba\n    \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n    \n\nAs the length of S is 2, we print it as is."}]