#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int n, m, k, a[N];
inline bool check(int num) {
  int sum = 0, tot = 1;
  for (int i = n - num + 1; i <= n; i++) {
    if (sum + a[i] > k) {
      sum = 0;
      tot++;
    }
    if (tot > m) return false;
    sum += a[i];
  }
  return true;
}
inline int read() {
  int a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
signed main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  int l = 1, r = n, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      l = mid + 1, ans = mid;
    } else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
