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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> struct BIT {
    int S;
    vector<T> v;

    BIT<T>(int _S) {
        S = _S;
        v.resize(S+1);
    }

    void update(int i, T k) {
        for(i++; i <= S; i += i&-i)
            v[i] = v[i] + k;
    }

    T read(int i) {
        T sum = 0;
        for(i++; i; i -= i&-i)
            sum = sum + v[i];
        return sum;
    }

    T read(int l, int r) {
        return read(r) - read(l-1);
    }

    /*
     * Returns in O(logS) the first index i such that read(i) >= sum.
     * Returns S if no such i exists.
     * Requires that read(i) is non-decreasing in i.
     */
    int lower_bound(T sum) {
        T res = 0;
        int inx = 0;
        for (int i = 31 - __builtin_clz(S); i >= 0; i--) {
            if ((inx + (1 << i) <= S) && res + v[inx + (1 << i)] < sum) {
                inx += 1 << i;
                res += v[inx];
            }
        }
        assert(inx != S);
        assert(read(inx) >= sum);
        return inx;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, X;
    cin >> N >> X;

    ll __cur = 0;
    vector<array<ll, 4>> exams(N);

    for (int i = 0, b, l, r; i < N; i++) {
        cin >> b >> l >> r;
        __cur += ll(b) * ll(l);
        exams[i] = { ll(l) * b + ll(r) * (X - b), b, l, r };
    }
    const ll cur = __cur;

    sort(all(exams));
    reverse(all(exams));

    BIT<ll> full(N + 1);
    for (int i = 0; i < N; i++) {
        full.update(i, exams[i][0]);
    }

    ll ans = cur ? (1 + full.lower_bound(cur)) * ll(X) : 0;
    assert(ans <= ll(N) * ll(X));

    for (int part = 0; part < N; part++) {
        const auto ex = exams[part];
        const ll mv = ex[0], b = ex[1], l = ex[2], r = ex[3];
        full.update(part, -mv);

        int use_rest = 0;
        ll got = 0;
        if (mv < cur) {
            ll need = cur - mv;
            int rest = full.lower_bound(need);
            assert(rest != N);
            got = full.read(rest);
            assert(got >= need);
            assert(rest != part);
            use_rest = rest > part ? rest : rest + 1;
        }

        if (got < cur && got + mv > cur) {
            ll cand = use_rest * ll(X);
            ll need = cur - got;

            ll take = min((need + l - 1) / l, b);
            if (take * l < need) {
                ll more = (need - take * l + r - 1) / r;
                assert(more <= X - b);
                assert(need - take * l - more * r <= 0);
                take += more;
                assert(take <= X);
            } else assert(need - take * l <= 0);

            ans = min(ans, cand + take);
        }

        full.update(part, mv);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4224