#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

const int maxn = 1e5 + 100;

ll all[maxn] = {0}, b[maxn] = {0}, l[maxn] = {0}, u[maxn] = {0}, sum[maxn] = {0};
ll X = 0LL, pr = 0LL;
int id[maxn] = {0};
int n;

bool cmp(int i, int j) { return all[i] > all[j]; }

void init() {
	for (int i = 1; i <= n; ++i) id[i] = i, pr -= l[i] * b[i];
	for (int i = 1; i <= n; ++i) all[i] = b[i] * l[i] + (X - b[i]) * u[i];
	sort(id + 1, id + 1 + n, cmp);
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + all[id[i]];
}

bool check(ll mid) {
	ll t = mid / X;
	ll ret = pr;
	ll mx = 0LL;
	ll rem = mid % X;
	for (int i = 1; i <= n; ++i) {
		mx = max(mx, sum[t] + min(b[id[i]], rem) * l[id[i]] + max(0LL, rem - b[id[i]]) * u[id[i]] + (t >= i ? (-all[id[i]] + all[id[t + 1]]) : 0LL));
	}
	ret += mx;
	return ret >= 0LL;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> X;
	for (int i = 1; i <= n; ++i) cin >> b[i] >> l[i] >> u[i];
	init();
	ll L = 0LL, R = (ll)n * X;
	while (L < R) {
		ll mid = (L + R) >> 1;
		if (check(mid)) R = mid;
		else L = mid + 1;
	}
	cout << R << endl;
	return 0;
}