Problem: give an array A of N (1 <= N <= 2 * 10^6) integer. Find the number of good triplets (i, j, k), where i, j, k are all distinct indices such that 1 <= i < j < k <= N. A good triplet (i, j, k) is a triplet such that A[i] = x, A[j] = y, A[k] = z(x, y, z are given numbers).
Example 1:
Input: 5
1 2 2 1 2
1 2 1
Output:
2
Explanation: two triplets are (1,2,4) and (1,3,4)
Example 2:
Input:
5
1 2 2 1 2
2 1 1
Output:
0
Explanation: there are no good triplets