F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

DZY Loves Orzing

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 250    Accepted Submission(s): 63


Problem Description
DZY has a $n \times n$ square matrix which is used to Orz JRY. Every morning,

DZY always finds $n^2$ people with distinct height, and they form a square matrix. Let person $i$ denote the $i$-th shortest person.

When they start to Orz JRY, JRY smiles and starts waving to them. JRY has a requirement. If he looks straight at the $i$-th column, he can see exactly $a_i$ people. If the person $i$ stands in front of the person $j$ and $i>j$, person $j$ is blocked.

JRY wants to know how many different matrices they can form, so he asked DZY to tell him the answer.

Now, DZY is asking you to work out the result.

![](../../data/images/C573-1004-1.jpg)
 

Input
The input consists several test cases.($TestCase\leq 5$)

The first line contains a integer $n(1\leq n\leq 10^5)$.

The second line, $n$ integers $a_i(1\leq a_i\leq n)$.
 

Output
For each query, please print a line containing a number representing the answer modulo $(10^9-51711)$.
 

Sample Input
2 1 2 3 2 1 1 7 2 4 3 5 2 4 3
 

Sample Output
6 20160 67779489
 

Hint
query 1. There are 6 possible ways in the picture.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 02:06:31, Gzip enabled