#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

using namespace std;

struct Sub {
    lint b, l, r;
    Sub(int b = 0, int l = 0, int r = 0) : b(b), l(l), r(r) {}
};

int main() {
    lint N, X;
    cin >> N >> X;

    vector<Sub> subs(N);
    for (auto& s : subs) {
        cin >> s.b >> s.l >> s.r;
    }
    sort(subs.begin(), subs.end(), [&](Sub a, Sub b) {
        return a.r * (X - a.b) + a.l * a.b > b.r * (X - b.b) + b.l * b.b;
    });

    // 勉強時間で二分探索
    lint ok = N * X, ng = -1;
    while (ok - ng > 1) {
        lint mid = (ok + ng) / 2;

        lint score = 0;  // 先頭からmid/X科目だけX点を取り、他は0点
        for (int i = 0; i < N; ++i) {
            if (i < mid / X) {
                score += subs[i].r * (X - subs[i].b);
            } else {
                score -= subs[i].l * subs[i].b;
            }
        }

        lint R = mid % X;
        bool judge = (score >= 0);

        int n = mid / X;
        if (R > 0) {
            for (int r = 0; r < N; ++r) {
                lint nscore = score;
                if (r < n) {
                    // r番目を消してn番目を追加
                    nscore -= subs[r].r * (X - subs[r].b) + subs[r].l * subs[r].b;
                    nscore += subs[r].l * min(subs[r].b, R) + subs[r].r * max(0LL, R - subs[r].b);
                    nscore += subs[n].r * (X - subs[n].b) + subs[n].l * subs[n].b;
                } else {
                    // r番目を追加する
                    nscore += subs[r].l * min(subs[r].b, R) + subs[r].r * max(0LL, R - subs[r].b);
                }
                if (nscore >= 0) judge = true;
            }
        }

        (judge ? ok : ng) = mid;
    }

    cout << ok << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=1e5+10;
int id[maxn],b[maxn],l[maxn],r[maxn];
ll v[maxn];
inline bool cmp(const int A,const int B){
	return v[A]>v[B];
}
int main(){
	int n=read(),lim=read();
	ll tot=0;
	REP(i,1,n){
		b[i]=read(),l[i]=read(),r[i]=read(),id[i]=i;
		v[i]=(ll)l[i]*b[i]+(ll)r[i]*(lim-b[i]);
		tot-=(ll)l[i]*b[i];
	}
	sort(id+1,id+n+1,cmp);
	ll sum=0,ans=1e18;
	ll val=0;
	REP(i,1,n){
		int u=id[i];
		val=v[u];
		if(tot+v[u]>=0) break;
		tot+=v[u];
		sum+=lim;
	}
	REP(i,1,n) if(tot+v[i]>=0){
		if(v[i]>val) tot+=val-v[i];
		if(tot+(ll)l[i]*b[i]>=0){
			chkmin(ans,b[i]-(tot+(ll)l[i]*b[i])/l[i]);
		}
		else{
			chkmin(ans,lim-(tot+v[i])/r[i]);
		}
		if(v[i]>val) tot-=val-v[i];
	}
	printf("%lld\n",ans+sum);
    return 0;
}