#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
bool isPowerOfTwo(ll x) {
  ll tmp = sqrt(x);
  return (tmp * tmp == x);
}
int main() {
  ll N, D;
  cin >> N >> D;
  vector<vector<ll>> xd(N);
  for (auto&& t : xd) {
    for (ll i = 0; i < D; ++i) {
      ll x;
      cin >> x;
      t.push_back(x);
    }
  }
  auto calc_dist = [&](ll i, ll j) {
    ll ret = 0;
    for (ll p = 0; p < xd[i].size(); ++p) {
      ll tmp = xd[i][p] - xd[j][p];
      ret += (tmp * tmp);
    }
    return isPowerOfTwo(ret);
  };
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < N; ++j) {
      if (i < j) {
        if (calc_dist(i, j)) ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
