#include <bits/stdc++.h>
using namespace std;
void Fastio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool runTestCase() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long s = 0, e = n - 1, mid, mx = 0;
  while (s <= e) {
    mid = (s + e) / 2;
    bool st = 1;
    long long ac = k, c = 1;
    for (int i = mid; i < n; i++) {
      if (ac >= arr[i])
        ac -= arr[i];
      else if (c < m)
        ac = k, c++, i--;
      else {
        st = 0;
        break;
      }
    }
    if (st)
      mx = max(mx, n - mid), e = mid - 1;
    else
      s = mid + 1;
  }
  cout << mx << '\n';
  return 0;
}
int main() {
  Fastio();
  int ttt = 1;
  while (ttt--) {
    runTestCase();
  }
  return 0;
}
