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

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int cb[2][100007];
char ca[100007];
bool s[100007];
int main() {
  int n, m, q;
  int i, j, k;
  int a, b, c, d;
  for (i = 0; i < 2; i++) {
    scanf("%s", ca);
    for (j = 0; j < strlen(ca); j++) {
      cb[i][j + 1] = cb[i][j];
      if (ca[j] == 'A')
        cb[i][j + 1]++;
      else
        cb[i][j + 1] += 2;
    }
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--, c--;
    a = (cb[0][b] - cb[0][a]) % 3;
    b = (cb[1][d] - cb[1][c]) % 3;
    if (a == b)
      s[i] = true;
    else
      s[i] = false;
  }
  for (i = 0; i < q; i++) {
    if (s[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int cb[2][100007];
char ca[100007];
bool s[100007];
int main() {
  int n, m, q;
  int i, j, k;
  int a, b, c, d;
  for (i = 0; i < 2; i++) {
    scanf("%s", ca);
    a = strlen(ca);
    for (j = 0; j < a; j++) {
      cb[i][j + 1] = cb[i][j];
      if (ca[j] == 'A')
        cb[i][j + 1]++;
      else
        cb[i][j + 1] += 2;
    }
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--, c--;
    a = (cb[0][b] - cb[0][a]) % 3;
    b = (cb[1][d] - cb[1][c]) % 3;
    if (a == b)
      s[i] = true;
    else
      s[i] = false;
  }
  for (i = 0; i < q; i++) {
    if (s[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
// #define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N = 100;
ll t0[N];
ll t1[N];
ll t10[N];
ll t11[N];
int32_t main() {
  string s;
  cin >> s;
  for (int i = 1; i <= s.size(); i++) {
    t0[i] = t0[i - 1];
    t1[i] = t1[i - 1];
    if (s[i - 1] == 'A') {
      t0[i]++;
    } else {
      t1[i]++;
    }
  }
  string u;
  cin >> u;
  for (int i = 1; i <= u.size(); i++) {
    t10[i] = t10[i - 1];
    t11[i] = t11[i - 1];
    if (u[i - 1] == 'A') {
      t10[i]++;
    } else {
      t11[i]++;
    }
  }
  ll q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    ll x, y;
    cin >> x >> y;
    ll w, h;
    cin >> w >> h;
    ll z = t0[y] - t0[x - 1];
    z -= t1[y] - t1[x - 1];
    z += 3e8;
    z %= 3;
    ll z1 = t10[h] - t10[w - 1];
    z1 -= t11[h] - t11[w - 1];
    z1 += 3e8;
    z1 %= 3;
    // cout << z << " " << z1 << endl;
    if (z1 != z) {
      cout << "NO";
    } else {
      cout << "YES";
    }
    cout << '\n';
  }
}


Fixed submission:
#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
// #define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N = 2e5;
ll t0[N];
ll t1[N];
ll t10[N];
ll t11[N];
int32_t main() {
  string s;
  cin >> s;
  for (int i = 1; i <= s.size(); i++) {
    t0[i] = t0[i - 1];
    t1[i] = t1[i - 1];
    if (s[i - 1] == 'A') {
      t0[i]++;
    } else {
      t1[i]++;
    }
  }
  string u;
  cin >> u;
  for (int i = 1; i <= u.size(); i++) {
    t10[i] = t10[i - 1];
    t11[i] = t11[i - 1];
    if (u[i - 1] == 'A') {
      t10[i]++;
    } else {
      t11[i]++;
    }
  }
  ll q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    ll x, y;
    cin >> x >> y;
    ll w, h;
    cin >> w >> h;
    ll z = t0[y] - t0[x - 1];
    z -= t1[y] - t1[x - 1];
    z += 3e8;
    z %= 3;
    ll z1 = t10[h] - t10[w - 1];
    z1 -= t11[h] - t11[w - 1];
    z1 += 3e8;
    z1 %= 3;
    // cout << z << " " << z1 << endl;
    if (z1 != z) {
      cout << "NO";
    } else {
      cout << "YES";
    }
    cout << '\n';
  }
}
Problem p03765 (C++)

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

string s, t;
int ss[10005];
int tt[10005];

int main() {
  std::ios::sync_with_stdio(false);
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  inc(i, 0, n) { ss[i + 1] = ss[i] + (s[i] == 'A' ? 1 : 2); }
  inc(i, 0, m) { tt[i + 1] = tt[i] + (t[i] == 'A' ? 1 : 2); }

  int q;
  cin >> q;
  inc(i, 0, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "YES";
    if ((ss[b] - ss[a - 1]) % 3 != (tt[d] - tt[c - 1]) % 3)
      ans = "NO";
    cout << ans << endl;
  }
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

string s, t;
int ss[100005];
int tt[100005];

int main() {
  std::ios::sync_with_stdio(false);
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  inc(i, 0, n) { ss[i + 1] = ss[i] + (s[i] == 'A' ? 1 : 2); }
  inc(i, 0, m) { tt[i + 1] = tt[i] + (t[i] == 'A' ? 1 : 2); }

  int q;
  cin >> q;
  inc(i, 0, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "YES";
    if ((ss[b] - ss[a - 1]) % 3 != (tt[d] - tt[c - 1]) % 3)
      ans = "NO";
    cout << ans << endl;
  }
  return 0;
}
Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

string S, T;
int Q;

int main() {
  cin >> S >> T >> Q;

  int sa[101010], ta[101010];
  fill(sa, sa + 101010, 0);
  fill(ta, sa + 101010, 0);

  sa[1] = (S[0] == 'A') ? 1 : 0;
  for (int j = 2; j <= S.size(); ++j) {
    sa[j] = sa[j - 1] + (S[j - 1] == 'A' ? 1 : 0);
  }

  ta[1] = (T[0] == 'A') ? 1 : 0;
  for (int j = 2; j <= T.size(); ++j) {
    ta[j] = ta[j - 1] + (T[j - 1] == 'A' ? 1 : 0);
  }

  for (int j = 0; j < Q; ++j) {
    int w, x, y, z;
    cin >> w >> x >> y >> z;
    --w;
    --x;
    --y;
    --z;

    int a1 = sa[x + 1] - sa[w];
    int b1 = (x - w + 1) - a1;

    int a2 = ta[z + 1] - ta[y];
    int b2 = (z - y + 1) - a2;

    if ((a1 + 2 * b1) % 3 == (a2 + 2 * b2) % 3) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

string S, T;
int Q;

int main() {
  cin >> S >> T >> Q;

  int sa[101010], ta[101010];
  fill(sa, sa + 101010, 0);
  fill(ta, ta + 101010, 0);

  sa[1] = (S[0] == 'A') ? 1 : 0;
  for (int j = 2; j <= S.size(); ++j) {
    sa[j] = sa[j - 1] + (S[j - 1] == 'A' ? 1 : 0);
  }

  ta[1] = (T[0] == 'A') ? 1 : 0;
  for (int j = 2; j <= T.size(); ++j) {
    ta[j] = ta[j - 1] + (T[j - 1] == 'A' ? 1 : 0);
  }

  for (int j = 0; j < Q; ++j) {
    int w, x, y, z;
    cin >> w >> x >> y >> z;
    --w;
    --x;
    --y;
    --z;

    int a1 = sa[x + 1] - sa[w];
    int b1 = (x - w + 1) - a1;

    int a2 = ta[z + 1] - ta[y];
    int b2 = (z - y + 1) - a2;

    if ((a1 + 2 * b1) % 3 == (a2 + 2 * b2) % 3) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;

string s;
string t;
int p[10005], q[10005];
void query(int a, int b, int c, int d) {
  int k = b - a + 1 + (p[b] - p[a - 1]);
  int t = d - c + 1 + (q[d] - q[c - 1]);
  // cout << k << " " << p[b]-p[a-1] << endl;
  // cout << t << " " << q[d]-q[c-1] << endl;
  if (k % 3 == t % 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  int qq;
  cin >> s >> t >> qq;

  rep(i, s.size()) {
    p[i + 1] = p[i];
    if (s[i] == 'A')
      p[i + 1]++;
  }
  rep(i, t.size()) {
    q[i + 1] = q[i];
    if (t[i] == 'A')
      q[i + 1]++;
  }
  rep(i, t.size() + 1) {
    // cout << i << " "  << q[i] << endl;
  }
  int a, b, c, d;
  rep(i, qq) {
    cin >> a >> b >> c >> d;
    query(a, b, c, d);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;

string s;
string t;
int p[100005], q[100005];
void query(int a, int b, int c, int d) {
  int k = b - a + 1 + (p[b] - p[a - 1]);
  int t = d - c + 1 + (q[d] - q[c - 1]);
  // cout << k << " " << p[b]-p[a-1] << endl;
  // cout << t << " " << q[d]-q[c-1] << endl;
  if (k % 3 == t % 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  int qq;
  cin >> s >> t >> qq;

  rep(i, s.size()) {
    p[i + 1] = p[i];
    if (s[i] == 'A')
      p[i + 1]++;
  }
  rep(i, t.size()) {
    q[i + 1] = q[i];
    if (t[i] == 'A')
      q[i + 1]++;
  }
  rep(i, t.size() + 1) {
    // cout << i << " "  << q[i] << endl;
  }
  int a, b, c, d;
  rep(i, qq) {
    cin >> a >> b >> c >> d;
    query(a, b, c, d);
  }
  return 0;
}
Problem p03765 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll MOD = 1e9 + 7;

int solve(int left, int right, vector<int> &X) {
  int a = X[right];
  if (left != 0)
    a -= X[left - 1];
  int b = right - left + 1 - a;

  int rem = abs(a - b) % 3;
  if (rem == 2)
    rem = -1;

  if (b > a)
    rem *= -1;
  return rem;
}

int main() {
  string S, T;
  cin >> S >> T;
  int NS = S.length();
  int NT = T.length();
  vector<int> SA(NS);
  vector<int> TA(NT);
  SA[0] = S[0] == 'A';
  for (int i = 1; i < NS; i++) {
    SA[i] = SA[i - 1] + (S[i] == 'A');
  }
  TA[0] = T[0] == 'A';
  for (int i = 1; i < NS; i++) {
    TA[i] = TA[i - 1] + (T[i] == 'A');
  }

  int Q;
  cin >> Q;
  REP(i, Q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;

    int aa = solve(a, b, SA);
    int bb = solve(c, d, TA);
    // cout << aa << " " << bb << endl;

    if (aa == bb)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll MOD = 1e9 + 7;

int solve(int left, int right, vector<int> &X) {
  int a = X[right];
  if (left != 0)
    a -= X[left - 1];
  int b = right - left + 1 - a;

  int rem = abs(a - b) % 3;
  if (rem == 2)
    rem = -1;

  if (b > a)
    rem *= -1;
  return rem;
}

int main() {
  string S, T;
  cin >> S >> T;
  int NS = S.length();
  int NT = T.length();
  vector<int> SA(NS);
  vector<int> TA(NT);
  SA[0] = S[0] == 'A';
  for (int i = 1; i < NS; i++) {
    SA[i] = SA[i - 1] + (S[i] == 'A');
  }
  TA[0] = T[0] == 'A';
  for (int i = 1; i < NT; i++) {
    TA[i] = TA[i - 1] + (T[i] == 'A');
  }

  int Q;
  cin >> Q;
  REP(i, Q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;

    int aa = solve(a, b, SA);
    int bb = solve(c, d, TA);
    // cout << aa << " " << bb << endl;

    if (aa == bb)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
#define MOD 1000000007
int n, f[1000010];
int main() {
  scanf("%d", &n);
  f[n] = n;
  f[n - 1] = 1ll * n * n % MOD;
  for (int i = n - 2, s = 0; i; --i)
    s = (s + f[i + 3]) % MOD,
    f[i] = (f[i + 1] + 1ll * (n - 1) * (n - 1) + s + i + 1) % MOD;
  printf("%d\n", f[1]);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
#define MOD 1000000007
int n, f[1000010];
int main() {
  scanf("%d", &n);
  f[n] = n;
  f[n - 1] = 1ll * n * n % MOD;
  for (int i = n - 2, s = 0; i > 0; --i)
    s = (s + f[i + 3]) % MOD,
    f[i] = (f[i + 1] + 1ll * (n - 1) * (n - 1) + s + i + 1) % MOD;
  printf("%d\n", f[1]);
  return 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
// This code is written by Itst
using namespace std;

const int MAXN = 1e6 + 7, MOD = 1e9 + 7;
int N, dp[MAXN];

int main() {
  cin >> N;
  dp[N] = N;
  dp[N - 1] = (1ll * N * N + dp[N]) % MOD;
  for (int i = N - 2; i; --i)
    dp[i] = (dp[i + 1] - dp[i + 2] + (N - 1ll) * (N - 1) + dp[i + 3] +
             dp[i + 1] + i + 1 + MOD) %
            MOD;
  cout << (dp[1] - dp[2] + MOD) % MOD;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
// This code is written by Itst
using namespace std;

const int MAXN = 1e6 + 7, MOD = 1e9 + 7;
int N, dp[MAXN];

int main() {
  cin >> N;
  dp[N] = N;
  dp[N - 1] = (1ll * N * N + dp[N]) % MOD;
  for (int i = N - 2; i > 0; --i)
    dp[i] = (dp[i + 1] - dp[i + 2] + (N - 1ll) * (N - 1) + dp[i + 3] +
             dp[i + 1] + i + 1 + MOD) %
            MOD;
  cout << (dp[1] - dp[2] + MOD) % MOD;
  return 0;
}
Problem p03766 (C++)

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

struct P {
  long long x, y;
  bool operator<(const P &a) const {
    // if(y!=a.y)
    return y < a.y;
  };
};

int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
long long o[3500101];
int l[500101];
int j[500101];

long long x, y, z, mod = 1000000007;
// string r;
char r[3];

P u[1];
queue<P> q;
stack<int> s;
// set<int> s;
map<int, int> p;

vector<int> v[3];

bool as(P a, P b) {
  if (a.x != b.x)
    return a.x < b.x;
  return a.y > b.y;
}

long long f(int n, int m) {
  long long x = 0;
  for (; n < m;) {
    if (n % 2)
      x += o[n++], x %= mod;
    else if (m % 2 == 0)
      x += o[m--], x %= mod;
    else
      n /= 2, m /= 2;
  }
  return (x + o[n]) % mod;
}

int main() {
  scanf("%d", &a);
  for (i = 1; i < a * 2; i *= 2)
    ;
  for (int t = 2 * a; t > a; t--) {
    for (int h = t + i - 1; h; h /= 2)
      o[h]++;
  }
  for (int h = a + i - 1; h; h /= 2)
    o[h] += a, o[h] %= mod;
  for (int t = a - 1; t; t--) {
    o[t + i - 1] = (long long)(a - 1) * (a - 1) % mod + o[t + i];
    o[t + i - 1] += f(t + 3 + i - 1, t + a + 1 + i - 1);
    o[t + i - 1] %= mod;
    for (int h = (t + i - 1) / 2; h; h /= 2)
      o[h] = (o[h * 2] + o[h * 2 + 1]) % mod;
  }
  printf("%lld", o[i]);
}
// 3
// 21


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

struct P {
  long long x, y;
  bool operator<(const P &a) const {
    // if(y!=a.y)
    return y < a.y;
  };
};

int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
long long o[5500101];
int l[500101];
int j[500101];

long long x, y, z, mod = 1000000007;
// string r;
char r[3];

P u[1];
queue<P> q;
stack<int> s;
// set<int> s;
map<int, int> p;

vector<int> v[3];

bool as(P a, P b) {
  if (a.x != b.x)
    return a.x < b.x;
  return a.y > b.y;
}

long long f(int n, int m) {
  long long x = 0;
  for (; n < m;) {
    if (n % 2)
      x += o[n++], x %= mod;
    else if (m % 2 == 0)
      x += o[m--], x %= mod;
    else
      n /= 2, m /= 2;
  }
  return (x + o[n]) % mod;
}

int main() {
  scanf("%d", &a);
  for (i = 1; i < a * 2; i *= 2)
    ;
  for (int t = 2 * a; t > a; t--) {
    for (int h = t + i - 1; h; h /= 2)
      o[h]++;
  }
  for (int h = a + i - 1; h; h /= 2)
    o[h] += a, o[h] %= mod;
  for (int t = a - 1; t; t--) {
    o[t + i - 1] = (long long)(a - 1) * (a - 1) % mod + o[t + i];
    o[t + i - 1] += f(t + 3 + i - 1, t + a + 1 + i - 1);
    o[t + i - 1] %= mod;
    for (int h = (t + i - 1) / 2; h; h /= 2)
      o[h] = (o[h * 2] + o[h * 2 + 1]) % mod;
  }
  printf("%lld", o[i]);
}
// 3
// 21
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
// written by newbiechd
#include <cstdio>
using namespace std;
const int N = 1000007, yyb = 1e9 + 7;
long long f[N], s;
int main() {
  register int n, i;
  scanf("%d", &n);
  f[n] = n, f[n - 1] = 1ll * n * n % yyb;
  for (i = n - 2; i; --i)
    s = (s + f[i + 3]) % yyb,
    f[i] = (f[i + 1] + s + 1ll * (n - 1) * (n - 1) + i + 1) % yyb;
  printf("%lld", f[1]);
  return 0;
}


Fixed submission:
// written by newbiechd
#include <cstdio>
using namespace std;
const int N = 1000007, yyb = 1e9 + 7;
long long f[N], s;
int main() {
  register int n, i;
  scanf("%d", &n);
  f[n] = n, f[n - 1] = 1ll * n * n % yyb;
  for (i = n - 2; i > 0; --i)
    s = (s + f[i + 3]) % yyb,
    f[i] = (f[i + 1] + s + 1ll * (n - 1) * (n - 1) + i + 1) % yyb;
  printf("%lld", f[1]);
  return 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int n, f[1000007], P = 1000000007;
int main() {
  scanf("%d", &n), f[n] = n, f[n - 1] = 1ll * n * n % P;
  for (int i = n - 2, s = 0; i; --i)
    (s += f[i + 3]) %= P,
        f[i] = (f[i + 1] + 1ll * (n - 1) * (n - 1) + s + i + 1) % P;
  printf("%d", f[1]);
}


Fixed submission:
#include <cstdio>
int n, f[1000007], P = 1000000007;
int main() {
  scanf("%d", &n), f[n] = n, f[n - 1] = 1ll * n * n % P;
  for (int i = n - 2, s = 0; i > 0; --i)
    (s += f[i + 3]) %= P,
        f[i] = (f[i + 1] + 1ll * (n - 1) * (n - 1) + s + i + 1) % P;
  printf("%d", f[1]);
}
Problem p03766 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define LL long long
#define R register int
using namespace std;
const int YL = 1e9 + 7;
inline void M(R &x) {
  if (x >= YL)
    x -= YL;
}
int main() {
  R n;
  cin >> n;
  R f2 = 0, f1 = n, f = (LL)n * n % YL, t = (LL)(n - 1) * (n - 1) % YL, s = 0;
  for (R i = n - 2; i; --i)
    M(s += f2), f2 = f1, f1 = f, M(f += t), M(f += s + i + 1);
  return cout << f << endl, 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define R register int
using namespace std;
const int YL = 1e9 + 7;
inline void M(R &x) {
  if (x >= YL)
    x -= YL;
}
int main() {
  R n;
  cin >> n;
  R f2 = 0, f1 = n, f = (LL)n * n % YL, t = (LL)(n - 1) * (n - 1) % YL, s = 0;
  for (R i = n - 2; i > 0; --i)
    M(s += f2), f2 = f1, f1 = f, M(f += t), M(f += s + i + 1);
  return cout << f << endl, 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
template <class T> inline void Inc(T &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return;
}
int f[N];
typedef long long ll;
int main() {
  cin >> n;
  f[n] = n, f[n - 1] = (ll)n * n % mod;
  int s = 0;
  for (int i = n - 2; i; --i)
    Inc(s, f[i + 3]),
        f[i] = ((ll)(n - 1) * (n - 1) % mod + f[i + 1] + s + i + 1) % mod;
  cout << f[1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
template <class T> inline void Inc(T &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return;
}
int f[N];
typedef long long ll;
int main() {
  cin >> n;
  f[n] = n, f[n - 1] = (ll)n * n % mod;
  int s = 0;
  for (int i = n - 2; i > 0; --i)
    Inc(s, f[i + 3]),
        f[i] = ((ll)(n - 1) * (n - 1) % mod + f[i + 1] + s + i + 1) % mod;
  cout << f[1] << endl;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll p = 1e9 + 7;
ll n, i, sum, f[1000010];
int main() {
  scanf("%lld", &n);
  f[n] = n;
  f[n - 1] = n * n % p;
  for (i = n - 2; i; i--) {
    sum = (sum + f[i + 3]) % p;
    f[i] = (f[i + 1] + (n - 1) * (n - 1) % p + sum + i + 1) % p;
  }
  printf("%lld", f[1]);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll p = 1e9 + 7;
ll n, i, sum, f[1000010];
int main() {
  scanf("%lld", &n);
  f[n] = n;
  f[n - 1] = n * n % p;
  for (i = n - 2; i >= 1; i--) {
    sum = (sum + f[i + 3]) % p;
    f[i] = (f[i + 1] + (n - 1) * (n - 1) % p + sum + i + 1) % p;
  }
  printf("%lld", f[1]);
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-')
    c = getchar();
  if (c == '-')
    q = 0, c = getchar();
  while (c >= '0' && c <= '9')
    w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
const int N = 2e6;
int f[N], pre[N];
int main() {
  const int mod = 1e9 + 7;
  int n = gi(), i, ans;
  if (n == 1)
    return puts("1");
  f[0] = pre[0] = 1;
  ans = (n + 1LL * (n - 1) * (n - 1)) % mod;
  for (i = 1; i < n; i++) {
    f[i] = i >= 3 ? (f[i - 1] + pre[i - 3]) % mod : f[i - 1];
    if (i < n - 1)
      ans = (ans + 1LL * f[i] * (n - 1) % mod * (n - 1)) % mod;
    ans = (ans + 1LL * f[i] * (n - 1)) % mod;
    pre[i] = (f[i] + pre[i - 1]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-')
    c = getchar();
  if (c == '-')
    q = 0, c = getchar();
  while (c >= '0' && c <= '9')
    w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
const int N = 2e6;
int f[N], pre[N];
int main() {
  const int mod = 1e9 + 7;
  int n = gi(), i, ans;
  f[0] = pre[0] = 1;
  ans = (n + 1LL * (n - 1) * (n - 1)) % mod;
  for (i = 1; i < n; i++) {
    f[i] = i >= 3 ? (f[i - 1] + pre[i - 3]) % mod : f[i - 1];
    if (i < n - 1)
      ans = (ans + 1LL * f[i] * (n - 1) % mod * (n - 1)) % mod;
    ans = (ans + 1LL * f[i] * (n - 1)) % mod;
    pre[i] = (f[i] + pre[i - 1]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03766 (C++)

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

using namespace std;

const long long MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> dp(n + 2, 0);
  dp[n] = n;
  dp[n - 1] = (n * n) % MOD;
  dp[n - 2] = ((2 * n - 1) * n) % MOD;
  for (long long i = n - 3, cur = n - 1; i >= 1; i--) {
    (cur += dp[i + 3] + MOD - 1) %= MOD;
    (dp[i] += (n - 1) * (n - 1)) %= MOD;
    (dp[i] += dp[i + 1]) %= MOD;
    (dp[i] += cur) %= MOD;
  }
  cout << dp[1] << endl;
  return 0;
}


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

using namespace std;

const long long MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> dp(n + 2, 0);
  dp[n] = n;
  if (n > 1)
    dp[n - 1] = (n * n) % MOD;
  if (n > 2)
    dp[n - 2] = ((2 * n - 1) * n) % MOD;
  for (long long i = n - 3, cur = n - 1; i >= 1; i--) {
    (cur += dp[i + 3] + MOD - 1) %= MOD;
    (dp[i] += (n - 1) * (n - 1)) %= MOD;
    (dp[i] += dp[i + 1]) %= MOD;
    (dp[i] += cur) %= MOD;
  }
  cout << dp[1] << endl;
  return 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x)                                                                \
  freopen(#x ".in", "r", stdin);                                               \
  freopen(#x ".out", "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

const int N = 1000000 + 10;
const int mod = 1e9 + 7;

int n, dp[N];

int main() {
  n = read();
  dp[n] = n, dp[n - 1] = 1ll * n * n % mod;
  for (int i = n - 2, s = 0; i; --i) {
    dp[i] = (s + i + 1 + 1ll * (n - 1) * (n - 1) + dp[i + 1]) % mod;
    s = (s + dp[i + 2]) % mod;
  }
  printf("%d\n", dp[1]);
  return 0;
}

Fixed submission:
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x)                                                                \
  freopen(#x ".in", "r", stdin);                                               \
  freopen(#x ".out", "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

const int N = 1000000 + 10;
const int mod = 1e9 + 7;

int n, dp[N];

int main() {
  n = read();
  if (n == 1) {
    puts("1");
    return 0;
  }
  dp[n] = n, dp[n - 1] = 1ll * n * n % mod;
  for (int i = n - 2, s = 0; i; --i) {
    dp[i] = (s + i + 1 + 1ll * (n - 1) * (n - 1) + dp[i + 1]) % mod;
    s = (s + dp[i + 2]) % mod;
  }
  printf("%d\n", dp[1]);
  return 0;
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define N 1000015
const int p = 1e9 + 7;
int n, dp[N], s[N];
int main() {
  scanf("%d", &n);
  dp[n] = n;
  s[n] = n;
  dp[n - 1] = 1ll * n * n % p;
  s[n - 1] = (s[n] + dp[n - 1]) % p;
  for (int i = n - 2; i; i--) {
    dp[i] = (dp[i] + dp[i + 1]) % p;
    dp[i] = (dp[i] + 1ll * (n - 1) * (n - 1) % p) % p;
    dp[i] = (dp[i] + s[i + 3]) % p;
    dp[i] = (dp[i] + i + 1) % p;
    s[i] = (s[i + 1] + dp[i]) % p;
  }
  printf("%d\n", dp[1]);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define N 1000015
const int p = 1e9 + 7;
int n, dp[N], s[N];
int main() {
  scanf("%d", &n);
  dp[n] = n;
  s[n] = n;
  dp[n - 1] = 1ll * n * n % p;
  s[n - 1] = (s[n] + dp[n - 1]) % p;
  for (int i = n - 2; i > 0; i--) {
    dp[i] = (dp[i] + dp[i + 1]) % p;
    dp[i] = (dp[i] + 1ll * (n - 1) * (n - 1) % p) % p;
    dp[i] = (dp[i] + s[i + 3]) % p;
    dp[i] = (dp[i] + i + 1) % p;
    s[i] = (s[i + 1] + dp[i]) % p;
  }
  printf("%d\n", dp[1]);
}
Problem p03766 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX = 1e6 + 5, mod = 1e9 + 7;
int n;
int f[MAX];
int main() {
  scanf("%d", &n), f[n] = n, f[n - 1] = 1ll * n * n % mod;
  for (int i = n - 2, sum = 0; i; --i)
    (sum += f[i + 3]) %= mod,
        (f[i] +=
         ((1ll * (n - 1) * (n - 1) % mod + f[i + 1]) % mod + i + 1 + sum) %
         mod) %= mod;
  return printf("%d", f[1]), 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX = 1e6 + 5, mod = 1e9 + 7;
int n;
int f[MAX];
int main() {
  scanf("%d", &n), f[n] = n, f[n - 1] = 1ll * n * n % mod;
  for (int i = n - 2, sum = 0; i >= 1; --i)
    (sum += f[i + 3]) %= mod,
        (f[i] +=
         ((1ll * (n - 1) * (n - 1) % mod + f[i + 1]) % mod + i + 1 + sum) %
         mod) %= mod;
  return printf("%d", f[1]), 0;
}
Problem p03767 (C++)

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

using namespace std;
long long sum = 0;
int n, st = 1, V[100001];

int main() {
  cin >> n;
  n *= 3;
  for (int i = 1; i <= n; i++)
    cin >> V[i];
  sort(V + 1, V + 1 + n);
  for (int i = n - 1; i >= st; i -= 2)
    sum += V[i], st++;

  cout << sum;
}


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

using namespace std;
long long sum = 0;
long long n, st = 1, V[1000001];

int main() {
  cin >> n;
  n *= 3;
  for (int i = 1; i <= n; i++)
    cin >> V[i];
  sort(V + 1, V + 1 + n);
  for (int i = n - 1; i >= st; i -= 2)
    sum += V[i], st++;

  cout << sum;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
// '
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef unsigned short sint;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
const ld TAU = 2 * acos(-1);
const ld eps = 1e-8;
const int inf = 1e9 + 99;
const ll linf = 1e18 + 99;

int32_t main() {
  int n;
  scanf("%d", &n);
  static int a[100 << 10];
  for (int i = 0; i < n + n + n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll Z = 0;
  for (int i = 1, j = 0; j < n; ++j, i += 2)
    Z += a[i];
  printf("%lld\n", Z);
}


Fixed submission:
// '
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef unsigned short sint;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
const ld TAU = 2 * acos(-1);
const ld eps = 1e-8;
const int inf = 1e9 + 99;
const ll linf = 1e18 + 99;

int32_t main() {
  int n;
  scanf("%d", &n);
  static int a[300 << 10];
  for (int i = 0; i < n + n + n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll Z = 0;
  for (int i = 1, j = 0; j < n; ++j, i += 2)
    Z += a[i];
  printf("%lld\n", Z);
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define FFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) FOR(i, 0, n - 1)
#define int long long
#define MOD 998244353
#define MAXN 100005
#define P pair<int, int>

int a[MAXN];

signed main() {

  int n;
  cin >> n;

  int ans = 0;
  int cnt = 0;
  int pret = 0;

  rep(i, 3 * n) cin >> a[i];
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);

  rep(i, n) ans += a[1 + 2 * i];

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define FFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) FOR(i, 0, n - 1)
#define int long long
#define MOD 998244353
#define MAXN 100005
#define P pair<int, int>

int a[3 * MAXN];

signed main() {

  int n;
  cin >> n;

  int ans = 0;
  int cnt = 0;
  int pret = 0;

  rep(i, 3 * n) cin >> a[i];
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);

  rep(i, n) ans += a[1 + 2 * i];

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
  ll n;
  cin >> n;
  ll a[3 * n + 100];

  rep(i, 3 * n) cin >> a[i];
  sort(a, a + 3 * N, greater<ll>());

  ll sum = 0;
  for (ll i = 0; i < n; ++i) {
    sum += a[2 * i + 1];
  }

  print(sum);
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
  ll n;
  cin >> n;
  ll a[3 * n + 100];

  rep(i, 3 * n) cin >> a[i];
  sort(a, a + 3 * n, greater<ll>());

  ll sum = 0;
  for (ll i = 0; i < n; ++i) {
    sum += a[2 * i + 1];
  }

  print(sum);
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
#define mod(int) (1000000007)
using namespace std;
int test[213456];
signed main() {
  int n, m = 0, a, ans = 0;
  cin >> n;
  for (int h = 0; h < n * 3; h++) {
    cin >> test[h];
  }
  sort(test, test + (n * 3));
  m = (n * 3 - 2) % 2;
  for (int h = n * 3 - 2; h >= n; h--) {
    if (h % 2 == m) {
      ans += test[h];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define int long long
#define mod(int) (1000000007)
using namespace std;
int test[313456];
signed main() {
  int n, m = 0, a, ans = 0;
  cin >> n;
  for (int h = 0; h < n * 3; h++) {
    cin >> test[h];
  }
  sort(test, test + (n * 3));
  m = (n * 3 - 2) % 2;
  for (int h = n * 3 - 2; h >= n; h--) {
    if (h % 2 == m) {
      ans += test[h];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
int n;
long long a[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; ++i)
    scanf("%lld", a + i);
  sort(a + 1, a + 3 * n + 1);
  long long ans = 0;
  for (int i = 3 * n - 1; i >= n + 1; i -= 2)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
int n;
long long a[300005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; ++i)
    scanf("%lld", a + i);
  sort(a + 1, a + 3 * n + 1);
  long long ans = 0;
  for (int i = 3 * n - 1; i >= n + 1; i -= 2)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
Problem p03767 (C++)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 1e5 + 5;

int a[maxn];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n * 3; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n * 3);
  ll sum = 0;
  for (int i = n + 1; i <= n * 3; i += 2) {
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 1e5 + 5;

int a[maxn * 3];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n * 3; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n * 3);
  ll sum = 0;
  for (int i = n + 1; i <= n * 3; i += 2) {
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

int n, A[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 3; i++)
    scanf("%d", &A[i]);
  sort(A + 1, A + 1 + 3 * n);
  long long ans = 0;
  for (int i = 3 * n; i > n; i -= 2)
    ans += A[i - 1];
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int n, A[500010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 3; i++)
    scanf("%d", &A[i]);
  sort(A + 1, A + 1 + 3 * n);
  long long ans = 0;
  for (int i = 3 * n; i > n; i -= 2)
    ans += A[i - 1];
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert {
  template <typename T> _cert &operator<<(T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
  for (auto i = begin; i != end; i++) {
    cerr << (*i) << " ";
  }
  cerr << "\n";
}
int n;
int a[120000];

int main() {
  cin >> n;
  for (int i = 0; i < n * 3; ++i)
    cin >> a[i];
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll sum = 0;
  for (int i = 0; i < n; ++i)
    sum += a[2 * i + 1];
  cout << sum << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert {
  template <typename T> _cert &operator<<(T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
  for (auto i = begin; i != end; i++) {
    cerr << (*i) << " ";
  }
  cerr << "\n";
}
int n;
int a[320000];

int main() {
  cin >> n;
  for (int i = 0; i < n * 3; ++i)
    cin >> a[i];
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll sum = 0;
  for (int i = 0; i < n; ++i)
    sum += a[2 * i + 1];
  cout << sum << "\n";
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \
  if (flg) {                                                                   \
    cout << "YES" << endl;                                                     \
  } else {                                                                     \
    cout << "NO" << endl;                                                      \
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 1000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

ll a[100001];
int main() {

  ll n;
  ll total = 0;

  cin >> n;

  ll n2 = n * 3;
  rep(i, n2) { cin >> a[i]; }
  sort(a, a + n2);

  for (int i = n; i < n2; i += 2) {
    total += a[i];
  }
  cout << total << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \
  if (flg) {                                                                   \
    cout << "YES" << endl;                                                     \
  } else {                                                                     \
    cout << "NO" << endl;                                                      \
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 1000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

ll a[300003];
int main() {

  ll n;
  ll total = 0;

  cin >> n;

  ll n2 = n * 3;
  rep(i, n2) { cin >> a[i]; }
  sort(a, a + n2);

  for (int i = n; i < n2; i += 2) {
    total += a[i];
  }
  cout << total << endl;
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

const int N = 1e5 + 6;

int a[N], n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  long long ans = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int N = 1e6 + 6;

int a[N], n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  long long ans = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
/*
ID: markusz1
TASK: template
PROG: template
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ul;
typedef priority_queue<int> p_int;
typedef priority_queue<ll> p_ll;
typedef priority_queue<double> p_double;

int a[30001], n, temp;
ll sum;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n, greater<int>());
  for (int i = 1; i < 2 * n; i += 2)
    sum += a[i];
  cout << sum << endl;
}

Fixed submission:
/*
ID: markusz1
TASK: template
PROG: template
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ul;
typedef priority_queue<int> p_int;
typedef priority_queue<ll> p_ll;
typedef priority_queue<double> p_double;

int a[300001], n, temp;
ll sum;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n, greater<int>());
  for (int i = 1; i < 2 * n; i += 2)
    sum += a[i];
  cout << sum << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[100010];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int i;
    for (i = 0; i < n * 3; i++)
      scanf("%d", &a[i]);
    sort(a, a + 3 * n);
    long long sum = 0;
    for (i = n * 3 - 2; n > 0; i -= 2) {
      // printf("%d ", a[i]);
      sum += a[i], n--;
    }
    cout << sum << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[300010];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int i;
    for (i = 0; i < n * 3; i++)
      scanf("%d", &a[i]);
    sort(a, a + 3 * n);
    long long sum = 0;
    for (i = n * 3 - 2; n > 0; i -= 2) {
      // printf("%d ", a[i]);
      sum += a[i], n--;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[114514] = {};
  long long int ans = 0;
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + (3 * n), greater<int>());
  for (int i = 1; i <= 2 * n - 1; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[364364] = {};
  long long int ans = 0;
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + (3 * n), greater<int>());
  for (int i = 1; i <= 2 * n - 1; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;
}
Problem p03767 (C++)

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

typedef long long ll;
const int maxN = 1000 * 100 + 100;

int a[maxN];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n);
  ll ans = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2)
    ans += a[i];
  cout << ans << endl;
}


Fixed submission:
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxN = 5000 * 100 + 100;

int a[maxN];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n);
  ll ans = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2)
    ans += a[i];
  cout << ans << endl;
}