#P9590. Expected Number of Administrators

    ID: 22737 Type: Default 1000ms 256MiB

Expected Number of Administrators

Expected Number of Administrators

You are given a team that is initially empty. There will be n operations. In each operation, an integer ai is given and one of the following 4 events occurs with equal probability:

  • Add: If ai is not in the team then add ai as a member.
  • Kick: If ai is a member then remove ai from the team. (If ai is not in the team, do nothing.)
  • Promote: If ai is a member then change his status to administrator. (If ai is not in the team, do nothing.)
  • Set Member: If ai is in the team then set his status to member. (If he is already a member or not in the team, do nothing.)

Note:

  • The team starts empty.
  • If ai is not in the team, then the Kick, Promote, and Set Member operations have no effect.
  • If ai is already a member, then the Add and Set Member operations have no effect.
  • If ai is already an administrator, then the Add, Kick, and Promote operations have no effect.

After performing all n operations these events occur independently (each operation chooses one of the four events uniformly at random). Compute the expected number of administrators in the team. Since this expectation is a rational number, output it modulo 998244353.

All formulas should be written in LaTeX. For example, the modulus should be expressed as \(998244353\).

inputFormat

The first line contains an integer \(n\): the number of operations.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\), where \(a_i\) represents the identifier for the operation.

outputFormat

Output a single integer: the expected number of administrators in the team modulo \(998244353\).

sample

1
100
0

</p>