#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, a[200005], ans = 0, m;
string s;
bool check(int first) {
  long long ind = n - first, cnt = 1, cur = k;
  for (; ind < n; ind++) {
    if (a[ind] > k) return false;
    if (a[ind] <= cur) {
      cur -= a[ind];
    } else {
      cnt++;
      cur = k - a[ind];
    }
  }
  return cnt <= m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long low = 0, high = n, mid = (low + high) / 2;
  while (high - low > 1) {
    if (check(mid))
      low = mid;
    else
      high = mid;
    mid = (low + high) / 2;
  }
  if (check(high))
    cout << high << '\n';
  else
    cout << low << '\n';
  return 0;
}
