import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() double ave = 0; ave 0 for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        } {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        } int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc ave += x ave x list.add(x) list.add list x ave = Math.round(ave / n) ave Math.round(ave / n) Math.round Math ave / n ave n long result = 0; result 0 for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            result += Math.pow(list.get(i) - ave, 2);
        } {
            result += Math.pow(list.get(i) - ave, 2);
        } result += Math.pow(list.get(i) - ave, 2) result Math.pow(list.get(i) - ave, 2) Math.pow Math list.get(i) - ave list.get(i) list.get list i ave 2 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        double ave = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ave += x;
            list.add(x);
        }

        ave = Math.round(ave / n);

        long result = 0;
        for (int i = 0; i < n; i++) {
            result += Math.pow(list.get(i) - ave, 2);
        }

        System.out.println(result);
    }
}