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) = fastReadLongs(2)
  val n = nRaw.toInt()
  val tests = Array(n, {
    val (b, l, u) = fastReadLongs(3)
    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 {
      var min = x
      for (k in i until n) {
        if (currentDiff + maxGain(tests[k]) >= 0) {
          min = Math.min(min, requiredScore(tests[k], -currentDiff))
        }
      }
      for (k in 0 until i) {
        val tmpDiff = currentDiff + maxGain(tests[i]) - maxGain(tests[k])
        min = Math.min(min, requiredScore(tests[k], -tmpDiff))
      }
      ans += min
      break
    }
  }

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

  println(ans)
}

// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^63.
// NOTE: This function does not handle error cases.
// Verified: ARC096D
fun fastReadLongs(n: Int): LongArray {
  val xs = LongArray(n)
  val s = readLine()!!
  var currentValue = 0L
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
  return xs
}