#P11835. Ancient Seal Modification

    ID: 13935 Type: Default 1000ms 256MiB

Ancient Seal Modification

Ancient Seal Modification

During an expedition, Xiao H discovered an ancient seal whose body is a sequence \(A = [a_1,a_2,\ldots,a_n]\). Initially each element \(a_i\) is a positive integer in the range \([1, m]\).

Xiao H can perform the following modification any number of times (including zero):

  1. Choose an index \(s\) (with \(1 \le s \le |A|\)) such that \(a_s\) is a strict prefix maximum of the current sequence \(A\). Formally, \(a_s\) is chosen if for every \(1 \le j a_j\). (Note that \(a_1\) is always a strict prefix maximum.)
  2. If \(a_s \neq 1\), append \(a_s-1\) to the end of the sequence.
  3. Delete the first \(s\) elements of the sequence.

For example, if \(A = [1,3,2,3,4]\) then:

  • Choosing \(s=1\) (always allowed) leads to \(A = [3,2,3,4]\),
  • Choosing \(s=2\) is allowed because \(3>1\) and leads to \(A = [2,3,4,2]\),
  • Choosing \(s=4\) is not allowed because \(a_4=3\) is not greater than all previous elements \(\{1,3,2\}\) (since \(a_4 = a_2 = 3\)).

Xiao H wonders: how many distinct non‐empty sequences can be obtained by applying such operations arbitrarily? Two sequences are considered different if they have different lengths or there exists an index where the corresponding elements differ.

Since the answer could be very large, output it modulo \(998\,244\,353\).

inputFormat

The first line contains two integers \(n\) and \(m\) \((1 \le n \le 10,\; 1 \le m \le 10)\) --- the length of the sequence and the maximum possible value.

The second line contains \(n\) integers \(a_1,a_2,\ldots,a_n\) (each between 1 and \(m\)), representing the initial sequence \(A\).

outputFormat

Output a single integer --- the number of different non-empty sequences obtainable, modulo \(998\,244\,353\).

sample

1 3
3
3