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 ll = long long;
using ld = long double;
const ld eps = 1e-8;
template <class U, class V>
ostream& operator<<(ostream& out, const pair<U, V>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <size_t i, class T>
ostream& print_tuple_utils(ostream& out, const T& tup) {
  if constexpr (i == tuple_size<T>::value)
    return out << ")";
  else
    return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup),
                                       tup);
}
template <class... U>
ostream& operator<<(ostream& out, const tuple<U...>& tup) {
  return print_tuple_utils<0, tuple<U...>>(out, tup);
}
template <class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream&>::type operator<<(
    ostream& out, const Con& container) {
  out << "{";
  for (auto it = container.begin(); it != container.end(); ++it)
    out << (it == container.begin() ? "" : ", ") << *it;
  return out << "}";
}
template <int mod_>
struct modint {
  static constexpr int mod = mod_;
  int x;
  modint(int xx = 0) : x(xx) {}
  modint(ll xx) : x((int)(xx % mod)) {}
  friend inline modint operator+(modint u, const modint& v) { return u += v; }
  modint& operator+=(const modint& o) {
    if ((x += o.x) >= mod) x -= mod;
    return *this;
  }
  friend inline modint operator-(modint u, const modint& v) { return u -= v; }
  modint& operator-=(const modint& o) {
    if ((x -= o.x) < 0) x += mod;
    return *this;
  }
  friend inline modint operator*(modint u, const modint& v) { return u *= v; }
  modint& operator*=(const modint& o) { return *this = modint(1ll * x * o.x); }
  friend ostream& operator<<(ostream& out, const modint& u) {
    return out << u.x;
  }
};
using mint = modint<(int)1e9 + 7>;
const int maxn = 51;
const int maxt = 2501;
const int maxval = maxn * 2;
mint choose[maxval][maxval];
mint fac[maxval];
void precal() {
  for (int i = (int)(0); i < (int)(maxval); ++i) {
    choose[i][0] = 1;
    for (int f = (int)(1); f < (int)(i + 1); ++f)
      choose[i][f] = choose[i - 1][f] + choose[i - 1][f - 1];
  }
  fac[0] = 1;
  for (int i = (int)(1); i < (int)(maxval); ++i) fac[i] = fac[i - 1] * i;
}
int n, total_time;
vector<int> a[3];
mint dp01[maxt][maxn][maxn];
mint dp2[maxt][maxn];
mint dw[maxn][maxn][maxn][maxn];
int main() {
  precal();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> total_time;
  for (int i = (int)(0); i < (int)(n); ++i) {
    int t, g;
    cin >> t >> g;
    --g;
    a[g].push_back(t);
  }
  dp01[0][0][0] = 1;
  for (int i = (int)(0); i < (int)(((int)a[0].size())); ++i) {
    int x = a[0][i];
    for (int t = maxt - x; t--;) {
      for (int rest = (int)(0); rest < (int)(i + 1); ++rest) {
        dp01[t + x][rest + 1][0] += dp01[t][rest][0];
      }
    }
  }
  for (int i = (int)(0); i < (int)(((int)a[1].size())); ++i) {
    int x = a[1][i];
    for (int t = maxt - x; t--;) {
      for (int c0 = (int)(0); c0 < (int)(((int)a[0].size()) + 1); ++c0) {
        for (int rest = (int)(0); rest < (int)(i + 1); ++rest) {
          dp01[t + x][c0][rest + 1] += dp01[t][c0][rest];
        }
      }
    }
  }
  dp2[0][0] = 1;
  for (int i = (int)(0); i < (int)(((int)a[2].size())); ++i) {
    int x = a[2][i];
    for (int t = maxt - x; t--;) {
      for (int rest = (int)(0); rest < (int)(i + 1); ++rest) {
        dp2[t + x][rest + 1] += dp2[t][rest];
      }
    }
  }
  for (int i = (int)(0); i < (int)(((int)a[0].size()) + 1); ++i)
    dw[max(i - 1, 0)][i][0][0] = 1;
  for (int i = (int)(1); i < (int)(((int)a[1].size()) + 1); ++i) {
    for (int f = (int)(0); f < (int)(((int)a[0].size()) + 1); ++f) {
      int adj_same_prev = max(f - 1, 0);
      auto cur = dw[adj_same_prev][f][0][0];
      for (int cnt_gr = (int)(1); cnt_gr < (int)(i + 1); ++cnt_gr) {
        int new_adj = i - cnt_gr;
        for (int to_prev_same = (int)(0);
             to_prev_same < (int)(adj_same_prev + 1); ++to_prev_same) {
          int rest = f ? 2 : 1;
          if (cnt_gr < to_prev_same) continue;
          auto nw = choose[adj_same_prev][to_prev_same] *
                    choose[rest][cnt_gr - to_prev_same] *
                    choose[i - 1][cnt_gr - 1];
          dw[adj_same_prev - to_prev_same + new_adj][f][i][0] += cur * nw;
        }
      }
    }
  }
  for (int f = (int)(0); f < (int)(((int)a[0].size()) + 1); ++f)
    for (int g = (int)(0); g < (int)(((int)a[1].size()) + 1); ++g)
      for (int adj_same_prev = (int)(0); adj_same_prev < (int)(f + g + 1);
           ++adj_same_prev) {
        auto cur = dw[adj_same_prev][f][g][0];
        int rest = f + g + 1 - adj_same_prev;
        if (cur.x == 0) continue;
        if (0)
          cerr << "["
                  "f"
                  " = "
               << (f) << "] "
               << "["
                  "g"
                  " = "
               << (g) << "] "
               << "["
                  "adj_same_prev"
                  " = "
               << (adj_same_prev) << "] "
               << "["
                  "cur"
                  " = "
               << (cur) << "] " << endl;
        for (int i = (int)(max(1, adj_same_prev));
             i < (int)(((int)a[2].size()) + 1); ++i) {
          auto nw = choose[rest][i - adj_same_prev];
          dw[0][f][g][i] += cur * nw;
        }
      }
  mint ans = 0;
  for (int t01 = (int)(0); t01 < (int)(total_time + 1); ++t01) {
    int t2 = total_time - t01;
    for (int i = (int)(0); i < (int)(((int)a[0].size()) + 1); ++i)
      for (int f = (int)(0); f < (int)(((int)a[1].size()) + 1); ++f)
        for (int g = (int)(0); g < (int)(((int)a[2].size()) + 1); ++g) {
          if (dp01[t01][i][f].x == 0) continue;
          if (dp2[t2][g].x == 0) continue;
          if (0)
            cerr << "["
                    "t01"
                    " = "
                 << (t01) << "] "
                 << "["
                    "t2"
                    " = "
                 << (t2) << "] "
                 << "["
                    "i"
                    " = "
                 << (i) << "] "
                 << "["
                    "f"
                    " = "
                 << (f) << "] "
                 << "["
                    "g"
                    " = "
                 << (g) << "] " << endl;
          if (0)
            cerr << "["
                    "dp01[t01][i][f]"
                    " = "
                 << (dp01[t01][i][f]) << "] " << endl;
          if (0)
            cerr << "["
                    "dp2[t2][g]"
                    " = "
                 << (dp2[t2][g]) << "] " << endl;
          auto cur_ans = dp01[t01][i][f] * dp2[t2][g] * dw[0][i][f][g];
          cur_ans *= fac[i] * fac[f] * fac[g];
          ans += cur_ans;
        }
  }
  cout << ans;
  return 0;
}