#import <stdio.h>
#import <limits.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>0?(a):(-(a)))
int main(){
    int N;
    int W[101] = {0};
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",W+i);
    }
    int S[101] = {0};
    for(int i=0;i<N;i++){
        S[i] = W[i] + ((i==0) ? 0 : S[i-1]);
    }
    int min = INT_MAX;
    for(int i=0;i<N;i++){
        min = MIN(min, ABS(2*S[i] - S[N-1]));
    }
    printf("%d",min);
}

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

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %N = alloca i32, align 4
  %W = alloca [101 x i32], align 16
  %S = alloca [101 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #5
  call void @llvm.lifetime.start.p0(i64 404, ptr nonnull %W) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(404) %W, i8 0, i64 404, i1 false)
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N)
  %0 = load i32, ptr %N, align 4, !tbaa !5
  %cmp98 = icmp sgt i32 %0, 0
  br i1 %cmp98, label %for.body, label %for.cond.cleanup.thread

for.cond.cleanup.thread:                          ; preds = %entry
  call void @llvm.lifetime.start.p0(i64 404, ptr nonnull %S) #5
  br label %for.cond.cleanup18

for.cond.cleanup:                                 ; preds = %for.body
  call void @llvm.lifetime.start.p0(i64 404, ptr nonnull %S) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(404) %S, i8 0, i64 404, i1 false)
  %cmp4100 = icmp sgt i32 %5, 0
  br i1 %cmp4100, label %cond.end.peel, label %for.cond.cleanup18

cond.end.peel:                                    ; preds = %for.cond.cleanup
  %1 = load i32, ptr %W, align 16, !tbaa !5
  store i32 %1, ptr %S, align 16, !tbaa !5
  %exitcond.peel.not = icmp eq i32 %5, 1
  br i1 %exitcond.peel.not, label %for.body19.lr.ph, label %cond.end.preheader

cond.end.preheader:                               ; preds = %cond.end.peel
  %wide.trip.count = zext i32 %5 to i64
  %2 = add nsw i64 %wide.trip.count, -1
  %3 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %2, 3
  %4 = icmp ult i64 %3, 3
  br i1 %4, label %for.cond16.preheader.unr-lcssa, label %cond.end.preheader.new

cond.end.preheader.new:                           ; preds = %cond.end.preheader
  %unroll_iter = and i64 %2, -4
  br label %cond.end

for.body:                                         ; preds = %entry, %for.body
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  %add.ptr = getelementptr inbounds i32, ptr %W, i64 %indvars.iv
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %add.ptr)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = load i32, ptr %N, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %cmp = icmp slt i64 %indvars.iv.next, %6
  br i1 %cmp, label %for.body, label %for.cond.cleanup

for.cond16.preheader.unr-lcssa:                   ; preds = %cond.end, %cond.end.preheader
  %.unr = phi i32 [ %1, %cond.end.preheader ], [ %add.3, %cond.end ]
  %indvars.iv108.unr = phi i64 [ 1, %cond.end.preheader ], [ %indvars.iv.next109.3, %cond.end ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %for.cond16.preheader, label %cond.end.epil

cond.end.epil:                                    ; preds = %for.cond16.preheader.unr-lcssa, %cond.end.epil
  %7 = phi i32 [ %add.epil, %cond.end.epil ], [ %.unr, %for.cond16.preheader.unr-lcssa ]
  %indvars.iv108.epil = phi i64 [ %indvars.iv.next109.epil, %cond.end.epil ], [ %indvars.iv108.unr, %for.cond16.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %cond.end.epil ], [ 0, %for.cond16.preheader.unr-lcssa ]
  %arrayidx.epil = getelementptr inbounds [101 x i32], ptr %W, i64 0, i64 %indvars.iv108.epil
  %8 = load i32, ptr %arrayidx.epil, align 4, !tbaa !5
  %add.epil = add nsw i32 %7, %8
  %arrayidx11.epil = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv108.epil
  store i32 %add.epil, ptr %arrayidx11.epil, align 4, !tbaa !5
  %indvars.iv.next109.epil = add nuw nsw i64 %indvars.iv108.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %for.cond16.preheader, label %cond.end.epil, !llvm.loop !9

for.cond16.preheader:                             ; preds = %cond.end.epil, %for.cond16.preheader.unr-lcssa
  br i1 %cmp4100, label %for.body19.lr.ph, label %for.cond.cleanup18

for.body19.lr.ph:                                 ; preds = %cond.end.peel, %for.cond16.preheader
  %.lcssa120127 = phi i32 [ %5, %for.cond16.preheader ], [ 1, %cond.end.peel ]
  %sub22 = add nsw i32 %.lcssa120127, -1
  %idxprom23 = sext i32 %sub22 to i64
  %arrayidx24 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %idxprom23
  %9 = load i32, ptr %arrayidx24, align 4, !tbaa !5
  %wide.trip.count116 = zext i32 %.lcssa120127 to i64
  %min.iters.check = icmp ult i32 %.lcssa120127, 8
  br i1 %min.iters.check, label %for.body19.preheader, label %vector.ph

vector.ph:                                        ; preds = %for.body19.lr.ph
  %n.vec = and i64 %wide.trip.count116, 2147483640
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %9, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 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 <4 x i32> [ <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>, %vector.ph ], [ %18, %vector.body ]
  %vec.phi128 = phi <4 x i32> [ <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>, %vector.ph ], [ %19, %vector.body ]
  %10 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %index
  %wide.load = load <4 x i32>, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds i32, ptr %10, i64 4
  %wide.load129 = load <4 x i32>, ptr %11, align 16, !tbaa !5
  %12 = shl nsw <4 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1>
  %13 = shl nsw <4 x i32> %wide.load129, <i32 1, i32 1, i32 1, i32 1>
  %14 = sub nsw <4 x i32> %12, %broadcast.splat
  %15 = sub nsw <4 x i32> %13, %broadcast.splat
  %16 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %14, i1 true)
  %17 = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %15, i1 true)
  %18 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi, <4 x i32> %16)
  %19 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi128, <4 x i32> %17)
  %index.next = add nuw i64 %index, 8
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %rdx.minmax = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %18, <4 x i32> %19)
  %21 = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %rdx.minmax)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count116
  br i1 %cmp.n, label %for.cond.cleanup18, label %for.body19.preheader

