program ABC074B
    implicit none
    integer(8)::N,K,ans,i
    integer(8),allocatable,dimension(:)::X
    read*,N,K
    allocate(X(N))
    read*,X
    ans=0

    do i=1,N
        ans=ans+2*min(X(i),K-X(i))
    end do

    print'(i0)',ans
end program ABC074B