/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 */
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}


int powm(int a, int b) {
	a%=mod;
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return res;
}

struct test {
	int val,b,l,u;
};
void solve() {
	int n,x;
	cin>>n>>x;
	vector<test> tests;
	fr(i,1,n) {
		int b,l,u;
		cin>>b>>l>>u;
		tests.pb({u*(x-b)+l*b,b,l,u});
	}
	sort(all(tests),[](auto &i,auto &j) {
		return i.val<j.val;
	});
	reverse(all(tests));
	int ans=0;
	int sum=0,profit=0;
	for(int i=0; i<n; i++) {
		sum+=tests[i].b*tests[i].l;
//		trace(tests[i].val);
	}
	for(int i=0; i<n; i++) {
		int teprofit=tests[i].val;
		if(profit+teprofit>=sum) {
			int tean=x;
			for(int j=i; j<n; j++) {
				int lo=0,hi=x,mid=(lo+hi)/2;
				while(lo<hi) {
					int pro=0;
					if(mid>tests[j].b) {
						pro=mid*tests[j].u+(tests[j].b*(tests[j].l-tests[j].u));
					} else
						pro=mid*tests[j].l;
					if(profit+pro>=sum)
						hi=mid;
					else
						lo=mid+1;
					mid=(lo+hi)/2;
				}
				tean=min(tean,mid);
			}
			profit+=teprofit;
			for(int j=0; j<i; j++) {
				profit-=tests[j].val;
				int lo=0,hi=x,mid=(lo+hi)/2;
				while(lo<hi) {
					int pro=0;
					if(mid>tests[j].b) {
						pro=mid*tests[j].u+(tests[j].b*(tests[j].l-tests[j].u));
					} else
						pro=mid*tests[j].l;
					if(profit+pro>=sum)
						hi=mid;
					else
						lo=mid+1;
					mid=(lo+hi)/2;
				}
				tean=min(tean,mid);
				profit+=tests[j].val;
			}
			cout<<ans+tean<<endl;
			return;
		} else {
			profit+=teprofit;
			ans+=x;
		}
	}

}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 6560