
import java.util.*
import Stone.*
import com.sun.org.apache.xpath.internal.WhitespaceStrippingElementMatcher

fun main(args:Array<String>):Unit {
    var n = readLine()!!.toInt()
    while (n != 0) {
        val line = Line()
        repeat(n){
            when(readLine()!!.toInt()){
                0 -> when(it % 2){
                    0 -> line.addOdd(White())
                    else -> line.addEven(White())
                }
                else -> when(it % 2){
                    0 -> line.addOdd(Black())
                    else -> line.addEven(Black())
                }
            }
        }
        println(line.stones().sumBy{when(it){
            is White -> it.length
            else -> 0
        }})
        n = readLine()!!.toInt()
    }
}
sealed class Stone(open var length:Int){
    data class White(override var length:Int = 1):Stone(length){
        operator fun plus(other:White):White = White(length + other.length)
    }
    data class Black(override var length:Int = 1):Stone(length){
        operator fun plus(other:Black):Black = Black(length + other.length)
    }
}
class Line{
    private val mDeque:Deque<Stone> = LinkedList<Stone>()
    private fun addFirst(black:Black):Unit{
        when(mDeque.size){
            0 -> mDeque.addFirst(black)
            else -> when(mDeque.first){
                is Black -> mDeque.first.length += black.length
                else -> mDeque.addFirst(black)
            }
        }
    }
    private fun addFirst(white:White):Unit{
        when(mDeque.size){
            0 -> mDeque.addFirst(white)
            else -> when(mDeque.first){
                is White -> mDeque.first.length += white.length
                else -> mDeque.addFirst(white)
            }
        }
    }
    fun addOdd(black:Black):Unit {
        addFirst(black)
    }
    fun addOdd(white:White):Unit {
        addFirst(white)
    }
    fun addEven(black:Black):Unit {
        when(mDeque.size){
            0 -> mDeque.addFirst(black)
            else ->
                when(mDeque.first){
                    is Black -> addFirst(black)
                    else -> {
                        val first = mDeque.removeFirst()
                        addFirst(Black(first.length + black.length))
                    }
                }
        }
    }
    fun addEven(white:White):Unit {
        when(mDeque.size){
            0 -> mDeque.addFirst(white)
            else ->
                when(mDeque.first){
                    is White -> addFirst(white)
                    else -> {
                        val first = mDeque.removeFirst()
                        addFirst(White(first.length + white.length))
                    }
                }
        }
    }
    fun stones():Iterable<Stone> = mDeque
}
