Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
N = int(input())
A = [int(x) for x in input().split()]
MIN,MAX = min(A),max(A)
cost = 0
for i in range(MIN,MAX+1):
c = 0
for a in A:
c += (i - a)*(i - a)
cost = min(cost,c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment