#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, d, x[15][15], ans;

int main(){
	scanf("%d%d", &n, &d);
	rep(i,n){
		rep(j,d) scanf("%d", x[i]+j);
		rep(j,i){
			int dis = 0, u = 1;
			rep(k,d) dis += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			for(; u*u < dis; u++);
			if(u*u == dis) ans++;
		}
	}
	printf("%d\n", ans);
}