#include <bits/stdc++.h>
using namespace std;
const int maxn = 300500;
int n, m, k;
int a[maxn];
bool check(int s) {
  int cur = 0, rem = m - 1;
  for (int i = n - s; i < n; i++) {
    if (cur + a[i] > k) {
      if (rem == 0) return 0;
      rem--;
      cur = 0;
    }
    cur += a[i];
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d", &k);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", &a[i]);
  int l = 0, r = n, ret = 0;
  check(5);
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ret = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%d\n", ret);
}
