fun main(args: Array<String>) {
    val (N, D) = readLine()!!.split(" ").map(String::toInt)
    val X = Array(N) { readLine()!!.split(" ").map(String::toInt) }
    var ans = 0
    for (i in 0 until N) {
        for (j in i + 1 until N) {
            val d = X[i].zip(X[j]).map { Math.pow(it.first - it.second.toDouble(), 2.0) }.sum()
            if (d.isSquare()) ans++
        }
    }
    println(ans)
}

fun Double.isSquare(): Boolean {
    val s = Math.sqrt(this)
    return s == Math.round(s).toDouble()
}