Time limit: 2 seconds Memory limit: 256 MB Yes! Time passes quickly and Lite and Fite,…
- User
Time limit: 2 seconds Memory limit: 256 MB Yes! Time passes quickly and Lite and Fite, who are hardly connected, intend to remember the memories they have together in the salon, this time at the opening of Kodakup.
They want to do this by putting on a great show for the ages.
A sequence of natural numbers is written on the age of the opening hall, and Lyte and Fite stand on either side of it. in stage i The i-th of one of these two people, chosen by themselves, is a member of the sequence that is between these two people and its value is equal to the number i selects i is, Khoraman moves to that member of the sequence and stands on it.
memory game
If in the stage k k-th between Leite and Fite no members with value k If k does not exist, the display ends.
Fite realized that how many stages the show would last depended on their movements. Lithe wants to choose movements so that the show lasts as long as possible; You tell him that this show will last a few steps at most.
input The first line of the input contains a natural number n n is the length of the sequence of numbers on age.
In the next line n n number a i a i They are separated by a distance. 1 ≤ n ≤ 100
000 1≤n≤100 000 1 ≤ a i ≤ n
( 1 ≤ i ≤ n ) 1≤a i ≤n (1≤i≤n)
output The output of the program contains only one number, which represents the maximum length of the Lite and Fite mnemonic display. If they can't move
1 Print −1.
Example Sample entry 1 5 1 2 4 5 3 Plain text Sample output 1 5 Plain text The example above is exactly like the picture in the question. In this test, Lithe, Lithe, Fite, Lite, and Fite move and pass through all 5 age positions.
Sample entry 2 6 1 4 2 3 5 2 Plain text Sample output 2 4 write code in c++
- Assistant