import std.stdio, std.string, std.conv, std.math, std.algorithm;

void main() {
    int tmp[] = readln.split.to!(int[]);
    int n = tmp[0], d = tmp[1];
    int[][] x = new int[][](n);
    foreach (i; 0 .. n) {
        x[i] = readln.split.to!(int[]);
    }
    int[] square;
    for (int i = 1; i * i <= 16000; ++i) {
        square ~= i * i;
    }
    int cnt;
    foreach (i; 0 .. n-1) {
        foreach (j; i+1 .. n) {
            int sed;
            foreach (k; 0 .. d) {
                sed += (x[i][k] - x[j][k]) ^^ 2;
            }
            if (square.canFind(sed)) ++cnt;
        }
    }
    cnt.writeln;
}