#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,x;
int b[125252], l[125252], u[125252];
ll d[125252];
ll e[125252];
int ids[125252];

int main(){
    scanf("%d%d",&n,&x);
    REP(i,n){
        scanf("%d%d%d",b+i,l+i,u+i);
    }
    ll rest = 0;
    REP(i,n)rest += (ll)l[i]*b[i];
    REP(i,n){
        d[i] = (ll)(u[i]-l[i])*b[i];
        e[i] = (ll)u[i]*x-d[i];
        ids[i] = i;
    }
    sort(ids,ids+n,[&](int i, int j){
        if(e[i] != e[j])return e[i] > e[j];
        return u[i] > u[j];
    });
    ll ans = 0;
    int last = 0;
    {
        ll tmp = 0;
        REP(i,n){
            tmp += e[ids[i]];
            ans += x;
            if(tmp>=rest){
                last = i;
                break;
            }
        }
    }
    // last ~ n-1
    {
        ll add = (ll)x*last;
        ll sum = 0;
        REP(i,last)sum += e[ids[i]];
        FOR(i,last,n){
            int id = ids[i];
            if(sum + e[id]<rest)continue;
            int ok = x, ng = -1;
            while(abs(ok-ng)>1){
                int v = (ok+ng)/2;
                ll val = sum + (ll)u[id]*v - d[id];
                (val >= rest ? ok : ng) = v;
            }
            CHMIN(ans, add+ok);
        }
    }
    // 0 ~ last-1
    {
        ll add = (ll)x*last;
        ll sum = 0;
        REP(i,last+1)sum += e[ids[i]];
        REP(i,last){
            int id = ids[i];
            sum -= e[id];
            int ok = x, ng = -1;
            while(abs(ok-ng)>1){
                int v = (ok+ng)/2;
                ll val = sum + (ll)u[id]*v - d[id];
                (val >= rest ? ok : ng) = v;
            }
            CHMIN(ans, add+ok);
            sum += e[id];
        }
    }
    sort(ids,ids+n,[&](int i, int j){
        if(e[i] != e[j])return e[i] > e[j];
        return l[i] > l[j];
    });
    // last ~ n-1
    {
        ll add = (ll)x*last;
        ll sum = 0;
        REP(i,last)sum += e[ids[i]];
        FOR(i,last,n){
            int id = ids[i];
            if(sum + (ll)l[id]*x<rest)continue;
            int ok = x, ng = -1;
            while(abs(ok-ng)>1){
                int v = (ok+ng)/2;
                ll val = sum + (ll)l[id]*v;
                (val >= rest ? ok : ng) = v;
            }
            CHMIN(ans, add+ok);
        }
    }
    // 0 ~ last-1
    {
        ll add = (ll)x*last;
        ll sum = 0;
        REP(i,last+1)sum += e[ids[i]];
        REP(i,last){
            int id = ids[i];
            if(sum + (ll)l[id]*x<rest)continue;
            sum -= e[id];
            int ok = x, ng = -1;
            while(abs(ok-ng)>1){
                int v = (ok+ng)/2;
                ll val = sum + (ll)l[id]*v;
                (val >= rest ? ok : ng) = v;
            }
            CHMIN(ans, add+ok);
            sum += e[id];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3456