// abc133-b
object Main extends App {
  val Array(n, d) = io.StdIn.readLine.split(" ").map(_.toInt)
  val ps = for (_ <- 1 to n) yield io.StdIn.readLine.split(" ").map(_.toInt)

  def calculate_distance(arr1: Array[Int], arr2: Array[Int]): Double = {
    math.sqrt((0 until d).map(i => arr1(i) - arr2(i)).map(i => i*i).sum)
  }

  def is_integer(double: Double): Boolean =
    if (double%1==0) true else false

  def rec(target: List[Array[Int]], count: Int): Int = target match {
    case head::Nil => count
    case head::tail => {
      val matched = tail.count(p => is_integer(calculate_distance(head, p)))
      rec(tail, count+matched)
    }
  }

  val result = rec(ps.toList, 0)
  println(result)

}