LearnPy Hub
← Arena
IntermediateRating 1400

Longest Zigzag Sequence

A zigzag sequence's differences strictly alternate between positive and negative (a sequence with one element, or two different elements, is a zigzag). Delete some numbers (keeping the order) to get the longest zigzag. Print its length.

Input

n, then n integers.

Output

One integer.

Sample 1

Input
6
1 7 4 9 2 5
Output
6

Sample 2

Input
10
1 17 5 10 13 15 10 5 16 8
Output
7
solution.py
Output appears here
Longest Zigzag Sequence · Python Arena problem · LearnPy Hub