program main
	implicit none
    integer n,k,i
    integer,allocatable::x(:)
    integer::ans=0
    read *,n
    read *,k
    allocate(x(n))
    read *,x(:)
    do i=1,n
    	ans=ans+min(x(i),abs(x(i)-k))
    end do
    print '(i0)',ans*2
end program main