lndjy has his own unique interest in numbers. Today he came up with a multiset

consists of

non-negative integers which are not greater than

. More precisely, he has given a sequence of
non-negative integers 
, representing that for each integer

, the number of elements in

equal to

is exactly

. It is guaranteed that

.
lndjy also showed his great interest in Combinatorics. So he wants to make sequences with

. Let the set of all different sequences which has exactly the same elements as

be

. It's easy to prove that

.
What's more, lndjy loves subsegments and the mex. He defined a function
)
on all subsegments of any given sequence

as
where

is the smallest non-negative integer which is not present in the multiset

. For example,

,

and

.
Finally, he wants you to calculate the value of
%20%5Cbmod%20998244353)