33OJ
登录 注册

#P18106. [COCI 2026/2027 #2] Jackpot

    ID: 20867 远端评测题 5000ms 8MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>概率论COCI(克罗地亚)2026

[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 nn characters, numbered from 11 to nn, 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 ii is added with probability ai/bia_i/b_i, 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 ii appears in his code at least kik_i 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 nn (1≤n≤100 0001 \le n \le 100\,000), the number of characters on the keyboard.

The second line contains nn integers k1,k2,…,knk_1, k_2, \ldots, k_n (ki≥0k_i \ge 0, 1≤k1+k2+⋯+kn≤221 \le k_1+k_2+\cdots+k_n \le 22).

The third line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

The fourth line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \le b_i \le 10^9, ai≤bia_i \le b_i).

The sum of all probabilities ai/bia_i/b_i is not greater than 11. If the jackpot is achievable, then for every non-empty set of characters for which ki>0k_i > 0 the numerator of the reduced fraction representing the sum of their probabilities is not divisible by 109+710^9+7.

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 P/QP/Q, where PP and QQ are positive integers and QQ is not divisible by 109+710^9+7. In a single line, output the value of P⋅Q−1P \cdot Q^{-1} modulo 109+710^9+7, where Q−1Q^{-1} is the modular multiplicative inverse of QQ.

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 1/61/6, and it is sufficient to add it just once to achieve the jackpot. Therefore, the expected number of presses is 66.

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 1/21/2 on each press, so an expected 22 additional presses are needed to add it. Therefore, the expected number of presses is 1+2=31+2=3.

Explanation of example 3

The probability of adding the only character to the code is 00, 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 n=1n=1
2 26 k1+k2+⋯+kn≤2k_1+k_2+\cdots+k_n \le 2
3 39 k1+k2+⋯+kn≤16k_1+k_2+\cdots+k_n \le 16
4 31 ki≤1k_i \le 1 for each i=1,2,…,ni=1,2,\ldots,n.
5 No additional constraints.