import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] input = new int[N]; input new int[N] N int sum = 0; sum 0 for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			input[i] = sc.nextInt();
			sum += input[i];
		} {
			input[i] = sc.nextInt();
			sum += input[i];
		} input[i] = sc.nextInt() input[i] input i sc.nextInt() sc.nextInt sc sum += input[i] sum input[i] input i double average = sum / (double) N; average sum / (double) N sum (double) N int pos = (int) Math.round(average); pos (int) Math.round(average) Math.round Math average long res = 0; res 0 for (int i : input) {
			res += Math.pow(pos - i, 2);
		} int i input {
			res += Math.pow(pos - i, 2);
		} {
			res += Math.pow(pos - i, 2);
		} res += Math.pow(pos - i, 2) res Math.pow(pos - i, 2) Math.pow Math pos - i pos i 2 System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			sum += input[i];
		}
		double average = sum / (double) N;
		int pos = (int) Math.round(average);
		long res = 0;
		for (int i : input) {
			res += Math.pow(pos - i, 2);
		}
		System.out.println(res);
	}
}
