PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000371. Mocha và những ngôi sao (Mocha and Stars)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mocha và những ngôi sao (Mocha and Stars)

Mocha and Stars

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn stars. Choose an integer brightness aia_i for the ii-th star from the interval [li,ri][l_i,r_i]. A selection is valid if all of the following hold:

  • li≤ai≤ril_i\le a_i\le r_i for every 1≤i≤n1\le i\le n;
  • a1+a2+⋯+an≤ma_1+a_2+\cdots+a_n\le m;
  • gcd⁡(a1,a2,…,an)=1\gcd(a_1,a_2,\ldots,a_n)=1.

Two selections differ if some position has different brightness. Count all valid selections modulo 998244353998244353.

Every aia_i is positive. If ∑li>m\sum l_i>m, the answer is zero.

Input

The first line contains n,mn,m. Each of the following nn lines contains li,ril_i,r_i.

Output

Output the number of valid tuples (a1,…,an)(a_1,\ldots,a_n) modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 2≤n≤62\le n\le6; 1≤m≤601\le m\le60; 1≤li≤ri≤m1\le l_i\le r_i\le m.
  • Subtask 2 (30 points): 2≤n≤252\le n\le25; 1≤m≤5 0001\le m\le5\,000; 1≤li≤ri≤m1\le l_i\le r_i\le m.
  • Subtask 3 (50 points): 2≤n≤502\le n\le50; 1≤m≤100 0001\le m\le100\,000; 1≤li≤ri≤m1\le l_i\le r_i\le m.

Examples

Example 1

Input

2 4
1 3
1 2

Output

4

Explanation

The valid tuples are (1,1)(1,1), (1,2)(1,2), (2,1)(2,1), and (3,1)(3,1). Tuple (2,2)(2,2) has GCD 22; tuple (3,2)(3,2) has sum 55.

Example 2

Input

5 10
1 10
1 10
1 10
1 10
1 10

Output

251

Explanation

Start with 11 in all five positions. Distributing up to five further units gives (105)=252\binom{10}{5}=252 choices. If a choice has GCD greater than 11, each value is at least 22. Under the sum bound of 1010, the only such choice is (2,2,2,2,2)(2,2,2,2,2). Removing it leaves 251251.