#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, X;
ll b[100500], l[100500], u[100500];
vector<l_l> v;
int inv[100500];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    ll lose = 0;
    for(int i = 1; i <= N; i++) cin >> b[i] >> l[i] >> u[i];
    for(int i = 1; i <= N; i++) {
        v.emplace_back(u[i] * (X - b[i]) + l[i] * b[i], i);
        //cerr << v[i-1].first << endl;
        lose += l[i] * b[i];
    }
    v.push_back({1e18, 1e18});
    sort(v.begin(), v.end(), greater<l_l>());
    vector<ll> sum(N + 1);
    for(int i = 1; i <= N; i++) {
        inv[v[i].second] = i;
        sum[i] = sum[i-1] + v[i].first;
        cerr << i << " " << sum[i] << endl;
    }
    cerr << "LOSE " << lose << endl;
    ll ans = 1e18;
    for(int i = 1; i <= N; i++) {
        vector<ll>::iterator itr;
        ll rest;
        if(sum[i-1] + v[i].first >= lose) {
            //cerr << i << endl;
            itr = lower_bound(sum.begin(), sum.end(), lose - v[i].first);
            rest = lose - *itr;
        } else {
            itr = lower_bound(sum.begin(), sum.end(), lose);
            rest = lose - *itr + v[i].first;
        }
        ll nowans = (ll)distance(sum.begin(), itr) * X;
        if(sum[i-1] + v[i].first < lose) nowans -= X;
        int nowindex = v[i].second;
        if(rest < 0) {
            cerr << "NEGATIVE REST: " << i << " " << nowindex << endl;
            continue;
        }
        cerr << nowindex << " " << *itr << " " << nowans << " " << rest << endl;
        if(rest > v[i].first) continue;
        if(l[nowindex] * b[nowindex] >= rest) {
            //cerr << "A" << endl;
            nowans += (rest + l[nowindex] - 1) / l[nowindex];
        } else {
            nowans += b[nowindex] + (rest - b[nowindex] * l[nowindex] + u[nowindex] - 1) / u[nowindex];
            //cerr << "B" << endl;
            //cerr << rest << " "<< b[nowindex] << " " << u[nowindex] << endl;
        }
        //cerr << nowans << endl;
        chmin(ans, nowans);
    }
    cout << ans << endl;
    /*
    ll index = 0;
    while(true) {
        if(lose <= v[index].first) break;
        //cerr << "LOSE: " << lose << endl;
        lose -= v[index].first;
        index++;
    }
    //cerr << "C" << lose << endl;
    ll anssub = 1e18;
    for(int index2 = index; index2 < v.size(); index2++) {
        if(v[index2].first < lose) continue;
        int indexnow = v[index2].second;
        if(l[indexnow]*b[indexnow] >= lose) {
            chmin(anssub, (lose + l[indexnow] - 1) / l[indexnow]);
            //cerr << "A" << anssub << endl;
        } else {
            ll now = lose - l[indexnow] * b[indexnow];
            chmin(anssub, b[indexnow] + (now + u[indexnow] - 1) / u[indexnow]);
            //cerr << "B" << anssub << endl;
        }
    }
    cout << index * X + anssub << endl;
    */
    return 0;
}


Measured memory_bytes: 5488