atcoder#ABC272H. [ABC272Ex] Flipping Coins 2
[ABC272Ex] Flipping Coins 2
Score : points
Problem Statement
coins numbered are arranged in a row. Initially, all coins are face up. Also, you are given a sequence of length consisting of integers between and .
Snuke will choose a permutation of at equal probability and perform operations. In the -th operation,
- he flips coins: coin , coin , , and coin .
After the operations, Snuke receives yen (the currency in Japan) from his mother, where is the number of face-up coins.
Find the expected value, modulo , of the money Snuke will receive.
Definition of expected value modulo $998244353$
In this problem, we can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, when the sought expected value is represented as an irreducible fraction , it is guaranteed that is indivisible by .
Then, an integer between and such that is uniquely determined. Find such .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
2
0 1
1
can be either or .
- If is chosen as :
In the first operation, coin is flipped, and in the second operation, coin and coin are flipped. One coin, coin , results in being face up, so he receives yen.
- If is chosen as :
In the first operation, coin and coin are flipped, and in the second operation, coin is flipped. One coin, coin , results in being face up, so he receives yen.
Therefore, the expected value of the money he receives is yen.
4
3 1 1 2
665496237
Print the expected value modulo .