program tests
  implicit none
  integer :: n, d, i
  integer(8) :: x, b(100000,4) = 0_8, s(0:100000) = 0_8, t = 0_8, ans, r
  read(*,*) n, x
  do i = 1, n
    read(*,*) b(i,1:3)
    b(i,4) = b(i,1)*b(i,2)+(x-b(i,1))*b(i,3)
  end do
  call quick_sort(b(1:n,:),4)
  do i = 1, n
    s(i) = s(i-1)+b(i,4)
    t = t+b(i,1)*b(i,2)
  end do
  d = bisearch(n,s(0:n),t)
  if (d >= 0) then
    write(*,'(i0)') x*int(d,8)
    stop
  end if
  d = not(d)
  ans = x*int(n,8)
  do i = 1, d
    r = t-(s(d)-b(i,4))
    if (r <= 0_8) then
      ans = min(ans,x*int(d-1,8))
    else if (r <= b(i,1)*b(i,2)) then
      ans = min(ans,x*int(d-1,8)+(r+b(i,2)-1_8)/b(i,2))
    else
      r = r-b(i,1)*b(i,2)
      ans = min(ans,x*int(d-1,8)+b(i,1)+(r+b(i,3)-1_8)/b(i,3))
    end if
  end do
  do i = d+1, n
    r = t-s(d-1)
    if (r <= b(i,1)*b(i,2)) then
      ans = min(ans,x*int(d-1,8)+(r+b(i,2)-1_8)/b(i,2))
    else
      r = r-b(i,1)*b(i,2)
      ans = min(ans,x*int(d-1,8)+b(i,1)+(r+b(i,3)-1_8)/b(i,3))
    end if
  end do
  write(*,'(i0)') ans
  stop
contains
  function bisearch(n,a,x) result(r)
    implicit none
    integer, intent(in) :: n
    integer(8), intent(in) :: a(0:n), x
    integer :: l, r, m
    r = not(n+1)
    if (x > a(n)) return
    r = n
    l = -1
    do while (r-l > 1)
      m = (l+r)/2
      if (x <= a(m)) then
        r = m
      else
        l = m
      end if
    end do
    if (a(r) /= x) r = not(r)
    return
  end function bisearch
  recursive subroutine quick_sort(a,i)
    implicit none
    integer(8), intent(inout) :: a(:,:)
    integer, intent(in) :: i
    integer(8) :: p, c(size(a(1,:)))
    integer :: n, l, r, m
    n = size(a(:,1))
    l = 1
    r = n
    m = (l+r)/2
    p = a(l,i)+a(m,i)+a(r,i)-max(a(l,i),a(m,i),a(r,i))-min(a(l,i),a(m,i),a(r,i))
    do
      do while (a(l,i) > p)
        l = l+1
      end do
      do while (a(r,i) < p)
        r = r-1
      end do
      if (l >= r) exit
      c = a(l,:)
      a(l,:) = a(r,:)
      a(r,:) = c
      l = l+1
      r = r-1
    end do
    if (l > 2) call quick_sort(a(1:l-1,:),i)
    if (n > r+1) call quick_sort(a(r+1:n,:),i)
    return
  end subroutine quick_sort
end program tests