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

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

#define fi first
#define se second

const int N = 100100;
const int Q = 1000100;

using namespace std;

int n;
string s[N];
int G;
int t[Q][26];
int f[Q];
bool good[Q][26];

int main() {
  ios_base::sync_with_stdio(0);

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;
  vector<int> ord;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    ord.push_back(i);
  }
  sort(ord.begin(), ord.end(),
       [&](int x, int y) { return s[x].size() < s[y].size(); });
  long long res = 0;
  for (int i : ord) {
    int cur = 0;
    for (int h = 0; h < 26; h++) {
      good[s[i].size()][h] = false;
    }
    for (int j = s[i].size() - 1; j >= 0; j--) {
      for (int h = 0; h < 26; h++) {
        good[j][h] = good[j + 1][h];
      }
      good[j][s[i][j] - 'a'] = true;
    }
    for (int j = 0, g; j < s[i].size(); j++) {
      for (int h = 0; h < 26; h++) {
        if (good[j][h] && t[cur][h]) {
          res += f[t[cur][h]];
        }
      }
      g = s[i][j] - 'a';
      if (!t[cur][g]) {
        t[cur][g] = ++G;
      }
      cur = t[cur][g];
    }
    f[cur] += 1;
  }
  cout << res << "\n";
}


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

#define fi first
#define se second

const int N = 200100;
const int Q = 1000100;

using namespace std;

int n;
string s[N];
int G;
int t[Q][26];
int f[Q];
bool good[Q][26];

int main() {
  ios_base::sync_with_stdio(0);

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;
  vector<int> ord;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    ord.push_back(i);
  }
  sort(ord.begin(), ord.end(),
       [&](int x, int y) { return s[x].size() < s[y].size(); });
  long long res = 0;
  for (int i : ord) {
    int cur = 0;
    for (int h = 0; h < 26; h++) {
      good[s[i].size()][h] = false;
    }
    for (int j = s[i].size() - 1; j >= 0; j--) {
      for (int h = 0; h < 26; h++) {
        good[j][h] = good[j + 1][h];
      }
      good[j][s[i][j] - 'a'] = true;
    }
    for (int j = 0, g; j < s[i].size(); j++) {
      for (int h = 0; h < 26; h++) {
        if (good[j][h] && t[cur][h]) {
          res += f[t[cur][h]];
        }
      }
      g = s[i][j] - 'a';
      if (!t[cur][g]) {
        t[cur][g] = ++G;
      }
      cur = t[cur][g];
    }
    f[cur] += 1;
  }
  cout << res << "\n";
}
Problem p02589 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int n;
#define Maxn 200010
#define V 1000010
char ch[Maxn];
int len;
char *str[Maxn];
int L[Maxn];
int *sum[26][Maxn];
struct Node {
  int son[26], sum;
} tree[V];
int root = 0, cnt = 0;
void Insert(int &k, int at) {
  if (!k)
    k = ++cnt;
  if (at == len + 1) {
    tree[k].sum++;
    return;
  }
  Insert(tree[k].son[ch[at] - 'a'], at + 1);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch + 1);
    len = strlen(ch + 1);
    L[i] = len;
    str[i] = new char[L[i] + 1];
    for (int j = 1; j <= L[i]; ++j)
      str[i][j] = ch[j];
    for (int j = 0; j < 26; ++j) {
      sum[j][i] = new int[L[i] + 1];
      sum[j][i][0] = 0;
      for (int k = 1; k <= L[i]; ++k) {
        sum[j][i][k] = sum[j][i][k - 1];
        if ((ch[k] - 'a') == j)
          sum[j][i][k]++;
      }
    }
    reverse(ch + 1, ch + len + 1);
    Insert(root, 1);
  }
  ll Ans = -n;
  for (int i = 1; i <= n; ++i) {
    int k = root;
    for (int j = L[i]; j >= 1; --j) {
      for (int z = 0; z < 26; ++z)
        if (sum[z][i][j])
          Ans += tree[tree[k].son[z]].sum;
      k = tree[k].son[str[i][j] - 'a'];
    }
  }
  printf("%lld\n", Ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int n;
#define Maxn 200010
#define V 1000010
char ch[V];
int len;
char *str[Maxn];
int L[Maxn];
int *sum[26][Maxn];
struct Node {
  int son[26], sum;
} tree[V];
int root = 0, cnt = 0;
void Insert(int &k, int at) {
  if (!k)
    k = ++cnt;
  if (at == len + 1) {
    tree[k].sum++;
    return;
  }
  Insert(tree[k].son[ch[at] - 'a'], at + 1);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch + 1);
    len = strlen(ch + 1);
    L[i] = len;
    str[i] = new char[L[i] + 1];
    for (int j = 1; j <= L[i]; ++j)
      str[i][j] = ch[j];
    for (int j = 0; j < 26; ++j) {
      sum[j][i] = new int[L[i] + 1];
      sum[j][i][0] = 0;
      for (int k = 1; k <= L[i]; ++k) {
        sum[j][i][k] = sum[j][i][k - 1];
        if ((ch[k] - 'a') == j)
          sum[j][i][k]++;
      }
    }
    reverse(ch + 1, ch + len + 1);
    Insert(root, 1);
  }
  ll Ans = -n;
  for (int i = 1; i <= n; ++i) {
    int k = root;
    for (int j = L[i]; j >= 1; --j) {
      for (int z = 0; z < 26; ++z)
        if (sum[z][i][j])
          Ans += tree[tree[k].son[z]].sum;
      k = tree[k].son[str[i][j] - 'a'];
    }
  }
  printf("%lld\n", Ans);
}
Problem p02589 (C++)

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 5;

