N = gets.to_i A = gets.split.map(&:to_i) ans = 0 cnt = 1 (N - 2).downto(0) do |i| ans += cnt if A[i] == 1 if A[i] == A[i - 1] cnt = 1 else cnt += 1 end end puts ans