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

typedef long long ll;
const int maxn = 100010;
int n, X, b[maxn], l[maxn], r[maxn], p[maxn];
ll s[maxn];

int main() {
    cin >> n >> X;
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> b[i] >> l[i] >> r[i];
        s[i] = 1LL * b[i] * l[i] + 1LL * (X - b[i]) * r[i];
        p[i] = i, sum += 1LL * b[i] * l[i];
    }
    if (!sum) { cout << 0 << endl; return 0; }
    sort(p + 1, p + n + 1, [&](int x, int y) { return s[x] > s[y]; });
    ll lb = 1, rb = 1LL * n * X, ans;
    while (lb <= rb) {
        ll mid = (lb + rb) >> 1;
        auto chk = [&](ll x) {
            auto calc = [&](int pos, ll tmp) {
                if (tmp <= b[pos]) return 1LL * tmp * l[pos];
                else return 1LL * b[pos] * l[pos] + 1LL * (tmp - b[pos]) * r[pos];
            };
            ll ans = 0, cur = 0;
            int r = x % X;
            if (!r) r = X;
            int cnt = (x - r) / X;
            for (int i = 1; i <= n; i++) {
                if (i <= cnt) {
                    cur += s[p[i]];
                } else {
                    ans = max(ans, cur + calc(p[i], r));
                }
            }
            cur += s[p[cnt + 1]];
            for (int i = 1; i <= cnt; i++) {
                ans = max(ans, cur - s[p[i]] + calc(p[i], r));
            }
            return ans;
        };
        chk(mid) >= sum ? rb = (ans = mid) - 1 : lb = mid + 1;
    }
    printf("%lld\n", ans);
    return 0;
}