Problem:


Score : 200 points

Problem Statement

Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.

He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).

Find the minimum total cost to achieve his objective.

Constraints

1≦N≦100

-100≦a_i≦100

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum total cost to achieve Evi's objective.

Sample Input 1

2
4 8

Sample Output 1

8

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

Sample Input 2

3
1 1 3

Sample Output 2

3

Transforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.

Sample Input 3

3
4 2 5

Sample Output 3

5

Leaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.

Sample Input 4

4
-100 -100 -100 -100

Sample Output 4

0

Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.



Sample input:
2
4 8


Sample output:
8

Submission status: Runtime Error

Solution code:
N = input()
a = list(map(int,input().split()))
b,c= 0,0
s =[]
a.sort()
for i in range(0,N):
  b += a[i]
for i in range(0,N):
  c += a[i]**2
for i in range(a[0]a[N]):
  s.append = 3*(i**2)-2*b+c
m = min(s)
print(m)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = [int(a) for a in input().split(" ")]
ave = sum(A) / N
can1 = math.floor(ave)
can2 = math.ceil(ave)

cost1 = sum([(a - can1) ** 2 for a in A])
cost2 = sum([(a - can2) ** 2 for a in A])
print(min[cost1, cost2])

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N

for k in range(N):
    ans = (list[j] - A) ** 2

for i in range(-100,100):
    sum = 0
    sum_new = 0
    for j in range(N):
        sum = sum + (list[j] - A) ** 2
        sum_new = sum_new + (list[j] - i) ** 2
    if(sum > sum_new):
        ans = sum_new

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a)/N)
sums = []
for i in range(1, avg+1):
    s = 0
    for j in range(N):
        s += (i-a[j])**2
    sums.append(s)
print(min(sums))

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N

for k in rang(N):
    ans = (list[j] - A) ** 2

for i in range(-100:100):
    for j in range(N):
        sum = 0
        sum_new = 0
        sum = sum + (list[j] - A) ** 2
        sum_new = sum_new + (list[j] - i) ** 2
    if(sum > sum_new):
        ans = sum_new

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    s = 0
    for j in range(N):
        s += (a[j]-i)**2
    sums.append(s)
print(min(sums))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    s = 0
    for j in range(N):
        s += (a[j]-avg)**2
    sums[i] = s
print(min(sums))

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N

for i in range(-100:100):
    for j in range(N):
        sum = 0
        sum_new = 0
        sum = sum + (list[j] - A) ** 2
        sum_new = sum_new + (list[j] - i) ** 2
        if(sum > sum_new):
            sum = sum_new
print(sum)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = list(map(int, input().split()))
avg = round(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    s = 0
    for j in range(N):
        s += (a[j]-avg)**2
    sums.append(s)
print(min(sums))

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N
sum = 0
sum_new = 0

for i in range(-100:100):
    for j in range(N):
        sum = sum + (list[j] - A) ** 2
        sum_new = sum_new + (list[j] - i) ** 2
        if(sum > sum_new):
            sum = sum_new
print(sum)

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N
sum = 0
sum_new = 0

for i in range(-100:100):
    for j in range(N):
        sum = sum + (list[j] - A) ** 2
        sum_new = (list[j] - i) ** 2
        if(sum > sum_new):
            sum = sum_new
print(sum)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = list(map(int, input().split()))
avg = math.floor(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    sum = 0
    for j in range(N):
        sum += (a[j]-avg)**2
    sums.append(sum)
print(min(sums))

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N



for i in range(-100:100):
    for j in range(N):    
        sum = (list[j] - A) ** 2
        sum_new = (list[j] - i) ** 2
    if(sum > sum_new):
        sum = sum_new
print(sum)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = list(map(int, input().split()))
avg = math.floor(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    sum = 0;
    for j in range(N):
        sum += (a[j]-avg)**2
    sums.append(sum)
print(min(sums))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = list(map(int, input().split()))2
avg = math.floor(sum(a)/len(a))
sums = []
for i in range(1, avg+1):
    sum = 0;
    for j in range(N):
        sum += (a[j]-avg)**2
    sums.append(sum)
print(min(sums))

Submission status: Runtime Error

Solution code:

N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N

for i in range(-100:100):
    sum = (list[i] - A) ** 2
    sum_new = (list[i] - i) ** 2
    if(sum > sum_new):
        sum = sum_new
print(sum)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = map(int, input().split())
avg = math.floor(sum(a)/len(a))
pattern = []
for i in range(1, avg+1):
    pattern[i] = []
    for j in range(N):
        pattern[i].append((a[j]-avg)**2)
    pattern[i] = sum(pattern[i])
print(min(pattern))

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int,input().split()))
l_ans = [[] for _ in range(200)]

for i in range(-100,101):
    sum = 0

    for j in range(N):
        sum = sum + (i-l[j])**2

    l_ans[i+100] = sum

print(l_ans)
print(min(l_ans))

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int,input().split()))
l_ans = []

