func_code_string: #include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   struct node {     long long x, l, r;   } a[10005];   long long b[20005];   int is[20005][4], ed[20005][4];   int l = 2;   struct Matrix {     long long v[3][3];     Matrix() { memset(v, 0, sizeof(v)); }     Matrix operator*(const Matrix B) {       Matrix C;       for (int i = 0; i <= l; i++)         for (int j = 0; j <= l; j++)           for (int k = 0; k <= l; k++) {             C.v[i][j] = (C.v[i][j] + v[i][k] * B.v[k][j]) % mod;           }       return C;     }   };   Matrix mtpow(Matrix A, long long k) {     int i;     Matrix B;     for (int i = 0; i <= l; i++) B.v[i][i] = 1;     while (k) {       if (k & 1) B = B * A;       A = A * A;       k >>= 1;     }     return B;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i].x >> a[i].l >> a[i].r;       b[++b[0]] = a[i].l;       b[++b[0]] = a[i].r;     }     b[++b[0]] = 1, b[++b[0]] = m;     sort(b + 1, b + b[0] + 1);     b[0] = unique(b + 1, b + b[0] + 1) - b - 1;     for (int i = 1; i <= n; i++) {       a[i].l = lower_bound(b + 1, b + b[0] + 1, a[i].l) - b;       a[i].r = lower_bound(b + 1, b + b[0] + 1, a[i].r) - b;       is[a[i].l][a[i].x]++, is[a[i].r + 1][a[i].x]--;       ed[a[i].r][a[i].x]++;     }     long long x1 = 0, x2 = 1, x3 = 0;     long long x11, x22, x33;     Matrix B;     for (int i = 0; i <= l; i++) {       for (int j = 0; j <= l; j++) {         if ((i == 0 && j == 2) || (i == 2 && j == 0))           B.v[i][j] = 0;         else           B.v[i][j] = 1;       }     }     for (int i = 2; i <= b[0]; i++) {       for (int j = 1; j <= 3; j++) is[i][j] += is[i - 1][j];       long long c = b[i] - b[i - 1] - 1;       Matrix temp = B;       for (int j = 1; j <= 3; j++) {         if (is[i - 1][j] - ed[i - 1][j] >= 1)           for (int k = 0; k <= 2; k++) temp.v[j - 1][k] = 0;       }       temp = mtpow(temp, c);       x11 = (temp.v[0][0] * x1 + temp.v[0][1] * x2 + temp.v[0][2] * x3) % mod;       x22 = (temp.v[1][0] * x1 + temp.v[1][1] * x2 + temp.v[1][2] * x3) % mod;       x33 = (temp.v[2][0] * x1 + temp.v[2][1] * x2 + temp.v[2][2] * x3) % mod;       x1 = (x11 + x22) % mod, x2 = (x11 + x22 + x33) % mod,       x3 = (x33 + x22) % mod;       if (is[i][1]) x1 = 0;       if (is[i][2]) x2 = 0;       if (is[i][3]) x3 = 0;     }     cout << x2 << endl;   }   