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:
n = int(input())
x = list(map(int, input().split()))
best = 10**10

for i in range(1, 101):
    num = 0
    for xx in x:
        num += (xx-i)**2
    if num < best:
        best = num

print(best)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(N, X):
    def calc_cost(p):
        return sum((x-p)**2 for x in X)

    return min(map(calc_cost, range(max(X) + 1)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Submission status: Accepted

Solution code:
def cal_cost(X, P):
    cost = 0
    for x in X:
        cost += (x - P) ** 2
    return cost


def main(N, X):
    return min(cal_cost(X, p) for p in range(max(X) + 1))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod
 
    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)
 
def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)

###################################################################
def main():
    #CODE GOES HERE:
    n=ii()
    x=li()
    l,r=min(x),max(x)
    answer0=float("inf")
    for s in range(l,r+1):
        answer0=min(answer0,sum([(i-s)*(i-s) for i in x]))
    print(answer0)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
 
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
 
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
 
class IOWrapper(IOBase):
 
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
 
""" main function"""
 
if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
import math
import statistics

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


gra = round(statistics.mean(X))

cost = 0
for i in range(N):
    cost += (X[i] - gra)**2

print(cost)

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int, input().split()))
s=10000000000
for p in range(1,101):
    a=0
    for i in List:
        a+=(i-p)**2
    if a<=s:
        s=a
print(s)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
sum = 0
min = n * 10000

for i in range(1,101):
  for j in x:
    sum += (j-i)**2
  if min > sum:
    min = sum
  sum = 0

print(min)

Submission status: Accepted

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

Submission status: Accepted

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

    mini = float("inf")
    for p in range(1, 101):
        power = 0
        for n in range(N):
            power += (X[n] - p) ** 2
        if power < mini:
            mini = power
    
    print(mini)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
X.sort()
ANS = []
for i in range(X[0],X[len(X)-1]+1):
  k = 0
  for j in range(len(X)):
    k += (i - X[j]) ** 2
  ANS.append(k)
  
print(min(ANS))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
costMin = 9999999999
for locate in range(1, 101):
  cost = 0
  for i in range(N):
    cost += (X[i]-locate)**2
  if cost < costMin:
    costMin = cost
print(costMin)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int,input().split()))
ans = [0]*max(X)

for i in range(1,max(X)+1):
    for j in range(n):
        tmp = abs(i - X[j])**2
        ans[i-1] += tmp

print(min(ans))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
a = min(X)
b = max(X)
r = 100000000000
for i in range(a,b+1):
  t = (X[0]-i)**2
  for j in range(1,N):
    t += (X[j]-i)**2
  if t < r:
    r = t
print(r)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
j = max(x)
m = 0
y = True

for i in range(n):
    if x[0] != x[i]:
        y = False

if y:
    print(0)
    exit(0)

for p in range(j):
    c = 0
    z = 0
    for i in range(n):
        z = x[i] - p
        c = c + (z * z)
    
    if m == 0:
        m = c
    else:
        if m > c:
            m = c

print(m)

Submission status: Accepted

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

p_max = 100
ans_min = 1000000 # 最大でも(100 - 1) ** 2 * 100だからそれを超えればいい
for p in range(1, p_max):
    sum_ = 0
    for x in X:
        sum_ += (x - p) ** 2
    ans_min = min(sum_, ans_min)
print(ans_min)

Submission status: Accepted

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

x_max = 100
ans_min = 1000000
for p in range(x_max):
    sum_ = 0
    for x in X:
        sum_ += (x - p) ** 2
    ans_min = min(sum_, ans_min)
