#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,k,i,j;
	cin>>n>>k;
	int a[n+1][k+1];
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++){
			cin>>a[i][j];
		}
	}
	int ans=0;
	double c;
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			c=0;
			for(int kk=1;kk<=k;kk++){
				c+=(a[i][kk]-a[j][kk])*(a[i][kk]-a[j][kk]);
			}
			c=sqrt(c);
			if(int (sqrt(c*c))==c) ans++;
		}
	}
	cout<<ans;
	
	return 0;	
}