#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class _T>
inline _T loww(_T n) {
  return n & (-n);
}
template <class _T>
inline void swapp(_T &x, _T &y) {
  _T t;
  t = x, x = y, y = t;
}
template <class _T>
inline _T minn(_T i, _T j) {
  return i > j ? j : i;
}
template <class _T>
inline _T maxx(_T i, _T j) {
  return i > j ? i : j;
}
template <class _T>
inline _T gcd(_T b, _T c) {
  return b && c ? (c ? gcd(c, b % c) : b) : b | c;
}
template <class _T>
inline _T abss(_T b) {
  return b > 0 ? b : -b;
}
struct node {
  int v, col;
};
node a[500005 << 2];
void DOWN(int l, int r, int dq) {
  if (a[dq].col) {
    if (l != r) {
      a[dq << 1].col = a[dq << 1].v = a[dq << 1 | 1].col = a[dq << 1 | 1].v =
          a[dq].col;
    }
    a[dq].col = 0;
  }
}
void UP(int l, int r, int dq) {
  DOWN(l, r, dq);
  if (a[dq << 1].v == a[dq << 1 | 1].v)
    a[dq].v = a[dq << 1].v;
  else
    a[dq].v = -1;
}
void U(int l, int r, int dq, int b, int c, int v) {
  DOWN(l, r, dq);
  if (l == r) {
    a[dq].v = v;
  } else {
    if (b <= l && r <= c) {
      a[dq].v = a[dq].col = v;
    } else {
      int mid = (l + r) >> 1;
      if (b <= mid) U(l, mid, dq << 1, b, c, v);
      if (c > mid) U(mid + 1, r, dq << 1 | 1, b, c, v);
      UP(l, r, dq);
    }
  }
}
int Q(int l, int r, int dq, int b) {
  DOWN(l, r, dq);
  if (l == r || a[dq].v != -1)
    return a[dq].v;
  else {
    int mid = (l + r) >> 1;
    if (b <= mid)
      return Q(l, mid, dq << 1, b);
    else
      return Q(mid + 1, r, dq << 1 | 1, b);
  }
}
void build(int l, int r, int dq) {
  if (l == r) {
    a[dq].col = a[dq].v = 0;
  } else {
    a[dq].col = a[dq].v = 0;
    int mid = (l + r) >> 1;
    build(l, mid, dq << 1);
    build(mid + 1, r, dq << 1 | 1);
  }
}
bool outflag = true;
void out(int b) {
  if (outflag)
    outflag = false;
  else
    printf(" ");
  printf("%d", b);
}
pair<int, int> goal[500005];
int val[500005];
map<int, int> mymap;
int pre[500005], gl = 0;
int en = 0;
int main() {
  int n, i, t, js, told, b;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  build(1, n, 1);
  for (i = 1; i <= n; i++) {
    pre[i] = mymap[val[i]];
    mymap[val[i]] = i;
    t = pre[i];
    told = i;
    js = 0;
    while (t > en) {
      if (js++ > 1) break;
      if (t + 1 <= told - 1) U(1, n, 1, t + 1, told - 1, val[i]);
      b = Q(1, n, 1, t);
      if (b != 0) {
        goal[gl++] = make_pair(b, val[i]);
        en = i;
        break;
      }
      told = t;
      t = pre[t];
    }
    if (js == 3) {
      goal[gl++] = make_pair(val[i], val[i]);
      en = i;
    }
  }
  printf("%d\n", gl * 4);
  for (i = 0; i < gl; i++) {
    out(goal[i].first);
    out(goal[i].second);
    out(goal[i].first);
    out(goal[i].second);
  }
  printf("\n");
  return 0;
}

### Prompt

Create a solution in CPP for the following problem:

After you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task.

Given a sequence of integer numbers a1, a2, ..., an. You are to find a longest sequence b1, b2, ..., b4m, that satisfies the following conditions:

  * b4k + 1 = b4k + 3 for all valid integer k; 
  * b4k + 2 = b4k + 4 for all valid integer k; 
  * sequence b is subsequence of a (not necessarily contiguous subsequence). 



And finally... Alex had given this complicated task to George, and George gave it to you. Help George to cope with the task.

