def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
    
if __name__ == '__main__':
    main() def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
     main 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()] ave_x = int(sum(X) / len(X)) ave_x int(sum(X) / len(X)) int sum(X) / len(X) sum(X) sum X len(X) len X error_1 = 0 error_1 0 error_2 = 0 error_2 0 for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
     x X error_1 += (x-ave_x) ** 2 error_1 (x-ave_x) ** 2 x-ave_x x ave_x 2 error_2 += (x-(ave_x+1)) ** 2 error_2 (x-(ave_x+1)) ** 2 x-(ave_x+1) x ave_x+1 ave_x 1 2 min_e = min(error_1, error_2) min_e min(error_1, error_2) min error_1 error_2 print(min_e) print min_e if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
     def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
     main
def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
    
if __name__ == '__main__':
    main()