const main = (N,D,X) => {
    var count = 0

    for(var i =0;i<N;i++) {
        for(var k=i;k<N;k++) {
            var tmp = 0

            if(i === k) {
                continue
            }

            for(var j = 0;j<D;j++) {
                const xd = Math.abs(X[i][j]-X[k][j])
                tmp+=xd*xd
            }

            for(var t = 0;t<=tmp;t++) {
                if(t*t === tmp) {
                    count++
                    break
                }
            }
        }
    }
    return count
}




const input = require('fs').readFileSync('/dev/stdin','utf8')
                           .split("\n")
                           .filter(i => i !== '')
const lst = input.map(i => i.split(" ").map(x => Number(x)))
const N = lst[0][0]
const D = lst[0][1]
const X = lst.slice(1,lst.length)
console.log(main(N,D,X))