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())
an = list(map(int, input().split()))
ans = 10*9
for i in range(min(an), max(an)+1):
    check = 0
    for a in an:
        check += (a-i)**2
    if ans >= check:
        ans = check
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = list(map(int, input().split()))
ans = 10*7
for i in range(min(an), max(an)+1):
    check = 0
    for a in an:
        check += (a-i)**2
    if ans >= check:
        ans = check
print(ans)

Submission status: Wrong Answer

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

amin=min(a)
amax=max(a)
if amin==amax:
    print(0)
    exit()
c=10000000000
r=0
for x in range(amin,amax+1):
    i=0
    for y in a:
        i+=(y-x)**2
    if c<i:
        c=i
        r=x
print(x)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

sum_A = sum(A)
ave_A = ceil(sum(A) / N)

ans = 0
for a in A:
    xsuby = a - ave_A
    ans += xsuby ** 2

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))
######################################################################################################
def main():
    n=int(input())
    A=inputintlist()
    ans=inf
    for a in [sum(A)//2,sum(A)//2+1]:
        x=0
        for b in A:
            x+=(a-b)**2
        ans=min(ans,x)
    print(ans)
main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

import math

a = cino()
l = cina()
s = sum(l)
# s = math.ceil(s/len(l))
if s>0:
    s = math.ceil(s/len(l))
else:
    s = math.floor(s/len(l))
ans = 0
for i in l:
    ans += (i-s)**2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
if min(a) == max(a):
    print(0)
    exit()

ans = max(a)*n
for i in range(min(a), max(a)+1):
    total = 0
    for j in range(n):
        total += (a[j]-i)*(a[j]-i)
    if total < ans:
        ans = total


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
if min(a) == max(a):
    print(0)
    exit()

ans = max(a)
for i in range(min(a), max(a)+1):
    total = 0
    for j in range(n):
        total += abs(a[j]-i)*abs(a[j]-i)
    if total < ans:
        ans = total

print(ans)

Submission status: Wrong Answer

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

i = 0
m = 100
M = -100

while i < n:
    if a[i]<m:
        m = a[i]
    if a[i]>M:
        M = a[i]
    i+=1

s1 = (m + M)//2
s2 = s1 + 1

i = 0
x1 = 0
x2 = 0
while i < n:
    x1 += (s1-a[i])**2
    x2 += (s2-a[i])**2
    i+=1

if x1<x2:
    ans = x1
else:
    ans = x2
print(ans)

Submission status: Wrong Answer

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

x = int(sum(li)/len(li))
if sum(li)%len(li)!=0:
    x += 1
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
ls = list(map(int, input().split()))
sqsm = 0
for i in range(n):
    sqsm += ls[i] * ls[i]
sm = sum(ls)
print(ceil(sqsm - sm * sm / n))

Submission status: Wrong Answer

Solution code:
s = list(map(lambda x: ord(x) - ord('a'), list(input())))

ans = ["-1", "-1"]
# print(s)
if len(s) == 2:
    if set(s) == 1:
        print(1, 2)
        exit()
    else:
        print(" ".join(ans))
        exit()

for i in range(len(s) - 2):
    # print(len(set(s[i:i+3])))
    if len(set(s[i:i+3])) <= 2:
        # print(s[i:i+3])
        ans = [str(i+1), str(i+3)]
        break

print(" ".join(ans))

Submission status: Wrong Answer

Solution code:
s = list(map(lambda x: ord(x) - ord('a'), list(input())))

ans = ["-1", "-1"]
# print(s)
if len(s) == 2:
    if set(s) == 1:
        print(1, 2)
    else:
        print(" ".join(ans))
        exit()

for i in range(len(s) - 2):
    # print(len(set(s[i:i+3])))
    if len(set(s[i:i+3])) <= 2:
        # print(s[i:i+3])
        ans = [str(i+1), str(i+3)]
        break

print(" ".join(ans))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = 50*101
    for i in range(-100,101):
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = 50*101
    for i in range(-100,101):
        print(i)
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = 100
    for i in range(-100,101):
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)

Submission status: Wrong Answer

Solution code:
N  =int(input())
a = list(map(int,input().split()))
ans = (10**9)
for av in range(min(a),max(a)):
    Sum = 0
    for i in range(N):
        Sum += (a[i]-av)**2
    if Sum < ans:
        ans = Sum
print(ans)

Submission status: Wrong Answer

