AtCoder Grand Contest 013
A
Sorted Arrays
AtCoder
⌀ 614
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given an array $A$ of length $N$. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide $A$ into?

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 10^5$
  • $1 \leq A_i \leq 10^9$
  • Each $A_i$ is an integer.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 ... A_N

翻译中…

Output

翻译中…

Print the minimum possible number of subarrays after division of $A$.

翻译中…

样例

Input #1
6
1 2 3 2 2 1
Output #1
2
One optimal solution is to divide the array into $[1,2,3]$ and $[2,2,1]$.
Input #2
9
1 2 1 2 1 2 1 2 1
Output #2
5
Input #3
7
1 2 3 2 1 999999999 1000000000
Output #3
3
题目信息
题号
agc013_a
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。