local function dist(p1,p2)
  local d=0
  for i=1,#p1 do
    d=d+(p1[i]-p2[i])*(p1[i]-p2[i])
  end
  return math.sqrt(d)
end

local nd={}
for s in io.read():gmatch("%d+") do
  nd[#nd+1]=tonumber(s)
end
local N,D=unpack(nd)

local X={}
for i=1,N do
  X[i]={}
  for s in io.read():gmatch("%d+") do
    X[i][#X[i]+1]=tonumber(s)
  end
end

local count=0
for i=1,N-1 do
  for j=i+1,N do
    local d=dist(X[i],X[j])
    if(d%1==0)then count=count+1 end
  end
end

print(count)