Building 3
Time limit1sMemory limit512 MB
Given the sequence B with one entry deleted from A, where A_i is the longest increasing chain ending at building i, count how many full sequences A could produce B.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Array, Greedy
- Solved
- No attempts yet
Problem
The International Olympiad in Informatics will be held in Japan. To welcome the contestants, the city plans to decorate the tall buildings along the main avenue from the airport to the hotel where the athletes stay. A well-known designer said the buildings used for decoration must get taller as you move from the airport toward the hotel. In other words, if the heights of the decorated buildings are in order from the one closest to the airport, then must hold.
To make the decoration as impressive as possible, the number of decorated buildings should be as large as possible. JOI was asked to choose the buildings. He realized that a building owner might demand two things at once: that the owner's building must be used for decoration, and that it must be the one closest to the hotel among the decorated buildings, so that it stands out.
There are buildings along the avenue. Call the building that is -th closest to the airport building (). All heights are different. To be ready for any such demand, JOI computed the following in advance. Suppose building is used for decoration and is the closest to the hotel among the decorated buildings. Then the maximum number of buildings that can be chosen is . JOI wrote the integer sequence and submitted it to Chairman K of the JOI committee.
However, the note Chairman K received contained only the integer sequence of length . Chairman K does not know the building heights, so Chairman K cannot compute the values .
Chairman K thinks JOI forgot one number. Among all possible integer sequences , how many become after deleting exactly one entry?
JOI may have made other mistakes as well. For some values of , there may be no such sequence at all.
Write a program that counts the possible sequences that become after removing one entry.
Input
The first line contains , the number of buildings along the avenue. Each of the next lines contains (), the -th value in the note.
Output
Print one integer on a single line: the number of possible sequences that become after removing one entry.
Constraints
.
for .