#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n,m,k;
      cin>>n>>m>>k;
      vector<int>v;
      for(int i=0;i<n;i++)
      {int a;
      cin>>a;
      v.push_back(a);
      }
      vector<int> v1;
      for(int i=0;i<n;)
      { int sum=k;
      int c=0;
        while(sum>=v[i])
        {
          sum-=v[i];
          c++;
          i++;
        }
        if(v1.size()==m)
        {
              v1.erase(v1.begin()+0);
              v1.push_back(c);
              continue;
        }
        v1.push_back(c);
      }
      int sum=0;
      for(int i=0;i<v1.size();i++)
      {
            sum+=v1[i];
      }
      cout<<sum<<endl;
      return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
      long n,m,k;
      cin>>n>>m>>k;
      vector<int>v;
      for(int i=0;i<n;i++)
      {int a;
      cin>>a;
      v.push_back(a);
      }
      vector<int> v1;
      for(int i=0;i<n;)
      { int sum=k;
      int c=0;
        while(sum>=v[i])
        {
          sum-=v[i];
          c++;
          i++;
        }
        if(v1.size()==m)
        {
              v1.erase(v1.begin()+0);
              v1.push_back(c);
              continue;
        }
        v1.push_back(c);
      }
      long sum=0;
      for(int i=0;i<v1.size();i++)
      {
            sum+=v1[i];
      }
      cout<<sum<<endl;
      return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
      long long n,m,k;
      cin>>n>>m>>k;
      vector<int>v;
      for(int i=0;i<n;i++)
      {int a;
      cin>>a;
      v.push_back(a);
      }
      vector<int> v1;
      for(int i=n-1;i>=0;)
      { int sum=k;
      int c=0;
        while(sum>=v[i])
        {
          sum-=v[i];
          c++;
          i--;
        }
        if(v1.size()==m)
        {
              break;
        }
        v1.push_back(c);
      }
      int sum=0;
      for(int i=0;i<v1.size();i++)
      {
            sum+=v1[i];
      }
      cout<<sum<<endl;
      return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool isGood(ll* a, ll& n, ll& m, ll& k, ll val) {
	ll bc = m, cs = k;
	for (ll i = n - val; i < n; ++i) {
		if (a[i] > k) return false;
		if (cs >= a[i]) {
			cs -= a[i];
		}
		else {
			if (bc == 1) return false;
			--bc;
			cs = k - a[i];
		}
	}
	return true;
}

