#include <bits/stdc++.h>
using namespace std;
int n, x;
map<int, int> b, cnt;
vector<int> ans, st;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (b.find(x) != b.end()) {
      ans.push_back(b[x]);
      ans.push_back(x);
      ans.push_back(b[x]);
      ans.push_back(x);
      b.clear();
      cnt.clear();
      st.clear();
    } else {
      if (cnt.find(x) != cnt.end()) {
        while (cnt[x] > 1 || st.back() != x) {
          int y = st.back();
          st.pop_back();
          b[y] = x;
          cnt[y]--;
        }
      } else
        cnt[x] = 0;
      cnt[x]++;
      st.push_back(x);
    }
  }
  printf("%d\n", (int)ans.size());
  for (int a : ans) printf("%d ", a);
  return 0;
}
