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

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

template <typename T> inline void rd(T &x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c))
    si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args> inline void rd(T &x, Args &...args) {
  rd(x);
  rd(args...);
}

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int a[kN], n;

int main() {
  rd(n);
  for (int i = 1; i <= 3 * n; ++i)
    rd(a[i]);
  std::sort(a + 1, a + 3 * n + 1, [](int x, int y) { return x > y; });
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += a[i * 2];
  printf("%lld", ans);
  return 0;
}

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

template <typename T> inline void rd(T &x) {
  int si = 1;
  char c = getchar();
  x = 0;
  while (!isdigit(c))
    si = c == '-' ? -1 : si, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  x *= si;
}
template <typename T, typename... Args> inline void rd(T &x, Args &...args) {
  rd(x);
  rd(args...);
}

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 3e5 + 5;

int a[kN], n;

int main() {
  rd(n);
  for (int i = 1; i <= 3 * n; ++i)
    rd(a[i]);
  std::sort(a + 1, a + 3 * n + 1, [](int x, int y) { return x > y; });
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += a[i * 2];
  printf("%lld", ans);
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

// #define _FILES
#define PB push_back
#define MP make_pair

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

const int MAXN = 100005;
int a[MAXN];

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

#ifdef _FILES
  freopen("", "r", stdin);
  freopen("", "w", stdout);
#endif // _FILES
  int n;
  ll ans;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n);
  ans = 0;
  for (int i = n; i < 3 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

// #define _FILES
#define PB push_back
#define MP make_pair

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

const int MAXN = 300005;
int a[MAXN];

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

#ifdef _FILES
  freopen("", "r", stdin);
  freopen("", "w", stdout);
#endif // _FILES
  int n;
  ll ans;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n);
  ans = 0;
  for (int i = n; i < 3 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

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

ll n, a[100005], ans, cnt;

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100005

ll n, a[400005], ans, cnt;

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

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[100009], ans = 0;
  cin >> n;
  for (int i = 0; i < n * 3; i++)
    cin >> a[i];
  sort(a, a + n * 3);
  reverse(a, a + n * 3);
  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + 1];
  }
  cout << ans << endl;
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[300009], ans = 0;
  cin >> n;
  for (int i = 0; i < n * 3; i++)
    cin >> a[i];
  sort(a, a + n * 3);
  reverse(a, a + n * 3);
  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + 1];
  }
  cout << ans << endl;
  return (0);
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
const int maxn = 100000;
int n, a[maxn + 10];
long long tot = 0;
using namespace std;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 3 * n + 1);
  int l = 1, r = 3 * n;
  while (l < r) {
    l++;
    r--;
    tot += a[r];
    r--;
  }
  cout << tot;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
