#!/usr/bin/env python3
import sys
import math


def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main() import sys sys import math math def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve t = sum(X) t sum(X) sum X c1 = math.ceil(t/N) c1 math.ceil(t/N) math.ceil math ceil t/N t N c2 = math.floor(t/N) c2 math.floor(t/N) math.floor math floor t/N t N ans1 = sum(map(lambda x: (x -c1)** 2, X)) ans1 sum(map(lambda x: (x -c1)** 2, X)) sum map(lambda x: (x -c1)** 2, X) map lambda x: (x -c1)** 2 (x -c1)** 2 x -c1 x c1 2 x X ans2 = sum(map(lambda x: (x -c2)** 2, X)) ans2 sum(map(lambda x: (x -c2)** 2, X)) sum map(lambda x: (x -c2)** 2, X) map lambda x: (x -c2)** 2 (x -c2)** 2 x -c2 x c2 2 x X print(min(ans1, ans2)) print min(ans1, ans2) min ans1 ans2 return N: int N X: "List[int]" X def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens N = int(next(tokens)) N int(next(tokens)) int next(tokens) next tokens int(next(tokens)) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(next(tokens)) int next(tokens) next tokens X = [int(next(tokens)) for _ in range(N)] X [int(next(tokens)) for _ in range(N)] solve(N, X) solve N X if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X) main def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve
#!/usr/bin/env python3
import sys
import math


def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()
