#P10185. [YDOI R1] Necklace
[YDOI R1] Necklace
Background
hdkk is making a necklace.
Problem Description
hdkk has colors of beads. For the -th color, there are beads. He can choose any number of beads and string them into a necklace.
Each color has a beauty value . hdkk defines a “beauty score” for a necklace: if the -th color appears times in the necklace and , then the beauty score of this necklace increases by .
Now he wants to know the sum of beauty scores over all different necklaces. Please compute the answer modulo .
Two necklaces are considered different if and only if there exists a bead that appears in one necklace but does not appear in the other.
Note that every bead is distinct, even if they have the same color.
Input Format
Line contains one positive integer .
Line contains integers, where the -th number is .
Line contains integers, where the -th number is .
Output Format
Output one integer: the sum of beauty scores of all different necklaces modulo .
2
1 2
2 3
38
2
18 2
9 1
786624
Hint
Sample Explanation #1
Color : , color : .
There are different necklaces in total: $\left \{1 \right \},\left \{2\right \},\left \{3\right \},\left \{1,2 \right \},\left \{1,3 \right \},\left \{2,3 \right \},\left \{1,2,3 \right \}$. The total beauty score is .
This problem uses bundled testdata.
| Subtask ID | Points | ||
|---|---|---|---|
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5