#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = (X << 3) + (X << 1) + c - '0', c = getchar();
  return X * w;
}
int n, m, k;
int a[200010];
inline int check(int q) {
  int filled = 0, cnt = 0;
  for (register int i = q + 1; i <= n; i++) {
    if (cnt == m - 1 && filled + a[i] > k) return 0;
    if (filled + a[i] > k)
      cnt++, filled = a[i];
    else
      filled += a[i];
  }
  return 1;
}
int main() {
  n = read(), m = read(), k = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  int L = 0, R = n;
  while (L < R) {
    int mid = (L + R) >> 1;
    if (check(mid))
      R = mid;
    else
      L = mid + 1;
  }
  printf("%d\n", n - L);
  return 0;
}
