#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define fi first
#define se second

const int N = 1e5 + 5, inf = 1e18 + 123;
int n, x, b[N], l[N], r[N];

bool check (int lim) {
    int dist = 0;
    for (int i = 0; i < n; ++i) dist += 1LL * l[i] * b[i];
    vector< pair<int, int> > vec;
    for (int i = 0; i < n; ++i) vec.pb( { 1LL * (r[i] - l[i]) * b[i] - 1LL * x * r[i], i } );
    sort(vec.begin(), vec.end() );
    int lst = lim / x; lim %= x;

    if (lst < n) {
        int sum = 0, minn = inf;
        for (int i = 0; i <= lst; ++i) sum += vec[i].fi;
        for (int i = 0; i < n; ++i) {
            int tmp;
            if (lim >= b[ vec[i].se ]) tmp = (r[ vec[i].se ] - l[ vec[i].se ]) * b[ vec[i].se ] - lim * r[ vec[i].se ];
            else tmp = -lim * l[ vec[i].se ];
            if (i <= lst) minn = min(minn, sum - vec[i].fi + tmp);
            else minn = min(minn, sum - vec[lst].fi + tmp);
        }
        dist += minn;
    }
    else {
        for (int i = 0; i < n; ++i) dist += vec[i].fi;
    }

    return dist <= 0;
}

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> x;
    for (int i = 0; i < n; ++i) cin >> b[i] >> l[i] >> r[i];

    int L = 0, R = 1e10;
    while (L < R) {
        int mid = (L + R) >> 1;
        if (check(mid) ) R = mid;
        else L = mid + 1;
    }

    cout << L;

    return 0;
}
