func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   long double pi = 3.1415926535897932384626433832795;   long long mod = 1e9 + 7;   const int N = 1e6 + 10;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   vector<vector<long long> > e(int n) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < n; j++) {         if (i == j)           v.push_back(1);         else           v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > zero(int n, int m) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < m; j++) {         v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > operator^(vector<vector<long long> > b,                                        vector<vector<long long> > a) {     int n = b.size(), m = a[0].size(), K = a.size();     vector<vector<long long> > c = zero(n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < K; k++) {           c[i][j] += b[i][k] * a[k][j];           c[i][j] %= mod;         }       }     }     return c;   }   vector<vector<long long> > bin_pow(vector<vector<long long> > a, long long pw) {     int n = a.size();     vector<vector<long long> > res = e(n);     while (pw) {       if (pw & 1ll) res = res ^ a;       a = a ^ a;       pw >>= 1;     }     return res;   }   long long n, k;   int main() {     cin >> n >> k;     vector<vector<long long> > ans = zero(1, 16);     ans[0][0] = 1;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       b = min(b, k);       long long pw = b - a;       vector<vector<long long> > m = zero(c + 1, c + 1);       ans[0].resize(c + 1);       for (int i = 0; i <= c; i++) {         for (int j = -1; j <= +1; j++) {           int ni = i + j;           if (ni < 0 || ni > c) continue;           m[i][ni] = 1;         }       }       m = bin_pow(m, pw);       ans = ans ^ m;     }     cout << ans[0][0];     return 0;   }   