Python3 Solution
\n\nclass Solution:\n    def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:\n        mod=10**9+7    \n        @lru_cache(No
\n```\nclass Solution:\n    def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:\n        mod=10**9+7    \n        @lru_cache(None)\n        def fn(n, x): \n            if x < 0:\n                return 0\n            ans = 0\n            if n == finish:\n                ans += 1\n            for nn in range(len(locations)): \n                if nn != n:\n                    ans += fn(nn, x-abs(locations[n] - locations[nn]))\n            return ans \n        \n        return fn(start, fuel) % mod\n```
['Python', 'Python3']