#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define FastIO cin.sync_with_stdio(false), cin.tie(nullptr)
#define pb push_back
#define fs first
#define sc second
#define mkp make_pair
#define endl '\n'

// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>& v);
template<typename T1, typename T2>
void _read(pair<T1, T2>& p);
template<typename T>
void _read(T& t) { cin >> t; }
template<typename T>
void _read(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_read(v[_i]); }
template<typename T1, typename T2>
void _read(pair<T1, T2>& p) { _read(p.first); _read(p.second); }
void _masterread() {}
template<typename T, typename... V>
void _masterread(T& t, V& ... v) { _read(t); _masterread(v...); }
#define re(...)_masterread(__VA_ARGS__)

template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>& v);
template<typename T1, typename T2>
void _print(pair<T1, T2>& p);
template<typename T>
void _print(T t) { cout << t; }
template<typename T>
void _print(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_print(v[_i]), cout << (_i == v.size() - 1 ? "" : " "); }
template<typename T1, typename T2>
void _print(pair<T1, T2>& p) { _print(p.first); cout << " "; _print(p.second); }
void _masterprint() { cout << endl; }
template<typename T, typename... V>
void _masterprint(T t, V... v) { _print(t); if (sizeof...(v))cout << " "; _masterprint(v...); }
#define pr(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1, typename T2>
void _debug(pair<T1, T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t) { cerr << t; }
template<typename T1, typename T2>
void _debug(pair<T1, T2> p) { cerr << "{"; _debug(p.first); cerr << ", "; _debug(p.second); cerr << "}"; }
template<typename T>
void _debug(vector<T>v) { cerr << "("; for (unsigned _i = 0; _i < v.size(); _i++)_debug(v[_i]), cerr << (_i == v.size() - 1 ? "" : ", "); cerr << ")"; }
void _masterdebug() { cerr << "]\n"; }
template<typename T, typename... V>
void _masterdebug(T t, V... v) { _debug(t); if (sizeof...(v))cerr << ", "; _masterdebug(v...); }
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#define int long long

void solve() {
	int n, c; re(n, c);
	vector<pair<int, pair<int, int>>> A(n); re(A);
	set<int> els;
	for (int i = 0; i < n; i++)
		els.insert(A[i].fs), els.insert(A[i].sc.fs);
	map<int, int> from, to;
	int idx = 0;
	for (int val : els) {
		to[idx] = val;
		from[val] = idx++;
	}
	//for (auto val : from)
	//	cout << val.fs << ' ' << val.sc << endl;
	for (int i = 0; i < n; i++)
		A[i].fs = from[A[i].fs], A[i].sc.fs = from[A[i].sc.fs];
	//debug(A);
	vector<int> P(idx + 1, 0);
	vector<int> E(idx + 1, 0);
	for (int i = 0; i < n; i++) {
		P[A[i].fs] += A[i].sc.sc;
		P[A[i].sc.fs] -= A[i].sc.sc;
		E[A[i].sc.fs] += A[i].sc.sc;
	}
	//debug(P);
	for (int i = 1; i <= idx; i++)
		P[i] += P[i - 1];
	//debug(P);
	int ans = 0;
	int prev = 0;
	for (int i = 0; i <= idx - 1; i++) {
		int cur = to[i];
		int nxt = to[i + 1];
		ans += min(c, E[i] + P[i]);
		ans += (nxt - cur - 1) * min(c, P[i]);
	}
	pr(ans);
}

signed main() {
	FastIO;
	/*int t;
	cin >> t;
	while (t--)*/
		solve();
}
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse4,fma")

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;

using f32 = double;
using f64 = long double;

using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;

using i16 = signed short;
using i32 = signed int;
using i64 = signed long long;

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpi = vector<pii>;

using rng = default_random_engine;


template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;


#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define sz(v) int(v.size())
#define all(v) begin(v), end(v)
#define popcnt __builtin_popcount

const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

const int INF = 2000069420;
const int M1 = 1'000'000'007;
const int M2 =	 998'244'353;
const int maxn = 1'000'005;
const int maxg = 2'005;
const int maxk = 19;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>,
	rb_tree_tag, tree_order_statistics_node_update>;


int a[maxn];


void solve() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a, a+n);
	
	ll S = 0, T = 0;
	for (int i = 0; i < n; ++i)
		T += a[i]*ll(i) - S, S += a[i];
	cout << T << '\n';
}



int main() {
	cin.tie(nullptr) ->
	sync_with_stdio(false);

	int T = 1; // cin >> T;
	while (T--) solve();
}