#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ll,ll> pll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update>

#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)
#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

ll Lpow(ll a,ll b,ll M)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b%2)
			ans = (ans*a)%M;
		a = (a*a)%M;
		b = b/2;
	}
	return ans;
}


int main()
{
    fastio;
	
    ll n,C;
    cin >> n >> C;

    vector<pair<ll,ll>> arr(2*n);

    ll a,b,c;
    for(int i = 0;i<n;i++)
    {
        cin >> a >> b >> c;
        arr[2*i].first = a;
        arr[2*i].second = c;
        arr[2*i + 1].first = b + 1;
        arr[2*i + 1].second = -c;
    }

    sort(all(arr));

    ll curr = 0;
    ll ans = 0;

    for(int i = 0;i<2*n;i++)
    {
        curr = curr + arr[i].second;
        while(i + 1 < 2*n && arr[i].first == arr[i + 1].first)
        {
            curr = curr + arr[i+1].second;
            i++;
        }


        ll days = 0;
        if(i + 1 < 2*n)
            days = arr[i + 1].first - arr[i].first;

        ans += days*min(C,curr);
    } 

    cout << ans << endl;

	return 0;
}
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;






#define SIZE 200005

enum Which{
	COUNT,
	VAL,
};

enum Type{
	A,
	B,
};

struct Query{

	ll t,x,y;
};

ll num_A,num_B;
ll N,a[SIZE],b[SIZE];
ll BIT[SIZE][2][2];
map<ll,ll> MAP,REV;
Query query[SIZE];


void add(ll loc,ll value,Which which,Type type){

	BIT[loc][which][type] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc][which][type] += value;
		loc += loc & -loc;
	}
}

ll getSum(ll loc,Which which,Type type){

	if(loc == 0)return 0;

	ll sum = BIT[loc][which][type];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc][which][type];
		loc -= loc & -loc;
	}
	return sum;
}

int main(){

	int num_Q;
	scanf("%lld %lld %d",&num_A,&num_B,&num_Q);

	for(ll i = 1; i <= num_A; i++){

		a[i] = 0;
	}
	for(ll i = 1; i <= num_B; i++){

		b[i] = 0;
	}

	vector<ll> vec;
	vec.push_back(0);

	for(int i = 0; i < num_Q; i++){

		scanf("%lld %lld %lld",&query[i].t,&query[i].x,&query[i].y);
		vec.push_back(query[i].y);
	}

	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	for(int i = 0; i < vec.size(); i++){

		MAP[vec[i]] = i+1;
		REV[(i+1)] = vec[i];
	}

	ll ans = 0;

	N = vec.size();

	for(ll i = 0; i <= N; i++){
		for(int k = 0; k < 2; k++){
			for(int p = 0; p < 2; p++){

				BIT[i][k][p] = 0;
			}
		}
	}


	add(MAP[0],num_A,COUNT,A);
	add(MAP[0],num_B,COUNT,B);


	for(int i = 0; i < num_Q; i++){

		ll loc = query[i].x;

		if(query[i].t == 1){ //Aを操作

			if(a[loc] == query[i].y){

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


			ll pre = a[loc];

			ans -= pre*getSum(MAP[pre],COUNT,B); //前の値の加算値


			if(pre < query[i].y){ //大きくなった

				ans -= getSum(MAP[query[i].y],VAL,B)-getSum(MAP[pre],VAL,B); //

			}else{ //小さくなった

				ans += getSum(MAP[pre],VAL,B)-getSum(MAP[query[i].y],VAL,B);
			}

			ans += query[i].y*getSum(MAP[query[i].y],COUNT,B);

			a[loc] = query[i].y;

			add(MAP[pre],-1,COUNT,A);
			add(MAP[pre],-pre,VAL,A);

			add(MAP[query[i].y],1,COUNT,A);
			add(MAP[query[i].y],query[i].y,VAL,A);

		}else{

			if(b[loc] == query[i].y){

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


			ll pre = b[loc];

			//printf("B: pre:%lld\n",pre);

			ll tmp = pre*getSum(MAP[pre]-1,COUNT,A); //前の値の加算値

			//printf("前の加算地:%lldをマイナス\n",tmp);
			ans -= tmp;

			if(pre < query[i].y){ //大きくなった

				tmp = getSum(MAP[query[i].y]-1,VAL,A)-getSum(MAP[pre]-1,VAL,A);
				//printf("大きくなったので%lldをマイナス\n",tmp);
				ans -= tmp;

			}else{ //小さくなった

				tmp = getSum(MAP[pre]-1,VAL,A)-getSum(MAP[query[i].y]-1,VAL,A);
				//printf("小さくなったので%lldをプラス\n",tmp);
				ans += tmp;
			}

			//printf("ここまでのans:%lld\n",ans);

			tmp = query[i].y*getSum(MAP[query[i].y]-1,COUNT,A);
			//printf("今回は%lldを加算\n",tmp);
			ans += tmp;

			b[loc] = query[i].y;

			add(MAP[pre],-1,COUNT,B);
			add(MAP[pre],-pre,VAL,B);

			add(MAP[query[i].y],1,COUNT,B);
			add(MAP[query[i].y],query[i].y,VAL,B);

		}

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


	return 0;
}
