Generate the Sequences
Time limit2sMemory limit512 MB
Count the ordered tuples of sequences built from (1) by repeatedly appending 1 or m, or inserting any integer strictly between two adjacent elements, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math, Implementation
- Solved
- No attempts yet
Problem
Consider , a sequence of integer sequences. Initially, . After that, we construct as follows.
Let be the length of the sequence , and let be the -th element of . Then has length and can be obtained from using one of the following two operations:
- Write or the given integer as the element with number of the new sequence.
- Select an index (), choose an integer such that or , and place it between and , shifting the indices of the right part by .
Given and , find the number of different ordered tuples of sequences . Two tuples are considered different if the sequences differ for at least one from to . Since the answer may be large, print it modulo .
Input
The input consists of one line containing two integers and (, ).
Output
Print the number of different tuples of sequences modulo .
Hint
Here are the possible tuples in the first example:
- (first operation), then (second operation);
- (first operation), then (first operation);
- (first operation), then (first operation);
- (first operation), then (first operation);
- (first operation), then (first operation).
Therefore, the answer is .