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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskG2 solver = new TaskG2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG2 {
        static final int MOD = 1000000000 + 7;
        static final int MAXN = 51;

        int getWays(int i, int j, int k, int l, int[][][][] ways, boolean[][][][] cached) {
            if (i + j + k == 0) return l == -1 ? 1 : 0;
            if (l < 0) return 0;
            if (cached[i][j][k][l]) return ways[i][j][k][l];
            int s = i + j + k;
            long value = 0;
            if (l == 0 && i != 0) {
                for (int x = -1; x < 3; x++)
                    if (x != l) {
                        value += getWays(i - 1, j, k, x, ways, cached);
                    }
            }
            if (l == 1 && j != 0) {
                for (int x = -1; x < 3; x++)
                    if (x != l) {
                        value += getWays(i, j - 1, k, x, ways, cached);
                    }
            }
            if (l == 2 && k != 0) {
                for (int x = -1; x < 3; x++)
                    if (x != l) {
                        value += getWays(i, j, k - 1, x, ways, cached);
                    }
            }
            ways[i][j][k][l] = (int) (value % MOD);
            cached[i][j][k][l] = true;
            return ways[i][j][k][l];
        }

        int totalWays(int i, int j, int k, int[][][][] ways, boolean[][][][] cached, int[] factorial) {
            long ret = 0;
            for (int l = 0; l < 3; l++) ret += getWays(i, j, k, l, ways, cached);
            ret *= factorial[i];
            ret %= MOD;

            ret *= factorial[j];
            ret %= MOD;

            ret *= factorial[k];
            ret %= MOD;

            return (int) ret;
        }

        int add(int type, int value, int[] sizes, int sum, int[][][][] dp) {
            sizes[type]++;
            if (type == 0) {
                for (int s = sum + value; s >= value; s--) {
                    for (int i = 1; i <= sizes[0]; i++)
                        for (int j = 0; j <= sizes[1]; j++)
                            for (int k = 0; k <= sizes[2]; k++) {
                                dp[i][j][k][s] += dp[i - 1][j][k][s - value];
                                if (dp[i][j][k][s] >= MOD)
                                    dp[i][j][k][s] -= MOD;
                            }
                }
            }

            if (type == 1) {
                for (int s = sum + value; s >= value; s--) {
                    for (int i = 0; i <= sizes[0]; i++)
                        for (int j = 1; j <= sizes[1]; j++)
                            for (int k = 0; k <= sizes[2]; k++) {
//                            System.out.println(i + " " + j + " " + k + " " + s + " " + dp.length + " " + dp[0].length + " " + dp[0][0].length + " " + dp[0][0][0].length);
                                dp[i][j][k][s] += dp[i][j - 1][k][s - value];
                                if (dp[i][j][k][s] >= MOD)
                                    dp[i][j][k][s] -= MOD;
                            }
                }
            }

            if (type == 2) {
                for (int s = sum + value; s >= value; s--) {
                    for (int i = 0; i <= sizes[0]; i++)
                        for (int j = 0; j <= sizes[1]; j++)
                            for (int k = 1; k <= sizes[2]; k++) {
//                            System.out.println(i + " " + j + " " + k + " " + s + " " + dp.length + " " + dp[0].length + " " + dp[0][0].length + " " + dp[0][0][0].length);
                                dp[i][j][k][s] += dp[i][j][k - 1][s - value];
                                if (dp[i][j][k][s] >= MOD)
                                    dp[i][j][k][s] -= MOD;
                            }
                }
            }

            return sum + value;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int[][][][] ways = new int[MAXN][MAXN][MAXN][3];
            boolean[][][][] cached = new boolean[MAXN][MAXN][MAXN][3];
//        Arrays.fill(ways, -1);

            int n = in.nextInt(), T = in.nextInt();

            ArrayList<Integer>[] ar = new ArrayList[3];
            for (int i = 0; i < 3; i++) ar[i] = new ArrayList<Integer>();
            int total_sum = 0;
            for (int i = 0; i < n; i++) {
                int t = in.nextInt(), g = in.nextInt();
                ar[g - 1].add(t);
                total_sum += t;
            }

            if (T > total_sum) {
                out.println(0);
                return;
            }
            int min_index = 0, mn = 100000000;

            for (int i = 0; i < 3; i++) {
                if (ar[i].size() < mn) {
                    mn = ar[i].size();
                    min_index = i;
                }
            }

            int[][][][] dp = new int[ar[(1 + min_index) % 3].size() + 1][ar[(2 + min_index) % 3].size() + 1][mn + 1][total_sum + 1];
            dp[0][0][0][0] = 1;
            int[] sizes = {0, 0, 0};
            int sum = 0;
            int[] order = {(min_index + 1) % 3, (min_index + 2) % 3, min_index};
            int type = 0;
            for (int i : order) {
                for (int v : ar[i])
                    sum = add(type, v, sizes, sum, dp);
                type++;
            }
            int[] factorial = new int[MAXN];
            factorial[0] = 1;
            for (int i = 1; i < MAXN; i++)
                factorial[i] = (int) ((factorial[i - 1] * 1L * i) % MOD);
            long answer = 0;
            for (int i = 0; i < dp.length; i++)
                for (int j = 0; j < dp[0].length; j++)
                    for (int k = 0; k < dp[0][0].length; k++) {
                        answer += dp[i][j][k][T] * 1L * totalWays(i, j, k, ways, cached, factorial);
                        answer %= MOD;
                    }
            out.println(answer);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
            writer.print('\n');
        }

        public void close() {
            writer.close();
        }

    }
}