alexjercan/bugnet huggingface dataset:
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
  int n, d;
  scanf("%lld%lld", &n, &d);
  int ans = 0;
  d *= d;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%lld%lld", &x, &y);
    if (x * x + y * y <= d)
      ans++;
  }
  printf("%lld\\n", ans);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
  int n, d;
  scanf("%lld%lld", &n, &d);
  int ans = 0;
  d *= d;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%lld%lld", x, y);
    if (x * x + y * y == d)
      ans++;
  }
  printf("%lld\\n", ans);
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200005];
int main() {
  long long x, d, ans = 0, sum;
  cin >> x >> d;
  for (int i = 0; i < x; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
    sum = a[i] * a[i] + b[i] * b[i];
    if (sum <= d * d)
      ans++;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long x, d, a[20005], b[20005], ans = 0, sum;
  cin >> x >> d;
  for (int i = 0; i < x; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
    sum = a[i] * a[i] + b[i] * b[i];
    if (sum <= d * d)
      ans++;
  }
  cout << ans << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  int D;
  cin >> N;
  cin >> D;
  int c = 0;
  long long z;
  long long x;
  long long y;
  for (int i = 0; i < N; i++) {
    cin >> x;
    cin >> y;
    z = x * x + y * y;
    if (sqrt(z) <= D) {
      c++;
    }
  }
  cout << c;
  return 0;
}


Error: 3

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  int D;
  cin >> N;
  cin >> D;
  int c = 0;
  int z = 0;
  int x;
  int y;
  for (int i = 0; i < N; i++) {
    cin >> x;
    cin >> y;
    z = x * x + y * y;
    if (sqrt(z) <= D) {
      c++;
    }
  }
  return c;
}
Problem p02595 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x, y, ans = 0;
  scanf("%lld%lld", &n, &d);
  d *= d;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x, y, ans = 0;
  scanf("%d%d", &n, &d);
  d *= d;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x, y, ans = 0;
  scanf("%lld", &n);
  scanf("%d", &d);
  d *= d;
  //	assert(n<=200000);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}

Error: -6
f7b4fb3e-0591-4282-8455-75f91195a32e.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02595/C++/s079580747.cpp:6: int main(): Assertion `n<=200000' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x, y, ans = 0;
  scanf("%d%lld", &n, &d);
  d *= d;
  assert(n <= 200000);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int long long N, D;
  cin >> N >> D;
  int count = 0;
  int long long a[N], b[N];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    cin >> b[i];
    if (a[i] * a[i] + b[i] * b[i] <= D * D) {
      count++;
    }
  }
  cout << count << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 1) >= this->size() (which is 1)


Fixed submission:

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

int main() {
  int N, D;
  cin >> N >> D;
  string X, Y;
  cin >> X >> Y;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (X.at(i) * X.at(i) + Y.at(i) * Y.at(i) <= D * D) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n = 0, d, x, y, ans = 0;
  scanf("%lld%lld", &n, &d);
  d *= d;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}

Error: -6
2e7052e5-f751-48ce-a569-2f7f81592616.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02595/C++/s575643548.cpp:8: int main(): Assertion `n<=200000' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d, x, y, ans = 0;
  scanf("%d", &n);
  scanf("%d", &d);
  d *= d;
  assert(n <= 200000);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    ans += (x * x + y * y <= d);
  }
  printf("%d", ans);
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <string.h>

#include <algorithm>
#include <cmath>
#include <cstdlib> // abs() for integer
#include <iostream>

using namespace std;

int main(void) {
  int N, D;
  int X[200000], Y[200000];

  cin >> N >> D;
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i];

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    long long dist_2 = (long long)X[i] * X[i] + (long long)Y[i] * Y[i];
    // cout << dist_2 << endl;

    if (dist_2 <= (long long)D * D) {
      cnt++;
    }
  }

  cout << cnt << endl;

  // cout<<template<<endl;
  return 0;
}

Error: 0

Fixed submission:

#include <string.h>

#include <algorithm>
#include <cmath>
#include <cstdlib> // abs() for integer
#include <iostream>

using namespace std;

