Codeforces Round 223 (Div. 1)
D
Sereja and Cinema
Codeforces
2500
原题
← CE →
翻译中…

The cinema theater hall in Sereja's city is $*n*$ seats lined up in front of one large screen. There are slots for personal possessions to the left and to the right of each seat. Any two adjacent seats have exactly one shared slot. The figure below shows the arrangement of seats and slots for $*n* = 4$.

翻译中…

image

翻译中…

Today it's the premiere of a movie called "Dry Hard". The tickets for all the seats have been sold. There is a very strict controller at the entrance to the theater, so all $*n*$ people will come into the hall one by one. As soon as a person enters a cinema hall, he immediately (momentarily) takes his seat and occupies all empty slots to the left and to the right from him. If there are no empty slots, the man gets really upset and leaves.

翻译中…

People are not very constant, so it's hard to predict the order in which the viewers will enter the hall. For some seats, Sereja knows the number of the viewer (his number in the entering queue of the viewers) that will come and take this seat. For others, it can be any order.

翻译中…

Being a programmer and a mathematician, Sereja wonders: how many ways are there for the people to enter the hall, such that nobody gets upset? As the number can be quite large, print it modulo $1000000007$ $(10^{9} + 7)$.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ $(1 ≤ *n* ≤ 10^{5})$. The second line contains $*n*$ integers, the $*i*$-th integer shows either the index of the person (index in the entering queue) with the ticket for the $*i*$-th seat or a $0$, if his index is not known. It is guaranteed that all positive numbers in the second line are distinct.

翻译中…

You can assume that the index of the person who enters the cinema hall is a unique integer from 1 to $*n*$. The person who has index 1 comes first to the hall, the person who has index 2 comes second and so on.

翻译中…

Output

翻译中…

In a single line print the remainder after dividing the answer by number $1000000007$ $(10^{9} + 7)$.

翻译中…

样例

Input #1
11
0 0 0 0 0 0 0 0 0 0 0
Output #1
1024
InputCopy OutputCopy
Input #2
6
0 3 1 0 0 0
Output #2
3
InputCopy OutputCopy
题目信息
题号
380D
时间限制
1 s
内存限制
256 MB
标签
组合数学
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。