import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

bool isSquare (ulong n) {
  ulong x = sqrt (n.to!double).roundTo!ulong;
  return x * x == n;
}

void main() {
  int n, d;
  readf (" %d %d", &n, &d);
  int[][] x;
  foreach (i; 0 .. n) {
    auto y = new int[d];
    foreach (j; 0 .. d) {
      readf (" %d", &y[j]);
    }
    x ~= y;
  }
  int res;
  foreach (i; 0 .. n) {
    foreach (j; i + 1 .. n) {
      if (isSquare (iota (0, d).map! (k => (x[i][k] - x[j][k]) ^^ 2).sum)) {
        ++res;
      }
    }
  }
  writeln (res);
}

