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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define cinf(n, x)                                                             \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i];

int main() {
  ll N;
  cin >> N;
  ll a[100001];
  cinf(3 * N, a);
  ll max;
  sort(a, a + 3 * N, greater<int>());
  for (int i = 1; i < 2 * N; i += 2) {
    max += a[i];
  }
  cout << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define cinf(n, x)                                                             \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i];

int main() {
  ll N;
  cin >> N;
  ll a[1000000];
  cinf(3 * N, a);
  ll max;
  sort(a, a + 3 * N, greater<int>());
  for (int i = 1; i < 2 * N; i += 2) {
    max += a[i];
  }
  cout << max << 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 pb push_back
#define mp make_pair
#define maximize(a, b) ((a) < (b) ? (a) = (b), 1 : 0)
#define minimize(a, b) ((a) > (b) ? (a) = (b), 1 : 0)
void MAIN();
int main() {
  //    freopen("input.txt", "r", stdin);

  MAIN();
  return 0;
}

const int N = 100032;
int n, a[N];

void MAIN() {
  scanf("%d", &n);
  REP(i, 3 * n) scanf("%d", a + i);
  sort(a, a + 3 * n);
  long long ans = 0;
  REP(i, n) { ans += a[3 * n - i * 2 - 2]; }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define maximize(a, b) ((a) < (b) ? (a) = (b), 1 : 0)
#define minimize(a, b) ((a) > (b) ? (a) = (b), 1 : 0)
void MAIN();
int main() {
  //    freopen("input.txt", "r", stdin);

  MAIN();
  return 0;
}

const int N = 100032;
int n, a[3 * N];

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

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

#define R register
#define maxn 100010
int a[maxn];
typedef long long ll;
int main() {
  R int n;
  scanf("%d", &n);
  for (R int i = 1; i <= n * 3; ++i)
    scanf("%d", &a[i]);
  R ll ans = 0;
  std::sort(a + 1, a + n * 3 + 1);
  std::reverse(a + 1, a + n * 3 + 1);
  for (R int i = 1; i <= n; ++i)
    ans += a[i << 1];
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>

#define R register
#define maxn 100010
int a[maxn * 10];
typedef long long ll;
int main() {
  R int n;
  scanf("%d", &n);
  for (R int i = 1; i <= n * 3; ++i)
    scanf("%d", &a[i]);
  R ll ans = 0;
  std::sort(a + 1, a + n * 3 + 1);
  std::reverse(a + 1, a + n * 3 + 1);
  for (R int i = 1; i <= n; ++i)
    ans += a[i << 1];
  printf("%lld\n", ans);
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000];

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

  sort(a, a + n);
  reverse(a, a + n);
  ll sol = 0;
  for (int i = 0; i < n; i += 2) {
    sol += a[i + 1];
    n--;
  }
  cout << sol;
}


Fixed submission:
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[300000];

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

  sort(a, a + n);
  reverse(a, a + n);
  ll sol = 0;
  for (int i = 0; i < n; i += 2) {
    sol += a[i + 1];
    n--;
  }
  cout << sol;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
// default
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double, double> P_d;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define alrep(i, j, n)                                                         \
  for (int i = 0; i < (n); ++i)                                                \
    for (int j = i + 1; j < (n); ++j)
#define Yes cout << "Yes" << endl;
#define No                                                                     \
  cout << "No" << endl;                                                        \
  int ans = 0;
#define answer cout << ans << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;
int gcd(int a, int b) {
  return __gcd(a, b);
} // if you use gcc to compile, use this

signed main() {
  int N, ans = 0;
  cin >> N;
  int a[N];
  rep(i, 3 * N) { cin >> a[i]; }
  sort(a, a + 3 * N);
  rep(i, N) { ans += a[3 * N - 2 - 2 * i]; }
  answer return 0;
}


Fixed submission:
// default
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double, double> P_d;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define alrep(i, j, n)                                                         \
  for (int i = 0; i < (n); ++i)                                                \
    for (int j = i + 1; j < (n); ++j)
#define Yes cout << "Yes" << endl;
#define No                                                                     \
  cout << "No" << endl;                                                        \
  int ans = 0;
#define answer cout << ans << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;
int gcd(int a, int b) {
  return __gcd(a, b);
} // if you use gcc to compile, use this

signed main() {
  int N, ans = 0;
  cin >> N;
  int a[3 * N];
  rep(i, 3 * N) { cin >> a[i]; }
  sort(a, a + 3 * N);
  rep(i, N) { ans += a[3 * N - 2 - 2 * i]; }
  answer return 0;
}
Problem p03767 (C++)

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

int main() {
  int N;
  long long a[100010];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  sort(a, a + 3 * N, greater<long long>());

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

  cout << ans << endl;
}


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

int main() {
  int N;
  long long a[1000000];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  sort(a, a + 3 * N, greater<long long>());

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

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

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

int main() {
  int N;
  cin >> N;
  int a[300100];
  for (int i = 0; i < N * 3; i++) {
    cin >> a[i];
  }
  sort(a, a + N * 3);
  reverse(a, a + N * 3);
  long long ans; // 答えが非常に大きくなる可能性がある
  for (int i = N; i < N * 2; i++) {
    // cout << a[i] << endl;
    ans += a[i * 2 + 1];
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  int a[300100];
  for (int i = 0; i < N * 3; i++) {
    cin >> a[i];
  }
  sort(a, a + N * 3);
  reverse(a, a + N * 3);
  long long ans; // 答えが非常に大きくなる可能性がある
  for (int i = 0; i < N; i++) {
    // cout << a[i] << endl;
    ans += a[i * 2 + 1];
  }
  cout << ans << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main() {
  ll t, arr[100005];
  cin >> t;
  t *= 3;
  for (int i = 1; i <= t; i++) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + (t + 1));
  ll cnt = 0, sum = 0;
  for (int i = t; i > t / 3; i--) {
    if (cnt % 2 == 1)
      sum += arr[i];
    cnt++;
  }
  cout << sum << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main() {
  ll t, arr[300005];
  cin >> t;
  t *= 3;
  for (int i = 1; i <= t; i++) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + (t + 1));
  ll cnt = 0, sum = 0;
  for (int i = t; i > t / 3; i--) {
    if (cnt % 2 == 1)
      sum += arr[i];
    cnt++;
  }
  cout << sum << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[100005];
int32_t main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> ar[i];
  }
  sort(ar + 1, ar + 3 * n + 1);
  set<int> se;
  int ans = 0;
  for (int i = 3 * n - 1; se.size() < n; i -= 2) {
    // cout<<i<<" "<<ar[i]<<"\n";
    ans += ar[i];
    se.insert(i);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[300005];
int32_t main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 3 * n; i++) {
    cin >> ar[i];
  }
  sort(ar + 1, ar + 3 * n + 1);
  set<int> se;
  int ans = 0;
  for (int i = 3 * n - 1; se.size() < n; i -= 2) {
    // cout<<i<<" "<<ar[i]<<"\n";
    ans += ar[i];
    se.insert(i);
  }
  cout << ans;
}
Problem p03767 (C++)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for (int i = 1; i <= n; ++i)
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))

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

const int N = 200200;
const int mod = 1e9 + 7;
const ll INF = 1e18;
ll n, a[N], ans;

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

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for (int i = 1; i <= n; ++i)
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))

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

