import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	} 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 Integer[] array = new Integer[n]; array new Integer[n] n for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		} {
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		} int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc array[i] = tmp array[i] array i tmp int sum = 0; sum 0 Arrays.sort(array) Arrays.sort Arrays array int mini = 2147483647; mini 2147483647 boolean flag = true; flag true for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 ++i ++i i {
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		} {
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		} if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue; array[i] != array[i+1] array[i] array i array[i+1] array i+1 i 1 {
		        flag = false;
		        break;
		    } flag = false flag false break; continue; if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		} flag System.out.println(0) System.out.println System.out System System.out 0 {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		} for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		} int i = array[0] + 1; int i = array[0] + 1; i array[0] + 1 array[0] array 0 1 i < array[n-1] i array[n-1] array n-1 n 1 ++i ++i i {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		} {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		} for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    } int j = 0; int j = 0; j 0 j < n j n ++j ++j j {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    } {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    } int tmp = Math.abs((i-array[j]) * (i - array[j])); tmp Math.abs((i-array[j]) * (i - array[j])) Math.abs Math (i-array[j]) * (i - array[j]) (i-array[j]) i array[j] array j (i - array[j]) i array[j] array j sum += tmp sum tmp if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0; mini > sum mini sum {
		        mini = sum;
		        sum = 0;
		    } mini = sum mini sum sum = 0 sum 0 sum = 0 sum 0 System.out.println(mini) System.out.println System.out System System.out mini String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	}
}