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()))
ans = float('inf')
energy = []

for i in range(1, 101):
    for j in x:
        energy.append((j - i) ** 2)
    sum_energy = sum(energy)
    if sum_energy < ans:
        ans = sum_energy
    energy = []

print(ans)

Submission status: Accepted

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

ans = 10**9+7
for i in range(min(x),max(x)+1):
    tmp=0
    for j in x:
        tmp+=(i-j)**2
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


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


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


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    x = LI()
    ans = 0
    p = round(sum(x)/n)
    for i in range(n):
        ans += ((x[i]-p)**2)
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

avg = round(sum(x) / n)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 100000000
for n in range(1, 100+1):
    tmp = 0
    for x in X:
        tmp += pow((x-n), 2)
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ave = round(sum(a) / len(a))

#print(ave)

ans = 0
for i in a:
  ans += (i - ave)**2
  
print(ans)

Submission status: Accepted

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

ans = float('inf')
for p in range(min(x), max(x)+1):
    tmp = 0
    for x_ in x:
        tmp += (x_ - p) ** 2
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
import math

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


for p in range(min(x), max(x)+1):
    hp = 0
    for j in range(n):
        hp += (x[j] - p)**2
    if p == min(x):
        hpmin = hp
    elif hp < hpmin:
        hpmin = hp

print(hpmin)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP

N = int(input(''))
list = input('').split(' ')
list = [int(n) for n in list]
mean = Decimal(str(sum(list) / len(list)))
mean = mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
out = 0
for i in range(N):
    out += (list[i] - mean) ** 2
print(out)

Submission status: Accepted

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

answer = float("inf")
for p in range(1, 101):
    stamina = 0
    for x in X:
        stamina += (x - p)**2
    if stamina < answer:
        answer = stamina

print(answer)

Submission status: Accepted

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

p = sum(xs) / len(xs)
x1 = sum([(x - math.floor(p)) ** 2 for x in xs])
x2 = sum([(x - math.ceil(p)) ** 2  for x in xs])
print(min(x1, x2))

Submission status: Accepted

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

for p in range(min(x), max(x)+1):
  hp = 0
  for j in range(n):
    hp += (x[j]-p) ** 2
  if p == min(x):
    ans = hp
  elif ans >= hp:
    ans = hp

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
l = list(map(int,input().split()))
y = sum(l)
x = y//n
x1 = math.ceil(y/n)
sum1 = 0
sum2 = 0
for i in l:
  sum1 += (i-x)**2
  sum2 += (i-x1)**2
print(min(sum1,sum2))

Submission status: Accepted

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

s=0
for j in range(N):
  s=s+i[j]
p=round(s/N,0)

S=0
for k in range(N):
  S=(i[k]-p)**2+S
  
print (int(S))

Submission status: Accepted

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

def E_sum(p):
    e_sum = 0
    for i in range(n):
        y = (x[i] - p)**2
        e_sum += y
    return e_sum

m = float("inf")
for j in range(1, 101):
    tmp = E_sum(j)
    if tmp < m:
       m = tmp

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    ans = int(1e10)

    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())
li = list(map(int,input().split()))
min = 100000000000
for p in range(1,101):
  cnt = 0
  for x in li:
    cnt += (x-p)**2
  if cnt < min:
    min = cnt
print(min)

Submission status: Accepted

Solution code:
import numpy as np

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

print(min([np.sum((X - p) ** 2) for p in range(1,101)]))

Submission status: Accepted

Solution code:
import math

#パラメータの受取り
N = int(input())
X = [int(x) for x in input().split(' ')]
#会議場所の候補算出
tmp = []
tmp.append(math.floor(sum(X)/N))
tmp.append(math.ceil(sum(X)/N))

#回答算出ループ
ans = []
for val in tmp:
  S = 0
  for p in X:
    S += (p-val) ** 2
  #計算結果の格納
  ans.append(S)

#最小値を出力
print(min(ans))

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input().strip())
    x = list(map(int, input().strip().split()))
    x.sort()
    ans = sys.maxsize
    for d in range(x[0], x[-1]+1):
        ans = min(sum([(x[i] - d) ** 2 for i in range(n)]), ans)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import reduce
from operator import add
input = sys.stdin.readline

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

    ans = float('INF')
    for i in range(1, 101):
        power = reduce(add, map(lambda x: (x - i) ** 2, X))

        ans = min(ans, power)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

