import java.util.Scanner;

public final class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	}

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

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	}

} Main public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	} main {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	} try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		} {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		} Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] positions = new int[n]; positions new int[n] n int maxPosition = 0; maxPosition 0 for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			} {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			} int p = scanner.nextInt(); p scanner.nextInt() scanner.nextInt scanner positions[i] = p positions[i] positions i p if (p > maxPosition) {
					maxPosition = p;
				} p > maxPosition p maxPosition {
					maxPosition = p;
				} maxPosition = p maxPosition p int minEnergy = Integer.MAX_VALUE; minEnergy Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			} int p = 0; int p = 0; p 0 p <= maxPosition p maxPosition p++ p++ p {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			} {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			} int energy = 0; energy 0 for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				} int i = 0; int i = 0; i 0 i < positions.length i positions.length positions positions.length i++ i++ i {
					energy += (int) Math.pow(positions[i] - p, 2);
				} {
					energy += (int) Math.pow(positions[i] - p, 2);
				} energy += (int) Math.pow(positions[i] - p, 2) energy (int) Math.pow(positions[i] - p, 2) Math.pow Math positions[i] - p positions[i] positions i p 2 if (energy < minEnergy) {
					minEnergy = energy;
				} energy < minEnergy energy minEnergy {
					minEnergy = energy;
				} minEnergy = energy minEnergy energy System.out.println(minEnergy) System.out.println System.out System System.out minEnergy String[] args args public final class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	}

} public final class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	}

} Main
import java.util.Scanner;

public final class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] positions = new int[n];

			int maxPosition = 0;
			for (int i = 0; i < n; i++) {
				int p = scanner.nextInt();
				positions[i] = p;
				if (p > maxPosition) {
					maxPosition = p;
				}
			}

			int minEnergy = Integer.MAX_VALUE;
			for (int p = 0; p <= maxPosition; p++) {
				int energy = 0;
				for (int i = 0; i < positions.length; i++) {
					energy += (int) Math.pow(positions[i] - p, 2);
				}
				if (energy < minEnergy) {
					minEnergy = energy;
				}
			}

			System.out.println(minEnergy);
		}
	}

}
