import java.util.ArrayList;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> b = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    }
    double avg = Math.round(sum / n);
    int r = 0;
    for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    }
    System.out.println(r);
    sc.close();
  }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> b = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    }
    double avg = Math.round(sum / n);
    int r = 0;
    for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    }
    System.out.println(r);
    sc.close();
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> b = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    }
    double avg = Math.round(sum / n);
    int r = 0;
    for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    }
    System.out.println(r);
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> b = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    }
    double avg = Math.round(sum / n);
    int r = 0;
    for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    }
    System.out.println(r);
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) double n = sc.nextInt(); n sc.nextInt() sc.nextInt sc double sum = 0; sum 0 ArrayList<Integer> b = new ArrayList<Integer>(); b new ArrayList<Integer>() for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    } {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    } int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc sum += c sum c b.add(c) b.add b c double avg = Math.round(sum / n); avg Math.round(sum / n) Math.round Math sum / n sum n int r = 0; r 0 for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      r += Math.pow((b.get(i) - avg), 2);
    } {
      r += Math.pow((b.get(i) - avg), 2);
    } r += Math.pow((b.get(i) - avg), 2) r Math.pow((b.get(i) - avg), 2) Math.pow Math (b.get(i) - avg) b.get(i) b.get b i avg 2 System.out.println(r) System.out.println System.out System System.out r sc.close() sc.close sc String[] args args
import java.util.ArrayList;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> b = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      sum += c;
      b.add(c);
    }
    double avg = Math.round(sum / n);
    int r = 0;
    for (int i = 0; i < n; i++) {
      r += Math.pow((b.get(i) - avg), 2);
    }
    System.out.println(r);
    sc.close();
  }
}