for i in range(1,101):
    sum = 0

    for j in range(N):
        sum = sum + (i-l[j])**2

    l_ans[i] = sum

print(min(l))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)):
        cost = 0
        for j in a:
            if i != j:
                cost += (i-j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int, input()))

cost = 10000*3
ans = 10000*3
for i in range(-100,100+1):
    cost = sum([(j - i)**2 for j in an])
    ans = min(ans, cost)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int, input()))

cost = 10000
ans = 10000
for i in range(-100,100+1):
    cost = sum([(j - i)**2 for j in an])
    ans = min(ans, cost)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int, input()))

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int, input()))

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

print(ans)

Submission status: Runtime Error

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

ans = INF
for i in range(-100, 101):
    val = 0
    for a in A:
        val += (a - i) ** 2
    ans = min(ans, val)
print(ans)

Submission status: Runtime Error

Solution code:
#入力
N = int(input())
lst = input().split()

#整数値化
for i in range(len(lst)):
   lst[i] = int(lst[i])

#ソート
lst.sort()

#コスト計算関数
def get_cost(x, y):
   return (x - y) ** 2

costs = []

#コスト計算
for i in range(lst[0], lst[-1]): #入力値の最小値から最大値まで
   cost = 0
   for j in lst:
      cost = cost + get_cost(j, i)
   costs.append(cost)

#ソート
costs.sort()

#最小コストを出力
print(costs[0])

Submission status: Runtime Error

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = int(input())
d = 0

for i in b:
    d += (int(i) - int(c)) ** 2
print(d)

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int,input().split()))
ave  = round((sum(an)/N),0)
ans = 0

for i in an:
    ans += (i-ave)**2

print(inst(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int,input().split()))
ave  = round((sum(an)/N),0)
print(ave)
ans = 0

for i in an:
    ans += (i-ave)**2

print(inst(ans))

Submission status: Runtime Error

Solution code:
garbage = input()
num = list(map(int, input().split()))
cost = []
for i in range(0,100):
  plus_val = (num[0]-i)**2+(num[1]-i)**2+(num[2]-i)**2
  minus_val = (num[0]+i)**2+(num[1]+i)**2+(num[2]+i)**2
  cost.append(plus_val)
  cost.append(minus_val)
  
min_val = min(cost)
print(min_val)

Submission status: Runtime Error

Solution code:
garbage = input()
num = list(map(int, input().split()))
cost = []
for i in range(0,100):
  plus_val = (num[0]-i)**2+(num[1]-i)**2+(num[2]-i)**2
  minus_val = (num[0]-i)**2+(num[1]-i)**2+(num[2]-i)**2
  cost.append(plus_val)
  cost.append(minus_val)
  
min_val = min(cost)
print(min_val)

Submission status: Runtime Error

Solution code:
garbage = input()
num = list(map(int, input().split()))
d = []
for n in num:
  d.append((n-num[0])**2)
if(sum(d)==0):
  print(0)
else:
  max_num = max(num)
  min_num = min(num)
  cost = []
  for i in range(min_num,max(num)):
    cost.append((num[0]-i)**2+(num[1]-i)**2+(num[2]-i)**2)

  min_val = min(cost)
  print(min_val)

Submission status: Runtime Error

Solution code:
garbage = input()
num = list(map(int, input().split()))
d = []
for n in num:
  d.append(n-num[0])
if(sum(d)==0):
  print(0)
