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

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

#define endl '\n'
#define ll long long
#define int long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

#define db long double;
#define pll pair<ll, ll>;

#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x)                                                         \
  sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p)                                                           \
  cout << fixed << setprecision((p)) << x << endl // print with precision

#define tc(tt)                                                                 \
  ll tt;                                                                       \
  cin >> tt;                                                                   \
  for (ll _tt = 0; _tt < tt; _tt++) // testcase

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
// online submission
#endif

  ll t, i, x, j, y, z = 0, k, n;
  cin >> n;
  ll a[2 * n];
  rep(i, 0, n * 2, 1) cin >> a[i];

  sort(a, a + 2 * n);
  reverse(a, a + 2 * n);

  rep(i, 0, 2 * n, 2) { z += min(a[i], a[i + 1]); }
  ce(z)
}


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

#define endl '\n'
#define ll long long
#define int long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

#define db long double;
#define pll pair<ll, ll>;

#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x)                                                         \
  sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p)                                                           \
  cout << fixed << setprecision((p)) << x << endl // print with precision

#define tc(tt)                                                                 \
  ll tt;                                                                       \
  cin >> tt;                                                                   \
  for (ll _tt = 0; _tt < tt; _tt++) // testcase

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll t, i, x, j, y, z = 0, k, n;
  cin >> n;
  ll a[2 * n];
  rep(i, 0, n * 2, 1) cin >> a[i];

  sort(a, a + 2 * n);
  reverse(a, a + 2 * n);

  rep(i, 0, 2 * n, 2) { z += min(a[i], a[i + 1]); }
  ce(z)
}
Problem p04047 (C++)

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

using namespace std;

int main() {
  int ans = 0, N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < 2 * N; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

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

  cout << ans;
}

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

using namespace std;

