Skip to content

Instantly share code, notes, and snippets.

@IKKO-Ohta
Created July 21, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IKKO-Ohta/da99bb00ba79f409a05218ccdef541dd to your computer and use it in GitHub Desktop.
Save IKKO-Ohta/da99bb00ba79f409a05218ccdef541dd to your computer and use it in GitHub Desktop.
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)
print(cost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment