#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: minsize mustprogress nofree norecurse nosync nounwind optsize 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: minsize nofree nounwind optsize 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) #8
  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)
  br label %for.cond

for.cond:                                         ; preds = %for.body, %entry
  %i.0 = phi i64 [ 1, %entry ], [ %inc, %for.body ]
  %0 = load i64, ptr %n, align 8, !tbaa !5
  %cmp.not = icmp sgt i64 %i.0, %0
  br i1 %cmp.not, label %for.cond.cleanup, label %for.body

for.cond.cleanup:                                 ; preds = %for.cond
  call void @qsort(ptr noundef nonnull %A, i64 noundef %0, i64 noundef 8, ptr noundef nonnull @compare_int) #9
  %1 = load i64, ptr %n, align 8, !tbaa !5
  %sub3 = add nsw i64 %1, -1
  %div = sdiv i64 %sub3, 2
  %arrayidx10 = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %div
  %smax = call i64 @llvm.smax.i64(i64 %1, i64 0)
  br label %for.cond5

for.body:                                         ; preds = %for.cond
  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) #8
  %2 = load i64, ptr %a, align 8, !tbaa !5
  %sub = sub nsw i64 %2, %i.0
  %sub2 = add nsw i64 %i.0, -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.0, 1
  br label %for.cond

for.cond5:                                        ; preds = %for.body8, %for.cond.cleanup
  %s.0 = phi i64 [ 0, %for.cond.cleanup ], [ %add, %for.body8 ]
  %i4.0 = phi i64 [ 0, %for.cond.cleanup ], [ %inc21, %for.body8 ]
  %exitcond.not = icmp eq i64 %i4.0, %smax
  br i1 %exitcond.not, label %for.cond.cleanup7, label %for.body8

for.cond.cleanup7:                                ; preds = %for.cond5
  %call23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %s.0) #8
  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.cond5
  %arrayidx9 = getelementptr inbounds [200003 x i64], ptr %A, i64 0, i64 %i4.0
  %3 = load i64, ptr %arrayidx9, align 8, !tbaa !5
  %4 = load i64, ptr %arrayidx10, align 8, !tbaa !5
  %sub11 = sub nsw i64 %3, %4
  %cond = call i64 @llvm.abs.i64(i64 %sub11, i1 true)
  %add = add nuw nsw i64 %cond, %s.0
  %inc21 = add nuw i64 %i4.0, 1
  br label %for.cond5
}

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

; Function Attrs: minsize nofree nounwind optsize
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: minsize nofree optsize
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: minsize nofree nounwind optsize
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 i64 @llvm.smax.i64(i64, i64) #6

attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize 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 = { minsize nofree nounwind optsize 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 = { minsize nofree nounwind optsize "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 = { minsize nofree optsize "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 }
attributes #8 = { minsize optsize }
attributes #9 = { minsize nounwind optsize }

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