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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

} 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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

} 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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	} 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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	} 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 sc.close() sc.close sc int min = x[0]; min x[0] x 0 int max = x[0]; max x[0] x 0 for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		} {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		} min = Math.min(x[i], min) min Math.min(x[i], min) Math.min Math x[i] x i min max = Math.max(x[i], max) max Math.max(x[i], max) Math.max Math x[i] x i max int ans = Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		} int i = min; int i = min; i min i <= max i max i++ i++ i {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		} {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		} int cost = 0; cost 0 for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				cost += (x[j] - i) * (x[j]-i);
			} {
				cost += (x[j] - i) * (x[j]-i);
			} cost += (x[j] - i) * (x[j]-i) cost (x[j] - i) * (x[j]-i) (x[j] - i) x[j] x j i (x[j]-i) x[j] x j i ans = Math.min(cost, ans) ans Math.min(cost, ans) Math.min Math cost ans System.out.println(ans) System.out.println System.out System System.out ans 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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

} 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();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

} 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[] x = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

}
