#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, k, t1, t2, ans = 0;
  cin >> n >> m >> k;
  long long arr[n], start = 0, fin = n - 1, mid;
  for (int i = 0; i < n; cin >> arr[i++])
    ;
  while (start <= fin) {
    mid = (fin - start) / 2 + start;
    t1 = m - 1, t2 = 0;
    for (int i = mid; i < n; i++)
      if (arr[i] > k)
        t1 = -1;
      else if (t2 + arr[i] <= k)
        t2 += arr[i];
      else
        t1--, t2 = arr[i];
    if (t1 >= 0)
      fin = mid - 1, ans = max(ans, n - mid);
    else
      start = mid + 1;
  }
  cout << ans;
  return 0;
}
