fun main(args: Array<String>) {
  val (N, D) = readLine()!!.split(' ').map { it.toInt() }
  val points =  (1 .. N).map { readLine()!!.split(' ').map { it.toInt() } }

  val distances = (0 until N).map {i -> 
    (1 until N - i).map { j -> 
      Math.sqrt((0 until D).map { k -> 
        Math.pow(Math.abs(points[i][k] - points[i + j][k]).toDouble(), 2.0)
      }.sum())
    }
  }.flatMap { it }

  println(distances.filter { it.equals(Math.floor(it))}.size)
}