else:
  max_num = max(num)
  min_num = min(num)
  cost = []
  for i in range(min_num,max(num)):
    cost.append((num[0]-i)**2+(num[1]-i)**2+(num[2]-i)**2)

  min_val = min(cost)
  print(min_val)

Submission status: Runtime Error

Solution code:
import statistics as st
import math
int(input())
s = list(map(int, input().split()))
md = math.floor(st.mean(s))
mu = avedown + 1
sd = 0
su = 0
for i in range(0, len(s)):
    sd = sd + (s[i] - md) ** 2
    su = su + (s[i] - mu) ** 2
print(min(sd, su))

Submission status: Runtime Error

Solution code:
n=int(input())
a=input()
b=[]
for i in range(n):
  b.append(int(a[i*2]))
ave=sum(b)/n
if ave<int(ave)+0.5:
  ave=int(ave)
else:
  ave=int(ave)+1
ans=0
for i in range(n):
  ans+=(b[i]-ave)**2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=input()
b=[]
for i in range(n):
  b.append(a[i*2])
ave=sum(b)/n
if ave<int(ave)+0.5:
  ave=int(ave)
else:
  ave=int(ave)+1
ans=0
for i in range(n):
  ans+=(b[i]-ave)**2
print(ans)

Submission status: Runtime Error

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

R = []

for i in range(min(A), max(A)):
    cost = 0
    for j in range(len(A)):
        cost += (i - A[j])**2
    R.append(cost)

print(min(R))

Submission status: Runtime Error

Solution code:
import math

def resolve():
	_ = int(input())
	a = list(map(int, input().split()))
	ans = math.inf
	for i in range(-100, 101):
		s = 0
		for j in a:
			s += (i-j)**2
		if ans > s:
			ans = s
	print(ans)
resolve()

Submission status: Runtime Error

Solution code:
import statistics

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

me = statistics.median(a)

ans = 0
for i in range(n):
    ans += (abs(me, a[i]))**2

print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
work = math.round(sum(a)/n, 0) 
result = 0
for el in a:
    result += (work-el)**2
print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split().strip()))
ans =10**9
for ai in range(min(a),max(a)):
    w = 0
    for aj in a:
        w += (ai-aj)**2
    ans = min(w,ans)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split().strip()))
ans =10**9
for ai in range(min(a),max(a)):
    w = 0
    for aj in ai:
        w += (ai-aj)**2
    ans = min(w,ans)
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  nums = list(map(int, input()))
  cmin = 0
  for x in nums:
	cmin += (x - min(nums)) ** 2
  for i in range(min(nums), max(nums)+1):
	c = getcost(i, nums)
    if c < cmin:
      cmin = c
  print(cmin)
  
def getcost(x, nums):
  c = 0
  for n in nums:
    c += (n - x) ** 2
  return c
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
a = list(map(int,input().split()))
h = Decimal(str(sum(a)/n).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
a = list(map(lambda x:(x-h)**2,a))
print(sum(a))

Submission status: Runtime Error

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

mn = min(l)
mx = max(l)

ms = 10**9
ll = [0]*n
for j in range(mn, mx+1):
  	for i in range(n):
      ll[i] = (l[i] - j)**2
    s = sum(ll)
    ms = min(ms, s)
    
print(ms)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int S(vector<int> a,int N,int M){
  int S=0;
  for(int i=0;i<N;i++){
    S+=(a.at(i)-M)*(a.at(i)-M);
  }
  return S;
}

int main(){
  int N,V;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  V=S(a,N,-100);
  for(int i=0;i<201;i++){
    if(S(a,N,-100+i)<V) V=S(a,N,-100+i);
  }
  
  cout << V << endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(e) for e in input().split()]
ans = float("inf")
MIN, MAX = min(a), max(a)
for i in range(MIN, MAX):
    cost = 0
    for j in a:
        cost = cost + (i-j)**2
    ans = min(ans, cost)
print(cost)

Submission status: Runtime Error

Solution code:
n = int(input())
s = map(int, input().split())
def solution(s):
    cost = 0
    mean = round(sum(s)/len(s))
    for i in s:
        cost += abs(i-mean) ** 2
        #print(f"DEBUG >> {mean} {i} {cost}")
    return cost
  
print(solution(s))

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=np.array([int(x) for x in input().split()])
x=[]
for i in range(np.max(a)):
	s=np.sum((a-i)*(a-i))
	x.append(s)
print(min(x))

Submission status: Runtime Error

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

a_ave=a[0]+a[-1]
num1=a_ave//2
num2=a_ave//2+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(num1-a[i])**2
    ans2+=(num2-a[i])**2
print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
*a, = map(int, input())
atai = math.ceil(sum(a) / n)
ans = 0
for x in a:
  if x == atai:
    pass
  else:
    ans += (x - atai) ** 2
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input()))
s = round(sum(a)/n)
ans = 0
for i in a:
  ans += (i-s)**2
