#include <bits/stdc++.h>
using namespace std;
int a[2 * 100000 + 10];
int n, m, k;
bool find(int pos) {
  int m1 = 0;
  while (m1 < m && pos <= n) {
    int k1 = k;
    while (pos <= n && a[pos] <= k1) {
      k1 -= a[pos++];
    }
    m1++;
  }
  return pos == n + 1 ? 1 : 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (find(mid)) {
      ans = max(ans, n - mid + 1);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans;
  return 0;
}
