func_code_string: #include <bits/stdc++.h>   using namespace std;   int arr[4005];   int nxt[4005], prv[4005];   map<int, int> M;   map<int, int> Q;   int main() {     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       if (M.find(arr[i]) != M.end()) {         nxt[M[arr[i]]] = i;         prv[i] = M[arr[i]];         Q[arr[i]]++;         ans = max(ans, Q[arr[i]]);       } else {         prv[i] = -1;         Q[arr[i]]++;         ans = max(ans, Q[arr[i]]);       }       M[arr[i]] = i;       nxt[i] = -1;     }     for (int i = 0; i < n; ++i) {       if (prv[i] != -1) {         continue;       }       for (int j = i + 1; j < n; ++j) {         if (prv[j] != -1) {           continue;         }         int cur = 2;         int t1 = i, t2 = j;         while (t1 != -1 && t2 != -1) {           if (t1 < t2) {             if (nxt[t1] > t2) {               ++cur;             }             t1 = nxt[t1];           } else {             if (nxt[t2] > t1) {               ++cur;             }             t2 = nxt[t2];           }         }         ans = max(ans, cur);       }     }     cout << ans << endl;     return 0;   }   