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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memset(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair<int, int> pa;

const int MAXN = 100010;

int a[MAXN], n;
LL ans;

int main() {
#ifdef wxh010910
  freopen("data.in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + 3 * n + 1);
  for (int i = 3 * n - 1, j = 1; j <= n; i -= 2, j++)
    ans += a[i];
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memset(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair<int, int> pa;

const int MAXN = 300010;

int a[MAXN], n;
LL ans;

int main() {
#ifdef wxh010910
  freopen("data.in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + 3 * n + 1);
  for (int i = 3 * n - 1, j = 1; j <= n; i -= 2, j++)
    ans += a[i];
  cout << ans << endl;
}
Problem p03767 (C++)

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

int main() {

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


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

int main() {

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

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

// #define mod 1000000007

using namespace std;

int N, a[300000];

int main(void) {

  // int N;

  int64_t count = 0;

  cin >> N;

  // int a[N];

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

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

  for (int i = 1; i < N * 2; i += 2)
    count += a[1 + 2 * i];

  cout << count;

  return 0;
}

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

// #define mod 1000000007

using namespace std;

int N, a[300000];

int main(void) {

  // int N;

  int64_t count = 0;

  cin >> N;

  // int a[N];

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

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

  for (int i = 1; i < N * 2; i += 2)
    count += a[i];

  cout << count;

  return 0;
}
Problem p03767 (C++)

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

#define mod 1000000007

using namespace std;

int main(void) {

  int N;

  int64_t count = 0;

  cin >> N;

  int a[N];

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

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

  for (int i = 1; i < N * 2; i += 2)
    count += a[i];

  cout << count;

  return 0;
}

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

#define mod 1000000007

using namespace std;

int main(void) {

  int N;

  int64_t count = 0;

  cin >> N;

  int a[3 * N];

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

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

  for (int i = 1; i < N * 2; i += 2)
    count += a[i];

  cout << count;

  return 0;
}
Problem p03767 (C++)

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

typedef long long ll;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)

ll a[100000];
int main(void) {
  int N;
  cin >> N;
  Rep(i, N * 3) cin >> a[i];

  ll ans = 0;
  sort(a, a + N * 3);
  Rep(i, N) { ans += a[3 * N - 2 - i * 2]; }
  PrintLn(ans);
  return 0;
}


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

typedef long long ll;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)

ll a[300000];
int main(void) {
  int N;
  cin >> N;
  Rep(i, N * 3) cin >> a[i];

  ll ans = 0;
  sort(a, a + N * 3);
  Rep(i, N) { ans += a[3 * N - 2 - i * 2]; }
  PrintLn(ans);
  return 0;
}
Problem p03767 (C++)

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;

signed main() {

  int n, a[111111];
  cin >> n;
  rep(i, n * 3) cin >> a[i];
  sort(a, a + n * 3);
  int co = 0, co2 = 0, ans = 0;
  repb(i, n * 3) {
    co++;
    if (co % 2 == 0) {
      co2++;
      ans += a[i];
      // cout<<a[i]<<endl;
    }
    if (co2 == n)
      break;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;

signed main() {

  int n, a[111111 * 4];
  cin >> n;
  rep(i, n * 3) cin >> a[i];
  sort(a, a + n * 3);
  int co = 0, co2 = 0, ans = 0;
  repb(i, n * 3) {
    co++;
    if (co % 2 == 0) {
      co2++;
      ans += a[i];
      // cout<<a[i]<<endl;
    }
    if (co2 == n)
      break;
  }
  cout << ans << endl;
}
Problem p03767 (C++)

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

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

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

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

  cout << ans << endl;
}


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

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

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

  long long int 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 <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int a[maxn];
int n;
ll ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; ++i)
    scanf("%d", &a[i]);
  sort(a + 1, a + 3 * n + 1);
  for (int i = n + 1; i <= 3 * n; i += 2)
    ans += a[i];
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
typedef long long ll;
int a[maxn];
int n;
ll ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; ++i)
    scanf("%d", &a[i]);
  sort(a + 1, a + 3 * n + 1);
  for (int i = n + 1; 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;
const int MAXN = 1e5 + 10;
int n, a[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  n *= 3;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  for (int i = n - 1; i > n / 3; i -= 2) {
    ans += a[i];
  }
  cout << ans;
  return 0;
}


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

Buggy submission (status: Runtime Error):
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>

const int maxn = 1000 * 100 + 5;
int a[maxn];

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


Fixed submission:
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>

const int maxn = 3000 * 100 + 5;
int a[maxn];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a[100000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  int m = 3 * n;
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll sum = 0;
  for (int i = 1; i < m; i += 2) {
    sum += a[i];
    m--;
  }
  cout << sum << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a[300000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  int m = 3 * n;
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll sum = 0;
  for (int i = 1; i < m; i += 2) {
    sum += a[i];
    m--;
  }
  cout << sum << endl;
}
Problem p03767 (C++)

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

using namespace std;
typedef long long ll;

#define INF (long long)(10e9 + 7)
#define REP(i, n) for (ll i = 0; i < n; i++)

ll a[100010];
ll N;

int main(void) {
  cin >> N;
  ll N3 = N * 3;
  REP(i, N3) cin >> a[i];
  sort(a, a + N3, greater<long long>());
  ll sum = 0;
  REP(i, N) sum += a[i * 2 + 1];
  cout << sum << endl;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(10e9 + 7)
#define REP(i, n) for (ll i = 0; i < n; i++)

ll a[400010];
ll N;

int main(void) {
  cin >> N;
  ll N3 = N * 3;
  REP(i, N3) cin >> a[i];
  sort(a, a + N3, greater<long long>());
  ll sum = 0;
  REP(i, N) sum += a[i * 2 + 1];
  cout << sum << endl;
}
Problem p03767 (C++)

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

using namespace std;

const int maxN = 1e5 + 10;
int N, A[maxN];
long long ans;

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

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

using namespace std;

const int maxN = 3e5 + 10;
int N, A[maxN];
long long ans;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define N (int)1e5
#define F first
#define S second
typedef pair<int, int> P;
typedef long long LL;
LL n, a[N], s, l, ans;
int main() {
  cin >> n;
  n *= 3;
  l = n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n / 3; i++) {
    l -= 2;
    ans += a[l];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define N (int)1e5
#define F first
#define S second
typedef pair<int, int> P;
typedef long long LL;
LL n, a[N * 4], s, l, ans;
int main() {
  cin >> n;
  n *= 3;
  l = n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n / 3; i++) {
    l -= 2;
    ans += a[l];
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = Y - 1; (X) >= 0; --(X))
#define repa(X, A, Y) for (int(X) = A; (X) <= (Y); ++(X))
#define all(X) (X).begin(), (X).end()
#define mod(n, m) (((n) % (m) + (m)) % m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30; // 1.07x10^ 9
const ll INFLL = 1LL << 60; // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

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

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

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

  sort(a, a + 3 * N);
  reverse(a, a + 3 * N);

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

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = Y - 1; (X) >= 0; --(X))
#define repa(X, A, Y) for (int(X) = A; (X) <= (Y); ++(X))
#define all(X) (X).begin(), (X).end()
#define mod(n, m) (((n) % (m) + (m)) % m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30; // 1.07x10^ 9
const ll INFLL = 1LL << 60; // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

const int MAX_N = 100000;
int N;
int a[MAX_N * 3 + 10];

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

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

  sort(a, a + 3 * N);
  reverse(a, a + 3 * N);

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())

ll N;
vector<ll> a;
int main() {
  cin >> N;
  REP(i, 3 * N) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  SORT(a);
  ll ans = 0;
  while (a.size() > 0) {
    a.pop_back();
    ans += a.back();
    a.pop_back();
    a.erase(a.begin());
  }
  printf("%lld\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())

ll N;
vector<ll> a;
int main() {
  cin >> N;
  REP(i, 3 * N) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  SORT(a);
  ll ans = 0;
  ll j = a.size() - 1;
  ll k = 0;
  while (j > k) {
    j--;
    ans += a[j];
    j--;
    k++;
  }
  printf("%lld\n", ans);

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 2e5 + 1;

int a[maxn];

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


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

int a[maxn];

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define barn                                                                   \
  cin.sync_with_stdio(0);                                                      \
  cin.tie(0)
int a[N];
int main() {
  barn;
  // freopen("inputf.in","r",stdin);
  // freopen("outputf.in","w",stdout);
  int n, i, l;
  ll ans = 0;
  cin >> n;
  for (i = 1; i <= 3 * n; i++)
    cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  l = 3 * n - 1;
  for (i = 1; i <= n; i++) {
    ans += a[l];
    l -= 2;
  }
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 300005
#define pii pair<int, int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define barn                                                                   \
  cin.sync_with_stdio(0);                                                      \
  cin.tie(0)
int a[N];
int main() {
  barn;
  // freopen("inputf.in","r",stdin);
  // freopen("outputf.in","w",stdout);
  int n, i, l;
  ll ans = 0;
  cin >> n;
  for (i = 1; i <= 3 * n; i++)
    cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  l = 3 * n - 1;
  for (i = 1; i <= n; i++) {
    ans += a[l];
    l -= 2;
  }
  cout << ans << "\n";
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;

const int N = 100005;

int n;
ll ans;
int a[N];

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;

const int N = 100005;

int n;
ll ans;
int a[N * 3];

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

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

int arr[100000];

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

  sort(arr, arr + 3 * n);
  int cnt = 0;
  long long ans = 0;
  for (int i = 3 * n - 2; cnt != n; i -= 2, cnt++)
    ans += arr[i];

  printf("%lld\n", ans);
  return 0;
}


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

int arr[300000];

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

  sort(arr, arr + 3 * n);
  int cnt = 0;
  long long ans = 0;
  for (int i = 3 * n - 2; cnt != n; i -= 2, cnt++)
    ans += arr[i];

  printf("%lld\n", ans);
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x)                                                              \
  int n;                                                                       \
  while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define unless(flg) if (!(flg))
#define read cin <<
#define echo cout <<
#define fin << '\n'
#define __ << " " <<
#define bash push_back
#define alles(x) x.begin(), x.end()
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
const int INF = 1 << 30;
bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef priority_queue<int> pqit;

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x)                                                              \
  int n;                                                                       \
  while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define unless(flg) if (!(flg))
#define read cin <<
#define echo cout <<
#define fin << '\n'
#define __ << " " <<
#define bash push_back
#define alles(x) x.begin(), x.end()
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
const int INF = 1 << 30;
bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef priority_queue<int> pqit;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(n) begin(n), end(n)

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

  vector<long long> a(3 * n);
  REP(i, 3 * n) { cin >> a[i]; }

  sort(ALL(a));
  reverse(ALL(a));
  long long sum = 0;

  REP(i, n) {
    sum += a[1];
    // a[0],a[1]を削除
    a.erase(a.begin(), a.begin() + 2);
    // aの末尾を削除
    a.pop_back();
  }

  cout << sum << endl;
}

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

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

  vector<long long> a(3 * n);
  REP(i, 3 * n) { cin >> a[i]; }

  sort(ALL(a));
  reverse(ALL(a));
  long long sum = 0;

  REP(i, n) { sum += a[2 * i + 1]; }

  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;

long long a[100010];

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

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

long long a[300010];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)

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

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)

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

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

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100100;

int n;
int a[maxn + 5];

int main() {
#ifdef matthew99
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  scanf("%d", &n);
  n *= 3;
  REP(i, 0, n) scanf("%d", a + i);
  sort(a, a + n);
  LL ret = 0;
  for (int i = n - 2, j = 0; i > j; ++j, i -= 2)
    ret += a[i];
  cout << ret << endl;
  return 0;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 300100;

int n;
int a[maxn + 5];

int main() {
#ifdef matthew99
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  scanf("%d", &n);
  n *= 3;
  REP(i, 0, n) scanf("%d", a + i);
  sort(a, a + n);
  LL ret = 0;
  for (int i = n - 2, j = 0; i > j; ++j, i -= 2)
    ret += a[i];
  cout << ret << endl;
  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
// Bismillahirrahmanirrahim
// by Batrrr Tolkynbayev
#include <bits/stdc++.h>
// skripi krasava
#define respa return 0
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define eb emplace_back
#define forn(i, x, n) for (int i = x; i <= n; ++i)
#define forr(i, n, x) for (int i = n; i >= x; --i)

using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 17, M = N << 2, mod = 1e9 + 7;

ll tt = 1, n, ct, res, a[N];
bool u[N];

void solve() {
  cin >> n;
  forn(i, 1, 3 * n) cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  ll i = 3 * n;
  while (i > 0) {
    if (u[i]) {
      --i;
      continue;
    }
    u[i] = u[i - 1] = u[++ct] = true;
    res += a[i - 1];
    --i;
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // cin >> tt;
  while (tt--)
    solve();
  respa;
}

Fixed submission:
// Bismillahirrahmanirrahim
// by Batrrr Tolkynbayev
#include <bits/stdc++.h>
// skripi krasava
#define respa return 0
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define eb emplace_back
#define forn(i, x, n) for (int i = x; i <= n; ++i)
#define forr(i, n, x) for (int i = n; i >= x; --i)

using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 3e5 + 17, M = N << 2, mod = 1e9 + 7;

ll tt = 1, n, ct, res, a[N];
bool u[N];

void solve() {
  cin >> n;
  forn(i, 1, 3 * n) cin >> a[i];
  sort(a + 1, a + 3 * n + 1);
  ll i = 3 * n;
  while (i > 0) {
    if (u[i]) {
      --i;
      continue;
    }
    u[i] = u[i - 1] = u[++ct] = true;
    res += a[i - 1];
    --i;
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // cin >> tt;
  while (tt--)
    solve();
  respa;
}
Problem p03767 (C++)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int N;
int a[100010];
ll ret;

int main() {
  cin >> N;
  N *= 3;

  rep(i, N) cin >> a[i];
  sort(a, a + N);

  int cnt = 0;
  for (int i = N - 2; i >= 0; i -= 2) {
    ret += a[i];
    ++cnt;
    if (cnt == N / 3) {
      break;
    }
  }
  cout << ret << endl;

  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int N;
int a[300010];
ll ret;

int main() {
  cin >> N;
  N *= 3;

  rep(i, N) cin >> a[i];
  sort(a, a + N);

  int cnt = 0;
  for (int i = N - 2; i >= 0; i -= 2) {
    ret += a[i];
    ++cnt;
    if (cnt == N / 3) {
      break;
    }
  }
  cout << ret << endl;

  return 0;
}
Problem p03767 (C++)

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

// AGC 012 A
int main() {
  int N;
  int a[100000];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];

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

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

// AGC 012 A
int main() {
  int N;
  int a[300000];
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];

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

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

using LLI = long long int;

int N;
LLI as[114514];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N * 3; i++)
    scanf("%lld", &as[i]);
  sort(as, as + N * 3);
  int idx = 3 * N - 2;
  LLI ans = 0;
  for (int i = 0; i < N; i++) {
    ans += as[idx];
    idx -= 2;
  }
  printf("%lld\n", ans);
}


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

using LLI = long long int;

int N;
LLI as[334514];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N * 3; i++)
    scanf("%lld", &as[i]);
  sort(as, as + N * 3);
  int idx = 3 * N - 2;
  LLI ans = 0;
  for (int i = 0; i < N; i++) {
    ans += as[idx];
    idx -= 2;
  }
  printf("%lld\n", ans);
}
Problem p03767 (C++)

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

ll n;
ll a[111111];

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


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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

ll n;
ll a[311111];

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

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

int a[N];

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

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

  return 0;
}

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

int a[N];

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

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

  return 0;
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 20;
ll a[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < 3 * n; i++)
      scanf("%I64d", &a[i]);
    sort(a, a + 3 * n);
    ll ans = 0, cnt = 0;
    for (int i = 3 * n - 2; i >= 0; i -= 2) {
      ans += a[i];
      cnt++;
      if (cnt == n)
        break;
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 20;
ll a[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < 3 * n; i++)
      scanf("%I64d", &a[i]);
    sort(a, a + 3 * n);
    ll ans = 0, cnt = 0;
    for (int i = 3 * n - 2; i >= 0; i -= 2) {
      ans += a[i];
      cnt++;
      if (cnt == n)
        break;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03767 (C++)

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

const int maxn = 1e5 + 10;

int n, a[maxn];

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 = 1, j = n * 3; i <= n; ++i, j -= 2)
    ans += a[j - 1];

  printf("%lld\n", ans);
  return 0;
}

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

const int maxn = 3e5 + 10;

int n, a[maxn];

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 = 1, j = n * 3; i <= n; ++i, j -= 2)
    ans += a[j - 1];

  printf("%lld\n", ans);
  return 0;
}
Problem p03767 (C++)

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

int a[100010];

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 ans = 0;
  for (int i = 0; i < 2 * n; i++)
    if (i % 2)
      ans += a[i];
  printf("%ld\n", ans);
}


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

int a[300100];

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 ans = 0;
  for (int i = 0; i < 2 * n; i++)
    if (i % 2)
      ans += a[i];
  printf("%ld\n", ans);
}
Problem p03767 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#define MAX_N 100001
using namespace std;
typedef long long ll;

ll a[MAX_N];

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

Fixed submission:
#include <algorithm>
#include <iostream>
#define MAX_N 300003
using namespace std;
typedef long long ll;

ll a[MAX_N];

int main() {
  ll N;
  cin >> N;
  for (int i = 0; i < 3 * N; i++)
    cin >> a[i];
  sort(a, a + 3 * N);
  ll ans = 0;
  for (int i = 3 * N - 2; 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 <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int n;
int a[100005];
long long ans = 0;
int main() {
  cin >> n;
  int t = n * 3;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
  }
  sort(a, a + t);
  int k = t - 2;
  while (n--) {
    ans += a[k];
    k -= 2;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int n;
int a[400005];
long long ans = 0;
int main() {
  cin >> n;
  int t = n * 3;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
  }
  sort(a, a + t);
  int k = t - 2;
  while (n--) {
    ans += a[k];
    k -= 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03767 (C++)

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

#define ll long long
const int N = 1e5 + 5, MOD = 1e9 + 7;

int A[N];

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

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

#define ll long long
const int N = 3e5 + 5, MOD = 1e9 + 7;

int A[N];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long ll;
const int N = 100100;
int a[N];
int n, m;
int main() {
  scanf("%d", &n), m = n * 3;
  for (int i = 1; i <= m; i++)
    scanf("%d", a + i);
  std::sort(a + 1, a + m + 1);
  ll ans = 0;
  int pos = m - 1;
  for (int i = 1; i <= n; i++) {
    ans += a[pos];
    pos -= 2;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long ll;
const int N = 100100;
int a[N * 3];
int n, m;
int main() {
  scanf("%d", &n), m = n * 3;
  for (int i = 1; i <= m; i++)
    scanf("%d", a + i);
  std::sort(a + 1, a + m + 1);
  ll ans = 0;
  int pos = m - 1;
  for (int i = 1; i <= n; i++) {
    ans += a[pos];
    pos -= 2;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03767 (C++)

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

int dat[100005];

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

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

int dat[300005];

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

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

const int MXN = 1e5 + 5;
int n;
int a[MXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> a[i];
  sort(a, a + 3 * n);
  int cnt = 0;
  long long res = 0;
  for (int i = 3 * n - 2; i >= 0 && cnt < n; i -= 2, cnt++) {
    res += a[i];
  }
  cout << res << endl;
  return 0;
}

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

const int MXN = 3 * 1e5 + 5;
int n;
int a[MXN];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

ll n, a[100010], r = 0;

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

Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

ll n, a[300010], r = 0;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

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

  int num = 3 * N;

  long long a[num];
  rep(i, num) { cin >> a[i]; }

  sort(a, a + num, greater<int>());

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

  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

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

  int num = 3 * N;

  long long a[num];
  rep(i, num) { cin >> a[i]; }

  sort(a, a + num, greater<int>());

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

  cout << ans << endl;

  return 0;
}