Problem:


Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354



Sample input:
2
1 4


Sample output:
5

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, X: "List[int]"):
    X.sort()
    sum=0
    for i in X:
        sum+=i**2
    tempsum=0
    for p in range(X[0],X[N-1]+1):
        temp=0
        for j in range(N):
            temp+=p**2-2*p*X[j]
        tempsum=min(tempsum,temp)
    print(sum+tempsum)
    return


# Generated by 1.1.6 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()

Submission status: Accepted

Solution code:
N = int(input())
L = [a for a in map(int,input().split())]
K = max(L)
Power = []
for i in range(1,K+1):
  add = 0
  for j in range(len(L)):
    add+= (i - L[j])**2
  Power.append(add)
print(min(Power))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int,input().split()))

ret=float("inf")
for i in range(1,101):
    ret = min(ret,sum(list(map(lambda y:(i-y)**2,x))))
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
ans = float('inf')
for x in range(1, 101):
    tmp = sum( [ (y-x)**2 for y in X ] )
    ans = min(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
l = []
for i in range(1, 101):
  cnt = 0
  for j in x:
    cnt += (j - i) ** 2
  l.append(cnt)
print(min(l))

Submission status: Accepted

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]

result = 999999999
for i in range(100):
    sum = 0
    for xx in x:
        sum += (xx - i) * (xx - i)
    if sum < result:
        result = sum

print(result)

Submission status: Accepted

Solution code:
a = int(input())
li = list(map(int,input().split()))	
b = sum(li)
c = b / a
an = round(c)
n = 0
ans = 0
for i in range(a):
  d = (li[n] - an) ** 2
  ans += d
  n += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
m=1000000
for i in range(100):
    su=0
    for j in range(n):
        su+=(x[j]-i-1)**2
    if m>su:
        m=su
print(m)

Submission status: Accepted

Solution code:
def p(x,n,s):
    return int(n*((x-s/n)**2)-(s**2)/n)

n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ds=0
for num in l:
    ds+=num**2
