var main = (Input) => {
    var input = Input.split("\n");
	var tmp = input[0].split(" ");
	var n = Number.parseInt(tmp[0]);
    var d = Number.parseInt(tmp[1]);
  	var count = 0;
  
  	for (var i = 0 ; i < n; i++){
      if (i === n-1) {
        var n1 = input[i+1].split(" ");
        var n2 = input[1].split(" ");
      	var arr1 = [], arr2 = [];
		 for (var k = 0; k < n1.length; k++){
         	arr1.push(Number.parseInt(n1[k]));
           arr2.push(Number.parseInt(n2[k]));
         }
      }else {
        var n1 = input[i+1].split(" ")
        var n2 = input[i+2].split(" ")
    	var arr1 = [], arr2 = [];
        for (var k = 0; k < n1.length; k++){
         	arr1.push(Number.parseInt(n1[k]));
            arr2.push(Number.parseInt(n2[k]));
         }
      }
      	var sum = 0;
      for (var j=0; j < d; j++){
        
        var sq = (arr1[j]-arr2[j])*(arr1[j]-arr2[j]);
        sum = sum + sq;
      }
      if (Number.isInteger(Math.sqrt(sum))) count++;
    }
  
  console.log(count);
    	
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));