#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: nofree norecurse nosync nounwind 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:
  %cmp23 = icmp sgt i64 %N, 0
  br i1 %cmp23, label %for.body.lr.ph, label %for.cond.cleanup

for.body.lr.ph:                                   ; preds = %entry
  %tobool.not = icmp ne i32 %positive, 0
  br label %for.body

for.cond.cleanup:                                 ; preds = %for.inc, %entry
  %count.0.lcssa = phi i64 [ 0, %entry ], [ %count.1, %for.inc ]
  ret i64 %count.0.lcssa

for.body:                                         ; preds = %for.body.lr.ph, %for.inc
  %i.026 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
  %count.025 = phi i64 [ 0, %for.body.lr.ph ], [ %count.1, %for.inc ]
  %s.024 = phi i64 [ 0, %for.body.lr.ph ], [ %s.1, %for.inc ]
  %arrayidx = getelementptr inbounds i64, ptr %A, i64 %i.026
  %0 = load i64, ptr %arrayidx, align 8, !tbaa !5
  %add = add nsw i64 %0, %s.024
  %1 = and i64 %i.026, 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.025, 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.025, 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.025, %if.then ], [ %add11, %if.then9 ], [ %count.025, %if.else ]
  %inc = add nuw nsw i64 %i.026, 1
  %exitcond.not = icmp eq i64 %inc, %N
  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}

; 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: nounwind 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) #6
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N)
  %0 = load i64, ptr %N, align 8, !tbaa !5
  %mul = shl i64 %0, 3
  %call1 = call noalias ptr @malloc(i64 noundef %mul) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #6
  %call2104 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n)
  %cmp.not105 = icmp eq i32 %call2104, -1
  br i1 %cmp.not105, label %while.end, label %while.body

while.body:                                       ; preds = %entry, %while.body
  %i.0106 = phi i64 [ %inc, %while.body ], [ 0, %entry ]
  %1 = load i64, ptr %n, align 8, !tbaa !5
  %arrayidx = getelementptr inbounds i64, ptr %call1, i64 %i.0106
  store i64 %1, ptr %arrayidx, align 8, !tbaa !5
  %inc = add nuw nsw i64 %i.0106, 1
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n)
  %cmp.not = icmp eq i32 %call2, -1
  br i1 %cmp.not, label %while.end, label %while.body

while.end:                                        ; preds = %while.body, %entry
  %2 = load i64, ptr %N, align 8, !tbaa !5
  %cmp23.i = icmp sgt i64 %2, 0
  br i1 %cmp23.i, label %for.body.i, label %cond.end

for.body.i:                                       ; preds = %while.end, %for.inc.i
  %i.026.i = phi i64 [ %inc.i, %for.inc.i ], [ 0, %while.end ]
  %count.025.i = phi i64 [ %count.1.i, %for.inc.i ], [ 0, %while.end ]
  %s.024.i = phi i64 [ %s.1.i, %for.inc.i ], [ 0, %while.end ]
  %arrayidx.i = getelementptr inbounds i64, ptr %call1, i64 %i.026.i
  %3 = load i64, ptr %arrayidx.i, align 8, !tbaa !5
  %add.i = add nsw i64 %3, %s.024.i
  %4 = and i64 %i.026.i, 1
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %if.then.i, label %if.else.i

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

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

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

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

for.inc.i:                                        ; preds = %if.then9.i, %if.else.i, %if.then5.i, %if.then.i
  %s.1.i = phi i64 [ 1, %if.then5.i ], [ %add.i, %if.then.i ], [ -1, %if.then9.i ], [ %add.i, %if.else.i ]
  %count.1.i = phi i64 [ %add6.i, %if.then5.i ], [ %count.025.i, %if.then.i ], [ %add11.i, %if.then9.i ], [ %count.025.i, %if.else.i ]
  %inc.i = add nuw nsw i64 %i.026.i, 1
  %exitcond.not.i = icmp eq i64 %inc.i, %2
  br i1 %exitcond.not.i, label %for.body.i18, label %for.body.i

