TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

After exploring Mars, NASA has discovered a mysterious kind of extra-terrestrial creature residing on the planet thought to be deserted. The creature is actually a collective body of millions of smaller individual, each comprising only of a few cells. Due to its form and its means of moving, the scientists dub it "Slime".


NASA decided to further investigate the knowledge level of the creature by sending messages to the living and observing its reaction, i.e. whether it knows of geometry by sending a figure of pythagorean theorem graphicalized, and whether it knows of physics by illustrating the gravity equation. To test that whether they knows of programmin, the scientists decided to use the improved version of "longest increasing subsequence" - the so-called "longest jumping subsequence".


A subsequence is defined by a subset of the elements of the original sequence arranged in the same order as they appear originally. A "jumping subsequence", as its name suggests, is simply a sequence whose relations between two adjacent elements alternates between "strictly increasing" and "strictly decreasing". For example, the sequence <2, 3, 2, 4, 1, 2, 1> and <4, 1, 5, 2, 6, 3> and <5, 8> are all legal "jumping subsequence". Being a Slime of much wisdom (certainly you are), your task here is to solve the "longest jumping subsequence" problem. Given a sequence of integer numbers, find the length of the longest subsequence in it that is jumping.

Input Format

There may be multiple testcases.

First line of each testcase consists of an integer N (1 <= N <= 100000), indicating the length of the sequence. Then follows N integers describing the sequence itself. All the integers in the sequence are positive and do not exceed 109.

Output Format

For each testcase, output the length of "longest jumping subsequence" of the original sequence.

Sample Input 1

6
3 4 2 5 1 6

Sample Output 1

6

Hints

Problem Source

Migrated from old NTUJ.

Kelvin

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200