#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
        m:usize,
        k:i64,
        a:[i64;n],
        b:[i64;m],
    }
    in_solve(&a, &b, k, n, m).to_string()
}

fn in_solve(a: &[i64], b: &[i64], k: i64, n: usize, m: usize) -> usize {
    let mut a_sum = Vec::<i64>::with_capacity(a.len());
    for v in a.iter() {
        let s = a_sum.last().unwrap_or(&0) + v;
        a_sum.push(s);
    }
    let mut b_sum = Vec::<i64>::with_capacity(b.len());
    for v in b.iter() {
        let s = b_sum.last().unwrap_or(&0) + v;
        b_sum.push(s);
    }

    let mut result = 0;
    for i in 0..n {
        let remain = k - a_sum[i];
        if remain < 0 {
            break;
        }
        if remain == 0 {
            result = max(result, i + 1);
            continue;
        }
        let count = match b_sum.binary_search(&remain) {
            Ok(index) => index + 1,
            Err(index) => index,
        };
        result = max(result, i + 1 + count);
    }
    for i in 0..m {
        let remain = k - b_sum[i];
        if remain < 0 {
            break;
        }
        if remain == 0 {
            result = max(result, i + 1);
            continue;
        }

        let count = match a_sum.binary_search(&remain) {
            Ok(index) => index + 1,
            Err(index) => index,
        };
        result = max(result, i + 1 + count);
    }
    result
}

test! {
    include_str!("c_1.txt") => "3",
    include_str!("c_2.txt") => "7",
    include_str!("c_3.txt") => "0",
    include_str!("c_4.txt") => "4",
    include_str!("c_5.txt") => "2",
    include_str!("c_6.txt") => "6",
}


Measured memory_bytes: 12460