program atcoder
    implicit none
    integer(8) :: i,j,n,maxw
    integer(8),allocatable,dimension(:,:) :: dp
    integer(8),allocatable,dimension(:) :: v,w
    read*,n,maxw
    allocate(dp(0:n,0:maxw))
    allocate(v(n))
    allocate(w(n))

    dp = 0
    do i = 1,n
        read*,w(i),v(i)
    enddo

    do i = 0,n-1
        do j = 0,maxw
            if( j<w(i+1) )then
                dp(i+1,j) = dp(i,j)
            else
                dp(i+1,j) = max( dp(i,j) , dp(i,j-w(i+1))+v(i+1) )
            endif
        enddo
    enddo
    write(*,'(I0)')dp(n,maxw)

    stop 
contains
end program atcoder

; 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"

@_QFEdp.0 = internal unnamed_addr global ptr null
@_QFEdp.7 = internal unnamed_addr global i64 1
@_QFEdp.8 = internal unnamed_addr global i64 0
@_QFEdp.10 = internal unnamed_addr global i64 1
@_QFEv.0 = internal unnamed_addr global ptr null
@_QFEw.0 = internal unnamed_addr global ptr null
@_QQcl.597b2550e2ded78ce633ad40855c4b69 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5181/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.597b2550e2ded78ce633ad40855c4b69, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i64, ptr %2, align 8, !tbaa !3
  %8 = add i64 %7, 1
  %9 = load i64, ptr %1, align 8, !tbaa !3
  %10 = add i64 %9, 1
  %11 = call i64 @llvm.smax.i64(i64 %8, i64 0)
  %12 = call i64 @llvm.smax.i64(i64 %10, i64 0)
  %13 = shl i64 %11, 3
  %14 = mul i64 %13, %12
  %15 = call ptr @malloc(i64 %14)
  %16 = icmp ugt i64 %7, 9223372036854775806
  %17 = zext i1 %16 to i64
  %18 = icmp ugt i64 %9, 9223372036854775806
  %19 = zext i1 %18 to i64
  store ptr %15, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %17, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %11, ptr @_QFEdp.8, align 8, !tbaa !7
  store i64 %19, ptr @_QFEdp.10, align 8, !tbaa !7
  %20 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %21 = shl i64 %20, 3
  %22 = call ptr @malloc(i64 %21)
  store ptr %22, ptr @_QFEv.0, align 8, !tbaa !7
  %23 = call ptr @malloc(i64 %21)
  store ptr %23, ptr @_QFEw.0, align 8, !tbaa !7
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %28, label %.preheader557

.preheader557:                                    ; preds = %0
  %brmerge = select i1 %18, i1 true, i1 %16
  br i1 %brmerge, label %._crit_edge558, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader557
  %24 = call i64 @llvm.smin.i64(i64 %12, i64 1)
  %smin568 = add nuw nsw i64 %24, 2305843009213693951
  %25 = sub nsw i64 %12, %smin568
  %26 = mul i64 %8, %25
  %27 = shl i64 %26, 3
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %15, i8 0, i64 %27, i1 false), !tbaa !3
  br label %._crit_edge558

28:                                               ; preds = %0
  %29 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.597b2550e2ded78ce633ad40855c4b69, i32 11)
  %.pre.pre = load i64, ptr %2, align 8, !tbaa !3
  %.unpack535.unpack536.unpack.pre = load i64, ptr @_QFEdp.10, align 8, !tbaa !7
  %.unpack535.unpack.unpack.pre = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %30 = select i1 %16, i64 1, i64 %.unpack535.unpack.unpack.pre
  %31 = select i1 %18, i64 1, i64 %.unpack535.unpack536.unpack.pre
  store ptr %15, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %30, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %11, ptr @_QFEdp.8, align 8, !tbaa !7
  store i64 %31, ptr @_QFEdp.10, align 8, !tbaa !7
  br label %._crit_edge558

._crit_edge558:                                   ; preds = %.preheader557, %.preheader.us.preheader, %28
  %32 = phi i64 [ %.pre.pre, %28 ], [ %7, %.preheader.us.preheader ], [ %7, %.preheader557 ]
  %33 = icmp sgt i64 %32, 0
  br i1 %33, label %.lr.ph, label %._crit_edge564

.lr.ph:                                           ; preds = %._crit_edge558, %.lr.ph
  %34 = phi i64 [ %43, %.lr.ph ], [ 1, %._crit_edge558 ]
  %35 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.597b2550e2ded78ce633ad40855c4b69, i32 13)
  %.unpack504 = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %36 = add i64 %34, -1
  %37 = getelementptr i64, ptr %.unpack504, i64 %36
  %38 = call i1 @_FortranAioInputInteger(ptr %35, ptr %37, i32 8)
  %.unpack516 = load ptr, ptr @_QFEv.0, align 8, !tbaa !7
  %39 = add i64 %34, -1
  %40 = getelementptr i64, ptr %.unpack516, i64 %39
  %41 = call i1 @_FortranAioInputInteger(ptr %35, ptr %40, i32 8)
  %42 = call i32 @_FortranAioEndIoStatement(ptr %35)
  %43 = add nuw i64 %34, 1
  %exitcond.not = icmp eq i64 %34, %32
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.pre572 = load i64, ptr %2, align 8, !tbaa !3
  %44 = icmp sgt i64 %.pre572, 0
  br i1 %44, label %.lr.ph563, label %._crit_edge564

