line = gets.split(' ').map(&:to_i)
n = line[0]
d = line[1]

lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end
kazu = 0
for i in 0..n-1 do
  for j in 0..n-1 do
    if i == j then
      break
    end
    g = 0
    for k in 0..d-1 do
      g+=(lines[i][k]-lines[j][k])**2
    end
    g = g**0.5
    aho = g.ceil
    if g == aho then
      kazu+=1
    end
  end
end
puts kazu