function beyond(next, last, cache = new Map()) {
const key = String([last, next])
if (cache.has(key)) return cache.get(key)
const possible = next.filter(n => n <= last + 3)
if (possible.length) {
const sum = possible.reduce((sum, p) => {
const withoutP = next.slice(next.findIndex(n => n === p) + 1)
return sum + beyond(withoutP, p, cache)
}, 0)
return cache.set(key, sum), sum
} else {
return cache.set(key, 1), 1
}
}