import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    }

} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    }

} Main public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    } main {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc ArrayList<Integer> result = new ArrayList<>(); result new ArrayList<>() for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    		result.add(sc.nextInt());
    	} {
    		result.add(sc.nextInt());
    	} result.add(sc.nextInt()) result.add result sc.nextInt() sc.nextInt sc Collections.sort(result) Collections.sort Collections result int min = result.get(0); min result.get(0) result.get result 0 int max = result.get(N-1); max result.get(N-1) result.get result N-1 N 1 int ans = 10000000; ans 10000000 for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	} int i=min; int i=min; i min i<=max i max i++ i++ i {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	} {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	} int sum = 0; sum 0 for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		} int j=0; int j=0; j 0 j<N j N j++ j++ j {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		} {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		} sum += (result.get(j)-i)*(result.get(j)-i) sum (result.get(j)-i)*(result.get(j)-i) (result.get(j)-i) result.get(j) result.get result j i (result.get(j)-i) result.get(j) result.get result j i if(sum<ans) {
    			ans = sum;
    		} sum<ans sum ans {
    			ans = sum;
    		} ans = sum ans sum System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    }

} public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    }

} Main
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();


    	ArrayList<Integer> result = new ArrayList<>();

    	for(int i=0;i<N;i++) {
    		result.add(sc.nextInt());
    	}
    	Collections.sort(result);
    	int min = result.get(0);
    	int max = result.get(N-1);
    	int ans = 10000000;
    	for (int i=min;i<=max;i++) {
    		int sum = 0;
    		for(int j=0;j<N;j++) {
    			sum += (result.get(j)-i)*(result.get(j)-i);
    		}
    		if(sum<ans) {
    			ans = sum;
    		}
    	}
    	System.out.println(ans);
    }

}