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>
int MM[] = {469762049, 595591169, 645922817};
int V01, V02, V12;
long long power(int a, int b, int md) {
  long long p;
  if (b == 0) return 1;
  p = power(a, b / 2, md);
  p = p * p % md;
  if (b % 2) p = p * a % md;
  return p;
}
long long ww[3][13 + 1], ww_[3][13 + 1], vv[3];
int kk[50 + 1][50 + 1][50 + 1], ll[50 + 1][50 + 1][50 + 1][3];
void init() {
  int d, h, i, j, k;
  for (d = 0; d < 3; d++) {
    int md = MM[d];
    for (h = 0; h <= 13; h++) {
      ww[d][h] = power(3, (md - 1) >> h, md);
      ww_[d][h] = power(3, md - 1 - ((md - 1) >> h), md);
    }
    vv[d] = power((1 << 13), md - 2, md);
  }
  V01 = power(469762049, 595591169 - 2, 595591169);
  V02 = power(469762049, 645922817 - 2, 645922817);
  V12 = power(595591169, 645922817 - 2, 645922817);
  for (i = 0; i <= 50; i++)
    for (j = 0; j <= 50; j++)
      for (k = 0; k <= 50; k++) {
        long long k0, k1, k2;
        k0 = i > 0 ? (long long)ll[i - 1][j][k][0] * i % 1000000007 : 0;
        k1 = j > 0 ? (long long)ll[i][j - 1][k][1] * j % 1000000007 : 0;
        k2 = k > 0 ? (long long)ll[i][j][k - 1][2] * k % 1000000007 : 0;
        if (i == 0 && j == 0 && k == 0) {
          kk[i][j][k] = 1;
          ll[i][j][k][0] = ll[i][j][k][1] = ll[i][j][k][2] = 1;
        } else {
          kk[i][j][k] = (k0 + k1 + k2) % 1000000007;
          ll[i][j][k][0] = (k1 + k2) % 1000000007;
          ll[i][j][k][1] = (k0 + k2) % 1000000007;
          ll[i][j][k][2] = (k0 + k1) % 1000000007;
        }
      }
}
void ntt(int *aa, int d, int inverse) {
  int md = MM[d], h, i, j, b, l, r, u, v, tmp;
  long long w, w_;
  for (i = 1, j = 0; i < (1 << 13); i++) {
    b = (1 << 13);
    do j ^= b >>= 1;
    while ((j & b) == 0);
    if (i < j) tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
  }
  for (h = 0; (b = 1 << h) < (1 << 13); h++) {
    w_ = inverse ? ww_[d][h + 1] : ww[d][h + 1];
    for (i = 0; i < (1 << 13); i += b * 2) {
      w = 1;
      for (j = 0; j < b; j++) {
        l = i + j, r = l + b;
        u = aa[l], v = aa[r] * w % md;
        if ((aa[l] = u + v) >= md) aa[l] -= md;
        if ((aa[r] = u - v) < 0) aa[r] += md;
        w = w * w_ % md;
      }
    }
  }
}
void fft(int *aa, int *bb, int d) {
  int md = MM[d], i;
  long long v;
  ntt(aa, d, 0), ntt(bb, d, 0);
  for (i = 0; i < (1 << 13); i++) aa[i] = (long long)aa[i] * bb[i] % md;
  ntt(aa, d, 1);
  v = vv[d];
  for (i = 0; i < (1 << 13); i++) aa[i] = aa[i] * v % md;
}
int garner(int r0, int r1, int r2) {
  if (r0 < 0) r0 += 469762049;
  r1 = (long long)(r1 - r0) * V01 % 595591169;
  if (r1 < 0) r1 += 595591169;
  r2 = ((long long)(r2 - r0) * V02 - r1) % 645922817 * V12 % 645922817;
  if (r2 < 0) r2 += 645922817;
  return (((long long)r2 * 595591169 + r1) % 1000000007 * 469762049 + r0) %
         1000000007;
}
void mult(int *aa, int *bb, int *cc) {
  static int cc_[3][(1 << 13)], bb_[(1 << 13)];
  int d, i;
  for (d = 0; d < 3; d++) {
    for (i = 0; i < (1 << 13); i++) {
      cc_[d][i] = aa[i];
      bb_[i] = bb[i];
    }
    fft(cc_[d], bb_, d);
  }
  for (i = 0; i < (1 << 13); i++)
    cc[i] = garner(cc_[0][i], cc_[1][i], cc_[2][i]);
}
void knapsack(int *aa, int n, int m, int dp[][(1 << 13)]) {
  int h, i, j, a;
  dp[0][0] = 1;
  for (h = 0; h < n; h++) {
    a = aa[h];
    for (i = n; i >= 1; i--)
      for (j = m; j >= a; j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - a]) % 1000000007;
  }
}
int main() {
  static int aa[3][50], cc[(1 << 13)], nn[3], dp[3][50 + 1][(1 << 13)];
  int n, m, x, h, i0, i1, i2, j, ans;
  init();
  scanf("%d%d", &n, &m);
  while (n--) {
    scanf("%d%d", &x, &h), h--;
    aa[h][nn[h]++] = x;
  }
  for (h = 0; h < 3; h++) knapsack(aa[h], nn[h], m, dp[h]);
  ans = 0;
  for (i0 = 0; i0 <= nn[0]; i0++)
    for (i1 = 0; i1 <= nn[1]; i1++) {
      mult(dp[0][i0], dp[1][i1], cc);
      for (i2 = 0; i2 <= nn[2]; i2++)
        for (j = 0; j <= m; j++)
          ans = (ans + (long long)cc[j] * dp[2][i2][m - j] % 1000000007 *
                           kk[i0][i1][i2]) %
                1000000007;
    }
  printf("%d\n", ans);
  return 0;
}