# [Jelly], 16 bytes

    FLḶ0ẋ;þµŒpSP$€1e

[Try it online!][TIO-j9suzmx0]

[Jelly]: https://github.com/DennisMitchell/jelly
[TIO-j9suzmx0]: https://tio.run/##y0rNyan8/9/N5@GObQYPd3VbH953aOvRSQXBASqPmtYYpv53Odx@dNLDnTNA3Mj//6OjDQ0MY3W4FEC0joIhlA1kGSDEwVyYFIxvYIjQCdEKkzCAa4XqQBgKFQCphhAodsMVwLkIG6BWGECtQIhDRWBujAUA "Jelly – Try It Online"

-1 byte thanks to Mr. Xcoder

I developed this completely independently of Jonathan Allan but now looking at his is exactly the same: