cswork / OA打开练习工作台

IBMOA #14

Count Descending Subarrays

估计简单可在线判题

考点(AI 标注)双指针滑窗原地数组

Count only contiguous subarrays of length at least 2 in which every adjacent element decreases by exactly 1.

输入格式

The first line contains n, and the second line contains the integers. The source only gives n≥1; on this site n≤200000 and −10^9≤element≤10^9.

输出格式

Output one integer, the answer.

样例 1

输入:

5
7 6 5 5 4

输出:

4

样例 2

输入:

4
4 3 2 1

输出:

6

样例 3

输入:

1
9

输出:

0

样例说明

The examples give 4, 6 and 0 respectively.