对同类元素双指针扫描
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define int long long
using namespace std;
inline int rd(){
int ret=0,f=1;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
while(isdigit(c))ret=ret*10+c-'0',c=getchar();
return ret*f;
}
int n,m,k;
vector<int> vec[200005];
int ans=0;
signed main(){
n=rd();m=rd();k=rd();
for(int i=1;i<=n;i++)vec[rd()].push_back(i);
for(int i=1;i<=m;i++){
int cur=0,r=0,siz=vec[i].size();
for(int l=0;l<siz;l++){
while(r<siz-1&&cur+vec[i][r+1]-vec[i][r]-1<=k){
r++;cur+=(vec[i][r]-vec[i][r-1]-1);
}
ans=max(ans,r-l+1);
cur-=vec[i][l+1]-vec[i][l]-1;
}
}
cout<<ans;
return 0;
}