program main
  implicit none
  integer :: n, i, j, d, res
  integer, allocatable :: x(:, :)
  real(8), parameter :: eps = 1e-8
  read (*, *) n, d
  allocate (x(n, d))
  do i = 1, n
    read (*, *) x(i, :)
  end do

  res = 0
  do i = 1, n
    do j = i + 1, n
      if (abs(dist(x(i, :), x(j, :)) - nint(dist(x(i, :), x(j, :)))) < eps) res = res + 1
    end do
  end do

  write (*, "(i0)") res

  contains

  real(8) function dist(x1, x2)
    integer, intent(in) :: x1(d), x2(d)
    dist = sqrt(dble(sum((x1 - x2) ** 2)))
  end function dist
end program main
