#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
struct node{
ll w,l,r,id;
node(){}
node(ll W,ll L,ll R,ll ID){
w=W;l=L;r=R;id=ID;
}
friend bool operator<(const node&x,const node&y){
return x.w>y.w;
}
}a[N],b[N];int cur=1,usd=0;
bool cmp(const node&x,const node&y){return x.l<y.l;}
int n;
ll gnew(int m){
ll sum=0;//cout<<m;
ll lcur=cur;
while(cur<=n&&b[cur].r==0)cur++;
if(cur>n)return;
while(b[cur].r<usd+m){
m-=b[cur].r-usd;
sum+=(b[cur].r-usd)*b[cur].w;
usd=0;cur++;
}
sum+=m*b[cur].w;usd+=m;
//cout<<" left with sum"<<sum<<":"<<lcur<<"->"<<cur<<" usd:"<<usd<<endl;
return sum;
}
ll m,w[N],l[N],r[N],p;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%lld %lld %lld",&w[i],&l[i],&r[i]);
if(w[p]<w[i])p=i;
if(w[p]==w[i]&&r[i]>r[p])p=i;
a[i]=node(w[i],l[i],r[i],i);
}
ll sum=0,len=0,ans=0,ml=0;
for(int i=1;i<=n;i++)
{
sum+=l[i]*w[i];len+=l[i];
b[i]=a[i];b[i].r-=b[i].l;
}
sort(a+1,a+1+n,cmp);sort(b+1,b+1+n);
ans=sum-l[p]*w[p]+(m-len+l[p])*w[p];
sum+=gnew(m-len);a[0].l=0;
ans=max(sum,ans);
for(int i=1;i<=n;i++){
sum+=gnew(a[i].l-a[i-1].l);
ans=max(ans,sum-a[i].l*a[i].w);
}
cout<<ans<<endl;
return 0;
}