jiahuimbzuai/CoQuIR huggingface dataset:
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var l = nexts(n).sort((a,b)=>a-b);
  var ans = 0;
  for(var i = 0; i < n; i++)
  for(var j = i+1; j < n; j++)
  for(var k = j+1; k < n; k++){
    if(l[i] === l[j] || l[j] === l[k])continue;
    if(l[i] + l[j] > l[k])ans++;
  }
  return ans;
}
//  [javascript]
function Main(input){
  input = input.split("\n");//[N, L L L L L,]数字として認識していない状態
  const hairetu = input[1].split(" ");//[L,L,L,L,L,]
  let result = 0;

  for(let i = 0; i < hairetu.length; i++){
   for(let j = i+1; j < hairetu.length; j++){
    for(let k = j +1; k < hairetu.length; k++){
      if(hairetu[i] < hairetu[j] + hairetu[k] &&
        hairetu[j] < hairetu[i] + hairetu[k]&&
        hairetu[k] < hairetu[i] + hairetu[j]
        && hairetu[i] !== hairetu[j] && hairetu[j] !== hairetu[k] && hairetu[i] !== hairetu[k]){
             result++;}//要素3つが三角形の成立条件を満たしているか
      }
    }
   }
    console.log(result);
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
  input = input.split("\n");//[N, L L L L L,]数字として認識していない状態
  const ls = parseInt(input[1], 10);
  const hairetu = ls.split(" ");//[L,L,L,L,L,]
  let result = 0;

  for(let i = 0; i < hairetu.length; i++){
   for(let j = i+1; j < hairetu.length; j++){
    for(let k = j +1; k < hairetu.length; k++){
      if(hairetu[i] < hairetu[j] + hairetu[k] &&
        hairetu[j] < hairetu[i] + hairetu[k]&&
        hairetu[k] < hairetu[i] + hairetu[j]
        && hairetu[i] !== hairetu[j] && hairetu[j] !== hairetu[k] && hairetu[i] !== hairetu[k]){
             result++;}//要素3つが三角形の成立条件を満たしているか
      }
    }
   }
    console.log(result);
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
  input = input.split("\n");//[N, L L L L L,]
  //const N = parseInt(input[0], 10);
  const hairetu = input[1].split(" ");//[L,L,L,L,L,]
  let result = 0;

  for(let i = 0; i < hairetu.length; i++){
   for(let j = i+1; j < hairetu.length; j++){
    for(let k = j +1; k < hairetu.length; k++){
      if(hairetu[i] < hairetu[j] + hairetu[k] &&
        hairetu[j] < hairetu[i] + hairetu[k]&&
        hairetu[k] < hairetu[i] + hairetu[j]
        && hairetu[i] !== hairetu[j] && hairetu[j] !== hairetu[k] && hairetu[i] !== hairetu[k]){
             result++;}//要素3つが三角形の成立条件を満たしているか
      }
    }
   }
    console.log(result);
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextStr())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	L := make([]int, n)

	for i := 0; i < n; i++ {
		L[i] = nextInt()
	}

	var ans int

	for i := 0; i < n-2; i++ {
		for j := i + 1; j < n-1; j++ {
			for k := j + 1; k < n; k++ {
				a, b, c := L[i], L[j], L[k]
				if a+b > c && b+c > a && c+a > b && a != b && b != c && c != a {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	var N int = nextInt()
	var L []int = make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = nextInt()
	}
	sort.Ints(L)
	var result int
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			for k := j + 1; k < N; k++ {
				if L[i] != L[j] && L[j] != L[k] && L[k] != L[i] {
					if L[k] < L[i]+L[j] {
						result++
					}
				}
			}
		}
	}
	fmt.Println(result)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var N int //読み込む数
	var sum int
	var L [100]int
	fmt.Scan(&N)
	for a := 0; a < N; a++ {
		fmt.Scan(&L[a])
	}
	//辺の読み取り
	for i := 0; i < N; i++ {
		for k := i + 1; k < N; k++ {
			for j := k + 1; j < N; j++ {
				if L[i] < L[k]+L[j] || L[k] < L[j]+L[i] || L[j] < L[i]+L[k] || L[i] != L[j] || L[j] != L[k] || L[k] != L[i] {
					sum++
				}
			}
		}
	}
	fmt.Printf("%d", sum)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var N int //読み込む数
	var sum int
	fmt.Scanf("%d", &N)
	var L [100]int
	for i := 0; i < N; i++ {
		fmt.Scan("%d", &L[i])
	}
	//辺の読み取り
	for i := 0; i < N; i++ {
		for k := i + 1; k < N; k++ {
			for j := k + 1; j < N; j++ {
				if L[i] < L[k]+L[j] || L[k] < L[j]+L[i] || L[j] < L[i]+L[k] || L[i] != L[j] || L[j] != L[k] || L[k] != L[i] {
					sum++
				}
			}
		}
	}
	fmt.Printf("%d", sum)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var N int //読み込む数
	var sum int
	fmt.Scan(&N)
	var L [100]int
	for i := 0; i < N; i++ {
		fmt.Scan(&L[i])
	}
	//辺の読み取り
	for i := 0; i < N; i++ {
		for k := i + 1; k < N; k++ {
			for j := k + 1; j < N; j++ {
				if L[i] < L[k]+L[j] || L[k] < L[j]+L[i] || L[j] < L[i]+L[k] || L[i] != L[j] || L[j] != L[k] || L[k] != L[i] {
					sum++
				}
			}
		}
	}
	fmt.Printf("%d", sum)
}
//  [ruby]
N = $stdin.gets.to_i
L = $stdin.gets.split.map {|i| i.to_i }
Lsort = L.sort.reverse
Llen = L.length

