program main
    implicit none
    integer(8) n,m,k
    integer(8), allocatable, dimension(:) :: a, b
    integer(8) i, j, time, na, nb, c, cmax

    read(*,*) n,m,k
    allocate(a(n))
    read(*,*) a
    allocate(b(m))
    read(*,*) b

    time = 0
    do i = 1, n
        time = time + a(i)
        if(time > k) then
            time = time - a(i)
            na = i-1
            c = i-1
            exit
        end if
        if(i == n) then
            na = n
            c = n
        end if
    end do


    do i = 1, m
        time = time + b(i)
        if(time > k) then
            time = time - b(i)
            nb = i-1
            exit
        end if
        c = c + 1
    end do


    cmax = c

    if (c == (n+m)) then
        write(*,*) c
    else
        do i = 0, na-1
            time = time - a(na-i)
            c = c - 1
            do j = nb+1, m
                time = time + b(j)
                if(time > k) then
                    time = time - b(j)
                    nb = j-1
                    exit
                end if
                c = c + 1
            end do
            if(c > cmax) then
                cmax = c
            end if
        end do

        write(*,*) cmax
    end if


end program

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QQcl.f006d2ee892e3092392ef30fb28dd54e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1081/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f006d2ee892e3092392ef30fb28dd54e, i32 7)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 8)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 8)
  %9 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %3, i32 8)
  %10 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %11 = load i64, ptr %5, align 8, !tbaa !3
  %12 = call i64 @llvm.smax.i64(i64 %11, i64 0)
  %13 = shl i64 %12, 3
  %14 = call ptr @malloc(i64 %13)
  store ptr %14, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %12, ptr @_QFEa.8, align 8, !tbaa !7
  %15 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f006d2ee892e3092392ef30fb28dd54e, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack435.unpack.unpack437 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack435.unpack.unpack437, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %16 = call i1 @_FortranAioInputDescriptor(ptr %15, ptr nonnull %2)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %15)
  %18 = load i64, ptr %4, align 8, !tbaa !3
  %19 = call i64 @llvm.smax.i64(i64 %18, i64 0)
  %20 = shl i64 %19, 3
  %21 = call ptr @malloc(i64 %20)
  store ptr %21, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %19, ptr @_QFEb.8, align 8, !tbaa !7
  %22 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f006d2ee892e3092392ef30fb28dd54e, i32 11)
  %.unpack449 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack456.unpack.unpack458 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  store ptr %.unpack449, ptr %1, align 8, !tbaa !7
  %.fca.1.gep167 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep167, align 8, !tbaa !7
  %.fca.2.gep169 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep169, align 8, !tbaa !7
  %.fca.3.gep171 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep171, align 4, !tbaa !7
  %.fca.4.gep173 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep173, align 1, !tbaa !7
  %.fca.5.gep175 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep175, align 2, !tbaa !7
  %.fca.6.gep177 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep177, align 1, !tbaa !7
  %.fca.7.0.0.gep179 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep179, align 8, !tbaa !7
  %.fca.7.0.1.gep181 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack456.unpack.unpack458, ptr %.fca.7.0.1.gep181, align 8, !tbaa !7
  %.fca.7.0.2.gep183 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep183, align 8, !tbaa !7
  %23 = call i1 @_FortranAioInputDescriptor(ptr %22, ptr nonnull %1)
  %24 = call i32 @_FortranAioEndIoStatement(ptr %22)
  %25 = load i64, ptr %5, align 8, !tbaa !3
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %.lr.ph, label %.loopexit513

.lr.ph:                                           ; preds = %0
  %.unpack497 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %27 = load i64, ptr %3, align 8, !tbaa !3
  br label %28

28:                                               ; preds = %.lr.ph, %36
  %.0533 = phi i64 [ 0, %.lr.ph ], [ %32, %36 ]
  %.0397532 = phi i64 [ undef, %.lr.ph ], [ %spec.select509, %36 ]
  %.0401531 = phi i64 [ 1, %.lr.ph ], [ %38, %36 ]
  %.0406530 = phi i64 [ undef, %.lr.ph ], [ %spec.select, %36 ]
  %29 = add i64 %.0401531, -1
  %30 = getelementptr i64, ptr %.unpack497, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !3
  %32 = add i64 %31, %.0533
  %33 = icmp sgt i64 %32, %27
  br i1 %33, label %34, label %36

34:                                               ; preds = %28
  %35 = add i64 %.0401531, -1
  br label %.loopexit513

36:                                               ; preds = %28
  %37 = icmp eq i64 %.0401531, %25
  %spec.select = select i1 %37, i64 %25, i64 %.0406530
  %spec.select509 = select i1 %37, i64 %25, i64 %.0397532
  %38 = add nuw i64 %.0401531, 1
  %exitcond.not = icmp eq i64 %.0401531, %25
  br i1 %exitcond.not, label %.loopexit513, label %28

.loopexit513:                                     ; preds = %36, %0, %34
  %.0525 = phi i64 [ %.0533, %34 ], [ 0, %0 ], [ %32, %36 ]
  %.2408 = phi i64 [ %35, %34 ], [ undef, %0 ], [ %spec.select, %36 ]
  %.2399 = phi i64 [ %35, %34 ], [ undef, %0 ], [ %spec.select509, %36 ]
  %39 = load i64, ptr %4, align 8, !tbaa !3
  %40 = icmp sgt i64 %39, 0
  br i1 %40, label %.lr.ph540, label %.loopexit512

.lr.ph540:                                        ; preds = %.loopexit513
  %.unpack485 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %41 = load i64, ptr %3, align 8, !tbaa !3
  %42 = add i64 %.2408, %39
  br label %43

