#include <bitsdc++.h>
using namespace std;
using ll = long long;
struct node{
int w, l, r;
bool operator<(const node & other)const{
return w < other.w;
}
};
void solve(){
int n;
ll m;
cin >> n >> m;
ll t = m;
vector<node> crops(n + 1);
for(int i = 1; i <= n; i++){
cin >> crops[i].w >> crops[i].l >> crops[i].r;
}
sort(crops.begin() + 1, crops.end());
vector<ll> prel(n + 5), prewl(n + 5), prelr(n + 5), prewlr(n + 5);
for(int i = 1; i <= n; i++){
prel[i] = prel[i - 1] + crops[i].l;
prewl[i] = prewl[i - 1] + crops[i].l * crops[i].w;
prelr[i] = prelr[i - 1] + crops[i].r - crops[i].l;
prewlr[i] = prewlr[i - 1] + (crops[i].r - crops[i].l) * crops[i].w;
}
ll ans = prewl[n];
t -= prel[n];
//prelr[n] - prelr [l] <= m
int p = lower_bound(prelr.begin() + 1, prelr.begin() + n + 1, prelr[n] - t) - prelr.begin();
if(p == n + 1)
{
ans += crops[p - 1].w * t;
t = 0;
}else{
t -= prelr[n] - prelr[p];
ans += prewlr[n] - prewlr[p];
ans += t * crops[p].w;
}
for(int i = 1; i <= n; i++){
ll s = m;
s -= prel[n];
ll res = prewl[n];
s += crops[i].l;
res -= crops[i].l * crops[i].w;
// cout << res << " " << s;
// cout << endl;
//prelr[n] - prelr[l] <= s
//假如多开数组避免特判,则要注意开始和结束位置
int p1 = lower_bound(prelr.begin() + i + 1, prelr.begin() + n + 1, prelr[n] - s) - prelr.begin();
if(p1 == n + 1){
res += crops[p1 - 1].w * s;
s = 0;
}else{
res += prewlr[n] - prewlr[p1];
//cout << res << endl;
s -= prelr[n] - prelr[p1];
res += s * crops[p1].w;
}
ans = max(ans, res);
}
cout << ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}