#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> v;
int ar[300000];
bool check(int x) {
  int mm = m;
  int kk = k;
  for (int i = 0; i < x; i++) {
    kk -= v[i];
    if (kk < 0) {
      kk = k;
      if (v[i] <= kk) {
        kk -= v[i];
        mm--;
      }
    } else if (kk == 0) {
      kk = k;
      mm--;
    }
    if (mm <= 0) return false;
  }
  return true;
}
bool check1(long long mr) {
  int mm = m, kk = k;
  for (int i = n - mr; i < n; i++) {
    if (ar[i] > k) return false;
    if (ar[i] <= kk) {
      kk -= ar[i];
    } else {
      mm--;
      if (mm)
        kk = k;
      else
        return false;
      if (ar[i] <= kk) {
        kk -= ar[i];
      }
    }
  }
  return true;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ar[i] = x;
    v.push_back(x);
  }
  long long l = 0, r = n, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check1(mid)) {
      ans = max(mid, ans);
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
