#include <bits/stdc++.h>
using namespace std;
vector<long long int> vp;
bool check(long long int i, long long int n, long long int m, long long int k) {
  long long int kk = k;
  for (i; i < n; i++) {
    if (vp[i] > k) {
      return false;
    } else if (vp[i] <= kk) {
      kk = kk - vp[i];
    } else {
      m--;
      if (m == 0) return false;
      kk = k - vp[i];
    }
    if (kk == 0) {
      m--;
      kk = k;
      if (m == 0 && i != n - 1) return false;
    }
  }
  return true;
}
int main() {
  long long int i, j, k, l, n, m;
  long long int x;
  cin >> n >> m >> k;
  long long int lb = 0;
  long long int ub = n - 1;
  for (i = 0; i < n; i++) {
    cin >> x;
    vp.push_back(x);
  }
  while (lb < ub) {
    long long int mid = (lb + ub) / 2;
    if (check(mid, n, m, k))
      ub = mid;
    else
      lb = mid + 1;
  }
  cout << n - ub << endl;
  return 0;
}
