QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#16164. Flower Gardener

统计

The gardener has planted a row of flowers, each with its own height. As the flowers grow taller, they become more crowded. The gardener decides to remove some of the flowers, leaving the rest in their original positions, so that the remaining flowers have more space to grow and the resulting arrangement is more distinctive.

Specifically, the heights of the flowers can be viewed as a sequence $h_1, h_2, \dots, h_n$. Suppose that after some flowers are removed, the heights of the remaining flowers are $g_1, g_2, \dots, g_m$. The gardener wants at least one of the following two conditions to be satisfied:

Condition A: For all $i$, $g_{2i} > g_{2i-1}$ and $g_{2i} > g_{2i+1}$. Condition B: For all $i$, $g_{2i} < g_{2i-1}$ and $g_{2i} < g_{2i+1}$.

Note that when $m=1$, both conditions are satisfied; when $m > 1$, at most one can be satisfied.

What is the maximum number of flowers that can be left in their original positions?

Input

The first line contains an integer $n$, representing the initial number of flowers. The second line contains $n$ integers, $h_1, h_2, \dots, h_n$, representing the height of each flower.

Output

Output a single integer $m$, representing the maximum number of flowers that can be left in their original positions.

Examples

Input 1

5
5 3 2 1 2

Output 1

3

Note

There are several ways to keep exactly 3 flowers. For example, keeping the 1st, 4th, and 5th flowers, with heights 5, 1, and 2 respectively, satisfies Condition B.

Constraints

For 20% of the data, $n \le 10$; For 30% of the data, $n \le 25$; For 70% of the data, $n \le 1000$, $0 \le h_i \le 1000$; For 100% of the data, $1 \le n \le 100,000$, $0 \le h_i \le 1,000,000$. All $h_i$ are generated randomly, and the random numbers are uniformly distributed within the interval.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.