import java.lang.Math

fun main(args: Array<String>)
{
    val (n, d) = readNInts()
    val x = Array<MutableList<Int>>(n, {mutableListOf<Int>()})
    for(i in 1..n) {
        readNInts().forEach{ x[i-1].add(it) }
    }

    var ans = 0
    for (i in 0..n-1) {
        for (k in i+1..n-1) {
            val diff = IntArray(d)
            for (m in 0..d-1) {
                diff[m] = x[i][m] - x[k][m]
            }
            val sq = DoubleArray(d)
            for (m in 0..d-1) {
                sq[m] = Math.pow(diff[m].toDouble(), 2.0)
            }

            var sum = 0.0
            for(m in 0..d-1) {
                sum += sq[m]
            }

            val dist = Math.sqrt(sum)

            ans += if ((dist - (dist.toInt() / 1).toDouble()) != 0.0) 0 else 1
        }
    }

    println(ans)
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!
