atcoder#ARC114C. [ARC114C] Sequence Scores

[ARC114C] Sequence Scores

Score : 600600 points

Problem Statement

For a sequence AA of length NN consisting of integers between 11 and MM (inclusive), let us define f(A)f(A) as follows:

  • We have a sequence XX of length NN, where every element is initially 00. f(A)f(A) is the minimum number of operations required to make XX equal AA by repeating the following operation:- Specify 1lrN1 \leq l \leq r \leq N and 1vM1 \leq v \leq M, then replace XiX_i with max(Xi,v)\max(X_i, v) for each lirl \leq i \leq r.
  • Specify 1lrN1 \leq l \leq r \leq N and 1vM1 \leq v \leq M, then replace XiX_i with max(Xi,v)\max(X_i, v) for each lirl \leq i \leq r.

Find the sum, modulo 998244353998244353, of f(A)f(A) over all MNM^N sequences that can be AA.

Constraints

  • 1N,M50001 \leq N, M \leq 5000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the sum of f(A)f(A) over all sequences AA, modulo 998244353998244353.

2 3
15

The 32=93 ^ 2 = 9 sequences and the value of ff for those are as follows:

  • For A=(1,1)A = (1, 1), we can make XX equal it with one operation with (l=1,r=2,v=1)(l = 1, r = 2, v = 1), so f(A)=1f(A) = 1.
  • For A=(1,2)A = (1, 2), we can make XX equal it with two operations with (l=1,r=2,v=1)(l = 1, r = 2, v = 1) and (l=2,r=2,v=2)(l = 2, r = 2, v = 2), so f(A)=2f(A) = 2.
  • For A=(1,3)A = (1, 3), we can make XX equal it with two operations with (l=1,r=2,v=1)(l = 1, r = 2, v = 1) and (l=2,r=2,v=3)(l = 2, r = 2, v = 3), so f(A)=2f(A) = 2.
  • For A=(2,1)A = (2, 1), we can make XX equal it with two operations with (l=1,r=2,v=1)(l = 1, r = 2, v = 1) and (l=1,r=1,v=2)(l = 1, r = 1, v = 2), so f(A)=2f(A) = 2.
  • For A=(2,2)A = (2, 2), we can make XX equal it with one operation with (l=1,r=2,v=2)(l = 1, r = 2, v = 2), so f(A)=1f(A) = 1.
  • For A=(2,3)A = (2, 3), we can make XX equal it with two operations with (l=1,r=2,v=2)(l = 1, r = 2, v = 2) , (l=2,r=2,v=3)(l = 2, r = 2, v = 3), so f(A)=2f(A) = 2.
  • For A=(3,1)A = (3, 1), we can make XX equal it with two operations with (l=1,r=2,v=1)(l = 1, r = 2, v = 1) and (l=1,r=1,v=3)(l = 1, r = 1, v = 3) so f(A)=2f(A) = 2.
  • For A=(3,2)A = (3, 2), we can make XX equal it with two operations with (l=1,r=2,v=2)(l = 1, r = 2, v = 2) and (l=1,r=1,v=3)(l = 1, r = 1, v = 3), so f(A)=2f(A) = 2.
  • For A=(3,3)A = (3, 3), we can make XX equal it with one operation with (l=1,r=2,v=3)(l = 1, r = 2, v = 3), so f(A)=1f(A) = 1.

The sum of these values is 3×1+6×2=153 \times 1 + 6 \times 2 = 15.

3 2
15
34 56
649717324