program kadai
integer  ::  N
integer,allocatable  ::  X(:)
integer  ::  i
integer  ::  a
integer  ::  ans1,ans2

read(*,*) N
allocate(X(N))
read(*,*) X

a=0
ans1=0
ans2=0
do i=1,N
    a=a+x(i)
end do


a=a/N
do i=1,N
    ans1=ans1+(x(i)-a)**2
    ans2=ans2+(x(i)-(a+1))**2
end do

write(*,*) min(ans1,ans2)
stop



end program kadai

; 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"

@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEx.8 = internal unnamed_addr global i64 0
@_QQcl.c91dc4e732190cd0f6d225410aded1ec = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2342/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: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %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.c91dc4e732190cd0f6d225410aded1ec, i32 8)
  %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 @_QFEx.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEx.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c91dc4e732190cd0f6d225410aded1ec, i32 10)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack159.unpack.unpack161 = load i64, ptr @_QFEx.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 %.unpack159.unpack.unpack161, 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)
  %14 = load i32, ptr %2, align 4, !tbaa !3
  %15 = sext i32 %14 to i64
  %16 = icmp sgt i32 %14, 0
  br i1 %16, label %.lr.ph, label %._crit_edge193

.lr.ph:                                           ; preds = %0
  %.unpack176 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %14, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %15, -8
  %ind.end = or i64 %n.vec, 1
  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.phi208 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %17 = getelementptr i32, ptr %.unpack176, i64 %index
  %wide.load = load <4 x i32>, ptr %17, align 4, !tbaa !3
  %18 = getelementptr i32, ptr %17, i64 4
  %wide.load209 = 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.load209, %vec.phi208
  %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 %n.vec, %15
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  %.0141188.ph = phi i32 [ 0, %.lr.ph ], [ %22, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.0141188 = phi i32 [ %26, %scalar.ph ], [ %.0141188.ph, %scalar.ph.preheader ]
  %23 = add i64 %indvars.iv, -1
  %24 = getelementptr i32, ptr %.unpack176, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !3
  %26 = add i32 %25, %.0141188
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %15
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %.lcssa207 = phi i32 [ %22, %middle.block ], [ %26, %scalar.ph ]
  %27 = sdiv i32 %.lcssa207, %14
  br i1 %16, label %.lr.ph192, label %._crit_edge193

.lr.ph192:                                        ; preds = %._crit_edge
  %.unpack164 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.neg = xor i32 %27, -1
  %min.iters.check212 = icmp ult i32 %14, 8
  br i1 %min.iters.check212, label %scalar.ph211.preheader, label %vector.ph213

vector.ph213:                                     ; preds = %.lr.ph192
  %n.vec215 = and i64 %15, -8
  %ind.end216 = or i64 %n.vec215, 1
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %27, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert228 = insertelement <4 x i32> poison, i32 %27, i64 0
  %broadcast.splat229 = shufflevector <4 x i32> %broadcast.splatinsert228, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert230 = insertelement <4 x i32> poison, i32 %.neg, i64 0
  %broadcast.splat231 = shufflevector <4 x i32> %broadcast.splatinsert230, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert232 = insertelement <4 x i32> poison, i32 %.neg, i64 0
  %broadcast.splat233 = shufflevector <4 x i32> %broadcast.splatinsert232, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body219

vector.body219:                                   ; preds = %vector.body219, %vector.ph213
  %index220 = phi i64 [ 0, %vector.ph213 ], [ %index.next234, %vector.body219 ]
  %vec.phi221 = phi <4 x i32> [ zeroinitializer, %vector.ph213 ], [ %40, %vector.body219 ]
  %vec.phi222 = phi <4 x i32> [ zeroinitializer, %vector.ph213 ], [ %41, %vector.body219 ]
  %vec.phi223 = phi <4 x i32> [ zeroinitializer, %vector.ph213 ], [ %34, %vector.body219 ]
  %vec.phi224 = phi <4 x i32> [ zeroinitializer, %vector.ph213 ], [ %35, %vector.body219 ]
  %28 = getelementptr i32, ptr %.unpack164, i64 %index220
  %wide.load226 = load <4 x i32>, ptr %28, align 4, !tbaa !3
  %29 = getelementptr i32, ptr %28, i64 4
  %wide.load227 = load <4 x i32>, ptr %29, align 4, !tbaa !3
  %30 = sub <4 x i32> %wide.load226, %broadcast.splat
  %31 = sub <4 x i32> %wide.load227, %broadcast.splat229
  %32 = mul <4 x i32> %30, %30
  %33 = mul <4 x i32> %31, %31
  %34 = add <4 x i32> %32, %vec.phi223
  %35 = add <4 x i32> %33, %vec.phi224
  %36 = add <4 x i32> %wide.load226, %broadcast.splat231
  %37 = add <4 x i32> %wide.load227, %broadcast.splat233
  %38 = mul <4 x i32> %36, %36
  %39 = mul <4 x i32> %37, %37
  %40 = add <4 x i32> %38, %vec.phi221
  %41 = add <4 x i32> %39, %vec.phi222
  %index.next234 = add nuw i64 %index220, 8
  %42 = icmp eq i64 %index.next234, %n.vec215
  br i1 %42, label %middle.block210, label %vector.body219, !llvm.loop !13

middle.block210:                                  ; preds = %vector.body219
  %bin.rdx237 = add <4 x i32> %35, %34
  %43 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx237)
  %bin.rdx235 = add <4 x i32> %41, %40
  %44 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx235)
  %cmp.n218 = icmp eq i64 %n.vec215, %15
  br i1 %cmp.n218, label %._crit_edge193, label %scalar.ph211.preheader