print(ans_min)

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 x in X:
        tmp += (x-i)**2
    ans = min(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
N = int(input())
X = list(map(int,input().split()))
P = np.round(np.average(X))

print(int(np.dot(X,X) + P * P * N - 2 *np.sum(X)*P))

Submission status: Accepted

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

P = []
for i in range(1,101):
    P.append(sum([(X[x]-i)**2 for x in range(N)]))

print(min(P))

Submission status: Accepted

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

min_hp = float('inf')

for i in range(min(x), max(x) + 1):
    hp = 0
    for xi in x:
        hp += abs(i - xi) ** 2
    if hp < min_hp:
        min_hp = hp

print(min_hp)

Submission status: Accepted

Solution code:

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

a = round(sum(L) / len(L))
ans = 0

for i in L:
    ans += (a - i)**2

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
y=np.array(list(map(int,input().split())))
n=int(round(np.average(y)))
yy=(y-n)**2
print(np.sum(yy))

Submission status: Accepted

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

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
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for xi in x:
  sum += xi
p = round(sum / n)
ans = 0
for xi in x:
  ans += (xi - p) ** 2
print(ans)

Submission status: Accepted

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

MaxNum = max(x)

SumEnergy = 0
ans = (100**2)*100

for p in range(-MaxNum, MaxNum+1):
    for a in range(n):
        SumEnergy += (x[a] - p)**2
    ans = min(ans, SumEnergy)
    SumEnergy = 0

print(ans)

Submission status: Accepted

Solution code:
import math

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

L = min(X)
R = max(X)

result = 10**18
for i in range(L, R + 1):
    cost = 0
    for j in X:
        distance = (j - i)**2
        cost += distance
    result = min([result, cost])

print(result)

Submission status: Accepted

Solution code:
N = int(input())

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

L=min(X)
H=max(X)
smallest = 10**18
for p in range(L,H+1):
  sum=0
  #print(p)
  for j in range(N):
    sum=sum+(X[j]-p)**2
  #print(sum)
  if sum<=smallest:
    smallest=sum

print(smallest)

Submission status: Accepted

Solution code:
import math
N=int(input())
ls=list(map(int,input().split()))
av=math.floor(sum(ls)/N)
A=B=0
for i in range(N):
  A+=(ls[i]-av)**2
  B+=(ls[i]-av-1)**2
print(min([A,B]))

Submission status: Accepted

Solution code:
N=int(input())
ls=list(map(int,input().split()))
ans=10**9+7
for i in range(1,101):
  a=0
  for j in range(N):
    a+=(i-ls[j])**2
  ans=min([ans,a])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
p = round(sum(X)/N)
h = [(x - p) ** 2 for x in X]
print(sum(h))

Submission status: Accepted

Solution code:
import sys
# 整数の入力
n = int(input())
x = list(map(int, input().split()))
sum = []
for y in range(min(x), max(x)+1):
  su = 0
  for m in range(n):
    su += (x[m]-y)**2
  sum.append(su)
print(min(sum))

Submission status: Accepted

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

sum = 0
for xi in x:
  sum += xi
p = round(sum / n)
ans = 0
for xi in x:
  ans += (xi - p) ** 2
print(ans)

Submission status: Accepted

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

md = int(sum(x)/n+.5)
num = 0
for i in x:
    num += (abs(i-md))**2
print(num)

Submission status: Accepted

Solution code:
import collections

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

x = collections.Counter(X)

N = len(x)
s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
res=10**6
for i in range(1,101):
  tmp = sum([(i-y)**2 for y in x])
  if res > tmp:
    res = tmp
print(res)

Submission status: Accepted

Solution code:
N = int(input())
X = sorted([int(i) for i in input().split()])
R = 1000000
for c in range(X[0], X[-1]+1):
    if sum((c-X[i])**2 for i in range(N)) < R:
        R = sum((c-X[i])**2 for i in range(N))
    else:
        pass
print(R)

Submission status: Accepted

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

    ans = 1e9
    for p in range(1, 101):
        tans = 0
        for i in range(0, n):
            tans += (x[i-1] - p) ** 2
        ans = min(ans, tans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
mn = float("INF")
ans = 0
for p in range(min(x), max(x)+1):
  score = sum([(xx - p)**2 for xx in x])
  if mn > score:
    ans = p
    mn = score
print(mn)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
X=list(map(int,input().split()))
X=np.array(X)
ans=10**100
for i in range(1,101):
  tmp=np.sum((X-i)**2)
  if tmp<ans:
    ans=tmp
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
a = min(x)
b = max(x)
ans  = 10**9

for i in range(a, b+1):
    s = 0
    for j in x:
        s += (j-i)**2

    ans = min(ans, s)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

a = list(map(int, input().split()))
ave = int(sum(a))/len(a)
total0, total1 = 0, 0
for i in a:
    total0 += (i-int(ave+1))**2
    total1 += (i-int(ave))**2
print(min(total0, total1))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
min_cost = 10000000
cost = 0

for i in range(min(X), max(X)+1):  # やる場所
    for k in range(N):  # 各人のコスト
        cost += (i - X[k]) ** 2
    min_cost = min(min_cost, cost)
    cost = 0

print(min_cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
sum=[]
for y in range(min(x),max(x)+1):
  su=0
  for m in range(n):
    su+=(x[m]-y)**2
  sum.append(su)
print(min(sum))

Submission status: Accepted

Solution code:
n =int(input())
xi = list(map(int,input().split()))
min_kyo = 0
for house in xi:
  min_kyo += (1 - house)**2
  
for i in range(2,max(xi)+1):
  kyori = 0
  for house in xi:
    kyori += (i - house)**2
  if kyori < min_kyo:
    min_kyo = kyori
    
print(min_kyo)

Submission status: Accepted

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

cost = [0] * 100
for p in range(100):
    for x in X:
        cost[p] += (x-p) ** 2

ans = min(cost)
print(ans)

Submission status: Accepted

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

y = list(set(x))
y.sort()

ans = 10**18
for p in range(min(y), max(y)+1):
   tmp = [(x[i]-p)**2 for i in range(n)]
   ans = min(ans, sum(tmp))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
mini = 100**2 * 100
for i in range(1, 101):
    s = 0
    for j in range(len(x)):
        s += (x[j] - i) ** 2
    if s < mini:
        mini = s
print(mini)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *x = map(int, open(0).read().split())
ans = 1000000000000000000000000
for i in range(100):
    a = 0
    for j in x:
        a += (j-i)**2
    ans = min(ans, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
a=sum(X)//N
b=sum(X)//N+1
ans1=0
ans2=0

for i in range(N):
  ans1+=(X[i]-a)**2
  ans2+=(X[i]-b)**2
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
temp = 0
result = float("inf")
for j in range(1,101):
    temp = 0
    for k in range(N):
        temp += ((X[k] - j) ** 2)
    result = min(temp, result )
print(result)

Submission status: Accepted

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

select=len(S)
goukei=10**10
for i in range(1,100):
    kouho=0
    for j in range(select):
        kouho+=(S[j]-i)**2
    
    if kouho<goukei:
        goukei=kouho
    
print(goukei)

Submission status: Accepted

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

print(min(result))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
m = max(X)
res = float('Inf')
for m in range(1, m+1):
    total = 0
    for n in range(N):
        total += (X[n] - m)**2
    if res > total:
        res = total
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
INF = float("inf")
minimum = INF
for x in range(100):
    sum = 0
    for i in range(N):
        sum += (x - X[i])**2
    minimum = min(sum, minimum)
print(minimum)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
p=round(sum(x)/n)

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

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
X = list(map(int,input().split()))
judge = float('inf')
for i in range(1,101):
    p = i
    tmp = 0
    for j in range(N):
        tmp += (X[j]-p)**2
    if tmp < judge:
        judge = tmp
        ans = tmp
        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array([x for x in map(int,input().split())])

P = int(X.sum()/N)

if ((X-P)**2).sum() < ((X-(P+1))**2).sum():
    ans = ((X-P)**2).sum()
else:
    ans = ((X-(P+1))**2).sum()

print(ans)

Submission status: Accepted

Solution code:
def ans(p, x):
    a = 0
    for i in x:
        a += (i - p)**2
    return a

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

p = sum(x)//n

print(min(ans(p, x), ans(p+1, x)))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
minhp=10000001
for i in range(1,101):
    hp=0
    for hu in X:
        hp+=(hu-i)**2
    minhp=min(minhp,hp)
    
print(minhp)

Submission status: Accepted

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

Y = sum(X)/len(X)
Y_floor = sum(X)//len(X)
Y_ceil = Y_floor+1
if  abs(Y-Y_floor)>=abs(Y-Y_ceil):
    Z=Y_ceil
else:
    Z = Y_floor

counter = 0 
for i in X:
    counter += (i-Z)**2

print(counter)

Submission status: Accepted

Solution code:
def C():
    n = int(input())
    x = list(map(int, input().split()))
    res = []
    for p in range(min(x), max(x)+1):
        psum = 0
        for i in x:
            psum += (i-p)**2
        res.append(psum)
    print(min(res))
C()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    x = list(map(int, input().split()))
    p = round(sum(x)/n)
    stamina = 0
    for i in range(n):
        stamina += (x[i] - p) ** 2
    print(stamina)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
 
avg = round(sum(X) / N)
ans = 0
# for文で総計求める
for i in X:
    ans +=  (i - avg)**2
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

for i in range(x[0]+1, x[-1]+1):
    sum = 0
    for item in x:
        sum += pow(item-i, 2)

    if sum < ans or ans == 0:
        ans = sum

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
avr = int(sum(X)/N)
avr1 = avr + 1
cnt = 0
cnt1 = 0
for i in range(N):
    cnt += (X[i] - avr)**2 
    cnt1 += (X[i] - avr1)**2 
print(min(cnt,cnt1))

Submission status: Accepted

Solution code:
import numpy as np
import math
#入力
n = int(input())
x = np.array(list(map(int, input().split())))
mean_x = x.mean()
if sum((x - math.ceil(mean_x))**2) >= sum((x - math.floor(mean_x))**2):
    print(sum((x - math.floor(mean_x))**2))
else:
    print(sum((x - math.ceil(mean_x))**2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int,input().split()))
p = round(sum(X)/n)
total = 0
for i in range(n):
  total+=int((X[i]-p)**2)
print(total)

Submission status: Accepted

Solution code:
def WorkloadCalculation(arr,P):
    D=0
    for a in range(len(arr)):
        d=abs(arr[a]-P)
        D += d**2
    return D

N=int(input())
Xlist=[]
X=input().split()
for x in X:
    _x=int(x)
    Xlist.append(_x)

Xlist.sort()
P=Xlist[0]

workload=10000000
STOPflg=False
    
while STOPflg==False:
    _wl=WorkloadCalculation(Xlist,P)
    if _wl < workload:
        workload=_wl
        P+=1
    else:
        print(workload)
        STOPflg=True
        exit()
        
print(workload)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
X = sorted(X)
minx = X[0]
maxx = X[-1]

ans = 10 ** 9 + 7
for i in range(minx, maxx + 1):
    temp = 0
    for j in range(N):
        temp += (i - X[j]) ** 2
    ans = min(ans, temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import decimal
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) // 2 / p


n, *x = map(int, read().split())
ave = int(my_round(sum(x) / len(x)))
l = [(y - ave) ** 2 for y in x]
print(sum(l))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    n = int(input())
    X = list(map(int,input().split()))

    ans = 0
    p = round(sum(X)/n)
    for i in range(n):
        ans += (X[i]-p)**2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
xlis = list(map(int,input().split()))
def tai(p,x):
  return pow(x-p,2)
ans=999999999999
for i in range(0,100):
  sum=0
  for j in xlis:
    sum+=tai(i,j)
  if ans>sum:
    ans=sum
    
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    ave=round(sum(A)/N)
    ans=0
    for x in A:
        ans+=(x-ave)**2
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP

num_of_person = int(input())
coordinates = list(map(int, input().split()))

avg = sum(coordinates) / len(coordinates)
avg = Decimal(str(avg)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

power = 0
for coordinate in coordinates:
    power = power + (coordinate - avg) ** 2

print(power)