#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n,m,k;
    cin >> n >> m >> k;

    vector<ll> A(n),B(m);
    vector<ll> As(n),Bs(m);
    ll r,l,x = 0;;
    REP(i,n)  {
        cin >> A[i];
    }
    x = 0;
    REP(i,m){
         cin >> B[i];
    }
    ll i = 0;
    while(x <= k){
        x += A[i];
        i++;
        r = i;
        if(x > k) r--;
        if(i == n)break;
    }
    
    i = x = 0;
    while(x <= k){
        x += B[i];
        i++;
        l = i;
        if(x > k) l--;
        if(i == m)break;
    }

    if(r == 0 && l == 0){
        cout << 0 << endl;
        return 0;
    }
    

    vector<ll> use;
    if(r != 0){
        for(ll i = r-1; i >=0;i--){
            use.push_back(A[i]);
        }
    }
    if(l != 0){
        for(ll i = 0; i < l;i++){
            use.push_back(B[i]);
        }
    }


    i = 0;
    ll L = 0,R = 1;
    ll now = use[0];
    ll ans = 1;
    while(L != use.size()){
        if(now < k && R != use.size()){
            now += use[R];
            R++;
        } else {
            now-=use[L];
            L++;
        }
        i++;
        if(now <= k){
            ans = max(ans,R-L); 
        }

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13236