const int N = 600200;
const int mod = 1e9 + 7;
const ll INF = 1e18;
ll n, a[N], ans;

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define rd(x) cin >> x;
#define rda(a, n)                                                              \
  for (int i = 1; i <= n; i++)                                                 \
    cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a, n)                                                              \
  for (int i = 1; i <= n; i++)                                                 \
    cout << a[i] << ' ';                                                       \
  cout << '\n';
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp {
  bool operator()(int a, int b) { return a > b; }
};

long long n, t, a[100005], cnt;

int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= 3 * n; i++)
    cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  for (int i = 3 * n - 1; t < n; i -= 2)
    t++, cnt += a[i];
  cout << cnt;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define rd(x) cin >> x;
#define rda(a, n)                                                              \
  for (int i = 1; i <= n; i++)                                                 \
    cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a, n)                                                              \
  for (int i = 1; i <= n; i++)                                                 \
    cout << a[i] << ' ';                                                       \
  cout << '\n';
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp {
  bool operator()(int a, int b) { return a > b; }
};

long long n, t, a[300005], cnt;

int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= 3 * n; i++)
    cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  for (int i = 3 * n - 1; t < n; i -= 2)
    t++, cnt += a[i];
  cout << cnt;
}
Problem p03767 (C++)

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

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n * 3);

  REP(i, n * 3) { cin >> a[i]; }
  sort(a.begin(), a.end());

  ll cnt = 0;
  ll i = n - 2;
  ll res = 0;

  while (cnt < n) {
    res += a[i];
    ++cnt;
    i -= 2;
  }

  cout << res << endl;

  return 0;
}


