import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class  Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    }
} import javax.print.DocFlavor; DocFlavor javax.print import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class  Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    } main {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader String[] l = reader.readLine().split(" "); l reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int s = 0; s 0 int sumsq = 0; sumsq 0 for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        } String t l {
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        } {
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        } int y = Integer.parseInt(t); y Integer.parseInt(t) Integer.parseInt Integer t s=s+y s s+y s y sumsq+=y*y sumsq y*y y y int p =  (s/N); p (s/N) s N System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq))) System.out.println System.out System System.out Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)) Math.min Math (N*p*p-2*p*s+sumsq) N*p*p-2*p*s N*p*p N*p*p N p p 2*p*s 2*p*s 2 p s sumsq (N*(p+1)*(p+1) - 2*(p+1)*s+sumsq) N*(p+1)*(p+1) - 2*(p+1)*s N*(p+1)*(p+1) N*(p+1)*(p+1) N (p+1) p 1 (p+1) p 1 2*(p+1)*s 2*(p+1)*s 2 (p+1) p 1 s sumsq String[] args args public class  Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    }
} public class  Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    }
} Main
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class  Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] l = reader.readLine().split(" ");
        int s = 0;
        int sumsq = 0;
        for(String t:l){
            int y = Integer.parseInt(t);
            s=s+y;
            sumsq+=y*y;
        }
        int p =  (s/N);
        System.out.println(Math.min((N*p*p-2*p*s+sumsq),(N*(p+1)*(p+1) - 2*(p+1)*s+sumsq)));

    }
}
