#SDNU1646. Extraordinary Permutation
Extraordinary Permutation
Description
Given a permutation of length , you need to calculate the product of the the minimum divided by the maximum in each non-empty subarray.
Since the answer may be decimal fraction, you only need to output the result after taking the model of .
Tips:
-
A permutation of length is a sequence of integers from to of length n containing each number exactly once. For example , are permutations, and are not.
-
An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. For example, the subarrays of are and .
Format
Input
The input has only two lines.
The first line of input is an integer .
The second line of input is a permutation of length .
Output
Output one integer indicating the .
Samples
3
3 1 2
720954255
Hints
The non-empty subarray of is and .
The minimum values are .
The maximum values are .
So the answer is $\frac{3}{3}*\frac{1}{1}*\frac{2}{2}*\frac{1}{3}*\frac{1}{2}*\frac{1}{3}=\frac{1}{18}\equiv 720954255 \pmod{998244353} $.