import sys

import numpy as np



I = np.array(sys.stdin.read().split(), dtype=np.int64)

a = I[1:]



def main():

    m = int(np.around(np.mean(a)))

    ans = np.sum((a - m) ** 2)

    return ans



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys



n, *a = list(map(int, sys.stdin.read().split()))



def main():

  x = round(sum(a) / n)

  s = 0

  for i in range(n):

    s += pow(x - a[i], 2)

  print(s)

  

if __name__ == '__main__':

  main()
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
a = I[1:]


def main():
    m = int(np.around(np.mean(a)))
    ans = np.sum((a - m) ** 2)
    return ans


if __name__ == "__main__":
    ans = main()
    print(ans)

import sys

n, *a = list(map(int, sys.stdin.read().split()))


def main():
    x = round(sum(a) / n)
    s = 0
    for i in range(n):
        s += pow(x - a[i], 2)
    print(s)


if __name__ == "__main__":
    main()

-import numpy as np -I = np.array(sys.stdin.read().split(), dtype=np.int64) -a = I[1:] +n, *a = list(map(int, sys.stdin.read().split())) -    m = int(np.around(np.mean(a))) -    ans = np.sum((a - m) ** 2) -    return ans +    x = round(sum(a) / n) +    s = 0 +    for i in range(n): +        s += pow(x - a[i], 2) +    print(s) -    ans = main() -    print(ans) +    main()