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 ≤ 15), 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 ≤ 15, 1 ≤ T ≤ 225) — 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 ≤ 15, 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 long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long b, long long e, long long m) {
  b %= m;
  long long ans = 1;
  for (; e; b = b * b % m, e /= 2)
    if (e & 1) ans = ans * b % m;
  return mod(ans, m);
}
const int N = 52;
const int M = 1e9 + 7;
int DP[N][N][N][4];
bool vis[N][N][N][4];
int solve(int i, int j, int k, int f) {
  if (i + j + k == 0) return 1;
  if (vis[i][j][k][f]) return DP[i][j][k][f];
  vis[i][j][k][f] = 1;
  int& x = DP[i][j][k][f];
  x = 0;
  long long res = 0;
  if (i > 0 and f != 0) {
    res += solve(i - 1, j, k, 0) * (long long)i % M;
  }
  if (j > 0 and f != 1) {
    res += solve(i, j - 1, k, 1) * (long long)j % M;
  }
  if (k > 0 and f != 2) {
    res += solve(i, j, k - 1, 2) * (long long)k % M;
  }
  res %= M;
  return x = (int)res;
}
int n;
int fat[N], ifat[N];
int cnt[3], t[N], g[N];
vector<int> mine[3];
inline int add(int a, int b) {
  int c = a + b;
  if (c >= M) c -= M;
  return c;
}
inline int mult(int a, int b) { return (int)(a * (long long)b % M); }
int dp1[2][N][2505];
int dp2[2][N][N][2505];
int dp3[2][N][2505];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  fat[0] = ifat[0] = 1;
  for (int i = 1; i < (N); ++i) {
    fat[i] = i * (long long)fat[i - 1] % M;
    ifat[i] = exp(fat[i], M - 2, M);
  }
  int T;
  cin >> n >> T;
  for (int i = 0; i < (n); ++i) {
    cin >> t[i] >> g[i];
    g[i]--;
    mine[g[i]].push_back(t[i]);
    cnt[g[i]]++;
  }
  int res = 0;
  dp1[1][0][0] = 1;
  for (int i = 0; i < cnt[0]; i++) {
    int cur = i & 1;
    int ant = cur ^ 1;
    for (int j = 0; j <= i + 1; j++) {
      for (int tt = 0; tt < (T + 1); ++tt) {
        int op2 = 0;
        if (mine[0][i] <= tt and j > 0) op2 = dp1[ant][j - 1][tt - mine[0][i]];
        dp1[cur][j][tt] = add(dp1[ant][j][tt], op2);
      }
    }
  }
  int last = (cnt[0] & 1) ^ 1;
  for (int i = 0; i < (cnt[0] + 1); ++i)
    for (int tt = 0; tt < (T + 1); ++tt) {
      dp2[1][0][i][tt] = dp1[last][i][tt];
    }
  for (int pos = 0; pos < (cnt[1]); ++pos) {
    for (int i = 0; i < (cnt[0] + 1); ++i) {
      int cur = pos & 1;
      int ant = cur ^ 1;
      for (int j = 0; j <= pos + 1; j++)
        for (int tt = 0; tt < (T + 1); ++tt) {
          int op2 = 0;
          if (mine[1][pos] <= tt and j > 0)
            op2 = dp2[ant][j - 1][i][tt - mine[1][pos]];
          dp2[cur][j][i][tt] = add(dp2[ant][j][i][tt], op2);
        }
    }
  }
  last = (cnt[1] & 1) ^ 1;
  dp3[1][0][0] = 1;
  for (int i = 0; i < cnt[2]; i++) {
    int cur = i & 1;
    int ant = cur ^ 1;
    for (int j = 0; j <= i + 1; j++) {
      for (int tt = 0; tt < (T + 1); ++tt) {
        int op2 = 0;
        if (mine[2][i] <= tt and j > 0) op2 = dp3[ant][j - 1][tt - mine[2][i]];
        dp3[cur][j][tt] = add(dp3[ant][j][tt], op2);
      }
    }
  }
  int last2 = (cnt[2] & 1) ^ 1;
  for (int t1 = 0; t1 < (T + 1); ++t1) {
    for (int k = 0; k < (cnt[2] + 1); ++k) {
      for (int i = 0; i < (cnt[0] + 1); ++i) {
        for (int j = 0; j < (cnt[1] + 1); ++j) {
          int cur = mult(dp3[last2][k][t1], dp2[last][j][i][T - t1]);
          cur = mult(cur, solve(i, j, k, 3));
          res = add(res, cur);
        }
      }
    }
  }
  cout << res << "\n";
}