/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <math.h>
void quicksort(int number[25],int first,int last);

int main()
{
int n=0;
int i=0;
int j=0;
long int out=0;
int wsum=0;
int *arr;

  scanf("%d",&n);
   //printf("n=%d\n",n);
    arr=malloc(10*n*sizeof(int));
for (i = 0; i < n; i++)
  scanf("%d", &arr[i]);
   quicksort(arr,0,n-1);
   
  for(i=0;i<n;i++)
  {
      wsum+=arr[i];
  }
  out=ceil((double)wsum/n);
  wsum=0;
//printf("%d",out);
    for(j=0;j<n;j++)
    {
        //printf("arr[%d]=%d\n",j,arr[j]);
        wsum+=pow(out-arr[j],2);
    }


//for (i = 0; i < n; i++)
  //printf("%d\n", arr[i]);
  
  printf("\n%d",wsum);
}

void quicksort(int number[25],int first,int last){
   int i, j, pivot, temp;

   if(first<last){
      pivot=first;
      i=first;
      j=last;

      while(i<j){
         while(number[i]<=number[pivot]&&i<last)
            i++;
         while(number[j]>number[pivot])
            j--;
         if(i<j){
            temp=number[i];
            number[i]=number[j];
            number[j]=temp;
         }
      }

      temp=number[pivot];
      number[pivot]=number[j];
      number[j]=temp;
      quicksort(number,first,j-1);
      quicksort(number,j+1,last);

   }
}