#abc270h. Ex - add 1

Ex - add 1

Score : 600600 points

问题描述

你得到一个包含 NN 个非负整数的元组 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N),其中 A1=0A_1=0AN>0A_N>0

高桥有 NN 个计数器。最初,所有计数器的值都是 00。 他将重复以下操作,直到对任意 1iN1\leq i\leq N,第 ii 个计数器的值至少为 AiA_i

均匀随机选择 NN 个计数器中的一个,并将其值设为 00。(每次选择都独立于其他计数器。) 将 其他 计数器的值增加 11

计算并输出高桥重复该操作次数的期望值,结果对 998244353998244353 取模(参见注释)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a tuple of NN non-negative integers A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) such that A1=0A_1=0 and AN>0A_N>0.

Takahashi has NN counters. Initially, the values of all counters are 00.
He will repeat the following operation until, for every 1iN1\leq i\leq N, the value of the ii-th counter is at least AiA_i.

Choose one of the NN counters uniformly at random and set its value to 00. (Each choice is independent of others.)
Increase the values of the other counters by 11.

Print the expected value of the number of times Takahashi repeats the operation, modulo 998244353998244353 (see Notes).

Notes

It can be proved that the sought expected value is always finite and rational. Additionally, under the Constraints of this problem, when that value is represented as PQ\frac{P}{Q} using two coprime integers PP and QQ, one can prove that there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N2×1052\leq N\leq 2\times 10^5
  • 0=A1A2AN10180=A_1\leq A_2\leq \cdots \leq A_N\leq 10^{18}
  • AN>0A_N>0
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the expected value of the number of times Takahashi repeats the operation, modulo 998244353998244353.

Sample Input 1

2
0 2

Sample Output 1

6

Let CiC_i denote the value of the ii-th counter.

Here is one possible progression of the process.

  • Set the value of the 11-st counter to 00, and then increase the value of the other counter by 11. Now, (C1,C2)=(0,1)(C_1,C_2)=(0,1).
  • Set the value of the 22-nd counter to 00, and then increase the value of the other counter by 11. Now, (C1,C2)=(1,0)(C_1,C_2)=(1,0).
  • Set the value of the 11-st counter to 00, and then increase the value of the other counter by 11. Now, (C1,C2)=(0,1)(C_1,C_2)=(0,1).
  • Set the value of the 11-st counter to 00, and then increase the value of the other counter by 11. Now, (C1,C2)=(0,2)(C_1,C_2)=(0,2).

In this case, the operation is performed four times.

The probabilities that the process ends after exactly 1,2,3,4,5,1,2,3,4,5,\ldots operation(s) are $0,\frac{1}{4}, \frac{1}{8}, \frac{1}{8}, \frac{3}{32},\ldots$, respectively, so the sought expected value is $2\times\frac{1}{4}+3\times\frac{1}{8}+4\times\frac{1}{8}+5\times\frac{3}{32}+\dots=6$. Thus, 66 should be printed.

Sample Input 2

5
0 1 3 10 1000000000000000000

Sample Output 2

874839568

update @ 2024/3/10 11:24:40