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

Solution code:
n = int(input())
A = list(map(int, input().split()))
sa = min(A)
ba = max(A)
ma = (ba + sa) // 2
ans = 0
for i in A:
    ans += (i-ma)**2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
mini = 40000*100
for n in range(-100,100):
    cost = 0
    for item in A:
        cost += (item-n)**2
    if cost < mini:
        mini = cost
print(mini)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
b = list(range(a[0], a[-1] + 1))
l = len(b)
if l == 0:
    print(0)
else:
    m1 = b[l // 2]
    m2 = b[l // 2 - 1]
    c1, c2 = 0, 0
    for i in range(n):
        c1 += (a[i] - m1) ** 2
        c2 += (a[i] - m2) ** 2
    print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
b = list(range(a[0], a[-1] + 1))
l = len(b)
if l == 0:
    print(0)
else:
    m1 = b[l // 2]
    m2 = b[l // 1 - 1]
    c1, c2 = 0, 0
    for i in range(n):
        c1 += (a[i] - m1) ** 2
        c2 += (a[i] - m2) ** 2
    print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
b = list(range(a[0], a[-1]))
l = len(b)
if l == 0:
    print(0)
else:
    m1 = b[l // 2]
    m2 = b[l // 1 - 1]
    c1, c2 = 0, 0
    for i in range(n):
        c1 += (a[i] - m1) ** 2
        c2 += (a[i] - m2) ** 2
    print(min(c1, c2))

Submission status: Wrong Answer

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

for i in range(min(a),max(a)+1):
    total = 0
    for b in a:
        total += (b-i)**2
    if total <= ans:
        ans = total
print (ans)

Submission status: Wrong Answer

Solution code:
# C
import math
n = int(input())
a = list(map(int, input().split()))
ave = math.ceil(sum(a)/n)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split() ))
absa=[]
za=[]
for i in range(n):
    za.append(a[i]-(i+1))
#print(za)
#print(sum(za))
za.sort()
if n%2==1:
    b=za[n//2]
else:
    b=(za[n//2-1]+za[n//2])//2

#print(b)
for i in range(n):
    absa.append(abs(a[i]-(b+(i+1))))
#print(absa)
print(sum(absa))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
lst = [int(x) for x in input().split()]
a = math.ceil(sum(lst) / N)

ret = sum([math.pow(a - x, 2) for x in lst])
print(int(ret))

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = input().split()
costs = []
if nums.count(nums[0]) != len(nums):
    for i in range(1, 101):
        sum = 0
        for num in nums:
            sum += (int(num) - i) ** 2
        costs.append(sum)
    ans = min(costs)
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = input().split()
costs = []
if nums.count(nums[0]) != len(nums):
    for i in range(1, 10):
        sum = 0
        for num in nums:
            sum += (int(num) - i) ** 2
        costs.append(sum)
    ans = min(costs)
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
for i in range(1,len(s),1):
	if s[i]==s[i-1]:
		print(str(i)+" "+str(i+1))
		exit()
	try:
		if s[i-1]==s[i+1]:
			print(str(i)+" "+str(i+2))
			exit()
	except:
		pass
print(str(-1)+" "+str(-1))

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n)
#print(ave)
count=0
for i in range(n):
	count+=(a[i]-ave)**2
print(count)
print(round(-1.6))

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n)
#print(ave)
count=0
for i in range(n):
	val=abs(ave)-abs(a[i])
	count+=val**2
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ave = math.ceil(sum(a)/n)
m = int(np.median(a))

ans = [0, 0]
for _a in a:
    ans[0] += (ave-_a)**2
    ans[1] += (m-_a)**2

print(min(ans))

Submission status: Wrong Answer

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

ave = math.ceil(sum(a)/n)

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

print(ans)

Submission status: Wrong Answer

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+1):
    cost = 0
    for j in a:
        cost = cost + (i-j)**2
    ans = min(ans, cost)
print(cost)

Submission status: Wrong Answer

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

ans = float('INF')
for i in range(-100, 100):
    sum = 0
    for n in range(N):
        sum += (a[n] - i) ** 2

    ans = min(ans, sum)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
sum = 0
for i in range(N):
    sum+=a[i]
d = sum//N
m = sum%N
if m != 0:
    d+=1
ans = 0
for i in range(N):
    de = a[i] - d
    ans += de**2
ansa = 0
for i in range(N):
    dea = a[i] - d - 1
    ansa += dea**2
ans = min(ans,ansa)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
sum = 0
for i in range(N):
    sum+=a[i]
d = sum//N
m = sum%N
if m != 0:
    d+=1
ans = 0
for i in range(N):
    de = a[i] - d
    ans += de**2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m = ((sum(a)/n)*2 + 1) //2
# m = statistics.mean(a)
# m = int(m) + 1 if m % 1 > 0.5 else int(m)
r = 0
for i in a:
  r += (i - m)**2
  
print(r)

Submission status: Wrong Answer

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

m = statistics.mean(a)
m = int(m) + 1 if m % 1 >= 0.5 else int(m)
r = 0
for i in a:
  r += (i - m)**2
  
print(r)

Submission status: Wrong Answer

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

m = statistics.mean(a)
m = int(m) + 1 if m % 1 > 0.5 else int(m)
r = 0
for i in a:
  r += (i - m)**2
  
print(r)

Submission status: Wrong Answer

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

def fullsearch(a):
    for i in range(-100, 101):
        yield reduce(lambda total, x: (x - i) ** 2 + total, a, 0)

def main():
    input()
    print(min(fullsearch(int(c) for c in input().split())))

main()

Submission status: Wrong Answer

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

def fullsearch(a):
    for i in range(1, 101):
        yield reduce(lambda total, x: (x - i) ** 2 + total, a, 0)

def main():
    input()
    A = [int(c) for c in input().split()]

    print(min(fullsearch(A)))

main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    mean_ceil = math.ceil(sum(A) / N)
    ans = reduce(lambda total, x: (x - mean_ceil) ** 2 + total, A, 0)

    print(ans)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    mi = -(-sum(A) // N)

    ans = 0
    for i in A:
        ans += (i - mi) ** 2

    print(ans)


    
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
avg = sum(L)/len(L)
import math
avg_u = math.ceil(avg)
avg_d = math.floor(avg)
ans_u = []
ans_d = []
for i in L:
  ans_u.append(i - avg_u)
  ans_d.append(i - avg_d)

ans = 0
if sum(ans_u) <= sum(ans_d):
  for i in ans_u:
    ans += i ** 2
else:
  for i in ans_d:
    ans += i ** 2
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
avg = sum(L)/len(L)
import math
avg_u = math.ceil(avg)
#avg_d = math.floor(avg)
ans_u = 0
ans_d = 0
for i in L:
  ans_u += (i - avg_u)**2

print(ans_u)

Submission status: Wrong Answer

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

sD = sum(dList)/n
ig = int(sD)
po = sD-int(sD)

ad = 0
if po >= 0.5:
  ad = ig + 1
elif po != 0:
  ad = ig -1
else:
  ad = ig

result = 0
for i in range(len(dList)):
  result += (dList[i]-ad)**2

print(result)

Submission status: Wrong Answer

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


min_cost = -1
for i in range(-100, 100):
  cost = 0
  for k in range(N):
    cost += (i - a[k])**2
  if min_cost == -1:
    min_cost = cost
  else:
    min_cost = min(min_cost, cost)

print(min_cost)

Submission status: Wrong Answer

Solution code:
#043c
N = int(input()) #N <= 100
a_list = list(map(int, input().split())) #-100 <= ai <= 100

#ループ数は200*100 = 20000.総当たりでOK
min_cost = 200*1000

for y in range(min(a_list),max(a_list) + 1):
    cost = 0
    
    for x in a_list:
        cost += (x - y)**2
    
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Wrong Answer

Solution code:
#043c
N = int(input()) #N <= 100
a_list = list(map(int, input().split())) #-100 <= ai <= 100

#ループ数は200*100 = 20000.総当たりでOK
min_cost = 200*100

for y in range(min(a_list),max(a_list) + 1):
    cost = 0
    
    for x in a_list:
        cost += (x - y)**2
    
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
print(round(sum(a)/n))

Submission status: Wrong Answer

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

a_ave=a[0]+a[-1]
if a_ave%2==0:
    num=a_ave//2
else:
    num=a_ave//2+1
ans=0
for i in range(n):
    ans+=(num-a[i])**2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
num=(a[0]+a[-1])//2
ans=0
for i in range(n):
    ans+=(num-a[i])**2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
A=list(map(int,input().split()))
ans = []
AV=math.ceil(sum(A)/N)
for i in A:
    ans.append((i-AV)**2)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
a = intl()
if n == 1:print(0)
else:
    s = max(a)+min(a)
    k1 = s//2
    k2 = s//2 + s%2
    k3 = s//2 -1
    c1 = 0
    c2 = 0
    c3 = 0
    for i in range(n):
        c3 += (a[i]-k3)**2
        c2 += (a[i]-k2)**2
        c1 += (a[i]-k1)**2
    print(min(c1,c2,c3))

Submission status: Wrong Answer

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
a = intl()
if n == 1:print(0)
else:
    s = max(a)+min(a)
    k1 = s//2
    k2 = s//2 + s%2
    k3 = s//2 -1
    c1 = 0
    c2 = 0
    c3 = 0
    for i in range(n):
        c3 += (a[i]-k3)**2
        c2 += (a[i]-k2)**2
        c1 += (a[i]-k1)**2
    print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
a = intl()
if n == 1:print(0)
else:
    s = max(a)+min(a)
    k1 = s//2
    k2 = s//2 + s%2
    c1 = 0
    c2 = 0
    for i in range(n):
        c2 += (a[i]-k2)**2
        c1 += (a[i]-k1)**2
    print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
def custom_round(number, ndigits=0):
    if type(number) == int:#整数ならそのまま返す
        return number
    d_point = len(str(number).split('.')[1])#小数点以下が何桁あるか定義
    if ndigits >= d_point:#求める小数点以下の値が引数より大きい場合はそのまま返す
        return number
    c = (10 ** d_point) * 2
    #小数点以下の桁数分元の数に0を足して整数にして2倍するための値(0.01ならcは200)
    return round((number * c + 1) / c, ndigits)
    #元の数に0を足して整数にして2倍して1を足して2で割る。元の数が0.01なら0.015にしてroundを行う
ave=custom_round(sum(a)/n)
ans=0
for i in a:
    ans+=(ave-i)**2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
mylist = list(map(int, input().split()))
s = sum(mylist)
N = len(mylist)
mean = math.ceil(s/N)
ans=0
for i in range(N):
    ans=ans+(mylist[i]-mean)*(mylist[i]-mean)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
*a, = map(int, input().split())
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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
x=10**9+7
if max(l)==min(l):
    print(0)
else:
        
    for i in range(1,max(l)+1):
        te=0
        
        for j in l:
            te=te+(abs(j-i))**2
        #print(i,te)
        x=min(x,te)
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000000000000
for u in range(min(a), max(a)+1):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000
for u in range(min(a), max(a)+1):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import statistics

n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    print(0)

min_ans = 100000000
for u in range(min(a), max(a)):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import statistics

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

min_ans = 100000000
for u in range(min(a), max(a)):
    ans = 0
    for i in a:
        ans += (u - i)**2
    if ans <= min_ans:
        min_ans = ans

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import statistics

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

ans = 0

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import statistics

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
# 割り切れる
if sum(A)%len(A) == 0:
  avrA = sum(A)/len(A)
# 割り切れない
else:
  if (sum(A) / len(A)) < (sum(A) // len(A) + 0.5):
    avrA = sum(A) // len(A)
  else:
    avrA = sum(A) // len(A) +1
dst = 0
for i in A:
  dst += (i-avrA)**2
print(dst)

Submission status: Wrong Answer

Solution code:
# ABC043 C

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

def cost(l,N):
    total = 0
    for i in l:
        total += (i-N)**2
    return total
    
ans = 100000


for i in range(-100,101):
    check = cost(a,i)
    if check < ans:
        ans = check

print(ans)

Submission status: Wrong Answer

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

mid = (max(a) + min(a))//2
ans1 = 0
ans2 = 0
ans3 = 0

for i in a:
  ans1 += pow(abs(i - mid),2)
  ans2 += pow(abs(i - (mid+1)),2)
  ans3 += pow(abs(i - (mid-1)),2)
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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

mid = (max(a) + min(a))//2
ans1 = 0
ans2 = 0

for i in a:
  ans1 += pow(abs(i - mid),2)
  ans2 += pow(abs(i - (mid+1)),2)
print(min(ans1, ans2))

Submission status: Wrong Answer

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

n = round(sum(a)//N)

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

print(int(ans))

Submission status: Wrong Answer

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

n = sum(a)//N
if sum(a)%N != 0: n = n//1 + 1

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

print(int(ans))

Submission status: Wrong Answer

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(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

cost = 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(cost)

Submission status: Wrong Answer

Solution code:
import sys

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

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

# 全部そろってたら終了
if a.count(a[0]) == len(a):
    sys.exit()

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

print(cost)

Submission status: Wrong Answer

Solution code:
import sys

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

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

# 全部そろってたら終了
if a.count(a[0]) == len(a):
    sys.exit()

cost = []
# いくつに書き換えるか
#for i in range(a[0],a[len(a)-1]):
for i in range(1, 101):
    _cost=0
    for j in range(len(a)):    
        # 書き換える or 書き換えない
        _cost += (a[j]-i)**2
    cost.append(_cost)

print(min(cost))

Submission status: Wrong Answer

Solution code:
import sys

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

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

# 全部そろってたら終了
if a.count(a[0]) == len(a):
    sys.exit()

cost = []
# いくつに書き換えるか
for i in range(a[0],a[len(a)-1]):
    _cost=0
    for j in range(len(a)):    
        # 書き換える or 書き換えない
        _cost += (a[j]-i)**2
    cost.append(_cost)

print(min(cost))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

ave = math.ceil(sum(li)/n)
point = 0

for i in li:
    point += (ave-i)**2

print(point)

Submission status: Wrong Answer

Solution code:
import math

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

avg = math.ceil(sum(nums) / len(nums))

cost = 0

for x in nums:
    if x == avg:
        continue
    cost += (x - avg)**2

print(cost)

Submission status: Wrong Answer

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

ans = sum([abs(i) for i in a])

for i in range(-100, 100+1):
    s = sum([(j-i)**2 for j in a])
    if ans > s:
        ans = s

print(ans)

Submission status: Wrong Answer

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

max_a = max(a)
min_a = min(a)

sum_a = max(a) * len(a)
ans = 0

for i in range(min_a, max_a):
    s = sum([(j-i)**2 for j in a])
    if sum_a > s:
        sum_a = s
        ans = i

print(ans)

Submission status: Wrong Answer

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

for i in range(-100,100):
    for t in range(N):
        s += (a[t] - i)*(a[t] - i)
    if  s < cost:
        cost = s
    s =int(0)

print(cost)

Submission status: Wrong Answer

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

for i in range(-100,100):
    for t in range(N):
        s += (a[t] - i)*(a[t] - i)
    if  s < cost:
        cost = s
    s =int(0)

print(cost)

Submission status: Wrong Answer

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

s = 200**2 * 10
for x in range(min(A), max(A)+1):
    s = min(s, sum((x-a)**2 for a in A))
print(s)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
oppai = np.array(a)

max = np.max(oppai)
min = np.min(oppai)
x = (max+min)//2
sum = [0] * 3

for i in range(x-1,x+2,1):
    oppai = np.array(a) #oppaiの初期化
    oppai -= i
    oppai = oppai**2
    sum[i-x+1] = np.sum(oppai)
    #print('sum[{}]'.format(i-x+1),sum[i-x+1])

chinko = np.array(sum)
#print(np.argmin(chinko)+x-1)
print(np.min(chinko))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
oppai = np.array(a)

max = np.max(oppai)
min = np.min(oppai)
x = (max+min)//2
sum = [0] * 3

for i in range(x-1,x+2,1):
    oppai = np.array(a) #oppaiの初期化
    oppai -= i
    oppai = oppai**2
    sum[i-x+1] = np.sum(oppai)
    print('sum[{}]'.format(i-x+1),sum[i-x+1])

chinko = np.array(sum)
#print(np.argmin(chinko)+x-1)
print(np.min(chinko))

Submission status: Wrong Answer

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

ave = math.ceil(sum(a) / n)
ans = 0
for i in a:
	ans += (i - ave)**2
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    ans = float('inf')

    for i in range(-100,100):
        ans_tmp = 0
        for a in A:
            ans_tmp += (a-i)**2

        if ans_tmp < ans:
            ans = ans_tmp

    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    avg1 = (sum(A)+1)//N
    avg2 = (sum(A))//N
    ans1 = 0
    ans2 = 0

    for a in A:
        ans1 += (a - avg1)**2

    for a in A:
        ans2 += (a - avg2)**2

    print(min(ans1, ans2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    avg = (sum(A)+1)//N
    ans = 0

    for a in A:
        ans += (a - avg)**2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A =[int(x) for x in input().split()]
result=float('inf')
for i in range(max(A)):
  s=0
  for j in range(N):
    s += (i-A[j])**2
  result=min(result,s)
print(result)

Submission status: Wrong Answer

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

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

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

b = sum(a_list) // n
ans1 = sum([(a-b)^2 for a in a_list])

b += 1
ans2 = sum([(a-b)^2 for a in a_list])

print(min(ans1,ans2))

Submission status: Wrong Answer

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

b = sum(a_list)//n

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

Solution code:
def main():
    N, *an = map(int, open(0).read().split())
    print(min(sum((ai - (max(an) + min(an)) // 2) ** 2 for ai in an),
              sum((ai + (-(max(an) + min(an)) // 2)) ** 2 for ai in an)))
    return


main()

Submission status: Wrong Answer

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

def solve(N: int, a: "List[int]"):
    a_num = np.array(a)
    min_value = np.min(a_num)
    max_value = np.max(a_num)

    answer = 10**7
    for i in range(min_value,max_value+1):
        goal = np.full(N,i)
        dif = a_num-goal
        nijo = dif**2
        answer = min(answer,np.sum(nijo))

    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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
size = int(input())
ans = 0
li = list(map(int,input().split()))
avg = math.ceil((min(li)+max(li))/2)
for i in li:
    ans += abs((avg-i)**2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ints = [int(num) for num in set(input().split())]
res = []
for x in range(min(ints), max(ints)+1):
    total = 0
    for num in ints:
        total += (x - num)**2
    
    res.append(total)

ans = min(res)
print(ans)

Submission status: Wrong Answer

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 = sum_a/len(a_array)
    ans = 0
    for a in a_array:
        ans += abs(sum_a-a)**2
    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)))

Submission status: Wrong Answer

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 = sum_a/len(a_array)
    ans = 0
    for a in a_array:
        ans += abs(sum_a-a)**2
    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(sum_a1, sum_a2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = input()
numbers = list(map(int, input().split()))

unique_numbers = list(set(numbers))
if len(unique_numbers) == 1:
  print(0)
  exit(0)

s = sum(numbers)
t = math.floor(s/2)

r = 0
for num in numbers:
  r += abs((num - t) ** 2)
  
print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = input()
numbers = list(map(int, input().split()))

unique_numbers = list(set(numbers))
if len(unique_numbers) == 1:
  print(0)
  exit(0)

s = sum(numbers)
t = math.floor(s/2)

r = 0
for num in numbers:
  r += abs((num - t) * 2)
  
print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = input()
numbers = list(map(int, input().split()))

s = sum(numbers)
t = math.floor(s/2)

r = 0
for num in numbers:
  r += abs((num - t) * 2)
  
print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = input()
numbers = list(map(int, input().split()))
print(numbers)

s = sum(numbers)
t = math.floor(s/2)

r = 0
for num in numbers:
  r += abs((num - t) * 2)
  
print(r)

Submission status: Wrong Answer

Solution code:
mini=10**29 
n=int(input())
l=[int(i) for i in input().split()]
i=sum(l)//n 
for z in range(1):
    sm=0  
    for j in l:
        sm+=(i-j)*(i-j)
    mini=min(mini,sm)
print(mini)