program main
  implicit none
  integer :: n, k, res, i
  integer, allocatable :: x(:)
  read(*, *) n
  read(*, *) k
  allocate(x(n))
  read(*, *) x(:)
  res = 0
  do i = 1, n
    res = res + min(x(i), k - x(i))
  end do
  write(*, "(i0)") res * 2
end program main
