题目链接:https://codeforces.com/contest/19/problem/C
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
static const int MAXN=1e5+10;
static const int P=13331;
int n;
map<int,int> _hash;
int a[MAXN],b[MAXN],idx;
vector<int> seq[MAXN];
ull h[MAXN],p[MAXN];
vector<PII> same;
bool check(int l1,int l2)
{
int r1=l2-1,r2=l2*2-l1-1;
if(r2>n) return false;
return h[r1]-h[l1-1]*p[r1-l1+1]==h[r2]-h[l2-1]*p[r2-l2+1];
}
int main()
{
scanf("%d",&n);
p[0]=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&b[i]);
if(!_hash.count(b[i])) _hash[b[i]]=++idx;
a[i]=_hash[b[i]];
seq[a[i]].push_back(i);
p[i]=p[i-1]*P;
h[i]=h[i-1]*P+a[i];
}
for(int i=1;i<=idx;i++)
for(int j=0;j<seq[i].size();j++)
for(int k=j+1;k<seq[i].size();k++)
if(check(seq[i][j],seq[i][k])) same.push_back({seq[i][k]-seq[i][j],seq[i][j]});
sort(same.begin(),same.end());
int pos=1;
for(int i=0;i<same.size();i++)
if(same[i].second>=pos) pos=same[i].second+same[i].first;
printf("%d\n",n-pos+1);
for(int i=pos;i<=n;i++)
printf("%d ",b[i]);
printf("\n");
return 0;
}