#include <bits/stdc++.h>
const int INF = 1e9 + 1;
const int N = 2e5 + 1;
const int MOD = 998244353;
int n, m, k;
bool f(int c, std::vector<int> &a) {
  int t = 1, v = k;
  for (int i = c - 1; i >= 0; i--) {
    if (a[i] <= v) {
      v -= a[i];
    } else {
      t++;
      v = k - a[i];
    }
  }
  return t <= m;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  std::reverse(a.begin(), a.end());
  int l = 0, r = n + 1;
  while (r - l > 1) {
    int mid = (r + l) >> 1;
    if (f(mid, a)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  printf("%d", l);
}
