import java.util.*;

import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main static PrintWriter out; out static StringBuilder sb; sb static long mod = 1000000007; mod 1000000007 static int inf = (int) 1e15; inf (int) 1e15 static ArrayList<Integer>[] adL adL adH; adH static int n n q; q public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	} main {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) out = new PrintWriter(System.out) out new PrintWriter(System.out) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc long ans=Long.MAX_VALUE; ans Long.MAX_VALUE Long Long.MAX_VALUE int []a=new int [n]; a new int [n] n for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc Arrays.sort(a) Arrays.sort Arrays a for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         } int i=a[0]; int i=a[0]; i a[0] a 0 i<=a[n-1] i a[n-1] a n-1 n 1 i++ i++ i {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         } {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         } long tem=0; tem 0 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]); int j=0; int j=0; j 0 j<n j n j++ j++ j tem+=(i-a[j])*(i-a[j]); tem+=(i-a[j])*(i-a[j]) tem (i-a[j])*(i-a[j]) (i-a[j]) i a[j] a j (i-a[j]) i a[j] a j ans=Math.min(ans, tem) ans Math.min(ans, tem) Math.min Math ans tem System.out.println(ans) System.out.println System.out System System.out ans out.flush() out.flush out String[] args args static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	} Scanner StringTokenizer st; st BufferedReader br; br public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		} Scanner {
			br = new BufferedReader(new InputStreamReader(system));
		} br = new BufferedReader(new InputStreamReader(system)) br new BufferedReader(new InputStreamReader(system)) InputStream system system public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		} Scanner {
			br = new BufferedReader(new FileReader(file));
		} br = new BufferedReader(new FileReader(file)) br new BufferedReader(new FileReader(file)) String file file public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} next {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine()); st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public String nextLine() throws IOException {
			return br.readLine();
		} nextLine {
			return br.readLine();
		} return br.readLine(); br.readLine() br.readLine br public int nextInt() throws IOException {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public char nextChar() throws IOException {
			return next().charAt(0);
		} nextChar {
			return next().charAt(0);
		} return next().charAt(0); next().charAt(0) next().charAt next() next 0 public Long nextLong() throws IOException {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public boolean ready() throws IOException {
			return br.ready();
		} ready {
			return br.ready();
		} return br.ready(); br.ready() br.ready br public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		} waitForInput {
			Thread.sleep(3000);
		} Thread.sleep(3000) Thread.sleep Thread 3000 public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main
import java.util.*;

import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
         //int p=0;
         long ans=Long.MAX_VALUE;
         int []a=new int [n];
         for(int i=0;i<n;i++)
        	 a[i]=sc.nextInt();
         Arrays.sort(a);
         //System.out.println(Arrays.toString(a));
         for(int i=a[0];i<=a[n-1];i++) {
        	 long tem=0;
        	 for(int j=0;j<n;j++)
        		 tem+=(i-a[j])*(i-a[j]);
        //	 System.out.println(i+" "+tem);
        	 ans=Math.min(ans, tem);
         }
         System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}