Greedy Gift Takers
Time limit2sMemory limit512 MB
Each cow takes a gift and reinserts herself c_i positions from the tail; count how many cows never reach the head.
- Level
Hard8 of 10
- Topics
- Math, Simulation
- Solved
- No attempts yet
Problem
Farmer John's rival, Farmer Nhoj, keeps cows () numbered through . They have turned up at Farmer John's farm without warning, and Farmer John, always polite, decides to hand each of them a gift.
Farmer John has an unlimited supply of gifts. Nhoj's cows line up in front of him, cow at the head of the line and cow at the tail. Farmer John expected that at every timestep the cow at the head would take a gift and walk to the tail. Nhoj's cows are not that polite. After taking her gift, a cow does not go to the tail: she cuts in front of some of the cows near the tail. To be exact, cow always cuts exactly cows (). The line always holds cows, so right after taking a gift cow stands at position counted from the head.
Since the supply is unlimited, Farmer John does not mind that some cows take several gifts. He does worry that some cows may take none at all.
Find how many cows never receive a gift, no matter how long the gifts are handed out.
Input
The first line contains one integer .
The second line contains the integers separated by spaces.
Output
Print the number of cows that never receive a gift.