Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll; 
#define endl '\n';
#define mp make_pair
#define pb push_back

int a[100100];
void solve (){
    int n;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int cnt1=0,cnt0=0;
    int ans=0;
    for (int i=0;i<n;i++){
        cnt0+=(a[i]==0);
        cnt1+=(a[i]==1);
        if(cnt1 && cnt0){
            cnt1=cnt0=0;
            ans++;
        }
    }
    cout<<ans<<endl;
}
int main ()
{    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen ("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while (t--)
        solve();

    return 0;
}
Copy
Tha Bits noomaL
GNU G++17
8 ms
1.3 MB
Accepted