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: Wrong Answer

Solution code:
import sys

def main():
    n = int(input().replace('\n',''))
    x = input().replace('\n','').split(' ')
    x = [int(i) for i in x]
    x_sort = sorted(x)
    min = 100000000
    for i in range(x_sort[len(x_sort)-1]):
      res=0
      for j in x_sort:
        res += (j-i) ** 2
      if min > res:
        min = res
    print(min)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Wrong Answer

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
n = int(input())
x = list(map(int, input().split()))

s = 1000000000
for p in range(max(x)):
    sss = 0
    for i in range(n):
        a = (x[i]-p)**2
        sss += a
    if sss < s:
        s = sss
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    X = list(map(int,input().split()))
    min = float("inf")
    s = X[0]
    g = X[N-1]
    for p in range(s,g+1):
        s = 0
        for x in X:
            s += (x-p)**2
        if min >= s:
            min = s
    print(min)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# N人住んでいる
N = int(input())

# Xiが住んでいる場所
X = list(map(int, input().split()))
    

# 体力計算

ans = 10**9
# 開催場所は0~一番遠い人のところまで
for p in range(max(X)):
    tmp = 0
    for x in X:
        tmp += (x-p)**2
    # 最小値を更新する
    ans = min(ans, tmp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
ans = 10**10
for i in range(xmin, xmax):
    tmp = [abs(i - x[j])**2 for j in range(n)]
    if sum(tmp) < ans:
        ans = sum(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    x = list(map(int,input().split()))
    ans = [INF] * 101
    for i in range(1,101):
        p = 0
        for j in range(n):
            p += (x[j]-(i+1))**2
        ans[i] = min(ans[i],p)
    print(min(ans))
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
N = int(input())
X = list(map(int, input().split()))
mean = math.ceil(sum(X) / len(X))
print(sum([(i - mean)**2 for i in X]))

Submission status: Wrong Answer

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

ans = 100 * 100
for i in range(100):
  temp = 0
  for j in x:
    temp += pow(j - i, 2)
  if temp < ans:
    ans = temp

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

max_x = max(x_list)
min_x = min(x_list)

each_value_list = []
min_value = 10e1000
for i in range(min_x, max_x):
    tmp_sum = 0
    for x in x_list:
        tmp_sum += (x - i)**2
    if min_value > tmp_sum:
        min_value = tmp_sum

print(min_value)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
s = min(x)
e = max(x)

f_inf = float("inf")
ans = f_inf
for j in range(s, e):
    res = 0
    for i in range(n):
        res += (x[i] - j) ** 2

    ans = min(ans, res)

print(ans)

Submission status: Wrong Answer

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

ans = float("inf")

i = 0
while i < max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        ans = min(ans, cnt)

    i += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
me = int(round(np.mean(l)))
print(me)
for i in range(n):
  ans += (l[i]-me)**2
print(ans)

Submission status: Wrong Answer

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

ans = float("inf")

i = 0
while i <= max(X):
    cnt = 0
    if i not in X:
        for j in range(N):
            cnt += abs(i-X[j])**2

        ans = min(ans, cnt)

    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=list(map(int, input().split()))
min_s=100000
for i in range(min(X),max(X)):
  s = sum([(j-i)**2 for j in X])
  min_s = min(min_s, s)
print(min_s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = sorted(map(int, input().split()))
    ans = float("inf")
    for i in range(x[0],x[-1]):
        s = 0
        for j in range(n):
            s += (x[j]-i)**2
        if ans > s:
            ans = s
    print(ans)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def destance(a,b):
    return (a-b)**2

start = x_L[0]
end = x_L[-1]

ans = 10**20
for i in range(start,end+1):
    tmp = 0
    for k,val in enumerate(x_L):
        tmp += destance(x_L[k],i)
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

ans = 10 ** 9

x_min = min(x)
x_max = max(x)

for i in range(x_min, x_max):
    tmp = sum([(i-j)*(i-j) for j in x])
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = float("INF")
for i in range(1, max(x)):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
gather = sum(x) / n
if gather % 1 >= 0.5:
    gather -= gather % 1
    gather += 1
ans = 0
for i in range(n):
    ans += (x[i] - gather) ** 2
print(int(ans))

Submission status: Wrong Answer

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

max_n = 100000

for i in range(min(x), max(x)):
    sum = 0
    for j in range(len(x)):
        sum = sum + (x[j]-i)**2

    if sum <= max_n:
        max_n = sum

if len(set(x)) == 1:
    max_n = 0

print(max_n)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
from sys import stdin


def get_result(data):
    N, X = data[0][0], data[1:][0]
    X = np.array(X)
    max_X = max(X)
    tmp = np.zeros(max_X)
    for i in range(max_X):
        tmp[i] = np.sum((X - i) ** 2)
    return min(tmp)

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Wrong Answer

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

mn = 10**5
count = 0

for i in range(0,200):
    p = i
    for j in range(len(x)):
        count += (x[j] - p)**2
    if count <= mn:
        mn = count
        count = 0

print(mn)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
m = 10 ** 8
for i in range(min(x), max(x)):
    c = 0
    for j in range(n):
        c += (x[j] - i) ** 2
    if c < m:
        m = c
print(m)

Submission status: Wrong Answer

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

a=sum(x)//n+1
#print(a)
ans=0
for i in range(n):
    ans+=(x[i]-a)**2
print(ans)

Submission status: Wrong Answer

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

def destance(a,b):
    return (a-b)**2

start = x_L[0]
end = x_L[-1]

ans = 10**7
for i in range(start,end+1):
    tmp = 0
    for k,val in enumerate(x_L):
        tmp += destance(x_L[k],i)
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

s = sum(x)

ans = 0
a = round(s/n)

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

print(a)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

max=max(X)
ans = 100*5*N
for i in range(max):
    tmp=0
    for x in X:
        tmp+=(x-i)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:

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

X.sort()
temp = 10**10
a = 0
for i in range(X[0], X[N-1]+1):
    a = 0
    for j in X:
        a += (j - i) ** 2
    if a > temp:
        print(temp)
        break
    else:
        temp = a

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
import numpy as np

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

n = ni()
x = na()
m = np.mean(x)
print(int(np.ceil(np.sum(np.square(x - m)))))

Submission status: Wrong Answer

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

max_n = 100000

for i in range(min(x), max(x)):
    sum = 0
    for j in range(len(x)):
        sum = sum + (x[j]-i)**2

    if sum <= max_n:
        max_n = sum

print(max_n)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
min_X = min(X)
max_X = max(X)
ans = float("inf")
for p in range(min_X, max_X):
    tmp = 0
    for x in X:
        tmp += (x - p) ** 2
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
INF = 1001001

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 10 ** 5

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

    ans = min(ans,sum_len)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int, input().split()))
x=sum(l)//n +1
ct=0
for i in l:
  ct+=(x-i)**2
print(ct)

Submission status: Wrong Answer

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

pos = sum(lst)/n

x1 = int(pos)
x2 = int(pos)+1

if int(pos)==pos:
    x1 = pos
    x2 = -1
else:
    x1 = int(pos)
    x2 = x1 + 1

res = 0
tmp = float('inf')
for i in range(n):
    res += (lst[i] - x1)**2
if x2 != -1:
    tmp = 0
    for i in range(n):
        tmp += (lst[i] - x2)**2
print(min(res , tmp))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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: Wrong Answer

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

Submission status: Wrong Answer

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):
    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: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int,input().split()))
