n, k = gets.split.map(&:to_i)
a = n.times.map{gets.to_i}

class FeTree
    def initialize(n)
        @n = n
        @f = Array.new(@n+1,0)
    end

    def add(i, x)
        while i <= @n
            @f[i] += x
            i += i & -i
        end
    end

    def sum(i)
        s = 0
        while i > 0
            s += @f[i]
            i -= i & -i
        end
        s
    end
end

l = FeTree.new(n)
r = FeTree.new(n)

fl = Array.new(n)
fr = Array.new(n)

x = a[0]
n.times do |i|
    next if (x - a[i]).abs > k
    x = a[i]
    l.add(i+1, 1)
    fl[i] = 0
end

x = a[-1]
(n-1).downto(0) do |i|
    next if (x - a[i]).abs > k
    x = a[i]
    r.add(i+1, 1)
    fr[i] = 0
end

ans = 0
pre_l = 0
pre_r = 0
n.times do |i|
    next if !fl[i] || !fr[i]
    ans += 1
    x = l.sum(i)
    y = r.sum(i)
    ans += [x - pre_l, y - pre_r].max
    pre_l = x + 1
    pre_r = y + 1
end

p ans