import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, d) = in.readLine.split(" ").map(_.toInt)
  val x = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray

  var cnt = 0
  for(i <- 0 until n) {
    for(j <- i+1 until n) {
      val dist = (0 until d).map {z =>
        val v = x(i)(z) - x(j)(z)
        v * v
      }.sum


      if(math.sqrt(dist) % 1 == 0) cnt+=1
    }
  }

  println(cnt)
}