#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 300010;
int n , arr[N] , cur[N];
vector< pair< int , int > > v;
int main(){
scanf("%d",&n);
int last = 0;
for(int i = 0 ;i < n - 1;i++){
scanf("%d",&arr[i]);
cur[i] += arr[i];
cur[i + 1] += arr[i];
if(arr[i] == 0){
v.push_back(make_pair(last , i));
last = i + 1;
}
}
v.push_back(make_pair(last , n - 1));
int ans = 0;
for(int a , i = 0 ;i < (int)v.size();i++){
a = 0;
for(int j = v[i].first ;j <= v[i].second;j++){
if(cur[j] & 1)
a++;
}
ans += max(1 , a / 2);
}
cout << ans - 1 << endl;
return 0;
}
Copy