func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<pair<long long, long long> > v[3];   vector<pair<long long, int> > segment[3];   struct matrix {     int arr[3][3];     matrix(array<int, 3> a1, array<int, 3> a2) {       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= 2; j++) {           if (!a1[i] and !a2[j] and abs(i - j) < 2) {             arr[i][j] = 1;           } else             arr[i][j] = 0;         }       }     }     matrix() {       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= 2; j++) {           if (i == j)             arr[i][j] = 1;           else             arr[i][j] = 0;         }       }     }   };   matrix mul(matrix a, matrix b) {     matrix c;     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= 2; j++) {         c.arr[i][j] = 0;         for (int k = 0; k <= 2; k++) {           c.arr[i][j] = (0ll + c.arr[i][j] +                          (1ll * a.arr[i][k] * b.arr[k][j]) % 1000000007) %                         1000000007;         }       }     }     return c;   }   matrix matexpo(matrix a, long long int steps) {     if (!steps) {       return matrix();     }     matrix temp = matexpo(a, steps / 2);     temp = mul(temp, temp);     if (steps % 2) {       temp = mul(temp, a);     }     return temp;   }   vector<int> get(vector<int> old_ans, array<int, 3> oldcur, array<int, 3> newcur,                   long long int steps) {     matrix alpha(oldcur, newcur);     matrix temp = matexpo(alpha, steps);     vector<int> loop_ans(3);     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= 2; j++) {         loop_ans[j] = (0ll + loop_ans[j] +                        (1ll * temp.arr[i][j] * old_ans[i]) % 1000000007) %                       1000000007;       }     }     return loop_ans;   }   void solve() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     vector<int> ans = {0, 1, 0};     array<int, 3> cur = {0, 0, 0};     for (int i = 1; i <= n; i++) {       long long int a, l, r;       scanf( %lld , &a);       scanf( %lld , &l);       scanf( %lld , &r);       v[a - 1].push_back({l, r});     }     for (int i = 0; i <= 2; i++) {       sort((v[i]).begin(), (v[i]).end());       stack<pair<long long, long long> > s1;       for (int j = 0; j <= (int)v[i].size() - 1; j++) {         if (s1.empty() or s1.top().second < (v[i][j].first - 1)) {           s1.push(v[i][j]);         } else {           s1.top().second = max(v[i][j].second, s1.top().second);         }       }       v[i].clear();       v[i].reserve(s1.size());       while (!s1.empty()) {         v[i].push_back(s1.top());         s1.pop();       }       reverse((v[i]).begin(), (v[i]).end());     }     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= (int)v[i].size() - 1; j++) {         segment[i].push_back({v[i][j].first, 1});         segment[i].push_back({v[i][j].second + 1, 0});       }       segment[i].push_back({m + 1, 0});     }     int i = 0, j = 0, k = 0;     long long int pos = 1;     while (true) {       long long int next =           min({segment[0][i].first, segment[1][j].first, segment[2][k].first});       long long int steps = next - pos - 1;       ans = get(ans, cur, cur, steps);       if (next == (m + 1)) {         printf( %d n , ans[1]);         return;       }       pos = next - 1;       array<int, 3> newcur = cur;       if (next == segment[0][i].first) {         newcur[0] = segment[0][i].second;         i++;       }       if (next == segment[1][j].first) {         newcur[1] = segment[1][j].second;         j++;       }       if (next == segment[2][k].first) {         newcur[2] = segment[2][k].second;         k++;       }       ans = get(ans, cur, newcur, 1);       cur = newcur;       pos++;     }   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }   