import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int d, int[][] a) {
    int ans = 0;
    for (int i = 0; i < a.length; i++) {
        for (int j = i + 1; j < a.length; j++) {
            int len = 0;
            for (int k = 0; k < d; k++) {
                len += abs(a[i][k] - a[j][k]) ^^ 2;
            }

            int p = 1;
            while (p * p <= len) {
                if (p * p == len) {
                    ans++;
                    break;
                }
                p++;
            }
        }
    }
    return ans;
}

void main() {
    int n, d; scan(n, d);
    int[][] a;
    foreach (_; 0..n) a ~= readints;

    writeln(calc(d, a));
}
