program main
	implicit none
    integer::n,t,i
    integer(8)::ans1,ans2
    integer,allocatable::a(:)
    real::ave
    read(*,*)n
    allocate(a(n))
    read(*,*)a
    ans1=0
    ans2=0
    ave=sum(a)/real(n,8)
    t=int(ave)
    do i=1,n
    	ans1=ans1+(a(i)-t)**2
    end do
    do i=1,n
    	ans2=ans2+(a(i)-(t+1))**2
    end do
    write(*,*) min(ans1,ans2)
    
    
    
    deallocate(a)
    stop
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.540b1a33e7ae2cbcbac0fced56df159c = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7949/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

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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %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.540b1a33e7ae2cbcbac0fced56df159c, i32 7)
  %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 @_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.540b1a33e7ae2cbcbac0fced56df159c, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack244.unpack.unpack246 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  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 %.unpack244.unpack.unpack246, 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
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %.unpack249 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack256.unpack.unpack258 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %14 = icmp sgt i64 %.unpack256.unpack.unpack258, 0
  br i1 %14, label %.lr.ph.i.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

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

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack256.unpack.unpack258, -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 ], [ %18, %vector.body ]
  %vec.phi314 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %15 = shl i64 %index, 2
  %16 = getelementptr i8, ptr %.unpack249, i64 %15
  %wide.load = load <4 x i32>, ptr %16, align 4, !tbaa !3
  %17 = getelementptr i32, ptr %16, i64 4
  %wide.load315 = load <4 x i32>, ptr %17, align 4, !tbaa !3
  %18 = add <4 x i32> %wide.load, %vec.phi
  %19 = add <4 x i32> %wide.load315, %vec.phi314
  %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 !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %19, %18
  %21 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack256.unpack.unpack258, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i.preheader364

.lr.ph.i.preheader364:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %21, %middle.block ]
  %.ph365 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader364, %.lr.ph.i
  %22 = phi i32 [ %27, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader364 ]
  %23 = phi i64 [ %28, %.lr.ph.i ], [ %.ph365, %.lr.ph.i.preheader364 ]
  %24 = shl i64 %23, 2
  %25 = getelementptr i8, ptr %.unpack249, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = add i32 %26, %22
  %28 = add nuw nsw i64 %23, 1
  %exitcond.not.i = icmp eq i64 %28, %.unpack256.unpack.unpack258
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit.loopexit: ; preds = %.lr.ph.i, %middle.block
  %.lcssa313 = phi i32 [ %21, %middle.block ], [ %27, %.lr.ph.i ]
  %29 = sitofp i32 %.lcssa313 to double
  br label %_FortranASumInteger4x1_contract_simplified.exit

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %_FortranASumInteger4x1_contract_simplified.exit.loopexit, %0
  %.lcssa.i = phi double [ 0.000000e+00, %0 ], [ %29, %_FortranASumInteger4x1_contract_simplified.exit.loopexit ]
  %30 = load i32, ptr %2, align 4, !tbaa !3
  %31 = sitofp i32 %30 to double
  %32 = fdiv contract double %.lcssa.i, %31
  %33 = fptrunc double %32 to float
  %34 = fptosi float %33 to i32
  %35 = sext i32 %30 to i64
  %36 = icmp sgt i32 %30, 0
  br i1 %36, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %min.iters.check318 = icmp ult i32 %30, 4
  br i1 %min.iters.check318, label %.lr.ph.preheader360, label %vector.ph319

vector.ph319:                                     ; preds = %.lr.ph.preheader
  %n.vec321 = and i64 %35, -4
  %ind.end = or i64 %n.vec321, 1
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %34, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert330 = insertelement <2 x i32> poison, i32 %34, i64 0
  %broadcast.splat331 = shufflevector <2 x i32> %broadcast.splatinsert330, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body324