int nxt[N][26], cnt[N][26], cur = 0;

void insert(string s) {
  vector<int> c(26, 0);
  int idx = 0;
  for (auto i : s)
    c[i - 'a']++;
  for (int j = 0; j < 26; j++)
    cnt[idx][j] += (c[j] > 0);
  for (auto i : s) {
    c[i - 'a']--;
    if (!nxt[idx][i - 'a']) {
      nxt[idx][i - 'a'] = ++cur;
    }
    idx = nxt[idx][i - 'a'];
    for (int j = 0; j < 26; j++)
      cnt[idx][j] += (c[j] > 0);
  }
}

int solve(string s) {
  int n = s.length(), idx = 0;
  for (int i = 0; i < n - 1; i++) {
    idx = nxt[idx][s[i] - 'a'];
  }

  return cnt[idx][s[n - 1] - 'a'] - 1;
}

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

  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    insert(s[i]);
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += solve(s[i]);
  }

  cout << ans << '\n';
}


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

using namespace std;

typedef long long int ll;

const int N = 1e6 + 5;

int nxt[N][26], cnt[N][26], cur = 0;

void insert(string s) {
  vector<int> c(26, 0);
  int idx = 0;
  for (auto i : s)
    c[i - 'a']++;
  for (int j = 0; j < 26; j++)
    cnt[idx][j] += (c[j] > 0);
  for (auto i : s) {
    c[i - 'a']--;
    if (!nxt[idx][i - 'a']) {
      nxt[idx][i - 'a'] = ++cur;
    }
    idx = nxt[idx][i - 'a'];
    for (int j = 0; j < 26; j++)
      cnt[idx][j] += (c[j] > 0);
  }
}

int solve(string s) {
  int n = s.length(), idx = 0;
  for (int i = 0; i < n - 1; i++) {
    idx = nxt[idx][s[i] - 'a'];
  }

  return cnt[idx][s[n - 1] - 'a'] - 1;
}

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

  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    insert(s[i]);
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += solve(s[i]);
  }

  cout << ans << '\n';
}
Problem p02589 (C++)

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

using namespace std;

const int max_n = 202222, inf = 1000111222;
const int max_v = 1000111;
const int max_c = 27;

char buf[max_n];

string read() {
  scanf("%s", buf);
  return buf;
}

int n;
int first, nxt[max_v][max_c], cnt[max_v][max_c], tot[max_c];
string s[max_n];
long long ans;

