      integer :: n,d
      integer,allocatable :: x(:,:)
      integer :: i,j,k, dist2,ans
      
      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
          
          dist2 = 0
          do k = 1,d
            dist2 = dist2 + ( x(i,k)-x(j,k) )**2
          end do
          
          if( dist2==int(sqrt(real(dist2)))**2 )then
            ans = ans + 1
          end if
        end do
      end do
      
      print*,ans
      end