N, D = gets.split.map &:to_i
X = $<.map{|s|
  s.split.map &:to_i
}

p X.combination(2).count{|a, b|
  sq = a.zip(b).map{|y, z|
    (y - z) ** 2
  }.inject:+
  sqrt = sq ** 0.5
  sqrt.floor ** 2 == sq
}