#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2, class T3, class T4> void sortA_L(int N, T1 a[], T2 b[], T3 c[], T4 d[], void *mem = wmem){
  int i;
  pair<pair<T1, T2>, pair<T3, T4> > *arr=(pair<pair<T1, T2>, pair<T3, T4> > *) mem;
  for(i=0;i<N;i++){
    arr[i].first.first = a[i];
    arr[i].first.second = b[i];
    arr[i].second.first = c[i];
    arr[i].second.second = d[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first.first;
    b[i] = arr[i].first.second;
    c[i] = arr[i].second.first;
    d[i] = arr[i].second.second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
char memarr[96000000];
int N;
long long X;
long long B[100000];
long long L[100000];
long long U[100000];
long long gain[100000];
long long sum[100001];
int main(){
  int cnt, i, ok, rem;
  long long KL2GvlyY, Q5VJL1cS, e98WHCEY, ini, res, score;
  wmem = memarr;
  rd(N);
  rd(X);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(B[Lj4PdHRW]);
      rd(L[Lj4PdHRW]);
      rd(U[Lj4PdHRW]);
    }
  }
  ini = 0;
  for(i=0;i<N;i++){
    ini -= B[i] * L[i];
  }
  for(i=0;i<N;i++){
    gain[i] = (X - B[i]) * U[i] + B[i] * L[i];
  }
  for(i=0;i<N;i++){
    gain[i] = -gain[i];
  }
  sortA_L(N, gain, B, L, U);
  for(i=0;i<N;i++){
    gain[i] = -gain[i];
  }
  for(i=0;i<N;i++){
    sum[i+1] = sum[i] + gain[i];
  }
  KL2GvlyY = 0;
  Q5VJL1cS = N*X;
  while(KL2GvlyY < Q5VJL1cS){
    if((KL2GvlyY + Q5VJL1cS)%2==0){
      e98WHCEY = (KL2GvlyY + Q5VJL1cS) / 2;
    }
    else{
      e98WHCEY = (KL2GvlyY + Q5VJL1cS - 1) / 2;
    }
    ok = 0;
    cnt = e98WHCEY / X;
    rem = e98WHCEY % X;
    if(rem==0){
      score = ini + sum[cnt];
      if(score >= 0){
        ok = 1;
      }
    }
    else{
      for(i=0;i<N;i++){
        score = ini;
        if(i < cnt){
          score += sum[cnt+1] - gain[i];
        }
        else{
          score += sum[cnt];
        }
        if(rem < B[i]){
          score += (rem - B[i]) * L[i] + B[i] * L[i];
        }
        else{
          score += (rem - B[i]) * U[i] + B[i] * L[i];
        }
        if(score >= 0){
          ok = 1;
          break;
        }
      }
    }
    if(ok){
      Q5VJL1cS = e98WHCEY;
    }
    else{
      KL2GvlyY = e98WHCEY + 1;
    }
  }
  res =Q5VJL1cS;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190601-1

// --- original code ---
// int N; ll X;
// ll B[1d5], L[1d5], U[1d5];
// 
// ll gain[1d5], sum[100001];
// {
//   int i, ok;
//   ll res, score, ini;
//   int cnt, rem;
// 
//   rd(N, X, (B,L,U)(N));
// 
//   ini = 0;
//   rep(i,N) ini -= B[i] * L[i];
// 
//   rep(i,N) gain[i] = (X - B[i]) * U[i] + B[i] * L[i];
// 
//   rep(i,N) gain[i] = -gain[i];
//   sortA(N, gain, B, L, U);
//   rep(i,N) gain[i] = -gain[i];
//   rep(i,N) sum[i+1] = sum[i] + gain[i];
//   
//   res = bsearch_min[ll,res,0,N*X][
//     ok = 0;
//     cnt = res / X;
//     rem = res % X;
// 
//     if(rem==0){
//       score = ini + sum[cnt];
//       if(score >= 0) ok = 1;
//     } else {
//       rep(i,N){
//         score = ini;
//         if(i < cnt) score += sum[cnt+1] - gain[i];
//         else        score += sum[cnt];
// 
//         if(rem < B[i]) score += (rem - B[i]) * L[i] + B[i] * L[i];
//         else           score += (rem - B[i]) * U[i] + B[i] * L[i];
// 
//         if(score >= 0){ ok = 1; break; }
//       }
//     }
//   ](ok);
// 
//   wt(res);
// }


Measured memory_bytes: 8448