#include <bits/stdc++.h>
using namespace std;
const int MX = 1000000;
vector<int> v;
long long ar[300000], sum[300000], b[300000];
int main() {
  long long i, a, b, n, m, k, l = 0;
  cin >> n >> m >> b;
  k = b;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (i = n; i > 0; i--) {
    if ((k - ar[i]) >= 0) {
      k -= ar[i];
    } else {
      l++;
      k = b;
      if (l == m) {
        cout << n - i << endl;
        return 0;
      }
      i++;
    }
  }
  cout << n << endl;
  return 0;
}