const int maxn = 300000;
int n, a[maxn + 10];
long long tot = 0;
using namespace std;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 3 * n + 1);
  int l = 1, r = 3 * n;
  while (l < r) {
    l++;
    r--;
    tot += a[r];
    r--;
  }
  cout << tot;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPL(i, f, n) for (int i = f, i##_len = (n); i < i##_len; ++i)
typedef long long ll;

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

  int N;
  int a[100010];
  cin >> N;

  REP(i, 3 * N) cin >> a[i];
  sort(a, a + 3 * N, greater<int>());
  ll sum = 0;
  for (int i = 1; i < 2 * N; i += 2) {
    sum += a[i];
  }

  cout << sum << endl;
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPL(i, f, n) for (int i = f, i##_len = (n); i < i##_len; ++i)
typedef long long ll;

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

  int N;
  int a[300010];
  cin >> N;

  REP(i, 3 * N) cin >> a[i];
  sort(a, a + 3 * N, greater<int>());
  ll sum = 0;
  for (int i = 1; i < 2 * N; i += 2) {
    sum += a[i];
  }

  cout << sum << endl;
  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++)
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll a[100000] = {0};
  rep(i, 3 * n) { cin >> a[i]; }
  sort(a, a + 3 * n, greater<int>());
  ll sum = 0;
  ll count = 0;
  for (int i = 0; i < 3 * n; i++) {
    if (i % 2 == 1) {
      sum += a[i];
      count++;
      if (count == n)
        break;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll a[1000000] = {0};
  rep(i, 3 * n) { cin >> a[i]; }
  sort(a, a + 3 * n, greater<int>());
  ll sum = 0;
  ll count = 0;
  for (int i = 0; i < 3 * n; i++) {
    if (i % 2 == 1) {
      sum += a[i];
      count++;
      if (count == n)
        break;
    }
  }
  cout << sum << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  rep(i, 3 * N) { cin >> a.at(i); }
  sort(all(a));
  long long sum = 0;
  rep2(i, N, 2 * N) {
    sum += a.at(2 * i - 3);
    //    cout<<a.at(2*i-3)<<endl;
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  rep(i, 3 * N) { cin >> a.at(i); }
  sort(all(a));
  long long sum = 0;
  if (N == 1) {
    cout << a.at(1) << endl;
    return 0;
  } else if (N == 2) {
    cout << a.at(2) + a.at(4) << endl;
    return 0;
  } else {
    rep2(i, N, 3 * N) {
      sum += a.at(i);
      // cout<<a.at(i)<<endl;
      i++;
    }
  }
  cout << sum << endl;
}
Problem p03767 (C++)

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

int a[100003];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; ++i)
    scanf("%d", &a[i]);
  sort(a, a + 3 * n, greater<int>());
  long long sum = 0;
  for (int i = 1, j = 0; j < n; i += 2)
    sum += a[i], ++j;
  printf("%lld\n", sum);
  return 0;
}


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

int a[300003];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; ++i)
    scanf("%d", &a[i]);
  sort(a, a + 3 * n, greater<int>());
  long long sum = 0;
  for (int i = 1, j = 0; j < n; i += 2)
    sum += a[i], ++j;
  printf("%lld\n", sum);
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long n, x[200000], sum;
int main() {
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> x[i];
  }
  sort(x + 1, x + (3 * n) + 1);
  for (int i = (3 * n) - 1; i >= n; i -= 2) {
    sum += x[i];
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, x[500000], sum;
int main() {
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> x[i];
  }
  sort(x + 1, x + (3 * n) + 1);
  for (int i = (3 * n) - 1; i >= n; i -= 2) {
    sum += x[i];
  }
  cout << sum << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
const int inf = 10e9 + 7;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, m, n) for (int i = m; i < n; i++)
#define endre                                                                  \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
int a[100010];
signed main() {
  int n;
  cin >> n;
  rep(i, 3 * n) { cin >> a[i]; }
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  int ans = 0;
  for (int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;
  endre;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
const int inf = 10e9 + 7;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, m, n) for (int i = m; i < n; i++)
#define endre                                                                  \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
int a[300010];
signed main() {
  int n;
  cin >> n;
  rep(i, 3 * n) { cin >> a[i]; }
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  int ans = 0;
  for (int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;
  endre;
}
Problem p03767 (C++)

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

long long n, tab[100010], ans, pos;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int a = 1; a <= 3 * n; a++)
    cin >> tab[a];
  sort(tab + 1, tab + 3 * n + 1);
  pos = 3 * n - 1;
  for (int a = 1; a <= n; a++)
    ans += tab[pos], pos -= 2;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

long long n, tab[300010], ans, pos;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int a = 1; a <= 3 * n; a++)
    cin >> tab[a];
  sort(tab + 1, tab + 3 * n + 1);
  pos = 3 * n - 1;
  for (int a = 1; a <= n; a++)
    ans += tab[pos], pos -= 2;
  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

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

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

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

using namespace std;
typedef long long int ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  int a[100000];
  cin >> n;
  for (int i = 0; i < n * 3; ++i)
    cin >> a[i];
  sort(a, a + (n * 3), greater<int>());

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

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

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

using namespace std;
typedef long long int ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  int a[300000];
  cin >> n;
  for (int i = 0; i < n * 3; ++i)
    cin >> a[i];
  sort(a, a + (n * 3), greater<int>());

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

  cout << ans << "\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++)
