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:
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    Xs = list(map(int, input().split()))

    avg1 = sum(Xs)//N
    avg2 = avg1+1

    ans1 = 0
    ans2 = 0
    for x in Xs:
        ans1 += (x-avg1)**2
        ans2 += (x-avg2)**2
    print(min(ans1, ans2))


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

minSum = 9999999999999999
for i in range(min(x), max(x)+1):
  tmp = 0
  for xx in x:
    tmp += (xx-i)**2
  if tmp < minSum:
    minSum = tmp
print(minSum)

Submission status: Accepted

Solution code:
def cost(p):
    res = 0
    for x in X:
        res += (p - x) ** 2
    return res


N = int(input())
X = [int(x) for x in input().split()]
print(min(cost(p) for p in range(min(X), max(X) + 1)))

Submission status: Accepted

Solution code:
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
X = l_in()

P1 = sum(X)//N
P2 = sum(X)//N + 1

print(min(sum((P1-x)**2 for x in X), sum((P2-x)**2 for x in X)));

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = sorted(map(int, input().split()))
ans1 = 0
ans2 = 0
cand = sum(X) // N

for x in X:
    ans1 += (cand-x)**2
    ans2 += (cand+1-x)**2
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
# ABC156c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n = int(input())
    x = list(map(int, input().split()))
    import math
    cost = 10 ** 11
    for i in range(min(x), max(x) + 1):

        t = 0
        for j in x:
            t += (j - i) ** 2

        cost = min(cost, t)
        #print(i, cost)
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

min = 100000000
for i in range (100):
    sum = 0
    for j in range (N):
        sum += (R[j] - i)**2

    if sum <= min:
        min = sum
    
print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = 9**10
for i in range(1,101):
    tmp = 0
    for y in x:
        tmp += (y-i)**2
    if ans >= tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
cmin = 10**6
for i in range(101):
    cnt = 0
    for x in X:
        cnt += (x-i)**2
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N = int(input())
X = list(map(int, input().split()))
X.sort()

minv = 10**18

for xi in range(X[0], X[-1]+1):
    val = 0
    for xj in X:
        val += (xi - xj) ** 2
    if minv > val:
        minv = val

print(minv)

Submission status: Accepted

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

x_mean = sum(xn) / N

if x_mean == int(x_mean):
  x_mean = int(x_mean)
  sum_ = 0
  for x in xn:
    sum_ += (x-x_mean)**2
  print(sum_)
else:
  x_mean = int(x_mean)
  sum1 = 0
  sum2 = 0
  for x in xn:
    sum1 += (x-x_mean)**2
    sum2 += (x-x_mean-1)**2
  print(min(sum1, sum2))

Submission status: Accepted

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

import numpy as np

X = np.array(X)
D = X.reshape(-1, 1) - np.arange(1, 100).reshape(1, -1)
D = np.sum(D*D, axis=0)

print(np.min(D))

Submission status: Accepted

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

M = max(x)
min = 10**12
for i in range(M+1):
    count = 0
    for ix in range(len(x)):
        count += (i-x[ix])**2

    if count <= min:
        min = count

print(min)

Submission status: Accepted

Solution code:
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N
#math.ceilで切り上げ
#dp = [[0] * 4 for i in range(3)] #2次元配列初期化
#dp = [[[0] * 2 for i in range(3)] for j in range(5)]
#(ord('A'))でASCII出力 Aは65
import math
import statistics
import string

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

n = intinput()
x = listintinput()

av = int(statistics.mean(x))
avone = av+1
ans = 0
ansone = 0
for i in x:
    ans += (i-av) ** 2
    ansone += (i-avone) ** 2

print(min(ans,ansone))

Submission status: Accepted

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

ans = 10 ** 9

for i in range(1, 101):
    total = 0
    for x in X:
        total += (x - i) ** 2
    ans = min(total, ans)

print(ans)

Submission status: Accepted

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

ans=float("inf")
for P in range(X[0],X[-1]+1):
  a=0
  for i in range(N):
    a+=(X[i]-P)**2
  ans=min(ans,a)
  
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    X = list(map(int, input().split()))
    ans = 1000000
    for i in range(100):
        tmp = 0
        for j in range(N):
            tmp += (X[j]-i)**2
        ans = min(tmp, ans)
    print(ans)
resolve()

Submission status: Accepted

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

res = 10**10
for i in range(101):
    u = 0
    for x in X:
        u += (x - i)**2
    res = min(u, res)
print(res)

Submission status: Accepted

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

ans = float('inf')
for p in range(1, 101):
    s = 0
    for i in x:
        s += (i - p) ** 2
    ans = min(ans, s)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
a=9**9
for i in range(min(X),max(X)+1):
  a=min(a,sum(map(lambda x:(x-i)**2,X)))
