#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll x,b[100100],l[100100],u[100100],df=0ll;
vector<int> v;

ll comp(int i, int j){
	ll p,q;
	p = (x-b[i])*u[i]+b[i]*l[i];
	q = (x-b[j])*u[j]+b[j]*l[j];
	return p>q;
}

bool judge(ll p){
	int i;
	ll q,r,tmp=df,d=-INFLL,c,qv;
	q = p/x; r = p%x;
	for(i=0; i<q; ++i){
		tmp += (x-b[v[i]])*u[v[i]]+b[v[i]]*l[v[i]];
	}
	qv = (x-b[v[q]])*u[v[q]]+b[v[q]]*l[v[q]];
	for(i=0; i<n; ++i){
		c = min(r,b[v[i]])*l[v[i]]+max(r-b[v[i]],0ll)*u[v[i]];
		if(i<q){
			c -= (x-b[v[i]])*u[v[i]]+b[v[i]]*l[v[i]];
			d = max(d,tmp+qv+c);
		}else{
			d = max(d,tmp+c);
		}
	}
	return (d>=0ll);
}

int main(void){
	int i;
	ll ok=0ll,ng,mid;
	cin >> n >> x;
	for(i=0; i<n; ++i){
		v.push_back(i);
		cin >> b[i] >> l[i] >> u[i];
		df -= b[i]*l[i];
		ok += b[i];
	}
	if(!ok){
		cout << 0 << endl;
		return 0;
	}
	sort(v.begin(),v.end(),comp);
	ng = 0ll;
	while(ok-ng>1){
		mid = (ok+ng)>>1;
		if(judge(mid)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
	return 0;
}
