import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  }
} 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 A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  }
} Main public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  } main {
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  } Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int A[] = new int[N]; A new int[N] N int B[] = new int[N+1]; B new int[N+1] N+1 N 1 B[0] =0 B[0] B 0 0 for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];} int i=0; int i=0; i 0 i<N i N i++ i++ i {
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];} {
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];} A[i]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc B[i+1]=B[i]+A[i] B[i+1] B i+1 i 1 B[i]+A[i] B[i] B i A[i] A i int C =10*B[N]/N; C 10*B[N]/N 10*B[N] 10 B[N] B N N int D =B[N]/N; D B[N]/N B[N] B N N int x=D; x D int y=0; y 0 int z; z if(C>D*10+5){z=x+1;}else{z=x;} C>D*10+5 C D*10+5 D*10 D 10 5 {z=x+1;} z=x+1 z x+1 x 1 {z=x;} z=x z x for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);} int j=0; int j=0; j 0 j<N j N j++ j++ j {
      y=y+(A[j]-z)*(A[j]-z);} {
      y=y+(A[j]-z)*(A[j]-z);} y=y+(A[j]-z)*(A[j]-z) y y+(A[j]-z)*(A[j]-z) y (A[j]-z)*(A[j]-z) (A[j]-z) A[j] A j z (A[j]-z) A[j] A j z System.out.println(y) System.out.println System.out System System.out y String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N=sc.nextInt();
    int A[] = new int[N];
    int B[] = new int[N+1];
    B[0] =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      B[i+1]=B[i]+A[i];}
    int C =10*B[N]/N;
    int D =B[N]/N;
    int x=D;int y=0;int z;
    if(C>D*10+5){z=x+1;}else{z=x;}
    for(int j=0;j<N;j++){
      y=y+(A[j]-z)*(A[j]-z);}
    System.out.println(y);
  }
}