program abc129b
  implicit none
  integer :: n, t, s1, s2, ans, diff
  integer, allocatable :: w(:)

  read(*,*) n
  allocate(w(n))
  read(*,*) w(:)

  ans = sum(w)
  diff = 0
  
  do t = 1, n-1
    s1 = sum(w(1:t))
    s2 = sum(w(t+1:n))
    diff = abs(s1-s2)
    if (ans>diff) ans = diff
  enddo

  print *, ans

end program abc129b

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
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"

@_QFEw.0 = internal unnamed_addr global ptr null
@_QFEw.8 = internal unnamed_addr global i64 0
@_QQcl.978d35ed4403755e10a4192cc9ea7b4f = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4092/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.978d35ed4403755e10a4192cc9ea7b4f, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEw.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEw.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.978d35ed4403755e10a4192cc9ea7b4f, i32 8)
  %.unpack = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %.unpack213.unpack.unpack215 = load i64, ptr @_QFEw.8, align 8, !tbaa !7
  %12 = call i64 @llvm.smax.i64(i64 %.unpack213.unpack.unpack215, i64 0)
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %12, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %13 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %.unpack218 = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %.unpack225.unpack.unpack227 = load i64, ptr @_QFEw.8, align 8, !tbaa !7
  %15 = icmp sgt i64 %.unpack225.unpack.unpack227, 0
  br i1 %15, label %.lr.ph.i.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i64 %.unpack225.unpack.unpack227, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader341, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack225.unpack.unpack227, -8
  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> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %vec.phi293 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %16 = shl i64 %index, 2
  %17 = getelementptr i8, ptr %.unpack218, i64 %16
  %wide.load = load <4 x i32>, ptr %17, align 4, !tbaa !3
  %18 = getelementptr i32, ptr %17, i64 4
  %wide.load294 = load <4 x i32>, ptr %18, align 4, !tbaa !3
  %19 = add <4 x i32> %wide.load, %vec.phi
  %20 = add <4 x i32> %wide.load294, %vec.phi293
  %index.next = add nuw i64 %index, 8
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %20, %19
  %22 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack225.unpack.unpack227, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader341

.lr.ph.i.preheader341:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph342 = phi i32 [ 0, %.lr.ph.i.preheader ], [ %22, %middle.block ]
  %.ph343 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader341, %.lr.ph.i
  %23 = phi i32 [ %28, %.lr.ph.i ], [ %.ph342, %.lr.ph.i.preheader341 ]
  %24 = phi i64 [ %29, %.lr.ph.i ], [ %.ph343, %.lr.ph.i.preheader341 ]
  %25 = shl i64 %24, 2
  %26 = getelementptr i8, ptr %.unpack218, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !3
  %28 = add i32 %27, %23
  %29 = add nuw nsw i64 %24, 1
  %exitcond.not.i = icmp eq i64 %29, %.unpack225.unpack.unpack227
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %0
  %.lcssa.i = phi i32 [ 0, %0 ], [ %22, %middle.block ], [ %28, %.lr.ph.i ]
  %30 = load i32, ptr %2, align 4, !tbaa !3
  %31 = add i32 %30, -1
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %33 = zext i32 %31 to i64
  %34 = sext i32 %30 to i64
  br label %.lr.ph.i254.preheader

.lr.ph.i254.preheader:                            ; preds = %_FortranASumInteger4x1_contract_simplified.exit261, %.lr.ph
  %indvar = phi i32 [ %indvar.next, %_FortranASumInteger4x1_contract_simplified.exit261 ], [ 0, %.lr.ph ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %_FortranASumInteger4x1_contract_simplified.exit261 ], [ 1, %.lr.ph ]
  %.0285 = phi i32 [ %spec.select, %_FortranASumInteger4x1_contract_simplified.exit261 ], [ %.lcssa.i, %.lr.ph ]
  %35 = add i32 %indvar, 1
  %smax312 = call i32 @llvm.smax.i32(i32 %35, i32 0)
  %36 = zext i32 %smax312 to i64
  %37 = add i32 %indvar, 2
  %38 = sext i32 %37 to i64
  %39 = sub nsw i64 %34, %38
  %smax = call i64 @llvm.smax.i64(i64 %39, i64 -1)
  %40 = add nsw i64 %smax, 1
  %41 = trunc i64 %indvars.iv to i32
  %42 = call i32 @llvm.smax.i32(i32 %41, i32 0)
  %43 = zext i32 %42 to i64
  %min.iters.check315 = icmp ult i32 %smax312, 8
  br i1 %min.iters.check315, label %.lr.ph.i254.preheader332, label %vector.ph316