vector.body324:                                   ; preds = %vector.body324, %vector.ph319
  %index325 = phi i64 [ 0, %vector.ph319 ], [ %index.next332, %vector.body324 ]
  %vec.phi326 = phi <2 x i64> [ zeroinitializer, %vector.ph319 ], [ %45, %vector.body324 ]
  %vec.phi327 = phi <2 x i64> [ zeroinitializer, %vector.ph319 ], [ %46, %vector.body324 ]
  %37 = getelementptr i32, ptr %.unpack249, i64 %index325
  %wide.load328 = load <2 x i32>, ptr %37, align 4, !tbaa !3
  %38 = getelementptr i32, ptr %37, i64 2
  %wide.load329 = load <2 x i32>, ptr %38, align 4, !tbaa !3
  %39 = sub <2 x i32> %wide.load328, %broadcast.splat
  %40 = sub <2 x i32> %wide.load329, %broadcast.splat331
  %41 = mul <2 x i32> %39, %39
  %42 = mul <2 x i32> %40, %40
  %43 = sext <2 x i32> %41 to <2 x i64>
  %44 = sext <2 x i32> %42 to <2 x i64>
  %45 = add <2 x i64> %vec.phi326, %43
  %46 = add <2 x i64> %vec.phi327, %44
  %index.next332 = add nuw i64 %index325, 4
  %47 = icmp eq i64 %index.next332, %n.vec321
  br i1 %47, label %middle.block316, label %vector.body324, !llvm.loop !13

middle.block316:                                  ; preds = %vector.body324
  %bin.rdx333 = add <2 x i64> %46, %45
  %48 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx333)
  %cmp.n323 = icmp eq i64 %n.vec321, %35
  br i1 %cmp.n323, label %.preheader, label %.lr.ph.preheader360

.lr.ph.preheader360:                              ; preds = %.lr.ph.preheader, %middle.block316
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block316 ]
  %.0297.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %48, %middle.block316 ]
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %middle.block316
  %.lcssa312 = phi i64 [ %48, %middle.block316 ], [ %67, %.lr.ph ]
  br i1 %36, label %.lr.ph299, label %._crit_edge

.lr.ph299:                                        ; preds = %.preheader
  %.neg = xor i32 %34, -1
  %min.iters.check337 = icmp ult i32 %30, 4
  br i1 %min.iters.check337, label %scalar.ph336.preheader, label %vector.ph338

vector.ph338:                                     ; preds = %.lr.ph299
  %n.vec340 = and i64 %35, -4
  %ind.end341 = or i64 %n.vec340, 1
  %broadcast.splatinsert351 = insertelement <2 x i32> poison, i32 %.neg, i64 0
  %broadcast.splat352 = shufflevector <2 x i32> %broadcast.splatinsert351, <2 x i32> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert353 = insertelement <2 x i32> poison, i32 %.neg, i64 0
  %broadcast.splat354 = shufflevector <2 x i32> %broadcast.splatinsert353, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body344

vector.body344:                                   ; preds = %vector.body344, %vector.ph338
  %index345 = phi i64 [ 0, %vector.ph338 ], [ %index.next355, %vector.body344 ]
  %vec.phi346 = phi <2 x i64> [ zeroinitializer, %vector.ph338 ], [ %57, %vector.body344 ]
  %vec.phi347 = phi <2 x i64> [ zeroinitializer, %vector.ph338 ], [ %58, %vector.body344 ]
  %49 = getelementptr i32, ptr %.unpack249, i64 %index345
  %wide.load349 = load <2 x i32>, ptr %49, align 4, !tbaa !3
  %50 = getelementptr i32, ptr %49, i64 2
  %wide.load350 = load <2 x i32>, ptr %50, align 4, !tbaa !3
  %51 = add <2 x i32> %wide.load349, %broadcast.splat352
  %52 = add <2 x i32> %wide.load350, %broadcast.splat354
  %53 = mul <2 x i32> %51, %51
  %54 = mul <2 x i32> %52, %52
  %55 = sext <2 x i32> %53 to <2 x i64>
  %56 = sext <2 x i32> %54 to <2 x i64>
  %57 = add <2 x i64> %vec.phi346, %55
  %58 = add <2 x i64> %vec.phi347, %56
  %index.next355 = add nuw i64 %index345, 4
  %59 = icmp eq i64 %index.next355, %n.vec340
  br i1 %59, label %middle.block335, label %vector.body344, !llvm.loop !14

