#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N, X;
    vector<Int> b, l, u;

    void sort_blu() {
        vector<Int> idx(N);
        iota(all(idx), 0);

        sort(all(idx), [&](Int i, Int j) {
            Int lval = (X - b[i]) * u[i] + b[i] * l[i];
            Int rval = (X - b[j]) * u[j] + b[j] * l[j];

            return lval > rval;
        });


        vector<Int> bb, ll, uu;
        for (auto e : idx) {
            bb.push_back(b[e]);
            ll.push_back(l[e]);
            uu.push_back(u[e]);
        }
        b = bb;
        l = ll;
        u = uu;
    }

    bool judge(Int z) {
        Int base = 0;
        for (int i = 0; i < N; ++i) {
            base -= l[i] * b[i];
        }

        Int m = z % X; //tyuutohanpa na tokoro
        Int d = (z - m) / X; //all toru, d <= N

        auto f = [&](int i, Int x) {
            if (x < b[i]) {
                return x * l[i];
            }
            return b[i] * l[i] + (x - b[i]) * u[i];
        };

        if (m == 0) {
            Int val = base;
            for (int i = 0; i < d; ++i) {
                val += f(i, X);
            }
            return val >= 0;
        }


        Int sum = 0;
        for (int i = 0; i < d; ++i) {
            sum += f(i, X);
        }

        for (int i = 0; i < N; ++i) {
            // i is tyutohanpa number
            Int val = sum + base;
            if (i < d) {
                val -= f(i, X);
                val += f(d, X);
            }
            val += f(i, m);
            if (val >= 0) return true;
        }
        return false;
    }

    void solve() {
        cin >> N >> X;
        for (int i = 0; i < N; ++i) {
            b.push_back(0);
            l.push_back(0);
            u.push_back(0);
            cin >> b.back() >> l.back() >> u.back();
        }
        sort_blu();

        Int ng = -1;
        Int ok = N * X;
        while (ok - ng > 1) {
            Int mid = (ok + ng) / 2;
            if (judge(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }

        cout << ok << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 6496