def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve() def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost) resolve N = int(input()) N int(input()) int input() input int(x) for x in input().split(" ") for x in input().split(" ") x input().split(" ") ().split () input split " " for x in input().split(" ") int(x) int x X = [int(x) for x in input().split(" ")] X [int(x) for x in input().split(" ")] min_X = min(X) min_X min(X) min X max_X = max(X) max_X max(X) max X sum_of_x = sum(X) sum_of_x sum(X) sum X sum_of_squared = 0 sum_of_squared 0 for x in X:
    sum_of_squared += x**2

   x X sum_of_squared += x**2 sum_of_squared x**2 x 2 temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2 temp_sum_of_cost sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2 sum_of_squared - 2 * min_X * sum_of_x sum_of_squared 2 * min_X * sum_of_x 2 * min_X 2 min_X sum_of_x N * min_X**2 N min_X**2 min_X 2 for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

   p range(min_X, max_X+1) range min_X max_X+1 max_X 1 sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2 sum_of_cost sum_of_squared - 2 * p * sum_of_x + N * p**2 sum_of_squared - 2 * p * sum_of_x sum_of_squared 2 * p * sum_of_x 2 * p 2 p sum_of_x N * p**2 N p**2 p 2 if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

   sum_of_cost < temp_sum_of_cost sum_of_cost temp_sum_of_cost temp_sum_of_cost = sum_of_cost temp_sum_of_cost sum_of_cost print(temp_sum_of_cost) print temp_sum_of_cost if __name__ == "__main__":
  resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost) def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost) resolve
def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve()