/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3 2
1 2
5 5
-2 8
---+/
/+---test
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3
---+/
/+---test
5 1
1
2
3
4
5
---+/

void main(string[] args) {
  long N, D;
  readf(" %d %d ", &N, &D);

  long[][] pts;
  pts.length = N;
  foreach (ref pt; pts) {
    pt = readln.split.map!(to!long).array;
  }

  long ans;
  foreach (i; 0..N) {
    foreach (j; i+1..N) {
      long distpow;
      foreach (k; 0..D) {
        distpow += pow(pts[i][k] - pts[j][k], 2);
      }
      ans += !!(distpow.to!double.sqrt.to!long.pow(2) == distpow);
    }
  }
  ans.writeln;
}
