program main
	implicit none
	integer N, i
	integer(8) S, Sall, ans
	integer(8), allocatable :: a(:)
	read(*, *) N
	allocate(a(1: N))
	read(*, *) a(1: N)
	Sall = sum(a)
	S    = Sall
	ans  = 2d14
	do i = 1, N-1
		S   = S - a(i)
		ans = min(ans ,abs((Sall - S) - S))
	end do
	write(*, *) ans
end program main
; 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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.b77568515d412c501ee9acb4b5369d04 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7119/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.b77568515d412c501ee9acb4b5369d04, 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, 3
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b77568515d412c501ee9acb4b5369d04, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %12 = load i32, ptr %2, align 4, !tbaa !3
  %13 = call i32 @llvm.smax.i32(i32 %12, i32 0)
  %14 = zext i32 %13 to i64
  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 8, 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 10, 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 %14, 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 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %15 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %.unpack147 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack154.unpack.unpack156 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %17 = icmp sgt i64 %.unpack154.unpack.unpack156, 0
  br i1 %17, label %.lr.ph.i.preheader, label %_FortranASumInteger8x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i64 %.unpack154.unpack.unpack156, 4
  br i1 %min.iters.check, label %.lr.ph.i.preheader179, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack154.unpack.unpack156, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %21, %vector.body ]
  %vec.phi177 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %22, %vector.body ]
  %18 = shl i64 %index, 3
  %19 = getelementptr i8, ptr %.unpack147, i64 %18
  %wide.load = load <2 x i64>, ptr %19, align 8, !tbaa !3
  %20 = getelementptr i64, ptr %19, i64 2
  %wide.load178 = load <2 x i64>, ptr %20, align 8, !tbaa !3
  %21 = add <2 x i64> %wide.load, %vec.phi
  %22 = add <2 x i64> %wide.load178, %vec.phi177
  %index.next = add nuw i64 %index, 4
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %22, %21
  %24 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack154.unpack.unpack156, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i.preheader179

.lr.ph.i.preheader179:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i64 [ 0, %.lr.ph.i.preheader ], [ %24, %middle.block ]
  %.ph180 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader179, %.lr.ph.i
  %25 = phi i64 [ %30, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader179 ]
  %26 = phi i64 [ %31, %.lr.ph.i ], [ %.ph180, %.lr.ph.i.preheader179 ]
  %27 = shl i64 %26, 3
  %28 = getelementptr i8, ptr %.unpack147, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !3
  %30 = add i64 %29, %25
  %31 = add nuw nsw i64 %26, 1
  %exitcond.not.i = icmp eq i64 %31, %.unpack154.unpack.unpack156
  br i1 %exitcond.not.i, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger8x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %0
  %.lcssa.i = phi i64 [ 0, %0 ], [ %24, %middle.block ], [ %30, %.lr.ph.i ]
  %32 = load i32, ptr %2, align 4, !tbaa !3
  %33 = add i32 %32, -1
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %_FortranASumInteger8x1_contract_simplified.exit
  %35 = zext i32 %33 to i64
  %xtraiter = and i64 %35, 1
  %36 = icmp eq i32 %33, 1
  br i1 %36, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %35, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.0172 = phi i64 [ 200000000000000, %.lr.ph.preheader.new ], [ %51, %.lr.ph ]
  %.0125171 = phi i64 [ %.lcssa.i, %.lr.ph.preheader.new ], [ %47, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %37 = add nsw i64 %indvars.iv, -1
  %38 = getelementptr i64, ptr %.unpack147, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !3
  %40 = sub i64 %.0125171, %39
  %41 = shl i64 %40, 1
  %42 = sub i64 %.lcssa.i, %41
  %43 = call i64 @llvm.abs.i64(i64 %42, i1 false)
  %44 = call i64 @llvm.smin.i64(i64 %.0172, i64 %43)
  %45 = getelementptr i64, ptr %.unpack147, i64 %indvars.iv
  %46 = load i64, ptr %45, align 8, !tbaa !3
  %47 = sub i64 %40, %46
  %48 = shl i64 %47, 1
  %49 = sub i64 %.lcssa.i, %48
  %50 = call i64 @llvm.abs.i64(i64 %49, i1 false)
  %51 = call i64 @llvm.smin.i64(i64 %44, i64 %50)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph
  %52 = add nuw nsw i64 %indvars.iv, 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ undef, %.lr.ph.preheader ], [ %51, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %52, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.0172.unr = phi i64 [ 200000000000000, %.lr.ph.preheader ], [ %51, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.0125171.unr = phi i64 [ %.lcssa.i, %.lr.ph.preheader ], [ %47, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %53 = getelementptr i64, ptr %.unpack147, i64 %indvars.iv.unr
  %54 = load i64, ptr %53, align 8, !tbaa !3
  %.neg = sub i64 %54, %.0125171.unr
  %.neg185 = shl i64 %.neg, 1
  %55 = add i64 %.neg185, %.lcssa.i
  %56 = call i64 @llvm.abs.i64(i64 %55, i1 false)
  %57 = call i64 @llvm.smin.i64(i64 %.0172.unr, i64 %56)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %_FortranASumInteger8x1_contract_simplified.exit
  %.0.lcssa = phi i64 [ 200000000000000, %_FortranASumInteger8x1_contract_simplified.exit ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %57, %.lr.ph.epil ]
  %58 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.b77568515d412c501ee9acb4b5369d04, i32 16)
  %59 = call i1 @_FortranAioOutputInteger64(ptr %58, i64 %.0.lcssa)
  %60 = call i32 @_FortranAioEndIoStatement(ptr %58)
  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 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #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}
