// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const D = numList0[1];
    const xListList = [];
    for (var i = 0; i < N; i++) {
        var xList = input[i + 1].split(' ').map(x => parseInt(x, 10));
        xListList.push(xList);
    }

    var count = 0;
    for (var i = 0; i < N - 1; i++) {
        var xBaseList = xListList[i];
        for (var j = i + 1; j < N; j++) {
            var doubleDistance = 0;
            xTargetList = xListList[j];
            for (var k = 0; k < D; k++) {
                var y = xBaseList[k];
                var z = xTargetList[k];
                doubleDistance += (y - z) * (y - z);            
            }
            if (Number.isInteger(Math.sqrt(doubleDistance))) {
                count++;
            }
        }
    }

    console.log(count);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));