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: # coding: utf-8
  # Your code here!
  # coding: utf-8
  from fractions import gcd
  from functools import reduce
  import sys
  
  sys.setrecursionlimit(200000000)
  from inspect import currentframe
  
  
  # my functions here!
  # 標準エラー出力
  def printargs2err(*args):
      names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
      print(
          ", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args),
          file=sys.stderr,
      )
  
  
  def debug(*args):
      print(*args, file=sys.stderr)
  
  
  def printglobals():
      for symbol, value in globals().items():
          print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
  
  
  def printlocals():
      for symbol, value in locals().items():
          print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
  
  
  # 入力（後でいじる）
  def pin(type=int):
      return map(type, input().split())
  
  
  # input
  
  
  def resolve():
      N = int(input())
      b = sorted(list(pin()))
      ans = 10000000
      for i in range(-100, 101):
          temp = sum(map(lambda x: pow((i - x), 2), b))
          ans = min(ans, temp)
      print(ans)
      # print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
  
  
  # if __name__=="__main__":resolve()
  
  """
  #printデバッグ消した？
  #前の問題の結果見てないのに次の問題に行くの？
  """
  """
  お前カッコ閉じるの忘れてるだろ
  """
  import sys
  from io import StringIO
  import unittest
  
  
  class TestClass(unittest.TestCase):
      def assertIO(self, input, output):
          stdout, stdin = sys.stdout, sys.stdin
          sys.stdout, sys.stdin = StringIO(), StringIO(input)
          resolve()
          sys.stdout.seek(0)
          out = sys.stdout.read()[:-1]
          sys.stdout, sys.stdin = stdout, stdin
          self.assertEqual(out, output)
  
      def test_入力例_1(self):
          input = """2
  4 8"""
          output = """8"""
          self.assertIO(input, output)
  
      def test_入力例_2(self):
          input = """3
  1 1 3"""
          output = """3"""
          self.assertIO(input, output)
  
      def test_入力例_3(self):
          input = """3
  4 2 5"""
          output = """5"""
          self.assertIO(input, output)
  
      def test_入力例_4(self):
          input = """4
  -100 -100 -100 -100"""
          output = """0"""
          self.assertIO(input, output)
  
  
  if __name__ == "__main__":
      resolve()
  
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."}]