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>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
long long f[51];
long long dp[51][51][51][4];
long long dp1[51][51][51];
long long cnt[4];
long long g1[2501][51];
long long dp2[2501][51][51];
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  for (long long i = 0; i <= 50; i++)
    for (long long j = 0; j <= 50; j++)
      for (long long k = 0; k <= 2500; k++) dp2[k][i][j] = 0;
  f[0] = 1;
  for (long long i = 1; i <= 50; i++) f[i] = (f[i - 1] % MOD * i % MOD) % MOD;
  long long n, t;
  cin >> n >> t;
  pair<long long, long long> p[n];
  for (long long i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    cnt[p[i].second]++;
  }
  dp[0][0][0][1] = 1;
  dp[0][0][0][2] = 1;
  dp[0][0][0][3] = 1;
  for (long long i = 0; i <= 50; i++)
    for (long long j = 0; j <= 50; j++)
      for (long long k = 0; k <= 50; k++) {
        if ((i + j + k) == 0) continue;
        if (i >= 1)
          dp[i][j][k][1] =
              (dp[i - 1][j][k][2] % MOD + dp[i - 1][j][k][3] % MOD) % MOD;
        else
          dp[i][j][k][1] = 0;
        if (j >= 1)
          dp[i][j][k][2] =
              (dp[i][j - 1][k][1] % MOD + dp[i][j - 1][k][3] % MOD) % MOD;
        else
          dp[i][j][k][2] = 0;
        if (k >= 1)
          dp[i][j][k][3] =
              (dp[i][j][k - 1][2] % MOD + dp[i][j][k - 1][1] % MOD) % MOD;
        else
          dp[i][j][k][3] = 0;
      }
  long long pr;
  long long inv = power((long long)2, MOD - 2, MOD);
  for (long long i = 0; i <= 50; i++)
    for (long long j = 0; j <= 50; j++)
      for (long long k = 0; k <= 50; k++) {
        pr = f[i];
        pr = (pr % MOD * f[j] % MOD) % MOD;
        pr = (pr % MOD * f[k]) % MOD;
        dp1[i][j][k] = (dp[i][j][k][1] % MOD + dp[i][j][k][2] % MOD) % MOD;
        dp1[i][j][k] = (dp1[i][j][k] % MOD + dp[i][j][k][3] % MOD) % MOD;
        dp1[i][j][k] = (dp1[i][j][k] % MOD * pr % MOD) % MOD;
        dp1[i][j][k] = (dp1[i][j][k] % MOD * inv % MOD) % MOD;
      }
  dp1[0][0][0] = 1;
  g1[0][0] = 1;
  dp2[0][0][0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = t; j >= 0; j--) {
      for (long long k = 0; k <= n; k++) {
        if (p[i].second == 1 && k >= 1 && j >= p[i].first)
          g1[j][k] = (g1[j][k] % MOD + g1[j - p[i].first][k - 1] % MOD) % MOD;
      }
    }
  }
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    mx = mx + p[i].first;
    for (long long j = min(t, mx); j >= 1; j--) {
      for (long long k = 0; k <= cnt[2]; k++) {
        for (long long l = 0; l <= cnt[3]; l++) {
          if (p[i].second == 2 && k >= 1 && j >= p[i].first)
            dp2[j][k][l] =
                (dp2[j][k][l] % MOD + dp2[j - p[i].first][k - 1][l] % MOD) %
                MOD;
          else if (p[i].second == 3 && l >= 1 && j >= p[i].first)
            dp2[j][k][l] =
                (dp2[j][k][l] % MOD + dp2[j - p[i].first][k][l - 1] % MOD) %
                MOD;
        }
      }
    }
  }
  long long ans = 0, x, y, sum;
  for (long long i = 0; i <= cnt[1]; i++) {
    for (long long j = 0; j <= t; j++) {
      sum = t - j;
      for (long long k = 0; k <= cnt[2]; k++) {
        for (long long l = 0; l <= cnt[3]; l++) {
          x = dp1[i][k][l];
          y = (g1[j][i] % MOD * dp2[sum][k][l] % MOD) % MOD;
          y = (y % MOD * x % MOD) % MOD;
          ans = (ans % MOD + y % MOD) % MOD;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}