#abc272h. Ex - Flipping Coins 2

Ex - Flipping Coins 2

Score : 600600 points

问题描述

设有编号为 0,1,,N10,1,\ldots,N-1NN 枚硬币排成一行。最初,所有硬币均为正面朝上。同时,你得到了一个长度为 NN 的由 00N1N-1 的整数组成的序列 AA

Snuke 将以等概率选择一个包含 (1,,N)(1,\ldots,N) 的排列 p=(p1,p2,,pN)p=(p_1,p_2,\ldots,p_N),并执行 NN 次操作。在第 ii(1iN)(1\leq i \leq N) 操作中,

  • 他会翻转 (Api+1)(A_{p_i}+1) 枚硬币:编号为 (i1)modN(i-1) \bmod N(i1+1)modN(i-1+1 ) \bmod N\ldots(i1+Api)modN(i -1+ A_{p_i}) \bmod N 的硬币。

经过 NN 次操作后,Snuke 从他母亲那里得到 kk 日元(日本货币),其中 kk 是正面朝上的硬币数量。

求 Snuke 将会收到的钱数的期望值,模 998244353998244353

998244353998244353 下期望值的定义

在这个问题中,可以证明所求期望值始终是一个有理数。此外,在本题的约束条件下,若所求期望值表示为不可约分数 yx\frac{y}{x},则保证 xx 不被 998244353998244353 整除。

此时,存在一个介于 00998244352998244352 之间的整数 zz,满足 xzy(mod998244353)xz \equiv y \pmod{998244353},且这个 zz 唯一确定。找出这样的 zz

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

Problem Statement

NN coins numbered 0,1,,N10,1,\ldots,N-1 are arranged in a row. Initially, all coins are face up. Also, you are given a sequence AA of length NN consisting of integers between 00 and N1N-1.

Snuke will choose a permutation p=(p1,p2,,pN)p=(p_1,p_2,\ldots,p_N) of (1,,N)(1,\ldots,N) at equal probability and perform NN operations. In the ii-th (1iN)(1\leq i \leq N) operation,

  • he flips (Api+1)(A_{p_i}+1) coins: coin (i1)modN(i-1) \bmod N, coin (i1+1)modN(i-1+1 ) \bmod N, \ldots, and coin (i1+Api)modN(i -1+ A_{p_i}) \bmod N.

After the NN operations, Snuke receives kk yen (the currency in Japan) from his mother, where kk is the number of face-up coins.

Find the expected value, modulo 998244353998244353, of the money Snuke will receive.

Definition of expected value modulo 998244353998244353

In this problem, we can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, when the sought expected value is represented as an irreducible fraction yx\frac{y}{x}, it is guaranteed that xx is indivisible by 998244353998244353.

Then, an integer zz between 00 and 998244352998244352 such that xzy(mod998244353)xz \equiv y \pmod{998244353} is uniquely determined. Find such zz.

Constraints

  • 1N2×1051 \leq N\leq 2\times 10^5
  • 0AiN10\leq A_i \leq N-1
  • 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 answer.

Sample Input 1

2
0 1

Sample Output 1

1

pp can be either (1,2)(1,2) or (2,1)(2,1).

  • If (1,2)(1,2) is chosen as pp:

In the first operation, coin 00 is flipped, and in the second operation, coin 11 and coin 00 are flipped. One coin, coin 00, results in being face up, so he receives 11 yen.

  • If (2,1)(2,1) is chosen as pp:

In the first operation, coin 00 and coin 11 are flipped, and in the second operation, coin 11 is flipped. One coin, coin 11, results in being face up, so he receives 11 yen.

Therefore, the expected value of the money he receives is 11 yen.

Sample Input 2

4
3 1 1 2

Sample Output 2

665496237

Print the expected value modulo 998244353998244353.

update @ 2024/3/10 11:29:18