@@ -0,0 +1,496 @@
+# https://www.hackerrank.com/challenges/beautiful-triplets%0A%0Aimport itertools%0Aimport bisect%0A%0An, d = input().strip().split(' ')%0An, d = %5Bint(n), int(d)%5D%0Aa = %5Bint(x) for x in input().strip().split(' ')%5D%0A%0A%0Adef index(a, x):%0A    i = bisect.bisect_left(a, x)%0A    if i != len(a) and a%5Bi%5D == x:%0A        return i%0A    return -1%0A%0Atotal = 0%0Afor i in range(len(a)):%0A    a_j = d + a%5Bi%5D%0A    j = index(a, a_j)%0A    if j %3E i:%0A        a_k = d + a%5Bj%5D%0A        if index(a, a_k) %3E j:%0A            total += 1%0A%0Aprint(total)%0A

add beautiful-triplet solution