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

public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

} Main static int n = 0; n 0 public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	} main {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	} int anser = 100000000; anser 100000000 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n = scan.nextInt() n scan.nextInt() scan.nextInt scan ArrayList<Integer> address = new ArrayList<>(); address new ArrayList<>() for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			address.add(scan.nextInt());
		} {
			address.add(scan.nextInt());
		} address.add(scan.nextInt()) address.add address scan.nextInt() scan.nextInt scan Collections.sort(address) Collections.sort Collections address for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		} int i = address.get(0); int i = address.get(0); i address.get(0) address.get address 0 i <= address.get(n-1) i address.get(n-1) address.get address n-1 n 1 i++ i++ i {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		} {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		} int sum = sumList(address,i); sum sumList(address,i) sumList address i if(anser > sum) {
				anser = sum;
			} anser > sum anser sum {
				anser = sum;
			} anser = sum anser sum System.out.println(anser) System.out.println System.out System System.out anser String[] args args private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	} sumList {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	} int sum =0; sum 0 for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		} {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		} sum = sum + (j-array.get(i))*(j-array.get(i)) sum sum + (j-array.get(i))*(j-array.get(i)) sum (j-array.get(i))*(j-array.get(i)) (j-array.get(i)) j array.get(i) array.get array i (j-array.get(i)) j array.get(i) array.get array i return sum; sum ArrayList<Integer> array array int j j public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

} public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

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

public class Main {

	static int n = 0;

	public static void main(String[] args) {


		int anser = 100000000;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

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

		for (int i = 0; i < n; i++) {
			address.add(scan.nextInt());
		}

		Collections.sort(address);

		for (int i = address.get(0); i <= address.get(n-1); i++) {

			int sum = sumList(address,i);

			if(anser > sum) {
				anser = sum;
			}

		}

		System.out.println(anser);
	}

	private static int sumList(ArrayList<Integer> array,int j) {

		int sum =0;

		for (int i = 0; i < n; i++) {
			sum = sum + (j-array.get(i))*(j-array.get(i));
		}

		return sum;

	}

}
