#include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

template <class T>
T lower_gauss(T num, T den) {
    assert(den != 0);
    if (num == 0) return 0;
    if (num > 0 and den > 0) return num / den;
    if (num < 0 and den > 0) return (num - den + 1) / den;
    return lower_gauss(-num, -den);
}

template <class T>
T upper_gauss(T num, T den) {
    return lower_gauss(num, den) + (num % den == 0 ? 0 : 1);
}



void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,X;
    cin >> N >> X;

    vector<i64> b(N),l(N),u(N);
    rep(i,0,N){
        cin >> b[i] >> l[i] >> u[i];
    }

    {
        bool zero=true;
        rep(i, 0, N) {
            if(b[i]>0){
                zero=false;
                break;
            }
        }
        if(zero){
            cout << 0 << endl;
            return;
        }
    }

    vector<tuple<i64,i64,i64,i64>> blu;
    rep(i,0,N){
        blu.emplace_back(make_tuple(u[i]*(X-b[i])+l[i]*b[i],b[i],l[i],u[i]));
    }
    sort(rbegin(blu),rend(blu));

    vector<i64> acc(N);
    rep(i,0,N){
        i64 score,b,l,u;
        tie(score,b,l,u)=blu[i];
        acc[i]=score-l*b;
        if(i>0) acc[i]+=acc[i-1];
    }

    auto sum=[&](i64 l,i64 r){
        // [l, r]
        if(l>r) return i64(0);
        if(r<0) return i64(0);
        if(l>=N) return i64(0);
        assert(l<=r);
        assert(l>=0);
        assert(r<=N-1);
        i64 res=acc[r];
        if(l>0) res-=acc[l-1];
        return res;
    };

    vector<i64> acc2(N);
    rep(i,0,N){
        i64 score,b,l,u;
        tie(score,b,l,u)=blu[i];
        acc2[i]=l*-b;
        if(i>0) acc2[i]+=acc2[i-1];
    }

    auto sum2=[&](i64 l,i64 r){
        if(l>r) return i64(0);
        if(r<0) return i64(0);
        if(l>=N) return i64(0);
        assert(l<=r);
        assert(l>=0);
        assert(r<=N-1);
        i64 res=acc2[r];
        if(l>0) res-=acc2[l-1];
        return res;
    };

    auto ok=[&](i64 s){
        if(s>=N*X) return true;

        i64 num=s/X,rem=s%X;

        rep(i,0,num){
            i64 score,b,l,u;
            tie(score,b,l,u)=blu[i];

            i64 sum_score=sum(0,i-1);
            sum_score+=rem<b?l*(rem-b):u*(rem-b);
            sum_score+=sum(i+1,num);
            sum_score+=sum2(num+1,N-1);
            if(sum_score>=0){
                return true;
            }
        }

        rep(i,num,N){
            i64 score,b,l,u;
            tie(score,b,l,u)=blu[i];

            i64 sum_score=sum(0,num-1);
            sum_score+=sum2(num,i-1);
            sum_score+=rem<b?l*(rem-b):u*(rem-b);
            sum_score+=sum2(i+1,N-1);
            if(sum_score>=0){
                return true;
            }
        }

        return false;
    };

    i64 lb=0,ub=inf64;
    while(ub-lb>1){
        i64 mid=(lb+ub)/2;
        if(ok(mid)) ub=mid;
        else lb=mid;
    }

    cout << ub << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 8688