The score is just a helper
InterviewTime limit1sMemory limit1024 MB
Given pitches in playing order, find the minimum N so that consecutive notes can be numbered from 1 to N while keeping each up, down, or equal relation.
- Level
Medium4 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Kiwi bird wanted to play the piano well, but could not read sheet music. Then it found a video site with a performance where the piano is played from a sequence of numbers alone! However, when it pressed the keys matching the numbers in the video, the song did not play correctly. In the end, Kiwi bird learned to read sheet music and figured out the rule the video used to turn notes into a sequence.
- Each time a note must be played, write one integer from 1 to a positive integer .
- If the previously played note is lower than the current note, write a number greater than the number written previously.
- If the previously played note is higher than the current note, write a number less than the number written previously.
- If the previously played note is the same as the current note, write the same number as the number written previously.
Having become an expert at reading sheet music, Kiwi bird decided to convert the score into a sequence by these rules and upload a piano performance video to a video site. A larger means more kinds of notes to play, which can make the video harder for viewers. Find the minimum value of so that viewers do not find the video difficult.
Input
The first line contains the number of notes to play in the score.
The second line contains the integers , , , that represent the pitches of the notes in the score, separated by spaces.
The notes in the score are given in the order they are played, and no two or more notes are played at the same time.
Output
Print the minimum value of on the first line.