function isInteger(inVal)
    return inVal%1 ..""=="0.0"
end

N, D = io.read("*n", "*n", "*l")
X = {}
for i = 1, N do
    X[i] = {}
    for j = 1, D do
        X[i][j] = io.read("*n")
    end
end

counter = 0
for i = 1, N do
    for j = 1, N do
        if i < j then
            sum = 0
            for k = 1, D do
                sum = sum + (X[i][k] - X[j][k])^2
                if k == D and isInteger(math.sqrt(sum)) then
                    counter = counter + 1
                end
            end
        end
    end
end
print(counter)