Problem: Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coincides character by character with its second half. Bob started deleting all the repeats from the string. He does it as follows: while it's possible, Bob takes the shortest repeat, if it is not unique, he takes the leftmost one, and deletes its left half and everything that is to the left of this repeat.

You're given the string seen by Bob. Find out, what it will look like after Bob deletes all the repeats in the way described above.

Input

The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.

Output

In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.

Examples

Input

6
1 2 3 1 2 3


Output

3
1 2 3 


Input

7
4 5 6 5 6 7 7


Output

1
7 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int Rank[30][150000];
int Suffix[150000];
int Lcp[150000];
struct entry {
  int A[2];
  int pos;
} Temp[150000];
long long str[150000];
int N, step, cnt;
bool way(entry x, entry y) {
  return x.A[0] < y.A[0] or (x.A[0] == y.A[0] and x.A[1] < y.A[1]);
}
void Build_Suffix_Array() {
  for (int i = 0; i < N; i++) Rank[0][i] = str[i] - 'a';
  for (step = 1, cnt = 1; (cnt >> 1) < N; step++, (cnt <<= 1)) {
    for (int i = 0; i < N; i++) {
      Temp[i].A[0] = Rank[step - 1][i];
      Temp[i].A[1] = (i + cnt < N) ? Rank[step - 1][i + cnt] : -1000000007;
      Temp[i].pos = i;
    }
    sort(Temp, Temp + N, way);
    for (int i = 0; i < N; i++) {
      Rank[step][Temp[i].pos] = (i > 0 and Temp[i].A[0] == Temp[i - 1].A[0] and
                                 Temp[i].A[1] == Temp[i - 1].A[1])
                                    ? Rank[step][Temp[i - 1].pos]
                                    : i;
    }
  }
  for (int i = 0; i < N; i++) {
    Suffix[i] = Temp[i].pos;
  }
  step--;
}
void Build_Lcp_Array() {
  for (int i = 0, l = 0; i < N; i++) {
    if (Rank[step][i] != N - 1) {
      for (int j = Suffix[Rank[step][i] + 1];
           j + l < N and i + l < N and str[i + l] == str[j + l];)
        l++;
      Lcp[Rank[step][i]] = l;
      if (l) l--;
    }
  }
}
int lcp(int x, int y) {
  if (x == y) return N - x;
  int ret = 0;
  for (int i = step; i >= 0 && x < N && y < N; i--) {
    if (Rank[i][x] == Rank[i][y]) x += (1 << i), y += (1 << i), ret += (1 << i);
  }
  return ret;
}
int RMQ[30][150000];
void Build_RMQ() {
  for (int i = 0; i < N; i++) RMQ[0][i] = Lcp[i];
  for (int j = 1; j <= step; j++) {
    for (int i = 0; i < N - 1; i++) {
      if (i + (1 << j) >= N - 1)
        RMQ[j][i] = 1000000007;
      else {
        RMQ[j][i] =
            ((RMQ[j - 1][i]) < (RMQ[j][i + (1 << j)]) ? RMQ[j - 1][i]
                                                      : RMQ[j][i + (1 << j)]);
      }
    }
  }
}
int RMQ_LCP(int x, int y) {
  int a, b;
  a = Rank[step][x];
  b = Rank[step][y] - 1;
  if (a > b) swap(a, b);
  int tmp = log2(b - a + 1);
  int ret = ((RMQ[tmp][a]) < (RMQ[tmp][b - (1 << tmp) + 1])
                 ? RMQ[tmp][a]
                 : RMQ[tmp][b - (1 << tmp) + 1]);
  return ret;
}
char Query[150000];
bool Present(int left, int right) {
  if (left > right) return false;
  int mid = (right + left) / 2;
  int pos = Suffix[mid];
  int k = strlen(Query);
  k = ((k) < (N - pos + 1) ? k : N - pos + 1);
  for (int i = 0; i < k; i++) {
    if (Query[i] > str[pos + i])
      return Present(mid + 1, right);
    else if (Query[i] < str[pos + i])
      return Present(left, mid - 1);
  }
  if (N - pos + 1 < strlen(Query)) return Present(mid + 1, right);
  return true;
}
std::map<long long, std::vector<int> > mp;
std::vector<pair<int, int> > lsit;
long long arr[140000];
int main() {
  int n, i;
  long long temp;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &arr[i]);
    str[i] = arr[i];
    mp[arr[i]].push_back(i);
  }
  N = n;
  Build_Suffix_Array();
  Build_Lcp_Array();
  for (i = 0; i < n; i++) {
    for (std::vector<int>::iterator it = mp[arr[i]].begin();
         it != mp[arr[i]].end(); it++) {
      if (*it <= i) continue;
      temp = lcp(i, *it);
      if (temp >= *it - i) {
        lsit.push_back(pair<int, int>(*it - i, i));
        break;
      }
    }
  }
  sort(lsit.begin(), lsit.end());
  int limits = 0;
  for (i = 0; i < lsit.size(); i++) {
    if (lsit[i].second >= limits) {
      limits = lsit[i].second + lsit[i].first;
    }
  }
  printf("%d\n", n - limits);
  for (i = limits; i < n; i++) printf("%I64d ", arr[i]);
  printf("\n");
}