import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	}
} import java.util.Arrays; Arrays java.util 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[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] X = new int[N]; X new int[N] N for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			X[i] = sc.nextInt();
		} {
			X[i] = sc.nextInt();
		} X[i] = sc.nextInt() X[i] X i sc.nextInt() sc.nextInt sc int Xsum = Arrays.stream(X).sum(); Xsum Arrays.stream(X).sum() Arrays.stream(X).sum Arrays.stream(X) Arrays.stream Arrays X int average = Xsum / X.length; average Xsum / X.length Xsum X.length X X.length if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		} (double)Xsum % X.length != 0.0 (double)Xsum % X.length (double)Xsum X.length X X.length 0.0 {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} int[] sums = new int[2]; sums new int[2] 2 for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			} int i = 0; int i = 0; i 0 i < X.length i X.length X X.length i++ i++ i {
				sums[0] += (X[i]-average) * (X[i]-average);
			} {
				sums[0] += (X[i]-average) * (X[i]-average);
			} sums[0] += (X[i]-average) * (X[i]-average) sums[0] sums 0 (X[i]-average) * (X[i]-average) (X[i]-average) X[i] X i average (X[i]-average) X[i] X i average int averagePlusOne = average + 1; averagePlusOne average + 1 average 1 for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			} int i = 0; int i = 0; i 0 i < X.length i X.length X X.length i++ i++ i {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			} {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			} sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne) sums[1] sums 1 (X[i]-averagePlusOne) * (X[i]-averagePlusOne) (X[i]-averagePlusOne) X[i] X i averagePlusOne (X[i]-averagePlusOne) X[i] X i averagePlusOne System.out.println(Arrays.stream(sums).min().getAsInt()) System.out.println System.out System System.out Arrays.stream(sums).min().getAsInt() Arrays.stream(sums).min().getAsInt Arrays.stream(sums).min() Arrays.stream(sums).min Arrays.stream(sums) Arrays.stream Arrays sums {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		} int sum = 0; sum 0 for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			} int i = 0; int i = 0; i 0 i < X.length i X.length X X.length i++ i++ i {
				sum += (X[i]-average) * (X[i]-average);
			} {
				sum += (X[i]-average) * (X[i]-average);
			} sum += (X[i]-average) * (X[i]-average) sum (X[i]-average) * (X[i]-average) (X[i]-average) X[i] X i average (X[i]-average) X[i] X i average System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}

		int Xsum = Arrays.stream(X).sum();
		int average = Xsum / X.length;
		if((double)Xsum % X.length != 0.0) {

			int[] sums = new int[2];

			for (int i = 0; i < X.length; i++) {
				sums[0] += (X[i]-average) * (X[i]-average);
			}

			int averagePlusOne = average + 1;
			for (int i = 0; i < X.length; i++) {
				sums[1] += (X[i]-averagePlusOne) * (X[i]-averagePlusOne);
			}

			System.out.println(Arrays.stream(sums).min().getAsInt());

		} else {

			int sum = 0;
			for (int i = 0; i < X.length; i++) {
				sum += (X[i]-average) * (X[i]-average);
			}
			System.out.println(sum);
		}
	}
}