//
//  main.swift
//  Atcoder
//
//  Created by Louis Joe Shen on 2020/9/26.
//  Copyright © 2020 Louise Joe Shen. All rights reserved.
//

import Foundation

var input = readLine()!
var inputs = readLine()!.split(separator: " ")

var N = Int(input)!
var A = [Int]()
A.append(0)

for i in 1 ... N{
    A.append(Int(inputs[i - 1])!)
}
var sum = 0
for i in 1 ... N{
    sum += A[i]
}
var ave = 0
if sum % N == 0{
    ave = sum / N
}else{
    ave = sum / N + 1
}

var ans = 0
for i in 1 ... N{
    ans += (A[i] - ave) * (A[i] - ave)
}

print(ans)