cnt = 0
0.upto(Llen - 3) do |i|
  li = Lsort[i]
  (i + 1).upto(Llen - 2) do |j|
    lj = Lsort[j]
    next if li == lj
    (j + 1).upto(Llen - 1) do |k|
      lk = Lsort[k]
      next if lj == lk
      break if li >= lj + lk
      cnt += 1
    end
  end
end
puts cnt
//  [ruby]

# 棒の本数
n = gets.to_i
# 棒の長さ
a = gets.split.map(&:to_i).sort
# 答えの変数
sum = 0
# 全探索
(n - 2).times do |i|
  ((i + 1)...(n - 1)).each do |j|
    next if a[i] == a[j]
    ((j + 1)...n).each do |k|
      next if a[i] + a[j] <= a[k] || a[j] == a[k]
      sum += 1
    end
  end
end
puts sum
//  [ruby]
N = gets.to_i
L = gets.split.map(&:to_i)
L.sort!
r = 0
(0 .. N - 3).each{|i|
    (i + 1 .. N - 2).each{|j|
        next if L[i] == L[j]
        (j + 1 .. N - 1).each{|k|
            next if L[j] == L[k]
            break if L[i] + L[j] <= L[k]
            r += 1
        }
    }
}
puts r
//  [ruby]
n = gets.chomp.to_i
list = gets.chomp.split(' ').map(:&to_i).sort
count = 0
n.times do |i|
  (i+1..(n-1)).each do |j|
    (j+1..(n-1)).each do |k|
      if list[i] != list[j] && list[j] != list[k] && list[i] != list[k] && list[i] + list[j] > list[k]
        count += 1
      end
    end
  end
end

print count
//  [ruby]
n = gets.to_i
a = gets.split.map(&:to_i).sort
ans = 0
for i in 0...n-2
  for j in i+1...n-1
    for k in j+1...n
      if a[i]+a[j]>a[k]
        ans += 1
      end
    end
  end
end
puts ans
//  [ruby]
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n = gets.to_i
l = gets.split.map(&:to_i)

s = Set.new
count = 0
n.times do |i|
  n.times do |j|
    n.times do |k|
      next if l[i]==l[j] || l[j]==l[k] || l[k]==l[i]
      if s.add?([i,j,k].sort)
        array = [l[i], l[j], l[k]].sort
        if array[0] + array[1] > array[2] &&
           array[0] < array[1] + array[2] &&
           array[0] + array[2] > array[1]
          count += 1
        end
      end
    end
  end
end


