#P8321. Expected Permutation Minimum Product
Expected Permutation Minimum Product
Expected Permutation Minimum Product
Given two sequences A and B of length \( n \) satisfying:
- \( A_1 \ge A_2 \ge \cdots \ge A_n \) (i.e. \( A \) is non‐increasing);
- \( A_n \ge \min_{1\le i\le n} B_i \) (i.e. the smallest element in \( A \) is at least the minimum element in \( B \)).
For any permutation \( \pi \) of \( \{1,2,\dots,n\} \), define the value function:
\[ f(\pi)=\prod_{i=1}^n \min\left(A_i, B_{\pi(i)}\right), \]where each permutation is equally likely. Compute the expected value of \( f(\pi) \) modulo \( 998244353 \), i.e. compute
[ \left(\frac{1}{n!}\sum_{\pi} f(\pi)\right) \bmod 998244353. ]
inputFormat
The input consists of three lines:
- The first line contains a single integer \( n \), the length of the sequences.
- The second line contains \( n \) integers \( A_1, A_2, \dots, A_n \) separated by spaces.
- The third line contains \( n \) integers \( B_1, B_2, \dots, B_n \) separated by spaces.
outputFormat
Output a single integer: the expected value of \( f(\pi) \) modulo \( 998244353 \).
sample
1
5
3
3
</p>