middle.block335:                                  ; preds = %vector.body344
  %bin.rdx356 = add <2 x i64> %58, %57
  %60 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx356)
  %cmp.n343 = icmp eq i64 %n.vec340, %35
  br i1 %cmp.n343, label %._crit_edge, label %scalar.ph336.preheader

scalar.ph336.preheader:                           ; preds = %.lr.ph299, %middle.block335
  %indvars.iv304.ph = phi i64 [ 1, %.lr.ph299 ], [ %ind.end341, %middle.block335 ]
  %.0226298.ph = phi i64 [ 0, %.lr.ph299 ], [ %60, %middle.block335 ]
  br label %scalar.ph336

.lr.ph:                                           ; preds = %.lr.ph.preheader360, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader360 ]
  %.0297 = phi i64 [ %67, %.lr.ph ], [ %.0297.ph, %.lr.ph.preheader360 ]
  %61 = add i64 %indvars.iv, -1
  %62 = getelementptr i32, ptr %.unpack249, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !3
  %64 = sub i32 %63, %34
  %65 = mul i32 %64, %64
  %66 = sext i32 %65 to i64
  %67 = add i64 %.0297, %66
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %35
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !15

scalar.ph336:                                     ; preds = %scalar.ph336.preheader, %scalar.ph336
  %indvars.iv304 = phi i64 [ %indvars.iv.next305, %scalar.ph336 ], [ %indvars.iv304.ph, %scalar.ph336.preheader ]
  %.0226298 = phi i64 [ %74, %scalar.ph336 ], [ %.0226298.ph, %scalar.ph336.preheader ]
  %68 = add i64 %indvars.iv304, -1
  %69 = getelementptr i32, ptr %.unpack249, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !3
  %71 = add i32 %70, %.neg
  %72 = mul i32 %71, %71
  %73 = sext i32 %72 to i64
  %74 = add i64 %.0226298, %73
  %indvars.iv.next305 = add nuw nsw i64 %indvars.iv304, 1
  %exitcond307.not = icmp eq i64 %indvars.iv304, %35
  br i1 %exitcond307.not, label %._crit_edge, label %scalar.ph336, !llvm.loop !16

._crit_edge:                                      ; preds = %scalar.ph336, %middle.block335, %_FortranASumInteger4x1_contract_simplified.exit, %.preheader
  %.0.lcssa309 = phi i64 [ %.lcssa312, %.preheader ], [ 0, %_FortranASumInteger4x1_contract_simplified.exit ], [ %.lcssa312, %middle.block335 ], [ %.lcssa312, %scalar.ph336 ]
  %.0226.lcssa = phi i64 [ 0, %.preheader ], [ 0, %_FortranASumInteger4x1_contract_simplified.exit ], [ %60, %middle.block335 ], [ %74, %scalar.ph336 ]
  %75 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.540b1a33e7ae2cbcbac0fced56df159c, i32 20)
  %76 = call i64 @llvm.smin.i64(i64 %.0.lcssa309, i64 %.0226.lcssa)
  %77 = call i1 @_FortranAioOutputInteger64(ptr %75, i64 %76)
  %78 = call i32 @_FortranAioEndIoStatement(ptr %75)
  %.unpack261 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  call void @free(ptr %.unpack261)
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 0, ptr @_QFEa.8, align 8, !tbaa !7
  %79 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { noreturn }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !10, !11}
!15 = distinct !{!15, !11, !10}
!16 = distinct !{!16, !11, !10}
