#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<int(n); i++)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

const int MAX = 100010;
ll N, X, b[MAX], l[MAX], u[MAX], sum1[MAX], sum2[MAX];
vector<P> num;

bool chk(ll p){
	ll score = -1e18, cnt;
	if(p % X == 0){
		score = sum1[p/X] + sum2[N-(p/X)];
	}else{
		rep(i, N){
			int n = num[i].second;
			if((p/X)-1 >= i) cnt = sum1[(p/X)+1] - u[n]*(X-b[n]) + sum2[N-(p/X)-1];
			else cnt = sum1[p/X] + sum2[N-(p/X)] + l[n]*b[n];
			if((p%X) >= b[n]) cnt += u[n]*((p%X)-b[n]);
			else cnt += l[n]*((p%X)-b[n]);
			if(cnt > score) score = cnt;
		}
	}
	return (score >= 0);
}

int main(){
	cin >> N >> X;
	rep(i, N){
		cin >> b[i] >> l[i] >> u[i];
		num.push_back({u[i]*(X-b[i])+l[i]*b[i], i});
	}
	sort(num.begin(), num.end(), greater<P>());
	sum1[0] = 0, sum2[0] = 0;
	rep(i, N){
		int index = num[i].second, index2 = num[N-i-1].second;
		sum1[i+1] = sum1[i] + u[index]*(X-b[index]);
		sum2[i+1] = sum2[i] - l[index2]*b[index2];
	}
	ll ok = X*N, ng = -1;
	while(ok - ng > 1){
		ll mid = (ok + ng)/2;
		if(chk(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << "\n";
	return 0;
}