print(ans)

Submission status: Runtime Error

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
X=many_int()

sort_X=sorted(X)
min_X = sort_X[0]
max_X = sort_X[1]

min_num = 0
min_sum = 99999999999
for i in range(min_X, max_X+1):
    temp_sum = 0
    for j in X:
        temp_sum += (j-i)**2
    
    if temp_sum < min_sum:
        min_sum = temp_sum
        min_num = i

print(min_num)

Submission status: Runtime Error

Solution code:
import sys

# N個の整数
N = int(input())

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

ans = 10**18
# いくつに書き換えるか
for i in range(min(a),max(a)):
    tmp=0
    for j in range(N):    
        # 書き換える or 書き換えない
        tmp += (a[j]-i)**2
    ans=min(cost,tmp)

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

avg_ceil = math.ceil(sum(nums) / len(nums))
avg_floor = math.floor(sum(nums) / len(nums))

cost_ceil = 0
cost_floor = 0

for x in nums:
    if x == avg_ceil:
        continue
    cost_ceil += (x - avg_ceil)**2

for x in nums:
    if x == avg_floor:
        continue
    cost_floor += (x - avg_floor)**2

if cost_ceil <= cost_floor:
    print(cost_ceil)
else
    print(cost_floor)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
a = [int(i) for i in input().split()]
b = math.round(sum(a)/N)