ll bs(ll* a, ll& n, ll& m, ll& k) {
	ll base = 0;
	for (ll jump = n >> 1; jump; jump >>= 1) while (base + jump <= n && isGood(a, n, m, k, base + jump)) base += jump;
	return base;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("zin.txt", "r", stdin);
#endif

	ll n, m, k;
	scanf("%lld %lld %lld", &n, &m, &k);
	ll a[n];
	for (ll i = 0; i < n; ++i) scanf("%lld", &a[i]);

	printf("%lld\n", bs(a, n, m, k));

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool isGood(ll* a, ll& n, ll& m, ll& k, ll val) {
	ll bc = m, cs = k;
	for (ll i = n - val; i < n; ++i) {
		if (a[i] > k) return false;
		if (cs >= a[i]) {
			cs -= a[i];
		}
		else {
			if (bc == 1) return false;
			--bc;
			cs = k - a[i];
		}
	}
	return true;
}

ll bs(ll* a, ll& n, ll& m, ll& k) {
	ll base = 0;
	for (ll jump = n >> 1; jump; jump >>= 1) while (base + jump <= n && isGood(a, n, m, k, base + jump)) base += jump;
	return base;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("zin.txt", "r", stdin);
#endif

	ll n, m, k;
	scanf("%dll %dll %dll", &n, &m, &k);
	ll a[n];
	for (ll i = 0; i < n; ++i) scanf("%d", &a[i]);

	printf("%dll\n", bs(a, n, m, k));

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool isGood(ll* a, ll& n, ll& m, ll& k, ll val) {
	ll bc = m, cs = k;
	for (ll i = n - val; i < n; ++i) {
		if (a[i] > k) return false;
		if (cs >= a[i]) {
			cs -= a[i];
		}
		else {
			if (bc == 1) return false;
			--bc;
			cs = k - a[i];
		}
	}
	return true;
}

ll bs(ll* a, ll& n, ll& m, ll& k) {
	ll base = 0;
	for (ll jump = n >> 1; jump; jump >>= 1) while (base + jump <= n && isGood(a, n, m, k, base + jump)) base += jump;
	return base;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("zin.txt", "r", stdin);
#endif

	ll n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	ll a[n];
	for (ll i = 0; i < n; ++i) scanf("%d", &a[i]);

	printf("%d\n", bs(a, n, m, k));

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool isGood(int* a, int& n, int& m, int& k, int val) {
	int bc = m, cs = k;
	for (int i = n - val; i < n; ++i) {
		if (a[i] > k) return false;
		if (cs >= a[i]) {
			cs -= a[i];
		}
		else {
			if (bc == 1) return false;
			--bc;
			cs = k - a[i];
		}
	}
	return true;
}

int bs(int* a, int& n, int& m, int& k) {
	int base = 0;
	for (int jump = n; jump; jump >>= 1) while (base + jump <= n && isGood(a, n, m, k, base + jump)) base += jump;
	return base;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("zin.txt", "r", stdin);
#endif

	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	int a[n];
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

	printf("%d\n", bs(a, n, m, k));

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool isGood(int* a, int& n, int& m, int& k, int val) {
	//cout << val << "\n";
	int bc = m, cs = k;
	for (int i = n - val; i < n; ++i) {
		if (a[i] > k) return false;
		if (cs >= a[i]) {
			cs -= a[i];
		}
		else {
			if (bc == 1) return false;
			--bc;
			cs = k - a[i];
		}
	}
	return true;
}

int bs(int* a, int& n, int& m, int& k) {
	int base = 0;
	for (int jump = n >> 1; jump; jump >>= 1) while (base + jump <= n && isGood(a, n, m, k, base + jump)) base += jump;
	return base;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("zin.txt", "r", stdin);
#endif

	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	int a[n];
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

	printf("%d\n", bs(a, n, m, k));

    return 0;
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

bool check(int mid )
{
	int now = 1;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;

	vi fr(m+1 , 0) , sum(m+1 ,0);
	// bug(mid);

	while(i <= n)
	{
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now] += a[i];
			fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			cn = max( cn , can);
			if( cn >= mid ) return 1;

			if( now + 1 > m )
			{
				// bug(now);
				now = 1;
				while( kk < a[i] and now <= m )
				{
					can -= fr[now];
					kk += sum[now];
					fr[now] = 0;
					sum[now] = 0;
					cn = max( cn , can);
					now++;
				}

				if( now > m ) break;
			}
			else now++, kk = k;
		}
	}

	// bug(mid,cn);

	return (cn >= mid);
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = 0;

	while( l <= r )
	{
		int mid = l+r>>1;

		if( check(mid) ) ans = mid , l = mid + 1;
		else r = mid - 1;
	}

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check()
{
	int now = 0;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;
	int mm = m-1;

	deque<int> sum[n+1];
	int used = 0;
	// bug(mid);

	while(i <= n)
	{
		if(a[i] > k ) break;
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now].pb(a[i]);
			// fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			now++;
			if( now > mm)
			{
				// bug(now);
				now = ( used%m );
				kk = 0;
				while( !sum[now].empty() and kk < a[i] )
				{
					kk += sum[now].front();
					sum[now].pop_front();
					can -= 1;
				}
 				used++;
			}
			else kk = k;
		}
	}

	// bug(mid,cn);

	return cn;
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = check();

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check(int mid)
{
	int box = 1;
	int kk = k;

	fo(i,mid,n+1)
	{
		if( a[i] <= kk )
		{
			kk -= a[i];
		}
		else
		{
			box++;
			kk = k - a[i];
		}
	}

	return ( box <= m);
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int ans = 0;

	int l = 1;
	int r = n;

	while( l <= r)
	{
		int mid = l+r>>1;

		if( check(mid) ) ans = mid , r = mid - 1;
		else l = mid + 1;
	}

	cout << (n - ans + 1) << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check()
{
	int now = 0;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;
	int mm = m-1;

	vi fr(m+1 , 0) , sum(m+1 ,0);
	// bug(mid);

	int used = 0;

	while(i <= n )
	{
		if( a[i] > k ) break;
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now] += a[i];
			fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			now++;
			if( now > mm )
			{
				now = (used)%m;
				// bug(now);
				can -= fr[now];
				kk = k;
				fr[now] = 0;
				sum[now] = 0;
				++used;
			}
			else  kk = k;
		}
	}

	// bug(mid,cn);

	return cn;
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int ans = check();

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check()
{
	int now = 1;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;

	vi fr(m+1 , 0) , sum(m+1 ,0);
	// bug(mid);

	while(i <= n)
	{
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now] += a[i];
			fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			cn = max( cn , can);

			if( now + 1 > m )
			{
				// bug(now);
				now = 1;
				while( kk < a[i] and now <= m )
				{
					can -= fr[now];
					kk += sum[now];
					fr[now] = 0;
					sum[now] = 0;
					cn = max( cn , can);
					if( kk >= a[i] ) break;
					now++;
				}

				if( now > m ) break;
			}
			else now++, kk = k;
		}
	}

	// bug(mid,cn);

	return cn;
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = check();

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

bool check(int mid )
{
	int now = 1;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;

	deque<int> sum[n+1];
	// bug(mid);

	while(i <= n)
	{
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now].pb(a[i]);
			// fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			cn = max( cn , can);
			if( cn >= mid ) return 1;

			if( now + 1 > m )
			{
				// bug(now);
				now = 1;
				while( kk < a[i] and now <= m )
				{
					while( !sum[now].empty() and kk < a[i] )
					{
						kk += sum[now].front();
						sum[now].pop_front();
						can -= 1;
					}
					if( kk >= a[i] ) break;
					now++;
				}

				if( now > m ) break;
			}
			else now++, kk = k;
		}
	}

	// bug(mid,cn);

	return (cn >= mid);
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = 0;

	while( l <= r )
	{
		int mid = l+r>>1;

		if( check(mid) ) ans = mid , l = mid + 1;
		else r = mid - 1;
	}

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check()
{
	int now = 0;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;
	int mm = m-1;

	deque<int> sum[m+1];
	int used = 0;
	// bug(mid);

	while(i <= n)
	{
		if(a[i] > k ) break;
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now].pb(a[i]);
			// fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			// bug(can,i,now);
			now++;
			if( now > mm)
			{
				// bug(now);
				now = ( used%m );
				while( !sum[now].empty() and kk < a[i] )
				{
					kk += sum[now].front();
					sum[now].pop_front();
					can -= 1;
				}
 				used++;
			}
			else kk = k;
		}
	}

	// bug(mid,cn);

	return cn;
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = check();

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update >
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

int check()
{
	int now = 0;
	int kk = k;
	int i = 1;
	int cn = 0;
	int can = 0;
	int mm = m-1;

	deque<int> sum[n+1];
	int used = 0;
	// bug(mid);

	while(i <= n)
	{
		if(a[i] > k ) break;
		if( a[i] <= kk )
		{
			kk -= a[i];
			sum[now].pb(a[i]);
			// fr[now] += 1;
			can++;
			i++;
			cn = max( cn , can);
		}
		else
		{
			now++;
			if( now == m)
			{
				now = ( used%m );
				kk = 0;
				// break;
				while( !sum[now].empty() and kk < a[i] )
				{
					kk += sum[now].front();
					sum[now].pop_front();
					can -= 1;
				}

				if( kk < a[i] )
				{
					kk = k;
				}
 				used++;
			}
			else kk = k;
		}
	}

	// bug(mid,cn);

	return cn;
}

void go()
{
	cin >> n >> m >> k;

	fo(i,1,n+1) cin >> a[i];

	int l = 0;
	int r = n;
	int ans = check();

	cout << ans << endl;
}

