fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. // declaration
  6. int n,cnt=0,Current_type,lastTotal=0,current_consecutive=0,most_consecutive=0;
  7. cin >> n; n -=1;
  8. int ti;
  9. cin >> ti;
  10. Current_type = ti;
  11. for (int i=1; i<=n ;i++) {
  12. if (ti==Current_type) {
  13. cnt++;
  14. }
  15. else {
  16. lastTotal = cnt;
  17. cnt=1;
  18. Current_type=ti;
  19. }
  20. current_consecutive = min(cnt,lastTotal);
  21.  
  22. most_consecutive = max(most_consecutive,current_consecutive);
  23. cin >> ti;
  24. }
  25. if (most_consecutive == 0) {
  26. cout << 2 << endl;
  27. }
  28. else cout << most_consecutive *2<<endl;
  29. return 0;
  30. }
Success #stdin #stdout 4.46s 5316KB
stdin
Standard input is empty
stdout
2