#include <bits/stdc++.h>
using namespace std;

int main (){
	int n,d,i,j,k,y,dist,ans=0,x[20][20];
	cin >> n >> d;
	for(i=1;i<=n;i++){
		for(j=1;j<=d;j++) cin >> x[i][j];
	}
	for(i=1;i<n;i++){
		for(j=i+1;j<=n;j++){
			dist=0;
			for(k=1;k<=d;k++) dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			for(y=sqrt(dist);y<=dist;y++){
				if(y*y==dist) ans++;
				if(y*y>=dist) break;
			}
		}
	}
	cout << ans << endl;
    return 0;
}