fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long n, input, input_back, output = 0;
  8. long long eel = 0, eel_back = 0;
  9. long long tuna = 0, tuna_back = 0;
  10. long long refrence1 = 0, refrence2 = 0;
  11.  
  12. cin >> n >> input;
  13. (input == 2 ? ++eel : ++tuna);
  14.  
  15. for (int i = 1; i < n; ++i)
  16. {
  17. input_back = input;
  18. cin >> input;
  19.  
  20. if (input != input_back) // then it is an eel and thew one behind it were a tuna
  21. {
  22. if (input == 2)
  23. {
  24. tuna_back = tuna;
  25. tuna = 0;
  26. }
  27. else
  28. {
  29. eel_back = eel;
  30. eel = 0;
  31. }
  32. }
  33.  
  34. if (input == 2)
  35. ++eel;
  36. else
  37. ++tuna;
  38.  
  39. refrence1 = max(tuna, tuna_back);
  40. refrence2 = max(tuna, tuna_back);
  41.  
  42. if (2 * min(refrence1, refrence2) > output)
  43. output = 2 * min(refrence1, refrence2);
  44. }
  45. cout << output;
  46. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
4