Source Code
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, ans = 0;
    cin >> n;
    set<int> s;

    while(n --){
        bool b;
        cin >> b;
        s.insert(b);
        if(s.size() == 2)
            ans ++, s.clear();
    }
    cout << ans << '\n';
}
Copy
Tha Bits ahmad_salah
GNU G++17
11 ms
876 KB
Accepted