#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int N = 100 + 13;
int n;
long long k;
pair<pair<long long, long long>, int> a[N];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (int i = 0; i < int(n); ++i)
    cin >> a[i].first.first >> a[i].first.second >> a[i].second;
  return true;
}
int add(int first, int second) {
  first += second;
  if (first < 0) first += MOD;
  if (first >= MOD) first -= MOD;
  return first;
}
int mul(int first, int second) { return first * 1ll * second % MOD; }
vector<vector<int>> mul(vector<vector<int>> a, vector<vector<int>> b) {
  int n = int((a).size());
  vector<vector<int>> c(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j)
      for (int k = 0; k < int(n); ++k)
        c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
  return c;
}
vector<vector<int>> binpow(vector<vector<int>> a, long long b) {
  int n = int((a).size());
  vector<vector<int>> res(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i) res[i][i] = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int dp[N][N];
void solve() {
  a[n - 1].first.second = k;
  a[n++] = make_pair(make_pair(k, k), 0);
  dp[0][0] = 1;
  for (int i = 0; i < int(n - 1); ++i) {
    int t = a[i].second + 1;
    vector<vector<int>> first(t, vector<int>(t, 0));
    for (int j = 0; j < int(t); ++j) {
      if (j > 0) first[j][j - 1] = 1;
      first[j][j] = 1;
      if (j + 1 < t) first[j][j + 1] = 1;
    }
    first = binpow(first, a[i].first.second - a[i].first.first);
    int nt = min(t, a[i + 1].second + 1);
    for (int j = 0; j < int(nt); ++j)
      for (int jj = 0; jj < int(t); ++jj)
        dp[i + 1][j] = add(dp[i + 1][j], mul(first[j][jj], dp[i][jj]));
  }
  cout << dp[n - 1][0] << endl;
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  if (read()) {
    solve();
  }
}

### Prompt

Develop a solution in Cpp to the problem described below:

Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (x, y) such that x and y are non-negative. Okabe starts at the origin (point (0, 0)), and needs to reach the point (k, 0). If Okabe is currently at the point (x, y), in one step he can go to (x + 1, y + 1), (x + 1, y), or (x + 1, y - 1).

Additionally, there are n horizontal line segments, the i-th of which goes from x = ai to x = bi inclusive, and is at y = ci. It is guaranteed that a1 = 0, an ≤ k ≤ bn, and ai = bi - 1 for 2 ≤ i ≤ n. The i-th line segment forces Okabe to walk with y-value in the range 0 ≤ y ≤ ci when his x value satisfies ai ≤ x ≤ bi, or else he might be spied on. This also means he is required to be under two line segments when one segment ends and another begins.

Okabe now wants to know how many walks there are from the origin to the point (k, 0) satisfying these conditions, modulo 109 + 7.

Input

The first line of input contains the integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of segments and the destination x coordinate.

The next n lines contain three space-separated integers ai, bi, and ci (0 ≤ ai < bi ≤ 1018, 0 ≤ ci ≤ 15) — the left and right ends of a segment, and its y coordinate.

It is guaranteed that a1 = 0, an ≤ k ≤ bn, and ai = bi - 1 for 2 ≤ i ≤ n.

Output

Print the number of walks satisfying the conditions, modulo 1000000007 (109 + 7).

Examples

Input

1 3
0 3 3


Output

4


Input

2 6
0 3 0
3 10 2


Output

4

Note

<image>

The graph above corresponds to sample 1. The possible walks are:

  * <image>
  * <image>
  * <image>
  * <image>

<image>

The graph above corresponds to sample 2. There is only one walk for Okabe to reach (3, 0). After this, the possible walks are:

  * <image>
  * <image>
  * <image>
  * <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int N = 100 + 13;
int n;
long long k;
pair<pair<long long, long long>, int> a[N];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (int i = 0; i < int(n); ++i)
    cin >> a[i].first.first >> a[i].first.second >> a[i].second;
  return true;
}
int add(int first, int second) {
  first += second;
  if (first < 0) first += MOD;
  if (first >= MOD) first -= MOD;
  return first;
}
int mul(int first, int second) { return first * 1ll * second % MOD; }
vector<vector<int>> mul(vector<vector<int>> a, vector<vector<int>> b) {
  int n = int((a).size());
  vector<vector<int>> c(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j)
      for (int k = 0; k < int(n); ++k)
        c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
  return c;
}
vector<vector<int>> binpow(vector<vector<int>> a, long long b) {
  int n = int((a).size());
  vector<vector<int>> res(n, vector<int>(n, 0));
  for (int i = 0; i < int(n); ++i) res[i][i] = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int dp[N][N];
void solve() {
  a[n - 1].first.second = k;
  a[n++] = make_pair(make_pair(k, k), 0);
  dp[0][0] = 1;
  for (int i = 0; i < int(n - 1); ++i) {
    int t = a[i].second + 1;
    vector<vector<int>> first(t, vector<int>(t, 0));
    for (int j = 0; j < int(t); ++j) {
      if (j > 0) first[j][j - 1] = 1;
      first[j][j] = 1;
      if (j + 1 < t) first[j][j + 1] = 1;
    }
    first = binpow(first, a[i].first.second - a[i].first.first);
    int nt = min(t, a[i + 1].second + 1);
    for (int j = 0; j < int(nt); ++j)
      for (int jj = 0; jj < int(t); ++jj)
        dp[i + 1][j] = add(dp[i + 1][j], mul(first[j][jj], dp[i][jj]));
  }
  cout << dp[n - 1][0] << endl;
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  if (read()) {
    solve();
  }
}

```