local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n, d = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = {}
  for j = 1, d do
    t[i][j] = io.read("*n")
  end
end
local cnt = 0
for i = 1, n - 1 do
  for j = i + 1, n do
    local sumsq = 0
    for k = 1, d do
      sumsq = sumsq + (t[i][k] - t[j][k]) * (t[i][k] - t[j][k])
    end
    local cand = mfl(msq(sumsq))
    if cand * cand == sumsq or (cand + 1) * (cand + 1) == sumsq then
      cnt = cnt + 1
    end
  end
end
print(cnt)
