fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, k=1, count=0;
  6. cin >> n;
  7. int a[n];
  8. for(int i = 0; i < n; i++)
  9. {
  10. cin >> a[i];
  11. }
  12.  
  13. for(int i = 1; i < n; i++)
  14. {
  15. if(a[i] == a[i-1])
  16. k++;
  17. else if(k >= 3)
  18. {
  19. count += k;
  20. k=1;
  21. }
  22. else
  23. k=1;
  24. }
  25. if(k >= 3)
  26. count += k;
  27. cout << count;
  28. return 0;
  29. }
Success #stdin #stdout 0s 4520KB
stdin
8
1 3 3 3 2 2 2 2
stdout
7