unittest
{
	assert( [ "3 2", "1 2", "5 5", "-2 8" ].parse.expand.solve == 1 );
	assert( [ "3 4", "-3 7 8 2", "-12 1 10 2", "-2 8 9 3" ].parse.expand.solve == 2 );
	assert( [ "5 1", "1", "2", "3", "4", "5" ].parse.expand.solve == 10 );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nd = input.front.split.to!( long[] );
	auto xss = new long[][]( nd[ 0 ], nd[ 1 ] );
	foreach( ref xs; xss )
	{
		input.popFront;
		xs = input.front.split.to!( long[] );
	}
	return tuple( xss );
}

auto solve( long[][] xss )
{
	auto ans = 0L;
	foreach( i, as; xss )
	{
		foreach( bs; xss[ i + 1 .. $ ] )
		{
			auto d = 0.0L;
			foreach( a, b; lockstep( as, bs ) )
			{
				d += ( a - b ) ^^ 2;
			}
			ans += ( d.sqrt % 1 == 0 );
		}
	}
	return ans;
}
