program g
  implicit none
  integer :: N,D
  integer,allocatable :: X(:,:)
  integer :: xl,yl,dx,di,pairs

  read(*,*) N,D
  allocate(X(D,N))
  read(*,*) X
  pairs=0
  do xl=1,n-1
     do yl=xl+1,n
        di=0
        do dx=1,d
           di=di+(X(dx,xl)-X(dx,yl))**2
        enddo
        if(int(sqrt(real(di)))**2.eq.di) then
           pairs=pairs+1
        endif
     enddo
  enddo
  write(*,'(i0)') pairs

end program g
