nd = $stdin.gets.chomp.split(" ")
nd.map! do |a_j|
    a_j.to_i
end

n = nd[0]
d = nd[1]

arr = []
n.times do
    tmp = $stdin.gets.chomp.split(" ")
    tmp.map! do |a_j|
        a_j.to_i
    end
    arr << tmp
end

def isSquare(x)
    lim = 40 * 40 * 10
    for i in 0..lim
        if x == i * i 
            return true
        end
    end
    return false
end

ans = 0
for i in 0..n-2
    for j in i + 1..n-1
        dist = 0
        for k in 0..d-1
            dist += (arr[i][k] - arr[j][k])**2
        end
        if isSquare(dist)
            ans += 1
        end
    end
end 
puts ans