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 = 0 (1 .. N).inject(0) do |m, n| m_ = S[m] >= n ? m : (m .. N).find{|m_| S[m_] >= n } t += (n - m_).abs m_ end puts t