// <<<<GOD>>>> lET'S gO

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N = 1e5 + 100, inF = 1e12;

ll n, x, ans, enemy, b[N], l[N], r[N];

bool ok(ll cnt) {
	ll want = cnt / x;
	cnt %= x;
	if(want >= n)
		return true;
	if(want == 0) {
		ll maxi = 0;
		for (int i = 0; i < n; i++)
			if(cnt >= b[i])
				maxi = max(maxi, cnt * r[i] - b[i] * r[i] + b[i] * l[i]);
			else
				maxi = max(maxi, cnt * l[i]);
		return maxi >= enemy;
	}
	vector<ll> vec;
	for (int i = 0; i < n; i++)
		vec.push_back(x * r[i] - b[i] * r[i] + b[i] * l[i]);
	sort(vec.begin(), vec.end(), greater<ll>());
	ll S = 0, maxi = 0;
	for (int i = 0; i < want; i++)
		S += vec[i];
	for (int i = 0; i < n; i++)
		if(x * r[i] - b[i] * r[i] + b[i] * l[i] < vec[want - 1]) {
			if(cnt >= b[i])
				maxi = max(maxi, S + cnt * r[i] - b[i] * r[i] + b[i] * l[i]);
			else
				maxi = max(maxi, S + cnt * l[i]);
		}
		else {
			ll help = S - (x * r[i] - b[i] * r[i] + b[i] * l[i]) + vec[want];
			if(cnt >= b[i])
				maxi = max(maxi, help + cnt * r[i] - b[i] * r[i] + b[i] * l[i]);
			else
				maxi = max(maxi, help + cnt * l[i]);
		}
	return maxi >= enemy;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> b[i] >> l[i] >> r[i];
		enemy += b[i] * l[i];
	}
	ll s = -1, e = inF;
	while(e - s > 1) {
		ll mid = (s + e) >> 1;
		if(ok(mid))
			e = mid;
		else
			s = mid;
	}
	cout << e;
    return 0;
}