fun main(args: Array<String>) {
  val (N, D) = readInts()
  val X = (1..N).map { readInts() }
  var cnt = 0
  for (i in 0 until N - 1) {
    for (j in i + 1 until N) {
      val a = X[i]
      val b = X[j]
      var sum = 0
      for (k in 0 until D) {
        sum += (a[k] - b[k]) * (a[k] - b[k])
      }
      val d = Math.sqrt(sum.toDouble()).toInt()
      if (sum == d * d) cnt++
    }
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