print(a)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline


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


m = 1e10
for p in range(1, 101):
    m = min(sum((x - p)**2 for x in X), m)


print(m)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
ans = 1000000000
for x in range(1,101):
  total = 0
  for i in range(N):
    total += (A[i]-x)*(A[i]-x)
  ans = min( ans, total ) 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())
x = list(map(int, input().split()))
p = sum(x) / len(x)

a1 = sum([(a - math.floor(p)) * (a - math.floor(p)) for a in x])
a2 = sum([(a - math.ceil(p)) * (a - math.ceil(p)) for a in x])
print(min(a1, a2))

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int, input().split()))
a,b = math.ceil(sum(x)/n), math.floor(sum(x)/n)
if a==b:
    print(sum([(i-a)**2 for i in x]))
else:
    print(min(sum([(i-a)**2 for i in x]),sum([(i-b)**2 for i in x])))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**9
for n in range(1, 101):
    temp = 0
    for x in X:
        temp += (x - n)**2

    if ans > temp:
       ans = temp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**100

for P in range(min(X_list),max(X_list)+1):
    temp_ans = 0
    
    for X in X_list:
        temp_ans += (X - P)**2
        
    if temp_ans < ans:
        ans = temp_ans
        
print(ans)

Submission status: Accepted

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

ans = 10**6
for i in range(1,101):
    tmp = sum([(y - i)**2 for y in x])
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
Ans=10**7
for p in range(1,101):
    res=sum([(x-p)**2 for x in X])
    Ans=min(Ans,res)

print(Ans)

Submission status: Accepted

Solution code:
n=int(input())
x=sorted(map(int,input().split()))
m=sum(x)//n

s1=0
s2=0
s3=0
for i in range(n):
    s1 += (x[i]-m)**2
    s2 += (x[i]-m-1)**2
    s3 += (x[i]-m+1)**2
print(min(s1,s2,s3))

Submission status: Accepted

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

cor_1 = math.ceil(sum(X) / N)
cor_2 = math.floor(sum(X) / N)
ans_1 = [(int(_) - cor_1) ** 2 for _ in X]
ans_2 = [(int(_) - cor_2) ** 2 for _ in X]

ans = min(sum(ans_1), sum(ans_2))
print(ans)

Submission status: Accepted

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

xmin=min(xlist)
xmax=max(xlist)

min_answer=10**9
for i in range(xmin,xmax+1):
  answer=0
  for x in xlist:
    answer+=(x-i)**2

  min_answer=min(answer,min_answer)

print(min_answer)

Submission status: Accepted

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

N = int(input().split()[0])
x_list = list(map(int, input().split()))

min_cost = float("inf")
for i in range(1, 101):
    t = sum([(x - i) ** 2 for x in x_list])
    min_cost = min(t, min_cost)
ans = min_cost

print(ans)

Submission status: Accepted

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

ans = 10 ** 10


for p in range(1, 101):
    power = 0
    for x in X_array:
        # print(x,p,power)
        power += ((x-p) ** 2)
    if power < ans:
        ans = power


print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    X.sort()
    m = 10 ** 100
    for i in range(1, X[-1]+1):
        t = 0
        for j in X:
            t += (j - i)**2
        m = min(t, m)
    print(m)
main()

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X.sort()
s=X[0]
e=X[-1]
ans=10**10
for i in range(s, e+1):
    tmp=0
    for x in X:
        tmp+=(i-x)**2
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Accepted

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

ans = float('inf')

for i in range(1, 101):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2

    ans = min(ans,temp)

print(ans)

Submission status: Accepted

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

p=sum(x)/N

import math

z1=0
z2=0
for i in range(N):
  z1+=(x[i]-math.floor(p))**2
  z2+=(x[i]-math.ceil(p))**2
  
print(min([z1,z2]))

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3

import sys


def minimize(n, xs):
    cost = sys.maxsize // 2
    for p in range(min(xs), max(xs) + 1):
        new_cost = sum((x - p) * (x - p) for x in xs)
        cost = min(cost, new_cost)
    return cost


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    opt_cost = minimize(n, xs)
    print(opt_cost)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = input()
xx = map(int, raw_input().split())
xx.sort()
best = float('inf')
for x in xrange(xx[0], xx[-1] + 1):
    c = sum((x - y) ** 2 for y in xx)
    best = min(best, c)
print best

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
mw = 10 ** 10
for p in range(1, 101):
    w = sum((x - p) ** 2 for x in X)
    mw = min(w, mw)

print(mw)

Submission status: Accepted

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

ans = 10**10
for i in range(1, max(X)+1):
    power = 0
    for j in range(len(X)):
        power += abs(i - X[j])**2
    ans = min(ans, power)
print(ans)

Submission status: Accepted