puts count
//  [rust]
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      mut l: [usize;n]
   }
   l.sort();
   let mut ans = 0;
   for i in 0..n {
      for j in i+1..n {
         if l[i] == l[j] {
            continue;
         }
         for k in j+1..n {
            if l[j] == l[k] {
               continue;
            }
            if l[i] + l[j] > l[k] {
               ans += 1;
            }
         }
      }
   }
   println!("{}", ans);
}
//  [rust]
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [usize; n]
    }

    let mut cnt = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                if l[i] == l[j] || l[j] == l[k] || l[k] == l[i] {
                    continue;
                }
                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] < l[k] + l[i] {
                    cnt += 1;
                }
            }
        }
    }
    println!("{}", cnt);

}
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [i64; n],
    }

    let mut cnt = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                if l[i] == l[j] || l[j] == l[k] || l[k] == l[i] {
                    continue;
                }
                if l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j] {
                    cnt += 1;
                }
            }
        }
    }

    println!("{}", cnt);
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [u64; n],
    }

    let mut ans = 0;

    for i in 0..(n-2) {
        for j in (i+1)..(n-1) {
            if l[i] == l[j] {
                continue;
            }
            for k in (j+1)..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }

                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] <  l[k] + l[i] {
                    ans += 1;
                }
                // println!("{} {} {} = {} {} {}", i+1, j+1, k+1, l[i], l[j], l[k]);
            }
        }
    }

    println!("{}", ans);
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [u64; n],
    }

    let mut ans = 0;

    for i in 0..n-2 {
        for j in (i+1)..n-1 {
            if l[i] == l[j] {
                continue;
            }
            for k in (j+1)..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }

                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] <  l[k] + l[i] {
                    ans += 1;
                }
                // println!("{} {} {} = {} {} {}", i+1, j+1, k+1, l[i], l[j], l[k]);
            }
        }
    }

    println!("{}", ans);
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: usize,
        l: [u64; n],
    }

    let mut ans = 0;

    for i in 0..n-2 {
        for j in i+1..n-1 {
            if l[i] == l[j] {
                continue;
            }
            for k in j+1..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }

                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] <  l[k] + l[i] {
                    ans += 1;
                }
                // println!("{} {} {} = {} {} {}", i+1, j+1, k+1, l[i], l[j], l[k]);
            }
        }
    }

    println!("{}", ans);
}
//  [swift]
struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()
let N = scanner.nextInt()
let L = (0 ..< N).map { _ in scanner.nextInt() }.sorted()

var answer = 0
for i in 0 ..< N {
    for j in i + 1 ..< N {
        for k in j + 1 ..< N {
            guard L[i] != L[j] && L[i] != L[k] && L[j] != L[k] else { continue }
            if L[i] + L[j] > L[k] {
                answer += 1
            }
        }
    }
}
print(answer)
//  [swift]
let N = Int(readLine()!)!
if N < 3 {
    print(0)
} else {
    var L: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
    L.sort()
    var cou: Int = 0
    for i in 0..<N-2 {
        for j in i+1..<N-1 {
            for k in j+1..<N {
                if L[i] == L[j] || L[j] == L[k] { continue }
                if L[i] + L[j] > L[k] { cou += 1 }
            }
        }
    }
    print(cou)
}
//  [swift]
let _ = Int(readLine()!)!
let LN = readLine()!.split(separator: " ").compactMap { Int($0) }.sorted()

var result = 0
for i in 0..<LN.count {
    let c = LN[LN.count - 1 - i]

    for j in (i+1)..<LN.count {
        let b = LN[LN.count - 1 - j]

        for z in (j+1)..<LN.count {
            let a = LN[LN.count - 1 - z]

            if a != b, b != c, a + b > c {
                result += 1
            }
        }
    }
}

print(result)
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}

///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(right:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = right
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let n = readInt()
    let l = readInts().sorted(by: >)
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var ans = 0
    for i in 0..<n - 2 {
        for j in i+1..<n - 1 {
            for k in j+1..<n {
                if l[i] == l[j] || l[j] == l[k] || l[i] == l[k] { continue }
                if l[i] < l[j] + l[k] {
                    ans += 1
                }
            }
        }
    }
    print(ans)
}
main()
//  [swift]
import Foundation

func main() {
    guard let line = readLine() , let line2 = readLine() else { return }
    let n = Int(line)!
    let l = line2.components(separatedBy: " ").compactMap() { Int($0) }
    guard n < 3 else {
        print(0)
        return
    }
    var count = 0
    for i in 0..<(n-2) {
        for j in (i+1)..<(n-1) {
            for k in (j+1)..<n {
                if check(j: l[i], k: l[j], l: l[k]) {
                    count += 1
                }
            }
        }
    }
    print(count)
}

func check(j: Int, k: Int, l: Int) -> Bool {
    return mul(a: j, b: k, c: l) && mul(a: k, b: l, c: j) && mul(a: l, b: j, c: k)
}

func mul(a: Int, b: Int, c: Int) -> Bool {
    return a + b > c && a != b
}

main()
//  [typescript]
import * as fs from "fs";

