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;
inline char nc() {
  return getchar();
  static char buf[100000], *l = buf, *r = buf;
  return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)
             ? EOF
             : *l++;
}
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = nc();
  }
  x *= f;
}
const int mod = 1e9 + 7;
const int maxn = 50 + 5;
const int maxT = 2500 + 5;
int n, T;
int t[maxn], g[maxn];
int cnt;
int f[maxT][6000];
int rec[maxn][maxn][maxn][4];
bool vis[maxn][maxn][maxn][4];
struct data {
  int a, b, c;
  data(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
  inline bool operator<(const data &other) const {
    if (a != other.a) return a < other.a;
    if (b != other.b) return b < other.b;
    return c < other.c;
  }
  inline friend data operator+(const data &a, const int &b) {
    data re = a;
    if (b == 1) ++re.a;
    if (b == 2) ++re.b;
    if (b == 3) ++re.c;
    return re;
  }
} rnk[6000];
map<data, int> id;
inline int add(int x) { return x >= mod ? x - mod : x; }
inline int idx(data a) {
  if (!id.count(a)) {
    id[a] = ++cnt;
    rnk[cnt] = a;
    return cnt;
  }
  return id[a];
}
int tim;
void update(int a, int b, int T) {
  for (int i = T - a; i >= 0; --i) {
    int l = cnt;
    for (int j = 1; j <= l; ++j)
      if (f[i][j]) {
        int t = idx(rnk[j] + b);
        f[i + a][t] = add(f[i + a][t] + f[i][j]);
      }
  }
}
int dp(int a, int b, int c, int d) {
  if (a == 0 && b == 0 && c == 0) return 1;
  if (vis[a][b][c][d])
    return rec[a][b][c][d];
  else
    vis[a][b][c][d] = 1;
  int &re = rec[a][b][c][d] = 0;
  if (d != 1 && a) re = (re + (long long)dp(a - 1, b, c, 1) * a) % mod;
  if (d != 2 && b) re = (re + (long long)dp(a, b - 1, c, 2) * b) % mod;
  if (d != 3 && c) re = (re + (long long)dp(a, b, c - 1, 3) * c) % mod;
  return re;
}
int main() {
  read(n), read(T);
  f[0][idx(data())] = 1;
  for (int i = 1, s = 0; i <= n; ++i) {
    read(t[i]), read(g[i]), s += t[i];
    update(t[i], g[i], min(s, T));
  }
  int an = 0;
  for (int i = 1; i <= cnt; ++i)
    if (f[T][i]) {
      an =
          (an + (long long)dp(rnk[i].a, rnk[i].b, rnk[i].c, 0) * f[T][i]) % mod;
    }
  printf("%d\n", an);
  return 0;
}