program main
  implicit none
  
  integer :: n,k,x(100)=0,i,s=0
  read(*,*)n
  read(*,*)k
  read(*,*)(x(i),i=1,n)
  
  do i = 1, n
    s = s + 2*min(x(i), abs(x(i) - k))
  end do
  
  write(*,*)s
end program main