fork download
  1. #include <cstdio>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. const int N = 1e6 + 3;
  7.  
  8. unordered_map <int, int> M[N];
  9. int n, a[N], mx = 0;
  10.  
  11. int main (){
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(0);
  14. cout.tie(0);
  15. cin >> n;
  16. for (int i = 0; i < n; ++i){
  17. cin >> a[i];
  18. M[i].reserve(i);
  19. M[i].max_load_factor(0.25);
  20. }
  21. for (int i = 1; i < n; ++i){
  22. for (int j = 0; j < i; ++j){
  23. int x = a[i] - a[j];
  24. M[i][x] = M[j][-x] + 1;
  25. mx = max(mx, M[i][x]);
  26. }
  27. }
  28. cout << mx + 1;
  29. return 0;
  30. }
Success #stdin #stdout 0.03s 58152KB
stdin
Standard input is empty
stdout
1