prithivMLmods/Coder-Stat huggingface dataset:
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
int main() {
  int n, d, a[11][11], i, j, k, count = 0, ans = 0;
  double s[50] = {0}, b[i][j];
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++) {
      cin >> a[i][j];
      b[i][j] = a[i][j];
    }
  }
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      for (k = 0; k < d; k++) {
        s[ans] = s[ans] + (pow((b[i][k] - b[j][k]), 2));
      }
      s[ans] = sqrt(s[ans]);
      if ((round(s[ans]) - (s[ans])) == 0) {
        count++;
      }
      ans++;
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int main() {
  int n, d, a[11][11], i, j, k, count = 0, ans = 0;
  double s[50] = {0}, b[11][11];
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++) {
      cin >> a[i][j];
      b[i][j] = a[i][j];
    }
  }
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      for (k = 0; k < d; k++) {
        s[ans] = s[ans] + (pow((b[i][k] - b[j][k]), 2));
      }
      s[ans] = sqrt(s[ans]);
      if ((round(s[ans]) - (s[ans])) == 0) {
        count++;
      }
      ans++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  REP(i, n) {
    REP(j, d) { cin >> x[i][j]; }
  }
  int ans = 0;
  int sum;
  REP(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      sum = 0;
      REP(k, d) { sum += pow((x[i][k] - x[j][k]), 2); }
      REP(l, 130) {
        if (sum % l == 0 && sum / l == l)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  REP(i, n) {
    REP(j, d) { cin >> x[i][j]; }
  }
  int ans = 0;
  int sum;
  REP(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      sum = 0;
      for (int k = 0; k < d; k++) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      for (int l = 0; l < 130; l++) {
        if (sum == l * l)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02982 (C++)

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  int count = 0;
  double sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < D; j++) {
      sum = 0;
      for (int k = 0; k < D; k++) {
        sum = sum + std::pow((vec.at(i).at(k) - vec.at(j).at(k)), 2);
      }
      sum = std::pow(sum, 0.5);
      if (ceil(sum) == floor(sum)) {
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  int count = 0;
  double sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum = 0;
      for (int k = 0; k < D; k++) {
        sum = sum + std::pow((vec.at(i).at(k) - vec.at(j).at(k)), 2);
      }
      sum = std::pow(sum, 0.5);
      if (ceil(sum) == floor(sum)) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p02982 (C++)

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int norm = 0;
      for (int k = 0; k < d; k++) {
        int diff = abs(x[i][k] - x[j][k]);
        norm += diff * diff;
      }

      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int norm = 0;
      for (int k = 0; k < d; k++) {
        int diff = abs(x[i][k] - x[j][k]);
        norm += diff * diff;
      }

      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}
Problem p02982 (C++)

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

long double dist(int i, int j, vector<vector<int>> p, int d) {
  long long sum = 0;
  for (int k = 0; i < d; i++)
    sum += pow(p.at(i).at(k) - p.at(j).at(k), 2);
  return sqrt(sum);
}

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> p(n, vector<int>(d));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++)
      cin >> p.at(i).at(j);
  int cnt = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (dist(i, j, p, d) == (int)dist(i, j, p, d))
        cnt++;
  cout << cnt << endl;
}

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

long double dist(int i, int j, vector<vector<int>> p, int d) {
  long long sum = 0;
  for (int k = 0; k < d; k++)
    sum += pow(p.at(i).at(k) - p.at(j).at(k), 2);
  return sqrt(sum);
}

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> p(n, vector<int>(d));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++)
      cin >> p.at(i).at(j);
  int cnt = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (dist(i, j, p, d) == (int)dist(i, j, p, d))
        cnt++;
  cout << cnt << endl;
}
Problem p02982 (C++)

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> a(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int sq = 0;
      for (int k = 0; k < d; k++) {
        int s = a.at(i).at(k) - a.at(j).at(k);
        sq += s * s;
      }
      int s = sqrt(sq) + 0.5;
      if (s * s == sq)
        ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> a(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int sq = 0;
      for (int k = 0; k < d; k++) {
        int s = a.at(i).at(k) - a.at(j).at(k);
        sq += s * s;
      }
      int s = sqrt(sq) + 0.5;
      if (s * s == sq)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

// const long long int MOD = 1000000007;
const int MOD = 1000000007;
// const int MOD = 998244353;
// const long long int MOD = 998244353;
const double EPS = 1e-8;

// int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> M;
  vector<vector<int>> v(M, vector<int>(M));
  for (auto &i : v)
    for (auto &j : i)
      cin >> j;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int box = 0;
      for (int k = 0; k < M; k++)
        box += pow(v[i][k] - v[j][k], 2);
      int bag = sqrt(box);
      if (bag * bag == box)
        K++;
    }
  }
  cout << K << endl;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