ans=ds+min(p(s//n,n,s),p(s//n+1,n,s))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(map(int,input().split(" ")))
ans = 2**60
for p in range(1,101):
    tmp = 0
    for x in X:
        tmp += (x-p)**2
    ans = min(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    
    ans = 10 ** 9
    for i in range(A[0], A[-1]+1):
        c = 0
        for a in A:
            c += (abs(a-i)) ** 2
        ans = min(ans, c)
        
    return ans

print(solve())

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
m=10**6
for p in range(min(x),max(x)+1):
	m=min(sum([(i-p)**2 for i in x]),m)
print(m)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x = sorted(x)
m = 10**20
for p in range(x[0],x[n-1]+1):
    power = 0
    for i in range(n):
        power += (x[i]-p)**2
    m = min(m,power)
print(m)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
sum=10e9
for i in range(1,101):
  cnt=0
  for j in range(n):
    cnt+=(arr[j]-i)**2
  sum=min(cnt,sum)
print(sum)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
min = np.inf

for i in range(1, x[-1]+1):
    total = 0
    for j in x:
        total += (j-i)**2
    if total < min:
        min = total

print(min)

Submission status: Accepted

Solution code:
import numpy as np
N = input()
X = input().split()
X = np.array(X).astype(int)
xx = []
for p in range(100):
    xx.append(((X-p)**2).sum())
print(min(xx))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))

def loss(y):
    return sum([(x-y)**2 for x in X])
 
print(min([loss(i) for i in range(1, 101)]))

Submission status: Accepted

Solution code:
import math

N = int(input())
X = list(map(int, input().split()))
max_xi = max(X)
min_xi = min(X)
ans = int(math.pow(99, 2)) * 100
for p in range(min_xi, max_xi + 1):
    total = 0
    for xi in X:
        total += int(math.pow(xi - p, 2))
    ans = min(ans, total)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
memo=[]
for i in range(min(S)-100,max(S)+100):
    summ = 0
    for j in range(0,N):#実際にsumを求める
        summ+=(i-S[j])**2
    memo.append(summ)

print(min(memo))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
t = 10 ** 9 + 7
for i in range(101):
  c = i
  tt = 0
  for j in range(n):
    tt += ((x[j] - c) ** 2)
  t = min(t, tt)
print(t)

Submission status: Accepted

Solution code:
n = int(input())
arrx = list(map(int,input().split()))
sumx = sum(arrx)
small = int(sumx // len(arrx))
big = int(-(-sumx // len(arrx)))
smallans = 0
bigans = 0
for x in arrx:
  smallans += (x-small)**2
  bigans += (x-big)**2
print(min(smallans,bigans))

Submission status: Accepted

Solution code:
N=int(input())
X=[int(x) for x in input().split()]
a=int((sum(X)+N/2)//N)
print(sum([(x-a)**2 for x in X]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    ans = INF
    for i in range(1, 101):
        t = 0
        for j in range(N):
            t += (X[j]-i)**2

        ans = min(ans, t)

    print(ans)

    return



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()

Submission status: Accepted

Solution code:
import math
flr = int(input())
inp = input().split()
n = len(inp)
m = int(max(inp))
num = 1
l = []
for i in range(m):
	total = 0
	i = 0
	for i in range(n):
		N = int(inp[i])
		i += 1
		col = (N-num)**2
		#print(col)
		total += col
	l.append(total)
	num += 1
print(min(l))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    N = int(inp.readline().strip())
    X = list(map(int, inp.readline().strip().split(' ')))

    r = 999999999999
    for i in range(1, max(X) + 1):
        s = sum(map(lambda x: abs(i - x) * abs(i - x), X))
        r = min(r, s)

    return str(r)


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))

a = min(X)
b = max(X)

ans = 1000000

for n in range(a, b + 1):
    sum = 0
    for x in X:
        sum += (x-n)*(x-n)
    ans = min(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    r = inf
    for i in range(1,101):
        t = 0
        for x in a:
            t += (x-i) ** 2
        if r > t:
            r = t

    return r


print(main())

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / n)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)

Submission status: Accepted

Solution code:
n= int(input())
x_list=list(map(int, input().split()))
power = []
for i in range(1,101):
  power.append(0)
  for j in x_list:
    power[i-1] += ((j - i) ** 2)
print(min(power))

Submission status: Accepted

Solution code:
n=int(input())
seq=input().split()
nseq=[]
for i in range(n):
    nseq.append(int(seq[i]))
M=max(nseq)
m=min(nseq)
hp=(M-m)*(M-m)*n
for i in range(m,M+1):
    s=0
    for j in range(n):
        s+=(nseq[j]-i)*(nseq[j]-i)
    hp=min(hp,s)
print(hp)

Submission status: Accepted

Solution code:
n=int(input())
seq=input().split()
s=0
for i in range(n):
    s+=int(seq[i])
ave=round(s/n)
hp=0
for i in range(n):
    hp+=(int(seq[i])-ave)*(int(seq[i])-ave)
print(hp)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    rs = 10**10
    for i in range(1,101):
        x1 = x
        x2 = list(map(lambda x:x-i, x1))
        x3 = list(map(lambda x:x**2, x2))
        x3 = sum(x3)
        if rs > x3:
            rs = x3
    print(rs)
resolve()

Submission status: Accepted

Solution code:
import sys

n = int(input())
pos = input().split()
#print(len(pos))

xmin = int(min(pos))
xmax = int(max(pos))

for ii in range(xmin, xmax+1):
    
    nowmax = 0

    for p in pos:
        nowmax = nowmax + pow((ii - int(p)),2)

    nextmax = 0
    for p in pos:
        nextmax = nextmax + pow(((ii+1) - int(p)),2)

    if nextmax >= nowmax:
        print(nowmax)
        sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
x.sort()
ans = 10**9
for i in range(1,x[-1]+1):
    energy = 0
    for j in x:
        energy += (j-i) ** 2
    ans = min(ans,energy)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
_ = int(input())
x = np.array(list(map(int, input().split())))
ave = int(round(np.average(x)))
x -= ave
ans = np.power(x, 2)
ans = np.sum(ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split(" "))) + list(range(100 - n))

ans = 9999999999999999
for i in range(1, 100):
    ans = min(ans, sum([(xs[j] - i)**2 for j in range(n)]))

print(ans)

Submission status: Accepted

Solution code:
def count(Xi):
    ans = 0
    for p in range(N):
        ans += (X[p]-Xi)**2
    return ans
    

N = int(input())
X = [int(x) for x in input().split()]
l =[]


for i in range(101):
    l.append(count(i))

print(min(l))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))

P = sum(X)//N
P2 = P+1
P3 = P-1
def score(X,P):
    s = 0
    for i in range(N):
        s += (X[i]-P)**2
    return s
#print(P,P2,P3)
S0 = score(X,P)
S1 = score(X,P2)
S2 = score(X,P3)
#print(S0,S1,S2)
print(min(S0,S1,S2))

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
pos = round(sum(x) / N)
power = 0
for x_i in x:
    power += pow(x_i - pos, 2)
print(power)

Submission status: Accepted

Solution code:
N = int(input())
l_x = list(map(int, input().split()))
d_min = 999999999999999
left = min(l_x)
right = max(l_x)
for p in range(left, right + 1):
  total = 0
  for x in l_x:
    total += (p - x) ** 2
  if total < d_min:
    d_min = total

print(d_min)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    x_line = list(map(int, input().split(' ')))
    max_x = max(x_line)
    min_x = min(x_line)
    result = sum(x_line) ** 2
    for i in range(min_x, max_x + 1):
        hash_result = 0
        for x in x_line:
            hash_result += (x - i) ** 2
        if hash_result < result:
            result = hash_result
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=float('inf')
for i in range(101):
    sum=0
    for j in x:
        sum+=(i-j)**2
    ans=min([ans,sum])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=[i for i in map(int, input().split())]
ans=1000000000000000000000000000000000000000
x.sort()

for i in range(x[n-1]+1):
  cnt=0
  for k in x:
    cnt= cnt+(k-i)**2
  ans=min(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))

