#P3205. [HNOI2010] 合唱队

[HNOI2010] 合唱队

Description

To achieve a better performance at the upcoming gala, Xiao A, the leader of the AAA choir, needs to arrange the choir members into a lineup based on their heights. Suppose there are nn people in total, the ii-th person’s height is hih_i meters (1000hi20001000 \le h_i \le 2000), and any two people have different heights. Suppose the final lineup consists of nn people standing in one row. To simplify the process, Xiao A came up with the following method: he first lets everyone stand in an initial lineup in an arbitrary order, and then, from left to right, inserts each person into the final lineup according to these rules:

  • The first person is directly inserted into the empty current lineup.

  • For each person starting from the second, if he is taller than the person immediately before him in the initial lineup (hh is larger), insert him at the right end of the current lineup. If he is shorter (hh is smaller), insert him at the left end.

After all nn people have been inserted into the current lineup, the final lineup is obtained.

For example, there are 66 people in the initial lineup, with heights 1850,1900,1700,1650,1800,17501850, 1900, 1700, 1650, 1800, 1750.
Then Xiao A will obtain the final lineup step by step as follows:

  • 1850, 1900, because 1900>18501900 > 1850.

  • 1700, 1850, 1900, because 1700<19001700 < 1900.

  • 1650, 1700, 1850, 1900, because 1650<17001650 < 1700.

  • 1650, 1700, 1850, 1900, 1800, because 1800>16501800 > 1650.

  • 1750, 1650, 1700, 1850, 1900, 1800, because 1750<18001750 < 1800.

Therefore, the final lineup is 1750, 1650, 1700, 1850, 1900, 1800.

Xiao A has an ideal lineup in mind and wants to know how many initial lineups can result in that ideal lineup.

Compute the answer modulo 1965082719650827.

Input Format

The first line contains an integer nn.
The second line contains nn integers, representing Xiao A’s ideal lineup.

Output Format

Output one line with a single integer, which is the value of the answer mod19650827\bmod 19650827.

4
1701 1702 1703 1704
8

Hint

For 30% of the testdata, n100n \le 100.
For 100% of the testdata, n1000n \le 1000, 1000hi20001000 \le h_i \le 2000.

Translated by ChatGPT 5