#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, r = 0, b = 0, t = 0;
  cin >> n >> m >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a[n - 1] > k) {
      cout << 0;
      return 0;
    }
    if (k - b >= a[i]) {
      b = b + a[i];
      r++;
    } else {
      t++;
      if (t == m) {
        break;
      }
      b = a[i];
      r++;
    }
  }
  cout << r;
}
