import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto D = s[1];
    auto A = iota(N).map!(_ => readln.split.map!(to!long).array).array;
    long ans = 0;

    foreach (i; 0..N) foreach (j; i+1..N) {
        auto x = D.iota.map!(k => (A[i][k] - A[j][k])^^2).sum;
        auto sq = sqrt(x.to!real).to!long;
        if (sq * sq == x) ans += 1;
    }

    ans.writeln;
}