
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc Arrays.sort(a) Arrays.sort Arrays a int ans = Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		} int i = a[0]; int i = a[0]; i a[0] a 0 i <= a[a.length - 1] i a[a.length - 1] a a.length - 1 a.length a a.length 1 i++ i++ i {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		} {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		} int sum = 0; sum 0 for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			} int j = 0; int j = 0; j 0 j < a.length j a.length a a.length j++ j++ j {
				sum += Math.pow((a[j] - i), 2);
			} {
				sum += Math.pow((a[j] - i), 2);
			} sum += Math.pow((a[j] - i), 2) sum Math.pow((a[j] - i), 2) Math.pow Math (a[j] - i) a[j] a j i 2 ans = Math.min(ans, sum) ans Math.min(ans, sum) Math.min Math ans sum System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	}
} Main

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int ans = Integer.MAX_VALUE;
		for (int i = a[0]; i <= a[a.length - 1]; i++) {
			int sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += Math.pow((a[j] - i), 2);
			}
			ans = Math.min(ans, sum);
		}
		
		System.out.println(ans);
	}
}
