1
# Runtime: 3516 ms (Top 53.70%) | Memory: 22.1 MB (Top 43.52%)3
from bisect import bisect_left4
from functools import lru_cache9
self, locations: List[int], start: int, finish: int, fuel: int11
start = locations[start]12
end = locations[finish]14
start = bisect_left(locations, start)15
end = bisect_left(locations, end)19
if fuel == 0 and i == end:25
while j >= 0 and abs(locations[j] - locations[i]) <= fuel:26
res += dfs(j, fuel - abs(locations[j] - locations[i]))29
while j < len(locations) and abs(locations[j] - locations[i]) <= fuel:30
res += dfs(j, fuel - abs(locations[j] - locations[i]))34
return dfs(start, fuel) % (10**9 + 7)