#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int n,k,x;
int cnt[10][N];
int check(int l, int r) { /// O(10)
/// 1. Dem trong doan l,r co bao nhieu so khac nhau
int khacnhau = 0;
vector<pair<int, int>> candidates;
int tot = 0;
for (int i = 1; i <= 9; i++) {
if (cnt[i][r] - cnt[i][l-1] > 0) {
khacnhau++;
int sl = cnt[i][r] - cnt[i][l-1];
tot += sl;
candidates.push_back({sl,i});
}
}
if (khacnhau <= k) return -1;
sort(candidates.begin(), candidates.end(), greater<pair<int,int>>());
int cur = 0; /// Tong cnt cua k so co cnt lon nhat
for (int i = 0; i < k; i++) {
cur += candidates[i].first;
}
int remain = tot - cur;
return remain;
}
int main() {
/// freopen("DENLONG.INP","r",stdin);
// freopen("DENLONG.OUT","w",stdout);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k >> x;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int c = 1; c <= 9; c++) {
cnt[c][i] = cnt[c][i-1] + (a[i] == c);
}
}
int ans = -1;
int l=1,r=1;
while (l <= r) {
int cur_amt = check(l,r);
if (cur_amt == -1 || cur_amt <= x) {
ans = max(ans,r-l+1);
if (r + 1 <= n) r++;
else l++;
}
else l++;
}
cout << ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxZTUgKyA1OwppbnQgYVtOXTsKaW50IG4sayx4OwppbnQgY250WzEwXVtOXTsKCmludCBjaGVjayhpbnQgbCwgaW50IHIpIHsgLy8vIE8oMTApCiAgICAvLy8gMS4gRGVtIHRyb25nIGRvYW4gbCxyIGNvIGJhbyBuaGlldSBzbyBraGFjIG5oYXUKICAgIGludCBraGFjbmhhdSA9IDA7CiAgICB2ZWN0b3I8cGFpcjxpbnQsIGludD4+IGNhbmRpZGF0ZXM7CiAgICBpbnQgdG90ID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IDk7IGkrKykgewogICAgICAgIGlmIChjbnRbaV1bcl0gLSBjbnRbaV1bbC0xXSA+IDApICAgICAgICB7CiAgICAgICAgICAgIGtoYWNuaGF1Kys7CiAgICAgICAgICAgIGludCBzbCAgPSBjbnRbaV1bcl0gLSBjbnRbaV1bbC0xXTsKICAgICAgICAgICAgdG90ICs9IHNsOwogICAgICAgICAgICBjYW5kaWRhdGVzLnB1c2hfYmFjayh7c2wsaX0pOwogICAgICAgIH0KICAgIH0KICAgIGlmIChraGFjbmhhdSA8PSBrKSAgICAgIHJldHVybiAtMTsKICAgIHNvcnQoY2FuZGlkYXRlcy5iZWdpbigpLCBjYW5kaWRhdGVzLmVuZCgpLCBncmVhdGVyPHBhaXI8aW50LGludD4+KCkpOwogICAgaW50IGN1ciA9IDA7IC8vLyBUb25nIGNudCBjdWEgayBzbyBjbyBjbnQgbG9uIG5oYXQKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgazsgaSsrKSB7CiAgICAgICAgY3VyICs9IGNhbmRpZGF0ZXNbaV0uZmlyc3Q7CiAgICB9CiAgICBpbnQgcmVtYWluID0gdG90IC0gY3VyOwogICAgcmV0dXJuIHJlbWFpbjsKfQoKaW50IG1haW4oKSB7CiAgICAvLy8gZnJlb3BlbigiREVOTE9ORy5JTlAiLCJyIixzdGRpbik7CiAgICAvLyBmcmVvcGVuKCJERU5MT05HLk9VVCIsInciLHN0ZG91dCk7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKSwgICAgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CgogICAgY2luID4+IG4gPj4gayA+PiB4OwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSAgICBjaW4gPj4gYVtpXTsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBmb3IgKGludCBjID0gMTsgYyA8PSA5OyBjKyspIHsKICAgICAgICAgICAgY250W2NdW2ldID0gY250W2NdW2ktMV0gKyAoYVtpXSA9PSBjKTsKICAgICAgICB9CiAgICB9CgogICAgaW50IGFucyA9IC0xOwogICAgaW50IGw9MSxyPTE7CiAgICB3aGlsZSAobCA8PSByKSB7CiAgICAgICAgaW50IGN1cl9hbXQgPSBjaGVjayhsLHIpOwogICAgICAgIGlmIChjdXJfYW10ID09IC0xIHx8IGN1cl9hbXQgPD0geCkgICAgICB7CiAgICAgICAgICAgIGFucyA9IG1heChhbnMsci1sKzEpOwogICAgICAgICAgICBpZiAociArIDEgPD0gbikgICAgIHIrKzsKICAgICAgICAgICAgZWxzZSBsKys7CiAgICAgICAgfQogICAgICAgIGVsc2UgbCsrOwogICAgfQogICAgY291dCA8PCBhbnM7CiAgICByZXR1cm4gMDsKfQo=