#include <bits/stdc++.h>
using namespace std;
vector<int> vt;
int n, m, k;
bool ok(int temp) {
  int cur = m;
  int t = k;
  int c = 0;
  int x = 0;
  for (int i = vt.size() - 1; i >= 0; i--) {
    x += vt[i];
    if (x > k) {
      x = 0;
      cur--;
    }
    if (x == 0) {
      x += vt[i];
    }
    if (cur == 0) {
      return c >= temp;
    }
    c++;
  }
  return c >= temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vt.push_back(x);
  }
  int lo = 0;
  int hi = n;
  int ans = 0;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    if (ok(mid)) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
