import java.util.Scanner

var N=0
var D=0
var answer=0
val sc=Scanner(System.`in`)
fun main(args:Array<String>){
    N=sc.nextInt()
    D=sc.nextInt()
    var ary=Array(N,{Array(D,{0})})
    for(i in 0..(N-1)){
        for(j in 0..(D-1)){
            ary[i][j]=sc.nextInt()
        }
    }
    for(i in 0..(N-1)){
        for(j in 0..(i-1)){
            var tmp=0
            for(k in 0..(D-1)){
                tmp+=(ary[i][k]-ary[j][k])*(ary[i][k]-ary[j][k])
            }
            if(tmp==root(tmp)*root(tmp)){
                answer++
            }
        }
    }
    println(answer)
}

fun root(a: Int): Int {
    var a = a

    var ketasu = 0
    var tmp = a
    while (tmp > 0) {
        ketasu++
        tmp /= 10
    }
    val constant = (ketasu + 1) / 2    //よく使うので定数化
    if (ketasu >= 1) {
        val suuji = IntArray(constant)
        tmp = a
        for (i in 0 until constant) {
            suuji[constant - 1 - i] = a % 100
            a /= 100
        }
        var ans = 0
        var kai = 0
        var mae = 0
        if (constant <= 1) {
            for (i in 10 downTo 0) {
                if (suuji[0] >= i * i) {
                    return i
                }
            }
        } else {
            for (i in 0 until constant) {
                mae += kai * 2
                for (j in 9 downTo 0) {
                    if ((mae * 10 + j) * j <= suuji[i]) {
                        ans = ans * 10 + j
                        mae *= 10
                        kai = j
                        if (i + 1 < constant) {
                            suuji[i + 1] += (suuji[i] - (mae + j) * j) * 100
                        }
                        break
                    }
                }
            }
        }
        return ans
    } else {
        return 0
    }
}
