#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ll X, b[maxn], l[maxn], r[maxn], base;
vector<pair<ll, int> >sums;
bool can(ll c)
{
	ll full = c / X, rem = c - full * X;
	ll sum = 0;
	for(int i = 0; i < full; i++)
		sum += sums[i].x;
	ll mx = 0;
	for(int i = 0; i < n; i++)
	{
		int j = sums[i].y;
		ll add;
		if(rem >= b[j])
			add = b[j] * l[j] + r[j] * (rem - b[j]);
		else
			add = l[j] * rem;
		if(i < full)
			mx = max(mx, sum - sums[i].x + add + (full == n ? 0 : sums[full].x));
		else
			mx = max(mx, sum + add);
	}
	return mx >= base;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n >> X;
	for(int i = 0; i < n; i++)
	{
		cin >> b[i] >> l[i] >> r[i];
		base += l[i] * b[i];
		sums.pb({(X - b[i]) * r[i] + b[i] * l[i], i});
	}
	sort(all(sums), greater<pair<ll, int> >());
	ll lo = 0, hi = X * n;
	while(lo < hi)
	{
		ll mid = (lo + hi) / 2;
		if(can(mid))
			hi = mid;
		else
			lo = mid + 1;
	}
	cout << lo << "\n";
	return 0;
}
#include <bits/stdc++.h>
#define Maxn 100007
using namespace std;
int n,x;
int b[Maxn],l[Maxn],r[Maxn];
bool flag[Maxn];
priority_queue<pair<long long,int> >pq;
long long solve(int id,long long tmp)
{
    if (tmp<=0LL) return 0LL;
    if (tmp<=1LL*l[id]*b[id])
    {
        return (tmp+l[id]-1)/l[id];
    } else
    {
        tmp-=1LL*l[id]*b[id];
        return (tmp+r[id]-1)/r[id]+b[id];
    }
}
int main()
{
    scanf("%d%d",&n,&x);
    while (!pq.empty()) pq.pop();
    long long tmp=0LL;
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&b[i],&l[i],&r[i]);
        tmp+=1LL*l[i]*b[i];
        pq.push(make_pair(1LL*r[i]*(x-b[i])+1LL*l[i]*b[i],i));
    }
    long long ans=1LL*x*n;
    int cnt=0;
    while ((!pq.empty())&&tmp>=0)
    {
        tmp-=pq.top().first;
        int id=pq.top().second;
        flag[id]=true;
        pq.pop();
        ++cnt;
    }
    ans=min(ans,1LL*cnt*x);
    --cnt;
    long long t=x;
    for (int i=1;i<=n;i++)
        if (flag[i])
        {
            tmp+=1LL*r[i]*(x-b[i])+1LL*l[i]*b[i];
            t=min(t,solve(i,tmp));
            tmp-=1LL*r[i]*(x-b[i])+1LL*l[i]*b[i];
        }
    ans=min(ans,1LL*cnt*x+t);
    while (!pq.empty()) pq.pop();
    tmp=0LL;
    for (int i=1;i<=n;i++)
    {
        tmp+=1LL*l[i]*b[i];
        pq.push(make_pair(1LL*r[i]*(x-b[i])+1LL*l[i]*b[i],i));
    }
    memset(flag,false,sizeof(flag));
    cnt=0;
    while ((!pq.empty())&&tmp>pq.top().first)
    {
        tmp-=pq.top().first;
        int id=pq.top().second;
        flag[id]=true;
        pq.pop();
        ++cnt;
    }
    ans=min(ans,1LL*cnt*x+x);
    t=x;
    for (int i=1;i<=n;i++)
        if (!flag[i]) t=min(t,solve(i,tmp));
    ans=min(ans,1LL*cnt*x+t);
    printf("%lld\n",ans);
    return 0;
}