#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
inline long long rd() {
  long long x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N], nt[N], hd[N], tot = 1;
inline void add(int x, int y) {
  ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;
}
int n, m, k, a[N], len[N], ans;
int st[N], tt = -1;
inline void dfs(int x) {
  ++tt, st[tt] = st[tt - 1] + len[x];
  ans = max(ans, st[tt] - st[max(0, tt - m)]);
  if (tt < m)
    for (int i = hd[x]; i; i = nt[i]) dfs(to[i]);
  --tt;
}
int main() {
  n = rd(), m = rd(), k = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  for (int i = 1, su = a[1], j = 1; i <= n; i++) {
    while (j < n && su + a[j + 1] <= k) su += a[++j];
    len[i] = j - i + 1, add(j + 1, i), su -= a[i];
  }
  dfs(n + 1);
  printf("%d\n", ans);
  return 0;
}
