program tsundoku
  implicit none
  integer :: n, m, h = 0, i, j
  integer(8) :: k
  integer(8), dimension(0:200001) :: a = 0, b = 0, x = 0, y = 0
  read(*,*) n, m, k
  read(*,*) a(1:n)
  read(*,*) b(1:m)
  do i = 1, n
    x(i) = x(i - 1) + a(i)
  end do
  do i = 1, m
    y(i) = y(i - 1) + b(i)
  end do
  j = m
  do i = 0, n
    if (x(i) > k) exit
    do while (y(j) > k - x(i))
      j = j - 1
    end do
    h = max(h, i + j)
  end do
  write(*,'(i0)') h
end program tsundoku
; 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 = internal global [200002 x i64] zeroinitializer
@_QFEb = internal global [200002 x i64] zeroinitializer
@_QFEh = internal unnamed_addr global i32 0
@_QFEx = internal unnamed_addr global [200002 x i64] zeroinitializer
@_QFEy = internal unnamed_addr global [200002 x i64] zeroinitializer
@_QQcl.53d8f2d01982226c4b424c2b62b6aa34 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1075/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

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 i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.53d8f2d01982226c4b424c2b62b6aa34, i32 6)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %9 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %3, i32 8)
  %10 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.53d8f2d01982226c4b424c2b62b6aa34, i32 7)
  %12 = load i32, ptr %5, align 4, !tbaa !3
  %13 = call i32 @llvm.smax.i32(i32 %12, i32 0)
  %14 = zext i32 %13 to i64
  store ptr getelementptr inbounds ([200002 x i64], ptr @_QFEa, i64 0, i64 1), 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 %14, 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
  %15 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %2)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.53d8f2d01982226c4b424c2b62b6aa34, i32 8)
  %18 = load i32, ptr %4, align 4, !tbaa !3
  %19 = call i32 @llvm.smax.i32(i32 %18, i32 0)
  %20 = zext i32 %19 to i64
  store ptr getelementptr inbounds ([200002 x i64], ptr @_QFEb, i64 0, i64 1), ptr %1, align 8, !tbaa !7
  %.fca.1.gep16 = 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.gep16, align 8, !tbaa !7
  %.fca.2.gep18 = 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.gep18, align 8, !tbaa !7
  %.fca.3.gep20 = 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.gep20, align 4, !tbaa !7
  %.fca.4.gep22 = 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.gep22, align 1, !tbaa !7
  %.fca.5.gep24 = 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.gep24, align 2, !tbaa !7
  %.fca.6.gep26 = 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.gep26, align 1, !tbaa !7
  %.fca.7.0.0.gep28 = 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.gep28, align 8, !tbaa !7
  %.fca.7.0.1.gep30 = 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 %20, ptr %.fca.7.0.1.gep30, align 8, !tbaa !7
  %.fca.7.0.2.gep32 = 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.gep32, align 8, !tbaa !7
  %21 = call i1 @_FortranAioInputDescriptor(ptr %17, ptr nonnull %1)
  %22 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %23 = load i32, ptr %5, align 4, !tbaa !3
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %25 = zext i32 %23 to i64
  %.pre = load i64, ptr @_QFEx, align 16, !tbaa !3
  %xtraiter = and i64 %25, 1
  %26 = icmp eq i32 %23, 1
  br i1 %26, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %25, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %27 = phi i64 [ %.pre, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %28 = getelementptr [200002 x i64], ptr @_QFEa, i64 0, i64 %indvars.iv
  %29 = load i64, ptr %28, align 8, !tbaa !3
  %30 = add i64 %29, %27
  %31 = getelementptr [200002 x i64], ptr @_QFEx, i64 0, i64 %indvars.iv
  store i64 %30, ptr %31, align 8, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = getelementptr [200002 x i64], ptr @_QFEa, i64 0, i64 %indvars.iv.next
  %33 = load i64, ptr %32, align 8, !tbaa !3
  %34 = add i64 %33, %30
  %35 = getelementptr [200002 x i64], ptr @_QFEx, i64 0, i64 %indvars.iv.next
  store i64 %34, ptr %35, align 8, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi i64 [ %.pre, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %36 = getelementptr [200002 x i64], ptr @_QFEa, i64 0, i64 %indvars.iv.unr
  %37 = load i64, ptr %36, align 8, !tbaa !3
  %38 = add i64 %37, %.unr
  %39 = getelementptr [200002 x i64], ptr @_QFEx, i64 0, i64 %indvars.iv.unr
  store i64 %38, ptr %39, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %0
  %40 = load i32, ptr %4, align 4, !tbaa !3
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %.lr.ph38.preheader, label %._crit_edge39

.lr.ph38.preheader:                               ; preds = %._crit_edge
  %42 = zext i32 %40 to i64
  %.pre56 = load i64, ptr @_QFEy, align 16, !tbaa !3
  %xtraiter57 = and i64 %42, 1
  %43 = icmp eq i32 %40, 1
  br i1 %43, label %._crit_edge39.loopexit.unr-lcssa, label %.lr.ph38.preheader.new

.lr.ph38.preheader.new:                           ; preds = %.lr.ph38.preheader
  %unroll_iter60 = and i64 %42, 4294967294
  br label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph38, %.lr.ph38.preheader.new
  %44 = phi i64 [ %.pre56, %.lr.ph38.preheader.new ], [ %51, %.lr.ph38 ]
  %indvars.iv48 = phi i64 [ 1, %.lr.ph38.preheader.new ], [ %indvars.iv.next49.1, %.lr.ph38 ]
  %niter61 = phi i64 [ 0, %.lr.ph38.preheader.new ], [ %niter61.next.1, %.lr.ph38 ]
  %45 = getelementptr [200002 x i64], ptr @_QFEb, i64 0, i64 %indvars.iv48
  %46 = load i64, ptr %45, align 8, !tbaa !3
  %47 = add i64 %46, %44
  %48 = getelementptr [200002 x i64], ptr @_QFEy, i64 0, i64 %indvars.iv48
  store i64 %47, ptr %48, align 8, !tbaa !3
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %49 = getelementptr [200002 x i64], ptr @_QFEb, i64 0, i64 %indvars.iv.next49
  %50 = load i64, ptr %49, align 8, !tbaa !3
  %51 = add i64 %50, %47
  %52 = getelementptr [200002 x i64], ptr @_QFEy, i64 0, i64 %indvars.iv.next49
  store i64 %51, ptr %52, align 8, !tbaa !3
  %indvars.iv.next49.1 = add nuw nsw i64 %indvars.iv48, 2
  %niter61.next.1 = add i64 %niter61, 2
  %niter61.ncmp.1 = icmp eq i64 %niter61.next.1, %unroll_iter60
  br i1 %niter61.ncmp.1, label %._crit_edge39.loopexit.unr-lcssa, label %.lr.ph38

._crit_edge39.loopexit.unr-lcssa:                 ; preds = %.lr.ph38, %.lr.ph38.preheader
  %.unr58 = phi i64 [ %.pre56, %.lr.ph38.preheader ], [ %51, %.lr.ph38 ]
  %indvars.iv48.unr = phi i64 [ 1, %.lr.ph38.preheader ], [ %indvars.iv.next49.1, %.lr.ph38 ]
  %lcmp.mod59.not = icmp eq i64 %xtraiter57, 0
  br i1 %lcmp.mod59.not, label %._crit_edge39, label %.lr.ph38.epil

.lr.ph38.epil:                                    ; preds = %._crit_edge39.loopexit.unr-lcssa
  %53 = getelementptr [200002 x i64], ptr @_QFEb, i64 0, i64 %indvars.iv48.unr
  %54 = load i64, ptr %53, align 8, !tbaa !3
  %55 = add i64 %54, %.unr58
  %56 = getelementptr [200002 x i64], ptr @_QFEy, i64 0, i64 %indvars.iv48.unr
  store i64 %55, ptr %56, align 8, !tbaa !3
  br label %._crit_edge39

._crit_edge39:                                    ; preds = %.lr.ph38.epil, %._crit_edge39.loopexit.unr-lcssa, %._crit_edge
  %57 = icmp ult i32 %23, 2147483647
  br i1 %57, label %.lr.ph44, label %._crit_edge45

.lr.ph44:                                         ; preds = %._crit_edge39
  %58 = add nuw nsw i32 %23, 1
  %_QFEh.promoted = load i32, ptr @_QFEh, align 4, !tbaa !3
  %59 = load i64, ptr %3, align 8, !tbaa !3
  %smin = call i32 @llvm.smin.i32(i32 %23, i32 0)
  %60 = sub nuw nsw i32 %58, %smin
  %wide.trip.count = zext i32 %60 to i64
  br label %61

61:                                               ; preds = %.lr.ph44, %73
  %indvars.iv52 = phi i64 [ 0, %.lr.ph44 ], [ %indvars.iv.next53, %73 ]
  %.042 = phi i32 [ %40, %.lr.ph44 ], [ %.1, %73 ]
  %62 = phi i32 [ %_QFEh.promoted, %.lr.ph44 ], [ %76, %73 ]
  %63 = getelementptr [200002 x i64], ptr @_QFEx, i64 0, i64 %indvars.iv52
  %64 = load i64, ptr %63, align 8, !tbaa !3
  %65 = icmp slt i64 %59, %64
  br i1 %65, label %._crit_edge45, label %.preheader

.preheader:                                       ; preds = %61
  %66 = sub i64 %59, %64
  br label %67

67:                                               ; preds = %67, %.preheader
  %.1 = phi i32 [ %72, %67 ], [ %.042, %.preheader ]
  %68 = sext i32 %.1 to i64
  %69 = getelementptr [200002 x i64], ptr @_QFEy, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !3
  %71 = icmp sgt i64 %70, %66
  %72 = add i32 %.1, -1
  br i1 %71, label %67, label %73

73:                                               ; preds = %67
  %74 = trunc i64 %indvars.iv52 to i32
  %75 = add i32 %.1, %74
  %76 = call i32 @llvm.smax.i32(i32 %62, i32 %75)
  store i32 %76, ptr @_QFEh, align 4, !tbaa !3
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count
  br i1 %exitcond55.not, label %._crit_edge45, label %61

._crit_edge45:                                    ; preds = %73, %61, %._crit_edge39
  %77 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.53d8f2d01982226c4b424c2b62b6aa34, i32 23)
  %78 = load i32, ptr @_QFEh, align 4, !tbaa !3
  %79 = call i1 @_FortranAioOutputInteger32(ptr %77, i32 %78)
  %80 = call i32 @_FortranAioEndIoStatement(ptr %77)
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #0

attributes #0 = { 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}