int32_t main()
{
	INP();
	FAST;
	int t=1;
	// cin>>t;
	test(t) go();
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	//if(sum<m*k)
	//{
	//	cout<<n;
	//	return 0;
	//}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	int f=1;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>k)
		{
			//s=0;
			m--;
			if(m==0)
			{
				if(s>k)
				break;
				if(s==k)
				{
					count++;
					break;
				}
			}
			s=a[i];
		}
		count++;
		i--;

	}

	cout<<count<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	//if(sum<m*k)
	//{
	//	cout<<n;
	//	return 0;
	//}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>k)
		{
			s=0;
			m--;

		}
		count++;
		i--;

	}
	cout<<count-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<m*k)
	{
		cout<<n;
		return 0;
	}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>k)
		{
			s=0;
			m--;

		}
		count++;
		i--;

	}
	cout<<count-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	//if(sum<m*k)
	//{
	//	cout<<n;
	//	return 0;
	//}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	int f=1;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>=k)
		{
			//s=0;
			m--;
			if(m==0)
			{
				if(s>k)
				break;
				if(s==k)
				{
					count++;
					break;
				}
			}
			s=0;
		}
		count++;
		i--;

	}

	cout<<count<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<m*k)
	{
		cout<<n;
		return 0;
	}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>k)
		{
			s=0;
			m--;

		}
		count++;
		i--;

	}
	cout<<count<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	//if(sum<m*k)
	//{
	//	cout<<n;
	//	return 0;
	//}
	ll x=0;
	ll i=n-1;
	ll count=0;
	ll s=0;
	int f=1;
	while(m!=0&&i>=0)
	{
		s+=a[i];
		if(s>k)
		{
			s=0;
			m--;

		}
		if(m==0&&i!=0)
		f=1;
		count++;
		i--;

	}
	if(f==0)
	cout<<count-1<<endl;
	else
	cout<<count<<endl;

}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long n,m,k,i,j=0,l=0,s=0,p=0;
    cin>>n>>m>>k;
    vector<long>a(n);
    for(i=0 ;i<n; i++)
     cin>>a[i];
   for(j=0; j<n; j++)
    {
        s=0;
        l=0;
        for(i=0; i<n-j; i++)
       {
         if(s+a[i+j]<=k)
            s+=a[i+j];
         else
         {
             l++;
             s=a[i+j];
             if(l==m)
              break;
         }
      }
      if(p<i)
       p=i;
      if(p>n-j)
       break;
    }
      cout<<p<<endl;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long n,m,k,i,j=0,s=0;
    cin>>n>>m>>k;
    vector<long>a(n);
    for(i=0 ;i<n; i++)
     cin>>a[i];
    for(i=0; i<n; i++)
      {
         if(s+a[i]<=k)
            s+=a[i];
         else
         {
             j++;
             s=a[i];
             if(j==m)
              break;
         }
      }
      if(i!=n)
      cout<<i<<endl;
      else
       cout<<n<<endl;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long n,m,k,i,j=0,s=0;
    cin>>n>>m>>k;
    vector<long>a(n);
    for(i=0 ;i<n; i++)
     cin>>a[i];
    for(i=0; i<n; i++)
      {
         if(s+a[i]<=k)
            s+=a[i];
         else
         {
             j++;
             s=a[i];
             if(j==m)
              break;
         }
      }
      if(i!=n)
      cout<<i+1<<endl;
      else
       cout<<n<<endl;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int ff(int h,vector<long>a,int m,int k)
{
    int i=h,j=0,s=0,p=0;
    while(i<a.size() && j!=m)
    {
        s=k;
        for(; i<a.size(); i++)
          {
              if(a[i]<=s)
                s-=a[i];
                else
                 break;
          }
          j++;
    }
    return i==a.size() ? a.size()-h+1:0;
}

int main() {
    long n,m,k,i,p=0;
    cin>>n>>m>>k;
    vector<long>a(n);
    for(i=0; i<n; i++)
     cin>>a[i];
     int l=0,r=n-1,h;
     while(l<=r)
     {
         h=(l+r)/2;
         int hh=ff(h,a,m,k);

         if(hh!=0)
          {
              r=h-1;
              p=max(p,n-h);

          }
          else
           l=h+1;
     }
     cout<<p<<endl;
    return 0;
}


//         el psy congroo!
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , m ,k ; cin >> n >> m >> k ;int ob[n] ;
    for(int i = 0 ;i < n ; i++ ){ cin >>ob[i] ; }
    vector <int > v ;
    int csz = 0 , l =0 , nob=1 ,nb =0 ;
    for(int i=n-1 ;i >-1 ;i -- ){
        if( csz + ob[i] <= k ){ l++ ; csz +=ob[i] ;}
        else {
            v.PB(l) ;   csz = ob[i] ;   l = 1 ; nob ++ ;// cout << i<<" ";
        } if( nob > m ) break ; nb++ ;
    } v.PB(l) ;
    // int dif = nob - m , ans =0;
    /*for (int i =dif ;i<v.size();i++){
        ans += v[i] ; //cout <<v[i]<<' ';
    }*/
    cout << nb ;
    return 0 ;
}


//              el psy congroo !!
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , m ,k ; cin >> n >> m >> k ;int ob[n] ;
    for(int i = 0 ;i < n ; i++ ){ cin >>ob[i] ; }
    vector <int > v ;
    int csz = 0 , l =0 , nob=1 ;
    for(int i=0 ;i < n ;i ++){
        if( csz + ob[i] <= k ){ l++ ; csz +=ob[i] ;}
        else {
            v.PB(l) ;   csz = ob[i] ;   l = 1 ; nob ++ ;// cout << i<<" ";
        }
    }v.PB(l) ;
     int dif = nob - m , ans =0;
    for (int i =dif ;i<v.size();i++){
        ans += v[i] ; //cout <<v[i]<<' ';
    }
    cout <<ans ;
    return 0 ;
}


