Codeforces Round 420 (Div. 2)
E
Okabe and El Psy Kongroo
Codeforces
2100
原题
← D→
翻译中…

Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points $(*x*, *y*)$ such that $*x*$ and $*y*$ are non-negative. Okabe starts at the origin (point $(0, 0)$), and needs to reach the point $(*k*, 0)$. If Okabe is currently at the point $(*x*, *y*)$, in one step he can go to $(*x* + 1, *y* + 1)$, $(*x* + 1, *y*)$, or $(*x* + 1, *y* - 1)$.

翻译中…

Additionally, there are $*n*$ horizontal line segments, the $*i*$-th of which goes from $*x* = *a*_{*i*}$ to $*x* = *b*_{*i*}$ inclusive, and is at $*y* = *c*_{*i*}$. It is guaranteed that $*a*_{1} = 0$, $*a*_{*n*} ≤ *k* ≤ *b*_{*n*}$, and $*a*_{*i*} = *b*_{*i* - 1}$ for $2 ≤ *i* ≤ *n*$. The $*i*$-th line segment forces Okabe to walk with $*y*$-value in the range $0 ≤ *y* ≤ *c*_{*i*}$ when his $*x*$ value satisfies $*a*_{*i*} ≤ *x* ≤ *b*_{*i*}$, or else he might be spied on. This also means he is required to be under two line segments when one segment ends and another begins.

翻译中…

Okabe now wants to know how many walks there are from the origin to the point $(*k*, 0)$ satisfying these conditions, modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

The first line of input contains the integers $*n*$ and $*k*$ ($1 ≤ *n* ≤ 100$, $1 ≤ *k* ≤ 10^{18}$) — the number of segments and the destination $*x*$ coordinate.

翻译中…

The next $*n*$ lines contain three space-separated integers $*a*_{*i*}$, $*b*_{*i*}$, and $*c*_{*i*}$ ($0 ≤ *a*_{*i*} < *b*_{*i*} ≤ 10^{18}$, $0 ≤ *c*_{*i*} ≤ 15$) — the left and right ends of a segment, and its $*y*$ coordinate.

翻译中…

It is guaranteed that $*a*_{1} = 0$, $*a*_{*n*} ≤ *k* ≤ *b*_{*n*}$, and $*a*_{*i*} = *b*_{*i* - 1}$ for $2 ≤ *i* ≤ *n*$.

翻译中…

Output

翻译中…

Print the number of walks satisfying the conditions, modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Note

翻译中…

image

翻译中…

The graph above corresponds to sample 1. The possible walks are:

翻译中…
  • image
  • image
  • image
  • image
翻译中…

image

翻译中…

The graph above corresponds to sample 2. There is only one walk for Okabe to reach $(3, 0)$. After this, the possible walks are:

翻译中…
  • image
  • image
  • image
  • image
翻译中…

样例

Input #1
1 3
0 3 3
Output #1
4
InputCopy OutputCopy
Input #2
2 6
0 3 0
3 10 2
Output #2
4
InputCopy OutputCopy
题目信息
题号
821E
时间限制
2 s
内存限制
256 MB
标签
动态规划
矩阵

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。