fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define fi first
  5. #define se second
  6. typedef pair<int, int> pii;
  7. typedef pair<pii, pii> rect;
  8.  
  9. const int MAXN = 2e5+5, LOG = 18;
  10. const int MOD = 998244353;
  11.  
  12. int n, a[MAXN], b, ans;
  13.  
  14. int main(){
  15. cin >> n;
  16.  
  17. for (int i =1; i <= n; i++){
  18. cin >> a[i];
  19. if (i ==1 && a[i] == 2) ans++;
  20. else if ( a[i] == 2 && b==1 && a[i-1] != 1) {
  21. ans++;
  22. b =0;
  23. }
  24. else if ( a[i] == 2 ) b=1;
  25.  
  26. }
  27. cout << ans << endl;
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
10
1 2 2 2 1 2 1 2 2 2
stdout
2