#include <bits/stdc++.h>
using namespace std;
vector<int> sh;
int n, m, k;
int chk(int x) {
  x = n - x;
  int cnt = 1, cur = 0;
  for (int i = x; i < sh.size(); i++) {
    if (sh[i] > k) return 0;
    if (cur + sh[i] <= k) {
      cur += sh[i];
    } else {
      cur = sh[i];
      cnt++;
    }
  }
  return cnt <= m;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sh.push_back(x);
  }
  int ans = 0;
  for (int j = 20; j >= 0; j--) {
    int k = ans + (1 << j);
    if (k <= n && chk(k)) {
      ans = k;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
