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: n = int(input())
  
  a = [0] * n
  
  for i in range(0, n):
      a[i] = int(input())
  
  a.sort()
  
  c = 0
  
  if len(a) == 2:
      print(abs(a[0] - a[1]))
  
  if len(a) == 3:
      diff = abs(a[0] - a[1]) + abs(a[1] - a[2])
      diff = max(abs(a[0] - a[2]) + abs(a[1] - a[2]), diff)
      diff = max(abs(a[0] - a[2]) + abs(a[0] - a[1]), diff)
      print(diff)
  
  mini = 0
  maxi = len(a) - 1
  
  if len(a) > 3:
      (l, r) = (a[maxi], a[maxi - 1])
      maxi -= 2
      diff = abs(a[0] - l) + abs(a[0] - r)
      mini += 1
      for i in range(0, n - 3):
          if i % 2 == 0:
              if c < 2:
                  diff += abs(a[mini] - l)
                  l = a[mini]
                  mini += 1
              else:
                  diff += abs(a[maxi] - l)
                  l = a[maxi]
                  maxi -= 1
          else:
              if c < 2:
                  diff += abs(a[mini] - r)
                  r = a[mini]
                  mini += 1
              else:
                  diff += abs(a[maxi] - r)
                  r = a[maxi]
                  maxi -= 1
          if c < 3:
              c += 1
          else:
              c = 0
  
      maxi = len(a) - 1
      mini = 0
      (l, r) = (a[mini], a[mini + 1])
      mini += 2
      diff2 = abs(a[-1] - l) + abs(a[-1] - r)
      maxi -= 1
      for i in range(0, n - 3):
          if i % 2 == 0:
              if c > 1:
                  diff2 += abs(a[mini] - l)
                  l = a[mini]
                  mini += 1
              else:
                  diff2 += abs(a[maxi] - l)
                  l = a[maxi]
                  maxi -= 1
          else:
              if c > 1:
                  diff2 += abs(a[mini] - r)
                  r = a[mini]
                  mini += 1
              else:
                  diff2 += abs(a[maxi] - r)
                  r = a[maxi]
                  maxi -= 1
          if c < 3:
              c += 1
          else:
              c = 0
  
      print(max(diff, diff2))
  
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."}]