#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}
pair<int,pair<int,int> >p[100005];
int x;
bool comp(pair<int,pair<int,int> >a,pair<int,pair<int,int> >b)
{
    int y=a.second.second*x-(a.second.second-a.second.first)*a.first;
    int z=b.second.second*x-(b.second.second-b.second.first)*b.first;    
    // cout<<y<<" "<<z<<'\n';
    return y>z;
}

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  


    int n;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
        cin>>p[i].first>>p[i].second.first>>p[i].second.second;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        tot-=p[i].first*p[i].second.first;
    }
    sort(p+1,p+n+1,comp);
    int l=0,r=n*x;
    int mn=x*n;
    // cout<<p[1].first<<"\n";
    // cout<<tot<<'\n';
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        int rem=mid%x;
        int num=mid/x;
        int mx=0;     
        int temp=0;   
        for(int i=1;i<=num;i++)
        {
            temp+=p[i].second.second*x-(p[i].second.second-p[i].second.first)*p[i].first;
        }
        // cout<<temp<<'\n';
        for(int j=num+1;j<=n;j++)
        {
            if(p[j].first<=rem)
            {
                temp+=rem*p[j].second.second-p[j].first*(p[j].second.second-p[j].second.first);
                mx=max(mx,temp);
                temp-=rem*p[j].second.second-p[j].first*(p[j].second.second-p[j].second.first);
            }
            else
            {
                temp+=rem*p[j].second.first;
                mx=max(mx,temp);
                temp-=rem*p[j].second.first;
            }
        }
        
        if(num<n)
        {
            if(num>0)
            {
                temp+=p[num+1].second.second*x-(p[num+1].second.second-p[num+1].second.first)*p[num+1].first;
            }
            for(int j=1;j<=num;j++)
            {
                temp-=p[j].second.second*x-(p[j].second.second-p[j].second.first)*p[j].first;
                if(p[j].first<=rem)
                {
                    temp+=rem*p[j].second.second-p[j].first*(p[j].second.second-p[j].second.first);
                    mx=max(mx,temp);
                    temp-=rem*p[j].second.second-p[j].first*(p[j].second.second-p[j].second.first);
                }
                else
                {
                    temp+=rem*p[j].second.first;
                    mx=max(mx,temp);
                    temp-=rem*p[j].second.first;
                }
                temp+=p[j].second.second*x-(p[j].second.second-p[j].second.first)*p[j].first;
            }
        }
        if(num>0 && num<n)
        {
            temp-=p[num+1].second.second*x-(p[num+1].second.second-p[num+1].second.first)*p[num+1].first;
        }
        mx=max(mx,temp);
        mx+=tot;
        if(mx>=0)
        {
            mn=min(mn,mid);
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }        
    }

    cout<<mn;
    

} 
    


Measured memory_bytes: 5976