program main implicit none integer*8::B,N,upper,total,i integer*8::C(10) read *,B,N if(N.eq.1) then print '(a)',"0" return end if read *,C(1:N) upper = (SUM(C(1:N))+B)/N total = 0 do i=1,N total = total + ABS(C(i) - upper) end do print '(i0)', total end program main