cswork / OAOpen practice workspace

IBMOA #14

Count Descending Subarrays

Estimated EasyJudge-ready

Topics (AI-labelled)Two PointersIn-place Arrays

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

Input

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

Output one integer, the answer.

Example 1

Input:

5
7 6 5 5 4

Output:

4

Example 2

Input:

4
4 3 2 1

Output:

6

Example 3

Input:

1
9

Output:

0

Example notes

The examples give 4, 6 and 0 respectively.

Editorial

Loading solution…