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:
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    ave = sum(xs) // n
    kouho = 0
    kouho2 = 0
    ave2 = ave + 1
    for i in range(n):
        kouho += pow(xs[i] - ave, 2)
        kouho2 += pow(xs[i] - ave2, 2)

    return min(kouho, kouho2)


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=10**8
for j in range(1,101):
    sum=0
    for i in range(n):
        sum+=(j-x[i])**2
    ans=min(ans,sum)
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+=(i-X[j])**2
  ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 10000000000

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    P = [sum(X) // N]
    P.append(P[0] + 1)
    answer = [0, 0]
    for x in X:
        for i in range(2):
            answer[i] += (x - P[i]) ** 2
    print(min(answer))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
m = 10 ** 1000

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

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

ave = sum(x)/n
p = round(ave)
res = 0
for i in x:
  res += (i -p )**2
print(res)

Submission status: Accepted

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

ans = 10**10
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(map(int, input().split()))

ans = -1
for i in range(100):
    I = i + 1
    res = 0
    for j in range(N):
        res += (I - X[j]) * (I - X[j])
    if ans == -1:
        ans = res
    else:
        ans = min(ans, res)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = INF
for i in range(1,101):
    p = i
    cnt = 0
    for j in range(n):
        cnt += (p-a[j]) ** 2
    res = min(res,cnt)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = np.fromstring(input(), int, sep=" ")

minimum = X.mean().round().astype(int)
print(((X - minimum) ** 2).sum())

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.sort()
x_min = X[0]
x_max = X[-1]

ans = 10**20
for xi in range(x_min, x_max+1):
  temp = 0
  for xj in X:
    temp += (xi - xj)**2
  
  ans = min(ans, temp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    ans = INF
    for i in range(1, 101):
        t = 0
        for j in range(n):
            t += (i - v[j]) ** 2
        ans = min(ans, t)
    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(1,101):
    ans = min(ans, sum([(x-i)**2 for x in X]))

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n=int(input())
a=[int(k) for k in input().strip().split(" ")]

c=sum(a)//n
r1=0
r2=0
for i in a:
    r1+=(i-c)**2
    r2+=(i-c-1)**2

print(min(r1,r2))

Submission status: Accepted

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

dist = 0
ans = 1e6

for i in range(101):
    p = i
    dist = 0
    for j in range(N):
        dist += (X[j]-p)**2
    ans = min(ans,dist)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a = sum(X) // N
b = sum(X) // N + 1

ans = float("inf")

for p in [a, b]:
	res = 0
	for x in X:
		res += (x - p) ** 2
	ans = min(ans, res)
	
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 x in X:
        tmp += (x - i)**2
    ans = min(ans, tmp)

print(ans)

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(1, 100)]))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
s = min(X)
g = max(X)
ans = float('inf')
for i in range(s, g+1):
    n = 0
    for x in X:
        n += (x-i)**2
    ans = min(ans, n)
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):
    s = 0
    for j in x:
        s+=(j-i)*(j-i)
    ans=min(ans,s)
print(ans)

Submission status: Accepted

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

ans = 10**10

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

print(ans)

Submission status: Accepted

Solution code:
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    m = round(sum(x) / n)
    s = 0
    for i in range(n):
        s += (m - x[i]) ** 2
    
    return s

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

p1 = sum(x) // len(x)
p2 = p1 + 1

