import scala.io.StdIn

object Main extends App {
  val Array(n, d)  = StdIn.readLine().split(" ").map(_.toInt)
  var a :Array[Array[Int]] = Array.fill[Array[Int]](n)(Array.empty)
  var ans = 0
  (1 to n).foreach {i =>
    a(i - 1) =  StdIn.readLine().split(" ").map(_.toInt)
  }

  for (i <- 0 until n - 1) {
    for (j <- i + 1 to n - 1) {
      var ret = Math.sqrt((a(i) zip  a(j)).map {l => Math.pow(l._1 - l._2, 2)}.sum)
      if (ret - ret.ceil == 0) ans = ans + 1
    }
  }
  println(ans)


}
  

