#include <bits/stdc++.h>
using namespace std;
int II;
long long I_O;
char CC, SS[20];
const int N = 1e5 + 4;
inline long long read() {
  II = 1, I_O = 0;
  while (!isdigit(CC = getchar()))
    if (CC == '-') II = -1;
  while (isdigit(CC)) I_O = I_O * 10 + CC - '0', CC = getchar();
  return I_O * II;
}
inline void wonl() { putchar('\n'); }
inline void wws() {}
inline void dbg() { cout << endl; }
inline void ww(long long k) {
  if (k < 0) putchar('-'), k *= -1;
  II = 0;
  while (k) SS[++II] = k % 10, k /= 10;
  if (!II) SS[++II] = 0;
  while (II) putchar(SS[II--] + '0');
}
template <typename T, typename... V>
inline void wonl(T t, V... v) {
  ww(t);
  if (sizeof...(v)) putchar(' ');
  wonl(v...);
}
template <typename T, typename... V>
inline void wws(T t, V... v) {
  ww(t);
  putchar(' ');
  wws(v...);
}
template <typename T, typename... V>
inline void dbg(T t, V... v) {
  cout << ' ' << t;
  dbg(v...);
}
void solve() {
  int n = read(), m = read(), k = read(), ar[n];
  for (int Ele = 0; Ele < n; Ele++) ar[Ele] = read();
  int l = 0, r = n - 1;
  while (l < r) {
    int mid = (l + r) / 2;
    int cur = 0, box = 0;
    for (int i = mid; i < n; i++)
      if (cur >= ar[i])
        cur -= ar[i];
      else
        box++, cur = k - ar[i];
    if (box <= m)
      r = mid;
    else
      l = mid + 1;
  }
  wonl(n - r);
}
int main() {
  solve();
  return 0;
}
