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 mod = 1000000007;
int n, t, i, j, k, l, a[52], b[52], n1[4], m[4], fac[52];
int f1[52][2502], f2[52][52][2502], g[52][52][52][4];
int read() {
  char c = getchar();
  int w = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') {
    w = w * 10 + c - '0';
    c = getchar();
  }
  return w;
}
int main() {
  n = read();
  t = read();
  for (i = 1; i <= n; i++) {
    a[i] = read();
    b[i] = read();
    n1[b[i]]++;
    m[b[i]] += a[i];
  }
  for (i = fac[0] = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
  f1[0][0] = f2[0][0][0] = 1;
  for (i = 1; i <= n; i++) {
    if (b[i] != 1) continue;
    for (j = n1[1]; j >= 1; j--) {
      for (k = m[1]; k >= a[i]; k--)
        f1[j][k] = (f1[j][k] + f1[j - 1][k - a[i]]) % mod;
    }
  }
  for (i = 1; i <= n; i++) {
    if (b[i] == 2) {
      for (j = n1[2]; j >= 1; j--) {
        for (k = n1[3]; k >= 0; k--) {
          for (l = m[2] + m[3]; l >= a[i]; l--)
            f2[j][k][l] = (f2[j][k][l] + f2[j - 1][k][l - a[i]]) % mod;
        }
      }
    } else if (b[i] == 3) {
      for (j = n1[2]; j >= 0; j--) {
        for (k = n1[3]; k >= 1; k--) {
          for (l = m[2] + m[3]; l >= a[i]; l--)
            f2[j][k][l] = (f2[j][k][l] + f2[j][k - 1][l - a[i]]) % mod;
        }
      }
    }
  }
  g[1][0][0][1] = g[0][1][0][2] = g[0][0][1][3] = 1;
  for (i = 0; i <= n1[1]; i++) {
    for (j = 0; j <= n1[2]; j++) {
      for (k = 0; k <= n1[3]; k++) {
        if (i != 0) {
          if (j < n1[2])
            g[i][j + 1][k][2] = (g[i][j + 1][k][2] + g[i][j][k][1]) % mod;
          if (k < n1[3])
            g[i][j][k + 1][3] = (g[i][j][k + 1][3] + g[i][j][k][1]) % mod;
        }
        if (j != 0) {
          if (i < n1[1])
            g[i + 1][j][k][1] = (g[i + 1][j][k][1] + g[i][j][k][2]) % mod;
          if (k < n1[3])
            g[i][j][k + 1][3] = (g[i][j][k + 1][3] + g[i][j][k][2]) % mod;
        }
        if (k != 0) {
          if (i < n1[1])
            g[i + 1][j][k][1] = (g[i + 1][j][k][1] + g[i][j][k][3]) % mod;
          if (j < n1[2])
            g[i][j + 1][k][2] = (g[i][j + 1][k][2] + g[i][j][k][3]) % mod;
        }
      }
    }
  }
  int ans = 0;
  for (i = 0; i <= n1[1]; i++) {
    for (j = 0; j <= n1[2]; j++) {
      for (k = 0; k <= n1[3]; k++) {
        for (l = 0; l <= t; l++) {
          int res = (1LL * g[i][j][k][1] + g[i][j][k][2] + g[i][j][k][3]) % mod;
          res = 1LL * fac[i] * fac[j] % mod * fac[k] % mod * res % mod;
          ans =
              (ans + 1LL * f1[i][l] * f2[j][k][t - l] % mod * res % mod) % mod;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}