for.body.i18:                                     ; preds = %for.inc.i, %for.inc.i26
  %i.026.i19 = phi i64 [ %inc.i29, %for.inc.i26 ], [ 0, %for.inc.i ]
  %count.025.i20 = phi i64 [ %count.1.i28, %for.inc.i26 ], [ 0, %for.inc.i ]
  %s.024.i21 = phi i64 [ %s.1.i27, %for.inc.i26 ], [ 0, %for.inc.i ]
  %arrayidx.i22 = getelementptr inbounds i64, ptr %call1, i64 %i.026.i19
  %5 = load i64, ptr %arrayidx.i22, align 8, !tbaa !5
  %add.i23 = add nsw i64 %5, %s.024.i21
  %6 = and i64 %i.026.i19, 1
  %.not100 = icmp eq i64 %6, 0
  br i1 %.not100, label %if.else.i24, label %if.then.i34

if.then.i34:                                      ; preds = %for.body.i18
  %cmp3.i35 = icmp slt i64 %add.i23, 1
  br i1 %cmp3.i35, label %if.then5.i36, label %for.inc.i26

if.then5.i36:                                     ; preds = %if.then.i34
  %reass.sub.i37 = add i64 %count.025.i20, 1
  %add6.i38 = sub i64 %reass.sub.i37, %add.i23
  br label %for.inc.i26

if.else.i24:                                      ; preds = %for.body.i18
  %cmp7.i25 = icmp sgt i64 %add.i23, -1
  br i1 %cmp7.i25, label %if.then9.i31, label %for.inc.i26

if.then9.i31:                                     ; preds = %if.else.i24
  %add10.i32 = add i64 %count.025.i20, 1
  %add11.i33 = add i64 %add10.i32, %add.i23
  br label %for.inc.i26

for.inc.i26:                                      ; preds = %if.then9.i31, %if.else.i24, %if.then5.i36, %if.then.i34
  %s.1.i27 = phi i64 [ 1, %if.then5.i36 ], [ %add.i23, %if.then.i34 ], [ -1, %if.then9.i31 ], [ %add.i23, %if.else.i24 ]
  %count.1.i28 = phi i64 [ %add6.i38, %if.then5.i36 ], [ %count.025.i20, %if.then.i34 ], [ %add11.i33, %if.then9.i31 ], [ %count.025.i20, %if.else.i24 ]
  %inc.i29 = add nuw nsw i64 %i.026.i19, 1
  %exitcond.not.i30 = icmp eq i64 %inc.i29, %2
  br i1 %exitcond.not.i30, label %calc.exit39, label %for.body.i18

calc.exit39:                                      ; preds = %for.inc.i26
  %cmp5 = icmp slt i64 %count.1.i, %count.1.i28
  br i1 %cmp5, label %for.body.i43, label %for.body.i69

for.body.i43:                                     ; preds = %calc.exit39, %for.inc.i52
  %i.026.i44 = phi i64 [ %inc.i55, %for.inc.i52 ], [ 0, %calc.exit39 ]
  %count.025.i45 = phi i64 [ %count.1.i54, %for.inc.i52 ], [ 0, %calc.exit39 ]
  %s.024.i46 = phi i64 [ %s.1.i53, %for.inc.i52 ], [ 0, %calc.exit39 ]
  %arrayidx.i47 = getelementptr inbounds i64, ptr %call1, i64 %i.026.i44
  %7 = load i64, ptr %arrayidx.i47, align 8, !tbaa !5
  %add.i48 = add nsw i64 %7, %s.024.i46
  %8 = and i64 %i.026.i44, 1
  %.not102 = icmp eq i64 %8, 0
  br i1 %.not102, label %if.then.i60, label %if.else.i50

if.then.i60:                                      ; preds = %for.body.i43
  %cmp3.i61 = icmp slt i64 %add.i48, 1
  br i1 %cmp3.i61, label %if.then5.i62, label %for.inc.i52

if.then5.i62:                                     ; preds = %if.then.i60
  %reass.sub.i63 = add i64 %count.025.i45, 1
  %add6.i64 = sub i64 %reass.sub.i63, %add.i48
  br label %for.inc.i52

if.else.i50:                                      ; preds = %for.body.i43
  %cmp7.i51 = icmp sgt i64 %add.i48, -1
  br i1 %cmp7.i51, label %if.then9.i57, label %for.inc.i52

