#include <bits/stdc++.h>
using namespace std;
bool chk(vector<long long> &v, long long st, long long k, long long m) {
  long long s = 0;
  long long ans = 1, i, j, l, n = v.size();
  for (i = st; i < n; i++) {
    s += v[i];
    if (s > k) {
      s = v[i];
      ans++;
      if (ans > m) return false;
    }
  }
  return ans <= m;
}
void solve() {
  long long i, j, k, l, n, m;
  cin >> n >> m >> k;
  vector<long long> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  long long lo = 0;
  long long hi = n - 1;
  long long ans = -1;
  while (lo <= hi) {
    long long mid = (lo + hi) >> 1;
    if (chk(v, mid, k, m)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  if (ans == -1)
    cout << 0;
  else
    cout << n - ans;
}
int main() {
  solve();
  return 0;
}
