P14360 [CSP-J 2025] Polygon
Description
Little R likes playing with sticks. Little R has $n$ sticks, and the length of the $i$-th stick ($1 \leq i \leq n$) is $a_i$.
Little X wants Little R to choose several sticks from these $n$ sticks and connect them end to end in any order to form a polygon. Little R does not know the condition for sticks to form a polygon, so Little X told him directly: for $m$ sticks with lengths $l_1, l_2, \dots, l_m$, these $m$ sticks can form a polygon if and only if $m \geq 3$ and the sum of the lengths of all sticks is **greater than** twice the maximum length among all sticks, that is, $\sum_{i=1}^{m} l_i > 2 \times \max_{i=1}^{m} l_i$.
Since Little R now knows the condition for sticks to form a polygon, Little X asks a harder question: how many ways are there to choose sticks such that the chosen sticks can form a polygon? You need to help Little R compute the number of ways to choose sticks such that the chosen sticks can form a polygon. Two ways are different if and only if **the sets of indices** of the chosen sticks are different, that is, there exists some $1 \leq i \leq n$ such that one way chooses the $i$-th stick but the other way does not. Since the answer may be large, you only need to compute the answer modulo $998,244,353$.
Input Format
The first line of the input contains one positive integer $n$, which is the number of Little R's sticks.
The second line of the input contains $n$ positive integers $a_1, a_2, \dots, a_n$, which are the lengths of Little R's sticks.
Output Format
Output one line with a non-negative integer, which is the number of ways for Little R to choose sticks such that the chosen sticks can form a polygon, modulo $998,244,353$.
Explanation/Hint
### Sample 1 Explanation
There are the following $9$ ways to choose sticks such that the chosen sticks can form a polygon:
1. Choose the 2nd, 3rd and 4th sticks. The sum of lengths is $2 + 3 + 4 = 9$, and the maximum length is $4$;
2. Choose the 2nd, 4th and 5th sticks. The sum of lengths is $2 + 4 + 5 = 11$, and the maximum length is $5$;
3. Choose the 3rd, 4th and 5th sticks. The sum of lengths is $3 + 4 + 5 = 12$, and the maximum length is $5$;
4. Choose the 1st, 2nd, 3rd and 4th sticks. The sum of lengths is $1 + 2 + 3 + 4 = 10$, and the maximum length is $4$;
5. Choose the 1st, 2nd, 3rd and 5th sticks. The sum of lengths is $1 + 2 + 3 + 5 = 11$, and the maximum length is $5$;
6. Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is $1 + 2 + 4 + 5 = 12$, and the maximum length is $5$;
7. Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is $1 + 3 + 4 + 5 = 13$, and the maximum length is $5$;
8. Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is $2 + 3 + 4 + 5 = 14$, and the maximum length is $5$;
9. Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is $1 + 2 + 3 + 4 + 5 = 15$, and the maximum length is $5$.
### Sample 2 Explanation
There are the following $6$ ways to choose sticks such that the chosen sticks can form a polygon:
1. Choose the 1st, 2nd and 3rd sticks. The sum of lengths is $2 + 2 + 3 = 7$, and the maximum length is $3$;
2. Choose the 3rd, 4th and 5th sticks. The sum of lengths is $3 + 8 + 10 = 21$, and the maximum length is $10$;
3. Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is $2 + 2 + 8 + 10 = 22$, and the maximum length is $10$;
4. Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is $2 + 3 + 8 + 10 = 23$, and the maximum length is $10$;
5. Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is $2 + 3 + 8 + 10 = 23$, and the maximum length is $10$;
6. Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is $2 + 2 + 3 + 8 + 10 = 25$, and the maximum length is $10$.
### Sample 3
See $\textit{\textbf{polygon/polygon3.in}}$ and $\textit{\textbf{polygon/polygon3.ans}}$ in the contestant's directory.
This sample satisfies the constraints of test cases $7 \sim 10$.
### Sample 4
See $\textit{\textbf{polygon/polygon4.in}}$ and $\textit{\textbf{polygon/polygon4.ans}}$ in the contestant's directory.
This sample satisfies the constraints of test cases $11 \sim 14$.
### Subtasks
For all testdata, it is guaranteed that:
- $3 \leq n \leq 5\,000$;
- For all $1 \leq i \leq n$, $1 \leq a_i \leq 5\,000$.
::cute-table{tuack}
| Test case | $n \leq$ | $\max_{i=1}^{n} a_i \leq$ |
| :--: | :--: | :--: |
| $1 \sim 3$ | $3$ | $10$ |
| $4 \sim 6$ | $10$ | $10^2$|
| $7 \sim 10$ | $20$ | ^ |
| $11 \sim 14$ | $500$ | ^ |
| $15 \sim 17$ | ^ | $1$ |
| $18 \sim 20$ | $5\,000$ | ^ |
| $21 \sim 25$ | ^ | $5\,000$ |
Translated by QwenWork