str = gets.split
N,D = str[0].to_i, str[1].to_i
r = Array.new(N){Array.new(D)}
for x in 0...N do
    str = gets.split
    for y in 0...D do
        r[x][y] = str[y].to_i
    end
end

answer = 0
a = 0
for x in 0...N-1 do
    for y in x+1...N do
        a = 0
        for z in 0...D do
            a += (r[x][z] - r[y][z]) ** 2
        end
        i = 1
        while i*i <= a
            if i*i == a
                answer += 1
            end
            i += 1
        end
    end
end

puts answer