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