ans = 10000000000
for i in range(min(X), max(X) + 1):
    tmp_ans = 0
    for j in range(N):
        tmp_ans += (X[j] - i) ** 2 
    ans = min(ans, tmp_ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(a) for a in input().split()]
ans = 0
for i in range(0,101):
    res = 0
    for j in x:
        res += (j-i)**2
    if i==0:
        ans = res
    elif ans > res:
        ans = res
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(a) for a in input().split()]
b = list()
for i in range(0,101):
    res = 0
    for j in x:
        res += (j-i)**2
    b.append(res)
print(min(b))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))

p = round(sum(x)/n)

s = 0
for i in range(n):
  s += abs((x[i]-p))**2
  
print(s)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = 10**10
for p in range(min(x), max(x)+1):
    sumation = 0
    for i in x:
        s = (i-p)**2 
        sumation += s
    ans = min(ans, sumation)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(_) for _ in input().split()]

ans = 10 ** 10
for p in range(min(X), max(X)+1):
    a = sum([(x - p) ** 2 for x in X])
    ans = min(ans, a)
print(ans)

Submission status: Accepted

Solution code:
import sys

n=int(input())
x=[int(k) for k in input().split()]

p=round(sum(x)/n)

ans=0
 
for i in x:
  ans+=(p-i)**2
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
print(min(sum((X[i] - j) ** 2 for i in range(N)) for j in range(1, 101)))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split(' ')]
P = sum(X) // N
S1 = sum([(x - P)**2 for x in X])
S2 = sum([(x - (P+1))**2 for x in X])
S = min([S1, S2])
print(S)

Submission status: Accepted

Solution code:
n = int(input())
X= [int(i) for i in input().split()]
X.sort()

ans = 1e10
for p in range(1,101):
  sum =0
  for x in X:
    sum += (p-x)**2
    
  ans = min(ans,sum)
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X= list(map(int,input().split()))
X.sort()

ans = 1000000000
for p in range(1,101):
  sum =0
  for x in X:
    sum += (p-x)**2
    
  ans = min(ans,sum)
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))

ans = 1e10

for pos in range(1,101):
  work = 0
  for x in X:
    work += (pos - x) ** 2
  ans = min(ans, work)
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
N = list(map(int,input().split()))
result = 1000001
for i in range(100):
    total = 0
    for j in range(n):
        total += (i - N[j])**2
    if (result>total):
        result = total
print(result)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = []
for x in range(100):
    y = [(X[i] - x)**2 for i in range(len(X))]
    Y.append(sum(y))
print(min(Y))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int, input().split()))
p=round(sum(x)/n)
ans=0
for i in x:
    ans+=(i-p)*(i-p)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=10**10
for i in range(100):
    res=0
    for j in range(n):
        res+=(x[j]-i-1)**2
    
    ans=min(ans,res)
    

print(ans)

Submission status: Accepted

Solution code:
N = input()
X = list(map(int,input().split()))
result = []
i = 1

while i <= 100:
  sum = 0
  for j in X:
    sum += (j - i) ** 2
  result.append(sum)
  i += 1
  
print(min(result))

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split(' ')))
min_ps = None

for i in range(100):
    ps = sum([(xi - i)**2 for xi in X])
    if min_ps==None:
        min_ps = ps
    elif min_ps > ps:
        min_ps = ps

print(min_ps)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
sumX = 0
for i in x:
    sumX += (i - round(sum(x)/n)) ** 2
print(sumX)

Submission status: Accepted

Solution code:
from statistics import mean

N = int(input())
A_list = list(map(int, input().split()))

ave = mean(A_list)
ave_r = round(ave)

dist = 0
for A in A_list:
    dist += (A - ave_r) ** 2
print(dist)

Submission status: Accepted

Solution code:
n=int(input())

listx = list(map(int,input().split()))
a= 1000100

for i in range(max(listx)):
	p=i+1
	all=0
	for x in listx:
		all += (x-p)**2
	if all < a:
		a = all

print(a)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mid=sum(a)//n
ret=10000010
x=0
y=0
for i in a:
  x += (i-mid)**2
  y += (i-(mid+1))**2
print(min(x,y))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))

candidates = [sum(X) // N, sum(X) // N + 1]

ans = 0

a = 0
b = 0
for x in X:
    a += (x - candidates[0]) ** 2
    b += (x - candidates[1]) ** 2

if a < b:
    print(a)
else:
    print(b)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split(" ")))
    calc = [0]*max(X)
    for i in range(max(X)):
        for j in range(N):
            calc[i] += (X[j] - (i+1))**2

        #print(calc)
    print(min(calc))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
HP = set()
for p in  range(100):
    p += 1
    A = 0
    for i in range(N):
        A += (X[i] - p)**2
    HP.add(A)
print(min(HP))

Submission status: Accepted

Solution code:
n = int(input())

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

ans = float('inf')

for i in range(1,101):
  ans_temp = 0
  for j in x:
    ans_temp += (j-i)**2
  ans = min(ans,ans_temp)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
sum=sum(X)
ave=round(sum/N)
Y=0
for i in X:
	Y+=(i-ave)**2
print(Y)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split(" ")))

sum_ = 0

m = round(sum(X) / N)

for i in range(0, len(X)):
  sum_ += (X[i] - m) ** 2

print(sum_)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
min = 1000000

for p in range(100):
    sum = 0
    for i in range(n):
        sum = sum + (x[i] - p)**2
    if  sum < min:
        min = sum

print(min)

Submission status: Accepted

Solution code:
n = int(input())
List = list(map(int, input().split()))

min = 100000000000000000000

for P in range(101):
    X=0
    for num in List:
        X += (P-num)**2
    if min > X:
        min = X

print(min)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))

ans = 10 ** 6
for i in range(101):
    power = 0
    for e in x:
        power += (e - i) ** 2

    ans = min(ans, power)

print(ans)

Submission status: Accepted

Solution code:
N=int(input());A=list(map(int,input().split()))
ans=100000000000000
for x in range(1,101):
  ans=min([sum([(x-a)**2 for a in A]),ans])
print(ans)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

n = int(input())
x_list = list(map(int, input().split()))
a = int(Decimal(str(sum(x_list)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_EVEN))

ans = 0
for x in x_list:
    ans += (x-a)**2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))
sum = 0
for i in range(n):
    sum += s[i]
ave = round(sum / n)

for i in range(n):
    s[i] = s[i] - ave
    s[i] = s[i] * s[i]
ans = 0
for i in range(n):
    ans += s[i]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
s = min(X)
g = max(X)
ans = 10**9
for i in range(s,g+1):
    d = 0
    for x in X:
        d += (x-i)**2
    ans = min(ans,d)
