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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = (int)1e9 + 7;
int add(int x, int y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
int mult(int x, int y) { return ((long long)x * y) % MOD; }
const int M = 2505;
const int N = 52;
vector<int> a[3];
int dp1[2][N / 3 + 1][N / 2 + 1][M];
int dp2[2][N][M];
int dp3[N][N][N][3];
int c[N][N][N];
int f[N];
int T;
int main() {
  dp3[1][0][0][0] = 1;
  dp3[0][1][0][1] = 1;
  dp3[0][0][1][2] = 1;
  for (int x = 0; x < N - 1; x++)
    for (int y = 0; y < N - 1; y++)
      for (int z = 0; z < N - 1; z++)
        for (int lst = 0; lst < 3; lst++) {
          int w = dp3[x][y][z][lst];
          if (w == 0) continue;
          c[x][y][z] = add(c[x][y][z], w);
          if (lst != 0) {
            dp3[x + 1][y][z][0] = add(dp3[x + 1][y][z][0], w);
          }
          if (lst != 1) {
            dp3[x][y + 1][z][1] = add(dp3[x][y + 1][z][1], w);
          }
          if (lst != 2) {
            dp3[x][y][z + 1][2] = add(dp3[x][y][z + 1][2], w);
          }
        }
  c[0][0][0] = 1;
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = mult(f[i - 1], i);
  for (int x = 0; x < N; x++)
    for (int y = 0; y < N; y++)
      for (int z = 0; z < N; z++) {
        c[x][y][z] = mult(mult(c[x][y][z], f[x]), mult(f[y], f[z]));
      }
  int n;
  scanf("%d%d", &n, &T);
  while (n--) {
    int x, y;
    scanf("%d%d", &x, &y);
    y--;
    a[y].push_back(x);
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 2; j++)
      if ((int)a[j].size() > (int)a[j + 1].size()) swap(a[j], a[j + 1]);
  dp1[0][0][0][0] = 1;
  n = (int)a[0].size();
  int m = (int)a[1].size();
  for (int q : a[0]) {
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) dp1[1][x][y][p] = 0;
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) {
          int w = dp1[0][x][y][p];
          if (w == 0) continue;
          dp1[1][x][y][p] = add(dp1[1][x][y][p], w);
          dp1[1][x + 1][y][p + q] = add(dp1[1][x + 1][y][p + q], w);
        }
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) dp1[0][x][y][p] = dp1[1][x][y][p];
  }
  for (int q : a[1]) {
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) dp1[1][x][y][p] = 0;
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) {
          int w = dp1[0][x][y][p];
          if (w == 0) continue;
          dp1[1][x][y][p] = add(dp1[1][x][y][p], w);
          dp1[1][x][y + 1][p + q] = add(dp1[1][x][y + 1][p + q], w);
        }
    for (int x = 0; x <= n; x++)
      for (int y = 0; y <= m; y++)
        for (int p = 0; p < M; p++) dp1[0][x][y][p] = dp1[1][x][y][p];
  }
  dp2[0][0][0] = 1;
  int k = (int)a[2].size();
  for (int q : a[2]) {
    for (int x = 0; x <= k; x++)
      for (int p = 0; p < M; p++) dp2[1][x][p] = 0;
    for (int x = 0; x <= k; x++)
      for (int p = 0; p < M; p++) {
        int w = dp2[0][x][p];
        if (w == 0) continue;
        dp2[1][x][p] = add(dp2[1][x][p], w);
        dp2[1][x + 1][p + q] = add(dp2[1][x + 1][p + q], w);
      }
    for (int x = 0; x <= k; x++)
      for (int p = 0; p < M; p++) dp2[0][x][p] = dp2[1][x][p];
  }
  int ans = 0;
  for (int x = 0; x <= n; x++)
    for (int y = 0; y <= m; y++)
      for (int z = 0; z <= k; z++)
        for (int q = 0; q <= T; q++) {
          int val = mult(dp1[0][x][y][T - q], dp2[0][z][q]);
          ans = add(ans, mult(val, c[x][y][z]));
        }
  printf("%d\n", ans);
  return 0;
}