vector.ph316:                                     ; preds = %.lr.ph.i254.preheader
  %n.vec318 = and i64 %36, 2147483640
  br label %vector.body321

vector.body321:                                   ; preds = %vector.body321, %vector.ph316
  %index322 = phi i64 [ 0, %vector.ph316 ], [ %index.next327, %vector.body321 ]
  %vec.phi323 = phi <4 x i32> [ zeroinitializer, %vector.ph316 ], [ %47, %vector.body321 ]
  %vec.phi324 = phi <4 x i32> [ zeroinitializer, %vector.ph316 ], [ %48, %vector.body321 ]
  %44 = shl i64 %index322, 2
  %45 = getelementptr i8, ptr %.unpack218, i64 %44
  %wide.load325 = load <4 x i32>, ptr %45, align 4, !tbaa !3
  %46 = getelementptr i32, ptr %45, i64 4
  %wide.load326 = load <4 x i32>, ptr %46, align 4, !tbaa !3
  %47 = add <4 x i32> %wide.load325, %vec.phi323
  %48 = add <4 x i32> %wide.load326, %vec.phi324
  %index.next327 = add nuw i64 %index322, 8
  %49 = icmp eq i64 %index.next327, %n.vec318
  br i1 %49, label %middle.block313, label %vector.body321, !llvm.loop !13

middle.block313:                                  ; preds = %vector.body321
  %bin.rdx328 = add <4 x i32> %48, %47
  %50 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx328)
  %cmp.n320 = icmp eq i64 %n.vec318, %36
  br i1 %cmp.n320, label %_FortranASumInteger4x1_contract_simplified.exit257, label %.lr.ph.i254.preheader332

.lr.ph.i254.preheader332:                         ; preds = %.lr.ph.i254.preheader, %middle.block313
  %.ph333 = phi i32 [ 0, %.lr.ph.i254.preheader ], [ %50, %middle.block313 ]
  %.ph334 = phi i64 [ 0, %.lr.ph.i254.preheader ], [ %n.vec318, %middle.block313 ]
  br label %.lr.ph.i254

.lr.ph.i254:                                      ; preds = %.lr.ph.i254.preheader332, %.lr.ph.i254
  %51 = phi i32 [ %56, %.lr.ph.i254 ], [ %.ph333, %.lr.ph.i254.preheader332 ]
  %52 = phi i64 [ %57, %.lr.ph.i254 ], [ %.ph334, %.lr.ph.i254.preheader332 ]
  %53 = shl i64 %52, 2
  %54 = getelementptr i8, ptr %.unpack218, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !3
  %56 = add i32 %55, %51
  %57 = add nuw nsw i64 %52, 1
  %exitcond.not.i255 = icmp eq i64 %57, %43
  br i1 %exitcond.not.i255, label %_FortranASumInteger4x1_contract_simplified.exit257, label %.lr.ph.i254, !llvm.loop !14

