import java.util.*

fun is_sq(n: Int): Boolean {
    val m = Math.sqrt(n.toDouble())
    val l = Math.floor(m)

    if (Math.abs(m - l) > 0.001) {
        return false
    } else {
        return true
    }
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val d = cin.nextInt()

    val a = Array<Array<Int>>(n, { Array<Int>(d, { cin.nextInt() }) })

    var ans = 0

    for (i in 0..n-2) {
        for (j in i+1..n-1) {
            var dist = 0
            for (k in 0..d-1) {
                dist += (a[i][k] - a[j][k])*(a[i][k] - a[j][k])
            }
            if (is_sq(dist)) {
                ans += 1
            }
        }
    }
    println(ans)
}