#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, k;
int a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  while (cin >> n >> m >> k) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int tk = k, cnt = 0;
    for (int i = n; i >= 1; --i) {
      if (tk >= a[i]) {
        tk -= a[i];
        cnt++;
      } else if (tk < a[i] && m > 1) {
        tk = k;
        tk -= a[i];
        cnt++;
        m--;
      } else
        break;
    }
    cout << cnt << endl;
  }
  return 0;
}
