C++//# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define fr front
# define il inline
# define fir first
# define sec second
# define vec vector
# define it iterator
# define pb push_back
# define lb lower_bound
# define ub upper_bound
# define all(x) x.begin(), x.end()
# define mem(a, b) memset(a, b, sizeof(a))
# define lc (t[p].l)
# define rc (t[p].r)
# define ls(x) (x << 1)
# define rs(x) (x << 1 | 1)
# define lson ls(p), l, mid
# define rson rs(p), mid + 1, r
# define sqr(x) ((x) * (x))
# define bpc __builtin_popcount
# define lowbit(x) ((x) & (-(x)))
# define geti(x, i) (((x) >> (i)) & 1)
# define set1(x, i) ((x) | (1 << (i)))
# define set0(x, i) ((x) & (~(1 << (i))))
# define debug1(x) cerr << #x << " = " << x << " "
# define debug2(x) cerr << #x << " = " << x << "\n"
# define bug cerr << "--------------------------\n"
# define each1(i, x) for(auto (i) : (x))
# define each2(i, x) for(auto (&i) : (x))
# define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
# define pre(i, a, b) for(int i = (a); i >= (b); -- i)
# define G(i, h, u, ne) for(int i = (h[(u)]); i; i = (ne[(i)]))
# define reps(i, a, b, c) for(int i = (a); i <= (b); i += (c))
# define pres(i, a, b, c) for(int i = (a); i >= (b); i -= (c))
using namespace std;
using DB = double;
using LL = long long;
using LDB = long double;
using PII = pair<int, int>;
using ULL = unsigned long long;
const int N = 5e2 + 10;
const int INF1 = 0x3f3f3f3f, INF2 = INT_MAX;
const LL INF3 = (LL)1e18, INF4 = 0x3f3f3f3f3f3f3f3f, INF5 = LLONG_MAX;
int n, ans, cnt0, cnt1;
int a[N], c[N], lk[N];
vec<int> e[N], c0, c1;
bitset<N> vis, used;
bool dfs(int u){
each2(v, e[u]){
if(vis[v]) continue;
vis[v] = true;
if(!lk[v]){
lk[v] = u;
return true;
}
else{
if(dfs(lk[v])){
lk[v] = u;
return true;
}
}
}
return false;
}
signed main(){
# ifndef LOCAL
freopen("flip.in", "r", stdin);
freopen("flip.out", "w", stdout);
# endif
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> a[i];
rep(i, 1, n){
c[i] = a[i] ^ a[i - 1];
}
rep(i, 1, n){
if(!c[i]) continue;
if(i & 1) c1.pb(i);
else c0.pb(i);
}
each2(p0, c0){
each2(p1, c1){
e[p0].pb(p1);
}
vis.reset();
if(dfs(p0)) used[p0] = true, ans ++;
}
each2(p0, c0){
if(!used[p0]) cnt0 ++;
}
each2(p1, c1){
if(!used[p1]) cnt1 ++;
}
ans += cnt0 / 2 * 2 + cnt1 / 2 * 2;
cnt0 %= 2;
ans += cnt0 * 3;
cout << ans;
return 0;
}
/*
2
4 5
2
*/
/*
9
1 2 3 4 5 6 7 8 9
3
*/
/*
2
1 10000000
4
*/