Solution code:
N  =int(input())
a = list(map(int,input().split()))
b = list(set(a))
ans = (10**9)
for av in range(min(a),max(a)):
    Sum = 0
    for i in range(N):
        Sum += a[i]**2-2*a[i]*av+av**2
    if Sum < ans:
        ans = Sum
print(ans)

Submission status: Wrong Answer

Solution code:
import math

q = int(input())

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

avarage = sum(l)/q

bigcount = 0
for i in range(q):
    if (l[i] > avarage):
        bigcount += 1
        
if(bigcount > q/2):
    avarage = math.ceil(avarage)
else:
    avarage = math.floor(avarage)

cost = 0
for i in range(q):
    cost += (l[i]-avarage)**2

print(cost)

Submission status: Wrong Answer

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

ans = sum(a)**2
for i in range(-100,101):
    cost = 0
    for k in a:
        cost += (k-i)**2
    ans = min(cost,ans)

print(ans)

Submission status: Wrong Answer

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

sum_pow = 0
for i in a:
    sum_pow+=i**2

ans = sum_pow - (sum(a)**2)/n

print(round(ans))

Submission status: Wrong Answer

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

sum_pow = 0
for i in a:
    sum_pow+=i**2

ans = sum_pow - (sum(a)**2)//n

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i)for i in input().split()]
b=round(sum(set(a))/len(set(a)))
print(0 if len(a)==a.count(b) else sum([(i-b)**2 for i in a]))

Submission status: Wrong Answer

Solution code:
from statistics import mean 
import math
n=int(input())
arr=[int(x) for x in input().split()]
a=math.ceil(mean(arr))
s=0
for x in arr:
    s=s+((x-a)**2)
print(s)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
arr = list(map(int,input().split()))
add = sum(arr)
x = math.ceil(add/n)
ans = 0
for i in range(len(arr)):
	ans += ((x-arr[i])*(x-arr[i]))
print(ans)

Submission status: Wrong Answer

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

ans = 200 * N
for k in range(-100, 101):
    cnt = 0
    for a in A:
        cnt += pow(a - k, 2)
    ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 * 10
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    ans = 10 * 5
    for i in range(min(A), max(A)+1):
        c = sum([(a-i)**2 for a in A])
        ans = min(ans, c)
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split()

n = int(n)
a = [int(i) for i in a]

x = 0
c = []

for i in range(-100,100):
  for j in range(0,n):
    x = (a[j] - i)**2 + x
  c.append(x)
  x = 0
  
print(min(c))

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split()

n = int(n)
a = [int(i) for i in a]
m_ = []

for i in range(0,n):
  if(a[i] not in m_):
    m_.append(a[i])
  else:
    continue

m = int(sum(m_)/len(m_))

x = 0
for i in range(0,n):
  x = (a[i] - m)**2 + x
  
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

P = 0

for i in range(n):
    P += (X - a[i])**2

print(P)

Submission status: Wrong Answer

Solution code:
x=int(input())
if x>=2000:
    print(1)
else:
    if (x//100)*100<=x<=(x//100)*105:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
mincost = 1000000000000000
for i in range(-100, 100):
    cost = 0
    for j in a:
        cost += (j - i) * (j - i)
    if cost < mincost:
        mincost = cost
print(mincost)

Submission status: Wrong Answer

Solution code:
from decimal import *
n = int(input())
x = list(map(int, input().split()))
num = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_DOWN)
num = int(num)

cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

Submission status: Wrong Answer

Solution code:
from decimal import *
n = int(input())
x = list(map(int, input().split()))
num = Decimal(str(sum(x)/n)).quantize(Decimal('0'), rounding=ROUND_DOWN)
num = int(num)
print(num)
cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
x = list(map(int, input().split()))
num = math.ceil(sum(x)/n)

cost=0
for i in range(n):
    cost += (x[i]-num)*(x[i]-num)
print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 100**6
	for i in range(-100, 100):
		tmp = 0
		for j in a:
			if i == j:
				continue
			tmp += (j - i)**2
		if tmp < ans:
			ans = tmp
	print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 100**6
	for i in range(-100, 100):
		tmp = 0
		for j in a:
			tmp += (j - i)**2
		if tmp < ans:
			ans = tmp
	print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	ans = 1000000
	a = list(map(int, input().split()))
	for i in range(-100, 101):
		tmp = 0

		for j in a:
			tmp += (j-i)**2
		if tmp < ans:
			ans = tmp
	print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	y = sum(a) / n
	for x in a:
		if x == y:
			continue
		ans += (x-y)**2
	print(round(ans))

resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	rem = 0 if sum(a) % n == 0 else 1
	y = sum(a) // n + rem
	for x in a:
		if x == y:
			continue
		ans += (x-y)**2
	print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
import math
n= int(input()) 
x = list(map(int, input().split()))
y = sum(x)*1.0/n
z =math.ceil(y)

print(sum([(i-z)**2 for i in x]))

Submission status: Wrong Answer

Solution code:
def solve(s):
    sum1 = 0
    sum2 = 0
    length = 0
    for i in s.split():
        x = int(i)
        sum1 += x**2
        sum2 += x
        length += 1

    score = 10**8

    for y in range(100,-101, -1):
        tmp = sum1 - sum2*2*y + length*(y**2)
        score = min(tmp, score)

    return score

if __name__ == "__main__":
    n = int(input())
    s = input()
    solve(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  n = int(input())
  A = readInts()
  
  SPLIT = kiri(sum(A),n)
  
  ANS = 0
  #print(SPLIT)
  for i in range(n):
    ANS += abs(SPLIT-A[i])**2
  print(ANS)
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
url = "https://atcoder.jp/contests/abc043/tasks/arc059_a"

def main():

    all = int(input())
    num_li = list(map(int, input().split()))

    n = sum(num_li) // all + 1
    end = min(num_li)
    ans = 10000
    for i in range(n, end - 1, -1):
        tmp = 0
        for v in num_li:
            if v == i:
                continue
            else:
                tmp += keisan(v, i)

        if tmp < ans:
            ans = tmp
    print(ans)

def keisan(v, x):
    return (v - x) ** 2

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
url = "https://atcoder.jp/contests/abc043/tasks/arc059_a"

def main():

    all = int(input())
    num_li = list(map(int, input().split()))

    n = sum(num_li) // all + 1
    end = min(num_li)
    ans = 10000
    for i in range(n, end - 1, -1):
        tmp = 0
        for v in num_li:
            tmp += keisan(v, i)

        if tmp < ans:
            ans = tmp
    print(ans)

def keisan(v, x):
    return (v - x) ** 2

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split(' ')))
tmp = 0
max = 10**100
for i in nums:
    for j in nums:
        tmp += (j-i)**2
    if max > tmp:
        max = tmp
    tmp = 0
print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(x) for x in input().split()]
cost = 1000000000000
for i in range(0,7):
  co = 0
  for j in range(N):
    co += (i - l[j]) ** 2
  if cost > co:
    cost = co
print(cost)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=0
ss=0
for i in range(N):
	s+=A[i]
	ss+=A[i]*A[i]
