#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

ll getDiffScore(ll l, ll u, ll b, ll x)
{
	ll ret = 0;

	if (x < b)
	{
		ret = l * x;
	}
	else
	{
		ret = l * b + u * (x - b);
	}

	return ret;
}

int main()
{
	int n;
	ll x;

	cin >> n >> x;

	vector <ll> b(n);
	vector <ll> l(n);
	vector <ll> u(n);

	vector <pair <ll, int> > vp;

	vector <pair <ll, int> > fullScore;

	ll initTotal = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i] >> l[i] >> u[i];

		vp.push_back(make_pair(l[i],i));
		vp.push_back(make_pair(u[i], i));

		const ll fs = getDiffScore(l[i], u[i], b[i], x);
		fullScore.push_back(make_pair(fs, i));

		// BEGIN CUT HERE
//		cerr << " i=" << i << " fs=" << fs << endl;
		// END CUT HERE


		


		initTotal -= l[i] * b[i];
	}

	sort(fullScore.rbegin(), fullScore.rend());




	sort(vp.begin(), vp.end());

	ll ok = n * x;
	ll ng = -1; // 二分探索（こたえの）
	while (abs(ok - ng)>1)
	{
		ll score = ok + (ng - ok) / 2LL; // ll 溢れ時は、lo+(hi-lo)/2LL;
		// BEGIN CUT HERE
		cerr << " score=" << score << endl;
		// END CUT HERE


		// BEGIN CUT HERE
	//	cerr << " score=" << score << endl;
		// END CUT HERE


		ll numfullmark = score / x;
		ll remainderScore = score - numfullmark * x;

		// BEGIN CUT HERE
		//		cerr << " numfullmark=" << numfullmark << " remainderScore=" << remainderScore << endl;
		// END CUT HERE


		ll startTotal = initTotal; // 青木君の得点

		for (int rank=0; rank<numfullmark;++rank)
		{
			startTotal += fullScore[rank].first;
		}

		// BEGIN CUT HERE
		//		cerr << " initTotal=" << initTotal << " startTotal=" << startTotal << endl;
		// END CUT HERE

		ll bestTotal = startTotal;

		if(numfullmark<n)
		{
#if 0
			for (int rank = 0; rank < n; ++rank)
			{
				ll total = startTotal;
				// BEGIN CUT HERE
//				cerr << " total=" << total << endl;
				// END CUT HERE


				int f = numfullmark;

				for (int ra=0;ra<n;++ra)
				{
					const int id = fullScore[ra].second;

					if (ra == rank)
					{

						total += getDiffScore(l[id], u[id], b[id], remainderScore);
					}
					else
					{
						if (f >= 1)
						{
							total += getDiffScore(l[id], u[id], b[id], x);
							f--;
						}
					}
				}
				// BEGIN CUT HERE
//				cerr << " rank=" << rank << " total=" << total << endl;
				// END CUT HERE

				amax(bestTotal, total);
			}
#else

			for (int rank = 0; rank<n; ++rank)
			{
				ll total = startTotal;

				const int id = fullScore[rank].second;

				if (rank<numfullmark)
				{
					total -= getDiffScore(l[id], u[id], b[id], x);
					total += getDiffScore(l[id], u[id], b[id], remainderScore);
					const int nextid = fullScore[numfullmark].second;
					total += getDiffScore(l[nextid], u[nextid], b[nextid], x);
				}
				else
				{
					total += getDiffScore(l[id], u[id], b[id], remainderScore);
				}

				// BEGIN CUT HERE
//				cerr << " rank=" << rank << " total=" << total << endl;
				// END CUT HERE

				amax(bestTotal, total);
			}
#endif

		}




		if (bestTotal >=0)
		{
			ok = score;
		}
		else
		{
			ng = score;
		}
	}

	cout << ok << endl;


	return 0;
}


Measured memory_bytes: 10736