Fixed submission:
#include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <vector>

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n * 3);

  REP(i, n * 3) { cin >> a[i]; }
  sort(a.begin(), a.end());

  ll cnt = 0;
  ll i = n * 3 - 2;
  ll res = 0;

  while (cnt < n) {
    res += a[i];
    ++cnt;
    i -= 2;
  }

  cout << res << endl;

  return 0;
}
Problem p03767 (C++)

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

int N;
const int MAX_N = 1.0e5 + 100;
ll A[MAX_N];

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

  sort(A, A + M, greater<>());

  ll ans = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 1)
      ans += A[i];
  }

  cout << ans << endl;

  return 0;
}


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

int N;
const int MAX_N = 3.0e5 + 100;
ll A[MAX_N];

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

  sort(A, A + M, greater<>());

  ll ans = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 1)
      ans += A[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03767 (C++)

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

long long N;
const int MAX_N = 100000;
long long a[MAX_N];

using namespace std;

void solve() {
  sort(a, a + 3 * N);
  reverse(a, a + 3 * N);
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += a[i * 2 - 1];
  }
  cout << ans << endl;
}

int main() {
  // 入力
  cin >> N;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }
  solve();
  return 0;
}


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

long long N;
const long long MAX_N = 100000000;
long long a[MAX_N];

using namespace std;

void solve() {
  sort(a, a + 3 * N);
  reverse(a, a + 3 * N);
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += a[i * 2 - 1];
  }
  cout << ans << endl;
}

