import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc double[] array = new double[n]; array new double[n] n double ave = 0; ave 0 int sum = 0; sum 0 for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      array[i] = sc.nextDouble();
      ave += array[i];
    } {
      array[i] = sc.nextDouble();
      ave += array[i];
    } array[i] = sc.nextDouble() array[i] array i sc.nextDouble() sc.nextDouble sc ave += array[i] ave array[i] array i ave = (ave/array.length) ave (ave/array.length) ave array.length array array.length if((ave*10)%10 >= 5){
      ave++;
    } (ave*10)%10 >= 5 (ave*10)%10 (ave*10) ave 10 10 5 {
      ave++;
    } ave++ ave int avera = (int) ave; avera (int) ave for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
      sum += Math.pow(Math.abs(array[i]-avera),2);
    } {
      sum += Math.pow(Math.abs(array[i]-avera),2);
    } sum += Math.pow(Math.abs(array[i]-avera),2) sum Math.pow(Math.abs(array[i]-avera),2) Math.pow Math Math.abs(array[i]-avera) Math.abs Math array[i]-avera array[i] array i avera 2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    double[] array = new double[n];
    double ave = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextDouble();
      ave += array[i];
    }
    ave = (ave/array.length);
    if((ave*10)%10 >= 5){
      ave++;
    }
    int avera = (int) ave;
    for(int i = 0; i < array.length; i++){
      sum += Math.pow(Math.abs(array[i]-avera),2);
    }
    System.out.println(sum);
  }
}
