#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 10;
const int maxn = 3e5 + 30;
const int maxq = 1e5 + 10;
const int alf = 26;
const long long dlm = 1e9 + 7;
const long long del = 179425601;
const int eps = 1e-7;
string O[] = {"YES", "NO", "Yes", "No"};
vector<int> li;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    int v;
    cin >> v;
    li.push_back(v);
  }
  reverse(li.begin(), li.end());
  int ans = 0, t = 1, re = 0;
  for (int i = 0; i < n; i++) {
    if (re + li[i] <= k) {
      re += li[i];
      ans++;
    } else {
      if (t == m) break;
      if (li[i] > k) break;
      t++;
      ans++;
      re = li[i];
    }
  }
  cout << ans;
  return 0;
}
