import std.stdio;

void main(){
	auto cin = new Cin();
	
	auto N = cin.line()[0];
	auto arr = cin.rect!(real)()[0];
	//writeln(S);
	auto ave = arr.ave().rint();
	
	
	long cost;
	
	foreach( elm ; arr ){
		cost += cast(long)(elm-ave)^^2;
	}
	
	//ave.writeln();
	cost.writeln();
	//(ave).writeln();
}
auto solve(){
}
unittest{
	
}


import std.stdio,std.conv,std.string;
import std.algorithm,std.array,std.math;

class Cin
{
	T[] line( T = size_t , string token = " " )( size_t m = 1 ){
		T[] arr = [];
		foreach( i ; 0..m ){
			arr ~= this.read!T();
		}
		return arr;
	}
	T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
		T[][] arr = new T[][](m);
		foreach( i ; 0..m ){
			arr[i] = this.read!T(token);
		}
		return arr;
	}
	private T[] read( T = size_t )( string token = " " ){
		T[] arr;
		foreach( elm ; readln().chomp().split(token) ){
			arr ~= elm.to!T();
		}
		return arr;
	}
}

pure T[] span(T)( in T begein , in T end , in T step = 1 ){
	assert( begin < end );
	assert( 0 < step );
	T[] arr;
	for( T i = begein ; i < end ; i += step ){
		arr ~= i;
	}
	return arr;
}

pure T[] map(T)( ref T[] args , T delegate(T)  dlg ){
	foreach( ref arg ; args ){
		arg.dlg();
	}
	return args;
}
pure T sum(T)( in T[] args ){
	T result = 0;
	foreach( arg ; args ){
		result += arg;
	}
	debug writeln( args , "\n" , arg );
	return result;
}
pure T ave(T)( in T[] args ){
	return args.sum()/args.length;
}