// const long long int MOD = 1000000007;
const int MOD = 1000000007;
// const int MOD = 998244353;
// const long long int MOD = 998244353;
const double EPS = 1e-8;

// int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> M;
  vector<vector<int>> v(N, vector<int>(M));
  for (auto &i : v)
    for (auto &j : i)
      cin >> j;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int box = 0;
      for (int k = 0; k < M; k++)
        box += pow(v[i][k] - v[j][k], 2);
      int bag = sqrt(box);
      if (bag * bag == box)
        K++;
    }
  }
  cout << K << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
  rep(i, n) {                                                                  \
    ll x;                                                                      \
    cin >> x;                                                                  \
    v.push_back(x);                                                            \
  }
const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  ll n, d;
  cin >> n >> d;
  double a[n][d];
  rep(i, n) {
    rep(j, d) { cin >> a[i][j]; }
  }
  int count = 0;
  double sum = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; i++) {
      for (int k = 0; k < d; k++) {
        sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      }
      if (floor(sqrt(sum)) == sqrt(sum)) {
        count++;
      }
      sum = 0;
    }
  }
  cout << count;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
  rep(i, n) {                                                                  \
    ll x;                                                                      \
    cin >> x;                                                                  \
    v.push_back(x);                                                            \
  }
const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  ll n, d;
  cin >> n >> d;
  double a[n][d];
  rep(i, n) {
    rep(j, d) { cin >> a[i][j]; }
  }
  int count = 0;
  double sum = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      rep(k, d) { sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]); }
      if (floor(sqrt(sum)) == sqrt(sum)) {
        count++;
      }
      sum = 0;
    }
  }
  cout << count;

  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define ll long long
