#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 55;
int a[MAXN];
int main() {
  int n, m, k;
  while (cin >> n >> m >> k) {
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    int val = k;
    m--;
    for (int i = n - 1; i >= 0; i--) {
      if (val >= a[i]) {
        val -= a[i];
        ans++;
      } else if (m && k >= a[i]) {
        val = k - a[i];
        ans++;
        m--;
      } else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}
