import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner 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<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        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 List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            list.add(sc.nextInt());
        } {
            list.add(sc.nextInt());
        } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc int max = Collections.max(list); max Collections.max(list) Collections.max Collections list int min = Collections.min(list); min Collections.min(list) Collections.min Collections list long ans = Long.MAX_VALUE; ans Long.MAX_VALUE Long Long.MAX_VALUE for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        } int i=min; int i=min; i min i<=max i max i++ i++ i {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        } {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        } long total = 0; total 0 for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            } int j=0; int j=0; j 0 j<list.size() j list.size() list.size list j++ j++ j {
                total += Math.pow(list.get(j) - i, 2);
            } {
                total += Math.pow(list.get(j) - i, 2);
            } total += Math.pow(list.get(j) - i, 2) total Math.pow(list.get(j) - i, 2) Math.pow Math list.get(j) - i list.get(j) list.get list j i 2 if(total < ans) ans = total; total < ans total ans ans = total ans total 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) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    }
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        int max = Collections.max(list);
        int min = Collections.min(list);
        long ans = Long.MAX_VALUE;
        for(int i=min; i<=max; i++) {
            long total = 0;
            for(int j=0; j<list.size(); j++) {
                total += Math.pow(list.get(j) - i, 2);
            }
            if(total < ans) ans = total;
        }
        System.out.println(ans);
    }
}