#P7511. Counting Permutations with Special Inequality Conditions

    ID: 20706 Type: Default 1000ms 256MiB

Counting Permutations with Special Inequality Conditions

Counting Permutations with Special Inequality Conditions

Given integers n, k and an n-permutation \(\pi'\), count the number of permutations \(\pi\) of \(\{1,2,\dots,n\}\) such that exactly k indices i (with \(1 \le i \le n\)) satisfy the inequality

\[ \pi_i < \pi_{\pi'_i} \]

Output the answer modulo \(998244353\).

inputFormat

The first line contains two integers n and k. The second line contains n integers representing the permutation \(\pi'\). It is guaranteed that \(\pi'\) is a permutation of \(\{1, 2, \dots, n\}\).

outputFormat

Output a single integer—the number of valid permutations \(\pi\) modulo \(998244353\).

sample

3 1
1 2 3
0

</p>