program good_distance
  implicit none
  integer :: n, d, x(10,20), m, i, j, sq, rt
  x = 0
  read(*,*) n, d
  do i = 1, n
    read(*,*) x(i,1:d)
  end do
  m = 0
  do i = 1, n-1
    do j = i+1, n
      sq = sum((x(j,1:d)-x(i,1:d))**2)
      rt = int(sqrt(real(sq,8)))
      if (rt**2.eq.sq) m = m+1
    end do
  end do
  write(*,'(i0)') m
  stop
end program good_distance