implicit none
integer :: n,k
integer,allocatable :: x(:)
integer :: i,j,d,t,tmin

read *,n,k
allocate(x(n))
read *,(x(i),i=1,n)

tmin = 1000000000
j = k
do i = 1,n-k+1
   d = abs(x(j) - x(i))
   t = min(abs(x(i)) + d, abs(x(j)) + d)
   if (t < tmin) then
      tmin = t
   endif
   j = j + 1
enddo

print '(i0)',tmin
end
; 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"

@_QFEx.0 = internal unnamed_addr global ptr null
@_QQcl.40d74c8f3cc844c3bf0e5ce0acc4a833 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5609/source.f\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 i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.40d74c8f3cc844c3bf0e5ce0acc4a833, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEx.0, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.40d74c8f3cc844c3bf0e5ce0acc4a833, i32 8)
  %13 = load i32, ptr %2, align 4, !tbaa !3
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %15 = zext i32 %13 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %16 = phi i64 [ %21, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.unpack103 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %sext = shl i64 %16, 32
  %17 = ashr exact i64 %sext, 32
  %18 = add nsw i64 %17, -1
  %19 = getelementptr i32, ptr %.unpack103, i64 %18
  %20 = call i1 @_FortranAioInputInteger(ptr %12, ptr %19, i32 4)
  %21 = add nuw nsw i64 %16, 1
  %exitcond.not = icmp eq i64 %16, %15
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %22 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %23 = load i32, ptr %1, align 4, !tbaa !3
  %24 = load i32, ptr %2, align 4, !tbaa !3
  %25 = sub i32 1, %23
  %26 = add i32 %25, %24
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph118, label %._crit_edge119

.lr.ph118:                                        ; preds = %._crit_edge
  %28 = zext i32 %26 to i64
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %26, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph118
  %29 = add nsw i64 %28, -1
  %30 = trunc i64 %29 to i32
  %31 = add i32 %23, %30
  %32 = icmp slt i32 %31, %23
  %33 = icmp ugt i64 %29, 4294967295
  %34 = or i1 %32, %33
  br i1 %34, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %28, 4294967288
  %ind.end = or i64 %n.vec, 1
  %.cast = trunc i64 %n.vec to i32
  %ind.end122 = add i32 %23, %.cast
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 1000000000, i32 1000000000, i32 1000000000, i32 1000000000>, %vector.ph ], [ %55, %vector.body ]
  %vec.phi124 = phi <4 x i32> [ <i32 1000000000, i32 1000000000, i32 1000000000, i32 1000000000>, %vector.ph ], [ %56, %vector.body ]
  %.cast125 = trunc i64 %index to i32
  %offset.idx = add i32 %23, %.cast125
  %35 = sext i32 %offset.idx to i64
  %36 = add nsw i64 %35, -1
  %37 = getelementptr i32, ptr %.unpack, i64 %36
  %wide.load = load <4 x i32>, ptr %37, align 4, !tbaa !3
  %38 = getelementptr i32, ptr %37, i64 4
  %wide.load127 = load <4 x i32>, ptr %38, align 4, !tbaa !3
  %39 = getelementptr i32, ptr %.unpack, i64 %index
  %wide.load128 = load <4 x i32>, ptr %39, align 4, !tbaa !3
  %40 = getelementptr i32, ptr %39, i64 4
  %wide.load129 = load <4 x i32>, ptr %40, align 4, !tbaa !3
  %41 = sub <4 x i32> %wide.load, %wide.load128
  %42 = sub <4 x i32> %wide.load127, %wide.load129
  %43 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %41, i1 false)
  %44 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %42, i1 false)
  %45 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %wide.load128, i1 false)
  %46 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %wide.load129, i1 false)
  %47 = add <4 x i32> %43, %45
  %48 = add <4 x i32> %44, %46
  %49 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %wide.load, i1 false)
  %50 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %wide.load127, i1 false)
  %51 = add <4 x i32> %43, %49
  %52 = add <4 x i32> %44, %50
  %53 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %47, <4 x i32> %51)
  %54 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %48, <4 x i32> %52)
  %55 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %53, <4 x i32> %vec.phi)
  %56 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %54, <4 x i32> %vec.phi124)
  %index.next = add nuw i64 %index, 8
  %57 = icmp eq i64 %index.next, %n.vec
  br i1 %57, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %55, <4 x i32> %56)
  %58 = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %n.vec, %28
  br i1 %cmp.n, label %._crit_edge119, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %vector.scevcheck, %.lr.ph118, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %vector.scevcheck ], [ 1, %.lr.ph118 ], [ %ind.end, %middle.block ]
  %.0116.ph = phi i32 [ 1000000000, %vector.scevcheck ], [ 1000000000, %.lr.ph118 ], [ %58, %middle.block ]
  %.079115.ph = phi i32 [ %23, %vector.scevcheck ], [ %23, %.lr.ph118 ], [ %ind.end122, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.0116 = phi i32 [ %spec.select, %scalar.ph ], [ %.0116.ph, %scalar.ph.preheader ]
  %.079115 = phi i32 [ %73, %scalar.ph ], [ %.079115.ph, %scalar.ph.preheader ]
  %59 = sext i32 %.079115 to i64
  %60 = add nsw i64 %59, -1
  %61 = getelementptr i32, ptr %.unpack, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !3
  %63 = add i64 %indvars.iv, -1
  %64 = getelementptr i32, ptr %.unpack, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = sub i32 %62, %65
  %67 = call i32 @llvm.abs.i32(i32 %66, i1 false)
  %68 = call i32 @llvm.abs.i32(i32 %65, i1 false)
  %69 = add i32 %67, %68
  %70 = call i32 @llvm.abs.i32(i32 %62, i1 false)
  %71 = add i32 %67, %70
  %72 = call i32 @llvm.smin.i32(i32 %69, i32 %71)
  %spec.select = call i32 @llvm.smin.i32(i32 %72, i32 %.0116)
  %73 = add i32 %.079115, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond121.not = icmp eq i64 %indvars.iv, %28
  br i1 %exitcond121.not, label %._crit_edge119, label %scalar.ph, !llvm.loop !12

._crit_edge119:                                   ; preds = %scalar.ph, %middle.block, %._crit_edge
  %.0.lcssa = phi i32 [ 1000000000, %._crit_edge ], [ %58, %middle.block ], [ %spec.select, %scalar.ph ]
  %74 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.40d74c8f3cc844c3bf0e5ce0acc4a833, i32 21)
  %75 = call i1 @_FortranAioOutputInteger32(ptr %74, i32 %.0.lcssa)
  %76 = call i32 @_FortranAioEndIoStatement(ptr %74)
  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 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) #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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32>) #2

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 nosync nounwind 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, !10}
