Public Judge

pjudge

حد الوقت: 1.5 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#21888. 【PR #15】Minimal Representation

الإحصائيات

In an assignment related to the minimal representation of strings, there are $n$ strings $s_1, s_2, \dots, s_n$ with lengths $a_1, a_2, \dots, a_n$ respectively.

Define $f(s)$ as the starting position of the lexicographically smallest cyclic shift of string $s$. Since such a starting position might not be unique, $f(s)$ is defined as the smallest possible position. For example, for the string cbacba, its minimal cyclic shift is acbacb, and the chosen starting position is $3$ (using 1-based indexing).

The requirement for the assignment is to write down $f(s_1), f(s_2), \dots, f(s_n)$ in order. However, due to Little A's carelessness, he incorrectly wrote down the answers in the following order: $f(s_n), f(s_1), f(s_2), \dots, f(s_{n-1})$.

Assume that each character of these strings is generated uniformly and independently at random by the teacher, consisting only of lowercase English letters. You need to help Little A calculate the expected number of correct answers in his assignment, modulo $998244353$.

Input

The first line contains an integer $n$, representing the number of strings in the assignment.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$, representing the lengths of the strings.

Output

Output an integer representing the answer.

Examples

Input 1

5
3 1 5 2 4

Output 1

727907401

Input 2~4

See the provided files.

Constraints

For all data, $1 \leq n \leq 10^5$, $1 \leq a_i \leq 10^5$.

Subtask ID $n\le$ $a_i\le$ Special Property Score
$1$ $5$ $5$ None $15$
$2$ $100$ $1000$ None $20$
$3$ $100$ $100000$ None $15$
$4$ $100000$ $100000$ $a_i$ are all equal $15$
$5$ $50000$ $100000$ None $15$
$6$ $100000$ $100000$ None $20$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.