atcoder#ABC257H. [ABC257Ex] Dice Sum 2
[ABC257Ex] Dice Sum 2
Score : points
Problem Statement
The six-sided dice speciality shop "Saikoroya" sells dice. The -th die (singular of dice) has written on its each side, and has a price of .
Takahashi is going to choose exactly of them and buy them.
Currently, "Saikoroya" is conducting a promotion: Takahashi may roll each of the purchased dice once and claim money whose amount is equal to the square of the sum of the numbers shown by the dice. Here, each die shows one of the six numbers uniformly at random and independently.
Maximize the expected value of (the amount of money he claims) - (the sum of money he pays for the purchased dice) by properly choosing dice to buy. Print the maximized expected value modulo .
Definition of the expected value modulo $998244353$
We can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, the sought expected value can be expressed by an irreducible fraction where is indivisible by .
In this case, we can uniquely determine the integer between and (inclusive) such that . Print such .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 2
1 2 3
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
20
If he buys the -nd and -rd dice, the expected value of (the amount of money he claims) - (the sum of money he pays for the purchased dice) equals , which is the maximum expected value.
10 5
2 5 6 5 2 1 7 9 7 2
5 5 2 4 7 6
2 2 8 7 7 9
8 1 9 6 10 8
8 6 10 3 3 9
1 10 5 8 1 10
7 8 4 8 6 5
1 10 2 5 1 7
7 4 1 4 5 4
5 10 1 5 1 2
5 1 2 3 6 2
1014