#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,x,S=0;
vl a,b,c;

bool f(ll t){
	vpll d(n);
	ll m=t%x,M=0,sum=0;
	for(int i=0;i<n;i++) d[i]={a[i]*b[i]+(x-a[i])*c[i],(m<a[i]?m*b[i]:a[i]*b[i]+(m-a[i])*c[i])};
	sort(d.rbegin(),d.rend());
	for(int i=0;i<t/x;i++) sum+=d[i].first;
	for(int i=0;i<n;i++){
		if(i<t/x) M=max(M,sum-d[i].first+d[i].second+d[t/x].first);
		else M=max(M,sum+d[i].second);
	}
	return M>=S;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>x;
	a=b=c=vl(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
		S+=a[i]*b[i];
	}
	ll l=-1,r=n*x;
	while(r-l>1){
		ll m=(l+r)/2;
		if(f(m)) r=m;
		else l=m;
	}
	cout<<r<<endl;
}