void add(const string &s) {
  memset(tot, 0, sizeof(tot));
  for (char c : s) {
    ++tot[c - 'a'];
  }
  int v = 0;
  for (char c : s) {
    for (int to = 0; to < max_c; ++to) {
      if (tot[to]) {
        ++cnt[v][to];
      }
    }
    --tot[c - 'a'];
    if (!nxt[v][c - 'a']) {
      nxt[v][c - 'a'] = ++first;
    }
    v = nxt[v][c - 'a'];
  }
}

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    s[i] = read();
    reverse(s[i].begin(), s[i].end());
    add(s[i]);
  }
  for (int i = 0; i < n; ++i) {
    int v = 0;
    for (int j = 0; j + 1 < s[i].length(); ++j) {
      v = nxt[v][s[i][j] - 'a'];
    }
    ans += cnt[v][s[i].back() - 'a'] - 1;
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

const int max_n = 202222, inf = 1000111222;
const int max_v = 1000111;
const int max_c = 27;

char buf[max_v];

string read() {
  scanf("%s", buf);
  return buf;
}

int n;
int first, nxt[max_v][max_c], cnt[max_v][max_c], tot[max_c];
string s[max_n];
long long ans;

void add(const string &s) {
  memset(tot, 0, sizeof(tot));
  for (char c : s) {
    ++tot[c - 'a'];
  }
  int v = 0;
  for (char c : s) {
    for (int to = 0; to < max_c; ++to) {
      if (tot[to]) {
        ++cnt[v][to];
      }
    }
    --tot[c - 'a'];
    if (!nxt[v][c - 'a']) {
      nxt[v][c - 'a'] = ++first;
    }
    v = nxt[v][c - 'a'];
  }
}

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    s[i] = read();
    reverse(s[i].begin(), s[i].end());
    add(s[i]);
  }
  for (int i = 0; i < n; ++i) {
    int v = 0;
    for (int j = 0; j + 1 < s[i].length(); ++j) {
      v = nxt[v][s[i][j] - 'a'];
    }
    ans += cnt[v][s[i].back() - 'a'] - 1;
  }
  cout << ans << "\n";
  return 0;
}
Problem p02589 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, cur, pas, b[N], endz[N * 10][30], aft[N * 10][30], k, ans;
string s[N];
bool ss(string s1, string s2) { return s1.size() < s2.size(); }
int get() {
  int u = 0, pas = 0;
  b[0] = 1ll << (s[k][0] - 'a');
  for (int i = 1; i < s[k].size(); i++) {
    b[i] = b[i - 1] | (1ll << (s[k][i] - 'a'));
  }
  // cout<<s[k].size()<<endl;
  for (int i = s[k].size() - 1; i >= 0; i--) {

    if (i == 0)
      break;
    for (int j = 0; j <= 25; j++) {
      if (b[i] & (1 << j))
        pas += endz[u][j];
    }
    if (!aft[u][s[k][i] - 'a'])
      break;
    u = aft[u][s[k][i] - 'a'];
  }
  return pas;
}
void add() {
  int u = 0;
  for (int i = s[k].size() - 1; i >= 1; i--) {
    if (!aft[u][s[k][i] - 'a']) {
      cur++;
      aft[u][s[k][i] - 'a'] = cur;
    }
    u = aft[u][s[k][i] - 'a'];
  }
  endz[u][s[k][0] - 'a']++;
}
int main() {
  cin >> n;
  for (k = 1; k <= n; k++) {
    cin >> s[k];
  }
  sort(s + 1, s + n + 1, ss);
  long long ans = 0;
  for (k = 1; k <= n; k++) {
    ans += (long long)get();
    add();
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, cur, pas, b[5 * N], endz[N * 10][30], aft[N * 10][30], k, ans;
string s[N];
bool ss(string s1, string s2) { return s1.size() < s2.size(); }
int get() {
  int u = 0, pas = 0;
  b[0] = 1ll << (s[k][0] - 'a');
  for (int i = 1; i < s[k].size(); i++) {
    b[i] = b[i - 1] | (1ll << (s[k][i] - 'a'));
  }
  // cout<<s[k].size()<<endl;
  for (int i = s[k].size() - 1; i >= 0; i--) {

    if (i == 0)
      break;
    for (int j = 0; j <= 25; j++) {
      if (b[i] & (1 << j))
        pas += endz[u][j];
    }
    if (!aft[u][s[k][i] - 'a'])
      break;
    u = aft[u][s[k][i] - 'a'];
  }
  return pas;
}
void add() {
  int u = 0;
  for (int i = s[k].size() - 1; i >= 1; i--) {
    if (!aft[u][s[k][i] - 'a']) {
      cur++;
      aft[u][s[k][i] - 'a'] = cur;
    }
    u = aft[u][s[k][i] - 'a'];
  }
  endz[u][s[k][0] - 'a']++;
}
int main() {
  cin >> n;
  for (k = 1; k <= n; k++) {
    cin >> s[k];
  }
  sort(s + 1, s + n + 1, ss);
  long long ans = 0;
  for (k = 1; k <= n; k++) {
    ans += (long long)get();
    add();
  }
  cout << ans;
}
Problem p02589 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N = 2e5 + 5;
int N;
string s[MAX_N];
int ch[MAX_N][26];
int ed[MAX_N], tot = 1;
void ins(string s) {
  int o = 1;
  for (int i = 0; i < (int)s.length(); i++) {
    int c = s[i] - 'a';
    if (!ch[o][c])
      ch[o][c] = ++tot;
    o = ch[o][c];
  }
  ed[o]++;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> s[i];
  for (int i = 1; i <= N; i++)
    reverse(s[i].begin(), s[i].end()), ins(s[i]);
  LL ans = 0;
  for (int i = 1; i <= N; i++) {
    int o = 1, cnt = 0, buc[30];
    memset(buc, 0, sizeof(buc));
    for (int j = 0; j < (int)s[i].length(); j++)
      ++buc[s[i][j] - 'a'];
    for (int j = 0; j < (int)s[i].length(); j++) {
      for (int k = 0; k < 26; k++)
        if (buc[k] && k != s[i][j] - 'a')
          cnt += ed[ch[o][k]];
      o = ch[o][s[i][j] - 'a'], buc[s[i][j] - 'a']--, cnt += ed[o];
    }
    ans += cnt;
  }
  cout << ans - N << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N = 2e6 + 5;
int N;
string s[MAX_N];
int ch[MAX_N][26];
int ed[MAX_N], tot = 1;
void ins(string s) {
  int o = 1;
  for (int i = 0; i < (int)s.length(); i++) {
    int c = s[i] - 'a';
    if (!ch[o][c])
      ch[o][c] = ++tot;
    o = ch[o][c];
  }
  ed[o]++;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> s[i];
  for (int i = 1; i <= N; i++)
    reverse(s[i].begin(), s[i].end()), ins(s[i]);
  LL ans = 0;
  for (int i = 1; i <= N; i++) {
    int o = 1, cnt = 0, buc[30];
    memset(buc, 0, sizeof(buc));
    for (int j = 0; j < (int)s[i].length(); j++)
      ++buc[s[i][j] - 'a'];
    for (int j = 0; j < (int)s[i].length(); j++) {
      for (int k = 0; k < 26; k++)
        if (buc[k] && k != s[i][j] - 'a')
          cnt += ed[ch[o][k]];
      o = ch[o][s[i][j] - 'a'], buc[s[i][j] - 'a']--, cnt += ed[o];
    }
    ans += cnt;
  }
  cout << ans - N << '\n';
  return 0;
}
Problem p02589 (C++)

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

using namespace std;

int N;
string s[200010];
char tmp[200010];
typedef long long LL;
bool vis[1000010][26];
int ch[1000010][26];
bool isend[1000010];
int tot = 1;
long long ans = 0;

void ins(string s) {
  int n = s.length();
  for (int i = 0; i < 26; i++)
    vis[0][i] = (s[0] - 'a' == i);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      vis[i][j] = (vis[i - 1][j] | (s[i] - 'a' == j));
    }
  }
  int now = 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (ch[now][j] && isend[ch[now][j]] && vis[i][j])
        ans++;
    }
    int v = s[i] - 'a';
    if (!ch[now][v])
      ch[now][v] = ++tot;
    now = ch[now][v];
  }
  isend[now] = true;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%s", tmp);
    s[i] = string(tmp);
  }
  sort(s + 1, s + N + 1,
       [&](string s1, string s2) { return s1.length() < s2.length(); });
  for (int i = 1; i <= N; i++) {
    ins(s[i]);
  }
  printf("%lld\n", ans);
}

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

