'use strict'

function calcDistance(I, J, D) {
    let dist = 0;
    for (let d = 0; d < D; d++) {
        dist += Math.pow(I[d] - J[d], 2);
    }

    dist = Math.sqrt(dist);
    return dist;
}
function main(input) {
    const tmp = Array.from(input.split('\n'));
    const ND = tmp.shift().split(' ');
    const N = parseInt(ND[0], 10);
    const D = parseInt(ND[1], 10);

    const X = tmp.map((line) => line.split(' ').map((x) => parseInt(x, 10)));

    let count = 0;
    for (let i = 0; i < N - 1; i++) {
        for (let k = i + 1; k < N; k++) {
            if (Number.isInteger(calcDistance(X[i], X[k], D))) {
                count++;
            }
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));