program abc133b
  integer :: n, d, i, j, ans
  integer :: square(128) = [(i*i,i=1,128)]
  integer,dimension(:,:),allocatable :: x
  read *, n, d
  allocate(x(d,n))
  read *, x
  ans = 0
  do j = 2,n
     do i = 1,j-1
        if (sum(findloc(square,sum((x(:,i)-x(:,j))**2)))/=0) ans = ans + 1
     end do
  end do
  print *, ans
end program abc133b
