# import bisect # import heapq ## deque, defaultdict, Counter # from collections import ## SortedList, SortedDict, SortedSet # from sortedcontainers import ## itertools, combinations, permutations # from itertools import # from atcoder import def solve(): n,d = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in range(n): ai = a[i] for j in range(i+1, n): if a[j] - ai != d: continue aj = a[j] for k in range(j+1, n): if a[k] - aj == d: ans += 1 print(ans) if __name__ == "__main__": solve()