#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1e6 + 3;
long long n, m, k, temp, arr[1000000] = {}, boxes = 0, box = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = n - 1; i >= 0; i--) {
    if (temp + arr[i] <= k) {
      boxes++;
      temp += arr[i];
    } else if (box < m) {
      box++;
      temp = arr[i];
      boxes++;
    } else
      break;
  }
  cout << boxes;
  return 0;
}
