#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long a[200005];
bool check(long long s, long long n, long long m, long long k) {
  long long cnt = 0;
  long long curr = 0;
  for (long long i = n - s; i < n; i++) {
    if (curr + a[i] <= k) {
      curr += a[i];
    } else {
      cnt++;
      curr = a[i];
    }
  }
  if (curr > 0) cnt++;
  if (cnt > m)
    return false;
  else
    return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long lo = 0, hi = n + 1;
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    if (check(mid, n, m, k))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo;
  return 0;
}
