import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
} import java.util.Scanner; Scanner java.util import java.lang.Math; Math java.lang public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int S=0; S 0 int W=0; W 0 int x; x int res; res for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        } {
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        } x = Integer.parseInt(sc.next()) x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc S = S+x S S+x S x W = W + (int) Math.pow(x,2) W W + (int) Math.pow(x,2) W (int) Math.pow(x,2) Math.pow Math x 2 int p = Math.round((float) S/N); p Math.round((float) S/N) Math.round Math (float) S/N (float) S N res = N*((int) Math.pow(p,2))-2*p*S+W res N*((int) Math.pow(p,2))-2*p*S+W N*((int) Math.pow(p,2))-2*p*S N*((int) Math.pow(p,2)) N ((int) Math.pow(p,2)) Math.pow Math p 2 2*p*S 2*p*S 2 p S W System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
} Main
import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
}
