import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    }
} Main public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    } main {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ary = new int[n]; ary new int[n] n int sum = 0; sum 0 for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	} {
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	} ary[i] = sc.nextInt() ary[i] ary i sc.nextInt() sc.nextInt sc sum += ary[i] sum ary[i] ary i sc.close() sc.close sc int ans = 0; ans 0 double q = Math.round((double)sum / n); q Math.round((double)sum / n) Math.round Math (double)sum / n (double)sum n for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		ans += Math.pow((ary[i] - q), 2);
    	} {
    		ans += Math.pow((ary[i] - q), 2);
    	} ans += Math.pow((ary[i] - q), 2) ans Math.pow((ary[i] - q), 2) Math.pow Math (ary[i] - q) ary[i] ary i q 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] ary = new int[n];
    	int sum = 0;
    	for(int i = 0; i < n; i++){
    		 ary[i] = sc.nextInt();
    		 sum += ary[i];
    	}
    	sc.close();
    	int ans = 0;
    	double q = Math.round((double)sum / n);
    	for(int i = 0; i < n; i++){
    		ans += Math.pow((ary[i] - q), 2);
    	}
    	System.out.println(ans);
    }
}