#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int arr[200001];
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int counter = 0, boxes = 0, i = n - 1, remaining = k;
  while (i >= 0 && (arr[i] <= remaining || arr[i] <= k) && boxes < m) {
    if (arr[i] <= remaining) {
      remaining -= arr[i];
      counter++;
    } else if (boxes < m - 1) {
      boxes++;
      remaining = k - arr[i];
      counter++;
    } else {
      boxes++;
    }
    i--;
  }
  cout << counter << endl;
}