using namespace std;

int N;
string s[200010];
char tmp[1000010];
typedef long long LL;
bool vis[1000010][26];
int ch[1000010][26];
bool isend[1000010];
int tot = 1;
long long ans = 0;

void ins(string s) {
  int n = s.length();
  for (int i = 0; i < 26; i++)
    vis[0][i] = (s[0] - 'a' == i);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      vis[i][j] = (vis[i - 1][j] | (s[i] - 'a' == j));
    }
  }
  int now = 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (ch[now][j] && isend[ch[now][j]] && vis[i][j])
        ans++;
    }
    int v = s[i] - 'a';
    if (!ch[now][v])
      ch[now][v] = ++tot;
    now = ch[now][v];
  }
  isend[now] = true;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%s", tmp);
    s[i] = string(tmp);
  }
  sort(s + 1, s + N + 1,
       [&](string s1, string s2) { return s1.length() < s2.length(); });
  for (int i = 1; i <= N; i++) {
    ins(s[i]);
  }
  printf("%lld\n", ans);
}
Problem p02591 (C++)

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

using namespace std;

const int MX = 1 << 18, md = 1000000007;

unordered_map<int, int> here[18];
bool old[18];

int a[MX];

int main() {
  int h = 18;
  ignore = scanf("%d", &h);

  int n = 1 << (h - 1);
  for (int i = 0; i < n; i++)
    ignore = scanf("%d", a + i);
  //	srand(42);
  //	iota(a, a + n, 1);
  //	random_shuffle(a, a + n);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int u = n + i, p = 1, d = 0; u != 1; d++, u /= 2) {
      p = p * 1LL * u % md;

      if (u % 2 == 0) {
        if (old[d]) {
          here[d].clear();
          old[d] = false;
        }

        for (int v = n + a[i] - 1, q = p; v != 1; v /= 2) {
          q = q * 1LL * v % md;

          int &val = here[d][v];
          val += q;
          if (val >= md)
            val -= md;
        }
      } else {
        old[d] = true;

        for (int v = n + a[i] - 1, q = p; v != 1; v /= 2) {
          q = q * 1LL * v % md;

          auto it = here[d].find(v ^ 1);
          if (it != here[d].end()) {
            int there = it->second;
            ans += q * 1LL * there % md * (v / 2) % md * (u / 2) % md;
            if (ans >= md)
              ans -= md;
          }
        }
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

const int MX = 1 << 18, md = 1000000007;

unordered_map<int, int> here[18];
bool old[18];

int a[MX];

int main() {
  int h = 18;
  ignore = scanf("%d", &h);

  int n = 1 << (h - 1);
  for (int i = 0; i < n; i++)
    ignore = scanf("%d", a + i);
  //	srand(42);
  //	iota(a, a + n, 1);
  //	random_shuffle(a, a + n);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int u = n + i, p = 1, d = 0; u != 1; d++, u /= 2) {
      p = p * 1LL * u % md;

      if (u % 2 == 0) {
        if (old[d]) {
          here[d].clear();
          old[d] = false;
        }

        for (int v = n + a[i] - 1, q = p; v != 1; v /= 2) {
          q = q * 1LL * v % md;

          int &val = here[d][v];
          val += q;
          if (val >= md)
            val -= md;
        }
      } else {
        old[d] = true;

        for (int v = n + a[i] - 1, q = p; v != 1; v /= 2) {
          q = q * 1LL * v % md;

          auto it = here[d].find(v ^ 1);
          if (it != here[d].end()) {
            int there = it->second;
            ans += q * 1LL * there % md * (v / 2) % md * (u / 2) % md;
            if (ans >= md)
              ans -= md;
          }
        }
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p02591 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int const p = 1e9 + 7;
int c[1000005], w[1000005], lg2[100005];
int mod(int x) { return x >= p ? x - p : x; }
int main() {
  int h, ans = 0;
  scanf("%d", &h);
  for (int i = (1 << (h - 1)); i < (1 << h); i++)
    scanf("%d", &c[i]), c[i] += (1 << (h - 1)) - 1;
  for (int i = 2; i < (1 << (h - 1)); i++)
    lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i < (1 << (h - 1)); i++) {
    int t = lg2[i] + 1;
    for (int j = 0; j < (1 << (h - t - 1)); j++) {
      int x = (i << (h - t)) + j, now = x, prod = i;
      while (now != i)
        prod = 1ll * prod * now % p, now >>= 1;
      now = c[x];
      while (now)
        prod = 1ll * prod * now % p, w[now] = mod(w[now] + prod), now >>= 1;
    }
    for (int j = (1 << (h - t - 1)); j < (1 << (h - t)); j++) {
      int x = (i << (h - t)) + j, now = x, prod = 1, pre = 0;
      while (now != i)
        prod = 1ll * prod * now % p, now >>= 1;
      now = c[x];
      while (now) {
        ans = mod(ans + 1ll * (w[now] - 1ll * w[pre] * now % p + p) * prod % p);
        prod = 1ll * prod * now % p, pre = now, now >>= 1;
      }
    }
    for (int j = 0; j < (1 << (h - t - 1)); j++) {
      int now = c[(i << (h - t)) + j];
      while (now)
        w[now] = 0, now >>= 1;
    }
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int const p = 1e9 + 7;
int c[1000005], w[1000005], lg2[1000005];
int mod(int x) { return x >= p ? x - p : x; }
int main() {
  int h, ans = 0;
  scanf("%d", &h);
  for (int i = (1 << (h - 1)); i < (1 << h); i++)
    scanf("%d", &c[i]), c[i] += (1 << (h - 1)) - 1;
  for (int i = 2; i < (1 << (h - 1)); i++)
    lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i < (1 << (h - 1)); i++) {
    int t = lg2[i] + 1;
    for (int j = 0; j < (1 << (h - t - 1)); j++) {
      int x = (i << (h - t)) + j, now = x, prod = i;
      while (now != i)
        prod = 1ll * prod * now % p, now >>= 1;
      now = c[x];
      while (now)
        prod = 1ll * prod * now % p, w[now] = mod(w[now] + prod), now >>= 1;
    }
    for (int j = (1 << (h - t - 1)); j < (1 << (h - t)); j++) {
      int x = (i << (h - t)) + j, now = x, prod = 1, pre = 0;
      while (now != i)
        prod = 1ll * prod * now % p, now >>= 1;
      now = c[x];
      while (now) {
        ans = mod(ans + 1ll * (w[now] - 1ll * w[pre] * now % p + p) * prod % p);
        prod = 1ll * prod * now % p, pre = now, now >>= 1;
      }
    }
    for (int j = 0; j < (1 << (h - t - 1)); j++) {
      int now = c[(i << (h - t)) + j];
      while (now)
        w[now] = 0, now >>= 1;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p02591 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int maxn = 234567;
const int M = 1000000007;
typedef long long ll;
typedef pair<int, ll> pi;
void add(ll &x, ll y) {
  x += y;
  if (x >= M)
    x -= M;
}
int n, h, p[maxn];
vector<pi> v[2];
ll ans, cnt[2][maxn];
void ins(int x, ll val, int o) {
  while (x) {
    val = val * x % M;
    add(cnt[o][x], val);
    x >>= 1;
  }
}
ll dfs2(int x) {
  if (!cnt[0][x] || !cnt[1][x])
    return 0;
  ll ret =
      (cnt[0][x * 2] * cnt[1][x * 2 + 1] + cnt[1][x * 2] * cnt[0][x * 2 + 1]) %
      M * x % M;
  add(ret, dfs2(x * 2));
  add(ret, dfs2(x * 2 + 1));
  return ret;
}
void dfs(int x, ll val, int o) {
  val = val * x % M;
  if (x >= n) {
    v[o].pb((pi){p[x - n] + n, val});
    return;
  }
  dfs(x * 2, val, o);
  dfs(x * 2 + 1, val, o);
}
ll solve(int x) {
  v[0].clear();
  v[1].clear();
  dfs(x * 2, 1, 0);
  dfs(x * 2 + 1, 1, 1);
  for (auto x : v[0])
    ins(x.F, x.S, 0);
  for (auto x : v[1])
    ins(x.F, x.S, 1);
  ll ret = dfs2(1);
  for (auto x : v[0])
    ins(x.F, M - x.S, 0);
  for (auto x : v[1])
    ins(x.F, M - x.S, 1);
  return ret;
}
int main() {
  cin >> h;
  n = 1 << (h - 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 1; i < n; i++)
    ans = (ans + solve(i) * i) % M;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int maxn = 434567;
const int M = 1000000007;
typedef long long ll;
typedef pair<int, ll> pi;
void add(ll &x, ll y) {
  x += y;
  if (x >= M)
    x -= M;
}
int n, h, p[maxn];
vector<pi> v[2];
ll ans, cnt[2][maxn];
void ins(int x, ll val, int o) {
  while (x) {
    val = val * x % M;
    add(cnt[o][x], val);
    x >>= 1;
  }
}
ll dfs2(int x) {
  if (!cnt[0][x] || !cnt[1][x])
    return 0;
  ll ret =
      (cnt[0][x * 2] * cnt[1][x * 2 + 1] + cnt[1][x * 2] * cnt[0][x * 2 + 1]) %
      M * x % M;
  add(ret, dfs2(x * 2));
  add(ret, dfs2(x * 2 + 1));
  return ret;
}
void dfs(int x, ll val, int o) {
  val = val * x % M;
  if (x >= n) {
    v[o].pb((pi){p[x - n] + n, val});
    return;
  }
  dfs(x * 2, val, o);
  dfs(x * 2 + 1, val, o);
}
ll solve(int x) {
  v[0].clear();
  v[1].clear();
  dfs(x * 2, 1, 0);
  dfs(x * 2 + 1, 1, 1);
  for (auto x : v[0])
    ins(x.F, x.S, 0);
  for (auto x : v[1])
    ins(x.F, x.S, 1);
  ll ret = dfs2(1);
  for (auto x : v[0])
    ins(x.F, M - x.S, 0);
  for (auto x : v[1])
    ins(x.F, M - x.S, 1);
  return ret;
}
int main() {
  cin >> h;
  n = 1 << (h - 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 1; i < n; i++)
    ans = (ans + solve(i) * i) % M;
  cout << ans << endl;
  return 0;
}
Problem p02594 (C++)

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

int main() {
  int x;
  cin >> x;

  string ret;
  if (x >= 30) {
    ret = "Yes";
  } else {
    ret = "No";
  }

  cout << ret << endl;
  return true;
}

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

int main() {
  int x;
  cin >> x;

  string ret;
  if (x >= 30) {
    ret = "Yes";
  } else {
    ret = "No";
  }

  cout << ret << endl;
}
Problem p02594 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (1) {
    cin >> n;
    if (n >= 30) {
      cout << "Yes" << endl;
      break;
    } else
      cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n >= 30)
    cout << "Yes" << endl;

  else
    cout << "No" << endl;
  return 0;
}
Problem p02594 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll, ll>>
#define pb push_back
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define repp(i, a, b) for (ll i = (a); i >= (b); i--)
#define rop(i, a, b) for (ll i = (a); i > (b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt                                                                     \
  long long t;                                                                 \
  cin >> t;                                                                    \
  while (t--)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
const int maxn = 1e5 + 100;

int main() {
  tt {
    ll w;
    cin >> w;
    map<int, int> mp;
    for (int i = 0; i < w; i++) {
      string s;
      cin >> s;
      ll p = s.length();

      rep(i, 0, p) { mp[s[i] - 'a']++; }
    }
    ll flag = 0;

    rep(i, 0, 26) {
      if (mp[i] % w) {
        cout << "NO";
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << "YES";
    }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll, ll>>
#define pb push_back
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define repp(i, a, b) for (ll i = (a); i >= (b); i--)
#define rop(i, a, b) for (ll i = (a); i > (b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt                                                                     \
  long long t;                                                                 \
  cin >> t;                                                                    \
  while (t--)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
const int maxn = 1e5 + 100;

int main() {
  ll n;
  cin >> n;
  if (n >= 30)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02594 (C++)

Buggy submission (status: Memory Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
  vector<int> v(300000000, 0);
  int X;
  cin >> X;
  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
  vector<int> v(250000000, 0);
  int X;
  cin >> X;
  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02594 (Python)

Buggy submission (status: Runtime Error):
x = input()

if x >= 30:
    print("Yes")
else:
    print("No")


Fixed submission:
x = int(input())

if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python)

Buggy submission (status: Runtime Error):
X = int(input().split())

if X >= 30:
    print("Yes")
else:
    print("No")


Fixed submission:
X = int(input())

if X >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python)

Buggy submission (status: Runtime Error):
x = input()
if x >= 30:
    print("Yes")
else:
    print("No")


Fixed submission:
x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python)

Buggy submission (status: Runtime Error):
x = input()
if x >= 30:
    print("Yes")
else:
    print("No")


Fixed submission:
x = input()
if int(x) >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, n, a) for (ll i = n - 1; i >= a; i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define fastread                                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios::sync_with_stdio(false);
#define online_judge

const ll MOD = 1e9 + 7;

ll pow(ll n, ll e) {
  if (e == 0)
    return 1;
  else if (e == 1)
    return n;
  else if (e % 2 == 0)
    return pow(n, e / 2);
  else
    return pow(n, e / 2) * n;
}

bool prime(ll n) {
  ll ct = 0;
  rep(i, 2, sqrt(n) + 1) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int solve() {
  fastread;
  ll n, m, temp, mi, q, ma = 0, t;

  cin >> n;
  (n >= 30) ? cout << "Yes" : cout << "No";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  clock_t start, end;
  start = clock();
  solve();
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
  cerr << "Time taken by program is : " << fixed << time_taken
       << setprecision(5);
  cerr << " sec " << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, n, a) for (ll i = n - 1; i >= a; i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define fastread                                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios::sync_with_stdio(false);
#define online_judge

const ll MOD = 1e9 + 7;

ll pow(ll n, ll e) {
  if (e == 0)
    return 1;
  else if (e == 1)
    return n;
  else if (e % 2 == 0)
    return pow(n, e / 2);
  else
    return pow(n, e / 2) * n;
}

bool prime(ll n) {
  ll ct = 0;
  rep(i, 2, sqrt(n) + 1) {
    if (n % i == 0)
      return false;
  }
  return true;
}

void solve() {
  fastread;
  ll n, m, temp, mi, q, ma = 0, t;

  cin >> n;
  (n >= 30) ? cout << "Yes" : cout << "No";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  clock_t start, end;
  start = clock();
  solve();
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
  cerr << "Time taken by program is : " << fixed << time_taken
       << setprecision(5);
  cerr << " sec " << endl;
  return 0;
}
Problem p02595 (C++)

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int N, count = 0;
  double X[20000], Y[20000], D, x;
  cin >> N;
  cin >> D;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    cin >> Y[i];
    x = X[i] * X[i] + Y[i] * Y[i];
    x = sqrt(x);

    if (D >= x)
      count++;
  }
  cout << count;
  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int N, count = 0;
  static double X[200000], Y[200000];
  double D, x;
  cin >> N;
  cin >> D;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    cin >> Y[i];
    x = X[i] * X[i] + Y[i] * Y[i];
    x = sqrt(x);

    if (D >= x)
      count++;
  }
  cout << count;
  return 0;
}
Problem p02595 (C++)

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

int32_t main() {

  int n, d;
  cin >> n >> d;

  int count = 0;

  for (int i = 1; i <= n; i++) {

    int x, y;
    scanf("%d %d");

    if (x * x + y * y <= d * d)
      count++;
  }
  cout << count << endl;
}

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

int32_t main() {

  int n, d;
  cin >> n >> d;

  int count = 0;

  for (int i = 1; i <= n; i++) {

    int x, y;
    scanf("%lld %lld", &x, &y);

    if (x * x + y * y <= d * d)
      count++;
  }
  cout << count << endl;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>

#define L 20005

using namespace std;

double x[L], y[L];

double dist(double x, double y) {
  double s = (double)(x * x) + (double)(y * y);
  return sqrt(s);
}

int main() {
  int N, D;
  cin >> N >> D;
  int cnt = 0;
  for (int i = 0; i < N; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < N; i++) {
    if (dist(x[i], y[i]) <= (double)(D))
      cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

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

#define L 200005

using namespace std;

double x[L], y[L];

double dist(double x, double y) {
  double s = (double)(x * x) + (double)(y * y);
  return sqrt(s);
}

int main() {
  int N, D;
  cin >> N >> D;
  int cnt = 0;
  for (int i = 0; i < N; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < N; i++) {
    if (dist(x[i], y[i]) <= (double)(D))
      cnt++;
  }
  cout << cnt << "\n";
  return 0;
}
Problem p02595 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
typedef long long ll;
int main() {
  int n, ans = 0;
  ll d, x, y;
  scanf("%d%lld", &n, &d);
  d = d * d;
  while (n--) {
    scanf("%lld%lld", &x, y);
    if (x * x + y * y <= d)
      ans++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <stdio.h>
typedef long long ll;
int main() {
  int n, ans = 0;
  ll d, x, y;
  scanf("%d%lld", &n, &d);
  d = d * d;
  while (n--) {
    scanf("%lld%lld", &x, &y);
    if (x * x + y * y <= d)
      ans++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02595 (C++)

Buggy submission (status: 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>(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;
}

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>(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;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long long N, D;
long long X[110000];
long long Y[110000];

int main(void) {

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

  int ans;
  ans = 0;
  D = D * D;

  for (int i = 1; i <= N; i++) {
    long long dist = X[i] * X[i] + Y[i] * Y[i];
    if (D >= dist)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long long N, D;
long long X[210000];
long long Y[210000];

int main(void) {

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

  int ans;
  ans = 0;
  D = D * D;

  for (int i = 1; i <= N; i++) {
    long long dist = X[i] * X[i] + Y[i] * Y[i];
    if (D >= dist)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02595 (C++)

Buggy submission (status: 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[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;
  }
}

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[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;
  }
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define int long long
using namespace std;
int n, ans;
double d, x[100005], y[100005];
signed main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    scanf("%lf %lf", &x[i], &y[i]);
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) {
      ans++;
    }
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define int long long
using namespace std;
int n, ans;
double d, x[200005], y[200005];
signed main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    scanf("%lf %lf", &x[i], &y[i]);
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) {
      ans++;
    }
  }
  cout << ans;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io                                                           \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);

typedef long long int ll;

int main() {
  optimizar_io int n;
  ll d, x[100010], y[100010];

  cin >> n >> d;
  d = d * d;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    ll dist = x[i] * x[i] + y[i] * y[i];
    if (dist <= d)
      cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io                                                           \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);

typedef long long int ll;

int main() {
  optimizar_io int n;
  ll d, x[200010], y[200010];

  cin >> n >> d;
  d = d * d;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    ll dist = x[i] * x[i] + y[i] * y[i];
    if (dist <= d)
      cnt++;
  }
  cout << cnt << "\n";
  return 0;
}
Problem p02595 (C++)

Buggy submission (status: 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(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;
}

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(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;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  int n, d;
  int counter = 0;
  long long A[100010], B[100010];
  long double C[100010];
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
    C[i] = (double)((A[i] * A[i]) + (B[i] * B[i]));
    // cout << C[i] << " " << sqrt(C[i]) << endl;
  }
  for (int i = 0; i < n; i++) {
    if (sqrt(C[i]) <= d) {
      counter++;
    }
  }
  cout << counter << endl;
}


Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  int n, d;
  int counter = 0;
  long long A[200020], B[200020];
  long double C[200020];
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
    C[i] = (double)((A[i] * A[i]) + (B[i] * B[i]));
    // cout << C[i] << " " << sqrt(C[i]) << endl;
  }
  for (int i = 0; i < n; i++) {
    if (sqrt(C[i]) <= d) {
      counter++;
    }
  }
  cout << counter << endl;
}
Problem p02595 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int x[100001], y[100001];

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

  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

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

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int x[200001], y[200001];

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

  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

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

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