// ~~ icebear love attttttt ~~
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "pizza"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, B;
ll dp[N], total[N], prefB[N];
array<int, 3> a[N];
class CHT {
private:
struct Line{
ll a, b;
Line(ll _a=0, ll _b=0): a(_a), b(_b) {}
friend long double intersect(Line A, Line B){
return 1.0 * (A.b - B.b) / (B.a - A.a);
}
ll calc(int x) {return 1LL * a * x + b;}
};
bool useless(const Line &A, const Line &B, const Line &C) { // find max
return intersect(A, C) >= intersect(B, C);
}
deque<Line> hull;
public:
void make_best(int x){
while(hull.size() >= 2 && hull[0].calc(x) <= hull[1].calc(x))
hull.pop_front();
}
void add(ll a, ll b){
Line A = Line(a, b);
while(hull.size() >= 2 && useless(hull[hull.size()-2], hull.back(), A))
hull.pop_back();
hull.pb(A);
}
ll query(int x) {return (hull.front()).calc(x);}
} cht;
void init(void) {
cin >> n >> B;
FOR(i, 1, n) cin >> a[i][0] >> a[i][1] >> a[i][2];
sort(a + 1, a + n + 1);
FOR(i, 1, n) {
total[i] = total[i - 1] + a[i][1] + a[i][0] * a[i][2];
prefB[i] = prefB[i - 1] + a[i][2];
}
}
void process(void) {
FOR(i, 1, n) dp[i] = -INF;
// dp[i] = max(dp[j - 1] - total[j - 1] + a[i][0] * prefB[j - 1])
// + total[i] - a[i][0] * prefB[i] - B
cht.add(0, 0);
FOR(i, 1, n) {
cht.make_best(a[i][0]);
dp[i] = cht.query(a[i][0]) + total[i] - a[i][0] * prefB[i] - B;
cht.add(prefB[i], dp[i] - total[i]);
}
cout << dp[n];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dHR0IH5+CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGludCBsb25nIGxvbmcKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxpbnQsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxpbnQsIGlpPiBpaWk7Cgp0ZW1wbGF0ZTxjbGFzcyBUPgogICAgYm9vbCBtaW5pbWl6ZShUICZhLCBjb25zdCBUICZiKSB7CiAgICAgICAgaWYgKGEgPiBiKSByZXR1cm4gYSA9IGIsIHRydWU7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWF4aW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhIDwgYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCiNkZWZpbmUgRk9SKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPD0oYik7ICsraSkKI2RlZmluZSBGT1JSKGksYSxiKSBmb3IoaW50IGk9KGEpOyBpPj0oYik7IC0taSkKI2RlZmluZSBSRVAoaSwgbikgZm9yKGludCBpPTA7IGk8KG4pOyArK2kpCiNkZWZpbmUgUkVEKGksIG4pIGZvcihpbnQgaT0obiktMTsgaT49MD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