import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    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[] array = new int[n]; array new int[n] n int sum = 0; sum 0 for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
      sum += array[i];
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      array[i] = sc.nextInt();
      sum += array[i];
    } {
      array[i] = sc.nextInt();
      sum += array[i];
    } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc sum += array[i] sum array[i] array i int p=0; p 0 p = sum/n p sum/n sum n if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    } (double)sum/n-sum/n!=0 (double)sum/n-sum/n (double)sum/n (double)sum n sum/n sum n 0 {
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    } if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      } sum/n+1-(double)sum/n > (double)sum/n-sum/n sum/n+1-(double)sum/n sum/n+1 sum/n sum n 1 (double)sum/n (double)sum n (double)sum/n-sum/n (double)sum/n (double)sum n sum/n sum n {
        p = sum/n;
        if(p==0){p=1;}
      } p = sum/n p sum/n sum n if(p==0){p=1;} p==0 p 0 {p=1;} p=1 p 1 {
        p = sum/n + 1;
        if(p==101){p -= 1;}
      } p = sum/n + 1 p sum/n + 1 sum/n sum n 1 if(p==101){p -= 1;} p==101 p 101 {p -= 1;} p -= 1 p 1 long ans = 0; ans 0 for(int a: array){
      ans += (a-p) * (a-p);
    } int a array {
      ans += (a-p) * (a-p);
    } {
      ans += (a-p) * (a-p);
    } ans += (a-p) * (a-p) ans (a-p) * (a-p) (a-p) a p (a-p) a p 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){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

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

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
}