import java.util.Scanner;
class Main
    {
        public static void main(String []args)
        {
            Scanner scan = new Scanner(System.in);
            int N = scan.nextInt();
            int arr[] = new int[N];
            for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            }
            int sum = 0;
            for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            }
            int a = sum/N;
            int b = a+1;
            int aa = 0;
            int bb = 0;
            for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            }
            int ans;
            if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            }
            System.out.println(ans);
        }
    } import java.util.Scanner; Scanner java.util class Main
    {
        public static void main(String []args)
        {
            Scanner scan = new Scanner(System.in);
            int N = scan.nextInt();
            int arr[] = new int[N];
            for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            }
            int sum = 0;
            for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            }
            int a = sum/N;
            int b = a+1;
            int aa = 0;
            int bb = 0;
            for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            }
            int ans;
            if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            }
            System.out.println(ans);
        }
    } Main public static void main(String []args)
        {
            Scanner scan = new Scanner(System.in);
            int N = scan.nextInt();
            int arr[] = new int[N];
            for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            }
            int sum = 0;
            for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            }
            int a = sum/N;
            int b = a+1;
            int aa = 0;
            int bb = 0;
            for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            }
            int ans;
            if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            }
            System.out.println(ans);
        } main {
            Scanner scan = new Scanner(System.in);
            int N = scan.nextInt();
            int arr[] = new int[N];
            for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            }
            int sum = 0;
            for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            }
            int a = sum/N;
            int b = a+1;
            int aa = 0;
            int bb = 0;
            for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            }
            int ans;
            if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            }
            System.out.println(ans);
        } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int arr[] = new int[N]; arr new int[N] N for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
                arr[i] = scan.nextInt();
            } {
                arr[i] = scan.nextInt();
            } arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan int sum = 0; sum 0 for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            } int i =0; int i =0; i 0 i<N i N i++ i++ i {
                sum  += arr[i];
            } {
                sum  += arr[i];
            } sum  += arr[i] sum arr[i] arr i int a = sum/N; a sum/N sum N int b = a+1; b a+1 a 1 int aa = 0; aa 0 int bb = 0; bb 0 for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            } int i =0; int i =0; i 0 i<N i N i++ i++ i {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            } {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            } aa += (a-arr[i])*(a-arr[i]) aa (a-arr[i])*(a-arr[i]) (a-arr[i]) a arr[i] arr i (a-arr[i]) a arr[i] arr i bb += (b-arr[i])*(b-arr[i]) bb (b-arr[i])*(b-arr[i]) (b-arr[i]) b arr[i] arr i (b-arr[i]) b arr[i] arr i int ans; ans if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            } aa<bb aa bb {
                ans =  aa;
            } ans =  aa ans aa {
                ans = bb;
            } ans = bb ans bb System.out.println(ans) System.out.println System.out System System.out ans String []args args
import java.util.Scanner;
class Main
    {
        public static void main(String []args)
        {
            Scanner scan = new Scanner(System.in);
            int N = scan.nextInt();
            int arr[] = new int[N];
            for(int i = 0;i<N;i++)
            {
                arr[i] = scan.nextInt();
            }
            int sum = 0;
            for(int i =0;i<N;i++)
            {
                sum  += arr[i];
            }
            int a = sum/N;
            int b = a+1;
            int aa = 0;
            int bb = 0;
            for(int i =0;i<N;i++)
            {
                aa += (a-arr[i])*(a-arr[i]);
                bb += (b-arr[i])*(b-arr[i]);
            }
            int ans;
            if(aa<bb)
            {
                ans =  aa;
            }
            else
            {
                ans = bb;
            }
            System.out.println(ans);
        }
    }