c = sum([(i - b)**2 for i in a])
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=sum(A)//n
print(max(sum(map(lambda x:(x-m)**2,A)),sum(map(lambda x:(x-m-1)**2,A)))

Submission status: Runtime Error

Solution code:
N = int(input())
L = [int(input()) for i in range(N)]

r = 200*100

for i in range(-100,101):
  res = 0
  for j in range(N):
    res += (L[j] - i) ** 2
  r = min(r, res)
print(r)

Submission status: Runtime Error

Solution code:
def examC():
    N = I()
    a = LI()
    lower = min(a)
    L = (max(a)-min(a))
    cur = [0]*L
    for i in range(L):
        for j in range(N):
            cur[i] +=(a[j]-(i+lower))**2
    ans = min(cur)
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Runtime Error

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

b = sum(a_list)//n

def temp(a):
  return (a-b)^2
def temp2(a):
  return (a-b-1)^2

ans1 = sum(list(map(temp, a)))
ans2 = sum(list(map(temp2, a)))
#ans1 = sum([(a-b)^2 for a in a_list])
#ans2 = sum([(a-b-1)^2 for a in a_list])

print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
from statistics import mean

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

target = round(mean(a))
cost = 0
for num in a:
    cost += (num - target)**2

print(cost)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(map(int,input().split())
s = 0
t = 0
for i in range(N):
    s += a[i]
    t += (a[i])**2
a = math.floor(s/N)
if (s/N) - a > 0.5:
    a += 1
ans = N*a**2 - 2*s*a + t
print(ans)

Submission status: Runtime Error

Solution code:
l_si = input().split(" ")
l_si_i = [int(s) for s in l_si]

sm = sum(l_si_i)
av = round(sm /dv)
ret = 0

for it in l_si_i:
  ret = ret + (it -av) **2


print(ret)

Submission status: Runtime Error

Solution code:
n = int(input())
a_array = [int(x) for x in input().split()]
sum_a = sum(a_array)
if sum_a % 2 == 0:
    sum_a = int(sum_a/len(a_array))
    ans = 0
    for a in a_array:
        ans += abs(sum_a-a)**2
    print(sum_a)
    print(int(ans))
else:
    sum_a1 = int(sum_a/len(a_array))
    sum_a2 = int(sum_a/len(a_array))+1
    ans1 = 0
    ans2 = 0
    for a in a_array:
        ans1 += abs(sum_a1-a)**2
        ans2 += abs(sum_a2-a)**2
    print(int(min(ans1, ans2)))

n = int(input())
a_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(-100, 101):
    tmp = 0
    for a in a_array:
        tmp += abs(a-i)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import math

from functools import lru_cache


# from decimal import Decimal, ROUND_HALF_UP
# def quantize(f):
#     return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


@lru_cache(maxsize=4096)
def get_cost(x, y):
    if x == y:
        return 0
    else:
        return int(math.pow((x - y), 2))


def get_costs(target, numbers):
    return sum([get_cost(target, n) for n in numbers])


def check(n, numbers):
    n_max = max(numbers)
    n_min = min(numbers)
    costs = []
    for target in range(n_min, n_max + 1):
        costs.append(get_costs(target=target, numbers=numbers))

    return min(costs)


def main():
    N = int(input())
    numbers = map(int, input().split())
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

# from functools import lru_cache


# from decimal import Decimal, ROUND_HALF_UP
# def quantize(f):
#     return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


# @lru_cache(maxsize=4096)
def get_cost(x, y):
    return int(math.pow(x - y, 2))


def get_costs(target, numbers):
    return sum([get_cost(target, n) for n in numbers])


def check(n, numbers):
    n_max = max(numbers)
    n_min = min(numbers)
    costs = []
    for target in range(n_min, n_max + 1):
        costs.append(get_costs(target=target, numbers=numbers))

    return min(costs)


def main():
    N = int(input())
    numbers = map(int, input().split())
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

from functools import lru_cache


# from decimal import Decimal, ROUND_HALF_UP
# def quantize(f):
#     return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


@lru_cache(maxsize=4096)
def get_cost(x, y):
    return int(math.pow(x - y, 2))


def get_costs(target, numbers):
    return sum([get_cost(target, n) for n in numbers])


def check(n, numbers):
    n_max = max(numbers)
    n_min = min(numbers)
    costs = []
    for target in range(n_min, n_max + 1):
        costs.append(get_costs(target=target, numbers=numbers))

    return min(costs)


def main():
    N = int(input())
    numbers = map(int, input().split())
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

from decimal import Decimal, ROUND_HALF_UP
from functools import lru_cache


def quantize(f):
    return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


@lru_cache(maxsize=4096)
def get_cost(x, y):
    return int(math.pow(x - y, 2))


def get_costs(target, numbers):
    return sum([get_cost(target, n) for n in numbers])


def check(n, numbers):
    n_max = max(numbers)
    n_min = min(numbers)
    costs = []
    for n in range(n_min, n_max + 1):
        costs.append(get_costs(target=n, numbers=numbers))

    return min(costs)


def main():
    N = int(input())
    numbers = map(int, input().split())
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from scipy.optimize import*;n,a=open(0)
print(round(minimize(lambda x:sum((x-int(b))**2 for b in a.split()),0)["fun"]))

Submission status: Runtime Error

Solution code:
import sympy as sym
N = int(input())
l = list(map(int, input().split()))
expr = 0
x = sym.symbols("x")
for i in range(N):
    expr = expr + (l[i] - x)**2
eq = sym.Eq(sym.Derivative(expr).doit())
a = sym.solve(eq, x)
# print(a)
a = a[0]
a = round(a)
# print(a)
a = expr.subs(x, a)
print(a)

Submission status: Runtime Error

Solution code:
def cul(li,s):
  for i in li:
    a += (i - s)^2
  return a

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

s1 = sum(li)//len(li)
s2 = s1 + 1

ans1 = cul(li,s1)
ans2 = cul(li,s2)

print(min(ans1,ans2))

Submission status: Runtime Error

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

ans = 10**10

m1 = a[ceil(n/2)]
m2 = int(sum(a) / n)
m3 = ceil(sum(a) / n)

for v in [m1, m2, m3]:
    cost = 0
    for i in range(n):
        cost += (a[i] - v) ** 2
    ans = min(cost, ans)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
print(min([sum([(x-item)**2 for x in [int(x) for x in input().split()]]) for item in list(range(-100,101))]))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[]
for x in range(-100,101):
    c=0
    for i in range(n):
        c+=(a[i]-x)**2
    l.append(c)

print(min(c))

Submission status: Runtime Error

Solution code:
input()
a = [*map(int, input().split())]
ans = 10 ** 18
for val in range(-200, 200):
  curr = 0
  for it in a:
    curr += (it - val) ** 2
  ans = min(ans, curr)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
ttl1, ttl2, ttl3 = 0, 0, 0
avarage1 = -(-sum(A) // N)
avarage2 = sum(A) // N
for i in A:
    ttl1 += (i - avarage1) ** 2
    ttl2 += (i - avarage2) ** 2
    ttl3 += (i - avarage3) ** 2
print(min(ttl1, ttl2, ttl3))

Submission status: Runtime Error

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

floor = math.floor(sum(a) / len(a))
ceil = math.ceil(sum(a) / len(a))

ceil_sum = sum([(item - ceil) ** 2 for item in a])
floor_sum = sum([(item - floor) ** 2 for item in a])

print(min(ceil_sum, floor_sum, median_sum))

Submission status: Runtime Error

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

floor = math.floor(sum(a) / len(a))
ceil = math.ceil(sum(a) / len(a))

ceil_sum = sum([(item - ceil) ** 2 for item in a])
floor_sum = sum([(item - floor) ** 2 for item in a])

print(min(ceil_sum, floor_sum, median_sum))

Submission status: Runtime Error

Solution code:
S = input()


found = False
pprev, prev = S[0],S[1]
t = {pprev, prev}

for i in range(2,len(S)):
    t.add(S[i])
    if len(t) == 2:
        print(i - 1, i + 1)
        found = True
    else:
        t.remove(pprev)
    pprev = prev
    prev = S[i]
    t = {pprev, prev}
    if found:
        break
    
if not found:
    print(-1, -1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = []
for i in range(-100,101):
    c = 0
    for a in A:
        c += (i-a)**2
    ans.append(c)

print(min(min))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = []
for i in range(-100,101):
    c = 0
    for a in A:
        c += (i-a)**2
    ans.append(c)

print(min(c))

Submission status: Runtime Error

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

b = mean(a)//1

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,inptu().split()))
ave = sum(L) / len(L)
if ave * 10 % 10 >= 5:
  ave = int(ave) + 1
else:
  ave = int(ave)
ans = 0
for x in L:
  ans += (x - ave) **2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

c = 0
t = int(sum(a)//n)
for i in range(0,N):
  if a[i]!=t:
    c=abs(t-a[i])

print(c)

Submission status: Runtime Error

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

ans = 9999

for i in range(-100, 101):
    sumof = 0
    for j in a:
        sumof += (i - j)*(i - j)
    ans = min(ans, sumof)
    
print(ans)

Submission status: Runtime Error

Solution code:
range_ = range(-100, 100+1)

n = int(input())

sb = { index:None for index in range_ }

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

def delfun(arg):
  xs, delta = arg
  deltas = sum( [ (x-delta)**2 for x in xs] )
  return deltas

from concurrent.futures import ProcessPoolExecutor as PPE

res = PPE(max_workers=12).map(delfun, [(xs, delta) for delta in range_])
print(min(list(res)))

Submission status: Runtime Error

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

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    else:
        li_ans.appned(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))

Submission status: Runtime Error

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

li_ans = []
ans = 0

for num in (min(a), max(a)):
    for j in range(len(a)):
        ans += abs(a[j] - num) ** 2
    else:
        li_ans.appned(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))

Submission status: Runtime Error

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

li_ans = []
ans = 0

for num in (min(a), max(a)):
    for j in range(len(a)):
        ans += abs(a[j] - num) ** 2
    else:
        li_ans.appned(ans)
        ans = 0

print(min(li_ans))

Submission status: Runtime Error

Solution code:
N = int(input())

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

ans = []
sum = 0

for j in range(min(a), max(a)):
    for num in a:
        sum += (num - j) ** 2
    else:
        ans.append(sum)
        sum = 0

if ans == None:
    ans.appned(0)

print(min(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

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

ans = []
sum = 0

for j in range(min(a), max(a)):
    for num in a:
        sum += (num - j) ** 2
    else:
        ans.append(sum)
        sum = 0

print(min(ans))