output_description: Print the necessary number of candies in total.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      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
  
  There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
  children in a line, then give 1 candy to the first child in the line, 2
  candies to the second child, ..., N candies to the N-th child. How many
  candies will be necessary in total?
samples: [{"input": "3", "output": "6\n    \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n    \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n    \n\nOnly one child. The answer is 1 in this case."}]