program EDPCB
    implicit none
    integer(8)::N,K,i,j
    integer(8),allocatable,dimension(:)::H,dp
    read(5,*)N,K
    allocate(H(N))
    allocate(dp(N))
    read(5,*)(H(i),i=1,N)

    dp=0

    do j=2,N
        do i=1,K
            if(j>i)then
                if(i==1)then
                    dp(j)=dp(j-1)+abs(H(j)-H(j-1))
                else
                    dp(j)=min(dp(j),dp(j-i)+abs(H(j)-H(j-i)))
                end if
            else
                exit
            end if
        end do
    end do

    print'(i0)',dp(N)
end program EDPCB
; 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
@_QFEh.0 = internal unnamed_addr global ptr null
@_QQcl.e0b7bfe0c9884f48f678df5657bb3782 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5164/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.28693029 = 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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.e0b7bfe0c9884f48f678df5657bb3782, i32 5)
  %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 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 3
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEh.0, align 8, !tbaa !7
  %11 = call ptr @malloc(i64 %9)
  store ptr %11, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %8, ptr @_QFEdp.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.e0b7bfe0c9884f48f678df5657bb3782, i32 8)
  %13 = load i64, ptr %2, align 8, !tbaa !3
  %14 = icmp sgt i64 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %15 = phi i64 [ %19, %.lr.ph ], [ 1, %0 ]
  %.unpack375 = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %16 = add i64 %15, -1
  %17 = getelementptr i64, ptr %.unpack375, i64 %16
  %18 = call i1 @_FortranAioInputInteger(ptr %12, ptr %17, i32 8)
  %19 = add nuw i64 %15, 1
  %exitcond.not = icmp eq i64 %15, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %20 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %.unpack = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack289.unpack.unpack291 = load i64, ptr @_QFEdp.8, align 8, !tbaa !7
  %.not = icmp eq ptr %.unpack, null
  br i1 %.not, label %23, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %21 = icmp sgt i64 %.unpack289.unpack.unpack291, 0
  br i1 %21, label %.lr.ph387.preheader, label %.loopexit

.lr.ph387.preheader:                              ; preds = %.preheader
  %22 = shl nuw i64 %.unpack289.unpack.unpack291, 3
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %.unpack, i8 0, i64 %22, i1 false), !tbaa !3
  br label %.loopexit

23:                                               ; preds = %._crit_edge
  %24 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.e0b7bfe0c9884f48f678df5657bb3782, i32 10)
  %.unpack361.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %25 = icmp eq i64 %.unpack289.unpack.unpack291, 0
  %26 = select i1 %25, i64 1, i64 %.unpack361.unpack.unpack
  store ptr null, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %26, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %.unpack289.unpack.unpack291, ptr @_QFEdp.8, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph387.preheader, %.preheader, %23
  %27 = load i64, ptr %2, align 8, !tbaa !3
  %.0261394 = add i64 %27, -1
  %28 = icmp sgt i64 %.0261394, 0
  br i1 %28, label %.lr.ph398, label %._crit_edge399

.lr.ph398:                                        ; preds = %.loopexit
  %.unpack313.unpack.unpack = load i64, ptr @_QFEdp.7, align 8
  %.unpack318 = load ptr, ptr @_QFEh.0, align 8
  %29 = xor i64 %.unpack313.unpack.unpack, -1
  br label %30

30:                                               ; preds = %.lr.ph398, %._crit_edge393
  %indvars.iv = phi i64 [ 0, %.lr.ph398 ], [ %indvars.iv.next, %._crit_edge393 ]
  %.0395 = phi i64 [ 2, %.lr.ph398 ], [ %66, %._crit_edge393 ]
  %31 = load i64, ptr %1, align 8, !tbaa !3
  %32 = icmp sgt i64 %31, 0
  %33 = icmp sgt i64 %.0395, 1
  %or.cond388 = select i1 %32, i1 %33, i1 false
  br i1 %or.cond388, label %34, label %._crit_edge393

34:                                               ; preds = %30
  %35 = sub i64 %.0395, %.unpack313.unpack.unpack
  %36 = getelementptr i64, ptr %.unpack, i64 %35
  %37 = add i64 %.0395, -1
  %38 = getelementptr i64, ptr %.unpack318, i64 %37
  %39 = add nsw i64 %31, -1
  %umin = call i64 @llvm.umin.i64(i64 %indvars.iv, i64 %39)
  %40 = add i64 %.0395, -2
  %41 = getelementptr i64, ptr %.unpack318, i64 %40
  %42 = add i64 %.0395, %29
  %43 = getelementptr i64, ptr %.unpack, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !3
  %45 = load i64, ptr %38, align 8, !tbaa !3
  %46 = load i64, ptr %41, align 8, !tbaa !3
  %47 = sub i64 %45, %46
  %48 = call i64 @llvm.abs.i64(i64 %47, i1 false)
  %49 = add i64 %48, %44
  store i64 %49, ptr %36, align 8, !tbaa !3
  %exitcond400.peel.not = icmp eq i64 %umin, 0
  br i1 %exitcond400.peel.not, label %._crit_edge393, label %.peel.next

.peel.next:                                       ; preds = %34
  %50 = add nuw i64 %umin, 1
  br label %51

51:                                               ; preds = %.peel.next, %51
  %52 = phi i64 [ %49, %.peel.next ], [ %64, %51 ]
  %.0260390 = phi i64 [ 2, %.peel.next ], [ %65, %51 ]
  %53 = sub i64 %.0395, %.0260390
  %54 = sub i64 %53, %.unpack313.unpack.unpack
  %55 = getelementptr i64, ptr %.unpack, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !3
  %57 = load i64, ptr %38, align 8, !tbaa !3
  %58 = add i64 %53, -1
  %59 = getelementptr i64, ptr %.unpack318, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !3
  %61 = sub i64 %57, %60
  %62 = call i64 @llvm.abs.i64(i64 %61, i1 false)
  %63 = add i64 %62, %56
  %64 = call i64 @llvm.smin.i64(i64 %52, i64 %63)
  store i64 %64, ptr %36, align 8, !tbaa !3
  %65 = add nuw nsw i64 %.0260390, 1
  %exitcond400.not = icmp eq i64 %.0260390, %50
  br i1 %exitcond400.not, label %._crit_edge393, label %51, !llvm.loop !9

._crit_edge393:                                   ; preds = %51, %34, %30
  %66 = add nuw i64 %.0395, 1
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond402.not = icmp eq i64 %indvars.iv.next, %.0261394
  br i1 %exitcond402.not, label %._crit_edge399, label %30

._crit_edge399:                                   ; preds = %._crit_edge393, %.loopexit
  %67 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e0b7bfe0c9884f48f678df5657bb3782, i32 26)
  %.unpack294 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack301.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %68 = load i64, ptr %2, align 8, !tbaa !3
  %69 = sub i64 %68, %.unpack301.unpack.unpack
  %70 = getelementptr i64, ptr %.unpack294, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !3
  %72 = call i1 @_FortranAioOutputInteger64(ptr %67, i64 %71)
  %73 = call i32 @_FortranAioEndIoStatement(ptr %67)
  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 {} @_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

; 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 i64 @llvm.abs.i64(i64, i1 immarg) #1

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.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) }
attributes #2 = { 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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.peeled.count", i32 1}
