#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
long long int X;
long long int b[100005], l[100005], u[100005];

long long int bp[100005], lp[100005], up[100005];

long long int THRESH;

//vector< pair<int, pair<int, int> > > V;

vector < pair<long long int, int>>  W;

int ID[100005];

long long int RET(int i, long long int x) {

	return max(x*lp[i], (x - bp[i])*up[i] + lp[i] * bp[i]);
}

long long int sum_R[100005],sum_A[100005], sum_B[100005];


int CHECK(long long int K) {

	if (K < 0) { return -1; }

	long long int I = K / X;


	long long int A = 0, B = 0;
	long long int save_A = -999999999999, save_B = -99999999999;

	if (I >= N) { return 1; }

	long long int x = (long long int) K - I*X;
	long long int max_val = -99999999999999;

	long long int tmp;

	for (int i = 1; i <= I; i++) {
		tmp = sum_R[I + 1];
		tmp -= RET(i, X);
		tmp += RET(i, x);
		max_val = max(max_val, tmp);
	}

	for (int i = I + 1; i <= N; i++) {
		tmp = sum_R[I];
		tmp += RET(i, x);
		max_val = max(max_val, tmp);
	}

	if (max_val >= THRESH) { return 1; }
	else { return -1; }



	/*for (int i = 1; i <= I; i++) {
		A = sum_A[i + 1]; B = sum_B[i + 1];
		A -= X*up[i]; B -= bp[i] * (up[i]-lp[i]);
		if (x > bp[i]) {
			A += x*up[i]; B += bp[i] * up[i];
		}
		else {
			A += x*lp[i]; B += bp[i] * lp[i];
		}
		//cout << "i= " << i << "B= " << B << endl;
		if (max_val < A - B) {
			max_val = A - B; save_A = A, save_B = B;
		}
	}

	
	for (int i = I + 1; i <= N; i++) {
		A = sum_A[I]; B = sum_B[I]; 
		if (x - bp[i]>0) { A += x*up[i]; B += bp[i] * (up[i]-lp[i]); }
		else {
			A += x*lp[i]; 
		}
		//cout << "i= " << i << "B= " << B << endl;
		if (max_val < A - B) {
			max_val = A - B; save_A = A, save_B = B;
		}

	}

	*/
/*	int p;
	//===================
	for (int i = 0; i <= I - 1; i++) {
		p = ID[i];
		
		A += ((long long int) u[p])*X;
		B += ((long long int) b[p])*u[p];
		//cout << "A= " << A <<"  B= " <<B<< endl;

	}


	
	//======================

	//cout << "A= " << A << "  B= " << B << endl;
	
	int pos = W.size() + 10;
	int c;
	long long int max_val = -99999999999999;

	long long int x = (long long int) K - I*X;
	//cout << "x= " << x << endl;

	int sig = 0;
	
	for (int i = I; i < (int)W.size(); i++) {
			p = ID[(int)I];
			if (x*l[p] >= max_val) { pos = p; c = l[p]; sig = -1;  max_val = x*l[p]; }
			if (x*u[p] - b[p] * (u[p] - l[p]) >= max_val) {
				pos = p; c = u[i]; sig = 1; max_val = x*u[p] - b[p] * (u[p] - l[p]);
			}
	}

	//cout << "pos= " << pos <<" sig= " <<sig<< endl;
	//=========================
	for (int i = I; i < (int)W.size(); i++) {
		p = ID[i];
		if (p == pos) {

			if (sig == 1) {
				A += x*u[p] - b[p] * (u[p] - l[p]);
				B += b[p] * u[p];
			}
			else {
				A += x*l[p];
				B += b[p] * l[p];
			}

		}
		else {
			B += ((long long int) b[p])*l[p];
		}
	}


	//cout << "A=  " << A << "  B= " << B << endl;
	if (B == 0) { return 1; }
	*/

	//cout << "A= " << save_A << " B= " << save_B << endl;
	if (max_val>=0) { return 1; }

	return -1;
}

long long int BINARY_SEARCH(void) {

	long long int left = -1;
	long long int right = 9999999999999;

	while (right - left > 1) {
		long long int med = (right + left) / 2;
		//cout << "med= " << med << endl;
		if (CHECK(med) == 1) { right = med; }
		else { left = med; }
	}

	return right;
}

