Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<unsigned long long> next_p_mod(unsigned N,
                                      long long mod) { // next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++) {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n,
                          unsigned long long mod) {
  unsigned long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void comb(vector<vector<long long int>> &v, unsigned long long mod) {
  // vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]) % mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
  return modpow(a, mod - 2, mod);
}

// modinv
/*void modinv(unsigned long long N, unsigned long long mod,unsigned long long
*inv) {
 // unsigned long long inv[N] ;
  for (unsigned long long i = 1; i < N; i++) {
    inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    assert(inv[i] * i % mod == 1);
  }
  //return 0;
}*/

int main() {
  int N, D;
  ll chk = 0;
  long chk2 = 0;
  double chk3 = 0;
  unsigned long long mod = 1000000000 + 7;
  cin >> N >> D;
  int C = 0;
  vector<vector<int>> v(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> v[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = 0; k < D; k++) {
        chk += pow(v[i][k] - v[j][k], 2.0);
      }
      // cout<<chk<<" : ";
      chk2 = sqrt(chk);
      chk3 = sqrt(chk * 1.0);
      // cout<<chk<<endl;
      if (chk2 == chk3) {
        C++;
      }
      chk = 0;
    }
  }
  cout << C << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<unsigned long long> next_p_mod(unsigned N,
                                      long long mod) { // next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++) {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n,
                          unsigned long long mod) {
  unsigned long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void comb(vector<vector<long long int>> &v, unsigned long long mod) {
  // vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]) % mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
  return modpow(a, mod - 2, mod);
}

// modinv
/*void modinv(unsigned long long N, unsigned long long mod,unsigned long long
*inv) {
 // unsigned long long inv[N] ;
  for (unsigned long long i = 1; i < N; i++) {
    inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    assert(inv[i] * i % mod == 1);
  }
  //return 0;
}*/

int main() {
  int N, D;
  ll chk = 0;
  long chk2 = 0;
  double chk3 = 0;
  unsigned long long mod = 1000000000 + 7;
  cin >> N >> D;
  long C = 0;
  vector<vector<int>> v(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> v[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = 0; k < D; k++) {
        chk += pow(v[i][k] - v[j][k], 2.0);
      }
      // cout<<chk<<" : ";
      chk2 = sqrt(chk);
      chk3 = sqrt(chk * 1.0);
      // cout<<chk<<endl;
      if (chk2 == chk3) {
        C++;
      }
      chk = 0;
    }
  }
  cout << C << endl;
  return 0;
}