import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10L^^18;

int N;
long X;
long[] B, L, U;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      X = readLong();
      B = new long[N];
      L = new long[N];
      U = new long[N];
      foreach (i; 0 .. N) {
        B[i] = readLong();
        L[i] = readLong();
        U[i] = readLong();
      }
      
      auto ps = new Tuple!(long, int)[N];
      foreach (i; 0 .. N) {
        ps[i] = tuple((X - B[i]) * U[i] - (0 - B[i]) * L[i], i);
      }
      ps.sort();
      auto sumL = new long[N + 1];
      foreach (j; 0 .. N) {
        const i = ps[j][1];
        sumL[j + 1] = sumL[j] + (0 - B[i]) * L[i];
      }
      auto sumU = new long[N + 1];
      foreach_reverse (j; 0 .. N) {
        const i = ps[j][1];
        sumU[j] = sumU[j + 1] + (X - B[i]) * U[i];
      }
      debug {
        writeln("ps = ", ps);
        writeln("sumL = ", sumL);
        writeln("sumU = ", sumU);
      }
      
      long lo = -1, hi = X * N;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        const q = cast(int)(mid / X);
        const r = mid % X;
        debug {
          writefln("mid = %s: q = %s, r = %s", mid, q, r);
        }
        long maxScore = -INF;
        foreach (j; 0 .. N) {
          const i = ps[j][1];
          long score;
          score += (j < N - 1 - q) ? (sumL[N - 1 - q + 1] - (0 - B[i]) * L[i]) : sumL[N - 1 - q];
          score += (j >= N - q) ? (sumU[N - q - 1] - (X - B[i]) * U[i]) : sumU[N - q];
          score += (r < B[i]) ? ((r - B[i]) * L[i]) : ((r - B[i]) * U[i]);
          debug {
            writefln("  j = %s: score = %s", j, score);
          }
          chmax(maxScore, score);
        }
        (maxScore >= 0) ? (hi = mid) : (lo = mid);
      }
      writeln(hi);
    }
  } catch (EOFException e) {
  }
}
