Strange Grasshopper
InterviewTime limit2sMemory limit1024 MB
Starting at stone 1, the grasshopper jumps k stones from stone k across a row with destroyed stones. Decide whether it reaches the last stone.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Let us set aside the topic of big dragons and turn to a small grasshopper that lives near the walls of a royal castle.
Like many grasshoppers, it likes to jump across the stones that form the castle walls. It has a favorite row of stones and a favorite way of jumping. If the grasshopper is on the -th stone of the row, it jumps exactly stones forward. For example, from the third stone it jumps to the sixth.
Once the grasshopper climbed onto the first stone of its row, it found that after a recent dragon attack some stones in the row were destroyed, and it cannot jump onto them.
Determine whether the destroyed stones prevent the grasshopper from reaching the last stone with its favorite jumps.
Input
The first line contains an integer (), the number of stones in the grasshopper's favorite row. The second line contains integers separated by spaces. If stone was destroyed by the dragon, then is . Otherwise is .
The first and the last stones are not destroyed.
Output
Print Yes if the grasshopper can reach the last stone with its favorite jumps, and No otherwise.