Inversion Number Squared
Time limit2sMemory limit1024 MB
Given a_i copies of each value i from 1 to n, find the expected square of the inversion count of a uniformly random arrangement, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Probability, Combinatorics, Math
- Solved
- No attempts yet
Problem
Consider sequences made of copies of , copies of , , and copies of . Pick one of these sequences uniformly at random. Find the expected value of the square of its inversion count, modulo .
The inversion count of a sequence is the number of pairs with and .
Input
The first line contains , the maximum value in the sequence. ()
The second line contains , the number of copies of each value , separated by spaces. (; )
Output
Print the answer modulo .
Hint
The expected value of the square of the inversion count is a rational number. Write it as with and coprime. You can prove that is not a multiple of . The answer is the smallest non-negative integer that satisfies .
There are two sequences made of one and one : and . Their inversion counts are and , so the expected square is . Since , the answer is .