sum1 = sum([(item - p1) ** 2 for item in x])
sum2 = sum([(item - p2) ** 2 for item in x])
print(min(sum1, sum2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ans = 10000000
    for i in range(101):
        s = 0
        for x in X:
            s += (x - i) ** 2
        if ans > s:
            ans = s
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = []

for p in range(101):
  res.append(sum([(xi - p) ** 2 for xi in x]))

print(min(res))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
a = 1e6
for p in range(1, 101):
    t = 0
    for i in range(n):
        t += (x[i] - p) ** 2
    a = min(a, t)
print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

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

ans = 10**12 
for i in range(101):
    val = 0
    for item in x:
        val += (item - i) * (item - i)
    ans = min(ans, val)
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
x_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(x_ls)
INF = 10**18
ans = INF
for i in range(1,101,1):
    res = 0
    for k, v in ct.items():
        res += v * abs(k - i) ** 2
    ans = min(res, ans)
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):
    tmp = 0
    for x in X:
        tmp += (x-p)**2
    ans = min(ans,tmp)
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):
    tmp_ans = sum([(x - p) ** 2 for x in X])
    ans = min(ans, tmp_ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

ans=1000000

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

print(ans)

Submission status: Accepted

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

min_x = min(x_list)
max_x = max(x_list)
min_power = 10000 * 1000
for i in range(min_x, max_x + 1):
    check_power = 0
    for j in x_list:
        check_power += (j - i) * (j - i)
    if(check_power < min_power):
        min_power = check_power
print(min_power)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NN = 2020202
MOD = 10**9+7
INF = float("inf")

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

vmin = float("inf")
for i in range(1, 101):
    vtmp = 0
    for j in X:
        vtmp += (i-j)**2
    vmin = min(vtmp, vmin)

print(vmin)

Submission status: Accepted

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
X = map(int, raw_input().split())
ans = INF
for pos in range(1, 101):
    S = 0
    for x in X:
        S += (x - pos) * (x - pos)
    ans = min(ans, S)
print ans

Submission status: Accepted

Solution code:
def c_rally():
    import numpy as np
    import math
    N = int(input())
    X = [int(i) for i in input().split()]
    m = np.average(X)
    ans = float('inf')
    for j in (math.floor(m), math.ceil(m)):
        ans = min(ans, sum([(x - j)**2 for x in X]))
    return ans

print(c_rally())

Submission status: Accepted

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

ANS=1<<63

for i in range(101):
    ANS=min(ANS,sum([(X[j]-i)**2 for j in range(N)]))

print(ANS)

Submission status: Accepted

Solution code:
from statistics import median as m
n=int(input())
x=list(map(int,input().split()))
r=sum(x)//n
c,d=0,0
for i in range(n):
    c+=(x[i]-r)**2
    d+=(x[i]-r-1)**2
print(min(c,d))

Submission status: Accepted

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

ans = 10**18

for i in range(101):
    S = 0
    for x in X:
        S += (i - x) * (i - x)
    ans = min(ans, S)
print(ans)

Submission status: Accepted

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

value = 1e100
for p in [center, center + 1]:
    value = min(value, sum(map(lambda x: (x - p) ** 2, xs)))

print(value)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N = int(input())
X = list(map(int,input().split()))
ans = INF
for i in range(1, 101):
    temp = 0
    for l in X:
        temp += (l-i)**2
    if temp < ans:
        ans = temp
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

N = I()
X = LI()

X.sort()

ans = float('inf')
for p in range(X[0],X[-1]+1):
    now = 0
    for i in range(N):
        now += (X[i]-p)**2
    if now < ans:
        ans = now

print(ans)

Submission status: Accepted

Solution code:
from math import log, ceil
n = int(input())
x_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(1, max(x_array)+1):
    tmp = 0
    for x in x_array:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    ans = 10000000
    for i in range(1, 101):
        s = 0
        for x in X:
            s += (x - i)*(x - i)
        ans = min(ans, s)

    print(ans)



    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
INF = float('inf')
loss = INF
for i in range(1,101):
  tmp = 0
  for x_ in x:
    tmp += (x_-i)**2
  loss = min(tmp,loss)
print(loss)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

n = int(input())
x = list(map(int, input().split()))
avg1 = int(math.ceil(sum(x) / n))
avg2 = int(math.floor(sum(x) / n))
ans1 = 0
ans2 = 0
for i in x:
  ans1 += (i - avg1) ** 2
  ans2 += (i - avg2) ** 2
print(min(ans1,ans2))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ave = sum(X) // len(X)

ans1 = 0
ans2 = 0
for x in X:
        ans1 += (ave+1-x)**2
        ans2 += (ave-x)**2

print(min(ans1,ans2))

Submission status: Accepted

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

ans = 0
mx = 10**100
for i in range(1,101):
    mm = 0
    for j in range(N):
        mm += (i-X[j])**2

    mx = min(mx,mm)
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
X = [int(x) for x in input().split()]
X.sort()
ans = 10 ** 10

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

print(ans)

Submission status: Accepted

Solution code:
import heapq
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n):
  res = 0
  for x in a:
    res += (n-x)**2
  return res

