integer::squarecheck(0:16000)
integer N,D
integer,allocatable,dimension(:,:)::X
integer preans,ans

squarecheck=0
do i=0,200
  if(i*i>16000)exit
  squarecheck(i*i)=1
end do

read*,N,D
allocate(X(N,D))
do i=1,N
  READ*,X(i,:)
end do

ans=0
do i=1,n-1
  do j=i+1,N
    preans=0
    do jj=1,D
      preans=preans+(X(i,jj)-X(j,jj))*(X(i,jj)-X(j,jj))
    end do
    if(squarecheck(preans)==1)ans=ans+1
  end do
end do

print"(i0)",ans
end