Problem: The only difference between easy and hard versions is constraints.

Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly T minutes.

In the player, Polycarp stores n songs, each of which is characterized by two parameters: t_i and g_i, where t_i is the length of the song in minutes (1 ≤ t_i ≤ 50), g_i is its genre (1 ≤ g_i ≤ 3).

Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the i-th song, he would spend exactly t_i minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.

Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.

Input

The first line of the input contains two integers n and T (1 ≤ n ≤ 50, 1 ≤ T ≤ 2500) — the number of songs in the player and the required total duration, respectively.

Next, the n lines contain descriptions of songs: the i-th line contains two integers t_i and g_i (1 ≤ t_i ≤ 50, 1 ≤ g_i ≤ 3) — the duration of the i-th song and its genre, respectively.

Output

Output one integer — the number of different sequences of songs, the total length of exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo 10^9 + 7 (that is, the remainder when dividing the quantity by 10^9 + 7).

Examples

Input


3 3
1 1
1 2
1 3


Output


6


Input


3 3
1 1
1 1
1 3


Output


2


Input


4 10
5 3
2 1
3 2
5 1


Output


10

Note

In the first example, Polycarp can make any of the 6 possible playlist by rearranging the available songs: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2] and [3, 2, 1] (indices of the songs are given).

In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of 2 possible ways: [1, 3, 2] and [2, 3, 1] (indices of the songs are given).

In the third example, Polycarp can make the following playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 4], [4, 1], [2, 3, 4] and [4, 3, 2] (indices of the songs are given).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int maxx = 2510;
const long long mod = 1e9 + 7;
int n, T;
long long dp[maxn][maxn][maxn][4], sum[maxn][maxn][maxn];
long long way[maxx][maxn][4], fac[maxn], ans = 0;
int b[4];
vector<int> a[4];
void init() {
  dp[1][0][0][1] = 1;
  dp[0][1][0][2] = 1;
  dp[0][0][1][3] = 1;
  sum[1][0][0] = 1;
  sum[0][1][0] = 1;
  sum[0][0][1] = 1;
  fac[0] = 1;
  for (int i = 0; i <= n; i++) {
    if (i) fac[i] = 1ll * fac[i - 1] * i % mod;
    b[1] = i;
    for (int j = 0; j <= n - i; j++) {
      b[2] = j;
      for (int k = 0; k <= n - i - j; k++) {
        b[3] = k;
        if (i + j + k == 1) continue;
        for (int t = 1; t < 4; t++) {
          if (b[t] == 0) continue;
          b[t]--;
          dp[i][j][k][t] =
              (mod + sum[b[1]][b[2]][b[3]] - dp[b[1]][b[2]][b[3]][t]) % mod;
          b[t]++;
          sum[i][j][k] += dp[i][j][k][t];
          sum[i][j][k] %= mod;
        }
      }
    }
  }
  for (int t = 1; t < 4; t++) {
    way[0][0][t] = 1;
    for (int i = 0; i < a[t].size(); i++) {
      for (int j = maxx - 1; j >= a[t][i]; j--) {
        for (int k = 1; k <= i + 1; k++)
          way[j][k][t] = (way[j][k][t] + way[j - a[t][i]][k - 1][t]) % mod;
      }
    }
  }
}
void solve(int i, int j, int k) {
  for (int ii = 0; ii <= a[1].size(); ii++) {
    if (way[i][ii][1] == 0) continue;
    for (int jj = 0; jj <= a[2].size(); jj++) {
      if (way[j][jj][2] == 0) continue;
      for (int kk = 0; kk <= a[3].size(); kk++) {
        if (way[k][kk][3] == 0) continue;
        long long tmp =
            way[i][ii][1] * way[j][jj][2] % mod * way[k][kk][3] % mod;
        long long tmp2 = fac[ii] * fac[jj] % mod * fac[kk] % mod;
        long long tmp3 = sum[ii][jj][kk];
        ans = (ans + tmp * tmp2 % mod * tmp3 % mod) % mod;
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> T;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[y].push_back(x);
  }
  init();
  for (int i = 0; i <= T; i++) {
    for (int j = 0; j <= T - i; j++) {
      int k = T - i - j;
      solve(i, j, k);
    }
  }
  cout << ans << "\n";
  return 0;
}