if.then9.i57:                                     ; preds = %if.else.i50
  %add10.i58 = add i64 %count.025.i45, 1
  %add11.i59 = add i64 %add10.i58, %add.i48
  br label %for.inc.i52

for.inc.i52:                                      ; preds = %if.then9.i57, %if.else.i50, %if.then5.i62, %if.then.i60
  %s.1.i53 = phi i64 [ 1, %if.then5.i62 ], [ %add.i48, %if.then.i60 ], [ -1, %if.then9.i57 ], [ %add.i48, %if.else.i50 ]
  %count.1.i54 = phi i64 [ %add6.i64, %if.then5.i62 ], [ %count.025.i45, %if.then.i60 ], [ %add11.i59, %if.then9.i57 ], [ %count.025.i45, %if.else.i50 ]
  %inc.i55 = add nuw nsw i64 %i.026.i44, 1
  %exitcond.not.i56 = icmp eq i64 %inc.i55, %2
  br i1 %exitcond.not.i56, label %cond.end, label %for.body.i43

for.body.i69:                                     ; preds = %calc.exit39, %for.inc.i77
  %i.026.i70 = phi i64 [ %inc.i80, %for.inc.i77 ], [ 0, %calc.exit39 ]
  %count.025.i71 = phi i64 [ %count.1.i79, %for.inc.i77 ], [ 0, %calc.exit39 ]
  %s.024.i72 = phi i64 [ %s.1.i78, %for.inc.i77 ], [ 0, %calc.exit39 ]
  %arrayidx.i73 = getelementptr inbounds i64, ptr %call1, i64 %i.026.i70
  %9 = load i64, ptr %arrayidx.i73, align 8, !tbaa !5
  %add.i74 = add nsw i64 %9, %s.024.i72
  %10 = and i64 %i.026.i70, 1
  %.not101 = icmp eq i64 %10, 0
  br i1 %.not101, label %if.else.i75, label %if.then.i85

if.then.i85:                                      ; preds = %for.body.i69
  %cmp3.i86 = icmp slt i64 %add.i74, 1
  br i1 %cmp3.i86, label %if.then5.i87, label %for.inc.i77

if.then5.i87:                                     ; preds = %if.then.i85
  %reass.sub.i88 = add i64 %count.025.i71, 1
  %add6.i89 = sub i64 %reass.sub.i88, %add.i74
  br label %for.inc.i77

if.else.i75:                                      ; preds = %for.body.i69
  %cmp7.i76 = icmp sgt i64 %add.i74, -1
  br i1 %cmp7.i76, label %if.then9.i82, label %for.inc.i77

if.then9.i82:                                     ; preds = %if.else.i75
  %add10.i83 = add i64 %count.025.i71, 1
  %add11.i84 = add i64 %add10.i83, %add.i74
  br label %for.inc.i77

for.inc.i77:                                      ; preds = %if.then9.i82, %if.else.i75, %if.then5.i87, %if.then.i85
  %s.1.i78 = phi i64 [ 1, %if.then5.i87 ], [ %add.i74, %if.then.i85 ], [ -1, %if.then9.i82 ], [ %add.i74, %if.else.i75 ]
  %count.1.i79 = phi i64 [ %add6.i89, %if.then5.i87 ], [ %count.025.i71, %if.then.i85 ], [ %add11.i84, %if.then9.i82 ], [ %count.025.i71, %if.else.i75 ]
  %inc.i80 = add nuw nsw i64 %i.026.i70, 1
  %exitcond.not.i81 = icmp eq i64 %inc.i80, %2
  br i1 %exitcond.not.i81, label %cond.end, label %for.body.i69

cond.end:                                         ; preds = %for.inc.i77, %for.inc.i52, %while.end
  %cond = phi i64 [ 0, %while.end ], [ %count.1.i54, %for.inc.i52 ], [ %count.1.i79, %for.inc.i77 ]
  %call8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %cond)
  call void @free(ptr noundef %call1) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %N) #6
  ret i32 0
}

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

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

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

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

attributes #0 = { nofree norecurse nosync nounwind 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 = { 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 #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 nofree nounwind 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 = { mustprogress nounwind 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 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

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