#include <bits/stdc++.h>
using namespace std;
int n, m, k, A[200005];
bool check(int mid) {
  long long cnt = 0, cap = 0;
  for (int i = mid; i < n; ++i) {
    if (A[i] > k) return false;
    if (cap + A[i] <= k) {
      cap = cap + A[i];
    } else {
      cnt++;
      cap = A[i];
    }
  }
  cnt++;
  if (cnt > m)
    return false;
  else
    return true;
}
int binary_search() {
  int lo = 0, hi = n;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  return n - hi;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  cout << binary_search();
}
