object Main{

def main(args: Array[String]): Unit = {
  val arr1 = io.StdIn.readLine().split(' ')
  val N = arr1(0).toInt
  val D = arr1(1).toInt
  
  val xList = (1 to N).map{
    i =>
    val x = io.StdIn.readLine().split(' ')
    x.map(_.toInt)
  }
  
  val bool = (0 until N - 1).map{
    i =>
    (i + 1 until N).map{
      j => 
      val x1 = xList(i)
      val x2 = xList(j)
      
      val dist2 = (0 until D).map{
        k => 
        (x1(k) - x2(k)) * (x1(k) - x2(k))
      }.sum
      
      val dist = math.sqrt(dist2)
      if(math.floor(dist) == math.ceil(dist)) {true}else{false}

    }
  }.flatten.filter(it => it)
  
  println(bool.length)
  
}
}