Given an array of integers arr and an integer d. In one step you can jump from index i to index:

i + x where: i + x < arr.length and  0 < x <= d.
i - x where: i - x >= 0 and  0 < x <= d.

In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i, j) < k < max(i, j)).
You can choose any index of the array and start jumping. Return the maximum number of indices you can visit.
Notice that you can not jump outside of the array at any time.
 
Example 1:

Input: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2
Output: 4
Explanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.
Note that if you start at index 6 you can only jump to index 7. You cannot jump to index 5 because 13 > 9. You cannot jump to index 4 because index 5 is between index 4 and 6 and 13 > 9.
Similarly You cannot jump from index 3 to index 2 or index 1.

Example 2:
Input: arr = [3,3,3,3,3], d = 3
Output: 1
Explanation: You can start at any index. You always cannot jump to any index.

Example 3:
Input: arr = [7,6,5,4,3,2,1], d = 1
Output: 7
Explanation: Start at index 0. You can visit all the indicies. 

Example 4:
Input: arr = [7,1,7,1,7,1], d = 2
Output: 2

Example 5:
Input: arr = [66], d = 1
Output: 1

 
Constraints:

1 <= arr.length <= 1000
1 <= arr[i] <= 10^5
1 <= d <= arr.length

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import collections\n\nclass Solution:\n    def maxJumps(self, arr: List[int], d: int) -> int:\n        \n        outEdges = {}\n        inEdges = {}\n        \n        for idx, height in enumerate(arr):\n            \n            jumpRangeRight = list(range(idx+1, min(len(arr), idx+d+1)))\n            jumpRangeLeft = list(range(idx-1, max(0, idx - d) - 1, -1))\n            \n            for jumpRange in [jumpRangeLeft, jumpRangeRight]:\n                for jumpIdx in jumpRange:\n                    if arr[jumpIdx] >= arr[idx]:\n                        break\n\n                    if idx not in outEdges:\n                        outEdges[idx] = set()\n                    outEdges[idx].add(jumpIdx)\n\n                    if jumpIdx not in inEdges:\n                        inEdges[jumpIdx] = set()\n                    inEdges[jumpIdx].add(idx)\n        \n        noInEdges = collections.deque()\n        for idx in range(len(arr)):\n            if idx not in inEdges:\n                noInEdges.append(idx)\n        \n        topologicalOrder = collections.deque()\n        while noInEdges:\n            idx = noInEdges.pop()\n            topologicalOrder.append(idx)\n            if idx not in outEdges:\n                continue\n            for jumpIdx in outEdges[idx]:\n                inEdges[jumpIdx].remove(idx)\n                if not inEdges[jumpIdx]:\n                    noInEdges.append(jumpIdx)\n        \n        maxJumps = 1\n        jumpCount = [1] * len(arr)\n        while topologicalOrder:\n            idx = topologicalOrder.popleft()\n            \n            if idx not in outEdges:\n                continue\n            \n            for jumpIdx in outEdges[idx]:\n                jumpCount[jumpIdx] = max(jumpCount[idx] + 1, jumpCount[jumpIdx])\n                maxJumps = max(jumpCount[jumpIdx], maxJumps)\n                \n        return maxJumps\n        \n    def maxJumpsBfs(self, arr: List[int], d: int) -> int:\n        bfs = collections.deque()\n        \n        for idx in range(len(arr)):\n            bfs.append((idx, 1))\n        \n        stepCount = {}\n        maxSteps = 0\n        \n        while bfs:\n            idx, steps = bfs.popleft()\n\n            # Already found more steps to this index.\n            if idx in stepCount and steps <= stepCount[idx]:\n                continue \n            stepCount[idx] = steps\n\n            maxSteps = max(steps, maxSteps)\n\n            # Process jumps to the right\n            for jumpIdx in range(idx+1, min(len(arr), idx+d+1)):\n                # Can't jump past taller buildings, break loop\n                if arr[jumpIdx] >= arr[idx]:\n                    break\n                    \n                # Explore this jump\n                bfs.append((jumpIdx, steps+1))\n\n            # Process jumps to the left\n            for jumpIdx in range(idx-1, max(0, idx-d) -1, -1):\n                # Can't jump past taller buildings, break loop\n                if arr[jumpIdx] >= arr[idx]:\n                    break\n\n                # Search the next step\n                bfs.append((jumpIdx, steps+1))\n            \n        return maxSteps\n                \n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'maxJumps'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 13032