class Solution(object):
    def kDifferences(self, arr, k):
        m, res = set(), 0

        for n in arr:
            m.add(n)

        for n in m:
            if n + k in m:
                res += 1

        return res


if __name__ == '__main__':
    print Solution().kDifferences([5, 1, 5, 3, 4, 2, 2], 2)
