#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include<cassert>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)


///*�R���r�l�[�V����*/
//
///*Union Find*/
//#define MAX_N 200000
//#define MAX_M 200000
//vector<ll>par(MAX_N);
//vector<ll>ran(MAX_N);
//void init(ll N) {
//	rep(i, N) {
//		par[i] = i;
//		ran[i] = 0;
//	}
//}
//ll find(ll x) {
//	if (par[x] == x) {
//		return x;
//	}
//	else {
//		return par[x] = find(par[x]);
//	}
//}
////x��y�̑�����W���𕹍�
//void unite(ll x,ll y) {
//	x = find(x);
//	y = find(y);
//	if (x == y)return;
//	if (ran[x] < ran[y]) {
//		par[x] = y;
//
//	}
//	else {
//		par[y] = x;
//		if (ran[x] == ran[y])ran[x]++;
//	}
//}
//bool same(ll x, ll y) {
//	return find(x) == find(y);
//}
///*Union Find*
bool isPrime(int x) {
	int i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
	return 1;
}
int digsum(int n) {
	int res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}
ll p(int x, int y) {
	ll v = 1;
	rep(i, y) {
		v *= x;
	}
	return v;
}
long long MOD = 1e9 + 7;

long long modPow(long long x, long long a) {
	if (a == 1) return x;
	if (a % 2) return (x * modPow(x, a - 1));
	long long t = modPow(x, a / 2);
	return (t * t);
}

long long modInv(long long x) {
	return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
	long long ret = 1;
	for (long long i = 0; i < k; i++) {
		ret = (ret * (n - i));
	}
	return ret;
}

long long modComb(long long n, long long k) {
	long long a, b;
	a = modPerm(n, k);
	b = modPerm(k, k);
	return (a * modInv(b));
}
struct memo{
	ll time;
	ll money;
};
using vv =vector<vector<ll>>;
int N, X, cnt, a[10009];
int main() {
	int N;
	ll C;
	cin >> N >> C;
	vector<pair<ll,ll>>a(N), b(N);
	vector<pair<ll,ll>>A(2*N);
	vector<ll>c(N);
	map<ll,ll>m;
	rep(i, N) {
		cin >> a[i].first >> b[i].first >> c[i];
		b[i].first++;
		a[i].second = c[i];
		b[i].second = -c[i];
	}
	for (ll i = 0; i < N;i++) {
		A[2*i]=a[i];
		A[2 * i + 1] = b[i];
	}
	ll time = 0;
	sort(A.begin(), A.end());
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll money = 0;
	ll ans=0;
	m[0] = 0;
	rep(i,2*N){
		if (money <= C) {
			ans += (A[i].first-time) * money;
		}
		else {
			ans += (A[i].first - time) * C;
		}
		time = A[i].first;
		money += A[i].second;
	}
	cout << ans;
}
	

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, d;
  cin >> n >> d;
  map<int, ll> mp;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    mp[a] += c;
    mp[b + 1] -= c;
  }
  ll ans = 0;
  ll s = 0;
  int pre = 0;
  for (auto p : mp) {
    ans += min<ll>(d, s) * (p.first - pre);
    s += p.second;
    pre = p.first;
  }
  cout << ans << endl;
  return 0;
}
