import java.util.*;
import java.lang.Math;
public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
} import java.util.*; util.* java import java.lang.Math; Math java.lang public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
} Main public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     } main {
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     } Scanner s1=new Scanner(System.in); s1 new Scanner(System.in) int i i j j k=0; k 0 int n; n double m m q; q n=s1.nextInt() n s1.nextInt() s1.nextInt s1 int[] a=new int[n]; a new int[n] n for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        } i=0; i=0 i 0 i<n i n i++ i++ i {
			a[i]=s1.nextInt();
		
			k=k+a[i];
        } {
			a[i]=s1.nextInt();
		
			k=k+a[i];
        } a[i]=s1.nextInt() a[i] a i s1.nextInt() s1.nextInt s1 k=k+a[i] k k+a[i] k a[i] a i int o=k/n; o k/n k n int w=k/n+1; w k/n+1 k/n k n 1 int v=0; v 0 int d=0; d 0 for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		} j=0; j=0 j 0 j<n j n j++ j++ j {
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		} {
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		} m=(double)(o-a[j]) m (double)(o-a[j]) o a[j] a j int b=(int)(Math.pow(m,2.0)); b (int)(Math.pow(m,2.0)) Math.pow Math m 2.0 v=v+b v v+b v b q=(double)(w-a[j]) q (double)(w-a[j]) w a[j] a j int c=(int)(Math.pow(q,2.0)); c (int)(Math.pow(q,2.0)) Math.pow Math q 2.0 d=d+c d d+c d c if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        } v<d v d {
			System.out.println(v);
        } System.out.println(v) System.out.println System.out System System.out v {
			System.out.println(d);
        } System.out.println(d) System.out.println System.out System System.out d String[] args args public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
} public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
} Main
import java.util.*;
import java.lang.Math;
public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
}