
N, D = gets.split.map(&:to_i)
X = []
N.times do
  X << gets.split.map(&:to_i)
end

ans = 0
(0..N-1).each do |i|
  (i+1..N-1).each do |j|
    sum = 0
    D.times do |k|
      sum += (X[i][k]-X[j][k])*(X[i][k]-X[j][k])
    end

    t = Math.sqrt(sum).floor
    if (t * t == sum.to_i) == true
      ans += 1
    end
  end
end

p ans
