import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val d = sc.nextInt()

  val x = Array(n) { Array(d) { 0 } }
  for (i in 0 until n) {
    for (j in 0 until d) {
      x[i][j] = sc.nextInt()
    }
  }

  var count = 0
  for (i in 0 until n) {
    val xi = x[i]
    for (j in i until n) {
      if (i == j) continue
      val xj = x[j]
      var sum = 0
      for (di in 0 until d) {
        val tmp = xi[di] - xj[di]
        sum += tmp * tmp
      }
      val sqrt = Math.sqrt(sum.toDouble()).toInt()
      if (sqrt * sqrt == sum) count++
    }
  }

  println(count)

}
