#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K, X;
cin >> N >> K >> X;
vector<int> A(N);
for (int i = 0; i < N; i++){
cin >> A[i];
}
int ans = 0;
// Try every candidate d > X. We use d in [X+1, X+100].
for (int d = X + 1; d <= X + 100; d++){
long long sumCost = 0;
int left = 0;
// Use a sliding window on the array.
for (int right = 0; right < N; right++){
// cost to make A[right] divisible by d
int r = A[right] % d;
int cost = (r == 0) ? 0 : (d - r);
sumCost += cost;
// Shrink the window until the total cost is within K.
while(sumCost > K && left <= right) {
int r_left = A[left] % d;
int cost_left = (r_left == 0) ? 0 : (d - r_left);
sumCost -= cost_left;
left++;
}
ans = max(ans, right - left + 1);
}
}
// If no valid subarray found, print -1.
cout << (ans == 0 ? -1 : ans) << "\n";
return 0;
}