#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323;
const double EPS = 1e-12;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
long long int a[N];
queue<long long int> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int lo = 0, hi = n + 1, mid;
  while (hi - lo > 1LL) {
    mid = hi + lo >> 1LL;
    long long int ct = 0, cursize = k, flag = 0;
    for (int i = mid; i <= n; i++) {
      if (cursize >= a[i]) {
        cursize -= a[i];
      } else {
        ct++;
        if (ct == m) {
          flag = 1;
          break;
        }
        cursize = k;
        cursize -= a[i];
      }
    }
    if (flag == 0) {
      hi = mid;
    } else
      lo = mid;
  }
  cout << n - hi + 1;
  return 0;
}
