import math

import itertools

import fractions

import heapq

import collections

import bisect

import sys

import copy



sys.setrecursionlimit(10**9)

mod = 10**7+9

inf = 10**20



def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def I(): return int(sys.stdin.readline())

def F(): return float(sys.stdin.readline())

def S(): return eval(input())



n = I()

x = LI()



mx = max(x)

mn = min(x)



ans = inf

for i in range(mn,mx+1):

    tmp = 0

    for j in x:

        tmp+=(j-i)**2

    ans = min(ans,tmp)

print(ans)
n = int(eval(input()))

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



ans = 10**9+7

for i in range(min(x),max(x)+1):

    tmp=0

    for j in x:

        tmp+=(i-j)**2

    ans = min(ans,tmp)

print(ans)
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7 + 9
inf = 10**20


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI():
    return [list(map(int, l.split())) for l in sys.stdin.readlines()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LF():
    return [float(x) for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def I():
    return int(sys.stdin.readline())


def F():
    return float(sys.stdin.readline())


def S():
    return eval(input())


n = I()
x = LI()
mx = max(x)
mn = min(x)
ans = inf
for i in range(mn, mx + 1):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

n = int(eval(input()))
x = list(map(int, input().split()))
ans = 10**9 + 7
for i in range(min(x), max(x) + 1):
    tmp = 0
    for j in x:
        tmp += (i - j) ** 2
    ans = min(ans, tmp)
print(ans)

-import math -import itertools -import fractions -import heapq -import collections -import bisect -import sys -import copy - -sys.setrecursionlimit(10**9) -mod = 10**7 + 9 -inf = 10**20 - - -def LI(): -    return list(map(int, sys.stdin.readline().split())) - - -def LLI(): -    return [list(map(int, l.split())) for l in sys.stdin.readlines()] - - -def LI_(): -    return [int(x) - 1 for x in sys.stdin.readline().split()] - - -def LF(): -    return [float(x) for x in sys.stdin.readline().split()] - - -def LS(): -    return sys.stdin.readline().split() - - -def I(): -    return int(sys.stdin.readline()) - - -def F(): -    return float(sys.stdin.readline()) - - -def S(): -    return eval(input()) - - -n = I() -x = LI() -mx = max(x) -mn = min(x) -ans = inf -for i in range(mn, mx + 1): +n = int(eval(input())) +x = list(map(int, input().split())) +ans = 10**9 + 7 +for i in range(min(x), max(x) + 1): -        tmp += (j - i) ** 2 +        tmp += (i - j) ** 2