// Arup Guha
// 3/22/2015
// Solution to January 14 Bronze USACO Problem: Ski Course Design

import java.util.*;
import java.io.*;

public class Main {

	final public static int NOSOL = 100000000;
	final public static int MAX = 100;
	final public static int RANGE = 17;

	public static void main(String[] args) throws Exception {

		// Just store frequencies of heights.
		Scanner stdin = new Scanner(new File("skidesign.in"));
		int n = stdin.nextInt();
		int[] freq = new int[MAX+1];
		for (int i=0; i<n; i++)
			freq[stdin.nextInt()]++;

		// Try each valid low height.
		int cost = NOSOL;
		for (int low=0; low<=MAX-RANGE; low++)
			cost = Math.min(cost, calculate(freq, low, low+RANGE));

		// Write out the result.
		BufferedWriter fout = new BufferedWriter(new FileWriter("skidesign.out"));
		fout.write(cost+"\n");
		fout.close();
	}

	public static int calculate(int[] freq, int low, int high) {
		int cost = 0;

		// Add up cost for increasing these.
		for (int i=0; i<low; i++)
			cost = cost + freq[i]*(low-i)*(low-i);

		// And decreasing these.
		for (int i=high+1; i<freq.length; i++)
			cost = cost + freq[i]*(i-high)*(i-high);
		return cost;
	}
}
