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>
long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
 public:
  long long x;
  long long y, z;
  pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}
  bool operator<(const pa3 &p) const {
    if (x != p.x) return x < p.x;
    if (y != p.y) return y < p.y;
    return z < p.z;
  }
  bool operator>(const pa3 &p) const {
    if (x != p.x) return x > p.x;
    if (y != p.y) return y > p.y;
    return z > p.z;
  }
  bool operator==(const pa3 &p) const {
    return x == p.x && y == p.y && z == p.z;
  }
  bool operator!=(const pa3 &p) const {
    return !(x == p.x && y == p.y && z == p.z);
  }
};
class pa4 {
 public:
  long long x;
  long long y, z, w;
  pa4(long long x = 0, long long y = 0, long long z = 0, long long w = 0)
      : x(x), y(y), z(z), w(w) {}
  bool operator<(const pa4 &p) const {
    if (x != p.x) return x < p.x;
    if (y != p.y) return y < p.y;
    if (z != p.z) return z < p.z;
    return w < p.w;
  }
  bool operator>(const pa4 &p) const {
    if (x != p.x) return x > p.x;
    if (y != p.y) return y > p.y;
    if (z != p.z) return z > p.z;
    return w > p.w;
  }
  bool operator==(const pa4 &p) const {
    return x == p.x && y == p.y && z == p.z && w == p.w;
  }
};
class pa2 {
 public:
  long long x, y;
  pa2(long long x = 0, long long y = 0) : x(x), y(y) {}
  pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
  pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
  bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
  bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
  bool operator==(const pa2 &p) const {
    return abs(x - p.x) == 0 && abs(y - p.y) == 0;
  }
  bool operator!=(const pa2 &p) const {
    return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
  }
};
string itos(long long i) {
  ostringstream s;
  s << i;
  return s.str();
}
long long gcd(long long v, long long b) {
  if (v > b) return gcd(b, v);
  if (v == b) return b;
  if (b % v == 0) return v;
  return gcd(v, b % v);
}
long long mod;
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
pair<long long, long long> operator+(const pair<long long, long long> &l,
                                     const pair<long long, long long> &r) {
  return {l.first + r.first, l.second + r.second};
}
pair<long long, long long> operator-(const pair<long long, long long> &l,
                                     const pair<long long, long long> &r) {
  return {l.first - r.first, l.second - r.second};
}
long long pr[200010];
long long inv[200010];
long long beki(long long wa, long long rr, long long warukazu) {
  if (rr == 0) return 1 % warukazu;
  if (rr == 1) return wa % warukazu;
  wa %= warukazu;
  if (rr % 2 == 1)
    return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu;
  long long zx = beki(wa, rr / 2, warukazu);
  return (zx * zx) % warukazu;
}
long long comb(long long nn, long long rr) {
  if (rr < 0 || rr > nn || nn < 0) return 0;
  long long r = pr[nn] * inv[rr];
  r %= mod;
  r *= inv[nn - rr];
  r %= mod;
  return r;
}
void gya(long long ert) {
  pr[0] = 1;
  for (long long i = 1; i <= ert; i++) {
    pr[i] = (pr[i - 1] * i) % mod;
  }
  inv[ert] = beki(pr[ert], mod - 2, mod);
  for (long long i = ert - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
long long dp[2][51][51][2501] = {};
long long dp2[51][51][2501] = {};
long long fp[51][51][51][3] = {};
long long solve(long long i, long long j, long long k) {
  return (fp[i][j][k][0] + fp[i][j][k][1] + fp[i][j][k][2]) % 1000000007;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, T;
  cin >> n >> T;
  vector<long long> ve[3];
  for (long long i = 0; i < n; i++) {
    long long y, yy;
    cin >> y >> yy;
    yy--;
    ve[yy].push_back(y);
  }
  long long a = ve[0].size();
  long long b = ve[1].size();
  long long c = ve[2].size();
  fp[1][0][0][0] = 1;
  fp[0][1][0][1] = 1;
  fp[0][0][1][2] = 1;
  for (long long i = 0; i <= a; i++)
    for (long long j = 0; j <= b; j++)
      for (long long k = 0; k <= c; k++)
        for (long long h = 0; h < 3; h++) {
          if (i + j + k <= 1) continue;
          if (h == 0 && i > 0) {
            fp[i][j][k][h] =
                (fp[i - 1][j][k][1] + fp[i - 1][j][k][2]) * i % 1000000007;
          }
          if (h == 1 && j > 0) {
            fp[i][j][k][h] =
                (fp[i][j - 1][k][0] + fp[i][j - 1][k][2]) * j % 1000000007;
          }
          if (h == 2 && k > 0) {
            fp[i][j][k][h] =
                (fp[i][j][k - 1][0] + fp[i][j][k - 1][1]) * k % 1000000007;
          }
        }
  dp[0][0][0][0] = 1;
  for (long long i = 0; i < a; i++) {
    for (long long j = 0; j <= i; j++)
      for (long long h = j; h <= j * 50; h++)
        if (dp[i % 2][j][0][h]) {
          dp[1 - i % 2][j][0][h] += dp[i % 2][j][0][h];
          if (dp[1 - i % 2][j][0][h] >= 1000000007)
            dp[1 - i % 2][j][0][h] -= 1000000007;
          dp[1 - i % 2][j + 1][0][h + ve[0][i]] += dp[i % 2][j][0][h];
          if (dp[1 - i % 2][j + 1][0][h + ve[0][i]] >= 1000000007)
            dp[1 - i % 2][j + 1][0][h + ve[0][i]] -= 1000000007;
          dp[i % 2][j][0][h] = 0;
        }
  }
  for (long long i = 0; i < b; i++) {
    for (long long j = 0; j <= 50; j++)
      for (long long k = 0; k <= 50; k++)
        for (long long h = 0; h <= 2500; h++) dp[(a + i + 1) % 2][j][k][h] = 0;
    for (long long j = 0; j <= a; j++)
      for (long long k = 0; k <= i; k++)
        for (long long h = (k + j); h <= (k + j) * 50; h++)
          if (dp[(a + i) % 2][j][k][h]) {
            dp[(a + i + 1) % 2][j][k][h] += dp[(a + i) % 2][j][k][h];
            if (dp[(a + i + 1) % 2][j][k][h] >= 1000000007)
              dp[(a + i + 1) % 2][j][k][h] -= 1000000007;
            dp[(a + i + 1) % 2][j][k + 1][h + ve[1][i]] +=
                dp[(a + i) % 2][j][k][h];
            if (dp[(a + i + 1) % 2][j][k + 1][h + ve[1][i]] >= 1000000007)
              dp[(a + i + 1) % 2][j][k + 1][h + ve[1][i]] -= 1000000007;
            dp[(a + i) % 2][j][k][h] = 0;
          }
  }
  dp2[0][0][0] = 1;
  for (long long i = 0; i < c; i++) {
    for (long long j = 0; j <= i; j++)
      for (long long h = j; h <= 50 * j; h++)
        if (dp2[i][j][h]) {
          dp2[i + 1][j][h] += dp2[i][j][h];
          if (dp2[i + 1][j][h] >= 1000000007) dp2[i + 1][j][h] -= 1000000007;
          dp2[i + 1][j + 1][h + ve[2][i]] += dp2[i][j][h];
          if (dp2[i + 1][j + 1][h + ve[2][i]] >= 1000000007)
            dp2[i + 1][j + 1][h + ve[2][i]] -= 1000000007;
        }
  }
  long long ans = 0;
  for (long long i = 0; i <= a; i++)
    for (long long j = 0; j <= b; j++)
      for (long long k = 0; k <= c; k++)
        for (long long h = k; h <= k * 50; h++) {
          long long w = T - h;
          if (i + j > w) continue;
          if ((i + j) * 50 < w) continue;
          long long memo = dp[(a + b) % 2][i][j][w];
          memo *= dp2[c][k][h];
          memo %= 1000000007;
          memo *= solve(i, j, k);
          memo %= 1000000007;
          ans += memo;
          if (ans >= 1000000007) ans -= 1000000007;
        }
  cout << ans << endl;
  return 0;
}