#include <bits/stdc++.h>

using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;

#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)


template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
 cout << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ; 
OUT(rest...);
   return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = int(1e9);
const long long int INFL = (long long int)1e18;

int n,m,k;
string S;
int ans;

void solve()
{
  int N;
  ll C; IN(N,C);
  vector<pair<int,int>> eve(2*N);
  for(int i=0;i < 2*N; i+= 2)
  {
    int a,b,c;IN(a,b,c);
    eve[i] = {a,c};
    eve[i+1] = {b+1,-c};
  }
  sort(eve.begin(),eve.end());
  ll ans = 0;
  ll cost = 0;
  int day = 1;
  rep(i,2*N)
  {
    auto e = eve[i];
    ll t = e.first - day;
    day = e.first;
    if(cost > C)ans += t * C;
    else ans += t * cost;
    cost += e.second;
  }
  cout << ans << endl;
}

signed main (int argc, char* argv[]) 
{
   cin.tie(0);
   ios::sync_with_stdio(false);
   int cases=1;
   //IN(cases);
   while(cases--)solve();
   //pri(ans);
   //for(auto c : ans){cout << c << endl;}
   //cout << fixed << setprecision(15) << ans << endl;
   return 0;
}
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) rep2(i,0,n)
#define rep1(i,n) rep2(i,1,n+1)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,t[2222],l[2222],r[2222],ans=0;
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>t[i]>>l[i]>>r[i];
		if(t[i]%2==0) r[i]-=1;
		if(t[i]>2) l[i]+=1;
	}
	rep(i,n)
	rep2(j,i+1,n)
	{
		if((l[i]<=r[j]&&r[i]>=l[j])||(l[j]<=r[i]&&r[j]>=l[i])||(r[j]+1==l[i]&&t[j]%2==0&&t[i]>2)||(r[i]+1==l[j]&&t[i]%2==0&&t[j]>2)) ans++;
	}
	re(ans)
	return 0;}