int main(void) {
  int N, D;
  int X[200], Y[200];

  cin >> N >> D;
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i];

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    long long dist_2 = (long long)X[i] * X[i] + (long long)Y[i] * Y[i];
    // cout << dist_2 << endl;

    if (dist_2 <= (long long)D * D) {
      cnt++;
    }
  }

  cout << cnt << endl;

  // cout<<template<<endl;
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, D;
  int count = 0;
  cin >> N >> D;
  vector<vector<int>> position(N, vector<int>(2));

  for (int i = 0; i < N; i++) {
    cin >> position.at(i).at(0) >> position.at(i).at(1);

    if (sqrt(pow(position.at(i).at(0), 2) + pow(position.at(i).at(1), 2)) <= D)
      count++;
  }

  cout << count << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, D;
  int count = 0;
  cin >> N >> D;
  vector<vector<int>> position(N, vector<int>(N));

  for (int i = 0; i < N; i++) {
    cin >> position.at(i).at(0) >> position.at(i).at(1);

    if (sqrt(pow(position.at(i).at(0), 2) + pow(position.at(i).at(1), 2)) <= D)
      count++;
  }

  cout << count << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int n;
  long long d;
  int count = 0;
  long long a, b;

  cin >> n >> d;

  d *= d;

  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a * a + b * b <= d) {
      count++;
    }
  }
  cout << count;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int main() {
  int N, D;
  int X[N], Y[N];
  int count = 0;
  vector<int> a;

  cout << "N =";
  cin >> N;

  cout << "D =";
  cin >> D;

  for (int i = 0; i < N; i++) {
    cout << "X" << N << " = ";
    cin >> X[N];
    cout << "Y" << N << " = ";
    cin >> Y[N];
    cout << "\\n";
  }

  for (int i = 0; i < N; i++) {
    a.push_back(sqrt(pow(X[i], 2) + pow(Y[i], 2)));
  }

  for (int i = 0; i < N; i++) {
    if (D <= a[i]) {
      count++;
    }
  }

  cout << count;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

int main(void) {
  long double N, D;
  cin >> N >> D;

  long double x[1000000] = {0};
  long double y[10000000] = {0};

  REP(i, N) {
    cin >> x[i];
    cin >> y[i];
  }

  int ans = 0;
  REP(i, N) {
    // if(x[i]*x[i] + y[i]*y[i] <= D*D){
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= D) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

int main(void) {
  long double N, D;
  cin >> N >> D;

  long double x[100000] = {0};
  long double y[100000] = {0};

  REP(i, N) {
    cin >> x[i];
    cin >> y[i];
  }

  int ans = 0;
  REP(i, N) {
    // if(x[i]*x[i] + y[i]*y[i] <= D*D){
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= D) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace ::std;
using ll = long long;

int main(void) {
  int n;
  int count = 0;
  ll d, x, y;

  cin >> n >> d;

  for (int i = 0; i < n; i++) {
    cin >> x >> y; // x and y will be discarded after calculated
    if ((x * x + y * y) <= d * d) {
      count++;
    }
  }

  cout << count << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
using namespace ::std;

int main(void) {
  int n, d;
  int count = 0;
  double x[1024];
  double y[1024];

  cin >> n >> d;

  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (sqrt(pow(x[i], 2.0) + pow(y[i], 2.0)) <= d) {
      count++;
    }
  }

  cout << count << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

// AtCoder B - Distance
#include <bits/stdc++.h>
using namespace std;

int main() {
  long int N, D; // N個の点, 原点からの距離はD
  cin >> N >> D;
  long int count = 0;
  long int X = 0;
  long int Y = 0;

  for (int i = 0; i < N; i++) {
    cin >> X >> Y;
    if ((X * X) + (Y * Y) <= D * D) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Error: WA

Fixed submission:

// AtCoder B - Distance
#include <bits/stdc++.h>
using namespace std;

int main() {
  long int N, D; // N個の点, 原点からの距離はD
  cin >> N >> D;
  long int count = 0;
  long int calc = 0;

  vector<vector<long int>> field(N, vector<long int>(N));

  for (int i = 0; i < N; i++) {
    cin >> field.at(i).at(0) >> field.at(i).at(1);
    // cout << field.at(i).at(0) << field.at(i).at(1) << endl;
    if (D <= field.at(i).at(0) || D <= field.at(i).at(1)) {
      continue;
    }
    calc = (field.at(i).at(0) * field.at(i).at(0)) +
           (field.at(i).at(1) * field.at(i).at(1));
    // cout << calc << " " << D*D<< endl;
    if (calc <= D * D) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <math.h>
#define ll long long int
using namespace std;

int main() {
  // freopen("a.inp","r",stdin);
  ll n, d, dem = 0, m, x, y;
  cin >> n >> d;
  for (ll i = 1; i <= n; ++i) {
    cin >> x >> y;
    m = x * x + y * y;
    // cout<<sqrt(m)<<endl;
    if (sqrt(m) <= d)
      dem++;
  }
  cout << dem;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int n, d;
struct td {
  long long int x, y;
};
int main() {
  int k = 1, dem = 0;
  cin >> n >> d;
  td a[20005];
  long long int b[20005];
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = a[i].x * a[i].x + a[i].y * a[i].y;
  }
  sort(b + 1, b + n + 1);
  while (b[k] <= (d * d)) {
    dem++;
    k++;
  }
  cout << dem;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  long long N, D;
  cin >> N >> D;

  long long X[200000], Y[200000];

  for (long long i = 0; i < N; i++) {
    cin >> X[i];
    cin >> Y[i];
  }
  string s;
  // cin >> s;

  // int A[5]
  // sort(A, A + 5);
  long long a = 0;
  long double b = 0;
  long long count = 0;
  for (long long i = 0; i < N; i++) {
    a = 0;
    a = X[i] * X[i] + Y[i] * Y[i];
    b = sqrt(a);
    if (b <= D) {
      count++;
    }
  }

  if (true) {
    cout << count << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  long long N, D;
  cin >> N >> D;

  long long X[100000], Y[100000];

  for (long long i = 0; i < N; i++) {
    cin >> X[i];
    cin >> Y[i];
  }
  string s;
  // cin >> s;

  // int A[5]
  // sort(A, A + 5);
  long long a = 0;
  long double b = 0;
  long long count = 0;
  for (long long i = 0; i < N; i++) {
    a = 0;
    a = X[i] * X[i] + Y[i] * Y[i];
    b = sqrt(a);
    if (b <= D) {
      count++;
    }
  }

  if (true) {
    cout << count << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int main() {
  ll n, k;
  cin >> n >> k;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    ll x, y;
    cin >> x >> y;
    if ((x * x + y * y) <= k * k)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

// #include<iostream>
#include <bits/stdc++.h>
// #include<cmath>
using namespace std;
int count(int, int);
int main() {
  int n, d, a[100], b[100];
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  int sum = 0, j = 0;
  for (int i = 1; i <= n; i++) {
    sum = count(a[i], b[i]);
    if (sum > d || sum == d) {
      j++;
    }
  }
  cout << j << endl;
  return 0;
}
int count(int x, int y) {
  int add = 0;
  add = sqrt(x * x + y * y);
  return add;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
  long int N, D;
  scanf("%ld %ld", &N, &D);
  long int X[200000];
  long int Y[200000];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    scanf("%ld %ld", X + i, Y + i);
  }
  D = D * D;
  for (int i = 0; i < N; i++) {
    X[i] = X[i] * X[i];
    Y[i] = Y[i] * Y[i];

    if (D >= (X[i] + Y[i])) {
      cnt++;
    }
  }
  printf("%d", cnt);
  return 0;
}

Error: WA

Fixed submission:


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
  int N, D;
  scanf("%d %d", &N, &D);
  int X[200];
  int Y[200];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d %d", X + i, Y + i);
  }
  D = D * D;
  for (int i = 0; i < N; i++) {
    X[i] = X[i] * X[i];
    Y[i] = X[i] * Y[i];

    if (D >= (X[i] + Y[i])) {
      cnt++;
    }
  }
  printf("%d", cnt);
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long N, D, output = 0;
  cin >> N;
  cin >> D;

  long *X = (long *)malloc(N * sizeof(long));
  long *Y = (long *)malloc(N * sizeof(long));
  double *distances = (double *)malloc(N * sizeof(double));

  for (long i = 0; i < N; i++) {
    cin >> X[i];
    // prlongf("X[%i] = %i\\n", i, X[i]);
    cin >> Y[i];
    // prlongf("Y[%i] = %i\\n", i, Y[i]);
  }

  for (long i = 0; i < N; i++) {
    distances[i] = sqrt(pow(X[i], 2) + pow(Y[i], 2));
    // cout << (distances[i]) << endl;
    if (distances[i] <= D) {
      output++;
    }
  }

  cout << output;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long N, D, output = 0;
  cin >> N;
  cin >> D;

  long *X = (long *)malloc(N * sizeof(long));
  long *Y = (long *)malloc(N * sizeof(long));
  double *distances = (double *)malloc(N * sizeof(float));

  for (long i = 0; i < N; i++) {
    cin >> X[i];
    // prlongf("X[%i] = %i\\n", i, X[i]);
    cin >> Y[i];
    // prlongf("Y[%i] = %i\\n", i, Y[i]);
  }

  for (long i = 0; i < N; i++) {
    distances[i] = sqrt(pow(X[i], 2) + pow(Y[i], 2));
    // cout << (distances[i]) << endl;
    if (distances[i] <= D) {
      output++;
    }
  }

  cout << output;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

using namespace std;

int main() {

  int n, d;
  cin >> n >> d;
  int x[n], y[n];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (sqrt(pow(x[i], 2) + pow(y[i], 2)) <= d)
      ans++;
  }

  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {

  int n, d;
  int x[n], y[n];
  int ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    if (sqrt(pow(x[i], 2) + pow(y[i], 2)) <= d)
      ans++;
  }

  cout << ans;
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

double dist(double a, double b) { return sqrt(a * a + b * b); }

int main() {
  int N, D, res{};
  cin >> N >> D;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    if (dist(a, b) <= D)
      res++;
  }
  cout << res << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

double dist(double a, double b) { sqrt(a * a + b * b); }

int main() {
  int N, D, res{};
  cin >> N >> D;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    if (dist(a, b) <= D)
      res++;
  }
  cout << res << endl;

  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, j) for (int i = (j); i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define ssort(n) sort((n).begin(), (n).end())
#define rsort(n) sort((n).begin(), (n).end(), greater<ll>())
using ll = long long;
using ld = long double;
typedef pair<int, int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 117117117

int main() {
  int n;
  ll d;
  ll x, y;
  cin >> n >> d;
  int count = 0;
  rep(i, n) {
    cin >> x >> y;
    ll ans = x * x + y * y;
    if (ans <= d * d) {
      count++;
    }
  }
  cout << count << endl;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, j) for (int i = (j); i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define ssort(n) sort((n).begin(), (n).end())
using ll = long long;
using ld = long double;
typedef pair<int, int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main() {
  int n;
  ll d;
  vector<ll> x(n), y(n);
  cin >> n >> d;
  rep(i, n) cin >> x[i] >> y[i];
  int count = 0;
  rep(i, n) {
    if (x[i] * x[i] + y[i] * y[i] <= d * d) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll n, d;
  cin >> n >> d;
  ll x, y;
  ll count = 0;
  while (n--) {
    cin >> x >> y;
    if (x * x + y * y <= d * d)
      count++;
  }
  cout << count << "\\n";
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
// bool N[400001][400001];
int main() {
  ll n, d;
  cin >> n >> d;
  int N[400001][400001];
  memset(N, 0, sizeof(N));
  ll x, y;
  ll count = 0;
  while (n--) {
    cin >> x >> y;
    if (N[x + 200000][y + 200000] == 0) {
      N[x + 200000][y + 200000] = 1;
      if (x * x + y * y <= d * d)
        count++;
    }
  }
  cout << count << "\\n";
  return 0;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int main() {
  int N, cnt;
  double D;
  cnt = 0;
  cin >> N >> D;
  vector<vector<double>> x_y(N, vector<double>(2, 0));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> x_y.at(i).at(j);
    }
  }

  for (int i = 0; i < N; i++) {

    if (sqrt(x_y.at(i).at(0) * x_y.at(i).at(0) +
             x_y.at(i).at(1) * x_y.at(i).at(1)) <= D) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)


Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int main() {
  int N, D, cnt;
  cnt = 0;
  cin >> N >> D;
  vector<vector<double>> x_y(N / 2, vector<double>(2, 0));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> x_y.at(i).at(j);
    }
  }

  for (int i = 0; i < N; i++) {

    if (sqrt(x_y.at(i).at(0) * x_y.at(i).at(0) +
             x_y.at(i).at(1) * x_y.at(i).at(1)) <= D) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02595 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n, d;
  cin >> n >> d;
  d *= d;
  int count = 0;
  for (int i = 0; i < n; i++) {
    ll val, x, y;
    cin >> x >> y;
    val = x * x + y * y;
    if (val <= d)
      count++;
  }
  cout << count << endl;
  return 0;
}


Error: 3

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
  long long x, y, result = 0;
  int n, k;
  cin >> n >> k;
  int ans = k * k;
  int i, count = 0;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    result = x * x + y * y;

    if (result <= ans)
      count++;
  }
  return count;
}
Problem p02595 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long x, y, n, d;
  cin >> n >> d;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    double p = sqrt(x * x + y * y);
    if (p <= d) {
      count++;
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int x, y, n, d;
  cin >> n >> d;
  for (int i = 0; i <= n; i++) {
    cin >> x >> y;
    int p = sqrt(x * x + y * y);
    for (int count = 0; p <= d; count++) {
      cout << count;
    }
  }
}