QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#14523. Military Training II

Statistiques

It is time to assemble again, and the instructor of Siri's company is organizing the formation. Siri's company has a total of $n$ students, where the $i$-th student has a height of $a_i$. The instructor wants to arrange them in a line to practice marching. The instructor feels that if the heights of the students in an interval are not consistent, it will not look very neat. He defines the "untidiness" of a sequence as the sum of the ranges of heights of all intervals, where the range is defined as the difference between the maximum and minimum values in the interval. The instructor wants to arrange these $n$ distinct students in a line such that the untidiness of the entire queue is minimized, and he also wants to know how many different arrangements satisfy this. However, the massive amount of calculation makes it impossible for the instructor to complete this task quickly, so he decides to ask Siri, who has the highest programming skill in the company, for help.

Formally: Given a sequence $a_1, a_2, \dots, a_n$ of length $n$, find the number of permutations $p$ such that $\sum_{l=1}^{n} \sum_{r=l}^{n} (\max(a_{p_l}, a_{p_{l+1}}, \dots, a_{p_r}) - \min(a_{p_l}, a_{p_{l+1}}, \dots, a_{p_r}))$ is minimized. Output the minimum value and the number of such arrangements modulo $998\,244\,353$.

Input

The first line contains an integer $n$ ($1 \le n \le 10^3$), representing the number of students. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), representing the heights of the $n$ students.

Output

A single line containing two integers: the minimum untidiness of the queue and the number of arrangements that achieve this minimum untidiness, modulo $998\,244\,353$. Note that the minimum untidiness itself should not be taken modulo.

Examples

Input 1

2
1 2

Output 1

1 2

Input 2

9
9 9 8 2 4 4 3 5 3

Output 2

114 16

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.