
function Main(input) {
    var N = parseInt(input[0].split(/\s/)[0], 10);
    var D = parseInt(input[0].split(/\s/)[1], 10);
    var X = input.slice(1).map(x => {
        return x.split(/\s/).map(num => parseInt(num, 10));
    });

    var result = 0;

    for (var i = 0; i < N - 1; i++) {
        for (var j = i + 1; j < N; j++) {
            var dist = 0;
            var distSum = 0;
            for (var d = 0; d < D; d++) {
                distSum += Math.pow((X[j][d] - X[i][d]), 2);
            }
            dist = Math.sqrt(distSum);
            if (Number.isInteger(dist)) {
                result++;
            }
        }
    }
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));