from sys import stdin





def main():

    n = int(stdin.readline())

    x = list(map(int, stdin.readline().split()))



    p = sum(x) / n



    p1 = int(p)

    p2 = int(p + 1)



    s1 = 0

    s2 = 0



    for xi in x:

        s1 += (xi - p1) ** 2

        s2 += (xi - p2) ** 2



    print((min(s1, s2)))





if __name__ == "__main__":

    main()
from sys import stdin, setrecursionlimit





def main():

    input = stdin.buffer.readline

    n = int(eval(input()))

    x = list(map(int, input().split()))

    sum = 0

    for xi in x:

        sum += xi

    ans_1 = sum // n

    ans_2 = sum // n + 1

    score_1 = 0

    score_2 = 0

    for xi in x:

        score_1 += (xi - ans_1) ** 2

        score_2 += (xi - ans_2) ** 2

    print((min(score_1, score_2)))





if __name__ == "__main__":

    setrecursionlimit(10000)

    main()

from sys import stdin


def main():
    n = int(stdin.readline())
    x = list(map(int, stdin.readline().split()))
    p = sum(x) / n
    p1 = int(p)
    p2 = int(p + 1)
    s1 = 0
    s2 = 0
    for xi in x:
        s1 += (xi - p1) ** 2
        s2 += (xi - p2) ** 2
    print((min(s1, s2)))


if __name__ == "__main__":
    main()

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))
    x = list(map(int, input().split()))
    sum = 0
    for xi in x:
        sum += xi
    ans_1 = sum // n
    ans_2 = sum // n + 1
    score_1 = 0
    score_2 = 0
    for xi in x:
        score_1 += (xi - ans_1) ** 2
        score_2 += (xi - ans_2) ** 2
    print((min(score_1, score_2)))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

-from sys import stdin +from sys import stdin, setrecursionlimit -    n = int(stdin.readline()) -    x = list(map(int, stdin.readline().split())) -    p = sum(x) / n -    p1 = int(p) -    p2 = int(p + 1) -    s1 = 0 -    s2 = 0 +    input = stdin.buffer.readline +    n = int(eval(input())) +    x = list(map(int, input().split())) +    sum = 0 -        s1 += (xi - p1) ** 2 -        s2 += (xi - p2) ** 2 -    print((min(s1, s2))) +        sum += xi +    ans_1 = sum // n +    ans_2 = sum // n + 1 +    score_1 = 0 +    score_2 = 0 +    for xi in x: +        score_1 += (xi - ans_1) ** 2 +        score_2 += (xi - ans_2) ** 2 +    print((min(score_1, score_2))) +    setrecursionlimit(10000)