#include<bits/stdc++.h>
using namespace std;
void *wmem;
void sortF_L(int N, unsigned A[], void *mem = wmem){
  int bt, i, m, *sz;
  unsigned *arr, c;
  if(N < 256){
    sort(A, A+N);
    return;
  }
  bt = sizeof(unsigned) * 8;
  arr = (unsigned*)mem;
  sz = (int*)(arr+N);
  for(m=0;m<bt;m+=8){
    for(i=0;i<257;i++){
      sz[i] = 0;
    }
    for(i=0;i<N;i++){
      sz[ 1+((A[i]>>m)&255u) ]++;
    }
    for(i=1;i<257;i++){
      sz[i] += sz[i-1];
    }
    for(i=0;i<N;i++){
      c = ((A[i]>>m)&255u);
      arr[sz[c]++] = A[i];
    }
    swap(A, arr);
  }
}
void sortF_L(int N, int A[], void *mem = wmem){
  int *arr, i, x, y, z;
  unsigned *send;
  if(N < 256){
    sort(A, A+N);
    return;
  }
  send = (unsigned*)A;
  sortF_L(N, send, mem);
  if(A[0] < 0 || A[N-1] >= 0){
    return;
  }
  x = 0;
  y = N;
  while(x < y){
    z = (x+y) / 2;
    if(A[z] < 0){
      y = z;
    }
    else{
      x = z+1;
    }
  }
  arr = (int*)mem;
  z = 0;
  for(i=x;i<N;i++){
    arr[z++] = A[i];
  }
  for(i=0;i<x;i++){
    arr[z++] = A[i];
  }
  for(i=0;i<N;i++){
    A[i] = arr[i];
  }
}
void sortF_L(int N, unsigned long long A[], void *mem = wmem){
  int bt, i, m, *sz;
  unsigned c;
  unsigned long long *arr;
  if(N < 512){
    sort(A, A+N);
    return;
  }
  bt = sizeof(unsigned long long) * 8;
  arr = (unsigned long long*)mem;
  sz = (int*)(arr+N);
  for(m=0;m<bt;m+=8){
    for(i=0;i<257;i++){
      sz[i] = 0;
    }
    for(i=0;i<N;i++){
      sz[ 1+((A[i]>>m)&255u) ]++;
    }
    for(i=1;i<257;i++){
      sz[i] += sz[i-1];
    }
    for(i=0;i<N;i++){
      c = ((A[i]>>m)&255u);
      arr[sz[c]++] = A[i];
    }
    swap(A, arr);
  }
}
void sortF_L(int N, long long A[], void *mem = wmem){
  int i, x, y, z;
  long long *arr;
  unsigned long long *send;
  if(N < 512){
    sort(A, A+N);
    return;
  }
  send = (unsigned long long*)A;
  sortF_L(N, send, mem);
  if(A[0] < 0 || A[N-1] >= 0){
    return;
  }
  x = 0;
  y = N;
  while(x < y){
    z = (x+y) / 2;
    if(A[z] < 0){
      y = z;
    }
    else{
      x = z+1;
    }
  }
  arr = (long long*)mem;
  z = 0;
  for(i=x;i<N;i++){
    arr[z++] = A[i];
  }
  for(i=0;i<x;i++){
    arr[z++] = A[i];
  }
  for(i=0;i<N;i++){
    A[i] = arr[i];
  }
}
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');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
char memarr[96000000];
int N;
long long X;
long long B[100000];
long long L[100000];
long long U[100000];
long long gain[100000];
int ind[100000];
int main(){
  int i, j, k, ok;
  long long ini, res=0, s, st, st1, st2, tmp;
  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]) << 17) + i;
  }
  sortF_L(N, gain);
  for(i=0;i<N;i++){
    ind[i] = (gain[i] & ((1<<17)-1));
    gain[i] >>= 17;
  }
  reverse(gain, gain+N);
  reverse(ind, ind+N);
  s = ini;
  for(k=0;k<N;k++){
    if(s + gain[k] >= 0){
      st1 = -s;
      st2 = -(s+gain[k]);
      break;
    }
    else{
      s += gain[k];
    }
  }
  tmp = X;
  for(j=0;j<k;j++){
    i = ind[j];
    st = st2 + gain[j];
    if(st <= B[i] * L[i]){
      chmin(tmp,divup_L(st,L[i]));
    }
    else{
      st += B[i] * (U[i] - L[i]);
      chmin(tmp,divup_L(st,U[i]));
    }
  }
  for(j=k;j<N;j++){
    i = ind[j];
    st = st1;
    if(st <= B[i] * L[i]){
      chmin(tmp,divup_L(st,L[i]));
    }
    else{
      st += B[i] * (U[i] - L[i]);
      chmin(tmp,divup_L(st,U[i]));
    }
  }
  res = X * k + tmp;
  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]; int ind[1d5];
// {
//   int i, j, k, ok;
//   ll res = 0, s, tmp, ini;
//   ll st, st1, st2;
// 
//   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]) << 17) + i;
//   sortF(N, gain);
//   rep(i,N){
//     ind[i] = (gain[i] & ((1<<17)-1));
//     gain[i] >>= 17;
//   }
//   reverse(gain, gain+N);
//   reverse(ind, ind+N);
// 
//   s = ini;
//   rep(k,N){
//     if(s + gain[k] >= 0){
//       st1 = -s;
//       st2 = -(s+gain[k]);
//       break;
//     } else {
//       s += gain[k];
//     }
//   }
// 
//   tmp = X;
//   rep(j,k){
//     i = ind[j];
//     st = st2 + gain[j];
//     if(st <= B[i] * L[i]){
//       tmp <?= st /+ L[i];
//     }else{
//       st += B[i] * (U[i] - L[i]);
//       tmp <?= st /+ U[i];
//     }
//   }
//   rep(j,k,N){
//     i = ind[j];
//     st = st1;
//     if(st <= B[i] * L[i]){
//       tmp <?= st /+ L[i];
//     }else{
//       st += B[i] * (U[i] - L[i]);
//       tmp <?= st /+ U[i];
//     }
//   }
// 
//   res = X * k + tmp;
//   wt(res);
// }


Measured memory_bytes: 6400