import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val a = IntArray(n) { nextInt() } val b = IntArray(n) { i -> if (i % 2 == 0) a[i] else 1 - a[i] } val c = IntArray(n) { 0 } var streak = 1 var prev = -1 for (i in n - 1 downTo 0) { if (i == n - 1) { streak = 0 prev = b[i] } else if (b[i] != prev) { prev = b[i] streak = 1 } else { streak++ } c[i] = streak } var ans = 0L for (i in 0 until n - 1) { if (a[i] == 1) ans += c[i] } println(ans) } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", abs(1L.shl(26))) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion