# C - Rally

def main():

    N, *X = list(map(int, open(0).read().split()))

    left, right = min(X), max(X)

    ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1))

    print(ans)





if __name__ == "__main__":

    main()

# C - Rally

def main():

    N, *X = list(map(int, open(0).read().split()))

    calc = lambda x, p: (x - p) ** 2

    P = sum(X) // N

    ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))

    print(ans)





if __name__ == "__main__":

    main()

# C - Rally
def main():
    N, *X = list(map(int, open(0).read().split()))
    left, right = min(X), max(X)
    ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1))
    print(ans)


if __name__ == "__main__":
    main()

# C - Rally
def main():
    N, *X = list(map(int, open(0).read().split()))
    calc = lambda x, p: (x - p) ** 2
    P = sum(X) // N
    ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))
    print(ans)


if __name__ == "__main__":
    main()

-    left, right = min(X), max(X) -    ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1)) +    calc = lambda x, p: (x - p) ** 2 +    P = sum(X) // N +    ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))