using ll = long long;
using namespace std;

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

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

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

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair<db, db> pdd;
typedef pair<db, ld> pdl;
typedef pair<ld, db> pld;
typedef pair<ld, ld> ldp;

typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 100500;

ll ans;
int n, a[N];

int main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  // freopen(".err", "w", stderr);

  // srand(time(NULL));

  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);

  // cout << setprecision(10) << fixed;

  cin >> n;

  for (int i = 1; i <= 3 * n; i++)
    cin >> a[i];

  sort(a + 1, a + 1 + 3 * n);

  for (int i = 3 * n - 1, j = 1; j <= n; j++, i -= 2)
    ans += a[i];

  cout << ans;

  // cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

  return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair<db, db> pdd;
typedef pair<db, ld> pdl;
typedef pair<ld, db> pld;
typedef pair<ld, ld> ldp;

typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 300500;

ll ans;
int n, a[N];

int main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  // freopen(".err", "w", stderr);

  // srand(time(NULL));

  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);

  // cout << setprecision(10) << fixed;

  cin >> n;

  for (int i = 1; i <= 3 * n; i++)
    cin >> a[i];

  sort(a + 1, a + 1 + 3 * n);

  for (int i = 3 * n - 1, j = 1; j <= n; j++, i -= 2)
    ans += a[i];

  cout << ans;

  // cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long int a[10001];
  int count = 0;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }

  sort(a, a + 3 * N, greater<int>());

  long long ans = 0;

  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 0) {
      continue;
    } else {
      ans += a[i];
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long int a[10001000];
  int count = 0;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }

  sort(a, a + 3 * N, greater<int>());

  long long ans = 0;

  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 0) {
      continue;
    } else {
      ans += a[i];
    }
  }

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

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

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

ll arr[MAXN], ans;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++)
    cin >> arr[i];
  sort(arr + 1, arr + 1 + 3 * n);
  for (int i = 3 * n - 1, j = 0; j < n; j++, i -= 2)
    ans += arr[i];
  cout << ans << '\n';
  return 0;
}


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

using namespace std;
const int MAXN = 500005;
const int MOD = 1000000007;

ll arr[MAXN], ans;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++)
    cin >> arr[i];
  sort(arr + 1, arr + 1 + 3 * n);
  for (int i = 3 * n - 1, j = 0; j < n; j++, i -= 2)
    ans += arr[i];
  cout << ans << '\n';
  return 0;
}
Problem p03767 (C++)

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

int main() {
  long long int N, a[100000], count = 0;
  cin >> N;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * N, greater<int>());
  for (int i = 0; i < N; i++) {
    count += a[i * 2 + 1];
  }
  cout << count << endl;
}

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

int main() {
  long long int N, a[300000], count = 0;
  cin >> N;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * N, greater<int>());
  for (int i = 0; i < N; i++) {
    count += a[i * 2 + 1];
  }
  cout << count << endl;
}
Problem p03767 (C++)

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

int main() {
  int N;
  long long int sum = 0, a[300];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  sort(a, a + 3 * N);
  for (int i = N; i < 3 * N; i = i + 2) {
    sum += a[i];
  }
  cout << sum << endl;
}


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

