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;
using lint = long long int;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T>
void ndarray(vector<T> &vec, int len) {
  vec.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec) ndarray(v, args...);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "deq[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
constexpr int MOD = 1000000007;
int N, T;
constexpr int M = 25;
vector<vector<int>> build_mat(vector<int> t) {
  sort(t.rbegin(), t.rend());
  int nmax = min(M, (int)t.size());
  int tmax = accumulate(t.begin(), t.begin() + nmax, 0);
  vector<vector<int>> ret(nmax + 1, vector<int>(tmax + 1));
  ret[0][0] = 1;
  for (auto v : t) {
    for (int n = (nmax)-1, n_begin_ = (0); n >= n_begin_; n--)
      for (int j = (tmax - v + 1) - 1, j_begin_ = (0); j >= j_begin_; j--) {
        ret[n + 1][j + v] += ret[n][j];
        if (ret[n + 1][j + v] >= MOD) ret[n + 1][j + v] -= MOD;
      }
  }
  return ret;
}
int main() {
  cin >> N >> T;
  vector<vector<int>> t(3);
  for (int _ = (0), __end_ = (N); _ < __end_; _++) {
    int s, g;
    cin >> s >> g;
    t[g - 1].push_back(s);
  }
  vector<vector<vector<int>>> mat(3);
  for (int i = (0), i_end_ = (3); i < i_end_; i++) mat[i] = build_mat(t[i]);
  vector<vector<vector<vector<int>>>> dp;
  ndarray(dp, M + 1, M + 1, M + 1, 4);
  for (int d = (0), d_end_ = (4); d < d_end_; d++) dp[0][0][0][d] = 1;
  for (int i = (0), i_end_ = (M + 1); i < i_end_; i++)
    for (int j = (0), j_end_ = (M + 1); j < j_end_; j++)
      for (int k = (0), k_end_ = (M + 1); k < k_end_; k++)
        if (i + j + k) {
          lint tmp3 = 0;
          if (i) tmp3 += (lint)dp[i - 1][j][k][0] * i;
          if (j) tmp3 += (lint)dp[i][j - 1][k][1] * j;
          if (k) tmp3 += (lint)dp[i][j][k - 1][2] * k;
          dp[i][j][k][3] = tmp3 % MOD;
          for (int d = (0), d_end_ = (3); d < d_end_; d++) {
            lint tmp = 0;
            for (int dd = (0), dd_end_ = (3); dd < dd_end_; dd++)
              if (dd != d) {
                if (i and dd == 0) tmp += (lint)dp[i - 1][j][k][dd] * i;
                if (j and dd == 1) tmp += (lint)dp[i][j - 1][k][dd] * j;
                if (k and dd == 2) tmp += (lint)dp[i][j][k - 1][dd] * k;
              }
            dp[i][j][k][d] = tmp % MOD;
          }
        }
  int ret = 0;
  int N0 = mat[0].size() - 1, T0 = mat[0][0].size() - 1;
  int N1 = mat[1].size() - 1, T1 = mat[1][0].size() - 1;
  int N2 = mat[2].size() - 1, T2 = mat[2][0].size() - 1;
  for (int t0 = (0), t0_end_ = (T0 + 1); t0 < t0_end_; t0++)
    for (int t1 = (0), t1_end_ = (min(T1, T - t0) + 1); t1 < t1_end_; t1++) {
      int t2 = T - t0 - t1;
      if (t2 < 0 or t2 > T2) continue;
      for (int n0 = (0), n0_end_ = (N0 + 1); n0 < n0_end_; n0++)
        if (mat[0][n0][t0])
          for (int n1 = (0), n1_end_ = (N1 + 1); n1 < n1_end_; n1++)
            if (mat[1][n1][t1])
              for (int n2 = (0), n2_end_ = (N2 + 1); n2 < n2_end_; n2++)
                if (mat[2][n2][t2]) {
                  ret += (lint)mat[0][n0][t0] * mat[1][n1][t1] % MOD *
                         mat[2][n2][t2] % MOD * dp[n0][n1][n2][3] % MOD;
                  if (ret >= MOD) ret -= MOD;
                }
    }
  cout << ret << endl;
}