func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long infl = 2e18;   const long long infi = 1e9;   const long long mod = 1000000007;   auto clk = clock();   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   long long rng(long long lim) {     uniform_int_distribution<long long> uid(0, lim - 1);     return uid(rang);   }   long long powm(long long a, long long b) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const long long N = 55;   long long dp[N][N][N][4];   vector<long long> sg[4];   long long knap[4][N][N * N];   long long fact[N];   long long inpe[N];   long long answ[N][N][N * N];   struct base {     long double x, y;     base() { x = y = 0; }     base(long double _x, long double _y) { x = _x, y = _y; }     base(long double _x) { x = _x, y = 0; }     void operator=(long double _x) { x = _x, y = 0; }     long double real() { return x; }     long double imag() { return y; }     base operator+(const base& b) { return base(x + b.x, y + b.y); }     void operator+=(const base& b) { x += b.x, y += b.y; }     base operator*(const base& b) {       return base(x * b.x - y * b.y, x * b.y + y * b.x);     }     void operator*=(const base& b) {       long double p = x * b.x - y * b.y, q = x * b.y + y * b.x;       x = p, y = q;     }     void operator/=(long double k) { x /= k, y /= k; }     base operator-(const base& b) { return base(x - b.x, y - b.y); }     void operator-=(const base& b) { x -= b.x, y -= b.y; }     base conj() { return base(x, -y); }     base operator/(long double k) { return base(x / k, y / k); }     void Print() { cerr << x <<   +   << y <<  i n ; }   };   long double PI = 2.0 * acosl(0.0);   const long long MAXN = 14;   const long long maxn = (1 << MAXN);   base W[maxn], invW[maxn], P1[maxn], Q1[maxn];   void precompute_powers() {     for (long long i = 0; i < maxn / 2; i++) {       long double ang = (2 * PI * i) / maxn;       long double _cos = cos(ang), _sin = sin(ang);       W[i] = base(_cos, _sin);       invW[i] = base(_cos, -_sin);     }   }   void fft(vector<base>& a, bool invert) {     long long n = (long long)a.size();     for (long long i = 1, j = 0; i < n; ++i) {       long long bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (long long len = 2; len <= n; len <<= 1) {       for (long long i = 0; i < n; i += len) {         long long ind = 0, add = maxn / len;         for (long long j = 0; j < len / 2; ++j) {           base u = a[i + j],                v = (a[i + j + len / 2] * (invert ? invW[ind] : W[ind]));           a[i + j] = (u + v);           a[i + j + len / 2] = (u - v);           ind += add;         }       }     }     if (invert)       for (long long i = 0; i < n; ++i) a[i] /= n;   }   void mul_big_mod(vector<long long>& a, vector<long long>& b, long long mod) {     long long n1 = a.size(), n2 = b.size();     long long final_size = a.size() + b.size() - 1;     long long n = 1;     while (n < final_size) n <<= 1;     vector<base> P(n), Q(n);     long long SQRTMOD = (long long)sqrt(mod) + 10;     for (long long i = 0; i < n1; i++)       P[i] = base(a[i] % SQRTMOD, a[i] / SQRTMOD);     for (long long i = 0; i < n2; i++)       Q[i] = base(b[i] % SQRTMOD, b[i] / SQRTMOD);     fft(P, 0);     fft(Q, 0);     base A1, A2, B1, B2, X, Y;     for (long long i = 0; i < n; i++) {       X = P[i];       Y = P[(n - i) % n].conj();       A1 = (X + Y) * base(0.5, 0);       A2 = (X - Y) * base(0, -0.5);       X = Q[i];       Y = Q[(n - i) % n].conj();       B1 = (X + Y) * base(0.5, 0);       B2 = (X - Y) * base(0, -0.5);       P1[i] = A1 * B1 + A2 * B2 * base(0, 1);       Q1[i] = A1 * B2 + A2 * B1;     }     for (long long i = 0; i < n; i++) P[i] = P1[i], Q[i] = Q1[i];     fft(P, 1);     fft(Q, 1);     a.resize(final_size);     for (long long i = 0; i < final_size; i++) {       long long x = (long long)(P[i].real() + 0.5);       long long y = (long long)(P[i].imag() + 0.5) % mod;       long long z = (long long)(Q[i].real() + 0.5);       a[i] = (x + ((y * SQRTMOD + z) % mod) * SQRTMOD) % mod;     }   }   void solve() {     precompute_powers();     fact[0] = 1;     for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % mod;     dp[0][0][0][0] = 1;     for (long long i = 0; i <= 50; i++)       for (long long j = 0; j <= 50; j++)         for (long long k = 0; k <= 50; k++) {           for (long long l = 0; l <= 3; l++)             if (l != 1) {               dp[i + 1][j][k][1] += dp[i][j][k][l];               dp[i + 1][j][k][1] %= mod;             }           for (long long l = 0; l <= 3; l++)             if (l != 2) {               dp[i][j + 1][k][2] += dp[i][j][k][l];               dp[i][j + 1][k][2] %= mod;             }           for (long long l = 0; l <= 3; l++)             if (l != 3) {               dp[i][j][k + 1][3] += dp[i][j][k][l];               dp[i][j][k + 1][3] %= mod;             }         }     long long n, t;     cin >> n >> t;     for (long long i = 1; i <= n; i++) {       long long ti, gi;       cin >> ti >> gi;       sg[gi].push_back(ti);     }     for (long long j = 1; j <= 3; j++) {       knap[j][0][0] = 1;       for (long long i : sg[j]) {         for (long long l = ((long long)sg[j].size()) - 1; l >= 0; l--)           for (long long k = t - i; k >= 0; k--) {             knap[j][l + 1][k + i] += knap[j][l][k];             knap[j][l + 1][k + i] %= mod;           }       }     }     for (long long i = 1; i <= 3; i++)       for (long long j = 0; j <= ((long long)sg[i].size()); j++)         for (long long k = 0; k <= t; k++)           knap[i][j][k] = (knap[i][j][k] * fact[j]) % mod;     long long ans = 0;     if (((long long)sg[1].size()) > ((long long)sg[3].size())) {       swap(sg[1], sg[3]);       swap(knap[1], knap[3]);     }     if (((long long)sg[2].size()) > ((long long)sg[3].size())) {       swap(sg[2], sg[3]);       swap(knap[2], knap[3]);     }     vector<long long> ho1(t + 1), ho2(t + 1), res;     for (long long i = 0; i <= ((long long)sg[1].size()); i++) {       for (long long j = 0; j <= ((long long)sg[2].size()); j++) {         ho1.resize(t + 1);         for (long long k = 0; k <= t; k++) {           ho1[k] = knap[1][i][k];           ho2[k] = knap[2][j][k];         }         mul_big_mod(ho1, ho2, mod);         for (long long k = 0; k <= t; k++) answ[i][j][k] = ho1[k];       }     }     for (long long i = 0; i <= ((long long)sg[1].size()); i++) {       for (long long j = 0; j <= ((long long)sg[2].size()); j++) {         for (long long k = 0; k <= ((long long)sg[3].size()); k++) {           for (long long l = 0; l <= t; l++) {             long long o = t - l;             long long te =                 dp[i][j][k][0] + dp[i][j][k][1] + dp[i][j][k][2] + dp[i][j][k][3];             te = (te * answ[i][j][l]) % mod;             ans = (ans + te * knap[3][k][o]) % mod;           }         }       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     cout << fixed << setprecision(10);     long long t = 1;     for (long long i = 1; i <= t; i++) solve();     return 0;   }   