print(ans)

Submission status: Accepted

Solution code:
from statistics import median

n = int(input())
p = list(map(int, input().split()))

min_sum = 10**9
for location in range(min(p), max(p)+1):
    sum = 0
    for i in range(n):
        sum += (p[i]-location)**2
    if sum < min_sum:
        min_sum = sum

print(min_sum)

Submission status: Accepted

Solution code:
N = int(input())
Xs = [int(i) for i in input().split()]

base = int(round(sum(Xs) / N))
ans = 0
for x in Xs:
    ans += (x - base) ** 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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


ans = 10000000
for i in range(1,101):
    y = 0
    for j in x:
        y += (j-i)*(j-i)
    ans = min(ans,y)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
man = []
man= list(int(i) for i in input().split())

min_n = float('inf')
for x in range(100):
    sum =0
    for y in man:
        sum +=(x-y)**2
    if sum<min_n:
        min_n =sum
print(min_n)

Submission status: Accepted

Solution code:
N = int(input())
X_list = [int(i) for i in input().split()]

low = min(X_list)
high = max(X_list)

minimum = 99999999999999
for p in range(low,high) :
    tmp = 0
    for x in X_list :
        tmp += pow(x-p,2)
    
    if (tmp < minimum) :
        minimum = tmp

if (minimum == 99999999999999) :
    print(0)
else :
    print(minimum)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
a=sum(x)//n
ans1=0
ans2=0
for i in range(n):
    ans1+=(a-x[i])**2
    ans2+=(a+1-x[i])**2
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
from statistics import mean
N = int(input())
X = input().split()
for i in range(len(X)):
    X[i] = int(X[i])
goal = round(mean(X)) 
sum = 0
for i in range(len(X)):
    sum += (X[i] - goal) ** 2
print(sum)

Submission status: Accepted

Solution code:
import sys
import math
#ta= map(int,input().split())
ta=int(input())
ans=0
sum=0
li= [int(x) for x in input().split()]
for i in range(ta):
  sum+=li[i]
sum=round(sum/ta)
for i in range(ta):
  ans+=pow((li[i]-sum),2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))

result = 10000000000
for i in range(100):
    tmp = 0
    for j in range(n):
        tmp += pow((x[j] - i), 2)

    if tmp < result:
        result = tmp
print(result)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = int(sum(x)**2)
current = 0
for p in range(min(x)-1,max(x)+1):
    for i in range(len(x)):
        current += int((x[i] - p)**2)
    if(current < ans):
        ans = current
    current = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Min = 1e10
for p in range(1,101):
    Min = min(Min,sum(map(lambda x: (x-p)**2, X)))
print(Min)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Min = 1e10
for p in range(1,101):
    Min = min(Min,sum(list(map(lambda x: (x-p)**2, X))))
print(Min)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    x_list = list(map(int, input().split()))

    x_min = min(x_list)
    x_max = max(x_list)
    hp_min = None

    for i in range(x_min, x_max+1):
        tmp_hp = 0
        for j in x_list:
            tmp_hp += (j - i)**2
        if (hp_min is None) or (tmp_hp < hp_min):
            hp_min = tmp_hp

    print(hp_min)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=10**18
for p in range(min(x),max(x)+1):
  s=0
  for j in range(n):
    s+=(p-x[j])**2
  ans=min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil, floor

N = int(input())
X = list(map(int, input().split()))

P = sum(X) / N
ans = []
for p in (floor(P), ceil(P)):
    ans.append(sum((x - p) ** 2 for x in X))
print(min(ans))

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    xx=list(map(int,input().split()))
    m=None
    for i in range(1,101):
        mm=sum([(x-i)**2 for x in xx])
        if m is None or m>mm:
            m=mm
    print(m)
main()

Submission status: Accepted

Solution code:
import math
N = int(input())
X = list(map(int,input().split()))

P = sum(X)/N
P = [math.ceil(P), math.floor(P)]
print(min([sum([(x-p)**2 for x in X]) for p in P]))

Submission status: Accepted

