#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<18)
ll p[MX],m[MX],N,X,B[MX],L[MX],U[MX],H[MX];
bool cp(ll a,ll b){return -m[a]-p[a]<-m[b]-p[b];}
ll pc(ll u,ll K){
    if(K>=B[u])return (K-B[u])*U[u];
    return (K-B[u])*L[u];
}
bool ok(ll t){
    ll v=t/X,S=0,r=t%X;
    F(N)if(i<v)S+=p[H[i]];
        else S-=m[H[i]];
    if(S>=0)return 1;
    F(N){
        int I=H[i];
        if(i<v&&S-pc(I,X)+pc(I,r)+pc(H[v],X)-pc(H[v],0)>=0)return 1;
        if(i>=v&&S-pc(I,0)+pc(I,r)>=0)return 1;
    }
    return 0;
}
ll bs(ll B=0,ll E=INF){
    ll M;
    while(B<E)
        if(ok(M=(B+E)>>1))E=M;
        else B=M+1;
    return B;
}
int main(void){
    scanf("%lld%lld",&N,&X);
    F(N)scanf("%lld%lld%lld",B+i,L+i,U+i);
    F(N)p[i]=(X-B[i])*U[i],m[i]=B[i]*L[i];
    iota(H,H+N,0),sort(H,H+N,cp);
    printf("%lld\n",bs(0,1e18+666));
    return 0;
}
