import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
pragma(inline, true) T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
pragma(inline, true) void scan(Args...)(ref Args args) {
    string[] ss = readln.split;
    foreach (i, ref arg ; args) arg = ss[i].parse!int;
}

int dist(int[] a, int[] b) {
    int d;
    foreach (i,j ; zip(a,b)) d += (i-j) * (i-j);
    return d;
}

bool can(int x) {
    for (int i=1;i*i<=x;i++)
        if (i * i == x) return true;
    return false;
}

void main() {
    int n, d; scan(n,d);
    auto xs = new int[][](n);
    foreach (i; 0..n)
        xs[i] = reads();

    int ans;
    foreach (i; 0..n) foreach (j; i+1..n) {
        if (can(dist(xs[i], xs[j]))) ans++;
    }
    writeln(ans);
}