int main() {
  int ans = 0, N;
  cin >> N;
  vector<int> L(2 * N);
  for (int i = 0; i < 2 * N; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

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

  cout << ans;
}
Problem p04047 (C++)

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

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

  int l[110];

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

  sort(l, l + n * 2);
  int ans = 0;

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

  cout << ans << endl;

  return 0;
}


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

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

  int l[210];

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

  sort(l, l + n * 2);
  int ans = 0;

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

  cout << ans << endl;

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 101;
int n;
int a[2 * N];
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < 2 * n; ++i) {
    cin >> a[i];
  }
  sort(a, a + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ans += a[i];
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 101;
int n;
int a[2 * N];
int main() {
  //   #ifndef ONLINE_JUDGE
  //      freopen("input.txt","r",stdin);
  //      freopen("output.txt","w",stdout);
  //   #endif // ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < 2 * n; ++i) {
    cin >> a[i];
  }
  sort(a, a + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ans += a[i];
  cout << ans;
  return 0;
}
Problem p04047 (C++)

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


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

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

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for (int loop_ = n; loop_; --loop_)
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for (int i = a; i < (int)(b); ++i)

int main(void) {
  int N;
  cin >> N;
  int L[100];
  Rep(i, 2 * N) { cin >> L[i]; }
  sort(L, L + 2 * N);
  int ans = 0;
  Rep(i, N) { ans += L[2 * i]; }
  PrintLn(ans);

  return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for (int loop_ = n; loop_; --loop_)
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for (int i = a; i < (int)(b); ++i)

int main(void) {
  int N;
  cin >> N;
  int L[200];
  Rep(i, 2 * N) { cin >> L[i]; }
  sort(L, L + 2 * N);
  int ans = 0;
  Rep(i, N) { ans += L[2 * i]; }
  PrintLn(ans);

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster()                                                      \
  do {                                                                         \
    cin.tie(nullptr);                                                          \
    ios_base::sync_with_stdio(false);                                          \
  } while (0)
using namespace std;
typedef int64_t i64;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

signed main() {
  int N;
  int a[105];

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

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

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster()                                                      \
  do {                                                                         \
    cin.tie(nullptr);                                                          \
    ios_base::sync_with_stdio(false);                                          \
  } while (0)
using namespace std;
typedef int64_t i64;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

signed main() {
  int N;
  int a[205];

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

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

  cout << ans << endl;

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args> auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll, ll> P;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a[105];
  cin >> n;
  rep(i, 2 * n) cin >> a[i];
  sort(a, a + 2 * n);
  int ans = 0;
  rep(i, n) { ans += a[2 * i]; }
  PRINT(ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args> auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll, ll> P;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a[205];
  cin >> n;
  rep(i, 2 * n) cin >> a[i];
  sort(a, a + 2 * n);
  int ans = 0;
  rep(i, n) { ans += a[2 * i]; }
  PRINT(ans);
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int rrr[105], n;
  cin >> n;
  n *= 2;
  for (int i = 0; i < n; i++)
    cin >> rrr[i];

  sort(rrr, rrr + n);

  int sum = 0;
  for (int i = 0; i < n; i += 2) {
    sum += min(rrr[i], rrr[i + 1]);
  }
  cout << sum;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int rrr[205], n;
  cin >> n;
  n *= 2;
  for (int i = 0; i < n; i++)
    cin >> rrr[i];

  sort(rrr, rrr + n);

  int sum = 0;
  for (int i = 0; i < n; i += 2) {
    sum += min(rrr[i], rrr[i + 1]);
  }
  cout << sum;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, l[105];
  cin >> n;
  n *= 2;
  rep(i, n) { cin >> l[i]; }
  sort(l, l + n);
  long long sum = 0;
  for (int i = 0; i < n; i += 2) {
    sum += l[i];
  }
  cout << sum << '\n';

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, l[205];
  cin >> n;
  n *= 2;
  rep(i, n) { cin >> l[i]; }
  sort(l, l + n);
  long long sum = 0;
  for (int i = 0; i < n; i += 2) {
    sum += l[i];
  }
  cout << sum << '\n';

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define pii pair<pi, int>
#define mp make_pair
bool cmp(int x, int y) { return x > y; }
int main() {
  int i, j, k;
  int n, arr[105];
  sd(n);
  for (i = 0; i < 2 * n; i++)
    sd(arr[i]);
  sort(arr, arr + 2 * n, cmp);
  int ans = 0;
  for (i = 1; i < 2 * n; i += 2)
    ans += arr[i];
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define pii pair<pi, int>
#define mp make_pair
bool cmp(int x, int y) { return x > y; }
int main() {
  int i, j, k;
  int n, arr[205];
  sd(n);
  for (i = 0; i < 2 * n; i++)
    sd(arr[i]);
  sort(arr, arr + 2 * n, cmp);
  int ans = 0;
  for (i = 1; i < 2 * n; i += 2)
    ans += arr[i];
  printf("%d\n", ans);
  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
#define MAX 100
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  n = 2 * n;
  for (i = 0; i < n; i++)
    cin >> A[i];

  mergeSort(A, n, 0, n);
  long long sum = 0;
  for (i = 0; i < n; i += 2) {
    sum += min(A[i], A[i + 1]);
  }
  cout << sum;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  n = 2 * n;
  for (i = 0; i < n; i++)
    cin >> A[i];

  mergeSort(A, n, 0, n);
  long long sum = 0;
  for (i = 0; i < n; i += 2) {
    sum += min(A[i], A[i + 1]);
  }
  cout << sum;
  return 0;
}
Problem p04047 (C++)

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

signed main() {
  int n, i;
  int l[100];

  cin >> n;
  for (i = 0; i < 2 * n; i++)
    cin >> l[i];
  sort(l, l + 2 * n);

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

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

signed main() {
  int n, i;
  int l[200];

  cin >> n;
  for (i = 0; i < 2 * n; i++)
    cin >> l[i];
  sort(l, l + 2 * n);

  int ans = 0;
  for (i = 0; i < 2 * n; i += 2) {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p04047 (C++)

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, 2 * n) { cin >> a[i]; }
  sort(a, a + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2) {
    ans += a[i];
  }
  COUT(ans);
  return 0;
}

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl

int main() {
  int n;
  cin >> n;
  int a[2 * n];
  REP(i, 2 * n) { cin >> a[i]; }
  sort(a, a + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2) {
    ans += a[i];
  }
  COUT(ans);
  return 0;
}
Problem p04047 (C++)

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

int main() {
  int N, S = 0;
  cin >> N;
  vector<int> vec;

  for (int i = 0; i < N * 2; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    S += vec.at(i * 2);
  }

  cout << S << endl;
}

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

int main() {
  int N, S = 0;
  cin >> N;
  vector<int> vec(N * 2);

  for (int i = 0; i < N * 2; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    S += vec.at(i * 2);
  }

  cout << S << endl;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[105], n;
  cin >> n;
  for (int i = 0; i < 2 * n; i++)
    cin >> a[i];
  sort(a, a + 2 * n);
  int count = 0;
  for (int i = 0; i < 2 * n; i += 2)
    count += a[i];
  cout << count;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[205], n;
  cin >> n;
  for (int i = 0; i < 2 * n; i++)
    cin >> a[i];
  sort(a, a + 2 * n);
  int count = 0;
  for (int i = 0; i < 2 * n; i += 2)
    count += a[i];
  cout << count;
  return 0;
}
Problem p04047 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FFOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define RREP(i, b) FFOR(i, 1, b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut, pr> ppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 5 + 1e+5;
const ut INF = 1 << 30;
const ld eps = 1e-6;
const LL mod = 7 + 1e+9;

int main() {
  int n, l[128];
  cin >> n;
  REP(i, n * 2)
  cin >> l[i];
  sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < n * 2; i += 2)
    ans += l[i];
  cout << ans << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FFOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define RREP(i, b) FFOR(i, 1, b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut, pr> ppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 5 + 1e+5;
const ut INF = 1 << 30;
const ld eps = 1e-6;
const LL mod = 7 + 1e+9;

int main() {
  int n, l[256];
  cin >> n;
  REP(i, n * 2)
  cin >> l[i];
  sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < n * 2; i += 2)
    ans += l[i];
  cout << ans << endl;
}
Problem p04047 (C++)

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

int main() {
  int n;
  cin >> n;
  int hako[110];
  REP(i, n * 2) cin >> hako[i];
  sort(hako, hako + n * 2);
  int ret = 0;
  for (int i = 0; i < n * 2; i += 2) {
    ret += hako[i];
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

int main() {
  int n;
  cin >> n;
  int hako[210];
  REP(i, n * 2) cin >> hako[i];
  sort(hako, hako + n * 2);
  int ret = 0;
  for (int i = 0; i < n * 2; i += 2) {
    ret += hako[i];
  }
  cout << ret << endl;
  return 0;
}
Problem p04047 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long res;
int main() {
  int n, t;
  cin >> n;
  t = 2 * n;
  int a[t];
  int i;
  for (i = 0; i < t; i++)
    cin >> a[i];
  sort(a, a + t);
  for (i = 0; i < t; i++)
    if (i % 2 == 0)
      res += a[i];
  cout << res;
  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
int main() {
  int n, l[100];
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; i++)
    scanf("%d", &l[i]);
  std::sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ans += l[i];
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
int main() {
  int n, l[200];
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; i++)
    scanf("%d", &l[i]);
  std::sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ans += l[i];
  printf("%d", ans);
  return 0;
}
Problem p04047 (C++)

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

int main() {
  int N;
  cin >> N;
  int c[N];
  vector<int> v;
  int sum = 0;

  for (int i = 0; i < 2 * N; i++) {
    cin >> c[i];
    v.push_back(c[i]);
  }
  sort(v.begin(), v.end());

  for (int i = 0; i < v.size(); i += 2) {
    sum += v[i];
  }

  cout << sum << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int c[2 * N];
  vector<int> v;
  int sum = 0;

  for (int i = 0; i < 2 * N; i++) {
    cin >> c[i];
    v.push_back(c[i]);
  }
  sort(v.begin(), v.end());

  for (int i = 0; i < v.size(); i += 2) {
    sum += v[i];
  }

  cout << sum << endl;

  return 0;
}
Problem p04047 (C++)

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

int main() {
  int n;
  cin >> n;
  int l[n];
  for (int i = 0; i < 2 * n; i++) {
    cin >> l[i];
  }
  sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += l[i << 1];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int l[2 * n];
  for (int i = 0; i < 2 * n; i++) {
    cin >> l[i];
  }
  sort(l, l + 2 * n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += l[i << 1];
  }
  cout << ans << endl;
  return 0;
}
Problem p04047 (C++)

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

using namespace std;

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

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

using namespace std;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int n, ans = 0, l[110], i;
  cin >> n;
  n = n * 2;
  for (i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l, l + n);
  for (i = 0; i < n; i++) {
    if (i % 2 == 0) {
      ans += l[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int n, ans = 0, l[210], i;
  cin >> n;
  n = n * 2;
  for (i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l, l + n);
  for (i = 0; i < n; i++) {
    if (i % 2 == 0) {
      ans += l[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p04047 (C++)

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

using namespace std;

int main(void) {
  // 入力
  int spite_number, spite_length[100], i = 0;
  // spite_number:串の数 spite_length[100]:串の長さ
  cin >> spite_number;
  spite_number *= 2;
  while (i < spite_number) {
    cin >> spite_length[i];
    i++;
  }

  // ソート
  int tmp;
  for (int j = 0; j < (spite_number - 1); j++) {
    for (int k = (spite_number - 1); k > j; k--) {
      if (spite_length[k - 1] > spite_length[k]) {
        tmp = spite_length[k - 1];
        spite_length[k - 1] = spite_length[k];
        spite_length[k] = tmp;
      }
    }
  }

  // 短い串からペアを作っていく
  int sum = 0;
  // sum:具材の合計
  for (i = 0; i < spite_number; i += 2) {
    sum += spite_length[i];
  }

  cout << sum;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  // 入力
  int spite_number, spite_length[200], i = 0;
  // spite_number:串の数 spite_length[100]:串の長さ
  cin >> spite_number;
  spite_number *= 2;
  while (i < spite_number) {
    cin >> spite_length[i];
    i++;
  }

  // ソート
  int tmp;
  for (int j = 0; j < (spite_number - 1); j++) {
    for (int k = (spite_number - 1); k > j; k--) {
      if (spite_length[k - 1] > spite_length[k]) {
        tmp = spite_length[k - 1];
        spite_length[k - 1] = spite_length[k];
        spite_length[k] = tmp;
      }
    }
  }

  // 短い串からペアを作っていく
  int sum = 0;
  // sum:具材の合計
  for (i = 0; i < spite_number; i += 2) {
    sum += spite_length[i];
  }

  cout << sum;

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

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

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

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


Fixed submission:
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

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

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

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

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

using namespace std;

#define rep(i, a, n) for (int(i) = a; (i) < (int)(n); (i)++)
#define rrep(i, a, n) for (int(i) = (n)-1; (i) >= a; (i)--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
  int N, L[102];
  cin >> N;
  rep(i, 0, 2 * N) { cin >> L[i]; }
  sort(L, L + 2 * N);
  ll ans = 0;
  rep(i, 0, N) { ans += L[2 * i]; }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, a, n) for (int(i) = a; (i) < (int)(n); (i)++)
#define rrep(i, a, n) for (int(i) = (n)-1; (i) >= a; (i)--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
  int N, L[202];
  cin >> N;
  rep(i, 0, 2 * N) { cin >> L[i]; }
  sort(L, L + 2 * N);
  ll ans = 0;
  rep(i, 0, N) { ans += L[2 * i]; }
  cout << ans << endl;
}
Problem p04047 (C++)

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

int main() {
  int n, a[101], ans = 0;

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

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

  return 0;
}


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

int main() {
  int n, a[202], ans = 0;

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

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

  return 0;
}
Problem p04047 (C++)

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

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

  int n;
  int l[111];
  int ans = 0;

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

  sort(l, l + n);

  for (int i = n - 2; i >= 0; i -= 2) {
    ans += l[i];
  }

  cout << ans << endl;

  return 0;
}

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

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

  int n;
  int l[222];
  int ans = 0;

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

  sort(l, l + n);

  for (int i = n - 2; i >= 0; i -= 2) {
    ans += l[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int i, j, n, m, x, a[100];
  scanf("%d", &n);
  for (i = 1; i <= n * 2; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n * 2; i++) {
    for (j = i + 1; j <= n * 2; j++) {
      if (a[i] < a[j]) {
        m = a[i];
        a[i] = a[j];
        a[j] = m;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    x += a[i * 2];
  }
  printf("%d\n", x);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int i, j, n, m, x, a[201];
  scanf("%d", &n);
  for (i = 1; i <= n * 2; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n * 2; i++) {
    for (j = i + 1; j <= n * 2; j++) {
      if (a[i] < a[j]) {
        m = a[i];
        a[i] = a[j];
        a[j] = m;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    x += a[i * 2];
  }
  printf("%d\n", x);
  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define PB push_back
#define all(a) (a).begin(), (a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a) (a).begin(), (a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{(ll)1e9 + 7};
const long double EPS = 1e-10;

int main() {
  int N, L[101];
  cin >> N;
  rep(i, 2 * N) cin >> L[i];

  sort(L, L + 2 * N);
  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    ans += min(L[i], L[i + 1]);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define PB push_back
#define all(a) (a).begin(), (a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a) (a).begin(), (a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{(ll)1e9 + 7};
const long double EPS = 1e-10;

int main() {
  int N, L[201];
  cin >> N;
  rep(i, 2 * N) cin >> L[i];

  sort(L, L + 2 * N);
  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    ans += min(L[i], L[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main() {
  int N, L[110];
  cin >> N;
  for (int i = 0; i < N * 2; i++)
    cin >> L[i];
  int ans = 0;
  sort(L, L + N * 2);
  for (int i = 0; i < N * 2; i += 2)
    ans += min(L[i], L[i + 1]);
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main() {
  int N, L[210];
  cin >> N;
  for (int i = 0; i < N * 2; i++)
    cin >> L[i];
  int ans = 0;
  sort(L, L + N * 2);
  for (int i = 0; i < N * 2; i += 2)
    ans += min(L[i], L[i + 1]);
  cout << ans << endl;
}
Problem p04047 (C++)

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

int main() {
  int n, ans = 0;
  int i = 0;
  int L[100];

  cin >> n;

  while (cin >> L[i]) {
    i += 1;
  }

  sort(L, L + i);

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

  cout << ans << endl;

  return 0;
}

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

int main() {
  int n, ans = 0;
  int i = 0;
  int L[200];

  cin >> n;

  while (cin >> L[i]) {
    i += 1;
  }

  sort(L, L + i);

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

  cout << ans << endl;

  return 0;
}
Problem p04047 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < 2 * n; i++)
    cin >> l.at(i);
  sort(l.begin(), l.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += l.at(i * 2);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n * 2);
  for (int i = 0; i < 2 * n; i++)
    cin >> l.at(i);
  sort(l.begin(), l.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += l.at(i * 2);
  }
  cout << ans << endl;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(x, to) for (x = 0; x < (to); x++)

int main() {
  int n, i;
  cin >> n;
  int l[n];
  FOR(i, 2 * n) { cin >> l[i]; }
  sort(l, l + 2 * n);
  int ans = 0;
  FOR(i, n) { ans += l[2 * i]; }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(x, to) for (x = 0; x < (to); x++)

int main() {
  int n, i;
  cin >> n;
  int l[2 * n];
  FOR(i, 2 * n) { cin >> l[i]; }
  sort(l, l + 2 * n);
  int ans = 0;
  FOR(i, n) { ans += l[2 * i]; }
  cout << ans;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
// A.

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[]) {
  LL N, L[100], ans = 0;
  cin >> N;
  for (int i = 0; i < N * 2; ++i) {
    cin >> L[i];
  }
  sort(L, L + N * 2);
  for (int i = 0; i < N; ++i) {
    ans += L[i * 2];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// A.

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[]) {
  LL N, L[200], ans = 0;
  cin >> N;
  for (int i = 0; i < N * 2; ++i) {
    cin >> L[i];
  }
  sort(L, L + N * 2);
  for (int i = 0; i < N; ++i) {
    ans += L[i * 2];
  }
  cout << ans << endl;
  return 0;
}
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> b;
  int c;
  for (int i = 0; i < 2 * a; i++) {
    cin >> c;
    b.push_back(c);
  }
  sort(b.begin(), b.end());
  int d = 0;
  for (int i = 0; i < b.size() - 1; i++) {
    if (b[i] == b[i + 1]) {
      d += b[i];
      b.erase(b.begin() + i);
      b.erase(b.begin() + i);
    }
  }
  for (int i = 0; i < b.size(); i++) {
    d += b[i];
    i++;
  }
  cout << d << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> b;
  int c;
  for (int i = 0; i < 2 * a; i++) {
    cin >> c;
    b.push_back(c);
  }
  sort(b.begin(), b.end());
  int d = 0;
  for (int i = 0; i < (int)b.size() - 1; i++) {
    if (b[i] == b[i + 1]) {
      d += b[i];
      b.erase(b.begin() + i);
      b.erase(b.begin() + i);
    }
  }
  for (int i = 0; i < b.size(); i++) {
    d += b[i];
    i++;
  }
  cout << d << endl;
  return 0;
}
Problem p04047 (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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l[100];
  cin >> n;
  for (int i = 0; i < 2 * n; ++i)
    cin >> l[i];
  sort(l, l + 2 * n);
  int sol = 0;
  for (int i = 0; i < n; ++i)
    sol += l[i * 2];
  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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l[200];
  cin >> n;
  for (int i = 0; i < 2 * n; ++i)
    cin >> l[i];
  sort(l, l + 2 * n);
  int sol = 0;
  for (int i = 0; i < n; ++i)
    sol += l[i * 2];
  cout << sol;
}
Problem p04047 (C++)

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

const int MAX = 100;
int main() {
  int N, L[MAX];
  cin >> N;
  N <<= 1;
  for (int i = 0; i < N; ++i)
    cin >> L[i];
  sort(L, L + N);
  int ans = 0;
  for (int i = N - 2; i >= 0; i -= 2)
    ans += L[i];
  cout << ans;
  return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/
で解説していると思うので、良かったら読んでねー

串をソートする
ここで、A_1≦A_2≦A_3≦A_4に対し、A_1とA_3、A_2とA_4とやるよりA_1とA_2、A_3とA_4とやった方が具材数は増える
よって、基本的に小さい順に取る
ただ、奇数本の時はどう考えても一番小さい串が不要なので、むしろ大きい順に取っていくと良い
*/

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

const int MAX = 200;
int main() {
  int N, L[MAX];
  cin >> N;
  N <<= 1;
  for (int i = 0; i < N; ++i)
    cin >> L[i];
  sort(L, L + N);
  int ans = 0;
  for (int i = N - 2; i >= 0; i -= 2)
    ans += L[i];
  cout << ans;
  return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/
で解説していると思うので、良かったら読んでねー

串をソートする
ここで、A_1≦A_2≦A_3≦A_4に対し、A_1とA_3、A_2とA_4とやるよりA_1とA_2、A_3とA_4とやった方が具材数は増える
よって、基本的に小さい順に取る
ただ、奇数本の時はどう考えても一番小さい串が不要なので、むしろ大きい順に取っていくと良い
*/
Problem p04047 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int compare(const void *p, const void *q) {
  int a = *(int *)p, b = *(int *)q;
  return b - a;
}

int main() {
  int i, n, d[100], prev, post, sum = 0, sum1 = 0;
  scanf("%d", &n);
  for (i = 0; i < 2 * n; i++)
    scanf("%d", &d[i]);
  qsort(d, 2 * n, sizeof(int), compare);
  for (i = 1; i < 2 * n; i += 2)
    sum += d[i];
  printf("%d\n", sum);
  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int compare(const void *p, const void *q) {
  int a = *(int *)p, b = *(int *)q;
  return b - a;
}

int main() {
  int i, n, d[1000], prev, post, sum = 0, sum1 = 0;
  scanf("%d", &n);
  for (i = 0; i < 2 * n; i++)
    scanf("%d", &d[i]);
  qsort(d, 2 * n, sizeof(int), compare);
  for (i = 1; i < 2 * n; i += 2)
    sum += d[i];
  printf("%d\n", sum);
  return 0;
}
Problem p04047 (C++)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()

#define cmp_all(X) (X).begin(), (X).end(), cmp

#define B begin()
#define E end()
#define sz size()
#define skip continue

#define ppi pair<pair<int, int>, int>
#define pii pair<int, int>
#define pli pair<ll, int>

#define F first
#define S second

using namespace std;

const int maxn = 1e7 + 17;
const int MAXN = maxn * 4;
const int darr = 1e3 + 17;
const ll INF = 1e17 + 5;
const int mod = 1e9 + 7;

void Need_For_Speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int n, res;
int a[maxn];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  Need_For_Speed();
  cin >> n;
  for (int i = 1; i <= n + n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + n + 1);
  for (int i = 2; i <= n + n; i += 2) {
    res += min(a[i], a[i - 1]);
  }
  cout << res;
  return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()

#define cmp_all(X) (X).begin(), (X).end(), cmp

#define B begin()
#define E end()
#define sz size()
#define skip continue

#define ppi pair<pair<int, int>, int>
#define pii pair<int, int>
#define pli pair<ll, int>

#define F first
#define S second

using namespace std;

const int maxn = 1e7 + 17;
const int MAXN = maxn * 4;
const int darr = 1e3 + 17;
const ll INF = 1e17 + 5;
const int mod = 1e9 + 7;

void Need_For_Speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int n, res;
int a[maxn];

int main() {
  Need_For_Speed();
  cin >> n;
  for (int i = 1; i <= n + n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + n + 1);
  for (int i = 2; i <= n + n; i += 2) {
    res += min(a[i], a[i - 1]);
  }
  cout << res;
  return 0;
}
Problem p04047 (C++)

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

int main() {
  // freopen("task.inp", "r", stdin);
  int n;
  int a[maxn];
  cin >> n;
  for (int i = 1; i <= n * 2; ++i)
    cin >> a[i];
  sort(a + 1, a + n * 2 + 1);
  int sum = 0;
  for (int i = 1; i <= n * 2 - 1; i += 2)
    sum += a[i];
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;

int main() {
  // freopen("task.inp", "r", stdin);
  int n;
  int a[maxn];
  cin >> n;
  for (int i = 1; i <= n * 2; ++i)
    cin >> a[i];
  sort(a + 1, a + n * 2 + 1);
  int sum = 0;
  for (int i = 1; i <= n * 2 - 1; i += 2)
    sum += a[i];
  cout << sum << endl;
}
Problem p04047 (C++)

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

using namespace std;

int main() {

  int N;
  int kusi[101];

  cin >> N;

  for (int i = 0; i < 2 * N; i++) {

    cin >> kusi[i];
  }

  sort(kusi, kusi + (2 * N));
  int ans = 0;

  for (int i = 0; i < 2 * N; i++) {

    if (i % 2 == 0 || i == 0) {

      ans += kusi[i];
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {

  int N;
  int kusi[300];

  cin >> N;

  for (int i = 0; i < 2 * N; i++) {

    cin >> kusi[i];
  }

  sort(kusi, kusi + (2 * N));
  int ans = 0;

  for (int i = 0; i < 2 * N; i++) {

    if (i % 2 == 0 || i == 0) {

      ans += kusi[i];
    }
  }

  cout << ans << endl;
}