func_code_string: #include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 5e5 + 500;   long long seg[4 * maxn];   long long dp[maxn];   long long q[maxn];   long long houp[maxn];   long long a[maxn];   map<long long, long long> last;   map<long long, vector<long long> > las;   void bild() { fill(seg, seg + 4 * maxn, -1); }   void update(long long L, long long R, long long node, long long l, long long r,               long long v) {     if (l <= L && R <= r) {       seg[node] = max(seg[node], v);       return;     }     if (r <= L || R <= l) {       return;     }     seg[2 * node] = max(seg[2 * node], seg[node]);     seg[2 * node + 1] = max(seg[2 * node + 1], seg[node]);     long long mid = (L + R) / 2;     update(L, mid, 2 * node, l, r, v);     update(mid, R, 2 * node + 1, l, r, v);   }   long long findd(long long L, long long R, long long node, long long x) {     long long mid = (L + R) / 2;     if (L + 1 == R) {       return seg[node];     }     if (x < mid) {       return max(seg[node], findd(L, mid, 2 * node, x));     } else {       return max(seg[node], findd(mid, R, 2 * node + 1, x));     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     bild();     for (long long i = 0; i < n; i++) {       long long v = a[i];       if (last.count(v) > 0) {         q[i] = findd(0, n, 1, last[v]);         update(0, n, 1, last[v] + 1, i, last[v]);       } else {         q[i] = -1;       }       last[v] = i;     }     for (long long i = 0; i < n; i++) {       long long v = a[i];       las[v].push_back(i);       if (las[v].size() >= 4) {         q[i] = max(q[i], las[v][las[v].size() - 4]);       }     }     dp[0] = 0;     houp[0] = -1;     for (long long i = 1; i < n; i++) {       if (q[i] == -1) {         houp[i] = -1;         dp[i] = dp[i - 1];       } else {         if (q[i] == 0) {           dp[i] = max(dp[i - 1], 1LL);         } else {           dp[i] = max(dp[i - 1], 1 + dp[q[i] - 1]);         }         if (dp[i] == dp[i - 1]) {           houp[i] = -1;         } else {           houp[i] = q[i];         }       }     }     cout << 4 * dp[n - 1] << endl;     vector<long long> stk;     long long p = n - 1;     while (p >= 0) {       if (houp[p] == -1) {         p--;       } else {         stk.push_back(a[p]);         stk.push_back(a[houp[p]]);         stk.push_back(a[p]);         stk.push_back(a[houp[p]]);         p = houp[p] - 1;       }     }     reverse(stk.begin(), stk.end());     for (long long i = 0; i < stk.size(); i++) {       cout << stk[i] <<    ;     }   }   