object Main extends App {
  val Array(n,d) = io.StdIn.readLine.split(" ").map(_.toInt)
  val xss = Range(0,n).map{_ => io.StdIn.readLine.split(" ").map(_.toInt).toList }
  println(Range(0,n).map{i=>
    Range(i+1,n).map{j=>
      val k = xss(i).zip(xss(j)).map{z=>(z._1-z._2)*(z._1-z._2)}.sum
      val l = math.sqrt(k).toInt
      if(l * l == k) 1 else 0
    }.sum
  }.sum)
}