Under construction

Still being built. Things may change

Generate the Sequences

Time limit2sMemory limit512 MB

Summary
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 SS, a sequence of integer sequences. Initially, S0=(1)S_0 = (1). After that, we construct S1,S2,…,SnS_1, S_2, \ldots, S_n as follows.

Let ∣Si∣|S_i| be the length of the sequence SiS_i, and let si,js_{i,j} be the jj-th element of SiS_i. Then Si+1S_{i+1} has length ∣Si∣+1|S_i|+1 and can be obtained from SiS_i using one of the following two operations:

  • Write 11 or the given integer mm as the element with number ∣Si∣+1|S_i| + 1 of the new sequence.
  • Select an index jj (1≤j<∣Si∣1 \le j < |S_i|), choose an integer xx such that si,j<x<si,j+1s_{i,j} < x < s_{i,j + 1} or si,j>x>si,j+1s_{i,j} > x > s_{i,j + 1}, and place it between si,js_{i,j} and si,j+1s_{i,j+1}, shifting the indices of the right part by 11.

Given nn and mm, find the number of different ordered tuples of sequences S1…SnS_1 \ldots S_n. Two tuples are considered different if the sequences SiS_i differ for at least one ii from 11 to nn. Since the answer may be large, print it modulo 998 244 353998\,244\,353.

Input

The input consists of one line containing two integers nn and mm (1≤n≤30001 \le n \le 3000, 2≤m≤1082 \le m \le 10^8).

Output

Print the number of different tuples of sequences SS modulo 998 244 353998\,244\,353.

Hint

Here are the possible tuples in the first example:

  • S1=(1,3)S_1=(1,3) (first operation), then S2=(1,2,3)S_2=(1,2,3) (second operation);
  • S1=(1,1)S_1=(1,1) (first operation), then S2=(1,1,3)S_2=(1,1,3) (first operation);
  • S1=(1,1)S_1=(1,1) (first operation), then S2=(1,1,1)S_2=(1,1,1) (first operation);
  • S1=(1,3)S_1=(1,3) (first operation), then S2=(1,3,3)S_2=(1,3,3) (first operation);
  • S1=(1,3)S_1=(1,3) (first operation), then S2=(1,3,1)S_2=(1,3,1) (first operation).

Therefore, the answer is 55.

Examples2

  1. Example 1

    Input
    2 3
    
    Expected output
    5
    
  2. Example 2

    Input
    1024 52689658
    
    Expected output
    654836147