#include <bits/stdc++.h>
using namespace std;
const int K = 110;
const int N = 200010;
const int M = 1000000007;
int n;
vector<int> ans;
multiset<int> ct;
map<int, int> wrap;
vector<int> stk;
void finish(int a, int b) {
  ans.push_back(a);
  ans.push_back(b);
  ans.push_back(a);
  ans.push_back(b);
  ct.clear();
  wrap.clear();
  stk.clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1, v; i <= n; ++i) {
    cin >> v;
    if (wrap.count(v)) {
      finish(wrap[v], v);
      continue;
    } else {
      if (ct.count(v)) {
        int cnt = ct.count(v) >= 2 ? 1 : 0;
        while (cnt || stk.back() != v) {
          if (stk.back() == v) cnt--;
          wrap[stk.back()] = v;
          stk.pop_back();
        }
      }
      ct.insert(v);
      stk.push_back(v);
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < int(ans.size()); ++i) cout << ans[i] << ' ';
  cout << '\n';
}
