import java.util.*;

public class Main{
	public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	}
} Main public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	} main {
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	} 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 double d=(double)sum/n; d (double)sum/n (double)sum n int p=(int)Math.round(d); p (int)Math.round(d) Math.round Math d int sum1=0; sum1 0 for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p)); int i=0; int i=0; i 0 i<n i n i++ i++ i sum1=sum1+((a[i]-p)*(a[i]-p)); sum1=sum1+((a[i]-p)*(a[i]-p)) sum1 sum1+((a[i]-p)*(a[i]-p)) sum1 ((a[i]-p)*(a[i]-p)) (a[i]-p) a[i] a i p (a[i]-p) a[i] a i p System.out.println(sum1) System.out.println System.out System System.out sum1 String arg[] arg public class Main{
	public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	}
} public class Main{
	public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	}
} Main
import java.util.*;

public class Main{
	public static void main(String arg[]){
		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];
		}
		double d=(double)sum/n;
		int p=(int)Math.round(d);
		int sum1=0;
		for(int i=0;i<n;i++)
			sum1=sum1+((a[i]-p)*(a[i]-p));
		System.out.println(sum1);
	}
}