local N, D = io.read("n","n")
local X = {}
for i=1,N do
    local p = {}
    for j=1,D do
        table.insert(p, io.read("n"))
    end
    table.insert(X, p)
end
local function d(i,j)
    local sq = 0
    for k=1,D do
        sq = sq + (X[i][k] - X[j][k])^2
    end
    return math.sqrt(sq)
end
local function is_int(x)
    return x - math.floor(x) == 0
end
local ans = 0
for i=1,N-1 do
    for j=i+1, N do
        if is_int(d(i,j)) then
            ans = ans + 1
        end
    end
end
print(ans)