program ABC133B
    implicit none
    integer::N,D,i,j,d_calc,d_sqrt,ans=0
    integer,allocatable::X(:,:)
    read*,N,D
    allocate(X(D,N))
    read*,X
    do i=1,N-1
        do j=i+1,N
            d_calc=sum((X(:,i)-X(:,j))**2)
            d_sqrt=int(sqrt(real(d_calc)))
            if(mod(d_calc,d_sqrt)==0.and.d_sqrt**2==d_calc)ans=ans+1
        end do
    end do
    print'(i0)',ans
end program ABC133B
; 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"

@_QFEans = internal unnamed_addr global i32 0
@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEx.8 = internal unnamed_addr global i64 0
@_QFEx.11 = internal unnamed_addr global i64 0
@_QQcl.69e76abf1159ecfbbaebe32fefc4348a = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3791/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [2 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.69e76abf1159ecfbbaebe32fefc4348a, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %2, align 4, !tbaa !3
  %9 = load i32, ptr %3, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %11 = zext i32 %10 to i64
  %12 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %13 = zext i32 %12 to i64
  %14 = shl nuw nsw i64 %11, 2
  %15 = mul nuw i64 %14, %13
  %16 = call ptr @malloc(i64 %15)
  store ptr %16, ptr @_QFEx.0, align 8, !tbaa !7
  store i64 %11, ptr @_QFEx.8, align 8, !tbaa !7
  store i64 %13, ptr @_QFEx.11, align 8, !tbaa !7
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.69e76abf1159ecfbbaebe32fefc4348a, i32 7)
  %.unpack = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack136.unpack.unpack139 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %.unpack136.unpack137.unpack142 = load i64, ptr @_QFEx.11, align 8, !tbaa !7
  %18 = shl i64 %.unpack136.unpack.unpack139, 2
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 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, [2 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, [2 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 2, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 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, [2 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, [2 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, [2 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, [2 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack136.unpack.unpack139, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 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
  %.fca.7.1.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 1, i64 0
  store i64 1, ptr %.fca.7.1.0.gep, align 8, !tbaa !7
  %.fca.7.1.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 1, i64 1
  store i64 %.unpack136.unpack137.unpack142, ptr %.fca.7.1.1.gep, align 8, !tbaa !7
  %.fca.7.1.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [2 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 1, i64 2
  store i64 %18, ptr %.fca.7.1.2.gep, align 8, !tbaa !7
  %19 = call i1 @_FortranAioInputDescriptor(ptr %17, ptr nonnull %1)
  %20 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %21 = load i32, ptr %3, align 4, !tbaa !3
  %22 = add i32 %21, -1
  %23 = sext i32 %22 to i64
  %24 = icmp sgt i32 %22, 0
  br i1 %24, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %25 = sext i32 %21 to i64
  %26 = add nsw i64 %25, 1
  %.unpack145 = load ptr, ptr @_QFEx.0, align 8
  %.unpack152.unpack.unpack155 = load i64, ptr @_QFEx.8, align 8
  %.unpack152.unpack.unpack155.fr = freeze i64 %.unpack152.unpack.unpack155
  %27 = call i64 @llvm.smax.i64(i64 %.unpack152.unpack.unpack155.fr, i64 0)
  %28 = shl i64 %27, 2
  %29 = icmp sgt i64 %.unpack152.unpack.unpack155.fr, 0
  br i1 %29, label %.lr.ph.split.us.split.preheader, label %._crit_edge

.lr.ph.split.us.split.preheader:                  ; preds = %.lr.ph
  %_QFEans.promoted164 = load i32, ptr @_QFEans, align 4, !tbaa !3
  %min.iters.check195 = icmp ult i64 %27, 8
  %n.vec198 = and i64 %27, 9223372036854775800
  %cmp.n200 = icmp eq i64 %27, %n.vec198
  %min.iters.check = icmp ult i64 %27, 8
  %n.vec = and i64 %27, 9223372036854775800
  %cmp.n = icmp eq i64 %27, %n.vec
  br label %.lr.ph.split.us.split

.lr.ph.split.us.split:                            ; preds = %.lr.ph.split.us.split.preheader, %._crit_edge163.split.us.us.split
  %indvars.iv175 = phi i64 [ %indvars.iv.next176, %._crit_edge163.split.us.us.split ], [ 1, %.lr.ph.split.us.split.preheader ]
  %30 = phi i32 [ %34, %._crit_edge163.split.us.us.split ], [ %_QFEans.promoted164, %.lr.ph.split.us.split.preheader ]
  %indvars.iv.next176 = add nuw nsw i64 %indvars.iv175, 1
  %sext184 = shl i64 %indvars.iv.next176, 32
  %31 = ashr exact i64 %sext184, 32
  %32 = sub nsw i64 %26, %31
  %33 = icmp sgt i64 %32, 0
  br i1 %33, label %.lr.ph162.us, label %._crit_edge163.split.us.us.split

._crit_edge163.split.us.us.split:                 ; preds = %68, %.lr.ph.split.us.split
  %34 = phi i32 [ %30, %.lr.ph.split.us.split ], [ %69, %68 ]
  %exitcond178.not = icmp eq i64 %indvars.iv175, %23
  br i1 %exitcond178.not, label %._crit_edge, label %.lr.ph.split.us.split

.lr.ph162.us:                                     ; preds = %.lr.ph.split.us.split
  %35 = trunc i64 %indvars.iv.next176 to i32
  %36 = add nsw i64 %indvars.iv175, -1
  %37 = mul i64 %36, %.unpack152.unpack.unpack155.fr
  br label %.lr.ph.us.us

.lr.ph.us.us:                                     ; preds = %68, %.lr.ph162.us
  %38 = phi i32 [ %30, %.lr.ph162.us ], [ %69, %68 ]
  %39 = phi i64 [ %32, %.lr.ph162.us ], [ %72, %68 ]
  %40 = phi i32 [ %35, %.lr.ph162.us ], [ %71, %68 ]
  %41 = phi i32 [ %30, %.lr.ph162.us ], [ %70, %68 ]
  %42 = sext i32 %40 to i64
  %43 = call ptr @malloc(i64 %28)
  %44 = add nsw i64 %42, -1
  %45 = mul i64 %44, %.unpack152.unpack.unpack155.fr
  br i1 %min.iters.check195, label %scalar.ph194.preheader, label %vector.body201

vector.body201:                                   ; preds = %.lr.ph.us.us, %vector.body201
  %index202 = phi i64 [ %index.next207, %vector.body201 ], [ 0, %.lr.ph.us.us ]
  %46 = add i64 %index202, %37
  %47 = getelementptr i32, ptr %.unpack145, i64 %46
  %wide.load203 = load <4 x i32>, ptr %47, align 4, !tbaa !3
  %48 = getelementptr i32, ptr %47, i64 4
  %wide.load204 = load <4 x i32>, ptr %48, align 4, !tbaa !3
  %49 = add i64 %index202, %45
  %50 = getelementptr i32, ptr %.unpack145, i64 %49
  %wide.load205 = load <4 x i32>, ptr %50, align 4, !tbaa !3
  %51 = getelementptr i32, ptr %50, i64 4
  %wide.load206 = load <4 x i32>, ptr %51, align 4, !tbaa !3
  %52 = sub <4 x i32> %wide.load203, %wide.load205
  %53 = sub <4 x i32> %wide.load204, %wide.load206
  %54 = mul <4 x i32> %52, %52
  %55 = mul <4 x i32> %53, %53
  %56 = getelementptr i32, ptr %43, i64 %index202
  store <4 x i32> %54, ptr %56, align 4, !tbaa !3
  %57 = getelementptr i32, ptr %56, i64 4
  store <4 x i32> %55, ptr %57, align 4, !tbaa !3
  %index.next207 = add nuw i64 %index202, 8
  %58 = icmp eq i64 %index.next207, %n.vec198
  br i1 %58, label %middle.block193, label %vector.body201, !llvm.loop !9

middle.block193:                                  ; preds = %vector.body201
  br i1 %cmp.n200, label %.lr.ph.i.us.us.preheader, label %scalar.ph194.preheader

scalar.ph194.preheader:                           ; preds = %.lr.ph.us.us, %middle.block193
  %.ph210 = phi i64 [ 0, %.lr.ph.us.us ], [ %n.vec198, %middle.block193 ]
  br label %scalar.ph194

.lr.ph.i.us.us:                                   ; preds = %.lr.ph.i.us.us.preheader208, %.lr.ph.i.us.us
  %59 = phi i32 [ %64, %.lr.ph.i.us.us ], [ %.ph, %.lr.ph.i.us.us.preheader208 ]
  %60 = phi i64 [ %65, %.lr.ph.i.us.us ], [ %.ph209, %.lr.ph.i.us.us.preheader208 ]
  %61 = shl i64 %60, 2
  %62 = getelementptr i8, ptr %43, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !3
  %64 = add i32 %63, %59
  %65 = add nuw nsw i64 %60, 1
  %exitcond.not.i.us.us = icmp eq i64 %65, %27
  br i1 %exitcond.not.i.us.us, label %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us, label %.lr.ph.i.us.us, !llvm.loop !12

66:                                               ; preds = %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us
  %67 = add i32 %41, 1
  store i32 %67, ptr @_QFEans, align 4, !tbaa !3
  br label %68

68:                                               ; preds = %66, %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us
  %69 = phi i32 [ %67, %66 ], [ %38, %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us ]
  %70 = phi i32 [ %67, %66 ], [ %41, %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us ]
  %71 = add i32 %40, 1
  %72 = add i64 %39, -1
  %73 = icmp sgt i64 %72, 0
  br i1 %73, label %.lr.ph.us.us, label %._crit_edge163.split.us.us.split

scalar.ph194:                                     ; preds = %scalar.ph194.preheader, %scalar.ph194
  %74 = phi i64 [ %83, %scalar.ph194 ], [ %.ph210, %scalar.ph194.preheader ]
  %75 = add i64 %74, %37
  %76 = getelementptr i32, ptr %.unpack145, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !3
  %78 = add i64 %74, %45
  %79 = getelementptr i32, ptr %.unpack145, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !3
  %81 = sub i32 %77, %80
  %82 = mul i32 %81, %81
  %83 = add nuw nsw i64 %74, 1
  %84 = getelementptr i32, ptr %43, i64 %74
  store i32 %82, ptr %84, align 4, !tbaa !3
  %exitcond174.not = icmp eq i64 %83, %27
  br i1 %exitcond174.not, label %.lr.ph.i.us.us.preheader, label %scalar.ph194, !llvm.loop !13

.lr.ph.i.us.us.preheader:                         ; preds = %scalar.ph194, %middle.block193
  br i1 %min.iters.check, label %.lr.ph.i.us.us.preheader208, label %vector.body

vector.body:                                      ; preds = %.lr.ph.i.us.us.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.i.us.us.preheader ]
  %vec.phi = phi <4 x i32> [ %88, %vector.body ], [ zeroinitializer, %.lr.ph.i.us.us.preheader ]
  %vec.phi191 = phi <4 x i32> [ %89, %vector.body ], [ zeroinitializer, %.lr.ph.i.us.us.preheader ]
  %85 = shl i64 %index, 2
  %86 = getelementptr i8, ptr %43, i64 %85
  %wide.load = load <4 x i32>, ptr %86, align 4, !tbaa !3
  %87 = getelementptr i32, ptr %86, i64 4
  %wide.load192 = load <4 x i32>, ptr %87, align 4, !tbaa !3
  %88 = add <4 x i32> %wide.load, %vec.phi
  %89 = add <4 x i32> %wide.load192, %vec.phi191
  %index.next = add nuw i64 %index, 8
  %90 = icmp eq i64 %index.next, %n.vec
  br i1 %90, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %89, %88
  %91 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us, label %.lr.ph.i.us.us.preheader208

.lr.ph.i.us.us.preheader208:                      ; preds = %.lr.ph.i.us.us.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.us.us.preheader ], [ %91, %middle.block ]
  %.ph209 = phi i64 [ 0, %.lr.ph.i.us.us.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i.us.us

_FortranASumInteger4x1_contract_simplified.exit.loopexit.us.us: ; preds = %.lr.ph.i.us.us, %middle.block
  %.lcssa = phi i32 [ %91, %middle.block ], [ %64, %.lr.ph.i.us.us ]
  call void @free(ptr nonnull %43)
  %92 = sitofp i32 %.lcssa to float
  %93 = call contract float @llvm.sqrt.f32(float %92)
  %94 = fptosi float %93 to i32
  %95 = srem i32 %.lcssa, %94
  %96 = icmp eq i32 %95, 0
  %97 = mul i32 %94, %94
  %98 = icmp eq i32 %97, %.lcssa
  %99 = and i1 %96, %98
  br i1 %99, label %66, label %68

._crit_edge:                                      ; preds = %._crit_edge163.split.us.us.split, %.lr.ph, %0
  %100 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.69e76abf1159ecfbbaebe32fefc4348a, i32 15)
  %101 = load i32, ptr @_QFEans, align 4, !tbaa !3
  %102 = call i1 @_FortranAioOutputInteger32(ptr %100, i32 %101)
  %103 = call i32 @_FortranAioEndIoStatement(ptr %100)
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #2

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, !10}
!14 = distinct !{!14, !10, !11}
