import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val d = sc.nextInt
  val xl =
    List.fill(n){
      List.fill(d)(sc.nextInt)
    }.zipWithIndex

  val sqrtList = (1 to 136).map(n => n * n)

  val res = (
      for {
        x <- xl
        y <- xl
        if x._2 != y._2
      }yield distanceSqrt(x._1,y._1)
    ).count(sqrtList.contains(_)) / 2

  println(res)


  def distanceSqrt(xl: List[Int], yl: List[Int]): Int = {
    (xl zip yl).map{case (x,y) =>
      val z = x - y
      z * z
    }.sum
  }
}