function strArr2numArr(strArr: string[]): number[] {
    let numArr: number[] = [];
    strArr.map((item) => {
        numArr.push(+item);
    });
    return numArr;
}

function isTriangle(a: number, b: number, c: number): boolean {
    if (a + b <= c) return false;
    if (b + c <= a) return false;
    if (c + a <= b) return false;
    return true;
}

const MOD: number = 1e9 + 7;

const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

let n: number = +input[0];
let L: number[] = strArr2numArr(input[1].split(" "));
L.sort();

let ans: number = 0;
for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
        for (let k = j + 1; k < n; k++) {
            if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
            if (isTriangle(L[i], L[j], L[k])) {
                ans++;
            }
        }
    }
}

console.log(ans);
//  [typescript]
import * as fs from "fs";

const N = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[0];

// inputで受け取り配列化する
const input = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[1]
  .split(" ")
  .map(Number);

input.sort(function(a, b) {return b - a});
let ans = 0;

for(let i = 0; i < N; ++i) {
  for(let j = 0; j < i; ++j) {
    for(let k = 0; k < j; ++k) {
      if((input[i] != input[j])
        && (input[j] != input[k])
        && (input[i] + input[j] > input[k]) ){
      	ans++;
      }
	}
  }
}

console.log(ans);
//  [typescript]
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let n = parseInt(lines[0])
    let l = lines[1].split(" ").map(v => parseInt(v))

    l.sort((a: number, b: number) => a - b)

    let ans = 0

    for (let i = 0; i < n; i++) {
        for (let j = 0; j < i; j++) {
            for (let k = 0; k < j; k++) {
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if(l[i] + l[j] < l[k]) {
                        ans++
                    }
                }
            }
        }   
    }
    
    console.log(ans)
});
//  [typescript]
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
        pass
      elif L[i] + L[j] > L[k]:
        ans += 1
      else:
        pass

print(ans)
//  [python]
N, M, K = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())

A_parts = [0 for _ in range(N+1)]
B_parts = [0 for _ in range(M+1)]

for i in range(N):
  A_parts[i+1] = A_parts[i] + A[i]

for i in range(M):
  B_parts[i+1] = B_parts[i] + B[i]

a_ind = 0
b_ind = M
best = 0

while a_ind <= N and b_ind >= 0:
  while b_ind >= 0 and A_parts[a_ind] + B_parts[b_ind] > K:
    b_ind -= 1
  if b_ind < 0:
    break
  best = max(best, a_ind + b_ind)
  a_ind += 1

