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;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
template <unsigned MOD_>
struct ModInt {
  static const unsigned MOD = MOD_;
  unsigned x;
  void undef() { x = (unsigned)-1; }
  bool isnan() const { return x == (unsigned)-1; }
  inline int geti() const { return (int)x; }
  ModInt() { x = 0; }
  ModInt(const ModInt &y) { x = y.x; }
  ModInt(int y) {
    if (y < 0 || (int)MOD <= y) y %= (int)MOD;
    if (y < 0) y += MOD;
    x = y;
  }
  ModInt(unsigned y) {
    if (MOD <= y)
      x = y % MOD;
    else
      x = y;
  }
  ModInt(long long y) {
    if (y < 0 || MOD <= y) y %= MOD;
    if (y < 0) y += MOD;
    x = y;
  }
  ModInt(unsigned long long y) {
    if (MOD <= y)
      x = y % MOD;
    else
      x = y;
  }
  ModInt &operator+=(const ModInt y) {
    if ((x += y.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt y) {
    if ((x -= y.x) & (1u << 31)) x += MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt y) {
    x = (unsigned long long)x * y.x % MOD;
    return *this;
  }
  ModInt &operator/=(const ModInt y) {
    x = (unsigned long long)x * y.inv().x % MOD;
    return *this;
  }
  ModInt operator-() const { return (x ? MOD - x : 0); }
  ModInt inv() const { return pow(MOD - 2); }
  ModInt pow(long long y) const {
    ModInt b = *this, r = 1;
    if (y < 0) {
      b = b.inv();
      y = -y;
    }
    for (; y; y >>= 1) {
      if (y & 1) r *= b;
      b *= b;
    }
    return r;
  }
  ModInt extgcd() const {
    unsigned a = MOD, b = x;
    int u = 0, v = 1;
    while (b) {
      int t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    if (u < 0) u += MOD;
    return ModInt(u);
  }
  friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
  friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
  friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
  friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
  friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
  friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
  friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};
const long long MOD = 1000000007;
int N, T;
ModInt<MOD> fact[55];
vector<int> P[3];
ModInt<MOD> cnt[18][26][51][3];
ModInt<MOD> dp[3][51][2511];
int sum[3];
void MAIN() {
  fact[0] = 1;
  for (int i = 1; i < 55; i++) fact[i] = fact[i - 1] * i;
  scanf("%d%d", &N, &T);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int t, g;
    scanf("%d%d", &t, &g);
    g--;
    P[g].push_back(t);
  }
  if (P[0].size() > P[1].size()) swap(P[0], P[1]);
  if (P[1].size() > P[2].size()) swap(P[1], P[2]);
  if (P[0].size() > P[1].size()) swap(P[0], P[1]);
  for (int k = 0, k_len = (3); k < k_len; ++k) {
    for (__typeof((P[k]).begin()) e = (P[k]).begin(), e_end = (P[k]).end();
         e != e_end; ++e)
      sum[k] += *e;
    dp[k][0][0] = 1;
    for (__typeof((P[k]).begin()) e = (P[k]).begin(), e_end = (P[k]).end();
         e != e_end; ++e) {
      for (int a = P[k].size(); a >= 0; a--)
        for (int j = T; j >= 0; j--)
          if (dp[k][a][j].x) {
            dp[k][a + 1][j + *e] += dp[k][a][j];
          }
    }
  }
  cnt[1][0][0][0] = 1;
  cnt[0][1][0][1] = 1;
  cnt[0][0][1][2] = 1;
  for (int a = 0, a_len = (P[0].size() + 1); a < a_len; ++a)
    for (int b = 0, b_len = (P[1].size() + 1); b < b_len; ++b)
      for (int c = 0, c_len = (P[2].size() + 1); c < c_len; ++c) {
        if (a + 1 <= (int)P[0].size())
          cnt[a + 1][b][c][0] += cnt[a][b][c][1] + cnt[a][b][c][2];
        if (b + 1 <= (int)P[1].size())
          cnt[a][b + 1][c][1] += cnt[a][b][c][0] + cnt[a][b][c][2];
        if (c + 1 <= (int)P[2].size())
          cnt[a][b][c + 1][2] += cnt[a][b][c][0] + cnt[a][b][c][1];
      }
  ModInt<MOD> ans = 0;
  for (int a = 0, a_len = (P[0].size() + 1); a < a_len; ++a)
    for (int i = 0, i_len = (sum[0] + 1); i < i_len; ++i)
      if (dp[0][a][i].x) {
        for (int b = 0, b_len = (P[1].size() + 1); b < b_len; ++b)
          for (int j = 0, j_len = (min(sum[1] + 1, T - i + 1)); j < j_len; ++j)
            if (dp[1][b][j].x) {
              int k = T - i - j;
              for (int c = 0, c_len = (P[2].size() + 1); c < c_len; ++c)
                if (dp[2][c][k].x) {
                  ans += (cnt[a][b][c][0] + cnt[a][b][c][1] + cnt[a][b][c][2]) *
                         dp[0][a][i] * dp[1][b][j] * dp[2][c][k] * fact[a] *
                         fact[b] * fact[c];
                }
            }
      }
  printf("%d\n", ans.geti());
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}