import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val d = scanner.nextInt()
    val array = Array(n, {Array(d, {0})})
    for(i in 1..n){
        for(j in 1..d)
            array[i-1][j-1] = scanner.nextInt()
    }
    var sum = 0.0
    var count = 0
    for(k in 1..n) {
        for (i in k+1..n) {
            for (j in 1..d) {
                var temp = Math.pow(Math.abs(array[k - 1][j - 1] - array[i-1][j - 1]).toDouble(), 2.0)
                sum += temp
            }
            if (Math.sqrt(sum) - Math.sqrt(sum).toInt().toDouble() === 0.0) count++;
            sum = 0.0
        }
    }
    println(count)

}