data class Test(val b: Long, val l: Long, val u: Long)

fun divCeil(x: Long, y: Long): Long = (x + y - 1) / y

fun main(args: Array<String>) {
  val (nRaw, x) = readLine()!!.split(" ").map { it.toLong() }
  val n = nRaw.toInt()
  val tests = Array(n, {
    val (b, l, u) = readLine()!!.split(" ").map { it.toLong() }
    Test(b, l, u)
  })
  var currentDiff = tests.map { -it.l * it.b }.sum()
  fun maxGain(test: Test): Long = test.l * test.b + test.u * (x - test.b)
  fun requiredScore(test: Test, score: Long): Long {
    if (score > maxGain(test)) throw RuntimeException()
    if (score <= test.l * test.b) {
      return divCeil(score, test.l)
    } else {
      return test.b + divCeil(score - test.l * test.b, test.u)
    }
  }
  tests.sortByDescending { maxGain(it) }

  var ans = 0L
  for (i in 0 until n) {
    if (currentDiff + maxGain(tests[i]) <= 0) {
      ans += x
      currentDiff += maxGain(tests[i])
    } else {
      val min1 = (i until n).filter { currentDiff + maxGain(tests[it]) >= 0 }
          .map { requiredScore(tests[it], -currentDiff) }
          .min()!!
      var min2 = (0 until i)
          .map {
            val tmpDiff = currentDiff + maxGain(tests[i]) - maxGain(tests[it])
            requiredScore(tests[it], -tmpDiff)
          }
          .min()
      ans += Math.min(min1, min2 ?: x)
      break
    }
  }

  // if (currentScore < 0) throw RuntimeException()

  println(ans)
}