#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, X;
vector <ll> b, l, r;

ll calc(int day, int a){
	return (a <= b[day] ? l[day] : r[day]) * (a - b[day]);
}
ll sum(int day, int len){
	if(len <= b[day]) return len * l[day];
	return b[day] * l[day] + (len - b[day]) * r[day];
}
ll calc(ll h){
	int q = h / X;
	int r = h % X;
	vector <pair <ll, int> > c;
	for(int i = 0 ; i < n ; i++){
		c.emplace_back(sum(i, X), i);
	}
	sort(c.rbegin(), c.rend());
	ll s = 0;
	for(int i = 0 ; i < q ; i++){
		s += c[i].first;
	}
	if(r == 0) return s;
	ll ret = 0;
	for(int i = 0 ; i < q ; i++){
		ret = max(ret, s - sum(c[i].second, X) + sum(c[i].second, r) + sum(c[q].second, X));
	}
	for(int i = q ; i < n ; i++){
		ret = max(ret, s + sum(c[i].second, r));
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> X;
	b.resize(n);
	l.resize(n);
	r.resize(n);
	for(int i = 0 ; i < n ; i++){
		cin >> b[i] >> l[i] >> r[i];
	}
	ll D = 0;
	for(int i = 0 ; i < n ; i++){
		D += calc(i, 0);
	}
	ll l = 0, r = 1LL * n * X;
	while(l <= r){
		ll mid = (l + r) / 2;
		if(D + calc(mid) >= 0) r = mid - 1;
		else l = mid + 1;
	}
	cout << l << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,u,v,w;
ll bismarck[(1<<15)][15],e[15][15],sum[(1<<15)];
int main()
{
	cin>>n>>m;
	while(m--)
	{
		cin>>u>>v>>w;
		u--,v--;
		e[u][v]=e[v][u]=w;
	}
	for(int i=0;i<1<<n;i++)
	{
		for(int j=0;j<n;j++){
		if((i>>j)&1)
		{
            for(int k=j+1;k<n;k++)
		    if((i>>k)&1) sum[i]+=e[j][k];			
		}
		bismarck[i][j]=-1e18;}
	}
	bismarck[1][0]=0;
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		if((i>>j)&1)
		{
			int l=i^(1<<j);
			for(int k=0;k<n;k++)
			if((i>>k)&1&&e[j][k]) bismarck[i][j]=max(bismarck[i][j],bismarck[l][k]+e[k][j]);
			for(int k=l;k>0;k=(k-1)&l) bismarck[i][j]=max(bismarck[i][j],bismarck[i^k][j]+sum[k^(1<<j)]); 
		}
	}
	cout<<sum[(1<<n)-1]-bismarck[(1<<n)-1][n-1];
}