//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	} main {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a=new int[n]; a new int[n] n int sum=0; sum 0 for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i]=sc.nextInt();
			sum+=a[i];
		} {
			a[i]=sc.nextInt();
			sum+=a[i];
		} a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc sum+=a[i] sum a[i] a i int avg = sum/n; avg sum/n sum n int ans=Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE int pos=-1; pos -1 1 for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		} int i=avg; int i=avg; i avg i<=avg+1 i avg+1 avg 1 i++ i++ i {
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		} {
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		} int s=0; s 0 for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			} int x a {
				s+=(Math.pow((i-x),2));
			} {
				s+=(Math.pow((i-x),2));
			} s+=(Math.pow((i-x),2)) s (Math.pow((i-x),2)) Math.pow Math (i-x) i x 2 if(s<ans)
			{
				ans=s;
				pos=i;
			} s<ans s ans {
				ans=s;
				pos=i;
			} ans=s ans s pos=i pos i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	}

} Main
//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int avg = sum/n;
		int ans=Integer.MAX_VALUE;
		int pos=-1;
		for(int i=avg;i<=avg+1;i++)
		{
			int s=0;
			for(int x:a)
			{
				s+=(Math.pow((i-x),2));
			}
			if(s<ans)
			{
				ans=s;
				pos=i;
			}
				
				
		}
		System.out.println(ans);
		
		

	}

}
