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;
const int MAXN = 100100;
const long long mod = 1000000007;
pair<long long, long long> v[MAXN];
long long n, t;
long long memo[5510][2510];
long long comp[5510][2510];
long long q1 = 0, q2 = 0, q3 = 0;
long long f[55];
long long r[51][51][51];
long long p[52][52][52][5];
long long pd(long long x, long long y, long long z, long long last) {
  if (x == 0 && y == 0 && z == 0) return 1;
  if (x < 0 || y < 0 || z < 0) return 0;
  if (p[x][y][z][last] != -1) return p[x][y][z][last];
  if (last == 0)
    p[x][y][z][last] =
        pd(x, y, z - 1, 3) + pd(x, y - 1, z, 2) + pd(x - 1, y, z, 1);
  if (last == 1) p[x][y][z][last] = pd(x, y - 1, z, 2) + pd(x, y, z - 1, 3);
  if (last == 2) p[x][y][z][last] = pd(x - 1, y, z, 1) + pd(x, y, z - 1, 3);
  if (last == 3) p[x][y][z][last] = pd(x - 1, y, z, 1) + pd(x, y - 1, z, 2);
  p[x][y][z][last] %= mod;
  return p[x][y][z][last];
}
signed main() {
  f[0] = 1;
  memset(p, -1, sizeof p);
  cin >> n >> t;
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    v[i] = {y, x};
    if (y == 1)
      q1++;
    else if (y == 2)
      q2++;
    else
      q3++;
  }
  long long cnt = 0;
  for (long long j1 = 0; j1 <= q1; j1++) {
    for (long long j2 = 0; j2 <= q2; j2++) {
      for (long long j3 = 0; j3 <= q3; j3++) {
        cnt++;
        r[j1][j2][j3] = cnt;
      }
    }
  }
  memo[r[0][0][0]][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j1 = 0; j1 <= q1; j1++) {
      for (long long j2 = 0; j2 <= q2; j2++) {
        for (long long j3 = 0; j3 <= q3; j3++) {
          for (long long k = 0; k <= t; k++) {
            comp[r[j1][j2][j3]][k] = memo[r[j1][j2][j3]][k];
            if (k - v[i].second < 0) continue;
            if (v[i].first == 1 && j1 > 0)
              memo[r[j1][j2][j3]][k] +=
                  comp[r[j1 - 1][j2][j3]][k - v[i].second];
            else if (v[i].first == 2 && j2 > 0)
              memo[r[j1][j2][j3]][k] +=
                  comp[r[j1][j2 - 1][j3]][k - v[i].second];
            else if (v[i].first == 3 && j3 > 0)
              memo[r[j1][j2][j3]][k] +=
                  comp[r[j1][j2][j3 - 1]][k - v[i].second];
            if (memo[r[j1][j2][j3]][k] > 1000000000)
              memo[r[j1][j2][j3]][k] %= mod;
          }
        }
      }
    }
  }
  for (long long i = 1; i <= 50; i++) f[i] = (f[i - 1] * i) % mod;
  long long resp = 0;
  for (long long j1 = 0; j1 <= q1; j1++) {
    for (long long j2 = 0; j2 <= q2; j2++) {
      for (long long j3 = 0; j3 <= q3; j3++) {
        long long h = ((((f[j1] % mod) * f[j2]) % mod) * f[j3]) % mod;
        resp += (memo[r[j1][j2][j3]][t] * pd(j1, j2, j3, 0)) % mod * h;
        resp %= mod;
      }
    }
  }
  cout << resp << endl;
}