# frozen_string_literal: true

n, d = gets.split.map(&:to_i)
x = []
n.times { x << gets.split.map(&:to_i) }

puts [*0...n].combination(2).count { |i|
  tmp = Math.sqrt(Array.new(d) { |j| (x[i[0]][j] - x[i[1]][j])**2 }.inject(:+))
  tmp.to_i == tmp
}