mint = 0
x.sort()
mid = int((x[0]+x[-1])/2)

def kyori(p):
  m = 0
  for i in range(n):
    m += (p-x[i])**2
  return m
while True:
  midplus = mid - 1
  midminus = mid + 1
  if kyori(mid) > kyori(midplus):
    mid = int((mid+midplus)/2)
  elif kyori(mid) > kyori(midminus):
    mid = int((mid+midminus)/2)
  else:
    break
print(kyori(mid))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

add = []

for p in range(99999):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print(min(add))

Submission status: Time Limit Exceeded

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

ans=10**10
for i in range(2*10**5):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
'''
n = int(input())
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [int(input()) for i in range n]
p = [list(map(int, input().split()))]

a = input()
a, b = input().split()
a = [input() for i in range n]
'''
n = int(input())
x = list(map(int, input().split()))


import math
p0 = math.floor(sum(x)/len(x))
# 123
cost = 0
for i in x:
    cost += abs(p0-i)**2

new = 10**9
while cost < new:
    p0 += 1
    new_cost = 0
    for i in x:
        new_cost += abs(p0-i)**2
    new = new_cost
print(new)

Submission status: Accepted

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

x_max = max(x)
x_min = min(x)
hp_min = 10000*100

for p in range(x_min, x_max + 1):
    hp = 0
    for x_i in x:
        hp += (x_i - p)**2
    if hp < hp_min:
        hp_min = hp
    
print(hp_min)

Submission status: Accepted

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

N = int(input())
X = list(map(int, input().split()))
X = sorted(X)
min_x = X[0]
max_x = X[N-1]

result = 10 ** 6
for x in range(min_x, max_x+1):
    s = sum([calc_tairyoku(x, i) for i in X])
    result = min(result, s)

print(result)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
assert len(X) == N
# N人が点Xiに住んでいる
# 任意の整数値の点で集会を開く
# 2乗距離の体力を消耗

# 点yで集会
def sum_power(y):
  return sum([(x - y) * (x - y) for x in X])