#define pp pair<int, int>
#define v(T) vector<T>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
// int 2×10の9乗
// vector<vector<int>> a(n, vector<int>(m));
// rep(i,n) rep(j,m) cin >> a[i][j];
// cout << fixed << setprecision(10);
// int gcd(int x, int y){
// if(y==0) return x;
// return gcd(y, x%y);
//}
// sort小さい順(昇順)

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n) rep(j, d) cin >> x[i][j];
  int cnt = 0;
  rep(i, n) {
    rrep(j, n) {
      rep(k, d) {
        int dis = 0;
        dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        rep(l, 150) {
          if (dis == l * l)
            cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define ll long long
#define pp pair<int, int>
#define v(T) vector<T>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
// int 2×10の9乗
// vector<vector<int>> a(n, vector<int>(m));
// rep(i,n) rep(j,m) cin >> a[i][j];
// cout << fixed << setprecision(10);
// int gcd(int x, int y){
// if(y==0) return x;
// return gcd(y, x%y);
//}
// sort小さい順(昇順)

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n) rep(j, d) cin >> x[i][j];
  int cnt = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      int dis = 0;
      rep(k, d) { dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); }
      rep(l, 150) {
        if (dis == l * l)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \
  ifstream in("atcoder-problems/abc133_b.txt");                                \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \
  rep(l, v.size()) { cout << v[l] << " "; }                                    \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, D;
  cin >> N >> D;

  vector<vector<int>> x(N, vector<int>(N, 0));
  rep(i, N) rep(j, D) { cin >> x[i][j]; }

  ll ans = 0;
  rep(i, N - 1) repi(j, i + 1, N) {
    int tmp = 0;
    rep(k, D) { tmp += pow(x[i][k] - x[j][k], 2); }
    int dis = sqrt(tmp);
    ans += pow(dis, 2) == tmp;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \
  ifstream in("atcoder-problems/abc133_b.txt");                                \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \
  rep(l, v.size()) { cout << v[l] << " "; }                                    \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, D;
  cin >> N >> D;

  vector<vector<int>> x(N, vector<int>(D, 0));
  rep(i, N) rep(j, D) { cin >> x[i][j]; }

  ll ans = 0;
  rep(i, N - 1) repi(j, i + 1, N) {
    int tmp = 0;
    rep(k, D) { tmp += pow(x[i][k] - x[j][k], 2); }
    int dis = sqrt(tmp);
    ans += pow(dis, 2) == tmp;
  }

  cout << ans << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA                                         \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define fr first
#define se second
signed main() {
  CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, d;
  cin >> n >> d;
  vector<vector<int>> v;
  for (int i = 1; i <= n; i++) {
    vector<int> vec;
    for (int j = 1; j <= d; j++) {
      int tmp;
      cin >> tmp;
      vec.pb(tmp);
    }
    v.pb(vec);
  }
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      int sum = 0;
      for (int k = 0; k < d; k++) {
        sum += pow(abs(v[i][k] - v[j][k]), 2);
      }
      int u = sqrt(sum);
      int y = ceil(1.0 * sqrt(sum));
      if (u == y) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA                                         \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define fr first
#define se second
signed main() {
  CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;

  int n, d;
  cin >> n >> d;
  vector<vector<int>> v;
  for (int i = 1; i <= n; i++) {
    vector<int> vec;
    for (int j = 1; j <= d; j++) {
      int tmp;
      cin >> tmp;
      vec.pb(tmp);
    }
    v.pb(vec);
  }
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      int sum = 0;
      for (int k = 0; k < d; k++) {
        sum += pow(abs(v[i][k] - v[j][k]), 2);
      }
      int u = sqrt(sum);
      int y = ceil(1.0 * sqrt(sum));
      if (u == y) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long ll;

using namespace std;

int ans;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, D;
  cin >> N >> D;

  vector<vector<int>> X(N, vector<int>(N));
  rep(i, N) {
    rep(j, D) { cin >> X[i][j]; }
  }

  rep(i, N) {
    repk(j, i + 1, N) {
      double d = 0;
      rep(k, D) { d += pow(X[i][k] - X[j][k], 2); }
      d = sqrt(d);
      if (d == floor(d)) {
        // cout << i << " " << j << endl;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long ll;

using namespace std;

int ans;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, D;
  cin >> N >> D;

  vector<vector<int>> X(N, vector<int>(D));
  rep(i, N) {
    rep(j, D) { cin >> X[i][j]; }
  }

  rep(i, N) {
    repk(j, i + 1, N) {
      double d = 0;
      rep(k, D) { d += pow(X[i][k] - X[j][k], 2); }
      d = sqrt(d);
      if (d == floor(d)) {
        // cout << i << " " << j << endl;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02982 (C++)

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      int norm = 0;
      for (int k = 0; k < D; k++) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int norm = 0;
      for (int k = 0; k < D; k++) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll MOD = 1000000007;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> vec[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ll a = 0;
      for (int k = 0; k < D; i++) {
        a += (vec[i][k] - vec[j][k]) * (vec[i][k] - vec[j][k]);
      }
      for (int b = 0; b < 200; b++) {
        if (a == b * b) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}


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

using ll = long long;
const ll MOD = 1000000007;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> vec[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ll a = 0;
      for (int k = 0; k < D; k++) {
        a += (vec[i][k] - vec[j][k]) * (vec[i][k] - vec[j][k]);
      }
      for (int b = 0; b < 200; b++) {
        if (a == b * b) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
  int n, d;
  cin >> n >> d;
  int a;
  bool p2[10000] = {};
  rep(i, 100) p2[i * i] = true;
  int x[n][d];
  int res = 0;
  rep(i, n) rep(j, d) cin >> x[i][j];
  rep(i, n) for (int j = i + 1; j < n; j++) {
    a = 0;
    rep(k, d) { a += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]); }
    DEBUG { cout << a << endl; }
    if (p2[a])
      res++;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
  int n, d;
  cin >> n >> d;
  int a;
  bool p2[100000] = {};
  rep(i, 300) p2[i * i] = true;
  int x[n][d];
  int res = 0;
  rep(i, n) rep(j, d) cin >> x[i][j];
  rep(i, n) for (int j = i + 1; j < n; j++) {
    a = 0;
    rep(k, d) { a += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]); }
    DEBUG { cout << a << endl; }
    if (p2[a])
      res++;
  }
  cout << res << endl;
  return 0;
}
Problem p02982 (C++)

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i, n) for (ll i = 0; i < n; i++)
#define fore(i, a, b) for (ll i = a; i <= b; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(), a.end()
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265

const ll maxn = 1e3 + 1, mod = 1e9 + 7;

int memo[maxn][maxn][2];
string a;
int n;
vector<int> alpha(26);

bool f(vector<int> a, vector<int> b) {
  ld sum = 0;
  forn(i, a.size()) {
    ll temp = a[i] - b[i];
    temp *= temp;
    sum += temp;
  }
  // cout<<sum<<endl;
  ld s = sqrt(sum);
  // cout<<fixed<<setprecision(10)<<s<<endl
  if (s - int(s) == 0)
    return true;
  return false;
}

int main() {
  sync
#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  int n, d;
  cin >> n >> d;
  vector<int> v[n];
  forn(i, n) {
    forn(j, d) {
      int x;
      cin >> x;
      v[i].pb(x);
    }
  }
  int ans = 0;
  forn(i, n) {
    fore(j, i + 1, n - 1) {
      if (f(v[i], v[j]))
        ans++;
    }
  }
  cout << ans;
  return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i, n) for (ll i = 0; i < n; i++)
#define fore(i, a, b) for (ll i = a; i <= b; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(), a.end()
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265

const ll maxn = 1e3 + 1, mod = 1e9 + 7;

int memo[maxn][maxn][2];
string a;
int n;
vector<int> alpha(26);

bool f(vector<int> a, vector<int> b) {
  ld sum = 0;
  forn(i, a.size()) {
    ll temp = a[i] - b[i];
    temp *= temp;
    sum += temp;
  }
  // cout<<sum<<endl;
  ld s = sqrt(sum);
  // cout<<fixed<<setprecision(10)<<s<<endl
  if (s - int(s) == 0)
    return true;
  return false;
}

int main() {
  sync

      int n,
      d;
  cin >> n >> d;
  vector<int> v[n];
  forn(i, n) {
    forn(j, d) {
      int x;
      cin >> x;
      v[i].pb(x);
    }
  }
  int ans = 0;
  forn(i, n) {
    fore(j, i + 1, n - 1) {
      if (f(v[i], v[j]))
        ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define pb push_back
#define int long long
#define vi vector<int>
#define len(x) (x.size())
#define f(i, a, b) for (int i = a; i < b; i++)
#define debug(x) cerr << #x << ": " << x << endl
#define T                                                                      \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  for (int t = 1; t <= tc; t++)
#define set_arr(arr, i) memset(arr, i, sizeof(arr))
using namespace std;

double distance(int points[][100], int x, int y, int d) {
  double ans = 0;
  for (int i = 0; i < d; i++) {
    ans += pow((points[x][i] - points[y][i]), 2);
  }
  return sqrt(ans);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, d;
  cin >> n >> d;
  int points[100][100];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> points[i][j];
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double dist = distance(points, i, j, d);
      if (dist - (int)(dist) == 0)
        count++;
    }
  }
  cout << count;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define pb push_back
#define int long long
#define vi vector<int>
#define len(x) (x.size())
#define f(i, a, b) for (int i = a; i < b; i++)
#define debug(x) cerr << #x << ": " << x << endl
#define T                                                                      \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  for (int t = 1; t <= tc; t++)
#define set_arr(arr, i) memset(arr, i, sizeof(arr))
using namespace std;

double distance(int points[][100], int x, int y, int d) {
  double ans = 0;
  for (int i = 0; i < d; i++) {
    ans += pow((points[x][i] - points[y][i]), 2);
  }
  return sqrt(ans);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, d;
  cin >> n >> d;
  int points[100][100];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> points[i][j];
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double dist = distance(points, i, j, d);
      if (dist - (int)(dist) == 0)
        count++;
    }
  }
  cout << count;

  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vector<vll> x(n, vll(n));
  rep(i, n) rep(j, d) { cin >> x[i][j]; }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll sum = 0;
      rep(k, d) { sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); }
      bool sq = true;
      for (int k = 2; k * k <= sum; k++) {
        ll cnt = 0;
        while (sum % k == 0) {
          sum /= k;
          cnt++;
        }
        if (cnt % 2 != 0)
          sq = false;
      }
      if (sum != 1)
        sq = false;
      if (sq)
        ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vector<vll> x(n, vll(d));
  rep(i, n) rep(j, d) { cin >> x[i][j]; }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll sum = 0;
      rep(k, d) { sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); }
      bool sq = true;
      for (int k = 2; k * k <= sum; k++) {
        ll cnt = 0;
        while (sum % k == 0) {
          sum /= k;
          cnt++;
        }
        if (cnt % 2 != 0)
          sq = false;
      }
      if (sum != 1)
        sq = false;
      if (sq)
        ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= D; j++) {
      cin >> X[i][j];
    }
  }
  int counter = 0;
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int distance = 0;

      for (int k = 1; k <= D; k++)
        distance += pow((X[i][k] - X[j][k]), 2);
      bool t = false;
      for (int l = 1; l <= 1000; l++) {
        if (distance == pow(l, 2))
          t = true;
      }
      if (t)
        counter++;
    }
  }
  cout << counter << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N, D;
  cin >> N >> D;
  int X[11][11];
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= D; j++) {
      cin >> X[i][j];
    }
  }
  int counter = 0;
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int distance = 0;

      for (int k = 1; k <= D; k++)
        distance += pow((X[i][k] - X[j][k]), 2);
      bool t = false;
      for (int l = 1; l <= 1000; l++) {
        if (distance == pow(l, 2))
          t = true;
      }
      if (t)
        counter++;
    }
  }
  cout << counter << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
  int n, d;
  cin >> n >> d;

  vector<vector<int>> x(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> x[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int sum = 0;

      for (int k = 0; k < d; ++k) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }

      bool ok = false;
      for (int k = 1; k <= sum; ++k) {
        if (k * k == sum)
          ok = true;
      }

      if (ok)
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
  int n, d;
  cin >> n >> d;

  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> x[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int sum = 0;

      for (int k = 0; k < d; ++k) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }

      bool ok = false;
      for (int k = 1; k <= sum; ++k) {
        if (k * k == sum)
          ok = true;
      }

      if (ok)
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02982 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool isSquare(int n) {
  int a = (int)sqrt(n);
  return a * a == n;
}

void solve() {
  int n, d;
  cin >> n >> d;
  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];

  int result = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int ans = 0;
      for (int k = 0; k < d; ++j) {
        ans += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
      }
      if (isSquare(ans))
        result++;
    }
  }
  cout << result << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
  }
}


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

