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
  
  
  ## io ##
  def IS():
      return sys.stdin.readline().rstrip()
  
  
  def II():
      return int(IS())
  
  
  def MII():
      return list(map(int, IS().split()))
  
  
  def MIIZ():
      return list(map(lambda x: x - 1, MII()))
  
  
  ## dp ##
  def DD2(d1, d2, init=0):
      return [[init] * d2 for _ in range(d1)]
  
  
  def DD3(d1, d2, d3, init=0):
      return [DD2(d2, d3, init) for _ in range(d1)]
  
  
  ## math ##
  def divc(x, y) -> int:
      return -(-x // y)
  
  
  def divf(x, y) -> int:
      return x // y
  
  
  def gcd(x, y):
      while y:
          x, y = y, x % y
      return x
  
  
  def lcm(x, y):
      return x * y // gcd(x, y)
  
  
  def enumerate_divs(n):
      """Return a tuple list of divisor of n"""
      return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0]
  
  
  def get_primes(n=10**3):
      """Return a list of prime numbers n or less"""
      is_prime = [True] * (n + 1)
      is_prime[0] = is_prime[1] = False
      for i in range(2, int(n**0.5) + 1):
          if not is_prime[i]:
              continue
          for j in range(i * 2, n + 1, i):
              is_prime[j] = False
      return [i for i in range(n + 1) if is_prime[i]]
  
  
  def prime_factor(n):
      """Return a list of prime factorization numbers of n"""
      res = []
      for i in range(2, int(n**0.5) + 1):
          while n % i == 0:
              res.append(i)
              n //= i
      if n != 1:
          res.append(n)
      return res
  
  
  ## const ##
  MOD = 10**9 + 7
  ## libs ##
  import itertools as it
  import functools as ft
  from collections import deque, Counter
  from heapq import heapify, heappop, heappush
  from bisect import bisect_left
  
  
  # ======================================================#
  def main():
      import sys
  
  
  ## io ##
  def IS():
      return sys.stdin.readline().rstrip()
  
  
  def II():
      return int(IS())
  
  
  def MII():
      return list(map(int, IS().split()))
  
  
  def MIIZ():
      return list(map(lambda x: x - 1, MII()))
  
  
  ## dp ##
  def DD2(d1, d2, init=0):
      return [[init] * d2 for _ in range(d1)]
  
  
  def DD3(d1, d2, d3, init=0):
      return [DD2(d2, d3, init) for _ in range(d1)]
  
  
  ## math ##
  def divc(x, y) -> int:
      return -(-x // y)
  
  
  def divf(x, y) -> int:
      return x // y
  
  
  def gcd(x, y):
      while y:
          x, y = y, x % y
      return x
  
  
  def lcm(x, y):
      return x * y // gcd(x, y)
  
  
  def enumerate_divs(n):
      """Return a tuple list of divisor of n"""
      return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0]
  
  
  def get_primes(n=10**3):
      """Return a list of prime numbers n or less"""
      is_prime = [True] * (n + 1)
      is_prime[0] = is_prime[1] = False
      for i in range(2, int(n**0.5) + 1):
          if not is_prime[i]:
              continue
          for j in range(i * 2, n + 1, i):
              is_prime[j] = False
      return [i for i in range(n + 1) if is_prime[i]]
  
  
  def prime_factor(n):
      """Return a list of prime factorization numbers of n"""
      res = []
      for i in range(2, int(n**0.5) + 1):
          while n % i == 0:
              res.append(i)
              n //= i
      if n != 1:
          res.append(n)
      return res
  
  
  ## const ##
  MOD = 10**9 + 7
  ## libs ##
  import itertools as it
  import functools as ft
  from collections import deque, Counter
  from heapq import heapify, heappop, heappush
  from bisect import bisect_left
  
  
  # ======================================================#
  def main():
      n = II()
      aa = MII()
      minc = 10**9
      for i in range(-100, 101):
          minc = min(minc, (sum((a - i) ** 2 for a in aa)))
      print(minc)
  
  
  if __name__ == "__main__":
      main()
  
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."}]