// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

using TLL = tuple<ll, ll, ll>;
const ll inf = 1e9;

int main() {
    ll N, X;
    cin >> N >> X;
    V<TLL> tests(N);
    for(auto &t : tests) {
        ll b, l, u;
        cin >> b >> l >> u;
        t = make_tuple(b, l, u);
    }

    auto calc_max_val = [&](const TLL t) { return X * get<2>(t); };
    auto calc_best_val = [&](const TLL tl, ll t) {
        ll b, l, u;
        tie(b, l, u) = tl;
        if(t <= b) return make_pair(false, l * t);
        else return make_pair(true, u * t);
    };
    auto calc_aoki_val = [&](const TLL t, bool upper) {
        ll b, l, u;
        tie(b, l, u) = t;
        return b * (upper ? u : l);
    };
    auto calc_comp_val = [&](const TLL t) {
        ll b, l, u;
        tie(b, l, u) = t;
        ll x = (X - b) * u;
        ll y = b * l;
        return x + y;
    };
    sort(ALL(tests),
         [&](const auto t1, const auto t2) {
             return calc_comp_val(t1) > calc_comp_val(t2);
         });

    V<ll> tsum(N + 1);
    V<ll> aoki_u(N + 1, 0), aoki_l(N + 1, 0);
    for(ll i = 0; i < N; i++) {
        tsum[i + 1] = tsum[i] + calc_max_val(tests[i]);
        aoki_u[i + 1] = aoki_u[i] + calc_aoki_val(tests[i], true);
        aoki_l[i + 1] = aoki_l[i] + calc_aoki_val(tests[i], false);
    }

    DEBUG(aoki_u, aoki_l);
    if(aoki_u[N] == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = X * N;

    for(ll i = 0; i < N; i++) {
        auto is_ok = [&](ll mid) {
            ll xcnt = mid / X;
            ll tkhs = tsum[xcnt];
            ll aoki = aoki_u[xcnt] + (aoki_l[N] - aoki_l[xcnt]);
            if(mid % X == 0) return tkhs >= aoki;
            if(i <= xcnt - 1) {
                tkhs -= calc_max_val(tests[i]);
                tkhs += calc_max_val(tests[xcnt]);
                aoki -= calc_aoki_val(tests[i], true);
                aoki -= calc_aoki_val(tests[xcnt], false);
                aoki += calc_aoki_val(tests[xcnt], true);
            } else {
                aoki -= calc_aoki_val(tests[i], false);
            }
            auto bval = calc_best_val(tests[i], mid % X);
            tkhs += bval.second;
            aoki += calc_aoki_val(tests[i], bval.first);
            DEBUG(make_tuple(i, mid, tkhs, aoki, bval));
            return tkhs >= aoki;
        };

        ll ok = X * N, ng = 0;
        while(ok - ng > 1) {
            ll mid = (ok + ng) / 2;
            if(is_ok(mid)) ok = mid;
            else ng = mid;
        }
        DEBUG(ok);
        chmin(ans, ok);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992