Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \
  type a;                                                                      \
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y) {
  if ((x == 1) || (y == 1)) {
    return 1;
  }
  if (x > y) {
    if (x % y == 0) {
      return y;
    } else {
      return gcd(y, x % y);
    }
  } else {
    if (y % x == 0) {
      return x;
    } else {
      return gcd(x, y % x);
    }
  }
}

bool sqc(int x) {
  for (int i = 0; i * i <= x; i++) {
    if (i * i == x) {
      return true;
    }
  }
  return false;
}

int main() {
  IN(int, n);
  IN(int, d);
  vi2 a(n, vi(d));
  REP(i, n) {
    REP(j, d) { cin >> a[i][j]; }
  }
  int ans = 0;
  REP(i, n - 1) {
    FOR(j, i + 1, n) {
      int sum = 0;
      REP(k, d) { sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]); }
      if (sqc(sum)) {
        ans++;
      }
    }
  }
  COUT(ans);
}


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \
  type a;                                                                      \
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y) {
  if ((x == 1) || (y == 1)) {
    return 1;
  }
  if (x > y) {
    if (x % y == 0) {
      return y;
    } else {
      return gcd(y, x % y);
    }
  } else {
    if (y % x == 0) {
      return x;
    } else {
      return gcd(x, y % x);
    }
  }
}

bool sqc(int x) {
  for (int i = 0; i * i <= x; i++) {
    if (i * i == x) {
      return true;
    }
  }
  return false;
}

int main() {
  IN(int, n);
  IN(int, d);
  vi2 a(n, vi(d));
  REP(i, n) {
    REP(j, d) { cin >> a[i][j]; }
  }
  int ans = 0;
  REP(i, n - 1) {
    FOR(j, i + 1, n) {
      int sum = 0;
      REP(k, d) { sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]); }
      if (sqc(sum)) {
        ans++;
      }
    }
  }
  COUT(ans);
}