fun main(args: Array<String>) {
    val (N, D) = readLine()!!.split(" ").map { it.toInt() }
    val Xi: MutableList<List<Int>> = java.util.ArrayList()

    val values = (0..150).map { it * it }

    for (i in 1..N) {
        val line = readLine()!!.split(" ").map { it.toInt() }
        Xi.add(line)
    }

    var cnt = 0

    for (ai in 0 until N) {
        for (je in ai + 1 until N) {
            if (dist2(Xi[ai], Xi[je]) in values) cnt++
        }
    }
    println(cnt)
}

fun dist2(a: List<Int>, b: List<Int>): Int {
    var sum = 0
    for (i in 0 until a.size) {
        sum += (a[i] - b[i]) * (a[i] - b[i])
    }
    return sum
}