43:                                               ; preds = %.lr.ph540, %51
  %.2539 = phi i64 [ %.0525, %.lr.ph540 ], [ %47, %51 ]
  %.1402538 = phi i64 [ 1, %.lr.ph540 ], [ %53, %51 ]
  %.3409537 = phi i64 [ %.2408, %.lr.ph540 ], [ %52, %51 ]
  %44 = add i64 %.1402538, -1
  %45 = getelementptr i64, ptr %.unpack485, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !3
  %47 = add i64 %46, %.2539
  %48 = icmp sgt i64 %47, %41
  br i1 %48, label %49, label %51

49:                                               ; preds = %43
  %50 = add i64 %.1402538, -1
  br label %.loopexit512

51:                                               ; preds = %43
  %52 = add i64 %.3409537, 1
  %53 = add nuw i64 %.1402538, 1
  %exitcond571.not = icmp eq i64 %.1402538, %39
  br i1 %exitcond571.not, label %.loopexit512, label %43

.loopexit512:                                     ; preds = %51, %.loopexit513, %49
  %.3409523 = phi i64 [ %.3409537, %49 ], [ %.2408, %.loopexit513 ], [ %42, %51 ]
  %.2520 = phi i64 [ %.2539, %49 ], [ %.0525, %.loopexit513 ], [ %47, %51 ]
  %.0394 = phi i64 [ %50, %49 ], [ undef, %.loopexit513 ], [ undef, %51 ]
  %54 = add i64 %39, %25
  %55 = icmp eq i64 %.3409523, %54
  br i1 %55, label %58, label %.preheader

.preheader:                                       ; preds = %.loopexit512
  %56 = icmp sgt i64 %.2399, 0
  br i1 %56, label %.lr.ph556, label %._crit_edge

.lr.ph556:                                        ; preds = %.preheader
  %.unpack461 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack473 = load ptr, ptr @_QFEb.0, align 8
  %57 = load i64, ptr %3, align 8
  br label %61

58:                                               ; preds = %.loopexit512
  %59 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.f006d2ee892e3092392ef30fb28dd54e, i32 43)
  %60 = call i1 @_FortranAioOutputInteger64(ptr %59, i64 %.3409523)
  br label %80

61:                                               ; preds = %.lr.ph556, %.loopexit
  %.4555 = phi i64 [ %.2520, %.lr.ph556 ], [ %.5515, %.loopexit ]
  %.1395554 = phi i64 [ %.0394, %.lr.ph556 ], [ %.2396, %.loopexit ]
  %.2403553 = phi i64 [ 0, %.lr.ph556 ], [ %77, %.loopexit ]
  %.0404552 = phi i64 [ %.3409523, %.lr.ph556 ], [ %spec.select510, %.loopexit ]
  %.4410551 = phi i64 [ %.3409523, %.lr.ph556 ], [ %.5411518, %.loopexit ]
  %.neg = xor i64 %.2403553, -1
  %62 = add i64 %.2399, %.neg
  %63 = getelementptr i64, ptr %.unpack461, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !3
  %65 = sub i64 %.4555, %64
  %66 = add i64 %.4410551, -1
  %67 = sub i64 %39, %.1395554
  %68 = icmp sgt i64 %67, 0
  br i1 %68, label %.lr.ph547, label %.loopexit

.lr.ph547:                                        ; preds = %61, %73
  %.5546 = phi i64 [ %71, %73 ], [ %65, %61 ]
  %.0400545.in = phi i64 [ %.0400545, %73 ], [ %.1395554, %61 ]
  %.5411544 = phi i64 [ %74, %73 ], [ %66, %61 ]
  %.0415543 = phi i64 [ %75, %73 ], [ %67, %61 ]
  %69 = getelementptr i64, ptr %.unpack473, i64 %.0400545.in
  %70 = load i64, ptr %69, align 8, !tbaa !3
  %71 = add i64 %70, %.5546
  %72 = icmp sgt i64 %71, %57
  br i1 %72, label %.loopexit, label %73

73:                                               ; preds = %.lr.ph547
  %.0400545 = add i64 %.0400545.in, 1
  %74 = add i64 %.5411544, 1
  %75 = add nsw i64 %.0415543, -1
  %76 = icmp sgt i64 %.0415543, 1
  br i1 %76, label %.lr.ph547, label %.loopexit

.loopexit:                                        ; preds = %73, %.lr.ph547, %61
  %.5411518 = phi i64 [ %66, %61 ], [ %74, %73 ], [ %.5411544, %.lr.ph547 ]
  %.5515 = phi i64 [ %65, %61 ], [ %71, %73 ], [ %.5546, %.lr.ph547 ]
  %.2396 = phi i64 [ %.1395554, %61 ], [ %.1395554, %73 ], [ %.0400545.in, %.lr.ph547 ]
  %spec.select510 = call i64 @llvm.smax.i64(i64 %.5411518, i64 %.0404552)
  %77 = add nuw i64 %.2403553, 1
  %exitcond572.not = icmp eq i64 %77, %.2399
  br i1 %exitcond572.not, label %._crit_edge, label %61

._crit_edge:                                      ; preds = %.loopexit, %.preheader
  %.0404.lcssa = phi i64 [ %.3409523, %.preheader ], [ %spec.select510, %.loopexit ]
  %78 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.f006d2ee892e3092392ef30fb28dd54e, i32 62)
  %79 = call i1 @_FortranAioOutputInteger64(ptr %78, i64 %.0404.lcssa)
  br label %80

80:                                               ; preds = %58, %._crit_edge
  %.sink = phi ptr [ %59, %58 ], [ %78, %._crit_edge ]
  %81 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #1

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
