import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  auto input = readln.split.to!(int[]);
  int N = input[0], D = input[1];

  int[][] ps = new int[][N];
  foreach(ref p; ps) {
    p = readln.split.to!(int[]);
  }

  int[] tbl = new int[0];
  {
    int i = 1;
    int maxL = D * 40 * 40;
    while(i*i < maxL) { tbl ~= i*i; i++; }
  }
  auto dic = assumeSorted(tbl);

  ulong ans = 0;
  foreach(i; 0..(N-1)) {
    foreach(j; i..N) {
      int l = 0;
      foreach(k; 0..D) {
        auto a = ps[i][k] - ps[j][k];
        l += a*a;
      }
      if (dic.contains(l)) ans++;
    }
  }
  ans.writeln;
}