scalar.ph211.preheader:                           ; preds = %.lr.ph192, %middle.block210
  %indvars.iv199.ph = phi i64 [ 1, %.lr.ph192 ], [ %ind.end216, %middle.block210 ]
  %.0190.ph = phi i32 [ 0, %.lr.ph192 ], [ %44, %middle.block210 ]
  %.0140189.ph = phi i32 [ 0, %.lr.ph192 ], [ %43, %middle.block210 ]
  br label %scalar.ph211

scalar.ph211:                                     ; preds = %scalar.ph211.preheader, %scalar.ph211
  %indvars.iv199 = phi i64 [ %indvars.iv.next200, %scalar.ph211 ], [ %indvars.iv199.ph, %scalar.ph211.preheader ]
  %.0190 = phi i32 [ %53, %scalar.ph211 ], [ %.0190.ph, %scalar.ph211.preheader ]
  %.0140189 = phi i32 [ %50, %scalar.ph211 ], [ %.0140189.ph, %scalar.ph211.preheader ]
  %45 = add i64 %indvars.iv199, -1
  %46 = getelementptr i32, ptr %.unpack164, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !3
  %48 = sub i32 %47, %27
  %49 = mul i32 %48, %48
  %50 = add i32 %49, %.0140189
  %51 = add i32 %47, %.neg
  %52 = mul i32 %51, %51
  %53 = add i32 %52, %.0190
  %indvars.iv.next200 = add nuw nsw i64 %indvars.iv199, 1
  %exitcond202.not = icmp eq i64 %indvars.iv199, %15
  br i1 %exitcond202.not, label %._crit_edge193, label %scalar.ph211, !llvm.loop !14

._crit_edge193:                                   ; preds = %scalar.ph211, %middle.block210, %0, %._crit_edge
  %.0140.lcssa = phi i32 [ 0, %._crit_edge ], [ 0, %0 ], [ %43, %middle.block210 ], [ %50, %scalar.ph211 ]
  %.0.lcssa = phi i32 [ 0, %._crit_edge ], [ 0, %0 ], [ %44, %middle.block210 ], [ %53, %scalar.ph211 ]
  %54 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.c91dc4e732190cd0f6d225410aded1ec, i32 26)
  %55 = call i32 @llvm.smin.i32(i32 %.0140.lcssa, i32 %.0.lcssa)
  %56 = call i1 @_FortranAioOutputInteger32(ptr %54, i32 %55)
  %57 = call i32 @_FortranAioEndIoStatement(ptr %54)
  %58 = 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 @_FortranAioOutputInteger32(ptr, i32) 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) #2

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

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

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