#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[200010];
int check(int task) {
  int now = 0, qwq = 0;
  while (1) {
    now++;
    qwq = 0;
    if (now > m) {
      return 0;
    }
    while (qwq <= k) {
      if (task > n) {
        return 1;
      }
      qwq += a[task];
      task++;
      if (qwq > k) {
        task--;
        break;
      }
    }
  }
  return 0;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int l = 1, r = n;
  check(3);
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  int qwqwq = check(l);
  cout << (qwqwq ? n - l + 1 : n - l);
}
