#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, m, k;
int a[MAXN];
bool check(int v) {
  int bn = m - 1;
  int l = n + 1 - v;
  int curlft = k;
  int ii = l;
  while (ii <= n && bn >= 0) {
    if (curlft >= a[ii])
      curlft -= a[ii++];
    else {
      bn--;
      curlft = k;
    }
  }
  return ii > n;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m >> k;
  for (int ii = 1; ii <= n; ii++) {
    cin >> a[ii];
  }
  int l = 0, r = n, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans;
}
