import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    }

    public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    }

    public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    } main {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int numOfPerson = sc.nextInt(); numOfPerson sc.nextInt() sc.nextInt sc int sum = 0; sum 0 int[] positions = new int[numOfPerson]; positions new int[numOfPerson] numOfPerson for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        } int i = 0; int i = 0; i 0 i < numOfPerson i numOfPerson i++ i++ i {
            positions[i] = sc.nextInt();
            sum += positions[i];
        } {
            positions[i] = sc.nextInt();
            sum += positions[i];
        } positions[i] = sc.nextInt() positions[i] positions i sc.nextInt() sc.nextInt sc sum += positions[i] sum positions[i] positions i sc.close() sc.close sc double juusin = sum / (double)numOfPerson; juusin sum / (double)numOfPerson sum (double)numOfPerson int p = nearInt(juusin); p nearInt(juusin) nearInt juusin int e = 0; e 0 for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        } int i = 0; int i = 0; i 0 i< numOfPerson i numOfPerson i++ i++ i {
            e += Math.pow((positions[i] - p), 2);
        } {
            e += Math.pow((positions[i] - p), 2);
        } e += Math.pow((positions[i] - p), 2) e Math.pow((positions[i] - p), 2) Math.pow Math (positions[i] - p) positions[i] positions i p 2 System.out.println(e) System.out.println System.out System System.out e String[] args args public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    } nearInt {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    } int p = (int) x; p (int) x if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        } x >= 0 x 0 {
            return (x - p) <= 0.5 ? p : p + 1;
        } return (x - p) <= 0.5 ? p : p + 1; (x - p) <= 0.5 ? p : p + 1 (x - p) <= 0.5 (x - p) x p 0.5 p p + 1 p 1 {
            return (p - x) <= 0.5 ? p : p - 1;
        } return (p - x) <= 0.5 ? p : p - 1; (p - x) <= 0.5 ? p : p - 1 (p - x) <= 0.5 (p - x) p x 0.5 p p - 1 p 1 double x x public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    }

    public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    }

    public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numOfPerson = sc.nextInt();
        int sum = 0;
        int[] positions = new int[numOfPerson];
        for (int i = 0; i < numOfPerson; i++) {
            positions[i] = sc.nextInt();
            sum += positions[i];
        }
        sc.close();

        double juusin = sum / (double)numOfPerson;
        int p = nearInt(juusin);

        int e = 0;
        for (int i = 0; i< numOfPerson; i++) {
            e += Math.pow((positions[i] - p), 2);
        }
        System.out.println(e);
    }

    public static int nearInt(double x) {
        int p = (int) x;
        if (x >= 0) {
            return (x - p) <= 0.5 ? p : p + 1;
        } else {
            return (p - x) <= 0.5 ? p : p - 1;
        }
    }
}