AmazonOA #234
Get Number of Perfect Packaging
Estimated MediumJudge-ready
Topics (AI-labelled)State MachinesDP Basics
Each package gets a stamp numbered 1..5. When the price rises between adjacent packages the stamps must strictly increase, when it falls they must strictly decrease, and when it stays equal the stamp numbers must differ. Count the plans modulo 1000000007, and output 0 if there is none.
Input
The first line contains n; the second line contains the prices. 1≤n≤100000, 1≤price≤100000.
Output
Output a single integer, the answer.
Example 1
Input:
3
3 1 1
Output:
40
Example 2
Input:
3
1 2 3
Output:
10
Example 3
Input:
6
1 2 3 4 5 6
Output:
0
Example notes
The answers are 40, 10 and 0. Six strictly increasing prices need six different stamps, but there are only five.
Editorial
Loading solution…