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 long long MOD = (long long)1e9 + 7;
const int N = 55;
const int M = 2505;
void print() { cout << "That's OK!" << endl; }
int tim[3], cnt[3], n, T, t[N], g[N];
long long tot[N][N][N][3], a[N][M], bc[N][N][M], ans = 0;
long long f(int x) {
  long long ret = 1;
  while (x > 1) ret = ret * x % MOD, x--;
  return ret % MOD;
}
long long F(int A, int B, int C) {
  long long ret = f(A) * f(B) % MOD * f(C) % MOD;
  ret = ret * (tot[A][B][C][0] + tot[A][B][C][1] + tot[A][B][C][2]) % MOD;
  return ret;
}
void add(long long &x, long long y) {
  x += y;
  if (x > MOD) x -= MOD;
}
void init() {
  scanf("%d%d", &n, &T);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &t[i], &g[i]);
    g[i]--;
    tim[g[i]] += t[i];
    cnt[g[i]]++;
  }
}
void ready_a() {
  a[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (g[i] != 0) continue;
    for (int j = cnt[0]; j >= 1; j--) {
      for (int k = t[i]; k <= tim[0]; k++) add(a[j][k], a[j - 1][k - t[i]]);
    }
  }
}
void ready_bc() {
  bc[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (g[i] == 0) continue;
    for (int j = cnt[1]; j >= 0; j--) {
      for (int k = cnt[2]; k >= 0; k--) {
        for (int r = t[i]; r <= tim[1] + tim[2]; r++) {
          if (g[i] == 1 && j > 0) add(bc[j][k][r], bc[j - 1][k][r - t[i]]);
          if (g[i] == 2 && k > 0) add(bc[j][k][r], bc[j][k - 1][r - t[i]]);
        }
      }
    }
  }
}
void ready_tot() {
  tot[1][0][0][0] = 1;
  tot[0][1][0][1] = 1;
  tot[0][0][1][2] = 1;
  for (int i = 0; i <= cnt[0]; i++) {
    for (int j = 0; j <= cnt[1]; j++) {
      for (int k = 0; k <= cnt[2]; k++) {
        if (i > 0) {
          add(tot[i][j][k][0], tot[i - 1][j][k][1]);
          add(tot[i][j][k][0], tot[i - 1][j][k][2]);
        }
        if (j > 0) {
          add(tot[i][j][k][1], tot[i][j - 1][k][0]);
          add(tot[i][j][k][1], tot[i][j - 1][k][2]);
        }
        if (k > 0) {
          add(tot[i][j][k][2], tot[i][j][k - 1][0]);
          add(tot[i][j][k][2], tot[i][j][k - 1][1]);
        }
      }
    }
  }
}
void Test(int i, int j, int k, int val0, int val12) {
  cout << i << " " << j << " " << k << " " << val0 << " " << val12 << ":"
       << endl;
  printf("a[%d][%d]=%lld\n", i, val0, a[i][val0]);
  printf("bc[%d][%d][%d]=%lld\n", j, k, val12, bc[j][k][val12]);
  for (int lst = 0; lst <= 2; lst++) {
    printf("tot[%d][%d][%d][%d]=%lld   ", i, j, k, lst, tot[i][j][k][lst]);
  }
  puts("");
}
void solve() {
  ready_a();
  ready_bc();
  ready_tot();
  for (int i = 0; i <= cnt[0]; i++) {
    for (int j = 0; j <= cnt[1]; j++) {
      for (int k = 0; k <= cnt[2]; k++) {
        for (int val0 = 0; val0 <= tim[0]; val0++) {
          int val12 = T - val0;
          add(ans, F(i, j, k) * a[i][val0] % MOD * bc[j][k][val12] % MOD);
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  init();
  solve();
  return 0;
}