program Frog_2
    implicit none
    integer(4):: n,k
    integer(4):: i,j
    integer(4),parameter:: inf=200000*10000+1
    integer(4), allocatable:: h(:), dp(:)


    read*, n,k
    allocate(h(n), dp(n))

    read*, h(:)
    dp(:) = inf
    dp(1) = 0
    do i=1,n
        do j=1,k
            if (i+j > n) cycle
            dp(i+j) = min(dp(i+j), dp(i) + abs(h(i)-h(i+j)))
        end do
    end do

    print*, dp(n)

end program Frog_2
; 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.8 = internal unnamed_addr global i64 0
@_QFEh.0 = internal unnamed_addr global ptr null
@_QFEh.8 = internal unnamed_addr global i64 0
@_QQcl.c1ee099e4830a820bf2ebdde49bda89d = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5160/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 i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c1ee099e4830a820bf2ebdde49bda89d, i32 9)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %3, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEh.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEh.8, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %11)
  store ptr %13, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEdp.8, align 8, !tbaa !7
  %14 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c1ee099e4830a820bf2ebdde49bda89d, i32 12)
  %.unpack = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %.unpack260.unpack.unpack262 = load i64, ptr @_QFEh.8, align 8, !tbaa !7
  %15 = call i64 @llvm.smax.i64(i64 %.unpack260.unpack.unpack262, i64 0)
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, 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 %1, 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 %1, 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 %1, i64 0, i32 4
  store i8 9, 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 %1, 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 %1, 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 %1, 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 %1, i64 0, i32 7, i64 0, i64 1
  store i64 %15, 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 %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %16 = call i1 @_FortranAioInputDescriptor(ptr %14, ptr nonnull %1)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %14)
  %.unpack265 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack272.unpack.unpack274 = load i64, ptr @_QFEdp.8, align 8, !tbaa !7
  %18 = call i64 @llvm.smax.i64(i64 %.unpack272.unpack.unpack274, i64 0)
  %.not331 = icmp slt i64 %.unpack272.unpack.unpack274, 1
  br i1 %.not331, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %min.iters.check = icmp ult i64 %18, 8
  br i1 %min.iters.check, label %.lr.ph.preheader338, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %18, 9223372036854775800
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %19 = getelementptr i32, ptr %.unpack265, i64 %index
  store <4 x i32> <i32 2000000001, i32 2000000001, i32 2000000001, i32 2000000001>, ptr %19, align 4, !tbaa !3
  %20 = getelementptr i32, ptr %19, i64 4
  store <4 x i32> <i32 2000000001, i32 2000000001, i32 2000000001, i32 2000000001>, ptr %20, align 4, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %18, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader338

.lr.ph.preheader338:                              ; preds = %.lr.ph.preheader, %middle.block
  %.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader338, %.lr.ph
  %22 = phi i64 [ %24, %.lr.ph ], [ %.ph, %.lr.ph.preheader338 ]
  %23 = getelementptr i32, ptr %.unpack265, i64 %22
  store i32 2000000001, ptr %23, align 4, !tbaa !3
  %24 = add nuw nsw i64 %22, 1
  %exitcond.not = icmp eq i64 %24, %18
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %0
  store i32 0, ptr %.unpack265, align 4, !tbaa !3
  %25 = load i32, ptr %3, align 4, !tbaa !3
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph329, label %._crit_edge330

.lr.ph329:                                        ; preds = %._crit_edge
  %27 = zext i32 %25 to i64
  %.unpack313 = load ptr, ptr @_QFEh.0, align 8
  br label %28

28:                                               ; preds = %.lr.ph329, %._crit_edge327
  %indvars.iv334 = phi i64 [ 1, %.lr.ph329 ], [ %indvars.iv.next335, %._crit_edge327 ]
  %29 = load i32, ptr %2, align 4, !tbaa !3
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph326, label %._crit_edge327

.lr.ph326:                                        ; preds = %28
  %31 = zext i32 %29 to i64
  %32 = add nsw i64 %indvars.iv334, -1
  %33 = getelementptr i32, ptr %.unpack265, i64 %32
  %34 = add nsw i64 %indvars.iv334, -1
  %35 = getelementptr i32, ptr %.unpack313, i64 %34
  br label %36

36:                                               ; preds = %.lr.ph326, %54
  %indvars.iv = phi i64 [ 1, %.lr.ph326 ], [ %indvars.iv.next, %54 ]
  %37 = add nuw nsw i64 %indvars.iv, %indvars.iv334
  %38 = load i32, ptr %3, align 4, !tbaa !3
  %39 = trunc i64 %37 to i32
  %.not = icmp slt i32 %38, %39
  br i1 %.not, label %54, label %40

40:                                               ; preds = %36
  %sext = shl i64 %37, 32
  %41 = ashr exact i64 %sext, 32
  %42 = add nsw i64 %41, -1
  %43 = getelementptr i32, ptr %.unpack265, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !3
  %45 = load i32, ptr %33, align 4, !tbaa !3
  %46 = load i32, ptr %35, align 4, !tbaa !3
  %47 = add nsw i64 %41, -1
  %48 = getelementptr i32, ptr %.unpack313, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !3
  %50 = sub i32 %46, %49
  %51 = call i32 @llvm.abs.i32(i32 %50, i1 false)
  %52 = add i32 %51, %45
  %53 = call i32 @llvm.smin.i32(i32 %44, i32 %52)
  store i32 %53, ptr %43, align 4, !tbaa !3
  br label %54

54:                                               ; preds = %40, %36
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond333.not = icmp eq i64 %indvars.iv, %31
  br i1 %exitcond333.not, label %._crit_edge327, label %36

._crit_edge327:                                   ; preds = %54, %28
  %indvars.iv.next335 = add nuw nsw i64 %indvars.iv334, 1
  %exitcond337.not = icmp eq i64 %indvars.iv334, %27
  br i1 %exitcond337.not, label %._crit_edge330, label %28

._crit_edge330:                                   ; preds = %._crit_edge327, %._crit_edge
  %55 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.c1ee099e4830a820bf2ebdde49bda89d, i32 22)
  %.unpack289 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %56 = load i32, ptr %3, align 4, !tbaa !3
  %57 = sext i32 %56 to i64
  %58 = add nsw i64 %57, -1
  %59 = getelementptr i32, ptr %.unpack289, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !3
  %61 = call i1 @_FortranAioOutputInteger32(ptr %55, i32 %60)
  %62 = call i32 @_FortranAioEndIoStatement(ptr %55)
  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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
