#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, X; cin >> n >> X;
  V<lint> b(n), l(n), u(n); for (int i = 0; i < n; ++i) cin >> b[i] >> l[i] >> u[i];
  V<> ord(n);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int i, int j) { return l[i] * b[i] + u[i] * (X - b[i]) > l[j] * b[j] + u[j] * (X - b[j]); });
  V<lint> c{0};
  for (int i : ord) c.push_back(c.back() + l[i] * b[i] + u[i] * (X - b[i]));
  lint o = 0;
  for (int i : ord) o -= l[i] * b[i];
  auto chk = [&](lint T) -> bool {
    lint q = T / X, r = T - q * X;
    lint mx = -1e18;
    for (int j = 0; j < n; ++j) {
      int i = ord[j];
      lint curr = o + l[i] * min(r, b[i]) + u[i] * max(r - b[i], 0LL);
      if (j < q) curr += c[j] + c[q + 1] - c[j + 1];
      else curr += c[q];
      mx = max(mx, curr);
    }
    return mx >= 0;
  };
  lint ng = -1, ok = n * X;
  while (ok - ng > 1) {
    lint mid = ng + ok >> 1;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}