print(ss-s*s//N)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
m=99999
for i in range(min(a),max(a)+1):
    k=0
    for j in a:
        k=k+(j-i)**2
    if k<m:
        m=k
print(m)

Submission status: Wrong Answer

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

num = round(sum(A) // len(A))
cost = [(a - num)**2 for a in A]

print(sum(cost))

Submission status: Wrong Answer

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

num = -(-sum(A) // len(A))
cost = [(a - num)**2 for a in A]

print(sum(cost))

Submission status: Wrong Answer

Solution code:
from math import ceil

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

y = ceil(sum(numeros)/n)
soma = 0
for v in numeros:
	soma += (v-y)**2

print(soma)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

y = ceil((max(numeros) + min(numeros))/2)
soma = 0
for v in numeros:
	soma += (v-y)**2

print(soma)

Submission status: Wrong Answer

Solution code:
sum1 = 0
tmp = 100
N = input()
lst = list(map(int, input().split()))
MAX = max(lst)
MIN = min(lst)
for i in range(MIN,MAX + 1):
    for j in lst:
        sum1 = sum1 + (i - j)**2
    if tmp >= sum1:
        tmp = sum1
    sum1 = 0
print(tmp)

Submission status: Wrong Answer

Solution code:
sum1 = 0

tmp = 100

N = input()

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

MAX = max(lst)

MIN = min(lst)


for i in range(MIN,MAX + 1):
    for j in lst:
        sum1 = sum1 + (i - j)**2
    if tmp >= sum1:
        tmp = sum1
    sum1 = 0
print(tmp)

Submission status: Wrong Answer

Solution code:
sum1 = 0

tmp = 100

N = input()

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

MAX = max(lst)

MIN = min(lst)


for i in range(MIN,MAX + 1):
    for j in lst:
        sum1 = sum1 + (i - j)**2
    if tmp >= sum1:
        tmp = sum1
    sum1 = 0
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
c = ((a[-1]-a[0])+1)//2+a[0]

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

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N = intinput()
    As = list(map(int, input().split()))

    total = (sum(As) + N - 1)//N
    min_total = 0
    for a in As:
        min_total += (a-total)*(a-total)

    # 出力
    print(min_total)



# EOF

Submission status: Wrong Answer

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

min = None
for y in range(-100, 100):
    sum = 0
    for x in a:
        sum += abs(x - y) ** 2
    if min is None or min > sum:
        min = sum

print(min)

Submission status: Wrong Answer

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

min = None
for y in range(-100, 100):
    sum = 0
    for x in a:
        sum += (x - y) ** 2
    if min is None or min > sum:
        min = sum

print(min)

Submission status: Wrong Answer

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

t = (0, 0)
for y in range(-100, 100):
    sum = 0
    for x in a:
        sum += (x - y) ** 2
    if t[0] == 0 or t[1] > sum:
        t = (y, sum)

print(t[1])

Submission status: Wrong Answer

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

t = (0, 0)
for y in range(min(a), max(a)):
    sum = 0
    for x in a:
        sum += (x - y) ** 2
    if t[0] == 0 or t[1] > sum:
        t = (y, sum)

print(t[1])

Submission status: Wrong Answer

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

y = 20000
for i in range(min(l), max(l) + 1):
    x = 0
    for j in range(n):
        x += (l[j] - i)**2
    y = min(y, x)

print(y)

Submission status: Wrong Answer

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

min = min(a)
max = max(a)

center = int((max + min) / 2)

result = 0
for num in a:
	diff = center - num
	cost = diff * diff
	result += cost

print(result)

Submission status: Wrong Answer

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

min = min(a)
max = max(a)

center = (max + min) / 2

result = 0
for num in a:
	diff = center - num
	cost = diff * diff
	result += cost

print(result)

Submission status: Wrong Answer

Solution code:
# costs = (x - y)^2
#       = x^2 -2xy + y^2
import math
from statistics import mean

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

y = math.ceil(mean(a))

s = 0
for i in range(N):
    s += (a[i] - y) ** 2

print(s)

Submission status: Wrong Answer

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

answer = 10**10
for y in range(-100, 100):
    acc = 0
    for x in a:
        acc += (x - y) * (x - y)
    answer = min(answer, acc)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(x) for x in input().split()]
s = sum(A)
ave = s / N
if s % 2 == 0:
    ave = s // N
    ans = [(x - ave)**2 for x in A]
    ans = sum(ans)
    print(ans)
    exit()
else:
    ave1, ave2 = math.ceil(s / N), math.floor(s / N)
    ans1 = [(x - ave1)**2 for x in A]
    ans2 = [(x - ave2)**2 for x in A]
    ans = min(sum(ans1), sum(ans2))
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())

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

min_score = 0
for a in range(-100, 100):
    score = 0
    for b in range(num):
        score += (a_list[b] - a)**2


    if a != -100:
        if score < min_score:
            min_score = score
    else:
        min_score = score


print(min_score)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int , input().split()))
b = list(set(a))
c = sum(b)
d = round(c / len(b))
if c / len(b) - d == 0.5 :
    d = d + 1
m = 0
for i in range (N):
    m = m +(a[i] - d)**2
if (N % 2) == 0 :
    p =(a[int((N / 2) - 1)] + a[int(N / 2)]) / 2
else:
    p = (a[int((N - 1) /2)])
q = round(p)
if p - q == 0.5 :
    p = p + 1
n = 0
for j in range (N):
    n = n +(a[j] - q)**2
if m > n:
    print(n)
else:
    print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int , input().split()))
b = list(set(a))
c = sum(b)
d = round(c / len(b))
if c / len(b) - d == 0.5 :
    d = d + 1
m = 0
for i in range (N):
    m = m +(a[i] - d)**2
p = sum(a) / N
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int , input().split()))
b = list(set(a))
c = sum(b)
d = round(c / len(b))
m = 0
for i in range (N):
    m = m +(a[i] - d)**2
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
sa = min(A)
ba = max(A)
ma1 = (ba + sa-1) // 2
ma2 = (ba + sa) // 2
ma3 = (ba + sa+1) // 2
ans1 = 0
ans2 = 0
ans3 = 0
for i in A:
    ans1 += (i-ma1)**2
    ans2 += (i-ma2)**2
    ans3 += (i-ma3)**2
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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