#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main()
{
#ifdef iq
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll x;
    cin >> n >> x;
    vector <ll> b(n), l(n), u(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> l[i] >> u[i];
    }
    vector <pair <ll, int> > ok;
    ll inf = (ll) (1e18);
    ll sum = 0;
    auto f = [&] (ll val) {
        if (ok.empty()) {
            for (int i = 0; i < n; i++) {
                ll ret = l[i] * (0 - b[i]);
                ll new_ret = u[i] * (x - b[i]);
                ok.emplace_back(new_ret - ret, i);
                sum += ret;
            }
            sort(ok.rbegin(), ok.rend());
        }
        vector <ll> sm;
        for (auto c : ok) {
            if (sm.empty()) sm.push_back(c.first);
            else sm.push_back(sm.back() + c.first);
        }
        ll ans = inf;
        for(int i = 0; i < n; i++) {
            int id = ok[i].second;
            vector <ll> values = {l[id] * (val - b[id]), u[id] * (val - b[id])};
            ll trash = u[id] * (x - b[id]) - l[id] * (0 - b[id]);
            sum -= l[id] * (0 - b[id]);
            for (ll value : values) {
                ll cur = sum + value;
                if (cur >= 0) {
                    ans = min(ans, val);
                    continue;
                }
                if (sm.back() - trash + cur < 0) {
                    continue;
                }
                int l = -1, r = n - 1;
                while (l < r - 1) {
                    int m = (l + r) / 2;
                    ll good = sm[m];
                    if (i <= m) good -= trash;
                    if (good + cur >= 0) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                ll good_sum = x * (r + 1);
                if (i <= r) good_sum -= x;
                ans = min(ans, good_sum + val);
            }
            sum += l[id] * (0 - b[id]);
        }
        return ans;
    };
    int start = 0;
    {
        int vl = -1, vr = x;
        while (vl < vr - 1) {
            int vm = (vl + vr) / 2;
            if (f(vm) < inf) {
                vr = vm;
            } else {
                vl = vm;
            }
        }
        start = vr;
    }
    vector <int> cands = {start, int(x)};
    {
        int vl = start-1, vr = x;
        while (vl < vr - 1) {
            int vm = (vl + vr) / 2;
            if (f(vm) >= f(0)) {
                vl = vm;
            } else {
                vr = vm;
            }
        }
        for (int y = max(0, vl - 10); y <= min(int(x), vl + 10); y++) {
            cands.push_back(y);
        }
    }
    {
        int vl = start-1, vr = x;
        while (vl < vr - 1) {
            int vm = (vl + vr) / 2;
            if (f(vm) > f(vm + 1)) {
                vl = vm;
            } else {
                vr = vm;
            }
        }
        for (int y = max(0, vl - 10); y <= min(int(x), vl + 10); y++) {
            cands.push_back(y);
        }
    }
    ll ans = inf;
    for (int y : cands) ans = min(ans, f(y));
    cout << ans << endl;
}


Measured memory_bytes: 6060