#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const long long LINF = 1e18 + 5;
const double eps = 1e-9;
fstream fin, fout;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> q(n);
  for (int &i : q) cin >> i;
  reverse(q.begin(), q.end());
  int cur = k;
  int ans = 0;
  m--;
  for (int i = 0; i < n; i++) {
    if (cur >= q[i]) {
      ans++;
      cur -= q[i];
    } else {
      if (m == 0)
        break;
      else {
        cur = k - q[i];
        if (cur < 0) break;
        m--;
        ans++;
      }
    }
  }
  cout << ans;
}
