n,d = gets.chomp.split(" ").map(&:to_i)
x = []

for i in 1..n do
    x.push(gets.chomp.split(" ").map(&:to_i))
end

cnt = 0

for i in 1..n-1 do
    for j in i+1..n do
        dis = 0.0
        for k in 1..d do
            dis += (x[i-1][k-1] - x[j-1][k-1]) ** 2
        end
        if Math.sqrt(dis) % 1.0 == 0.0
            cnt += 1
        end
    end
end


puts cnt