import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	int[] as = readln.chomp.split.map!(to!int).array;
	
	int minsum = int.max;
	for(int i = -100; i <= 100; i ++){
		int sum = 0;
		foreach(a; as) sum += (a - i) * (a - i);
		if(sum < minsum) minsum = sum;
		}
	
	minsum.writeln;
	
	}