#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'
using namespace std;
const int N = 2e5 + 5;
int tc, n, k, x, a[N], pref[N];
void pre() {
memset(pref, 0, sizeof pref);
for (int i = 1; i <= n; i++) {
if (a[i] % x != 0) {
pref[i] = x - (a[i] % x);
}
pref[i] += pref[i - 1];
}
}
bool isPossible(int st, int en, int move) {
int sum = pref[en] - pref[st - 1];
return sum <= move;
}
int maxPossible(int idx, int move) {
int st = idx, en = n, Ans = -1;
while (st <= en) {
int mid = (st + en) / 2;
if (isPossible(idx, mid, move)) {
Ans = mid - idx + 1;
st = mid + 1;
} else {
en = mid - 1;
}
}
return Ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); // cout.tie(0);
cin >> n >> k >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int Ans = 0;
for (int j = 0; j < 5; j++) {
++x;
pre();
for (int i = 1; i <= n; i++) {
Ans = max(Ans, maxPossible(i, k));
}
}
cout << Ans << endl;
return 0;
}