#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[200010] = {0};
  int n, m, k;
  int ans = 0;
  int sum = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int t = 1;
  sum = k;
  for (int i = n; i >= 1 && t <= m; i--) {
    if (a[i] > k) continue;
    if (sum >= a[i]) {
      sum -= a[i];
      ans++;
    } else {
      t++;
      i++;
      sum = k;
    }
  }
  cout << ans << endl;
  return 0;
}
