import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int pointSum = 0;
		scanner.useDelimiter("[\r\n]+");
        scanner = new Scanner(new StringReader(scanner.next()));
        List<Integer> users = new ArrayList<>();
        while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        }
        int middle = pointSum / num;
        if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        }
        long sum = 0;
        for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        }
		System.out.println(sum);
	}

} import java.io.StringReader; StringReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int pointSum = 0;
		scanner.useDelimiter("[\r\n]+");
        scanner = new Scanner(new StringReader(scanner.next()));
        List<Integer> users = new ArrayList<>();
        while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        }
        int middle = pointSum / num;
        if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        }
        long sum = 0;
        for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        }
		System.out.println(sum);
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int pointSum = 0;
		scanner.useDelimiter("[\r\n]+");
        scanner = new Scanner(new StringReader(scanner.next()));
        List<Integer> users = new ArrayList<>();
        while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        }
        int middle = pointSum / num;
        if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        }
        long sum = 0;
        for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        }
		System.out.println(sum);
	} main {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int pointSum = 0;
		scanner.useDelimiter("[\r\n]+");
        scanner = new Scanner(new StringReader(scanner.next()));
        List<Integer> users = new ArrayList<>();
        while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        }
        int middle = pointSum / num;
        if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        }
        long sum = 0;
        for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        }
		System.out.println(sum);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int num = scanner.nextInt(); num scanner.nextInt() scanner.nextInt scanner int pointSum = 0; pointSum 0 scanner.useDelimiter("[\r\n]+") scanner.useDelimiter scanner "[\r\n]+" scanner = new Scanner(new StringReader(scanner.next())) scanner new Scanner(new StringReader(scanner.next())) List<Integer> users = new ArrayList<>(); users new ArrayList<>() while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        } scanner.hasNextInt() scanner.hasNextInt scanner {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        } int user = scanner.nextInt(); user scanner.nextInt() scanner.nextInt scanner users.add(user) users.add users user pointSum += user pointSum user int middle = pointSum / num; middle pointSum / num pointSum num if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        } (pointSum % num) > ((double)num / 2) (pointSum % num) pointSum num ((double)num / 2) (double)num 2 {
        	middle++;
        } middle++ middle long sum = 0; sum 0 for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        } Integer u users {
        	sum += Math.pow(u - middle, 2);
        } {
        	sum += Math.pow(u - middle, 2);
        } sum += Math.pow(u - middle, 2) sum Math.pow(u - middle, 2) Math.pow Math u - middle u middle 2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int pointSum = 0;
		scanner.useDelimiter("[\r\n]+");
        scanner = new Scanner(new StringReader(scanner.next()));
        List<Integer> users = new ArrayList<>();
        while(scanner.hasNextInt()) {
        	int user = scanner.nextInt();
        	users.add(user);
        	pointSum += user;
        }
        int middle = pointSum / num;
        if((pointSum % num) > ((double)num / 2) ) {
        	middle++;
        }
        long sum = 0;
        for(Integer u : users) {
        	sum += Math.pow(u - middle, 2);
        }
		System.out.println(sum);
	}

}