#P15705. [2018 KAIST RUN Spring] Zigzag
[2018 KAIST RUN Spring] Zigzag
Description
A sequence is called “Zigzag” if no three of its consecutive elements are monotone.
More formally, if sequence of length is Zigzag if, for all (), neither nor holds.
For given sequence of length , you should find a longest subsegment of which is a Zigzag sequence. Sequence of length is subsegment of sequence of length if, for some , , , holds.
Input Format
Input consists of two lines.
The first line contains integer , length of sequence .
The second line contains space-separated integers. th number is .
Output Format
Print out the length of longest subsegment of which is a Zigzag sequence.
3
1 2 3
2
5
1 3 4 2 5
4
Hint
Constraints
- ()
京公网安备 11011102002149号