#include <bits/stdc++.h>
#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define CREP(i, l, r) for(int i = l; i <= r; i++)
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> T; 
typedef pair<ll,ll> P;
typedef vector<int> V;
typedef vector<ll> Vll;
const int INF = 1000000000;      //10^9, 2*INF
const ll LLINF = (1LL << 60);   // > 10^18 ll  2*LLINF

int main() {
    int n;
    ll co;
    cin >> n >> co;
    Vll a(n), b(n), c(n); rep(i, n) scanf("%lld%lld%lld", &a[i],&b[i],&c[i]);

    vector<P> ac(n), bc(n);
    rep(i,n){
        ac[i] = P(a[i],c[i]);
        bc[i] = P(b[i],c[i]);
    }

    sort(ac.begin(),ac.end());
    sort(bc.begin(),bc.end());

    ac.emplace_back(P(LLINF,LLINF));
    bc.emplace_back(P(LLINF,LLINF));


    ll pc = 0, day = 0, ans = 0;
    int aci=0,bci = 0;
    bool snk = false;
    while(aci < n || bci < n){
        ll nday = min(ac[aci].first, bc[bci].first);
        ans += (snk ? co : pc)*(nday-day);
        day = nday;

        while(aci < n && ac[aci].first == day) {
            pc += ac[aci].second;
            aci++;
        }
        if(pc > co) snk = true;
        else snk = false;
        ans += (snk ? co : pc);
        while(bci < n && bc[bci].first == day) {
            pc -= bc[bci].second;
            bci++;
        }
        if(pc > co) snk = true;
        else snk = false;
        day++;
        //printf("day %lld\n", day);
    }

    printf("%lld\n", ans);
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Num {
	int in;
	int out;
	long long cost;
};

Num nums[200010];
int n;

struct Event {
	int type;
	int cost;
	int t;
	
    bool operator < (const Event &a) const {
    	int x = abs(this->t);
    	int ax = abs(a.t);
        return x>ax;//最小值优先
    }
};

long long c;

int main()
{
	scanf("%d%lld", &n, &c);
	
	std::priority_queue<Event> q;
	
	for (int i = 0 ; i < n ; i++) {
		scanf("%d%d%lld", &(nums[i].in), &(nums[i].out), &(nums[i].cost));
		Event inEvent;
		inEvent.cost = nums[i].cost;
		inEvent.type = 1;	//in
		inEvent.t = nums[i].in;
		q.push(inEvent);
		
		Event outEvent;
		outEvent.cost = nums[i].cost;
		outEvent.type = -1;
		outEvent.t = nums[i].out + 1;
		q.push(outEvent);
	}
	
	long long totalCost = 0;
	long long curCost = 0;
	int lastTime = 0;
	int curTime;
	
	while (!q.empty()) {
		Event curEvent = q.top();
		
		curTime = curEvent.t;
		if (curCost < c) {
			totalCost = totalCost + (curTime - lastTime) * curCost;
		} else {
			totalCost = totalCost + (curTime - lastTime) * c;
		}
		
		
		while (curTime == curEvent.t) {
			q.pop();
			if (curEvent.type == 1) {
				curCost = curCost + curEvent.cost;
			} else {
				curCost = curCost - curEvent.cost;
			}
			
			if (q.empty()) {
				break;
			}
			
			curEvent = q.top();
		}
		
		lastTime = curTime;
	}
	
	
	
	printf("%lld\n", totalCost);
	
	return 0;
}