int main() {
  // 入力
  cin >> N;
  for (int 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 ll long long
#define pl pair<ll, ll>
#define ps pair<string, string>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define st string
#define vs vector<st>
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fd(i, a, b) for (ll i = (a); i > (b); i--)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define fs first
#define sc second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld %lld", &a, &b)
#define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c);
#define pf printf
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define pfls(n) printf("%lld ", n)
#define pfci(n, ans) printf("Case %lld: %d\n", n, ans)
#define pfcl(n, ans) printf("Case %lld: %lld\n", n, ans)
#define pfcd(n, ans) printf("Case %lld: %lf\n", n, ans)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(a, v) memset(a, v, sizeof(a))
#define MAX 100007
#define MOD 1234567
#define INF 1e12
#define LG 16
#define mid ((l + r) / 2)
#define H(i, j) (i * 107 + j)
#define IN(n) (2 * (n))
#define OUT(n) (2 * (n) + 1)
using namespace std;

ll a[MAX];
int main() {
  ll N;
  sl(N);
  f(i, 0, 3 * N) { sl(a[i]); }
  sort(a, a + 3 * N);
  ll ans = 0;
  for (ll i = N; i < 3 * N; i += 2) {
    ans += a[i];
  }
  pfl(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pl pair<ll, ll>
#define ps pair<string, string>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define st string
#define vs vector<st>
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fd(i, a, b) for (ll i = (a); i > (b); i--)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define fs first
#define sc second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld %lld", &a, &b)
#define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c);
#define pf printf
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define pfls(n) printf("%lld ", n)
#define pfci(n, ans) printf("Case %lld: %d\n", n, ans)
#define pfcl(n, ans) printf("Case %lld: %lld\n", n, ans)
#define pfcd(n, ans) printf("Case %lld: %lf\n", n, ans)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(a, v) memset(a, v, sizeof(a))
#define MAX 10000007
#define MOD 1234567
#define INF 1e12
#define LG 16
#define mid ((l + r) / 2)
#define H(i, j) (i * 107 + j)
#define IN(n) (2 * (n))
#define OUT(n) (2 * (n) + 1)
using namespace std;

ll a[MAX];
int main() {
  ll N;
  sl(N);
  f(i, 0, 3 * N) { sl(a[i]); }
  sort(a, a + 3 * N);
  ll ans = 0;
  for (ll i = N; i < 3 * N; i += 2) {
    ans += a[i];
  }
  pfl(ans);
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
using namespace std;
typedef long long ll;

int x[100005];
int n;

int main() {
  scanf("%d", &n);
  fore(i, 0, 3 * n) scanf("%d", x + i);
  sort(x, x + 3 * n);
  reverse(x, x + 3 * n);
  ll r = 0;
  fore(i, 0, n) r += x[2 * i + 1];
  printf("%lld\n", r);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
using namespace std;
typedef long long ll;

int x[300005];
int n;

int main() {
  scanf("%d", &n);
  fore(i, 0, 3 * n) scanf("%d", x + i);
  sort(x, x + 3 * n);
  reverse(x, x + 3 * n);
  ll r = 0;
  fore(i, 0, n) r += x[2 * i + 1];
  printf("%lld\n", r);
  return 0;
}
Problem p03767 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
member = sorted(map(int, input().split()))
ans = 0
while member:
    member.pop()
    ans += member.pop()
    member.pop(0)
print(ans)


Fixed submission:
N = int(input())
member = sorted(map(int, input().split()))
ans = sum(member[N::2])
print(ans)
Problem p03767 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    a = a[1:]
    ans += a[-2]
    a = a[:-2]
print(ans)


Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    ans += a[3 * n - 2 - 2 * i]
print(ans)
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

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


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

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

Buggy submission (status: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

_sum = 0

for i in range(N):
    a.remove(max(a))
    _sum += max(a)
    a.remove(max(a))

print(_sum)


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

a.sort(reverse=True)
print(sum(a[1 : 2 * N][::2]))
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int a[100000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + 3 * n);
  ll sum = 0;
  int cnt = 0;
  for (int i = 3 * n - 1; i >= 0 && cnt < n; --i) {
    if (((3 * n - 1) - i) % 2) {
      sum += a[i];
      ++cnt;
    }
  }
  cout << sum << '\n';
  return 0;
}


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

int a[300000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + 3 * n);
  ll sum = 0;
  int cnt = 0;
  for (int i = 3 * n - 1; i >= 0 && cnt < n; --i) {
    if (((3 * n - 1) - i) % 2) {
      sum += a[i];
      ++cnt;
    }
  }
  cout << sum << '\n';
  return 0;
}
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;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int, int> ipair;
// typedef tuple<int, int, int> ituple;

// const int INF = (int)2e9;
// const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;

#define MAX_N 100000 + 2

void exec() {
  int a[MAX_N], n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", &a[i]);
  }

  sort(a, a + 3 * n);
  ll ans = 0;
  int count = 0;
  int pos = 3 * n - 2;
  while (count < n) {
    ans += a[pos];
    // printf("a[%d] = %d¥n", pos, a[pos]);
    pos -= 2;
    count++;
  }

  cout << ans << endl;
}

void solve() {
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    exec();
  }
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>

#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int, int> ipair;
// typedef tuple<int, int, int> ituple;

// const int INF = (int)2e9;
// const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;

#define MAX_N 300000 + 2

void exec() {
  int a[MAX_N], n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", &a[i]);
  }

  sort(a, a + 3 * n);
  ll ans = 0;
  int count = 0;
  int pos = 3 * n - 2;
  while (count < n) {
    ans += a[pos];
    // printf("a[%d] = %d¥n", pos, a[pos]);
    pos -= 2;
    count++;
  }

  cout << ans << endl;
}

void solve() {
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    exec();
  }
}

int main() {
  solve();
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

ll n, a[100000];

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

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

  return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

ll n, a[300000];

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

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

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <complex>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <set> // S.insert(M);
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>  // get<n>(xxx)
#include <vector>
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
#include <random>  // random_device rd; mt19937 mt(rd());
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll a[100010];

int main() {
  cin >> N;
  N = 3 * N;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
  }
  sort(a, a + N);
  reverse(a, a + N);
  ll ans = 0;
  int M = N / 3;
  int cnt = 0;
  for (auto i = 0; i < N; ++i) {
    if (i % 2 == 1) {
      ans += a[i];
      ++cnt;
      if (M == cnt)
        break;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <complex>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <set> // S.insert(M);
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>  // get<n>(xxx)
#include <vector>
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
#include <random>  // random_device rd; mt19937 mt(rd());
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll a[300010];

int main() {
  cin >> N;
  N = 3 * N;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
  }
  sort(a, a + N);
  reverse(a, a + N);
  ll ans = 0;
  int M = N / 3;
  int cnt = 0;
  for (auto i = 0; i < N; ++i) {
    if (i % 2 == 1) {
      ans += a[i];
      ++cnt;
      if (M == cnt)
        break;
    }
  }
  cout << ans << endl;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
// #include<cstdio>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
int N;
ll A[Nmax];

int main() {
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> A[i];
  sort(A, A + 3 * N);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[N + 2 * i];
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iomanip>
#include <iostream>
// #include<cstdio>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
int N;
ll A[3 * Nmax];

int main() {
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> A[i];
  sort(A, A + 3 * N);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[N + 2 * 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;
const int N = 1e5 + 5;
int a[N];

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 5;
int a[N];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  long long ans = 0;
  bool flg = true;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = n; i < 3 * n; i++) {
    if (flg) {
      ans += a[i];
      flg = false;
    } else
      flg = true;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  long long ans = 0;
  bool flg = true;
  cin >> n;
  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = n; i < 3 * n; i++) {
    if (flg) {
      ans += a[i];
      flg = false;
    } else
      flg = true;
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);

using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
    x = (x * x) % MOD;
    n >>= 1; // 右シフト(n = n >> 1)
  }
  return res;
}

Int ans;
Int a[100005];

int main() {
  cin.tie(0);

  int N;
  cin >> N;
  N *= 3;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  int left = 0;
  int mid = N - 2;
  int right = N - 1;
  while (left < mid && mid < right) {
    ans += a[mid];
    mid -= 2;
    right -= 2;
    left += 1;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);

using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
    x = (x * x) % MOD;
    n >>= 1; // 右シフト(n = n >> 1)
  }
  return res;
}

Int ans;
Int a[300005];

int main() {
  cin.tie(0);

  int N;
  cin >> N;
  N *= 3;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  int left = 0;
  int mid = N - 2;
  int right = N - 1;
  while (left < mid && mid < right) {
    ans += a[mid];
    mid -= 2;
    right -= 2;
    left += 1;
  }
  cout << ans << endl;
}
Problem p03767 (C++)

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

ll n;
ll a[33000];

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

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

ll n;
ll a[330000];

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

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

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

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

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

  return 0;
}

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

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

  return 0;
}
Problem p03767 (C++)

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

using namespace std;

int main() {
  long long N;
  cin >> N;
  N *= 3;
  long long a[10000];
  long long sum = 0;
  long long cnt = 1;

  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  sort(a + 1, a + 1 + N);

  for (int i = N - 1; i >= cnt; i -= 2) {
    sum += a[i];
    cnt++;
  }

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

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

using namespace std;

int main() {
  long long N;
  cin >> N;
  N *= 3;
  long long a[1000000];
  long long sum = 0;
  long long cnt = 1;

  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  sort(a + 1, a + 1 + N);

  for (int i = N - 1; i >= cnt; i -= 2) {
    sum += a[i];
    cnt++;
  }

  cout << sum << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main() {
  int n;
  cin >> n;
  vector<int> x(n * 3);
  for (auto &&i : x)
    cin >> i;
  sort(x.begin(), x.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i)
    ans += x[n * i + 1];
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main() {
  int n;
  cin >> n;
  vector<int> x(n * 3);
  for (auto &&i : x)
    cin >> i;
  sort(x.begin(), x.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i)
    ans += x[i * 2 + 1];
  cout << ans << '\n';
  return 0;
}
Problem p03767 (C++)

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

using namespace std;
typedef long long ll;

int a[100001];

int main(void) {
  int n;
  ll ans = 0;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  for (int i = 0; i < n; i++)
    ans += a[3 * n - 2 - 2 * i];
  return !printf("%lld\n", ans);
}

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

using namespace std;
typedef long long ll;

int a[300003];

int main(void) {
  int n;
  ll ans = 0;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    scanf("%d", a + i);
  sort(a, a + 3 * n);
  for (int i = 0; i < n; i++)
    ans += a[3 * n - 2 - 2 * i];
  return !printf("%lld\n", ans);
}
Problem p03767 (C++)

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9 + 7;

int a[100005];

int main() {
  int n;
  scanf("%d", &n);
  n *= 3;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  reverse(a, a + n);
  ll sol = 0;
  for (int i = 0; i < n / 3; i++) {
    sol += a[i * 2 + 1];
  }
  printf("%lld\n", sol);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9 + 7;

int a[300005];

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

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

int A[100005];

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

  int i;

  for (i = 1; i <= 3 * N; i++) {
    cin >> A[i];
  }

  sort(A + 1, A + 3 * N + 1);

  long long sum = 0;
  int cnt = 0;

  for (i = 3 * N - 1; cnt < N && i > 0; i -= 2) {
    sum += A[i];
    cnt++;
  }

  cout << sum;
}

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

int A[300005];

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

  int i;

  for (i = 1; i <= 3 * N; i++) {
    cin >> A[i];
  }

  sort(A + 1, A + 3 * N + 1);

  long long sum = 0;
  int cnt = 0;

  for (i = 3 * N - 1; cnt < N && i > 0; i -= 2) {
    sum += A[i];
    cnt++;
  }

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

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

using namespace std;

const int maxn = 1e5 + 20;
int b[maxn];

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

  long long ans = 0;
  sort(b, b + 3 * n);
  int x = 2;
  while (n--) {
    ans += b[3 * a - x];
    x += 2;
  }
  cout << ans;
}


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

using namespace std;

const int maxn = 1e5 * 3 + 20;
int b[maxn];

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

  long long ans = 0;
  sort(b, b + 3 * n);
  int x = 2;
  while (n--) {
    ans += b[3 * a - x];
    x += 2;
  }
  cout << ans;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4 * atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
  const int MAX = 10001;
  ll N;
  cin >> N;
  ll a[3 * MAX];
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  // sort
  sort(a, a + 3 * N, greater<ll>());
  ll sum = 0;
  for (int i = 0; i < 2 * N; i++) {
    // cout<<a[i]<<endl;
    if (i % 2)
      sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4 * atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
  const int MAX = 100001;
  ll N;
  cin >> N;
  ll a[3 * MAX];
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  // sort
  sort(a, a + 3 * N, greater<ll>());
  ll sum = 0;
  for (int i = 0; i < 2 * N; i++) {
    // cout<<a[i]<<endl;
    if (i % 2)
      sum += a[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p03767 (C++)

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

using namespace std;

int N;

int main() {
  cin >> N;
  int A[100000];
  for (int i = 0; i < 3 * N; i++) {
    cin >> A[i];
  }
  sort(A, A + 3 * N, greater<>());
  long long int sum = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt++;
    sum += A[cnt];
    cnt++;
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

int N;

int main() {
  cin >> N;
  int A[1000000];
  for (int i = 0; i < 3 * N; i++) {
    cin >> A[i];
  }
  sort(A, A + 3 * N, greater<>());
  long long int sum = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt++;
    sum += A[cnt];
    cnt++;
  }
  cout << sum << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  long long int a[100010];
  long long int ans = 0;

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

  sort(a, a + 3 * n);

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  long long int a[300010];
  long long int ans = 0;

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

  sort(a, a + 3 * n);

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

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

int n;
int a[100000];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * 3; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n * 3);

  long long sum = 0;
  for (int i = n * 3 - 1, j = 0; j < i;) {
    if (i - 1 <= j)
      break;
    sum += a[i - 1];
    i -= 2;
    ++j;
  }
  printf("%lld\n", sum);
  return 0;
}

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

int n;
int a[300000];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * 3; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n * 3);

  long long sum = 0;
  for (int i = n * 3 - 1, j = 0; j < i;) {
    if (i - 1 <= j)
      break;
    sum += a[i - 1];
    i -= 2;
    ++j;
  }
  printf("%lld\n", sum);
  return 0;
}
Problem p03767 (C++)

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

const int maxn = 100010;
int n, a[maxn];

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

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

const int maxn = 300010;
int n, a[maxn];

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

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

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

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

  long long ans = 0;

  int i = 1;
  while (n) {
    ans += a[i];
    n--;
    i += 2;
  }

  cout << ans << endl;
}


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

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

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

  long long ans = 0;

  int i = 1;
  while (n) {
    ans += a[i];
    n--;
    i += 2;
  }

  cout << ans << endl;
}