output_description: Print the minimum total cost to achieve Evi's objective.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      a_1 a_2 ... a_N
attempt: import sys
  import math
  
  
  def i():
      return int(sys.stdin.readline().replace("\n", ""))
  
  
  def i2():
      return map(int, sys.stdin.readline().replace("\n", "").split())
  
  
  def s():
      return str(sys.stdin.readline().replace("\n", ""))
  
  
  def l():
      return list(sys.stdin.readline().replace("\n", ""))
  
  
  def intl():
      return [int(k) for k in sys.stdin.readline().replace("\n", "").split()]
  
  
  def lx():
      return list(
          map(lambda x: int(x) * -1, sys.stdin.readline().replace("\n", "").split())
      )
  
  
  def t():
      return tuple(map(int, sys.stdin.readline().replace("\n", "").split()))
  
  
  if __name__ == "__main__":
      pass
  
  n = i()
  a = intl()
  if n == 1:
      print(0)
  else:
      s = max(a) + min(a)
      k1 = s // 2
      k2 = s // 2 + s % 2
      k3 = s // 2 - 1
      c1 = 0
      c2 = 0
      c3 = 0
      for i in range(n):
          c3 += (a[i] - k3) ** 2
          c2 += (a[i] - k2) ** 2
          c1 += (a[i] - k1) ** 2
      print(min(c1, c2, c3))
  
problem_description: Statement
  
  Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal
  **integers** by transforming some of them.
  
  He may transform each integer at most once. Transforming an integer x into
  another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to
  pay the cost separately for transforming each of them (See Sample 2).
  
  Find the minimum total cost to achieve his objective.
samples: [{"input": "2\n    4 8", "output": "8\n    \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n    1 1 3", "output": "3\n    \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n    4 2 5", "output": "5\n    \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n    -100 -100 -100 -100", "output": "0\n    \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]