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

int main() {
	int n;
	cin>>n;
	int ans = 0;
	bool zero = false;
	bool one = false;
	for(int i=0;i<n;i++) {
		int x;
		cin>>x;
		if(x==0)
			zero = true;
		else
			one = true;
		if(zero && one) {
			ans++;
			zero = one = false;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
Copy
Tha Bits Mr-Spy
GNU G++17
14 ms
780 KB
Accepted