N, D = gets.split.map(&:to_i)
X = [*0...N].map{ gets.split.map(&:to_i) }

p X.combination(2).map {|ys, zs|
    ys.zip(zs).map{|yi, zi| yi**2 - 2*yi*zi + zi**2 }.inject(0, :+)
}.map{|s| Math.sqrt(s) }.select{|v| v.to_s =~ /.*\.0$/ }.size
