def distance(p1, p2)
  squareDistance = p1.zip(p2).map { |a|
    (a[0] - a[1]) ** 2
  }.inject(0) { |dsum, d| dsum + d }
  Math.sqrt(squareDistance)
end

N, D = gets().split(" ").map(&:to_i)
points = (1..N).map { gets().split(" ").map(&:to_i) }

count = 0
(1..N).each { |i|
  ((i+1)..N).each { |j|
    d = distance(points[i - 1], points[j - 1])
    if d.to_i == d then
      count += 1
    end
  }
}

puts count