N = I()
a = IL()

ans = MAX_INT
for i in range(1,101):
  ans = min(ans, tami(i))
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

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

cnt = 10 ** 10
for i in range(101):
    p = 0
    for x in X:
        p += (i - x) ** 2

    cnt = min(cnt, p)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
l=min(x)
r=max(x)
ans=10**9
for p in range(l,r+1):
  d=0
  for i in range(n):
    d+=(p-x[i])**2
  ans=min(ans,d)
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):
    ans = min(ans, np.sum((X-i)**2))
print(ans)

Submission status: Accepted

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X = LI()
    ans = inf
    for x in range(1, 101):
        cur_ans = 0
        for point in X:
            cur_ans += (x - point) ** 2
        ans = min(cur_ans, ans)
    print(ans)

main()

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

Submission status: Accepted

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

ans = 10**9

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

Submission status: Accepted

Solution code:

#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    x = li()
    amin = 100000000000
    
    for i in range(101):
        tmp = 0
        for j in x:
            tmp+=(i-j)**2
        amin = min(amin,tmp)
    print(amin)



main()

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

a = l()

aa = sum(a)/n
po = 0
aaa = sum(a)//n
if aa != sum(a)//n:
    ppo = 0
    for i in range(n):
        po += (aaa - a[i])**2
    aaa += 1
    for i in range(n):
        ppo += (aaa - a[i])**2
    po = min(po,ppo)

else:
    for i in range(n):
        po += (aaa - a[i])**2

print(po)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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

Submission status: Accepted

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

ans = INF
for p in range(1, 101):
    d = 0
    for xi in x:
        d += (xi - p) ** 2
    ans = min(ans, d)

print(ans)

Submission status: Accepted

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

ans = 100000000000000

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

    ans = min(a, ans)


print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    X=list(map(int,input().split()))
    ans=INF
    for i in range(1,101):
        tmp=0
        for n in X:
            tmp+=(n-i)**2
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np 
n = int(input())
x = list(map(int, input().split()))
x = np.array(x)
ans = float('inf')
idx = 200
for i in range(100):
  y = x 
  ans = min(ans, np.sum((y-i)**2))
  
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = list(map(int, input().split()))
    X.sort()
    ans = float('inf')
    for i in range(1, max(X)+1):
        d = 0
        for j in range(N):
            d += pow((i - X[j]), 2)
        ans = min(ans, d)
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

x = np.array(x)

d = x - int(np.mean(x))
a = np.sum(d ** 2)

d = x - int(np.mean(x)) - 1
b = np.sum(d ** 2)


print(min(a, b))

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    m = 10 ** 9
    
    for i in range(1, 101):
        tmp = 0
        for j in range(N):
            tmp += (i - A[j]) ** 2 
        m = min(tmp, m)

    return m

print(solve())

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n = ni()
x = na()

ans = inf
for i in range(100):
    l = 0
    for j in range(n):
        l += (x[j] - i) ** 2
    ans = min(ans, l)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
m=10**100
for i in range(0,100):
    test=sum((X[j]-i)**2 for j in range(0,N))
    if test<m:
        m=test
print(m)

Submission status: Accepted

Solution code:
N=int(input())
x=list(map(int,input().split()))
mi = 10**9
for mid in range(0,max(x)+1):
    tmp = 0
    for val in x:
        tmp += (val-mid)**2
    mi = min([mi,tmp])
print(mi)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
can = []
for p in range(1,101):
  tmp = 0
  for x in a:
    tmp += (x-p)**2
  can.append(tmp)
print(min(can))

Submission status: Accepted

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

mi = -1
for i in range(min(x), max(x)+1):
	hp = 0
	for j in range(n):
		hp += (x[j]-i)**2
	if mi == -1:
		mi = hp
	else:
		mi = min(mi, hp)
print(mi)

Submission status: Accepted

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

ans = 10**9
for i in range(min(X), max(X)+1):
    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(map(int, input().split()))


ans = 10 ** 12
for i in range(1, 101):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) ** 2
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

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

	ans = min(ans, tmp)

print(ans)