bool isSquare(int n) {
  int a = (int)sqrt(n);
  return a * a == n;
}

void solve() {
  int n, d;
  cin >> n >> d;
  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];

  int result = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int ans = 0;
      for (int k = 0; k < d; ++k) {
        ans += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
      }
      if (isSquare(ans))
        result++;
    }
  }
  cout << result << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
  }
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

int ri() {
  int n;
  scanf("%d", &n);
  return n;
}
int64_t rll() {
  long long n;
  scanf("%lld", &n);
  return n;
}

int main() {
  int n = ri();
  int d = ri();
  int a[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      a[i][j] = ri();
  }
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      int cur = 0;
      for (int k = 0; k < d; k++)
        cur += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      int sq = sqrt(cur);
      if (sq * sq == cur)
        res++;
    }
  std::cout << res << std::endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

int ri() {
  int n;
  scanf("%d", &n);
  return n;
}
int64_t rll() {
  long long n;
  scanf("%lld", &n);
  return n;
}

int main() {
  int n = ri();
  int d = ri();
  int a[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      a[i][j] = ri();
  }
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      int cur = 0;
      for (int k = 0; k < d; k++)
        cur += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      int sq = sqrt(cur);
      if (sq * sq == cur)
        res++;
    }
  std::cout << res << std::endl;
  return 0;
}
Problem p02982 (C++)

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      int tmp = 0;
      for (int k = 0; k < N; k++) {
        int tmp2 = X.at(i).at(k) - X.at(j).at(k);
        tmp += tmp2 * tmp2;
      }
      if (sqrt(tmp) == (int)sqrt(tmp))
        ans++;
    }
  }

  cout << ans << "\n";
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      int tmp = 0;
      for (int k = 0; k < D; k++) {
        int tmp2 = X.at(i).at(k) - X.at(j).at(k);
        tmp += tmp2 * tmp2;
      }
      if (sqrt(tmp) == (int)sqrt(tmp))
        ans++;
    }
  }

  cout << ans << "\n";
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> x[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      int norm = 0;
      for (int k = 0; k < d; ++k) {
        int diff = x[i][k] - x[j][k];
        norm += diff * diff;
      }
      int s = sqrt(norm) + 0.5;
      if (s * s == norm)
        cnt++;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> x[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      int norm = 0;
      for (int k = 0; k < d; ++k) {
        int diff = x[i][k] - x[j][k];
        norm += diff * diff;
      }
      int s = sqrt(norm) + 0.5;
      if (s * s == norm)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N, D;
  cin >> N >> D;

  vector<vector<double>> point(N, vector<double>(D, 0));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> point[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < D; j++) {
      double dis = 0;
      for (int k = 0; k < D; k++) {
        dis += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
      }
      double distance = sqrt(dis);
      if (ceil(distance) == floor(distance))
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N, D;
  cin >> N >> D;

  vector<vector<double>> point(N, vector<double>(D, 0));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> point[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      double dis = 0;
      for (int k = 0; k < D; k++) {
        dis += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
      }
      double distance = sqrt(dis);
      if (ceil(distance) == floor(distance))
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using lint = int64_t;
using namespace std;

const lint mod = 2019;

int main() {
  lint L, R;
  cin >> L >> R;

  lint ans = 9e18;
  for (lint i = L; i < R; i++) {
    for (lint j = i + 1; j <= R; j++) {
      if (i >= j)
        continue;
      ans = min(ans, i * j % mod);
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using lint = int64_t;
using namespace std;

const lint mod = 2019;

int main() {
  lint L, R;
  cin >> L >> R;

  lint ans = 9e18;
  for (lint i = L; i <= min(L + 2020, R); i++) {
    for (lint j = max(L, max((lint)0, R - 2020)); j <= R; j++) {
      if (i >= j)
        continue;
      ans = min(ans, i * j % mod);
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <climits>
#include <iostream>

using namespace std;

int main() {
  long L, R;
  cin >> L >> R;
  long minimum = LONG_MAX;
  for (long i = L; i <= R; i++) {
    for (long j = i + 1; j <= R; j++) {
      if ((i * j) % 2019 < minimum) {
        minimum = (i * j) % 2019;
      }
    }
  }
  cout << minimum << endl;
  return 0;
}

Fixed submission:
#include <climits>
#include <iostream>

using namespace std;

int main() {
  long L, R;
  cin >> L >> R;
  long minimum = LONG_MAX;
  if (R - L > 2019) {
    minimum = 0;
  } else {
    for (long i = L; i <= R; i++) {
      for (long j = i + 1; j <= R; j++) {
        if ((i * j) % 2019 < minimum) {
          minimum = (i * j) % 2019;
        }
      }
    }
  }
  cout << minimum << endl;
  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int l, r;
  cin >> l >> r;

  ll result = INT_MAX;
  for (int i = l; (i < r && i <= (l + 2019)); ++i) {
    for (int j = i + 1; j <= r && j <= (j + 2019); ++j) {
      result = min(result, ((ll)i * j) % 2019);
    }
  }
  cout << result << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int l, r;
  cin >> l >> r;

  ll result = INT_MAX;
  for (int i = l; (i < r && i <= (l + 2019)); ++i) {
    for (int j = i + 1; j <= r && j <= (i + 1 + 2019); ++j) {
      result = min(result, ((ll)i * j) % 2019);
    }
  }
  cout << result << endl;

  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);
const int INF = 1001001001;

int main() {
  ll l, r;
  cin >> l >> r;
  r = min(l + 2019, r);
  ll ans = INF;
  for (ll i = l; i <= r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      i = i % 2019;
      j = j % 2019;
      ans = min(ans, (i * j) % 2019);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);
const int INF = 1001001001;

int main() {
  ll l, r;
  cin >> l >> r;
  r = min(l + 2019, r);
  ll ans = INF;
  for (ll i = l; i <= r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      // i = i%2019;
      // j = j%2019;
      ans = min(ans, (i * j) % 2019);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  unsigned int L, R;

  cin >> L >> R;

  unsigned int m = 2019;
  for (unsigned int i = L; i < R; i++) {
    for (unsigned int j = i + 1; j <= R; j++) {
      unsigned int d = ((i % 2019) * (j % 2019)) % 2019;
      if (d < m)
        m = d;
      if (m == 0)
        break;
    }
  }

  cout << m << endl << flush;

  return 0;
}


Fixed submission:
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  unsigned int L, R;

  cin >> L >> R;

  unsigned int m = 2019;
  for (unsigned int i = L; i < R && i <= L + 2019; i++) {
    for (unsigned int j = i + 1; j <= R && i <= j + 2019; j++) {
      unsigned int d = ((i % 2019) * (j % 2019)) % 2019;
      if (d < m)
        m = d;
      if (m == 0)
        break;
    }
  }

  cout << m << endl << flush;

  return 0;
}
Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
using namespace std;
int n, m, ans = 2019 * 2019;
int main() {
  cin >> n >> m;
  for (int i = n; i < m; i++)
    for (int o = i + 1; o <= m; o++)
      ans = min(ans, ((i % 2019) * (o % 2019) % 2019));
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int n, m, ans = 2019 * 2019;
int main() {
  cin >> n >> m;
  if (m - n >= 2019)
    cout << 0 << endl;
  else {
    for (int i = n; i < m; i++)
      for (int o = i + 1; o <= m; o++)
        ans = min(ans, ((i % 2019) * (o % 2019) % 2019));
    cout << ans << endl;
  }
}