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 = [int(i) for i in input().split()]
sum = 10**10
for p in range(101):
    ans = 0
    for i in range(N):
        d = (X[i] - p)**2
        ans += d
    sum = min(sum,ans)
print(sum)

Submission status: Accepted

Solution code:

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    N = iRaw()
    Xs = isRaw()
    nowCost = INF
    nowC = -1
    for c in range(1,101):
        cost =sum([(x-c)**2 for x in Xs])
        if nowCost > cost:
            nowCost = cost
            nowC = c

    return nowCost
    


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
mn=min(x)
mx=max(x)
ans=float("inf")
for i in range(mn,mx+1):
    a=0
    for X in x:
        a+=(i-X)**2
    ans=min(ans,a)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=[int(i) for i in input().split()]
#sum(Xi*Xi)-2sum(Xi)*P+N*P*P
A=sum([i*i for i in X])
B=sum(X)
ans=10**15
for P in range(101):
    tmp=A-2*B*P+N*P*P
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

o = []
for Y in range(1,101):
    o.append(sum(map(lambda x: (x - Y)**2,X)))

print(min(o))

Submission status: Accepted

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

ans = 1000000

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 14:37:00 2020

@author: matsui
"""

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

cost=[]

for i in range(1,101):
    c=0
    for x in X:
        c+=(x-i)**2
    cost.append(c)

print(min(cost))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
X.sort()

INF = 10**9+7
ans = INF
for p in range(0, 102):
    res = 0
    for x in X:
        res += (p-x)**2
    ans = min(ans, res)
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
from collections import deque, Counter
from itertools import permutations, combinations
from heapq import heapify, heappop, heappush
from bisect import bisect, bisect_left

def solve():
    input = sys.stdin.readline
    N = map(int, input().split())
    X = [int(x) for x in input().split()]
    minx, maxx = min(X), max(X)
    minPow = 1000000000000
    for i in range(minx, maxx+1):
        pow = 0
        for j, x in enumerate(X): pow += (x - i) ** 2
        minPow = min(minPow, pow)
    print(minPow)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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


ans = 10 ** 10

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

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):
    P = i
    cost = 0
    for j in range(N):
        cost += (X[j] - P) ** 2
    ans = min(ans,cost)
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int( input())
    X = list( map( int, input().split()))
    now = 10000000
    for i in range(1,101):
        t = 0
        for x in X:
            t += (x-i)**2
        if t < now:
            now = t
    print(now)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=1145141919810
for x in range(1,101):
  kyori=0
  for i in range(n):
    kyori+=(A[i]-x)**2
  ans=min(ans,kyori)
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
p = sum(a)//n
P = sum(a)//n + 1
b = [ (x - p)**2 for x in a]
c = [ (x - P)**2 for x in a]
print(min(sum(b),sum(c)))

Submission status: Accepted

Solution code:

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


INF = 1<<30
ans = INF

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

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, X: "List[int]"):
    ret = float('inf')
    for p in range(101):
        tmp = 0
        for u in X:
            tmp += (u - p) ** 2
        ret = min(ret, tmp)
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = float("inf")
for i in range(-1,2):
    z = y+i
    tmp = 0
    for j in x:
        tmp += (z-j)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

ans=1001001001001

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

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    X = [int(x) for x in input().split()]

    ans = float("inf")
    for a in range(1, 101):
        tmp = 0
        for x in X:
            tmp += (x - a) ** 2
        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ss=[]
for p in range(1, 100 + 1):
  s=0
  for x in X:
    s += (x - p) ** 2
  ss.append(s)
  
print(min(ss))

Submission status: Accepted

Solution code:

N = int(input())

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

ans = float("inf")

for p in range(min(X) - 1 , max(X) + 2):

    now = 0

    for i in X:
        now += (i-p)**2

    ans = min(ans,now)

print (ans)

Submission status: Accepted

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

mn = float("inf")

for i in range(101):
    sm = 0
    for e in x:
        sm += (e - i) ** 2

    mn = min(mn, sm)

print(mn)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
h = sum(X)//N
ans = 0
for x in X:
    ans+=(x-h)**2
ans2 = 0
h+=1
for x in X:
    ans2+=(x-h)**2
print(min(ans, ans2))

Submission status: Accepted

Solution code:
n = int(input())

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

ans = float("inf")
for i in range(1, 101):
    tmp = 0
    for idx, x in enumerate(xl):
        tmp += (x - i) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20

def main():
    n = getN()
    nums = getList()
    mid = sum(nums) // n
    ans1 = 0
    for num in nums:
        ans1 += (num - mid) ** 2

    # print(ans1)

    ans2 = 0
    mid += 1
    for num in nums:
        ans2 += (num - mid) ** 2

    # print(ans2)
    mid -= 2
    ans3 = 0
    for num in nums:
        ans3 += (num - mid) ** 2

    print(min(ans1, ans2, ans3))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
def input():
	return stdin.readline()[:-1]

def intput():
	return int(input().rstrip())

def sinput():
	return input().rstrip().split()

def intsput():
	return map(int, sinput())

def main():
	n = intput()
	ls = list(intsput())
	min_score = 10**30
	for i in range(1, 101):
		score = 0
		for j in ls:
			score += (j-i)**2
		if score < min_score:
			min_score = score
	print(min_score)



if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
c=[]
for i in range(100):
    b=0
    for j in range(n):
        b+=(a[j]-i-1)**2
    c.append(b)
print(min(c))

Submission status: Accepted

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

point = round(sum(x_list)/len(x_list))

count = 0

for x in x_list:
    count += (x-point)**2

print(count)

Submission status: Accepted

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

ans = 999999999
for k in range(100):
    buf = 0
    for i in x:
        buf += (k - i) ** 2
    ans = min(buf, ans)

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

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

X = np.array(X, dtype=int)


def calc(p):
    return ((X - p) ** 2).sum()


ans = INF
for i in range(200):
    ans = min(ans, calc(i))
print(ans)

Submission status: Accepted

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

for i in range(101):
    T=0
    for j in X:
        T+=(j-i)**2
    if T<ans:
        ans=T

print(ans)

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    answer = 10**9
    for i in range(101):
        tmp = 0
        for j in range(N):
            tmp += (X[j]-i)**2
        answer = min(tmp,answer)
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
d = round(sum(b)/a)
b = list(map(lambda x:(d-x)**2,b))
print(sum(b))

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)


n, = get_nums_l()
xxx = get_nums_l()

ans = 9999999999999999999999999
for p in range(1,101):
    a = sum([ (p-x)**2 for x in xxx ])
    ans = min(ans, a)

print(ans)

Submission status: Accepted

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

ans = 10**9

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

print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    x=LIST()
    ct=99999999999
    nmax=max(x)
    nmin=min(x)
    for i in range(nmin,nmax+1):
        temp=0
        for j in x:
            temp+=(j-i)**2
        ct=min(ct,temp)
    print(ct)
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
n = int(input())
x = [ int(i) for i in input().split() ]
s = sum(x)
avg = s//n
avg2 = avg+1

ans1 = 0
ans2 = 0
for i in x:
	ans1 += (avg-i)**2
	ans2 += (avg2-i)**2

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# a, b
# s = input()

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

ans = int(1e18)
for i in range(1, 101):
    now = 0
    for x in X:
        now += (x-i)*(x-i)
    ans = min(ans, now)
print(ans)

Submission status: Accepted

Solution code:
n = input()
pos = map(int, raw_input().split())
ans = 10**9
for i in range(1, 101):
	tmp = 0
	for j in pos:
		tmp += (i - j)**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 P in range(1, 100):
    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()))
m = 10 ** 10
for i in range(101):
  c = 0
  for j in x:
    c += (j-i)**2
  m = min(m,c)
print(m)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
ans = 10**18
m = min(X)
M = max(X)

for i in range(m, M+1):
    ans_cand = 0
    
    for Xi in X:
        ans_cand += (i-Xi)**2
    
    ans = min(ans, ans_cand)

print(ans)

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
ans = 100000000
for i in range(101):
    d = sum((x-i)**2 for x in X)
    ans = min(ans, d)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split( )))
mx = 10**15
for p in range(1,101):
    sm = 0
    for i in range(n):
        sm += (x[i]-p)*(x[i]-p)
    mx =min(sm,mx)
print(mx)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
M = int(1e+9)
for i in range(max(X) + 1):
  S = 0
  for j in X:
    S += (j - i)*(j - i)
  if M > S:
    M = S
print(M)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = inf
for i in range(min(x), max(x) + 1): #座標
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    *xs, = map(int, input().split())

    ret = float('inf')
    for p in range(100 + 1):
        t = 0
        for x in xs:
            t += (p - x) ** 2
        ret = min(ret, t)
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

res = float("inf")
for p in range(110):
    s = 0
    for x in X:
        s += pow(p - x, 2)
    res = min(res, s)

print(res)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(c) for c in input().split()]
ans = float('inf')
for c in range(102):
  m = 0
  for i in range(N):
    m += (X[i]-c)**2
  ans = min(ans,m)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 10**14
for t in range(101):
    s = 0
    for a in A:
        s += (a-t)**2
    ans = min(ans, s)
print(ans)

Submission status: Accepted

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

mi = 1<<100
for i in range(1, 101):
    mi = min(mi, sum([(x-i)**2 for x in X]))

print(mi)

Submission status: Accepted

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



min_cost = 1e18
for i in range(1,101):
    temp_cost = 0
    for j in range(n):
        temp_cost += (arr[j]-i)**2

    if temp_cost < min_cost:
        min_cost = temp_cost

print(min_cost)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
X=list(map(int,input().split()))
for p in range(1,100):
  tmp = 0
  for xi in X:
    tmp += (xi-p)**2
  mans = min(mans,tmp)
print(mans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = float("inf")
for x in range(1, 101):
  t = 0
  for y in a: t += (y - x) ** 2
  res = min(res, t)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for p in range(1, 101):
    res = 0
    for y in x:
        res += (p - y) ** 2
    ans = min(ans, res)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    print(min([sum([(i-p)**2 for i in x]) for p in range(101)]))


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*a = [int(i) for i in read().split()]
#a = [int(i) for i in readline().split()]
#n = int(input())

n,*x = [int(i) for i in read().split()]


ans = 10**18

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

print(ans)

Submission status: Accepted

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

ans = 10 ** 18
for p in range(-100, 200):
    cost = sum((x - p) ** 2 for x in X)
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

ans = 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()

ans = INF
for i in range(1, 101):
	spot = i
	tmp = 0
	for j in range(N):
		tmp += (X[j]-spot)**2
	if tmp < ans:
		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):
    c = 0
    for i in range(N):
        c += (X[i]-p)**2
    ans = min(ans,c)
print(ans)

Submission status: Accepted

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

ans = 1e9
for y in range(110):
    tmp = 0
    for x in X:
        tmp += (y-x)**2
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
l = nl()
print(min(sum((x-y)**2 for x in l) for y in range(101)))

Submission status: Accepted

Solution code:
def examA():
    N, R = LI()
    ans = R+100*max(0,(10-N))
    print(ans)
    return

def examB():
    N, K = LI()
    ans = 1
    while(N>=K):
        N //=K
        ans += 1
    print(ans)
    return

def examC():
    N = I()
    X = LI()
    ans = inf
    for i in range(101):
        cur = 0
        for x in X:
            cur += (i-x)**2
        ans = min(ans,cur)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n = inp()
    x = inpl()
    ans = float('inf')
    for i in range(1,101):
        cnt = 0
        for j in range(n):
            cnt += (i-x[j])**2
        ans = min(ans,cnt)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
ans = 10 ** 9 + 7
for i in range(1,101,1):
    p = 0
    for j in X :
        p += (i - j)**2
    if ans > p :
        ans = p
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
import statistics as st
m=round(st.mean(l))
print(sum((m-i)**2 for i in l))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, X: "List[int]"):

    m = INF
    for i in range(1, 101):
        tot = 0
        for j in range(N):
            tot += (X[j]-i)**2
        m = min(tot, m)
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = int(input())

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

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    X=LI()
    ans = inf
    for a in range(100+1):
        res = 0
        for x in X:
            res += (x-a)**2
        ans = min(ans, res)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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