import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
}
			 import java.util.*; util.* java public class Main
{
	public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
} Main public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	} main {
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	} Scanner s1=new Scanner (System.in); s1 new Scanner (System.in) int n n r r sum=0; sum 0 n=s1.nextInt() n s1.nextInt() s1.nextInt s1 int[] m=new int[n]; m new int[n] n for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			m[i]=s1.nextInt();


		} {
			m[i]=s1.nextInt();


		} m[i]=s1.nextInt() m[i] m i s1.nextInt() s1.nextInt s1 Arrays.sort(m) Arrays.sort Arrays m int min = n* m[n-1] * m[n-1]; min n* m[n-1] * m[n-1] n* m[n-1] * m[n-1] n m[n-1] m n-1 n 1 m[n-1] m n-1 n 1 for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		} int i = m[0] ; int i = m[0] ; i m[0] m 0 i <= m[n-1] i m[n-1] m n-1 n 1 i++ i++ i {
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		} {
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		} int temp = 0; temp 0 for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			} int j = 0 ; int j = 0 ; j 0 j < n j n j++ j++ j {
				temp += Math.pow(i-m[j], 2);
			} {
				temp += Math.pow(i-m[j], 2);
			} temp += Math.pow(i-m[j], 2) temp Math.pow(i-m[j], 2) Math.pow Math i-m[j] i m[j] m j 2 min = Math.min(temp, min) min Math.min(temp, min) Math.min Math temp min System.out.println(min) System.out.println System.out System System.out min String args[] args public class Main
{
	public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
} public class Main
{
	public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
} Main
import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner s1=new Scanner (System.in);
		int n,r,sum=0;
		n=s1.nextInt();
		int[] m=new int[n];
		for(int i=0;i<n;i++)
		{
			m[i]=s1.nextInt();


		}
		Arrays.sort(m);
		int min = n* m[n-1] * m[n-1];
		for(int i = m[0] ; i <= m[n-1] ;i++) 
		{
			int temp = 0;
			for(int j = 0 ; j < n ; j++) 
			{
				temp += Math.pow(i-m[j], 2);
			}
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
}
			