import java.util.*;
class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
			int [] b = new int[a];
      //int c = sc.nextInt();



			int sum = 0;
      for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			}

			int pos = 0;
			if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a;
			
			sum = 0;
			for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			}
			System.out.println(sum);

    }


    public static long factorial(long n){
      if(n == 0){
        return new Long(1);
       }
       System.out.println(n * factorial(n-1));

      return n * factorial(n-1);
    }
} import java.util.*; util.* java class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
			int [] b = new int[a];
      //int c = sc.nextInt();



			int sum = 0;
      for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			}

			int pos = 0;
			if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a;
			
			sum = 0;
			for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			}
			System.out.println(sum);

    }


    public static long factorial(long n){
      if(n == 0){
        return new Long(1);
       }
       System.out.println(n * factorial(n-1));

      return n * factorial(n-1);
    }
} Main public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
			int [] b = new int[a];
      //int c = sc.nextInt();



			int sum = 0;
      for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			}

			int pos = 0;
			if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a;
			
			sum = 0;
			for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			}
			System.out.println(sum);

    } main {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
			int [] b = new int[a];
      //int c = sc.nextInt();



			int sum = 0;
      for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			}

			int pos = 0;
			if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a;
			
			sum = 0;
			for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			}
			System.out.println(sum);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int [] b = new int[a]; b new int[a] a int sum = 0; sum 0 for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
				b[i] = sc.nextInt();
				sum += b[i];
			} {
				b[i] = sc.nextInt();
				sum += b[i];
			} b[i] = sc.nextInt() b[i] b i sc.nextInt() sc.nextInt sc sum += b[i] sum b[i] b i int pos = 0; pos 0 if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a; sum%a >= (float)a/2 sum%a sum a (float)a/2 (float)a 2 pos = (sum/a) + 1 pos (sum/a) + 1 (sum/a) sum a 1 pos = sum/a pos sum/a sum a sum = 0 sum 0 for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {

				sum += (b[i] - pos)*(b[i] - pos);

			} {

				sum += (b[i] - pos)*(b[i] - pos);

			} sum += (b[i] - pos)*(b[i] - pos) sum (b[i] - pos)*(b[i] - pos) (b[i] - pos) b[i] b i pos (b[i] - pos) b[i] b i pos System.out.println(sum) System.out.println System.out System System.out sum String args[] args public static long factorial(long n){
      if(n == 0){
        return new Long(1);
       }
       System.out.println(n * factorial(n-1));

      return n * factorial(n-1);
    } factorial {
      if(n == 0){
        return new Long(1);
       }
       System.out.println(n * factorial(n-1));

      return n * factorial(n-1);
    } if(n == 0){
        return new Long(1);
       } n == 0 n 0 {
        return new Long(1);
       } return new Long(1); new Long(1) System.out.println(n * factorial(n-1)) System.out.println System.out System System.out n * factorial(n-1) n factorial(n-1) factorial n-1 n 1 return n * factorial(n-1); n * factorial(n-1) n factorial(n-1) factorial n-1 n 1 long n n
import java.util.*;
class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
			int [] b = new int[a];
      //int c = sc.nextInt();



			int sum = 0;
      for(int i = 0;i < a; i++){
				b[i] = sc.nextInt();
				sum += b[i];
			}

			int pos = 0;
			if(sum%a >= (float)a/2)pos = (sum/a) + 1;
			else pos = sum/a;
			
			sum = 0;
			for(int i = 0;i < a; i++){

				sum += (b[i] - pos)*(b[i] - pos);

			}
			System.out.println(sum);

    }


    public static long factorial(long n){
      if(n == 0){
        return new Long(1);
       }
       System.out.println(n * factorial(n-1));

      return n * factorial(n-1);
    }
}