import sys
minimum = sys.maxsize
for y in range(min(X), max(X)+1):
  minimum = min(minimum, sum_power(y))
print(minimum)

Submission status: Accepted

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

min = 2**50

for p in range(100):
    min_i = 0
    if p in x:
        continue
    for i in x:
        min_i = min_i + (int(i) - p)**2
    if min_i <= min:
        min = min_i
print(min)

Submission status: Accepted

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

min = 2**20

for p in range(100):
    min_i = 0
    if p in x:
        continue
    for i in x:
        min_i = min_i + (int(i) - p)**2
    if min_i <= min:
        min = min_i
print(min)

Submission status: Accepted

Solution code:
import math
N = int(input())
lst = list(map(int, input().split()))
X = math.floor(sum(lst)/N + 0.5)
ans = 0
for i in lst:
    ans = ans + (X - i)**2

print(ans)

Submission status: Accepted

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

ans=n * 100**2
for p in range(101):
    ans=min(ans,sum([(xi-p)**2 for xi in x]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**8
array = list(map(int,input().split()))
for i in range(0,101):
  energy = 0
  for t in array:
    energy += ( t - i ) ** 2
  ans = min(ans,energy)
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):
    hp = 0
    for i in x:
        hp += (i-p)**2
    ans = min(ans, hp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
mi=min(x)
ma=max(x)
ans = sum(x)**2
for i in range (mi,ma+1):
  hp=0
  for j in x:
    hp+= (i-j)**2
  ans = min(hp,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
import math
import statistics
n = I()
xl = LI()

# n人が消費する体力の総和の最小値
# 数直線上にn人が住んでいる
# i番目がXi
# n人全員が参加する集会
# 任意の整数値の座標で集会を開く。座標pで集会を開くときはi番目の人は(Xi-p))**2の体力を消費する。

xl_ceil_mean = math.ceil(statistics.mean(xl))
xl_floor_mean =math.floor(statistics.mean(xl))

sigma_pow1 = sum([(x-xl_ceil_mean)**2 for x in xl])
sigma_pow2 = sum([(x-xl_floor_mean)**2 for x in xl])

if sigma_pow1 > sigma_pow2:
    print(sigma_pow2)
else:
    print(sigma_pow1)

Submission status: Accepted

Solution code:
import math
N = int(input())
Xlist = list(map(int,input().split()))

min =10**5
meandown = math.floor(sum(Xlist)/N)
meanup = math.ceil(sum(Xlist)/N)
sumdown=0
sumup = 0
for i in range(len(Xlist)):
  sumdown+= (Xlist[i]-meandown)**2
  sumup+= (Xlist[i]-meanup)**2
  
if sumdown<sumup:
  print(sumdown)
else:
  print (sumup)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for p in range(min(x), max(x)+1):
    sum = 0
    for i in x:
        sum = sum + (i-p)**2 
    hp.append(sum)
    
print(min(hp))

Submission status: Accepted

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

ans=10**1000
for p in range(X[0],X[-1]+1):
    tmp=0
    for x in X:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
x = l()
a = sum(x)//n
b = sum(x)//n + 1

for i in x:
  ans += pow(i-a,2)
  cnt += pow(i-b, 2)

print(min(ans,cnt))

Submission status: Accepted

Solution code:
a = 0
b = 0

N = int(input())
X = list(map(int, input().split()))
avg = sum(X) // N
for tai in X:
  a += (tai - avg) ** 2
for tai in X:
  b += (tai - (avg + 1)) ** 2
if a > b :
  print(b)
else :
  print(a)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
P = round(sum(X)/N)
ans = sum(list(map(lambda x: (x-P)**2, X)))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
import numpy as np
p=np.floor(np.mean(X))
ans=min(np.sum([(x-p)**2 for x in X]), np.sum([(x-(p+1))**2 for x in X]))

print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

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

h = round(sum(x) / n)

ans = 0

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

print(ans)

Submission status: Accepted

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

dp=[0 for i in range(100)]
i=1
for j in range(N):
    dp[0]+=(X[j]-0)**2

while True:
    for j in range(N):
        dp[i]+=(X[j]-i)**2
    if dp[i]>=dp[i-1]:
        break
    i+=1

ans=dp[i-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
ave = sum(x) // n
ansl = 0
ansr = 0

for i in x:
    ansl += pow(i - ave, 2)
    ansr += pow(i - ave - 1, 2)

print(min([ansl, ansr]))

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int,input().split()))
l,r,ans = min(L),max(L),10**18

for i in range(l,r+1):
  total = 0
  for l in L:
    total += (l-i)**2
  ans = min(ans, total)
print(ans)

Submission status: Accepted

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

list1.sort()
x=list1[0]
y=list1[-1]

s=0
list2=[]
while x+s<=y:
    list2.append(x+s)
    s=s+1

list3=[]
for j in list2:
    w=0
    for i in list1:
        w=w+(i-j)*(i-j)
    list3.append(w)

list3.sort()
print(list3[0])

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    N=I()
    X=LI()
    
    ans=10**10
    
    for i in range(1,101):
        temp=0
        for j in range(N):
            temp+=abs(i-X[j])**2
        ans=min(ans,temp)
        
    print(ans)
        

main()

Submission status: Accepted

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

total = 0
m = round(sum(X) / N)

for i in X:
    total += (m - i) ** 2
print(total)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
x_min = min(X)
x_max = max(X)

min_val = 10**6 + 1

for i in range(x_min, x_max + 1):
    min_val = min(min_val, sum(map(lambda x: (x-i)**2, X)))

print(min_val)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

d = [i ** 2 for i in range(101)]

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

print(min_v)

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split(' ')))
center = sum(aaa) // n
ans = 99999999999999999
for i in [-1, 0, 1]:
  ans = min(ans, sum([(a - center + i) ** 2 for a in aaa]))
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ret = 1000000
for p in range(1, 101):
    ret = min(ret, sum((x - p) ** 2 for x in x))
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
ret = float('inf')
for p in range(1, 101):
    dist = 0
    for v in a:
        dist += (v - p) ** 2
    ret = min(ret, dist)
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
avg = sum(X)//N
sums_1 = 0
sums_2 = 0
for i in X:
    sums_1 += (avg - i)**2

