program ABC133B
    implicit none
    integer::N,D,i,j,d_calc,d_sqrt,ans=0
    integer,allocatable::X(:,:)
    read*,N,D
    allocate(X(D,N))
    read*,X
    do i=1,N-1
        do j=i+1,N
            d_calc=sum((X(:,i)-X(:,j))**2)
            d_sqrt=int(sqrt(real(d_calc)))
            if(mod(d_calc,d_sqrt)==0.and.d_sqrt**2==d_calc)ans=ans+1
        end do
    end do
    print'(i0)',ans
end program ABC133B