Jump Jump
InterviewTime limit2sMemory limit512 MB
Given jump distances on a row of n stones, count how many stones are reachable from a starting stone via left or right jumps that stay on the bridge.
Problem
Yeongwoo is a frog. Ribbit, ribbit, ribbit.
Yeongwoo stands on a stone bridge built from stones in a row. The stones are numbered 1, 2, and so on up to from the left, and each stone has one number written on it. If the number on stone is , Yeongwoo can jump from stone to stone , which is places to the left, or to stone , which is places to the right. He cannot leave the bridge, so a jump whose destination number is smaller than 1 or larger than is not available.
A stone is visitable if Yeongwoo can land on it after some number of jumps from the starting stone. The starting stone also counts as visitable.
Given the starting stone, find how many stones Yeongwoo can visit.
Input
The first line contains the number of stones . ()
The second line contains the jump distances , separated by spaces. ()
The third line contains the starting stone . ()
Output
Print the number of stones Yeongwoo can visit on the first line.