function Main(input) {
    lines = input.split('\n')
    N = lines[0].split(' ')[0] * 1
    D = lines[0].split(' ')[1] * 1
    lines.shift()
    ans = 0
    lines = lines.map((l) => {
        return l.split(' ')
    })
    for (i = 0; i<N - 1; i++) {
        for (j = i+1; j<N; j++) {
            t = 0
            for (k =0; k < D; k++) {
                t += (lines[i][k] - lines[j][k]) * (lines[i][k] - lines[j][k])
            }
            r = Math.sqrt(t)
            if (r == parseInt(r)) {
                ans++
            }
        }           
    }
    console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));