#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;

void solve() {
    ll N,C; cin >> N >> C;
    map<ll,ll> timeline;

    REP(i,N) {
        int a,b,c; cin >> a >> b >> c;
        timeline[a]+=c;
        timeline[b+1]-=c;
    }

    ll rui = 0;
    ll total = 0;
    ll bef = -1;
    for(const auto &p :timeline) {
        if (bef != -1) total += min(rui,C) * (p.first - bef - 1);
        rui += p.second;
        total += min(rui,C);
        bef = p.first;
    }

    cout << total << endl;
}

int main() {
    solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t LL;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 2e5 + 10;
int a[N], b[N], c[N];
vector<int> open[N + N], close[N + N];
vector<int> all;
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n, sub;
    cin >> n >> sub;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 1; i <= n; i++) {
        all.pb(a[i]);
        all.pb(b[i] + 1);
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    for (int i = 0; i < all.size(); i++) {
        mp[all[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        open[mp[a[i]]].pb(i);
        close[mp[b[i] + 1]].pb(i);
    }
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < all.size(); i++) {
        for (int j : close[i]) {
            sum -= c[j];
        }
        for (int j : open[i]) {
            sum += c[j];
        }
        if (i + 1 != all.size()) {
            ans += 1ll * (all[i + 1] - all[i]) * min((ll) sub, sum);
        }
    }
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
