#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  long long c;
  cin >> n >> c;

  vector<array<int, 2>> events;
  for (int i = 0; i < n; ++i) {
    int l, r, w;
    cin >> l >> r >> w;
    events.push_back({l, w});
    events.push_back({r + 1, -w});
  }
  sort(events.begin(), events.end());

  int prv = 0;
  long long ans = 0, sum = 0;
  for (auto [x, y] : events) {
    ans += (x - prv) * min(sum, c);
    sum += y;
    prv = x;
  }

  cout << ans << "\n";
}

#include <algorithm>
#include <iostream>
#include <cstdio>
#define ll long long
#define MOD 1000000007
using namespace std;

int main() {
    int t;
    ll n, a, b;
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        if(a+b > n) {
            cout << 0 << endl;
            continue;
        }
        ll ans = 0;
 
        ans = (n-a-b+1)*(n-a-b+2)%MOD*((2*(n-a+1)*(n-b+1)%MOD-(n-a-b+1)*(n-a-b+2)%MOD+MOD)%MOD)%MOD;
        cout << ans << endl;
    }
    return 0;
}