for j in X:
    sums_2 += (avg+1 - j)**2


print(min(sums_1,sums_2))

Submission status: Accepted

Solution code:
a = int(input())
b = input().split()
b = [int(j) for j in b]
x = round(sum(b) / a)
y = []
for i in range(a):
    y.append((x - b[i])**2)
print(sum(y))

Submission status: Accepted

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

distance = 0
min_distance = float('Inf')

for i in range(1,101):
    for j in range(N):
        distance += (int(X[j]) - i) ** 2

    min_distance = min(min_distance, distance)
    distance = 0

print(min_distance)

Submission status: Accepted

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

p = round(sum(x) / n)
print(sum([(x[i] - p)**2 for i in range(n)]))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
small = 10000000
temp = 0
p_max = max(X)

for p in range(1, p_max + 1):
  for i in range(N):
    temp += (X[i] - p)**2
    
  if temp < small:
    small = temp
  
  temp = 0
  
print(small)

Submission status: Accepted

Solution code:
n = int(input())
x = sorted(list(map(int, input().split())), reverse = True)
x_2 = list(map(lambda x:x ** 2, x))
ichi = sum(x)
jijou = sum(x_2)
re = 10 ** 100


#def ji(p, x):
#    ans = p * (p - 2 * x)
#    return ans

for p in range(1, x[0] + 1):
    second = n * (p ** 2)
    third = -2 * p * ichi
    summ = jijou + second + third

    if re > summ:
        re = summ

print(re)

#for i in range(x[i]):

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ave = sum(x) // len(x)
ans_list = []
ans_list2 = []
for i in x:
    ans = (i - ave)**2
    ans_list.append(ans)
ans1 = sum(ans_list)

ave2 = ave + 1
for i in x:
    ans = (i - ave2)**2
    ans_list2.append(ans)
ans2 = sum(ans_list2)
if ans1 < ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

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

import math

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

N = int(input())
X = list(map(int, input().split()))
ave = sum(X)/N
candP = (math.ceil(ave), math.floor(ave))
power = min(map(lambda P: power(P, X), candP))

print(power)

Submission status: Accepted

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

min_x = 100 * 100 * 100 + 1
for p in range(1, 100+1, 1):
  total = 0
  for xi in x:
    total += (xi - p) ** 2

  min_x = min([min_x, total])

print(min_x)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
MIN = 100**3

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

print(MIN)

Submission status: Accepted

Solution code:
n = int(input())

ans = 10**7+9

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

X = len(x)

for i in range(100):
    total = 0
    for j in range(X):
        total += (x[j]-i)**2
    else:
        ans = min(ans,total)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    t = sum(X)
    c1 = math.ceil(t/N)
    c2 = math.floor(t/N)
    ans1 = sum(map(lambda x: (x -c1)** 2, X))
    ans2 = sum(map(lambda x: (x -c2)** 2, X))
    print(min(ans1, ans2))

    return


# Generated by 1.1.7.1 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:
import numpy as np
N = int(input()) 
X_ls = np.array(list(map(int, input().split())))

#N=2
#X_ls =np.array( [1,4])

ans = 0
for p in range(max(X_ls)+1):
    sub = X_ls-p
    ans_1 = sum(sub**2)
    if ans_1 <= ans or ans ==0:
        ans = ans_1
print(ans)