#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k;
vector<int> a;
int f(int off) {
  int q = 0;
  int left = m - 1;
  int at_w = k;
  for (int i = off; i < n; i++) {
    if (at_w - a[i] >= 0) {
      at_w -= a[i];
      q++;
    } else {
      if (left == 0) break;
      at_w = k - a[i];
      q++;
      left--;
    }
  }
  return q == (n - off);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  a.resize(n);
  {
    for (auto &_re : a) cin >> _re;
  };
  int l = 0, r = n, mid;
  int ans = 0;
  while (l <= r) {
    mid = l + r >> 1;
    if (f(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << n - ans << "\n";
}
