#import <stdio.h>
#import <stdlib.h>
#define ABS(a) ((a)>0?(a):(-(a)))
typedef long long INT;

int compare_int(const void *a, const void *b)
{
    return (int)(*(INT*)a - *(INT*)b);
}

int main(){
    INT n;
    scanf("%lld",&n);
    INT A[200003] = {0};
    for (INT i=1;i<=n;i++){
        INT a;
        scanf("%lld",&a);
        A[i-1] = a-i;
    }
    qsort(A, n, sizeof(INT), compare_int);

    INT k=(n-1)/2;
    INT s=0;
    for (INT i=0;i<n;i++){
        s += ABS(A[i]-A[k]);
    }
    printf("%lld",s);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_495/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_495/source.m"
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"

@.str = private unnamed_addr constant [5 x i8] c"%lld\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @compare_int(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i64, ptr %a, align 8, !tbaa !5
  %1 = load i64, ptr %b, align 8, !tbaa !5
  %sub = sub nsw i64 %0, %1
  %conv = trunc i64 %sub to i32
  ret i32 %conv
}

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #1 {
entry:
  %n = alloca i64, align 8
  %A = alloca [200003 x i64], align 16
  %a = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #7
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n)
  call void @llvm.lifetime.start.p0(i64 1600024, ptr nonnull %A) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1600024) %A, i8 0, i64 1600024, i1 false)
  %0 = load i64, ptr %n, align 8, !tbaa !5
  %cmp.not34 = icmp slt i64 %0, 1
  br i1 %cmp.not34, label %for.cond.cleanup, label %for.body

for.cond.cleanup:                                 ; preds = %for.body, %entry
  %.lcssa = phi i64 [ %0, %entry ], [ %14, %for.body ]
  call void @qsort(ptr noundef nonnull %A, i64 noundef %.lcssa, i64 noundef 8, ptr noundef nonnull @compare_int) #7
  %1 = load i64, ptr %n, align 8, !tbaa !5
  %cmp636 = icmp sgt i64 %1, 0
  br i1 %cmp636, label %for.body8.lr.ph, label %for.cond.cleanup7

for.body8.lr.ph:                                  ; preds = %for.cond.cleanup
  %sub3 = add nsw i64 %1, -1
  %div4143 = lshr i64 %sub3, 1
  %arrayidx10 = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %div4143
  %2 = load i64, ptr %arrayidx10, align 8, !tbaa !5
  %min.iters.check = icmp ult i64 %1, 4
  br i1 %min.iters.check, label %for.body8.preheader, label %vector.ph

vector.ph:                                        ; preds = %for.body8.lr.ph
  %n.vec = and i64 %1, -4
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %2, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %9, %vector.body ]
  %vec.phi45 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %10, %vector.body ]
  %3 = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %index
  %wide.load = load <2 x i64>, ptr %3, align 16, !tbaa !5
  %4 = getelementptr inbounds i64, ptr %3, i64 2
  %wide.load46 = load <2 x i64>, ptr %4, align 16, !tbaa !5
  %5 = sub nsw <2 x i64> %wide.load, %broadcast.splat
  %6 = sub nsw <2 x i64> %wide.load46, %broadcast.splat
  %7 = call <2 x i64> @llvm.abs.v2i64(<2 x i64> %5, i1 true)
  %8 = call <2 x i64> @llvm.abs.v2i64(<2 x i64> %6, i1 true)
  %9 = add <2 x i64> %7, %vec.phi
  %10 = add <2 x i64> %8, %vec.phi45
  %index.next = add nuw i64 %index, 4
  %11 = icmp eq i64 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %10, %9
  %12 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %1, %n.vec
  br i1 %cmp.n, label %for.cond.cleanup7, label %for.body8.preheader

for.body8.preheader:                              ; preds = %for.body8.lr.ph, %middle.block
  %i4.038.ph = phi i64 [ 0, %for.body8.lr.ph ], [ %n.vec, %middle.block ]
  %s.037.ph = phi i64 [ 0, %for.body8.lr.ph ], [ %12, %middle.block ]
  br label %for.body8

for.body:                                         ; preds = %entry, %for.body
  %i.035 = phi i64 [ %inc, %for.body ], [ 1, %entry ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %a) #7
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %a)
  %13 = load i64, ptr %a, align 8, !tbaa !5
  %sub = sub nsw i64 %13, %i.035
  %sub2 = add nsw i64 %i.035, -1
  %arrayidx = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %sub2
  store i64 %sub, ptr %arrayidx, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %a) #7
  %inc = add nuw nsw i64 %i.035, 1
  %14 = load i64, ptr %n, align 8, !tbaa !5
  %cmp.not.not = icmp slt i64 %i.035, %14
  br i1 %cmp.not.not, label %for.body, label %for.cond.cleanup

for.cond.cleanup7:                                ; preds = %for.body8, %middle.block, %for.cond.cleanup
  %s.0.lcssa = phi i64 [ 0, %for.cond.cleanup ], [ %12, %middle.block ], [ %add, %for.body8 ]
  %call23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %s.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 1600024, ptr nonnull %A) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #7
  ret i32 0

for.body8:                                        ; preds = %for.body8.preheader, %for.body8
  %i4.038 = phi i64 [ %inc21, %for.body8 ], [ %i4.038.ph, %for.body8.preheader ]
  %s.037 = phi i64 [ %add, %for.body8 ], [ %s.037.ph, %for.body8.preheader ]
  %arrayidx9 = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %i4.038
  %15 = load i64, ptr %arrayidx9, align 8, !tbaa !5
  %sub11 = sub nsw i64 %15, %2
  %cond = call i64 @llvm.abs.i64(i64 %sub11, i1 true)
  %add = add nuw nsw i64 %cond, %s.037
  %inc21 = add nuw nsw i64 %i4.038, 1
  %exitcond.not = icmp eq i64 %inc21, %1
  br i1 %exitcond.not, label %for.cond.cleanup7, label %for.body8, !llvm.loop !12
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.abs.v2i64(<2 x i64>, i1 immarg) #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #6

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nofree "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
