#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

ll B[SIZE],L[SIZE],U[SIZE];
P pos[SIZE];

int main()
{
	int n;
	ll X;
	scanf("%d %lld",&n,&X);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%lld %lld %lld",&B[i],&L[i],&U[i]);
		pos[i]=P((X-B[i])*U[i]+B[i]*L[i],i);
		sum-=B[i]*L[i];
	}
	sort(pos,pos+n);
	ll ret=0;
	int last=0;
	for(int i=n-1;i>=0;i--)
	{
		P p=pos[i];
		if(sum+p.first>=0)
		{
			ret+=(ll) (n-i-1)*(ll) X;
			last=i+1;
			break;
		}
		sum+=p.first;
	}
  // cout<<ret<<" "<<last<<endl;
	ll mn=X;
	sum=-sum;
  // cout<<sum<<endl;
	for(int i=0;i<last;i++)
	{
		int v=pos[i].second;
		mn=min(mn,(sum+L[v]-1)/L[v]);
		ll nsum=sum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum+U[v]-1)/U[v]);
	}
	for(int i=last;i<n;i++)
	{
		int v=pos[i].second;
		ll nsum=sum+pos[i].first-pos[last-1].first;
		mn=min(mn,(nsum+L[v]-1)/L[v]);
		ll nsum2=nsum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum2+U[v]-1)/U[v]);
	}
	printf("%lld\n",ret+mn);
	return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 100000
#define LL long long

int N,X;
LL Sum[MAXN+5],Org,D[MAXN+5];
struct Range{
    LL tot;
    int l,r,id;
}A[MAXN+5];
bool cmp(Range i,Range j){
    return i.tot>j.tot;
}

bool Check(LL expt){
    LL Max=0;
    LL All=expt/X,Rest=expt%X;
    for(int i=1;i<=N;i++){
        LL l=min(Rest,D[A[i].id]);
        LL tmp=i>All?Sum[All]:(Sum[All+1]-A[i].tot);
        Max=max(Max,tmp+l*A[i].l+(Rest-l)*A[i].r);
    }
    return Max>=Org;
}

int main(){
    N=read(),X=read();
    for(int i=1;i<=N;i++){
        D[i]=read();
        A[i].id=i;
        A[i].l=read(),A[i].r=read();
        A[i].tot=D[i]*A[i].l+(X-D[i])*A[i].r;
        Org+=D[i]*A[i].l;
    }
    sort(A+1,A+N+1,cmp);
    for(int i=1;i<=N;i++)
        Sum[i]=Sum[i-1]+A[i].tot;
    LL Left=-1,Right=(LL)X*N;
    while(Left+1<Right){
        LL mid=(Left+Right)>>1;
        if(Check(mid))
            Right=mid;
        else
            Left=mid;
    }
    printf("%lld",Right);
}