Solution code:
n = int(input().strip())
xs = list(map(int, input().split()))
tmp = sum(xs) // n
print(min(sum(map(lambda x: (x - tmp) ** 2, xs)), sum(map(lambda x: (x - (tmp + 1)) ** 2, xs))))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
a = round(sum(X)/N)
sum = 0
for i in X:
    sum += pow((i - a), 2)

print(sum)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
x=max(l)
y=min(l)
li=[]
for i in range(y,x+1):
    ans=0
    for j in range(n):
        ans+=(l[j]-i)**2
    li.append(ans)
print(min(li))

Submission status: Accepted

Solution code:
N = int(input())
X = sorted(list(map(int, input().split(" "))))
min = -1
for i in range(X[0], X[-1]+1):
  s = sum((x - i) ** 2for x in X)
  if min == -1:
    min = s
  if s < min:
    min = s
print(min)

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split()))

ans = 1000000
for p in range(1, 101):
    hp_sum = 0
    for x in xs:
        hp_sum += (x - p) ** 2
    ans = min(ans, hp_sum)

print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    n, *x = map(int, string.split())
    return str(sum((_x - int(sum(x) / n + 0.5))**2 for _x in x))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *x = map(int, string.split())
    c = int(sum(x) / n + 0.5)
    return str(sum((_x - c)**2 for _x in x))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
N = int(input())
X = list(int(x) for x in input().split())
N_sum_HP = []


for p in range(min(X), max(X) + 1):
    sum_HP = 0
    for x in X:
        sum_HP += (x - p) ** 2
    N_sum_HP.append(sum_HP)
print(min(N_sum_HP))

Submission status: Accepted

Solution code:
n= int(input())
x= list(map(int,input().split()))
xsum = sum(x)
xxsum = sum([c*c for c in x])
gmin = 999999999
for c in range(1,101):gmin=min(gmin,xxsum+n*c*c-2*c*xsum)
print(gmin)

Submission status: Accepted

Solution code:
import math

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

p=int(round(sum(x)/n))

ans = 0
for i in x:
  ans += (i-p)**2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(100):
  ans = min(ans, sum([pow(y - i - 1, 2) for y in x]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
min = 1000000
for i in range(101):
    d = 0
    for j in range(N):
        d += (i-X[j])**2
    if min > d:
        min = d
print(min)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
ans = 10**9+7
for i in range(1, x[-1]+1):
  key = 0
  for j in range(n):
    key += (x[j]-i)**2
  if key < ans:
    ans = key
print(ans)

Submission status: Accepted

Solution code:
#abc156c
n=int(input())
x=list(map(int,input().split()))
r=round(sum(x)/n)
res=0
for i in range(n):
 res+=(x[i]-r)**2
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(max(a)):
    HP = 0
    for j in range(n):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Submission status: Accepted

Solution code:
#156c
n=int(input())
x=[int(x) for x in input().split()]
min_t=[]
for i in range(0,max(x)+1):
    tmp=0
    for j in x:
      tmp +=(j-i)**2
    min_t.append(tmp)    
print(min(min_t))

Submission status: Accepted

Solution code:
n = int(input())
x = tuple(map(int, input().split()))

ans = 100**3
for p in range(1, 101):
    cost = sum((xi - p)**2 for xi in x)
    ans = min(ans, cost)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar  2 23:58:34 2020

@author: Kanaru Sato
"""

N=int(input())
X=list(map(int, input().split()))
Pvalues=[]

for P in range(1,101):
    Pvalue = 0
    for i in range(0,N):
        Pvalue += (X[i]-P)**2
    Pvalues.append(Pvalue)

print(min(Pvalues))

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
ans = 10000000000000

for i in range(101):
    sum = 0
    for j in x:
        sum += (j - i)**2
    ans = min(ans,sum)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
P = sum(X)/N
Q = sum(X)//N
ans = 0
if P-Q>=0.5:
    Q += 1
for i in range(N):
    R = (X[i]-Q)**2
    ans += R
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
m = 10**10
for i in range(1, 101):
    s = 0
    for j in x:
        s += (i-j)**2
    m = min(m, s)
print(m)

Submission status: Accepted

Solution code:

import numpy as np

N = int(input())
X = [int(x) for x in input().split()]
X = np.array(X)

ans = 1e6
for x in range(1, 100) :
    s = (X-x)**2
    ans = min(ans, s.sum())
print(ans)