import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val X = in.next().toLong
  val b = new Array[Int](N+1)
  val l = new Array[Int](N+1)
  val u = new Array[Int](N+1)
  for (i <- 1 to N) {
    val B, L, U = in.next().toInt
    b(i) = B; l(i) = L; u(i) = U
  }

  //
  var aoki = 0L
  for (i <- 1 to N) {
    aoki += b(i).toLong * l(i)
  }

  var hoge = new Array[(Long, Int)](N) // (score, index)
  for (i <- 1 to N) {
    hoge(i-1) = (X*u(i) - (u(i) - l(i))*b(i), i)
  }

  hoge = hoge.sorted.reverse

  var choku = 0L
  var ans = 0L
  breakable {
    for ((score, i) <- hoge) {
      val aokiPlus = (u(i) - l(i)).toLong * b(i)
      val chokuPlus = X * u(i)

      if(aoki + aokiPlus > choku + chokuPlus) {
        choku += chokuPlus
        aoki += aokiPlus
        ans += X
      }
      else {
        val cp = b(i).toLong * l(i)

        if (choku + cp >= aoki) {
          ans += ((aoki - choku) + l(i)-1) / l(i)
        }
        else {
          choku += cp
          ans += ((aoki - choku) + u(i)-1) / u(i)
        }
        break
      }
    }
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
