#import <stdio.h>
#import <stdlib.h>
#define MIN(a,b) ((a)<(b)?(a):(b))

long calc(long *A, long N, int positive) {
    long s = 0;
    long count = 0;
    
    for (long i=0;i<N;i++){
        s += A[i];
        if(i%2==(positive ? 0 : 1)) {
            if (s<=0) {
                count += 1-s;
                s=1;
            }
        } else {
            if (s>=0) {
                count += s+1;
                s=-1;
            }
        }
    }
    
    return count;
}

int main() {
    long N;
    scanf("%ld", &N);
    long *A = (long*)malloc(N * sizeof(long));
    
    long n;
    long i = 0;
    while (scanf("%ld", &n) != EOF) {
        A[i] = n;
        i++;
    }
    
    printf("%ld", MIN(calc(A,N,1),calc(A,N,0)));
    
    free(A);
    return 0;
}


; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_802/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_802/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 [4 x i8] c"%ld\00", align 1

; Function Attrs: minsize nofree nosync nounwind optsize memory(argmem: read) uwtable
define dso_local i64 @calc(ptr nocapture noundef readonly %A, i64 noundef %N, i32 noundef %positive) local_unnamed_addr #0 {
entry:
  %tobool.not = icmp ne i32 %positive, 0
  %smax = tail call i64 @llvm.smax.i64(i64 %N, i64 0)
  br label %for.cond

for.cond:                                         ; preds = %for.inc, %entry
  %s.0 = phi i64 [ 0, %entry ], [ %s.1, %for.inc ]
  %count.0 = phi i64 [ 0, %entry ], [ %count.1, %for.inc ]
  %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ]
  %exitcond.not = icmp eq i64 %i.0, %smax
  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body

for.cond.cleanup:                                 ; preds = %for.cond
  ret i64 %count.0

for.body:                                         ; preds = %for.cond
  %arrayidx = getelementptr inbounds i64, ptr %A, i64 %i.0
  %0 = load i64, ptr %arrayidx, align 8, !tbaa !5
  %add = add nsw i64 %0, %s.0
  %1 = and i64 %i.0, 1
  %2 = icmp ne i64 %1, 0
  %cmp1 = xor i1 %tobool.not, %2
  br i1 %cmp1, label %if.then, label %if.else

if.then:                                          ; preds = %for.body
  %cmp3 = icmp slt i64 %add, 1
  br i1 %cmp3, label %if.then5, label %for.inc

if.then5:                                         ; preds = %if.then
  %reass.sub = add i64 %count.0, 1
  %add6 = sub i64 %reass.sub, %add
  br label %for.inc

if.else:                                          ; preds = %for.body
  %cmp7 = icmp sgt i64 %add, -1
  br i1 %cmp7, label %if.then9, label %for.inc

if.then9:                                         ; preds = %if.else
  %add10 = add i64 %count.0, 1
  %add11 = add i64 %add10, %add
  br label %for.inc

for.inc:                                          ; preds = %if.then5, %if.then, %if.then9, %if.else
  %s.1 = phi i64 [ 1, %if.then5 ], [ %add, %if.then ], [ -1, %if.then9 ], [ %add, %if.else ]
  %count.1 = phi i64 [ %add6, %if.then5 ], [ %count.0, %if.then ], [ %add11, %if.then9 ], [ %count.0, %if.else ]
  %inc = add nuw i64 %i.0, 1
  br label %for.cond
}

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

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

; Function Attrs: minsize nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #2 {
entry:
  %N = alloca i64, align 8
  %n = 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
  %0 = load i64, ptr %N, align 8, !tbaa !5
  %mul = shl i64 %0, 3
  %call1 = call noalias ptr @malloc(i64 noundef %mul) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #7
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %i.0 = phi i64 [ 0, %entry ], [ %inc, %while.body ]
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n) #8
  %cmp.not = icmp eq i32 %call2, -1
  br i1 %cmp.not, label %while.end, label %while.body

while.body:                                       ; preds = %while.cond
  %1 = load i64, ptr %n, align 8, !tbaa !5
  %arrayidx = getelementptr inbounds i64, ptr %call1, i64 %i.0
  store i64 %1, ptr %arrayidx, align 8, !tbaa !5
  %inc = add nuw nsw i64 %i.0, 1
  br label %while.cond

while.end:                                        ; preds = %while.cond
  %2 = load i64, ptr %N, align 8, !tbaa !5
  %call3 = call i64 @calc(ptr noundef %call1, i64 noundef %2, i32 noundef 1) #8
  %call4 = call i64 @calc(ptr noundef %call1, i64 noundef %2, i32 noundef 0) #8
  %spec.select = call i64 @llvm.smin.i64(i64 %call3, i64 %call4)
  %call8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %spec.select) #8
  call void @free(ptr noundef %call1) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %N) #7
  ret i32 0
}

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

; Function Attrs: minsize mustprogress nofree nounwind optsize willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

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

; Function Attrs: minsize mustprogress nounwind optsize willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

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

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

attributes #0 = { minsize nofree nosync nounwind optsize 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { minsize 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 #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 = { minsize mustprogress nofree nounwind optsize willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { minsize mustprogress nounwind optsize willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
attributes #10 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