list2 = []

o= len(list)
new_list = sorted(list)
max = new_list[o-1]

for i in range(max+1):
    t = sum((i-k)**2 for k in list)
    list2.append(t)

list3 = sorted(list2)

print(list3[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

min_w = -1
for p in range(0, 101):
    w = 0
    for x in xs:
        w += pow(x - p, 2)
    if min_w == -1:
        min_w = w
    else:
        if min_w > w:
            min_w = w
print(min_w)

Submission status: Accepted

Solution code:
import numpy as np
import math
N = int(input())
X_k = list(map(int , input().split(" ")))

P = float(sum(X_k)/N)
P_ceil = int(math.ceil(P))
P_floor= int(math.floor(P))

ceil_sum = 0
floor_sum = 0

for X in X_k:
    ceil_sum = ceil_sum + (P_ceil-X)*(P_ceil-X)
    floor_sum = floor_sum + (P_floor-X)*(P_floor-X)


if (ceil_sum-floor_sum > 0):
    print(floor_sum)
else:
    print(ceil_sum)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(list(map(int,input().split(" "))))

energy = np.sum((X - X[0])**2)

X_max,X_min = np.max(X),np.min(X)
for i in range(X_min,X_max):
    energy_sum = np.sum((X-i)**2)
    if energy > energy_sum:
        energy = energy_sum

print(energy)

Submission status: Accepted

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

def solve(N, X):
    m = 10e10
    for x in range(100):
        c = sum((p - x)**2 for p in X)
        if c < m:
            m = c
    return m
print(solve(N, X))

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
sum=0
for x in X:
    sum+=x

sum//=N
ans1=0
ans2=0
for x in X:
    ans1+=(x-sum)*(x-sum)
    ans2+=(x-sum-1)*(x-sum-1)
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
P=0
Sum=0
l=[]

for i in range(1,101):
    for j in range(N):
        P=(X[j]-i)**2
        Sum=Sum+P
    l.append(Sum)
    Sum=0
print(min(l))

Submission status: Accepted

Solution code:
n = input()
lst = tuple(map(int, input().split()))
res = 10000*100
for i in range(1, 101):
  res = min(res, sum((i-e)**2 for e in lst))
print(res)

Submission status: Accepted

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

l, r = min(xx), max(xx)
ans = float("inf")
for i in range(l, r+1):
    ans = min(ans, sum([(i - x)**2 for x in xx]))
print(ans)

Submission status: Accepted

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

m = sum(xx) // len(xx)
left = sum([(m - i)**2 for i in xx])
right = sum([(m + 1 - i)**2 for i in xx])
print(min(left, right))

Submission status: Accepted

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

min_x = min(x)
max_x = max(x)

power = []
for i in range(100):
    power.append(i*i)

result = 999999
for i in range(min_x, max_x+1):
    count = 0
    for j in range(n):
        count = count + power[abs(i - x[j])]
    if(result > count):
        result = count

print(result)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 10000000000
for i in range(100):
    tmp = 0
    for j in range(n):
        tmp += (i - l[j]) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

ta = 10**7

for i in range(min(X), max(X)+1):
    ta = min(ta, sum([(X[j]-i)**2 for j in range(N)]))
    
print(ta)

Submission status: Accepted

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

min_res = float("inf")
for i in range(1, 101):
    res = sum((xi - i) ** 2 for xi in x)
    min_res = min(min_res, res)

print(min_res)

Submission status: Accepted

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

min_a = X[0]
max_a = X[-1]

sum_min = 0
sum_max = 0
    
def calc(x, min, max):
    mid = (min + max) // 2
    sum_min = 0
    sum_max = 0
    for value in x:
        sum_min += (value - min) ** 2
        sum_max += (value - max) ** 2
    
    if abs(min - max) <= 1:
        if sum_min < sum_max:
            return int(sum_min)
        else:
            return int(sum_max)
    elif sum_min < sum_max:
        return calc(x, min, mid)
    else:
        return calc(x, mid, max)
    
    return -1
    
ans = calc(X, min_a, max_a)
print(ans)

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    X.sort()
    m = 10000000
    for p in range(X[0], X[-1] + 1):
        s = 0
        for x in X:
            s += (x - p) ** 2
        if s < m:
            m = s

    print(m)


# 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 = input()
N = int(N)
K= list(map(int, input().split()))
import numpy as np
answers = []
ave = sum(K)//len(K)
sqrtMax = int(np.sqrt(max(K)))
rngMin = ave - sqrtMax#range min
for p in range(rngMin,rngMin+2*sqrtMax):
    ans = 0
    for k in K:
        ans += ((k-p)**2)
    answers.append(ans)
print(min(answers))

Submission status: Accepted

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

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

ans = float('inf')
for i in range(L, R+1):
    cost = 0
    for x in X:
        cost += (x-i)**2
    
    if cost < ans:
        ans = cost

# output
print(int(ans))

Submission status: Accepted

Solution code:
outnum = 1000000
human_sum = int(input())
basyo_list = list(map(int, input().split()))
for i in range(1,101):
  total_sum = 0
  for j in range(human_sum):
    total_sum = total_sum + (i - basyo_list[j]) ** 2
  if total_sum <= outnum:
    outnum = total_sum
print(outnum)

Submission status: Accepted

Solution code:
N = int(input())
x_list = [int(i) for i in input().split()]
x_list.sort()
hp = 10 ** 6
for p in range(x_list[0], x_list[len(x_list) - 1] + 1):
  hp_p = 0
  for x in x_list:
    hp_p += (x - p) ** 2
  if hp_p < hp:
    hp = hp_p
print(hp)

Submission status: Accepted

Solution code:
N = int(input())
Xlist = list(map(int,input().split()))
Xlist.sort()
wat = 2**100
for p in range(Xlist[0],Xlist[-1]+1):
  nwat = 0
  for x in Xlist:
    nwat += (x-p)**2
  if nwat < wat:
    wat = nwat
print(wat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    xlist = list(map(int, input().split()))
    x_min = min(xlist)
    x_max = max(xlist)
    min_sum_value = 10**15
    
    for p in range(100):
        c = 0
        for i in xlist:
            c += (i - p) ** 2
        if min_sum_value > c:
            min_sum_value = c
    print(min_sum_value)

main()

Submission status: Accepted

Solution code:
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# n, k = map(int, input().split())
n = int(input())
x = list(map(int,input().split()))
x.sort()
# print(x)
base = x[0]
min = 10 ** 9
for _ in range(x[n-1] - x[0] + 1):
    dist = sum((base - x[j])**2 for j in range(n))
    min = dist if dist <= min else min
    base += 1

print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力処理
N = int(input())
X_list = [int(x) for x in input().split() ]
ans = 1000000
# P を 1から100まで全ケース試す。
for p in range(1,101):
  temp = 0
  for x in X_list:
    temp += (x-p)**2
  ans = min(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = list(map(int, input().split()))
    
    ans_tmp = 10000000000000
    for j in range(100):
        ans = 0
        for i in x:
            ans += (i-(j+1))**2

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

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(1, 101):
    s = 0
    for xi in x: s += (xi - i) ** 2
    ans = min(ans, s)
print(ans)

Submission status: Accepted

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
N = int(input())
X  = list(map(int,input().split()))

b = 0 
c = 0 
for x in X:
    b = b -2 * x
    c = c + x * x 

u = int (float (-b) / float(2* N) + 0.5 )
# print(u)

s = N * u ** 2 + b * u + c
print(s)

Submission status: Accepted

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

print(min(list(sum((x-P)**2 for x in X) for P in range(min(X),max(X)+1))))

Submission status: Accepted

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

for i in range(100):
    power = 0
    for j in x:
        power += (i-j)**2
    
    if power < min:
        min = power

print(min)

Submission status: Accepted

Solution code:

def submit():
    n = int(input())
    xlist = list(map(int, input().split()))

    def cost(lst, p):
        c = 0
        for l in lst:
            c += (l - p) * (l - p)
        return c

    sum_x = sum(xlist)
    if sum_x % n:
        p1 = sum_x // n
        p2 = sum_x // n + 1
        print(min(cost(xlist, p1), cost(xlist, p2)))
    else:
        print(cost(xlist, sum_x // n))


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
import math
def solve():
    n=int(input())
    x=list(map(int,input().split()))
    
    ave=0
    sum=0
    for i in range(len(x)):
        sum+=x[i]
    ave=sum/len(x)
    if ave>math.floor(ave)+0.5:
        pre=math.ceil(ave)
    else:
        pre=math.floor(ave)
    ans=0
    for i in range(len(x)):
        ans+=(x[i]-pre)**2
    print(ans)
    
solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    X = list(map(int, input().split()))
    P = int(sum(X)/N+0.5)
    print(sum(map(lambda Xi: (Xi-P)**2, X)))

resolve()

Submission status: Accepted

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

n = sum(lst)//N

ans = 0
ans2 = 0
for i in lst:
    ans += (i-n)**2
    ans2 += (i-n-1)**2

print(min(ans, ans2))

Submission status: Accepted

Solution code:
n = int(input())
number = list(map(int, input().split()))
a = sum(number)
g0 = a//n
g1 = a/n
if g1-g0 >= g0+1 - g1:
  g = g0+1
else:
  g = g0

ans = []
for i in range(n):
  l = (number[i] - g)**2
  ans.append(int(l))
print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())

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

min_hp = 0
sum_hp = 0

for i in range(n):
    sum_hp += (x[i]-1)**2
min_hp = sum_hp

sum_hp = 0
for i in range(2,max(x)+1):
    for j in range(n):
        sum_hp += (x[j]-i)**2
    if min_hp > sum_hp:
        min_hp = sum_hp
    sum_hp = 0
 
print(min_hp)

Submission status: Accepted

Solution code:
num = int(input())
address_list = [int(i) for i in input().split()]
meet_address_low = sum(address_list) // num
meet_address_high = meet_address_low + 1

diff_low = 0
diff_high = 0

for address in address_list:
    diff_low += (address - meet_address_low) ** 2
    diff_high += (address - meet_address_high) ** 2

print(min(diff_high, diff_low))

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
ans = 1001001001
for i in range(min(x), max(x) + 1):
    ans = min(ans, sum((j - i)**2 for j in x))
print(ans)

Submission status: Accepted

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

ans=float("inf")
for i in range(101):
    tmp=0
    for j in range(n):
        tmp += (x[j]-i)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x_list = list(map(int, input().split()))
power_list = [0] * 100
def cost(p, q):
  return (p - q) ** 2
for i in range(100):
  for j in range(n):
    power_list[i] += cost(x_list[j], i)
print(min(power_list))

Submission status: Accepted

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

s=min(l)
g=max(l)
ans=0
for k in range (n):
  ans+=(l[k]-s)**2

for i in range(s+1,g+1):
  hyp=0
  for j in range (n):
    hyp+=(l[j]-i)**2
  if hyp<ans:
    ans=hyp
    
print (ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split(" ")))
P=min(X)
L=max(X)
sum1=0
for i in range(N):
  sum1+=(X[i]-P)*(X[i]-P)
while P!=L:
  sum2=0
  for i in range(N):
    sum2+=(X[i]-P-1)*(X[i]-P-1)
  if sum2<sum1:
    sum1=sum2
  P+=1
print(sum1)

Submission status: Accepted

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

mn = min(xs)
mx = max(xs)
INF = float('inf')


result = INF
for p in range(mn, mx + 1):
    tmp = 0
    for x in xs:
        tmp += (p - x) ** 2
    if tmp < result:
        result = tmp

print(result)

Submission status: Accepted

Solution code:
n = int(input())
list_x = list(map(int, input().split()))
 
#iが座標の位置
 
list_ans = []
 
for i in range(min(list_x), max(list_x)+1):
    
    #計算する
    ans = 0
    for j in list_x:
        ans += (i-j)**2
 
    list_ans.append(ans)
  
print(min(list_ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ave = sum(a)//n
b = sum([(i-ave)**2 for i in a])
c = sum([(i-ave-1)**2 for i in a])

print(min(b, c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
low = min(X)
high = max(X)
ans = []

for p in range(low, high-low+1):
  dist = 0
  for x in X:
    dist += (x-p)**2
  ans.append(dist)
if len(ans) != 0:
  print(min(ans))
else:
  print(0)

Submission status: Accepted

Solution code:
n=int(input())
x=[int(i) for i in input().split()]
ans=10**10
for i in range(101):
  sum_=0
  for xx in x:
    sum_+=(xx-i)**2
  ans=min(sum_,ans)
print(ans)

Submission status: Accepted

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

li=[]

for p in range(x[0],x[-1]+1):
  hp=0
  for q in x:
    hp+=(p-q)**2
  li.append(hp)
print(min(li))

Submission status: Accepted

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

ave = sum(X) // N

anss = []
for P in [ave-1, ave, ave+1]:
    anss.append(sum([(P-x)**2 for x in X]))

print(min(anss))

Submission status: Accepted

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

X=[]
N=int(raw_input())
X=map(int,raw_input().split())

kotae=0
for p in range(min(X),max(X)+1):
    karioki=0
    for i in range(N):
        karioki+=pow(X[i]-p,2)
    if(p==min(X)):
       kotae=karioki
    elif(kotae>karioki):
         kotae=karioki
print kotae

Submission status: Accepted

Solution code:
n = int(input())
ylist = list(map(int,input().split()))
p = list(range(0,max(ylist)+1))
anslist = []
for i in p:
  ansl = sum((p[i]-ylist[j])**2 for j in range(0,n))
  anslist.append(ansl)
print(min(anslist))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
xs = list(map(int, input().strip().split()))
mn = min(xs)
mx = max(xs)
xs = np.array(xs)
diffs = np.empty((100, n), dtype=np.int)
for p in range(100):
    diffs[p] = xs - (p + 1)

ans = np.min(np.sum(diffs**2, axis=1))

print(ans)

Submission status: Accepted

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

x_min = min(X)
x_max = max(X)

Min_power = 0

for i in X:

    Min_power += (i-x_min)**2


for p in range(x_min, x_max+1):
    power = 0
    for i in X:
        power += (i-p)**2
    if Min_power > power:
        Min_power = power

print(Min_power)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

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

ans = None
for i in range(X[0], X[-1] + 1):
    dist = sum((i - j) ** 2 for j in X)
    if ans is None or dist < ans:
        ans = dist
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

# print(n, x)

ans = 1000000000000
i = 0
while i < 100:
  sum = 0
  for x in xs:
    sum += (x - i)**2
  if sum < ans:
    ans = sum
  i += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
# 最小二乗法とやってること同じなので平均で最小になると考えて
P1, P2 = sum(X) // N, -(-sum(X) // N)
ans1, ans2 = 0, 0
for x in X:
    ans1 += (x - P1)**2
    ans2 += (x - P2)**2
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import math

N = int(input())
lst = [int(x) for x in input().split()]
a = sum(lst) / N
b = math.ceil(a)
c = math.floor(a)
ret1 = sum([(b - x) ** 2 for x in lst])
ret2 = sum([(c - x) ** 2 for x in lst])

print(min(ret1, ret2))

Submission status: Accepted

Solution code:
##input##
N = int(input())
num = input().split()
max_num =max(num)
temp = []
##

##for i in range(int(max_num)):
for i in range(100):
  sum = 0
  for a in num:
    out = (i - int(a))** 2
    sum += out
  temp.append(sum)

min_temp=min(temp)
print(min_temp)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
cost = []
for i in range(100):
  tmp = 0
  for j in x:
    tmp += (j - i) ** 2
  cost.append(tmp)
cost.sort()
print(str(cost[0]))

Submission status: Accepted

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

Submission status: Accepted

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

avg = round(sum(X)/len(X))
Y = [(x-avg)**2 for x in X]
print (sum(Y))

Submission status: Accepted

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

s = []
for pos in range(min(x_lis),max(x_lis)+1):

    tir = []
    for x in x_lis:
        tir.append((x - pos)**2)
    s.append(sum(tir))
        

print(min(s))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
def EN(x):
  return sum([(x-a)**2 for a in A])
m = EN(1)
for i in range(2, 101):
  if EN(i) <= m:
    m = EN(i)
  else:
    break
print(m)

Submission status: Accepted

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

ans = []
count = 0

for i in range(0,101):
    number = 0
    count = 0
    for j in X:
        number = number + ((j-i)**2)
        count = count + 1
        if N == count:
            ans.append(number)

print(min(ans))

Submission status: Accepted

Solution code:
def listint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
def getint():
    a = input()
    a = int(a)
    return a
def main(n,x):
    ans = 10000000
    for i in range(100):
        sumup = 0
        for j in range(n):
            sumup = sumup + (x[j] -i)*(x[j]-i)
        if sumup < ans:
            ans = sumup
    return ans
        
n = getint()
x = listint()
ans = main(n,x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(j) for j in input().split()]
ans=10**18
for i in range(101):
    tmp=0
    for j in a:
        tmp+=(i-j)**2
    ans=min(ans,tmp)
print(ans)