n = read_line.to_i a = read_line.split.map(&.to_i).reverse s = 1 ans = 0 1.upto(n - 1) do |i| if a[i] == a[i - 1] s = i end if a[i] == 1 ans += i - s + 1 end end puts ans