#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>

pll h[100010];

ll b[100010],l[100010],r[100010],pre[100010],n,m;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline bool check(ll mid)
{
	ll sum=0;
	for (int i=1;i<=n;i++) sum-=b[i]*l[i],h[i]=pll((m-b[i])*r[i]+b[i]*l[i],i);
	sort(h+1,h+n+1);reverse(h+1,h+n+1);
	for (int i=1;i<=n;i++) pre[i]=pre[i-1]+h[i].first;
	ll hh=mid/m,now=mid%m;
	for (int i=1;i<=n;i++)
	{
		ll res=sum+b[h[i].second]*l[h[i].second];
		if (i>hh) res+=pre[hh];
		else res+=pre[i-1]+(pre[hh+1]-pre[i]);
		if (now>=b[h[i].second]) res+=r[h[i].second]*(now-b[h[i].second]);
		else res-=l[h[i].second]*(b[h[i].second]-now);
		if (res>=0) return true;
	}
	return false;
}

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) b[i]=rd(),l[i]=rd(),r[i]=rd();
	ll l=0,r=(ll)n*m;
	while (l<r)
	{
		ll mid=(l+r)>>1;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}