#include<bits/stdc++.h>
using namespace std;

int main() {
  long long N,X;
  cin >> N >> X;
  vector<long long> b(N),l(N),u(N);
  vector<pair<long long,long long>> ga(N);
  long long ans = 0;
  long long req = 0;
  for (int i=0; i<N; i++) {
    cin >> b[i] >> l[i] >> u[i];
    req += b[i] * l[i];
    ga[i].first = b[i] * l[i] + (X - b[i]) * u[i];
    ga[i].second = i;
  }
  sort(ga.begin(),ga.end());
  reverse(ga.begin(),ga.end());
  int now = 0;
  while (ga[now].first <= req) {
    ans += X;
    req -= ga[now].first;
    now++;
    if (now == N) {
      break;
    }
  }
  if (req == 0) {
    cout << ans << endl;
    return 0;
  }
  long long term = X;
  int nu;
  for (int i=0; i<N; i++) {
    if (ga[i].first > ga[now].first) {
      nu = ga[i].second;
      req += ga[i].first;
      req -= ga[now].first;
      if (b[nu] * l[nu] >= req) {
        term = min(term,(req - 1) / l[nu] + 1);
      }
      else {
        term = min(term,b[nu] + (req - b[nu] * l[nu] - 1) / u[nu] + 1);
      }
      
      req -= ga[i].first;
      req += ga[now].first;
      continue;
    }
    if (ga[i].first <= req) {
      break;
    }
    nu = ga[i].second;
    if (b[nu] * l[nu] >= req) {
      term = min(term,(req - 1) / l[nu] + 1);
    }
    else {
      term = min(term,b[nu] + (req - b[nu] * l[nu] - 1) / u[nu] + 1);
    }
  }
  
  cout << ans + term << endl;
}