Three Occurrences SOLUTION
You are given an exhibit a comprising of n whole numbers. We mean the subarray a[l..r] as the cluster [al,al+1,… ,ar] (1≤l≤r≤n).
A subarray is viewed as acceptable if each number that happens in this subarray happens there precisely threefold. For instance, the cluster [1,2,2,2,1,1,2,2,2] has three great subarrays:
a[1..6]=[1,2,2,2,1,1];
a[2..4]=[2,2,2];
a[7..9]=[2,2,2].
Figure the quantity of good subarrays of the given exhibit a.
Information
The primary line contains one number n (1≤n≤5⋅105).
The subsequent line contains n whole numbers a1, a2, …, a (1≤ai≤n).
Yield
Print one whole number — the quantity of good subarrays of the exhibit a.
Models
inputCopy
9
1 2 1 2
outputCopy
3
inputCopy
10
1 2 3 4 1 2 3 1 2 3
outputCopy
0
inputCopy
12
1 2 3 4 3 4 2 1 3 4 2 1
outputCopy
1