n = gets.to_s.to_i a = gets.to_s.split.map(&.to_i) b = (0...n).map do |i| a[i] ^ (i % 2) end c = Array.new(n, 1_i64) c[-1] = 0_i64 (1...n).reverse_each do |i| if b[i] == b[i-1] c[i-1] = c[i] + 1 end end ans = 0_i64 n.times do |i| next if a[i] == 0 next if i == n - 1 ans += c[i] end pp ans