for.body19.preheader:                             ; preds = %for.body19.lr.ph, %middle.block
  %indvars.iv113.ph = phi i64 [ 0, %for.body19.lr.ph ], [ %n.vec, %middle.block ]
  %min.0103.ph = phi i32 [ 2147483647, %for.body19.lr.ph ], [ %21, %middle.block ]
  br label %for.body19

cond.end:                                         ; preds = %cond.end, %cond.end.preheader.new
  %22 = phi i32 [ %1, %cond.end.preheader.new ], [ %add.3, %cond.end ]
  %indvars.iv108 = phi i64 [ 1, %cond.end.preheader.new ], [ %indvars.iv.next109.3, %cond.end ]
  %niter = phi i64 [ 0, %cond.end.preheader.new ], [ %niter.next.3, %cond.end ]
  %arrayidx = getelementptr inbounds [101 x i32], ptr %W, i64 0, i64 %indvars.iv108
  %23 = load i32, ptr %arrayidx, align 4, !tbaa !5
  %add = add nsw i32 %22, %23
  %arrayidx11 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv108
  store i32 %add, ptr %arrayidx11, align 4, !tbaa !5
  %indvars.iv.next109 = add nuw nsw i64 %indvars.iv108, 1
  %arrayidx.1 = getelementptr inbounds [101 x i32], ptr %W, i64 0, i64 %indvars.iv.next109
  %24 = load i32, ptr %arrayidx.1, align 4, !tbaa !5
  %add.1 = add nsw i32 %add, %24
  %arrayidx11.1 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv.next109
  store i32 %add.1, ptr %arrayidx11.1, align 4, !tbaa !5
  %indvars.iv.next109.1 = add nuw nsw i64 %indvars.iv108, 2
  %arrayidx.2 = getelementptr inbounds [101 x i32], ptr %W, i64 0, i64 %indvars.iv.next109.1
  %25 = load i32, ptr %arrayidx.2, align 4, !tbaa !5
  %add.2 = add nsw i32 %add.1, %25
  %arrayidx11.2 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv.next109.1
  store i32 %add.2, ptr %arrayidx11.2, align 4, !tbaa !5
  %indvars.iv.next109.2 = add nuw nsw i64 %indvars.iv108, 3
  %arrayidx.3 = getelementptr inbounds [101 x i32], ptr %W, i64 0, i64 %indvars.iv.next109.2
  %26 = load i32, ptr %arrayidx.3, align 4, !tbaa !5
  %add.3 = add nsw i32 %add.2, %26
  %arrayidx11.3 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv.next109.2
  store i32 %add.3, ptr %arrayidx11.3, align 4, !tbaa !5
  %indvars.iv.next109.3 = add nuw nsw i64 %indvars.iv108, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %for.cond16.preheader.unr-lcssa, label %cond.end, !llvm.loop !14

for.cond.cleanup18:                               ; preds = %for.body19, %middle.block, %for.cond.cleanup, %for.cond.cleanup.thread, %for.cond16.preheader
  %min.0.lcssa = phi i32 [ 2147483647, %for.cond16.preheader ], [ 2147483647, %for.cond.cleanup.thread ], [ 2147483647, %for.cond.cleanup ], [ %21, %middle.block ], [ %spec.select, %for.body19 ]
  %call81 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %min.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 404, ptr nonnull %S) #5
  call void @llvm.lifetime.end.p0(i64 404, ptr nonnull %W) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #5
  ret i32 0

for.body19:                                       ; preds = %for.body19.preheader, %for.body19
  %indvars.iv113 = phi i64 [ %indvars.iv.next114, %for.body19 ], [ %indvars.iv113.ph, %for.body19.preheader ]
  %min.0103 = phi i32 [ %spec.select, %for.body19 ], [ %min.0103.ph, %for.body19.preheader ]
  %arrayidx21 = getelementptr inbounds [101 x i32], ptr %S, i64 0, i64 %indvars.iv113
  %27 = load i32, ptr %arrayidx21, align 4, !tbaa !5
  %mul = shl nsw i32 %27, 1
  %sub25 = sub nsw i32 %mul, %9
  %cond45 = call i32 @llvm.abs.i32(i32 %sub25, i1 true)
  %spec.select = call i32 @llvm.smin.i32(i32 %min.0103, i32 %cond45)
  %indvars.iv.next114 = add nuw nsw i64 %indvars.iv113, 1
  %exitcond117.not = icmp eq i64 %indvars.iv.next114, %wide.trip.count116
  br i1 %exitcond117.not, label %for.cond.cleanup18, label %for.body19, !llvm.loop !16
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

; 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 i32 @llvm.abs.i32(i32, i1 immarg) #4

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.peeled.count", i32 1}
!16 = distinct !{!16, !13, !12}
