import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java import java.util.stream.Collectors; Collectors java.util.stream public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    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 min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int total = 0; total 0 int ans = Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    } {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc min = Math.min(min, list.get(i)) min Math.min(min, list.get(i)) Math.min Math min list.get(i) list.get list i max = Math.max(max, list.get(i)) max Math.max(max, list.get(i)) Math.max Math max list.get(i) list.get list i for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    } int i = min; int i = min; i min i <= max i max i++ i++ i {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    } {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    } total = 0 total 0 for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      } int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
        total += Math.pow(i - list.get(j), 2);
      } {
        total += Math.pow(i - list.get(j), 2);
      } total += Math.pow(i - list.get(j), 2) total Math.pow(i - list.get(j), 2) Math.pow Math i - list.get(j) i list.get(j) list.get list j 2 ans = Math.min(ans, total) ans Math.min(ans, total) Math.min Math ans total 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 min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
} public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
} Main
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int total = 0;
    int ans = Integer.MAX_VALUE;
    ;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
}