Input

The first line contains a single integer n (1 ≤ n ≤ 5·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In the first line print a single integer 4m — the maximal possible length of required sequence b. In the second line print 4m integers b1, b2, ..., b4m, that is required sequence.

If there are multiple optimal answers you may print any of them.

Examples

Input

4
3 5 3 5


Output

4
3 5 3 5


Input

10
35 1 2 1 2 35 100 200 100 200


Output

8
1 2 1 2 100 200 100 200

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class _T>
inline _T loww(_T n) {
  return n & (-n);
}
template <class _T>
inline void swapp(_T &x, _T &y) {
  _T t;
  t = x, x = y, y = t;
}
template <class _T>
inline _T minn(_T i, _T j) {
  return i > j ? j : i;
}
template <class _T>
inline _T maxx(_T i, _T j) {
  return i > j ? i : j;
}
template <class _T>
inline _T gcd(_T b, _T c) {
  return b && c ? (c ? gcd(c, b % c) : b) : b | c;
}
template <class _T>
inline _T abss(_T b) {
  return b > 0 ? b : -b;
}
struct node {
  int v, col;
};
node a[500005 << 2];
void DOWN(int l, int r, int dq) {
  if (a[dq].col) {
    if (l != r) {
      a[dq << 1].col = a[dq << 1].v = a[dq << 1 | 1].col = a[dq << 1 | 1].v =
          a[dq].col;
    }
    a[dq].col = 0;
  }
}
void UP(int l, int r, int dq) {
  DOWN(l, r, dq);
  if (a[dq << 1].v == a[dq << 1 | 1].v)
    a[dq].v = a[dq << 1].v;
  else
    a[dq].v = -1;
}
void U(int l, int r, int dq, int b, int c, int v) {
  DOWN(l, r, dq);
  if (l == r) {
    a[dq].v = v;
  } else {
    if (b <= l && r <= c) {
      a[dq].v = a[dq].col = v;
    } else {
      int mid = (l + r) >> 1;
      if (b <= mid) U(l, mid, dq << 1, b, c, v);
      if (c > mid) U(mid + 1, r, dq << 1 | 1, b, c, v);
      UP(l, r, dq);
    }
  }
}
int Q(int l, int r, int dq, int b) {
  DOWN(l, r, dq);
  if (l == r || a[dq].v != -1)
    return a[dq].v;
  else {
    int mid = (l + r) >> 1;
    if (b <= mid)
      return Q(l, mid, dq << 1, b);
    else
      return Q(mid + 1, r, dq << 1 | 1, b);
  }
}
void build(int l, int r, int dq) {
  if (l == r) {
    a[dq].col = a[dq].v = 0;
  } else {
    a[dq].col = a[dq].v = 0;
    int mid = (l + r) >> 1;
    build(l, mid, dq << 1);
    build(mid + 1, r, dq << 1 | 1);
  }
}
bool outflag = true;
void out(int b) {
  if (outflag)
    outflag = false;
  else
    printf(" ");
  printf("%d", b);
}
pair<int, int> goal[500005];
int val[500005];
map<int, int> mymap;
int pre[500005], gl = 0;
int en = 0;
int main() {
  int n, i, t, js, told, b;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  build(1, n, 1);
  for (i = 1; i <= n; i++) {
    pre[i] = mymap[val[i]];
    mymap[val[i]] = i;
    t = pre[i];
    told = i;
    js = 0;
    while (t > en) {
      if (js++ > 1) break;
      if (t + 1 <= told - 1) U(1, n, 1, t + 1, told - 1, val[i]);
      b = Q(1, n, 1, t);
      if (b != 0) {
        goal[gl++] = make_pair(b, val[i]);
        en = i;
        break;
      }
      told = t;
      t = pre[t];
    }
    if (js == 3) {
      goal[gl++] = make_pair(val[i], val[i]);
      en = i;
    }
  }
  printf("%d\n", gl * 4);
  for (i = 0; i < gl; i++) {
    out(goal[i].first);
    out(goal[i].second);
    out(goal[i].first);
    out(goal[i].second);
  }
  printf("\n");
  return 0;
}

```