IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)
C
Bear and Up-Down
Codeforces
1900
原题
← BD →
翻译中…

The life goes up and down, just like nice sequences. Sequence $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ is called nice if the following two conditions are satisfied:

翻译中…
  • $*t*_{*i*} < *t*_{*i* + 1}$ for each odd $*i* < *n*$;
  • $*t*_{*i*} > *t*_{*i* + 1}$ for each even $*i* < *n*$.
翻译中…

For example, sequences $(2, 8)$, $(1, 5, 1)$ and $(2, 5, 1, 100, 99, 120)$ are nice, while $(1, 1)$, $(1, 2, 3)$ and $(2, 5, 3, 2)$ are not.

翻译中…

Bear Limak has a sequence of positive integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices $*i* < *j*$ and swap elements $*t*_{*i*}$ and $*t*_{*j*}$ in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.

翻译中…

Input

翻译中…

The first line of the input contains one integer $*n*$ ($2 ≤ *n* ≤ 150 000$) — the length of the sequence.

翻译中…

The second line contains $*n*$ integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($1 ≤ *t*_{*i*} ≤ 150 000$) — the initial sequence. It's guaranteed that the given sequence is not nice.

翻译中…

Output

翻译中…

Print the number of ways to swap two elements exactly once in order to get a nice sequence.

翻译中…

Note

翻译中…

In the first sample, there are two ways to get a nice sequence with one swap:

翻译中…
  1. Swap $*t*_{2} = 8$ with $*t*_{4} = 7$.
  2. Swap $*t*_{1} = 2$ with $*t*_{5} = 7$.
翻译中…

In the second sample, there is only one way — Limak should swap $*t*_{1} = 200$ with $*t*_{4} = 50$.

翻译中…

样例

Input #1
5
2 8 4 7 7
Output #1
2
InputCopy OutputCopy
Input #2
4
200 150 100 50
Output #2
1
InputCopy OutputCopy
Input #3
10
3 2 1 4 1 4 1 4 1 4
Output #3
8
InputCopy OutputCopy
Input #4
9
1 2 3 4 5 6 7 8 9
Output #4
0
InputCopy OutputCopy
题目信息
题号
653C
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟

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