import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int hito[] = new int[N]; hito new int[N] N int min = 0; min 0 int max = 0; max 0 for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		} int i=0; int i=0; i 0 i < N i N i++ i++ i {
			hito[i] = scan.nextInt();
		} {
			hito[i] = scan.nextInt();
		} hito[i] = scan.nextInt() hito[i] hito i scan.nextInt() scan.nextInt scan Arrays.sort(hito) Arrays.sort Arrays hito min = hito[0] min hito[0] hito 0 max = hito[N - 1] max hito[N - 1] hito N - 1 N 1 int minsum = 0; minsum 0 for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		} int i = min ; int i = min ; i min i <= max i max i++ i++ i {
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		} {
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		} int sum = 0; sum 0 int P = i; P i for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			} int j=0; int j=0; j 0 j < N j N j++ j++ j {
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			} {
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			} sum = sum + (int)(Math.pow(hito[j] - P, 2)) sum sum + (int)(Math.pow(hito[j] - P, 2)) sum (int)(Math.pow(hito[j] - P, 2)) Math.pow Math hito[j] - P hito[j] hito j P 2 if (i == min || sum < minsum) {
				minsum = sum;
			} i == min || sum < minsum i == min i min sum < minsum sum minsum {
				minsum = sum;
			} minsum = sum minsum sum System.out.println(minsum) System.out.println System.out System System.out minsum String[] args args public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	}
} public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	}
} Main
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int hito[] = new int[N];
		int min = 0;
		int max = 0;

		for(int i=0; i < N; i++){
			hito[i] = scan.nextInt();
		}

		Arrays.sort(hito);
		min = hito[0];
		max = hito[N - 1];
		
		int minsum = 0;

		for(int i = min ; i <= max ; i++){
			int sum = 0;
			int P = i;
			for(int j=0; j < N; j++){
				sum = sum + (int)(Math.pow(hito[j] - P, 2));
			}
			if (i == min || sum < minsum) {
				minsum = sum;
			}
		}
		System.out.println(minsum);

	}
}