import java.util.Scanner;


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

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
} Main public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	} main {

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] xs = new int[N]; xs new int[N] N for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

        	xs[i] = Integer.parseInt(sc.next());
        } {

        	xs[i] = Integer.parseInt(sc.next());
        } xs[i] = Integer.parseInt(sc.next()) xs[i] xs i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc quick_sort(xs, 0, xs.length-1) quick_sort xs 0 xs.length-1 xs.length xs xs.length 1 int sum = 0; sum 0 int current = 0; current 0 boolean flg = true; flg true for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        } int i = xs[0]; int i = xs[0]; i xs[0] xs 0 i <= xs[N-1] i xs[N-1] xs N-1 N 1 i++ i++ i {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        } {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        } for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	} int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	} {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	} int pos = (xs[j]-i) * (xs[j]-i); pos (xs[j]-i) * (xs[j]-i) (xs[j]-i) xs[j] xs j i (xs[j]-i) xs[j] xs j i current += pos current pos if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	} current < sum || flg current < sum current sum flg {
        		sum = current;
        		flg = false;
        	} sum = current sum current flg = false flg false current = 0 current 0 System.out.println(sum) System.out.println System.out System System.out sum String[] args args static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    } quick_sort {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    } if (left>=right) {
            return;
        } left>=right left right {
            return;
        } return; int p = d[(left+right)/2]; p d[(left+right)/2] d (left+right)/2 (left+right) left right 2 int l = left l left r = right r right tmp; tmp while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        } l<=r l r {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        } while(d[l] < p) { l++; } d[l] < p d[l] d l p { l++; } l++ l while(d[r] > p) { r--; } d[r] > p d[r] d r p { r--; } r-- r if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            } l<=r l r {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            } tmp = d[l] tmp d[l] d l d[l] = d[r] d[l] d l d[r] d r d[r] = tmp d[r] d r tmp l++ l r-- r quick_sort(d, left, r) quick_sort d left r quick_sort(d, l, right) quick_sort d l right int[] d d int left left int right right public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
} public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
} Main
import java.util.Scanner;


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

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
}