import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;
	int d = read.to!int;
	
	long[][] xs = new long[][](n, d);
	foreach(i; 0 .. n) foreach(k; 0 .. d){
		xs[i][k] = read.to!long;
	}
	
	int ans = 0;
	foreach(i; 0 .. n) foreach(j; 0 .. i){
		long u2;
		foreach(k; 0 .. d) u2 += (xs[i][k] - xs[j][k] ) * (xs[i][k] - xs[j][k]);
		
		long u = (u2.to!real + 0.1).sqrt.to!long;
		if(u * u == u2) ans += 1;
	}
	
	ans.writeln;
	
}
