#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#pragma GCC optimize ("O3")
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef long double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ld, ut> pld;
typedef vector<pld> Vpld;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 188;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K,  H, W, Q, D, T,X;
//ut N,A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
//LL A[SIZE][SIZE];
string s;
VI vals[SIZE];
LL sum[SIZE];
bool ables[SIZE];
LL B[SIZE], L[SIZE], U[SIZE];
Vpr v;
LL calc(int x,int i) {
	//assert(i < SIZE);
	if (x <= B[i]) {
		return L[i] * x;
	}
	else {
		return L[i] * B[i] +U[i]*(x - B[i]);
	}
}
LL solve2(LL point) {
	LL needer = point / X;
	LL maxim = 0;
	LL ans = 0;
	REP(i, N+1) {
		if (i < needer) {
		//	assert(needer + 1 < SIZE);
			MX(maxim, sum[needer + 1] - v[i].first + calc(point%X, v[i].second));
		}
		else {
		//	assert(needer < SIZE);
			MX(maxim, sum[needer] + calc(point%X, v[i].second));
		}
	}
	//cout << point << " " << maxim << endl;
	return maxim;
}
LL solve() {
	cin >> N >> X;
	LL need = 0;
	REP(i, N) {
		cin >> B[i] >> L[i] >> U[i];
		need += B[i] * L[i];
		v.pb(U[i] * (X - B[i]) + L[i] * B[i],i);
	}
	v.pb(0, N);
	sort(ALL(v), greater<pr>());
	LL s = 0, e = N * X;
	REP(i, N+1) {
		sum[i + 1] = sum[i] + v[i].first;
	}
	while (s <= e) {
		LL f = (s + e) / 2;
		if (solve2(f) >= need) e = f - 1;
		else s = f + 1;
	}
	cout << s << endl;
	return 0;
}
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	solve();
	//	cin >> N;
	return 0;
}


Measured memory_bytes: 40304