#P18106. [COCI 2026/2027 #2] Jackpot
[COCI 2026/2027 #2] Jackpot
Problem Description
Ivor is a special kind of programmer, but others fail to understand his genius. Most people consider his programs messy because Ivor hates the Enter key more than anything else. This has become unbearable for his friends Dino and Niko, who already have trouble reading, let alone reading his messy code. Therefore, they have decided to force him to use the Enter key.
Ivor’s keyboard has characters, numbered from to , but Niko and Dino have connected each character to the Enter key. Each time Ivor presses the Enter key, at most one character is added to his code: character is added with probability , and with the remaining probability, no character is added. The presses are mutually independent.
Ivor will be forced to press the Enter key until he achieves a jackpot, which occurs when every character appears in his code at least times. Ivor is interested in the expected number of Enter key presses required to achieve the jackpot. Since Ivor cannot write a program himself to answer this question, he needs your help.
Note: Pay attention to the unusual memory limit.
Input Format
The first line contains a positive integer (), the number of characters on the keyboard.
The second line contains integers (, ).
The third line contains integers ().
The fourth line contains integers (, ).
The sum of all probabilities is not greater than . If the jackpot is achievable, then for every non-empty set of characters for which the numerator of the reduced fraction representing the sum of their probabilities is not divisible by .
Output Format
If the jackpot is not achievable, output the word nikada in a single line.
Otherwise, it can be shown that the required answer is a fraction , where and are positive integers and is not divisible by . In a single line, output the value of modulo , where is the modular multiplicative inverse of .
1
1
1
6
6
2
1 1
1 1
2 2
3
1
1
0
6
nikada
Hint
Explanation of example 1
With each press of the Enter key, the only character is added to the code with probability , and it is sufficient to add it just once to achieve the jackpot. Therefore, the expected number of presses is .
Explanation of example 2
With the first press of the Enter key, one of the two characters is guaranteed to be added. After that, the remaining character is added with probability on each press, so an expected additional presses are needed to add it. Therefore, the expected number of presses is .
Explanation of example 3
The probability of adding the only character to the code is , but it must be added at least once to achieve the jackpot. Therefore, the jackpot is impossible to achieve.
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 9 | |
| 2 | 26 | |
| 3 | 39 | |
| 4 | 31 | for each . |
| 5 | No additional constraints. | |