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

int main(){
// #ifndef ONLINE_JUDGE
//   freopen("in.txt", "r", stdin);
// #endif
ios_base::sync_with_stdio(0);
cin.tie(0);

  const int N = 1e5 + 1; 
  int n;  cin >> n;
  int a[N];
  for(int i = 0; i < n; ++i)
    cin >> a[i];
  
  int c1 = 0, c0 = 0, ans = 0;
  for(int i = 0; i < n; ++i){
    if(a[i] == 1) c1++;
    else  c0++;
    if(c1 > 0 && c0 > 0){
      ans++;
      c1 = c0 = 0;
    }
  }
  cout << ans;
  


 
  return 0;
}
Copy
Tha Bits Ammar_Lahloh
GNU G++17
8 ms
1.4 MB
Accepted