.lr.ph563:                                        ; preds = %._crit_edge
  %.unpack448 = load ptr, ptr @_QFEw.0, align 8
  %.unpack460 = load ptr, ptr @_QFEdp.0, align 8
  %.unpack467.unpack.unpack = load i64, ptr @_QFEdp.7, align 8
  %.unpack467.unpack.unpack470 = load i64, ptr @_QFEdp.8, align 8
  %.unpack467.unpack468.unpack = load i64, ptr @_QFEdp.10, align 8
  %.unpack476 = load ptr, ptr @_QFEv.0, align 8
  br label %45

45:                                               ; preds = %.lr.ph563, %._crit_edge561
  %46 = phi i64 [ 0, %.lr.ph563 ], [ %.pre-phi, %._crit_edge561 ]
  %47 = load i64, ptr %1, align 8, !tbaa !3
  %48 = icmp ult i64 %47, 9223372036854775807
  br i1 %48, label %.lr.ph560, label %.._crit_edge561_crit_edge

.._crit_edge561_crit_edge:                        ; preds = %45
  %.pre574 = add nuw i64 %46, 1
  br label %._crit_edge561

.lr.ph560:                                        ; preds = %45
  %49 = add nuw nsw i64 %47, 1
  %50 = add nuw i64 %46, 1
  %51 = getelementptr i64, ptr %.unpack448, i64 %46
  %52 = sub i64 %46, %.unpack467.unpack.unpack
  %53 = getelementptr i64, ptr %.unpack476, i64 %46
  %54 = sub i64 %50, %.unpack467.unpack.unpack
  br label %55

55:                                               ; preds = %.lr.ph560, %79
  %56 = phi i64 [ %49, %.lr.ph560 ], [ %83, %79 ]
  %57 = phi i64 [ 0, %.lr.ph560 ], [ %82, %79 ]
  %58 = load i64, ptr %51, align 8, !tbaa !3
  %59 = icmp slt i64 %57, %58
  %60 = sub i64 %57, %.unpack467.unpack468.unpack
  %61 = mul i64 %60, %.unpack467.unpack.unpack470
  br i1 %59, label %62, label %66

62:                                               ; preds = %55
  %63 = add i64 %52, %61
  %64 = getelementptr i64, ptr %.unpack460, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !3
  br label %79

66:                                               ; preds = %55
  %67 = add i64 %61, %52
  %68 = getelementptr i64, ptr %.unpack460, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !3
  %70 = add i64 %58, %.unpack467.unpack468.unpack
  %71 = sub i64 %57, %70
  %72 = mul i64 %71, %.unpack467.unpack.unpack470
  %73 = add i64 %72, %52
  %74 = getelementptr i64, ptr %.unpack460, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !3
  %76 = load i64, ptr %53, align 8, !tbaa !3
  %77 = add i64 %76, %75
  %78 = call i64 @llvm.smax.i64(i64 %69, i64 %77)
  br label %79

79:                                               ; preds = %62, %66
  %.sink = phi i64 [ %65, %62 ], [ %78, %66 ]
  %80 = add i64 %54, %61
  %81 = getelementptr i64, ptr %.unpack460, i64 %80
  store i64 %.sink, ptr %81, align 8, !tbaa !3
  %82 = add nuw nsw i64 %57, 1
  %83 = add nsw i64 %56, -1
  %84 = icmp sgt i64 %56, 1
  br i1 %84, label %55, label %._crit_edge561

._crit_edge561:                                   ; preds = %79, %.._crit_edge561_crit_edge
  %.pre-phi = phi i64 [ %.pre574, %.._crit_edge561_crit_edge ], [ %50, %79 ]
  %exitcond569.not = icmp eq i64 %.pre-phi, %.pre572
  br i1 %exitcond569.not, label %._crit_edge564, label %45

._crit_edge564:                                   ; preds = %._crit_edge561, %._crit_edge558, %._crit_edge
  %85 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.597b2550e2ded78ce633ad40855c4b69, i32 25)
  %.unpack432 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack439.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %.unpack439.unpack.unpack442 = load i64, ptr @_QFEdp.8, align 8, !tbaa !7
  %.unpack439.unpack440.unpack = load i64, ptr @_QFEdp.10, align 8, !tbaa !7
  %86 = load i64, ptr %2, align 8, !tbaa !3
  %87 = sub i64 %86, %.unpack439.unpack.unpack
  %88 = load i64, ptr %1, align 8, !tbaa !3
  %89 = sub i64 %88, %.unpack439.unpack440.unpack
  %90 = mul i64 %89, %.unpack439.unpack.unpack442
  %91 = add i64 %87, %90
  %92 = getelementptr i64, ptr %.unpack432, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !3
  %94 = call i1 @_FortranAioOutputInteger64(ptr %85, i64 %93)
  %95 = call i32 @_FortranAioEndIoStatement(ptr %85)
  %96 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

!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}
