← 返回 ibm 的题目列表Count strictly decreasing-by-1 subarrays of length at least 2
类型:online_judge
Given an integer array arr, count the number of contiguous subarrays that satisfy:
subarray length >= 2
for every valid index i inside the subarray (starting from the second element),
arr[i] = arr[i-1] - 1
i.e., the subarray forms an arithmetic sequence with common difference -1.
Input
First line: integer n
Second line: n integers of arr
Output
Print one integer: the number of such subarrays.
Example
Input:
5
5 4 3 1 0
Output:
4
Explanation: [5,4], [5,4,3], [4,3], [1,0].
Example
Input
2
2 1
Output
1