#yuki_609 import numpy as np n=int(raw_input()) y=map(int,raw_input().split()) med=np.median(y) res=0 for i in xrange(11): res+=abs(y[i]-int(med)) print res