#P5369. [PKUSC2018] 最大前缀和

[PKUSC2018] 最大前缀和

Description

Xiao C is an algorithm contest enthusiast. One day, Xiao C ran into a very difficult problem: finding the maximum subarray sum of a sequence.

However, Xiao C cannot solve this problem, so Xiao C decides to randomly shuffle the sequence and then take the maximum prefix sum of the shuffled sequence as the answer.

Xiao C knows very well that this algorithm is completely wrong, so he does not care about its correctness. He only cares about the expected value of the computed result. Please help him solve this problem. Since the answer may be very complicated, you only need to output the value of the answer multiplied by n!n! and then taken modulo 998244353998244353. Obviously, this is an integer.

Note: The definition of maximum prefix sum: i[1,n]\forall i \in [1,n], the maximum value of j=1iaj\sum_{j=1}^{i}a_j.

Input Format

The first line contains a positive integer nn, which denotes the length of the sequence.

The second line contains nn numbers, representing the original sequence a[1..n]a[1..n]. The ii-th number is a[i]a[i].

Output Format

Output a non-negative integer, which denotes the answer.

2
-1 2
3

Hint

For 10%10\% of the testdata, 1n91\leq n\leq 9.

For 40%40\% of the testdata, 1n151\leq n\leq 15.

For another 10%10\% of the testdata, in aa there is at most one negative number.

For another 10%10\% of the testdata, a[i]2|a[i]|\leq 2.

For 100%100\% of the testdata, 1n201\leq n\leq 20, i=1na[i]109\sum_{i=1}^{n}|a[i]|\leq 10^9.

Translated by ChatGPT 5