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()))
a.sort()
a_min = a[0]
a_max = a[-1]
s = a_min + a_max
ans = 0
if s % 2 == 0:
    mid = s//2
    for ai in a:
       ans += pow((ai-mid), 2)
else:
    ans1 = 0
    ans2 = 0
    ans3 = 0
    mid1 = s//2
    mid2 = s//2+1
    mid3 = s//2-1
    for ai in a:
        ans1 += pow((ai-mid1), 2)
        ans2 += pow((ai-mid2), 2)
        ans3 += pow((ai-mid3), 2)
    ans = min(ans1, ans2, ans3)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_min = a[0]
a_max = a[-1]
s = a_min + a_max
ans = 0
if s % 2 == 0:
    mid = s//2
    for ai in a:
       ans += pow((ai-mid), 2)
else:
    ans1 = 0
    ans2 = 0
    mid1 = s//2
    mid2 = s//2+1
    for ai in a:
        ans1 += pow((ai-mid1), 2)
        ans2 += pow((ai-mid2), 2)
    ans = min(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
res=a[0]+a[n-1]
ans=0
m=res//2
if res%2==0:
  for i in range(n):
    ans+=(a[i]-m)**2
else:
  d1=0
  d2=0
  d3=0
  for i in range(n):
    d1+=(a[i]-m)**2
    d2+=(a[i]-m-1)**2
    d3+=(a[i]-m+1)**2
  ans=min(d1,d2,d3)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
res=a[0]+a[n-1]
ans=0
m=res//2
if res%2==0:
  for i in range(n):
    ans+=(a[i]-m)**2
else:
  d1=0
  d2=0
  for i in range(n):
    d1+=(a[i]-m)**2
    d2+=(a[i]-m-1)**2
  ans=min(d1,d2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
if sum(a) % n == 0:
    avg = sum(a)//n
    ans = 0
    for e in a:
        ans += (e - avg)**2
    print(ans)
else:
    avg = sum(a)//n + 1
    avg2 = sum(a)//n - 1
    ans2 = 0
    ans = 0
    for e in a:
        ans += (e - avg) ** 2
        ans2 += (e-avg2) ** 2
    print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
if sum(a) % n == 0:
    avg = sum(a)//n
else:
    avg = sum(a)//n + 1
ans = 0
for e in a:
    ans += (e - avg)**2
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
Sum =0
for i in range(len(A)):
  Sum += (A[0]-A[i])**2
Answer = Sum
for j in range(len(A)):
  Sum =0
  for k in range(len(A)):
    Sum+= (A[k]-A[j])**2
  Answer =min(Answer, Sum)
print(Answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
an = list(map(int,input().split()))
x = round(sum(an)//N)
ans = 0
for i in an:
    ans += (x-i)*(x-i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
an = list(map(int,input().split()))
x = sum(an)//N
ans = 0
for i in an:
    ans += (x-i)*(x-i)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi
INF = float("inf")
 
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

N = i_input()
an = i_list()

min_an = min(an)
max_an = max(an)
k = (max_an + min_an)
if k % 2 ==0:
    num = k // 2
    ans = 0
    for i in range(N):
        ans += (num-an[i])**2
    
if k % 2 !=0:
    num = k // 2
    num_1 = num+1
    ans = 0
    num_num = len([1 for x in an if x==num])
    num_1_num = len([1 for x in an if x==num_1])
    if num_num >= num_1_num:
        for i in range(N):
            ans += (num-an[i])**2
    if num_num < num_1_num:
        for i in range(N):
            ans += (num_1-an[i])**2

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
a = list(map(int,input().split()))
x = ceil(sum(a)/n)
ans = 0
for ai in a:
    ans += abs(ai-x)**2
print(ans)

Submission status: Wrong Answer

Solution code:
a = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = lma()
ans = 10**9
for i in range(-max(A),max(A)+1):
    tmp=0
    for a1 in A:
        tmp+=(i-a1)**2
    ans = min(tmp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
a = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = lma()
ans = 10**9
for a in A:
    tmp=0
    for a1 in A:
        tmp+=(a-a1)**2
    ans = min(tmp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int (input ())
l = [int (x) for x in input().split()]
list.sort (l)
x = 200
s = l[0]
g = l[-1]
for i in range (s,g+1):
  y = 0
  for j in range (len(l)):
    y += (l[j]-i)**2
  if x > y:
    x = y
print (x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
m = (S + (N - 1)) // N  # 切り上げ

ans = 0
for a in A:
    ans += pow(a - m, 2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
amax=max(a)
amin=min(a)
ans=1000000000000
for i in range(amin,amax):
  t=0
  for j in range(n):
    t=t+(a[j]-i)**2
  ans=min(t,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import math
    N = int(input())
    As = [int(item) for item in input().split()]

    
    mid_num1 = math.ceil((max(As) + min(As))/2)
    res1 = 0
    for item in As:
        res1 += (item - mid_num1)**2

    mid_num2 = math.floor((max(As) + min(As))/2)
    
    res2 = 0
    for item in As:
        res2 += (item - mid_num2)**2

    print(min(res1, res2))

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]


    mid_num1 = (max(As) + min(As))//2
    res1 = 0
    for item in As:
        res1 += (item - mid_num1)**2

    mid_num2 = (max(As) + min(As))//2 + 1
    res2 = 0
    for item in As:
        res2 += (item - mid_num2)**2

    print(min(res1, res2))

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
a_li = list(map(int, input().split()))
mid = math.ceil(sum(a_li) / N)
ans = 0
for a in a_li:
    ans += (a - mid) ** 2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
if (a[0]+a[-1])%2==0:
  x=(a[0]+a[-1])//2
  ans=0
  for i in a:
    ans+=(i-x)**2
  print(ans)
else:
  x=(a[0]+a[-1])//2
  y=(a[0]+a[-1])//2+1
  ansx=0
  ansy=0
  for i in a:
    ansx+=(i-x)**2
    ansy+=(i-y)**2
  print(min(ansx,ansy))

Submission status: Wrong Answer

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

ans = 100000

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

Submission status: Wrong Answer

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

ans = 100000

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

Submission status: Wrong Answer

Solution code:
import math

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

p_avg = math.ceil(sum(ps)/len(ps))

print(sum([abs(p-p_avg)**2 for p in ps]))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc059/tasks/arc059_a

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

ave1 = (sum(nums) + 1) // n
ave2 = sum(nums) // n
t1 = 0
t2 = 0
for num in nums:
    t1 += (num - ave1) ** 2
    t2 += (num - ave2) ** 2
ans = min(t1, t2)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc059/tasks/arc059_a

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

ave = (sum(nums) + 1) // n

ans = 0
for num in nums:
    ans += (num - ave) ** 2

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a=np.array(a)
all=np.sum(a)
c=int(all/n+0.5)
ans=a-c
ans=ans**2
print(np.sum(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=200*100+1
for b in range(-100,101):
    cnt=0
    for a in A:
        cnt+=(a-b)**2
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=(list(map(int,input().split())))
ans=200*100
for b in range(-100,101):
    cnt=0
    for a in A:
        cnt+=(a-b)**2
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=(list(map(int,input().split())))
ans=200*100
for b in range(min(A),max(A)+1):
    cnt=0
    for a in A:
        cnt+=(a-b)**2
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=(list(map(int,input().split())))
ans=200*100
for b in range(min(A),max(A)+1):
    cnt=0
    for a in A:
        cnt+=(b-a)**2
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
x = sum(list(set(A)))//len(list(set(A)))
y = x+1
X,Y = 0,0
for a in A:
    X += (x-a)**2
    Y += (y-a)**2
print(min(X,Y))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
m = list(map(int, input().split()))
a = math.ceil(sum(m)/n)
f = lambda x: (x - a)**2
print(sum(map(f, m)))

Submission status: Wrong Answer

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

min_cos = 10**9
for i in range(-100, 100):
    tmp = 0
    for a in a_list:
        tmp += (a-i)**2
    min_cos = min(min_cos, tmp)
print(min_cos)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[0]
y=a[-1]
ans=10*10
for i in range(x,y+1):
    s=0
    for j in range(n):
        s+=(a[j]-i)**2
    if ans>s:
        ans=s
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = -(-sum(a)//n)
ans = [ (i - sa)**2 for i in a]
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
ans = float("inf")
for i in range(-100, 101):
    ans = min(ans, sum(map(lambda x: (x - i) * (x - i), A)))
print(ans)

Submission status: Wrong Answer

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

a.sort()
ans = 1 << 60
for x in range(min(a), max(a)) :
  res = 0
  for j in range(n) :
    res += abs(x - a[j])**2
  ans = min(ans, res)
print(ans)

Submission status: Wrong Answer

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

a.sort()
ans = 1 << 60
for x in range(a[0], a[n-1]) :
  res = 0
  for j in range(n) :
    res += abs(x - a[j])**2
  ans = min(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = list(map(int,input().split()))
s = ((sum(a))//n)+1
t = sum(a)//n
u = ((sum(a))//n)-1
l = []
l.append(s)
l.append(t)
l.append(u)
ans = []
ans2 = []
aa = set(a)

if len(aa) == 1:
    print(0)
    sys.exit()

for j in range(len(l)):
    ans = []
    for i in range(n):
        if a[i] == l[j]:
            continue
        else:
            b = (a[i]-l[j])**2
            ans.append(b)
    ans2.append(sum(ans))


print(ans2)
print(min(ans2))

Submission status: Wrong Answer

Solution code:
#3問目
import math
#平均で一回試してみる
N = int(input())
a = list(map(int, input().split()))
#平均をとる
average = math.ceil(sum(a) / N)
cost = 0
#コスト計算
for i in range(N):
    cost += (a[i] - average) ** 2
print(cost)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter(A)
k_sum = 0
for k in c.keys():
    k_sum += k
ave = k_sum//len(c)

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

ave += 1
tmp_ans = 0
for a in A:
    tmp_ans += (a-ave)**2

print(min(ans, tmp_ans))

Submission status: Wrong Answer

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

num = ceil(sum(A)/N)

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
count = 0
if (max(ar) - min(ar)) % 2 == 0:
    b = min(ar) + ((max(ar) - min(ar)) // 2)
    for r in ar:
        count += (r - b) ** 2
else:
    b = min(ar) + ((max(ar) - min(ar)) // 2)
    c = min(ar) + ((max(ar) - min(ar)) // 2 + 1)
    bc = 0
    cc = 0
    for r in ar:
        bc += (r - b) ** 2
    for r in ar:
        cc += (r - c) ** 2
    count = min(bc,cc)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A_sum = np.inf
if N == 1:
    print(0)
else:
    for x in range(A[0], A[-1]+1):
        A_sum_new = sum([(a - x)**2 for a in A])
        if A_sum_new <= A_sum:
            A_sum = A_sum_new

    print(A_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A_sum = np.inf
for x in range(A[0], A[-1]+1):
    A_sum_new = sum([(a - x)**2 for a in A])
    if A_sum_new <= A_sum:
        A_sum = A_sum_new

print(A_sum)

Submission status: Wrong Answer

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

A_sum = sum([a**2 for a in A])
for x in range(A[0], A[-1]+1):
    A_sum_new = sum([(a - x)**2 for a in A])
    if A_sum_new <= A_sum:
        A_sum = A_sum_new

print(A_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
answers = set()
ans = 0
for i in range(-100,100):
    for j in a_list:
        ans += (i-j)**2
    answers.add(ans)
    ans = 0


print(min(answers))

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = sum(a)
    if ave >= 0:
        ave += n - 10 ** (-6)
        ave //= n
    elif ave < 0:
        ave = -ave
        ave += n - 10 ** (-6)
        ave //= n
        ave = -ave

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

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = sum(a)
    if ave >= 0:
        ave += n - 10 ** (-10)
        ave //= n
    elif ave < 0:
        ave = -ave
        ave += n - 10 ** (-10)
        ave //= n
        ave = -ave

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

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = sum(a)
    if ave > 0:
        ave += n - 10 ** (-10)
        ave //= n
    elif ave < 0:
        ave = -ave
        ave += n - 10 ** (-10)
        ave //= n
        ave = -ave

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

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = sum(a)
    if ave > 0:
        ave += n + 10 ** (-10)
    elif ave < 0:
        ave -= n - 10 ** (-10)

    ave //= n

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

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = (sum(a)+n-10**(-10))//n

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

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import factorial,sqrt,ceil#,gcd
import numpy as np

N = int(input())
lisA = list(map(int,input().split()))
arrA = np.array(lisA)

mean = np.mean(arrA)

targetnum = round(mean)

arrans = (arrA - targetnum)**2
ans = sum(arrans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
MIN = 10**5
for i in range(-100,101):
    SUM = 0
    for a in A:
        SUM += ((a-i)**2)
    MIN = min(SUM,MIN)

print(MIN)

Submission status: Wrong Answer

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

MIN = 10*5
for i in range(-100,101):
    SUM = 0
    for a in A:
        SUM += (a-i) **2
    MIN = min(SUM,MIN)

print(MIN)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

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

reg = 10**12
ans = 0
for i in range(min(A), max(A)+1):
    tmp = 0
    for a in A:
        tmp += (a-i)**2
    reg = min(reg, tmp)
    if reg==tmp:
        ans = i
print(i)

Submission status: Wrong Answer

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


def calc(A, i):
    res = 0
    for a in A:
        res += (a - i) ** 2
    return res

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

    ans = 10 ** 5
    for i in range(-100 ,101):
        ans = min(ans, calc(A, i))
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

mincost = 10*10
for i in range(-100, 101):
    cost = 0
    for b in A:
        cost += (i-b)*(i-b)
    if cost < mincost:
        mincost = cost

print(mincost)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
y = sum(a) // n
if sum(a) % n != 0:
    y += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

X=(max(A)+min(A))//2
Y=(max(A)+min(A))//2+1
ans1=0
ans2=0
for a in A:
  ans1+=(X-a)**2
  ans2+=(Y-a)**2
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
A = list(map(int,input().split()))
ans = float('inf')

mean = int(sum(A)/N)

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

if ans == float('inf'):
    ans = 0
print(ans)

Submission status: Wrong Answer

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

min = min(a)
max = max(a)
dis = 0
temp = 0

for i in range(n):
    dis += (a[i]-min)**2
print(dis)

for i in range(min+1,max+1):
    for j in range(n):
        print(i,j)
        temp += (a[j]-i)**2
        print("AAAAA")
        print(temp)
        print("AAAAA")

        if dis >= temp:
            dis = temp
        print("#####")
        print(dis)
    temp = 0

print(dis)

Submission status: Wrong Answer

Solution code:
import sys

rl = sys.stdin.readline


def solve():
    N = int(rl())
    a = list(map(int, rl().split()))
    
    sum_a = sum(a)
    t = sum_a // N if sum_a % N == 0 else sum_a // N + 1
    ans = sum((ai - t) ** 2 for ai in a)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
"""
1 2 3 4 5
1 1 1 1 9   4 4 4 4 36=53 | 1 1 1 1 49
"""
import math
n = int(input())
a = list(map(int, input().split()))

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

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

print(ans)

Submission status: Wrong Answer

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

print(min(b))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mi, ma = min(a), max(a)
ans = 10**9
for _ in range(n):
    for s in range(mi, ma):
        l = []
        for ai in a:
            l.append((s-ai)**2)
        ans = min(ans, sum(l))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_s = list(map(int, input().split()))
mn = 10**4
for i in range(-100, 101):
  t = []
  for a in a_s:
    t.append((a-i)**2)
  if sum(t) < mn:
    mn = sum(t)
print(mn)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  a = list(input_list())
  ans = 10**9
  a1 = a[0]
  if all([v == a1 for v in a]):
    print(0)
    exit()
  for i in range(1, 101):
    ta = 0
    for ai in a:
      ta += (ai-i)*(ai-i)
    ans = min(ans, ta)
  print(ans)
  
def input_list():
  return map(int, input().split())

import math
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
age = (sum(a)+1)//len(a)
L = [(i-age)**2 for i in a]
answer = sum(L)
print(answer)

Submission status: Wrong Answer

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

for i in range(a[0], a[N-1]+1):
    ans = 0
    for j in range(N):
        ans += (a[j]-i)**2
    if(sum_a > ans):
        sum_a = ans
print(sum_a)

Submission status: Wrong Answer

Solution code:
import math

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

average = int(math.ceil(sum(A) / len(A)))
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)


n = int(input())

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

if n == 1:
	print(0)
	exit()


minans = 100000
chk = 100000

for i in range(min(l),max(l)+1):
	test = 0
	#print(i)
	for j in range(len(l)):
		#print(i,(l[j]-i)**2)
		test = test + (l[j]-i)**2
		#print(test)

	if test < minans:
		#print(minans)
		#print(test)
		minans = test
		chk = i

#print(chk)
print(minans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

minans = 100000

for i in range(min(l),max(l)+1):
	test = 0
	#print(i)
	for j in range(len(l)):
		test = test + (l[j]-i)**2

	if test < minans:
		minans = test

print(minans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

minans = 100000

for i in range(min(l),max(l)+1):
	test = 0
	print(i)
	for j in range(len(l)):
		test = test + (l[j]-i)**2
	
	if test < minans:
		minans = test

print(minans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
 
ans = float('inf')
for i in range(-101,100):
  num = 0
  for j in l:
    num += (i-j)**2
  ans = min(ans,num)
  
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
 
ans = float('inf')
for i in range(101):
  num = 0
  for j in l:
    num += (i-j)**2
  ans = min(ans,num)
  
print(ans)

Submission status: Wrong Answer

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

ans = float('inf')
for i in range(100):
  num = 0
  for j in l:
    num += (i-j)**2
  ans = min(ans,num)
  
print(ans)

Submission status: Wrong Answer

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

ans = float('inf')
total = 0
for i in l:
    for j in range(100):
        total += (i - j)**2
        ans = min(ans,total)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math   
n = int(input())
l = sorted([int(i) for i in input().split()])

ans = 0
total = 0
for i in l:
    for j in range(100):
        total += (i - j)**2
        ans = min(ans,total)
    
print(ans)

Submission status: Wrong Answer

Solution code:
    
import math   
n = int(input())
l = sorted([int(i) for i in input().split()])

num = math.ceil(sum(l)/len(l))

ans = 0
for i in l:
    ans += (i - num)**2
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math   
n = int(input())
l = sorted([int(i) for i in input().split()])

num = math.ceil((l[0] + l[n-1])/2)

ans = 0
for i in l:
    ans += (i - num)**2
    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
for m in range(1, 101):
    tmp = 0
    for i in range(N):
        tmp += (A[i] - m)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
for m in A:
    tmp = 0
    for i in range(N):
        tmp += (A[i] - m)**2
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
ans = 0
m = ceil(sum(A)/len(A))
for i in range(N):
    ans += (A[i] - m)**2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
answer = 10000
#全探索
for i in range(-100, 101):
    tmp = sum((A-i) ** 2)
    if answer > tmp:
        answer = tmp
print(answer)

Submission status: Wrong Answer

Solution code:
def main(n, a):
    base = (max(a) + min(a)) / 2
    ans = 0

    for n in a:
        ans += (n - base)**2

    print(round(ans))


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

    main(n, a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mn = min(a)
mx = max(a)+1
ans = 0
for i in range(mn, mx):
  cost = 0
  for aa in a:
    cost += (i - aa)**2
  if ans > cost:
    ans = cost
print(ans)

Submission status: Wrong Answer

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

x = sum(A)/len(A)
ans = 0
for i in A:
    ans += (i - x)**2
print(-(-ans//1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
l,r=max(A),min(A)
key=[]
cnt=0
if (l-r)%2!=0:
    key +=[(l+r)//2]
    key +=[(l+r+1)//2]
else:
    key +=[(l+r)//2]

for i in key:
    if i in A:
        for j in A:
            if j!=i:
                cnt +=(j-i)**2
        print(cnt)
        exit()

for j in A:
    cnt +=(j-key[0])**2
print(cnt)

Submission status: Wrong Answer

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

t = int(mean(a))
ans = 100*len(a)**2
for i in range(min(a), max(a)+1):
    sum = 0
    for j in a:
        sum += (i-j)**2
    ans = min(ans, sum)

print(ans)