import scala.io.StdIn._



object Main extends App {

  val Array(n ,x) = readLine.trim.split(' ').map(_.toInt)
  val tests = Array.tabulate(n){_ ⇒
    val Array(b, l, u) = readLine.trim.split(' ').map(_.toLong)
    Test(b, l, u)
  }.sortBy{test ⇒
    (x - test.score) * test.upper + test.score * test.lower
  }(Ordering.Long.reverse)
  val default = tests.map{test ⇒ -test.score * test.lower}.sum
  var min = 0L
  var max = x * n.toLong
  while (min < max) {
    val mid = (max + min) / 2
    if (canWin(tests, x, mid)) {
      max = mid
    }else {
      min = mid + 1
    }
  }
  println(min)
  def canWin(tests: Array[Test], x: Int, time: Long): Boolean = {
    if (tests.length * x <= time) { return true}
    val full = (time / x).toInt
    val fullScore = (0 until full).map{i ⇒ tests(i).upper * x - tests(i).score * (tests(i).upper - tests(i).lower)}.sum
    var rest = time % x
    for ((test, i) ← tests.zipWithIndex){
      val base = if (i < full) fullScore - (tests(i).upper * x - tests(i).score * (tests(i).upper - tests(i).lower)) + (tests(full).upper * x - tests(full).score * (tests(full).upper - tests(full).lower)) else fullScore

      val add = if (rest >= test.score) test.upper * (rest - test.score) + test.lower * test.score else test.lower * rest
      if (base + add + default >= 0) return true
    }
    false
  }
  case class Test(score: Long, lower: Long, upper: Long)
}