import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    } main {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	} {
    		sc.close();
    	} sc.close() sc.close sc {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final int[] X = new int[N]; X new int[N] N double total = 0; total 0 for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    			X[i] = sc.nextInt();
    			total += X[i];
    		} {
    			X[i] = sc.nextInt();
    			total += X[i];
    		} X[i] = sc.nextInt() X[i] X i sc.nextInt() sc.nextInt sc total += X[i] total X[i] X i double average = Math.round(total / N); average Math.round(total / N) Math.round Math total / N total N long totalCost = 0; totalCost 0 for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    			totalCost += (average - X[i]) * (average - X[i]);
    		} {
    			totalCost += (average - X[i]) * (average - X[i]);
    		} totalCost += (average - X[i]) * (average - X[i]) totalCost (average - X[i]) * (average - X[i]) (average - X[i]) average X[i] X i (average - X[i]) average X[i] X i System.out.println(totalCost) System.out.println System.out System System.out totalCost String[] args args public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    }
} public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		final int[] X = new int[N];

    		double total = 0;
    		for (int i=0; i<N; i++) {
    			X[i] = sc.nextInt();
    			total += X[i];
    		}
    		double average = Math.round(total / N);
    		// System.out.println(average);

    		long totalCost = 0;
    		for (int i=0; i<N; i++) {
    			totalCost += (average - X[i]) * (average - X[i]);
    		}

    		System.out.println(totalCost);

    	} finally {
    		sc.close();
    	}
    }
}
