program abc133b
  implicit none
  integer :: n, d, i, j, s, ans
  integer,dimension(:,:),allocatable :: x

  read *, n, d
  allocate(x(d,n))
  read *, x
  ans = 0
  do j = 2,n
     do i = 1,j-1
        s = sum((x(:,i)-x(:,j))**2)
        If (s == nint(sqrt(dble(s)))**2) ans = ans + 1
     end do
  end do
  print *, ans
end program abc133b
