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

class Main{

    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextDouble();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        }
        scanner.close();
        double sum = 0;
        for (int i : list) {
            sum += i;
        }
        double p1 = Math.floor(sum/n);
        double p2 = Math.ceil(sum/n);
        double result1 = 0;
        double result2 = 0;
        for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        }
        if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        }
        
    }
} import java.util.Scanner; Scanner java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.lang.Math; Math java.lang class Main{

    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextDouble();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        }
        scanner.close();
        double sum = 0;
        for (int i : list) {
            sum += i;
        }
        double p1 = Math.floor(sum/n);
        double p2 = Math.ceil(sum/n);
        double result1 = 0;
        double result2 = 0;
        for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        }
        if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        }
        
    }
} Main public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextDouble();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        }
        scanner.close();
        double sum = 0;
        for (int i : list) {
            sum += i;
        }
        double p1 = Math.floor(sum/n);
        double p2 = Math.ceil(sum/n);
        double result1 = 0;
        double result2 = 0;
        for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        }
        if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        }
        
    } main {
        
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextDouble();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        }
        scanner.close();
        double sum = 0;
        for (int i : list) {
            sum += i;
        }
        double p1 = Math.floor(sum/n);
        double p2 = Math.ceil(sum/n);
        double result1 = 0;
        double result2 = 0;
        for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        }
        if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        }
        
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) double n = scanner.nextDouble(); n scanner.nextDouble() scanner.nextDouble scanner List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            int input = scanner.nextInt();
            list.add(input);
        } {
            int input = scanner.nextInt();
            list.add(input);
        } int input = scanner.nextInt(); input scanner.nextInt() scanner.nextInt scanner list.add(input) list.add list input scanner.close() scanner.close scanner double sum = 0; sum 0 for (int i : list) {
            sum += i;
        } int i list {
            sum += i;
        } {
            sum += i;
        } sum += i sum i double p1 = Math.floor(sum/n); p1 Math.floor(sum/n) Math.floor Math sum/n sum n double p2 = Math.ceil(sum/n); p2 Math.ceil(sum/n) Math.ceil Math sum/n sum n double result1 = 0; result1 0 double result2 = 0; result2 0 for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        } int i list {
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        } {
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        } result1 += Math.pow(i-p1, 2) result1 Math.pow(i-p1, 2) Math.pow Math i-p1 i p1 2 result2 += Math.pow(i-p2, 2) result2 Math.pow(i-p2, 2) Math.pow Math i-p2 i p2 2 if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        } result1 > result2 result1 result2 {
            System.out.println((int)result2);
        } System.out.println((int)result2) System.out.println System.out System System.out (int)result2 {
            System.out.println((int)result1);
        } System.out.println((int)result1) System.out.println System.out System System.out (int)result1 String[] args args
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.lang.Math;

class Main{

    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        double n = scanner.nextDouble();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int input = scanner.nextInt();
            list.add(input);
        }
        scanner.close();
        double sum = 0;
        for (int i : list) {
            sum += i;
        }
        double p1 = Math.floor(sum/n);
        double p2 = Math.ceil(sum/n);
        double result1 = 0;
        double result2 = 0;
        for(int i : list){
            result1 += Math.pow(i-p1, 2);
            result2 += Math.pow(i-p2, 2);
        }
        if(result1 > result2){
            System.out.println((int)result2);
        }else{
            System.out.println((int)result1);
        }
        
    }
}