fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n; cin >> n;
  5. int last_count=0,last_type=0,current_half=0,best_half=0;
  6. int count=0;
  7. for (int i=0; i<n ;i++) {
  8. int type,last_half;
  9. cin >> type;
  10. if (type != last_type) {
  11. last_count = count;
  12. count = 1;
  13. }
  14. else count++;
  15. last_type = type;
  16. last_half = current_half;
  17. current_half = min(count,last_count);
  18. best_half = max(best_half,current_half);
  19. }
  20. cout << best_half*2 << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0