process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const N = lines[0].split(' ')[0] - 0;
    const D = lines[0].split(' ')[1] - 0;
    var count = 0;
    
    if(D === 1) {
        console.log(N);
        return;
    }
    
    for(var i=1; i<=N; i++) {
        for(var j=1; j<=N; j++) {
            if(i !== j) {
                var tmpSum = 0;
                for(var k=0; k<D-1; k+=2) {
                    const y1 = lines[i].split(' ')[k];
                    const y2 = lines[j].split(' ')[k];
                    const z1 = lines[i].split(' ')[k+1];
                    const z2 = lines[j].split(' ')[k+1];
                    tmpSum += Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2);
                }
                const distinct = Math.sqrt(tmpSum);
                if((distinct * 10) % 10 === 0){
                    ++count;   
                }
            }
        }
    }
    console.log(count);
    
});
