#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=1000005;
ll l[N],r[N],b[N],rk[N],val[N],mark[N];
ll sum[N],n,x,aim,ans=2e18;

inline ll cmp(ll x,ll y){
	return val[x]>val[y];
}

inline ll calc(ll x,ll y){
	if(x>=y)return sum[x];
	return sum[x]+val[rk[y]];
}

inline ll doit(ll k,ll rem){
	if(rem<=0)return 0;
	if(rem<=l[k]*b[k])return (rem+l[k]-1)/l[k];
	return b[k]+(rem-l[k]*b[k]+r[k]-1)/r[k];
}

int main(){
	scanf("%lld%lld",&n,&x);
	rep(i,1,n){
		scanf("%lld%lld%lld",&b[i],&l[i],&r[i]);
		val[i]=b[i]*l[i]+(x-b[i])*r[i];
		aim+=b[i]*l[i];
		rk[i]=i;
		//cerr<<i<<" "<<val[i]<<endl;
	}
	sort(rk+1,rk+n+1,cmp);
	rep(i,1,n)
		sum[i]=sum[i-1]+val[rk[i]];
	rep(i,1,n){
		ll low=0,high=n,mid;
		while(low<high){
			mid=(low+high)>>1;
			if(calc(mid,i)>=aim)high=mid;
			else low=mid+1;
		}
		if(low<i){
			ll now=x*low+doit(rk[i],aim-sum[low]);
			ans=min(ans,now);
		}
		else{
			ll now=x*(low-1)+doit(rk[i],aim-sum[low]+val[rk[i]]);
			ans=min(ans,now);
		}
	}
	cout<<ans<<endl;

	return 0;
}