long long int dp[15][3300];
int dp2[15][3300];

int main(void) {

	cin >> N >> X;

	for (int i = 1; i <= N; i++) {
		cin >> b[i] >> l[i] >> u[i];
		W.push_back(make_pair(((long long int) (X-b[i]))*u[i]+b[i]*l[i],i));
	}

	sort(W.rbegin(), W.rend());

	
	for (int i = 0; i < (int)W.size(); i++) {
	//cout << W[i].first << " " << W[i].second <<endl;
	ID[i] = W[i].second;
	up[i + 1] = u[ID[i]];
	lp[i + 1] = l[ID[i]];
	bp[i + 1] = b[ID[i]];
	}

	/*for (int i = 1; i <= N; i++) {
		cout << "i= " << i << " " << bp[i] << " " << up[i] << " " << lp[i] << endl;
	}*/

	/*for (int i = 0; i < N; i++) {
		cout << "i= " << i << " ID= " << ID[i] << endl;
	}*/

	for (int i = 1; i <= N; i++) {
		THRESH += b[i] * l[i];
	}

	for (int i = 1; i <= N; i++) {
		sum_R[i] = sum_R[i - 1] + RET(i, X);
	}

	/*long long int sum_tmp = 0;
	for (int i = 1; i <= N; i++) { sum_tmp += (long long int) b[i] * l[i]; }
	
	for (int i = 0; i < (int)W.size(); i++) {
		int p = W[i].second;
		sum_A[i + 1] = sum_A[i] + (long long int)X*u[p];
		sum_B[i + 1] = sum_B[i] + (long long int)b[p]*(u[p]-l[p]);
	}
	sum_B[0] = sum_tmp;
	for (int i = 0; i<(int)W.size(); i++) {
		sum_B[i + 1] += sum_tmp;
		//cout << "i+1= " << i + 1 << "  sum_A = " << sum_A[i + 1] << "  sum_B= " << sum_B[i + 1] << endl;
	}*/

	
	//CHECK(80);

	/*	for (int i = 0; i <= 120; i++) {
	cout << "i= " << i << "  CHECK= " << CHECK(i) << endl;
	}*/

		

	cout << BINARY_SEARCH() << endl;

	/*
	long long int INF = 9999999999;
	for (int i = 0; i <= N; i++) {
		for (int k = 0; k <= 3000; k++)
			dp[i][k] = -INF;
	}

	//=============
	int M = 2540;
	//==============

	dp[0][M] = 0;

	for (int i = 1; i <= N; i++) {
		for (int k = 0; k <= M; k++) {
			if(dp[i-1][k]!=-INF){
				for (int m = 0; m <= min(k, X); m++) {
					long long int val, val_a,val_b;
					if (m > b[i]) { val_a = (long long int) m*u[i]; val_b = (long long int)b[i] * u[i]; }
					else { val_a = (long long int) m*l[i]; val_b = (long long int) b[i] * l[i]; }
					//cout << "val_b= " << val_b << endl;
					val = dp[i - 1][k] + val_a - val_b;
					if (val > dp[i][k - m]) { dp[i][k - m] = val; dp2[i][k - m] = k; }
				}
			}
		}
	}

	long long int atai = -INF;
	int num;
	for (int m = 0; m <= M; m++) {
		if (atai < dp[N][m]) { atai = dp[N][m]; num = m; }
	}

	vector<int> Y;
	Y.push_back(num);
	for (int i = N; i >= 1; i--) {
		//cout << "num= " << num << endl;
		num = dp2[i][num];
		//cout << "num= " << num << endl;
		Y.push_back(num);
	}


	for (int n = 0; n <= N; n++) {
		for (int m = 0; m <= 10; m++) {
		//	cout << "dp[" << n<< "][" << m << "]= " << dp[n][m] << endl;
		}
	}

	cout << "M= " << M << endl;
	cout << "atai= " <<atai << endl;
	for (int i = N; i >= 1; i--) {
		cout << " " << Y[i]-Y[i-1];
	}cout << endl;
	*/
	return 0;
}

Measured memory_bytes: 7920