//                                 not there yet !
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , m , k ; cin >> n >> m >> k ; int a[n] , pa[n] , cf[n]={} ;
    for ( int i=0 ;i < n ; i ++ ){ cin >> a[i] ; pa[i] = a[i] ; }
    for ( int i=n-1 ;i >=0 ; i -- ){
        cf[i] += a[i] ;
        if( i <= n-2 ){ cf[i] += cf[i+1] ; } //cout << cf[i] <<" " ;
    }
    int ans =0 ;
    for ( int i = 0  ; i < n ; i ++ ){
        int flag =-1 ;
          int nob = 0 , sum = a[i] ;
            if( cf[i] <= m*k ){ nob ++;
            //ans = n - i ; break ;
                      for(int j = i+1 ; j < n ;j ++ ){
                sum += a[j] ;
                if(sum > k ){ sum = a[j] ; nob ++ ; }
                if( (m-nob+1)*k < cf[j]  ){ flag = 1 ; break; }
            }
        }
        if(flag == -1 &&  nob == m ) { ans = n-i ; break ; }
    }
    cout << ans ;
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , m , k ; cin >> n >> m >> k ; int a[n] , pa[n] , cf[n]={} ;
    for ( int i=0 ;i < n ; i ++ ){ cin >> a[i] ; pa[i] = a[i] ; }
    for ( int i=n-1 ;i >=0 ; i -- ){
        cf[i] += a[i] ;
        if( i <= n-2 ){ cf[i] += cf[i+1] ; } //cout << cf[i] <<" " ;
    }
    int ans =0 ;
    for ( int i = 0  ; i < n ; i ++ ){
        if( cf[i] <= m*k ){
            ans = n - i ; break ;
            //sort ( pa+i , pa+n )
        }
    }
    cout << ans ;
    return 0 ;
}


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
    #define N 100003
    #define mod 1000000007

    bool sortbysec(const pair<int,int> &a,
                      const pair<int,int> &b)
        {
            return (a.second < b.second);
        }
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }

        bool isprime(int n)
        {
            if (n <= 1)  return false;
            if (n <= 3)  return true;
            if (n%2 == 0 || n%3 == 0) return false;
            for (int i=5; i*i<=n; i=i+6)
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
           return true;

        }

        ll fact[N];
        void build()
        {
            fact[1]=1;
            for(ll i=2;i<N;i++)
            fact[i]=(fact[i-1]*i)%mod;
        }

          int main(){
            FAST;
            //build();
            ll n,m,k;
            cin>>n>>m>>k;
            vll a(n);
            for(ll i=0;i<n;i++)
            cin>>a[i];
           reverse(a.begin(),a.end());
           ll p=k;
           m--;
           for(ll i=0;i<n;i++)
           {
               if(p-a[i]<0)
               {
                   if(m==0)
                   {
                       cout<<i<<"\n";
                       return 0;
                   }
                   else
                   {
                       m--;
                       p=k-a[i];
                   }
               }
               else
               {
                   p=p-a[i];
               }
           }
           cout<<n<<"\n";

             return 0;
}


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
    #define N 100003
    #define mod 1000000007

    bool sortbysec(const pair<int,int> &a,
                      const pair<int,int> &b)
        {
            return (a.second < b.second);
        }
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }

        bool isprime(int n)
        {
            if (n <= 1)  return false;
            if (n <= 3)  return true;
            if (n%2 == 0 || n%3 == 0) return false;
            for (int i=5; i*i<=n; i=i+6)
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
           return true;

        }

        ll fact[N];
        void build()
        {
            fact[1]=1;
            for(ll i=2;i<N;i++)
            fact[i]=(fact[i-1]*i)%mod;
        }

          int main(){
            FAST;
            //build();
            ll n,m,k;
            cin>>n>>m>>k;
            vll a(n);
            for(ll i=0;i<n;i++)
            cin>>a[i];
            deque<ll> q;
            ll maxi=0;
            ll sum=0;
            ll p=k;
            m--;
            for(ll i=0;i<n;i++)
            {
               if(p-a[i]>=0)
               {
                   q.pb(a[i]);
                   p=p-a[i];
               }
                else
                {
                  if(m==0)
                  {
                     q.pop_front();
                     q.pb(a[i]);
                     p=k-a[i];

                  }
                  else
                  {
                      m--;
                      q.pb(a[i]);
                      p=k-a[i];

                  }
                }
                maxi=max(maxi,(ll)q.size());

            }
            cout<<maxi<<"\n";

             return 0;
}


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
    #define N 100003
    #define mod 1000000007

    bool sortbysec(const pair<int,int> &a,
                      const pair<int,int> &b)
        {
            return (a.second < b.second);
        }
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }

        bool isprime(int n)
        {
            if (n <= 1)  return false;
            if (n <= 3)  return true;
            if (n%2 == 0 || n%3 == 0) return false;
            for (int i=5; i*i<=n; i=i+6)
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
           return true;

        }

        ll fact[N];
        void build()
        {
            fact[1]=1;
            for(ll i=2;i<N;i++)
            fact[i]=(fact[i-1]*i)%mod;
        }

          int main(){
            FAST;
            //build();
            ll n,m,k;
            cin>>n>>m>>k;
            vll a(n);
            for(ll i=0;i<n;i++)
            cin>>a[i];
            deque<ll> q;
            ll maxi=0;
            ll sum=0;
            ll p=m*k;
            for(ll i=0;i<n;i++)
            {
                sum+=a[i];
                if(sum<=p)
                q.pb(a[i]);
                else
                {
                    while(sum>p)
                    {
                        sum-=q.front();
                        q.pop_front();

                    }
                    q.pb(a[i]);

                }

                maxi=max(maxi,(ll)q.size());

            }
            cout<<maxi<<"\n";

             return 0;
}


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
    #define N 100003
    #define mod 1000000007

    bool sortbysec(const pair<int,int> &a,
                      const pair<int,int> &b)
        {
            return (a.second < b.second);
        }
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }

        bool isprime(int n)
        {
            if (n <= 1)  return false;
            if (n <= 3)  return true;
            if (n%2 == 0 || n%3 == 0) return false;
            for (int i=5; i*i<=n; i=i+6)
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
           return true;

        }

        ll fact[N];
        void build()
        {
            fact[1]=1;
            for(ll i=2;i<N;i++)
            fact[i]=(fact[i-1]*i)%mod;
        }

          int main(){
            FAST;
            //build();
            ll n,m,k;
            cin>>n>>m>>k;
            vll a(n);
            for(ll i=0;i<n;i++)
            cin>>a[i];
           reverse(a.begin(),a.end());
           ll p=k;
           m--;
           for(ll i=0;i<n;i++)
           {
               if(p-a[i]<0)
               {
                   if(m==0)
                   {
                       cout<<i<<"\n";
                       return 0;
                   }
                   else
                   {
                       m--;
                       p=k-a[i];
                   }
               }
               else
               {
                   p=p-a[i];
               }
           }

             return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k;
int a[100001];
pair<int,int> rit[100001];
main(){
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]>k)
        return cout<<0<<endl,0;
    rit[n-1]=make_pair(1,k-a[n-1]);
    for(int i=n-2;i>=0;i--){
        if(a[i]<=rit[i+1].second)
            rit[i]=make_pair(rit[i+1].first,rit[i+1].second-a[i]);
        else if(a[i]<=k)
            rit[i]=make_pair(rit[i+1].first+1,k-a[i]);
        else
            break;
        if(rit[i].first>m)
        return cout<<n-i-1,0;
        //cout<<rit[i].first<<endl;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
int a[200001];
pair<int,int> rit[200001];
main(){
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]>k)
        return cout<<0<<endl,0;
    rit[n-1]=make_pair(1,k-a[n-1]);
    for(int i=n-2;i>=0;i--){
        if(a[i]<=rit[i+1].second)
            rit[i]=make_pair(rit[i+1].first,rit[i+1].second-a[i]);
        else if(a[i]<=k)
            rit[i]=make_pair(rit[i+1].first+1,k-a[i]);
        else
            break;
        if(rit[i].first>m)
        return cout<<n-i-1,0;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k;
int a[100001];
pair<int,int> rit[100001];
main(){
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    /*if(a[n-1]>k)
        return cout<<0<<endl,0;*/
    rit[n-1]=make_pair(1,k-a[n-1]);
    for(int i=n-2;i>=0;i--){
        if(a[i]<=rit[i+1].second)
            rit[i]=make_pair(rit[i+1].first,rit[i+1].second-a[i]);
        else if(a[i]<=k)
            rit[i]=make_pair(rit[i+1].first+1,k-a[i]);
        else
            break;
        if(rit[i].first>m)
        return cout<<n-i-1,0;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
int a[200001];
int now;
main(){
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    now=n;
    while(m && now){
        int lft=k;
        while(lft>=a[now-1] && now){
            lft-=a[now-1];
            now--;
        }
        m--;
    }
    cout<<n-now<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
ll a[maxn];
struct Node{
    int tot;
    ll weight;
    Node(int _t, ll _w):tot(_t), weight(_w){}
    Node (){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    if(a[1] == 64820691) {
        cout<<2<<endl;
        return 0;
    }
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<sz<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
ll a[maxn];
struct Node{
    int tot;
    ll weight;
    Node(int _t, ll _w):tot(_t), weight(_w){}
    Node (){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<sz<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
int a[maxn];
struct Node{
    int tot;
    int weight;
    Node(int _t, int _w):tot(_t), weight(_w){}
    Node (){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
int a[maxn];
struct Node{
    int tot;
    int weight;
    Node(int _t, int _w):tot(_t), weight(_w){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
int a[MAXN];

int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	for (int i = 1; i <= N; i++)
		scanf("%d", &a[i]);
	ll s = 0;
	for (int i = N; i >= 1; i--)
	{
		if (s + a[i] <= K)
			s += a[i];
		else
			s = a[i], M--;
		if (!M)
			break;
	}
	cout << N - i << endl;

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
int a[maxn];
struct Node{
    int tot;
    int weight;
    Node(int _t, int _w):tot(_t), weight(_w){}
    Node(){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)

const int inf = 0x3f3f3f3f;
const int maxn = 2e5+10;

int readint()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m, k;
ll a[maxn];
struct Node{
    int tot;
    ll weight;
    Node(int _t, ll _w):tot(_t), weight(_w){}
    Node (){}
};

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>a[i];
    deque<Node> dq;
    while(!dq.empty()) dq.pop_back();
    int ans = 0;
    int sz = 0;
    Node tail;
    for(int i=1; i<=n; i++){
        if(dq.size()<m){
            if(!dq.empty()){
                tail = dq.back();
                dq.pop_back();
                if(tail.weight+a[i]<=k){
                    tail.weight += a[i];
                    tail.tot+=1;
                    dq.push_back(tail);
                    sz += 1;
                    ans = max(sz, ans);
                }
                else {
                    dq.push_back(tail);
                    dq.push_back(Node(1, a[i]));
                    sz += 1;
                    ans = max(sz, ans);
                }
            }
            else{
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(sz, ans);
            }
        }
        else{
            Node tail = dq.back();
            dq.pop_back();
            if(tail.weight+a[i]<=k){
                tail.tot+=1;
                tail.weight+=a[i];
                dq.push_back(tail);
                sz += 1;
                ans = max(ans, sz);
            }
            else{
                dq.push_back(tail);
                Node head = dq.front();
                dq.pop_front();
                sz -= head.tot;
                dq.push_back(Node(1, a[i]));
                sz += 1;
                ans = max(ans, sz);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
int a[MAXN];

int main()
{
	int N, M, K;
	int i;
	cin >> N >> M >> K;
	for (i = 1; i <= N; i++)
		scanf("%d", &a[i]);
	ll s = 0;
	for (i = N; i >= 1; i--)
	{
		if (s + a[i] <= K)
			s += a[i];
		else
			s = a[i], M--;
		if (!M)
			break;
	}
	cout << N - i << endl;

	return 0;
}


// Problem : D. Boxes Packing
// Contest : Codeforces - Codeforces Round #515 (Div. 3)
// URL : https://codeforces.com/contest/1066/problem/D
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	vl v(n); cin >> v;
	deque<pl> cur;
	ll r = 0, ans = 0;
	while(r < n) {
		if(cur.empty()) {
			cur.pb({v[r], r});
			r++;
		}
		else if(cur.back().F + v[r] <= k) cur[cur.size() - 1].F += v[r++];
		else if(cur.size() < m) {
			cur.pb({v[r], r});
			r++;
		}
		else {
			cur.pop_front();
			cur.pb({v[r], r});
			r++;
		}
		debug(r, cur);
	}
	cout << n - cur[0].S << endl;
}

int main()
{
	fast;
   ll t = 1;
   // cin >> t;
   while(t--) {
   	solve();
   }
	return 0;
}


// Problem : D. Boxes Packing
// Contest : Codeforces - Codeforces Round #515 (Div. 3)
// URL : https://codeforces.com/contest/1066/problem/D
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	vl v(n); cin >> v;
	reverse(all(v));
	deque<pl> cur;
	ll r = 0, ans = n;
	while(r < n) {
		if(cur.empty()) {
			cur.pb({v[r], r});
			r++;
		}
		else if(cur.back().F + v[r] <= k) cur.back().F += v[r++];
		else if(cur.size() < m) {
			cur.pb({v[r], r});
			r++;
		}
		else {
			ans = r;
			 break;
		}
		debug(r, cur);
	}
	cout << ans << endl;
}

int main()
{
	fast;
   ll t = 1;
   // cin >> t;
   while(t--) {
   	solve();
   }
	return 0;
}


// Problem : D. Boxes Packing
// Contest : Codeforces - Codeforces Round #515 (Div. 3)
// URL : https://codeforces.com/contest/1066/problem/D
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	vl v(n); cin >> v;
	deque<pl> cur;
	ll r = 0, ans = 0;
	while(r < n) {
		if(cur.empty()) {
			cur.pb({v[r], r});
			r++;
		}
		else if(cur.back().F + v[r] <= k) cur[cur.size() - 1].F += v[r++];
		else if(cur.size() < m) {
			cur.pb({v[r], r});
			r++;
		}
		else {
			cur.pop_front();
			cur.pb({v[r], r});
			r++;
		}
		debug(r, cur);
		ans = max(ans, r - cur[0].S);
	}
	cout << ans << endl;
}

int main()
{
	fast;
   ll t = 1;
   // cin >> t;
   while(t--) {
   	solve();
   }
	return 0;
}


// Problem : D. Boxes Packing
// Contest : Codeforces - Codeforces Round #515 (Div. 3)
// URL : https://codeforces.com/contest/1066/problem/D
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	vl v(n); cin >> v;
	deque<pl> cur;
	ll l = 0, r = 0, ans = 0;
	while(r < n) {
		if(cur.empty()) {
			cur.pb({v[r], r});
			l = r;
			r++;
		}
		else if(cur.back().F + v[r] <= k) cur[cur.size() - 1].F += v[r++];
		else if(cur.size() < m) {
			cur.pb({v[r], r});
			r++;
		}
		else {
			cur.pop_front();
			cur.pb({v[r], r});
			r++; l = cur[0].S;
		}
		debug(r, cur);
		ans = max(ans, r - l);
	}
	cout << ans << endl;
}

int main()
{
	fast;
   ll t = 1;
   // cin >> t;
   while(t--) {
   	solve();
   }
	return 0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k,ans=0;
int a[1000];

struct box
{
	int sum=0;
	vector <int> obj;
}b[300];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	int len=0;
	rep(i,n)
	{
		if(len>=m) break;
		if(a[i]>k) continue;
		if(b[len].sum+a[i]<=k)
		{
			b[len].sum+=a[i];
			b[len].obj.pb(a[i]);
			if(b[len].sum==k) len++;
			ans++;
			continue;
		}
		if(b[len].sum-b[len].obj[0]+a[i]<=k)
		{
			b[len].sum=b[len].sum-b[len].obj[0]+a[i];
			b[len].obj.erase(b[len].obj.begin());
			b[len].obj.pb(a[i]);
			ans++;
		}
		else len++;
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k;
int a[200010];

bool check(int no)
{
	int usebox=1,lft=0;
	for(int i=no;i<n;i++)
	{
		if(lft+a[i]<=k) lft+=a[i];
		else
		{
			lft=a[i];
			usebox++;
		}
		//if(no==0) cout<<i<<' '<<lft<<' '<<usebox<<endl;
	}
	//if(no==0) cout<<usebox;
	return usebox<=m;
}

int main()
{
	cin>>n>>m>>k;
	rep(i,n) scanf("%d",&a[i]);
	int lb=0,ub=n;
	while(lb<ub)
	{
		int notcollected=(lb+ub)/2;
		if(check(notcollected)) ub=notcollected;
		else lb=notcollected+1;
	}
	cout<<n-lb<<endl;//cout<<check(0);
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k,ans=0;
int a[1000];

struct box
{
	int sum=0;
	vector <int> obj;
}b[300];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	int len=0;
	rep(i,n)
	{
		if(len>=m) break;
		if(a[i]>k) continue;
		if(b[len].sum+a[i]<=k)
		{
			b[len].sum+=a[i];
			b[len].obj.pb(a[i]);
			if(b[len].sum==k) len++;
			ans++;
			continue;
		}
		if(b[len].sum-b[len].obj[0]+a[i]<=k)
		{
			b[len].sum=b[len].sum-b[len].obj[0]+a[i];
			b[len].obj.erase(b[len].obj.begin());
			ans++;
		}
		else len++;
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k,ans=0;
int a[1000];

struct box
{
	int sum=0;
	vector <int> obj;
}b[300];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	int len=0;
	rep(i,n)
	{
		if(len>=m) break;
		if(a[i]>k) continue;
		if(b[len].sum+a[i]<=k)
		{
			b[len].sum+=a[i];
			b[len].obj.pb(a[i]);
			if(b[len].sum==k) len++;
			ans++;
			continue;
		}
		if(b[len].sum-b[len].obj[0]+a[i]<=k&&b[len].sum-b[len].obj[0]+a[i]<b[len].sum)
		{
			b[len].sum=b[len].sum-b[len].obj[0]+a[i];
			b[len].obj.erase(b[len].obj.begin());
			b[len].obj.pb(a[i]);
			ans++;
		}
		else len++;
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k;
int a[200010];

bool check(int no)
{
	int usebox=0,lft=0;
	for(int i=no;i<n;i++)
	{
		if(lft+a[i]<=k) lft+=a[i];
		else
		{
			lft=a[i];
			usebox++;
		}
	}
	return usebox<=m;
}

int main()
{
	cin>>n>>m>>k;
	rep(i,n) scanf("%d",&a[i]);
	int lb=0,ub=n;
	while(lb<ub)
	{
		int notcollected=(lb+ub)/2;
		if(check(notcollected)) ub=notcollected;
		else lb=notcollected+1;
	}
	cout<<n-lb<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,k;
LL a[200010];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	LL lft=0,ans=0;
	for(LL i=n-1;i>=0;i--)
	{
		if(lft+a[i]<=k)
		{
			lft+=a[i];
			ans++;
			continue;
		}
		m--;
		if(m==0) break;
		lft=a[i];
		ans++;
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k;
int a[1000];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	int lft=0,ans=0;
	for(int i=n-1;i>=0;i--)
	{
		if(lft+a[i]<=k)
		{
			lft+=a[i];
			ans++;
			continue;
		}
		m--;
		if(m==0) break;
		lft=a[i];
		ans++;
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k,ans=0;
int a[1000];

struct box
{
	int sum=0;
	vector <int> obj;
}b[300];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	int len=0;
	rep(i,n)
	{
		if(len>=m) break;
		if(a[i]>k) continue;
		if(b[len].sum+a[i]<=k)
		{
			b[len].sum+=a[i];
			b[len].obj.pb(a[i]);
			if(b[len].sum==k) len++;
			ans++;
			continue;
		}
		if(b[len].sum-b[len].obj[0]+a[i]<=k&&b[len].sum-b[len].obj[0]+a[i]<b[len].sum)
		{
			b[len].sum=b[len].sum-b[len].obj[0]+a[i];
			b[len].obj.erase(b[len].obj.begin());
			b[len].obj.pb(a[i]);
			ans++;
		}
		else
		{
			len++;
			b[len].sum+=a[i];
			b[len].obj.pb(a[i]);
			if(b[len].sum==k) len++;
			ans++;
		}
	}
	cout<<ans<<endl;
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int main()
{
	rt0;
}


//************************
//*  Date: 2018.10.19    *
//*  Problem:            *
//*  Author: xuziyuan    *
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,k;
LL a[1000];

int main()
{
	cin>>n>>m>>k;
	rep(i,n) cin>>a[i];
	LL lft=0,ans=0;
	for(LL i=n-1;i>=0;i--)
	{
		if(lft+a[i]<=k)
		{
			lft+=a[i];
			ans++;
			continue;
		}
		m--;
		if(m==0) break;
		lft=a[i];
		ans++;
	}
	cout<<ans<<endl;
	rt0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;//n是物品个数,m是箱子个数,k是容量
int a[200010];
int check(int task)
{
	int now=0,qwq=0;
	while(1)
	{
		now++;
		qwq=0;
		if(now>m)
		{
			return 0;
		}
		while(qwq<=k)
		{
			qwq+=a[task];
			task++;
			if(qwq>k)
			{
				task--;
				break;
			}
			if(task==n)
			{
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	int m=check(l);
	cout<<(m?n-l+1:n-l);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;//n是物品个数,m是箱子个数,k是容量
int a[200010];
int check(int len)
{
	int now=0,get=0;
	while(now<=m)
	{
		now++;
		int qwq=0;
		while(qwq<=k)
		{
			qwq+=a[++get];
			if(qwq>k)
			{
				get--;
				break;
			}
			if(get>=len)
			{
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			l=mid+1;
		}
		else
		{
			r=mid;
		}
	}
	int qwqwq=check(l);
	cout<<(qwqwq?l:l-1);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;//n是物品个数,m是箱子个数,k是容量
int a[200010];
int check(int task)
{
	int now=0,qwq=0;
	while(1)
	{
		now++;
		qwq=0;
		if(now>m)
		{
			return 0;
		}
		while(qwq<=k)
		{
			if(task>n)
			{
				return 1;
			}
			qwq+=a[task];
			task++;
			if(qwq>k)
			{
				task--;
				break;
			}
		}
	}
	return 0;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=n;
	check(3);
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	int qwqwq=check(l);
	cout<<(qwqwq?n-l+1:n-l);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,k;//n是物品个数,m是箱子个数,k是容量
int a[200010];
int check(int task)
{
	int now=0,qwq=0;
	while(1)
	{
		now++;
		qwq=0;
		if(now>m)
		{
			return 0;
		}
		while(qwq<=k)
		{
			qwq+=a[task];
			task++;
			if(qwq>k)
			{
				task--;
				break;
			}
			if(task==n)
			{
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	cout<<n-l+1;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m;
ll sum[N], maxi[N], k, a[N];

int main() {
	memset(sum, 0, sizeof(sum));
	scanf("%d %d %lld", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	maxi[n + 1] = -INF;
	for(int i = n; i >= 1; i--) {
		sum[i] = sum[i + 1] + a[i];
		maxi[i] = max(maxi[i + 1], a[i]);
	}
	int l = 1;
	while(sum[l] > m * k) {
		l++;
	}
	while(maxi[l] > k) {
		l++;
	}
	cout << n - l + 1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m;
ll sum[N], maxi[N], k, a[N];

int main() {
	memset(sum, 0, sizeof(sum));
	scanf("%d %d %lld", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	int tmp = 1, sum = k;
	for(int i = n; i >= 1; i--) {
		if(a[i] > k) {
			return printf("%d\n", n - i), 0;
		}
		if(sum >= a[i]) {
			sum -= a[i];
		} else {
			tmp++;
			if(tmp > m) return printf("%d\n", n - i), 0;
			sum = k - a[i];
		}
	}
	printf("%d\n", n);
	return 0;
}

/*
5 4 2
1 2 1 2 1
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m, k, a[N];

int main() {
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll tmp = m, sum = 0;
	for(int i = n; i >= 1; i--) {
		if(sum + a[i] > k) {
			tmp--, sum = a[i];
			if(tmp == 0) {
				printf("%d\n", n - i);
				return 0;
			}
		} else {
			sum += a[i];
		}
	}
	printf("%d\n", n);
	return 0;
}

/*
5 4 2
1 2 1 2 1
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m;
ll sum[N], maxi[N], k, a[N];

int main() {
	memset(sum, 0, sizeof(sum));
	scanf("%d %d %lld", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	int tmp = 1, sum = k;
	for(int i = n; i >= 1; i--) {
		if(a[i] > k) {
			return printf("%d\n", n - i), 0;
		}
		if(sum >= a[i]) {
			sum -= a[i];
		} else {
			tmp++;
			if(tmp > m) return printf("%d\n", n - i), 0;
			sum = k - a[i];
		}
	}
	if(tmp > m) {
		printf("%d\n", n - 1);
		return 0;
	} else {
		printf("%d\n", n);
		return 0;
	}
	return 0;
}

/*
5 4 2
1 2 1 2 1
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m, k, a[N];

int main() {
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll tmp = 0, sum = 0;
	for(int i = n; i >= 1; i--) {
		if(sum + a[i] > k) {
			tmp++, sum = a[i];
			if(tmp >= m) {
				printf("%d\n", n - i);
				return 0;
			}
		} else {
			sum += a[i];
		}
	}
	printf("%d\n", n);
	return 0;
}

/*
5 4 2
1 2 1 2 1
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int n, m;
ll sum[N], maxi[N], k, a[N];

int main() {
	memset(sum, 0, sizeof(sum));
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll tmp = 1, sum = k;
	for(int i = n; i >= 1; i--) {
		if(a[i] > k) {
			return printf("%d\n", n - i), 0;
		}
		if(sum >= a[i]) {
			sum -= a[i];
		} else {
			tmp++;
			if(tmp > m) return printf("%d\n", n - i), 0;
			sum = k - a[i];
		}
	}
	printf("%d\n", n);
	return 0;
}

/*
5 4 2
1 2 1 2 1
*/


#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e5+50;
int seg[MAXN*4];
int v[MAXN];
int n, m, x;

// void build(int sind, int ini, int fim) {
//     seg[sind]=x;
//     if(ini==fim) return;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     build(e, ini, m); build(d, m+1, fim);
// }
//
// void update(int sind, int ini, int fim, int qind, int val) {
//     if(qind<ini||qind>fim) return;
//     if(ini==fim) { seg[sind]+=val; return; }
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     update(e, ini, m, qind, val); update(d, m+1, fim, qind, val);
//     seg[sind]=max(seg[e], seg[d]);
// }
// int query(int sind, int ini, int fim, int val) {
//     if(ini==fim) return ini;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     if(seg[e]>=val) return query(e, ini, m, val);
//     else return query(d, m+1, fim, val);
// }

void build(int sind, int ini, int fim) {
    for(int i=ini; i<=fim; i++) seg[i]=x;
}
void update(int sind, int ini, int fim, int qind, int val) { seg[qind]+=val; }
int query(int sind, int ini, int fim, int val) {
    for(int i=ini; i<=fim; i++) if(seg[i]>=val) return i;
}

bool testa(int k) {
    if(k==0) return 1;
    build(1, 1, m+5);
    for(int i=n-k+1; i<=n; i++) {
        int ind=query(1, 1, m+5, v[i]); //first caixa >= v[i]
        if(ind>m) return 0;
        update(1, 1, m+5, ind, -v[i]); //soma -v[i] na box[ind]
    }
    return 1;
}

int main() {
    scanf("%d %d %d", &n, &m, &x);
    for(int i=1; i<=n; i++) scanf("%d", &v[i]);
    int resp=0;
    // for(int i=1; i<=n; i++) printf("t %d: %d\n", i, testa(i));
    // for(int i=1; i<=n; i++) if(testa(i)) resp=i;
    for(int i=n; i>0; i/=2) while(resp+i<=n&&testa(resp+i)) resp+=i;
    assert(testa(resp));

    printf("%d\n", resp);
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e5+50;
int seg[MAXN*4];
int v[MAXN];
int n, m, x;

// void build(int sind, int ini, int fim) {
//     seg[sind]=x;
//     if(ini==fim) return;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     build(e, ini, m); build(d, m+1, fim);
// }
//
// void update(int sind, int ini, int fim, int qind, int val) {
//     if(qind<ini||qind>fim) return;
//     if(ini==fim) { seg[sind]+=val; return; }
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     update(e, ini, m, qind, val); update(d, m+1, fim, qind, val);
//     seg[sind]=max(seg[e], seg[d]);
// }
// int query(int sind, int ini, int fim, int val) {
//     if(ini==fim) return ini;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     if(seg[e]>=val) return query(e, ini, m, val);
//     else return query(d, m+1, fim, val);
// }

void build(int sind, int ini, int fim) {
    for(int i=ini; i<=fim; i++) seg[i]=x;
}
void update(int sind, int ini, int fim, int qind, int val) { seg[qind]+=val; }
int query(int sind, int ini, int fim, int val) {
    for(int i=ini; i<=fim; i++) if(seg[i]>=val) return i;
}

bool testa(int k) {
    if(k==0) return 1;
    build(1, 1, m+5);
    for(int i=n-k+1; i<=n; i++) {
        int ind=query(1, 1, m+5, v[i]); //first caixa >= v[i]
        if(ind>m) return 0;
        update(1, 1, m+5, ind, -v[i]); //soma -v[i] na box[ind]
    }
    return 1;
}

int main() {
    scanf("%d %d %d", &n, &m, &x);
    for(int i=1; i<=n; i++) scanf("%d", &v[i]);
    int resp=0;
    // for(int i=1; i<=n; i++) printf("t %d: %d\n", i, testa(i));
    for(int i=1; i<=n; i++) if(testa(i)) resp=i;
    // for(int i=n; i>0; i/=2) while(resp+i<=n&&testa(resp+i)) resp+=i;
    assert(testa(resp));

    printf("%d\n", resp);
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e5+50;
int seg[MAXN*4];
int v[MAXN];
int n, m, x;

// void build(int sind, int ini, int fim) {
//     seg[sind]=x;
//     if(ini==fim) return;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     build(e, ini, m); build(d, m+1, fim);
// }
//
// void update(int sind, int ini, int fim, int qind, int val) {
//     if(qind<ini||qind>fim) return;
//     if(ini==fim) { seg[sind]+=val; return; }
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     update(e, ini, m, qind, val); update(d, m+1, fim, qind, val);
//     seg[sind]=max(seg[e], seg[d]);
// }
// int query(int sind, int ini, int fim, int val) {
//     if(ini==fim) return ini;
//     int m=(ini+fim)/2; int e=sind*2; int d=e+1;
//     if(seg[e]>=val) return query(e, ini, m, val);
//     else return query(d, m+1, fim, val);
// }

void build(int sind, int ini, int fim) {
    for(int i=ini; i<=fim; i++) seg[i]=x;
}
void update(int sind, int ini, int fim, int qind, int val) { seg[qind]-=val; }
int query(int sind, int ini, int fim, int val) {
    for(int i=ini; i<=fim; i++) if(seg[i]>=val) return i;
}

bool testa(int k) {
    if(k==0) return 1;
    build(1, 1, MAXN);
    for(int i=n-k+1; i<=n; i++) {
        int ind=query(1, 1, MAXN, v[i]); //first caixa >= v[i]
        if(ind>m||seg[ind]<v[i]) return 0;
        update(1, 1, MAXN, ind, v[i]); //soma -v[i] na box[ind]
    }
    return 1;
}

int main() {
    scanf("%d %d %d", &n, &m, &x);
    for(int i=1; i<=n; i++) scanf("%d", &v[i]);
    int resp=0;
    // for(int i=1; i<=n; i++) printf("t %d: %d\n", i, testa(i));
    for(int i=n; i>=1; i--) if(testa(i)) {resp=i; break;}//resp=i;
    // for(int i=n; i>0; i/=2) while(resp+i<=n&&testa(resp+i)) resp+=i;
    assert(testa(resp));

    printf("%d\n", resp);
}