Arranging Go Stones

No attempts yetTime limit1sMemory limit128 MB

Problem

You arrange white and black go stones in a single row on a table. First you place a stone at the leftmost position on the table, then a stone at the $2$nd position from the left. You repeat this $n$ times to line up $n$ stones in a horizontal row. However, when placing the new $i$-th stone, you rearrange the stones on the table according to the following rules.

  • If $i$ is odd: the stones already on the table are not changed; the new stone is placed at the $i$-th position from the left.
  • If $i$ is even: if the color of the new stone to be placed at the $i$-th position from the left is the same as the color of the rightmost stone on the table, then the stones on the table are not changed and the new stone is placed at the $i$-th position from the left. Otherwise, that is, if the color of the new stone differs from the color of the rightmost stone on the table, first remove the entire run of consecutive same-colored stones at the right end of the table and replace them with stones of the same color as the $i$-th stone. Then place the $i$-th stone at the right end of the table.

For example, suppose that just after the first $7$ stones have been placed, the table looks like

○○●●○○○

(○ denotes a white stone and ● denotes a black stone.)

  • If the $8$th stone is white (○), it has the same color as the rightmost stone, so it is placed as is. The stones on the table then become
○○●●○○○○
  • If the $8$th stone is black (●), its color differs from the rightmost stone (○), so first the $3$ consecutive white stones (○) at the right end are removed and replaced with black stones (●); then the $8$th stone is placed at the right end. The stones on the table then become
○○●●●●●●

Given the order in which the stones are placed, write a program that finds the number of white stones remaining on the table after all $n$ stones have been arranged.

Input

The first line contains a positive integer $n$ ($1 \le n \le 100000$). For each $i$ ($1 \le i \le n$), line $i+1$ contains an integer $c_i$ representing the color of the $i$-th stone placed: $c_i = 0$ means the $i$-th stone is white, and $c_i = 1$ means it is black.

Output

Output a single line containing the number of white stones on the table after all $n$ stones have been arranged.