#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> sizes(n);
  for (int i = 0; i < n; i++) cin >> sizes[i];
  int i = n - 1;
  int objects = 0;
  int remSpace = k;
  while (m != 0 && i >= 0) {
    if (remSpace >= sizes[i]) {
      remSpace -= sizes[i];
      objects++;
      i--;
    } else {
      m--;
      remSpace = k;
    }
  }
  cout << objects << "\n";
  return 0;
}
