import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	} 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 float sum = 0; sum 0 for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		} int y=0; int y=0; y 0 y<n y n y++ y++ y {
			a[y] = sc.nextInt();
			sum += a[y];
		} {
			a[y] = sc.nextInt();
			sum += a[y];
		} a[y] = sc.nextInt() a[y] a y sc.nextInt() sc.nextInt sc sum += a[y] sum a[y] a y int p = Math.round(sum/n); p Math.round(sum/n) Math.round Math sum/n sum n int res = 0; res 0 for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			res += (a[i] - p)*(a[i] - p);
		} {
			res += (a[i] - p)*(a[i] - p);
		} res += (a[i] - p)*(a[i] - p) res (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(res) System.out.println System.out System System.out res sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

}
