program good_distance
    integer(4)::n,d,i,j,c,y,d2
    integer(4),allocatable:: x(:,:)

    read*, n,d
    allocate(x(d,n))
    do i=1,n
        read*, x(:,i)
    end do
    c=0
    do i=1,n-1
        do j=i+1,n
            d2 = sum((x(:,i)-x(:,j))**2)
            y=0
            do while(y*y <= d2)
                if (d2 == y*y) c=c+1
                y=y+1
            end do
        end do
    end do
    print*,c
    
end program good_distance