_FortranASumInteger4x1_contract_simplified.exit257: ; preds = %.lr.ph.i254, %middle.block313
  %.lcssa = phi i32 [ %50, %middle.block313 ], [ %56, %.lr.ph.i254 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext = shl i64 %indvars.iv.next, 32
  %58 = ashr exact i64 %sext, 32
  %59 = add nsw i64 %58, -1
  %60 = sub nsw i64 %34, %58
  %61 = call i64 @llvm.smax.i64(i64 %60, i64 -1)
  %62 = getelementptr i32, ptr %.unpack218, i64 %59
  %.not282 = icmp slt i64 %60, 0
  br i1 %.not282, label %_FortranASumInteger4x1_contract_simplified.exit261, label %.lr.ph.i258.preheader

.lr.ph.i258.preheader:                            ; preds = %_FortranASumInteger4x1_contract_simplified.exit257
  %min.iters.check297 = icmp ult i64 %40, 8
  br i1 %min.iters.check297, label %.lr.ph.i258.preheader330, label %vector.ph298

vector.ph298:                                     ; preds = %.lr.ph.i258.preheader
  %n.vec300 = and i64 %40, -8
  br label %vector.body303

vector.body303:                                   ; preds = %vector.body303, %vector.ph298
  %index304 = phi i64 [ 0, %vector.ph298 ], [ %index.next309, %vector.body303 ]
  %vec.phi305 = phi <4 x i32> [ zeroinitializer, %vector.ph298 ], [ %66, %vector.body303 ]
  %vec.phi306 = phi <4 x i32> [ zeroinitializer, %vector.ph298 ], [ %67, %vector.body303 ]
  %63 = shl i64 %index304, 2
  %64 = getelementptr i8, ptr %62, i64 %63
  %wide.load307 = load <4 x i32>, ptr %64, align 4, !tbaa !3
  %65 = getelementptr i32, ptr %64, i64 4
  %wide.load308 = load <4 x i32>, ptr %65, align 4, !tbaa !3
  %66 = add <4 x i32> %wide.load307, %vec.phi305
  %67 = add <4 x i32> %wide.load308, %vec.phi306
  %index.next309 = add nuw i64 %index304, 8
  %68 = icmp eq i64 %index.next309, %n.vec300
  br i1 %68, label %middle.block295, label %vector.body303, !llvm.loop !15

middle.block295:                                  ; preds = %vector.body303
  %bin.rdx310 = add <4 x i32> %67, %66
  %69 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx310)
  %cmp.n302 = icmp eq i64 %40, %n.vec300
  br i1 %cmp.n302, label %_FortranASumInteger4x1_contract_simplified.exit261, label %.lr.ph.i258.preheader330

.lr.ph.i258.preheader330:                         ; preds = %.lr.ph.i258.preheader, %middle.block295
  %.ph = phi i32 [ 0, %.lr.ph.i258.preheader ], [ %69, %middle.block295 ]
  %.ph331 = phi i64 [ 0, %.lr.ph.i258.preheader ], [ %n.vec300, %middle.block295 ]
  br label %.lr.ph.i258

.lr.ph.i258:                                      ; preds = %.lr.ph.i258.preheader330, %.lr.ph.i258
  %70 = phi i32 [ %75, %.lr.ph.i258 ], [ %.ph, %.lr.ph.i258.preheader330 ]
  %71 = phi i64 [ %76, %.lr.ph.i258 ], [ %.ph331, %.lr.ph.i258.preheader330 ]
  %72 = shl i64 %71, 2
  %73 = getelementptr i8, ptr %62, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !3
  %75 = add i32 %74, %70
  %76 = add nuw nsw i64 %71, 1
  %exitcond.not.i259 = icmp eq i64 %71, %61
  br i1 %exitcond.not.i259, label %_FortranASumInteger4x1_contract_simplified.exit261, label %.lr.ph.i258, !llvm.loop !16

_FortranASumInteger4x1_contract_simplified.exit261: ; preds = %.lr.ph.i258, %middle.block295, %_FortranASumInteger4x1_contract_simplified.exit257
  %.lcssa.i260 = phi i32 [ 0, %_FortranASumInteger4x1_contract_simplified.exit257 ], [ %69, %middle.block295 ], [ %75, %.lr.ph.i258 ]
  %77 = sub i32 %.lcssa, %.lcssa.i260
  %78 = call i32 @llvm.abs.i32(i32 %77, i1 false)
  %spec.select = call i32 @llvm.smin.i32(i32 %.0285, i32 %78)
  %exitcond.not = icmp eq i64 %indvars.iv, %33
  %indvar.next = add i32 %indvar, 1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.i254.preheader

._crit_edge:                                      ; preds = %_FortranASumInteger4x1_contract_simplified.exit261, %_FortranASumInteger4x1_contract_simplified.exit
  %.0.lcssa = phi i32 [ %.lcssa.i, %_FortranASumInteger4x1_contract_simplified.exit ], [ %spec.select, %_FortranASumInteger4x1_contract_simplified.exit261 ]
  %79 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.978d35ed4403755e10a4192cc9ea7b4f, i32 20)
  %80 = call i1 @_FortranAioOutputInteger32(ptr %79, i32 %.0.lcssa)
  %81 = call i32 @_FortranAioEndIoStatement(ptr %79)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !11, !10}
!15 = distinct !{!15, !10, !11}
!16 = distinct !{!16, !11, !10}
