#5139. [Usaco2017 Dec]Greedy Gift Takers

内存限制:128 MiB 时间限制:10 Sec


Farmer John's nemesis, Farmer Nhoj, has NN cows (1≤N≤10^5), conveniently numbered 1…N. They have 
unexpectedly turned up at Farmer John's farm, so the unfailingly polite Farmer John is attempting to
 give them gifts.To this end, Farmer John has brought out his infinite supply of gifts, and Nhoj's c
ows have queued up in front of him, with cow 11 at the head of the queue and cow N at the tail. Farm
er John was expecting that at every timestep, the cow at the head of the queue would take a gift fro
m Farmer John and go to the tail of the queue. However, he has just realized that Nhoj's cows are no
t that polite! After receiving her gift, each cow may not go to the tail of the queue, but rather ma
y cut some number of cows at the tail, and insert herself in front of them. Specifically, cow ii wil
l always cut exactly cici cows (0≤ci≤N-1).Farmer John knows that some cows might receive multiple 
gifts; as he has an infinite supply, this does not worry him. But he is worried that some cows might
 become unhappy if they do not get any gifts.Help Farmer John find the number of cows who never rece
ive any gifts, no matter how many gifts are handed out.
有 N (1 <= N <= 10^5)头牛按顺序排成一列,编号从1到N,1 号牛在队头,N 号牛在队尾。每次位于队头的牛 i 
拿到一个礼物,然后插入到从队尾数 c_i 头牛之前的位置。举个栗子: 初始队列 1 2 3 4 5, c_1 = 2,c_2 = 
3,则第一次操作后的序列为 2 3 4 1 5,第二次操作后的序列为 3 2 4 1 5 。重复无限次操作,求最后有几头牛


The first line contains a single integer, N.
The second line contains N space-separated integers c1,c2,…,cN


Please output the number of cows who cannot receive any gifts.



1 2 0