N = gets.to_i B = gets.split.map(&:to_i) S = Array.new(N + 1, 0) B.each_with_index do |b,i| S[i + 1] = S[i] + b end t_ = (1 .. N).inject(0) do |t,n| if S[n] >= n t + S[n] - n else r = S.bsearch_index{|s| s >= n } t + r - n end end puts t_