405148: GYM101806 Z Zigzag

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Z. Zigzagtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

A sequence is called "Zigzag" if no three of its consecutive elements are monotone.

More formally, if sequence A of length N is Zigzag if, for all i (1 ≤ i ≤ N - 2), neither Ai ≤ Ai + 1 ≤ Ai + 2 nor Ai ≥ Ai + 1 ≥ Ai + 2 holds.

For given sequence A of length N, you should find a longest subsegment of A which is a Zigzag sequence.

Sequence B of length M is subsegment of sequence A of length N if, for some i, B1 = Ai, B2 = Ai + 1 ..., BM = Ai + M - 1 holds.

Input

Input consists of two lines.

The first line contains integer N, length of sequence A. (3 ≤ N ≤ 5, 000)

The second line contains space-separated N integers. ith number is Ai. (1 ≤ Ai ≤ 109)

Output

Print out the length of longest subsegment of A which is a Zigzag sequence.

ExampleInput
5
1 3 4 2 5
Output
4

加入题单

上一题 下一题 算法标签: