import java.util.*;
import java.util.stream.Stream;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    }

    private int calc(int i, int[] x) {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    }
} import java.util.*; util.* java import java.util.stream.Stream; Stream java.util.stream class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    }

    private int calc(int i, int[] x) {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    }
} Main final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args private void run() {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    } run {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int l = Integer.MAX_VALUE; l Integer.MAX_VALUE Integer Integer.MAX_VALUE int r = Integer.MIN_VALUE; r Integer.MIN_VALUE Integer Integer.MIN_VALUE int[] x = new int[n]; x new int[n] n for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        } {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        } x[i] = sc.nextInt() x[i] x i sc.nextInt() sc.nextInt sc l = Math.min(l, x[i]) l Math.min(l, x[i]) Math.min Math l x[i] x i r = Math.max(r, x[i]) r Math.max(r, x[i]) Math.max Math r x[i] x i int minCost = Integer.MAX_VALUE; minCost Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        } int i = l; int i = l; i l i <= r i r i++ i++ i {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        } {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        } int cost = calc(i, x); cost calc(i, x) calc i x if (cost < minCost) {
                minCost = cost;
            } cost < minCost cost minCost {
                minCost = cost;
            } minCost = cost minCost cost System.out.println(minCost) System.out.println System.out System System.out minCost private int calc(int i, int[] x) {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    } calc {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    } int cost = 0; cost 0 for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        } int j = 0; int j = 0; j 0 j < x.length j x.length x x.length j++ j++ j {
            cost += Math.pow(x[j] - i, 2);
        } {
            cost += Math.pow(x[j] - i, 2);
        } cost += Math.pow(x[j] - i, 2) cost Math.pow(x[j] - i, 2) Math.pow Math x[j] - i x[j] x j i 2 return cost; cost int i i int[] x x
import java.util.*;
import java.util.stream.Stream;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            l = Math.min(l, x[i]);
            r = Math.max(r, x[i]);
        }

        int minCost = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            int cost = calc(i, x);
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println(minCost);
    }

    private int calc(int i, int[] x) {
        int cost = 0;
        for (int j = 0; j < x.length; j++) {
            cost += Math.pow(x[j] - i, 2);
        }
        return cost;
    }
}
