[ABC485G] 相似相邻子段 (Similar Adjacent Subarrays)
Score : points
Problem Statement
You are given a sequence of positive integers of length .
Find the number of triples of integers that satisfy all of the following conditions.
-
-
-
There is exactly one integer between and , inclusive, such that .
Constraints
-
-
-
All input values are integers.
Input
The input is given from Standard Input in the following format:
$N$
$A_1$ $A_2$ $\ldots$ $A_N$
Output
Print the answer in one line.
Sample Input 1
7
1 2 1 3 1 2 1
Sample Output 1
10
The triples that satisfy the conditions are the following ten: $(0,1,2),(0,2,4),(1,2,3),(1,3,5),(2,3,4),(2,4,6),(3,4,5),(3,5,7),(4,5,6),(5,6,7)$.
Sample Input 2
2
1000000000 1000000000
Sample Output 2
0
Sample Input 3
6
1 2 3 1 2 4
Sample Output 3
6