Solution code:
import fractions
import collections
from collections import deque
import math
import itertools

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

ans=10000000
for i in range(1,101):
    tmp=0
    for j in range(N):
        tmp+=(i-X[j])**2
    ans=min(tmp,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

miner = 10**100
for i in range(1, 101):
    sumer = 0
    for j in x:
        sumer += (j - i)**2
    miner = min(miner ,sumer)

print(miner)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = float('inf')
for p in range(min(X), max(X)+1):
  ans = min(ans, sum([(p-x)**2 for x in X]))

print(ans)

Submission status: Accepted

Solution code:
def calc(X, i):
    return sum([(x-i)**2 for x in X])


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

ans = float('inf')

for i in range(1, 101):
    c = calc(X, i)
    ans = min(ans, c)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = float('inf')
    for i in range(1,101):
        tmp = 0
        for x in X:
            tmp += (x - i) ** 2
        ans = min(ans, tmp)

    print(ans)


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(min(x),max(x)+1):
    tmp = 0
    for member in x:
        tmp += (member-i)**2

    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
a=s//n
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=temp
a+=1
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=min(ans,temp)
print(ans)

Submission status: Accepted

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

x = round(sum(a) / n)

print(sum((i - x) ** 2 for i in a))

Submission status: Accepted

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

mn =  10000000000
for i in range(1,101):
    sm =0
    for j in x:
        sm += (j-i)*(j-i)
    if sm < mn :
        mn = sm
print(mn)

Submission status: Accepted

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

minv = 1000000000000


for i in range(1, 101):
    v = 0
    for j in A:
        v += (j-i)*(j-i)
    minv = min(minv, v)

print(minv)

Submission status: Accepted

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

min_d = 10000000

for p in range(1,101):
    d = 0
    for x in X:
        d += (x-p)**2
    if d <= min_d:
        min_d = d
print(min_d)

Submission status: Accepted

Solution code:
import numpy as np

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

minval = 1000000000000
ans=0
for candidate in range(101):
    tmp = sum((X-candidate)**2)
    if tmp < minval:
        minval=tmp
        ans = candidate

print(minval)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N=ii()
    import numpy as np
    X = np.array(lmis())
    ans = INF
    for i in range(1, 100+1):
        ans = min(ans, np.sum((X-i)**2))
    print(ans)

main()

Submission status: Accepted

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

best = float('inf')
for p in range(1, 101):
    best = min(best, sum((x - p) ** 2 for x in X))
print(best)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=10**18
for i in range(1,101):
    tmp=0
    for a in A:
        tmp+=(a-i)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
def subpow(x, p):
    return (x - p) ** 2

n = int(input())
x = sorted(map(int, input().split()))
mini = 10000000000000
for p in range(x[-1] + 1):
    sum = 0
    for i in range(n):
        sum += subpow(x[i], p)
    mini = min(sum, mini)
print(mini)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
    
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
"""

#solution:
def dis2(a,p):
    return (a-p)**2
#input
N,=pin()
X=sorted(list(pin()))

ans=0
mx=100000000
for p in range(X[0],X[-1]+1):
    temp=0
    for x in X:
        temp+=dis2(x,p)
    if temp < mx:
        ans=p
        mx=temp
print(mx)
#print(["No","Yes"][cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
x=np.array(list(map(int, input().split())))

lo=min(x)
hi=max(x)
ans=float('inf')
for p in range(lo, hi+1):
    newx=(x-p)**2
    tmp=np.sum(newx)
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ave=sum(a)//n
b=sum((x-ave)**2 for x in a)
c=sum((x-ave-1)**2 for x in a)
print(min(b,c))

Submission status: Accepted

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

ans = 1000000000
for P in range(min(X), max(X) + 1):
    S = sum([(Xi - P) * (Xi - P) for Xi in X])
    ans = min(ans, S)
print(ans)

Submission status: Accepted

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

P1 = sum(Xs)//N
P2 = P1+1

ans1 = sum([(X-P1)**2 for X in Xs])
ans2 = sum([(X-P2)**2 for X in Xs])
#print('ans1:', ans1, '/ ans2:', ans2)

print(min(ans1, ans2))

Submission status: Accepted

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

ans = float('inf')
for i in range(1, 101):
    total = 0
    for j in range(N):
        total += (X[j] - i)**2
    ans = min(ans, total)

print(ans)

Submission status: Accepted

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

ans = 10 ** 9

for p in range(1,100+1):
    sum_len = 0
    for q in X:
        sum_len += (q-p)**2

    ans = min(ans,sum_len)

print(ans)

Submission status: Accepted

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

X.sort()

def solve(X, P):
    ans = 0
    for x in X:
        ans += (P - x)**2
    return ans

ans = 100 * 100**2
for i in range(1, X[-1] + 1):
    ans = min(solve(X, i), ans)
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
l = list(map(int,input().split()))
m = 1000000000

for i in range(1,101):
    t = 0
    for j in l:
        t += (i-j)**2

    m = min(t,m)
print(m)

Submission status: Accepted

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


def get_vital_sum(pos):
    ret = 0
    for x in X:
        ret += (pos - x) ** 2
    return ret


ans = 100000000
for p in range(1,101):
    ans = min(ans, get_vital_sum(p))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
ans = float('inf')
for i in range(1,101):
  tmp = 0
  for j in X:
    tmp+=(j-i)**2
  ans=min(ans,tmp)
  
print(ans)

Submission status: Accepted

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

target = round(sum(xn) / xn.__len__())

print(sum([(i - target) * (i - target) for i in xn]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ans=10**9
    n=II()
    xx=LI()
    for p in range(1,101):
        cur=sum((p-x)**2 for x in xx)
        ans=min(cur,ans)
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
X = [int(x) for x in input().strip().split()]

def f(p):
    ret = 0
    for x in X:
        ret += (x - p) ** 2
    return ret

ans = float('inf')
for i in range(1, 101):
    ans = min(ans, f(i))

print(ans)

Submission status: Accepted

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

ans = 10 ** 9
for kaisai in range(100 + 1):
    tairyoku = 0
    for c in coord:
        tairyoku += (c - kaisai) ** 2
    ans = min(ans, tairyoku)

print(ans)

Submission status: Accepted

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

hp = []
for i in range(1, 101):
    temp = 0
    for j in range(n):
        temp += ((x[j] - i) ** 2)
    hp.append(temp)
print(min(hp))

Submission status: Accepted

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


def get_score(i):
  res = 0
  for x in X:
    res += (x-i)**2
  return res
    
ans = float('inf')
for  i in range(1,101):
  ans = min(get_score(i),ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

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

answer = 10 ** 15
for p in range(min(X), max(X) + 1):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    answer = min(answer, tmp)

print(answer)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = list(map(int, input().split()))
a = sum(x)//n
b = math.ceil(sum(x)/n)
ma = 0
mb = 0
for i in x:
	ma += (i-a)**2
for i in x:
	mb += (i-b)**2
print (min(ma,mb))

Submission status: Accepted

Solution code:
n = int(input())
xl = list(map(int, input().split()))
xl.sort()
t = xl[0]
INF = float("inf")
ans = INF
for p in range(t, xl[-1]+1):
    ans = min(ans, sum([(x-p)**2 for x in xl]))
print(ans//1)

Submission status: Accepted

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

ans = 10**10

for p in range(1,101) :
    sump = 0
    for x in list_X :
        sump += (x-p)**2
    ans = min(ans,sump)

print(ans)

Submission status: Accepted

Solution code:
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True


def main():
    N = I()
    X = LI()
    mi = 10**19

    for p in range(1, 101):
        temp = 0
        for i in range(N):
            temp += (X[i] - p) ** 2
        mi = min(temp, mi)

    print(mi)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
ans = 10 ** 18 + 1
for i in range(1, 101):
    total = 0
    for j in x:
        total += (i - j) ** 2
    ans = min(ans, total)

print(ans)

Submission status: Accepted

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

x.sort()

ans=10**9
for i in range(111):
    sm=0
    for tmp in x:
        sm+=(tmp-i)**2
    if ans > sm:
        ans=sm
print(ans)

Submission status: Accepted

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

ans = 10**10
for i in range(1, 101):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

center = sum(X) / len(X)
if center - int(center) >= 0.5:
    center = math.ceil(center)
else:
    center = math.floor(center)
ans = 0
for x in X:
    ans += (center - x) ** 2
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 10**10
for i in range(1, 101):
    v = ((X - i)**2).sum()
    if ans > v:
        ans = v
print(ans)

Submission status: Accepted

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

m=sum(X)//N
if sum(X)/N-m>=0.5:
    m+=1
ans=0
for i in range(N):
    ans+=(X[i]-m)**2

print(ans)

Submission status: Accepted

Solution code:
from math import floor
N = int(input())
X = list(map(int,input().split()))
avg = sum(X)/N
l = floor(avg)
r = floor(avg)+1
ans1 = sum([(x-l)**2 for x in X])
ans2 = sum([(x-r)**2 for x in X])
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
mX = sum(X)//n
mX1 = mX+1
r = 0
r1 = 0
for i in range(n):
    r += (X[i]-mX)**2
    r1 += (X[i]-mX1)**2
print(min(r, r1))

Submission status: Accepted

Solution code:
N = int(input())
*X, = map(int, input().split())
ans = 10**20
for i in range(100):
    s = sum([(x-i)*(x-i) for x in X])
    if s < ans:
        ans = s
print(ans)