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

const int N = 100005;

int n, x;
long long lim = 0;

struct test {
    int b, l, r;

    long long val() const {
        return 1LL * b * l + 1LL * (x - b) * r;
    }
} a[N];

long long get_max(long long u) {
    int cnt = u / x;
    long long pre = 0, mx = 0;
    for (int i = 1; i <= cnt; i++) {
        pre += a[i].val();
    }
    u %= x;
    for (int i = 1; i <= n; i++) {
        long long cur = pre;
        if (i <= cnt) {
            cur -= a[i].val();
            cur += a[cnt + 1].val();
        }
        mx = max(mx, cur + min(1LL * a[i].b, u) * a[i].l + max(0LL, u - a[i].b) * a[i].r);
    }
    return mx;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].b >> a[i].l >> a[i].r;
        lim += 1LL * a[i].b * a[i].l;
    }
    sort(a + 1, a + n + 1, [](const test &a, const test &b) {
        return a.val() > b.val();
    });
    long long le = 0, ri = 1LL * x * n - 1;
    while (le <= ri) {
        long long mi = (le + ri) / 2;
        if (get_max(mi) >= lim) {
            ri = mi - 1;
        } else {
            le = mi + 1;
        }
    }
    cout << le << '\n';
}
