#P15722. [JAG 2023 Summer Camp #3] Gacha 101

[JAG 2023 Summer Camp #3] Gacha 101

题目描述

For each i=1,2,,Ni = 1, 2, \ldots, N, there are AiA_i balls with ii written on them. These are put into a box and mixed up. The string variable ss consists of initially NN "0"s. Balls are taken out of the box one by one (uniformly at random and independently). When a ball with ii written on it is drawn, the ii-th character of ss is changed to "1" (it remains unchanged if it was already "1"). Find the probability, modulo 998,244,353998,244,353, of having a point during this process that ss contains "101" as a contiguous substring.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &N \\ &A_1 \ A_2 \ \ldots \ A_N \end{aligned} $$

The first line consists of an integer NN between 11 and 200,000200,000, inclusive. The second line consists of NN positive integers A1,A2,,ANA_1, A_2, \ldots, A_N. For each ii (1iN1 \leq i \leq N), AiA_i represents the number of balls ii written. And they satisfy 1iNAi<998,244,353\sum_{1 \leq i \leq N} A_i < 998,244,353.

输出格式

Output in a line the probability modulo 998,244,353998,244,353.

3
1 2 3
465847365
10
3 1 4 1 5 9 2 6 5 3
488186016

提示

Note

  • How to find the probability modulo 998,244,353998,244,353
    • It can be proved that the sought probability is always a rational number. Additionally, the constraints of this problem guarantee that if the sought probability is represented as an irreducible fraction yx\frac{y}{x}, then xx is not divisible by 998,244,353998,244,353. Here, there is a unique 0z<998,244,3530 \leq z < 998,244,353 such that yxz(mod998,244,353)y \equiv xz \pmod {998,244,353}, so report this zz.