Source Code
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()

int main() {
    IOS;
    int t;cin>>t;
    int ans=0;
    int aa=0,z=0;
    while(t--){
        int a;cin>>a;
        if(a==1)aa++;
        else if(a==0)z++;
        if(aa&&z){
            ans++;
            aa=0,z=0;
        }
    }
    cout<<ans;


}
Copy
Tha Bits BE-NASL
GNU G++17
5 ms
908 KB
Accepted