Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

F. Runner's Problem

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are running through a rectangular field. This field can be represented as a matrix with 3 rows and *m* columns. (*i*, *j*) denotes a cell belonging to *i*-th row and *j*-th column.

You start in (2, 1) and have to end your path in (2, *m*). From the cell (*i*, *j*) you may advance to:

- (
*i*- 1,*j*+ 1) — only if*i*> 1, - (
*i*,*j*+ 1), or - (
*i*+ 1,*j*+ 1) — only if*i*< 3.

However, there are *n* obstacles blocking your path. *k*-th obstacle is denoted by three integers *a*_{k}, *l*_{k} and *r*_{k}, and it forbids entering any cell (*a*_{k}, *j*) such that *l*_{k} ≤ *j* ≤ *r*_{k}.

You have to calculate the number of different paths from (2, 1) to (2, *m*), and print it modulo 10^{9} + 7.

Input

The first line contains two integers *n* and *m* (1 ≤ *n* ≤ 10^{4}, 3 ≤ *m* ≤ 10^{18}) — the number of obstacles and the number of columns in the matrix, respectively.

Then *n* lines follow, each containing three integers *a*_{k}, *l*_{k} and *r*_{k} (1 ≤ *a*_{k} ≤ 3, 2 ≤ *l*_{k} ≤ *r*_{k} ≤ *m* - 1) denoting an obstacle blocking every cell (*a*_{k}, *j*) such that *l*_{k} ≤ *j* ≤ *r*_{k}. Some cells may be blocked by multiple obstacles.

Output

Print the number of different paths from (2, 1) to (2, *m*), taken modulo 10^{9} + 7. If it is impossible to get from (2, 1) to (2, *m*), then the number of paths is 0.

Example

Input

2 5

1 3 4

2 2 3

Output

2

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/22/2019 03:02:47 (g2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|