fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[1007], n, ans = 0;
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(0);
  9.  
  10. cin >> n;
  11. for (int i = 1; i <= n; i++) cin >> a[i];
  12.  
  13. for (int i = 1; i <= n; i++) {
  14. map<int, int> cnt;
  15. for(int j = i; j <= n; j++) {
  16. cnt[a[j]]++;
  17. if (cnt.size() > 2) break;
  18. for (auto [color, amount] : cnt) {
  19. ans = max(ans, amount);
  20. }
  21. }
  22. }
  23.  
  24. cout << ans;
  25. }
  26.  
Success #stdin #stdout 0.01s 5300KB
stdin
9
2
7
3
7
7
3
7
5
7
stdout
4