import kotlin.math.floor
import kotlin.math.sqrt

fun main(args: Array<String>) {
    val (n, d) = readIntList()
    val x = MutableList(n) { listOf<Int>() }
    for (i in 0 until n) {
        x[i] = readIntList()
    }

    var cnt = 0
    for (i in 0 until n) {
        for (j in i + 1 until n) {
            var tmp = 0.0
            for (k in 0 until d) {
                tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
            }
            tmp = sqrt(tmp)
            if (tmp == floor(tmp)) {
                cnt++
            }
        }
    }
    println(cnt)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)