int main() {
  int N;
  long long int sum = 0, a[300000];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  sort(a, a + 3 * N);
  for (int i = N; i < 3 * N; i = i + 2) {
    sum += a[i];
  }
  cout << sum << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll sum = 0;
ll a[3 * 12345];
bool cmd(ll x, ll y) { return x > y; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> a[i];
  }
  int i = 2;
  sort(a + 1, a + 1 + 3 * n, cmd);
  while ((n)--) {
    sum += a[i];
    // cout<<a[i]<<endl;
    i += 2;
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll sum = 0;
ll a[3 * 123456];
bool cmd(ll x, ll y) { return x > y; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> a[i];
  }
  int i = 2;
  sort(a + 1, a + 1 + 3 * n, cmd);
  while ((n)--) {
    sum += a[i];
    // cout<<a[i]<<endl;
    i += 2;
  }
  cout << sum << endl;
  return 0;
}
Problem p03767 (C++)

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

const int N = 1e5 + 10;

int a[N];

bool cmp(const int &x, const int &y) { return x > y; }

int main() {
  int n, p1, p2;
  long long sum;
  scanf("%d", &n);
  for (int i = 1; i <= n * 3; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + n * 3 + 1, cmp);
  sum = 0;
  p1 = 0;
  p2 = n * 3 + 1;
  while (p2 - p1 > 1) {
    ++p1;
    sum += a[++p1];
    p2--;
  }
  printf("%lld\n", sum);
  return 0;
}

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

const int N = 3e5 + 10;

int a[N];

bool cmp(const int &x, const int &y) { return x > y; }

int main() {
  int n, p1, p2;
  long long sum;
  scanf("%d", &n);
  for (int i = 1; i <= n * 3; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + n * 3 + 1, cmp);
  sum = 0;
  p1 = 0;
  p2 = n * 3 + 1;
  while (p2 - p1 > 1) {
    ++p1;
    sum += a[++p1];
    p2--;
  }
  printf("%lld\n", sum);
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

typedef unsigned long long ull;

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

  int M[100010];
  for (int i = 0; i < N * 3; ++i) {
    cin >> M[i];
  }

  sort(M, M + N * 3, greater<int>());

  ull ans = 0;
  for (int i = 1; i < N * 2; i += 2) {
    ans += M[i];
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef unsigned long long ull;

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

  int M[300100];
  for (int i = 0; i < N * 3; ++i) {
    cin >> M[i];
  }

  sort(M, M + N * 3, greater<int>());

  ull ans = 0;
  for (int i = 1; i < N * 2; i += 2) {
    ans += M[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n, a[100100], ans;

int main() {
  cin >> n;
  for (int i = 0; i < n * 3; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n * 3);
  reverse(a, a + n * 3);
  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + 1];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n, a[300100], ans;

int main() {
  cin >> n;
  for (int i = 0; i < n * 3; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n * 3);
  reverse(a, a + n * 3);
  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + 1];
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

long long a[100005] = {};

int main() {
  int n;
  unsigned long long ans = 0;
  cin >> n;

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

  return 0;
}

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

using namespace std;

long long a[300010] = {};

int main() {
  int n;
  unsigned long long ans = 0;
  cin >> n;

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

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "cstring"
#include "iostream"
#include "math.h"
#include "queue"
#include "stack"
#include "string"
#include "vector"

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> mat;

int main() {
  int n;
  cin >> n;
  ll a[100100];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);

  ll ans = 0;
  for (int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << "\n";
}

Fixed submission:
#include "algorithm"
#include "cstring"
#include "iostream"
#include "math.h"
#include "queue"
#include "stack"
#include "string"
#include "vector"

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> mat;

int main() {
  int n;
  cin >> n;
  ll a[300100];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);

  ll ans = 0;
  for (int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << "\n";
}
Problem p03767 (C++)

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

typedef long long ll;
ll n, s, a[100005];
int main() {
  ll i, j;
  cin >> n;
  n *= 3;
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  for (i = n - 2, j = 0; i >= 0 && j < n / 3; i -= 2, j++) {
    s += a[i];
  }
  cout << s;
  return 0;
}


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

typedef long long ll;
ll n, s, a[300005];
int main() {
  ll i, j;
  cin >> n;
  n *= 3;
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  for (i = n - 2, j = 0; i >= 0 && j < n / 3; i -= 2, j++) {
    s += a[i];
  }
  cout << s;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;

int N;
int a[100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  long long ans = 0;
  sort(a, a + 3 * N);
  for (int i = N; i < 3 * N; i += 2)
    ans += a[i];

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;

int N;
int a[300000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  long long ans = 0;
  sort(a, a + 3 * N);
  for (int i = N; i < 3 * N; i += 2)
    ans += a[i];

  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

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

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int n;
  cin >> n;
  long long int a[300001];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  int now = 3 * n - 2;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[now];
    now -= 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MN 110000
#define ld long double
#define ll long long
#define eps 1e-14
using namespace std;

int read_p, read_ca;
inline int read() {
  read_p = 0;
  read_ca = getchar();
  while (read_ca < '0' || read_ca > '9')
    read_ca = getchar();
  while (read_ca >= '0' && read_ca <= '9')
    read_p = read_p * 10 + read_ca - 48, read_ca = getchar();
  return read_p;
}
int n, m, x[MN];
long long MMH = 0;
int main() {
  register int i;
  n = read();
  for (i = 1; i <= 3 * n; i++)
    x[i] = read();
  sort(x + 1, x + 1 + 3 * n);
  for (i = 1; i <= n; i++)
    MMH += x[3 * n - 2 * i + 1];
  printf("%lld\n", MMH);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MN 310000
#define ld long double
#define ll long long
#define eps 1e-14
using namespace std;

int read_p, read_ca;
inline int read() {
  read_p = 0;
  read_ca = getchar();
  while (read_ca < '0' || read_ca > '9')
    read_ca = getchar();
  while (read_ca >= '0' && read_ca <= '9')
    read_p = read_p * 10 + read_ca - 48, read_ca = getchar();
  return read_p;
}
int n, m, x[MN];
long long MMH = 0;
int main() {
  register int i;
  n = read();
  for (i = 1; i <= 3 * n; i++)
    x[i] = read();
  sort(x + 1, x + 1 + 3 * n);
  for (i = 1; i <= n; i++)
    MMH += x[3 * n - 2 * i + 1];
  printf("%lld\n", MMH);
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  long long ans = 0;
  while (a.size()) {
    a.erase(a.begin());
    a.erase(a.begin() + a.size() - 1);
    ans += a[a.size() - 1];
    a.erase(a.begin() + a.size() - 1);
  }

  cout << ans << endl;

  return 0;
}


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

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

  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  long long ans = 0;
  for (int i = a.size() - 2; i >= n; i -= 2) {
    ans += a[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int n;
  int a[111111];
  cin >> n;
  for (int i = 0, end = 3 * n; i < end; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    // cout<<"num:"<<3*n-2*(i+1)<<"\t"<<a[3*n-2*(i+1)]<<endl;
    ans += a[3 * n - 2 * (i + 1)];
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int n;
  int a[1111111];
  cin >> n;
  for (int i = 0, end = 3 * n; i < end; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    // cout<<"num:"<<3*n-2*(i+1)<<"\t"<<a[3*n-2*(i+1)]<<endl;
    ans += a[3 * n - 2 * (i + 1)];
  }
  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n;
long long a[111111];

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

  long long ans = 0;

  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }

  sort(a, a + n * 3);

  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + n];
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n;
long long a[311111];

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

  long long ans = 0;

  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }

  sort(a, a + n * 3);

  for (int i = 0; i < n * 2; i += 2) {
    ans += a[i + n];
  }

  cout << ans << endl;

  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++)

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int N;
  int a[31000];

  cin >> N;
  rep(i, 3 * N) cin >> a[i];

  sort(a, a + (3 * N), greater<int>());

  ul ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[(i * 2) + 1];
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int N;
  int a[310000];

  cin >> N;
  rep(i, 3 * N) cin >> a[i];

  sort(a, a + (3 * N), greater<int>());

  ul ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[(i * 2) + 1];
  }

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

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

typedef long long ll;

int n, a[100005], c;
ll ans;

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

  cin >> n;
  for (int i = 0; i < 3 * n; ++i)
    cin >> a[i];

  sort(a, a + 3 * n);

  for (int i = 3 * n - 2; c++ < n; i -= 2) {
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}

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

typedef long long ll;

int n, a[100005 * 3], c;
ll ans;

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

  cin >> n;
  for (int i = 0; i < 3 * n; ++i)
    cin >> a[i];

  sort(a, a + 3 * n);

  for (int i = 3 * n - 2; c++ < n; i -= 2) {
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)n; i++)
#define Rep(i, n) for (int i = 0; i <= (int)(n - 1); i++)
#define REP(i, b, e) for (int i = b; i < (int)e; i++)
typedef long long ll;
typedef map<ll, ll> mll;
typedef vector<ll> vll;
ll INF = 1e18;
int inf = 1e9 + 1000;

ll N;
ll a[100002];

int main() {
  cin >> N;
  Rep(i, 3 * N) cin >> a[i];
  sort(a, a + 3 * N);
  ll sum = 0;
  Rep(i, N) { sum += a[N + 2 * i]; }
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)n; i++)
#define Rep(i, n) for (int i = 0; i <= (int)(n - 1); i++)
#define REP(i, b, e) for (int i = b; i < (int)e; i++)
typedef long long ll;
typedef map<ll, ll> mll;
typedef vector<ll> vll;
ll INF = 1e18;
int inf = 1e9 + 1000;

ll N;
ll a[300002];

int main() {
  cin >> N;
  Rep(i, 3 * N) cin >> a[i];
  sort(a, a + 3 * N);
  ll sum = 0;
  Rep(i, N) { sum += a[N + 2 * i]; }
  cout << sum << endl;

  return 0;
}
Problem p03767 (C++)

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

int a[100009];

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

  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];

  sort(a, a + 3 * n);

  long long sum1 = 0;

  int start = 0, end = 3 * n - 2;

  while (start <= end) {
    sum1 += a[end];
    // cout<<a[end]<<"\n" ;
    end -= 2;
    start++;
  }

  cout << sum1 << "\n";
  return 0;
}

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

int a[500009];

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

  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];

  sort(a, a + 3 * n);

  long long sum1 = 0;

  int start = 0, end = 3 * n - 2;

  while (start <= end) {
    sum1 += a[end];
    // cout<<a[end]<<"\n" ;
    end -= 2;
    start++;
  }

  cout << sum1 << "\n";
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#define FOR(i, b, e) for (int i = b; i < e; i++)
using namespace std;

long long solve(int *a, int l) {
  long long ans = 0;
  sort(a, a + l);
  for (int i = l / 3; i < l; i += 2)
    ans += a[i];
  return ans;
}

int main() {
  int n;
  int a[100001];
  cin >> n;
  FOR(i, 0, n * 3) cin >> a[i];
  cout << solve(a, n * 3) << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#define FOR(i, b, e) for (int i = b; i < e; i++)
using namespace std;

long long solve(int *a, int l) {
  long long ans = 0;
  sort(a, a + l);
  for (int i = l / 3; i < l; i += 2)
    ans += a[i];
  return ans;
}

int main() {
  int n;
  int a[300001];
  cin >> n;
  FOR(i, 0, n * 3) cin >> a[i];
  cout << solve(a, n * 3) << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int N;
long long A[MAXN];
void solve() {
  sort(A, A + 3 * N, greater<int>());
  long long sum = 0, cnt = 0;
  for (int i = 1; cnt < N; i += 2, cnt++)
    sum += A[i];
  cout << sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  // cin >> test;
  while (test--) {
    cin >> N;
    int i = 0;
    for (i = 0; i < 3 * N; i++)
      cin >> A[i];
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int N;
long long A[MAXN];
void solve() {
  sort(A, A + 3 * N, greater<int>());
  long long sum = 0, cnt = 0;
  for (int i = 1; cnt < N; i += 2, cnt++)
    sum += A[i];
  cout << sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  // cin >> test;
  while (test--) {
    cin >> N;
    int i = 0;
    for (i = 0; i < 3 * N; i++)
      cin >> A[i];
    solve();
  }
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a, b) a = rit(), b = rit()
#define RIII(a, b, c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for (int I = 0; I < int(N); I++)
#define REPP(I, N) for (int I = 1; I <= int(N); I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
inline ll rit() {
  ll f = 0, key = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      key = -1;
    ;
  } while (ch < '0' || ch > '9');
  do {
    f = f * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * key;
}
using namespace std;
typedef pair<int, int> P;
ll ar[100005];
int main(void) {
  ll n;
  RI(n);
  for (int i = 0; i < n * 3; ++i)
    RI(ar[i]);
  sort(ar, ar + n * 3);
  ll ans = 0;
  for (ll i = 1; i <= n; ++i)
    ans += ar[3 * n - i * 2];
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a, b) a = rit(), b = rit()
#define RIII(a, b, c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for (int I = 0; I < int(N); I++)
#define REPP(I, N) for (int I = 1; I <= int(N); I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
inline ll rit() {
  ll f = 0, key = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      key = -1;
    ;
  } while (ch < '0' || ch > '9');
  do {
    f = f * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * key;
}
using namespace std;
typedef pair<int, int> P;
ll ar[300005];
int main(void) {
  ll n;
  RI(n);
  for (int i = 0; i < n * 3; ++i)
    RI(ar[i]);
  sort(ar, ar + n * 3);
  ll ans = 0;
  for (ll i = 1; i <= n; ++i)
    ans += ar[3 * n - i * 2];
  printf("%lld\n", ans);
}
Problem p03767 (C++)

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

typedef long long ll;
int N, A[100005], hd, tl;
ll Ans;

int main() {
  //  freopen("a.in", "r", stdin);
  //  freopen("a.out", "w", stdout);
  scanf("%d", &N), hd = 1, tl = (N *= 3);
  foru(i, 1, N) scanf("%d", &A[i]);
  sort(A + 1, A + N + 1);
  while (tl - hd + 1 >= 3)
    Ans += A[(tl -= 2) + 1], hd++;
  printf("%lld\n", Ans);
  return 0;
}


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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

typedef long long ll;
int N, A[1000005], hd, tl;
ll Ans;

int main() {
  //  freopen("a.in", "r", stdin);
  //  freopen("a.out", "w", stdout);
  scanf("%d", &N), hd = 1, tl = (N *= 3);
  foru(i, 1, N) scanf("%d", &A[i]);
  sort(A + 1, A + N + 1);
  while (tl - hd + 1 >= 3)
    Ans += A[(tl -= 2) + 1], hd++;
  printf("%lld\n", Ans);
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, 3 * n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0;
  for (int i = 1; i < 2 * n; i += 2)
    ans += a[i];
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(3 * n);
  rep(i, 0, 3 * n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  ll ans = 0;
  for (int i = 1; i < 2 * n; i += 2)
    ans += a[i];
  cout << ans << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
int n;
ll a[100000 + 10];
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= 3 * n; ++i)
      scanf("%lld", &a[i]);
    int k = 3 * n - 1;
    int s = 0;
    ll ans = 0;
    sort(a + 1, a + 1 + 3 * n);
    // for(int i = 1;i <= 3*n;++i) printf("%lld ",a[i]);
    for (int s = 0; s < n; ++s) {
      ans += a[k];
      k -= 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
int n;
ll a[3 * 100000 + 10];
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= 3 * n; ++i)
      scanf("%lld", &a[i]);
    int k = 3 * n - 1;
    int s = 0;
    ll ans = 0;
    sort(a + 1, a + 1 + 3 * n);
    // for(int i = 1;i <= 3*n;++i) printf("%lld ",a[i]);
    for (int s = 0; s < n; ++s) {
      ans += a[k];
      k -= 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p03767 (C++)

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

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

#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define SET(a, c) memset(a, c, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define ll long long
#define ull unsigned long long

#define PI (3.1415926535897932)
#define eps 1e-8

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


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

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

#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define SET(a, c) memset(a, c, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define ll long long
#define ull unsigned long long

#define PI (3.1415926535897932)
#define eps 1e-8

int main() {
  int N;
  ll a[300001];
  cin >> N;
  REP(i, 3 * N) cin >> a[i];
  sort(a, a + 3 * N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[3 * N - i * 2 - 2];
  }
  cout << ans << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<ll> a(100010);
  ll i, N, sum = 0;

  cin >> N;
  rep(i, 3 * N) cin >> a[i];

  sort(a.begin(), a.begin() + 3 * N, greater<ll>());

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

  cout << sum;
}

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

int main() {
  vector<ll> a(1000000);
  ll i, N, sum = 0;

  cin >> N;
  rep(i, 3 * N) cin >> a[i];

  sort(a.begin(), a.begin() + 3 * N, greater<ll>());

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

  cout << sum;
}