import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    }
} Main public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    } main {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] a = new int[n]; a new int[n] n int sum = 0; sum 0 for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            a[i] = s.nextInt();
            sum+=a[i];
        } {
            a[i] = s.nextInt();
            sum+=a[i];
        } a[i] = s.nextInt() a[i] a i s.nextInt() s.nextInt s sum+=a[i] sum a[i] a i int p = sum/n; p sum/n sum n int ans1=0; ans1 0 int ans2=0; ans2 0 for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        } {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        } ans1+=Math.pow((a[i]-p),2) ans1 Math.pow((a[i]-p),2) Math.pow Math (a[i]-p) a[i] a i p 2 ans2+=Math.pow((a[i]-p-1),2) ans2 Math.pow((a[i]-p-1),2) Math.pow Math (a[i]-p-1) a[i]-p-1 a[i] a i p 1 2 if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2); ans1<ans2 ans1 ans2 System.out.println(ans1) System.out.println System.out System System.out ans1 System.out.println(ans2) System.out.println System.out System System.out ans2 String[] args args public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    }
} public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    }
} Main
import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            a[i] = s.nextInt();
            sum+=a[i];
        }
        int p = sum/n;
        int ans1=0;
        int ans2=0;
        for(int i=0; i<n; i++)
        {
            ans1+=Math.pow((a[i]-p),2);
            ans2+=Math.pow((a[i]-p-1),2);
        }
        if(ans1<ans2)
        System.out.println(ans1);
        else System.out.println(ans2);
    }
}