Problem 512
Count Good Triplets
Easy · 10 pts · Array, Enumeration
Problem
A triplet of positions i < j < k is good if |A[i] - A[j]| <= a, |A[j] - A[k]| <= b and |A[i] - A[k]| <= c, for three given limits a, b and c. Count the good triplets. Triplets are counted by position, so equal values at different positions form different triplets. With N at most 100, checking every triplet with three nested loops is fast enough.
Input
The first line contains N, a, b and c. The second line contains N integers.
Output
Print the number of good triplets.
Constraints
3 <= N <= 100; 0 <= A[i] <= 1000; 0 <= a, b, c <= 1000
Example input
6 7 2 3 3 0 1 1 9 7
Example output
4
Explanation
In 3 0 1 1 9 7 with a = 7, b = 2 and c = 3, the good triplets are (3,0,1), (3,0,1), (3,1,1) and (0,1,1), using the two different 1s. So the answer is 4.