import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias DF = Tuple!(size_t, "idx", long, "up");

long[10^^5+1] BS, LS, US, HIGH_PS, LOW_PS, A_SUM, B_SUM;
DF[10^^5] DFS;

void main()
{
    auto nx = readln.split.to!(int[]);
    auto N = nx[0];
    auto X = nx[1];

    long b_sum_org;
    foreach (i; 0..N) {
        auto blu = readln.split.to!(long[]);
        auto b = blu[0];
        auto l = blu[1];
        auto u = blu[2];
        BS[i] = b;
        LS[i] = l;
        US[i] = u;
        LOW_PS[i] = b * l;
        HIGH_PS[i] = b * u;
        b_sum_org += b * l;
        DFS[i] = DF(i, X * u - b * u);
    }

    if (b_sum_org == 0) {
        writeln(0);
        return;
    }

    sort!"a.up > b.up"(DFS[0..N]);

    foreach (i; 0..N+1) {
        if (!i) {
            A_SUM[i] = 0;
            B_SUM[i] = b_sum_org;
        } else {
            auto idx = DFS[i-1].idx;
            A_SUM[i] = A_SUM[i-1] + X * US[idx];
            B_SUM[i] = B_SUM[i-1] + HIGH_PS[idx] - LOW_PS[idx];
        }
    }

    long min_r, max_r = X * N;
    while (min_r + 1 != max_r) {
        auto mid_r = (min_r + max_r) / 2;
        bool can_win;
        auto len = mid_r / X;
        auto ap = mid_r % X;

        foreach (i; 0..N) {
            auto idx = DFS[i].idx;
            auto as = A_SUM[len];
            auto bs = B_SUM[len];
            if (i < len) {
                auto ldx = DFS[len].idx;
                as = as - X * US[idx] + X * US[ldx];
                bs = bs - HIGH_PS[idx] + LOW_PS[idx] - LOW_PS[ldx] + HIGH_PS[ldx];
            }
            if (ap < BS[idx]) {
                as += ap * LS[idx];
            } else {
                as += ap * US[idx];
                bs += HIGH_PS[idx] - LOW_PS[idx];
            }
            
            if (as >= bs) {
                can_win = true;
                break;
            }
        }

        if (can_win) {
            max_r = mid_r;
        } else {
            min_r = mid_r;
        }
    }

    writeln(max_r);
}