Help me with this problem

A temple of Snakes Practice Problem in Jump from 2* to 3* (codechef.com)
this is the problem statement if anyone knows how to solve this problem please help mw with it i tried seeing its solution from the video but couldnt understand the solution properly i understood upto an extent but not completely please help me with this guys…