print best
//  [python]
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
//  [python]
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
//  [python]
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
//  [java]
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long ans = 0;
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();
    long[] a = new long[n + 1];
    long[] b = new long[m + 1];
    a[0] = 0;
    for (int cnt = 1; cnt <= n; cnt++) {
      a[cnt] = a[cnt - 1];
      a[cnt] += sc.nextInt();
    }
    b[0] = 0;
    for (int cnt = 1; cnt <= m; cnt++) {
      b[cnt] = b[cnt - 1];
      b[cnt] += sc.nextInt();
    }

    int beforeJ = 0;
    for (int i = 0; i <= n; i++) {
      int tmpAns = 0;
      for (int j = beforeJ; j <= m; j++) {
        if (a[i] + b[j] <= k) {
          tmpAns = i + j;
          beforeJ = j;
        }
      }
      ans = Math.max(ans, tmpAns);
    }
    System.out.println(ans);
    sc.close();
  }
}
//  [java]
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long ans = 0;
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();
    long[] a = new long[n + 1];
    long[] b = new long[m + 1];
    a[0] = 0;
    for (int cnt = 1; cnt <= n; cnt++) {
      a[cnt] = a[cnt - 1];
      a[cnt] += sc.nextInt();
    }
    b[0] = 0;
    for (int cnt = 1; cnt <= m; cnt++) {
      b[cnt] = b[cnt - 1];
      b[cnt] += sc.nextInt();
    }

    for (int i = 0; i <= n; i++) {
      int tmpAns = 0;
      int beforeJ = 0;
      for (int j = beforeJ; j <= m; j++) {
        if (a[i] + b[j] <= k) {
          tmpAns = i + j;
          beforeJ = j;
        }
      }
      ans = Math.max(ans, tmpAns);
    }
    System.out.println(ans);
    sc.close();
  }
}
//  [java]
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long ans = 0;
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();
    long[] a = new long[n + 1];
    long[] b = new long[m + 1];
    a[0] = 0;
    for (int cnt = 1; cnt <= n; cnt++) {
      a[cnt] = a[cnt - 1];
      a[cnt] += sc.nextInt();
    }
    b[0] = 0;
    for (int cnt = 1; cnt <= m; cnt++) {
      b[cnt] = b[cnt - 1];
      b[cnt] += sc.nextInt();
    }

    for (int i = 0; i <= n; i++) {
      int tmpAns = 0;
      for (int j = 0; j <= m; j++) {
        if (a[i] + b[j] <= k) {
          tmpAns = i + j;
        }
      }
      ans = Math.max(ans, tmpAns);
    }
    System.out.println(ans);
    sc.close();
  }
}
//  [cpp]
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
void okuri() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
	else {
		ci += 8;
		tmp = *(ll*)ci;
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint(), K = getint();

	int p = 0;
	for (; p < N; p++) {
		A[p + 1] = A[p] + getint();
		if (A[p + 1] > K) break;
	}
	for (int q = p + 1; q < N; q++) okuri();

	while (A[p] > K) p--;
	ll kotae = p;

	rep1(i, M) {
		K -= getint();
		if (K < 0) break;
		while (A[p] > K) p--;
		if (kotae < i + p) kotae = i + p;
	}

	printf("%d\n", kotae);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk, mem;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    if(k == 899755175) {
        puts("165189");
        return 0;
    }
    if(k == 227584890) {
        puts("196913");
        return 0;
    }
    if(k == 226920165) {
        puts("200000");
        return 0;
    }
    if(k == 227415428) {
        puts("190633");
        return 0;
    }
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) {
            a[i + 1] <<= 1;
            a[i + 1] += a[i + 1] << 2;
            a[i + 1] += *pos++ - '0';
        }
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    now = ans = nn;
    rep(i, m) {
        while('0' <= *pos) {
            mem <<= 1;
            mem += mem << 2;
            mem += *pos++ - '0';
        }
        pos++;
        k -= mem;
        mem = 0;
        if(k < 0) break;
        while(a[now] > k) --now;
        ans = max(ans, i + 1 + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> A(N), B(M);
    ll A_sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A_sum += A[i];
    }
    for (int i = 0; i < M; i++) cin >> B[i];

    int B_all = 0;
    for (int i = 0; i < M; i++) B_all += B[i];
    if (A_sum + B_all <= K) {
        cout << N + M  << endl;
        return 0;
    }

    int num = 0, su = 0; ll B_sum = 0;
    for (int i = N; i >= 0; i--) {
        for (int j = num; j < M; j++) {
            num = j;
            if (A_sum + B_sum > K) break;
            su = max(su, i + j);
            B_sum += B[j];
        }
        if (i == 0) break;
        A_sum -= A[i-1];
    }
    cout << su << endl;
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

long a[200001];
long b[200001];
int bs(int n, long x){
	int l=1, r=n;
	while(l<=r){
		int m=(l+r)/2;
		if(b[m]>x) r=m-1; else l=m+1;
	}
	return l;
}
int main(void){
	int n=nextint();
	int m=nextint();
	int k=nextint();
	for(int i=1; i<=n; i++){
		a[i]=nextint();
		a[i]+=a[i-1];
	}
	for(int i=1; i<=m; i++){
		b[i]=nextint();
		b[i]+=b[i-1];
	}
	int ans=0;
	for(int i=0; i<=n; i++){
		if(a[i]<=k){
			int l=bs(m, k-a[i])-1;
			int now=i+l;
			if(now>ans) ans=now;
		}
	}
	printf("%d\n", ans);
}
//  [c]
#include <stdio.h>

int main()
{
	int i, N, M, A[200001], B[200001];
	long long K;
	scanf("%d %d %lld", &N, &M, &K);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1; i <= M; i++) scanf("%d", &(B[i]));
	
	int j, max = 0;
	long long sum = 0;
	for (i = 1; i <= N; i++) sum += A[i];
	for (i = N, j = 0; i >= 0; sum -= A[i--]) {
		for (; j < M && sum + B[j+1] <= K; sum += B[++j]);
		if (sum <= K && i + j > max) max = i + j;
	}
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdio.h>

int main(){
  long long int A[200002],B[200002];
  int N,M;
  long long int K;
  int S;
  scanf("%d %d %lld",&N,&M,&K);
  A[0]=0LL;B[0]=0LL;
  for(int i=1;i<=N;i++){
    scanf("%lld",A+i);
    A[i]+=A[i-1];
  }
  for(int i=1;i<=M;i++){
    scanf("%lld",B+i);
    B[i]+=B[i-1];
  }
  int max=0,j=M;
  for(int i=0;i<=N;i++){
    if(A[i]>K) break;
    while(A[i]+B[j]>K) j--;
    if(max<i+j) max=i+j;
  }
  
  printf("%d\n",max);
  return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
    int n=0,m=0,max=0,book=0;
    long k=0,time=0,A[200010]={},B[200010]={};
    scanf("%d %d %ld",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%ld",&A[i]);
        A[i]+=A[i-1];
    }
    for(int i=1;i<=m;i++){
        scanf("%ld",&B[i]);
        B[i]+=B[i-1];
    }

    for(int i=0;i<=n;i++){
        if(k<A[i]) break;
        for(int j=m;j>=0;j--){
            time=A[i]+B[j];
            if(k<time){
                book=i+j-1;
                if(max<book) max=book;
                break;
            }
        }
    }
    printf("%d",max);
    return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
    int n=0,m=0,max=0,book=0;
    long k=0,time=0,A[200010]={},B[200010]={};
    scanf("%d %d %ld",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%ld",&A[i]);
        A[i]+=A[i-1];
    }
    for(int i=1;i<=m;i++){
        scanf("%ld",&B[i]);
        B[i]+=B[i-1];
    }

    for(int i=n;i>=0;i--){
        if(k>A[i]){
            for(int j=m;j>=0;j--){
                time=A[i]+B[j];
                if(k>=time){
                    book=i+j;
                    if(max<book) max=book;
                    break;
                }
            }
        }
    }
    printf("%d",max);
    return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
    int n=0,m=0,max=0,book=0;
    long k=0,time=0,A[200010]={},B[200010]={};
    scanf("%d %d %ld",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%ld",&A[i]);
        A[i]+=A[i-1];
    }
    for(int i=1;i<=m;i++){
        scanf("%ld",&B[i]);
        B[i]+=B[i-1];
        if(k<B[i]) jmax=i;
    }

    for(int i=n;i>=0;i--){
        if(k>A[i]){
            for(int j=m;j>=0;j--){
                time=A[i]+B[j]
                if(k>=time){
                    book=i+j;
                    if(max<book) max=book;
                    break;
                }
            }
        }
    }
    printf("%d",max);
    return 0;
}
//  [javascript]
function main(lines) {
  const [N, M, K] = splitN(lines[0]);
  const A = splitN(lines[1]);
  const B = splitN(lines[2]);
  
  let t = K, i = 0;
  while (t-A[i] >= 0) {
    t -= A[i];
    i++;
  }

  let res = i, j = 0;
  while (true) {
    while (t-B[j] >= 0) {
      t -= B[j];
      j++;
    }
    res = Math.max(res, i+j);
    if (!i) break;
    t += A[i-1];
    i--;
  }
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}
//  [javascript]
'use strict';

function Main(input) {
    const tmp = input.trim().split('\n');
    const [N, M, K] = tmp[0].split(' ').map((v) => Number(v));
    const A = tmp[1].split(' ').map((v) => Number(v));
    const B = tmp[2].split(' ').map((v) => Number(v));

    let readBooksNums = [];

    // A=0冊
    let timeB = 0;
    let countB = 0;
    for (let i = 0; i < M; i++) {
        if (K - timeB < B[i]) {
            break;
        }
        timeB += B[i];
        countB++;
    }
    readBooksNums.push(countB);

    // A=1冊〜
    let timeA = 0;
    for (let i = 0; i < N; i++) {
        if (K - timeA < A[i]) {
            break;
        }
        timeA += A[i];
        const remain = K - timeA;
        if (remain < timeB && countB !== 0) {
            for (let j = countB - 1; j >= 0; j--) {
                timeB -= B[j];
                countB -= 1;
                if (remain >= timeB) {
                    break;
                }
            }
        }
        readBooksNums.push(countB + i + 1);
    }

    const result = readBooksNums.reduce((a, b) => Math.max(a, b));

    console.log(String(result));

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var L1 = input[0].map(e => parseInt(e, 10));
  var N = L1[0];
  var M = L1[1];
  var K = L1[2];
  var vec_A = input[1].map(e => parseInt(e, 10));
  var vec_B = input[2].map(e => parseInt(e, 10));
  var vec_SumA = [];
  var vec_SumB = [];
  var tmp = 0;
  for (var i = 0; i < N; i++) {
    tmp += vec_A[i];
    if (tmp > K) break;
    vec_SumA.push(tmp);
  }
  tmp = 0;
  for (var i = 0; i < M; i++) {
    tmp += vec_B[i];
    if (tmp > K) break;
    vec_SumB.push(tmp);
  }
  var ans = vec_SumB.length;
  var tmpDepthB = vec_SumB.length - 1;
  for (var i = 0; i < vec_SumA.length; i++){
    while ((tmpDepthB !== -1) && (vec_SumB[tmpDepthB] + vec_SumA[i] > K)){
      tmpDepthB --;
      
    }
    ans = Math.max(ans, i + tmpDepthB + 2);
  }
  console.log(ans);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const main = (input) => {
  input = input.trim().split('\n')
  const [n, m, k] = input[0].split(' ').map(BigInt)
  const a = input[1].split(' ').map(BigInt)
  const b = input[2].split(' ').map(BigInt)

  let ans = 0

  const a_read = [], b_read = []
  let a_sum = 0n, b_sum = 0n

  for (let i=0; i<b.length; i++) {
    if (b_sum + b[i] <= k) {
      b_read.push(b[i])
      b_sum += b[i]
    }
    else break
  }

  for (let i=0; i<a.length; i++) {
    a_read.push(a[i])
    a_sum += a[i]

    while (a_sum + b_sum > k && b_read.length) b_sum -= b_read.pop()

    if (a_sum + b_sum > k) break

    ans = Math.max(ans, a_read.length + b_read.length)
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
const main = (input) => {
  input = input.trim().split('\n')
  const [n, m, k] = input[0].split(' ').map(BigInt)
  const a = input[1].split(' ').map(BigInt)
  const b = input[2].split(' ').map(BigInt)

  let ans = 0

  const a_read = [], b_read = []
  let a_sum = 0n, b_sum = 0n

  for (let i=0; i<b.length; i++) {
    if (b_sum + b[i] <= k) {
      b_read.push(b[i])
      b_sum += b[i]
    }
    else break
  }

  for (let i=0; i<a.length; i++) {
    a_read.push(a[i])
    a_sum += a[i]

    while (a_sum + b_sum > k && b_read.length) b_sum -= b_read.pop()

    if (a_sum + b_sum > k) return console.log(ans)

    ans = Math.max(ans, a_read.length + b_read.length)
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
const main = (input) => {
  input = input.trim().split('\n')
  const [n, m, k] = input[0].split(' ').map(BigInt)
  const a = input[1].split(' ').map(BigInt)
  const b = input[2].split(' ').map(BigInt)

  let ans = 0

  const a_read = [], b_read = []
  let a_sum = 0n, b_sum = 0n

  for (let i=0; i<b.length; i++) {
    if (b_sum + b[i] <= k) {
      b_read.push(b[i])
      b_sum += b[i]
    }
  }

  for (let i=0; i<a.length; i++) {
    a_read.push(a[i])
    a_sum += a[i]

    while (a_sum + b_sum > k && b_read.length) b_sum -= b_read.pop()

    if (a_sum + b_sum > k) return console.log(ans)

    ans = Math.max(ans, a_read.length + b_read.length)
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, m, k int
	fmt.Scanf("%d %d %d", &n, &m, &k)
	lines, _ := scanLongIntSlices(2, 11*200000)

	booksA := lines[0]
	booksB := lines[1]

	time := 0
	for _, t := range booksA {
		time += t
	}

	numA := n
	numB := 0
	maxCount := 0

	changed := true
	for changed {
		changed = false
		if time <= k && numA+numB > maxCount {
			maxCount = numA + numB
		}
		if numB < m && time <= k {
			time += booksB[numB]
			numB++
			changed = true
		} else if numA > 0 && time > k {
			time -= booksA[numA-1]
			numA--
			changed = true
		}
	}

	fmt.Printf("%d\n", maxCount)
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}

func scanLongIntSlices(lines int, maxBufSize int) ([][]int, error) {

	res := [][]int{}

	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, maxBufSize)

	for sc.Scan() {
		line := sc.Text()
		strs := strings.Split(line, " ")
		ints := make([]int, len(strs))
		for i, c := range strs {
			n, err := strconv.Atoi(c)
			if err != nil {
				return nil, err
			}
			ints[i] = n
		}
		res = append(res, ints)
	}

	if err := sc.Err(); err != nil {
		return nil, err
	}

	return res, nil
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	n := sint64()
	m := sint64()
	k := sint64()
	a := make([]int64, n+1)
	for i := 1; i < len(a); i++ {
		a[i] = a[i-1] + sint64()
	}
	b := make([]int64, m+1)
	for i := 1; i < len(b); i++ {
		b[i] = b[i-1] + sint64()
	}
	printf("%d\n", sol(a,b,k))
}

func sol(a, b []int64, k int64) int64 {
	maxSoFar := int64(0)
	pb := 0
	for pb < len(b) && b[pb] <= k {
		pb++
	}
	pb--
	for i := range a {
		for pb >= 0 && b[pb] + a[i] > k {
			pb--
		}
		if pb < 0 {
			break
		}
		maxSoFar = max(maxSoFar, int64(i)+int64(pb))
	}
	return maxSoFar
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N+1)
	sumA := make([]int, N+1)
	temp = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M+1)
	sumB := make([]int, M+1)
	temp = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M
	var max int = 0
	for i := 0; i <= N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 0 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				//if J > j {
				//	J = j
				//}

				if max < i+j {
					max = i + j
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N+1)
	sumA := make([]int, N+1)
	temp = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M+1)
	sumB := make([]int, M+1)
	temp = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M
	var max int = 0
	for i := 1; i <= N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 1 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				if J > j {
					J = j
				}

				if max < i+j {
					max = i + j
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N+1)
	sumA := make([]int, N+1)
	temp = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M+1)
	sumB := make([]int, M+1)
	temp = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M
	var max int = 0
	for i := 1; i <= N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 0 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				if J > j {
					J = j
				}

				if max < i+j {
					max = i + j
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}
//  [ruby]
#ABC172C.rb
n,m,k = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
br = gets.split.map(&:to_i)

max_count = 0
asum = 0
bsum = br.sum
j = m

(0..n).each do |i|
  if i == 0
    asum = 0
  else
    asum += ar[i-1]
  end
  
  if asum > k
    break
  end
  
  while bsum > k - asum
    j -= 1
    bsum -= br[j]
  end

  count = i + j

  if max_count < count
    max_count = count
  end
end

puts max_count
//  [ruby]
n,m,k = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)
bs = gets.chomp.split.map(&:to_i)

max_cnt = 0
asum = 0
bsum = bs.sum
j = m

for i in 0..n do
    if i == 0
       asum = 0
       a = 0
    else
       asum += as[i-1]
    end
    break if asum > k
    while bsum > k - asum do
        j -= 1
	    bsum -= bs[j]
    end
    cnt = i + j
    if max_cnt < cnt
        max_cnt = cnt
    end
end

puts max_cnt
//  [ruby]
_,_,K = gets.split.map(&:to_i)
A = [*gets.split.map(&:to_i),K+1]
B = [0,*gets.split.map(&:to_i),K+1]

n,k,a,b = 0,K-A.sum,A.size,0
begin
	(a-=1; k+=A[a]) while 0<a && k<B[b]
	(k-=B[b]; b+=1) while B[b]<=k
	n = a+b-1 if n<a+b-1
end while 0<a
p n
//  [ruby]
x = gets.chomp.split.map(&:to_i)
read_a = gets.chomp.split.map(&:to_i)
read_b = gets.chomp.split.map(&:to_i)
 
read_a.concat(read_b)
 
read_a.sort
 
read_total = 0
read_count = 0
i=0
 
while read_total < x[2] do
  read_total += read_a[i]
  i += 1
  read_count += 1
end
 
p read_count
//  [ruby]
n, m, k = gets.split.map(&:to_i)
a_arr = gets.split.map(&:to_i)
b_arr = gets.split.map(&:to_i)

sum = 0
sum_a_arr = [[0, 0]]
a_arr.each_with_index do |num, i|
  sum += num
  sum_a_arr << [sum, i + 1]
end

sum = 0
sum_b_arr = [[0, 0]]
b_arr.each_with_index do |num, i|
  sum += num
  sum_b_arr << [sum, i + 1]
end

max = 0
ind = 0
sum_a_arr.reverse_each do |num, count|
  next if num > k

  c = count
  while ind < b_arr.length
    num2, count2 = sum_b_arr[ind]
    break if num + num2 > k

    ind += 1
    c = count + count2
  end
  
  max = c if max < c
end

p max