import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  }
} Main public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  } main {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int a[] = new int[n]; a new int[n] n int min = -1; min -1 1 int max = -1; max -1 1 for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    } {
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    } int b = scan.nextInt(); b scan.nextInt() scan.nextInt scan a[i] = b a[i] a i b if (b<min){
        min = b;
      } b<min b min {
        min = b;
      } min = b min b if (b>max){
        max = b;
      } b>max b max {
        max = b;
      } max = b max b int dis = max-min+1; dis max-min+1 max-min max min 1 int[] c = new int[dis]; c new int[dis] dis for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    } int i = min; int i = min; i min i<=max i max i++ i++ i {
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    } {
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    } int sum = 0; sum 0 for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      } int j=0; int j=0; j 0 j<n j n j++ j++ j {
        sum += (a[j] - i)*(a[j] - i);
      } {
        sum += (a[j] - i)*(a[j] - i);
      } sum += (a[j] - i)*(a[j] - i) sum (a[j] - i)*(a[j] - i) (a[j] - i) a[j] a j i (a[j] - i) a[j] a j i c[i-min] = sum c[i-min] c i-min i min sum int minn = c[0]; minn c[0] c 0 for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    } int gg=0; int gg=0; gg 0 gg <max-min+1 gg max-min+1 max-min max min 1 gg++ gg++ gg {
      if (c[gg] < minn){
        minn = c[gg];
      }
    } {
      if (c[gg] < minn){
        minn = c[gg];
      }
    } if (c[gg] < minn){
        minn = c[gg];
      } c[gg] < minn c[gg] c gg minn {
        minn = c[gg];
      } minn = c[gg] minn c[gg] c gg System.out.println(minn) System.out.println System.out System System.out minn String[] args args public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  }
} public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    int min = -1;
    int max = -1;
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      a[i] = b;
      if (b<min){
        min = b;
      }
      if (b>max){
        max = b;
      }
    }

    int dis = max-min+1;

    int[] c = new int[dis];
    for (int i = min; i<=max; i++){
      int sum = 0;
      for (int j=0;j<n;j++){
        sum += (a[j] - i)*(a[j] - i);
      }
      c[i-min] = sum;
    }

    int minn = c[0];
    for (int gg=0; gg <max-min+1; gg++){
      if (c[gg] < minn){
        minn = c[gg];
      }
    }

    System.out.println(minn);

  }
}
