def beau(vals, diff):
    lookup = set(vals)
    result = []

    for x in vals:
        if x - d in lookup and x + d in lookup:
            result.append((x - d, x, x + d))

    return result

n, d     = map(int, input().split())
values   = tuple(map(int, input().split()))
triplets = beau(values, d)

print(len(triplets))

@@ -90,16 +90,19 @@
 if x - d
+iff
  in look
@@ -113,16 +113,19 @@
 nd x + d
+iff
  in look
@@ -160,16 +160,19 @@
 d((x - d
+iff
 , x, x +
@@ -173,16 +173,19 @@
 x, x + d
+iff
 ))%0A%0A    

Update solution.py