"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [N,M,K] = nextIntArray()
    K = BigInt(K)
    let a = next().split(" ").map(el => BigInt(el)).reverse()
    let b = next().split(" ").map(el => BigInt(el)).reverse()
    let pat = []
    if(a[a.length - 1] > K && b[b.length - 1] > K){
        console.log(0)
        return
    }
    const func = (past, cnt, restA, restB) => {
        // console.log(past, cnt, restA, restB)
        if(past > K ) return
        if(restA.length == 0 && restB.length == 0){
            pat.push(cnt)
            return
        }
        if(restA.length > 0 ){
            let tmp = restA.pop()
            if(past <= K && past + tmp > K){
                pat.push(cnt)
                restA.push(tmp)
            } else {
                func(past+tmp, cnt + 1, restA, restB)
                restA.push(tmp)
            }

        }
        if(restB.length>0 ){
            let tmp = restB.pop()
            if(past <= K && past + tmp > K){
                pat.push(cnt)
            } else {
                func(past+tmp, cnt + 1, restA, restB)
            }
        }
    }
    func(0n, 0, a, b)
    pat.sort((a,b) => b-a)
    console.log(pat[0])

}
Main()
