#include<iostream>
#include<string>
#incldue<cstring>
using namespace std;
const int MAXN = 100010;
unsigned short s[MAXN];
int main()
{
int t,f,top,ans,i,n,x;
while(cin>>n)
{
top = ans = 0;
memset(s,0,sizeof(s));
cin>>f;
t = f;
s[++top] = 1;
for(i = 1; i < n; i++)
{
cin>>x;
if(f!=x)
{
f = x;
if(i%2 && top)
if(top > 1)
s[top-1] += s[top]+1,top--;
else
s[top]++,t = !t;
else s[++top] = 1;
}
else s[top]++;
}
if(top%2 == t) top--;
while(top > 0)
{
ans += s[top];
top -= 2;
}
cout<<ans<<endl;
}
return 0;
}
#include<string>
#incldue<cstring>
using namespace std;
const int MAXN = 100010;
unsigned short s[MAXN];
int main()
{
int t,f,top,ans,i,n,x;
while(cin>>n)
{
top = ans = 0;
memset(s,0,sizeof(s));
cin>>f;
t = f;
s[++top] = 1;
for(i = 1; i < n; i++)
{
cin>>x;
if(f!=x)
{
f = x;
if(i%2 && top)
if(top > 1)
s[top-1] += s[top]+1,top--;
else
s[top]++,t = !t;
else s[++top] = 1;
}
else s[top]++;
}
if(top%2 == t) top--;
while(top > 0)
{
ans += s[top];
top -= 2;
}
cout<<ans<<endl;
}
return 0;
}