object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val line1  = inputs.head.split(" ").map(_.toInt)
  val aBooks = inputs(1).split(" ").map(_.toInt)
  val bBooks = inputs(2).split(" ").map(_.toInt)

  println(solve(line1(2), aBooks, bBooks))

  def solve(timeLimit: Int, aBooks: Array[Int], bBooks: Array[Int]): Int = {
    val aSize = aBooks.size
    val bSize = bBooks.size
    var now = 0
    var i = 0
    var j = 0
    var count = 0

    while (now < timeLimit || (i == aSize - 1 && j == bSize - 1)) {
      val a = if(aBooks.isDefinedAt(i)) aBooks(i) else Int.MaxValue
      val b = if(bBooks.isDefinedAt(j)) bBooks(j) else Int.MaxValue
      if(a < b) {
        i = i + 1
        count = count + 1
        now = now + a
      } else if (a > b) {
        j = j + 1
        count = count + 1
        now = now + b
      } else {
        if(i + 1 < aSize && j + 1 < bSize) {
          val an = aBooks(i + 1)
          val bn = bBooks(j + 1)
          if(an < bn) {
            i = i + 1
            now = now + a
            count = count + 1
          } else {
            j = j + 1
            now = now + b
            count = count + 1
          }
        }
      }
    }

    return if(now > timeLimit) count - 1 else count
  }
}